diff options
Diffstat (limited to 'usr.sbin/rtadvd/config.c')
-rw-r--r-- | usr.sbin/rtadvd/config.c | 367 |
1 files changed, 241 insertions, 126 deletions
diff --git a/usr.sbin/rtadvd/config.c b/usr.sbin/rtadvd/config.c index a667819..681611f 100644 --- a/usr.sbin/rtadvd/config.c +++ b/usr.sbin/rtadvd/config.c @@ -53,6 +53,7 @@ #include <stdio.h> #include <syslog.h> #include <errno.h> +#include <inttypes.h> #include <netdb.h> #include <string.h> #include <search.h> @@ -148,7 +149,6 @@ int loadconfig_ifname(char *ifname) { struct ifinfo *ifi; - int error; syslog(LOG_DEBUG, "<%s> enter", __func__); @@ -174,37 +174,21 @@ loadconfig_ifname(char *ifname) ifi->ifi_ifname); continue; } - if (getconfig(ifi->ifi_ifindex) == NULL) { + if (getconfig(ifi) == NULL) { syslog(LOG_ERR, "<%s> invalid configuration for %s. " "Ignored at this moment.", __func__, ifi->ifi_ifname); continue; } - ifi->ifi_state = IFI_STATE_CONFIGURED; - syslog(LOG_DEBUG, - "<%s> ifname=%s marked as configured.", - __func__, ifi->ifi_ifname); - - error = sock_mc_join(&sock, ifi->ifi_ifindex); - if (error) - exit(1); } return (0); } int -rmconfig(int idx) +rm_ifinfo_index(int idx) { - struct rainfo *rai; - struct prefix *pfx; - struct soliciter *sol; - struct rdnss *rdn; - struct rdnss_addr *rdna; - struct dnssl *dns; - struct rtinfo *rti; struct ifinfo *ifi; - int error; ifi = if_indextoifinfo(idx); if (ifi == NULL) { @@ -212,24 +196,39 @@ rmconfig(int idx) __func__, idx); return (-1); } - rai = ifi->ifi_rainfo; - if (ifi->ifi_state == IFI_STATE_CONFIGURED) { + return (rm_ifinfo(ifi)); +} + +int +rm_ifinfo(struct ifinfo *ifi) +{ + int error; + + syslog(LOG_DEBUG, "<%s> enter (%s).", __func__, ifi->ifi_ifname); + switch (ifi->ifi_state) { + case IFI_STATE_UNCONFIGURED: + return (0); + break; + default: ifi->ifi_state = IFI_STATE_UNCONFIGURED; syslog(LOG_DEBUG, - "<%s> ifname=%s marked as unconfigured.", + "<%s> ifname=%s marked as UNCONFIGURED.", __func__, ifi->ifi_ifname); - error = sock_mc_leave(&sock, ifi->ifi_ifindex); - if (error) - exit(1); + /* XXX: No MC leaving here becasue index is disappeared */ + + /* Inactivate timer */ + rtadvd_remove_timer(ifi->ifi_ra_timer); + ifi->ifi_ra_timer = NULL; + break; } /* clean up ifi */ if (!ifi->ifi_persist) { TAILQ_REMOVE(&ifilist, ifi, ifi_next); syslog(LOG_DEBUG, "<%s>: ifinfo (idx=%d) removed.", - __func__, idx); + __func__, ifi->ifi_ifindex); free(ifi); } else { /* recreate an empty entry */ @@ -237,16 +236,62 @@ rmconfig(int idx) syslog(LOG_DEBUG, "<%s>: ifname=%s is persistent.", __func__, ifi->ifi_ifname); } + /* clean up rai if any */ - if (rai == NULL) - return (0); + switch (ifi->ifi_state) { + case IFI_STATE_CONFIGURED: + if (ifi->ifi_rainfo != NULL) { + error = rm_rainfo(ifi->ifi_rainfo); + if (error) + return (error); + ifi->ifi_rainfo = NULL; + } + break; + case IFI_STATE_TRANSITIVE: + if (ifi->ifi_rainfo == ifi->ifi_rainfo_trans) { + if (ifi->ifi_rainfo != NULL) { + error = rm_rainfo(ifi->ifi_rainfo); + if (error) + return (error); + ifi->ifi_rainfo = NULL; + ifi->ifi_rainfo_trans = NULL; + } + } else { + if (ifi->ifi_rainfo != NULL) { + error = rm_rainfo(ifi->ifi_rainfo); + if (error) + return (error); + ifi->ifi_rainfo = NULL; + } + if (ifi->ifi_rainfo_trans != NULL) { + error = rm_rainfo(ifi->ifi_rainfo_trans); + if (error) + return (error); + ifi->ifi_rainfo_trans = NULL; + } + } + } - TAILQ_REMOVE(&railist, rai, rai_next); - syslog(LOG_DEBUG, "<%s>: rainfo (idx=%d) removed.", - __func__, idx); + syslog(LOG_DEBUG, "<%s> leave (%s).", __func__, ifi->ifi_ifname); + return (0); +} + +int +rm_rainfo(struct rainfo *rai) +{ + struct prefix *pfx; + struct soliciter *sol; + struct rdnss *rdn; + struct rdnss_addr *rdna; + struct dnssl *dns; + struct rtinfo *rti; - /* Free all of allocated memories for this entry. */ - rtadvd_remove_timer(rai->rai_timer); + syslog(LOG_DEBUG, "<%s>: enter", __func__); + + TAILQ_REMOVE(&railist, rai, rai_next); + if (rai->rai_ifinfo != NULL) + syslog(LOG_DEBUG, "<%s>: rainfo (idx=%d) removed.", + __func__, rai->rai_ifinfo->ifi_ifindex); if (rai->rai_ra_data != NULL) free(rai->rai_ra_data); @@ -276,34 +321,34 @@ rmconfig(int idx) free(rti); } free(rai); + syslog(LOG_DEBUG, "<%s>: leave", __func__); return (0); } struct ifinfo * -getconfig(int idx) +getconfig(struct ifinfo *ifi) { int stat, i; + int error; char tbuf[BUFSIZ]; struct rainfo *rai; struct rainfo *rai_old; - struct ifinfo *ifi; - long val; + int32_t val; int64_t val64; char buf[BUFSIZ]; char *bp = buf; char *addr, *flagstr; - if (idx == 0) - return (NULL); - TAILQ_FOREACH(ifi, &ifilist, ifi_next) { - if (ifi->ifi_ifindex == idx) - break; - } if (ifi == NULL) /* if does not exist */ return (NULL); - rai_old = ifi->ifi_rainfo; + if (ifi->ifi_state == IFI_STATE_TRANSITIVE && + ifi->ifi_rainfo == NULL) { + syslog(LOG_INFO, "<%s> %s is shutting down. Skipped.", + __func__, ifi->ifi_ifname); + return (NULL); + } if ((stat = agetent(tbuf, ifi->ifi_ifname)) <= 0) { memset(tbuf, 0, sizeof(tbuf)); @@ -316,9 +361,7 @@ getconfig(int idx) ELM_MALLOC(rai, exit(1)); TAILQ_INIT(&rai->rai_prefix); -#ifdef ROUTEINFO TAILQ_INIT(&rai->rai_route); -#endif TAILQ_INIT(&rai->rai_rdnss); TAILQ_INIT(&rai->rai_dnssl); TAILQ_INIT(&rai->rai_soliciter); @@ -350,24 +393,24 @@ getconfig(int idx) MAYHAVE(val, "maxinterval", DEF_MAXRTRADVINTERVAL); if (val < MIN_MAXINTERVAL || val > MAX_MAXINTERVAL) { syslog(LOG_ERR, - "<%s> maxinterval (%ld) on %s is invalid " + "<%s> maxinterval (%" PRIu32 ") on %s is invalid " "(must be between %u and %u)", __func__, val, ifi->ifi_ifname, MIN_MAXINTERVAL, MAX_MAXINTERVAL); goto getconfig_free_rai; } - rai->rai_maxinterval = (u_int)val; + rai->rai_maxinterval = (uint16_t)val; MAYHAVE(val, "mininterval", rai->rai_maxinterval/3); - if ((u_int)val < MIN_MININTERVAL || - (u_int)val > (rai->rai_maxinterval * 3) / 4) { + if ((uint16_t)val < MIN_MININTERVAL || + (uint16_t)val > (rai->rai_maxinterval * 3) / 4) { syslog(LOG_ERR, - "<%s> mininterval (%ld) on %s is invalid " + "<%s> mininterval (%" PRIu32 ") on %s is invalid " "(must be between %d and %d)", __func__, val, ifi->ifi_ifname, MIN_MININTERVAL, (rai->rai_maxinterval * 3) / 4); goto getconfig_free_rai; } - rai->rai_mininterval = (u_int)val; + rai->rai_mininterval = (uint16_t)val; MAYHAVE(val, "chlim", DEF_ADVCURHOPLIMIT); rai->rai_hoplimit = val & 0xff; @@ -405,10 +448,10 @@ getconfig(int idx) } MAYHAVE(val, "rltime", rai->rai_maxinterval * 3); - if ((u_int)val && ((u_int)val < rai->rai_maxinterval || - (u_int)val > MAXROUTERLIFETIME)) { + if ((uint16_t)val && ((uint16_t)val < rai->rai_maxinterval || + (uint16_t)val > MAXROUTERLIFETIME)) { syslog(LOG_ERR, - "<%s> router lifetime (%ld) on %s is invalid " + "<%s> router lifetime (%" PRIu32 ") on %s is invalid " "(must be 0 or between %d and %d)", __func__, val, ifi->ifi_ifname, rai->rai_maxinterval, MAXROUTERLIFETIME); @@ -419,20 +462,20 @@ getconfig(int idx) MAYHAVE(val, "rtime", DEF_ADVREACHABLETIME); if (val < 0 || val > MAXREACHABLETIME) { syslog(LOG_ERR, - "<%s> reachable time (%ld) on %s is invalid " + "<%s> reachable time (%" PRIu32 ") on %s is invalid " "(must be no greater than %d)", __func__, val, ifi->ifi_ifname, MAXREACHABLETIME); goto getconfig_free_rai; } - rai->rai_reachabletime = (u_int32_t)val; + rai->rai_reachabletime = (uint32_t)val; MAYHAVE(val64, "retrans", DEF_ADVRETRANSTIMER); if (val64 < 0 || val64 > 0xffffffff) { - syslog(LOG_ERR, "<%s> retrans time (%lld) on %s out of range", - __func__, (long long)val64, ifi->ifi_ifname); + syslog(LOG_ERR, "<%s> retrans time (%" PRIu64 ") on %s out of range", + __func__, val64, ifi->ifi_ifname); goto getconfig_free_rai; } - rai->rai_retranstimer = (u_int32_t)val64; + rai->rai_retranstimer = (uint32_t)val64; if (agetnum("hapref") != -1 || agetnum("hatime") != -1) { syslog(LOG_ERR, @@ -486,7 +529,7 @@ getconfig(int idx) makeentry(entbuf, sizeof(entbuf), i, "prefixlen"); MAYHAVE(val, entbuf, 64); if (val < 0 || val > 128) { - syslog(LOG_ERR, "<%s> prefixlen (%ld) for %s " + syslog(LOG_ERR, "<%s> prefixlen (%" PRIu32 ") for %s " "on %s out of range", __func__, val, addr, ifi->ifi_ifname); goto getconfig_free_pfx; @@ -510,13 +553,13 @@ getconfig(int idx) makeentry(entbuf, sizeof(entbuf), i, "vltime"); MAYHAVE(val64, entbuf, DEF_ADVVALIDLIFETIME); if (val64 < 0 || val64 > 0xffffffff) { - syslog(LOG_ERR, "<%s> vltime (%lld) for " + syslog(LOG_ERR, "<%s> vltime (%" PRIu64 ") for " "%s/%d on %s is out of range", - __func__, (long long)val64, + __func__, val64, addr, pfx->pfx_prefixlen, ifi->ifi_ifname); goto getconfig_free_pfx; } - pfx->pfx_validlifetime = (u_int32_t)val64; + pfx->pfx_validlifetime = (uint32_t)val64; makeentry(entbuf, sizeof(entbuf), i, "vltimedecr"); if (agetflag(entbuf)) { @@ -530,13 +573,13 @@ getconfig(int idx) MAYHAVE(val64, entbuf, DEF_ADVPREFERREDLIFETIME); if (val64 < 0 || val64 > 0xffffffff) { syslog(LOG_ERR, - "<%s> pltime (%lld) for %s/%d on %s " + "<%s> pltime (%" PRIu64 ") for %s/%d on %s " "is out of range", - __func__, (long long)val64, + __func__, val64, addr, pfx->pfx_prefixlen, ifi->ifi_ifname); goto getconfig_free_pfx; } - pfx->pfx_preflifetime = (u_int32_t)val64; + pfx->pfx_preflifetime = (uint32_t)val64; makeentry(entbuf, sizeof(entbuf), i, "pltimedecr"); if (agetflag(entbuf)) { @@ -555,14 +598,14 @@ getconfig_free_pfx: if (rai->rai_advifprefix && rai->rai_pfxs == 0) get_prefix(rai); - MAYHAVE(val, "mtu", 0); - if (val < 0 || (u_int)val > 0xffffffff) { + MAYHAVE(val64, "mtu", 0); + if (val < 0 || val64 > 0xffffffff) { syslog(LOG_ERR, - "<%s> mtu (%ld) on %s out of range", - __func__, val, ifi->ifi_ifname); + "<%s> mtu (%" PRIu64 ") on %s out of range", + __func__, val64, ifi->ifi_ifname); goto getconfig_free_rai; } - rai->rai_linkmtu = (u_int32_t)val; + rai->rai_linkmtu = (uint32_t)val64; if (rai->rai_linkmtu == 0) { char *mtustr; @@ -573,9 +616,9 @@ getconfig_free_pfx: else if (rai->rai_linkmtu < IPV6_MMTU || rai->rai_linkmtu > ifi->ifi_phymtu) { syslog(LOG_ERR, - "<%s> advertised link mtu (%lu) on %s is invalid (must " + "<%s> advertised link mtu (%" PRIu32 ") on %s is invalid (must " "be between least MTU (%d) and physical link MTU (%d)", - __func__, (unsigned long)rai->rai_linkmtu, ifi->ifi_ifname, + __func__, rai->rai_linkmtu, ifi->ifi_ifname, IPV6_MMTU, ifi->ifi_phymtu); goto getconfig_free_rai; } @@ -609,7 +652,6 @@ getconfig_free_pfx: #endif /* route information */ -#ifdef ROUTEINFO rai->rai_routes = 0; for (i = -1; i < MAXROUTE; i++) { struct rtinfo *rti; @@ -671,7 +713,7 @@ getconfig_free_pfx: val = 64; } if (val < 0 || val > 128) { - syslog(LOG_ERR, "<%s> prefixlen (%ld) for %s on %s " + syslog(LOG_ERR, "<%s> prefixlen (%" PRIu32 ") for %s on %s " "out of range", __func__, val, addr, ifi->ifi_ifname); goto getconfig_free_rti; @@ -735,13 +777,13 @@ getconfig_free_pfx: } } if (val64 < 0 || val64 > 0xffffffff) { - syslog(LOG_ERR, "<%s> route lifetime (%lld) for " + syslog(LOG_ERR, "<%s> route lifetime (%" PRIu64 ") for " "%s/%d on %s out of range", __func__, - (long long)val64, addr, rti->rti_prefixlen, + val64, addr, rti->rti_prefixlen, ifi->ifi_ifname); goto getconfig_free_rti; } - rti->rti_ltime = (u_int32_t)val64; + rti->rti_ltime = (uint32_t)val64; /* link into chain */ TAILQ_INSERT_TAIL(&rai->rai_route, rti, rti_next); @@ -750,7 +792,7 @@ getconfig_free_pfx: getconfig_free_rti: free(rti); } -#endif + /* DNS server and DNS search list information */ for (i = -1; i < MAXRDNSSENT ; i++) { struct rdnss *rdn; @@ -782,9 +824,9 @@ getconfig_free_rti: makeentry(entbuf, sizeof(entbuf), i, "rdnssltime"); MAYHAVE(val, entbuf, (rai->rai_maxinterval * 3 / 2)); - if ((u_int)val < rai->rai_maxinterval || - (u_int)val > rai->rai_maxinterval * 2) { - syslog(LOG_ERR, "%s (%ld) on %s is invalid " + if ((uint16_t)val < rai->rai_maxinterval || + (uint16_t)val > rai->rai_maxinterval * 2) { + syslog(LOG_ERR, "%s (%" PRIu16 ") on %s is invalid " "(must be between %d and %d)", entbuf, val, ifi->ifi_ifname, rai->rai_maxinterval, rai->rai_maxinterval * 2); @@ -831,9 +873,9 @@ getconfig_free_rdn: makeentry(entbuf, sizeof(entbuf), i, "dnsslltime"); MAYHAVE(val, entbuf, (rai->rai_maxinterval * 3 / 2)); - if ((u_int)val < rai->rai_maxinterval || - (u_int)val > rai->rai_maxinterval * 2) { - syslog(LOG_ERR, "%s (%ld) on %s is invalid " + if ((uint16_t)val < rai->rai_maxinterval || + (uint16_t)val > rai->rai_maxinterval * 2) { + syslog(LOG_ERR, "%s (%" PRIu16 ") on %s is invalid " "(must be between %d and %d)", entbuf, val, ifi->ifi_ifname, rai->rai_maxinterval, rai->rai_maxinterval * 2); @@ -859,26 +901,102 @@ getconfig_free_dns: * Before the removal, RDNSS and DNSSL options with * zero-lifetime will be sent. */ - if (rai_old != NULL) { - const int retrans = MAX_FINAL_RTR_ADVERTISEMENTS; - struct rdnss *rdn; - struct dnssl *dns; + switch (ifi->ifi_state) { + case IFI_STATE_UNCONFIGURED: + /* UNCONFIGURED -> TRANSITIVE */ + + error = sock_mc_join(&sock, ifi->ifi_ifindex); + if (error) + exit(1); + + ifi->ifi_state = IFI_STATE_TRANSITIVE; + ifi->ifi_burstcount = MAX_INITIAL_RTR_ADVERTISEMENTS; + ifi->ifi_burstinterval = MAX_INITIAL_RTR_ADVERT_INTERVAL; + + /* The same two rai mean initial burst */ + ifi->ifi_rainfo = rai; + ifi->ifi_rainfo_trans = rai; + TAILQ_INSERT_TAIL(&railist, rai, rai_next); + + if (ifi->ifi_ra_timer == NULL) + ifi->ifi_ra_timer = rtadvd_add_timer(ra_timeout, + ra_timer_update, ifi, ifi); + ra_timer_update(ifi, &ifi->ifi_ra_timer->rat_tm); + rtadvd_set_timer(&ifi->ifi_ra_timer->rat_tm, + ifi->ifi_ra_timer); - rai_old->rai_lifetime = 0; - TAILQ_FOREACH(rdn, &rai_old->rai_rdnss, rd_next) - rdn->rd_ltime = 0; - TAILQ_FOREACH(dns, &rai_old->rai_dnssl, dn_next) - dns->dn_ltime = 0; + syslog(LOG_DEBUG, + "<%s> ifname=%s marked as TRANSITIVE (initial burst).", + __func__, ifi->ifi_ifname); + break; + case IFI_STATE_CONFIGURED: + /* CONFIGURED -> TRANSITIVE */ + rai_old = ifi->ifi_rainfo; + if (rai_old == NULL) { + syslog(LOG_ERR, + "<%s> ifi_rainfo is NULL" + " in IFI_STATE_CONFIGURED.", __func__); + ifi = NULL; + break; + } else { + struct rdnss *rdn; + struct dnssl *dns; + + rai_old->rai_lifetime = 0; + TAILQ_FOREACH(rdn, &rai_old->rai_rdnss, rd_next) + rdn->rd_ltime = 0; + TAILQ_FOREACH(dns, &rai_old->rai_dnssl, dn_next) + dns->dn_ltime = 0; + + ifi->ifi_rainfo_trans = rai_old; + ifi->ifi_state = IFI_STATE_TRANSITIVE; + ifi->ifi_burstcount = MAX_FINAL_RTR_ADVERTISEMENTS; + ifi->ifi_burstinterval = MIN_DELAY_BETWEEN_RAS; + + ra_timer_update(ifi, &ifi->ifi_ra_timer->rat_tm); + rtadvd_set_timer(&ifi->ifi_ra_timer->rat_tm, + ifi->ifi_ra_timer); + + syslog(LOG_DEBUG, + "<%s> ifname=%s marked as TRANSITIVE" + " (transitional burst)", + __func__, ifi->ifi_ifname); + } + ifi->ifi_rainfo = rai; + TAILQ_INSERT_TAIL(&railist, rai, rai_next); + break; + case IFI_STATE_TRANSITIVE: + if (ifi->ifi_rainfo != NULL) { + if (ifi->ifi_rainfo == ifi->ifi_rainfo_trans) { + /* Reinitialize initial burst */ + rm_rainfo(ifi->ifi_rainfo); + ifi->ifi_rainfo = rai; + ifi->ifi_rainfo_trans = rai; + ifi->ifi_burstcount = + MAX_INITIAL_RTR_ADVERTISEMENTS; + ifi->ifi_burstinterval = + MAX_INITIAL_RTR_ADVERT_INTERVAL; + } else { + /* Replace ifi_rainfo with the new one */ + rm_rainfo(ifi->ifi_rainfo); + ifi->ifi_rainfo = rai; + } + TAILQ_INSERT_TAIL(&railist, rai, rai_next); + + ra_timer_update(ifi, &ifi->ifi_ra_timer->rat_tm); + rtadvd_set_timer(&ifi->ifi_ra_timer->rat_tm, + ifi->ifi_ra_timer); + } else { + /* XXX: NOTREACHED. Being shut down. */ + syslog(LOG_ERR, + "<%s> %s is shutting down. Skipped.", + __func__, ifi->ifi_ifname); + rm_rainfo(rai); - make_packet(rai_old); - for (i = 0; i < retrans; i++) { - ra_output(rai_old); - sleep(MIN_DELAY_BETWEEN_RAS); + return (NULL); } - rmconfig(idx); + break; } - ifi->ifi_rainfo = rai; - TAILQ_INSERT_TAIL(&railist, rai, rai_next); return (ifi); @@ -894,8 +1012,8 @@ get_prefix(struct rainfo *rai) struct prefix *pfx; struct in6_addr *a; struct ifinfo *ifi; - u_char *p, *ep, *m, *lim; - u_char ntopbuf[INET6_ADDRSTRLEN]; + char *p, *ep, *m, *lim; + char ntopbuf[INET6_ADDRSTRLEN]; if (getifaddrs(&ifap) < 0) { syslog(LOG_ERR, @@ -915,9 +1033,10 @@ 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; + m = (char *)&((struct sockaddr_in6 *)ifa->ifa_netmask)->sin6_addr; + lim = (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 " @@ -938,8 +1057,8 @@ get_prefix(struct rainfo *rai) /* set prefix, sweep bits outside of prefixlen */ pfx->pfx_prefixlen = plen; memcpy(&pfx->pfx_prefix, a, sizeof(*a)); - p = (u_char *)&pfx->pfx_prefix; - ep = (u_char *)(&pfx->pfx_prefix + 1); + p = (char *)&pfx->pfx_prefix; + ep = (char *)(&pfx->pfx_prefix + 1); while (m < lim && p < ep) *p++ &= *m++; while (p < ep) @@ -993,7 +1112,7 @@ add_prefix(struct rainfo *rai, struct in6_prefixreq *ipr) { struct prefix *pfx; struct ifinfo *ifi; - u_char ntopbuf[INET6_ADDRSTRLEN]; + char ntopbuf[INET6_ADDRSTRLEN]; ifi = rai->rai_ifinfo; ELM_MALLOC(pfx, return); @@ -1013,9 +1132,7 @@ add_prefix(struct rainfo *rai, struct in6_prefixreq *ipr) inet_ntop(AF_INET6, &ipr->ipr_prefix.sin6_addr, ntopbuf, sizeof(ntopbuf)), ipr->ipr_plen, ifi->ifi_ifname); - /* reconstruct the packet */ rai->rai_pfxs++; - make_packet(rai); } /* @@ -1028,7 +1145,7 @@ delete_prefix(struct prefix *pfx) { struct rainfo *rai; struct ifinfo *ifi; - u_char ntopbuf[INET6_ADDRSTRLEN]; + char ntopbuf[INET6_ADDRSTRLEN]; rai = pfx->pfx_rainfo; ifi = rai->rai_ifinfo; @@ -1040,8 +1157,8 @@ delete_prefix(struct prefix *pfx) if (pfx->pfx_timer) rtadvd_remove_timer(pfx->pfx_timer); free(pfx); + rai->rai_pfxs--; - make_packet(rai); } void @@ -1050,7 +1167,7 @@ invalidate_prefix(struct prefix *pfx) struct timeval timo; struct rainfo *rai; struct ifinfo *ifi; - u_char ntopbuf[INET6_ADDRSTRLEN]; + char ntopbuf[INET6_ADDRSTRLEN]; rai = pfx->pfx_rainfo; ifi = rai->rai_ifinfo; @@ -1092,7 +1209,7 @@ update_prefix(struct prefix *pfx) { struct rainfo *rai; struct ifinfo *ifi; - u_char ntopbuf[INET6_ADDRSTRLEN]; + char ntopbuf[INET6_ADDRSTRLEN]; rai = pfx->pfx_rainfo; ifi = rai->rai_ifinfo; @@ -1140,7 +1257,7 @@ init_prefix(struct in6_prefixreq *ipr) /* omit other field initialization */ } else if (ipr->ipr_origin < PR_ORIG_RR) { - u_char ntopbuf[INET6_ADDRSTRLEN]; + char ntopbuf[INET6_ADDRSTRLEN]; syslog(LOG_WARNING, "<%s> Added prefix(%s)'s origin %d is" "lower than PR_ORIG_RR(router renumbering)." @@ -1192,10 +1309,8 @@ make_packet(struct rainfo *rai) struct nd_router_advert *ra; struct nd_opt_prefix_info *ndopt_pi; struct nd_opt_mtu *ndopt_mtu; -#ifdef ROUTEINFO struct nd_opt_route_info *ndopt_rti; struct rtinfo *rti; -#endif struct nd_opt_rdnss *ndopt_rdnss; struct rdnss *rdn; struct nd_opt_dnssl *ndopt_dnssl; @@ -1221,11 +1336,11 @@ make_packet(struct rainfo *rai) packlen += sizeof(struct nd_opt_prefix_info) * rai->rai_pfxs; if (rai->rai_linkmtu) packlen += sizeof(struct nd_opt_mtu); -#ifdef ROUTEINFO + TAILQ_FOREACH(rti, &rai->rai_route, rti_next) packlen += sizeof(struct nd_opt_route_info) + ((rti->rti_prefixlen + 0x3f) >> 6) * 8; -#endif + TAILQ_FOREACH(rdn, &rai->rai_rdnss, rd_next) { struct rdnss_addr *rdna; @@ -1268,7 +1383,7 @@ make_packet(struct rainfo *rai) ra->nd_ra_type = ND_ROUTER_ADVERT; ra->nd_ra_code = 0; ra->nd_ra_cksum = 0; - ra->nd_ra_curhoplimit = (u_int8_t)(0xff & rai->rai_hoplimit); + ra->nd_ra_curhoplimit = (uint8_t)(0xff & rai->rai_hoplimit); ra->nd_ra_flags_reserved = 0; /* just in case */ /* * XXX: the router preference field, which is a 2-bit field, should be @@ -1299,7 +1414,7 @@ make_packet(struct rainfo *rai) } TAILQ_FOREACH(pfx, &rai->rai_prefix, pfx_next) { - u_int32_t vltime, pltime; + uint32_t vltime, pltime; struct timeval now; ndopt_pi = (struct nd_opt_prefix_info *)buf; @@ -1321,7 +1436,7 @@ make_packet(struct rainfo *rai) if (pfx->pfx_vltimeexpire == 0) vltime = pfx->pfx_validlifetime; else - vltime = (pfx->pfx_vltimeexpire > now.tv_sec) ? + vltime = ((time_t)pfx->pfx_vltimeexpire > now.tv_sec) ? pfx->pfx_vltimeexpire - now.tv_sec : 0; } if (pfx->pfx_timer) @@ -1330,7 +1445,7 @@ make_packet(struct rainfo *rai) if (pfx->pfx_pltimeexpire == 0) pltime = pfx->pfx_preflifetime; else - pltime = (pfx->pfx_pltimeexpire > now.tv_sec) ? + pltime = ((time_t)pfx->pfx_pltimeexpire > now.tv_sec) ? pfx->pfx_pltimeexpire - now.tv_sec : 0; } if (vltime < pltime) { @@ -1348,9 +1463,8 @@ make_packet(struct rainfo *rai) buf += sizeof(struct nd_opt_prefix_info); } -#ifdef ROUTEINFO TAILQ_FOREACH(rti, &rai->rai_route, rti_next) { - u_int8_t psize = (rti->rti_prefixlen + 0x3f) >> 6; + uint8_t psize = (rti->rti_prefixlen + 0x3f) >> 6; ndopt_rti = (struct nd_opt_route_info *)buf; ndopt_rti->nd_opt_rti_type = ND_OPT_ROUTE_INFO; @@ -1361,7 +1475,7 @@ make_packet(struct rainfo *rai) memcpy(ndopt_rti + 1, &rti->rti_prefix, psize * 8); buf += sizeof(struct nd_opt_route_info) + psize * 8; } -#endif + TAILQ_FOREACH(rdn, &rai->rai_rdnss, rd_next) { struct rdnss_addr *rdna; @@ -1382,6 +1496,7 @@ make_packet(struct rainfo *rai) syslog(LOG_DEBUG, "<%s>: nd_opt_dnss_len = %d", __func__, ndopt_rdnss->nd_opt_rdnss_len); } + TAILQ_FOREACH(dns, &rai->rai_dnssl, dn_next) { struct dnssl_addr *dnsa; |