Similar to Kev's patch dated 2004-08-26, allow specification of local
authorMichael Poole <mdpoole@troilus.org>
Fri, 10 Sep 2004 16:40:06 +0000 (16:40 +0000)
committerMichael Poole <mdpoole@troilus.org>
Fri, 10 Sep 2004 16:40:06 +0000 (16:40 +0000)
IPs for each Connect block in the config file.

git-svn-id: file:///home/klmitch/undernet-ircu/undernet-ircu-svn/ircu2/trunk@1111 c9e4aea6-c8fd-4c43-8297-357d70d61c8c

ChangeLog
include/s_conf.h
ircd/ircd_parser.y
ircd/s_bsd.c
ircd/s_conf.c

index 4c9873ffbd6dd1b7bcdf21d62a39cdaeff1776d9..fa867899a57d1c4a9dfbf80e904f3b8853addec6 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+2004-09-10  Michael Poole <mdpoole@troilus.org>
+
+       * include/s_conf.h (struct ConfItem): Add origin and origin_name
+       fields.
+
+       * ircd/ircd_parser.y: Add new global variable "origin."  Add a new
+       "connectionvhost" production that accepts vhost = "IP" inside a
+       Connect block and assigns the IP to origin_name.
+
+       * ircd/s_bsd (connect_inet): If aconf has a valid origin, use it
+       as the local address.  Otherwise, fall back to the old logic (if
+       VIRTUAL_HOST="TRUE", use the virtual host setting).
+
+       * ircd/s_conf.c (lookup_confhost): If the ConfItem has an
+       origin_name, try to parse it as an IP address.
+
 2004-04-17  Isomer <isomer@undernet.org>
        * ircd/parse.c: Don't rate limit /gline messages
 
index 31a715740cb304294c3b4ed86047c2a9ed99bb81..77a71b6db09e74b55cc9813c51d1452ece45643e 100644 (file)
@@ -52,8 +52,10 @@ struct ConfItem
   unsigned int status;      /* If CONF_ILLEGAL, delete when no clients */
   unsigned int clients;     /* Number of *LOCAL* clients using this */
   struct ConnectionClass *conn_class;  /* Class of connection */
+  struct irc_sockaddr origin;  /* local address */
   struct irc_sockaddr address; /* ip and port */
   char *host;
+  char *origin_name;
   char *passwd;
   char *name;
   time_t hold; /* Hold until this time (calendar time) */
index 0173b4001aed9336b33cbe4b758acd6a1ef78184..5d66f9dd4767d1701702a46b29227ddeedda7bfd 100644 (file)
@@ -72,7 +72,7 @@
   /* Now all the globals we need :/... */
   int tping, tconn, maxlinks, sendq, port, invert;
   int stringno;
-  char *name, *pass, *host;
+  char *name, *pass, *host, *origin;
   char *stringlist[MAX_STRINGS];
   struct ConnectionClass *c_class;
   struct ConfItem *aconf;
@@ -382,7 +382,7 @@ classusermode: USERMODE '=' QSTRING ';'
 
 connectblock: CONNECT
 {
- name = pass = host = NULL;
+ name = pass = host = origin = NULL;
  c_class = NULL;
  port = 0;
 } '{' connectitems '}'
@@ -393,6 +393,7 @@ connectblock: CONNECT
    aconf = make_conf();
    aconf->status = CONF_SERVER;
    aconf->name = name;
+   aconf->origin_name = origin;
    aconf->passwd = pass;
    aconf->conn_class = c_class;
    aconf->address.port = port;
@@ -407,13 +408,14 @@ connectblock: CONNECT
    MyFree(name);
    MyFree(pass);
    MyFree(host);
-   name = pass = host = NULL;
+   MyFree(origin);
    parse_error("Bad connect block");
  }
+ name = pass = host = origin = NULL;
 }';';
 connectitems: connectitem connectitems | connectitem;
 connectitem: connectname | connectpass | connectclass | connecthost
-              | connectport | error;
+              | connectport | connectvhost | error;
 connectname: NAME '=' QSTRING ';'
 {
  MyFree(name);
@@ -437,6 +439,11 @@ connectport: PORT '=' NUMBER ';'
 {
  port = $3;
 };
+connectvhost: VHOST '=' QSTRING ';'
+{
+ MyFree(origin);
+ DupString(origin, $3);
+};
 
 serverblock: SERVER
 {
index f8637137f65bf7272da25e0fb0e29f430889395c..b0bc051a0a9fbee973fd304a2c7ff339d7cee992 100644 (file)
@@ -226,6 +226,7 @@ int init_connection_limits(void)
  */
 static int connect_inet(struct ConfItem* aconf, struct Client* cptr)
 {
+  const struct irc_sockaddr *local;
   IOResult result;
   assert(0 != aconf);
   assert(0 != cptr);
@@ -233,7 +234,13 @@ static int connect_inet(struct ConfItem* aconf, struct Client* cptr)
    * Might as well get sockhost from here, the connection is attempted
    * with it so if it fails its useless.
    */
-  cli_fd(cptr) = os_socket((feature_bool(FEAT_VIRTUAL_HOST) ? &VirtualHost : NULL), SOCK_STREAM, cli_name(cptr));
+  if (irc_in_addr_valid(&aconf->origin.addr))
+    local = &aconf->origin;
+  else if (feature_bool(FEAT_VIRTUAL_HOST))
+    local = &VirtualHost;
+  else
+    local = NULL;
+  cli_fd(cptr) = os_socket(local, SOCK_STREAM, cli_name(cptr));
   if (cli_fd(cptr) < 0)
     return 0;
 
index 9b216653da47378c21b92b1a143ce5ceb068c4d8..bcc498bd6e2a00bd8fd9921d771a658c8c53c261 100644 (file)
@@ -245,6 +245,11 @@ lookup_confhost(struct ConfItem *aconf)
            aconf->host, aconf->name));
     return;
   }
+  if (aconf->origin_name
+      && !ircd_aton(&aconf->origin.addr, aconf->origin_name)) {
+    Debug((DEBUG_ERROR, "Origin name error: (%s) (%s)",
+        aconf->origin_name, aconf->name));
+  }
   /*
    * Do name lookup now on hostnames given and store the
    * ip numbers in conf structure.