From: Michael Poole Date: Mon, 13 Sep 2004 22:33:31 +0000 (+0000) Subject: Make default virtual host work for .12, and make IPv4-only X-Git-Url: http://git.pk910.de/?p=ircu2.10.12-pk.git;a=commitdiff_plain;h=0b1c58ace7aad7919ce1ba9c7e58da9711e59dce Make default virtual host work for .12, and make IPv4-only configurations work like users probably expect. git-svn-id: file:///home/klmitch/undernet-ircu/undernet-ircu-svn/ircu2/trunk@1141 c9e4aea6-c8fd-4c43-8297-357d70d61c8c --- diff --git a/ChangeLog b/ChangeLog index 6cc43f2..f2a2d42 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,31 @@ +2004-09-13 Michael Poole + + * doc/example.conf: Remove sample VIRTUAL_HOST setting. + + * doc/readme.features: Remove VIRTUAL_HOST documentation, and + update NODNS documentation to match current behavior. + + * include/s_conf.h: Remove now-unused vhost_address field and + set_virtual_host() function. + + * include/ircd_features.h, ircd/ircd_features.c, ircd/s_debug.c: + Remove VIRTUAL_HOST. + + * ircd/ircd_auth.c, ircd/s_bsd.c: Use VirtualHost as local address + if we do not have a more specific alternate. + + * ircd/ircd_parser.y: Check for sanity in General blocks (from old + conf_add_local()) and assign vhost directly to VirtualHost. + + * ircd/ircd_res.c (irc_in_addr_valid): Fix thinko; obviously any + value will be either != 0 or != 0xffff. + + * ircd/os_generic.c: Use AF_INET instead of AF_INET6 when the + local addresses are specified as IPv4 addresses. + + * ircd/s_conf.c: Remove unused conf_add_local() and + set_virtual_host(). + 2004-09-13 Michael Poole * ircd/listener.c (add_listener): Consolidate duplicated code, and diff --git a/doc/example.conf b/doc/example.conf index 8ca6cb9..189dfe0 100644 --- a/doc/example.conf +++ b/doc/example.conf @@ -803,7 +803,6 @@ features # "MPATH" = "ircd.motd"; # "RPATH" = "remote.motd"; # "PPATH" = "ircd.pid"; -# "VIRTUAL_HOST" = "FALSE"; # "TOS_SERVER" = "0x08"; # "TOS_CLIENT" = "0x08"; # "POLLS_PER_LOOP" = "200"; diff --git a/doc/readme.features b/doc/readme.features index 698e4db..0157be7 100644 --- a/doc/readme.features +++ b/doc/readme.features @@ -185,11 +185,10 @@ If you are playing with the server off-line, and no DNS is available, then long delays occur before the server starts up because it tries to resolve the name given in the General block (which usually isn't given in /etc/hosts) and for each connecting client. If you specify "TRUE" -here, then a call to gethostbyname() will be done only for the real -hostname, and the server will not try to resolve clients that connect -to "localhost." Note that other calls to gethostbyname() are still -done if you use VIRTUAL_HOST; also note that the server still tries to -resolve clients that connect to the real IP address of the server. +here, then a DNS lookup will be done only for the real hostname, and +the server will not try to resolve clients that connect to +"localhost." Note that other DNS lookups are still done for outbound +connections. RANDOM_SEED * Type: string @@ -411,18 +410,6 @@ PPATH is the filename (relative to DPATH) or the full path of the "PID" file. It is used for storing the server's process ID so that a ps(1) isn't necessary. -VIRTUAL_HOST - * Type: boolean - * Default: FALSE - -This option is only needed when you wish to run multiple IRC servers -on the same machine, and they must share at least one port. This will -require having multiple IP addresses for the machine that will be -hosting the servers. If you specify "TRUE" here, you can cause the -server to bind to one of these IP addresses. Use the vhost field of -the General block to specify the IP address. If you are unsure, stick -with "FALSE." - TOS_SERVER * Type: integer * Default: 0x08 diff --git a/include/ircd_features.h b/include/ircd_features.h index 58a0d61..fcfd02c 100644 --- a/include/ircd_features.h +++ b/include/ircd_features.h @@ -79,7 +79,6 @@ enum Feature { FEAT_PPATH, /* Networking features */ - FEAT_VIRTUAL_HOST, FEAT_TOS_SERVER, FEAT_TOS_CLIENT, FEAT_POLLS_PER_LOOP, diff --git a/include/s_bsd.h b/include/s_bsd.h index 69822bb..db8bd30 100644 --- a/include/s_bsd.h +++ b/include/s_bsd.h @@ -88,7 +88,6 @@ extern int read_message(time_t delay); extern void init_server_identity(void); extern void close_connections(int close_stderr); extern int init_connection_limits(void); -extern void set_virtual_host(const struct irc_in_addr *addr); extern void update_write(struct Client* cptr); #endif /* INCLUDED_s_bsd_h */ diff --git a/include/s_conf.h b/include/s_conf.h index 77a71b6..763c78d 100644 --- a/include/s_conf.h +++ b/include/s_conf.h @@ -105,7 +105,6 @@ struct DenyConf { struct LocalConf { char* name; char* description; - struct irc_in_addr vhost_address; unsigned int numeric; char* location1; char* location2; diff --git a/ircd/ircd_auth.c b/ircd/ircd_auth.c index 31fc366..dd9f9d7 100644 --- a/ircd/ircd_auth.c +++ b/ircd/ircd_auth.c @@ -362,7 +362,7 @@ static void iauth_reconnect(struct IAuth *iauth) gethost_byname(i_host(iauth), &i_query(iauth)); return; } - fd = os_socket((feature_bool(FEAT_VIRTUAL_HOST) ? &VirtualHost : NULL), SOCK_STREAM, "IAuth"); + fd = os_socket(&VirtualHost, SOCK_STREAM, "IAuth"); if (fd < 0) return; if (!os_set_sockbufs(fd, SERVER_TCP_WINDOW, SERVER_TCP_WINDOW)) { diff --git a/ircd/ircd_features.c b/ircd/ircd_features.c index 61e23ed..5a80dcd 100644 --- a/ircd/ircd_features.c +++ b/ircd/ircd_features.c @@ -285,7 +285,6 @@ static struct FeatureDesc { F_S(PPATH, FEAT_CASE | FEAT_MYOPER | FEAT_READ, "ircd.pid", 0), /* Networking features */ - F_B(VIRTUAL_HOST, 0, 0, 0), F_I(TOS_SERVER, 0, 0x08, 0), F_I(TOS_CLIENT, 0, 0x08, 0), F_I(POLLS_PER_LOOP, 0, 200, 0), diff --git a/ircd/ircd_parser.y b/ircd/ircd_parser.y index 5d66f9d..3aa0afc 100644 --- a/ircd/ircd_parser.y +++ b/ircd/ircd_parser.y @@ -265,7 +265,13 @@ jupenick: NICK '=' QSTRING addNickJupes($3); } ';'; -generalblock: GENERAL '{' generalitems '}' ';' ; +generalblock: GENERAL '{' generalitems '}' +{ + if (localConf.name == NULL) + parse_error("Your General block must contain a name."); + if (localConf.numeric == 0) + parse_error("Your General block must contain a numeric (between 1 and 4095)."); +} ';' ; generalitems: generalitem generalitems | generalitem; generalitem: generalnumeric | generalname | generalvhost | generaldesc | error; generalnumeric: NUMERIC '=' NUMBER ';' @@ -295,7 +301,7 @@ generaldesc: DESCRIPTION '=' QSTRING ';' generalvhost: VHOST '=' QSTRING ';' { - ircd_aton(&localConf.vhost_address, $3); + ircd_aton(&VirtualHost.addr, $3); }; adminblock: ADMIN '{' adminitems '}' diff --git a/ircd/ircd_res.c b/ircd/ircd_res.c index 4946e4b..557c874 100644 --- a/ircd/ircd_res.c +++ b/ircd/ircd_res.c @@ -898,7 +898,7 @@ int irc_in_addr_valid(const struct irc_in_addr *addr) unsigned short val; val = addr->in6_16[0]; - if (val != 0 || val != 0xffff) + if (val != 0 && val != 0xffff) return 1; for (ii = 1; ii < 8; ii++) if (addr->in6_16[ii] != val) diff --git a/ircd/os_generic.c b/ircd/os_generic.c index adada45..7b4fe0f 100644 --- a/ircd/os_generic.c +++ b/ircd/os_generic.c @@ -69,26 +69,50 @@ #ifdef IPV6 #define sockaddr_native sockaddr_in6 +#define sn_family sin6_family void sockaddr_to_irc(const struct sockaddr_in6 *v6, struct irc_sockaddr *irc) { - assert(v6->sin6_family == AF_INET6); - memcpy(&irc->addr.in6_16[0], &v6->sin6_addr, sizeof(v6->sin6_addr)); - irc->port = ntohs(v6->sin6_port); + if (v6->sin6_family == AF_INET6) { + memcpy(&irc->addr.in6_16[0], &v6->sin6_addr, sizeof(v6->sin6_addr)); + irc->port = ntohs(v6->sin6_port); + } + else if (v6->sin6_family == AF_INET) { + const struct sockaddr_in *v4 = (const struct sockaddr_in*)v6; + memset(&irc->addr, 0, 5*sizeof(int16_t)); + irc->addr.in6_16[5] = 0xffff; + memcpy(&irc->addr.in6_16[6], &v4->sin_addr, sizeof(v4->sin_addr)); + irc->port = ntohs(v4->sin_port); + } + else assert(0 && "Unhandled native address family"); } -void sockaddr_from_irc(struct sockaddr_in6 *v6, const struct irc_sockaddr *irc, int persist) +int sockaddr_from_irc(struct sockaddr_in6 *v6, const struct irc_sockaddr *irc, int persist) { memset(v6, 0, sizeof(*v6)); - v6->sin6_family = AF_INET6; - memcpy(&v6->sin6_addr, &irc->addr.in6_16[0], sizeof(v6->sin6_addr)); - if (persist && irc_in_addr_is_ipv4(&irc->addr)) - v6->sin6_addr.s6_addr[10] = v6->sin6_addr.s6_addr[11] = '\xff'; - v6->sin6_port = htons(irc->port); + if (!irc) { + memset(v6, 0, sizeof(v6)); + v6->sin6_family = AF_INET6; + return sizeof(*v6); + } + else if (persist && irc_in_addr_is_ipv4(&irc->addr)) { + struct sockaddr_in *v4 = (struct sockaddr_in*)v6; + v4->sin_family = AF_INET; + memcpy(&v4->sin_addr, &irc->addr.in6_16[6], sizeof(v4->sin_addr)); + v4->sin_port = htons(irc->port); + return sizeof(*v4); + } + else { + v6->sin6_family = AF_INET6; + memcpy(&v6->sin6_addr, &irc->addr.in6_16[0], sizeof(v6->sin6_addr)); + v6->sin6_port = htons(irc->port); + return sizeof(*v6); + } } #else #define sockaddr_native sockaddr_in +#define sn_family sin_family void sockaddr_to_irc(const struct sockaddr_in *v4, struct irc_sockaddr *irc) { @@ -98,13 +122,18 @@ void sockaddr_to_irc(const struct sockaddr_in *v4, struct irc_sockaddr *irc) irc->port = ntohs(v4->sin_port); } -void sockaddr_from_irc(struct sockaddr_in *v4, const struct irc_sockaddr *irc, int persist) +int sockaddr_from_irc(struct sockaddr_in *v4, const struct irc_sockaddr *irc, int persist) { v4->sin_family = AF_INET; - assert(!irc->addr.in6_16[0] && !irc->addr.in6_16[1] && !irc->addr.in6_16[2] && !irc->addr.in6_16[3] && !irc->addr.in6_16[4] && (!irc->addr.in6_16[5] || irc->addr.in6_16[5] == 0xffff)); - memcpy(&v4->sin_addr, &irc->addr.in6_16[6], sizeof(v4->sin_addr)); - v4->sin_port = htons(irc->port); + if (irc) { + assert(!irc->addr.in6_16[0] && !irc->addr.in6_16[1] && !irc->addr.in6_16[2] && !irc->addr.in6_16[3] && !irc->addr.in6_16[4] && (!irc->addr.in6_16[5] || irc->addr.in6_16[5] == 0xffff)); + memcpy(&v4->sin_addr, &irc->addr.in6_16[6], sizeof(v4->sin_addr)); + v4->sin_port = htons(irc->port); + } else{ + memset(&v4, 0, sizeof(v4)); + } (void)persist; + return sizeof(*v4); } #endif @@ -415,14 +444,14 @@ IOResult os_sendto_nonb(int fd, const char* buf, unsigned int length, const struct irc_sockaddr* peer) { struct sockaddr_native addr; - int res; + int res, size; assert(0 != buf); if (count_out) *count_out = 0; errno = 0; - sockaddr_from_irc(&addr, peer, 1); - if (-1 < (res = sendto(fd, buf, length, flags, (struct sockaddr*)&addr, sizeof(addr)))) { + size = sockaddr_from_irc(&addr, peer, 1); + if (-1 < (res = sendto(fd, buf, length, flags, (struct sockaddr*)&addr, size))) { if (count_out) *count_out = (unsigned) res; return IO_SUCCESS; @@ -509,13 +538,11 @@ IOResult os_sendv_nonb(int fd, struct MsgQ* buf, unsigned int* count_in, int os_socket(const struct irc_sockaddr* local, int type, const char* port_name) { - int family, fd; -#ifdef IPV6 - family = AF_INET6; -#else - family = AF_INET; -#endif - fd = socket(family, type, 0); + struct sockaddr_native addr; + int size, fd; + + size = sockaddr_from_irc(&addr, local, 1); + fd = socket(addr.sn_family, type, 0); if (fd < 0) { report_error(SOCKET_ERROR_MSG, port_name, errno); return -1; @@ -536,9 +563,7 @@ int os_socket(const struct irc_sockaddr* local, int type, const char* port_name) return -1; } if (local) { - struct sockaddr_native addr; - sockaddr_from_irc(&addr, local, 1); - if (bind(fd, (struct sockaddr*)&addr, sizeof(addr))) { + if (bind(fd, (struct sockaddr*)&addr, size)) { report_error(BIND_ERROR_MSG, port_name, errno); close(fd); return -1; @@ -565,8 +590,10 @@ int os_accept(int fd, struct irc_sockaddr* peer) IOResult os_connect_nonb(int fd, const struct irc_sockaddr* sin) { struct sockaddr_native addr; - sockaddr_from_irc(&addr, sin, 1); - if (connect(fd, (struct sockaddr*) &addr, sizeof(addr))) + int size; + + size = sockaddr_from_irc(&addr, sin, 1); + if (connect(fd, (struct sockaddr*) &addr, size)) return (errno == EINPROGRESS) ? IO_BLOCKED : IO_FAILURE; return IO_SUCCESS; } diff --git a/ircd/s_bsd.c b/ircd/s_bsd.c index b0bc051..8d14b45 100644 --- a/ircd/s_bsd.c +++ b/ircd/s_bsd.c @@ -236,10 +236,8 @@ static int connect_inet(struct ConfItem* aconf, struct Client* cptr) */ if (irc_in_addr_valid(&aconf->origin.addr)) local = &aconf->origin; - else if (feature_bool(FEAT_VIRTUAL_HOST)) - local = &VirtualHost; else - local = NULL; + local = &VirtualHost; cli_fd(cptr) = os_socket(local, SOCK_STREAM, cli_name(cptr)); if (cli_fd(cptr) < 0) return 0; @@ -898,15 +896,6 @@ int connect_server(struct ConfItem* aconf, struct Client* by) completed_connection(cptr) : 1; } -/* - * Setup local socket structure to use for binding to. - */ -void set_virtual_host(const struct irc_in_addr *addr) -{ - memset(&VirtualHost, 0, sizeof(VirtualHost)); - memcpy(&VirtualHost.addr, addr, sizeof(VirtualHost.addr)); -} - /* * Find the real hostname for the host running the server (or one which * matches the server's name) and its primary IP#. Hostname is stored diff --git a/ircd/s_conf.c b/ircd/s_conf.c index bcc498b..44859d8 100644 --- a/ircd/s_conf.c +++ b/ircd/s_conf.c @@ -693,41 +693,6 @@ void conf_add_listener(const char* const* fields, int count) add_listener(atoi(fields[4]), fields[2], fields[1], is_server, is_hidden); } -void conf_add_local(const char* const* fields, int count) -{ - if (count < 6 || EmptyString(fields[1]) || EmptyString(fields[5])) { - log_write(LS_CONFIG, L_CRIT, 0, "Your M: line must have 6 fields!"); - return; - } - /* - * these two can only be set the first time - */ - if (0 == localConf.name) { - if (string_is_hostname(fields[1])) - DupString(localConf.name, fields[1]); - } - if (0 == localConf.numeric) { - localConf.numeric = atoi(fields[5]); - if (0 == localConf.numeric) - log_write(LS_CONFIG, L_WARNING, 0, - "Your M: line must have a Numeric value greater than 0"); - } - /* - * these two can be changed while the server is running - */ - if (string_is_address(fields[2])) { - if (INADDR_NONE == (localConf.vhost_address.s_addr = inet_addr(fields[2]))) - localConf.vhost_address.s_addr = INADDR_ANY; - } - MyFree(localConf.description); - DupString(localConf.description, fields[3]); - /* - * XXX - shouldn't be setting these directly here - */ - ircd_strncpy(cli_info(&me), fields[3], REALLEN); - set_virtual_host(localConf.vhost_address); -} - void conf_add_admin(const char* const* fields, int count) { /* diff --git a/ircd/s_debug.c b/ircd/s_debug.c index 5c9ec6e..91639d5 100644 --- a/ircd/s_debug.c +++ b/ircd/s_debug.c @@ -106,9 +106,6 @@ const char* debug_serveropts(void) AddC('U'); #endif - if (feature_bool(FEAT_VIRTUAL_HOST)) - AddC('v'); - serveropts[i] = '\0'; return serveropts;