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 */,
#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
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 (;;) {
/*
- * Copyright (c) 2009-2012 Apple Inc. All rights reserved.
+ * Copyright (c) 2009-2017 Apple Inc. All rights reserved.
*
* @APPLE_OSREFERENCE_LICENSE_HEADER_START@
*
/*
* 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
#include <arpa/inet.h>
#include <stdio.h>
-#include <syslog.h>
#include <errno.h>
#include <string.h>
#include <search.h>
int rdnss_length;
int dnssl_length;
char tbuf[BUFSIZ];
- struct rainfo *tmp;
+ struct rainfo *rai;
long val;
int64_t val64;
char buf[BUFSIZ];
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) {
/* 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);
}
*/
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;
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);
}
} 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);
}
* 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);
}
* 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];
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);
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);
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);
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);
}
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);
/* route information */
#ifdef ROUTEINFO
- tmp->routes = 0;
+ rai->routes = 0;
for (i = -1; i < MAXROUTE; i++) {
struct rtinfo *rti;
char entbuf[256], oentbuf[256];
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);
}
*/
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);
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);
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__);
}
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);
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);
#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--) {
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);
}
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);
/* 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;
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);
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);
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);
}
/* 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++;
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;
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);
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);
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);
/* 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;
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);
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;
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,
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);
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;
/* 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);
}
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);
#include <time.h>
#include <stdio.h>
#include <stdarg.h>
-#include <syslog.h>
#include <string.h>
#include <errno.h>
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 */
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;
}
#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)
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);
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);
}
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;
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,
((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;
}
}
+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);
}
#define RTADV_TYPE2BITMASK(type) (0x1 << type)
-extern struct if_msghdr **iflist;
extern size_t ifblock_size;
extern char *ifblock;
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);
+
#include <errno.h>
#include <string.h>
#include <stdlib.h>
-#include <syslog.h>
#include "rtadvd.h"
#include "rrenum.h"
#include "if.h"
/* 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;
}
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;
}
* (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,
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;
}
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 */
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);
}
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);
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;
}
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;
}
goto tooshort;
if (do_pco(rr, rpmlen, rpm)) {
- syslog(LOG_WARNING, "<%s> invalid PCO", __func__);
+ errorlog("<%s> invalid PCO", __func__);
goto next;
}
/* 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;
}
/* 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;
/* 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;
(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));
return;
failed:
- syslog(LOG_ERR, "<%s> received RR was invalid", __func__);
+ errorlog("<%s> received RR was invalid", __func__);
return;
}
{
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),
/* 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),
*/
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),
/* 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;
.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
/*
* 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
#include <libutil.h>
#include <string.h>
#include <stdlib.h>
-#include <syslog.h>
#include "rtadvd.h"
#include "rrenum.h"
#include "advcap.h"
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;
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 */
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();
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__);
}
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__);
}
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;
}
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__);
}
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)) {
* 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));
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,
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));
}
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 */
/* 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;
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__,
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;
/* 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;
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__,
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));
}
/* 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 */
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.
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
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;
}
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;
}
* 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,
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,
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,
* 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,
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,
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,
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;
* 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;
}
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,
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),
*/
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));
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;
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
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;
}
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),
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),
* 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,
/* 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,
/* 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,
/* 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,
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,
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,
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,
* 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,
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),
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__,
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__,
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__,
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__,
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;
}
(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;
}
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;
continue;
}
if ((pfxlist = malloc(sizeof(*pfxlist))) == NULL) {
- syslog(LOG_ERR, "<%s> can't allocate memory",
+ errorlog("<%s> can't allocate memory",
__func__);
goto bad;
}
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);
}
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);
}
#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);
}
#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);
}
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);
}
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);
}
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);
}
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);
}
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);
}
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));
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);
}
}
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;
}
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));
}
/* 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);
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);
/*
* 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
--- /dev/null
+/*
+ * 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;
+}
--- /dev/null
+/*
+ * 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__)
#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;
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;
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;
}