Committer  : entrope
CVSROOT    : /cvsroot/undernet-ircu
Module     : ircu2.10
Commit time: 2007-02-25 16:12:55 UTC

Modified files:
     ChangeLog doc/example.conf include/res.h include/s_bsd.h
     ircd/ircd_lexer.l ircd/ircd_parser.y ircd/ircd_res.c
     ircd/ircd_reslib.c ircd/s_conf.c

Log message:

Allow specification of DNS vhost and server in ircd.conf. 
Change the default DNS vhost from the global vhost to unspecified. 

---------------------- diff included ----------------------
Index: ircu2.10/ChangeLog
diff -u ircu2.10/ChangeLog:1.835 ircu2.10/ChangeLog:1.836
--- ircu2.10/ChangeLog:1.835    Sun Feb 25 07:48:12 2007
+++ ircu2.10/ChangeLog  Sun Feb 25 08:12:45 2007
@@ -1,3 +1,35 @@
+2007-02-25  Michael Poole <[EMAIL PROTECTED]>
+
+       * doc/example.conf: Document new options for General block.
+       
+       * include/res.h (clear_nameservers): Declare new function.
+       (add_nameserver): Declare previously static function.
+
+       * include/s_bsd.h (VirtualHost_dns_v4): Declare.
+       (VirtualHost_dns_v6): Likewise.
+
+       * ircd/ircd_lexer.l (DNS): Recognize new token.
+
+       * ircd/ircd_parser.y (DNS): Declare new token.
+       (generalitem): Allow new items for dns vhost(s) and dns servers.
+       (generaldnsvhost): New production.
+       (generaldnsserver): New production.
+
+       * ircd/ircd_res.c (VirtualHost_dns_v4): New variable.
+       (VirtualHost_dns_v6): Likewise.
+       (clear_nameservers): New function.
+       (restart_resolver): Scan specified servers so we only try to open
+       DNS client sockets that we need.
+
+       * ircd/ircd_reslib.c (irc_nscount): Remove redundant initializer.
+       (irc_res_init): Only read the resolver config file if there are no
+       nameservers provided.
+       (add_nameserver): Make non-static.  Remove off-by-one check
+       against IRCD_MAXNS.
+
+       * ircd/s_conf.c (read_configuration_file): Clear nameserver list
+       before reading the config file.
+
 2007-01-27  Jeannot Langlois <[EMAIL PROTECTED]>
 
        * doc/example.conf (Features): Illustrate URLREG feature.
Index: ircu2.10/doc/example.conf
diff -u ircu2.10/doc/example.conf:1.78 ircu2.10/doc/example.conf:1.79
--- ircu2.10/doc/example.conf:1.78      Sun Feb 25 07:48:12 2007
+++ ircu2.10/doc/example.conf   Sun Feb 25 08:12:45 2007
@@ -56,6 +56,10 @@
 #         vhost = "ipv6vhost";
 #         description = "description";
 #         numeric = numericnumber;
+#         dns vhost = "ipv4vhost";
+#         dns vhost = "ipv6vhost";
+#         dns server = "ipaddress";
+#         dns server = "ipaddress2";
 # };
 #
 # If present, <virtual host> must contain a valid address in dotted
@@ -71,6 +75,15 @@
 #
 # Note that <server numeric> has to be unique on the network your server
 # is running on, must be between 0 and 4095, and is not updated on a rehash.
+#
+# The two DNS lines allow you to specify the local IP address to use
+# for DNS lookups ("dns vhost") and one or more DNS server addresses
+# to use.  If the vhost is ambiguous for some reason, you may list
+# IPV4 and/or IPV6 between the equals sign and the address string.
+# The default DNS vhost is to let the operating system assign the
+# address, and the default DNS servers are read from /etc/resolv.conf.
+# In most cases, you do not need to specify either the dns vhost or
+# the dns server.
 General {
          name = "London.UK.Eu.UnderNet.org";
          description = "University of London, England";
Index: ircu2.10/include/res.h
diff -u ircu2.10/include/res.h:1.19 ircu2.10/include/res.h:1.20
--- ircu2.10/include/res.h:1.19 Thu Apr  6 20:27:51 2006
+++ ircu2.10/include/res.h      Sun Feb 25 08:12:45 2007
@@ -1,6 +1,6 @@
 /** @file
  * @brief IRC resolver API.
- * @version $Id: res.h,v 1.19 2006/04/07 03:27:51 entrope Exp $
+ * @version $Id: res.h,v 1.20 2007/02/25 16:12:45 entrope Exp $
  */
 
 #ifndef INCLUDED_res_h
@@ -109,6 +109,8 @@
 } HEADER;
 
 extern void restart_resolver(void);
+extern void clear_nameservers(void);
+extern void add_nameserver(const char *ipaddr);
 extern size_t cres_mem(struct Client* cptr);
 extern void delete_resolver_queries(const void *vptr);
 extern void report_dns_servers(struct Client *source_p, const struct StatDesc 
*sd, char *param);
Index: ircu2.10/include/s_bsd.h
diff -u ircu2.10/include/s_bsd.h:1.23 ircu2.10/include/s_bsd.h:1.24
--- ircu2.10/include/s_bsd.h:1.23       Fri Jan  6 16:40:14 2006
+++ ircu2.10/include/s_bsd.h    Sun Feb 25 08:12:45 2007
@@ -1,6 +1,6 @@
 /** @file s_bsd.h
  * @brief Wrapper functions to avoid direct use of BSD APIs.
- * @version $Id: s_bsd.h,v 1.23 2006/01/07 00:40:14 entrope Exp $
+ * @version $Id: s_bsd.h,v 1.24 2007/02/25 16:12:45 entrope Exp $
  */
 #ifndef INCLUDED_s_bsd_h
 #define INCLUDED_s_bsd_h
@@ -47,6 +47,8 @@
 extern struct Client**     LocalClientArray;
 extern struct irc_sockaddr VirtualHost_v4;
 extern struct irc_sockaddr VirtualHost_v6;
+extern struct irc_sockaddr VirtualHost_dns_v4;
+extern struct irc_sockaddr VirtualHost_dns_v6;
 
 /*
  * Proto types
Index: ircu2.10/ircd/ircd_lexer.l
diff -u ircu2.10/ircd/ircd_lexer.l:1.30 ircu2.10/ircd/ircd_lexer.l:1.31
--- ircu2.10/ircd/ircd_lexer.l:1.30     Thu Dec  7 17:56:23 2006
+++ ircu2.10/ircd/ircd_lexer.l  Sun Feb 25 08:12:45 2007
@@ -17,7 +17,7 @@
  *  along with this program; if not, write to the Free Software
  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
  *  USA.
- * $Id: ircd_lexer.l,v 1.30 2006/12/08 01:56:23 entrope Exp $
+ * $Id: ircd_lexer.l,v 1.31 2007/02/25 16:12:45 entrope Exp $
  */
 
 %option never-interactive case-insensitive warn nodefault nounput yylineno
@@ -99,6 +99,7 @@
 DIRECTCON       return DIRECTCON;
 DIRECTOP        return DIRECTOP;
 DISPLAY                return TPRIV_DISPLAY;
+DNS             return DNS;
 FAST           return FAST;
 FEATURES       return FEATURES;
 FILE           return TFILE;
Index: ircu2.10/ircd/ircd_parser.y
diff -u ircu2.10/ircd/ircd_parser.y:1.71 ircu2.10/ircd/ircd_parser.y:1.72
--- ircu2.10/ircd/ircd_parser.y:1.71    Thu Dec  7 17:39:22 2006
+++ ircu2.10/ircd/ircd_parser.y Sun Feb 25 08:12:45 2007
@@ -17,7 +17,7 @@
  *  along with this program; if not, write to the Free Software
  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
  *  USA.
- * $Id: ircd_parser.y,v 1.71 2006/12/08 01:39:22 entrope Exp $
+ * $Id: ircd_parser.y,v 1.72 2007/02/25 16:12:45 entrope Exp $
  */
 %{
 
@@ -209,6 +209,7 @@
 %token AUTOCONNECT
 %token PROGRAM
 %token TOK_IPV4 TOK_IPV6
+%token DNS
 %token INCLUDE
 %token LINESYNC
 %token FROM
@@ -351,7 +352,9 @@
     parse_error("Your General block must contain a numeric (between 1 and 
4095).");
 };
 generalitems: generalitem generalitems | generalitem;
-generalitem: generalnumeric | generalname | generalvhost | generaldesc;
+generalitem: generalnumeric | generalname | generalvhost | generaldesc
+  | generaldnsvhost | generaldnsserver;
+
 generalnumeric: NUMERIC '=' NUMBER ';'
 {
   if (!permitted(BLOCK_GENERAL, 0))
@@ -409,6 +412,36 @@
   MyFree(vhost);
 };
 
+generaldnsvhost: DNS VHOST '=' address_family QSTRING ';'
+{
+  struct irc_in_addr addr;
+  int families = $4;
+  char *vhost = $5;
+
+  if (!strcmp(vhost, "*")) {
+    /* Let the operating system assign the default. */
+  } else if (!ircd_aton(&addr, vhost))
+    parse_error("Invalid DNS virtual host '%s'.", vhost);
+  else
+  {
+    if ((families & USE_IPV4)
+        || (!families && irc_in_addr_is_ipv4(&addr)))
+      memcpy(&VirtualHost_dns_v4.addr, &addr, sizeof(addr));
+    if ((families & USE_IPV6)
+        || (!families && !irc_in_addr_is_ipv4(&addr)))
+      memcpy(&VirtualHost_dns_v6.addr, &addr, sizeof(addr));
+  }
+  MyFree(vhost);
+};
+
+generaldnsserver: DNS SERVER '=' QSTRING ';'
+{
+  char *server = $4;
+
+  add_nameserver(server);
+  MyFree(server);
+};
+
 adminblock: ADMIN
 {
   if (permitted(BLOCK_ADMIN, 1))
Index: ircu2.10/ircd/ircd_res.c
diff -u ircu2.10/ircd/ircd_res.c:1.29 ircu2.10/ircd/ircd_res.c:1.30
--- ircu2.10/ircd/ircd_res.c:1.29       Fri Jul 14 17:09:10 2006
+++ ircu2.10/ircd/ircd_res.c    Sun Feb 25 08:12:45 2007
@@ -18,7 +18,7 @@
  */
 /** @file
  * @brief IRC resolver functions.
- * @version $Id: ircd_res.c,v 1.29 2006/07/15 00:09:10 entrope Exp $
+ * @version $Id: ircd_res.c,v 1.30 2007/02/25 16:12:45 entrope Exp $
  */
 
 #include "client.h"
@@ -55,6 +55,10 @@
 static struct Socket res_socket_v6;
 /** Next DNS lookup timeout. */
 static struct Timer res_timeout;
+/** Local address for IPv4 DNS lookups. */
+struct irc_sockaddr VirtualHost_dns_v4;
+/** Local address for IPv6 DNS lookups. */
+struct irc_sockaddr VirtualHost_dns_v6;
 /** Check for whether the resolver has been initialized yet. */
 #define resolver_started() (request_list.next != NULL)
 
@@ -141,6 +145,16 @@
 extern int irc_nscount;
 extern char irc_domain[HOSTLEN];
 
+/** Prepare the resolver library to (optionally) accept a list of
+ * DNS servers through add_dns_server().
+ */
+void clear_nameservers(void)
+{
+  irc_nscount = 0;
+  memset(&VirtualHost_dns_v4, 0, sizeof(VirtualHost_dns_v4));
+  memset(&VirtualHost_dns_v6, 0, sizeof(VirtualHost_dns_v6));
+}
+
 /** Check whether \a inp is a nameserver we use.
  * @param[in] inp Nameserver address.
  * @return Non-zero if we trust \a inp; zero if not.
@@ -165,23 +179,38 @@
 void
 restart_resolver(void)
 {
+  int need_v4;
+  int need_v6;
+  int ns;
+
   irc_res_init();
 
   if (!request_list.next)
     request_list.next = request_list.prev = &request_list;
 
-  if (!s_active(&res_socket_v4))
+  /* Check which address family (or families) our nameservers use. */
+  for (need_v4 = need_v6 = ns = 0; ns < irc_nscount; ns++)
+  {
+    if (irc_in_addr_is_ipv4(&irc_nsaddr_list[ns].addr))
+      need_v4 = 1;
+    else
+      need_v6 = 1;
+  }
+
+  /* If we need an IPv4 socket, and don't have one, open it. */
+  if (need_v4 && !s_active(&res_socket_v4))
   {
-    int fd = os_socket(&VirtualHost_v4, SOCK_DGRAM, "Resolver UDPv4 socket", 
AF_INET);
+    int fd = os_socket(&VirtualHost_dns_v4, SOCK_DGRAM, "Resolver UDPv4 
socket", AF_INET);
     if (fd >= 0)
       socket_add(&res_socket_v4, res_readreply, NULL,
                  SS_DATAGRAM, SOCK_EVENT_READABLE, fd);
   }
 
 #ifdef AF_INET6
-  if (!s_active(&res_socket_v6))
+  /* If we need an IPv6 socket, and don't have one, open it. */
+  if (need_v6 && !s_active(&res_socket_v6))
   {
-    int fd = os_socket(&VirtualHost_v6, SOCK_DGRAM, "Resolver UDPv6 socket", 
AF_INET6);
+    int fd = os_socket(&VirtualHost_dns_v6, SOCK_DGRAM, "Resolver UDPv6 
socket", AF_INET6);
     if (fd >= 0)
       socket_add(&res_socket_v6, res_readreply, NULL,
                  SS_DATAGRAM, SOCK_EVENT_READABLE, fd);
Index: ircu2.10/ircd/ircd_reslib.c
diff -u ircu2.10/ircd/ircd_reslib.c:1.7 ircu2.10/ircd/ircd_reslib.c:1.8
--- ircu2.10/ircd/ircd_reslib.c:1.7     Sun Jul 23 17:29:17 2006
+++ ircu2.10/ircd/ircd_reslib.c Sun Feb 25 08:12:45 2007
@@ -99,13 +99,13 @@
 
 /** @file
  * @brief DNS resolver library functions.
- * @version $Id: ircd_reslib.c,v 1.7 2006/07/24 00:29:17 entrope Exp $
+ * @version $Id: ircd_reslib.c,v 1.8 2007/02/25 16:12:45 entrope Exp $
  */
 
 /** Array of nameserver addresses. */
 struct irc_sockaddr irc_nsaddr_list[IRCD_MAXNS];
 /** Number of nameservers in #irc_nsaddr_list. */
-int irc_nscount = 0;
+int irc_nscount;
 /** Local domain to use as a search suffix. */
 char irc_domain[HOSTLEN + 1];
 
@@ -130,7 +130,6 @@
 };
 
 static int parse_resvconf(void);
-static void add_nameserver(char *arg);
 
 /** Array of decimal digits, indexed by value. */
 static const char digits[] = "0123456789";
@@ -152,8 +151,7 @@
 int
 irc_res_init(void)
 {
-  irc_nscount = 0;
-  return(parse_resvconf());
+  return (irc_nscount == 0) ? parse_resvconf() : 0;
 }
 
 /** Read resolver configuration file for domain and nameserver lines.
@@ -223,13 +221,13 @@
 /** Add a resolver to #irc_nsaddr_list.
  * @param[in] arg Dotted quad or IPv6 text form of nameserver address.
  */
-static void
-add_nameserver(char *arg)
+void
+add_nameserver(const char *arg)
 {
   struct irc_sockaddr res;
 
   /* Done max number of nameservers? */
-  if ((irc_nscount + 1) >= IRCD_MAXNS)
+  if (irc_nscount >= IRCD_MAXNS)
     return;
 
   /* Failure converting from numeric string? */
Index: ircu2.10/ircd/s_conf.c
diff -u ircu2.10/ircd/s_conf.c:1.94 ircu2.10/ircd/s_conf.c:1.95
--- ircu2.10/ircd/s_conf.c:1.94 Wed Jul 26 18:06:46 2006
+++ ircu2.10/ircd/s_conf.c      Sun Feb 25 08:12:45 2007
@@ -19,7 +19,7 @@
  */
 /** @file
  * @brief ircd configuration file driver
- * @version $Id: s_conf.c,v 1.94 2006/07/27 01:06:46 entrope Exp $
+ * @version $Id: s_conf.c,v 1.95 2007/02/25 16:12:45 entrope Exp $
  */
 #include "config.h"
 
@@ -833,6 +833,7 @@
 {
   conf_error = 0;
   feature_unmark(); /* unmark all features for resetting later */
+  clear_nameservers(); /* clear previous list of DNS servers */
   if (!init_lexer(configfile))
     return 0;
   yyparse();
----------------------- End of diff -----------------------
_______________________________________________
Patches mailing list
[email protected]
http://undernet.sbg.org/mailman/listinfo/patches

Reply via email to