diff options
-rw-r--r-- | usr.sbin/rtadvd/Makefile | 5 | ||||
-rw-r--r-- | usr.sbin/rtadvd/advcap.c | 12 | ||||
-rw-r--r-- | usr.sbin/rtadvd/config.c | 236 | ||||
-rw-r--r-- | usr.sbin/rtadvd/dump.c | 7 | ||||
-rw-r--r-- | usr.sbin/rtadvd/if.c | 67 | ||||
-rw-r--r-- | usr.sbin/rtadvd/log.c | 157 | ||||
-rw-r--r-- | usr.sbin/rtadvd/log.h | 28 | ||||
-rw-r--r-- | usr.sbin/rtadvd/rrenum.c | 113 | ||||
-rw-r--r-- | usr.sbin/rtadvd/rtadvd.8 | 16 | ||||
-rw-r--r-- | usr.sbin/rtadvd/rtadvd.c | 630 | ||||
-rw-r--r-- | usr.sbin/rtadvd/timer.c | 29 |
11 files changed, 608 insertions, 692 deletions
diff --git a/usr.sbin/rtadvd/Makefile b/usr.sbin/rtadvd/Makefile index 92c928d92fe..c9df9e0ae7f 100644 --- a/usr.sbin/rtadvd/Makefile +++ b/usr.sbin/rtadvd/Makefile @@ -1,8 +1,9 @@ -# $OpenBSD: Makefile,v 1.5 2006/12/19 14:50:29 itojun Exp $ +# $OpenBSD: Makefile,v 1.6 2008/04/21 20:40:55 rainer Exp $ PROG= rtadvd -SRCS= rtadvd.c rrenum.c advcap.c if.c config.c timer.c dump.c +SRCS= rtadvd.c rrenum.c advcap.c if.c config.c timer.c dump.c log.c +CFLAGS+=-Wall LDADD+= -lutil DPADD+= ${LIBUTIL} MAN= rtadvd.8 rtadvd.conf.5 diff --git a/usr.sbin/rtadvd/advcap.c b/usr.sbin/rtadvd/advcap.c index be9cf8baf9b..463f8352206 100644 --- a/usr.sbin/rtadvd/advcap.c +++ b/usr.sbin/rtadvd/advcap.c @@ -1,4 +1,4 @@ -/* $OpenBSD: advcap.c,v 1.12 2008/04/20 11:36:48 rainer Exp $ */ +/* $OpenBSD: advcap.c,v 1.13 2008/04/21 20:40:55 rainer Exp $ */ /* $KAME: advcap.c,v 1.9 2002/05/29 14:28:35 itojun Exp $ */ /* @@ -42,10 +42,10 @@ #include <ctype.h> #include <stdlib.h> #include <stdio.h> -#include <syslog.h> #include <errno.h> #include <string.h> #include "pathnames.h" +#include "log.h" #ifndef BUFSIZ #define BUFSIZ 1024 @@ -64,7 +64,6 @@ #define V_TERM "HOST" #endif -char *RM; /* * termcap - routines for dealing with the terminal capability data base @@ -131,11 +130,10 @@ getent(bp, name, cp) * has to already have the newlines crunched out. */ if (cp && *cp) { - tf = open(RM = cp, O_RDONLY); + tf = open(cp, O_RDONLY); } if (tf < 0) { - syslog(LOG_WARNING, - "<%s> open: %s", __func__, strerror(errno)); + log_warn("open"); return (-2); } for (;;) { @@ -211,6 +209,8 @@ tnchktc() return (0); } if (getent(tcbuf, tcname, remotefile) != 1) { + log_warnx("Could not parse %s: " + "Unresolvable reference to %s.", remotefile, tcname); return (0); } for (q = tcbuf; *q++ != ':'; ) diff --git a/usr.sbin/rtadvd/config.c b/usr.sbin/rtadvd/config.c index 2c7d032ca80..b344b51f13a 100644 --- a/usr.sbin/rtadvd/config.c +++ b/usr.sbin/rtadvd/config.c @@ -1,4 +1,4 @@ -/* $OpenBSD: config.c,v 1.24 2008/04/20 11:36:48 rainer Exp $ */ +/* $OpenBSD: config.c,v 1.25 2008/04/21 20:40:55 rainer Exp $ */ /* $KAME: config.c,v 1.62 2002/05/29 10:13:10 itojun Exp $ */ /* @@ -49,7 +49,6 @@ #include <arpa/inet.h> #include <stdio.h> -#include <syslog.h> #include <errno.h> #include <string.h> #include <stdlib.h> @@ -62,6 +61,7 @@ #include "timer.h" #include "if.h" #include "config.h" +#include "log.h" static void makeentry(char *, size_t, int, char *); static int getinet6sysctl(int); @@ -86,7 +86,7 @@ getconfig(intface) do { \ int64_t t; \ if ((t = agetnum(cap)) < 0) { \ - fprintf(stderr, "rtadvd: need %s for interface %s\n", \ + log_warnx("need %s for interface %s", \ cap, intface); \ exit(1); \ } \ @@ -100,19 +100,15 @@ getconfig(intface) if ((stat = agetent(tbuf, intface)) <= 0) { memset(tbuf, 0, sizeof(tbuf)); - syslog(LOG_INFO, - "<%s> %s isn't defined in the configuration file" - " or the configuration file doesn't exist." - " Treat it as default", - __func__, intface); + log_info("Could not parse configuration file for %s" + " or the configuration file doesn't exist." + " Treat it as default", intface); } tmp = (struct rainfo *)malloc(sizeof(*ralist)); - if (tmp == NULL) { - syslog(LOG_INFO, "<%s> %s: can't allocate enough memory", - __func__, intface); - exit(1); - } + if (tmp == NULL) + fatal("malloc"); + memset(tmp, 0, sizeof(*tmp)); tmp->prefix.next = tmp->prefix.prev = &tmp->prefix; @@ -129,9 +125,7 @@ getconfig(intface) tmp->advlinkopt = 1; if (tmp->advlinkopt) { if ((tmp->sdl = if_nametosdl(intface)) == NULL) { - syslog(LOG_ERR, - "<%s> can't get information of %s", - __func__, intface); + log_warnx("can't get information of %s", intface); exit(1); } tmp->ifindex = tmp->sdl->sdl_index; @@ -140,9 +134,8 @@ getconfig(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", - __func__, intface, IPV6_MMTU); + log_warn("can't get interface mtu of %s. Treat as %d", + intface, IPV6_MMTU); } /* @@ -150,20 +143,17 @@ getconfig(intface) */ MAYHAVE(val, "maxinterval", DEF_MAXRTRADVINTERVAL); if (val < MIN_MAXINTERVAL || val > MAX_MAXINTERVAL) { - syslog(LOG_ERR, - "<%s> maxinterval (%ld) on %s is invalid " - "(must be between %e and %u)", __func__, val, - intface, MIN_MAXINTERVAL, MAX_MAXINTERVAL); + log_warnx("maxinterval (%ld) on %s is invalid " + "(must be between %e and %u)", 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 " - "(must be between %e and %d)", - __func__, val, intface, MIN_MININTERVAL, - (tmp->maxinterval * 3) / 4); + log_warnx("mininterval (%ld) on %s is invalid " + "(must be between %e and %d)", + val, intface, MIN_MININTERVAL, (tmp->maxinterval * 3) / 4); exit(1); } tmp->mininterval = (u_int)val; @@ -180,18 +170,17 @@ getconfig(intface) #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); + log_warnx("invalid router preference (%02x) on %s", + tmp->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 " - "(must be 0 or between %d and %d)", - __func__, val, intface, - tmp->maxinterval, MAXROUTERLIFETIME); + log_warnx("router lifetime (%ld) on %s is invalid " + "(must be 0 or between %d and %d)", + val, intface, + tmp->maxinterval, MAXROUTERLIFETIME); exit(1); } /* @@ -203,37 +192,33 @@ getconfig(intface) * explicitly set zero. (see also the above section) */ if (val && forwarding == 0) { - syslog(LOG_ERR, - "<%s> non zero router lifetime is specified for %s, " - "which must not be allowed for hosts. you must " - "change router lifetime or enable IPv6 forwarding.", - __func__, intface); + log_warnx("non zero router lifetime is specified for %s, " + "which must not be allowed for hosts. you must " + "change router lifetime or enable IPv6 forwarding.", + intface); exit(1); } tmp->lifetime = val & 0xffff; MAYHAVE(val, "rtime", DEF_ADVREACHABLETIME); if (val < 0 || val > MAXREACHABLETIME) { - syslog(LOG_ERR, - "<%s> reachable time (%ld) on %s is invalid " - "(must be no greater than %d)", - __func__, val, intface, MAXREACHABLETIME); + log_warnx("reachable time (%ld) on %s is invalid" + " (must be no greater than %d)", + val, intface, MAXREACHABLETIME); exit(1); } tmp->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", - __func__, (long long)val64, intface); + log_warnx("retrans time (%lld) on %s out of range", + (long long)val64, intface); exit(1); } tmp->retranstimer = (u_int32_t)val64; if (agetnum("hapref") != -1 || agetnum("hatime") != -1) { - syslog(LOG_ERR, - "<%s> mobile-ip6 configuration not supported", - __func__); + log_warnx("mobile-ip6 configuration not supported"); exit(1); } /* prefix information */ @@ -257,12 +242,8 @@ getconfig(intface) continue; /* allocate memory to store prefix information */ - if ((pfx = malloc(sizeof(struct prefix))) == NULL) { - syslog(LOG_ERR, - "<%s> can't allocate enough memory", - __func__); - exit(1); - } + if ((pfx = malloc(sizeof(struct prefix))) == NULL) + fatal("malloc"); memset(pfx, 0, sizeof(*pfx)); /* link into chain */ @@ -272,30 +253,26 @@ getconfig(intface) pfx->origin = PREFIX_FROM_CONFIG; if (inet_pton(AF_INET6, addr, &pfx->prefix) != 1) { - syslog(LOG_ERR, - "<%s> inet_pton failed for %s", - __func__, addr); + log_warn("inet_pton failed for %s", addr); exit(1); } if (IN6_IS_ADDR_MULTICAST(&pfx->prefix)) { - syslog(LOG_ERR, - "<%s> multicast prefix (%s) must " - "not be advertised on %s", - __func__, addr, intface); + log_warnx("multicast prefix (%s) must" + " not be advertised on %s", + addr, intface); exit(1); } if (IN6_IS_ADDR_LINKLOCAL(&pfx->prefix)) - syslog(LOG_NOTICE, - "<%s> link-local prefix (%s) will be" - " advertised on %s", - __func__, addr, intface); + log_info("link-local prefix (%s) will be" + " advertised on %s", + 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 " - "on %s out of range", - __func__, val, addr, intface); + log_warnx("prefixlen (%ld) for %s " + "on %s out of range", + val, addr, intface); exit(1); } pfx->prefixlen = (int)val; @@ -309,9 +286,9 @@ getconfig(intface) makeentry(entbuf, sizeof(entbuf), i, "vltime"); MAYHAVE(val64, entbuf, DEF_ADVVALIDLIFETIME); if (val64 < 0 || val64 > 0xffffffff) { - syslog(LOG_ERR, "<%s> vltime (%lld) for " - "%s/%d on %s is out of range", - __func__, (long long)val64, + log_warnx("vltime (%lld) for" + " %s/%d on %s is out of range", + (long long)val64, addr, pfx->prefixlen, intface); exit(1); } @@ -328,10 +305,9 @@ getconfig(intface) makeentry(entbuf, sizeof(entbuf), i, "pltime"); MAYHAVE(val64, entbuf, DEF_ADVPREFERREDLIFETIME); if (val64 < 0 || val64 > 0xffffffff) { - syslog(LOG_ERR, - "<%s> pltime (%lld) for %s/%d on %s " - "is out of range", - __func__, (long long)val64, + log_warnx("pltime (%lld) for %s/%d on %s" + " is out of range", + (long long)val64, addr, pfx->prefixlen, intface); exit(1); } @@ -350,9 +326,7 @@ getconfig(intface) MAYHAVE(val, "mtu", 0); if (val < 0 || val > 0xffffffff) { - syslog(LOG_ERR, - "<%s> mtu (%ld) on %s out of range", - __func__, val, intface); + log_warnx("mtu (%ld) on %s out of range", val, intface); exit(1); } tmp->linkmtu = (u_int32_t)val; @@ -364,18 +338,17 @@ getconfig(intface) tmp->linkmtu = tmp->phymtu; } else if (tmp->linkmtu < IPV6_MMTU || tmp->linkmtu > tmp->phymtu) { - syslog(LOG_ERR, - "<%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); + log_warnx("advertised link mtu (%lu) on %s is invalid (must" + " be between least MTU (%d) and physical link MTU (%d)", + (unsigned long)tmp->linkmtu, intface, + IPV6_MMTU, tmp->phymtu); exit(1); } /* route information */ MAYHAVE(val, "routes", -1); if (val != -1) - syslog(LOG_INFO, "route information option is not available"); + log_info("route information option is not available"); /* okey */ tmp->next = ralist; @@ -400,12 +373,8 @@ get_prefix(struct rainfo *rai) u_char *p, *ep, *m, *lim; u_char ntopbuf[INET6_ADDRSTRLEN]; - if (getifaddrs(&ifap) < 0) { - syslog(LOG_ERR, - "<%s> can't get interface addresses", - __func__); - exit(1); - } + if (getifaddrs(&ifap) < 0) + fatal("can't get interface addresses"); for (ifa = ifap; ifa; ifa = ifa->ifa_next) { int plen; @@ -421,12 +390,8 @@ get_prefix(struct rainfo *rai) m = (u_char *)&((struct sockaddr_in6 *)ifa->ifa_netmask)->sin6_addr; 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 " - "or prefix is invalid", - __func__); - exit(1); - } + if (plen <= 0 || plen > 128) + fatalx("failed to get prefixlen or prefix is invalid"); if (plen == 128) /* XXX */ continue; if (find_prefix(rai, a, plen)) { @@ -435,12 +400,8 @@ get_prefix(struct rainfo *rai) } /* allocate memory to store prefix info. */ - if ((pp = malloc(sizeof(*pp))) == NULL) { - syslog(LOG_ERR, - "<%s> can't get allocate buffer for prefix", - __func__); - exit(1); - } + if ((pp = malloc(sizeof(*pp))) == NULL) + fatal("malloc"); memset(pp, 0, sizeof(*pp)); /* set prefix, sweep bits outside of prefixlen */ @@ -456,13 +417,10 @@ get_prefix(struct rainfo *rai) *p++ = 0x00; } if (!inet_ntop(AF_INET6, &pp->prefix, ntopbuf, - sizeof(ntopbuf))) { - syslog(LOG_ERR, "<%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); + sizeof(ntopbuf))) + fatal("inet_ntop failed"); + log_debug("add %s/%d to prefix list on %s", + ntopbuf, pp->prefixlen, rai->ifname); /* set other fields with protocol defaults */ pp->validlifetime = DEF_ADVVALIDLIFETIME; @@ -509,8 +467,7 @@ add_prefix(struct rainfo *rai, struct in6_prefixreq *ipr) u_char ntopbuf[INET6_ADDRSTRLEN]; if ((prefix = malloc(sizeof(*prefix))) == NULL) { - syslog(LOG_ERR, "<%s> memory allocation failed", - __func__); + log_warn("malloc"); return; /* XXX: error or exit? */ } memset(prefix, 0, sizeof(*prefix)); @@ -524,10 +481,10 @@ add_prefix(struct rainfo *rai, struct in6_prefixreq *ipr) insque(prefix, &rai->prefix); - syslog(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); + log_debug("new prefix %s/%d was added on %s", + inet_ntop(AF_INET6, &ipr->ipr_prefix.sin6_addr, + ntopbuf, INET6_ADDRSTRLEN), + ipr->ipr_plen, rai->ifname); /* free the previous packet */ free(rai->ra_data); @@ -556,10 +513,9 @@ delete_prefix(struct rainfo *rai, struct prefix *prefix) u_char ntopbuf[INET6_ADDRSTRLEN]; remque(prefix); - syslog(LOG_DEBUG, "<%s> prefix %s/%d was deleted on %s", - __func__, inet_ntop(AF_INET6, &prefix->prefix, - ntopbuf, INET6_ADDRSTRLEN), - prefix->prefixlen, rai->ifname); + log_debug("prefix %s/%d was deleted on %s", + inet_ntop(AF_INET6, &prefix->prefix, ntopbuf, INET6_ADDRSTRLEN), + prefix->prefixlen, rai->ifname); free(prefix); rai->pfxs--; make_packet(rai); @@ -577,14 +533,12 @@ init_prefix(struct in6_prefixreq *ipr) int s; if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) { - syslog(LOG_ERR, "<%s> socket: %s", __func__, - strerror(errno)); + log_warn("socket"); exit(1); } if (ioctl(s, SIOCGIFPREFIX_IN6, (caddr_t)ipr) < 0) { - syslog(LOG_WARNING, "<%s> ioctl:SIOCGIFPREFIX %s", __func__, - strerror(errno)); + log_warn("ioctl:SIOCGIFFLAGS: failed for %s", ifr.ifr_name); ipr->ipr_vltime = DEF_ADVVALIDLIFETIME; ipr->ipr_pltime = DEF_ADVPREFERREDLIFETIME; @@ -595,11 +549,11 @@ init_prefix(struct in6_prefixreq *ipr) else if (ipr->ipr_origin < PR_ORIG_RR) { u_char ntopbuf[INET6_ADDRSTRLEN]; - syslog(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, - sizeof(ntopbuf)), ipr->ipr_origin); + log_warn("Added prefix(%s)'s origin %d is" + " lower than PR_ORIG_RR(router renumbering)." + " This should not happen if I am router", + inet_ntop(AF_INET6, &ipr->ipr_prefix.sin6_addr, ntopbuf, + sizeof(ntopbuf)), ipr->ipr_origin); close(s); return 1; } @@ -622,9 +576,8 @@ 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" - "exist. This should not happen! %s", __func__, - ifindex, strerror(errno)); + log_warn("Prefix added interface No.%d doesn't" + " exist. This should not happen!", ifindex); exit(1); } ipr.ipr_prefix.sin6_len = sizeof(ipr.ipr_prefix); @@ -651,10 +604,9 @@ make_packet(struct rainfo *rainfo) packlen = sizeof(struct nd_router_advert); if (rainfo->advlinkopt) { if ((lladdroptlen = lladdropt_length(rainfo->sdl)) == 0) { - syslog(LOG_INFO, - "<%s> link-layer address option has" - " null length on %s. Treat as not included.", - __func__, rainfo->ifname); + log_info("link-layer address option has" + " null length on %s. Treat as not included.", + rainfo->ifname); rainfo->advlinkopt = 0; } packlen += lladdroptlen; @@ -665,12 +617,8 @@ make_packet(struct rainfo *rainfo) packlen += sizeof(struct nd_opt_mtu); /* allocate memory for the packet */ - if ((buf = malloc(packlen)) == NULL) { - syslog(LOG_ERR, - "<%s> can't get enough memory for an RA packet", - __func__); - exit(1); - } + if ((buf = malloc(packlen)) == NULL) + fatal("malloc"); if (rainfo->ra_data) { /* free the previous packet */ free(rainfo->ra_data); @@ -776,9 +724,7 @@ getinet6sysctl(int code) size = sizeof(value); if (sysctl(mib, sizeof(mib)/sizeof(mib[0]), &value, &size, NULL, 0) < 0) { - syslog(LOG_ERR, "<%s>: failed to get ip6 sysctl(%d): %s", - __func__, code, - strerror(errno)); + log_warn("failed to get ip6 sysctl(%d)", code); return(-1); } else diff --git a/usr.sbin/rtadvd/dump.c b/usr.sbin/rtadvd/dump.c index 401e97fc688..d6263f79935 100644 --- a/usr.sbin/rtadvd/dump.c +++ b/usr.sbin/rtadvd/dump.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dump.c,v 1.6 2002/06/10 19:57:35 espie Exp $ */ +/* $OpenBSD: dump.c,v 1.7 2008/04/21 20:40:55 rainer Exp $ */ /* $KAME: dump.c,v 1.27 2002/05/29 14:23:55 itojun Exp $ */ /* @@ -47,7 +47,6 @@ #include <time.h> #include <stdio.h> #include <stdarg.h> -#include <syslog.h> #include <string.h> #include <errno.h> #include <netdb.h> @@ -56,6 +55,7 @@ #include "timer.h" #include "if.h" #include "dump.h" +#include "log.h" static FILE *fp; @@ -207,8 +207,7 @@ rtadvd_dump_file(dumpfile) char *dumpfile; { if ((fp = fopen(dumpfile, "w")) == NULL) { - syslog(LOG_WARNING, "<%s> open a dump file(%s)", - __func__, dumpfile); + log_warn("open a dump file(%s)", dumpfile); return; } diff --git a/usr.sbin/rtadvd/if.c b/usr.sbin/rtadvd/if.c index 9bf5037987d..a388dfec180 100644 --- a/usr.sbin/rtadvd/if.c +++ b/usr.sbin/rtadvd/if.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if.c,v 1.17 2006/11/16 16:08:15 henning Exp $ */ +/* $OpenBSD: if.c,v 1.18 2008/04/21 20:40:55 rainer Exp $ */ /* $KAME: if.c,v 1.17 2001/01/21 15:27:30 itojun Exp $ */ /* @@ -46,9 +46,9 @@ #include <errno.h> #include <stdlib.h> #include <string.h> -#include <syslog.h> #include "rtadvd.h" #include "if.h" +#include "log.h" #define ROUNDUP(a, size) \ (((a) & ((size)-1)) ? (1 + ((a) | ((size)-1))) : (a)) @@ -161,15 +161,13 @@ if_getflags(int ifindex, int oifflags) int s; if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) { - syslog(LOG_ERR, "<%s> socket: %s", __func__, - strerror(errno)); + log_warn("socket"); 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", - __func__, ifr.ifr_name); + log_warn("ioctl:SIOCGIFFLAGS: failed for %s", ifr.ifr_name); close(s); return (oifflags & ~IFF_UP); } @@ -205,8 +203,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)", - __func__, sdl->sdl_type); + log_warn("unsupported link type(%d)", sdl->sdl_type); exit(1); } @@ -242,9 +239,8 @@ 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 " - "(buf=%p lim=%p rtm=%p)", __func__, - buf, lim, rtm); + log_warnx("rtm_msglen is 0 (buf=%p lim=%p rtm=%p)", + buf, lim, rtm); break; } if (FILTER_MATCH(rtm->rtm_type, filter) == 0) { @@ -463,20 +459,12 @@ get_iflist(char **buf, size_t *size) mib[4] = NET_RT_IFLIST; mib[5] = 0; - if (sysctl(mib, 6, NULL, size, NULL, 0) < 0) { - syslog(LOG_ERR, "<%s> sysctl: iflist size get failed", - __func__); - exit(1); - } - if ((*buf = malloc(*size)) == NULL) { - syslog(LOG_ERR, "<%s> malloc failed", __func__); - exit(1); - } - if (sysctl(mib, 6, *buf, size, NULL, 0) < 0) { - syslog(LOG_ERR, "<%s> sysctl: iflist get failed", - __func__); - exit(1); - } + if (sysctl(mib, 6, NULL, size, NULL, 0) < 0) + fatal("sysctl: iflist size get failed"); + if ((*buf = malloc(*size)) == NULL) + fatal("malloc"); + if (sysctl(mib, 6, *buf, size, NULL, 0) < 0) + fatal("sysctl: iflist get failed"); return; } @@ -499,29 +487,26 @@ parse_iflist(struct if_msghdr ***ifmlist_p, char *buf, size_t bufsize) 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); - } + if ((*ifmlist_p = (struct if_msghdr **)malloc(malloc_size)) == NULL) + fatal("malloc"); 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 " - "(buf=%p lim=%p ifm=%p)", __func__, - buf, lim, ifm); + log_warn("ifm_msglen is 0 (buf=%p lim=%p ifm=%p)", + buf, lim, ifm); return; } if (ifm->ifm_type == RTM_IFINFO) { (*ifmlist_p)[ifm->ifm_index] = ifm; } else { - syslog(LOG_ERR, "out of sync parsing NET_RT_IFLIST," - "expected %d, got %d, msglen = %d," - "buf:%p, ifm:%p, lim:%p", - RTM_IFINFO, ifm->ifm_type, ifm->ifm_msglen, - buf, ifm, lim); - exit (1); + log_warn("out of sync parsing NET_RT_IFLIST," + " expected %d, got %d, msglen = %d," + " buf:%p, ifm:%p, lim:%p", + RTM_IFINFO, ifm->ifm_type, ifm->ifm_msglen, + buf, ifm, lim); + exit(1); } for (ifam = (struct ifa_msghdr *) ((char *)ifm + ifm->ifm_msglen); @@ -530,9 +515,9 @@ parse_iflist(struct if_msghdr ***ifmlist_p, char *buf, size_t bufsize) ((char *)ifam + ifam->ifam_msglen)) { /* just for safety */ if (!ifam->ifam_msglen) { - syslog(LOG_WARNING, "<%s> ifa_msglen is 0 " - "(buf=%p lim=%p ifam=%p)", __func__, - buf, lim, ifam); + log_warnx("ifa_msglen is 0 " + "(buf=%p lim=%p ifam=%p)", + buf, lim, ifam); return; } if (ifam->ifam_type != RTM_NEWADDR) diff --git a/usr.sbin/rtadvd/log.c b/usr.sbin/rtadvd/log.c new file mode 100644 index 00000000000..9b6c8980590 --- /dev/null +++ b/usr.sbin/rtadvd/log.c @@ -0,0 +1,157 @@ +/* + * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <err.h> +#include <errno.h> +#include <netdb.h> +#include <stdarg.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <syslog.h> +#include <time.h> +#include <unistd.h> + +#include "log.h" + +int debug; + +void logit(int, const char *, ...); +void vlog(int pri, const char *fmt, va_list ap); + +void +log_init(int n_debug) +{ + extern char *__progname; + + debug = n_debug; + + if (!debug) + openlog(__progname, LOG_PID | LOG_NDELAY, LOG_DAEMON); + + tzset(); +} + +void +logit(int pri, const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + vlog(pri, fmt, ap); + va_end(ap); +} + +void +vlog(int pri, const char *fmt, va_list ap) +{ + char *nfmt; + + if (debug) { + /* best effort in out of mem situations */ + if (asprintf(&nfmt, "%s\n", fmt) == -1) { + vfprintf(stderr, fmt, ap); + fprintf(stderr, "\n"); + } else { + vfprintf(stderr, nfmt, ap); + free(nfmt); + } + fflush(stderr); + } else + vsyslog(pri, fmt, ap); +} + +void +log_warn(const char *emsg, ...) +{ + char *nfmt; + va_list ap; + + if (emsg == NULL) + logit(LOG_CRIT, "%s", strerror(errno)); + else { + va_start(ap, emsg); + + /* best effort to even work in out of memory situations */ + if (asprintf(&nfmt, "%s: %s", emsg, strerror(errno)) == -1) { + /* we tried it... */ + vlog(LOG_CRIT, emsg, ap); + logit(LOG_CRIT, "%s", strerror(errno)); + } else { + vlog(LOG_CRIT, nfmt, ap); + free(nfmt); + } + va_end(ap); + } +} + +void +log_warnx(const char *emsg, ...) +{ + va_list ap; + + va_start(ap, emsg); + vlog(LOG_CRIT, emsg, ap); + va_end(ap); +} + +void +log_info(const char *emsg, ...) +{ + va_list ap; + + va_start(ap, emsg); + vlog(LOG_INFO, emsg, ap); + va_end(ap); +} + +void +log_debug(const char *emsg, ...) +{ + va_list ap; + + if (debug) { + va_start(ap, emsg); + vlog(LOG_DEBUG, emsg, ap); + va_end(ap); + } +} + +void +fatal(const char *emsg) +{ + extern char *__progname; + + if (emsg == NULL) + logit(LOG_CRIT, "fatal in %s: %s", __progname, + strerror(errno)); + else + if (errno) + logit(LOG_CRIT, "fatal in %s: %s: %s", + __progname, emsg, strerror(errno)); + else + logit(LOG_CRIT, "fatal in %s: %s", + __progname, emsg); + + exit(1); +} + +void +fatalx(const char *emsg) +{ + errno = 0; + fatal(emsg); +} diff --git a/usr.sbin/rtadvd/log.h b/usr.sbin/rtadvd/log.h new file mode 100644 index 00000000000..aeb2c5bc6b5 --- /dev/null +++ b/usr.sbin/rtadvd/log.h @@ -0,0 +1,28 @@ +/* + * Copyright (c) 20083, 2004 Henning Brauer <henning@openbsd.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <stdarg.h> + +void log_init(int); +void logit(int pri, const char *fmt, ...); + +void fatal(const char*); +void log_warn(const char*, ...) __attribute__((format(printf, 1, 2))); +void log_info(const char*, ...) __attribute__((format(printf, 1, 2))); +void log_debug(const char*, ...) __attribute__((format(printf, 1, 2))); + +void fatalx(const char*); +void log_warnx(const char*, ...) __attribute__((format(printf, 1, 2))); diff --git a/usr.sbin/rtadvd/rrenum.c b/usr.sbin/rtadvd/rrenum.c index 6ef891bf395..4664ff2baad 100644 --- a/usr.sbin/rtadvd/rrenum.c +++ b/usr.sbin/rtadvd/rrenum.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rrenum.c,v 1.10 2002/06/10 19:57:35 espie Exp $ */ +/* $OpenBSD: rrenum.c,v 1.11 2008/04/21 20:40:55 rainer Exp $ */ /* $KAME: rrenum.c,v 1.11 2002/05/21 14:26:55 itojun Exp $ */ /* @@ -46,10 +46,10 @@ #include <errno.h> #include <string.h> #include <stdlib.h> -#include <syslog.h> #include "rtadvd.h" #include "rrenum.h" #include "if.h" +#include "log.h" #define RR_ISSET_SEGNUM(segnum_bits, segnum) \ ((((segnum_bits)[(segnum) >> 5]) & (1 << ((segnum) & 31))) != 0) @@ -84,8 +84,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", - __func__, rpm->rpm_len); + log_warnx("rpm_len %d is not 4N * 3", rpm->rpm_len); return 1; } /* rpm->rpm_code must be valid value */ @@ -95,14 +94,12 @@ 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__, - rpm->rpm_code); + log_warnx("unknown rpm_code %d", 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", - __func__, rpm->rpm_matchlen); + log_warnx("rpm_matchlen %d is over 128", rpm->rpm_matchlen); return 1; } @@ -124,11 +121,11 @@ 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" - " rpu_keeplen %d is %d(over 128)", - __func__, rpu->rpu_uselen, - rpu->rpu_keeplen, - rpu->rpu_uselen + rpu->rpu_keeplen); + log_warnx("sum of rpu_uselen %d and" + " rpu_keeplen %d is %d(over 128)", + rpu->rpu_uselen, + rpu->rpu_keeplen, + rpu->rpu_uselen + rpu->rpu_keeplen); return 1; } } @@ -162,8 +159,7 @@ do_use_prefix(int len, struct rr_pco_match *rpm, irr->irr_useprefix.sin6_addr = in6addr_any; if (ioctl(s, rrcmd2pco[rpm->rpm_code], (caddr_t)irr) < 0 && errno != EADDRNOTAVAIL) - syslog(LOG_ERR, "<%s> ioctl: %s", __func__, - strerror(errno)); + log_warn("ioctl"); return; } @@ -194,8 +190,7 @@ do_use_prefix(int len, struct rr_pco_match *rpm, if (ioctl(s, rrcmd2pco[rpm->rpm_code], (caddr_t)irr) < 0 && errno != EADDRNOTAVAIL) - syslog(LOG_ERR, "<%s> ioctl: %s", __func__, - strerror(errno)); + log_warn("ioctl"); /* very adhoc: should be rewritten */ if (rpm->rpm_code == RPM_PCO_CHANGE && @@ -246,11 +241,8 @@ do_pco(struct icmp6_router_renum *rr, int len, struct rr_pco_match *rpm) if ((rr_pco_check(len, rpm) != NULL)) return 1; - if (s == -1 && (s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) { - syslog(LOG_ERR, "<%s> socket: %s", __func__, - strerror(errno)); - exit(1); - } + if (s == -1 && (s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) + fatal("socket"); memset(&irr, 0, sizeof(irr)); irr.irr_origin = PR_ORIG_RR; @@ -275,8 +267,7 @@ do_pco(struct icmp6_router_renum *rr, int len, struct rr_pco_match *rpm) if (errno == ENXIO) return 0; else if (errno) { - syslog(LOG_ERR, "<%s> if_indextoname: %s", __func__, - strerror(errno)); + log_warn("if_indextoname"); return 1; } return 0; @@ -306,8 +297,8 @@ do_rr(int len, struct icmp6_router_renum *rr) rpm = (struct rr_pco_match *)cp; if (len < sizeof(struct rr_pco_match)) { tooshort: - syslog(LOG_ERR, "<%s> pkt too short. left len = %d. " - "gabage at end of pkt?", __func__, len); + log_warnx("pkt too short. left len = %d. " + "gabage at end of pkt?", len); return 1; } rpmlen = rpm->rpm_len << 3; @@ -315,7 +306,7 @@ do_rr(int len, struct icmp6_router_renum *rr) goto tooshort; if (do_pco(rr, rpmlen, rpm)) { - syslog(LOG_WARNING, "<%s> invalid PCO", __func__); + log_warn("invalid PCO"); goto next; } @@ -341,37 +332,33 @@ rr_command_check(int len, struct icmp6_router_renum *rr, struct in6_addr *from, /* rr_command length check */ if (len < (sizeof(struct icmp6_router_renum) + sizeof(struct rr_pco_match))) { - syslog(LOG_ERR, "<%s> rr_command len %d is too short", - __func__, len); + log_warnx("rr_command len %d is too short", 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", - __func__, - inet_ntop(AF_INET6, dst, ntopbuf, INET6_ADDRSTRLEN)); + log_warnx("dst mcast addr %s is illegal", + 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", - __func__, (u_int32_t)ntohl(rr->rr_seqnum), - inet_ntop(AF_INET6, from, ntopbuf, INET6_ADDRSTRLEN)); + log_warnx("rcvd old seqnum %d from %s", + (u_int32_t)ntohl(rr->rr_seqnum), + inet_ntop(AF_INET6, from, ntopbuf, INET6_ADDRSTRLEN)); return 1; } if (rro.rro_seqnum == rr->rr_seqnum && (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", - __func__, rr->rr_segnum, - inet_ntop(AF_INET6, from, ntopbuf, - INET6_ADDRSTRLEN)); + log_warnx("rcvd duped segnum %d from %s", + rr->rr_segnum, + inet_ntop(AF_INET6, from, ntopbuf, + INET6_ADDRSTRLEN)); return 0; } @@ -410,7 +397,7 @@ rr_command_input(int len, struct icmp6_router_renum *rr, return; failed: - syslog(LOG_ERR, "<%s> received RR was invalid", __func__); + log_warnx("received RR was invalid"); return; } @@ -420,23 +407,20 @@ rr_input(int len, struct icmp6_router_renum *rr, struct in6_pktinfo *pi, { u_char ntopbuf[2][INET6_ADDRSTRLEN], ifnamebuf[IFNAMSIZ]; - syslog(LOG_DEBUG, - "<%s> RR received from %s to %s on %s", - __func__, - inet_ntop(AF_INET6, &from->sin6_addr, - ntopbuf[0], INET6_ADDRSTRLEN), - inet_ntop(AF_INET6, &dst, ntopbuf[1], INET6_ADDRSTRLEN), - if_indextoname(pi->ipi6_ifindex, ifnamebuf)); + log_debug("RR received from %s to %s on %s", + inet_ntop(AF_INET6, &from->sin6_addr, + ntopbuf[0], INET6_ADDRSTRLEN), + inet_ntop(AF_INET6, &dst, ntopbuf[1], INET6_ADDRSTRLEN), + if_indextoname(pi->ipi6_ifindex, ifnamebuf)); /* 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", - __func__, len, - inet_ntop(AF_INET6, &from->sin6_addr, - ntopbuf[0], INET6_ADDRSTRLEN), - inet_ntop(AF_INET6, &dst, ntopbuf[1], INET6_ADDRSTRLEN), - if_indextoname(pi->ipi6_ifindex, ifnamebuf)); + log_info("RR short message (size %d) from %s to %s on %s", + len, + inet_ntop(AF_INET6, &from->sin6_addr, + ntopbuf[0], INET6_ADDRSTRLEN), + inet_ntop(AF_INET6, &dst, ntopbuf[1], INET6_ADDRSTRLEN), + if_indextoname(pi->ipi6_ifindex, ifnamebuf)); return; } @@ -450,14 +434,12 @@ rr_input(int len, struct icmp6_router_renum *rr, struct in6_pktinfo *pi, */ if (IN6_IS_ADDR_MULTICAST(&pi->ipi6_addr) && !IN6_ARE_ADDR_EQUAL(&in6a_site_allrouters, &pi->ipi6_addr)) { - syslog(LOG_NOTICE, - "<%s>: RR message with invalid destination (%s) " - "from %s on %s", - __func__, - inet_ntop(AF_INET6, &dst, ntopbuf[0], INET6_ADDRSTRLEN), - inet_ntop(AF_INET6, &from->sin6_addr, - ntopbuf[1], INET6_ADDRSTRLEN), - if_indextoname(pi->ipi6_ifindex, ifnamebuf)); + log_info("RR message with invalid destination (%s) " + "from %s on %s", + inet_ntop(AF_INET6, &dst, ntopbuf[0], INET6_ADDRSTRLEN), + inet_ntop(AF_INET6, &from->sin6_addr, + ntopbuf[1], INET6_ADDRSTRLEN), + if_indextoname(pi->ipi6_ifindex, ifnamebuf)); return; } @@ -475,8 +457,7 @@ rr_input(int len, struct icmp6_router_renum *rr, struct in6_pktinfo *pi, /* TODO: sequence number reset */ break; default: - syslog(LOG_ERR, "<%s> received unknown code %d", - __func__, rr->rr_code); + log_warnx("received unknown code %d", rr->rr_code); break; } diff --git a/usr.sbin/rtadvd/rtadvd.8 b/usr.sbin/rtadvd/rtadvd.8 index 6bc200c48d6..55d9cb393b1 100644 --- a/usr.sbin/rtadvd/rtadvd.8 +++ b/usr.sbin/rtadvd/rtadvd.8 @@ -1,4 +1,4 @@ -.\" $OpenBSD: rtadvd.8,v 1.23 2007/05/31 19:20:29 jmc Exp $ +.\" $OpenBSD: rtadvd.8,v 1.24 2008/04/21 20:40:55 rainer Exp $ .\" $KAME: rtadvd.8,v 1.18 2002/04/28 10:43:02 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 $Mdocdate: May 31 2007 $ +.Dd $Mdocdate: April 21 2008 $ .Dt RTADVD 8 .Os .Sh NAME @@ -36,7 +36,7 @@ .Nd router advertisement daemon .Sh SYNOPSIS .Nm -.Op Fl DdfMRs +.Op Fl dMRs .Op Fl c Ar configfile .Ar interface ... .Sh DESCRIPTION @@ -95,15 +95,9 @@ for the configuration file. 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. .It Fl d -Print debugging information. -.It Fl f -Foreground mode (useful when debugging). -Log messages will be dumped to stderr when this option is specified. +Do not daemonize. If this option is specified, rtadvd will run +in the foreground and log to stderr. .It Fl M Specify an interface to join the all-routers site-local multicast group. By default, diff --git a/usr.sbin/rtadvd/rtadvd.c b/usr.sbin/rtadvd/rtadvd.c index b258ca92fad..7640c8793b5 100644 --- a/usr.sbin/rtadvd/rtadvd.c +++ b/usr.sbin/rtadvd/rtadvd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rtadvd.c,v 1.31 2008/04/13 00:22:17 djm Exp $ */ +/* $OpenBSD: rtadvd.c,v 1.32 2008/04/21 20:40:55 rainer Exp $ */ /* $KAME: rtadvd.c,v 1.66 2002/05/29 14:18:36 itojun Exp $ */ /* @@ -54,7 +54,6 @@ #include <errno.h> #include <string.h> #include <stdlib.h> -#include <syslog.h> #include <util.h> #include "rtadvd.h" @@ -64,6 +63,7 @@ #include "if.h" #include "config.h" #include "dump.h" +#include "log.h" struct msghdr rcvmhdr; static u_char *rcvcmsgbuf; @@ -84,6 +84,7 @@ int sock; int rtsock = -1; int accept_rr = 0; int dflag = 0, sflag = 0; +int log_perror = 0; u_char *conffile = NULL; @@ -151,10 +152,11 @@ main(argc, argv) int maxfd = 0; struct timeval *timeout; int i, ch; - int fflag = 0, logopt; + + log_init(1); /* log to stderr until daemonized */ /* get command line options and arguments */ -#define OPTIONS "c:dDfM:Rs" +#define OPTIONS "c:dM:Rs" while ((ch = getopt(argc, argv, OPTIONS)) != -1) { #undef OPTIONS switch (ch) { @@ -164,12 +166,6 @@ main(argc, argv) case 'd': dflag = 1; break; - case 'D': - dflag = 2; - break; - case 'f': - fflag = 1; - break; case 'M': mcastif = optarg; break; @@ -188,22 +184,11 @@ main(argc, argv) argv += optind; if (argc == 0) { fprintf(stderr, - "usage: rtadvd [-DdfMRs] [-c configfile] " + "usage: rtadvd [-dMRs] [-c configfile] " "interface ...\n"); 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(); @@ -213,22 +198,19 @@ main(argc, argv) while (argc--) getconfig(*argv++); - if (inet_pton(AF_INET6, ALLNODES, &sin6_allnodes.sin6_addr) != 1) { - fprintf(stderr, "fatal: inet_pton failed\n"); - exit(1); - } + if (inet_pton(AF_INET6, ALLNODES, &sin6_allnodes.sin6_addr) != 1) + fatal("inet_pton failed"); + + log_init(dflag); - if (!fflag) + if (!dflag) daemon(1, 0); sock_open(); /* record the current PID */ - if (pidfile(NULL) < 0) { - syslog(LOG_ERR, - "<%s> failed to open the pid log file, run anyway.", - __func__); - } + if (pidfile(NULL) < 0) + log_warnx("failed to open the pid log file, run anyway."); maxfd = sock; if (sflag == 0) { @@ -271,24 +253,19 @@ main(argc, argv) /* timer expiration check and reset the timer */ timeout = rtadvd_check_timer(); - if (timeout != NULL) { - syslog(LOG_DEBUG, - "<%s> set timer to %ld:%ld. waiting for " - "inputs or timeout", __func__, + if (timeout != NULL) + log_debug("set timer to %ld:%ld. waiting for " + "inputs or timeout", (long int)timeout->tv_sec, (long int)timeout->tv_usec); - } else { - syslog(LOG_DEBUG, - "<%s> there's no timer. waiting for inputs", - __func__); - } + else + log_debug("there's no timer. waiting for inputs"); if ((i = select(maxfd + 1, selectfdp, NULL, NULL, timeout)) < 0) { /* EINTR would occur upon SIGUSR1 for status dump */ if (errno != EINTR) - syslog(LOG_ERR, "<%s> select: %s", - __func__, strerror(errno)); + log_warn("select"); continue; } if (i == 0) /* timeout */ @@ -320,10 +297,8 @@ die() int i; const int retrans = MAX_FINAL_RTR_ADVERTISEMENTS; - if (dflag > 1) { - syslog(LOG_DEBUG, "<%s> cease to be an advertising router", - __func__); - } + if (dflag) + log_debug("cease to be an advertising router"); for (ra = ralist; ra; ra = ra->next) { ra->lifetime = 0; @@ -351,21 +326,19 @@ rtmsg_input() char addrbuf[INET6_ADDRSTRLEN]; n = read(rtsock, msg, sizeof(msg)); - if (dflag > 1) { - syslog(LOG_DEBUG, "<%s> received a routing message " - "(type = %d, len = %d)", __func__, rtmsg_type(msg), n); - } + if (dflag) + log_debug("received a routing message " + "(type = %d, len = %d)", rtmsg_type(msg), n); if (n > rtmsg_len(msg)) { /* * This usually won't happen for messages received on * a routing socket. */ - if (dflag > 1) - syslog(LOG_DEBUG, - "<%s> received data length is larger than " + if (dflag) + log_debug("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)); + n, rtmsg_len(msg)); #if 0 /* adjust length */ n = rtmsg_len(msg); @@ -399,23 +372,17 @@ rtmsg_input() break; default: /* should not reach here */ - if (dflag > 1) { - syslog(LOG_DEBUG, - "<%s:%d> unknown rtmsg %d on %s", - __func__, __LINE__, type, - if_indextoname(ifindex, ifname)); - } + if (dflag) + log_debug("unknown rtmsg %d on %s", + type, if_indextoname(ifindex, ifname)); continue; } if ((rai = if_indextorainfo(ifindex)) == NULL) { - if (dflag > 1) { - syslog(LOG_DEBUG, - "<%s> route changed on " - "non advertising interface(%s)", - __func__, - if_indextoname(ifindex, ifname)); - } + if (dflag) + log_debug("route changed on " + "non advertising interface(%s)", + if_indextoname(ifindex, ifname)); continue; } oldifflags = iflist[ifindex]->ifm_flags; @@ -434,23 +401,19 @@ rtmsg_input() /* sanity check for plen */ /* as RFC2373, prefixlen is at least 4 */ if (plen < 4 || plen > 127) { - syslog(LOG_INFO, "<%s> new interface route's" - "plen %d is invalid for a prefix", - __func__, plen); + log_info("new interface route's" + " plen %d is invalid for a prefix", plen); break; } prefix = find_prefix(rai, addr, plen); if (prefix) { - if (dflag > 1) { - syslog(LOG_DEBUG, - "<%s> new prefix(%s/%d) " + if (dflag) + log_debug("new prefix(%s/%d) " "added on %s, " "but it was already in list", - __func__, inet_ntop(AF_INET6, addr, (char *)addrbuf, INET6_ADDRSTRLEN), plen, rai->ifname); - } break; } make_prefix(rai, ifindex, addr, plen); @@ -468,24 +431,19 @@ rtmsg_input() /* sanity check for plen */ /* as RFC2373, prefixlen is at least 4 */ if (plen < 4 || plen > 127) { - syslog(LOG_INFO, - "<%s> deleted interface route's " - "plen %d is invalid for a prefix", - __func__, plen); + log_info("deleted interface route's " + "plen %d is invalid for a prefix", plen); break; } prefix = find_prefix(rai, addr, plen); if (prefix == NULL) { - if (dflag > 1) { - syslog(LOG_DEBUG, - "<%s> prefix(%s/%d) was " + if (dflag) + log_debug("prefix(%s/%d) was " "deleted on %s, " "but it was not in list", - __func__, inet_ntop(AF_INET6, addr, (char *)addrbuf, INET6_ADDRSTRLEN), plen, rai->ifname); - } break; } delete_prefix(rai, prefix); @@ -501,27 +459,22 @@ rtmsg_input() break; default: /* should not reach here */ - if (dflag > 1) { - syslog(LOG_DEBUG, - "<%s:%d> unknown rtmsg %d on %s", - __func__, __LINE__, type, - if_indextoname(ifindex, ifname)); - } + if (dflag) + log_debug("unknown rtmsg %d on %s", + type, if_indextoname(ifindex, ifname)); return; } /* check if an interface flag is changed */ if ((oldifflags & IFF_UP) != 0 && /* UP to DOWN */ (iflist[ifindex]->ifm_flags & IFF_UP) == 0) { - syslog(LOG_INFO, - "<%s> interface %s becomes down. stop timer.", - __func__, rai->ifname); + log_info("interface %s becomes down. stop timer.", + rai->ifname); rtadvd_remove_timer(&rai->timer); } else if ((oldifflags & IFF_UP) == 0 && /* DOWN to UP */ (iflist[ifindex]->ifm_flags & IFF_UP) != 0) { - syslog(LOG_INFO, - "<%s> interface %s becomes up. restart timer.", - __func__, rai->ifname); + log_info("interface %s becomes up. restart timer.", + rai->ifname); rai->initcounter = 0; /* reset the counter */ rai->waiting = 0; /* XXX */ @@ -573,15 +526,11 @@ rtadvd_input() hlimp = (int *)CMSG_DATA(cm); } if (ifindex == 0) { - syslog(LOG_ERR, - "<%s> failed to get receiving interface", - __func__); + log_warnx("failed to get receiving interface"); return; } if (hlimp == NULL) { - syslog(LOG_ERR, - "<%s> failed to get receiving hop limit", - __func__); + log_warnx("failed to get receiving hop limit"); return; } @@ -590,17 +539,13 @@ rtadvd_input() * just discard the data. */ if ((iflist[pi->ipi6_ifindex]->ifm_flags & IFF_UP) == 0) { - syslog(LOG_INFO, - "<%s> received data on a disabled interface (%s)", - __func__, - if_indextoname(pi->ipi6_ifindex, ifnamebuf)); + log_info("received data on a disabled interface (%s)", + if_indextoname(pi->ipi6_ifindex, ifnamebuf)); return; } if (i < sizeof(struct icmp6_hdr)) { - syslog(LOG_ERR, - "<%s> packet size(%d) is too short", - __func__, i); + log_warnx("packet size(%d) is too short", i); return; } @@ -614,30 +559,26 @@ rtadvd_input() * but we can't completely rely on them. */ if (*hlimp != 255) { - syslog(LOG_NOTICE, - "<%s> RS with invalid hop limit(%d) " + log_info("RS with invalid hop limit(%d) " "received from %s on %s", - __func__, *hlimp, + *hlimp, inet_ntop(AF_INET6, &from.sin6_addr, ntopbuf, INET6_ADDRSTRLEN), if_indextoname(pi->ipi6_ifindex, ifnamebuf)); return; } if (icp->icmp6_code) { - syslog(LOG_NOTICE, - "<%s> RS with invalid ICMP6 code(%d) " + log_info("RS with invalid ICMP6 code(%d) " "received from %s on %s", - __func__, icp->icmp6_code, + icp->icmp6_code, inet_ntop(AF_INET6, &from.sin6_addr, ntopbuf, INET6_ADDRSTRLEN), if_indextoname(pi->ipi6_ifindex, ifnamebuf)); return; } if (i < sizeof(struct nd_router_solicit)) { - syslog(LOG_NOTICE, - "<%s> RS from %s on %s does not have enough " + log_info("RS from %s on %s does not have enough " "length (len = %d)", - __func__, inet_ntop(AF_INET6, &from.sin6_addr, ntopbuf, INET6_ADDRSTRLEN), if_indextoname(pi->ipi6_ifindex, ifnamebuf), i); @@ -651,30 +592,26 @@ rtadvd_input() * XXX: there's a same dilemma as above... */ if (*hlimp != 255) { - syslog(LOG_NOTICE, - "<%s> RA with invalid hop limit(%d) " + log_info("RA with invalid hop limit(%d) " "received from %s on %s", - __func__, *hlimp, + *hlimp, inet_ntop(AF_INET6, &from.sin6_addr, ntopbuf, INET6_ADDRSTRLEN), if_indextoname(pi->ipi6_ifindex, ifnamebuf)); return; } if (icp->icmp6_code) { - syslog(LOG_NOTICE, - "<%s> RA with invalid ICMP6 code(%d) " + log_info("RA with invalid ICMP6 code(%d) " "received from %s on %s", - __func__, icp->icmp6_code, + icp->icmp6_code, inet_ntop(AF_INET6, &from.sin6_addr, ntopbuf, INET6_ADDRSTRLEN), if_indextoname(pi->ipi6_ifindex, ifnamebuf)); return; } if (i < sizeof(struct nd_router_advert)) { - syslog(LOG_NOTICE, - "<%s> RA from %s on %s does not have enough " + log_info("RA from %s on %s does not have enough " "length (len = %d)", - __func__, inet_ntop(AF_INET6, &from.sin6_addr, ntopbuf, INET6_ADDRSTRLEN), if_indextoname(pi->ipi6_ifindex, ifnamebuf), i); @@ -684,9 +621,8 @@ rtadvd_input() break; case ICMP6_ROUTER_RENUMBERING: if (accept_rr == 0) { - syslog(LOG_ERR, "<%s> received a router renumbering " - "message, but not allowed to be accepted", - __func__); + log_warnx("received a router renumbering " + "message, but not allowed to be accepted"); break; } rr_input(i, (struct icmp6_router_renum *)icp, pi, &from, @@ -699,8 +635,7 @@ rtadvd_input() * could receive message after opening the socket and * before setting ICMP6 type filter(see sock_open()). */ - syslog(LOG_ERR, "<%s> invalid icmp type(%d)", - __func__, icp->icmp6_type); + log_warnx("invalid icmp type(%d)", icp->icmp6_type); return; } @@ -715,24 +650,20 @@ rs_input(int len, struct nd_router_solicit *rs, union nd_opts ndopts; struct rainfo *ra; - syslog(LOG_DEBUG, - "<%s> RS received from %s on %s", - __func__, - inet_ntop(AF_INET6, &from->sin6_addr, - ntopbuf, INET6_ADDRSTRLEN), - if_indextoname(pi->ipi6_ifindex, ifnamebuf)); + log_debug("RS received from %s on %s", + inet_ntop(AF_INET6, &from->sin6_addr, + ntopbuf, INET6_ADDRSTRLEN), + if_indextoname(pi->ipi6_ifindex, ifnamebuf)); /* ND option check */ memset(&ndopts, 0, sizeof(ndopts)); if (nd6_options((struct nd_opt_hdr *)(rs + 1), len - sizeof(struct nd_router_solicit), &ndopts, NDOPT_FLAG_SRCLINKADDR)) { - syslog(LOG_DEBUG, - "<%s> ND option check failed for an RS from %s on %s", - __func__, - inet_ntop(AF_INET6, &from->sin6_addr, - ntopbuf, INET6_ADDRSTRLEN), - if_indextoname(pi->ipi6_ifindex, ifnamebuf)); + log_debug("ND option check failed for an RS from %s on %s", + inet_ntop(AF_INET6, &from->sin6_addr, + ntopbuf, INET6_ADDRSTRLEN), + if_indextoname(pi->ipi6_ifindex, ifnamebuf)); return; } @@ -743,10 +674,8 @@ rs_input(int len, struct nd_router_solicit *rs, */ if (IN6_IS_ADDR_UNSPECIFIED(&from->sin6_addr) && ndopts.nd_opts_src_lladdr) { - syslog(LOG_ERR, - "<%s> RS from unspecified src on %s has a link-layer" + log_warnx("RS from unspecified src on %s has a link-layer" " address option", - __func__, if_indextoname(pi->ipi6_ifindex, ifnamebuf)); goto done; } @@ -758,10 +687,8 @@ rs_input(int len, struct nd_router_solicit *rs, ra = ra->next; } if (ra == NULL) { - syslog(LOG_INFO, - "<%s> RS received on non advertising interface(%s)", - __func__, - if_indextoname(pi->ipi6_ifindex, ifnamebuf)); + log_info("RS received on non advertising interface(%s)", + if_indextoname(pi->ipi6_ifindex, ifnamebuf)); goto done; } @@ -807,10 +734,8 @@ rs_input(int len, struct nd_router_solicit *rs, interval.tv_usec = delay; rest = rtadvd_timer_rest(ra->timer); if (TIMEVAL_LT(*rest, interval)) { - syslog(LOG_DEBUG, - "<%s> random delay is larger than " - "the rest of normal timer", - __func__); + log_debug("random delay is larger than " + "the rest of normal timer"); interval = *rest; } @@ -849,12 +774,10 @@ ra_input(int len, struct nd_router_advert *ra, u_int32_t reachabletime, retranstimer, mtu; int inconsistent = 0; - syslog(LOG_DEBUG, - "<%s> RA received from %s on %s", - __func__, - inet_ntop(AF_INET6, &from->sin6_addr, - ntopbuf, INET6_ADDRSTRLEN), - if_indextoname(pi->ipi6_ifindex, ifnamebuf)); + log_debug("RA received from %s on %s", + inet_ntop(AF_INET6, &from->sin6_addr, + ntopbuf, INET6_ADDRSTRLEN), + if_indextoname(pi->ipi6_ifindex, ifnamebuf)); /* ND option check */ memset(&ndopts, 0, sizeof(ndopts)); @@ -862,12 +785,10 @@ ra_input(int len, struct nd_router_advert *ra, len - sizeof(struct nd_router_advert), &ndopts, NDOPT_FLAG_SRCLINKADDR | NDOPT_FLAG_PREFIXINFO | NDOPT_FLAG_MTU)) { - syslog(LOG_ERR, - "<%s> ND option check failed for an RA from %s on %s", - __func__, - inet_ntop(AF_INET6, &from->sin6_addr, - ntopbuf, INET6_ADDRSTRLEN), - if_indextoname(pi->ipi6_ifindex, ifnamebuf)); + log_warnx("ND option check failed for an RA from %s on %s", + inet_ntop(AF_INET6, &from->sin6_addr, + ntopbuf, INET6_ADDRSTRLEN), + if_indextoname(pi->ipi6_ifindex, ifnamebuf)); return; } @@ -875,13 +796,10 @@ ra_input(int len, struct nd_router_advert *ra, * RA consistency check according to RFC-2461 6.2.7 */ if ((rai = if_indextorainfo(pi->ipi6_ifindex)) == 0) { - syslog(LOG_INFO, - "<%s> received RA from %s on non-advertising" - " interface(%s)", - __func__, - inet_ntop(AF_INET6, &from->sin6_addr, - ntopbuf, INET6_ADDRSTRLEN), - if_indextoname(pi->ipi6_ifindex, ifnamebuf)); + log_info("received RA from %s on non-advertising interface(%s)", + inet_ntop(AF_INET6, &from->sin6_addr, ntopbuf, + INET6_ADDRSTRLEN), + if_indextoname(pi->ipi6_ifindex, ifnamebuf)); goto done; } rai->rainput++; /* increment statistics */ @@ -889,87 +807,69 @@ ra_input(int len, struct nd_router_advert *ra, /* Cur Hop Limit value */ if (ra->nd_ra_curhoplimit && rai->hoplimit && ra->nd_ra_curhoplimit != rai->hoplimit) { - syslog(LOG_INFO, - "<%s> CurHopLimit inconsistent on %s:" - " %d from %s, %d from us", - __func__, - rai->ifname, - ra->nd_ra_curhoplimit, - inet_ntop(AF_INET6, &from->sin6_addr, - ntopbuf, INET6_ADDRSTRLEN), - rai->hoplimit); + log_info("CurHopLimit inconsistent on %s: %d from %s," + " %d from us", + rai->ifname, + ra->nd_ra_curhoplimit, + inet_ntop(AF_INET6, &from->sin6_addr, + ntopbuf, INET6_ADDRSTRLEN), + rai->hoplimit); inconsistent++; } /* M flag */ if ((ra->nd_ra_flags_reserved & ND_RA_FLAG_MANAGED) != rai->managedflg) { - syslog(LOG_INFO, - "<%s> M flag inconsistent on %s:" - " %s from %s, %s from us", - __func__, - rai->ifname, - on_off[!rai->managedflg], - inet_ntop(AF_INET6, &from->sin6_addr, - ntopbuf, INET6_ADDRSTRLEN), - on_off[rai->managedflg]); + log_info("M flag inconsistent on %s: %s from %s, %s from us", + rai->ifname, on_off[!rai->managedflg], + inet_ntop(AF_INET6, &from->sin6_addr, + ntopbuf, INET6_ADDRSTRLEN), + on_off[rai->managedflg]); inconsistent++; } /* O flag */ if ((ra->nd_ra_flags_reserved & ND_RA_FLAG_OTHER) != rai->otherflg) { - syslog(LOG_INFO, - "<%s> O flag inconsistent on %s:" - " %s from %s, %s from us", - __func__, - rai->ifname, - on_off[!rai->otherflg], - inet_ntop(AF_INET6, &from->sin6_addr, - ntopbuf, INET6_ADDRSTRLEN), - on_off[rai->otherflg]); + log_info("O flag inconsistent on %s: %s from %s, %s from us", + rai->ifname, on_off[!rai->otherflg], + inet_ntop(AF_INET6, &from->sin6_addr, + ntopbuf, INET6_ADDRSTRLEN), + on_off[rai->otherflg]); inconsistent++; } /* Reachable Time */ reachabletime = ntohl(ra->nd_ra_reachable); if (reachabletime && rai->reachabletime && reachabletime != rai->reachabletime) { - syslog(LOG_INFO, - "<%s> ReachableTime inconsistent on %s:" - " %d from %s, %d from us", - __func__, - rai->ifname, - reachabletime, - inet_ntop(AF_INET6, &from->sin6_addr, - ntopbuf, INET6_ADDRSTRLEN), - rai->reachabletime); + log_info("ReachableTime inconsistent on %s:" + " %d from %s, %d from us", + rai->ifname, reachabletime, + inet_ntop(AF_INET6, &from->sin6_addr, + ntopbuf, INET6_ADDRSTRLEN), + rai->reachabletime); inconsistent++; } /* Retrans Timer */ retranstimer = ntohl(ra->nd_ra_retransmit); if (retranstimer && rai->retranstimer && retranstimer != rai->retranstimer) { - syslog(LOG_INFO, - "<%s> RetranceTimer inconsistent on %s:" - " %d from %s, %d from us", - __func__, - rai->ifname, - retranstimer, - inet_ntop(AF_INET6, &from->sin6_addr, - ntopbuf, INET6_ADDRSTRLEN), - rai->retranstimer); + log_info("RetranceTimer inconsistent on %s:" + " %d from %s, %d from us", + rai->ifname, retranstimer, + inet_ntop(AF_INET6, &from->sin6_addr, + ntopbuf, INET6_ADDRSTRLEN), + rai->retranstimer); inconsistent++; } /* Values in the MTU options */ 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:" - " %d from %s, %d from us", - __func__, - rai->ifname, mtu, - inet_ntop(AF_INET6, &from->sin6_addr, - ntopbuf, INET6_ADDRSTRLEN), - rai->linkmtu); + log_info("MTU option value inconsistent on %s:" + " %d from %s, %d from us", + rai->ifname, mtu, + inet_ntop(AF_INET6, &from->sin6_addr, + ntopbuf, INET6_ADDRSTRLEN), + rai->linkmtu); inconsistent++; } } @@ -977,10 +877,9 @@ ra_input(int len, struct nd_router_advert *ra, { struct nd_optlist *optp = ndopts.nd_opts_list; - if (ndopts.nd_opts_pi) { + if (ndopts.nd_opts_pi) if (prefix_check(ndopts.nd_opts_pi, rai, from)) inconsistent++; - } while (optp) { if (prefix_check((struct nd_opt_prefix_info *)optp->opt, rai, from)) @@ -1016,30 +915,25 @@ prefix_check(struct nd_opt_prefix_info *pinfo, /* * log if the adveritsed prefix has link-local scope(sanity check?) */ - if (IN6_IS_ADDR_LINKLOCAL(&pinfo->nd_opt_pi_prefix)) { - syslog(LOG_INFO, - "<%s> link-local prefix %s/%d is advertised " - "from %s on %s", - __func__, - inet_ntop(AF_INET6, &pinfo->nd_opt_pi_prefix, - prefixbuf, INET6_ADDRSTRLEN), - pinfo->nd_opt_pi_prefix_len, - inet_ntop(AF_INET6, &from->sin6_addr, - ntopbuf, INET6_ADDRSTRLEN), - rai->ifname); - } + if (IN6_IS_ADDR_LINKLOCAL(&pinfo->nd_opt_pi_prefix)) + log_info("link-local prefix %s/%d is advertised " + "from %s on %s", + inet_ntop(AF_INET6, &pinfo->nd_opt_pi_prefix, + prefixbuf, INET6_ADDRSTRLEN), + pinfo->nd_opt_pi_prefix_len, + inet_ntop(AF_INET6, &from->sin6_addr, + ntopbuf, INET6_ADDRSTRLEN), + rai->ifname); 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", - __func__, - inet_ntop(AF_INET6, &pinfo->nd_opt_pi_prefix, - prefixbuf, INET6_ADDRSTRLEN), - pinfo->nd_opt_pi_prefix_len, - inet_ntop(AF_INET6, &from->sin6_addr, - ntopbuf, INET6_ADDRSTRLEN), - rai->ifname); + log_info("prefix %s/%d from %s on %s is not in our list", + inet_ntop(AF_INET6, &pinfo->nd_opt_pi_prefix, + prefixbuf, INET6_ADDRSTRLEN), + pinfo->nd_opt_pi_prefix_len, + inet_ntop(AF_INET6, &from->sin6_addr, + ntopbuf, INET6_ADDRSTRLEN), + rai->ifname); return(0); } @@ -1057,34 +951,29 @@ prefix_check(struct nd_opt_prefix_info *pinfo, if (rai->clockskew && abs(preferred_time - pp->pltimeexpire) > rai->clockskew) { - syslog(LOG_INFO, - "<%s> prefeerred lifetime for %s/%d" - " (decr. in real time) inconsistent on %s:" - " %d from %s, %ld from us", - __func__, - inet_ntop(AF_INET6, &pinfo->nd_opt_pi_prefix, - prefixbuf, INET6_ADDRSTRLEN), - pinfo->nd_opt_pi_prefix_len, - rai->ifname, preferred_time, - inet_ntop(AF_INET6, &from->sin6_addr, - ntopbuf, INET6_ADDRSTRLEN), - pp->pltimeexpire); + log_info("prefeerred lifetime for %s/%d" + " (decr. in real time) inconsistent on %s:" + " %d from %s, %ld from us", + inet_ntop(AF_INET6, &pinfo->nd_opt_pi_prefix, + prefixbuf, INET6_ADDRSTRLEN), + pinfo->nd_opt_pi_prefix_len, + rai->ifname, preferred_time, + inet_ntop(AF_INET6, &from->sin6_addr, + ntopbuf, INET6_ADDRSTRLEN), + pp->pltimeexpire); inconsistent++; } - } else if (preferred_time != pp->preflifetime) { - syslog(LOG_INFO, - "<%s> prefeerred lifetime for %s/%d" - " inconsistent on %s:" - " %d from %s, %d from us", - __func__, - inet_ntop(AF_INET6, &pinfo->nd_opt_pi_prefix, - prefixbuf, INET6_ADDRSTRLEN), - pinfo->nd_opt_pi_prefix_len, - rai->ifname, preferred_time, - inet_ntop(AF_INET6, &from->sin6_addr, - ntopbuf, INET6_ADDRSTRLEN), - pp->preflifetime); - } + } else if (preferred_time != pp->preflifetime) + log_info("prefeerred lifetime for %s/%d" + " inconsistent on %s:" + " %d from %s, %d from us", + inet_ntop(AF_INET6, &pinfo->nd_opt_pi_prefix, + prefixbuf, INET6_ADDRSTRLEN), + pinfo->nd_opt_pi_prefix_len, + rai->ifname, preferred_time, + inet_ntop(AF_INET6, &from->sin6_addr, + ntopbuf, INET6_ADDRSTRLEN), + pp->preflifetime); valid_time = ntohl(pinfo->nd_opt_pi_valid_time); if (pp->vltimeexpire) { @@ -1093,33 +982,29 @@ prefix_check(struct nd_opt_prefix_info *pinfo, if (rai->clockskew && abs(valid_time - pp->vltimeexpire) > rai->clockskew) { - syslog(LOG_INFO, - "<%s> valid lifetime for %s/%d" - " (decr. in real time) inconsistent on %s:" - " %d from %s, %ld from us", - __func__, - inet_ntop(AF_INET6, &pinfo->nd_opt_pi_prefix, - prefixbuf, INET6_ADDRSTRLEN), - pinfo->nd_opt_pi_prefix_len, - rai->ifname, preferred_time, - inet_ntop(AF_INET6, &from->sin6_addr, - ntopbuf, INET6_ADDRSTRLEN), - pp->vltimeexpire); + log_info("valid lifetime for %s/%d" + " (decr. in real time) inconsistent on %s:" + " %d from %s, %ld from us", + inet_ntop(AF_INET6, &pinfo->nd_opt_pi_prefix, + prefixbuf, INET6_ADDRSTRLEN), + pinfo->nd_opt_pi_prefix_len, + rai->ifname, preferred_time, + inet_ntop(AF_INET6, &from->sin6_addr, + ntopbuf, INET6_ADDRSTRLEN), + pp->vltimeexpire); inconsistent++; } } else if (valid_time != pp->validlifetime) { - syslog(LOG_INFO, - "<%s> valid lifetime for %s/%d" - " inconsistent on %s:" - " %d from %s, %d from us", - __func__, - inet_ntop(AF_INET6, &pinfo->nd_opt_pi_prefix, - prefixbuf, INET6_ADDRSTRLEN), - pinfo->nd_opt_pi_prefix_len, - rai->ifname, valid_time, - inet_ntop(AF_INET6, &from->sin6_addr, - ntopbuf, INET6_ADDRSTRLEN), - pp->validlifetime); + log_info("valid lifetime for %s/%d" + " inconsistent on %s:" + " %d from %s, %d from us", + inet_ntop(AF_INET6, &pinfo->nd_opt_pi_prefix, + prefixbuf, INET6_ADDRSTRLEN), + pinfo->nd_opt_pi_prefix_len, + rai->ifname, valid_time, + inet_ntop(AF_INET6, &from->sin6_addr, + ntopbuf, INET6_ADDRSTRLEN), + pp->validlifetime); inconsistent++; } @@ -1183,33 +1068,32 @@ nd6_options(struct nd_opt_hdr *hdr, int limit, for (; limit > 0; limit -= optlen) { if (limit < sizeof(struct nd_opt_hdr)) { - syslog(LOG_INFO, "<%s> short option header", __func__); + log_info("short option header"); goto bad; } hdr = (struct nd_opt_hdr *)((caddr_t)hdr + optlen); if (hdr->nd_opt_len == 0) { - syslog(LOG_ERR, - "<%s> bad ND option length(0) (type = %d)", - __func__, hdr->nd_opt_type); + log_warnx("bad ND option length(0) (type = %d)", + hdr->nd_opt_type); goto bad; } optlen = hdr->nd_opt_len << 3; if (optlen > limit) { - syslog(LOG_INFO, "<%s> short option", __func__); + log_info("short option"); goto bad; } if (hdr->nd_opt_type > ND_OPT_MTU) { - syslog(LOG_INFO, "<%s> unknown ND option(type %d)", - __func__, hdr->nd_opt_type); + log_info("unknown ND option(type %d)", + hdr->nd_opt_type); continue; } if ((ndopt_flags[hdr->nd_opt_type] & optflags) == 0) { - syslog(LOG_INFO, "<%s> unexpected ND option(type %d)", - __func__, hdr->nd_opt_type); + log_info("unexpected ND option(type %d)", + hdr->nd_opt_type); continue; } @@ -1221,8 +1105,7 @@ nd6_options(struct nd_opt_hdr *hdr, int limit, (optlen != sizeof(struct nd_opt_mtu))) || ((hdr->nd_opt_type == ND_OPT_PREFIX_INFORMATION && optlen != sizeof(struct nd_opt_prefix_info)))) { - syslog(LOG_INFO, "<%s> invalid option length", - __func__); + log_info("invalid option length"); continue; } @@ -1233,9 +1116,8 @@ nd6_options(struct nd_opt_hdr *hdr, int limit, break; /* we don't care about these options */ case ND_OPT_MTU: if (ndopts->nd_opt_array[hdr->nd_opt_type]) { - syslog(LOG_INFO, - "<%s> duplicated ND option (type = %d)", - __func__, hdr->nd_opt_type); + log_info("duplicated ND option (type = %d)", + hdr->nd_opt_type); } ndopts->nd_opt_array[hdr->nd_opt_type] = hdr; break; @@ -1249,8 +1131,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", - __func__); + log_warn("malloc"); goto bad; } pfxlist->next = ndopts->nd_opts_list; @@ -1297,42 +1178,29 @@ sock_open() rcvcmsgbuflen = CMSG_SPACE(sizeof(struct in6_pktinfo)) + CMSG_SPACE(sizeof(int)); rcvcmsgbuf = (u_char *)malloc(rcvcmsgbuflen); - if (rcvcmsgbuf == NULL) { - syslog(LOG_ERR, "<%s> not enough core", __func__); - exit(1); - } + if (rcvcmsgbuf == NULL) + fatal("malloc"); sndcmsgbuflen = CMSG_SPACE(sizeof(struct in6_pktinfo)) + CMSG_SPACE(sizeof(int)); sndcmsgbuf = (u_char *)malloc(sndcmsgbuflen); - if (sndcmsgbuf == NULL) { - syslog(LOG_ERR, "<%s> not enough core", __func__); - exit(1); - } + if (sndcmsgbuf == NULL) + fatal("malloc"); - if ((sock = socket(AF_INET6, SOCK_RAW, IPPROTO_ICMPV6)) < 0) { - syslog(LOG_ERR, "<%s> socket: %s", __func__, - strerror(errno)); - exit(1); - } + if ((sock = socket(AF_INET6, SOCK_RAW, IPPROTO_ICMPV6)) < 0) + fatal("socket"); /* specify to tell receiving interface */ on = 1; if (setsockopt(sock, IPPROTO_IPV6, IPV6_RECVPKTINFO, &on, - sizeof(on)) < 0) { - syslog(LOG_ERR, "<%s> IPV6_RECVPKTINFO: %s", - __func__, strerror(errno)); - exit(1); - } + sizeof(on)) < 0) + fatal("IPV6_RECVPKTINFO"); on = 1; /* specify to tell value of hoplimit field of received IP6 hdr */ if (setsockopt(sock, IPPROTO_IPV6, IPV6_RECVHOPLIMIT, &on, - sizeof(on)) < 0) { - syslog(LOG_ERR, "<%s> IPV6_RECVHOPLIMIT: %s", - __func__, strerror(errno)); - exit(1); - } + sizeof(on)) < 0) + fatal("IPV6_RECVHOPLIMIT"); ICMP6_FILTER_SETBLOCKALL(&filt); ICMP6_FILTER_SETPASS(ND_ROUTER_SOLICIT, &filt); @@ -1340,28 +1208,21 @@ sock_open() if (accept_rr) 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", - __func__, strerror(errno)); - exit(1); - } + sizeof(filt)) < 0) + fatal("IICMP6_FILTER"); /* * join all routers multicast address on each advertising interface. */ if (inet_pton(AF_INET6, ALLROUTERS_LINK, &mreq.ipv6mr_multiaddr.s6_addr) - != 1) { - syslog(LOG_ERR, "<%s> inet_pton failed(library bug?)", - __func__); - exit(1); - } + != 1) + fatal("inet_pton failed(library bug?)"); while (ra) { 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", - __func__, ra->ifname, strerror(errno)); + log_warn("IPV6_JOIN_GROUP(link) on %s", ra->ifname); exit(1); } ra = ra->next; @@ -1373,29 +1234,21 @@ sock_open() */ if (accept_rr) { if (inet_pton(AF_INET6, ALLROUTERS_SITE, - &in6a_site_allrouters) != 1) { - syslog(LOG_ERR, "<%s> inet_pton failed(library bug?)", - __func__); - exit(1); - } + &in6a_site_allrouters) != 1) + fatal("inet_pton failed(library bug?)"); mreq.ipv6mr_multiaddr = in6a_site_allrouters; if (mcastif) { if ((mreq.ipv6mr_interface = if_nametoindex(mcastif)) == 0) { - syslog(LOG_ERR, - "<%s> invalid interface: %s", - __func__, mcastif); + log_warn("invalid interface: %s", mcastif); exit(1); } } else 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", - __func__, - mcastif ? mcastif : ralist->ifname, - strerror(errno)); + log_warn("IPV6_JOIN_GROUP(site) on %s", + mcastif ? mcastif : ralist->ifname); exit(1); } } @@ -1424,11 +1277,8 @@ sock_open() static void rtsock_open() { - if ((rtsock = socket(PF_ROUTE, SOCK_RAW, 0)) < 0) { - syslog(LOG_ERR, - "<%s> socket: %s", __func__, strerror(errno)); - exit(1); - } + if ((rtsock = socket(PF_ROUTE, SOCK_RAW, 0)) < 0) + fatal("socket"); } struct rainfo * @@ -1454,8 +1304,7 @@ struct rainfo *rainfo; struct soliciter *sol, *nextsol; if ((iflist[rainfo->ifindex]->ifm_flags & IFF_UP) == 0) { - syslog(LOG_DEBUG, "<%s> %s is not up, skip sending RA", - __func__, rainfo->ifname); + log_debug("%s is not up, skip sending RA", rainfo->ifname); return; } @@ -1485,19 +1334,14 @@ struct rainfo *rainfo; memcpy(CMSG_DATA(cm), &hoplimit, sizeof(int)); } - syslog(LOG_DEBUG, - "<%s> send RA on %s, # of waitings = %d", - __func__, rainfo->ifname, rainfo->waiting); + log_debug("send RA on %s, # of waitings = %d", + 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", - __func__, rainfo->ifname, - strerror(errno)); - } - } + if (i < 0 || i != rainfo->ra_datalen) + if (i < 0) + log_warn("sendmsg on %s", rainfo->ifname); /* * unicast advertisements @@ -1510,14 +1354,10 @@ struct rainfo *rainfo; #if 0 sndmhdr.msg_name = (caddr_t)&sol->addr; i = sendmsg(sock, &sndmhdr, 0); - if (i < 0 || i != rainfo->ra_datalen) { - if (i < 0) { - syslog(LOG_ERR, - "<%s> unicast sendmsg on %s: %s", - __func__, rainfo->ifname, - strerror(errno)); - } - } + if (i < 0 || i != rainfo->ra_datalen) + if (i < 0) + log_warn("unicast sendmsg on %s", + rainfo->ifname); #endif sol->next = NULL; @@ -1547,9 +1387,7 @@ ra_timeout(void *data) /* if necessary, reconstruct the packet. */ #endif - syslog(LOG_DEBUG, - "<%s> RA timer on %s is expired", - __func__, rai->ifname); + log_debug("RA timer on %s is expired", rai->ifname); ra_output(rai); } @@ -1584,10 +1422,8 @@ ra_timer_update(void *data, struct timeval *tm) tm->tv_sec = interval; tm->tv_usec = 0; - syslog(LOG_DEBUG, - "<%s> RA timer on %s is set to %ld:%ld", - __func__, rai->ifname, - (long int)tm->tv_sec, (long int)tm->tv_usec); + log_debug("RA timer on %s is set to %ld:%ld", rai->ifname, + (long int)tm->tv_sec, (long int)tm->tv_usec); return; } diff --git a/usr.sbin/rtadvd/timer.c b/usr.sbin/rtadvd/timer.c index 1f6249d6c0f..055b6e93d43 100644 --- a/usr.sbin/rtadvd/timer.c +++ b/usr.sbin/rtadvd/timer.c @@ -1,4 +1,4 @@ -/* $OpenBSD: timer.c,v 1.8 2002/06/10 19:57:35 espie Exp $ */ +/* $OpenBSD: timer.c,v 1.9 2008/04/21 20:40:55 rainer Exp $ */ /* $KAME: timer.c,v 1.7 2002/05/21 14:26:55 itojun Exp $ */ /* @@ -33,11 +33,11 @@ #include <sys/time.h> #include <unistd.h> -#include <syslog.h> #include <stdlib.h> #include <string.h> #include <search.h> #include "timer.h" +#include "log.h" static struct rtadvd_timer timer_head; @@ -63,24 +63,15 @@ rtadvd_add_timer(void (*timeout)(void *), { struct rtadvd_timer *newtimer; - if ((newtimer = malloc(sizeof(*newtimer))) == NULL) { - syslog(LOG_ERR, - "<%s> can't allocate memory", __func__); - exit(1); - } + if ((newtimer = malloc(sizeof(*newtimer))) == NULL) + fatal("malloc"); memset(newtimer, 0, sizeof(*newtimer)); - if (timeout == NULL) { - syslog(LOG_ERR, - "<%s> timeout function unspecified", __func__); - exit(1); - } - if (update == NULL) { - syslog(LOG_ERR, - "<%s> update function unspecified", __func__); - exit(1); - } + if (timeout == NULL) + fatalx("timeout function unspecified"); + if (update == NULL) + fatalx("update function unspecified"); newtimer->expire = timeout; newtimer->update = update; newtimer->expire_data = timeodata; @@ -165,9 +156,7 @@ rtadvd_timer_rest(struct rtadvd_timer *timer) gettimeofday(&now, NULL); if (TIMEVAL_LEQ(timer->tm, now)) { - syslog(LOG_DEBUG, - "<%s> a timer must be expired, but not yet", - __func__); + log_debug("a timer must be expired, but not yet"); returnval.tv_sec = returnval.tv_usec = 0; } else |