Change the meaning of the 'D' flag to print errors to stderr instead of
syslog(3) and exit if poll(2) fails (intended to be used with unit-tests).
This commit is contained in:
parent
27ef7ea778
commit
4c18e5f405
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: advcap.c,v 1.16 2015/11/11 07:48:41 ozaki-r Exp $ */
|
||||
/* $NetBSD: advcap.c,v 1.17 2017/11/06 15:15:04 christos Exp $ */
|
||||
/* $KAME: advcap.c,v 1.11 2003/05/19 09:46:50 keiichi Exp $ */
|
||||
|
||||
/*
|
||||
|
@ -48,6 +48,8 @@
|
|||
#include "pathnames.h"
|
||||
#include "prog_ops.h"
|
||||
|
||||
#include "logit.h"
|
||||
|
||||
#ifndef __UNCONST
|
||||
#define __UNCONST(a) ((void *)(unsigned long)(const void *)(a))
|
||||
#endif
|
||||
|
@ -137,7 +139,7 @@ getent(char *bp, char *name, char *cp)
|
|||
tf = open(RM = cp, O_RDONLY);
|
||||
}
|
||||
if (tf < 0) {
|
||||
syslog(LOG_INFO, "<%s> open: %m", __func__);
|
||||
logit(LOG_INFO, "<%s> open: %m", __func__);
|
||||
return (-2);
|
||||
}
|
||||
for (;;) {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: config.c,v 1.36 2017/02/27 05:41:36 ozaki-r Exp $ */
|
||||
/* $NetBSD: config.c,v 1.37 2017/11/06 15:15:04 christos Exp $ */
|
||||
/* $KAME: config.c,v 1.93 2005/10/17 14:40:02 suz Exp $ */
|
||||
|
||||
/*
|
||||
|
@ -67,6 +67,7 @@
|
|||
#include "timer.h"
|
||||
#include "if.h"
|
||||
#include "config.h"
|
||||
#include "logit.h"
|
||||
#include "prog_ops.h"
|
||||
|
||||
#ifndef __arraycount
|
||||
|
@ -180,24 +181,24 @@ getconfig(const char *intface, int exithard)
|
|||
do { \
|
||||
p = calloc(1, sizeof(*p)); \
|
||||
if (p == NULL) { \
|
||||
syslog(LOG_ERR, "<%s> calloc failed: %m", \
|
||||
logit(LOG_ERR, "<%s> calloc failed: %m", \
|
||||
__func__); \
|
||||
goto errexit; \
|
||||
} \
|
||||
} while(/*CONSTCOND*/0)
|
||||
|
||||
if (if_nametoindex(intface) == 0) {
|
||||
syslog(LOG_INFO, "<%s> interface %s not found, ignoring",
|
||||
logit(LOG_INFO, "<%s> interface %s not found, ignoring",
|
||||
__func__, intface);
|
||||
return;
|
||||
}
|
||||
|
||||
syslog(LOG_DEBUG, "<%s> loading configuration for interface %s",
|
||||
logit(LOG_DEBUG, "<%s> loading configuration for interface %s",
|
||||
__func__, intface);
|
||||
|
||||
if ((stat = agetent(tbuf, intface)) <= 0) {
|
||||
memset(tbuf, 0, sizeof(tbuf));
|
||||
syslog(LOG_INFO,
|
||||
logit(LOG_INFO,
|
||||
"<%s> %s isn't defined in the configuration file"
|
||||
" or the configuration file doesn't exist."
|
||||
" Treat it as default",
|
||||
|
@ -223,7 +224,7 @@ getconfig(const char *intface, int exithard)
|
|||
tmp->advlinkopt = 1;
|
||||
if (tmp->advlinkopt) {
|
||||
if ((tmp->sdl = if_nametosdl(intface)) == NULL) {
|
||||
syslog(LOG_ERR,
|
||||
logit(LOG_ERR,
|
||||
"<%s> can't get information of %s",
|
||||
__func__, intface);
|
||||
goto errexit;
|
||||
|
@ -232,7 +233,7 @@ getconfig(const char *intface, int exithard)
|
|||
} else {
|
||||
tmp->ifindex = if_nametoindex(intface);
|
||||
if (tmp->ifindex == 0) {
|
||||
syslog(LOG_ERR,
|
||||
logit(LOG_ERR,
|
||||
"<%s> can't get information of %s",
|
||||
__func__, intface);
|
||||
goto errexit;
|
||||
|
@ -242,7 +243,7 @@ getconfig(const char *intface, int exithard)
|
|||
strlcpy(tmp->ifname, intface, sizeof(tmp->ifname));
|
||||
if ((tmp->phymtu = if_getmtu(intface)) == 0) {
|
||||
tmp->phymtu = IPV6_MMTU;
|
||||
syslog(LOG_WARNING,
|
||||
logit(LOG_WARNING,
|
||||
"<%s> can't get interface mtu of %s. Treat as %d",
|
||||
__func__, intface, IPV6_MMTU);
|
||||
}
|
||||
|
@ -252,7 +253,7 @@ getconfig(const char *intface, int exithard)
|
|||
*/
|
||||
MAYHAVE(val, "maxinterval", DEF_MAXRTRADVINTERVAL);
|
||||
if (val < MIN_MAXINTERVAL || val > MAX_MAXINTERVAL) {
|
||||
syslog(LOG_ERR,
|
||||
logit(LOG_ERR,
|
||||
"<%s> maxinterval (%d) on %s is invalid "
|
||||
"(must be between %u and %u)", __func__, val,
|
||||
intface, MIN_MAXINTERVAL, MAX_MAXINTERVAL);
|
||||
|
@ -261,7 +262,7 @@ getconfig(const char *intface, int exithard)
|
|||
tmp->maxinterval = val;
|
||||
MAYHAVE(val, "mininterval", tmp->maxinterval/3);
|
||||
if (val < MIN_MININTERVAL || val > (tmp->maxinterval * 3) / 4) {
|
||||
syslog(LOG_ERR,
|
||||
logit(LOG_ERR,
|
||||
"<%s> mininterval (%d) on %s is invalid "
|
||||
"(must be between %u and %d)",
|
||||
__func__, val, intface, MIN_MININTERVAL,
|
||||
|
@ -283,7 +284,7 @@ getconfig(const char *intface, int exithard)
|
|||
val |= ND_RA_FLAG_RTPREF_HIGH;
|
||||
if (strchr(flagstr, 'l')) {
|
||||
if ((val & ND_RA_FLAG_RTPREF_HIGH)) {
|
||||
syslog(LOG_ERR, "<%s> the \'h\' and \'l\'"
|
||||
logit(LOG_ERR, "<%s> the \'h\' and \'l\'"
|
||||
" router flags are exclusive", __func__);
|
||||
goto errexit;
|
||||
}
|
||||
|
@ -300,14 +301,14 @@ getconfig(const char *intface, int exithard)
|
|||
#endif
|
||||
tmp->rtpref = val & ND_RA_FLAG_RTPREF_MASK;
|
||||
if (tmp->rtpref == ND_RA_FLAG_RTPREF_RSV) {
|
||||
syslog(LOG_ERR, "<%s> invalid router preference (%02x) on %s",
|
||||
logit(LOG_ERR, "<%s> invalid router preference (%02x) on %s",
|
||||
__func__, tmp->rtpref, intface);
|
||||
goto errexit;
|
||||
}
|
||||
|
||||
MAYHAVE(val, "rltime", DEF_ADVROUTERLIFETIME);
|
||||
if (val && (val < tmp->maxinterval || val > MAXROUTERLIFETIME)) {
|
||||
syslog(LOG_ERR,
|
||||
logit(LOG_ERR,
|
||||
"<%s> router lifetime (%d) on %s is invalid "
|
||||
"(must be 0 or between %d and %d)",
|
||||
__func__, val, intface,
|
||||
|
@ -323,7 +324,7 @@ getconfig(const char *intface, int exithard)
|
|||
* explicitly set zero. (see also the above section)
|
||||
*/
|
||||
if (val && forwarding == 0) {
|
||||
syslog(LOG_ERR,
|
||||
logit(LOG_ERR,
|
||||
"<%s> non zero router lifetime is specified for %s, "
|
||||
"which must not be allowed for hosts. you must "
|
||||
"change router lifetime or enable IPv6 forwarding.",
|
||||
|
@ -334,7 +335,7 @@ getconfig(const char *intface, int exithard)
|
|||
|
||||
MAYHAVE(val, "rtime", DEF_ADVREACHABLETIME);
|
||||
if (val < 0 || val > MAXREACHABLETIME) {
|
||||
syslog(LOG_ERR,
|
||||
logit(LOG_ERR,
|
||||
"<%s> reachable time (%d) on %s is invalid "
|
||||
"(must be no greater than %d)",
|
||||
__func__, val, intface, MAXREACHABLETIME);
|
||||
|
@ -344,14 +345,14 @@ getconfig(const char *intface, int exithard)
|
|||
|
||||
MAYHAVE(val64, "retrans", DEF_ADVRETRANSTIMER);
|
||||
if (val64 < 0 || val64 > 0xffffffff) {
|
||||
syslog(LOG_ERR, "<%s> retrans time (%lld) on %s out of range",
|
||||
logit(LOG_ERR, "<%s> retrans time (%lld) on %s out of range",
|
||||
__func__, (long long)val64, intface);
|
||||
goto errexit;
|
||||
}
|
||||
tmp->retranstimer = (uint32_t)val64;
|
||||
|
||||
if (agetnum("hapref") != -1 || agetnum("hatime") != -1) {
|
||||
syslog(LOG_ERR,
|
||||
logit(LOG_ERR,
|
||||
"<%s> mobile-ip6 configuration not supported",
|
||||
__func__);
|
||||
goto errexit;
|
||||
|
@ -377,7 +378,7 @@ getconfig(const char *intface, int exithard)
|
|||
|
||||
/* allocate memory to store prefix information */
|
||||
if ((pfx = calloc(1, sizeof(*pfx))) == NULL) {
|
||||
syslog(LOG_ERR,
|
||||
logit(LOG_ERR,
|
||||
"<%s> can't allocate memory: %m",
|
||||
__func__);
|
||||
goto errexit;
|
||||
|
@ -390,20 +391,20 @@ getconfig(const char *intface, int exithard)
|
|||
pfx->origin = PREFIX_FROM_CONFIG;
|
||||
|
||||
if (inet_pton(AF_INET6, addr, &pfx->prefix) != 1) {
|
||||
syslog(LOG_ERR,
|
||||
logit(LOG_ERR,
|
||||
"<%s> inet_pton failed for %s",
|
||||
__func__, addr);
|
||||
goto errexit;
|
||||
}
|
||||
if (IN6_IS_ADDR_MULTICAST(&pfx->prefix)) {
|
||||
syslog(LOG_ERR,
|
||||
logit(LOG_ERR,
|
||||
"<%s> multicast prefix (%s) must "
|
||||
"not be advertised on %s",
|
||||
__func__, addr, intface);
|
||||
goto errexit;
|
||||
}
|
||||
if (IN6_IS_ADDR_LINKLOCAL(&pfx->prefix))
|
||||
syslog(LOG_NOTICE,
|
||||
logit(LOG_NOTICE,
|
||||
"<%s> link-local prefix (%s) will be"
|
||||
" advertised on %s",
|
||||
__func__, addr, intface);
|
||||
|
@ -411,7 +412,7 @@ getconfig(const char *intface, int exithard)
|
|||
makeentry(entbuf, sizeof(entbuf), i, "prefixlen");
|
||||
MAYHAVE(val, entbuf, 64);
|
||||
if (val < 0 || val > 128) {
|
||||
syslog(LOG_ERR, "<%s> prefixlen (%d) for %s "
|
||||
logit(LOG_ERR, "<%s> prefixlen (%d) for %s "
|
||||
"on %s out of range",
|
||||
__func__, val, addr, intface);
|
||||
goto errexit;
|
||||
|
@ -435,7 +436,7 @@ getconfig(const char *intface, int exithard)
|
|||
makeentry(entbuf, sizeof(entbuf), i, "vltime");
|
||||
MAYHAVE(val64, entbuf, DEF_ADVVALIDLIFETIME);
|
||||
if (val64 < 0 || val64 > 0xffffffff) {
|
||||
syslog(LOG_ERR, "<%s> vltime (%lld) for "
|
||||
logit(LOG_ERR, "<%s> vltime (%lld) for "
|
||||
"%s/%d on %s is out of range",
|
||||
__func__, (long long)val64,
|
||||
addr, pfx->prefixlen, intface);
|
||||
|
@ -454,7 +455,7 @@ getconfig(const char *intface, int exithard)
|
|||
makeentry(entbuf, sizeof(entbuf), i, "pltime");
|
||||
MAYHAVE(val64, entbuf, DEF_ADVPREFERREDLIFETIME);
|
||||
if (val64 < 0 || val64 > 0xffffffff) {
|
||||
syslog(LOG_ERR,
|
||||
logit(LOG_ERR,
|
||||
"<%s> pltime (%lld) for %s/%d on %s "
|
||||
"is out of range",
|
||||
__func__, (long long)val64,
|
||||
|
@ -476,7 +477,7 @@ getconfig(const char *intface, int exithard)
|
|||
|
||||
MAYHAVE(val64, "mtu", 0);
|
||||
if (val64 < 0 || val64 > 0xffffffff) {
|
||||
syslog(LOG_ERR,
|
||||
logit(LOG_ERR,
|
||||
"<%s> mtu (%" PRIi64 ") on %s out of range",
|
||||
__func__, val64, intface);
|
||||
goto errexit;
|
||||
|
@ -490,7 +491,7 @@ getconfig(const char *intface, int exithard)
|
|||
tmp->linkmtu = tmp->phymtu;
|
||||
}
|
||||
else if (tmp->linkmtu < IPV6_MMTU || tmp->linkmtu > tmp->phymtu) {
|
||||
syslog(LOG_ERR,
|
||||
logit(LOG_ERR,
|
||||
"<%s> advertised link mtu (%d) on %s is invalid (must "
|
||||
"be between least MTU (%d) and physical link MTU (%d)",
|
||||
__func__, tmp->linkmtu, intface,
|
||||
|
@ -504,13 +505,13 @@ getconfig(const char *intface, int exithard)
|
|||
int s;
|
||||
|
||||
if ((s = prog_socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
|
||||
syslog(LOG_ERR, "<%s> socket: %m", __func__);
|
||||
logit(LOG_ERR, "<%s> socket: %m", __func__);
|
||||
goto errexit;
|
||||
}
|
||||
memset(&ndi, 0, sizeof(ndi));
|
||||
strncpy(ndi.ifname, intface, IFNAMSIZ);
|
||||
if (prog_ioctl(s, SIOCGIFINFO_IN6, &ndi) < 0) {
|
||||
syslog(LOG_INFO, "<%s> ioctl:SIOCGIFINFO_IN6 at %s: %m",
|
||||
logit(LOG_INFO, "<%s> ioctl:SIOCGIFINFO_IN6 at %s: %m",
|
||||
__func__, intface);
|
||||
}
|
||||
|
||||
|
@ -519,7 +520,7 @@ getconfig(const char *intface, int exithard)
|
|||
ndi.ndi.retrans = tmp->retranstimer;
|
||||
ndi.ndi.basereachable = tmp->reachabletime;
|
||||
if (prog_ioctl(s, SIOCSIFINFO_IN6, &ndi) < 0) {
|
||||
syslog(LOG_INFO, "<%s> ioctl:SIOCSIFINFO_IN6 at %s: %m",
|
||||
logit(LOG_INFO, "<%s> ioctl:SIOCSIFINFO_IN6 at %s: %m",
|
||||
__func__, intface);
|
||||
}
|
||||
prog_close(s);
|
||||
|
@ -551,7 +552,7 @@ getconfig(const char *intface, int exithard)
|
|||
TAILQ_INSERT_TAIL(&tmp->route, rti, next);
|
||||
|
||||
if (inet_pton(AF_INET6, addr, &rti->prefix) != 1) {
|
||||
syslog(LOG_ERR, "<%s> inet_pton failed for %s",
|
||||
logit(LOG_ERR, "<%s> inet_pton failed for %s",
|
||||
__func__, addr);
|
||||
goto errexit;
|
||||
}
|
||||
|
@ -564,14 +565,14 @@ getconfig(const char *intface, int exithard)
|
|||
*/
|
||||
MAYHAVE(val64, entbuf, DEF_ADVVALIDLIFETIME);
|
||||
if (IN6_IS_ADDR_MULTICAST(&rti->prefix)) {
|
||||
syslog(LOG_ERR,
|
||||
logit(LOG_ERR,
|
||||
"<%s> multicast route (%s) must "
|
||||
"not be advertised on %s",
|
||||
__func__, addr, intface);
|
||||
goto errexit;
|
||||
}
|
||||
if (IN6_IS_ADDR_LINKLOCAL(&rti->prefix)) {
|
||||
syslog(LOG_NOTICE,
|
||||
logit(LOG_NOTICE,
|
||||
"<%s> link-local route (%s) will "
|
||||
"be advertised on %s",
|
||||
__func__, addr, intface);
|
||||
|
@ -592,7 +593,7 @@ getconfig(const char *intface, int exithard)
|
|||
val = 64;
|
||||
}
|
||||
if (val < 0 || val > 128) {
|
||||
syslog(LOG_ERR, "<%s> prefixlen (%d) for %s on %s "
|
||||
logit(LOG_ERR, "<%s> prefixlen (%d) for %s on %s "
|
||||
"out of range",
|
||||
__func__, val, addr, intface);
|
||||
goto errexit;
|
||||
|
@ -606,7 +607,7 @@ getconfig(const char *intface, int exithard)
|
|||
val |= ND_RA_FLAG_RTPREF_HIGH;
|
||||
if (strchr(flagstr, 'l')) {
|
||||
if ((val & ND_RA_FLAG_RTPREF_HIGH)) {
|
||||
syslog(LOG_ERR,
|
||||
logit(LOG_ERR,
|
||||
"<%s> the \'h\' and \'l\' route"
|
||||
" preferences are exclusive",
|
||||
__func__);
|
||||
|
@ -627,7 +628,7 @@ getconfig(const char *intface, int exithard)
|
|||
}
|
||||
rti->rtpref = val & ND_RA_FLAG_RTPREF_MASK;
|
||||
if (rti->rtpref == ND_RA_FLAG_RTPREF_RSV) {
|
||||
syslog(LOG_ERR, "<%s> invalid route preference (%02x) "
|
||||
logit(LOG_ERR, "<%s> invalid route preference (%02x) "
|
||||
"for %s/%d on %s",
|
||||
__func__, rti->rtpref, addr,
|
||||
rti->prefixlen, intface);
|
||||
|
@ -656,7 +657,7 @@ getconfig(const char *intface, int exithard)
|
|||
}
|
||||
}
|
||||
if (val64 < 0 || val64 > 0xffffffff) {
|
||||
syslog(LOG_ERR, "<%s> route lifetime (%lld) for "
|
||||
logit(LOG_ERR, "<%s> route lifetime (%lld) for "
|
||||
"%s/%d on %s out of range", __func__,
|
||||
(long long)val64, addr, rti->prefixlen, intface);
|
||||
goto errexit;
|
||||
|
@ -684,7 +685,7 @@ getconfig(const char *intface, int exithard)
|
|||
ELM_MALLOC(rdnsa);
|
||||
TAILQ_INSERT_TAIL(&rdnss->list, rdnsa, next);
|
||||
if (inet_pton(AF_INET6, abuf, &rdnsa->addr) != 1) {
|
||||
syslog(LOG_ERR, "<%s> inet_pton failed for %s",
|
||||
logit(LOG_ERR, "<%s> inet_pton failed for %s",
|
||||
__func__, addr);
|
||||
goto errexit;
|
||||
}
|
||||
|
@ -695,7 +696,7 @@ getconfig(const char *intface, int exithard)
|
|||
if (val64 < tmp->maxinterval ||
|
||||
val64 > tmp->maxinterval * 2)
|
||||
{
|
||||
syslog(LOG_ERR, "<%s> %s (%lld) on %s is invalid",
|
||||
logit(LOG_ERR, "<%s> %s (%lld) on %s is invalid",
|
||||
__func__, entbuf, (long long)val64, intface);
|
||||
goto errexit;
|
||||
}
|
||||
|
@ -731,7 +732,7 @@ getconfig(const char *intface, int exithard)
|
|||
if (val64 < tmp->maxinterval ||
|
||||
val64 > tmp->maxinterval * 2)
|
||||
{
|
||||
syslog(LOG_ERR, "<%s> %s (%lld) on %s is invalid",
|
||||
logit(LOG_ERR, "<%s> %s (%lld) on %s is invalid",
|
||||
__func__, entbuf, (long long)val64, intface);
|
||||
goto errexit;
|
||||
}
|
||||
|
@ -803,7 +804,7 @@ get_prefix(struct rainfo *rai)
|
|||
char ntopbuf[INET6_ADDRSTRLEN];
|
||||
|
||||
if (getifaddrs(&ifap) < 0) {
|
||||
syslog(LOG_ERR,
|
||||
logit(LOG_ERR,
|
||||
"<%s> can't get interface addresses",
|
||||
__func__);
|
||||
exit(1);
|
||||
|
@ -824,7 +825,7 @@ get_prefix(struct rainfo *rai)
|
|||
lim = (unsigned 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 "
|
||||
logit(LOG_ERR, "<%s> failed to get prefixlen "
|
||||
"or prefix is invalid",
|
||||
__func__);
|
||||
exit(1);
|
||||
|
@ -838,7 +839,7 @@ get_prefix(struct rainfo *rai)
|
|||
|
||||
/* allocate memory to store prefix info. */
|
||||
if ((pp = calloc(1, sizeof(*pp))) == NULL) {
|
||||
syslog(LOG_ERR,
|
||||
logit(LOG_ERR,
|
||||
"<%s> can't get allocate buffer for prefix",
|
||||
__func__);
|
||||
exit(1);
|
||||
|
@ -858,10 +859,10 @@ get_prefix(struct rainfo *rai)
|
|||
}
|
||||
if (!inet_ntop(AF_INET6, &pp->prefix, ntopbuf,
|
||||
sizeof(ntopbuf))) {
|
||||
syslog(LOG_ERR, "<%s> inet_ntop failed", __func__);
|
||||
logit(LOG_ERR, "<%s> inet_ntop failed", __func__);
|
||||
exit(1);
|
||||
}
|
||||
syslog(LOG_DEBUG,
|
||||
logit(LOG_DEBUG,
|
||||
"<%s> add %s/%d to prefix list on %s",
|
||||
__func__, ntopbuf, pp->prefixlen, rai->ifname);
|
||||
|
||||
|
@ -905,7 +906,7 @@ add_prefix(struct rainfo *rai, struct in6_prefixreq *ipr)
|
|||
char ntopbuf[INET6_ADDRSTRLEN];
|
||||
|
||||
if ((prefix = calloc(1, sizeof(*prefix))) == NULL) {
|
||||
syslog(LOG_ERR, "<%s> memory allocation failed",
|
||||
logit(LOG_ERR, "<%s> memory allocation failed",
|
||||
__func__);
|
||||
return; /* XXX: error or exit? */
|
||||
}
|
||||
|
@ -921,7 +922,7 @@ add_prefix(struct rainfo *rai, struct in6_prefixreq *ipr)
|
|||
TAILQ_INSERT_TAIL(&rai->prefix, prefix, next);
|
||||
rai->pfxs++;
|
||||
|
||||
syslog(LOG_DEBUG, "<%s> new prefix %s/%d was added on %s",
|
||||
logit(LOG_DEBUG, "<%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);
|
||||
|
@ -947,7 +948,7 @@ delete_prefix(struct prefix *prefix)
|
|||
|
||||
TAILQ_REMOVE(&rai->prefix, prefix, next);
|
||||
rai->pfxs--;
|
||||
syslog(LOG_DEBUG, "<%s> prefix %s/%d was deleted on %s",
|
||||
logit(LOG_DEBUG, "<%s> prefix %s/%d was deleted on %s",
|
||||
__func__, inet_ntop(AF_INET6, &prefix->prefix,
|
||||
ntopbuf, INET6_ADDRSTRLEN),
|
||||
prefix->prefixlen, rai->ifname);
|
||||
|
@ -963,13 +964,13 @@ invalidate_prefix(struct prefix *prefix)
|
|||
struct rainfo *rai = prefix->rainfo;
|
||||
|
||||
if (prefix->timer) { /* sanity check */
|
||||
syslog(LOG_ERR,
|
||||
logit(LOG_ERR,
|
||||
"<%s> assumption failure: timer already exists",
|
||||
__func__);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
syslog(LOG_DEBUG, "<%s> prefix %s/%d was invalidated on %s, "
|
||||
logit(LOG_DEBUG, "<%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);
|
||||
|
@ -977,7 +978,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. "
|
||||
logit(LOG_ERR, "<%s> failed to add a timer for a prefix. "
|
||||
"remove the prefix", __func__);
|
||||
delete_prefix(prefix);
|
||||
}
|
||||
|
@ -1003,13 +1004,13 @@ update_prefix(struct prefix * prefix)
|
|||
struct rainfo *rai = prefix->rainfo;
|
||||
|
||||
if (prefix->timer == NULL) { /* sanity check */
|
||||
syslog(LOG_ERR,
|
||||
logit(LOG_ERR,
|
||||
"<%s> assumption failure: timer does not exist",
|
||||
__func__);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
syslog(LOG_DEBUG, "<%s> prefix %s/%d was re-enabled on %s",
|
||||
logit(LOG_DEBUG, "<%s> prefix %s/%d was re-enabled on %s",
|
||||
__func__, inet_ntop(AF_INET6, &prefix->prefix, ntopbuf,
|
||||
INET6_ADDRSTRLEN), prefix->prefixlen, rai->ifname);
|
||||
|
||||
|
@ -1029,12 +1030,12 @@ init_prefix(struct in6_prefixreq *ipr)
|
|||
int s;
|
||||
|
||||
if ((s = prog_socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
|
||||
syslog(LOG_ERR, "<%s> socket: %m", __func__);
|
||||
logit(LOG_ERR, "<%s> socket: %m", __func__);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (prog_ioctl(s, SIOCGIFPREFIX_IN6, ipr) < 0) {
|
||||
syslog(LOG_INFO, "<%s> ioctl:SIOCGIFPREFIX: %m", __func__);
|
||||
logit(LOG_INFO, "<%s> ioctl:SIOCGIFPREFIX: %m", __func__);
|
||||
|
||||
ipr->ipr_vltime = DEF_ADVVALIDLIFETIME;
|
||||
ipr->ipr_pltime = DEF_ADVPREFERREDLIFETIME;
|
||||
|
@ -1045,7 +1046,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"
|
||||
logit(LOG_WARNING, "<%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,
|
||||
|
@ -1072,7 +1073,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"
|
||||
logit(LOG_ERR, "<%s> Prefix added interface No.%d doesn't"
|
||||
"exist. This should not happen: %m", __func__,
|
||||
ifindex);
|
||||
exit(1);
|
||||
|
@ -1110,7 +1111,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,
|
||||
logit(LOG_INFO,
|
||||
"<%s> link-layer address option has"
|
||||
" null length on %s. Treat as not included.",
|
||||
__func__, rainfo->ifname);
|
||||
|
@ -1142,7 +1143,7 @@ make_packet(struct rainfo *rainfo)
|
|||
|
||||
/* allocate memory for the packet */
|
||||
if ((buf = realloc(rainfo->ra_data, packlen)) == NULL) {
|
||||
syslog(LOG_ERR,
|
||||
logit(LOG_ERR,
|
||||
"<%s> can't get enough memory for an RA packet %m",
|
||||
__func__);
|
||||
exit(1);
|
||||
|
@ -1153,7 +1154,7 @@ make_packet(struct rainfo *rainfo)
|
|||
#define CHECKLEN(size) \
|
||||
do { \
|
||||
if (buf + size > rainfo->ra_data + packlen) { \
|
||||
syslog(LOG_ERR, \
|
||||
logit(LOG_ERR, \
|
||||
"<%s, %d> RA packet does not fit in %zu",\
|
||||
__func__, __LINE__, packlen); \
|
||||
exit(1); \
|
||||
|
@ -1316,7 +1317,7 @@ getinet6sysctl(int code)
|
|||
size = sizeof(value);
|
||||
if (prog_sysctl(mib, __arraycount(mib), &value, &size, NULL, 0)
|
||||
< 0) {
|
||||
syslog(LOG_ERR, "<%s>: failed to get ip6 sysctl(%d): %m",
|
||||
logit(LOG_ERR, "<%s>: failed to get ip6 sysctl(%d): %m",
|
||||
__func__, code);
|
||||
return -1;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: dump.c,v 1.14 2016/06/15 13:57:39 riastradh Exp $ */
|
||||
/* $NetBSD: dump.c,v 1.15 2017/11/06 15:15:04 christos Exp $ */
|
||||
/* $KAME: dump.c,v 1.34 2004/06/14 05:35:59 itojun Exp $ */
|
||||
|
||||
/*
|
||||
|
@ -57,6 +57,7 @@
|
|||
|
||||
#include "rtadvd.h"
|
||||
#include "timer.h"
|
||||
#include "logit.h"
|
||||
#include "if.h"
|
||||
#include "dump.h"
|
||||
#include "prog_ops.h"
|
||||
|
@ -266,11 +267,11 @@ if_dump(void)
|
|||
void
|
||||
rtadvd_dump_file(const char *dumpfile)
|
||||
{
|
||||
syslog(LOG_DEBUG, "<%s> dump current status to %s", __func__,
|
||||
logit(LOG_DEBUG, "<%s> dump current status to %s", __func__,
|
||||
dumpfile);
|
||||
|
||||
if ((fp = fopen(dumpfile, "w")) == NULL) {
|
||||
syslog(LOG_WARNING, "<%s> open a dump file(%s): %m",
|
||||
logit(LOG_WARNING, "<%s> open a dump file(%s): %m",
|
||||
__func__, dumpfile);
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: if.c,v 1.24 2015/11/11 07:48:41 ozaki-r Exp $ */
|
||||
/* $NetBSD: if.c,v 1.25 2017/11/06 15:15:04 christos Exp $ */
|
||||
/* $KAME: if.c,v 1.36 2004/11/30 22:32:01 suz Exp $ */
|
||||
|
||||
/*
|
||||
|
@ -55,6 +55,7 @@
|
|||
|
||||
#include "rtadvd.h"
|
||||
#include "if.h"
|
||||
#include "logit.h"
|
||||
#include "prog_ops.h"
|
||||
|
||||
#ifndef RT_ROUNDUP
|
||||
|
@ -135,14 +136,14 @@ if_getflags(int ifindex, int oifflags)
|
|||
int s;
|
||||
|
||||
if ((s = prog_socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
|
||||
syslog(LOG_ERR, "<%s> socket: %m", __func__);
|
||||
logit(LOG_ERR, "<%s> socket: %m", __func__);
|
||||
return (oifflags & ~IFF_UP);
|
||||
}
|
||||
|
||||
memset(&ifr, 0, sizeof(ifr));
|
||||
if_indextoname(ifindex, ifr.ifr_name);
|
||||
if (prog_ioctl(s, SIOCGIFFLAGS, &ifr) < 0) {
|
||||
syslog(LOG_ERR, "<%s> ioctl:SIOCGIFFLAGS: failed for %s",
|
||||
logit(LOG_ERR, "<%s> ioctl:SIOCGIFFLAGS: failed for %s",
|
||||
__func__, ifr.ifr_name);
|
||||
prog_close(s);
|
||||
return (oifflags & ~IFF_UP);
|
||||
|
@ -179,7 +180,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)",
|
||||
logit(LOG_ERR, "<%s> unsupported link type(%d)",
|
||||
__func__, sdl->sdl_type);
|
||||
exit(1);
|
||||
}
|
||||
|
@ -203,7 +204,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 "
|
||||
logit(LOG_WARNING, "<%s> rtm_msglen is 0 "
|
||||
"(buf=%p lim=%p rtm=%p)", __func__,
|
||||
buf, lim, rtm);
|
||||
break;
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
|
||||
void logit(int, const char *, ...) __sysloglike(2, 3);
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: rrenum.c,v 1.19 2015/11/11 07:48:41 ozaki-r Exp $ */
|
||||
/* $NetBSD: rrenum.c,v 1.20 2017/11/06 15:15:04 christos Exp $ */
|
||||
/* $KAME: rrenum.c,v 1.14 2004/06/14 05:36:00 itojun Exp $ */
|
||||
|
||||
/*
|
||||
|
@ -53,6 +53,7 @@
|
|||
#include "rtadvd.h"
|
||||
#include "rrenum.h"
|
||||
#include "if.h"
|
||||
#include "logit.h"
|
||||
#include "prog_ops.h"
|
||||
|
||||
#define RR_ISSET_SEGNUM(segnum_bits, segnum) \
|
||||
|
@ -88,7 +89,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",
|
||||
logit(LOG_WARNING, "<%s> rpm_len %d is not 4N * 3",
|
||||
__func__, rpm->rpm_len);
|
||||
return 1;
|
||||
}
|
||||
|
@ -99,13 +100,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__,
|
||||
logit(LOG_WARNING, "<%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",
|
||||
logit(LOG_WARNING, "<%s> rpm_matchlen %d is over 128",
|
||||
__func__, rpm->rpm_matchlen);
|
||||
return 1;
|
||||
}
|
||||
|
@ -128,7 +129,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"
|
||||
logit(LOG_WARNING, "<%s> sum of rpu_uselen %d and"
|
||||
" rpu_keeplen %d is %d(over 128)",
|
||||
__func__, rpu->rpu_uselen,
|
||||
rpu->rpu_keeplen,
|
||||
|
@ -166,7 +167,7 @@ do_use_prefix(int len, struct rr_pco_match *rpm,
|
|||
irr->irr_useprefix.sin6_addr = in6addr_any;
|
||||
if (prog_ioctl(s, rrcmd2pco[rpm->rpm_code], irr) < 0 &&
|
||||
errno != EADDRNOTAVAIL)
|
||||
syslog(LOG_ERR, "<%s> ioctl: %m", __func__);
|
||||
logit(LOG_ERR, "<%s> ioctl: %m", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -197,7 +198,7 @@ do_use_prefix(int len, struct rr_pco_match *rpm,
|
|||
|
||||
if (prog_ioctl(s, rrcmd2pco[rpm->rpm_code], irr) < 0 &&
|
||||
errno != EADDRNOTAVAIL)
|
||||
syslog(LOG_ERR, "<%s> ioctl: %m", __func__);
|
||||
logit(LOG_ERR, "<%s> ioctl: %m", __func__);
|
||||
|
||||
/* very adhoc: should be rewritten */
|
||||
if (rpm->rpm_code == RPM_PCO_CHANGE &&
|
||||
|
@ -251,7 +252,7 @@ do_pco(struct icmp6_router_renum *rr, int len, struct rr_pco_match *rpm)
|
|||
return 1;
|
||||
|
||||
if (s == -1 && (s = prog_socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
|
||||
syslog(LOG_ERR, "<%s> socket: %m", __func__);
|
||||
logit(LOG_ERR, "<%s> socket: %m", __func__);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
@ -281,7 +282,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: %m", __func__);
|
||||
logit(LOG_ERR, "<%s> if_indextoname: %m", __func__);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
|
@ -308,7 +309,7 @@ do_rr(size_t 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 = %zd. "
|
||||
logit(LOG_ERR, "<%s> pkt too short. left len = %zd. "
|
||||
"garbage at end of pkt?", __func__, len);
|
||||
return 1;
|
||||
}
|
||||
|
@ -317,7 +318,7 @@ do_rr(size_t len, struct icmp6_router_renum *rr)
|
|||
goto tooshort;
|
||||
|
||||
if (do_pco(rr, rpmlen, rpm)) {
|
||||
syslog(LOG_WARNING, "<%s> invalid PCO", __func__);
|
||||
logit(LOG_WARNING, "<%s> invalid PCO", __func__);
|
||||
goto next;
|
||||
}
|
||||
|
||||
|
@ -343,7 +344,7 @@ rr_command_check(size_t len, struct icmp6_router_renum *rr,
|
|||
/* rr_command length check */
|
||||
if (len < (sizeof(struct icmp6_router_renum) +
|
||||
sizeof(struct rr_pco_match))) {
|
||||
syslog(LOG_ERR, "<%s> rr_command len %zd is too short",
|
||||
logit(LOG_ERR, "<%s> rr_command len %zd is too short",
|
||||
__func__, len);
|
||||
return 1;
|
||||
}
|
||||
|
@ -351,7 +352,7 @@ rr_command_check(size_t len, struct icmp6_router_renum *rr,
|
|||
/* 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",
|
||||
logit(LOG_ERR, "<%s> dst mcast addr %s is illegal",
|
||||
__func__,
|
||||
inet_ntop(AF_INET6, dst, ntopbuf, INET6_ADDRSTRLEN));
|
||||
return 1;
|
||||
|
@ -359,7 +360,7 @@ rr_command_check(size_t len, struct icmp6_router_renum *rr,
|
|||
|
||||
/* seqnum and segnum check */
|
||||
if (rro.rro_seqnum > rr->rr_seqnum) {
|
||||
syslog(LOG_WARNING,
|
||||
logit(LOG_WARNING,
|
||||
"<%s> rcvd old seqnum %d from %s",
|
||||
__func__, (uint32_t)ntohl(rr->rr_seqnum),
|
||||
inet_ntop(AF_INET6, from, ntopbuf, INET6_ADDRSTRLEN));
|
||||
|
@ -369,7 +370,7 @@ rr_command_check(size_t len, struct icmp6_router_renum *rr,
|
|||
(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,
|
||||
logit(LOG_WARNING,
|
||||
"<%s> rcvd duped segnum %d from %s",
|
||||
__func__, rr->rr_segnum,
|
||||
inet_ntop(AF_INET6, from, ntopbuf,
|
||||
|
@ -412,7 +413,7 @@ rr_command_input(int len, struct icmp6_router_renum *rr,
|
|||
return;
|
||||
|
||||
failed:
|
||||
syslog(LOG_ERR, "<%s> received RR was invalid", __func__);
|
||||
logit(LOG_ERR, "<%s> received RR was invalid", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -422,7 +423,7 @@ rr_input(size_t len, struct icmp6_router_renum *rr, struct in6_pktinfo *pi,
|
|||
{
|
||||
char ntopbuf[2][INET6_ADDRSTRLEN], ifnamebuf[IFNAMSIZ];
|
||||
|
||||
syslog(LOG_DEBUG,
|
||||
logit(LOG_DEBUG,
|
||||
"<%s> RR received from %s to %s on %s",
|
||||
__func__,
|
||||
inet_ntop(AF_INET6, &from->sin6_addr,
|
||||
|
@ -432,7 +433,7 @@ rr_input(size_t 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,
|
||||
logit(LOG_NOTICE,
|
||||
"<%s>: RR short message (size %zd) from %s to %s on %s",
|
||||
__func__, len,
|
||||
inet_ntop(AF_INET6, &from->sin6_addr,
|
||||
|
@ -454,7 +455,7 @@ rr_input(size_t len, struct icmp6_router_renum *rr, struct in6_pktinfo *pi,
|
|||
!IN6_ARE_ADDR_EQUAL(&sin6_sitelocal_allrouters.sin6_addr,
|
||||
&pi->ipi6_addr))
|
||||
{
|
||||
syslog(LOG_NOTICE,
|
||||
logit(LOG_NOTICE,
|
||||
"<%s>: RR message with invalid destination (%s) "
|
||||
"from %s on %s",
|
||||
__func__,
|
||||
|
@ -479,7 +480,7 @@ rr_input(size_t len, struct icmp6_router_renum *rr, struct in6_pktinfo *pi,
|
|||
/* TODO: sequence number reset */
|
||||
break;
|
||||
default:
|
||||
syslog(LOG_ERR, "<%s> received unknown code %d",
|
||||
logit(LOG_ERR, "<%s> received unknown code %d",
|
||||
__func__, rr->rr_code);
|
||||
break;
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
.\" $NetBSD: rtadvd.8,v 1.25 2016/12/16 09:09:38 ozaki-r Exp $
|
||||
.\" $NetBSD: rtadvd.8,v 1.26 2017/11/06 15:15:04 christos Exp $
|
||||
.\" $KAME: rtadvd.8,v 1.24 2002/05/31 16:16:08 jinmei Exp $
|
||||
.\"
|
||||
.\" Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
|
||||
|
@ -28,7 +28,7 @@
|
|||
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
.\" SUCH DAMAGE.
|
||||
.\"
|
||||
.Dd December 16, 2016
|
||||
.Dd November 6, 2017
|
||||
.Dt RTADVD 8
|
||||
.Os
|
||||
.Sh NAME
|
||||
|
@ -120,11 +120,16 @@ By default,
|
|||
.Pa /etc/rtadvd.conf
|
||||
is used.
|
||||
.It Fl D
|
||||
Even more debugging information than that offered by the
|
||||
.Fl d
|
||||
option is printed.
|
||||
Instead of printing errors using
|
||||
.Xr syslog 3
|
||||
send them to
|
||||
.Dv stderr .
|
||||
Also when
|
||||
.Xr poll 2
|
||||
fails, exit instead of retrying.
|
||||
.It Fl d
|
||||
Print debugging information.
|
||||
Repeating this option, adds more verbose debugging.
|
||||
.It Fl f
|
||||
Foreground mode (useful when debugging).
|
||||
Log messages will be dumped to stderr when this option is specified.
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: rtadvd.c,v 1.56 2017/10/14 19:16:26 christos Exp $ */
|
||||
/* $NetBSD: rtadvd.c,v 1.57 2017/11/06 15:15:04 christos Exp $ */
|
||||
/* $KAME: rtadvd.c,v 1.92 2005/10/17 14:40:02 suz Exp $ */
|
||||
|
||||
/*
|
||||
|
@ -54,6 +54,7 @@
|
|||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <syslog.h>
|
||||
#include <stdarg.h>
|
||||
#ifdef __NetBSD__
|
||||
#include <util.h>
|
||||
#endif
|
||||
|
@ -67,6 +68,7 @@
|
|||
#include "if.h"
|
||||
#include "config.h"
|
||||
#include "dump.h"
|
||||
#include "logit.h"
|
||||
#include "prog_ops.h"
|
||||
|
||||
struct msghdr rcvmhdr;
|
||||
|
@ -86,7 +88,7 @@ static char *mcastif;
|
|||
int sock;
|
||||
int rtsock = -1;
|
||||
int accept_rr = 0;
|
||||
int dflag = 0, sflag = 0;
|
||||
int dflag = 0, sflag = 0, Dflag;
|
||||
|
||||
static char **if_argv;
|
||||
static int if_argc;
|
||||
|
@ -191,10 +193,10 @@ main(int argc, char *argv[])
|
|||
conffile = optarg;
|
||||
break;
|
||||
case 'd':
|
||||
dflag = 1;
|
||||
dflag++;
|
||||
break;
|
||||
case 'D':
|
||||
dflag = 2;
|
||||
Dflag++;
|
||||
break;
|
||||
case 'f':
|
||||
fflag = 1;
|
||||
|
@ -242,11 +244,11 @@ main(int argc, char *argv[])
|
|||
errno = 0; /* Ensure errno is 0 so we know if getpwnam errors or not */
|
||||
if ((pw = getpwnam(RTADVD_USER)) == NULL) {
|
||||
if (errno == 0)
|
||||
syslog(LOG_ERR,
|
||||
logit(LOG_ERR,
|
||||
"user %s does not exist, aborting",
|
||||
RTADVD_USER);
|
||||
else
|
||||
syslog(LOG_ERR, "getpwnam: %s: %m", RTADVD_USER);
|
||||
logit(LOG_ERR, "getpwnam: %s: %m", RTADVD_USER);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
|
@ -267,12 +269,12 @@ main(int argc, char *argv[])
|
|||
/* record the current PID */
|
||||
if (pidfile(pidfilepath) == -1) {
|
||||
if (errno == EEXIST) {
|
||||
syslog(LOG_ERR, "Another instance of `%s' is running "
|
||||
logit(LOG_ERR, "Another instance of `%s' is running "
|
||||
"(pid %d); exiting.", getprogname(),
|
||||
pidfile_read(pidfilepath));
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
syslog(LOG_ERR, "Failed to open the pid log file `%s' (%m), "
|
||||
logit(LOG_ERR, "Failed to open the pid log file `%s' (%m), "
|
||||
"run anyway.", pidfilepath);
|
||||
}
|
||||
#endif
|
||||
|
@ -286,20 +288,20 @@ main(int argc, char *argv[])
|
|||
} else
|
||||
set[1].fd = -1;
|
||||
|
||||
syslog(LOG_INFO, "dropping privileges to %s", RTADVD_USER);
|
||||
logit(LOG_INFO, "dropping privileges to %s", RTADVD_USER);
|
||||
if (prog_chroot(pw->pw_dir) == -1) {
|
||||
syslog(LOG_ERR, "chroot: %s: %m", pw->pw_dir);
|
||||
logit(LOG_ERR, "chroot: %s: %m", pw->pw_dir);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
if (prog_chdir("/") == -1) {
|
||||
syslog(LOG_ERR, "chdir: /: %m");
|
||||
logit(LOG_ERR, "chdir: /: %m");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
if (prog_setgroups(1, &pw->pw_gid) == -1 ||
|
||||
prog_setgid(pw->pw_gid) == -1 ||
|
||||
prog_setuid(pw->pw_uid) == -1)
|
||||
{
|
||||
syslog(LOG_ERR, "failed to drop privileges: %m");
|
||||
logit(LOG_ERR, "failed to drop privileges: %m");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
|
@ -316,7 +318,7 @@ main(int argc, char *argv[])
|
|||
|
||||
if (do_reconf) { /* SIGHUP */
|
||||
do_reconf = 0;
|
||||
syslog(LOG_INFO, "%s: reloading config on SIGHUP",
|
||||
logit(LOG_INFO, "%s: reloading config on SIGHUP",
|
||||
__func__);
|
||||
argc = if_argc;
|
||||
argv = if_argv;
|
||||
|
@ -333,13 +335,13 @@ main(int argc, char *argv[])
|
|||
}
|
||||
|
||||
if (timeout != NULL) {
|
||||
syslog(LOG_DEBUG,
|
||||
logit(LOG_DEBUG,
|
||||
"%s: set timer to %jd:%jd. waiting for "
|
||||
"inputs or timeout", __func__,
|
||||
(intmax_t)timeout->tv_sec,
|
||||
(intmax_t)timeout->tv_nsec);
|
||||
} else {
|
||||
syslog(LOG_DEBUG,
|
||||
logit(LOG_DEBUG,
|
||||
"%s: there's no timer. waiting for inputs",
|
||||
__func__);
|
||||
}
|
||||
|
@ -348,9 +350,12 @@ main(int argc, char *argv[])
|
|||
(timeout->tv_nsec + 999999) / 1000000) : INFTIM)) == -1)
|
||||
{
|
||||
/* EINTR would occur upon SIGUSR1 for status dump */
|
||||
if (errno != EINTR)
|
||||
syslog(LOG_ERR, "%s: poll: %m", __func__);
|
||||
continue;
|
||||
if (errno == EINTR)
|
||||
continue;
|
||||
|
||||
logit(LOG_ERR, "%s: poll: %m", __func__);
|
||||
if (Dflag)
|
||||
exit(1);
|
||||
}
|
||||
if (i == 0) /* timeout */
|
||||
continue;
|
||||
|
@ -393,12 +398,12 @@ die(void)
|
|||
|
||||
if (waiting) {
|
||||
if (TAILQ_FIRST(&ralist)) {
|
||||
syslog(LOG_INFO,
|
||||
logit(LOG_INFO,
|
||||
"%s: waiting for expiration of all RA timers",
|
||||
__func__);
|
||||
return;
|
||||
}
|
||||
syslog(LOG_NOTICE, "%s: gracefully terminated", __func__);
|
||||
logit(LOG_NOTICE, "%s: gracefully terminated", __func__);
|
||||
free(rcvcmsgbuf);
|
||||
free(sndcmsgbuf);
|
||||
exit(EXIT_SUCCESS);
|
||||
|
@ -406,13 +411,13 @@ die(void)
|
|||
}
|
||||
|
||||
if (TAILQ_FIRST(&ralist) == NULL) {
|
||||
syslog(LOG_NOTICE, "%s: gracefully terminated", __func__);
|
||||
logit(LOG_NOTICE, "%s: gracefully terminated", __func__);
|
||||
exit(EXIT_SUCCESS);
|
||||
/* NOT REACHED */
|
||||
}
|
||||
|
||||
waiting = 1;
|
||||
syslog(LOG_NOTICE, "%s: final RA transmission started", __func__);
|
||||
logit(LOG_NOTICE, "%s: final RA transmission started", __func__);
|
||||
|
||||
TAILQ_FOREACH_SAFE(rai, &ralist, next, ran) {
|
||||
if (rai->leaving) {
|
||||
|
@ -467,7 +472,7 @@ rtmsg_input(void)
|
|||
|
||||
msg = buffer.data;
|
||||
if (dflag > 1) {
|
||||
syslog(LOG_DEBUG, "%s: received a routing message "
|
||||
logit(LOG_DEBUG, "%s: received a routing message "
|
||||
"(type = %d, len = %d)", __func__, rtmsg_type(msg),
|
||||
rtmsg_len(msg));
|
||||
}
|
||||
|
@ -477,7 +482,7 @@ rtmsg_input(void)
|
|||
* a routing socket.
|
||||
*/
|
||||
if (dflag > 1)
|
||||
syslog(LOG_DEBUG,
|
||||
logit(LOG_DEBUG,
|
||||
"%s: received data length is larger than "
|
||||
"1st routing message len. multiple messages? "
|
||||
"read %d bytes, but 1st msg len = %d",
|
||||
|
@ -517,7 +522,7 @@ rtmsg_input(void)
|
|||
case RTM_IFANNOUNCE:
|
||||
ifindex = get_ifan_ifindex(next);
|
||||
if (get_ifan_what(next) == IFAN_ARRIVAL) {
|
||||
syslog(LOG_DEBUG,
|
||||
logit(LOG_DEBUG,
|
||||
"%s: interface %s arrived",
|
||||
__func__,
|
||||
if_indextoname(ifindex, ifname));
|
||||
|
@ -543,7 +548,7 @@ rtmsg_input(void)
|
|||
default:
|
||||
/* should not reach here */
|
||||
if (dflag > 1) {
|
||||
syslog(LOG_DEBUG, "%s: unknown rtmsg %d on %s",
|
||||
logit(LOG_DEBUG, "%s: unknown rtmsg %d on %s",
|
||||
__func__, type,
|
||||
if_indextoname(ifindex, ifname));
|
||||
}
|
||||
|
@ -552,7 +557,7 @@ rtmsg_input(void)
|
|||
|
||||
if ((rai = if_indextorainfo(ifindex)) == NULL) {
|
||||
if (dflag > 1) {
|
||||
syslog(LOG_DEBUG,
|
||||
logit(LOG_DEBUG,
|
||||
"%s: route changed on "
|
||||
"non advertising interface %s (%d)",
|
||||
__func__,
|
||||
|
@ -576,7 +581,7 @@ rtmsg_input(void)
|
|||
/* sanity check for plen */
|
||||
/* as RFC2373, prefixlen is at least 4 */
|
||||
if (plen < 4 || plen > 127) {
|
||||
syslog(LOG_INFO, "%s: new interface route's"
|
||||
logit(LOG_INFO, "%s: new interface route's"
|
||||
"plen %d is invalid for a prefix",
|
||||
__func__, plen);
|
||||
break;
|
||||
|
@ -591,7 +596,7 @@ rtmsg_input(void)
|
|||
update_prefix(prefix);
|
||||
prefixchange = 1;
|
||||
} else if (dflag > 1) {
|
||||
syslog(LOG_DEBUG,
|
||||
logit(LOG_DEBUG,
|
||||
"%s: new prefix(%s/%d) "
|
||||
"added on %s, "
|
||||
"but it was already in list",
|
||||
|
@ -617,7 +622,7 @@ rtmsg_input(void)
|
|||
/* sanity check for plen */
|
||||
/* as RFC2373, prefixlen is at least 4 */
|
||||
if (plen < 4 || plen > 127) {
|
||||
syslog(LOG_INFO,
|
||||
logit(LOG_INFO,
|
||||
"%s: deleted interface route's "
|
||||
"plen %d is invalid for a prefix",
|
||||
__func__, plen);
|
||||
|
@ -626,7 +631,7 @@ rtmsg_input(void)
|
|||
prefix = find_prefix(rai, addr, plen);
|
||||
if (prefix == NULL) {
|
||||
if (dflag > 1) {
|
||||
syslog(LOG_DEBUG,
|
||||
logit(LOG_DEBUG,
|
||||
"%s: prefix(%s/%d) was "
|
||||
"deleted on %s, "
|
||||
"but it was not in list",
|
||||
|
@ -651,7 +656,7 @@ rtmsg_input(void)
|
|||
#ifdef RTM_IFANNOUNCE
|
||||
case RTM_IFANNOUNCE:
|
||||
if (get_ifan_what(next) == IFAN_DEPARTURE) {
|
||||
syslog(LOG_DEBUG,
|
||||
logit(LOG_DEBUG,
|
||||
"%s: interface %s departed",
|
||||
__func__, rai->ifname);
|
||||
TAILQ_REMOVE(&ralist, rai, next);
|
||||
|
@ -665,7 +670,7 @@ rtmsg_input(void)
|
|||
default:
|
||||
/* should not reach here */
|
||||
if (dflag > 1) {
|
||||
syslog(LOG_DEBUG,
|
||||
logit(LOG_DEBUG,
|
||||
"%s: unknown rtmsg %d on %s",
|
||||
__func__, type,
|
||||
if_indextoname(ifindex, ifname));
|
||||
|
@ -676,13 +681,13 @@ rtmsg_input(void)
|
|||
/* check if an interface flag is changed */
|
||||
if ((oldifflags & IFF_UP) != 0 && /* UP to DOWN */
|
||||
(rai->ifflags & IFF_UP) == 0) {
|
||||
syslog(LOG_INFO,
|
||||
logit(LOG_INFO,
|
||||
"%s: interface %s becomes down. stop timer.",
|
||||
__func__, rai->ifname);
|
||||
rtadvd_remove_timer(&rai->timer);
|
||||
} else if ((oldifflags & IFF_UP) == 0 && /* DOWN to UP */
|
||||
(rai->ifflags & IFF_UP) != 0) {
|
||||
syslog(LOG_INFO,
|
||||
logit(LOG_INFO,
|
||||
"%s: interface %s becomes up. restart timer.",
|
||||
__func__, rai->ifname);
|
||||
|
||||
|
@ -752,13 +757,13 @@ rtadvd_input(void)
|
|||
hlimp = (int *)CMSG_DATA(cm);
|
||||
}
|
||||
if (ifindex == 0) {
|
||||
syslog(LOG_ERR,
|
||||
logit(LOG_ERR,
|
||||
"%s: failed to get receiving interface",
|
||||
__func__);
|
||||
return;
|
||||
}
|
||||
if (hlimp == NULL) {
|
||||
syslog(LOG_ERR,
|
||||
logit(LOG_ERR,
|
||||
"%s: failed to get receiving hop limit",
|
||||
__func__);
|
||||
return;
|
||||
|
@ -766,7 +771,7 @@ rtadvd_input(void)
|
|||
|
||||
if ((rai = if_indextorainfo(pi->ipi6_ifindex)) == NULL) {
|
||||
if (dflag > 1) {
|
||||
syslog(LOG_DEBUG,
|
||||
logit(LOG_DEBUG,
|
||||
"%s: received data for non advertising "
|
||||
"interface (%s)",
|
||||
__func__,
|
||||
|
@ -779,7 +784,7 @@ rtadvd_input(void)
|
|||
* just discard the data.
|
||||
*/
|
||||
if ((rai->ifflags & IFF_UP) == 0) {
|
||||
syslog(LOG_INFO,
|
||||
logit(LOG_INFO,
|
||||
"%s: received data on a disabled interface (%s)",
|
||||
__func__,
|
||||
if_indextoname(pi->ipi6_ifindex, ifnamebuf));
|
||||
|
@ -788,7 +793,7 @@ rtadvd_input(void)
|
|||
|
||||
#ifdef OLDRAWSOCKET
|
||||
if ((size_t)i < sizeof(struct ip6_hdr) + sizeof(struct icmp6_hdr)) {
|
||||
syslog(LOG_ERR,
|
||||
logit(LOG_ERR,
|
||||
"%s: packet size(%d) is too short",
|
||||
__func__, i);
|
||||
return;
|
||||
|
@ -798,7 +803,7 @@ rtadvd_input(void)
|
|||
icp = (struct icmp6_hdr *)(ip + 1); /* XXX: ext. hdr? */
|
||||
#else
|
||||
if ((size_t)i < sizeof(struct icmp6_hdr)) {
|
||||
syslog(LOG_ERR,
|
||||
logit(LOG_ERR,
|
||||
"%s: packet size(%zd) is too short",
|
||||
__func__, i);
|
||||
return;
|
||||
|
@ -815,7 +820,7 @@ rtadvd_input(void)
|
|||
* but we can't completely rely on them.
|
||||
*/
|
||||
if (*hlimp != 255) {
|
||||
syslog(LOG_NOTICE,
|
||||
logit(LOG_NOTICE,
|
||||
"%s: RS with invalid hop limit(%d) "
|
||||
"received from %s on %s",
|
||||
__func__, *hlimp,
|
||||
|
@ -825,7 +830,7 @@ rtadvd_input(void)
|
|||
return;
|
||||
}
|
||||
if (icp->icmp6_code) {
|
||||
syslog(LOG_NOTICE,
|
||||
logit(LOG_NOTICE,
|
||||
"%s: RS with invalid ICMP6 code(%d) "
|
||||
"received from %s on %s",
|
||||
__func__, icp->icmp6_code,
|
||||
|
@ -835,7 +840,7 @@ rtadvd_input(void)
|
|||
return;
|
||||
}
|
||||
if ((size_t)i < sizeof(struct nd_router_solicit)) {
|
||||
syslog(LOG_NOTICE,
|
||||
logit(LOG_NOTICE,
|
||||
"%s: RS from %s on %s does not have enough "
|
||||
"length (len = %zd)",
|
||||
__func__,
|
||||
|
@ -852,7 +857,7 @@ rtadvd_input(void)
|
|||
* XXX: there's a same dilemma as above...
|
||||
*/
|
||||
if (*hlimp != 255) {
|
||||
syslog(LOG_NOTICE,
|
||||
logit(LOG_NOTICE,
|
||||
"%s: RA with invalid hop limit(%d) "
|
||||
"received from %s on %s",
|
||||
__func__, *hlimp,
|
||||
|
@ -862,7 +867,7 @@ rtadvd_input(void)
|
|||
return;
|
||||
}
|
||||
if (icp->icmp6_code) {
|
||||
syslog(LOG_NOTICE,
|
||||
logit(LOG_NOTICE,
|
||||
"%s: RA with invalid ICMP6 code(%d) "
|
||||
"received from %s on %s",
|
||||
__func__, icp->icmp6_code,
|
||||
|
@ -872,7 +877,7 @@ rtadvd_input(void)
|
|||
return;
|
||||
}
|
||||
if ((size_t)i < sizeof(struct nd_router_advert)) {
|
||||
syslog(LOG_NOTICE,
|
||||
logit(LOG_NOTICE,
|
||||
"%s: RA from %s on %s does not have enough "
|
||||
"length (len = %zd)",
|
||||
__func__,
|
||||
|
@ -885,7 +890,7 @@ rtadvd_input(void)
|
|||
break;
|
||||
case ICMP6_ROUTER_RENUMBERING:
|
||||
if (accept_rr == 0) {
|
||||
syslog(LOG_ERR, "%s: received a router renumbering "
|
||||
logit(LOG_ERR, "%s: received a router renumbering "
|
||||
"message, but not allowed to be accepted",
|
||||
__func__);
|
||||
break;
|
||||
|
@ -900,7 +905,7 @@ rtadvd_input(void)
|
|||
* could receive message after opening the socket and
|
||||
* before setting ICMP6 type filter(see sock_open()).
|
||||
*/
|
||||
syslog(LOG_ERR, "%s: invalid icmp type(%d)",
|
||||
logit(LOG_ERR, "%s: invalid icmp type(%d)",
|
||||
__func__, icp->icmp6_type);
|
||||
return;
|
||||
}
|
||||
|
@ -915,7 +920,7 @@ rs_input(int len, struct nd_router_solicit *rs,
|
|||
struct rainfo *rai;
|
||||
struct soliciter *sol;
|
||||
|
||||
syslog(LOG_DEBUG,
|
||||
logit(LOG_DEBUG,
|
||||
"%s: RS received from %s on %s",
|
||||
__func__,
|
||||
inet_ntop(AF_INET6, &from->sin6_addr,
|
||||
|
@ -928,7 +933,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,
|
||||
logit(LOG_INFO,
|
||||
"%s: ND option check failed for an RS from %s on %s",
|
||||
__func__,
|
||||
inet_ntop(AF_INET6, &from->sin6_addr,
|
||||
|
@ -944,7 +949,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,
|
||||
logit(LOG_INFO,
|
||||
"%s: RS from unspecified src on %s has a link-layer"
|
||||
" address option",
|
||||
__func__,
|
||||
|
@ -953,7 +958,7 @@ rs_input(int len, struct nd_router_solicit *rs,
|
|||
}
|
||||
|
||||
if ((rai = if_indextorainfo(pi->ipi6_ifindex)) == NULL) {
|
||||
syslog(LOG_INFO,
|
||||
logit(LOG_INFO,
|
||||
"%s: RS received on non advertising interface(%s)",
|
||||
__func__,
|
||||
if_indextoname(pi->ipi6_ifindex, ifnamebuf));
|
||||
|
@ -961,7 +966,7 @@ rs_input(int len, struct nd_router_solicit *rs,
|
|||
}
|
||||
|
||||
if (rai->leaving) {
|
||||
syslog(LOG_INFO,
|
||||
logit(LOG_INFO,
|
||||
"%s: RS received on reconfiguring advertising interface(%s)",
|
||||
__func__, rai->ifname);
|
||||
goto done;
|
||||
|
@ -1014,7 +1019,7 @@ ra_timer_set_short_delay(struct rainfo *rai)
|
|||
interval.tv_nsec = delay;
|
||||
rest = rtadvd_timer_rest(rai->timer);
|
||||
if (timespeccmp(rest, &interval, <)) {
|
||||
syslog(LOG_DEBUG, "%s: random delay is larger than "
|
||||
logit(LOG_DEBUG, "%s: random delay is larger than "
|
||||
"the rest of current timer", __func__);
|
||||
interval = *rest;
|
||||
}
|
||||
|
@ -1049,7 +1054,7 @@ ra_input(int len, struct nd_router_advert *ra,
|
|||
struct nd_optlist *optp;
|
||||
int inconsistent = 0;
|
||||
|
||||
syslog(LOG_DEBUG,
|
||||
logit(LOG_DEBUG,
|
||||
"%s: RA received from %s on %s",
|
||||
__func__,
|
||||
inet_ntop(AF_INET6, &from->sin6_addr,
|
||||
|
@ -1065,7 +1070,7 @@ ra_input(int len, struct nd_router_advert *ra,
|
|||
NDOPT_FLAG_PREFIXINFO | NDOPT_FLAG_MTU |
|
||||
NDOPT_FLAG_RDNSS | NDOPT_FLAG_DNSSL))
|
||||
{
|
||||
syslog(LOG_INFO,
|
||||
logit(LOG_INFO,
|
||||
"%s: ND option check failed for an RA from %s on %s",
|
||||
__func__,
|
||||
inet_ntop(AF_INET6, &from->sin6_addr,
|
||||
|
@ -1078,7 +1083,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,
|
||||
logit(LOG_INFO,
|
||||
"%s: received RA from %s on non-advertising"
|
||||
" interface(%s)",
|
||||
__func__,
|
||||
|
@ -1088,7 +1093,7 @@ ra_input(int len, struct nd_router_advert *ra,
|
|||
goto done;
|
||||
}
|
||||
if (rai->leaving) {
|
||||
syslog(LOG_DEBUG,
|
||||
logit(LOG_DEBUG,
|
||||
"%s: received RA on re-configuring interface (%s)",
|
||||
__func__, rai->ifname);
|
||||
goto done;
|
||||
|
@ -1098,7 +1103,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,
|
||||
logit(LOG_INFO,
|
||||
"%s: CurHopLimit inconsistent on %s:"
|
||||
" %d from %s, %d from us",
|
||||
__func__,
|
||||
|
@ -1112,7 +1117,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,
|
||||
logit(LOG_INFO,
|
||||
"%s: M flag inconsistent on %s:"
|
||||
" %s from %s, %s from us",
|
||||
__func__,
|
||||
|
@ -1126,7 +1131,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,
|
||||
logit(LOG_INFO,
|
||||
"%s: O flag inconsistent on %s:"
|
||||
" %s from %s, %s from us",
|
||||
__func__,
|
||||
|
@ -1141,7 +1146,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,
|
||||
logit(LOG_INFO,
|
||||
"%s: ReachableTime inconsistent on %s:"
|
||||
" %d from %s, %d from us",
|
||||
__func__,
|
||||
|
@ -1156,7 +1161,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,
|
||||
logit(LOG_INFO,
|
||||
"%s: RetranceTimer inconsistent on %s:"
|
||||
" %d from %s, %d from us",
|
||||
__func__,
|
||||
|
@ -1171,7 +1176,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,
|
||||
logit(LOG_INFO,
|
||||
"%s: MTU option value inconsistent on %s:"
|
||||
" %d from %s, %d from us",
|
||||
__func__,
|
||||
|
@ -1218,7 +1223,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,
|
||||
logit(LOG_INFO,
|
||||
"%s: link-local prefix %s/%d is advertised "
|
||||
"from %s on %s",
|
||||
__func__,
|
||||
|
@ -1232,7 +1237,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,
|
||||
logit(LOG_INFO,
|
||||
"%s: prefix %s/%d from %s on %s is not in our list",
|
||||
__func__,
|
||||
inet_ntop(AF_INET6, &pinfo->nd_opt_pi_prefix,
|
||||
|
@ -1258,7 +1263,7 @@ prefix_check(struct nd_opt_prefix_info *pinfo,
|
|||
|
||||
if (!pp->timer && rai->clockskew &&
|
||||
llabs((long long)preferred_time - pp->pltimeexpire) > rai->clockskew) {
|
||||
syslog(LOG_INFO,
|
||||
logit(LOG_INFO,
|
||||
"%s: preferred lifetime for %s/%d"
|
||||
" (decr. in real time) inconsistent on %s:"
|
||||
" %d from %s, %ld from us",
|
||||
|
@ -1273,7 +1278,7 @@ prefix_check(struct nd_opt_prefix_info *pinfo,
|
|||
inconsistent++;
|
||||
}
|
||||
} else if (!pp->timer && preferred_time != pp->preflifetime) {
|
||||
syslog(LOG_INFO,
|
||||
logit(LOG_INFO,
|
||||
"%s: preferred lifetime for %s/%d"
|
||||
" inconsistent on %s:"
|
||||
" %d from %s, %d from us",
|
||||
|
@ -1294,7 +1299,7 @@ prefix_check(struct nd_opt_prefix_info *pinfo,
|
|||
|
||||
if (!pp->timer && rai->clockskew &&
|
||||
llabs((long long)valid_time - pp->vltimeexpire) > rai->clockskew) {
|
||||
syslog(LOG_INFO,
|
||||
logit(LOG_INFO,
|
||||
"%s: valid lifetime for %s/%d"
|
||||
" (decr. in real time) inconsistent on %s:"
|
||||
" %d from %s, %ld from us",
|
||||
|
@ -1309,7 +1314,7 @@ prefix_check(struct nd_opt_prefix_info *pinfo,
|
|||
inconsistent++;
|
||||
}
|
||||
} else if (!pp->timer && valid_time != pp->validlifetime) {
|
||||
syslog(LOG_INFO,
|
||||
logit(LOG_INFO,
|
||||
"%s: valid lifetime for %s/%d"
|
||||
" inconsistent on %s:"
|
||||
" %d from %s, %d from us",
|
||||
|
@ -1384,20 +1389,20 @@ nd6_options(struct nd_opt_hdr *hdr, int limit,
|
|||
|
||||
for (; limit > 0; limit -= optlen) {
|
||||
if ((size_t)limit < sizeof(struct nd_opt_hdr)) {
|
||||
syslog(LOG_INFO, "%s: short option header", __func__);
|
||||
logit(LOG_INFO, "%s: short option header", __func__);
|
||||
goto bad;
|
||||
}
|
||||
|
||||
hdr = (struct nd_opt_hdr *)((char *)hdr + optlen);
|
||||
if (hdr->nd_opt_len == 0) {
|
||||
syslog(LOG_INFO,
|
||||
logit(LOG_INFO,
|
||||
"%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__);
|
||||
logit(LOG_INFO, "%s: short option", __func__);
|
||||
goto bad;
|
||||
}
|
||||
|
||||
|
@ -1405,13 +1410,13 @@ nd6_options(struct nd_opt_hdr *hdr, int limit,
|
|||
hdr->nd_opt_type != ND_OPT_RDNSS &&
|
||||
hdr->nd_opt_type != ND_OPT_DNSSL)
|
||||
{
|
||||
syslog(LOG_INFO, "%s: unknown ND option(type %d)",
|
||||
logit(LOG_INFO, "%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)",
|
||||
logit(LOG_INFO, "%s: unexpected ND option(type %d)",
|
||||
__func__, hdr->nd_opt_type);
|
||||
continue;
|
||||
}
|
||||
|
@ -1430,7 +1435,7 @@ nd6_options(struct nd_opt_hdr *hdr, int limit,
|
|||
(hdr->nd_opt_type == ND_OPT_DNSSL &&
|
||||
optlen < (int)sizeof(struct nd_opt_dnssl)))
|
||||
{
|
||||
syslog(LOG_INFO, "%s: invalid option length",
|
||||
logit(LOG_INFO, "%s: invalid option length",
|
||||
__func__);
|
||||
continue;
|
||||
}
|
||||
|
@ -1444,7 +1449,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,
|
||||
logit(LOG_INFO,
|
||||
"%s: duplicated ND option (type = %d)",
|
||||
__func__, hdr->nd_opt_type);
|
||||
}
|
||||
|
@ -1460,7 +1465,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",
|
||||
logit(LOG_ERR, "%s: can't allocate memory",
|
||||
__func__);
|
||||
goto bad;
|
||||
}
|
||||
|
@ -1506,19 +1511,19 @@ sock_open(void)
|
|||
CMSG_SPACE(sizeof(int));
|
||||
rcvcmsgbuf = malloc(rcvcmsgbuflen);
|
||||
if (rcvcmsgbuf == NULL) {
|
||||
syslog(LOG_ERR, "%s: malloc: %m", __func__);
|
||||
logit(LOG_ERR, "%s: malloc: %m", __func__);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
sndcmsgbuflen = CMSG_SPACE(sizeof(struct in6_pktinfo));
|
||||
sndcmsgbuf = malloc(sndcmsgbuflen);
|
||||
if (sndcmsgbuf == NULL) {
|
||||
syslog(LOG_ERR, "%s: malloc: %m", __func__);
|
||||
logit(LOG_ERR, "%s: malloc: %m", __func__);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if ((sock = prog_socket(AF_INET6, SOCK_RAW, IPPROTO_ICMPV6)) == -1) {
|
||||
syslog(LOG_ERR, "%s: socket: %m", __func__);
|
||||
logit(LOG_ERR, "%s: socket: %m", __func__);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
|
@ -1526,7 +1531,7 @@ sock_open(void)
|
|||
on = 255;
|
||||
if (prog_setsockopt(sock, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, &on,
|
||||
sizeof(on)) == -1) {
|
||||
syslog(LOG_ERR, "%s: IPV6_MULTICAST_HOPS: %m", __func__);
|
||||
logit(LOG_ERR, "%s: IPV6_MULTICAST_HOPS: %m", __func__);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
|
@ -1535,13 +1540,13 @@ sock_open(void)
|
|||
#ifdef IPV6_RECVPKTINFO
|
||||
if (prog_setsockopt(sock, IPPROTO_IPV6, IPV6_RECVPKTINFO, &on,
|
||||
sizeof(on)) == -1) {
|
||||
syslog(LOG_ERR, "%s: IPV6_RECVPKTINFO: %m", __func__);
|
||||
logit(LOG_ERR, "%s: IPV6_RECVPKTINFO: %m", __func__);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
#else /* old adv. API */
|
||||
if (prog_setsockopt(sock, IPPROTO_IPV6, IPV6_PKTINFO, &on,
|
||||
sizeof(on)) == -1) {
|
||||
syslog(LOG_ERR, "%s: IPV6_PKTINFO: %m", __func__);
|
||||
logit(LOG_ERR, "%s: IPV6_PKTINFO: %m", __func__);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
#endif
|
||||
|
@ -1551,13 +1556,13 @@ sock_open(void)
|
|||
#ifdef IPV6_RECVHOPLIMIT
|
||||
if (prog_setsockopt(sock, IPPROTO_IPV6, IPV6_RECVHOPLIMIT, &on,
|
||||
sizeof(on)) == -1) {
|
||||
syslog(LOG_ERR, "%s: IPV6_RECVHOPLIMIT: %m", __func__);
|
||||
logit(LOG_ERR, "%s: IPV6_RECVHOPLIMIT: %m", __func__);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
#else /* old adv. API */
|
||||
if (prog_setsockopt(sock, IPPROTO_IPV6, IPV6_HOPLIMIT, &on,
|
||||
sizeof(on)) == -1) {
|
||||
syslog(LOG_ERR, "%s: IPV6_HOPLIMIT: %m", __func__);
|
||||
logit(LOG_ERR, "%s: IPV6_HOPLIMIT: %m", __func__);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
#endif
|
||||
|
@ -1569,7 +1574,7 @@ sock_open(void)
|
|||
ICMP6_FILTER_SETPASS(ICMP6_ROUTER_RENUMBERING, &filt);
|
||||
if (prog_setsockopt(sock, IPPROTO_ICMPV6, ICMP6_FILTER, &filt,
|
||||
sizeof(filt)) == -1) {
|
||||
syslog(LOG_ERR, "%s: IICMP6_FILTER: %m", __func__);
|
||||
logit(LOG_ERR, "%s: IICMP6_FILTER: %m", __func__);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
|
@ -1579,7 +1584,7 @@ sock_open(void)
|
|||
if (inet_pton(AF_INET6, ALLROUTERS_LINK,
|
||||
mreq.ipv6mr_multiaddr.s6_addr) != 1)
|
||||
{
|
||||
syslog(LOG_ERR, "%s: inet_pton failed(library bug?)",
|
||||
logit(LOG_ERR, "%s: inet_pton failed(library bug?)",
|
||||
__func__);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
@ -1587,7 +1592,7 @@ sock_open(void)
|
|||
mreq.ipv6mr_interface = ra->ifindex;
|
||||
if (prog_setsockopt(sock, IPPROTO_IPV6, IPV6_JOIN_GROUP, &mreq,
|
||||
sizeof(mreq)) == -1) {
|
||||
syslog(LOG_ERR, "%s: IPV6_JOIN_GROUP(link) on %s: %m",
|
||||
logit(LOG_ERR, "%s: IPV6_JOIN_GROUP(link) on %s: %m",
|
||||
__func__, ra->ifname);
|
||||
continue;
|
||||
}
|
||||
|
@ -1601,7 +1606,7 @@ sock_open(void)
|
|||
if (inet_pton(AF_INET6, ALLROUTERS_SITE,
|
||||
mreq.ipv6mr_multiaddr.s6_addr) != 1)
|
||||
{
|
||||
syslog(LOG_ERR, "%s: inet_pton failed(library bug?)",
|
||||
logit(LOG_ERR, "%s: inet_pton failed(library bug?)",
|
||||
__func__);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
@ -1609,7 +1614,7 @@ sock_open(void)
|
|||
if (mcastif) {
|
||||
if ((mreq.ipv6mr_interface = if_nametoindex(mcastif))
|
||||
== 0) {
|
||||
syslog(LOG_ERR,
|
||||
logit(LOG_ERR,
|
||||
"%s: invalid interface: %s",
|
||||
__func__, mcastif);
|
||||
exit(EXIT_FAILURE);
|
||||
|
@ -1618,7 +1623,7 @@ sock_open(void)
|
|||
mreq.ipv6mr_interface = ra->ifindex;
|
||||
if (prog_setsockopt(sock, IPPROTO_IPV6, IPV6_JOIN_GROUP,
|
||||
&mreq, sizeof(mreq)) == -1) {
|
||||
syslog(LOG_ERR,
|
||||
logit(LOG_ERR,
|
||||
"%s: IPV6_JOIN_GROUP(site) on %s: %m",
|
||||
__func__,
|
||||
mcastif ? mcastif : ra->ifname);
|
||||
|
@ -1660,13 +1665,13 @@ rtsock_open(void)
|
|||
#endif
|
||||
|
||||
if ((rtsock = prog_socket(PF_ROUTE, SOCK_RAW, 0)) == -1) {
|
||||
syslog(LOG_ERR, "%s: socket: %m", __func__);
|
||||
logit(LOG_ERR, "%s: socket: %m", __func__);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
#ifdef RO_MSGFILTER
|
||||
if (setsockopt(rtsock, PF_ROUTE, RO_MSGFILTER,
|
||||
&msgfilter, sizeof(msgfilter) == -1))
|
||||
syslog(LOG_ERR, "%s: RO_MSGFILTER: %m", __func__);
|
||||
logit(LOG_ERR, "%s: RO_MSGFILTER: %m", __func__);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -1692,7 +1697,7 @@ ra_output(struct rainfo *rai)
|
|||
struct soliciter *sol;
|
||||
|
||||
if ((rai->ifflags & IFF_UP) == 0) {
|
||||
syslog(LOG_DEBUG, "%s: %s is not up, skip sending RA",
|
||||
logit(LOG_DEBUG, "%s: %s is not up, skip sending RA",
|
||||
__func__, rai->ifname);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -1712,7 +1717,7 @@ ra_output(struct rainfo *rai)
|
|||
memset(&pi->ipi6_addr, 0, sizeof(pi->ipi6_addr)); /*XXX*/
|
||||
pi->ipi6_ifindex = rai->ifindex;
|
||||
|
||||
syslog(LOG_DEBUG,
|
||||
logit(LOG_DEBUG,
|
||||
"%s: send RA on %s, # of waitings = %d",
|
||||
__func__, rai->ifname, rai->waiting);
|
||||
|
||||
|
@ -1720,7 +1725,7 @@ ra_output(struct rainfo *rai)
|
|||
|
||||
if (i < 0 || (size_t)i != rai->ra_datalen) {
|
||||
if (i < 0) {
|
||||
syslog(LOG_ERR, "%s: sendmsg on %s: %m",
|
||||
logit(LOG_ERR, "%s: sendmsg on %s: %m",
|
||||
__func__, rai->ifname);
|
||||
}
|
||||
}
|
||||
|
@ -1736,7 +1741,7 @@ ra_output(struct rainfo *rai)
|
|||
i = sendmsg(sock, &sndmhdr, 0);
|
||||
if (i < 0 || i != rai->ra_datalen) {
|
||||
if (i < 0) {
|
||||
syslog(LOG_ERR,
|
||||
logit(LOG_ERR,
|
||||
"%s: unicast sendmsg on %s: %m",
|
||||
__func__, rai->ifname);
|
||||
}
|
||||
|
@ -1754,7 +1759,7 @@ ra_output(struct rainfo *rai)
|
|||
free_rainfo(rai);
|
||||
return NULL;
|
||||
}
|
||||
syslog(LOG_DEBUG,
|
||||
logit(LOG_DEBUG,
|
||||
"%s: expired RA,"
|
||||
" new config active for interface (%s)",
|
||||
__func__, rai->ifname);
|
||||
|
@ -1792,7 +1797,7 @@ ra_timeout(void *data)
|
|||
/* if necessary, reconstruct the packet. */
|
||||
#endif
|
||||
|
||||
syslog(LOG_DEBUG,
|
||||
logit(LOG_DEBUG,
|
||||
"%s: RA timer on %s is expired",
|
||||
__func__, rai->ifname);
|
||||
|
||||
|
@ -1832,8 +1837,48 @@ ra_timer_update(void *data, struct timespec *tm)
|
|||
tm->tv_sec = interval;
|
||||
tm->tv_nsec = 0;
|
||||
|
||||
syslog(LOG_DEBUG,
|
||||
logit(LOG_DEBUG,
|
||||
"%s: RA timer on %s is set to %jd:%jd",
|
||||
__func__, rai->ifname,
|
||||
(intmax_t)tm->tv_sec, (intmax_t)tm->tv_nsec);
|
||||
}
|
||||
|
||||
static const char *
|
||||
expandm(char *buf, size_t len, const char *fmt)
|
||||
{
|
||||
char *ptr;
|
||||
const char *e = strerror(errno);
|
||||
size_t cur = 0, elen = strlen(e);
|
||||
|
||||
*buf = '\0';
|
||||
while ((ptr = strstr(fmt, "%m")) != NULL) {
|
||||
size_t l = (size_t)(ptr - fmt);
|
||||
if (cur + elen + l + 1 >= len)
|
||||
return buf;
|
||||
memcpy(buf + cur, fmt, l);
|
||||
cur += l;
|
||||
memcpy(buf + cur, e, elen);
|
||||
cur += elen;
|
||||
fmt += l + 2;
|
||||
buf[cur] = '\0';
|
||||
}
|
||||
strlcat(buf, fmt, len);
|
||||
return buf;
|
||||
}
|
||||
|
||||
void
|
||||
logit(int level, const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
char buf[1024];
|
||||
|
||||
va_start(ap, fmt);
|
||||
if (!Dflag) {
|
||||
vsyslog(level, fmt, ap);
|
||||
va_end(ap);
|
||||
return;
|
||||
}
|
||||
|
||||
vfprintf(stderr, expandm(buf, sizeof(buf), fmt), ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: timer.c,v 1.13 2015/11/11 07:48:41 ozaki-r Exp $ */
|
||||
/* $NetBSD: timer.c,v 1.14 2017/11/06 15:15:04 christos Exp $ */
|
||||
/* $KAME: timer.c,v 1.11 2005/04/14 06:22:35 suz Exp $ */
|
||||
|
||||
/*
|
||||
|
@ -40,6 +40,7 @@
|
|||
#include <string.h>
|
||||
#include <search.h>
|
||||
#include "timer.h"
|
||||
#include "logit.h"
|
||||
#include "prog_ops.h"
|
||||
|
||||
struct rtadvd_timer_head_t ra_timer = TAILQ_HEAD_INITIALIZER(ra_timer);
|
||||
|
@ -62,7 +63,7 @@ rtadvd_add_timer(struct rtadvd_timer *(*timeout) (void *),
|
|||
struct rtadvd_timer *newtimer;
|
||||
|
||||
if ((newtimer = malloc(sizeof(*newtimer))) == NULL) {
|
||||
syslog(LOG_ERR,
|
||||
logit(LOG_ERR,
|
||||
"<%s> can't allocate memory", __func__);
|
||||
exit(1);
|
||||
}
|
||||
|
@ -70,7 +71,7 @@ rtadvd_add_timer(struct rtadvd_timer *(*timeout) (void *),
|
|||
memset(newtimer, 0, sizeof(*newtimer));
|
||||
|
||||
if (timeout == NULL) {
|
||||
syslog(LOG_ERR,
|
||||
logit(LOG_ERR,
|
||||
"<%s> timeout function unspecified", __func__);
|
||||
exit(1);
|
||||
}
|
||||
|
@ -156,7 +157,7 @@ rtadvd_timer_rest(struct rtadvd_timer *timer)
|
|||
|
||||
prog_clock_gettime(CLOCK_MONOTONIC, &now);
|
||||
if (timespeccmp(&timer->tm, &now, <=)) {
|
||||
syslog(LOG_DEBUG,
|
||||
logit(LOG_DEBUG,
|
||||
"<%s> a timer must be expired, but not yet",
|
||||
__func__);
|
||||
returnval.tv_sec = 0;
|
||||
|
|
Loading…
Reference in New Issue