Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.sbin/rtadvd Remove the iflist array and store ifflags in...
details: https://anonhg.NetBSD.org/src/rev/b6f0ce35a2ae
branches: trunk
changeset: 783285:b6f0ce35a2ae
user: roy <roy%NetBSD.org@localhost>
date: Thu Dec 13 15:36:35 2012 +0000
description:
Remove the iflist array and store ifflags in rainfo.
Add support for SIGHUP to re-read the configuration for each interface.
If an invalid configuration is found, we continue to use the old one;
otherwise we expire the current one and then start advertising the new one.
Specififed interfaces don't have to exist at startup.
If specified interfaces arrive, load their config and start advertising.
If they depart, remove their rainfo structure and continue.
Fixes PR/43881 and PR/47311
diffstat:
usr.sbin/rtadvd/advcap.c | 6 +-
usr.sbin/rtadvd/config.c | 221 ++++++++++++++++++++++++++++---------
usr.sbin/rtadvd/config.h | 5 +-
usr.sbin/rtadvd/dump.c | 8 +-
usr.sbin/rtadvd/if.c | 206 +++++++---------------------------
usr.sbin/rtadvd/if.h | 13 +-
usr.sbin/rtadvd/rrenum.c | 36 +++--
usr.sbin/rtadvd/rtadvd.8 | 20 ++-
usr.sbin/rtadvd/rtadvd.c | 277 +++++++++++++++++++++++++++++++++-------------
usr.sbin/rtadvd/rtadvd.h | 7 +-
usr.sbin/rtadvd/timer.c | 14 +-
11 files changed, 476 insertions(+), 337 deletions(-)
diffs (truncated from 1792 to 300 lines):
diff -r fd191962caf6 -r b6f0ce35a2ae usr.sbin/rtadvd/advcap.c
--- a/usr.sbin/rtadvd/advcap.c Thu Dec 13 15:35:09 2012 +0000
+++ b/usr.sbin/rtadvd/advcap.c Thu Dec 13 15:36:35 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: advcap.c,v 1.13 2011/12/10 19:14:29 roy Exp $ */
+/* $NetBSD: advcap.c,v 1.14 2012/12/13 15:36:35 roy Exp $ */
/* $KAME: advcap.c,v 1.11 2003/05/19 09:46:50 keiichi Exp $ */
/*
@@ -47,6 +47,10 @@
#include <string.h>
#include "pathnames.h"
+#ifndef __UNCONST
+#define __UNCONST(a) ((void *)(unsigned long)(const void *)(a))
+#endif
+
#ifndef BUFSIZ
#define BUFSIZ 1024
#endif
diff -r fd191962caf6 -r b6f0ce35a2ae usr.sbin/rtadvd/config.c
--- a/usr.sbin/rtadvd/config.c Thu Dec 13 15:35:09 2012 +0000
+++ b/usr.sbin/rtadvd/config.c Thu Dec 13 15:36:35 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: config.c,v 1.29 2012/12/11 16:37:23 roy Exp $ */
+/* $NetBSD: config.c,v 1.30 2012/12/13 15:36:36 roy Exp $ */
/* $KAME: config.c,v 1.93 2005/10/17 14:40:02 suz Exp $ */
/*
@@ -39,6 +39,9 @@
#include <net/if.h>
#include <net/route.h>
#include <net/if_dl.h>
+#ifdef __FreeBSD__
+#include <net/if_var.h>
+#endif
#include <netinet/in.h>
#include <netinet/in_var.h>
@@ -57,6 +60,7 @@
#include <search.h>
#include <unistd.h>
#include <ifaddrs.h>
+#include <inttypes.h>
#include "rtadvd.h"
#include "advcap.h"
@@ -64,6 +68,10 @@
#include "if.h"
#include "config.h"
+#ifndef __arraycount
+#define __arraycount(__x) (sizeof(__x) / sizeof(__x[0]))
+#endif
+
static time_t prefix_timo = (60 * 120); /* 2 hours.
* XXX: should be configurable. */
static struct rtadvd_timer *prefix_timeout(void *);
@@ -92,11 +100,56 @@
}
void
-getconfig(const char *intface)
+free_rainfo(struct rainfo *rai)
+{
+ struct prefix *pfx;
+ struct rtinfo *rti;
+ struct rdnss *rdnss;
+ struct rdnss_addr *rdnsa;
+ struct dnssl *dnssl;
+ struct dnssl_domain *dnsd;
+
+ rtadvd_remove_timer(&rai->timer);
+
+ while ((pfx = TAILQ_FIRST(&rai->prefix))) {
+ TAILQ_REMOVE(&rai->prefix, pfx, next);
+ free(pfx);
+ }
+
+ while ((rti = TAILQ_FIRST(&rai->route))) {
+ TAILQ_REMOVE(&rai->route, rti, next);
+ free(rti);
+ }
+
+ while ((rdnss = TAILQ_FIRST(&rai->rdnss))) {
+ TAILQ_REMOVE(&rai->rdnss, rdnss, next);
+ while ((rdnsa = TAILQ_FIRST(&rdnss->list))) {
+ TAILQ_REMOVE(&rdnss->list, rdnsa, next);
+ free(rdnsa);
+ }
+ free(rdnss);
+ }
+
+ while ((dnssl = TAILQ_FIRST(&rai->dnssl))) {
+ TAILQ_REMOVE(&rai->dnssl, dnssl, next);
+ while ((dnsd = TAILQ_FIRST(&dnssl->list))) {
+ TAILQ_REMOVE(&dnssl->list, dnsd, next);
+ free(dnsd);
+ }
+ free(dnssl);
+ }
+
+ free(rai->sdl);
+ free(rai->ra_data);
+ free(rai);
+}
+
+void
+getconfig(const char *intface, int exithard)
{
int stat, c, i;
char tbuf[BUFSIZ];
- struct rainfo *tmp;
+ struct rainfo *tmp, *rai;
int32_t val;
int64_t val64;
char buf[BUFSIZ];
@@ -104,6 +157,8 @@
char *addr, *flagstr, *ap;
static int forwarding = -1;
char entbuf[256], abuf[256];
+ struct rdnss *rdnss;
+ struct dnssl *dnssl;
#define MUSTHAVE(var, cap) \
do { \
@@ -111,7 +166,7 @@
if ((t = agetnum(cap)) < 0) { \
fprintf(stderr, "rtadvd: need %s for interface %s\n", \
cap, intface); \
- exit(1); \
+ goto errexit; \
} \
var = t; \
} while (0)
@@ -120,16 +175,24 @@
if ((var = agetnum(cap)) < 0) \
var = def; \
} while (0)
-#define ELM_MALLOC(p,error_action) \
+#define ELM_MALLOC(p) \
do { \
p = calloc(1, sizeof(*p)); \
if (p == NULL) { \
syslog(LOG_ERR, "<%s> calloc failed: %m", \
__func__); \
- error_action; \
+ goto errexit; \
} \
} while(/*CONSTCOND*/0)
+ if (if_nametoindex(intface) == 0) {
+ syslog(LOG_INFO, "<%s> interface %s not found, ignoring",
+ __func__, intface);
+ return;
+ }
+
+ syslog(LOG_DEBUG, "<%s> loading configuration for interface %s",
+ __func__, intface);
if ((stat = agetent(tbuf, intface)) <= 0) {
memset(tbuf, 0, sizeof(tbuf));
@@ -140,7 +203,11 @@
__func__, intface);
}
- ELM_MALLOC(tmp, exit(1));
+ ELM_MALLOC(tmp);
+ TAILQ_INIT(&tmp->prefix);
+ TAILQ_INIT(&tmp->route);
+ TAILQ_INIT(&tmp->rdnss);
+ TAILQ_INIT(&tmp->dnssl);
/* check if we are allowed to forward packets (if not determined) */
if (forwarding < 0) {
@@ -158,11 +225,19 @@
syslog(LOG_ERR,
"<%s> can't get information of %s",
__func__, intface);
- exit(1);
+ goto errexit;
}
tmp->ifindex = tmp->sdl->sdl_index;
- } else
+ } else {
tmp->ifindex = if_nametoindex(intface);
+ if (tmp->ifindex == 0) {
+ syslog(LOG_ERR,
+ "<%s> can't get information of %s",
+ __func__, intface);
+ goto errexit;
+ }
+ }
+ tmp->ifflags = if_getflags(tmp->ifindex, 0);
strlcpy(tmp->ifname, intface, sizeof(tmp->ifname));
if ((tmp->phymtu = if_getmtu(intface)) == 0) {
tmp->phymtu = IPV6_MMTU;
@@ -180,7 +255,7 @@
"<%s> maxinterval (%d) on %s is invalid "
"(must be between %u and %u)", __func__, val,
intface, MIN_MAXINTERVAL, MAX_MAXINTERVAL);
- exit(1);
+ goto errexit;
}
tmp->maxinterval = val;
MAYHAVE(val, "mininterval", tmp->maxinterval/3);
@@ -190,7 +265,7 @@
"(must be between %u and %d)",
__func__, val, intface, MIN_MININTERVAL,
(tmp->maxinterval * 3) / 4);
- exit(1);
+ goto errexit;
}
tmp->mininterval = val;
@@ -209,7 +284,7 @@
if ((val & ND_RA_FLAG_RTPREF_HIGH)) {
syslog(LOG_ERR, "<%s> the \'h\' and \'l\'"
" router flags are exclusive", __func__);
- exit(1);
+ goto errexit;
}
val |= ND_RA_FLAG_RTPREF_LOW;
}
@@ -226,7 +301,7 @@
if (tmp->rtpref == ND_RA_FLAG_RTPREF_RSV) {
syslog(LOG_ERR, "<%s> invalid router preference (%02x) on %s",
__func__, tmp->rtpref, intface);
- exit(1);
+ goto errexit;
}
MAYHAVE(val, "rltime", tmp->maxinterval * 3);
@@ -236,7 +311,7 @@
"(must be 0 or between %d and %d)",
__func__, val, intface,
tmp->maxinterval, MAXROUTERLIFETIME);
- exit(1);
+ goto errexit;
}
/*
* Basically, hosts MUST NOT send Router Advertisement messages at any
@@ -252,7 +327,7 @@
"which must not be allowed for hosts. you must "
"change router lifetime or enable IPv6 forwarding.",
__func__, intface);
- exit(1);
+ goto errexit;
}
tmp->lifetime = val & 0xffff;
@@ -262,7 +337,7 @@
"<%s> reachable time (%d) on %s is invalid "
"(must be no greater than %d)",
__func__, val, intface, MAXREACHABLETIME);
- exit(1);
+ goto errexit;
}
tmp->reachabletime = (uint32_t)val;
@@ -270,7 +345,7 @@
if (val64 < 0 || val64 > 0xffffffff) {
syslog(LOG_ERR, "<%s> retrans time (%lld) on %s out of range",
__func__, (long long)val64, intface);
- exit(1);
+ goto errexit;
}
tmp->retranstimer = (uint32_t)val64;
@@ -278,7 +353,7 @@
syslog(LOG_ERR,
"<%s> mobile-ip6 configuration not supported",
__func__);
- exit(1);
+ goto errexit;
}
/* prefix information */
@@ -291,7 +366,6 @@
tmp->clockskew = val;
tmp->pfxs = 0;
- TAILQ_INIT(&tmp->prefix);
for (i = -1; i < MAXPREFIX; i++) {
struct prefix *pfx;
@@ -305,7 +379,7 @@
syslog(LOG_ERR,
"<%s> can't allocate memory: %m",
__func__);
- exit(1);
+ goto errexit;
}
TAILQ_INSERT_TAIL(&tmp->prefix, pfx, next);
@@ -318,14 +392,14 @@
syslog(LOG_ERR,
"<%s> inet_pton failed for %s",
__func__, addr);
- exit(1);
Home |
Main Index |
Thread Index |
Old Index