]> git.saurik.com Git - apple/network_cmds.git/commitdiff
network_cmds-543.270.1.tar.gz macos-10146 v543.270.1
authorApple <opensource@apple.com>
Thu, 23 May 2019 04:02:29 +0000 (04:02 +0000)
committerApple <opensource@apple.com>
Thu, 23 May 2019 04:02:29 +0000 (04:02 +0000)
13 files changed:
network_cmds.xcodeproj/project.pbxproj
rtadvd.tproj/advcap.c
rtadvd.tproj/config.c
rtadvd.tproj/dump.c
rtadvd.tproj/if.c
rtadvd.tproj/if.h
rtadvd.tproj/rrenum.c
rtadvd.tproj/rtadvd.8
rtadvd.tproj/rtadvd.c
rtadvd.tproj/rtadvd.h
rtadvd.tproj/rtadvd_logging.c [new file with mode: 0644]
rtadvd.tproj/rtadvd_logging.h [new file with mode: 0644]
rtadvd.tproj/timer.c

index 1889a84b14f326fa3ffbadf9f6ffcffc00d2cc09..710cd117a5a49d084ff4d4f7749993d5d018bb8a 100755 (executable)
                72B732F11899B2430060E6D4 /* cfilstat.c in Sources */ = {isa = PBXBuildFile; fileRef = 72B732F01899B2430060E6D4 /* cfilstat.c */; };
                72B894EC0EEDB17C00C218D6 /* libipsec.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 72CD1DB50EE8C619005F825D /* libipsec.dylib */; };
                72D000C4142BB11100151981 /* dnctl.c in Sources */ = {isa = PBXBuildFile; fileRef = 72D000C3142BB11100151981 /* dnctl.c */; };
+               72D33F572271319400EF5B5E /* rtadvd_logging.c in Sources */ = {isa = PBXBuildFile; fileRef = 72D33F562271220100EF5B5E /* rtadvd_logging.c */; };
                72E42BA314B7CF3D003AAE28 /* network_cmds.plist in Install OSS Plist */ = {isa = PBXBuildFile; fileRef = 72E42BA214B7CF37003AAE28 /* network_cmds.plist */; };
                72E650A7107BF2F000AAF325 /* af_inet.c in Sources */ = {isa = PBXBuildFile; fileRef = 72E650A2107BF2F000AAF325 /* af_inet.c */; };
                72E650A8107BF2F000AAF325 /* af_inet6.c in Sources */ = {isa = PBXBuildFile; fileRef = 72E650A3107BF2F000AAF325 /* af_inet6.c */; };
                72B732F01899B2430060E6D4 /* cfilstat.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = cfilstat.c; sourceTree = "<group>"; };
                72CD1DB50EE8C619005F825D /* libipsec.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libipsec.dylib; path = /usr/lib/libipsec.dylib; sourceTree = "<absolute>"; };
                72D000C3142BB11100151981 /* dnctl.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = dnctl.c; sourceTree = "<group>"; };
+               72D33F552271220100EF5B5E /* rtadvd_logging.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = rtadvd_logging.h; sourceTree = "<group>"; };
+               72D33F562271220100EF5B5E /* rtadvd_logging.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = rtadvd_logging.c; sourceTree = "<group>"; };
                72E42BA214B7CF37003AAE28 /* network_cmds.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = network_cmds.plist; sourceTree = "<group>"; };
                72E650A2107BF2F000AAF325 /* af_inet.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = af_inet.c; sourceTree = "<group>"; };
                72E650A3107BF2F000AAF325 /* af_inet6.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = af_inet6.c; sourceTree = "<group>"; };
                726120BB0EE86F8200AFED1B /* rtadvd.tproj */ = {
                        isa = PBXGroup;
                        children = (
+                               72D33F562271220100EF5B5E /* rtadvd_logging.c */,
+                               72D33F552271220100EF5B5E /* rtadvd_logging.h */,
                                726120BC0EE86F8200AFED1B /* advcap.c */,
                                726120BD0EE86F8200AFED1B /* advcap.h */,
                                726120BE0EE86F8200AFED1B /* config.c */,
                        isa = PBXSourcesBuildPhase;
                        buildActionMask = 2147483647;
                        files = (
+                               72D33F572271319400EF5B5E /* rtadvd_logging.c in Sources */,
                                7216D3190EE89EC100AE70E4 /* advcap.c in Sources */,
                                7216D31A0EE89EC100AE70E4 /* config.c in Sources */,
                                7216D31B0EE89EC100AE70E4 /* dump.c in Sources */,
index 2c9e34da0a955368003cb75c6dc870d5e5949c8f..061230c27b06cd59787ee7b96b25ede614c3dca9 100644 (file)
 #include <ctype.h>
 #include <stdlib.h>
 #include <stdio.h>
-#include <syslog.h>
 #include <errno.h>
 #include <string.h>
 #include "pathnames.h"
+#include "rtadvd_logging.h"
 
 #ifndef BUFSIZ
 #define        BUFSIZ          1024
@@ -165,8 +165,7 @@ getent(bp, name, cp)
                tf = open(RM = cp, O_RDONLY);
        }
        if (tf < 0) {
-               syslog(LOG_INFO,
-                      "<%s> open: %s", __func__, strerror(errno));
+               infolog("<%s> open: %s", __func__, strerror(errno));
                return (-2);
        }
        for (;;) {
index b4bd8afce94d0c38dd5941d6987566d77b40eaa6..8ad5cf00ecac1ea230e8ab7af72801b54fcdb6ac 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2009-2012 Apple Inc. All rights reserved.
+ * Copyright (c) 2009-2017 Apple Inc. All rights reserved.
  *
  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
  *
@@ -30,6 +30,7 @@
 
 /*
  * Copyright (C) 1998 WIDE Project.
+ * Copyright (C) 2011 Hiroki Sato <hrs@FreeBSD.org>
  * All rights reserved.
  * 
  * Redistribution and use in source and binary forms, with or without
@@ -78,7 +79,6 @@
 #include <arpa/inet.h>
 
 #include <stdio.h>
-#include <syslog.h>
 #include <errno.h>
 #include <string.h>
 #include <search.h>
@@ -110,7 +110,7 @@ getconfig(intface)
        int rdnss_length;
        int dnssl_length;
        char tbuf[BUFSIZ];
-       struct rainfo *tmp;
+       struct rainfo *rai;
        long val;
        int64_t val64;
        char buf[BUFSIZ];
@@ -136,26 +136,19 @@ getconfig(intface)
 
        if ((stat = agetent(tbuf, intface)) <= 0) {
                memset(tbuf, 0, sizeof(tbuf));
-               syslog(LOG_INFO,
-                      "<%s> %s isn't defined in the configuration file"
+               errorlog("<%s> %s isn't defined in the configuration file"
                       " or the configuration file doesn't exist."
                       " Treat it as default",
                        __func__, intface);
        }
 
-       tmp = (struct rainfo *)malloc(sizeof(*ralist));
-       if (tmp == NULL) {
-               syslog(LOG_INFO, "<%s> %s: can't allocate enough memory",
-                   __func__, intface);
-               exit(1);
-       }
-       memset(tmp, 0, sizeof(*tmp));
-       tmp->prefix.next = tmp->prefix.prev = &tmp->prefix;
+       ELM_MALLOC(rai, exit(1));
+       rai->prefix.next = rai->prefix.prev = &rai->prefix;
 #ifdef ROUTEINFO
-       tmp->route.next = tmp->route.prev = &tmp->route;
+       rai->route.next = rai->route.prev = &rai->route;
 #endif
-       tmp->rdnss_list.next = tmp->rdnss_list.prev = &tmp->rdnss_list;
-       tmp->dnssl_list.next = tmp->dnssl_list.prev = &tmp->dnssl_list;
+       rai->rdnss_list.next = rai->rdnss_list.prev = &rai->rdnss_list;
+       rai->dnssl_list.next = rai->dnssl_list.prev = &rai->dnssl_list;
 
        /* check if we are allowed to forward packets (if not determined) */
        if (forwarding < 0) {
@@ -165,24 +158,22 @@ getconfig(intface)
 
        /* get interface information */
        if (agetflag("nolladdr"))
-               tmp->advlinkopt = 0;
+               rai->advlinkopt = 0;
        else
-               tmp->advlinkopt = 1;
-       if (tmp->advlinkopt) {
-               if ((tmp->sdl = if_nametosdl(intface)) == NULL) {
-                       syslog(LOG_ERR,
-                              "<%s> can't get information of %s",
+               rai->advlinkopt = 1;
+       if (rai->advlinkopt) {
+               if ((rai->sdl = if_nametosdl(intface)) == NULL) {
+                       errorlog("<%s> can't get information of %s",
                               __func__, intface);
                        exit(1);
                }
-               tmp->ifindex = tmp->sdl->sdl_index;
+               rai->ifindex = rai->sdl->sdl_index;
        } else
-               tmp->ifindex = if_nametoindex(intface);
-       strncpy(tmp->ifname, intface, sizeof(tmp->ifname));
-       if ((tmp->phymtu = if_getmtu(intface)) == 0) {
-               tmp->phymtu = IPV6_MMTU;
-               syslog(LOG_WARNING,
-                      "<%s> can't get interface mtu of %s. Treat as %d",
+               rai->ifindex = if_nametoindex(intface);
+       strlcpy(rai->ifname, intface, sizeof(rai->ifname));
+       if ((rai->phymtu = if_getmtu(intface)) == 0) {
+               rai->phymtu = IPV6_MMTU;
+               errorlog("<%s> can't get interface mtu of %s. Treat as %d",
                       __func__, intface, IPV6_MMTU);
        }
 
@@ -191,26 +182,24 @@ getconfig(intface)
         */
        MAYHAVE(val, "maxinterval", DEF_MAXRTRADVINTERVAL);
        if (val < MIN_MAXINTERVAL || val > MAX_MAXINTERVAL) {
-               syslog(LOG_ERR,
-                      "<%s> maxinterval (%ld) on %s is invalid "
+               errorlog("<%s> maxinterval (%ld) on %s is invalid "
                       "(must be between %u and %u)", __func__, val,
                       intface, MIN_MAXINTERVAL, MAX_MAXINTERVAL);
                exit(1);
        }
-       tmp->maxinterval = (u_int)val;
-       MAYHAVE(val, "mininterval", tmp->maxinterval/3);
-       if (val < MIN_MININTERVAL || val > (tmp->maxinterval * 3) / 4) {
-               syslog(LOG_ERR,
-                      "<%s> mininterval (%ld) on %s is invalid "
+       rai->maxinterval = (u_int)val;
+       MAYHAVE(val, "mininterval", rai->maxinterval/3);
+       if (val < MIN_MININTERVAL || val > (rai->maxinterval * 3) / 4) {
+               errorlog("<%s> mininterval (%ld) on %s is invalid "
                       "(must be between %d and %d)",
                       __func__, val, intface, MIN_MININTERVAL,
-                      (tmp->maxinterval * 3) / 4);
+                      (rai->maxinterval * 3) / 4);
                exit(1);
        }
-       tmp->mininterval = (u_int)val;
+       rai->mininterval = (u_int)val;
 
        MAYHAVE(val, "chlim", DEF_ADVCURHOPLIMIT);
-       tmp->hoplimit = val & 0xff;
+       rai->hoplimit = val & 0xff;
 
        if ((flagstr = (char *)agetstr("raflags", &bp))) {
                val = 0;
@@ -222,7 +211,7 @@ getconfig(intface)
                        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\'"
+                               errorlog("<%s> the \'h\' and \'l\'"
                                    " router flags are exclusive", __func__);
                                exit(1);
                        }
@@ -231,26 +220,25 @@ getconfig(intface)
        } else {
                MAYHAVE(val, "raflags", 0);
        }
-       tmp->managedflg = val & ND_RA_FLAG_MANAGED;
-       tmp->otherflg = val & ND_RA_FLAG_OTHER;
+       rai->managedflg = val & ND_RA_FLAG_MANAGED;
+       rai->otherflg = val & ND_RA_FLAG_OTHER;
 #ifndef ND_RA_FLAG_RTPREF_MASK
 #define ND_RA_FLAG_RTPREF_MASK 0x18 /* 00011000 */
 #define ND_RA_FLAG_RTPREF_RSV  0x10 /* 00010000 */
 #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",
-                      __func__, tmp->rtpref, intface);
+       rai->rtpref = val & ND_RA_FLAG_RTPREF_MASK;
+       if (rai->rtpref == ND_RA_FLAG_RTPREF_RSV) {
+               errorlog("<%s> invalid router preference (%02x) on %s",
+                      __func__, rai->rtpref, intface);
                exit(1);
        }
 
-       MAYHAVE(val, "rltime", tmp->maxinterval * 3);
-       if (val && (val < tmp->maxinterval || val > MAXROUTERLIFETIME)) {
-               syslog(LOG_ERR,
-                      "<%s> router lifetime (%ld) on %s is invalid "
+       MAYHAVE(val, "rltime", rai->maxinterval * 3);
+       if (val && (val < rai->maxinterval || val > MAXROUTERLIFETIME)) {
+               errorlog("<%s> router lifetime (%ld) on %s is invalid "
                       "(must be 0 or between %d and %d)",
                       __func__, val, intface,
-                      tmp->maxinterval,
+                      rai->maxinterval,
                       MAXROUTERLIFETIME);
                exit(1);
        }
@@ -263,36 +251,33 @@ getconfig(intface)
         * explicitly set zero. (see also the above section)
         */
        if (val && forwarding == 0) {
-               syslog(LOG_ERR,
-                      "<%s> non zero router lifetime is specified for %s, "
+               errorlog("<%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.",
                       __func__, intface);
                exit(1);
        }
-       tmp->lifetime = val & 0xffff;
+       rai->lifetime = val & 0xffff;
 
        MAYHAVE(val, "rtime", DEF_ADVREACHABLETIME);
        if (val < 0 || val > MAXREACHABLETIME) {
-               syslog(LOG_ERR,
-                      "<%s> reachable time (%ld) on %s is invalid "
+               errorlog("<%s> reachable time (%ld) on %s is invalid "
                       "(must be no greater than %d)",
                       __func__, val, intface, MAXREACHABLETIME);
                exit(1);
        }
-       tmp->reachabletime = (u_int32_t)val;
+       rai->reachabletime = (u_int32_t)val;
 
        MAYHAVE(val64, "retrans", DEF_ADVRETRANSTIMER);
        if (val64 < 0 || val64 > 0xffffffff) {
-               syslog(LOG_ERR, "<%s> retrans time (%lld) on %s out of range",
+               errorlog("<%s> retrans time (%lld) on %s out of range",
                       __func__, (long long)val64, intface);
                exit(1);
        }
-       tmp->retranstimer = (u_int32_t)val64;
+       rai->retranstimer = (u_int32_t)val64;
 
        if (agetnum("hapref") != -1 || agetnum("hatime") != -1) {
-               syslog(LOG_ERR,
-                      "<%s> mobile-ip6 configuration not supported",
+               errorlog("<%s> mobile-ip6 configuration not supported",
                       __func__);
                exit(1);
        }
@@ -304,9 +289,9 @@ getconfig(intface)
         * checking consistency of advertised lifetimes.
         */
        MAYHAVE(val, "clockskew", 0);
-       tmp->clockskew = val;
+       rai->clockskew = val;
 
-       tmp->pfxs = 0;
+       rai->pfxs = 0;
        for (i = -1; i < MAXPREFIX; i++) {
                struct prefix *pfx;
                char entbuf[256];
@@ -317,44 +302,31 @@ getconfig(intface)
                        continue;
 
                /* allocate memory to store prefix information */
-               if ((pfx = malloc(sizeof(struct prefix))) == NULL) {
-                       syslog(LOG_ERR,
-                              "<%s> can't allocate enough memory",
-                              __func__);
-                       exit(1);
-               }
-               memset(pfx, 0, sizeof(*pfx));
-
-               /* link into chain */
-               insque(pfx, &tmp->prefix);
-               tmp->pfxs++;
-               pfx->rainfo = tmp;
+               ELM_MALLOC(pfx, exit(1));
 
+               pfx->rainfo = rai;
                pfx->origin = PREFIX_FROM_CONFIG;
 
                if (inet_pton(AF_INET6, addr, &pfx->prefix) != 1) {
-                       syslog(LOG_ERR,
-                              "<%s> inet_pton failed for %s",
+                       errorlog("<%s> inet_pton failed for %s",
                               __func__, addr);
                        exit(1);
                }
                if (IN6_IS_ADDR_MULTICAST(&pfx->prefix)) {
-                       syslog(LOG_ERR,
-                              "<%s> multicast prefix (%s) must "
+                       errorlog("<%s> multicast prefix (%s) must "
                               "not be advertised on %s",
                               __func__, addr, intface);
                        exit(1);
                }
                if (IN6_IS_ADDR_LINKLOCAL(&pfx->prefix))
-                       syslog(LOG_NOTICE,
-                              "<%s> link-local prefix (%s) will be"
+                       noticelog("<%s> link-local prefix (%s) will be"
                               " advertised on %s",
                               __func__, addr, intface);
 
                makeentry(entbuf, sizeof(entbuf), i, "prefixlen");
                MAYHAVE(val, entbuf, 64);
                if (val < 0 || val > 128) {
-                       syslog(LOG_ERR, "<%s> prefixlen (%ld) for %s "
+                       errorlog("<%s> prefixlen (%ld) for %s "
                               "on %s out of range",
                               __func__, val, addr, intface);
                        exit(1);
@@ -378,7 +350,7 @@ getconfig(intface)
                makeentry(entbuf, sizeof(entbuf), i, "vltime");
                MAYHAVE(val64, entbuf, DEF_ADVVALIDLIFETIME);
                if (val64 < 0 || val64 > 0xffffffff) {
-                       syslog(LOG_ERR, "<%s> vltime (%lld) for "
+                       errorlog("<%s> vltime (%lld) for "
                            "%s/%d on %s is out of range",
                            __func__, (long long)val64,
                            addr, pfx->prefixlen, intface);
@@ -397,8 +369,7 @@ getconfig(intface)
                makeentry(entbuf, sizeof(entbuf), i, "pltime");
                MAYHAVE(val64, entbuf, DEF_ADVPREFERREDLIFETIME);
                if (val64 < 0 || val64 > 0xffffffff) {
-                       syslog(LOG_ERR,
-                           "<%s> pltime (%lld) for %s/%d on %s "
+                       errorlog("<%s> pltime (%lld) for %s/%d on %s "
                            "is out of range",
                            __func__, (long long)val64,
                            addr, pfx->prefixlen, intface);
@@ -413,31 +384,32 @@ getconfig(intface)
                        pfx->pltimeexpire =
                                now.tv_sec + pfx->preflifetime;
                }
+               /* link into chain */
+               insque(pfx, &rai->prefix);
+               rai->pfxs++;
        }
-       if (tmp->pfxs == 0)
-               get_prefix(tmp);
+       if (rai->pfxs == 0)
+               get_prefix(rai);
 
        MAYHAVE(val, "mtu", 0);
        if (val < 0 || val > 0xffffffff) {
-               syslog(LOG_ERR,
-                      "<%s> mtu (%ld) on %s out of range",
+               errorlog("<%s> mtu (%ld) on %s out of range",
                       __func__, val, intface);
                exit(1);
        }
-       tmp->linkmtu = (u_int32_t)val;
-       if (tmp->linkmtu == 0) {
+       rai->linkmtu = (u_int32_t)val;
+       if (rai->linkmtu == 0) {
                char *mtustr;
 
                if ((mtustr = (char *)agetstr("mtu", &bp)) &&
                    strcmp(mtustr, "auto") == 0)
-                       tmp->linkmtu = tmp->phymtu;
+                       rai->linkmtu = rai->phymtu;
        }
-       else if (tmp->linkmtu < IPV6_MMTU || tmp->linkmtu > tmp->phymtu) {
-               syslog(LOG_ERR,
-                      "<%s> advertised link mtu (%lu) on %s is invalid (must "
+       else if (rai->linkmtu < IPV6_MMTU || rai->linkmtu > rai->phymtu) {
+               errorlog("<%s> advertised link mtu (%lu) on %s is invalid (must "
                       "be between least MTU (%d) and physical link MTU (%d)",
-                      __func__, (unsigned long)tmp->linkmtu, intface,
-                      IPV6_MMTU, tmp->phymtu);
+                      __func__, (unsigned long)rai->linkmtu, intface,
+                      IPV6_MMTU, rai->phymtu);
                exit(1);
        }
 
@@ -447,23 +419,23 @@ getconfig(intface)
                int s;
 
                if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
-                       syslog(LOG_ERR, "<%s> socket: %s", __func__,
+                       errorlog("<%s> socket: %s", __func__,
                               strerror(errno));
                        exit(1);
                }
                memset(&ndi, 0, sizeof(ndi));
                strncpy(ndi.ifname, intface, IFNAMSIZ);
                if (ioctl(s, SIOCGIFINFO_IN6, (caddr_t)&ndi) < 0) {
-                       syslog(LOG_INFO, "<%s> ioctl:SIOCGIFINFO_IN6 at %s: %s",
+                       infolog("<%s> ioctl:SIOCGIFINFO_IN6 at %s: %s",
                             __func__, intface, strerror(errno));
                }
 
                /* reflect the RA info to the host variables in kernel */
-               ndi.ndi.chlim = tmp->hoplimit;
-               ndi.ndi.retrans = tmp->retranstimer;
-               ndi.ndi.basereachable = tmp->reachabletime;
+               ndi.ndi.chlim = rai->hoplimit;
+               ndi.ndi.retrans = rai->retranstimer;
+               ndi.ndi.basereachable = rai->reachabletime;
                if (ioctl(s, SIOCSIFINFO_IN6, (caddr_t)&ndi) < 0) {
-                       syslog(LOG_INFO, "<%s> ioctl:SIOCSIFINFO_IN6 at %s: %s",
+                       infolog("<%s> ioctl:SIOCSIFINFO_IN6 at %s: %s",
                             __func__, intface, strerror(errno));
                }
                close(s);
@@ -472,7 +444,7 @@ getconfig(intface)
 
        /* route information */
 #ifdef ROUTEINFO
-       tmp->routes = 0;
+       rai->routes = 0;
        for (i = -1; i < MAXROUTE; i++) {
                struct rtinfo *rti;
                char entbuf[256], oentbuf[256];
@@ -491,20 +463,14 @@ getconfig(intface)
                        continue;
 
                /* allocate memory to store prefix information */
-               if ((rti = malloc(sizeof(struct rtinfo))) == NULL) {
-                       syslog(LOG_ERR,
-                              "<%s> can't allocate enough memory",
-                              __func__);
-                       exit(1);
-               }
-               memset(rti, 0, sizeof(*rti));
+               ELM_MALLOC(rti, exit(1));
 
                /* link into chain */
-               insque(rti, &tmp->route);
-               tmp->routes++;
+               insque(rti, &rai->route);
+               rai->routes++;
 
                if (inet_pton(AF_INET6, addr, &rti->prefix) != 1) {
-                       syslog(LOG_ERR, "<%s> inet_pton failed for %s",
+                       errorlog( "<%s> inet_pton failed for %s",
                               __func__, addr);
                        exit(1);
                }
@@ -517,15 +483,13 @@ getconfig(intface)
                 */
                MAYHAVE(val64, entbuf, DEF_ADVVALIDLIFETIME);
                if (IN6_IS_ADDR_MULTICAST(&rti->prefix)) {
-                       syslog(LOG_ERR,
-                              "<%s> multicast route (%s) must "
+                       errorlog("<%s> multicast route (%s) must "
                               "not be advertised on %s",
                               __func__, addr, intface);
                        exit(1);
                }
                if (IN6_IS_ADDR_LINKLOCAL(&rti->prefix)) {
-                       syslog(LOG_NOTICE,
-                              "<%s> link-local route (%s) will "
+                       noticelog("<%s> link-local route (%s) will "
                               "be advertised on %s",
                               __func__, addr, intface);
                        exit(1);
@@ -545,7 +509,7 @@ getconfig(intface)
                                val = 64;
                }
                if (val < 0 || val > 128) {
-                       syslog(LOG_ERR, "<%s> prefixlen (%ld) for %s on %s "
+                       errorlog("<%s> prefixlen (%ld) for %s on %s "
                               "out of range",
                               __func__, val, addr, intface);
                        exit(1);
@@ -559,7 +523,7 @@ getconfig(intface)
                                val |= ND_RA_FLAG_RTPREF_HIGH;
                        if (strchr(flagstr, 'l')) {
                                if ((val & ND_RA_FLAG_RTPREF_HIGH)) {
-                                       syslog(LOG_ERR,
+                                       errorlog(
                                            "<%s> the \'h\' and \'l\' route"
                                            " preferences are exclusive",
                                            __func__);
@@ -580,7 +544,7 @@ getconfig(intface)
                }
                rti->rtpref = val & ND_RA_FLAG_RTPREF_MASK;
                if (rti->rtpref == ND_RA_FLAG_RTPREF_RSV) {
-                       syslog(LOG_ERR, "<%s> invalid route preference (%02x) "
+                       errorlog("<%s> invalid route preference (%02x) "
                               "for %s/%d on %s",
                               __func__, rti->rtpref, addr,
                               rti->prefixlen, intface);
@@ -605,11 +569,11 @@ getconfig(intface)
                                fprintf(stderr, "%s should be specified "
                                        "for interface %s.\n",
                                        entbuf, intface);
-                               val64 = tmp->lifetime;
+                               val64 = rai->lifetime;
                        }
                }
                if (val64 < 0 || val64 > 0xffffffff) {
-                       syslog(LOG_ERR, "<%s> route lifetime (%lld) for "
+                       errorlog( "<%s> route lifetime (%lld) for "
                            "%s/%d on %s out of range", __func__,
                            (long long)val64, addr, rti->prefixlen, intface);
                        exit(1);
@@ -619,19 +583,18 @@ getconfig(intface)
 #endif
 
        /* RDNSS option (RFC5006) */
-       MAYHAVE(val, "rdnsslifetime", 2 * tmp->maxinterval);
-       if (val < tmp->maxinterval || val > (2 * tmp->maxinterval)) {
-           syslog(LOG_NOTICE,
-                  "<%s> rdnsslifetime (%lu) on %s SHOULD "
+       MAYHAVE(val, "rdnsslifetime", 2 * rai->maxinterval);
+       if (val < rai->maxinterval || val > (2 * rai->maxinterval)) {
+           noticelog("<%s> rdnsslifetime (%lu) on %s SHOULD "
                   "be between %u and %u", __func__, val,
-                  intface, tmp->maxinterval, 2 * tmp->maxinterval);
+                  intface, rai->maxinterval, 2 * rai->maxinterval);
        }
-       tmp->rdnss_lifetime = val;
+       rai->rdnss_lifetime = val;
        if ((rdnss_length = agetnum("rdnssaddrs")) < 0) {
-           tmp->rdnss_length = 0;
+           rai->rdnss_length = 0;
        }
        else {
-           tmp->rdnss_length = rdnss_length;
+           rai->rdnss_length = rdnss_length;
 
            /* traverse in reverse order so that the queue has correct order */
            for (i = (rdnss_length - 1); i >= 0; i--) {
@@ -639,16 +602,9 @@ getconfig(intface)
                char entbuf[256];
 
                /* allocate memory to store server address information */
-               if ((rdnss = malloc(sizeof(struct rdnss))) == NULL) {
-                       syslog(LOG_ERR,
-                              "<%s> can't allocate enough memory",
-                              __func__);
-                       exit(1);
-               }
-               memset(rdnss, 0, sizeof(*rdnss));
-
+               ELM_MALLOC(rdnss, exit(1));
                /* link into chain */
-               insque(rdnss, &tmp->rdnss_list);
+               insque(rdnss, &rai->rdnss_list);
 
                makeentry(entbuf, sizeof(entbuf), i, "rdnssaddr");
                addr = (char *)agetstr(entbuf, &bp);
@@ -659,22 +615,19 @@ getconfig(intface)
                }
 
                if (addr == NULL) {
-                   syslog(LOG_ERR,
-                          "<%s> need %s as a DNS server address for "
+                   errorlog("<%s> need %s as a DNS server address for "
                           "interface %s",
                           __func__, entbuf, intface);
                    exit(1);
                }
 
                if (inet_pton(AF_INET6, addr, &rdnss->addr) != 1) {
-                       syslog(LOG_ERR,
-                              "<%s> inet_pton failed for %s",
+                       errorlog("<%s> inet_pton failed for %s",
                               __func__, addr);
                        exit(1);
                }
                if (IN6_IS_ADDR_MULTICAST(&rdnss->addr)) {
-                       syslog(LOG_ERR,
-                              "<%s> multicast address (%s) must "
+                       errorlog("<%s> multicast address (%s) must "
                               "not be advertised as recursive DNS server",
                               __func__, addr);
                        exit(1);
@@ -685,23 +638,22 @@ getconfig(intface)
        /* DNSSL option (RFC6106) */
 
        /* Parse the DNSSL lifetime from the config */
-       MAYHAVE(val, "dnssllifetime", 2 * tmp->maxinterval);
-       if (val < tmp->maxinterval || val > (2 * tmp->maxinterval)) {
-           syslog(LOG_NOTICE,
-                  "<%s> dnssllifetime (%lu) on %s SHOULD "
+       MAYHAVE(val, "dnssllifetime", 2 * rai->maxinterval);
+       if (val < rai->maxinterval || val > (2 * rai->maxinterval)) {
+           noticelog("<%s> dnssllifetime (%lu) on %s SHOULD "
                   "be between %u and %u", __func__, val,
-                  intface, tmp->maxinterval, 2 * tmp->maxinterval);
+                  intface, rai->maxinterval, 2 * rai->maxinterval);
        }
-       tmp->dnssl_lifetime = val;
-       tmp->dnssl_option_length = 8; /* 8 bytes for the option header */
+       rai->dnssl_lifetime = val;
+       rai->dnssl_option_length = 8; /* 8 bytes for the option header */
 
        /* Parse the DNSSL domain list from the config */
        if ((dnssl_length = agetnum("dnssldomains")) < 0) {
-           tmp->dnssl_length = 0;
+           rai->dnssl_length = 0;
        } else {
-           tmp->dnssl_length = dnssl_length;
+           rai->dnssl_length = dnssl_length;
 
-           for (i = (tmp->dnssl_length - 1); i >= 0; i--) {
+           for (i = (rai->dnssl_length - 1); i >= 0; i--) {
                unsigned char *dnssl_buf;
                struct dnssl *dnssl;
                int dnssl_len;
@@ -712,14 +664,13 @@ getconfig(intface)
                makeentry(entbuf, sizeof(entbuf), i, "dnssldomain");
                domain = agetstr(entbuf, &bp);
 
-               if (domain == NULL && tmp->dnssl_length == 1) {
+               if (domain == NULL && rai->dnssl_length == 1) {
                    makeentry(entbuf, sizeof(entbuf), -1, "dnssldomain");
                    domain = agetstr(entbuf, &bp);
                }
 
                if (domain == NULL) {
-                   syslog(LOG_ERR,
-                          "<%s> need %s as a DNS search domain for "
+                   errorlog("<%s> need %s as a DNS search domain for "
                           "interface %s",
                           __func__, entbuf, intface);
                    exit(1);
@@ -745,46 +696,46 @@ getconfig(intface)
                    memset(dnssl_buf, 0, dnssl_len);
 
                    dnssl = (struct dnssl *)dnssl_buf;
-                   insque(dnssl, &tmp->dnssl_list);
+                   insque(dnssl, &rai->dnssl_list);
 
                    /* Copy the domain name in at the end of the dnssl struct */
                    memcpy(dnssl_buf + offsetof(struct dnssl, domain), domain,
                           domain_len);
 
                    /* Add 2 for leading length byte and the trailing 0 byte */
-                   tmp->dnssl_option_length += domain_len + 2;
+                   rai->dnssl_option_length += domain_len + 2;
                }
            }
 
            /* Round up to the next multiple of 8 */
-           tmp->dnssl_option_length += (8 - (tmp->dnssl_option_length & 0x7));
+           rai->dnssl_option_length += (8 - (rai->dnssl_option_length & 0x7));
        }
 
        /* okey */
-       tmp->next = ralist;
-       ralist = tmp;
+       rai->next = ralist;
+       ralist = rai;
 
        /* construct the sending packet */
-       make_packet(tmp);
+       make_packet(rai);
 
        /* set timer */
-       tmp->timer = rtadvd_add_timer(ra_timeout, ra_timer_update,
-                                     tmp, tmp);
-       ra_timer_update((void *)tmp, &tmp->timer->tm);
-       rtadvd_set_timer(&tmp->timer->tm, tmp->timer);
+       rai->timer = rtadvd_add_timer(ra_timeout, ra_timer_update,
+                                     rai, rai);
+       ra_timer_update((void *)rai, &rai->timer->tm);
+       rtadvd_set_timer(&rai->timer->tm, rai->timer);
 }
 
 void
 get_prefix(struct rainfo *rai)
 {
        struct ifaddrs *ifap, *ifa;
-       struct prefix *pp;
+       struct prefix *pfx;
        struct in6_addr *a;
        u_char *p, *ep, *m, *lim;
        char ntopbuf[INET6_ADDRSTRLEN];
 
        if (getifaddrs(&ifap) < 0) {
-               syslog(LOG_ERR,
+               errorlog(
                       "<%s> can't get interface addresses",
                       __func__);
                exit(1);
@@ -805,7 +756,7 @@ get_prefix(struct rainfo *rai)
                lim = (u_char *)(ifa->ifa_netmask) + ifa->ifa_netmask->sa_len;
                plen = prefixlen(m, lim);
                if (plen <= 0 || plen > 128) {
-                       syslog(LOG_ERR, "<%s> failed to get prefixlen "
+                       errorlog( "<%s> failed to get prefixlen "
                               "or prefix is invalid",
                               __func__);
                        exit(1);
@@ -818,42 +769,34 @@ get_prefix(struct rainfo *rai)
                }
 
                /* allocate memory to store prefix info. */
-               if ((pp = malloc(sizeof(*pp))) == NULL) {
-                       syslog(LOG_ERR,
-                              "<%s> can't get allocate buffer for prefix",
-                              __func__);
-                       exit(1);
-               }
-               memset(pp, 0, sizeof(*pp));
-
+               ELM_MALLOC(pfx, exit(1));
                /* set prefix, sweep bits outside of prefixlen */
-               pp->prefixlen = plen;
-               memcpy(&pp->prefix, a, sizeof(*a));
-               p = (u_char *)&pp->prefix;
-               ep = (u_char *)(&pp->prefix + 1);
+               pfx->prefixlen = plen;
+               memcpy(&pfx->prefix, a, sizeof(*a));
+               p = (u_char *)&pfx->prefix;
+               ep = (u_char *)(&pfx->prefix + 1);
                while (m < lim && p < ep)
                        *p++ &= *m++;
                while (p < ep)
                        *p++ = 0x00;
-               if (!inet_ntop(AF_INET6, &pp->prefix, ntopbuf,
+               if (!inet_ntop(AF_INET6, &pfx->prefix, ntopbuf,
                    sizeof(ntopbuf))) {
-                       syslog(LOG_ERR, "<%s> inet_ntop failed", __func__);
+                       errorlog("<%s> inet_ntop failed", __func__);
                        exit(1);
                }
-               syslog(LOG_DEBUG,
-                      "<%s> add %s/%d to prefix list on %s",
-                      __func__, ntopbuf, pp->prefixlen, rai->ifname);
+               debuglog("<%s> add %s/%d to prefix list on %s",
+                      __func__, ntopbuf, pfx->prefixlen, rai->ifname);
 
                /* set other fields with protocol defaults */
-               pp->validlifetime = DEF_ADVVALIDLIFETIME;
-               pp->preflifetime = DEF_ADVPREFERREDLIFETIME;
-               pp->onlinkflg = 1;
-               pp->autoconfflg = 1;
-               pp->origin = PREFIX_FROM_KERNEL;
-               pp->rainfo = rai;
+               pfx->validlifetime = DEF_ADVVALIDLIFETIME;
+               pfx->preflifetime = DEF_ADVPREFERREDLIFETIME;
+               pfx->onlinkflg = 1;
+               pfx->autoconfflg = 1;
+               pfx->origin = PREFIX_FROM_KERNEL;
+               pfx->rainfo = rai;
 
                /* link into chain */
-               insque(pp, &rai->prefix);
+               insque(pfx, &rai->prefix);
 
                /* counter increment */
                rai->pfxs++;
@@ -889,12 +832,7 @@ add_prefix(struct rainfo *rai, struct in6_prefixreq *ipr)
        struct prefix *prefix;
        char ntopbuf[INET6_ADDRSTRLEN];
 
-       if ((prefix = malloc(sizeof(*prefix))) == NULL) {
-               syslog(LOG_ERR, "<%s> memory allocation failed",
-                      __func__);
-               return;         /* XXX: error or exit? */
-       }
-       memset(prefix, 0, sizeof(*prefix));
+       ELM_MALLOC(prefix, exit(1));
        prefix->prefix = ipr->ipr_prefix.sin6_addr;
        prefix->prefixlen = ipr->ipr_plen;
        prefix->validlifetime = ipr->ipr_vltime;
@@ -906,7 +844,7 @@ add_prefix(struct rainfo *rai, struct in6_prefixreq *ipr)
        insque(prefix, &rai->prefix);
        prefix->rainfo = rai;
 
-       syslog(LOG_DEBUG, "<%s> new prefix %s/%d was added on %s",
+       debuglog("<%s> new prefix %s/%d was added on %s",
               __func__, inet_ntop(AF_INET6, &ipr->ipr_prefix.sin6_addr,
                                       ntopbuf, INET6_ADDRSTRLEN),
               ipr->ipr_plen, rai->ifname);
@@ -932,7 +870,7 @@ delete_prefix(struct prefix *prefix)
        struct rainfo *rai = prefix->rainfo;
 
        remque(prefix);
-       syslog(LOG_DEBUG, "<%s> prefix %s/%d was deleted on %s",
+       debuglog("<%s> prefix %s/%d was deleted on %s",
               __func__, inet_ntop(AF_INET6, &prefix->prefix,
                                       ntopbuf, INET6_ADDRSTRLEN),
               prefix->prefixlen, rai->ifname);
@@ -950,13 +888,12 @@ invalidate_prefix(struct prefix *prefix)
        struct rainfo *rai = prefix->rainfo;
 
        if (prefix->timer) {    /* sanity check */
-               syslog(LOG_ERR,
-                   "<%s> assumption failure: timer already exists",
+               errorlog("<%s> assumption failure: timer already exists",
                    __func__);
                exit(1);
        }
 
-       syslog(LOG_DEBUG, "<%s> prefix %s/%d was invalidated on %s, "
+       debuglog("<%s> prefix %s/%d was invalidated on %s, "
            "will expire in %ld seconds", __func__,
            inet_ntop(AF_INET6, &prefix->prefix, ntopbuf, INET6_ADDRSTRLEN),
            prefix->prefixlen, rai->ifname, (long)prefix_timo);
@@ -964,7 +901,7 @@ invalidate_prefix(struct prefix *prefix)
        /* set the expiration timer */
        prefix->timer = rtadvd_add_timer(prefix_timeout, NULL, prefix, NULL);
        if (prefix->timer == NULL) {
-               syslog(LOG_ERR, "<%s> failed to add a timer for a prefix. "
+               errorlog("<%s> failed to add a timer for a prefix. "
                    "remove the prefix", __func__);
                delete_prefix(prefix);
                return;
@@ -991,13 +928,12 @@ update_prefix(struct prefix * prefix)
        struct rainfo *rai = prefix->rainfo;
 
        if (prefix->timer == NULL) { /* sanity check */
-               syslog(LOG_ERR,
-                   "<%s> assumption failure: timer does not exist",
+               errorlog("<%s> assumption failure: timer does not exist",
                    __func__);
                exit(1);
        }
 
-       syslog(LOG_DEBUG, "<%s> prefix %s/%d was re-enabled on %s",
+       debuglog("<%s> prefix %s/%d was re-enabled on %s",
            __func__, inet_ntop(AF_INET6, &prefix->prefix, ntopbuf,
            INET6_ADDRSTRLEN), prefix->prefixlen, rai->ifname);
 
@@ -1017,13 +953,13 @@ init_prefix(struct in6_prefixreq *ipr)
        int s;
 
        if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
-               syslog(LOG_ERR, "<%s> socket: %s", __func__,
+               errorlog("<%s> socket: %s", __func__,
                       strerror(errno));
                exit(1);
        }
 
        if (ioctl(s, SIOCGIFPREFIX_IN6, (caddr_t)ipr) < 0) {
-               syslog(LOG_INFO, "<%s> ioctl:SIOCGIFPREFIX %s", __func__,
+               infolog("<%s> ioctl:SIOCGIFPREFIX %s", __func__,
                       strerror(errno));
 
                ipr->ipr_vltime = DEF_ADVVALIDLIFETIME;
@@ -1035,7 +971,7 @@ init_prefix(struct in6_prefixreq *ipr)
        else if (ipr->ipr_origin < PR_ORIG_RR) {
                char ntopbuf[INET6_ADDRSTRLEN];
 
-               syslog(LOG_WARNING, "<%s> Added prefix(%s)'s origin %d is"
+               noticelog("<%s> Added prefix(%s)'s origin %d is"
                       "lower than PR_ORIG_RR(router renumbering)."
                       "This should not happen if I am router", __func__,
                       inet_ntop(AF_INET6, &ipr->ipr_prefix.sin6_addr, ntopbuf,
@@ -1062,7 +998,7 @@ make_prefix(struct rainfo *rai, int ifindex, struct in6_addr *addr, int plen)
 
        memset(&ipr, 0, sizeof(ipr));
        if (if_indextoname(ifindex, ipr.ipr_name) == NULL) {
-               syslog(LOG_ERR, "<%s> Prefix added interface No.%d doesn't"
+               errorlog("<%s> Prefix added interface No.%d doesn't"
                       "exist. This should not happen! %s", __func__,
                       ifindex, strerror(errno));
                exit(1);
@@ -1095,8 +1031,7 @@ make_packet(struct rainfo *rainfo)
        packlen = sizeof(struct nd_router_advert);
        if (rainfo->advlinkopt) {
                if ((lladdroptlen = lladdropt_length(rainfo->sdl)) == 0) {
-                       syslog(LOG_INFO,
-                              "<%s> link-layer address option has"
+                       infolog("<%s> link-layer address option has"
                               " null length on %s.  Treat as not included.",
                               __func__, rainfo->ifname);
                        rainfo->advlinkopt = 0;
@@ -1121,8 +1056,7 @@ make_packet(struct rainfo *rainfo)
 
        /* allocate memory for the packet */
        if ((buf = malloc(packlen)) == NULL) {
-               syslog(LOG_ERR,
-                      "<%s> can't get enough memory for an RA packet",
+               errorlog("<%s> can't get enough memory for an RA packet",
                       __func__);
                exit(1);
        }
@@ -1306,7 +1240,7 @@ getinet6sysctl(int code)
        size = sizeof(value);
        if (sysctl(mib, sizeof(mib)/sizeof(mib[0]), &value, &size, NULL, 0)
            < 0) {
-               syslog(LOG_ERR, "<%s>: failed to get ip6 sysctl(%d): %s",
+               errorlog( "<%s>: failed to get ip6 sysctl(%d): %s",
                       __func__, code,
                       strerror(errno));
                return(-1);
index fad2a618f9a3178290de173df1abc965140333f6..ea5dcd99368d33df86bb8fd080884fefd7616c76 100644 (file)
@@ -75,7 +75,6 @@
 #include <time.h>
 #include <stdio.h>
 #include <stdarg.h>
-#include <syslog.h>
 #include <string.h>
 #include <errno.h>
 
@@ -129,10 +128,15 @@ if_dump()
 
        gettimeofday(&now, NULL); /* XXX: unused in most cases */
        for (rai = ralist; rai; rai = rai->next) {
-               fprintf(fp, "%s:\n", rai->ifname);
-
+        fprintf(fp, "%s:\n", rai->ifname);
+        struct if_msghdr *ifm = get_interface_entry(rai->ifindex);
+        if (ifm == NULL) {
+            debuglog("Skippingg RA entry for interface %s"
+                "as we couldn't find interface entry for it.", rai->ifname);
+            continue;
+        }
                fprintf(fp, "  Status: %s\n",
-                       (iflist[rai->ifindex]->ifm_flags & IFF_UP) ? "UP" :
+                       (ifm->ifm_flags & IFF_UP) ? "UP" :
                        "DOWN");
 
                /* control information */
@@ -264,11 +268,11 @@ void
 rtadvd_dump_file(dumpfile)
        char *dumpfile;
 {
-       syslog(LOG_DEBUG, "<%s> dump current status to %s", __func__,
+       debuglog("<%s> dump current status to %s", __func__,
            dumpfile);
 
        if ((fp = fopen(dumpfile, "w")) == NULL) {
-               syslog(LOG_WARNING, "<%s> open a dump file(%s)",
+               errorlog("<%s> open a dump file(%s)",
                    __func__, dumpfile);
                return;
        }
index 5fb644eb29ee24a97d2ac84d70c63220447a6e4a..082714cbfad2b0836cf42516fd9fcc22f429a60d 100644 (file)
@@ -45,7 +45,6 @@
 #include <errno.h>
 #include <stdlib.h>
 #include <string.h>
-#include <syslog.h>
 #include "rtadvd.h"
 #include "if.h"
 
                                                 sizeof(uint32_t)) :\
                                                 sizeof(uint32_t)))
 
-struct if_msghdr **iflist;
-int iflist_init_ok;
+/* Interface list */
+TAILQ_HEAD(ifilist_head_t, ifinfo);
+struct ifilist_head_t ifilist = TAILQ_HEAD_INITIALIZER(ifilist);
 size_t ifblock_size;
 char *ifblock;
 
 static void get_iflist(char **buf, size_t *size);
-static void parse_iflist(struct if_msghdr ***ifmlist_p, char *buf,
-                      size_t bufsize);
+static void parse_iflist(char *buf, size_t bufsize);
+static void purge_iflist();
 
 static void
 get_rtaddrs(int addrs, struct sockaddr *sa, struct sockaddr **rti_info)
@@ -186,14 +186,14 @@ if_getflags(int ifindex, int oifflags)
        int s;
 
        if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
-               syslog(LOG_ERR, "<%s> socket: %s", __func__,
+               errorlog("<%s> socket: %s", __func__,
                       strerror(errno));
                return (oifflags & ~IFF_UP);
        }
 
        if_indextoname(ifindex, ifr.ifr_name);
        if (ioctl(s, SIOCGIFFLAGS, (caddr_t)&ifr) < 0) {
-               syslog(LOG_ERR, "<%s> ioctl:SIOCGIFFLAGS: failed for %s",
+               errorlog("<%s> ioctl:SIOCGIFFLAGS: failed for %s",
                       __func__, ifr.ifr_name);
                close(s);
                return (oifflags & ~IFF_UP);
@@ -228,7 +228,7 @@ lladdropt_fill(struct sockaddr_dl *sdl, struct nd_opt_hdr *ndopt)
                memcpy(addr, LLADDR(sdl), ETHER_ADDR_LEN);
                break;
        default:
-               syslog(LOG_ERR, "<%s> unsupported link type(%d)",
+               errorlog("<%s> unsupported link type(%d)",
                    __func__, sdl->sdl_type);
                exit(1);
        }
@@ -265,7 +265,7 @@ get_next_msg(char *buf, char *lim, int ifindex, size_t *lenp, int filter)
             rtm = (struct rt_msghdr *)(((char *)rtm) + rtm->rtm_msglen)) {
                /* just for safety */
                if (!rtm->rtm_msglen) {
-                       syslog(LOG_WARNING, "<%s> rtm_msglen is 0 "
+                       errorlog("<%s> rtm_msglen is 0 "
                                "(buf=%p lim=%p rtm=%p)", __func__,
                                buf, lim, rtm);
                        break;
@@ -484,59 +484,71 @@ get_iflist(char **buf, size_t *size)
        mib[5] = 0;
 
        if (sysctl(mib, 6, NULL, size, NULL, 0) < 0) {
-               syslog(LOG_ERR, "<%s> sysctl: iflist size get failed",
+               errorlog("<%s> sysctl: iflist size get failed",
                       __func__);
                exit(1);
        }
        if ((*buf = malloc(*size)) == NULL) {
-               syslog(LOG_ERR, "<%s> malloc failed", __func__);
+               errorlog("<%s> malloc failed", __func__);
                exit(1);
        }
        if (sysctl(mib, 6, *buf, size, NULL, 0) < 0) {
-               syslog(LOG_ERR, "<%s> sysctl: iflist get failed",
+               errorlog("<%s> sysctl: iflist get failed",
                       __func__);
                exit(1);
        }
        return;
 }
 
+struct if_msghdr *
+get_interface_entry(int if_index)
+{
+       struct ifinfo *ifi = NULL;
+       struct if_msghdr *ifm = NULL;
+
+       TAILQ_FOREACH(ifi, &ifilist, ifi_next) {
+               if (if_index == ifi->ifm->ifm_index) {
+                       ifm = ifi->ifm;
+                       break;
+               }
+       }
+       return ifm;
+}
+
 /*
  * alloc buffer and parse if_msghdrs block passed as arg,
  * and init the buffer as list of pointers ot each of the if_msghdr.
  */
 static void
-parse_iflist(struct if_msghdr ***ifmlist_p, char *buf, size_t bufsize)
+parse_iflist(char *buf, size_t bufsize)
 {
-       int iflentry_size, malloc_size;
        struct if_msghdr *ifm;
        struct ifa_msghdr *ifam;
        char *lim;
 
-       /*
-        * Estimate least size of an iflist entry, to be obtained from kernel.
-        * Should add sizeof(sockaddr) ??
-        */
-       iflentry_size = sizeof(struct if_msghdr);
-       /* roughly estimate max list size of pointers to each if_msghdr */
-       malloc_size = (bufsize/iflentry_size) * sizeof(size_t);
-       if ((*ifmlist_p = (struct if_msghdr **)malloc(malloc_size)) == NULL) {
-               syslog(LOG_ERR, "<%s> malloc failed", __func__);
-               exit(1);
-       }
-
        lim = buf + bufsize;
        for (ifm = (struct if_msghdr *)buf; ifm < (struct if_msghdr *)lim;) {
                if (ifm->ifm_msglen == 0) {
-                       syslog(LOG_WARNING, "<%s> ifm_msglen is 0 "
+                       errorlog("<%s> ifm_msglen is 0 "
                               "(buf=%p lim=%p ifm=%p)", __func__,
                               buf, lim, ifm);
                        return;
                }
 
                if (ifm->ifm_type == RTM_IFINFO) {
-                       (*ifmlist_p)[ifm->ifm_index] = ifm;
+                       struct ifinfo *ifi = NULL;
+
+                       if (get_interface_entry(ifm->ifm_index) != NULL) {
+                               debuglog("Interface entry is already present for "
+                                   "interface index: %d. Skipping.", ifm->ifm_index);
+                               continue;
+                       }
+
+                       ELM_MALLOC(ifi, exit(1));
+                       ifi->ifm = ifm;
+                       TAILQ_INSERT_TAIL(&ifilist, ifi, ifi_next);
                } else {
-                       syslog(LOG_ERR, "out of sync parsing NET_RT_IFLIST\n"
+                       errorlog("out of sync parsing NET_RT_IFLIST\n"
                               "expected %d, got %d\n msglen = %d\n"
                               "buf:%p, ifm:%p, lim:%p\n",
                               RTM_IFINFO, ifm->ifm_type, ifm->ifm_msglen,
@@ -550,7 +562,7 @@ parse_iflist(struct if_msghdr ***ifmlist_p, char *buf, size_t bufsize)
                        ((char *)ifam + ifam->ifam_msglen)) {
                        /* just for safety */
                        if (!ifam->ifam_msglen) {
-                               syslog(LOG_WARNING, "<%s> ifa_msglen is 0 "
+                               errorlog("<%s> ifa_msglen is 0 "
                                       "(buf=%p lim=%p ifam=%p)", __func__,
                                       buf, lim, ifam);
                                return;
@@ -562,18 +574,31 @@ parse_iflist(struct if_msghdr ***ifmlist_p, char *buf, size_t bufsize)
        }
 }
 
+static void
+purge_iflist()
+{
+       struct ifinfo *ifi = NULL;
+       if (!TAILQ_EMPTY(&ifilist)) {
+               while ((ifi = TAILQ_FIRST(&ifilist)) != NULL) {
+                       TAILQ_REMOVE(&ifilist, ifi, ifi_next);
+                       free(ifi);
+               }
+       }
+}
+
 void
 init_iflist()
 {
+       purge_iflist();
+
        if (ifblock) {
                free(ifblock);
                ifblock_size = 0;
        }
-       if (iflist)
-               free(iflist);
+
        /* get iflist block from kernel */
        get_iflist(&ifblock, &ifblock_size);
 
        /* make list of pointers to each if_msghdr */
-       parse_iflist(&iflist, ifblock, ifblock_size);
+       parse_iflist(ifblock, ifblock_size);
 }
index 32c70ae8bc971ed59c3617f204ad4a5a21489b13..e733d633c590b81f23dec5fd8e27eb0cd98fc89d 100644 (file)
@@ -31,7 +31,6 @@
 
 #define RTADV_TYPE2BITMASK(type) (0x1 << type)
 
-extern struct if_msghdr **iflist;
 extern size_t ifblock_size;
 extern char *ifblock;
 
@@ -55,3 +54,11 @@ int ifmsg_type(char *);
 int rtmsg_len(char *);
 int ifmsg_len(char *);
 void init_iflist(void);
+
+struct  ifinfo {
+       TAILQ_ENTRY(ifinfo)     ifi_next;
+       struct if_msghdr *              ifm;
+};
+
+struct if_msghdr *get_interface_entry(int if_index);
+
index bdac431deda9c31db49f1f2062c63af917b1d57b..ae04a5577622e774830efb5f6f21b245a115df55 100644 (file)
@@ -46,7 +46,6 @@
 #include <errno.h>
 #include <string.h>
 #include <stdlib.h>
-#include <syslog.h>
 #include "rtadvd.h"
 #include "rrenum.h"
 #include "if.h"
@@ -84,7 +83,7 @@ rr_pco_check(int len, struct rr_pco_match *rpm)
        /* rpm->rpm_len must be (4N * 3) as router-renum-05.txt */
        if ((rpm->rpm_len - 3) < 0 || /* must be at least 3 */
            (rpm->rpm_len - 3) & 0x3) { /* must be multiple of 4 */
-               syslog(LOG_WARNING, "<%s> rpm_len %d is not 4N * 3",
+               errorlog("<%s> rpm_len %d is not 4N * 3",
                       __func__, rpm->rpm_len);
                return 1;
        }
@@ -95,13 +94,13 @@ rr_pco_check(int len, struct rr_pco_match *rpm)
        case RPM_PCO_SETGLOBAL:
                break;
        default:
-               syslog(LOG_WARNING, "<%s> unknown rpm_code %d", __func__,
+               errorlog("<%s> unknown rpm_code %d", __func__,
                       rpm->rpm_code);
                return 1;
        }
        /* rpm->rpm_matchlen must be 0 to 128 inclusive */
        if (rpm->rpm_matchlen > 128) {
-               syslog(LOG_WARNING, "<%s> rpm_matchlen %d is over 128",
+               errorlog("<%s> rpm_matchlen %d is over 128",
                       __func__, rpm->rpm_matchlen);
                return 1;
        }
@@ -124,7 +123,7 @@ rr_pco_check(int len, struct rr_pco_match *rpm)
                 *  (rpu_uselen + rpu_keeplen > 0)
                 */
                if (checklen > 128) {
-                       syslog(LOG_WARNING, "<%s> sum of rpu_uselen %d and"
+                       errorlog("<%s> sum of rpu_uselen %d and"
                               " rpu_keeplen %d is %d(over 128)",
                               __func__, rpu->rpu_uselen,
                               rpu->rpu_keeplen,
@@ -162,7 +161,7 @@ do_use_prefix(int len, struct rr_pco_match *rpm,
                irr->irr_useprefix.sin6_addr = in6addr_any;
                if (ioctl(s, rrcmd2pco[rpm->rpm_code], (caddr_t)irr) < 0 &&
                    errno != EADDRNOTAVAIL)
-                       syslog(LOG_ERR, "<%s> ioctl: %s", __func__,
+                       errorlog("<%s> ioctl: %s", __func__,
                               strerror(errno));
                return;
        }
@@ -194,7 +193,7 @@ do_use_prefix(int len, struct rr_pco_match *rpm,
 
                if (ioctl(s, rrcmd2pco[rpm->rpm_code], (caddr_t)irr) < 0 &&
                    errno != EADDRNOTAVAIL)
-                       syslog(LOG_ERR, "<%s> ioctl: %s", __func__,
+                       errorlog("<%s> ioctl: %s", __func__,
                               strerror(errno));
 
                /* very adhoc: should be rewritten */
@@ -247,7 +246,7 @@ do_pco(struct icmp6_router_renum *rr, int len, struct rr_pco_match *rpm)
                return 1;
 
        if (s == -1 && (s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
-               syslog(LOG_ERR, "<%s> socket: %s", __func__,
+               errorlog("<%s> socket: %s", __func__,
                       strerror(errno));
                exit(1);
        }
@@ -262,12 +261,17 @@ do_pco(struct icmp6_router_renum *rr, int len, struct rr_pco_match *rpm)
        irr.irr_matchprefix.sin6_addr = rpm->rpm_prefix;
 
        while (if_indextoname(++ifindex, irr.irr_name)) {
+        struct if_msghdr * ifm = get_interface_entry(ifindex);
+        if (ifm == NULL) {
+            debuglog("Couldn't find interface entry for %d. Skipping.", ifindex);
+            continue;
+        }
                /*
                 * if ICMP6_RR_FLAGS_FORCEAPPLY(A flag) is 0 and IFF_UP is off,
                 * the interface is not applied
                 */
                if ((rr->rr_flags & ICMP6_RR_FLAGS_FORCEAPPLY) == 0 &&
-                   (iflist[ifindex]->ifm_flags & IFF_UP) == 0)
+                   (ifm->ifm_flags & IFF_UP) == 0)
                        continue;
                /* TODO: interface scope check */
                do_use_prefix(len, rpm, &irr, ifindex);
@@ -275,7 +279,7 @@ do_pco(struct icmp6_router_renum *rr, int len, struct rr_pco_match *rpm)
        if (errno == ENXIO)
                return 0;
        else if (errno) {
-               syslog(LOG_ERR, "<%s> if_indextoname: %s", __func__,
+               errorlog("<%s> if_indextoname: %s", __func__,
                       strerror(errno));
                return 1;
        }
@@ -306,7 +310,7 @@ do_rr(int len, struct icmp6_router_renum *rr)
                rpm = (struct rr_pco_match *)cp;
                if (len < sizeof(struct rr_pco_match)) {
                    tooshort:
-                       syslog(LOG_ERR, "<%s> pkt too short. left len = %d. "
+                       errorlog("<%s> pkt too short. left len = %d. "
                               "gabage at end of pkt?", __func__, len);
                        return 1;
                }
@@ -315,7 +319,7 @@ do_rr(int len, struct icmp6_router_renum *rr)
                        goto tooshort;
 
                if (do_pco(rr, rpmlen, rpm)) {
-                       syslog(LOG_WARNING, "<%s> invalid PCO", __func__);
+                       errorlog("<%s> invalid PCO", __func__);
                        goto next;
                }
 
@@ -341,7 +345,7 @@ rr_command_check(int len, struct icmp6_router_renum *rr, struct in6_addr *from,
        /* rr_command length check */
        if (len < (sizeof(struct icmp6_router_renum) +
                   sizeof(struct rr_pco_match))) {
-               syslog(LOG_ERR, "<%s> rr_command len %d is too short",
+               errorlog("<%s> rr_command len %d is too short",
                       __func__, len);
                return 1;
        }
@@ -349,7 +353,7 @@ rr_command_check(int len, struct icmp6_router_renum *rr, struct in6_addr *from,
        /* destination check. only for multicast. omit unicast check. */
        if (IN6_IS_ADDR_MULTICAST(dst) && !IN6_IS_ADDR_MC_LINKLOCAL(dst) &&
            !IN6_IS_ADDR_MC_SITELOCAL(dst)) {
-               syslog(LOG_ERR, "<%s> dst mcast addr %s is illegal",
+               errorlog("<%s> dst mcast addr %s is illegal",
                       __func__,
                       inet_ntop(AF_INET6, dst, ntopbuf, INET6_ADDRSTRLEN));
                return 1;
@@ -357,8 +361,7 @@ rr_command_check(int len, struct icmp6_router_renum *rr, struct in6_addr *from,
 
        /* seqnum and segnum check */
        if (rro.rro_seqnum > rr->rr_seqnum) {
-               syslog(LOG_WARNING,
-                      "<%s> rcvd old seqnum %d from %s",
+               errorlog("<%s> rcvd old seqnum %d from %s",
                       __func__, (u_int32_t)ntohl(rr->rr_seqnum),
                       inet_ntop(AF_INET6, from, ntopbuf, INET6_ADDRSTRLEN));
                return 1;
@@ -367,8 +370,7 @@ rr_command_check(int len, struct icmp6_router_renum *rr, struct in6_addr *from,
            (rr->rr_flags & ICMP6_RR_FLAGS_TEST) == 0 &&
            RR_ISSET_SEGNUM(rro.rro_segnum_bits, rr->rr_segnum)) {
                if ((rr->rr_flags & ICMP6_RR_FLAGS_REQRESULT) != 0)
-                       syslog(LOG_WARNING,
-                              "<%s> rcvd duped segnum %d from %s",
+                       errorlog("<%s> rcvd duped segnum %d from %s",
                               __func__, rr->rr_segnum,
                               inet_ntop(AF_INET6, from, ntopbuf,
                                         INET6_ADDRSTRLEN));
@@ -410,7 +412,7 @@ rr_command_input(int len, struct icmp6_router_renum *rr,
        return;
 
     failed:
-       syslog(LOG_ERR, "<%s> received RR was invalid", __func__);
+       errorlog("<%s> received RR was invalid", __func__);
        return;
 }
 
@@ -420,8 +422,7 @@ rr_input(int len, struct icmp6_router_renum *rr, struct in6_pktinfo *pi,
 {
        char ntopbuf[2][INET6_ADDRSTRLEN], ifnamebuf[IFNAMSIZ];
 
-       syslog(LOG_DEBUG,
-              "<%s> RR received from %s to %s on %s",
+       debuglog("<%s> RR received from %s to %s on %s",
               __func__,
               inet_ntop(AF_INET6, &from->sin6_addr,
                         ntopbuf[0], INET6_ADDRSTRLEN),
@@ -430,8 +431,7 @@ rr_input(int len, struct icmp6_router_renum *rr, struct in6_pktinfo *pi,
 
        /* packet validation based on Section 4.1 of RFC2894 */
        if (len < sizeof(struct icmp6_router_renum)) {
-               syslog(LOG_NOTICE,
-                      "<%s>: RR short message (size %d) from %s to %s on %s",
+               noticelog("<%s>: RR short message (size %d) from %s to %s on %s",
                       __func__, len,
                       inet_ntop(AF_INET6, &from->sin6_addr,
                                 ntopbuf[0], INET6_ADDRSTRLEN),
@@ -450,8 +450,7 @@ rr_input(int len, struct icmp6_router_renum *rr, struct in6_pktinfo *pi,
         */
        if (IN6_IS_ADDR_MULTICAST(&pi->ipi6_addr) &&
            !IN6_ARE_ADDR_EQUAL(&in6a_site_allrouters, &pi->ipi6_addr)) {
-               syslog(LOG_NOTICE,
-                      "<%s>: RR message with invalid destination (%s) "
+               noticelog("<%s>: RR message with invalid destination (%s) "
                       "from %s on %s",
                       __func__,
                       inet_ntop(AF_INET6, &dst, ntopbuf[0], INET6_ADDRSTRLEN),
@@ -475,7 +474,7 @@ rr_input(int len, struct icmp6_router_renum *rr, struct in6_pktinfo *pi,
                /* TODO: sequence number reset */
                break;
        default:
-               syslog(LOG_ERR, "<%s> received unknown code %d",
+               errorlog("<%s> received unknown code %d",
                       __func__, rr->rr_code);
                break;
 
index 69ebe9ab0689bdc6c4512269474c106de723cab6..27429de62e555219224dac9214261406944d3fcb 100644 (file)
@@ -125,8 +125,7 @@ Print debugging information.
 .It Fl D
 Even more debugging information is printed.
 .It Fl f
-Foreground mode (useful when debugging).
-Log messages will be dumped to stderr when this option is specified.
+This option is now deprecated and ignored.
 .It Fl F
 Specify an alternative file in which to dump internal states when
 .Nm
index 7ca027df4ab11e0c87b3349ced0aeb1dbd122c3a..43373bb7bc64924625e35397bf4ad2c8bb5af6c7 100644 (file)
@@ -2,6 +2,7 @@
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
+ * Copyright (C) 2011 Hiroki Sato <hrs@FreeBSD.org>
  * All rights reserved.
  * 
  * Redistribution and use in source and binary forms, with or without
@@ -54,7 +55,6 @@
 #include <libutil.h>
 #include <string.h>
 #include <stdlib.h>
-#include <syslog.h>
 #include "rtadvd.h"
 #include "rrenum.h"
 #include "advcap.h"
@@ -85,10 +85,10 @@ int rtsock = -1;
 int accept_rr = 0;
 int dflag = 0, sflag = 0;
 int so_traffic_class = SO_TC_CTL;      /* use control class, by default */
-
 char *conffile = NULL;
 
 struct rainfo *ralist = NULL;
+
 struct nd_optlist {
        struct nd_optlist *next;
        struct nd_opt_hdr *opt;
@@ -153,7 +153,7 @@ main(argc, argv)
        int maxfd = 0;
        struct timeval *timeout;
        int i, ch;
-       int fflag = 0, logopt;
+       int fflag = 0;
        pid_t pid, otherpid;
 
        /* get command line options and arguments */
@@ -200,17 +200,6 @@ main(argc, argv)
                exit(1);
        }
 
-       logopt = LOG_NDELAY | LOG_PID;
-       if (fflag)
-               logopt |= LOG_PERROR;
-       openlog("rtadvd", logopt, LOG_DAEMON);
-
-       /* set log level */
-       if (dflag == 0)
-               (void)setlogmask(LOG_UPTO(LOG_ERR));
-       if (dflag == 1)
-               (void)setlogmask(LOG_UPTO(LOG_INFO));
-
        /* timer initialization */
        rtadvd_timer_init();
 
@@ -233,8 +222,7 @@ main(argc, argv)
                if (errno == EEXIST)
                        errx(1, "%s already running, pid: %d",
                            getprogname(), otherpid);
-               syslog(LOG_ERR,
-                   "<%s> failed to open the pid log file, run anyway.",
+               errorlog("<%s> failed to open the pid log file, run anyway.",
                    __func__);
        }
 
@@ -289,14 +277,12 @@ main(argc, argv)
                timeout = rtadvd_check_timer();
 
                if (timeout != NULL) {
-                       syslog(LOG_DEBUG,
-                           "<%s> set timer to %ld:%ld. waiting for "
+                       debuglog("<%s> set timer to %ld:%ld. waiting for "
                            "inputs or timeout", __func__,
                            (long int)timeout->tv_sec,
                            (long int)timeout->tv_usec);
                } else {
-                       syslog(LOG_DEBUG,
-                           "<%s> there's no timer. waiting for inputs",
+                       debuglog("<%s> there's no timer. waiting for inputs",
                            __func__);
                }
 
@@ -304,7 +290,7 @@ main(argc, argv)
                    timeout)) < 0) {
                        /* EINTR would occur upon SIGUSR1 for status dump */
                        if (errno != EINTR)
-                               syslog(LOG_ERR, "<%s> select: %s",
+                               errorlog( "<%s> select: %s",
                                    __func__, strerror(errno));
                        continue;
                }
@@ -340,7 +326,7 @@ die()
        const int retrans = MAX_FINAL_RTR_ADVERTISEMENTS;
 
        if (dflag > 1) {
-               syslog(LOG_DEBUG, "<%s> cease to be an advertising router\n",
+               debuglog("<%s> cease to be an advertising router\n",
                    __func__);
        }
 
@@ -375,7 +361,7 @@ rtmsg_input()
 
        n = read(rtsock, msg, sizeof(msg));
        if (dflag > 1) {
-               syslog(LOG_DEBUG, "<%s> received a routing message "
+               debuglog( "<%s> received a routing message "
                    "(type = %d, len = %d)", __func__, rtmsg_type(msg), n);
        }
        if (n > rtmsg_len(msg)) {
@@ -384,8 +370,7 @@ rtmsg_input()
                 * a routing socket.
                 */
                if (dflag > 1)
-                       syslog(LOG_DEBUG,
-                           "<%s> received data length is larger than "
+                       debuglog("<%s> received data length is larger than "
                            "1st routing message len. multiple messages? "
                            "read %d bytes, but 1st msg len = %d",
                            __func__, n, rtmsg_len(msg));
@@ -397,6 +382,7 @@ rtmsg_input()
 
        lim = msg + n;
        for (next = msg; next < lim; next += len) {
+        struct if_msghdr * ifm = NULL;
                int oldifflags;
 
                next = get_next_msg(next, lim, 0, &len,
@@ -423,8 +409,7 @@ rtmsg_input()
                default:
                        /* should not reach here */
                        if (dflag > 1) {
-                               syslog(LOG_DEBUG,
-                                      "<%s:%d> unknown rtmsg %d on %s",
+                               debuglog("<%s:%d> unknown rtmsg %d on %s",
                                       __func__, __LINE__, type,
                                       if_indextoname(ifindex, ifname));
                        }
@@ -433,21 +418,25 @@ rtmsg_input()
 
                if ((rai = if_indextorainfo(ifindex)) == NULL) {
                        if (dflag > 1) {
-                               syslog(LOG_DEBUG,
-                                      "<%s> route changed on "
+                               debuglog("<%s> route changed on "
                                       "non advertising interface(%s)",
                                       __func__,
                                       if_indextoname(ifindex, ifname));
                        }
                        continue;
                }
-               oldifflags = iflist[ifindex]->ifm_flags;
+        ifm = get_interface_entry(ifindex);
+        if (ifm == NULL) {
+            debuglog("Couldn't find interface entry for %d. Skipping.", ifindex);
+            continue;
+        }
+               oldifflags = ifm->ifm_flags;
 
                switch (type) {
                case RTM_ADD:
                        /* init ifflags because it may have changed */
-                       iflist[ifindex]->ifm_flags =
-                           if_getflags(ifindex, iflist[ifindex]->ifm_flags);
+                       ifm->ifm_flags =
+                           if_getflags(ifindex, ifm->ifm_flags);
 
                        if (sflag)
                                break;  /* we aren't interested in prefixes  */
@@ -457,7 +446,7 @@ rtmsg_input()
                        /* sanity check for plen */
                        /* as RFC2373, prefixlen is at least 4 */
                        if (plen < 4 || plen > 127) {
-                               syslog(LOG_INFO, "<%s> new interface route's"
+                               infolog("<%s> new interface route's"
                                    "plen %d is invalid for a prefix",
                                    __func__, plen);
                                break;
@@ -472,8 +461,7 @@ rtmsg_input()
                                        update_prefix(prefix);
                                        prefixchange = 1;
                                } else if (dflag > 1) {
-                                       syslog(LOG_DEBUG,
-                                           "<%s> new prefix(%s/%d) "
+                                       debuglog("<%s> new prefix(%s/%d) "
                                            "added on %s, "
                                            "but it was already in list",
                                            __func__,
@@ -488,8 +476,7 @@ rtmsg_input()
                        break;
                case RTM_DELETE:
                        /* init ifflags because it may have changed */
-                       iflist[ifindex]->ifm_flags =
-                           if_getflags(ifindex, iflist[ifindex]->ifm_flags);
+                       ifm->ifm_flags = if_getflags(ifindex, ifm->ifm_flags);
 
                        if (sflag)
                                break;
@@ -499,8 +486,7 @@ rtmsg_input()
                        /* sanity check for plen */
                        /* as RFC2373, prefixlen is at least 4 */
                        if (plen < 4 || plen > 127) {
-                               syslog(LOG_INFO,
-                                   "<%s> deleted interface route's "
+                               infolog("<%s> deleted interface route's "
                                    "plen %d is invalid for a prefix",
                                    __func__, plen);
                                break;
@@ -508,8 +494,7 @@ rtmsg_input()
                        prefix = find_prefix(rai, addr, plen);
                        if (prefix == NULL) {
                                if (dflag > 1) {
-                                       syslog(LOG_DEBUG,
-                                           "<%s> prefix(%s/%d) was "
+                                       debuglog("<%s> prefix(%s/%d) was "
                                            "deleted on %s, "
                                            "but it was not in list",
                                            __func__,
@@ -525,17 +510,15 @@ rtmsg_input()
                case RTM_NEWADDR:
                case RTM_DELADDR:
                        /* init ifflags because it may have changed */
-                       iflist[ifindex]->ifm_flags =
-                           if_getflags(ifindex, iflist[ifindex]->ifm_flags);
+                       ifm->ifm_flags = if_getflags(ifindex, ifm->ifm_flags);
                        break;
                case RTM_IFINFO:
-                       iflist[ifindex]->ifm_flags = get_ifm_flags(next);
+                       ifm->ifm_flags = get_ifm_flags(next);
                        break;
                default:
                        /* should not reach here */
                        if (dflag > 1) {
-                               syslog(LOG_DEBUG,
-                                   "<%s:%d> unknown rtmsg %d on %s",
+                               debuglog("<%s:%d> unknown rtmsg %d on %s",
                                    __func__, __LINE__, type,
                                    if_indextoname(ifindex, ifname));
                        }
@@ -544,15 +527,13 @@ rtmsg_input()
 
                /* check if an interface flag is changed */
                if ((oldifflags & IFF_UP) && /* UP to DOWN */
-                   !(iflist[ifindex]->ifm_flags & IFF_UP)) {
-                       syslog(LOG_INFO,
-                           "<%s> interface %s becomes down. stop timer.",
+                   !(ifm->ifm_flags & IFF_UP)) {
+                       infolog("<%s> interface %s becomes down. stop timer.",
                            __func__, rai->ifname);
                        rtadvd_remove_timer(&rai->timer);
                } else if (!(oldifflags & IFF_UP) && /* DOWN to UP */
-                        (iflist[ifindex]->ifm_flags & IFF_UP)) {
-                       syslog(LOG_INFO,
-                           "<%s> interface %s becomes up. restart timer.",
+                        (ifm->ifm_flags & IFF_UP)) {
+                       infolog("<%s> interface %s becomes up. restart timer.",
                            __func__, rai->ifname);
 
                        rai->initcounter = 0; /* reset the counter */
@@ -562,7 +543,7 @@ rtmsg_input()
                        ra_timer_update((void *)rai, &rai->timer->tm);
                        rtadvd_set_timer(&rai->timer->tm, rai->timer);
                } else if (prefixchange &&
-                   (iflist[ifindex]->ifm_flags & IFF_UP)) {
+                   (ifm->ifm_flags & IFF_UP)) {
                        /*
                         * An advertised prefix has been added or invalidated.
                         * Will notice the change in a short delay.
@@ -589,6 +570,7 @@ rtadvd_input()
        struct in6_pktinfo *pi = NULL;
        char ntopbuf[INET6_ADDRSTRLEN], ifnamebuf[IFNAMSIZ];
        struct in6_addr dst = in6addr_any;
+    struct if_msghdr *ifm = NULL;
 
        /*
         * Get message. We reset msg_controllen since the field could
@@ -616,36 +598,33 @@ rtadvd_input()
                        hlimp = (int *)CMSG_DATA(cm);
        }
        if (ifindex == 0) {
-               syslog(LOG_ERR,
-                      "<%s> failed to get receiving interface",
+               errorlog("<%s> failed to get receiving interface",
                       __func__);
                return;
        }
        if (hlimp == NULL) {
-               syslog(LOG_ERR,
-                      "<%s> failed to get receiving hop limit",
+               errorlog("<%s> failed to get receiving hop limit",
                       __func__);
                return;
        }
 
+    ifm = get_interface_entry(pi->ipi6_ifindex);
        /*
         * If we happen to receive data on an interface which is now gone
         * or down, just discard the data.
         */
-       if (iflist[pi->ipi6_ifindex] == NULL ||
-           (iflist[pi->ipi6_ifindex]->ifm_flags & IFF_UP) == 0) {
-               syslog(LOG_INFO,
-                      "<%s> received data on a disabled interface (%s)",
+       if (ifm == NULL ||
+           (ifm->ifm_flags & IFF_UP) == 0) {
+               infolog("<%s> received data on a disabled interface (%s)",
                       __func__,
-                      (iflist[pi->ipi6_ifindex] == NULL) ? "[gone]" :
+                      (ifm == NULL) ? "[gone]" :
                            if_indextoname(pi->ipi6_ifindex, ifnamebuf));
                return;
        }
 
 #ifdef OLDRAWSOCKET
        if (i < sizeof(struct ip6_hdr) + sizeof(struct icmp6_hdr)) {
-               syslog(LOG_ERR,
-                      "<%s> packet size(%d) is too short",
+               errorlog("<%s> packet size(%d) is too short",
                       __func__, i);
                return;
        }
@@ -654,8 +633,7 @@ rtadvd_input()
        icp = (struct icmp6_hdr *)(ip + 1); /* XXX: ext. hdr? */
 #else
        if (i < sizeof(struct icmp6_hdr)) {
-               syslog(LOG_ERR,
-                      "<%s> packet size(%d) is too short",
+               errorlog("<%s> packet size(%d) is too short",
                       __func__, i);
                return;
        }
@@ -671,8 +649,7 @@ rtadvd_input()
                 *      but we can't completely rely on them.
                 */
                if (*hlimp != 255) {
-                       syslog(LOG_NOTICE,
-                           "<%s> RS with invalid hop limit(%d) "
+                       noticelog("<%s> RS with invalid hop limit(%d) "
                            "received from %s on %s",
                            __func__, *hlimp,
                            inet_ntop(AF_INET6, &rcvfrom.sin6_addr, ntopbuf,
@@ -681,8 +658,7 @@ rtadvd_input()
                        return;
                }
                if (icp->icmp6_code) {
-                       syslog(LOG_NOTICE,
-                           "<%s> RS with invalid ICMP6 code(%d) "
+                       noticelog("<%s> RS with invalid ICMP6 code(%d) "
                            "received from %s on %s",
                            __func__, icp->icmp6_code,
                            inet_ntop(AF_INET6, &rcvfrom.sin6_addr, ntopbuf,
@@ -691,8 +667,7 @@ rtadvd_input()
                        return;
                }
                if (i < sizeof(struct nd_router_solicit)) {
-                       syslog(LOG_NOTICE,
-                           "<%s> RS from %s on %s does not have enough "
+                       noticelog("<%s> RS from %s on %s does not have enough "
                            "length (len = %d)",
                            __func__,
                            inet_ntop(AF_INET6, &rcvfrom.sin6_addr, ntopbuf,
@@ -708,8 +683,7 @@ rtadvd_input()
                 * XXX: there's a same dilemma as above... 
                 */
                if (*hlimp != 255) {
-                       syslog(LOG_NOTICE,
-                           "<%s> RA with invalid hop limit(%d) "
+                       noticelog("<%s> RA with invalid hop limit(%d) "
                            "received from %s on %s",
                            __func__, *hlimp,
                            inet_ntop(AF_INET6, &rcvfrom.sin6_addr, ntopbuf,
@@ -718,8 +692,7 @@ rtadvd_input()
                        return;
                }
                if (icp->icmp6_code) {
-                       syslog(LOG_NOTICE,
-                           "<%s> RA with invalid ICMP6 code(%d) "
+                       noticelog("<%s> RA with invalid ICMP6 code(%d) "
                            "received from %s on %s",
                            __func__, icp->icmp6_code,
                            inet_ntop(AF_INET6, &rcvfrom.sin6_addr, ntopbuf,
@@ -728,8 +701,7 @@ rtadvd_input()
                        return;
                }
                if (i < sizeof(struct nd_router_advert)) {
-                       syslog(LOG_NOTICE,
-                           "<%s> RA from %s on %s does not have enough "
+                       noticelog("<%s> RA from %s on %s does not have enough "
                            "length (len = %d)",
                            __func__,
                            inet_ntop(AF_INET6, &rcvfrom.sin6_addr, ntopbuf,
@@ -741,7 +713,7 @@ rtadvd_input()
                break;
        case ICMP6_ROUTER_RENUMBERING:
                if (accept_rr == 0) {
-                       syslog(LOG_ERR, "<%s> received a router renumbering "
+                       errorlog("<%s> received a router renumbering "
                            "message, but not allowed to be accepted",
                            __func__);
                        break;
@@ -756,7 +728,7 @@ rtadvd_input()
                 * could receive message after opening the socket and
                 * before setting ICMP6 type filter(see sock_open()).
                 */
-               syslog(LOG_ERR, "<%s> invalid icmp type(%d)",
+               errorlog("<%s> invalid icmp type(%d)",
                    __func__, icp->icmp6_type);
                return;
        }
@@ -773,7 +745,7 @@ rs_input(int len, struct nd_router_solicit *rs,
        struct rainfo *ra;
        struct soliciter *sol;
 
-       syslog(LOG_DEBUG,
+       debuglog(
               "<%s> RS received from %s on %s",
               __func__,
               inet_ntop(AF_INET6, &from->sin6_addr,
@@ -785,8 +757,7 @@ rs_input(int len, struct nd_router_solicit *rs,
        if (nd6_options((struct nd_opt_hdr *)(rs + 1),
                        len - sizeof(struct nd_router_solicit),
                        &ndopts, NDOPT_FLAG_SRCLINKADDR)) {
-               syslog(LOG_INFO,
-                      "<%s> ND option check failed for an RS from %s on %s",
+               infolog("<%s> ND option check failed for an RS from %s on %s",
                       __func__,
                       inet_ntop(AF_INET6, &from->sin6_addr,
                                 ntopbuf, INET6_ADDRSTRLEN),
@@ -801,8 +772,7 @@ rs_input(int len, struct nd_router_solicit *rs,
         */
        if (IN6_IS_ADDR_UNSPECIFIED(&from->sin6_addr) &&
            ndopts.nd_opts_src_lladdr) {
-               syslog(LOG_INFO,
-                      "<%s> RS from unspecified src on %s has a link-layer"
+               infolog("<%s> RS from unspecified src on %s has a link-layer"
                       " address option",
                       __func__,
                       if_indextoname(pi->ipi6_ifindex, ifnamebuf));
@@ -816,8 +786,7 @@ rs_input(int len, struct nd_router_solicit *rs,
                ra = ra->next;
        }
        if (ra == NULL) {
-               syslog(LOG_INFO,
-                      "<%s> RS received on non advertising interface(%s)",
+               infolog("<%s> RS received on non advertising interface(%s)",
                       __func__,
                       if_indextoname(pi->ipi6_ifindex, ifnamebuf));
                goto done;
@@ -861,6 +830,8 @@ set_short_delay(rai)
        long delay;     /* must not be greater than 1000000 */
        struct timeval interval, now, min_delay, tm_tmp, *rest;
 
+       if (rai->timer == NULL)
+               return;
        /*
         * Compute a random delay. If the computed value
         * corresponds to a time later than the time the next
@@ -877,7 +848,7 @@ set_short_delay(rai)
        interval.tv_usec = delay;
        rest = rtadvd_timer_rest(rai->timer);
        if (TIMEVAL_LT(*rest, interval)) {
-               syslog(LOG_DEBUG, "<%s> random delay is larger than "
+               debuglog("<%s> random delay is larger than "
                    "the rest of the current timer", __func__);
                interval = *rest;
        }
@@ -911,8 +882,7 @@ ra_input(int len, struct nd_router_advert *ra,
        u_int32_t reachabletime, retranstimer, mtu;
        int inconsistent = 0;
 
-       syslog(LOG_DEBUG,
-              "<%s> RA received from %s on %s",
+       debuglog("<%s> RA received from %s on %s",
               __func__,
               inet_ntop(AF_INET6, &from->sin6_addr,
                         ntopbuf, INET6_ADDRSTRLEN),
@@ -924,8 +894,7 @@ ra_input(int len, struct nd_router_advert *ra,
                        len - sizeof(struct nd_router_advert),
                        &ndopts, NDOPT_FLAG_SRCLINKADDR |
                        NDOPT_FLAG_PREFIXINFO | NDOPT_FLAG_MTU)) {
-               syslog(LOG_INFO,
-                      "<%s> ND option check failed for an RA from %s on %s",
+               infolog("<%s> ND option check failed for an RA from %s on %s",
                       __func__,
                       inet_ntop(AF_INET6, &from->sin6_addr,
                                 ntopbuf, INET6_ADDRSTRLEN),
@@ -937,8 +906,7 @@ ra_input(int len, struct nd_router_advert *ra,
         * RA consistency check according to RFC-2461 6.2.7
         */
        if ((rai = if_indextorainfo(pi->ipi6_ifindex)) == 0) {
-               syslog(LOG_INFO,
-                      "<%s> received RA from %s on non-advertising"
+               infolog("<%s> received RA from %s on non-advertising"
                       " interface(%s)",
                       __func__,
                       inet_ntop(AF_INET6, &from->sin6_addr,
@@ -951,8 +919,7 @@ ra_input(int len, struct nd_router_advert *ra,
        /* Cur Hop Limit value */
        if (ra->nd_ra_curhoplimit && rai->hoplimit &&
            ra->nd_ra_curhoplimit != rai->hoplimit) {
-               syslog(LOG_INFO,
-                      "<%s> CurHopLimit inconsistent on %s:"
+               infolog("<%s> CurHopLimit inconsistent on %s:"
                       " %d from %s, %d from us",
                       __func__,
                       rai->ifname,
@@ -965,8 +932,7 @@ ra_input(int len, struct nd_router_advert *ra,
        /* M flag */
        if ((ra->nd_ra_flags_reserved & ND_RA_FLAG_MANAGED) !=
            rai->managedflg) {
-               syslog(LOG_INFO,
-                      "<%s> M flag inconsistent on %s:"
+               infolog("<%s> M flag inconsistent on %s:"
                       " %s from %s, %s from us",
                       __func__,
                       rai->ifname,
@@ -979,8 +945,7 @@ ra_input(int len, struct nd_router_advert *ra,
        /* O flag */
        if ((ra->nd_ra_flags_reserved & ND_RA_FLAG_OTHER) !=
            rai->otherflg) {
-               syslog(LOG_INFO,
-                      "<%s> O flag inconsistent on %s:"
+               infolog("<%s> O flag inconsistent on %s:"
                       " %s from %s, %s from us",
                       __func__,
                       rai->ifname,
@@ -994,8 +959,7 @@ ra_input(int len, struct nd_router_advert *ra,
        reachabletime = ntohl(ra->nd_ra_reachable);
        if (reachabletime && rai->reachabletime &&
            reachabletime != rai->reachabletime) {
-               syslog(LOG_INFO,
-                      "<%s> ReachableTime inconsistent on %s:"
+               infolog("<%s> ReachableTime inconsistent on %s:"
                       " %d from %s, %d from us",
                       __func__,
                       rai->ifname,
@@ -1009,8 +973,7 @@ ra_input(int len, struct nd_router_advert *ra,
        retranstimer = ntohl(ra->nd_ra_retransmit);
        if (retranstimer && rai->retranstimer &&
            retranstimer != rai->retranstimer) {
-               syslog(LOG_INFO,
-                      "<%s> RetranceTimer inconsistent on %s:"
+               infolog("<%s> RetranceTimer inconsistent on %s:"
                       " %d from %s, %d from us",
                       __func__,
                       rai->ifname,
@@ -1024,8 +987,7 @@ ra_input(int len, struct nd_router_advert *ra,
        if (ndopts.nd_opts_mtu) {
                mtu = ntohl(ndopts.nd_opts_mtu->nd_opt_mtu_mtu);
                if (mtu && rai->linkmtu && mtu != rai->linkmtu) {
-                       syslog(LOG_INFO,
-                              "<%s> MTU option value inconsistent on %s:"
+                       infolog("<%s> MTU option value inconsistent on %s:"
                               " %d from %s, %d from us",
                               __func__,
                               rai->ifname, mtu,
@@ -1079,8 +1041,7 @@ prefix_check(struct nd_opt_prefix_info *pinfo,
         * log if the adveritsed prefix has link-local scope(sanity check?)
         */
        if (IN6_IS_ADDR_LINKLOCAL(&pinfo->nd_opt_pi_prefix)) {
-               syslog(LOG_INFO,
-                      "<%s> link-local prefix %s/%d is advertised "
+               infolog("<%s> link-local prefix %s/%d is advertised "
                       "from %s on %s",
                       __func__,
                       inet_ntop(AF_INET6, &pinfo->nd_opt_pi_prefix,
@@ -1093,8 +1054,7 @@ prefix_check(struct nd_opt_prefix_info *pinfo,
 
        if ((pp = find_prefix(rai, &pinfo->nd_opt_pi_prefix,
                              pinfo->nd_opt_pi_prefix_len)) == NULL) {
-               syslog(LOG_INFO,
-                      "<%s> prefix %s/%d from %s on %s is not in our list",
+               infolog("<%s> prefix %s/%d from %s on %s is not in our list",
                       __func__,
                       inet_ntop(AF_INET6, &pinfo->nd_opt_pi_prefix,
                                 prefixbuf, INET6_ADDRSTRLEN),
@@ -1119,8 +1079,7 @@ prefix_check(struct nd_opt_prefix_info *pinfo,
 
                if (!pp->timer && rai->clockskew &&
                    preferred_time - pp->pltimeexpire > rai->clockskew) {
-                       syslog(LOG_INFO,
-                              "<%s> preferred lifetime for %s/%d"
+                       infolog("<%s> preferred lifetime for %s/%d"
                               " (decr. in real time) inconsistent on %s:"
                               " %d from %s, %ld from us",
                               __func__,
@@ -1134,8 +1093,7 @@ prefix_check(struct nd_opt_prefix_info *pinfo,
                        inconsistent++;
                }
        } else if (!pp->timer && preferred_time != pp->preflifetime) {
-               syslog(LOG_INFO,
-                      "<%s> preferred lifetime for %s/%d"
+               infolog("<%s> preferred lifetime for %s/%d"
                       " inconsistent on %s:"
                       " %d from %s, %d from us",
                       __func__,
@@ -1155,8 +1113,7 @@ prefix_check(struct nd_opt_prefix_info *pinfo,
 
                if (!pp->timer && rai->clockskew &&
                    valid_time - pp->vltimeexpire > rai->clockskew) {
-                       syslog(LOG_INFO,
-                              "<%s> valid lifetime for %s/%d"
+                       infolog("<%s> valid lifetime for %s/%d"
                               " (decr. in real time) inconsistent on %s:"
                               " %d from %s, %ld from us",
                               __func__,
@@ -1170,8 +1127,7 @@ prefix_check(struct nd_opt_prefix_info *pinfo,
                        inconsistent++;
                }
        } else if (!pp->timer && valid_time != pp->validlifetime) {
-               syslog(LOG_INFO,
-                      "<%s> valid lifetime for %s/%d"
+               infolog("<%s> valid lifetime for %s/%d"
                       " inconsistent on %s:"
                       " %d from %s, %d from us",
                       __func__,
@@ -1245,31 +1201,30 @@ nd6_options(struct nd_opt_hdr *hdr, int limit,
 
        for (; limit > 0; limit -= optlen) {
                if (limit < sizeof(struct nd_opt_hdr)) {
-                       syslog(LOG_INFO, "<%s> short option header", __func__);
+                       infolog("<%s> short option header", __func__);
                        goto bad;
                }
 
                hdr = (struct nd_opt_hdr *)((caddr_t)hdr + optlen);
                if (hdr->nd_opt_len == 0) {
-                       syslog(LOG_INFO,
-                           "<%s> bad ND option length(0) (type = %d)",
+                       infolog("<%s> bad ND option length(0) (type = %d)",
                            __func__, hdr->nd_opt_type);
                        goto bad;
                }
                optlen = hdr->nd_opt_len << 3;
                if (optlen > limit) {
-                       syslog(LOG_INFO, "<%s> short option", __func__);
+                       infolog("<%s> short option", __func__);
                        goto bad;
                }
 
                if (hdr->nd_opt_type > ND_OPT_MTU) {
-                       syslog(LOG_INFO, "<%s> unknown ND option(type %d)",
+                       infolog("<%s> unknown ND option(type %d)",
                            __func__, hdr->nd_opt_type);
                        continue;
                }
 
                if ((ndopt_flags[hdr->nd_opt_type] & optflags) == 0) {
-                       syslog(LOG_INFO, "<%s> unexpected ND option(type %d)",
+                       infolog("<%s> unexpected ND option(type %d)",
                            __func__, hdr->nd_opt_type);
                        continue;
                }
@@ -1282,7 +1237,7 @@ nd6_options(struct nd_opt_hdr *hdr, int limit,
                    (optlen != sizeof(struct nd_opt_mtu))) ||
                    ((hdr->nd_opt_type == ND_OPT_PREFIX_INFORMATION &&
                    optlen != sizeof(struct nd_opt_prefix_info)))) {
-                       syslog(LOG_INFO, "<%s> invalid option length",
+                       infolog("<%s> invalid option length",
                            __func__);
                        continue;
                }
@@ -1294,8 +1249,7 @@ nd6_options(struct nd_opt_hdr *hdr, int limit,
                case ND_OPT_SOURCE_LINKADDR:
                case ND_OPT_MTU:
                        if (ndopts->nd_opt_array[hdr->nd_opt_type]) {
-                               syslog(LOG_INFO,
-                                   "<%s> duplicated ND option (type = %d)",
+                               infolog("<%s> duplicated ND option (type = %d)",
                                    __func__, hdr->nd_opt_type);
                        }
                        ndopts->nd_opt_array[hdr->nd_opt_type] = hdr;
@@ -1310,7 +1264,7 @@ nd6_options(struct nd_opt_hdr *hdr, int limit,
                                continue;
                        }
                        if ((pfxlist = malloc(sizeof(*pfxlist))) == NULL) {
-                               syslog(LOG_ERR, "<%s> can't allocate memory",
+                               errorlog("<%s> can't allocate memory",
                                    __func__);
                                goto bad;
                        }
@@ -1359,7 +1313,7 @@ sock_open()
                                CMSG_SPACE(sizeof(int));
        rcvcmsgbuf = (u_char *)malloc(rcvcmsgbuflen);
        if (rcvcmsgbuf == NULL) {
-               syslog(LOG_ERR, "<%s> not enough core", __func__);
+               errorlog("<%s> not enough core", __func__);
                exit(1);
        }
 
@@ -1367,12 +1321,12 @@ sock_open()
                                CMSG_SPACE(sizeof(int));
        sndcmsgbuf = (u_char *)malloc(sndcmsgbuflen);
        if (sndcmsgbuf == NULL) {
-               syslog(LOG_ERR, "<%s> not enough core", __func__);
+               errorlog("<%s> not enough core", __func__);
                exit(1);
        }
 
        if ((sock = socket(AF_INET6, SOCK_RAW, IPPROTO_ICMPV6)) < 0) {
-               syslog(LOG_ERR, "<%s> socket: %s", __func__,
+               errorlog("<%s> socket: %s", __func__,
                       strerror(errno));
                exit(1);
        }
@@ -1385,14 +1339,14 @@ sock_open()
 #ifdef IPV6_RECVPKTINFO
        if (setsockopt(sock, IPPROTO_IPV6, IPV6_RECVPKTINFO, &on,
                       sizeof(on)) < 0) {
-               syslog(LOG_ERR, "<%s> IPV6_RECVPKTINFO: %s",
+               errorlog("<%s> IPV6_RECVPKTINFO: %s",
                       __func__, strerror(errno));
                exit(1);
        }
 #else  /* old adv. API */
        if (setsockopt(sock, IPPROTO_IPV6, IPV6_PKTINFO, &on,
                       sizeof(on)) < 0) {
-               syslog(LOG_ERR, "<%s> IPV6_PKTINFO: %s",
+               errorlog("<%s> IPV6_PKTINFO: %s",
                       __func__, strerror(errno));
                exit(1);
        }
@@ -1403,14 +1357,14 @@ sock_open()
 #ifdef IPV6_RECVHOPLIMIT
        if (setsockopt(sock, IPPROTO_IPV6, IPV6_RECVHOPLIMIT, &on,
                       sizeof(on)) < 0) {
-               syslog(LOG_ERR, "<%s> IPV6_RECVHOPLIMIT: %s",
+               errorlog( "<%s> IPV6_RECVHOPLIMIT: %s",
                       __func__, strerror(errno));
                exit(1);
        }
 #else  /* old adv. API */
        if (setsockopt(sock, IPPROTO_IPV6, IPV6_HOPLIMIT, &on,
                       sizeof(on)) < 0) {
-               syslog(LOG_ERR, "<%s> IPV6_HOPLIMIT: %s",
+               errorlog("<%s> IPV6_HOPLIMIT: %s",
                       __func__, strerror(errno));
                exit(1);
        }
@@ -1423,7 +1377,7 @@ sock_open()
                ICMP6_FILTER_SETPASS(ICMP6_ROUTER_RENUMBERING, &filt);
        if (setsockopt(sock, IPPROTO_ICMPV6, ICMP6_FILTER, &filt,
                       sizeof(filt)) < 0) {
-               syslog(LOG_ERR, "<%s> IICMP6_FILTER: %s",
+               errorlog("<%s> IICMP6_FILTER: %s",
                       __func__, strerror(errno));
                exit(1);
        }
@@ -1434,7 +1388,7 @@ sock_open()
        if (inet_pton(AF_INET6, ALLROUTERS_LINK,
                      &mreq.ipv6mr_multiaddr.s6_addr)
            != 1) {
-               syslog(LOG_ERR, "<%s> inet_pton failed(library bug?)",
+               errorlog("<%s> inet_pton failed(library bug?)",
                       __func__);
                exit(1);
        }
@@ -1442,7 +1396,7 @@ sock_open()
                mreq.ipv6mr_interface = ra->ifindex;
                if (setsockopt(sock, IPPROTO_IPV6, IPV6_JOIN_GROUP, &mreq,
                               sizeof(mreq)) < 0) {
-                       syslog(LOG_ERR, "<%s> IPV6_JOIN_GROUP(link) on %s: %s",
+                       errorlog("<%s> IPV6_JOIN_GROUP(link) on %s: %s",
                               __func__, ra->ifname, strerror(errno));
                        exit(1);
                }
@@ -1456,7 +1410,7 @@ sock_open()
        if (accept_rr) {
                if (inet_pton(AF_INET6, ALLROUTERS_SITE,
                              &in6a_site_allrouters) != 1) {
-                       syslog(LOG_ERR, "<%s> inet_pton failed(library bug?)",
+                       errorlog("<%s> inet_pton failed(library bug?)",
                               __func__);
                        exit(1);
                }
@@ -1464,8 +1418,7 @@ sock_open()
                if (mcastif) {
                        if ((mreq.ipv6mr_interface = if_nametoindex(mcastif))
                            == 0) {
-                               syslog(LOG_ERR,
-                                      "<%s> invalid interface: %s",
+                               errorlog("<%s> invalid interface: %s",
                                       __func__, mcastif);
                                exit(1);
                        }
@@ -1473,8 +1426,7 @@ sock_open()
                        mreq.ipv6mr_interface = ralist->ifindex;
                if (setsockopt(sock, IPPROTO_IPV6, IPV6_JOIN_GROUP,
                               &mreq, sizeof(mreq)) < 0) {
-                       syslog(LOG_ERR,
-                              "<%s> IPV6_JOIN_GROUP(site) on %s: %s",
+                       errorlog("<%s> IPV6_JOIN_GROUP(site) on %s: %s",
                               __func__,
                               mcastif ? mcastif : ralist->ifname,
                               strerror(errno));
@@ -1507,8 +1459,7 @@ static void
 rtsock_open()
 {
        if ((rtsock = socket(PF_ROUTE, SOCK_RAW, 0)) < 0) {
-               syslog(LOG_ERR,
-                      "<%s> socket: %s", __func__, strerror(errno));
+               errorlog("<%s> socket: %s", __func__, strerror(errno));
                exit(1);
        }
 }
@@ -1534,10 +1485,11 @@ struct rainfo *rainfo;
        struct cmsghdr *cm;
        struct in6_pktinfo *pi;
        struct soliciter *sol, *nextsol;
+    struct if_msghdr *ifm = get_interface_entry(rainfo->ifindex);
 
-       if (iflist[rainfo->ifindex] == NULL ||
-           (iflist[rainfo->ifindex]->ifm_flags & IFF_UP) == 0) {
-               syslog(LOG_DEBUG, "<%s> %s is not up, skip sending RA",
+       if (ifm == NULL ||
+           (ifm->ifm_flags & IFF_UP) == 0) {
+               debuglog("<%s> %s is not up, skip sending RA",
                       __func__, rainfo->ifname);
                return;
        }
@@ -1568,15 +1520,14 @@ struct rainfo *rainfo;
                memcpy(CMSG_DATA(cm), &hoplimit, sizeof(int));
        }
 
-       syslog(LOG_DEBUG,
-              "<%s> send RA on %s, # of waitings = %d",
+       debuglog("<%s> send RA on %s, # of waitings = %d",
               __func__, rainfo->ifname, rainfo->waiting); 
 
        i = sendmsg(sock, &sndmhdr, 0);
 
        if (i < 0 || i != rainfo->ra_datalen)  {
                if (i < 0) {
-                       syslog(LOG_ERR, "<%s> sendmsg on %s: %s",
+                       errorlog("<%s> sendmsg on %s: %s",
                               __func__, rainfo->ifname,
                               strerror(errno));
                }
@@ -1616,8 +1567,7 @@ ra_timeout(void *data)
        /* if necessary, reconstruct the packet. */
 #endif
 
-       syslog(LOG_DEBUG,
-              "<%s> RA timer on %s is expired",
+       debuglog("<%s> RA timer on %s is expired",
               __func__, rai->ifname);
 
        ra_output(rai);
@@ -1656,8 +1606,7 @@ ra_timer_update(void *data, struct timeval *tm)
        tm->tv_sec = rai->initcounter == 0 ? 0 : interval;
        tm->tv_usec = 0;
 
-       syslog(LOG_DEBUG,
-              "<%s> RA timer on %s is set to %ld:%ld",
+       debuglog("<%s> RA timer on %s is set to %ld:%ld",
               __func__, rai->ifname,
               (long int)tm->tv_sec, (long int)tm->tv_usec);
 
index d019b1945955a5ce84c23c658a0f43e072c823e5..7e4ca7663a56aa18b83f76855c2653212afafee4 100644 (file)
@@ -2,6 +2,7 @@
 
 /*
  * Copyright (C) 1998 WIDE Project.
+ * Copyright (C) 2011 Hiroki Sato <hrs@FreeBSD.org>
  * All rights reserved.
  * 
  * Redistribution and use in source and binary forms, with or without
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  */
+#include "rtadvd_logging.h"
+
+#define        ELM_MALLOC(p, error_action)                                     \
+       do {                                                            \
+               p = malloc(sizeof(*p));                                 \
+               if (p == NULL) {                                        \
+                       errorlog("<%s> malloc failed: %s",      \
+                           __func__, strerror(errno));                 \
+                       error_action;                                   \
+               }                                                       \
+               memset(p, 0, sizeof(*p));                               \
+       } while(0)
 
 #define        ROUTEINFO       1
 
diff --git a/rtadvd.tproj/rtadvd_logging.c b/rtadvd.tproj/rtadvd_logging.c
new file mode 100644 (file)
index 0000000..90dec08
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2019 Apple Inc. All rights reserved.
+ *
+ * This document is the property of Apple Inc.
+ * It is considered confidential and proprietary.
+ *
+ * This document may not be reproduced or transmitted in any form,
+ * in whole or in part, without the express written permission of
+ * Apple Inc.
+ */
+#include <assert.h>
+#include <os/log_private.h>
+
+#define kRtadvdLoggerID        "com.apple.rtadvd"
+static os_log_t rtadvdLogger = NULL;                        /* Handle for Logger */
+
+static boolean_t rtadvd_logger_create(void);
+
+static boolean_t
+rtadvd_logger_create(void)
+{
+    assert(rtadvdLogger == NULL);
+    rtadvdLogger = os_log_create(kRtadvdLoggerID, "daemon");
+
+    if (rtadvdLogger == NULL) {
+        os_log_error(OS_LOG_DEFAULT, "Couldn't create os log object");
+    }
+
+    return (rtadvdLogger != NULL);
+}
+
+void
+rtadvdLog(int level, const char *format, ...)
+{
+    va_list args;
+
+    if (rtadvdLogger == NULL && !rtadvd_logger_create()) {
+        return;
+    }
+
+    va_start(args, format);
+    os_log_with_args(rtadvdLogger, level, format, args, __builtin_return_address(0));
+    va_end(args);
+    return;
+}
diff --git a/rtadvd.tproj/rtadvd_logging.h b/rtadvd.tproj/rtadvd_logging.h
new file mode 100644 (file)
index 0000000..11273e6
--- /dev/null
@@ -0,0 +1,24 @@
+/*
+ * Copyright (c) 2019 Apple Inc. All rights reserved.
+ *
+ * This document is the property of Apple Inc.
+ * It is considered confidential and proprietary.
+ *
+ * This document may not be reproduced or transmitted in any form,
+ * in whole or in part, without the express written permission of
+ * Apple Inc.
+ */
+#include <os/log.h>
+extern void rtadvdLog(int level, const char *format, ...);
+
+#define errorlog(__format, ...)            \
+rtadvdLog(OS_LOG_TYPE_DEFAULT, __format, ## __VA_ARGS__)
+
+#define noticelog(__format, ...)            \
+rtadvdLog(OS_LOG_TYPE_DEFAULT, __format, ## __VA_ARGS__)
+
+#define infolog(__format, ...)            \
+rtadvdLog(OS_LOG_TYPE_INFO, __format, ## __VA_ARGS__)
+
+#define debuglog(__format, ...)            \
+rtadvdLog(OS_LOG_TYPE_DEBUG, __format, ## __VA_ARGS__)
index b03b4bf2012cb4a3e329d0f18d05dc2ace46d436..3134fc03fc0a78b8811ac8bfc8536d4b3976812a 100644 (file)
 #include <sys/time.h>
 
 #include <unistd.h>
-#include <syslog.h>
 #include <stdlib.h>
 #include <string.h>
 #include <search.h>
 #include "timer.h"
+#include "rtadvd_logging.h"
 
 static struct rtadvd_timer timer_head;
 
@@ -63,16 +63,14 @@ rtadvd_add_timer(struct rtadvd_timer *(*timeout)(void *),
        struct rtadvd_timer *newtimer;
 
        if ((newtimer = malloc(sizeof(*newtimer))) == NULL) {
-               syslog(LOG_ERR,
-                      "<%s> can't allocate memory", __func__);
+               errorlog("<%s> can't allocate memory", __func__);
                exit(1);
        }
 
        memset(newtimer, 0, sizeof(*newtimer));
 
        if (timeout == NULL) {
-               syslog(LOG_ERR,
-                      "<%s> timeout function unspecified", __func__);
+               errorlog("<%s> timeout function unspecified", __func__);
                exit(1);
        }
        newtimer->expire = timeout;
@@ -161,8 +159,7 @@ rtadvd_timer_rest(struct rtadvd_timer *timer)
 
        gettimeofday(&now, NULL);
        if (TIMEVAL_LEQ(timer->tm, now)) {
-               syslog(LOG_DEBUG,
-                      "<%s> a timer must be expired, but not yet",
+               debuglog("<%s> a timer must be expired, but not yet",
                       __func__);
                returnval.tv_sec = returnval.tv_usec = 0;
        }