Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/netbsd-1-5]: src/dist/bind/bin/named Pull up revision 1.8 (requested by ...



details:   https://anonhg.NetBSD.org/src/rev/38d9b20e01f2
branches:  netbsd-1-5
changeset: 490563:38d9b20e01f2
user:      he <he%NetBSD.org@localhost>
date:      Sun Jan 28 15:52:57 2001 +0000

description:
Pull up revision 1.8 (requested by itojun):
  Upgrade to BIND version 8.2.3.

diffstat:

 dist/bind/bin/named/ns_main.c |  315 ++++++++++++++++++++++++++++++-----------
 1 files changed, 230 insertions(+), 85 deletions(-)

diffs (truncated from 573 to 300 lines):

diff -r b978e70dc500 -r 38d9b20e01f2 dist/bind/bin/named/ns_main.c
--- a/dist/bind/bin/named/ns_main.c     Sun Jan 28 15:52:53 2001 +0000
+++ b/dist/bind/bin/named/ns_main.c     Sun Jan 28 15:52:57 2001 +0000
@@ -1,8 +1,8 @@
-/*     $NetBSD: ns_main.c,v 1.5.4.2 2000/11/13 22:00:08 tv Exp $       */
+/*     $NetBSD: ns_main.c,v 1.5.4.3 2001/01/28 15:52:57 he Exp $       */
 
 #if !defined(lint) && !defined(SABER)
 static const char sccsid[] = "@(#)ns_main.c    4.55 (Berkeley) 7/1/91";
-static const char rcsid[] = "Id: ns_main.c,v 8.118 1999/11/16 05:32:18 vixie Exp";
+static const char rcsid[] = "Id: ns_main.c,v 8.142 2001/01/15 20:06:25 vixie Exp";
 #endif /* not lint */
 
 /*
@@ -59,7 +59,7 @@
  */
 
 /*
- * Portions Copyright (c) 1996-1999 by Internet Software Consortium.
+ * Portions Copyright (c) 1996-2000 by Internet Software Consortium.
  *
  * Permission to use, copy, modify, and distribute this software for any
  * purpose with or without fee is hereby granted, provided that the above
@@ -114,6 +114,7 @@
 #include <errno.h>
 #include <fcntl.h>
 #include <grp.h>
+#include <irs.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <signal.h>
@@ -140,6 +141,17 @@
 #include "named.h"
 #undef MAIN_PROGRAM
 
+typedef void (*handler)(void);
+
+typedef struct _savedg {
+       struct sockaddr_in from;
+       int             dfd;
+       interface *     ifp;
+       time_t          gen;
+       u_char *        buf;
+       u_int16_t       buflen;
+} savedg;
+
                                /* list of interfaces */
 static LIST(struct _interface) iflist;
 static int                     iflist_initialized = 0;
@@ -148,7 +160,11 @@
 static const int               drbufsize = 32 * 1024,  /* UDP rcv buf size */
                                dsbufsize = 48 * 1024,  /* UDP snd buf size */
                                sbufsize = 16 * 1024,   /* TCP snd buf size */ 
+#ifdef BROKEN_RECVFROM
+                               nudptrans = 1,
+#else
                                nudptrans = 20,         /* #/udps per select */
+#endif
                                listenmax = 50;
 
 static u_int16_t               nsid_state;
@@ -160,9 +176,13 @@
 static u_int16_t               nsid_state2;
 static int                     nsid_algorithm;
 
-typedef void (*handler)(void);
-static int                     needs = 0;
+static int                     needs = 0, needs_exit = 0;
 static handler                 handlers[main_need_num];
+static void                    savedg_waitfunc(evContext, void*, const void*);
+static void                    need_waitfunc(evContext, void *, const void *);
+static int                     drain_rcvbuf(evContext, interface *, int,
+                                            int *, int *);
+static int                     drain_all_rcvbuf(evContext);
 
 static struct qstream          *sq_add(void);
 static int                     opensocket_d(interface *),
@@ -175,8 +195,6 @@
 
 static interface *             if_find(struct in_addr, u_int16_t port);
 
-static int                     sq_here(struct qstream *);
-
 static void                    deallocate_everything(void),
                                stream_accept(evContext, void *, int,
                                              const void *, int,
@@ -194,7 +212,8 @@
 static int                     only_digits(const char *);
 
 static void                    init_needs(void),
-                               handle_need(void);
+                               handle_needs(void),
+                               exit_handler(void);
 
 #ifndef HAVE_CUSTOM
 static void                    custom_init(void),
@@ -320,8 +339,8 @@
                        break;
 
                case 'v':
-                       fprintf(stderr, "%s\n", Version);
-                       exit(1);
+                       fprintf(stdout, "%s\n", Version);
+                       exit(0);
 
 #ifdef CAN_CHANGE_ID
                case 'u':
@@ -442,7 +461,7 @@
 #ifdef SYSLOG_42BSD
        openlog("named", n);
 #else
-       openlog("named", n, LOG_DAEMON);
+       openlog("named", n, ISC_FACILITY);
 #endif
 
        init_logging();
@@ -458,7 +477,7 @@
        init_needs();
        init_signals();
 
-       ns_notice(ns_log_default, "starting.  %s", Version);
+       ns_notice(ns_log_default, "starting (%s).  %s", conffile, Version);
 
        /*
         * Initialize and load database.
@@ -466,7 +485,7 @@
        gettime(&tt);
        buildservicelist();
        buildprotolist();
-       ns_init(conffile);
+       confmtime = ns_init(conffile);
        time(&boottime);
        resettime = boottime;
 
@@ -523,21 +542,16 @@
        ns_notice(ns_log_default, "Ready to answer queries.");
        gettime(&tt);
        prime_cache();
-       while (!main_needs_exit) {
+       while (!needs_exit) {
                evEvent event;
 
                ns_debug(ns_log_default, 15, "main loop");
-               if (needs != 0) {
-                       /* Drain outstanding events; handlers ~block~. */
-                       while (evGetNext(ev, &event, EV_POLL) != -1)
-                               INSIST_ERR(evDispatch(ev, event) != -1);
-                       INSIST_ERR(errno == EINTR || errno == EWOULDBLOCK);
-                       handle_need();
-               } else if (evGetNext(ev, &event, EV_WAIT) != -1) {
+               if (needs != 0)
+                       handle_needs();
+               else if (evGetNext(ev, &event, EV_WAIT) != -1)
                        INSIST_ERR(evDispatch(ev, event) != -1);
-               } else {
+               else
                        INSIST_ERR(errno == EINTR);
-               }
        }
        ns_info(ns_log_default, "named shutting down");
 #ifdef BIND_UPDATE
@@ -732,17 +746,14 @@
        INSIST_ERR(evRead(lev, rfd, &iov, 1, stream_getlen, sp, &sp->evID_r)
                   != -1);
        sp->flags |= STREAM_READ_EV;
-#ifdef DEBUG
-       if (debug)
-               ns_info(ns_log_default, "IP/TCP connection from %s (fd %d)",
-                       sin_ntoa(sp->s_from), rfd);
-#endif
+       ns_debug(ns_log_default, 1, "IP/TCP connection from %s (fd %d)",
+                sin_ntoa(sp->s_from), rfd);
 }
 
 int
 tcp_send(struct qinfo *qp) {
        struct qstream *sp;
-       int on = 1;
+       int on = 1, n;
        
        ns_debug(ns_log_default, 1, "tcp_send");
        if ((sp = sq_add()) == NULL) {
@@ -756,10 +767,34 @@
                sq_remove(sp);
                return (SERVFAIL);
        }
+       if (setsockopt(sp->s_rfd, SOL_SOCKET, SO_REUSEADDR,
+                      (char*)&on, sizeof(on)) < 0)
+               ns_info(ns_log_default,
+                       "tcp_send: setsockopt(SO_REUSEADDR): %s",
+                       strerror(errno));
+#ifdef SO_REUSEPORT
+       if (setsockopt(sp->s_rfd, SOL_SOCKET, SO_REUSEPORT,
+                      (char*)&on, sizeof(on)) < 0)
+               ns_info(ns_log_default,
+                       "tcp_send: setsockopt(SO_REUSEPORT): %s",
+                       strerror(errno));
+#endif
+       if (bind(sp->s_rfd, (struct sockaddr *)&server_options->query_source,
+                sizeof server_options->query_source) < 0)
+               ns_info(ns_log_default, "tcp_send: bind(query_source): %s",
+                       strerror(errno));
        if (fcntl(sp->s_rfd, F_SETFD, 1) < 0) {
                sq_remove(sp);
                return (SERVFAIL);
        }
+       if ((n = fcntl(sp->s_rfd, F_GETFL, 0)) == -1) {
+               sq_remove(sp);
+               return (SERVFAIL);
+       }
+       if (fcntl(sp->s_rfd, F_SETFL, n|PORT_NONBLOCK) == -1) {
+               sq_remove(sp);
+               return (SERVFAIL);
+       }
        if (sq_openw(sp, qp->q_msglen + INT16SZ) == -1) {
                sq_remove(sp);
                return (SERVFAIL);
@@ -770,10 +805,10 @@
        }
 
        if (setsockopt(sp->s_rfd, SOL_SOCKET, SO_KEEPALIVE,
-               (char*)&on, sizeof(on)) < 0)
-                       ns_info(ns_log_default,
-                               "tcp_send: setsockopt(rfd, SO_KEEPALIVE): %s",
-                               strerror(errno));
+                      (char*)&on, sizeof(on)) < 0)
+               ns_info(ns_log_default,
+                       "tcp_send: setsockopt(SO_KEEPALIVE): %s",
+                       strerror(errno));
        gettime(&tt);
        sp->s_size = -1;
        sp->s_time = tt.tv_sec; /* last transaction time */
@@ -791,7 +826,7 @@
 
 static void
 stream_send(evContext lev, void *uap, int fd, const void *la, int lalen,
-                               const void *ra, int ralen) {
+           const void *ra, int ralen) {
        struct qstream *sp = uap;
 
        ns_debug(ns_log_default, 1, "stream_send");
@@ -896,7 +931,8 @@
                }
        }
 
-       iov = evConsIovec(sp->s_buf, sp->s_size);
+       iov = evConsIovec(sp->s_buf, (sp->s_size <= sp->s_bufsize) ?
+                                    sp->s_size : sp->s_bufsize);
        if (evRead(lev, sp->s_rfd, &iov, 1, stream_getmsg, sp, &sp->evID_r)
            == -1)
                ns_panic(ns_log_default, 1, "evRead(fd %d): %s",
@@ -1024,6 +1060,21 @@
 }
 
 static void
+savedg_waitfunc(evContext ctx, void *uap, const void *tag) {
+       savedg *dg = (savedg *)uap;
+
+       if (!EMPTY(iflist) && HEAD(iflist)->gen == dg->gen) {
+               u_char buf[PACKETSZ];
+
+               memcpy(buf, dg->buf, dg->buflen);
+               dispatch_message(buf, dg->buflen, sizeof buf, NULL,
+                                dg->from, dg->dfd, dg->ifp);
+       }
+       memput(dg->buf, dg->buflen);
+       memput(dg, sizeof *dg);
+}
+
+static void
 dispatch_message(u_char *msg, int msglen, int buflen, struct qstream *qsp,
                 struct sockaddr_in from, int dfd, interface *ifp)
 {
@@ -1133,13 +1184,13 @@
                ifc.ifc_len = bufsiz;
                ifc.ifc_buf = buf;
 #ifdef IRIX_EMUL_IOCTL_SIOCGIFCONF
-              /*
-               * This is a fix for IRIX OS in which the call to ioctl with
-               * the flag SIOCGIFCONF may not return an entry for all the
-               * interfaces like most flavors of Unix.
-               */
-              if (emul_ioctl(&ifc) >= 0)
-                      break;
+               /*
+                * This is a fix for IRIX OS in which the call to ioctl with
+                * the flag SIOCGIFCONF may not return an entry for all the
+                * interfaces like most flavors of Unix.
+                */
+               if (emul_ioctl(&ifc) >= 0)
+                       break;
 #else
                if ((n = ioctl(s, SIOCGIFCONF, (char *)&ifc)) != -1) {
                        /*
@@ -1253,6 +1304,7 @@
                                        ns_panic(ns_log_default, 1,
                                                 "memget(interface)");
                                memset(ifp, 0, sizeof *ifp);
+                               INIT_LINK(ifp, link);
                                APPEND(iflist, ifp, link);



Home | Main Index | Thread Index | Old Index