Make default virtual host work for .12, and make IPv4-only
authorMichael Poole <mdpoole@troilus.org>
Mon, 13 Sep 2004 22:33:31 +0000 (22:33 +0000)
committerMichael Poole <mdpoole@troilus.org>
Mon, 13 Sep 2004 22:33:31 +0000 (22:33 +0000)
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

14 files changed:
ChangeLog
doc/example.conf
doc/readme.features
include/ircd_features.h
include/s_bsd.h
include/s_conf.h
ircd/ircd_auth.c
ircd/ircd_features.c
ircd/ircd_parser.y
ircd/ircd_res.c
ircd/os_generic.c
ircd/s_bsd.c
ircd/s_conf.c
ircd/s_debug.c

index 6cc43f227938ff76181e9bea300a62d726222c82..f2a2d42c1674dacb1f7d21c0cace8c9c92d4897f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,31 @@
+2004-09-13  Michael Poole <mdpoole@troilus.org>
+
+       * 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 <mdpoole@troilus.org>
 
        * ircd/listener.c (add_listener): Consolidate duplicated code, and
index 8ca6cb9ae0291c402ffd8d27a100147c8523ee21..189dfe07831d4dc3a6515a48cb37bf937df7a62d 100644 (file)
@@ -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";
index 698e4dbd85893049bf6d15194653db0dfec1b913..0157be78abce6fca2a1220c3849a8b409b966687 100644 (file)
@@ -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
index 58a0d61b510b86959fa6e8d5decb76c0a213b504..fcfd02c45caf79a4628f967ceb018c8f858bce33 100644 (file)
@@ -79,7 +79,6 @@ enum Feature {
   FEAT_PPATH,
 
   /* Networking features */
-  FEAT_VIRTUAL_HOST,
   FEAT_TOS_SERVER,
   FEAT_TOS_CLIENT,
   FEAT_POLLS_PER_LOOP,
index 69822bbd0892c40d9d1cec94eda337dde4c4a13b..db8bd3062843b9601df2cf1f5d6d60332d234a12 100644 (file)
@@ -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 */
index 77a71b6db09e74b55cc9813c51d1452ece45643e..763c78d477ff6b3dd2ccb1c3f51f871bc286c0c1 100644 (file)
@@ -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;
index 31fc36683972c9d5603d92d2d1e027eae64b9b97..dd9f9d7227c7a63674d062f6b2dce5d3b022ba3c 100644 (file)
@@ -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)) {
index 61e23ed20f0b6010510d87b667093eb2b76316d7..5a80dcda675b04a18a2698b5042d59b45250f233 100644 (file)
@@ -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),
index 5d66f9dd4767d1701702a46b29227ddeedda7bfd..3aa0afcad9c8b6fc5218b5eac54e0a0a7d8eae74 100644 (file)
@@ -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 '}'
index 4946e4beae3d0b19866188c369bd82166f7325cf..557c874f5c44823de867b129dcecbe8b0398011c 100644 (file)
@@ -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)
index adada4573a6b8381c4682f79e79a4e0f6ba31eb4..7b4fe0f01fd9d87d7bb69538bd4571918447deea 100644 (file)
 
 #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;
 }
index b0bc051a0a9fbee973fd304a2c7ff339d7cee992..8d14b451fbb1a5ecee0f151a003af218074bdba3 100644 (file)
@@ -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
index bcc498bd6e2a00bd8fd9921d771a658c8c53c261..44859d8742869ee5cb7cd050900ceaeb2cf285dd 100644 (file)
@@ -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)
 {
   /*
index 5c9ec6ef133fee7edbfb1b6be0715f2d756b5777..91639d580737cb06da4855cf1551f4a7aa47a6fe 100644 (file)
@@ -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;