relax addrs#x config parameter. should address PR 21872
This commit is contained in:
parent
33b48b0823
commit
8412a300dc
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: config.c,v 1.20 2003/05/17 18:51:13 itojun Exp $ */
|
||||
/* $NetBSD: config.c,v 1.21 2003/06/17 08:08:48 itojun Exp $ */
|
||||
/* $KAME: config.c,v 1.62 2002/05/29 10:13:10 itojun Exp $ */
|
||||
|
||||
/*
|
||||
|
@ -63,8 +63,7 @@
|
|||
#include "if.h"
|
||||
#include "config.h"
|
||||
|
||||
static void makeentry __P((char *, size_t, int, char *, int));
|
||||
static void get_prefix __P((struct rainfo *));
|
||||
static void makeentry __P((char *, size_t, int, char *));
|
||||
static int getinet6sysctl __P((int));
|
||||
|
||||
extern struct rainfo *ralist;
|
||||
|
@ -73,7 +72,7 @@ void
|
|||
getconfig(intface)
|
||||
char *intface;
|
||||
{
|
||||
int stat, pfxs, i;
|
||||
int stat, i;
|
||||
char tbuf[BUFSIZ];
|
||||
struct rainfo *tmp;
|
||||
long val;
|
||||
|
@ -240,132 +239,114 @@ getconfig(intface)
|
|||
/* prefix information */
|
||||
|
||||
/*
|
||||
* This is an implementation specific parameter to consinder
|
||||
* This is an implementation specific parameter to consider
|
||||
* link propagation delays and poorly synchronized clocks when
|
||||
* checking consistency of advertised lifetimes.
|
||||
*/
|
||||
MAYHAVE(val, "clockskew", 0);
|
||||
tmp->clockskew = val;
|
||||
|
||||
if ((pfxs = agetnum("addrs")) <= 0) {
|
||||
/* auto configure prefix information */
|
||||
if (agetstr("addr", &bp) || agetstr("addr1", &bp)) {
|
||||
tmp->pfxs = 0;
|
||||
for (i = -1; i < MAXPREFIX; i++) {
|
||||
struct prefix *pfx;
|
||||
char entbuf[256];
|
||||
|
||||
makeentry(entbuf, sizeof(entbuf), i, "addr");
|
||||
addr = (char *)agetstr(entbuf, &bp);
|
||||
if (addr == NULL)
|
||||
continue;
|
||||
|
||||
/* allocate memory to store prefix information */
|
||||
if ((pfx = malloc(sizeof(struct prefix))) == NULL) {
|
||||
syslog(LOG_ERR,
|
||||
"<%s> conflicting prefix configuration for %s: "
|
||||
"automatic and manual config at the same time",
|
||||
__func__, intface);
|
||||
"<%s> can't allocate enough memory",
|
||||
__func__);
|
||||
exit(1);
|
||||
}
|
||||
get_prefix(tmp);
|
||||
} else {
|
||||
tmp->pfxs = pfxs;
|
||||
for (i = 0; i < pfxs; i++) {
|
||||
struct prefix *pfx;
|
||||
char entbuf[256];
|
||||
int added = (pfxs > 1) ? 1 : 0;
|
||||
memset(pfx, 0, sizeof(*pfx));
|
||||
|
||||
/* allocate memory to store prefix information */
|
||||
if ((pfx = malloc(sizeof(struct prefix))) == NULL) {
|
||||
syslog(LOG_ERR,
|
||||
"<%s> can't allocate enough memory",
|
||||
__func__);
|
||||
exit(1);
|
||||
}
|
||||
memset(pfx, 0, sizeof(*pfx));
|
||||
/* link into chain */
|
||||
insque(pfx, &tmp->prefix);
|
||||
tmp->pfxs++;
|
||||
|
||||
/* link into chain */
|
||||
insque(pfx, &tmp->prefix);
|
||||
pfx->origin = PREFIX_FROM_CONFIG;
|
||||
|
||||
pfx->origin = PREFIX_FROM_CONFIG;
|
||||
if (inet_pton(AF_INET6, addr, &pfx->prefix) != 1) {
|
||||
syslog(LOG_ERR,
|
||||
"<%s> inet_pton failed for %s",
|
||||
__func__, addr);
|
||||
exit(1);
|
||||
}
|
||||
if (IN6_IS_ADDR_MULTICAST(&pfx->prefix)) {
|
||||
syslog(LOG_ERR,
|
||||
"<%s> multicast prefix (%s) must "
|
||||
"not be advertised on %s",
|
||||
__func__, addr, intface);
|
||||
exit(1);
|
||||
}
|
||||
if (IN6_IS_ADDR_LINKLOCAL(&pfx->prefix))
|
||||
syslog(LOG_NOTICE,
|
||||
"<%s> link-local prefix (%s) will be"
|
||||
" advertised on %s",
|
||||
__func__, addr, intface);
|
||||
|
||||
makeentry(entbuf, sizeof(entbuf), i, "prefixlen");
|
||||
MAYHAVE(val, entbuf, 64);
|
||||
if (val < 0 || val > 128) {
|
||||
syslog(LOG_ERR, "<%s> prefixlen (%ld) for %s "
|
||||
"on %s out of range",
|
||||
__func__, val, addr, intface);
|
||||
exit(1);
|
||||
}
|
||||
pfx->prefixlen = (int)val;
|
||||
|
||||
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",
|
||||
__func__, entbuf, intface);
|
||||
exit(1);
|
||||
}
|
||||
if (inet_pton(AF_INET6, addr,
|
||||
&pfx->prefix) != 1) {
|
||||
syslog(LOG_ERR,
|
||||
"<%s> inet_pton failed for %s",
|
||||
__func__, addr);
|
||||
exit(1);
|
||||
}
|
||||
if (IN6_IS_ADDR_MULTICAST(&pfx->prefix)) {
|
||||
syslog(LOG_ERR,
|
||||
"<%s> multicast prefix (%s) must "
|
||||
"not be advertised on %s",
|
||||
__func__, addr, intface);
|
||||
exit(1);
|
||||
}
|
||||
if (IN6_IS_ADDR_LINKLOCAL(&pfx->prefix))
|
||||
syslog(LOG_NOTICE,
|
||||
"<%s> link-local prefix (%s) will be"
|
||||
" advertised on %s",
|
||||
__func__, addr, intface);
|
||||
makeentry(entbuf, sizeof(entbuf), i, "pinfoflags");
|
||||
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;
|
||||
|
||||
makeentry(entbuf, sizeof(entbuf), i, "prefixlen",
|
||||
added);
|
||||
MAYHAVE(val, entbuf, 64);
|
||||
if (val < 0 || val > 128) {
|
||||
syslog(LOG_ERR, "<%s> prefixlen (%ld) for %s "
|
||||
"on %s out of range",
|
||||
__func__, val, addr, intface);
|
||||
exit(1);
|
||||
}
|
||||
pfx->prefixlen = (int)val;
|
||||
makeentry(entbuf, sizeof(entbuf), i, "vltime");
|
||||
MAYHAVE(val64, entbuf, DEF_ADVVALIDLIFETIME);
|
||||
if (val64 < 0 || val64 > 0xffffffff) {
|
||||
syslog(LOG_ERR, "<%s> vltime (%lld) for "
|
||||
"%s/%d on %s is out of range",
|
||||
__func__, (long long)val64,
|
||||
addr, pfx->prefixlen, intface);
|
||||
exit(1);
|
||||
}
|
||||
pfx->validlifetime = (u_int32_t)val64;
|
||||
|
||||
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;
|
||||
makeentry(entbuf, sizeof(entbuf), i, "vltimedecr");
|
||||
if (agetflag(entbuf)) {
|
||||
struct timeval now;
|
||||
gettimeofday(&now, 0);
|
||||
pfx->vltimeexpire =
|
||||
now.tv_sec + pfx->validlifetime;
|
||||
}
|
||||
|
||||
makeentry(entbuf, sizeof(entbuf), i, "vltime", added);
|
||||
MAYHAVE(val64, entbuf, DEF_ADVVALIDLIFETIME);
|
||||
if (val64 < 0 || val64 > 0xffffffff) {
|
||||
syslog(LOG_ERR, "<%s> vltime (%lld) for "
|
||||
"%s/%d on %s is out of range",
|
||||
__func__, (long long)val64,
|
||||
addr, pfx->prefixlen, intface);
|
||||
exit(1);
|
||||
}
|
||||
pfx->validlifetime = (u_int32_t)val64;
|
||||
makeentry(entbuf, sizeof(entbuf), i, "pltime");
|
||||
MAYHAVE(val64, entbuf, DEF_ADVPREFERREDLIFETIME);
|
||||
if (val64 < 0 || val64 > 0xffffffff) {
|
||||
syslog(LOG_ERR,
|
||||
"<%s> pltime (%lld) for %s/%d on %s "
|
||||
"is out of range",
|
||||
__func__, (long long)val64,
|
||||
addr, pfx->prefixlen, intface);
|
||||
exit(1);
|
||||
}
|
||||
pfx->preflifetime = (u_int32_t)val64;
|
||||
|
||||
makeentry(entbuf, sizeof(entbuf), i, "vltimedecr", added);
|
||||
if (agetflag(entbuf)) {
|
||||
struct timeval now;
|
||||
gettimeofday(&now, 0);
|
||||
pfx->vltimeexpire =
|
||||
now.tv_sec + pfx->validlifetime;
|
||||
}
|
||||
|
||||
makeentry(entbuf, sizeof(entbuf), i, "pltime", added);
|
||||
MAYHAVE(val64, entbuf, DEF_ADVPREFERREDLIFETIME);
|
||||
if (val64 < 0 || val64 > 0xffffffff) {
|
||||
syslog(LOG_ERR,
|
||||
"<%s> pltime (%lld) for %s/%d on %s "
|
||||
"is out of range",
|
||||
__func__, (long long)val64,
|
||||
addr, pfx->prefixlen, intface);
|
||||
exit(1);
|
||||
}
|
||||
pfx->preflifetime = (u_int32_t)val64;
|
||||
|
||||
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, sizeof(entbuf), i, "pltimedecr");
|
||||
if (agetflag(entbuf)) {
|
||||
struct timeval now;
|
||||
gettimeofday(&now, 0);
|
||||
pfx->pltimeexpire =
|
||||
now.tv_sec + pfx->preflifetime;
|
||||
}
|
||||
}
|
||||
if (tmp->pfxs == 0)
|
||||
get_prefix(tmp);
|
||||
|
||||
MAYHAVE(val, "mtu", 0);
|
||||
if (val < 0 || val > 0xffffffff) {
|
||||
|
@ -410,7 +391,7 @@ getconfig(intface)
|
|||
rtadvd_set_timer(&tmp->timer->tm, tmp->timer);
|
||||
}
|
||||
|
||||
static void
|
||||
void
|
||||
get_prefix(struct rainfo *rai)
|
||||
{
|
||||
struct ifaddrs *ifap, *ifa;
|
||||
|
@ -425,6 +406,7 @@ get_prefix(struct rainfo *rai)
|
|||
__func__);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
|
||||
int plen;
|
||||
|
||||
|
@ -464,6 +446,7 @@ get_prefix(struct rainfo *rai)
|
|||
/* set prefix, sweep bits outside of prefixlen */
|
||||
pp->prefixlen = plen;
|
||||
memcpy(&pp->prefix, a, sizeof(*a));
|
||||
if (1)
|
||||
{
|
||||
p = (u_char *)&pp->prefix;
|
||||
ep = (u_char *)(&pp->prefix + 1);
|
||||
|
@ -499,22 +482,17 @@ get_prefix(struct rainfo *rai)
|
|||
}
|
||||
|
||||
static void
|
||||
makeentry(buf, len, id, string, add)
|
||||
makeentry(buf, len, id, string)
|
||||
char *buf;
|
||||
size_t len;
|
||||
int id;
|
||||
char *string;
|
||||
int add;
|
||||
{
|
||||
char *ep = buf + len;
|
||||
|
||||
strlcpy(buf, string, len);
|
||||
if (add) {
|
||||
char *cp;
|
||||
|
||||
cp = (char *)strchr(buf, '\0');
|
||||
snprintf(cp, ep - cp, "%d", id);
|
||||
}
|
||||
if (id < 0)
|
||||
strlcpy(buf, string, len);
|
||||
else
|
||||
snprintf(buf, len, "%s%d", string, id);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: config.h,v 1.4 2000/05/23 11:37:58 itojun Exp $ */
|
||||
/* $NetBSD: config.h,v 1.5 2003/06/17 08:08:48 itojun Exp $ */
|
||||
/* $KAME: config.h,v 1.3 2000/05/16 13:34:13 itojun Exp $ */
|
||||
|
||||
/*
|
||||
|
@ -34,3 +34,11 @@ extern void getconfig __P((char *));
|
|||
extern void delete_prefix __P((struct rainfo *, struct prefix *));
|
||||
extern void make_prefix __P((struct rainfo *, int, struct in6_addr *, int));
|
||||
extern void make_packet __P((struct rainfo *));
|
||||
extern void get_prefix __P((struct rainfo *));
|
||||
|
||||
|
||||
/*
|
||||
* it is highly unlikely to have 100 prefix information options,
|
||||
* so it should be okay to limit it
|
||||
*/
|
||||
#define MAXPREFIX 100
|
||||
|
|
Loading…
Reference in New Issue