diff options
author | 2015-07-18 15:05:32 +0000 | |
---|---|---|
committer | 2015-07-18 15:05:32 +0000 | |
commit | 98918cf7c7668a96356d8065ecf3591ca04318b1 (patch) | |
tree | 6f4963483fc3a5d8de7d21126e17c432bbb52c10 | |
parent | Change unp_scan() and its callbacks to pass the array of struct file ** (diff) | |
download | wireguard-openbsd-98918cf7c7668a96356d8065ecf3591ca04318b1.tar.xz wireguard-openbsd-98918cf7c7668a96356d8065ecf3591ca04318b1.zip |
Merge two identical chunks to add new prefixes to the global data
structures into a function.
ok florian@
-rw-r--r-- | sys/netinet6/in6.c | 64 | ||||
-rw-r--r-- | sys/netinet6/in6_ifattach.c | 40 | ||||
-rw-r--r-- | sys/netinet6/nd6.h | 5 | ||||
-rw-r--r-- | sys/netinet6/nd6_rtr.c | 48 |
4 files changed, 72 insertions, 85 deletions
diff --git a/sys/netinet6/in6.c b/sys/netinet6/in6.c index 78263d88e02..b0671de01c4 100644 --- a/sys/netinet6/in6.c +++ b/sys/netinet6/in6.c @@ -1,4 +1,4 @@ -/* $OpenBSD: in6.c,v 1.160 2015/07/08 08:48:34 mpi Exp $ */ +/* $OpenBSD: in6.c,v 1.161 2015/07/18 15:05:32 mpi Exp $ */ /* $KAME: in6.c,v 1.372 2004/06/14 08:14:21 itojun Exp $ */ /* @@ -462,8 +462,8 @@ in6_control(struct socket *so, u_long cmd, caddr_t data, struct ifnet *ifp) case SIOCAIFADDR_IN6: { - int i, error = 0; - struct nd_prefix pr0, *pr; + struct nd_prefix *pr; + int plen, error = 0; /* reject read-only flags */ if ((ifra->ifra_flags & IN6_IFF_DUPLICATED) != 0 || @@ -492,58 +492,24 @@ in6_control(struct socket *so, u_long cmd, caddr_t data, struct ifnet *ifp) break; } + plen = in6_mask2len(&ifra->ifra_prefixmask.sin6_addr, NULL); + if (plen == 128) { + dohooks(ifp->if_addrhooks, 0); + break; /* we don't need to install a host route. */ + } + /* * then, make the prefix on-link on the interface. * XXX: we'd rather create the prefix before the address, but * we need at least one address to install the corresponding * interface route, so we configure the address first. */ - - /* - * convert mask to prefix length (prefixmask has already - * been validated in in6_update_ifa(). - */ - bzero(&pr0, sizeof(pr0)); - pr0.ndpr_ifp = ifp; - pr0.ndpr_plen = in6_mask2len(&ifra->ifra_prefixmask.sin6_addr, - NULL); - if (pr0.ndpr_plen == 128) { - dohooks(ifp->if_addrhooks, 0); - break; /* we don't need to install a host route. */ - } - pr0.ndpr_prefix = ifra->ifra_addr; - pr0.ndpr_mask = ifra->ifra_prefixmask.sin6_addr; - /* apply the mask for safety. */ - for (i = 0; i < 4; i++) { - pr0.ndpr_prefix.sin6_addr.s6_addr32[i] &= - ifra->ifra_prefixmask.sin6_addr.s6_addr32[i]; - } - /* - * XXX: since we don't have an API to set prefix (not address) - * lifetimes, we just use the same lifetimes as addresses. - * The (temporarily) installed lifetimes can be overridden by - * later advertised RAs (when accept_rtadv is non 0), which is - * an intended behavior. - */ - pr0.ndpr_raf_onlink = 1; /* should be configurable? */ - pr0.ndpr_raf_auto = - ((ifra->ifra_flags & IN6_IFF_AUTOCONF) != 0); - pr0.ndpr_vltime = ifra->ifra_lifetime.ia6t_vltime; - pr0.ndpr_pltime = ifra->ifra_lifetime.ia6t_pltime; - - /* add the prefix if not yet. */ - if ((pr = nd6_prefix_lookup(&pr0)) == NULL) { - /* - * nd6_prelist_add will install the corresponding - * interface route. - */ - if ((error = nd6_prelist_add(&pr0, NULL, &pr)) != 0) - return (error); - if (pr == NULL) { - log(LOG_ERR, "nd6_prelist_add succeeded but " - "no prefix\n"); - return (EINVAL); /* XXX panic here? */ - } + pr = nd6_prefix_add(ifp, &ifra->ifra_addr, + &ifra->ifra_prefixmask, &ifra->ifra_lifetime, + ((ifra->ifra_flags & IN6_IFF_AUTOCONF) != 0)); + if (pr == NULL) { + log(LOG_ERR, "cannot add prefix\n"); + return (EINVAL); /* XXX panic here? */ } /* relate the address to the prefix */ diff --git a/sys/netinet6/in6_ifattach.c b/sys/netinet6/in6_ifattach.c index a9058f60c0d..032484b7691 100644 --- a/sys/netinet6/in6_ifattach.c +++ b/sys/netinet6/in6_ifattach.c @@ -1,4 +1,4 @@ -/* $OpenBSD: in6_ifattach.c,v 1.89 2015/07/16 15:31:35 mpi Exp $ */ +/* $OpenBSD: in6_ifattach.c,v 1.90 2015/07/18 15:05:32 mpi Exp $ */ /* $KAME: in6_ifattach.c,v 1.124 2001/07/18 08:32:51 jinmei Exp $ */ /* @@ -294,8 +294,7 @@ in6_ifattach_linklocal(struct ifnet *ifp, struct in6_addr *ifid) { struct in6_ifaddr *ia6; struct in6_aliasreq ifra; - struct nd_prefix pr0; - int i, s, error; + int s, error; /* * configure link-local address. @@ -394,38 +393,11 @@ in6_ifattach_linklocal(struct ifnet *ifp, struct in6_addr *ifid) * and add it to the prefix list as a never-expire prefix. * XXX: this change might affect some existing code base... */ - bzero(&pr0, sizeof(pr0)); - pr0.ndpr_ifp = ifp; - /* this should be 64 at this moment. */ - pr0.ndpr_plen = in6_mask2len(&ifra.ifra_prefixmask.sin6_addr, NULL); - pr0.ndpr_mask = ifra.ifra_prefixmask.sin6_addr; - pr0.ndpr_prefix = ifra.ifra_addr; - /* apply the mask for safety. (nd6_prelist_add will apply it again) */ - for (i = 0; i < 4; i++) { - pr0.ndpr_prefix.sin6_addr.s6_addr32[i] &= - in6mask64.s6_addr32[i]; - } - /* - * Initialize parameters. The link-local prefix must always be - * on-link, and its lifetimes never expire. - */ - pr0.ndpr_raf_onlink = 1; - pr0.ndpr_raf_auto = 1; /* probably meaningless */ - pr0.ndpr_vltime = ND6_INFINITE_LIFETIME; - pr0.ndpr_pltime = ND6_INFINITE_LIFETIME; - /* - * Since there is no other link-local addresses, nd6_prefix_lookup() - * probably returns NULL. However, we cannot always expect the result. - * For example, if we first remove the (only) existing link-local - * address, and then reconfigure another one, the prefix is still - * valid with referring to the old link-local address. - */ - if (nd6_prefix_lookup(&pr0) == NULL) { - if ((error = nd6_prelist_add(&pr0, NULL, NULL)) != 0) - return (error); - } + if (nd6_prefix_add(ifp, &ifra.ifra_addr, &ifra.ifra_prefixmask, + &ifra.ifra_lifetime, 1) == NULL) + return (EINVAL); - return 0; + return (0); } int diff --git a/sys/netinet6/nd6.h b/sys/netinet6/nd6.h index 9286ae599bf..e96e4ce216a 100644 --- a/sys/netinet6/nd6.h +++ b/sys/netinet6/nd6.h @@ -1,4 +1,4 @@ -/* $OpenBSD: nd6.h,v 1.43 2015/07/16 15:31:35 mpi Exp $ */ +/* $OpenBSD: nd6.h,v 1.44 2015/07/18 15:05:32 mpi Exp $ */ /* $KAME: nd6.h,v 1.95 2002/06/08 11:31:06 itojun Exp $ */ /* @@ -313,6 +313,9 @@ int nd6_prefix_onlink(struct nd_prefix *); int nd6_prefix_offlink(struct nd_prefix *); void pfxlist_onlink_check(void); struct nd_defrouter *defrouter_lookup(struct in6_addr *, struct ifnet *); + +struct nd_prefix *nd6_prefix_add(struct ifnet *, struct sockaddr_in6 *, + struct sockaddr_in6 *, struct in6_addrlifetime *, int); struct nd_prefix *nd6_prefix_lookup(struct nd_prefix *); int in6_ifdel(struct ifnet *, struct in6_addr *); int in6_init_prefix_ltimes(struct nd_prefix *ndpr); diff --git a/sys/netinet6/nd6_rtr.c b/sys/netinet6/nd6_rtr.c index 3aca152ba8f..6a1255538d8 100644 --- a/sys/netinet6/nd6_rtr.c +++ b/sys/netinet6/nd6_rtr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: nd6_rtr.c,v 1.111 2015/07/17 17:18:05 florian Exp $ */ +/* $OpenBSD: nd6_rtr.c,v 1.112 2015/07/18 15:05:32 mpi Exp $ */ /* $KAME: nd6_rtr.c,v 1.97 2001/02/07 11:09:13 itojun Exp $ */ /* @@ -1075,6 +1075,52 @@ purge_detached(struct ifnet *ifp) } } +struct nd_prefix * +nd6_prefix_add(struct ifnet *ifp, struct sockaddr_in6 *addr, + struct sockaddr_in6 *mask, struct in6_addrlifetime *lt, int autoconf) +{ + struct nd_prefix pr0, *pr; + int i; + + /* + * convert mask to prefix length (prefixmask has already + * been validated in in6_update_ifa(). + */ + memset(&pr0, 0, sizeof(pr0)); + pr0.ndpr_ifp = ifp; + pr0.ndpr_plen = in6_mask2len(&mask->sin6_addr, NULL); + pr0.ndpr_prefix = *addr; + pr0.ndpr_mask = mask->sin6_addr; + /* apply the mask for safety. */ + for (i = 0; i < 4; i++) { + pr0.ndpr_prefix.sin6_addr.s6_addr32[i] &= + mask->sin6_addr.s6_addr32[i]; + } + /* + * XXX: since we don't have an API to set prefix (not address) + * lifetimes, we just use the same lifetimes as addresses. + * The (temporarily) installed lifetimes can be overridden by + * later advertised RAs (when accept_rtadv is non 0), which is + * an intended behavior. + */ + pr0.ndpr_raf_onlink = 1; /* should be configurable? */ + pr0.ndpr_raf_auto = autoconf; + pr0.ndpr_vltime = lt->ia6t_vltime; + pr0.ndpr_pltime = lt->ia6t_pltime; + + /* add the prefix if not yet. */ + if ((pr = nd6_prefix_lookup(&pr0)) == NULL) { + /* + * nd6_prelist_add will install the corresponding + * interface route. + */ + if (nd6_prelist_add(&pr0, NULL, &pr) != 0) + return (NULL); + } + + return (pr); +} + int nd6_prelist_add(struct nd_prefix *pr, struct nd_defrouter *dr, struct nd_prefix **newp) |