rtsol: factor out dump.c if -DSMALL (for boot floppy)

use __func__ not __FUNCTION__
use timeradd() and timersub() from sys/time.h

from kame
This commit is contained in:
itojun 2004-01-03 01:40:31 +00:00
parent 9b45ab8153
commit 85d26f975b
8 changed files with 126 additions and 142 deletions

View File

@ -1,13 +1,13 @@
# $NetBSD: Makefile,v 1.12 2003/09/06 12:56:43 itojun Exp $
# $NetBSD: Makefile,v 1.13 2004/01/03 01:40:31 itojun Exp $
NOMAN= # defined
.include <bsd.own.mk>
PROG= rtsol
SRCS= rtsold.c rtsol.c if.c probe.c dump.c rtsock.c
SRCS= rtsold.c rtsol.c if.c probe.c rtsock.c
CPPFLAGS+=-DINET6 -DUSE_RTSOCK
CPPFLAGS+=-DSMALL -DUSE_RTSOCK
#MAN= rtsold.8

View File

@ -1,9 +1,9 @@
# $NetBSD: Makefile,v 1.10 2003/09/06 12:56:43 itojun Exp $
# $NetBSD: Makefile,v 1.11 2004/01/03 01:40:31 itojun Exp $
PROG= rtsold
SRCS= rtsold.c rtsol.c if.c probe.c dump.c rtsock.c
CPPFLAGS+=-DINET6 -DUSE_RTSOCK
CPPFLAGS+=-DUSE_RTSOCK
MAN= rtsold.8
MLINKS= rtsold.8 rtsol.8

View File

@ -1,4 +1,4 @@
/* $NetBSD: dump.c,v 1.7 2002/07/14 00:37:46 wiz Exp $ */
/* $NetBSD: dump.c,v 1.8 2004/01/03 01:40:31 itojun Exp $ */
/* $KAME: dump.c,v 1.10 2002/05/31 10:10:03 itojun Exp $ */
/*
@ -97,7 +97,7 @@ void
rtsold_dump_file(char *dumpfile)
{
if ((fp = fopen(dumpfile, "w")) == NULL) {
warnmsg(LOG_WARNING, __FUNCTION__, "open a dump file(%s): %s",
warnmsg(LOG_WARNING, __func__, "open a dump file(%s): %s",
dumpfile, strerror(errno));
return;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: if.c,v 1.12 2003/05/15 14:44:57 itojun Exp $ */
/* $NetBSD: if.c,v 1.13 2004/01/03 01:40:31 itojun Exp $ */
/* $KAME: if.c,v 1.18 2002/05/31 10:10:03 itojun Exp $ */
/*
@ -82,38 +82,38 @@ interface_up(char *name)
strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
if (ioctl(ifsock, SIOCGIFFLAGS, (caddr_t)&ifr) < 0) {
warnmsg(LOG_WARNING, __FUNCTION__, "ioctl(SIOCGIFFLAGS): %s",
warnmsg(LOG_WARNING, __func__, "ioctl(SIOCGIFFLAGS): %s",
strerror(errno));
return(-1);
}
if (!(ifr.ifr_flags & IFF_UP)) {
ifr.ifr_flags |= IFF_UP;
if (ioctl(ifsock, SIOCSIFFLAGS, (caddr_t)&ifr) < 0)
warnmsg(LOG_ERR, __FUNCTION__,
warnmsg(LOG_ERR, __func__,
"ioctl(SIOCSIFFLAGS): %s", strerror(errno));
return(-1);
}
warnmsg(LOG_DEBUG, __FUNCTION__, "checking if %s is ready...", name);
warnmsg(LOG_DEBUG, __func__, "checking if %s is ready...", name);
llflag = get_llflag(name);
if (llflag < 0) {
warnmsg(LOG_WARNING, __FUNCTION__,
warnmsg(LOG_WARNING, __func__,
"get_llflag() failed, anyway I'll try");
return 0;
}
if (!(llflag & IN6_IFF_NOTREADY)) {
warnmsg(LOG_DEBUG, __FUNCTION__, "%s is ready", name);
warnmsg(LOG_DEBUG, __func__, "%s is ready", name);
return(0);
} else {
if (llflag & IN6_IFF_TENTATIVE) {
warnmsg(LOG_DEBUG, __FUNCTION__, "%s is tentative",
warnmsg(LOG_DEBUG, __func__, "%s is tentative",
name);
return IFS_TENTATIVE;
}
if (llflag & IN6_IFF_DUPLICATED)
warnmsg(LOG_DEBUG, __FUNCTION__, "%s is duplicated",
warnmsg(LOG_DEBUG, __func__, "%s is duplicated",
name);
return -1;
}
@ -130,7 +130,7 @@ interface_status(struct ifinfo *ifinfo)
memset(&ifr, 0, sizeof(ifr));
strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
if (ioctl(ifsock, SIOCGIFFLAGS, &ifr) < 0) {
warnmsg(LOG_ERR, __FUNCTION__, "ioctl(SIOCGIFFLAGS) on %s: %s",
warnmsg(LOG_ERR, __func__, "ioctl(SIOCGIFFLAGS) on %s: %s",
ifname, strerror(errno));
return(-1);
}
@ -150,7 +150,7 @@ interface_status(struct ifinfo *ifinfo)
if (ioctl(ifsock, SIOCGIFMEDIA, (caddr_t)&ifmr) < 0) {
if (errno != EINVAL) {
warnmsg(LOG_DEBUG, __FUNCTION__,
warnmsg(LOG_DEBUG, __func__,
"ioctl(SIOCGIFMEDIA) on %s: %s",
ifname, strerror(errno));
return(-1);
@ -222,7 +222,7 @@ lladdropt_fill(struct sockaddr_dl *sdl, struct nd_opt_hdr *ndopt)
memcpy(addr, LLADDR(sdl), ETHER_ADDR_LEN);
break;
default:
warnmsg(LOG_ERR, __FUNCTION__,
warnmsg(LOG_ERR, __func__,
"unsupported link type(%d)", sdl->sdl_type);
exit(1);
}
@ -310,12 +310,12 @@ get_llflag(const char *name)
int s;
if ((s = socket(PF_INET6, SOCK_DGRAM, 0)) < 0) {
warnmsg(LOG_ERR, __FUNCTION__, "socket(SOCK_DGRAM): %s",
warnmsg(LOG_ERR, __func__, "socket(SOCK_DGRAM): %s",
strerror(errno));
exit(1);
}
if (getifaddrs(&ifap) != 0) {
warnmsg(LOG_ERR, __FUNCTION__, "getifaddrs: %s",
warnmsg(LOG_ERR, __func__, "getifaddrs: %s",
strerror(errno));
exit(1);
}
@ -334,7 +334,7 @@ get_llflag(const char *name)
strncpy(ifr6.ifr_name, name, sizeof(ifr6.ifr_name));
memcpy(&ifr6.ifr_ifru.ifru_addr, sin6, sin6->sin6_len);
if (ioctl(s, SIOCGIFAFLAG_IN6, &ifr6) < 0) {
warnmsg(LOG_ERR, __FUNCTION__,
warnmsg(LOG_ERR, __func__,
"ioctl(SIOCGIFAFLAG_IN6): %s", strerror(errno));
exit(1);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: probe.c,v 1.8 2002/07/14 00:37:47 wiz Exp $ */
/* $NetBSD: probe.c,v 1.9 2004/01/03 01:40:32 itojun Exp $ */
/* $KAME: probe.c,v 1.15 2002/05/31 21:22:08 itojun Exp $ */
/*
@ -69,18 +69,18 @@ probe_init(void)
if (sndcmsgbuf == NULL &&
(sndcmsgbuf = (u_char *)malloc(scmsglen)) == NULL) {
warnmsg(LOG_ERR, __FUNCTION__, "malloc failed");
warnmsg(LOG_ERR, __func__, "malloc failed");
return(-1);
}
if ((probesock = socket(AF_INET6, SOCK_RAW, IPPROTO_NONE)) < 0) {
warnmsg(LOG_ERR, __FUNCTION__, "socket: %s", strerror(errno));
warnmsg(LOG_ERR, __func__, "socket: %s", strerror(errno));
return(-1);
}
/* make the socket send-only */
if (shutdown(probesock, 0)) {
warnmsg(LOG_ERR, __FUNCTION__, "shutdown: %s", strerror(errno));
warnmsg(LOG_ERR, __func__, "shutdown: %s", strerror(errno));
return(-1);
}
@ -105,13 +105,13 @@ defrouter_probe(struct ifinfo *ifinfo)
int ifindex = ifinfo->sdl->sdl_index;
if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
warnmsg(LOG_ERR, __FUNCTION__, "socket: %s", strerror(errno));
warnmsg(LOG_ERR, __func__, "socket: %s", strerror(errno));
return;
}
memset(&dr, 0, sizeof(dr));
strlcpy(dr.ifname, "lo0", sizeof dr.ifname); /* dummy interface */
if (ioctl(s, SIOCGDRLST_IN6, (caddr_t)&dr) < 0) {
warnmsg(LOG_ERR, __FUNCTION__, "ioctl(SIOCGDRLST_IN6): %s",
warnmsg(LOG_ERR, __func__, "ioctl(SIOCGDRLST_IN6): %s",
strerror(errno));
goto closeandend;
}
@ -120,7 +120,7 @@ defrouter_probe(struct ifinfo *ifinfo)
if (ifindex && dr.defrouter[i].if_index == ifindex) {
/* sanity check */
if (!IN6_IS_ADDR_LINKLOCAL(&dr.defrouter[i].rtaddr)) {
warnmsg(LOG_ERR, __FUNCTION__,
warnmsg(LOG_ERR, __func__,
"default router list contains a "
"non-link-local address(%s)",
inet_ntop(AF_INET6,
@ -172,11 +172,11 @@ sendprobe(struct in6_addr *addr, struct ifinfo *ifinfo)
cm->cmsg_len = CMSG_LEN(sizeof(int));
memcpy(CMSG_DATA(cm), &hoplimit, sizeof(int));
warnmsg(LOG_DEBUG, __FUNCTION__, "probe a router %s on %s",
warnmsg(LOG_DEBUG, __func__, "probe a router %s on %s",
inet_ntop(AF_INET6, addr, ntopbuf, INET6_ADDRSTRLEN),
if_indextoname(ifindex, ifnamebuf));
if (sendmsg(probesock, &sndmhdr, 0))
warnmsg(LOG_ERR, __FUNCTION__, "sendmsg on %s: %s",
warnmsg(LOG_ERR, __func__, "sendmsg on %s: %s",
if_indextoname(ifindex, ifnamebuf), strerror(errno));
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: rtsock.c,v 1.4 2003/10/21 02:37:22 fvdl Exp $ */
/* $NetBSD: rtsock.c,v 1.5 2004/01/03 01:40:32 itojun Exp $ */
/* $KAME: rtsock.c,v 1.4 2001/09/19 06:59:41 sakane Exp $ */
/*
@ -111,7 +111,7 @@ rtsock_input(int s)
break;
if (dflag > 1) {
warnmsg(LOG_INFO, __FUNCTION__,
warnmsg(LOG_INFO, __func__,
"rtmsg type %d, len=%lu", rtm->rtm_type,
(u_long)len);
}
@ -120,7 +120,7 @@ rtsock_input(int s)
if (rtm->rtm_type != rtsock_dispatch[idx].type)
continue;
if (rtm->rtm_msglen < rtsock_dispatch[idx].minlen) {
warnmsg(LOG_INFO, __FUNCTION__,
warnmsg(LOG_INFO, __func__,
"rtmsg type %d too short!", rtm->rtm_type);
continue;
}
@ -152,16 +152,16 @@ rtsock_input_ifannounce(int s, struct rt_msghdr *rtm, char *lim)
* we may be able to do a name-based interface match,
* and call ifreconfig() to enable the interface again.
*/
warnmsg(LOG_INFO, __FUNCTION__,
warnmsg(LOG_INFO, __func__,
"interface %s inserted", ifan->ifan_name);
break;
case IFAN_DEPARTURE:
warnmsg(LOG_WARNING, __FUNCTION__,
warnmsg(LOG_WARNING, __func__,
"interface %s removed", ifan->ifan_name);
ifinfo = find_ifinfo(ifan->ifan_index);
if (ifinfo) {
if (dflag > 1) {
warnmsg(LOG_INFO, __FUNCTION__,
warnmsg(LOG_INFO, __func__,
"bring interface %s to DOWN state",
ifan->ifan_name);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: rtsol.c,v 1.10 2002/07/14 00:37:47 wiz Exp $ */
/* $NetBSD: rtsol.c,v 1.11 2004/01/03 01:40:32 itojun Exp $ */
/* $KAME: rtsol.c,v 1.15 2002/05/31 10:10:03 itojun Exp $ */
/*
@ -80,12 +80,12 @@ sockopen(void)
sndcmsglen = rcvcmsglen = CMSG_SPACE(sizeof(struct in6_pktinfo)) +
CMSG_SPACE(sizeof(int));
if (rcvcmsgbuf == NULL && (rcvcmsgbuf = malloc(rcvcmsglen)) == NULL) {
warnmsg(LOG_ERR, __FUNCTION__,
warnmsg(LOG_ERR, __func__,
"malloc for receive msghdr failed");
return(-1);
}
if (sndcmsgbuf == NULL && (sndcmsgbuf = malloc(sndcmsglen)) == NULL) {
warnmsg(LOG_ERR, __FUNCTION__,
warnmsg(LOG_ERR, __func__,
"malloc for send msghdr failed");
return(-1);
}
@ -94,13 +94,13 @@ sockopen(void)
sin6_allrouters.sin6_len = sizeof(sin6_allrouters);
if (inet_pton(AF_INET6, ALLROUTER,
&sin6_allrouters.sin6_addr.s6_addr) != 1) {
warnmsg(LOG_ERR, __FUNCTION__, "inet_pton failed for %s",
warnmsg(LOG_ERR, __func__, "inet_pton failed for %s",
ALLROUTER);
return(-1);
}
if ((rssock = socket(AF_INET6, SOCK_RAW, IPPROTO_ICMPV6)) < 0) {
warnmsg(LOG_ERR, __FUNCTION__, "socket: %s", strerror(errno));
warnmsg(LOG_ERR, __func__, "socket: %s", strerror(errno));
return(-1);
}
@ -109,14 +109,14 @@ sockopen(void)
#ifdef IPV6_RECVPKTINFO
if (setsockopt(rssock, IPPROTO_IPV6, IPV6_RECVPKTINFO, &on,
sizeof(on)) < 0) {
warnmsg(LOG_ERR, __FUNCTION__, "IPV6_RECVPKTINFO: %s",
warnmsg(LOG_ERR, __func__, "IPV6_RECVPKTINFO: %s",
strerror(errno));
exit(1);
}
#else /* old adv. API */
if (setsockopt(rssock, IPPROTO_IPV6, IPV6_PKTINFO, &on,
sizeof(on)) < 0) {
warnmsg(LOG_ERR, __FUNCTION__, "IPV6_PKTINFO: %s",
warnmsg(LOG_ERR, __func__, "IPV6_PKTINFO: %s",
strerror(errno));
exit(1);
}
@ -127,14 +127,14 @@ sockopen(void)
#ifdef IPV6_RECVHOPLIMIT
if (setsockopt(rssock, IPPROTO_IPV6, IPV6_RECVHOPLIMIT, &on,
sizeof(on)) < 0) {
warnmsg(LOG_ERR, __FUNCTION__, "IPV6_RECVHOPLIMIT: %s",
warnmsg(LOG_ERR, __func__, "IPV6_RECVHOPLIMIT: %s",
strerror(errno));
exit(1);
}
#else /* old adv. API */
if (setsockopt(rssock, IPPROTO_IPV6, IPV6_HOPLIMIT, &on,
sizeof(on)) < 0) {
warnmsg(LOG_ERR, __FUNCTION__, "IPV6_HOPLIMIT: %s",
warnmsg(LOG_ERR, __func__, "IPV6_HOPLIMIT: %s",
strerror(errno));
exit(1);
}
@ -145,7 +145,7 @@ sockopen(void)
ICMP6_FILTER_SETPASS(ND_ROUTER_ADVERT, &filt);
if (setsockopt(rssock, IPPROTO_ICMPV6, ICMP6_FILTER, &filt,
sizeof(filt)) == -1) {
warnmsg(LOG_ERR, __FUNCTION__, "setsockopt(ICMP6_FILTER): %s",
warnmsg(LOG_ERR, __func__, "setsockopt(ICMP6_FILTER): %s",
strerror(errno));
return(-1);
}
@ -202,7 +202,7 @@ sendpacket(struct ifinfo *ifinfo)
cm->cmsg_len = CMSG_LEN(sizeof(int));
memcpy(CMSG_DATA(cm), &hoplimit, sizeof(int));
warnmsg(LOG_DEBUG, __FUNCTION__,
warnmsg(LOG_DEBUG, __func__,
"send RS on %s, whose state is %d",
ifinfo->ifname, ifinfo->state);
@ -214,7 +214,7 @@ sendpacket(struct ifinfo *ifinfo)
* network cards on a mobile node. We ignore it.
*/
if (errno != ENETDOWN || dflag > 0)
warnmsg(LOG_ERR, __FUNCTION__, "sendmsg on %s: %s",
warnmsg(LOG_ERR, __func__, "sendmsg on %s: %s",
ifinfo->ifname, strerror(errno));
}
@ -234,7 +234,7 @@ rtsol_input(int s)
/* get message */
if ((i = recvmsg(s, &rcvmhdr, 0)) < 0) {
warnmsg(LOG_ERR, __FUNCTION__, "recvmsg: %s", strerror(errno));
warnmsg(LOG_ERR, __func__, "recvmsg: %s", strerror(errno));
return;
}
@ -254,18 +254,18 @@ rtsol_input(int s)
}
if (ifindex == 0) {
warnmsg(LOG_ERR, __FUNCTION__,
warnmsg(LOG_ERR, __func__,
"failed to get receiving interface");
return;
}
if (hlimp == NULL) {
warnmsg(LOG_ERR, __FUNCTION__,
warnmsg(LOG_ERR, __func__,
"failed to get receiving hop limit");
return;
}
if (i < sizeof(struct nd_router_advert)) {
warnmsg(LOG_ERR, __FUNCTION__,
warnmsg(LOG_ERR, __func__,
"packet size(%d) is too short", i);
return;
}
@ -273,7 +273,7 @@ rtsol_input(int s)
icp = (struct icmp6_hdr *)rcvmhdr.msg_iov[0].iov_base;
if (icp->icmp6_type != ND_ROUTER_ADVERT) {
warnmsg(LOG_ERR, __FUNCTION__,
warnmsg(LOG_ERR, __func__,
"invalid icmp type(%d) from %s on %s", icp->icmp6_type,
inet_ntop(AF_INET6, &from.sin6_addr, ntopbuf,
INET6_ADDRSTRLEN),
@ -282,7 +282,7 @@ rtsol_input(int s)
}
if (icp->icmp6_code != 0) {
warnmsg(LOG_ERR, __FUNCTION__,
warnmsg(LOG_ERR, __func__,
"invalid icmp code(%d) from %s on %s", icp->icmp6_code,
inet_ntop(AF_INET6, &from.sin6_addr, ntopbuf,
INET6_ADDRSTRLEN),
@ -291,7 +291,7 @@ rtsol_input(int s)
}
if (*hlimp != 255) {
warnmsg(LOG_NOTICE, __FUNCTION__,
warnmsg(LOG_NOTICE, __func__,
"invalid RA with hop limit(%d) from %s on %s",
*hlimp,
inet_ntop(AF_INET6, &from.sin6_addr, ntopbuf,
@ -301,7 +301,7 @@ rtsol_input(int s)
}
if (pi && !IN6_IS_ADDR_LINKLOCAL(&from.sin6_addr)) {
warnmsg(LOG_NOTICE, __FUNCTION__,
warnmsg(LOG_NOTICE, __func__,
"invalid RA with non link-local source from %s on %s",
inet_ntop(AF_INET6, &from.sin6_addr, ntopbuf,
INET6_ADDRSTRLEN),
@ -312,7 +312,7 @@ rtsol_input(int s)
/* xxx: more validation? */
if ((ifi = find_ifinfo(pi->ipi6_ifindex)) == NULL) {
warnmsg(LOG_NOTICE, __FUNCTION__,
warnmsg(LOG_NOTICE, __func__,
"received RA from %s on an unexpeced IF(%s)",
inet_ntop(AF_INET6, &from.sin6_addr, ntopbuf,
INET6_ADDRSTRLEN),
@ -320,7 +320,7 @@ rtsol_input(int s)
return;
}
warnmsg(LOG_DEBUG, __FUNCTION__,
warnmsg(LOG_DEBUG, __func__,
"received RA from %s on %s, state is %d",
inet_ntop(AF_INET6, &from.sin6_addr, ntopbuf, INET6_ADDRSTRLEN),
ifi->ifname, ifi->state);

View File

@ -1,5 +1,5 @@
/* $NetBSD: rtsold.c,v 1.25 2003/09/06 12:56:43 itojun Exp $ */
/* $KAME: rtsold.c,v 1.55 2002/09/08 01:26:03 itojun Exp $ */
/* $NetBSD: rtsold.c,v 1.26 2004/01/03 01:40:32 itojun Exp $ */
/* $KAME: rtsold.c,v 1.77 2004/01/03 01:35:13 itojun Exp $ */
/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@ -56,53 +56,64 @@
#include "rtsold.h"
#ifdef __bsdi__
#define timeradd(tvp, uvp, vvp) \
do { \
(vvp)->tv_sec = (tvp)->tv_sec + (uvp)->tv_sec; \
(vvp)->tv_usec = (tvp)->tv_usec + (uvp)->tv_usec; \
if ((vvp)->tv_usec >= 1000000) { \
(vvp)->tv_sec++; \
(vvp)->tv_usec -= 1000000; \
} \
} while (/* CONSTCOND */ 0)
#define timersub(tvp, uvp, vvp) \
do { \
(vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec; \
(vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec; \
if ((vvp)->tv_usec < 0) { \
(vvp)->tv_sec--; \
(vvp)->tv_usec += 1000000; \
} \
} while (/* CONSTCOND */ 0)
#endif
struct ifinfo *iflist;
struct timeval tm_max = {0x7fffffff, 0x7fffffff};
int aflag = 0;
int dflag = 0;
static int log_upto = 999;
static int fflag = 0;
int aflag = 0;
int dflag = 0;
/* protocol constatns */
#define MAX_RTR_SOLICITATION_DELAY 1 /* second */
#define RTR_SOLICITATION_INTERVAL 4 /* seconds */
#define MAX_RTR_SOLICITATIONS 3 /* times */
/* implementation dependent constants */
#define PROBE_INTERVAL 60 /* secondes XXX: should be configurable */
/* utility macros */
/* a < b */
#define TIMEVAL_LT(a, b) (((a).tv_sec < (b).tv_sec) ||\
(((a).tv_sec == (b).tv_sec) && \
((a).tv_usec < (b).tv_usec)))
/* a <= b */
#define TIMEVAL_LEQ(a, b) (((a).tv_sec < (b).tv_sec) ||\
(((a).tv_sec == (b).tv_sec) &&\
((a).tv_usec <= (b).tv_usec)))
/* a == b */
#define TIMEVAL_EQ(a, b) (((a).tv_sec==(b).tv_sec) && ((a).tv_usec==(b).tv_usec))
/*
* implementation dependent constants in seconds
* XXX: should be configurable
*/
#define PROBE_INTERVAL 60
int main __P((int, char **));
/* static variables and functions */
static int mobile_node = 0;
#ifndef SMALL
static int do_dump;
static char *dumpfilename = "/var/run/rtsold.dump"; /* XXX: should be configurable */
#endif
#if 0
static int ifreconfig __P((char *));
#endif
static int make_packet __P((struct ifinfo *));
static struct timeval *rtsol_check_timer __P((void));
static void TIMEVAL_ADD __P((struct timeval *, struct timeval *,
struct timeval *));
static void TIMEVAL_SUB __P((struct timeval *, struct timeval *,
struct timeval *));
#ifndef SMALL
static void rtsold_set_dump_file __P((int));
#endif
static void usage __P((char *));
int
@ -185,8 +196,10 @@ main(int argc, char **argv)
if (getinet6sysctl(IPV6CTL_FORWARDING))
warnx("kernel is configured as a router, not a host");
#ifndef SMALL
/* initialization to dump internal status to a file */
signal(SIGUSR1, rtsold_set_dump_file);
#endif
if (!fflag)
daemon(0, 0); /* act as a daemon */
@ -197,7 +210,7 @@ main(int argc, char **argv)
* uses the socket.
*/
if ((s = sockopen()) < 0) {
warnmsg(LOG_ERR, __FUNCTION__, "failed to open a socket");
warnmsg(LOG_ERR, __func__, "failed to open a socket");
exit(1);
/*NOTREACHED*/
}
@ -208,7 +221,7 @@ main(int argc, char **argv)
#ifdef USE_RTSOCK
if ((rtsock = rtsock_open()) < 0) {
warnmsg(LOG_ERR, __FUNCTION__, "failed to open a socket");
warnmsg(LOG_ERR, __func__, "failed to open a socket");
exit(1);
/*NOTREACHED*/
}
@ -218,7 +231,7 @@ main(int argc, char **argv)
/* configuration per interface */
if (ifinit()) {
warnmsg(LOG_ERR, __FUNCTION__,
warnmsg(LOG_ERR, __func__,
"failed to initilizatoin interfaces");
exit(1);
/*NOTREACHED*/
@ -227,7 +240,7 @@ main(int argc, char **argv)
argv = autoifprobe();
while (argv && *argv) {
if (ifconfig(*argv)) {
warnmsg(LOG_ERR, __FUNCTION__,
warnmsg(LOG_ERR, __func__,
"failed to initialize %s", *argv);
exit(1);
/*NOTREACHED*/
@ -237,7 +250,7 @@ main(int argc, char **argv)
/* setup for probing default routers */
if (probe_init()) {
warnmsg(LOG_ERR, __FUNCTION__,
warnmsg(LOG_ERR, __func__,
"failed to setup for probing routers");
exit(1);
/*NOTREACHED*/
@ -246,7 +259,7 @@ main(int argc, char **argv)
/* dump the current pid */
if (!once) {
if (pidfile(NULL) < 0) {
warnmsg(LOG_ERR, __FUNCTION__,
warnmsg(LOG_ERR, __func__,
"failed to open a pid log file: %s",
strerror(errno));
}
@ -255,10 +268,12 @@ main(int argc, char **argv)
for (;;) { /* main loop */
int e;
#ifndef SMALL
if (do_dump) { /* SIGUSR1 */
do_dump = 0;
rtsold_dump_file(dumpfilename);
}
#endif
timeout = rtsol_check_timer();
@ -280,7 +295,7 @@ main(int argc, char **argv)
e = poll(set, 2, timeout ? (timeout->tv_sec * 1000 + timeout->tv_usec / 1000) : INFTIM);
if (e < 1) {
if (e < 0 && errno != EINTR) {
warnmsg(LOG_ERR, __FUNCTION__, "select: %s",
warnmsg(LOG_ERR, __func__, "select: %s",
strerror(errno));
}
continue;
@ -307,19 +322,19 @@ ifconfig(char *ifname)
int flags;
if ((sdl = if_nametosdl(ifname)) == NULL) {
warnmsg(LOG_ERR, __FUNCTION__,
warnmsg(LOG_ERR, __func__,
"failed to get link layer information for %s", ifname);
return(-1);
}
if (find_ifinfo(sdl->sdl_index)) {
warnmsg(LOG_ERR, __FUNCTION__,
warnmsg(LOG_ERR, __func__,
"interface %s was already configured", ifname);
free(sdl);
return(-1);
}
if ((ifinfo = malloc(sizeof(*ifinfo))) == NULL) {
warnmsg(LOG_ERR, __FUNCTION__, "memory allocation failed");
warnmsg(LOG_ERR, __func__, "memory allocation failed");
free(sdl);
return(-1);
}
@ -440,7 +455,7 @@ make_packet(struct ifinfo *ifinfo)
char *buf;
if ((lladdroptlen = lladdropt_length(ifinfo->sdl)) == 0) {
warnmsg(LOG_INFO, __FUNCTION__,
warnmsg(LOG_INFO, __func__,
"link-layer address option has null length"
" on %s. Treat as not included.", ifinfo->ifname);
}
@ -449,7 +464,7 @@ make_packet(struct ifinfo *ifinfo)
/* allocate buffer */
if ((buf = malloc(packlen)) == NULL) {
warnmsg(LOG_ERR, __FUNCTION__,
warnmsg(LOG_ERR, __func__,
"memory allocation failed for %s", ifinfo->ifname);
return(-1);
}
@ -483,9 +498,9 @@ rtsol_check_timer(void)
rtsol_timer = tm_max;
for (ifinfo = iflist; ifinfo; ifinfo = ifinfo->next) {
if (TIMEVAL_LEQ(ifinfo->expire, now)) {
if (timercmp(&ifinfo->expire, &now, <=)) {
if (dflag > 1)
warnmsg(LOG_DEBUG, __FUNCTION__,
warnmsg(LOG_DEBUG, __func__,
"timer expiration on %s, "
"state = %d", ifinfo->ifname,
ifinfo->state);
@ -510,7 +525,7 @@ rtsol_check_timer(void)
ifinfo->active = interface_status(ifinfo);
if (oldstatus != ifinfo->active) {
warnmsg(LOG_DEBUG, __FUNCTION__,
warnmsg(LOG_DEBUG, __func__,
"%s status is changed"
" from %d to %d",
ifinfo->ifname,
@ -539,7 +554,7 @@ rtsol_check_timer(void)
if (ifinfo->probes < MAX_RTR_SOLICITATIONS)
sendpacket(ifinfo);
else {
warnmsg(LOG_INFO, __FUNCTION__,
warnmsg(LOG_INFO, __func__,
"No answer after sending %d RSs",
ifinfo->probes);
ifinfo->probes = 0;
@ -550,21 +565,21 @@ rtsol_check_timer(void)
rtsol_timer_update(ifinfo);
}
if (TIMEVAL_LT(ifinfo->expire, rtsol_timer))
if (timercmp(&ifinfo->expire, &rtsol_timer, <))
rtsol_timer = ifinfo->expire;
}
if (TIMEVAL_EQ(rtsol_timer, tm_max)) {
warnmsg(LOG_DEBUG, __FUNCTION__, "there is no timer");
if (timercmp(&rtsol_timer, &tm_max, ==)) {
warnmsg(LOG_DEBUG, __func__, "there is no timer");
return(NULL);
} else if (TIMEVAL_LT(rtsol_timer, now))
} else if (timercmp(&rtsol_timer, &now, <))
/* this may occur when the interval is too small */
returnval.tv_sec = returnval.tv_usec = 0;
else
TIMEVAL_SUB(&rtsol_timer, &now, &returnval);
timersub(&rtsol_timer, &now, &returnval);
if (dflag > 1)
warnmsg(LOG_DEBUG, __FUNCTION__, "New timer is %ld.%06ld",
warnmsg(LOG_DEBUG, __func__, "New timer is %ld:%08ld",
(long)returnval.tv_sec, (long)returnval.tv_usec);
return(&returnval);
@ -616,23 +631,23 @@ rtsol_timer_update(struct ifinfo *ifinfo)
}
break;
default:
warnmsg(LOG_ERR, __FUNCTION__,
warnmsg(LOG_ERR, __func__,
"illegal interface state(%d) on %s",
ifinfo->state, ifinfo->ifname);
return;
}
/* reset the timer */
if (TIMEVAL_EQ(ifinfo->timer, tm_max)) {
if (timercmp(&ifinfo->timer, &tm_max, ==)) {
ifinfo->expire = tm_max;
warnmsg(LOG_DEBUG, __FUNCTION__,
warnmsg(LOG_DEBUG, __func__,
"stop timer for %s", ifinfo->ifname);
} else {
gettimeofday(&now, NULL);
TIMEVAL_ADD(&now, &ifinfo->timer, &ifinfo->expire);
timeradd(&now, &ifinfo->timer, &ifinfo->expire);
if (dflag > 1)
warnmsg(LOG_DEBUG, __FUNCTION__,
warnmsg(LOG_DEBUG, __func__,
"set timer for %s to %d:%d", ifinfo->ifname,
(int)ifinfo->timer.tv_sec,
(int)ifinfo->timer.tv_usec);
@ -644,44 +659,13 @@ rtsol_timer_update(struct ifinfo *ifinfo)
/* timer related utility functions */
#define MILLION 1000000
/* result = a + b */
static void
TIMEVAL_ADD(struct timeval *a, struct timeval *b, struct timeval *result)
{
long l;
if ((l = a->tv_usec + b->tv_usec) < MILLION) {
result->tv_usec = l;
result->tv_sec = a->tv_sec + b->tv_sec;
} else {
result->tv_usec = l - MILLION;
result->tv_sec = a->tv_sec + b->tv_sec + 1;
}
}
/*
* result = a - b
* XXX: this function assumes that a >= b.
*/
void
TIMEVAL_SUB(struct timeval *a, struct timeval *b, struct timeval *result)
{
long l;
if ((l = a->tv_usec - b->tv_usec) >= 0) {
result->tv_usec = l;
result->tv_sec = a->tv_sec - b->tv_sec;
} else {
result->tv_usec = MILLION + l;
result->tv_sec = a->tv_sec - b->tv_sec - 1;
}
}
#ifndef SMALL
static void
rtsold_set_dump_file(int sig)
{
do_dump = 1;
}
#endif
static void
usage(char *progname)