diff options
author | Jun-ichiro itojun Hagino <itojun@cvs.openbsd.org> | 2003-06-18 02:26:59 +0000 |
---|---|---|
committer | Jun-ichiro itojun Hagino <itojun@cvs.openbsd.org> | 2003-06-18 02:26:59 +0000 |
commit | 36d76bf27c1d9f525b8533a3e5f90ed8e8bd5cc6 (patch) | |
tree | bcfe1a72a1b38cbbfb400743bf78bc5b98b56db9 /usr.sbin | |
parent | f85fb260b49d430b401ed3fc400c61760f860c86 (diff) |
relax config syntax; addrs#x is not needed any more. millert ok
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/rtadvd/config.c | 238 | ||||
-rw-r--r-- | usr.sbin/rtadvd/config.h | 10 | ||||
-rw-r--r-- | usr.sbin/rtadvd/rtadvd.conf.5 | 35 |
3 files changed, 127 insertions, 156 deletions
diff --git a/usr.sbin/rtadvd/config.c b/usr.sbin/rtadvd/config.c index fd3e0ab291e..5ad9b5457c8 100644 --- a/usr.sbin/rtadvd/config.c +++ b/usr.sbin/rtadvd/config.c @@ -1,4 +1,4 @@ -/* $OpenBSD: config.c,v 1.21 2002/07/10 21:14:40 itojun Exp $ */ +/* $OpenBSD: config.c,v 1.22 2003/06/18 02:26:58 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(char *, size_t, int, char *, int); -static void get_prefix(struct rainfo *); +static void makeentry(char *, size_t, int, char *); static int getinet6sysctl(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; - - /* 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); - - pfx->origin = PREFIX_FROM_CONFIG; - - - 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, "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, "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, "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, "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; - } + memset(pfx, 0, sizeof(*pfx)); + + /* link into chain */ + insque(pfx, &tmp->prefix); + tmp->pfxs++; + + 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, "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, "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, "vltimedecr"); + if (agetflag(entbuf)) { + struct timeval now; + gettimeofday(&now, 0); + pfx->vltimeexpire = + now.tv_sec + pfx->validlifetime; + } + + 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, "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); } /* diff --git a/usr.sbin/rtadvd/config.h b/usr.sbin/rtadvd/config.h index eb3efbe2b6a..fa63c115cfe 100644 --- a/usr.sbin/rtadvd/config.h +++ b/usr.sbin/rtadvd/config.h @@ -1,4 +1,4 @@ -/* $OpenBSD: config.h,v 1.5 2002/02/16 21:28:08 millert Exp $ */ +/* $OpenBSD: config.h,v 1.6 2003/06/18 02:26:58 itojun Exp $ */ /* $KAME: config.h,v 1.3 2000/05/16 13:34:13 itojun Exp $ */ /* @@ -34,3 +34,11 @@ extern void getconfig(char *); extern void delete_prefix(struct rainfo *, struct prefix *); extern void make_prefix(struct rainfo *, int, struct in6_addr *, int); extern void make_packet(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 diff --git a/usr.sbin/rtadvd/rtadvd.conf.5 b/usr.sbin/rtadvd/rtadvd.conf.5 index 0fff184f7dc..c8195560b24 100644 --- a/usr.sbin/rtadvd/rtadvd.conf.5 +++ b/usr.sbin/rtadvd/rtadvd.conf.5 @@ -1,5 +1,5 @@ -.\" $OpenBSD: rtadvd.conf.5,v 1.17 2003/06/12 12:59:53 jmc Exp $ -.\" $KAME: rtadvd.conf.5,v 1.32 2001/01/19 05:32:05 jinmei Exp $ +.\" $OpenBSD: rtadvd.conf.5,v 1.18 2003/06/18 02:26:58 itojun Exp $ +.\" $KAME: rtadvd.conf.5,v 1.46 2003/06/17 08:26:35 itojun Exp $ .\" .\" Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. .\" All rights reserved. @@ -143,6 +143,11 @@ These items can be omitted, then .Nm rtadvd will automatically get appropriate prefixes from the kernel's routing table, and advertise the prefixes with the default parameters. +Keywords other than +.Cm clockskew +can be augmented with number, like +.Dq Li prefix2 , +to specify multiple prefixes. .Bl -tag -width indent .It Cm \&clockskew (num) Time skew to adjust link propagation delays and clock skews @@ -155,22 +160,6 @@ real time. If the value is 0, it means the consistency check will be skipped for such prefixes. The default value is 0. -.It Cm \&addrs -(num) Number of prefixes. -Its default is 0, so it must explicitly be set to positive values -if you want to specify any prefix information option. -If its value is 0, -.Xr rtadvd 8 -looks up the system routing table and -advertise the prefixes corresponding to interface routes -on the interface. -If its value is more than 1, you must specify the index of the prefix -for each item below. -Indices vary from 0 to N-1, where N is the -value of -.Cm addrs . -Each index shall follow the name of each item, e.g., -.Dq prefixlen2 . .It Cm \&prefixlen (num) Prefix length field. The default value is 64. @@ -195,10 +184,6 @@ is used for .Xr termcap 5 file format as well as IPv6 numeric address, the field MUST be quoted by doublequote character. -This field cannot be -omitted if the value of -.Cm addrs -is more than 0. .It Cm \&vltime (num) Valid lifetime field .Pq unit: seconds . @@ -286,7 +271,7 @@ option to .Xr rtadvd 8 . .Bd -literal -offset ef0:\\ - :addrs#1:addr="3ffe:501:ffff:1000::":prefixlen#64: + :addr="3ffe:501:ffff:1000::":prefixlen#64: .Ed .Pp The following example presents the default values in an explicit manner. @@ -295,9 +280,9 @@ YOU DO NOT NEED TO HAVE IT AT ALL. .Bd -literal -offset default:\\ :chlim#64:raflags#0:rltime#1800:rtime#0:retrans#0:\\ - :pinfoflags#192:vltime#2592000:pltime#604800:mtu#0: + :pinfoflags="la":vltime#2592000:pltime#604800:mtu#0: ef0:\\ - :addrs#1:addr="3ffe:501:ffff:1000::":prefixlen#64:tc=default: + :addr="3ffe:501:ffff:1000::":prefixlen#64:tc=default: .Ed .Sh SEE ALSO .Xr termcap 5 , |