Source-Changes-HG archive

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

[src/trunk]: src/usr.sbin/rtadvd Change the meaning of the 'D' flag to print ...



details:   https://anonhg.NetBSD.org/src/rev/55a345c6216d
branches:  trunk
changeset: 827638:55a345c6216d
user:      christos <christos%NetBSD.org@localhost>
date:      Mon Nov 06 15:15:04 2017 +0000

description:
Change the meaning of the 'D' flag to print errors to stderr instead of
syslog(3) and exit if poll(2) fails (intended to be used with unit-tests).

diffstat:

 usr.sbin/rtadvd/advcap.c |    6 +-
 usr.sbin/rtadvd/config.c |  121 +++++++++++-----------
 usr.sbin/rtadvd/dump.c   |    7 +-
 usr.sbin/rtadvd/if.c     |   11 +-
 usr.sbin/rtadvd/logit.h  |    2 +
 usr.sbin/rtadvd/rrenum.c |   41 +++---
 usr.sbin/rtadvd/rtadvd.8 |   15 +-
 usr.sbin/rtadvd/rtadvd.c |  249 +++++++++++++++++++++++++++-------------------
 usr.sbin/rtadvd/timer.c  |    9 +-
 9 files changed, 260 insertions(+), 201 deletions(-)

diffs (truncated from 1820 to 300 lines):

diff -r 04011a657319 -r 55a345c6216d usr.sbin/rtadvd/advcap.c
--- a/usr.sbin/rtadvd/advcap.c  Mon Nov 06 14:26:03 2017 +0000
+++ b/usr.sbin/rtadvd/advcap.c  Mon Nov 06 15:15:04 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: advcap.c,v 1.16 2015/11/11 07:48:41 ozaki-r Exp $      */
+/*     $NetBSD: advcap.c,v 1.17 2017/11/06 15:15:04 christos Exp $     */
 /*     $KAME: advcap.c,v 1.11 2003/05/19 09:46:50 keiichi Exp $        */
 
 /*
@@ -48,6 +48,8 @@
 #include "pathnames.h"
 #include "prog_ops.h"
 
+#include "logit.h"
+
 #ifndef __UNCONST
 #define __UNCONST(a)           ((void *)(unsigned long)(const void *)(a))
 #endif
@@ -137,7 +139,7 @@
                tf = open(RM = cp, O_RDONLY);
        }
        if (tf < 0) {
-               syslog(LOG_INFO, "<%s> open: %m", __func__);
+               logit(LOG_INFO, "<%s> open: %m", __func__);
                return (-2);
        }
        for (;;) {
diff -r 04011a657319 -r 55a345c6216d usr.sbin/rtadvd/config.c
--- a/usr.sbin/rtadvd/config.c  Mon Nov 06 14:26:03 2017 +0000
+++ b/usr.sbin/rtadvd/config.c  Mon Nov 06 15:15:04 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: config.c,v 1.36 2017/02/27 05:41:36 ozaki-r Exp $      */
+/*     $NetBSD: config.c,v 1.37 2017/11/06 15:15:04 christos Exp $     */
 /*     $KAME: config.c,v 1.93 2005/10/17 14:40:02 suz Exp $    */
 
 /*
@@ -67,6 +67,7 @@
 #include "timer.h"
 #include "if.h"
 #include "config.h"
+#include "logit.h"
 #include "prog_ops.h"
 
 #ifndef __arraycount
@@ -180,24 +181,24 @@
        do {                                                            \
                p = calloc(1, sizeof(*p));                              \
                if (p == NULL) {                                        \
-                       syslog(LOG_ERR, "<%s> calloc failed: %m",       \
+                       logit(LOG_ERR, "<%s> calloc failed: %m",        \
                            __func__);                                  \
                        goto errexit;                                   \
                }                                                       \
        } while(/*CONSTCOND*/0)
 
        if (if_nametoindex(intface) == 0) {
-               syslog(LOG_INFO, "<%s> interface %s not found, ignoring",
+               logit(LOG_INFO, "<%s> interface %s not found, ignoring",
                       __func__, intface);
                return;
        }
 
-       syslog(LOG_DEBUG, "<%s> loading configuration for interface %s",
+       logit(LOG_DEBUG, "<%s> loading configuration for interface %s",
               __func__, intface);
 
        if ((stat = agetent(tbuf, intface)) <= 0) {
                memset(tbuf, 0, sizeof(tbuf));
-               syslog(LOG_INFO,
+               logit(LOG_INFO,
                       "<%s> %s isn't defined in the configuration file"
                       " or the configuration file doesn't exist."
                       " Treat it as default",
@@ -223,7 +224,7 @@
                tmp->advlinkopt = 1;
        if (tmp->advlinkopt) {
                if ((tmp->sdl = if_nametosdl(intface)) == NULL) {
-                       syslog(LOG_ERR,
+                       logit(LOG_ERR,
                               "<%s> can't get information of %s",
                               __func__, intface);
                        goto errexit;
@@ -232,7 +233,7 @@
        } else {
                tmp->ifindex = if_nametoindex(intface);
                if (tmp->ifindex == 0) {
-                       syslog(LOG_ERR,
+                       logit(LOG_ERR,
                               "<%s> can't get information of %s",
                               __func__, intface);
                        goto errexit;
@@ -242,7 +243,7 @@
        strlcpy(tmp->ifname, intface, sizeof(tmp->ifname));
        if ((tmp->phymtu = if_getmtu(intface)) == 0) {
                tmp->phymtu = IPV6_MMTU;
-               syslog(LOG_WARNING,
+               logit(LOG_WARNING,
                       "<%s> can't get interface mtu of %s. Treat as %d",
                       __func__, intface, IPV6_MMTU);
        }
@@ -252,7 +253,7 @@
         */
        MAYHAVE(val, "maxinterval", DEF_MAXRTRADVINTERVAL);
        if (val < MIN_MAXINTERVAL || val > MAX_MAXINTERVAL) {
-               syslog(LOG_ERR,
+               logit(LOG_ERR,
                       "<%s> maxinterval (%d) on %s is invalid "
                       "(must be between %u and %u)", __func__, val,
                       intface, MIN_MAXINTERVAL, MAX_MAXINTERVAL);
@@ -261,7 +262,7 @@
        tmp->maxinterval = val;
        MAYHAVE(val, "mininterval", tmp->maxinterval/3);
        if (val < MIN_MININTERVAL || val > (tmp->maxinterval * 3) / 4) {
-               syslog(LOG_ERR,
+               logit(LOG_ERR,
                       "<%s> mininterval (%d) on %s is invalid "
                       "(must be between %u and %d)",
                       __func__, val, intface, MIN_MININTERVAL,
@@ -283,7 +284,7 @@
                        val |= ND_RA_FLAG_RTPREF_HIGH;
                if (strchr(flagstr, 'l')) {
                        if ((val & ND_RA_FLAG_RTPREF_HIGH)) {
-                               syslog(LOG_ERR, "<%s> the \'h\' and \'l\'"
+                               logit(LOG_ERR, "<%s> the \'h\' and \'l\'"
                                    " router flags are exclusive", __func__);
                                goto errexit;
                        }
@@ -300,14 +301,14 @@
 #endif
        tmp->rtpref = val & ND_RA_FLAG_RTPREF_MASK;
        if (tmp->rtpref == ND_RA_FLAG_RTPREF_RSV) {
-               syslog(LOG_ERR, "<%s> invalid router preference (%02x) on %s",
+               logit(LOG_ERR, "<%s> invalid router preference (%02x) on %s",
                       __func__, tmp->rtpref, intface);
                goto errexit;
        }
 
        MAYHAVE(val, "rltime", DEF_ADVROUTERLIFETIME);
        if (val && (val < tmp->maxinterval || val > MAXROUTERLIFETIME)) {
-               syslog(LOG_ERR,
+               logit(LOG_ERR,
                       "<%s> router lifetime (%d) on %s is invalid "
                       "(must be 0 or between %d and %d)",
                       __func__, val, intface,
@@ -323,7 +324,7 @@
         * explicitly set zero. (see also the above section)
         */
        if (val && forwarding == 0) {
-               syslog(LOG_ERR,
+               logit(LOG_ERR,
                       "<%s> non zero router lifetime is specified for %s, "
                       "which must not be allowed for hosts.  you must "
                       "change router lifetime or enable IPv6 forwarding.",
@@ -334,7 +335,7 @@
 
        MAYHAVE(val, "rtime", DEF_ADVREACHABLETIME);
        if (val < 0 || val > MAXREACHABLETIME) {
-               syslog(LOG_ERR,
+               logit(LOG_ERR,
                       "<%s> reachable time (%d) on %s is invalid "
                       "(must be no greater than %d)",
                       __func__, val, intface, MAXREACHABLETIME);
@@ -344,14 +345,14 @@
 
        MAYHAVE(val64, "retrans", DEF_ADVRETRANSTIMER);
        if (val64 < 0 || val64 > 0xffffffff) {
-               syslog(LOG_ERR, "<%s> retrans time (%lld) on %s out of range",
+               logit(LOG_ERR, "<%s> retrans time (%lld) on %s out of range",
                       __func__, (long long)val64, intface);
                goto errexit;
        }
        tmp->retranstimer = (uint32_t)val64;
 
        if (agetnum("hapref") != -1 || agetnum("hatime") != -1) {
-               syslog(LOG_ERR,
+               logit(LOG_ERR,
                       "<%s> mobile-ip6 configuration not supported",
                       __func__);
                goto errexit;
@@ -377,7 +378,7 @@
 
                /* allocate memory to store prefix information */
                if ((pfx = calloc(1, sizeof(*pfx))) == NULL) {
-                       syslog(LOG_ERR,
+                       logit(LOG_ERR,
                               "<%s> can't allocate memory: %m",
                               __func__);
                        goto errexit;
@@ -390,20 +391,20 @@
                pfx->origin = PREFIX_FROM_CONFIG;
 
                if (inet_pton(AF_INET6, addr, &pfx->prefix) != 1) {
-                       syslog(LOG_ERR,
+                       logit(LOG_ERR,
                               "<%s> inet_pton failed for %s",
                               __func__, addr);
                        goto errexit;
                }
                if (IN6_IS_ADDR_MULTICAST(&pfx->prefix)) {
-                       syslog(LOG_ERR,
+                       logit(LOG_ERR,
                               "<%s> multicast prefix (%s) must "
                               "not be advertised on %s",
                               __func__, addr, intface);
                        goto errexit;
                }
                if (IN6_IS_ADDR_LINKLOCAL(&pfx->prefix))
-                       syslog(LOG_NOTICE,
+                       logit(LOG_NOTICE,
                               "<%s> link-local prefix (%s) will be"
                               " advertised on %s",
                               __func__, addr, intface);
@@ -411,7 +412,7 @@
                makeentry(entbuf, sizeof(entbuf), i, "prefixlen");
                MAYHAVE(val, entbuf, 64);
                if (val < 0 || val > 128) {
-                       syslog(LOG_ERR, "<%s> prefixlen (%d) for %s "
+                       logit(LOG_ERR, "<%s> prefixlen (%d) for %s "
                               "on %s out of range",
                               __func__, val, addr, intface);
                        goto errexit;
@@ -435,7 +436,7 @@
                makeentry(entbuf, sizeof(entbuf), i, "vltime");
                MAYHAVE(val64, entbuf, DEF_ADVVALIDLIFETIME);
                if (val64 < 0 || val64 > 0xffffffff) {
-                       syslog(LOG_ERR, "<%s> vltime (%lld) for "
+                       logit(LOG_ERR, "<%s> vltime (%lld) for "
                            "%s/%d on %s is out of range",
                            __func__, (long long)val64,
                            addr, pfx->prefixlen, intface);
@@ -454,7 +455,7 @@
                makeentry(entbuf, sizeof(entbuf), i, "pltime");
                MAYHAVE(val64, entbuf, DEF_ADVPREFERREDLIFETIME);
                if (val64 < 0 || val64 > 0xffffffff) {
-                       syslog(LOG_ERR,
+                       logit(LOG_ERR,
                            "<%s> pltime (%lld) for %s/%d on %s "
                            "is out of range",
                            __func__, (long long)val64,
@@ -476,7 +477,7 @@
 
        MAYHAVE(val64, "mtu", 0);
        if (val64 < 0 || val64 > 0xffffffff) {
-               syslog(LOG_ERR,
+               logit(LOG_ERR,
                       "<%s> mtu (%" PRIi64 ") on %s out of range",
                       __func__, val64, intface);
                goto errexit;
@@ -490,7 +491,7 @@
                        tmp->linkmtu = tmp->phymtu;
        }
        else if (tmp->linkmtu < IPV6_MMTU || tmp->linkmtu > tmp->phymtu) {
-               syslog(LOG_ERR,
+               logit(LOG_ERR,
                       "<%s> advertised link mtu (%d) on %s is invalid (must "
                       "be between least MTU (%d) and physical link MTU (%d)",
                       __func__, tmp->linkmtu, intface,
@@ -504,13 +505,13 @@
                int s;
 
                if ((s = prog_socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
-                       syslog(LOG_ERR, "<%s> socket: %m", __func__);
+                       logit(LOG_ERR, "<%s> socket: %m", __func__);
                        goto errexit;
                }
                memset(&ndi, 0, sizeof(ndi));
                strncpy(ndi.ifname, intface, IFNAMSIZ);
                if (prog_ioctl(s, SIOCGIFINFO_IN6, &ndi) < 0) {
-                       syslog(LOG_INFO, "<%s> ioctl:SIOCGIFINFO_IN6 at %s: %m",
+                       logit(LOG_INFO, "<%s> ioctl:SIOCGIFINFO_IN6 at %s: %m",
                             __func__, intface);
                }
 
@@ -519,7 +520,7 @@
                ndi.ndi.retrans = tmp->retranstimer;
                ndi.ndi.basereachable = tmp->reachabletime;
                if (prog_ioctl(s, SIOCSIFINFO_IN6, &ndi) < 0) {
-                       syslog(LOG_INFO, "<%s> ioctl:SIOCSIFINFO_IN6 at %s: %m",
+                       logit(LOG_INFO, "<%s> ioctl:SIOCSIFINFO_IN6 at %s: %m",
                             __func__, intface);
                }
                prog_close(s);
@@ -551,7 +552,7 @@
                TAILQ_INSERT_TAIL(&tmp->route, rti, next);
 
                if (inet_pton(AF_INET6, addr, &rti->prefix) != 1) {
-                       syslog(LOG_ERR, "<%s> inet_pton failed for %s",
+                       logit(LOG_ERR, "<%s> inet_pton failed for %s",
                               __func__, addr);
                        goto errexit;
                }
@@ -564,14 +565,14 @@
                 */
                MAYHAVE(val64, entbuf, DEF_ADVVALIDLIFETIME);
                if (IN6_IS_ADDR_MULTICAST(&rti->prefix)) {
-                       syslog(LOG_ERR,
+                       logit(LOG_ERR,
                               "<%s> multicast route (%s) must "
                               "not be advertised on %s",
                               __func__, addr, intface);



Home | Main Index | Thread Index | Old Index