summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--usr.sbin/rtadvd/advcap.c16
-rw-r--r--usr.sbin/rtadvd/advcap.h6
-rw-r--r--usr.sbin/rtadvd/config.c344
-rw-r--r--usr.sbin/rtadvd/dump.c86
-rw-r--r--usr.sbin/rtadvd/rrenum.c7
-rw-r--r--usr.sbin/rtadvd/rtadvd.87
-rw-r--r--usr.sbin/rtadvd/rtadvd.c36
-rw-r--r--usr.sbin/rtadvd/rtadvd.h23
-rw-r--r--usr.sbin/rtadvd/timer.c4
9 files changed, 212 insertions, 317 deletions
diff --git a/usr.sbin/rtadvd/advcap.c b/usr.sbin/rtadvd/advcap.c
index 1a97ed18fcf..891ed8e97cf 100644
--- a/usr.sbin/rtadvd/advcap.c
+++ b/usr.sbin/rtadvd/advcap.c
@@ -1,5 +1,5 @@
-/* $OpenBSD: advcap.c,v 1.6 2002/03/14 16:44:25 mpech Exp $ */
-/* $KAME: advcap.c,v 1.5 2001/02/01 09:12:08 jinmei Exp $ */
+/* $OpenBSD: advcap.c,v 1.7 2002/05/29 14:34:05 itojun Exp $ */
+/* $KAME: advcap.c,v 1.9 2002/05/29 14:28:35 itojun Exp $ */
/*
* Copyright (c) 1983 The Regents of the University of California.
@@ -96,7 +96,7 @@ int getent(char *, char *, char *);
int tnchktc(void);
int tnamatch(char *);
static char *tskip(char *);
-long long tgetnum(char *);
+int64_t tgetnum(char *);
int tgetflag(char *);
char *tgetstr(char *, char **);
static char *tdecode(char *, char **);
@@ -161,7 +161,7 @@ getent(bp, name, cp)
}
break;
}
- if (cp >= bp+BUFSIZ) {
+ if (cp >= bp + BUFSIZ) {
write(2,"Remcap entry too long\n", 23);
break;
} else
@@ -197,7 +197,7 @@ tnchktc()
p = tbuf + strlen(tbuf) - 2; /* before the last colon */
while (*--p != ':')
- if (p<tbuf) {
+ if (p < tbuf) {
write(2, "Bad remcap entry\n", 18);
return (0);
}
@@ -205,7 +205,7 @@ tnchktc()
/* p now points to beginning of last field */
if (p[0] != 't' || p[1] != 'c')
return (1);
- strcpy(tcname, p+3);
+ strlcpy(tcname, p + 3, sizeof tcname);
q = tcname;
while (*q && *q != ':')
q++;
@@ -307,11 +307,11 @@ breakbreak:
* a # character. If the option is not found we return -1.
* Note that we handle octal numbers beginning with 0.
*/
-long long
+int64_t
tgetnum(id)
char *id;
{
- long long i;
+ int64_t i;
int base;
char *bp = tbuf;
diff --git a/usr.sbin/rtadvd/advcap.h b/usr.sbin/rtadvd/advcap.h
index 3c6ad980db4..50d3156fb11 100644
--- a/usr.sbin/rtadvd/advcap.h
+++ b/usr.sbin/rtadvd/advcap.h
@@ -1,5 +1,5 @@
-/* $OpenBSD: advcap.h,v 1.5 2002/02/16 21:28:08 millert Exp $ */
-/* $KAME: advcap.h,v 1.3 2001/02/01 09:12:08 jinmei Exp $ */
+/* $OpenBSD: advcap.h,v 1.6 2002/05/29 14:34:05 itojun Exp $ */
+/* $KAME: advcap.h,v 1.4 2001/06/08 04:46:19 jinmei Exp $ */
/*
* Copyright (C) 1994,1995 by Andrey A. Chernov, Moscow, Russia.
@@ -38,7 +38,7 @@ __BEGIN_DECLS
extern int agetent(char *, const char *);
extern int agetflag(const char *);
-extern long long agetnum(const char *);
+extern int64_t agetnum(const char *);
extern char *agetstr(const char *, char **);
__END_DECLS
diff --git a/usr.sbin/rtadvd/config.c b/usr.sbin/rtadvd/config.c
index a369c16757b..52587c3553a 100644
--- a/usr.sbin/rtadvd/config.c
+++ b/usr.sbin/rtadvd/config.c
@@ -1,5 +1,5 @@
-/* $OpenBSD: config.c,v 1.14 2002/02/16 21:28:08 millert Exp $ */
-/* $KAME: config.c,v 1.47 2001/06/02 18:50:46 jinmei Exp $ */
+/* $OpenBSD: config.c,v 1.15 2002/05/29 14:34:05 itojun Exp $ */
+/* $KAME: config.c,v 1.62 2002/05/29 10:13:10 itojun Exp $ */
/*
* Copyright (C) 1998 WIDE Project.
@@ -37,9 +37,6 @@
#include <sys/sysctl.h>
#include <net/if.h>
-#if defined(__FreeBSD__) && __FreeBSD__ >= 3
-#include <net/if_var.h>
-#endif /* __FreeBSD__ >= 3 */
#include <net/route.h>
#include <net/if_dl.h>
@@ -48,9 +45,6 @@
#include <netinet/ip6.h>
#include <netinet6/ip6_var.h>
#include <netinet/icmp6.h>
-#ifdef MIP6
-#include <netinet6/mip6.h>
-#endif
#include <arpa/inet.h>
@@ -59,9 +53,7 @@
#include <errno.h>
#include <string.h>
#include <stdlib.h>
-#if defined(__NetBSD__) || defined(__OpenBSD__)
#include <search.h>
-#endif
#include <unistd.h>
#include <ifaddrs.h>
@@ -71,7 +63,7 @@
#include "if.h"
#include "config.h"
-static void makeentry(char *, int, char *, int);
+static void makeentry(char *, size_t, int, char *, int);
static void get_prefix(struct rainfo *);
static int getinet6sysctl(int);
@@ -85,7 +77,7 @@ getconfig(intface)
char tbuf[BUFSIZ];
struct rainfo *tmp;
long val;
- long long val64;
+ int64_t val64;
char buf[BUFSIZ];
char *bp = buf;
char *addr;
@@ -93,7 +85,7 @@ getconfig(intface)
#define MUSTHAVE(var, cap) \
do { \
- long long t; \
+ int64_t t; \
if ((t = agetnum(cap)) < 0) { \
fprintf(stderr, "rtadvd: need %s for interface %s\n", \
cap, intface); \
@@ -155,17 +147,18 @@ getconfig(intface)
MAYHAVE(val, "maxinterval", DEF_MAXRTRADVINTERVAL);
if (val < MIN_MAXINTERVAL || val > MAX_MAXINTERVAL) {
syslog(LOG_ERR,
- "<%s> maxinterval must be between %e and %u",
- __FUNCTION__, MIN_MAXINTERVAL, MAX_MAXINTERVAL);
+ "<%s> maxinterval (%ld) on %s is invalid "
+ "(must be between %e and %u)", __FUNCTION__, val,
+ intface, MIN_MAXINTERVAL, MAX_MAXINTERVAL);
exit(1);
}
tmp->maxinterval = (u_int)val;
MAYHAVE(val, "mininterval", tmp->maxinterval/3);
if (val < MIN_MININTERVAL || val > (tmp->maxinterval * 3) / 4) {
syslog(LOG_ERR,
- "<%s> mininterval must be between %e and %d",
- __FUNCTION__,
- MIN_MININTERVAL,
+ "<%s> mininterval (%ld) on %s is invalid "
+ "(must be between %e and %d)",
+ __FUNCTION__, val, intface, MIN_MININTERVAL,
(tmp->maxinterval * 3) / 4);
exit(1);
}
@@ -175,19 +168,25 @@ getconfig(intface)
tmp->hoplimit = val & 0xff;
MAYHAVE(val, "raflags", 0);
- tmp->managedflg= val & ND_RA_FLAG_MANAGED;
+ tmp->managedflg = val & ND_RA_FLAG_MANAGED;
tmp->otherflg = val & ND_RA_FLAG_OTHER;
-#ifdef MIP6
- if (mobileip6)
- tmp->haflg = val & ND_RA_FLAG_HA;
+#ifndef ND_RA_FLAG_RTPREF_MASK
+#define ND_RA_FLAG_RTPREF_MASK 0x18 /* 00011000 */
+#define ND_RA_FLAG_RTPREF_RSV 0x10 /* 00010000 */
#endif
+ tmp->rtpref = val & ND_RA_FLAG_RTPREF_MASK;
+ if (tmp->rtpref == ND_RA_FLAG_RTPREF_RSV) {
+ syslog(LOG_ERR, "<%s> invalid router preference (%02x) on %s",
+ __FUNCTION__, tmp->rtpref, intface);
+ exit(1);
+ }
MAYHAVE(val, "rltime", tmp->maxinterval * 3);
if (val && (val < tmp->maxinterval || val > MAXROUTERLIFETIME)) {
syslog(LOG_ERR,
- "<%s> router lifetime on %s must be 0 or"
- " between %d and %d",
- __FUNCTION__, intface,
+ "<%s> router lifetime (%ld) on %s is invalid "
+ "(must be 0 or between %d and %d)",
+ __FUNCTION__, val, intface, tmp->maxinterval,
tmp->maxinterval, MAXROUTERLIFETIME);
exit(1);
}
@@ -200,65 +199,39 @@ getconfig(intface)
* explicitly set zero. (see also the above section)
*/
if (val && forwarding == 0) {
- syslog(LOG_WARNING,
+ syslog(LOG_ERR,
"<%s> non zero router lifetime is specified for %s, "
- "which must not be allowed for hosts.",
+ "which must not be allowed for hosts. you must "
+ "change router lifetime or enable IPv6 forwarding.",
__FUNCTION__, intface);
exit(1);
}
tmp->lifetime = val & 0xffff;
MAYHAVE(val, "rtime", DEF_ADVREACHABLETIME);
- if (val > MAXREACHABLETIME) {
+ if (val < 0 || val > MAXREACHABLETIME) {
syslog(LOG_ERR,
- "<%s> reachable time must be no greater than %d",
- __FUNCTION__, MAXREACHABLETIME);
+ "<%s> reachable time (%ld) on %s is invalid "
+ "(must be no greater than %d)",
+ __FUNCTION__, val, intface, MAXREACHABLETIME);
exit(1);
}
tmp->reachabletime = (u_int32_t)val;
MAYHAVE(val64, "retrans", DEF_ADVRETRANSTIMER);
if (val64 < 0 || val64 > 0xffffffff) {
- syslog(LOG_ERR,
- "<%s> retrans time out of range", __FUNCTION__);
+ syslog(LOG_ERR, "<%s> retrans time (%lld) on %s out of range",
+ __FUNCTION__, (long long)val64, intface);
exit(1);
}
tmp->retranstimer = (u_int32_t)val64;
-#ifndef MIP6
- if (agetstr("hapref", &bp) || agetstr("hatime", &bp)) {
+ if (agetnum("hapref") != -1 || agetnum("hatime") != -1) {
syslog(LOG_ERR,
"<%s> mobile-ip6 configuration not supported",
__FUNCTION__);
exit(1);
}
-#else
- if (!mobileip6) {
- if (agetstr("hapref", &bp) || agetstr("hatime", &bp)) {
- syslog(LOG_ERR,
- "<%s> mobile-ip6 configuration without "
- "proper command line option",
- __FUNCTION__);
- exit(1);
- }
- } else {
- tmp->hapref = 0;
- if ((val = agetnum("hapref")) >= 0)
- tmp->hapref = (int16_t)val;
- if (tmp->hapref != 0) {
- tmp->hatime = 0;
- MUSTHAVE(val, "hatime");
- tmp->hatime = (u_int16_t)val;
- if (tmp->hatime <= 0) {
- syslog(LOG_ERR,
- "<%s> home agent lifetime must be greater than 0",
- __FUNCTION__);
- exit(1);
- }
- }
- }
-#endif
-
/* prefix information */
/*
@@ -269,7 +242,7 @@ getconfig(intface)
MAYHAVE(val, "clockskew", 0);
tmp->clockskew = val;
- if ((pfxs = agetnum("addrs")) < 0) {
+ if ((pfxs = agetnum("addrs")) <= 0) {
/* auto configure prefix information */
if (agetstr("addr", &bp) || agetstr("addr1", &bp)) {
syslog(LOG_ERR,
@@ -279,8 +252,7 @@ getconfig(intface)
exit(1);
}
get_prefix(tmp);
- }
- else {
+ } else {
tmp->pfxs = pfxs;
for (i = 0; i < pfxs; i++) {
struct prefix *pfx;
@@ -301,46 +273,66 @@ getconfig(intface)
pfx->origin = PREFIX_FROM_CONFIG;
- makeentry(entbuf, i, "prefixlen", added);
+
+ makeentry(entbuf, sizeof(entbuf), i, "addr", added);
+ addr = (char *)agetstr(entbuf, &bp);
+ if (addr == NULL) {
+ syslog(LOG_ERR,
+ "<%s> need %s as a prefix for "
+ "interface %s",
+ __FUNCTION__, entbuf, intface);
+ exit(1);
+ }
+ if (inet_pton(AF_INET6, addr,
+ &pfx->prefix) != 1) {
+ syslog(LOG_ERR,
+ "<%s> inet_pton failed for %s",
+ __FUNCTION__, addr);
+ exit(1);
+ }
+ if (IN6_IS_ADDR_MULTICAST(&pfx->prefix)) {
+ syslog(LOG_ERR,
+ "<%s> multicast prefix (%s) must "
+ "not be advertised on %s",
+ __FUNCTION__, addr, intface);
+ exit(1);
+ }
+ if (IN6_IS_ADDR_LINKLOCAL(&pfx->prefix))
+ syslog(LOG_NOTICE,
+ "<%s> link-local prefix (%s) will be"
+ " advertised on %s",
+ __FUNCTION__, addr, intface);
+
+ makeentry(entbuf, sizeof(entbuf), i, "prefixlen",
+ added);
MAYHAVE(val, entbuf, 64);
if (val < 0 || val > 128) {
- syslog(LOG_ERR,
- "<%s> prefixlen out of range",
- __FUNCTION__);
+ syslog(LOG_ERR, "<%s> prefixlen (%ld) for %s "
+ "on %s out of range",
+ __FUNCTION__, val, addr, intface);
exit(1);
}
pfx->prefixlen = (int)val;
- makeentry(entbuf, i, "pinfoflags", added);
-#ifdef MIP6
- if (mobileip6)
- {
- MAYHAVE(val, entbuf,
- (ND_OPT_PI_FLAG_ONLINK|ND_OPT_PI_FLAG_AUTO|
- ND_OPT_PI_FLAG_ROUTER));
- } else
-#endif
- {
- MAYHAVE(val, entbuf,
- (ND_OPT_PI_FLAG_ONLINK|ND_OPT_PI_FLAG_AUTO));
- }
+ makeentry(entbuf, sizeof(entbuf), i, "pinfoflags",
+ added);
+ MAYHAVE(val, entbuf,
+ (ND_OPT_PI_FLAG_ONLINK|ND_OPT_PI_FLAG_AUTO));
pfx->onlinkflg = val & ND_OPT_PI_FLAG_ONLINK;
pfx->autoconfflg = val & ND_OPT_PI_FLAG_AUTO;
-#ifdef MIP6
- pfx->routeraddr = val & ND_OPT_PI_FLAG_ROUTER;
-#endif
- makeentry(entbuf, i, "vltime", added);
+ makeentry(entbuf, sizeof(entbuf), i, "vltime", added);
MAYHAVE(val64, entbuf, DEF_ADVVALIDLIFETIME);
if (val64 < 0 || val64 > 0xffffffff) {
- syslog(LOG_ERR,
- "<%s> vltime out of range",
- __FUNCTION__);
+ syslog(LOG_ERR, "<%s> vltime (%lld) for "
+ "%s/%d on %s is out of range",
+ __FUNCTION__, (long long)val64,
+ addr, pfx->prefixlen, intface);
exit(1);
}
pfx->validlifetime = (u_int32_t)val64;
- makeentry(entbuf, i, "vltimedecr", added);
+ makeentry(entbuf, sizeof(entbuf), i, "vltimedecr", added);
if (agetflag(entbuf)) {
struct timeval now;
gettimeofday(&now, 0);
@@ -348,59 +340,33 @@ getconfig(intface)
now.tv_sec + pfx->validlifetime;
}
- makeentry(entbuf, i, "pltime", added);
+ makeentry(entbuf, sizeof(entbuf), i, "pltime", added);
MAYHAVE(val64, entbuf, DEF_ADVPREFERREDLIFETIME);
if (val64 < 0 || val64 > 0xffffffff) {
syslog(LOG_ERR,
- "<%s> pltime out of range",
- __FUNCTION__);
+ "<%s> pltime (%lld) for %s/%d on %s "
+ "is out of range",
+ __FUNCTION__, (long long)val64,
+ addr, pfx->prefixlen, intface);
exit(1);
}
pfx->preflifetime = (u_int32_t)val64;
- makeentry(entbuf, i, "pltimedecr", added);
+ makeentry(entbuf, sizeof(entbuf), i, "pltimedecr", added);
if (agetflag(entbuf)) {
struct timeval now;
gettimeofday(&now, 0);
pfx->pltimeexpire =
now.tv_sec + pfx->preflifetime;
}
-
- makeentry(entbuf, i, "addr", added);
- addr = (char *)agetstr(entbuf, &bp);
- if (addr == NULL) {
- syslog(LOG_ERR,
- "<%s> need %s as an prefix for "
- "interface %s",
- __FUNCTION__, entbuf, intface);
- exit(1);
- }
- if (inet_pton(AF_INET6, addr,
- &pfx->prefix) != 1) {
- syslog(LOG_ERR,
- "<%s> inet_pton failed for %s",
- __FUNCTION__, addr);
- exit(1);
- }
- if (IN6_IS_ADDR_MULTICAST(&pfx->prefix)) {
- syslog(LOG_ERR,
- "<%s> multicast prefix(%s) must "
- "not be advertised (IF=%s)",
- __FUNCTION__, addr, intface);
- exit(1);
- }
- if (IN6_IS_ADDR_LINKLOCAL(&pfx->prefix))
- syslog(LOG_NOTICE,
- "<%s> link-local prefix(%s) will be"
- " advertised on %s",
- __FUNCTION__, addr, intface);
}
}
MAYHAVE(val, "mtu", 0);
if (val < 0 || val > 0xffffffff) {
syslog(LOG_ERR,
- "<%s> mtu out of range", __FUNCTION__);
+ "<%s> mtu (%ld) on %s out of range",
+ __FUNCTION__, val, intface);
exit(1);
}
tmp->linkmtu = (u_int32_t)val;
@@ -413,12 +379,18 @@ getconfig(intface)
}
else if (tmp->linkmtu < IPV6_MMTU || tmp->linkmtu > tmp->phymtu) {
syslog(LOG_ERR,
- "<%s> advertised link mtu must be between"
- " least MTU and physical link MTU",
- __FUNCTION__);
+ "<%s> advertised link mtu (%lu) on %s is invalid (must "
+ "be between least MTU (%d) and physical link MTU (%d)",
+ __FUNCTION__, (unsigned long)tmp->linkmtu, intface,
+ IPV6_MMTU, tmp->phymtu);
exit(1);
}
+ /* route information */
+ MAYHAVE(val, "routes", -1);
+ if (val != -1)
+ syslog(LOG_INFO, "route information option is not available");
+
/* okey */
tmp->next = ralist;
ralist = tmp;
@@ -449,6 +421,8 @@ get_prefix(struct rainfo *rai)
exit(1);
}
for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
+ int plen;
+
if (strcmp(ifa->ifa_name, rai->ifname) != 0)
continue;
if (ifa->ifa_addr->sa_family != AF_INET6)
@@ -456,6 +430,22 @@ get_prefix(struct rainfo *rai)
a = &((struct sockaddr_in6 *)ifa->ifa_addr)->sin6_addr;
if (IN6_IS_ADDR_LINKLOCAL(a))
continue;
+ /* get prefix length */
+ m = (u_char *)&((struct sockaddr_in6 *)ifa->ifa_netmask)->sin6_addr;
+ lim = (u_char *)(ifa->ifa_netmask) + ifa->ifa_netmask->sa_len;
+ plen = prefixlen(m, lim);
+ if (plen <= 0 || plen > 128) {
+ syslog(LOG_ERR, "<%s> failed to get prefixlen "
+ "or prefix is invalid",
+ __FUNCTION__);
+ exit(1);
+ }
+ if (plen == 128) /* XXX */
+ continue;
+ if (find_prefix(rai, a, plen)) {
+ /* ignore a duplicated prefix. */
+ continue;
+ }
/* allocate memory to store prefix info. */
if ((pp = malloc(sizeof(*pp))) == NULL) {
@@ -466,27 +456,17 @@ get_prefix(struct rainfo *rai)
}
memset(pp, 0, sizeof(*pp));
- /* set prefix length */
- m = (u_char *)&((struct sockaddr_in6 *)ifa->ifa_netmask)->sin6_addr;
- lim = (u_char *)(ifa->ifa_netmask) + ifa->ifa_netmask->sa_len;
- pp->prefixlen = prefixlen(m, lim);
- if (pp->prefixlen < 0 || pp->prefixlen > 128) {
- syslog(LOG_ERR,
- "<%s> failed to get prefixlen "
- "or prefix is invalid",
- __FUNCTION__);
- exit(1);
- }
-
/* set prefix, sweep bits outside of prefixlen */
+ pp->prefixlen = plen;
memcpy(&pp->prefix, a, sizeof(*a));
- p = (u_char *)&pp->prefix;
- ep = (u_char *)(&pp->prefix + 1);
- while (m < lim)
- *p++ &= *m++;
- while (p < ep)
- *p++ = 0x00;
-
+ {
+ p = (u_char *)&pp->prefix;
+ ep = (u_char *)(&pp->prefix + 1);
+ while (m < lim)
+ *p++ &= *m++;
+ while (p < ep)
+ *p++ = 0x00;
+ }
if (!inet_ntop(AF_INET6, &pp->prefix, ntopbuf,
sizeof(ntopbuf))) {
syslog(LOG_ERR, "<%s> inet_ntop failed", __FUNCTION__);
@@ -514,17 +494,21 @@ get_prefix(struct rainfo *rai)
}
static void
-makeentry(buf, id, string, add)
- char *buf, *string;
- int id, add;
+makeentry(buf, len, id, string, add)
+ char *buf;
+ size_t len;
+ int id;
+ char *string;
+ int add;
{
- strcpy(buf, string);
+ char *ep = buf + len;
+
+ strlcpy(buf, string, len);
if (add) {
char *cp;
cp = (char *)index(buf, '\0');
- cp += sprintf(cp, "%d", id);
- *cp = '\0';
+ snprintf(cp, ep - cp, "%d", id);
}
}
@@ -564,7 +548,7 @@ add_prefix(struct rainfo *rai, struct in6_prefixreq *ipr)
/* free the previous packet */
free(rai->ra_data);
- rai->ra_data = 0;
+ rai->ra_data = NULL;
/* reconstruct the packet */
rai->pfxs++;
@@ -670,10 +654,6 @@ make_packet(struct rainfo *rainfo)
struct nd_router_advert *ra;
struct nd_opt_prefix_info *ndopt_pi;
struct nd_opt_mtu *ndopt_mtu;
-#ifdef MIP6
- struct nd_opt_advinterval *ndopt_advint;
- struct nd_opt_homeagent_info *ndopt_hai;
-#endif
struct prefix *pfx;
/* calculate total length */
@@ -682,8 +662,7 @@ make_packet(struct rainfo *rainfo)
if ((lladdroptlen = lladdropt_length(rainfo->sdl)) == 0) {
syslog(LOG_INFO,
"<%s> link-layer address option has"
- " null length on %s."
- " Treat as not included.",
+ " null length on %s. Treat as not included.",
__FUNCTION__, rainfo->ifname);
rainfo->advlinkopt = 0;
}
@@ -693,12 +672,6 @@ make_packet(struct rainfo *rainfo)
packlen += sizeof(struct nd_opt_prefix_info) * rainfo->pfxs;
if (rainfo->linkmtu)
packlen += sizeof(struct nd_opt_mtu);
-#ifdef MIP6
- if (mobileip6 && rainfo->maxinterval)
- packlen += sizeof(struct nd_opt_advinterval);
- if (mobileip6 && rainfo->hatime)
- packlen += sizeof(struct nd_opt_homeagent_info);
-#endif
/* allocate memory for the packet */
if ((buf = malloc(packlen)) == NULL) {
@@ -707,6 +680,11 @@ make_packet(struct rainfo *rainfo)
__FUNCTION__);
exit(1);
}
+ if (rainfo->ra_data) {
+ /* free the previous packet */
+ free(rainfo->ra_data);
+ rainfo->ra_data = NULL;
+ }
rainfo->ra_data = buf;
/* XXX: what if packlen > 576? */
rainfo->ra_datalen = packlen;
@@ -719,15 +697,16 @@ make_packet(struct rainfo *rainfo)
ra->nd_ra_code = 0;
ra->nd_ra_cksum = 0;
ra->nd_ra_curhoplimit = (u_int8_t)(0xff & rainfo->hoplimit);
- ra->nd_ra_flags_reserved = 0;
+ ra->nd_ra_flags_reserved = 0; /* just in case */
+ /*
+ * XXX: the router preference field, which is a 2-bit field, should be
+ * initialized before other fields.
+ */
+ ra->nd_ra_flags_reserved = 0xff & rainfo->rtpref;
ra->nd_ra_flags_reserved |=
rainfo->managedflg ? ND_RA_FLAG_MANAGED : 0;
ra->nd_ra_flags_reserved |=
rainfo->otherflg ? ND_RA_FLAG_OTHER : 0;
-#ifdef MIP6
- ra->nd_ra_flags_reserved |=
- rainfo->haflg ? ND_RA_FLAG_HA : 0;
-#endif
ra->nd_ra_router_lifetime = htons(rainfo->lifetime);
ra->nd_ra_reachable = htonl(rainfo->reachabletime);
ra->nd_ra_retransmit = htonl(rainfo->retranstimer);
@@ -747,29 +726,7 @@ make_packet(struct rainfo *rainfo)
buf += sizeof(struct nd_opt_mtu);
}
-#ifdef MIP6
- if (mobileip6 && rainfo->maxinterval) {
- ndopt_advint = (struct nd_opt_advinterval *)buf;
- ndopt_advint->nd_opt_adv_type = ND_OPT_ADVINTERVAL;
- ndopt_advint->nd_opt_adv_len = 1;
- ndopt_advint->nd_opt_adv_reserved = 0;
- ndopt_advint->nd_opt_adv_interval = htonl(rainfo->maxinterval *
- 1000);
- buf += sizeof(struct nd_opt_advinterval);
- }
-#endif
-#ifdef MIP6
- if (rainfo->hatime) {
- ndopt_hai = (struct nd_opt_homeagent_info *)buf;
- ndopt_hai->nd_opt_hai_type = ND_OPT_HOMEAGENT_INFO;
- ndopt_hai->nd_opt_hai_len = 1;
- ndopt_hai->nd_opt_hai_reserved = 0;
- ndopt_hai->nd_opt_hai_preference = htons(rainfo->hapref);
- ndopt_hai->nd_opt_hai_lifetime = htons(rainfo->hatime);
- buf += sizeof(struct nd_opt_homeagent_info);
- }
-#endif
for (pfx = rainfo->prefix.next;
pfx != &rainfo->prefix; pfx = pfx->next) {
@@ -787,11 +744,6 @@ make_packet(struct rainfo *rainfo)
if (pfx->autoconfflg)
ndopt_pi->nd_opt_pi_flags_reserved |=
ND_OPT_PI_FLAG_AUTO;
-#ifdef MIP6
- if (pfx->routeraddr)
- ndopt_pi->nd_opt_pi_flags_reserved |=
- ND_OPT_PI_FLAG_ROUTER;
-#endif
if (pfx->vltimeexpire || pfx->pltimeexpire)
gettimeofday(&now, NULL);
if (pfx->vltimeexpire == 0)
diff --git a/usr.sbin/rtadvd/dump.c b/usr.sbin/rtadvd/dump.c
index 7735afed4ce..49c7565ff81 100644
--- a/usr.sbin/rtadvd/dump.c
+++ b/usr.sbin/rtadvd/dump.c
@@ -1,5 +1,5 @@
-/* $OpenBSD: dump.c,v 1.4 2002/02/16 21:28:08 millert Exp $ */
-/* $KAME: dump.c,v 1.15 2000/11/11 06:57:22 jinmei Exp $ */
+/* $OpenBSD: dump.c,v 1.5 2002/05/29 14:34:05 itojun Exp $ */
+/* $KAME: dump.c,v 1.27 2002/05/29 14:23:55 itojun Exp $ */
/*
* Copyright (C) 2000 WIDE Project.
@@ -34,9 +34,6 @@
#include <sys/queue.h>
#include <net/if.h>
-#if defined(__FreeBSD__) && __FreeBSD__ >= 3
-#include <net/if_var.h>
-#endif /* __FreeBSD__ >= 3 */
#include <net/if_dl.h>
#include <netinet/in.h>
@@ -53,6 +50,7 @@
#include <syslog.h>
#include <string.h>
#include <errno.h>
+#include <netdb.h>
#include "rtadvd.h"
#include "timer.h"
@@ -66,29 +64,28 @@ extern struct rainfo *ralist;
static char *ether_str(struct sockaddr_dl *);
static void if_dump(void);
-#ifdef __FreeBSD__ /* XXX: see PORTABILITY */
-#define LONGLONG "%qu"
-#else
-#define LONGLONG "%llu"
-#endif
+static char *rtpref_str[] = {
+ "medium", /* 00 */
+ "high", /* 01 */
+ "rsv", /* 10 */
+ "low" /* 11 */
+};
static char *
ether_str(sdl)
struct sockaddr_dl *sdl;
{
- static char ebuf[32];
+ static char hbuf[NI_MAXHOST];
u_char *cp;
- if (sdl->sdl_alen && sdl->sdl_alen > 5) {
+ if (sdl->sdl_alen) {
cp = (u_char *)LLADDR(sdl);
- sprintf(ebuf, "%x:%x:%x:%x:%x:%x",
+ snprintf(hbuf, sizeof(hbuf), "%x:%x:%x:%x:%x:%x",
cp[0], cp[1], cp[2], cp[3], cp[4], cp[5]);
- }
- else {
- sprintf(ebuf, "NONE");
- }
+ } else
+ snprintf(hbuf, sizeof(hbuf), "NONE");
- return(ebuf);
+ return(hbuf);
}
static void
@@ -124,43 +121,36 @@ if_dump()
rai->waiting, rai->initcounter);
/* statistics */
- fprintf(fp,
- " statistics: RA(out/in/inconsistent): "
- LONGLONG "/" LONGLONG "/" LONGLONG ", ",
- (unsigned long long)rai->raoutput,
- (unsigned long long)rai->rainput,
- (unsigned long long)rai->rainconsistent);
- fprintf(fp, "RS(input): " LONGLONG "\n",
- (unsigned long long)rai->rsinput);
+ fprintf(fp, " statistics: RA(out/in/inconsistent): "
+ "%llu/%llu/%llu, ",
+ (unsigned long long)rai->raoutput,
+ (unsigned long long)rai->rainput,
+ (unsigned long long)rai->rainconsistent);
+ fprintf(fp, "RS(input): %llu\n",
+ (unsigned long long)rai->rsinput);
/* interface information */
if (rai->advlinkopt)
fprintf(fp, " Link-layer address: %s\n",
- ether_str(rai->sdl));
+ ether_str(rai->sdl));
fprintf(fp, " MTU: %d\n", rai->phymtu);
/* Router configuration variables */
- fprintf(fp,
- " DefaultLifetime: %d, MaxAdvInterval: %d, "
- "MinAdvInterval: %d\n",
- rai->lifetime, rai->maxinterval, rai->mininterval);
- fprintf(fp, " Flags: %s%s%s MTU: %d\n",
- rai->managedflg ? "M" : "", rai->otherflg ? "O" : "",
-#ifdef MIP6
- rai->haflg ? "H" :
-#endif
- "", rai->linkmtu);
+ fprintf(fp, " DefaultLifetime: %d, MaxAdvInterval: %d, "
+ "MinAdvInterval: %d\n", rai->lifetime, rai->maxinterval,
+ rai->mininterval);
+ fprintf(fp, " Flags: %s%s%s, ",
+ rai->managedflg ? "M" : "", rai->otherflg ? "O" : "",
+ "");
+ fprintf(fp, "Preference: %s, ",
+ rtpref_str[(rai->rtpref >> 3) & 0xff]);
+ fprintf(fp, "MTU: %d\n", rai->linkmtu);
fprintf(fp, " ReachableTime: %d, RetransTimer: %d, "
"CurHopLimit: %d\n", rai->reachabletime,
rai->retranstimer, rai->hoplimit);
-#ifdef MIP6
- fprintf(fp, " HAPreference: %d, HALifetime: %d\n",
- rai->hapref, rai->hatime);
-#endif
-
if (rai->clockskew)
fprintf(fp, " Clock skew: %ldsec\n",
- rai->clockskew);
+ rai->clockskew);
for (first = 1, pfx = rai->prefix.next; pfx != &rai->prefix;
pfx = pfx->next) {
if (first) {
@@ -168,10 +158,9 @@ if_dump()
first = 0;
}
fprintf(fp, " %s/%d(",
- inet_ntop(AF_INET6, &pfx->prefix,
- prefixbuf, sizeof(prefixbuf)),
- pfx->prefixlen);
- switch(pfx->origin) {
+ inet_ntop(AF_INET6, &pfx->prefix, prefixbuf,
+ sizeof(prefixbuf)), pfx->prefixlen);
+ switch (pfx->origin) {
case PREFIX_FROM_KERNEL:
fprintf(fp, "KERNEL, ");
break;
@@ -207,9 +196,6 @@ if_dump()
fprintf(fp, "flags: %s%s%s",
pfx->onlinkflg ? "L" : "",
pfx->autoconfflg ? "A" : "",
-#ifdef MIP6
- pfx->routeraddr ? "R" :
-#endif
"");
fprintf(fp, ")\n");
}
diff --git a/usr.sbin/rtadvd/rrenum.c b/usr.sbin/rtadvd/rrenum.c
index e10930be8b4..ed6aa47ccdb 100644
--- a/usr.sbin/rtadvd/rrenum.c
+++ b/usr.sbin/rtadvd/rrenum.c
@@ -1,5 +1,5 @@
-/* $OpenBSD: rrenum.c,v 1.8 2002/05/21 23:29:46 itojun Exp $ */
-/* $KAME: rrenum.c,v 1.10 2001/01/21 15:32:16 itojun Exp $ */
+/* $OpenBSD: rrenum.c,v 1.9 2002/05/29 14:34:05 itojun Exp $ */
+/* $KAME: rrenum.c,v 1.11 2002/05/21 14:26:55 itojun Exp $ */
/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -36,9 +36,6 @@
#include <sys/sysctl.h>
#include <net/if.h>
-#if defined(__FreeBSD__) && __FreeBSD__ >= 3
-#include <net/if_var.h>
-#endif /* __FreeBSD__ >= 3 */
#include <net/route.h>
#include <netinet/in.h>
#include <netinet/in_var.h>
diff --git a/usr.sbin/rtadvd/rtadvd.8 b/usr.sbin/rtadvd/rtadvd.8
index dc6bbfce4b9..b57287f8134 100644
--- a/usr.sbin/rtadvd/rtadvd.8
+++ b/usr.sbin/rtadvd/rtadvd.8
@@ -1,5 +1,5 @@
-.\" $OpenBSD: rtadvd.8,v 1.16 2001/07/25 10:04:57 mpech Exp $
-.\" $KAME: rtadvd.8,v 1.17 2001/02/04 05:34:38 jinmei Exp $
+.\" $OpenBSD: rtadvd.8,v 1.17 2002/05/29 14:34:05 itojun Exp $
+.\" $KAME: rtadvd.8,v 1.18 2002/04/28 10:43:02 jinmei Exp $
.\"
.\" Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
.\" All rights reserved.
@@ -36,8 +36,8 @@
.Nd router advertisement daemon
.Sh SYNOPSIS
.Nm
+.Op Fl dDfMRs
.Op Fl c Ar configfile
-.Op Fl dDfRs
.Ar interface ...
.Sh DESCRIPTION
.Nm
@@ -102,6 +102,7 @@ Print debugging information.
Even more debugging information is printed.
.It Fl f
Foreground mode (useful when debugging).
+Log messages will be dumped to stderr when this option is specified.
.It Fl M
Specify an interface to join the all-routers site-local multicast group.
By default,
diff --git a/usr.sbin/rtadvd/rtadvd.c b/usr.sbin/rtadvd/rtadvd.c
index 6573a3ccfa5..e7474d47893 100644
--- a/usr.sbin/rtadvd/rtadvd.c
+++ b/usr.sbin/rtadvd/rtadvd.c
@@ -1,5 +1,5 @@
-/* $OpenBSD: rtadvd.c,v 1.17 2002/05/21 23:33:56 itojun Exp $ */
-/* $KAME: rtadvd.c,v 1.50 2001/02/04 06:15:15 itojun Exp $ */
+/* $OpenBSD: rtadvd.c,v 1.18 2002/05/29 14:34:05 itojun Exp $ */
+/* $KAME: rtadvd.c,v 1.66 2002/05/29 14:18:36 itojun Exp $ */
/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -82,9 +82,6 @@ static char *dumpfilename = "/var/run/rtadvd.dump"; /* XXX: should be configurab
static char *mcastif;
int sock;
int rtsock = -1;
-#ifdef MIP6
-int mobileip6 = 0;
-#endif
int accept_rr = 0;
int dflag = 0, sflag = 0;
@@ -96,7 +93,7 @@ struct nd_optlist {
struct nd_opt_hdr *opt;
};
union nd_opts {
- struct nd_opt_hdr *nd_opt_array[7];
+ struct nd_opt_hdr *nd_opt_array[9];
struct {
struct nd_opt_hdr *zero;
struct nd_opt_hdr *src_lladdr;
@@ -122,7 +119,7 @@ union nd_opts {
u_int32_t ndopt_flags[] = {
0, NDOPT_FLAG_SRCLINKADDR, NDOPT_FLAG_TGTLINKADDR,
- NDOPT_FLAG_PREFIXINFO, NDOPT_FLAG_RDHDR, NDOPT_FLAG_MTU
+ NDOPT_FLAG_PREFIXINFO, NDOPT_FLAG_RDHDR, NDOPT_FLAG_MTU,
};
int main(int, char *[]);
@@ -156,11 +153,7 @@ main(argc, argv)
int fflag = 0, logopt;
/* get command line options and arguments */
-#ifdef MIP6
-#define OPTIONS "c:dDfM:mRs"
-#else
#define OPTIONS "c:dDfM:Rs"
-#endif
while ((ch = getopt(argc, argv, OPTIONS)) != -1) {
#undef OPTIONS
switch (ch) {
@@ -179,11 +172,6 @@ main(argc, argv)
case 'M':
mcastif = optarg;
break;
-#ifdef MIP6
- case 'm':
- mobileip6 = 1;
- break;
-#endif
case 'R':
fprintf(stderr, "rtadvd: "
"the -R option is currently ignored.\n");
@@ -199,11 +187,7 @@ main(argc, argv)
argv += optind;
if (argc == 0) {
fprintf(stderr,
-#ifdef MIP6
- "usage: rtadvd [-dDfMmRs] [-c conffile] "
-#else
"usage: rtadvd [-dDfMRs] [-c conffile] "
-#endif
"interfaces...\n");
exit(1);
}
@@ -525,7 +509,7 @@ rtmsg_input()
"<%s> interface %s becomes down. stop timer.",
__FUNCTION__, rai->ifname);
rtadvd_remove_timer(&rai->timer);
- } else if ((oldifflags & IFF_UP) == 0 && /* DOWN to UP */
+ } else if ((oldifflags & IFF_UP) == 0 && /* DOWN to UP */
(iflist[ifindex]->ifm_flags & IFF_UP) != 0) {
syslog(LOG_INFO,
"<%s> interface %s becomes up. restart timer.",
@@ -749,7 +733,7 @@ rs_input(int len, struct nd_router_solicit *rs,
memset(&ndopts, 0, sizeof(ndopts));
if (nd6_options((struct nd_opt_hdr *)(rs + 1),
len - sizeof(struct nd_router_solicit),
- &ndopts, NDOPT_FLAG_SRCLINKADDR)) {
+ &ndopts, NDOPT_FLAG_SRCLINKADDR)) {
syslog(LOG_DEBUG,
"<%s> ND option check failed for an RS from %s on %s",
__FUNCTION__,
@@ -1214,11 +1198,7 @@ nd6_options(struct nd_opt_hdr *hdr, int limit,
goto bad;
}
-#ifdef MIP6
- if (hdr->nd_opt_type > ND_OPT_HOMEAGENT_INFO)
-#else
if (hdr->nd_opt_type > ND_OPT_MTU)
-#endif
{
syslog(LOG_INFO, "<%s> unknown ND option(type %d)",
__FUNCTION__, hdr->nd_opt_type);
@@ -1236,10 +1216,6 @@ nd6_options(struct nd_opt_hdr *hdr, int limit,
case ND_OPT_TARGET_LINKADDR:
case ND_OPT_REDIRECTED_HEADER:
case ND_OPT_MTU:
-#ifdef MIP6
- case ND_OPT_ADVINTERVAL:
- case ND_OPT_HOMEAGENT_INFO:
-#endif
if (ndopts->nd_opt_array[hdr->nd_opt_type]) {
syslog(LOG_INFO,
"<%s> duplicated ND option (type = %d)",
diff --git a/usr.sbin/rtadvd/rtadvd.h b/usr.sbin/rtadvd/rtadvd.h
index 01914adf8d0..403d0e991d9 100644
--- a/usr.sbin/rtadvd/rtadvd.h
+++ b/usr.sbin/rtadvd/rtadvd.h
@@ -1,5 +1,5 @@
-/* $OpenBSD: rtadvd.h,v 1.8 2002/05/21 23:29:46 itojun Exp $ */
-/* $KAME: rtadvd.h,v 1.19 2001/12/20 02:09:37 k-sugyou Exp $ */
+/* $OpenBSD: rtadvd.h,v 1.9 2002/05/29 14:34:05 itojun Exp $ */
+/* $KAME: rtadvd.h,v 1.20 2002/05/29 10:13:10 itojun Exp $ */
/*
* Copyright (C) 1998 WIDE Project.
@@ -46,9 +46,7 @@
#define DEF_ADVPREFERREDLIFETIME 604800
/*XXX int-to-double comparison for INTERVAL items */
-#ifndef MIP6
#define mobileip6 0
-#endif
#define MAXROUTERLIFETIME 9000
#define MIN_MAXINTERVAL (mobileip6 ? 1.5 : 4.0)
@@ -56,9 +54,7 @@
#define MIN_MININTERVAL (mobileip6 ? 0.05 : 3.0)
#define MAXREACHABLETIME 3600000
-#ifndef MIP6
#undef miobileip6
-#endif
#define MAX_INITIAL_RTR_ADVERT_INTERVAL 16
#define MAX_INITIAL_RTR_ADVERTISEMENTS 3
@@ -80,14 +76,12 @@ struct prefix {
long pltimeexpire; /* expiration of pltime; decrement case only */
u_int onlinkflg; /* bool: AdvOnLinkFlag */
u_int autoconfflg; /* bool: AdvAutonomousFlag */
-#ifdef MIP6
- u_int routeraddr; /* bool: RouterAddress */
-#endif
int prefixlen;
int origin; /* from kernel or cofig */
struct in6_addr prefix;
};
+
struct soliciter {
struct soliciter *next;
struct sockaddr_in6 addr;
@@ -116,9 +110,7 @@ struct rainfo {
u_int mininterval; /* MinRtrAdvInterval */
int managedflg; /* AdvManagedFlag */
int otherflg; /* AdvOtherConfigFlag */
-#ifdef MIP6
- int haflg; /* HAFlag */
-#endif
+ int rtpref; /* router preference */
u_int32_t linkmtu; /* AdvLinkMTU */
u_int32_t reachabletime; /* AdvReachableTime */
u_int32_t retranstimer; /* AdvRetransTimer */
@@ -127,10 +119,6 @@ struct rainfo {
int pfxs; /* number of prefixes */
long clockskew; /* used for consisitency check of lifetimes */
-#ifdef MIP6
- u_short hapref; /* Home Agent Preference */
- u_short hatime; /* Home Agent Lifetime */
-#endif
/* actual RA packet data and its length */
size_t ra_datalen;
@@ -154,6 +142,3 @@ struct rainfo *if_indextorainfo(int);
struct prefix *find_prefix(struct rainfo *, struct in6_addr *, int);
extern struct in6_addr in6a_site_allrouters;
-#ifdef MIP6
-extern int mobileip6;
-#endif
diff --git a/usr.sbin/rtadvd/timer.c b/usr.sbin/rtadvd/timer.c
index 55f9a221fca..8e6ccfd12cc 100644
--- a/usr.sbin/rtadvd/timer.c
+++ b/usr.sbin/rtadvd/timer.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: timer.c,v 1.6 2002/05/21 23:29:46 itojun Exp $ */
+/* $OpenBSD: timer.c,v 1.7 2002/05/29 14:34:05 itojun Exp $ */
/* $KAME: timer.c,v 1.7 2002/05/21 14:26:55 itojun Exp $ */
/*
@@ -36,9 +36,7 @@
#include <syslog.h>
#include <stdlib.h>
#include <string.h>
-#if defined(__NetBSD__) || defined(__OpenBSD__)
#include <search.h>
-#endif
#include "timer.h"
static struct rtadvd_timer timer_head;