Module Name: src
Committed By: martin
Date: Tue Nov 21 10:54:19 UTC 2017
Modified Files:
src/tests/net/ndp [netbsd-8]: t_ra.sh
src/usr.sbin/rtadvd [netbsd-8]: advcap.c config.c dump.c if.c rrenum.c
rtadvd.8 rtadvd.c timer.c
Added Files:
src/usr.sbin/rtadvd [netbsd-8]: logit.h
Log Message:
Pull up following revision(s) (requested by ozaki-r in ticket #358):
usr.sbin/rtadvd/rtadvd.c: revision 1.54-1.58
usr.sbin/rtadvd/config.c: revision 1.37
usr.sbin/rtadvd/if.c: revision 1.25
usr.sbin/rtadvd/dump.c: revision 1.15
usr.sbin/rtadvd/rrenum.c: revision 1.20
usr.sbin/rtadvd/logit.h: revision 1.1
usr.sbin/rtadvd/rtadvd.8: revision 1.26
tests/net/ndp/t_ra.sh: revision 1.30
usr.sbin/rtadvd/timer.c: revision 1.14
tests/net/ndp/t_ra.sh: revision 1.31
usr.sbin/rtadvd/advcap.c: revision 1.17
KNF, fix time printing formats.
Don't start another copy of rtadvd if one is running.
PR/52618: Shinichi Doyashiki: Don't exit if adding interface to multicast
group fails. This happens with empty vlan interfaces
- make syscalls checks against -1
- fix errors to print %s: instead of <%s>
XXX: if_vlan is the only pseudo interface in net/ that returns such an
error..
Kill rtadvd surely even if the tests fail in the middle
It may help PR bin/52701.
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).
Mark expandm as preserving format strings.
Let rtadvd not use syslog for logging
Thanks to christos@ now rtadvd can log via stderr instead of syslog
by -D option.
Address PR bin/52701
To generate a diff of this commit:
cvs rdiff -u -r1.27.2.1 -r1.27.2.2 src/tests/net/ndp/t_ra.sh
cvs rdiff -u -r1.16 -r1.16.8.1 src/usr.sbin/rtadvd/advcap.c
cvs rdiff -u -r1.36 -r1.36.4.1 src/usr.sbin/rtadvd/config.c
cvs rdiff -u -r1.14 -r1.14.8.1 src/usr.sbin/rtadvd/dump.c
cvs rdiff -u -r1.24 -r1.24.8.1 src/usr.sbin/rtadvd/if.c
cvs rdiff -u -r0 -r1.1.2.2 src/usr.sbin/rtadvd/logit.h
cvs rdiff -u -r1.19 -r1.19.8.1 src/usr.sbin/rtadvd/rrenum.c
cvs rdiff -u -r1.25 -r1.25.6.1 src/usr.sbin/rtadvd/rtadvd.8
cvs rdiff -u -r1.53 -r1.53.4.1 src/usr.sbin/rtadvd/rtadvd.c
cvs rdiff -u -r1.13 -r1.13.8.1 src/usr.sbin/rtadvd/timer.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/tests/net/ndp/t_ra.sh
diff -u src/tests/net/ndp/t_ra.sh:1.27.2.1 src/tests/net/ndp/t_ra.sh:1.27.2.2
--- src/tests/net/ndp/t_ra.sh:1.27.2.1 Fri Jul 7 13:57:26 2017
+++ src/tests/net/ndp/t_ra.sh Tue Nov 21 10:54:19 2017
@@ -1,4 +1,4 @@
-# $NetBSD: t_ra.sh,v 1.27.2.1 2017/07/07 13:57:26 martin Exp $
+# $NetBSD: t_ra.sh,v 1.27.2.2 2017/11/21 10:54:19 martin Exp $
#
# Copyright (c) 2015 Internet Initiative Japan Inc.
# All rights reserved.
@@ -85,6 +85,34 @@ wait_term()
return 0
}
+kill_rtadvd()
+{
+ local pidfile=$1
+
+ kill -KILL `cat $pidfile`
+ rm -f $pidfile
+}
+
+terminate_rtadvd()
+{
+ local pidfile=$1
+ local n=5
+
+ if [ ! -f $pidfile ]; then
+ return
+ fi
+
+ kill -TERM `cat $pidfile`
+ while [ -f $pidfile ]; do
+ n=$((n - 1))
+ if [ $n = 0 ]; then
+ kill_rtadvd $pidfile
+ break
+ fi
+ sleep 0.2
+ done
+}
+
create_rtadvdconfig()
{
@@ -123,7 +151,8 @@ start_rtadvd()
local pidfile=$2
export RUMP_SERVER=$sock
- atf_check -s exit:0 rump.rtadvd -c ${CONFIG} -p $pidfile shmif0
+ atf_check -s exit:0 -e ignore \
+ rump.rtadvd -D -c ${CONFIG} -p $pidfile shmif0
while [ ! -f $pidfile ]; do
sleep 0.2
done
@@ -203,8 +232,7 @@ ra_basic_body()
atf_check -s exit:0 -o not-match:'fc00:1:' rump.ifconfig shmif0 inet6
unset RUMP_SERVER
- atf_check -s exit:0 kill -TERM `cat ${PIDFILE}`
- wait_term ${PIDFILE}
+ terminate_rtadvd $PIDFILE
export RUMP_SERVER=${RUMPCLI}
atf_check -s exit:0 -o match:'0.->.1' rump.sysctl -w net.inet6.ip6.accept_rtadv=1
@@ -215,8 +243,7 @@ ra_basic_body()
check_entries $RUMPCLI $RUMPSRV $IP6SRV_PREFIX
- atf_check -s exit:0 kill -TERM `cat ${PIDFILE}`
- wait_term ${PIDFILE}
+ terminate_rtadvd $PIDFILE
rump_server_destroy_ifaces
}
@@ -224,12 +251,8 @@ ra_basic_body()
ra_basic_cleanup()
{
- if [ -f ${PIDFILE} ]; then
- kill -TERM `cat ${PIDFILE}`
- wait_term ${PIDFILE}
- fi
-
$DEBUG && dump
+ terminate_rtadvd $PIDFILE
cleanup
}
@@ -267,7 +290,7 @@ ra_flush_prefix_entries_body()
# Terminate rtadvd to prevent new RA messages from coming
# Note that ifconfig down; kill -TERM doesn't work
- kill -KILL `cat ${PIDFILE}`
+ kill_rtadvd $PIDFILE
# Flush all the entries in the prefix list
atf_check -s exit:0 rump.ndp -P
@@ -288,6 +311,7 @@ ra_flush_prefix_entries_cleanup()
{
$DEBUG && dump
+ terminate_rtadvd $PIDFILE
cleanup
}
@@ -325,7 +349,7 @@ ra_flush_defrouter_entries_body()
# Terminate rtadvd to prevent new RA messages from coming
# Note that ifconfig down; kill -TERM doesn't work
- kill -KILL `cat ${PIDFILE}`
+ kill_rtadvd $PIDFILE
# Flush all the entries in the default router list
atf_check -s exit:0 rump.ndp -R
@@ -345,6 +369,7 @@ ra_flush_defrouter_entries_cleanup()
{
$DEBUG && dump
+ terminate_rtadvd $PIDFILE
cleanup
}
@@ -384,8 +409,7 @@ ra_delete_address_body()
$(rump.ifconfig shmif0 |awk '/AUTOCONF/ {print $2}') delete
unset RUMP_SERVER
- atf_check -s exit:0 kill -TERM `cat ${PIDFILE}`
- wait_term ${PIDFILE}
+ terminate_rtadvd $PIDFILE
rump_server_destroy_ifaces
}
@@ -393,12 +417,8 @@ ra_delete_address_body()
ra_delete_address_cleanup()
{
- if [ -f ${PIDFILE} ]; then
- kill -TERM `cat ${PIDFILE}`
- wait_term ${PIDFILE}
- fi
-
$DEBUG && dump
+ terminate_rtadvd $PIDFILE
cleanup
}
@@ -444,10 +464,8 @@ ra_multiple_routers_body()
atf_check_equal $n 2
unset RUMP_SERVER
- atf_check -s exit:0 kill -TERM `cat ${PIDFILE}`
- wait_term ${PIDFILE}
- atf_check -s exit:0 kill -TERM `cat ${PIDFILE3}`
- wait_term ${PIDFILE3}
+ terminate_rtadvd $PIDFILE
+ terminate_rtadvd $PIDFILE3
rump_server_destroy_ifaces
}
@@ -455,16 +473,9 @@ ra_multiple_routers_body()
ra_multiple_routers_cleanup()
{
- if [ -f ${PIDFILE} ]; then
- kill -TERM `cat ${PIDFILE}`
- wait_term ${PIDFILE}
- fi
- if [ -f ${PIDFILE3} ]; then
- kill -TERM `cat ${PIDFILE3}`
- wait_term ${PIDFILE3}
- fi
-
$DEBUG && dump
+ terminate_rtadvd $PIDFILE
+ terminate_rtadvd $PIDFILE3
cleanup
}
@@ -510,10 +521,8 @@ ra_multiple_routers_single_prefix_body()
atf_check_equal $n 1
unset RUMP_SERVER
- atf_check -s exit:0 kill -TERM `cat ${PIDFILE}`
- wait_term ${PIDFILE}
- atf_check -s exit:0 kill -TERM `cat ${PIDFILE1_2}`
- wait_term ${PIDFILE1_2}
+ terminate_rtadvd $PIDFILE
+ terminate_rtadvd $PIDFILE1_2
rump_server_destroy_ifaces
}
@@ -521,16 +530,9 @@ ra_multiple_routers_single_prefix_body()
ra_multiple_routers_single_prefix_cleanup()
{
- if [ -f ${PIDFILE} ]; then
- kill -TERM `cat ${PIDFILE}`
- wait_term ${PIDFILE}
- fi
- if [ -f ${PIDFILE1_2} ]; then
- kill -TERM `cat ${PIDFILE1_2}`
- wait_term ${PIDFILE1_2}
- fi
-
$DEBUG && dump
+ terminate_rtadvd $PIDFILE
+ terminate_rtadvd $PIDFILE1_2
cleanup
}
@@ -588,12 +590,9 @@ ra_multiple_routers_maxifprefixes_body()
# TODO check other conditions
unset RUMP_SERVER
- atf_check -s exit:0 kill -TERM `cat ${PIDFILE}`
- wait_term ${PIDFILE}
- atf_check -s exit:0 kill -TERM `cat ${PIDFILE3}`
- wait_term ${PIDFILE3}
- atf_check -s exit:0 kill -TERM `cat ${PIDFILE4}`
- wait_term ${PIDFILE4}
+ terminate_rtadvd $PIDFILE
+ terminate_rtadvd $PIDFILE3
+ terminate_rtadvd $PIDFILE4
rump_server_destroy_ifaces
}
@@ -601,20 +600,10 @@ ra_multiple_routers_maxifprefixes_body()
ra_multiple_routers_maxifprefixes_cleanup()
{
- if [ -f ${PIDFILE} ]; then
- kill -TERM `cat ${PIDFILE}`
- wait_term ${PIDFILE}
- fi
- if [ -f ${PIDFILE3} ]; then
- kill -TERM `cat ${PIDFILE3}`
- wait_term ${PIDFILE3}
- fi
- if [ -f ${PIDFILE4} ]; then
- kill -TERM `cat ${PIDFILE4}`
- wait_term ${PIDFILE4}
- fi
-
$DEBUG && dump
+ terminate_rtadvd $PIDFILE
+ terminate_rtadvd $PIDFILE3
+ terminate_rtadvd $PIDFILE4
cleanup
}
@@ -693,8 +682,7 @@ ra_temporary_address_body()
unset RUMP_SERVER
- atf_check -s exit:0 kill -TERM `cat ${PIDFILE}`
- wait_term $PIDFILE
+ terminate_rtadvd $PIDFILE
rump_server_destroy_ifaces
}
@@ -702,12 +690,8 @@ ra_temporary_address_body()
ra_temporary_address_cleanup()
{
- if [ -f ${PIDFILE} ]; then
- kill -TERM `cat ${PIDFILE}`
- wait_term ${PIDFILE}
- fi
-
$DEBUG && dump
+ terminate_rtadvd $PIDFILE
cleanup
}
@@ -747,7 +731,7 @@ ra_defrouter_expiration_body()
# Terminate rtadvd to prevent new RA messages from coming
# Note that ifconfig down; kill -TERM doesn't work
- kill -KILL `cat ${PIDFILE}`
+ kill_rtadvd $PIDFILE
# Wait until the default routers and prefix entries are expired
sleep $expire_time
@@ -772,6 +756,7 @@ ra_defrouter_expiration_cleanup()
{
$DEBUG && dump
+ terminate_rtadvd $PIDFILE
cleanup
}
@@ -811,7 +796,7 @@ ra_prefix_expiration_body()
# Terminate rtadvd to prevent new RA messages from coming
# Note that ifconfig down; kill -TERM doesn't work
- kill -KILL `cat ${PIDFILE}`
+ kill_rtadvd $PIDFILE
# Wait until the default routers and prefix entries are expired
sleep $expire_time
@@ -837,6 +822,7 @@ ra_prefix_expiration_cleanup()
{
$DEBUG && dump
+ terminate_rtadvd $PIDFILE
cleanup
}
Index: src/usr.sbin/rtadvd/advcap.c
diff -u src/usr.sbin/rtadvd/advcap.c:1.16 src/usr.sbin/rtadvd/advcap.c:1.16.8.1
--- src/usr.sbin/rtadvd/advcap.c:1.16 Wed Nov 11 07:48:41 2015
+++ src/usr.sbin/rtadvd/advcap.c Tue Nov 21 10:54:18 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: advcap.c,v 1.16 2015/11/11 07:48:41 ozaki-r Exp $ */
+/* $NetBSD: advcap.c,v 1.16.8.1 2017/11/21 10:54:18 martin 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 (;;) {
Index: src/usr.sbin/rtadvd/config.c
diff -u src/usr.sbin/rtadvd/config.c:1.36 src/usr.sbin/rtadvd/config.c:1.36.4.1
--- src/usr.sbin/rtadvd/config.c:1.36 Mon Feb 27 05:41:36 2017
+++ src/usr.sbin/rtadvd/config.c Tue Nov 21 10:54:18 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: config.c,v 1.36 2017/02/27 05:41:36 ozaki-r Exp $ */
+/* $NetBSD: config.c,v 1.36.4.1 2017/11/21 10:54:18 martin 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 exith
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 exith
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 exith
} 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 exith
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 exith
*/
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 exith
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 exith
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 exith
#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 exith
* 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 exith
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 exith
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 exith
/* 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 exith
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 exith
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 exith
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 exith
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 exith
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 exith
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 exith
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 exith
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 exith
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 exith
*/
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 exith
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 exith
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 exith
}
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 exith
}
}
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 exith
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 exith
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 exith
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 in
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 in
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 ifin
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;
}
Index: src/usr.sbin/rtadvd/dump.c
diff -u src/usr.sbin/rtadvd/dump.c:1.14 src/usr.sbin/rtadvd/dump.c:1.14.8.1
--- src/usr.sbin/rtadvd/dump.c:1.14 Wed Jun 15 13:57:39 2016
+++ src/usr.sbin/rtadvd/dump.c Tue Nov 21 10:54:18 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: dump.c,v 1.14 2016/06/15 13:57:39 riastradh Exp $ */
+/* $NetBSD: dump.c,v 1.14.8.1 2017/11/21 10:54:18 martin 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;
}
Index: src/usr.sbin/rtadvd/if.c
diff -u src/usr.sbin/rtadvd/if.c:1.24 src/usr.sbin/rtadvd/if.c:1.24.8.1
--- src/usr.sbin/rtadvd/if.c:1.24 Wed Nov 11 07:48:41 2015
+++ src/usr.sbin/rtadvd/if.c Tue Nov 21 10:54:18 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: if.c,v 1.24 2015/11/11 07:48:41 ozaki-r Exp $ */
+/* $NetBSD: if.c,v 1.24.8.1 2017/11/21 10:54:18 martin 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,
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 i
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;
Index: src/usr.sbin/rtadvd/rrenum.c
diff -u src/usr.sbin/rtadvd/rrenum.c:1.19 src/usr.sbin/rtadvd/rrenum.c:1.19.8.1
--- src/usr.sbin/rtadvd/rrenum.c:1.19 Wed Nov 11 07:48:41 2015
+++ src/usr.sbin/rtadvd/rrenum.c Tue Nov 21 10:54:18 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: rrenum.c,v 1.19 2015/11/11 07:48:41 ozaki-r Exp $ */
+/* $NetBSD: rrenum.c,v 1.19.8.1 2017/11/21 10:54:18 martin 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_matc
/* 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_matc
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_matc
* (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_mat
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_mat
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, in
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, in
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_re
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_re
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 icmp
/* 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 icmp
/* 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 icmp
/* 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 icmp
(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_r
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
{
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
/* 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
!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
/* 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;
Index: src/usr.sbin/rtadvd/rtadvd.8
diff -u src/usr.sbin/rtadvd/rtadvd.8:1.25 src/usr.sbin/rtadvd/rtadvd.8:1.25.6.1
--- src/usr.sbin/rtadvd/rtadvd.8:1.25 Fri Dec 16 09:09:38 2016
+++ src/usr.sbin/rtadvd/rtadvd.8 Tue Nov 21 10:54:18 2017
@@ -1,4 +1,4 @@
-.\" $NetBSD: rtadvd.8,v 1.25 2016/12/16 09:09:38 ozaki-r Exp $
+.\" $NetBSD: rtadvd.8,v 1.25.6.1 2017/11/21 10:54:18 martin 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.
Index: src/usr.sbin/rtadvd/rtadvd.c
diff -u src/usr.sbin/rtadvd/rtadvd.c:1.53 src/usr.sbin/rtadvd/rtadvd.c:1.53.4.1
--- src/usr.sbin/rtadvd/rtadvd.c:1.53 Tue Apr 11 14:29:23 2017
+++ src/usr.sbin/rtadvd/rtadvd.c Tue Nov 21 10:54:18 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: rtadvd.c,v 1.53 2017/04/11 14:29:23 roy Exp $ */
+/* $NetBSD: rtadvd.c,v 1.53.4.1 2017/11/21 10:54:18 martin 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;
@@ -219,14 +221,13 @@ main(int argc, char *argv[])
argc -= optind;
argv += optind;
if (argc == 0) {
- fprintf(stderr,
- "usage: rtadvd [-DdfRs] [-c conffile]"
- " [-M ifname] [-p pidfile] interface ...\n");
- exit(1);
+ fprintf(stderr, "Ysage: %s [-DdfRs] [-c conffile]"
+ " [-M ifname] [-p pidfile] interface ...\n", getprogname());
+ return EXIT_FAILURE;
}
if (prog_init && prog_init() == -1) {
- err(1, "init failed");
+ err(EXIT_FAILURE, "init failed");
}
logopt = LOG_NDELAY | LOG_PID;
@@ -243,12 +244,12 @@ 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);
- exit(1);
+ logit(LOG_ERR, "getpwnam: %s: %m", RTADVD_USER);
+ return EXIT_FAILURE;
}
/* timer initialization */
@@ -266,10 +267,15 @@ main(int argc, char *argv[])
#ifdef __NetBSD__
/* record the current PID */
- if (pidfile(pidfilepath) < 0) {
- syslog(LOG_ERR,
- "<%s> failed to open the pid log file, run anyway.",
- __func__);
+ if (pidfile(pidfilepath) == -1) {
+ if (errno == EEXIST) {
+ logit(LOG_ERR, "Another instance of `%s' is running "
+ "(pid %d); exiting.", getprogname(),
+ pidfile_read(pidfilepath));
+ return EXIT_FAILURE;
+ }
+ logit(LOG_ERR, "Failed to open the pid log file `%s' (%m), "
+ "run anyway.", pidfilepath);
}
#endif
@@ -282,21 +288,21 @@ 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);
- exit(1);
+ logit(LOG_ERR, "chroot: %s: %m", pw->pw_dir);
+ return EXIT_FAILURE;
}
if (prog_chdir("/") == -1) {
- syslog(LOG_ERR, "chdir: /: %m");
- exit(1);
+ 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");
- exit(1);
+ logit(LOG_ERR, "failed to drop privileges: %m");
+ return EXIT_FAILURE;
}
signal(SIGINT, set_die);
@@ -312,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;
@@ -329,24 +335,27 @@ main(int argc, char *argv[])
}
if (timeout != NULL) {
- syslog(LOG_DEBUG,
- "<%s> set timer to %ld:%ld. waiting for "
+ logit(LOG_DEBUG,
+ "%s: set timer to %jd:%jd. waiting for "
"inputs or timeout", __func__,
- (long int)timeout->tv_sec,
- (long int)timeout->tv_nsec);
+ (intmax_t)timeout->tv_sec,
+ (intmax_t)timeout->tv_nsec);
} else {
- syslog(LOG_DEBUG,
- "<%s> there's no timer. waiting for inputs",
+ logit(LOG_DEBUG,
+ "%s: there's no timer. waiting for inputs",
__func__);
}
if ((i = prog_poll(set, 2, timeout ? (timeout->tv_sec * 1000 +
- (timeout->tv_nsec + 999999) / 1000000) : INFTIM)) < 0)
+ (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;
@@ -355,7 +364,7 @@ main(int argc, char *argv[])
if (set[0].revents & POLLIN)
rtadvd_input();
}
- exit(0); /* NOTREACHED */
+ return EXIT_SUCCESS; /* NOTREACHED */
}
static void
@@ -389,26 +398,26 @@ die(void)
if (waiting) {
if (TAILQ_FIRST(&ralist)) {
- syslog(LOG_INFO,
- "<%s> waiting for expiration of all RA timers",
+ 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(0);
+ exit(EXIT_SUCCESS);
/* NOT REACHED */
}
if (TAILQ_FIRST(&ralist) == NULL) {
- syslog(LOG_NOTICE, "<%s> gracefully terminated", __func__);
- exit(0);
+ 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) {
@@ -432,7 +441,7 @@ die(void)
rai->maxinterval = MIN_DELAY_BETWEEN_RAS;
rai->leaving_adv = MAX_FINAL_RTR_ADVERTISEMENTS;
ra_output(rai);
- ra_timer_update((void *)rai, &rai->timer->tm);
+ ra_timer_update(rai, &rai->timer->tm);
rtadvd_set_timer(&rai->timer->tm, rai->timer);
}
}
@@ -463,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));
}
@@ -473,8 +482,8 @@ rtmsg_input(void)
* a routing socket.
*/
if (dflag > 1)
- syslog(LOG_DEBUG,
- "<%s> received data length is larger than "
+ logit(LOG_DEBUG,
+ "%s: received data length is larger than "
"1st routing message len. multiple messages? "
"read %d bytes, but 1st msg len = %d",
__func__, n, rtmsg_len(msg));
@@ -513,8 +522,8 @@ rtmsg_input(void)
case RTM_IFANNOUNCE:
ifindex = get_ifan_ifindex(next);
if (get_ifan_what(next) == IFAN_ARRIVAL) {
- syslog(LOG_DEBUG,
- "<%s> interface %s arrived",
+ logit(LOG_DEBUG,
+ "%s: interface %s arrived",
__func__,
if_indextoname(ifindex, ifname));
if (if_argc == 0) {
@@ -539,9 +548,8 @@ rtmsg_input(void)
default:
/* should not reach here */
if (dflag > 1) {
- syslog(LOG_DEBUG,
- "<%s:%d> unknown rtmsg %d on %s",
- __func__, __LINE__, type,
+ logit(LOG_DEBUG, "%s: unknown rtmsg %d on %s",
+ __func__, type,
if_indextoname(ifindex, ifname));
}
continue;
@@ -549,8 +557,8 @@ rtmsg_input(void)
if ((rai = if_indextorainfo(ifindex)) == NULL) {
if (dflag > 1) {
- syslog(LOG_DEBUG,
- "<%s> route changed on "
+ logit(LOG_DEBUG,
+ "%s: route changed on "
"non advertising interface %s (%d)",
__func__,
if_indextoname(ifindex, ifname),
@@ -573,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;
@@ -588,8 +596,8 @@ rtmsg_input(void)
update_prefix(prefix);
prefixchange = 1;
} else if (dflag > 1) {
- syslog(LOG_DEBUG,
- "<%s> new prefix(%s/%d) "
+ logit(LOG_DEBUG,
+ "%s: new prefix(%s/%d) "
"added on %s, "
"but it was already in list",
__func__,
@@ -614,8 +622,8 @@ rtmsg_input(void)
/* sanity check for plen */
/* as RFC2373, prefixlen is at least 4 */
if (plen < 4 || plen > 127) {
- syslog(LOG_INFO,
- "<%s> deleted interface route's "
+ logit(LOG_INFO,
+ "%s: deleted interface route's "
"plen %d is invalid for a prefix",
__func__, plen);
break;
@@ -623,8 +631,8 @@ rtmsg_input(void)
prefix = find_prefix(rai, addr, plen);
if (prefix == NULL) {
if (dflag > 1) {
- syslog(LOG_DEBUG,
- "<%s> prefix(%s/%d) was "
+ logit(LOG_DEBUG,
+ "%s: prefix(%s/%d) was "
"deleted on %s, "
"but it was not in list",
__func__,
@@ -648,8 +656,8 @@ rtmsg_input(void)
#ifdef RTM_IFANNOUNCE
case RTM_IFANNOUNCE:
if (get_ifan_what(next) == IFAN_DEPARTURE) {
- syslog(LOG_DEBUG,
- "<%s> interface %s departed",
+ logit(LOG_DEBUG,
+ "%s: interface %s departed",
__func__, rai->ifname);
TAILQ_REMOVE(&ralist, rai, next);
if (rai->leaving)
@@ -662,9 +670,9 @@ rtmsg_input(void)
default:
/* should not reach here */
if (dflag > 1) {
- syslog(LOG_DEBUG,
- "<%s:%d> unknown rtmsg %d on %s",
- __func__, __LINE__, type,
+ logit(LOG_DEBUG,
+ "%s: unknown rtmsg %d on %s",
+ __func__, type,
if_indextoname(ifindex, ifname));
}
return;
@@ -673,14 +681,14 @@ 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,
- "<%s> interface %s becomes down. stop timer.",
+ 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,
- "<%s> interface %s becomes up. restart timer.",
+ logit(LOG_INFO,
+ "%s: interface %s becomes up. restart timer.",
__func__, rai->ifname);
rai->initcounter = 0; /* reset the counter */
@@ -688,7 +696,7 @@ rtmsg_input(void)
rtadvd_remove_timer(&rai->timer);
rai->timer = rtadvd_add_timer(ra_timeout,
ra_timer_update, rai, rai);
- ra_timer_update((void *)rai, &rai->timer->tm);
+ ra_timer_update(rai, &rai->timer->tm);
rtadvd_set_timer(&rai->timer->tm, rai->timer);
} else if (prefixchange && rai->ifflags & IFF_UP) {
/*
@@ -725,7 +733,7 @@ rtadvd_input(void)
* receive options.
*/
rcvmhdr.msg_controllen = rcvcmsgbuflen;
- if ((i = prog_recvmsg(sock, &rcvmhdr, 0)) < 0)
+ if ((i = prog_recvmsg(sock, &rcvmhdr, 0)) == -1)
return;
/* We read the buffer first to clear the FD */
@@ -749,22 +757,22 @@ rtadvd_input(void)
hlimp = (int *)CMSG_DATA(cm);
}
if (ifindex == 0) {
- syslog(LOG_ERR,
- "<%s> failed to get receiving interface",
+ logit(LOG_ERR,
+ "%s: failed to get receiving interface",
__func__);
return;
}
if (hlimp == NULL) {
- syslog(LOG_ERR,
- "<%s> failed to get receiving hop limit",
+ logit(LOG_ERR,
+ "%s: failed to get receiving hop limit",
__func__);
return;
}
if ((rai = if_indextorainfo(pi->ipi6_ifindex)) == NULL) {
if (dflag > 1) {
- syslog(LOG_DEBUG,
- "<%s> received data for non advertising "
+ logit(LOG_DEBUG,
+ "%s: received data for non advertising "
"interface (%s)",
__func__,
if_indextoname(pi->ipi6_ifindex, ifnamebuf));
@@ -776,8 +784,8 @@ rtadvd_input(void)
* just discard the data.
*/
if ((rai->ifflags & IFF_UP) == 0) {
- syslog(LOG_INFO,
- "<%s> received data on a disabled interface (%s)",
+ logit(LOG_INFO,
+ "%s: received data on a disabled interface (%s)",
__func__,
if_indextoname(pi->ipi6_ifindex, ifnamebuf));
return;
@@ -785,8 +793,8 @@ rtadvd_input(void)
#ifdef OLDRAWSOCKET
if ((size_t)i < sizeof(struct ip6_hdr) + sizeof(struct icmp6_hdr)) {
- syslog(LOG_ERR,
- "<%s> packet size(%d) is too short",
+ logit(LOG_ERR,
+ "%s: packet size(%d) is too short",
__func__, i);
return;
}
@@ -795,8 +803,8 @@ rtadvd_input(void)
icp = (struct icmp6_hdr *)(ip + 1); /* XXX: ext. hdr? */
#else
if ((size_t)i < sizeof(struct icmp6_hdr)) {
- syslog(LOG_ERR,
- "<%s> packet size(%zd) is too short",
+ logit(LOG_ERR,
+ "%s: packet size(%zd) is too short",
__func__, i);
return;
}
@@ -812,8 +820,8 @@ rtadvd_input(void)
* but we can't completely rely on them.
*/
if (*hlimp != 255) {
- syslog(LOG_NOTICE,
- "<%s> RS with invalid hop limit(%d) "
+ logit(LOG_NOTICE,
+ "%s: RS with invalid hop limit(%d) "
"received from %s on %s",
__func__, *hlimp,
inet_ntop(AF_INET6, &rcvfrom.sin6_addr, ntopbuf,
@@ -822,8 +830,8 @@ rtadvd_input(void)
return;
}
if (icp->icmp6_code) {
- syslog(LOG_NOTICE,
- "<%s> RS with invalid ICMP6 code(%d) "
+ logit(LOG_NOTICE,
+ "%s: RS with invalid ICMP6 code(%d) "
"received from %s on %s",
__func__, icp->icmp6_code,
inet_ntop(AF_INET6, &rcvfrom.sin6_addr, ntopbuf,
@@ -832,8 +840,8 @@ rtadvd_input(void)
return;
}
if ((size_t)i < sizeof(struct nd_router_solicit)) {
- syslog(LOG_NOTICE,
- "<%s> RS from %s on %s does not have enough "
+ logit(LOG_NOTICE,
+ "%s: RS from %s on %s does not have enough "
"length (len = %zd)",
__func__,
inet_ntop(AF_INET6, &rcvfrom.sin6_addr, ntopbuf,
@@ -849,8 +857,8 @@ rtadvd_input(void)
* XXX: there's a same dilemma as above...
*/
if (*hlimp != 255) {
- syslog(LOG_NOTICE,
- "<%s> RA with invalid hop limit(%d) "
+ logit(LOG_NOTICE,
+ "%s: RA with invalid hop limit(%d) "
"received from %s on %s",
__func__, *hlimp,
inet_ntop(AF_INET6, &rcvfrom.sin6_addr, ntopbuf,
@@ -859,8 +867,8 @@ rtadvd_input(void)
return;
}
if (icp->icmp6_code) {
- syslog(LOG_NOTICE,
- "<%s> RA with invalid ICMP6 code(%d) "
+ logit(LOG_NOTICE,
+ "%s: RA with invalid ICMP6 code(%d) "
"received from %s on %s",
__func__, icp->icmp6_code,
inet_ntop(AF_INET6, &rcvfrom.sin6_addr, ntopbuf,
@@ -869,8 +877,8 @@ rtadvd_input(void)
return;
}
if ((size_t)i < sizeof(struct nd_router_advert)) {
- syslog(LOG_NOTICE,
- "<%s> RA from %s on %s does not have enough "
+ logit(LOG_NOTICE,
+ "%s: RA from %s on %s does not have enough "
"length (len = %zd)",
__func__,
inet_ntop(AF_INET6, &rcvfrom.sin6_addr, ntopbuf,
@@ -882,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;
@@ -897,12 +905,10 @@ 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;
}
-
- return;
}
static void
@@ -914,8 +920,8 @@ rs_input(int len, struct nd_router_solic
struct rainfo *rai;
struct soliciter *sol;
- syslog(LOG_DEBUG,
- "<%s> RS received from %s on %s",
+ logit(LOG_DEBUG,
+ "%s: RS received from %s on %s",
__func__,
inet_ntop(AF_INET6, &from->sin6_addr,
ntopbuf, INET6_ADDRSTRLEN),
@@ -927,8 +933,8 @@ rs_input(int len, struct nd_router_solic
if (nd6_options((struct nd_opt_hdr *)(rs + 1),
len - sizeof(struct nd_router_solicit),
&ndopts, NDOPT_FLAG_SRCLINKADDR)) {
- syslog(LOG_INFO,
- "<%s> ND option check failed for an RS from %s on %s",
+ logit(LOG_INFO,
+ "%s: ND option check failed for an RS from %s on %s",
__func__,
inet_ntop(AF_INET6, &from->sin6_addr,
ntopbuf, INET6_ADDRSTRLEN),
@@ -943,8 +949,8 @@ rs_input(int len, struct nd_router_solic
*/
if (IN6_IS_ADDR_UNSPECIFIED(&from->sin6_addr) &&
ndopts.nd_opts_src_lladdr) {
- syslog(LOG_INFO,
- "<%s> RS from unspecified src on %s has a link-layer"
+ logit(LOG_INFO,
+ "%s: RS from unspecified src on %s has a link-layer"
" address option",
__func__,
if_indextoname(pi->ipi6_ifindex, ifnamebuf));
@@ -952,16 +958,16 @@ rs_input(int len, struct nd_router_solic
}
if ((rai = if_indextorainfo(pi->ipi6_ifindex)) == NULL) {
- syslog(LOG_INFO,
- "<%s> RS received on non advertising interface(%s)",
+ logit(LOG_INFO,
+ "%s: RS received on non advertising interface(%s)",
__func__,
if_indextoname(pi->ipi6_ifindex, ifnamebuf));
goto done;
}
if (rai->leaving) {
- syslog(LOG_INFO,
- "<%s> RS received on reconfiguring advertising interface(%s)",
+ logit(LOG_INFO,
+ "%s: RS received on reconfiguring advertising interface(%s)",
__func__, rai->ifname);
goto done;
}
@@ -993,7 +999,6 @@ rs_input(int len, struct nd_router_solic
done:
free_ndopts(&ndopts);
- return;
}
void
@@ -1014,7 +1019,7 @@ ra_timer_set_short_delay(struct rainfo *
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,8 +1054,8 @@ ra_input(int len, struct nd_router_adver
struct nd_optlist *optp;
int inconsistent = 0;
- syslog(LOG_DEBUG,
- "<%s> RA received from %s on %s",
+ logit(LOG_DEBUG,
+ "%s: RA received from %s on %s",
__func__,
inet_ntop(AF_INET6, &from->sin6_addr,
ntopbuf, INET6_ADDRSTRLEN),
@@ -1065,8 +1070,8 @@ ra_input(int len, struct nd_router_adver
NDOPT_FLAG_PREFIXINFO | NDOPT_FLAG_MTU |
NDOPT_FLAG_RDNSS | NDOPT_FLAG_DNSSL))
{
- syslog(LOG_INFO,
- "<%s> ND option check failed for an RA from %s on %s",
+ logit(LOG_INFO,
+ "%s: ND option check failed for an RA from %s on %s",
__func__,
inet_ntop(AF_INET6, &from->sin6_addr,
ntopbuf, INET6_ADDRSTRLEN),
@@ -1078,8 +1083,8 @@ ra_input(int len, struct nd_router_adver
* 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"
+ logit(LOG_INFO,
+ "%s: received RA from %s on non-advertising"
" interface(%s)",
__func__,
inet_ntop(AF_INET6, &from->sin6_addr,
@@ -1088,8 +1093,8 @@ ra_input(int len, struct nd_router_adver
goto done;
}
if (rai->leaving) {
- syslog(LOG_DEBUG,
- "<%s> received RA on re-configuring interface (%s)",
+ logit(LOG_DEBUG,
+ "%s: received RA on re-configuring interface (%s)",
__func__, rai->ifname);
goto done;
}
@@ -1098,8 +1103,8 @@ ra_input(int len, struct nd_router_adver
/* 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:"
+ logit(LOG_INFO,
+ "%s: CurHopLimit inconsistent on %s:"
" %d from %s, %d from us",
__func__,
rai->ifname,
@@ -1112,8 +1117,8 @@ ra_input(int len, struct nd_router_adver
/* M flag */
if ((ra->nd_ra_flags_reserved & ND_RA_FLAG_MANAGED) !=
rai->managedflg) {
- syslog(LOG_INFO,
- "<%s> M flag inconsistent on %s:"
+ logit(LOG_INFO,
+ "%s: M flag inconsistent on %s:"
" %s from %s, %s from us",
__func__,
rai->ifname,
@@ -1126,8 +1131,8 @@ ra_input(int len, struct nd_router_adver
/* O flag */
if ((ra->nd_ra_flags_reserved & ND_RA_FLAG_OTHER) !=
rai->otherflg) {
- syslog(LOG_INFO,
- "<%s> O flag inconsistent on %s:"
+ logit(LOG_INFO,
+ "%s: O flag inconsistent on %s:"
" %s from %s, %s from us",
__func__,
rai->ifname,
@@ -1141,8 +1146,8 @@ ra_input(int len, struct nd_router_adver
reachabletime = ntohl(ra->nd_ra_reachable);
if (reachabletime && rai->reachabletime &&
reachabletime != rai->reachabletime) {
- syslog(LOG_INFO,
- "<%s> ReachableTime inconsistent on %s:"
+ logit(LOG_INFO,
+ "%s: ReachableTime inconsistent on %s:"
" %d from %s, %d from us",
__func__,
rai->ifname,
@@ -1156,8 +1161,8 @@ ra_input(int len, struct nd_router_adver
retranstimer = ntohl(ra->nd_ra_retransmit);
if (retranstimer && rai->retranstimer &&
retranstimer != rai->retranstimer) {
- syslog(LOG_INFO,
- "<%s> RetranceTimer inconsistent on %s:"
+ logit(LOG_INFO,
+ "%s: RetranceTimer inconsistent on %s:"
" %d from %s, %d from us",
__func__,
rai->ifname,
@@ -1171,8 +1176,8 @@ ra_input(int len, struct nd_router_adver
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:"
+ logit(LOG_INFO,
+ "%s: MTU option value inconsistent on %s:"
" %d from %s, %d from us",
__func__,
rai->ifname, mtu,
@@ -1196,7 +1201,6 @@ ra_input(int len, struct nd_router_adver
done:
free_ndopts(&ndopts);
- return;
}
/* return a non-zero value if the received prefix is inconsitent with ours */
@@ -1212,15 +1216,15 @@ prefix_check(struct nd_opt_prefix_info *
#if 0 /* impossible */
if (pinfo->nd_opt_pi_type != ND_OPT_PREFIX_INFORMATION)
- return(0);
+ return 0;
#endif
/*
* 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 "
+ logit(LOG_INFO,
+ "%s: link-local prefix %s/%d is advertised "
"from %s on %s",
__func__,
inet_ntop(AF_INET6, &pinfo->nd_opt_pi_prefix,
@@ -1233,8 +1237,8 @@ prefix_check(struct nd_opt_prefix_info *
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",
+ 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,
prefixbuf, INET6_ADDRSTRLEN),
@@ -1242,7 +1246,7 @@ prefix_check(struct nd_opt_prefix_info *
inet_ntop(AF_INET6, &from->sin6_addr,
ntopbuf, INET6_ADDRSTRLEN),
rai->ifname);
- return(0);
+ return 0;
}
preferred_time = ntohl(pinfo->nd_opt_pi_preferred_time);
@@ -1259,8 +1263,8 @@ prefix_check(struct nd_opt_prefix_info *
if (!pp->timer && rai->clockskew &&
llabs((long long)preferred_time - pp->pltimeexpire) > rai->clockskew) {
- syslog(LOG_INFO,
- "<%s> preferred lifetime for %s/%d"
+ logit(LOG_INFO,
+ "%s: preferred lifetime for %s/%d"
" (decr. in real time) inconsistent on %s:"
" %d from %s, %ld from us",
__func__,
@@ -1274,8 +1278,8 @@ prefix_check(struct nd_opt_prefix_info *
inconsistent++;
}
} else if (!pp->timer && preferred_time != pp->preflifetime) {
- syslog(LOG_INFO,
- "<%s> preferred lifetime for %s/%d"
+ logit(LOG_INFO,
+ "%s: preferred lifetime for %s/%d"
" inconsistent on %s:"
" %d from %s, %d from us",
__func__,
@@ -1295,8 +1299,8 @@ prefix_check(struct nd_opt_prefix_info *
if (!pp->timer && rai->clockskew &&
llabs((long long)valid_time - pp->vltimeexpire) > rai->clockskew) {
- syslog(LOG_INFO,
- "<%s> valid lifetime for %s/%d"
+ logit(LOG_INFO,
+ "%s: valid lifetime for %s/%d"
" (decr. in real time) inconsistent on %s:"
" %d from %s, %ld from us",
__func__,
@@ -1310,8 +1314,8 @@ prefix_check(struct nd_opt_prefix_info *
inconsistent++;
}
} else if (!pp->timer && valid_time != pp->validlifetime) {
- syslog(LOG_INFO,
- "<%s> valid lifetime for %s/%d"
+ logit(LOG_INFO,
+ "%s: valid lifetime for %s/%d"
" inconsistent on %s:"
" %d from %s, %d from us",
__func__,
@@ -1325,7 +1329,7 @@ prefix_check(struct nd_opt_prefix_info *
inconsistent++;
}
- return(inconsistent);
+ return inconsistent;
}
struct prefix *
@@ -1341,16 +1345,16 @@ find_prefix(struct rainfo *rai, struct i
bytelen = plen / 8;
bitlen = plen % 8;
bitmask = 0xff << (8 - bitlen);
- if (memcmp((void *)prefix, (void *)&pp->prefix, bytelen))
+ if (memcmp(prefix, &pp->prefix, bytelen))
continue;
if (bitlen == 0 ||
((prefix->s6_addr[bytelen] & bitmask) ==
(pp->prefix.s6_addr[bytelen] & bitmask))) {
- return(pp);
+ return pp;
}
}
- return(NULL);
+ return NULL;
}
/* check if p0/plen0 matches p1/plen1; return 1 if matches, otherwise 0. */
@@ -1362,19 +1366,19 @@ prefix_match(struct in6_addr *p0, int pl
unsigned char bitmask;
if (plen0 < plen1)
- return(0);
+ return 0;
bytelen = plen1 / 8;
bitlen = plen1 % 8;
bitmask = 0xff << (8 - bitlen);
- if (memcmp((void *)p0, (void *)p1, bytelen))
- return(0);
+ if (memcmp(p0, p1, bytelen))
+ return 0;
if (bitlen == 0 ||
((p0->s6_addr[bytelen] & bitmask) ==
(p1->s6_addr[bytelen] & bitmask))) {
- return(1);
+ return 1;
}
- return(0);
+ return 0;
}
static int
@@ -1385,20 +1389,20 @@ nd6_options(struct nd_opt_hdr *hdr, int
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,
- "<%s> bad ND option length(0) (type = %d)",
+ 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;
}
@@ -1406,13 +1410,13 @@ nd6_options(struct nd_opt_hdr *hdr, int
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;
}
@@ -1431,7 +1435,7 @@ nd6_options(struct nd_opt_hdr *hdr, int
(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;
}
@@ -1445,8 +1449,8 @@ nd6_options(struct nd_opt_hdr *hdr, int
case ND_OPT_SOURCE_LINKADDR:
case ND_OPT_MTU:
if (ndopts->nd_opt_array[hdr->nd_opt_type]) {
- syslog(LOG_INFO,
- "<%s> duplicated ND option (type = %d)",
+ logit(LOG_INFO,
+ "%s: duplicated ND option (type = %d)",
__func__, hdr->nd_opt_type);
}
ndopts->nd_opt_array[hdr->nd_opt_type] = hdr;
@@ -1461,7 +1465,7 @@ nd6_options(struct nd_opt_hdr *hdr, int
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;
}
@@ -1475,12 +1479,11 @@ nd6_options(struct nd_opt_hdr *hdr, int
}
}
- return(0);
+ return 0;
bad:
free_ndopts(ndopts);
-
- return(-1);
+ return -1;
}
static void
@@ -1508,43 +1511,43 @@ sock_open(void)
CMSG_SPACE(sizeof(int));
rcvcmsgbuf = malloc(rcvcmsgbuflen);
if (rcvcmsgbuf == NULL) {
- syslog(LOG_ERR, "<%s> malloc: %m", __func__);
- exit(1);
+ 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__);
- exit(1);
+ logit(LOG_ERR, "%s: malloc: %m", __func__);
+ exit(EXIT_FAILURE);
}
- if ((sock = prog_socket(AF_INET6, SOCK_RAW, IPPROTO_ICMPV6)) < 0) {
- syslog(LOG_ERR, "<%s> socket: %m", __func__);
- exit(1);
+ if ((sock = prog_socket(AF_INET6, SOCK_RAW, IPPROTO_ICMPV6)) == -1) {
+ logit(LOG_ERR, "%s: socket: %m", __func__);
+ exit(EXIT_FAILURE);
}
/* RFC 4861 Section 4.2 */
on = 255;
if (prog_setsockopt(sock, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, &on,
sizeof(on)) == -1) {
- syslog(LOG_ERR, "<%s> IPV6_MULTICAST_HOPS: %m", __func__);
- exit(1);
+ logit(LOG_ERR, "%s: IPV6_MULTICAST_HOPS: %m", __func__);
+ exit(EXIT_FAILURE);
}
/* specify to tell receiving interface */
on = 1;
#ifdef IPV6_RECVPKTINFO
if (prog_setsockopt(sock, IPPROTO_IPV6, IPV6_RECVPKTINFO, &on,
- sizeof(on)) < 0) {
- syslog(LOG_ERR, "<%s> IPV6_RECVPKTINFO: %m", __func__);
- exit(1);
+ sizeof(on)) == -1) {
+ 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)) < 0) {
- syslog(LOG_ERR, "<%s> IPV6_PKTINFO: %m", __func__);
- exit(1);
+ sizeof(on)) == -1) {
+ logit(LOG_ERR, "%s: IPV6_PKTINFO: %m", __func__);
+ exit(EXIT_FAILURE);
}
#endif
@@ -1552,15 +1555,15 @@ sock_open(void)
/* specify to tell value of hoplimit field of received IP6 hdr */
#ifdef IPV6_RECVHOPLIMIT
if (prog_setsockopt(sock, IPPROTO_IPV6, IPV6_RECVHOPLIMIT, &on,
- sizeof(on)) < 0) {
- syslog(LOG_ERR, "<%s> IPV6_RECVHOPLIMIT: %m", __func__);
- exit(1);
+ sizeof(on)) == -1) {
+ 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)) < 0) {
- syslog(LOG_ERR, "<%s> IPV6_HOPLIMIT: %m", __func__);
- exit(1);
+ sizeof(on)) == -1) {
+ logit(LOG_ERR, "%s: IPV6_HOPLIMIT: %m", __func__);
+ exit(EXIT_FAILURE);
}
#endif
@@ -1570,9 +1573,9 @@ sock_open(void)
if (accept_rr)
ICMP6_FILTER_SETPASS(ICMP6_ROUTER_RENUMBERING, &filt);
if (prog_setsockopt(sock, IPPROTO_ICMPV6, ICMP6_FILTER, &filt,
- sizeof(filt)) < 0) {
- syslog(LOG_ERR, "<%s> IICMP6_FILTER: %m", __func__);
- exit(1);
+ sizeof(filt)) == -1) {
+ logit(LOG_ERR, "%s: IICMP6_FILTER: %m", __func__);
+ exit(EXIT_FAILURE);
}
/*
@@ -1581,17 +1584,17 @@ 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(1);
+ exit(EXIT_FAILURE);
}
TAILQ_FOREACH(ra, &ralist, next) {
mreq.ipv6mr_interface = ra->ifindex;
if (prog_setsockopt(sock, IPPROTO_IPV6, IPV6_JOIN_GROUP, &mreq,
- sizeof(mreq)) < 0) {
- syslog(LOG_ERR, "<%s> IPV6_JOIN_GROUP(link) on %s: %m",
+ sizeof(mreq)) == -1) {
+ logit(LOG_ERR, "%s: IPV6_JOIN_GROUP(link) on %s: %m",
__func__, ra->ifname);
- exit(1);
+ continue;
}
}
@@ -1603,28 +1606,28 @@ 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(1);
+ exit(EXIT_FAILURE);
}
ra = TAILQ_FIRST(&ralist);
if (mcastif) {
if ((mreq.ipv6mr_interface = if_nametoindex(mcastif))
== 0) {
- syslog(LOG_ERR,
- "<%s> invalid interface: %s",
+ logit(LOG_ERR,
+ "%s: invalid interface: %s",
__func__, mcastif);
- exit(1);
+ exit(EXIT_FAILURE);
}
} else
mreq.ipv6mr_interface = ra->ifindex;
if (prog_setsockopt(sock, IPPROTO_IPV6, IPV6_JOIN_GROUP,
- &mreq, sizeof(mreq)) < 0) {
- syslog(LOG_ERR,
- "<%s> IPV6_JOIN_GROUP(site) on %s: %m",
+ &mreq, sizeof(mreq)) == -1) {
+ logit(LOG_ERR,
+ "%s: IPV6_JOIN_GROUP(site) on %s: %m",
__func__,
mcastif ? mcastif : ra->ifname);
- exit(1);
+ exit(EXIT_FAILURE);
}
}
@@ -1642,10 +1645,8 @@ sock_open(void)
sndmhdr.msg_namelen = sizeof(struct sockaddr_in6);
sndmhdr.msg_iov = sndiov;
sndmhdr.msg_iovlen = 1;
- sndmhdr.msg_control = (void *)sndcmsgbuf;
+ sndmhdr.msg_control = sndcmsgbuf;
sndmhdr.msg_controllen = sndcmsgbuflen;
-
- return;
}
/* open a routing socket to watch the routing table */
@@ -1663,14 +1664,14 @@ rtsock_open(void)
};
#endif
- if ((rtsock = prog_socket(PF_ROUTE, SOCK_RAW, 0)) < 0) {
- syslog(LOG_ERR, "<%s> socket: %m", __func__);
- exit(1);
+ if ((rtsock = prog_socket(PF_ROUTE, SOCK_RAW, 0)) == -1) {
+ 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
}
@@ -1681,10 +1682,10 @@ if_indextorainfo(unsigned int idx)
TAILQ_FOREACH(rai, &ralist, next) {
if (rai->ifindex == idx)
- return(rai);
+ return rai;
}
- return(NULL); /* search failed */
+ return NULL; /* search failed */
}
struct rainfo *
@@ -1696,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;
}
@@ -1716,15 +1717,15 @@ ra_output(struct rainfo *rai)
memset(&pi->ipi6_addr, 0, sizeof(pi->ipi6_addr)); /*XXX*/
pi->ipi6_ifindex = rai->ifindex;
- syslog(LOG_DEBUG,
- "<%s> send RA on %s, # of waitings = %d",
+ logit(LOG_DEBUG,
+ "%s: send RA on %s, # of waitings = %d",
__func__, rai->ifname, rai->waiting);
i = prog_sendmsg(sock, &sndmhdr, 0);
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);
}
}
@@ -1740,8 +1741,8 @@ ra_output(struct rainfo *rai)
i = sendmsg(sock, &sndmhdr, 0);
if (i < 0 || i != rai->ra_datalen) {
if (i < 0) {
- syslog(LOG_ERR,
- "<%s> unicast sendmsg on %s: %m",
+ logit(LOG_ERR,
+ "%s: unicast sendmsg on %s: %m",
__func__, rai->ifname);
}
}
@@ -1758,8 +1759,8 @@ ra_output(struct rainfo *rai)
free_rainfo(rai);
return NULL;
}
- syslog(LOG_DEBUG,
- "<%s> expired RA,"
+ logit(LOG_DEBUG,
+ "%s: expired RA,"
" new config active for interface (%s)",
__func__, rai->ifname);
rai->leaving_for->timer = rtadvd_add_timer(ra_timeout,
@@ -1796,12 +1797,12 @@ ra_timeout(void *data)
/* if necessary, reconstruct the packet. */
#endif
- syslog(LOG_DEBUG,
- "<%s> RA timer on %s is expired",
+ logit(LOG_DEBUG,
+ "%s: RA timer on %s is expired",
__func__, rai->ifname);
if (ra_output(rai))
- return(rai->timer);
+ return rai->timer;
return NULL;
}
@@ -1836,10 +1837,49 @@ ra_timer_update(void *data, struct times
tm->tv_sec = interval;
tm->tv_nsec = 0;
- syslog(LOG_DEBUG,
- "<%s> RA timer on %s is set to %ld:%ld",
+ logit(LOG_DEBUG,
+ "%s: RA timer on %s is set to %jd:%jd",
__func__, rai->ifname,
- (long int)tm->tv_sec, (long int)tm->tv_nsec);
+ (intmax_t)tm->tv_sec, (intmax_t)tm->tv_nsec);
+}
- return;
+ __format_arg(3)
+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);
}
Index: src/usr.sbin/rtadvd/timer.c
diff -u src/usr.sbin/rtadvd/timer.c:1.13 src/usr.sbin/rtadvd/timer.c:1.13.8.1
--- src/usr.sbin/rtadvd/timer.c:1.13 Wed Nov 11 07:48:41 2015
+++ src/usr.sbin/rtadvd/timer.c Tue Nov 21 10:54:18 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: timer.c,v 1.13 2015/11/11 07:48:41 ozaki-r Exp $ */
+/* $NetBSD: timer.c,v 1.13.8.1 2017/11/21 10:54:18 martin 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 *(*
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 *(*
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 *t
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;
Added files:
Index: src/usr.sbin/rtadvd/logit.h
diff -u /dev/null src/usr.sbin/rtadvd/logit.h:1.1.2.2
--- /dev/null Tue Nov 21 10:54:19 2017
+++ src/usr.sbin/rtadvd/logit.h Tue Nov 21 10:54:18 2017
@@ -0,0 +1,2 @@
+
+void logit(int, const char *, ...) __sysloglike(2, 3);