From d71d91b3f552e5c930c9fe6d44bddd589374547e Mon Sep 17 00:00:00 2001 From: markj Date: Tue, 3 May 2016 23:46:01 +0000 Subject: [PATCH] MFC r295575, r295576, r295578, r295579, r295580: Various NDP cleanups. No functional change intended. git-svn-id: svn://svn.freebsd.org/base/stable/10@299014 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f --- sys/netinet6/nd6.c | 8 +---- sys/netinet6/nd6_nbr.c | 8 ----- sys/netinet6/nd6_rtr.c | 67 ++++++++++++++++++------------------------ 3 files changed, 29 insertions(+), 54 deletions(-) diff --git a/sys/netinet6/nd6.c b/sys/netinet6/nd6.c index d22691137..62d3a5cf9 100644 --- a/sys/netinet6/nd6.c +++ b/sys/netinet6/nd6.c @@ -112,11 +112,6 @@ VNET_DEFINE(int, nd6_debug) = 1; VNET_DEFINE(int, nd6_debug) = 0; #endif -/* for debugging? */ -#if 0 -static int nd6_inuse, nd6_allocated; -#endif - VNET_DEFINE(struct nd_drhead, nd_defrouter); VNET_DEFINE(struct nd_prhead, nd_prefix); @@ -175,7 +170,7 @@ nd6_ifattach(struct ifnet *ifp) { struct nd_ifinfo *nd; - nd = (struct nd_ifinfo *)malloc(sizeof(*nd), M_IP6NDP, M_WAITOK|M_ZERO); + nd = malloc(sizeof(*nd), M_IP6NDP, M_WAITOK | M_ZERO); nd->initialized = 1; nd->chlim = IPV6_DEFHLIM; @@ -2182,7 +2177,6 @@ clear_llinfo_pqueue(struct llentry *ln) } ln->la_hold = NULL; - return; } static int nd6_sysctl_drlist(SYSCTL_HANDLER_ARGS); diff --git a/sys/netinet6/nd6_nbr.c b/sys/netinet6/nd6_nbr.c index 5232f8fb8..46c8dfe8d 100644 --- a/sys/netinet6/nd6_nbr.c +++ b/sys/netinet6/nd6_nbr.c @@ -623,7 +623,6 @@ nd6_ns_output_fib(struct ifnet *ifp, const struct in6_addr *daddr6, RTFREE(ro.ro_rt); } m_freem(m); - return; } #ifndef BURN_BRIDGES @@ -901,12 +900,6 @@ nd6_na_input(struct mbuf *m, int off, int icmp6len) in6 = &L3_ADDR_SIN6(ln)->sin6_addr; - /* - * Lock to protect the default router list. - * XXX: this might be unnecessary, since this function - * is only called under the network software interrupt - * context. However, we keep it just for safety. - */ dr = defrouter_lookup(in6, ln->lle_tbl->llt_ifp); if (dr) defrtrlist_del(dr); @@ -1127,7 +1120,6 @@ nd6_na_output_fib(struct ifnet *ifp, const struct in6_addr *daddr6_0, RTFREE(ro.ro_rt); } m_freem(m); - return; } #ifndef BURN_BRIDGES diff --git a/sys/netinet6/nd6_rtr.c b/sys/netinet6/nd6_rtr.c index 8588a6b40..175ece1ef 100644 --- a/sys/netinet6/nd6_rtr.c +++ b/sys/netinet6/nd6_rtr.c @@ -501,7 +501,6 @@ defrouter_addreq(struct nd_defrouter *new) } if (error == 0) new->installed = 1; - return; } struct nd_defrouter * @@ -700,8 +699,6 @@ defrouter_select(void) defrouter_delreq(installed_dr); defrouter_addreq(selected_dr); } - - return; } /* @@ -735,53 +732,47 @@ static struct nd_defrouter * defrtrlist_update(struct nd_defrouter *new) { struct nd_defrouter *dr, *n; + int oldpref; if ((dr = defrouter_lookup(&new->rtaddr, new->ifp)) != NULL) { /* entry exists */ if (new->rtlifetime == 0) { defrtrlist_del(dr); - dr = NULL; - } else { - int oldpref = rtpref(dr); + return (NULL); + } - /* override */ - dr->flags = new->flags; /* xxx flag check */ - dr->rtlifetime = new->rtlifetime; - dr->expire = new->expire; + oldpref = rtpref(dr); - /* - * If the preference does not change, there's no need - * to sort the entries. Also make sure the selected - * router is still installed in the kernel. - */ - if (dr->installed && rtpref(new) == oldpref) - return (dr); + /* override */ + dr->flags = new->flags; /* xxx flag check */ + dr->rtlifetime = new->rtlifetime; + dr->expire = new->expire; - /* - * preferred router may be changed, so relocate - * this router. - * XXX: calling TAILQ_REMOVE directly is a bad manner. - * However, since defrtrlist_del() has many side - * effects, we intentionally do so here. - * defrouter_select() below will handle routing - * changes later. - */ - TAILQ_REMOVE(&V_nd_defrouter, dr, dr_entry); - n = dr; - goto insert; - } - return (dr); + /* + * If the preference does not change, there's no need + * to sort the entries. Also make sure the selected + * router is still installed in the kernel. + */ + if (dr->installed && rtpref(new) == oldpref) + return (dr); + + /* + * The preferred router may have changed, so relocate this + * router. + */ + TAILQ_REMOVE(&V_nd_defrouter, dr, dr_entry); + n = dr; + goto insert; } /* entry does not exist */ if (new->rtlifetime == 0) return (NULL); - n = (struct nd_defrouter *)malloc(sizeof(*n), M_IP6NDP, M_NOWAIT); + n = malloc(sizeof(*n), M_IP6NDP, M_NOWAIT | M_ZERO); if (n == NULL) return (NULL); - bzero(n, sizeof(*n)); - *n = *new; + memcpy(n, new, sizeof(*n)); insert: /* @@ -824,10 +815,9 @@ pfxrtr_add(struct nd_prefix *pr, struct nd_defrouter *dr) { struct nd_pfxrouter *new; - new = (struct nd_pfxrouter *)malloc(sizeof(*new), M_IP6NDP, M_NOWAIT); + new = malloc(sizeof(*new), M_IP6NDP, M_NOWAIT | M_ZERO); if (new == NULL) return; - bzero(new, sizeof(*new)); new->router = dr; LIST_INSERT_HEAD(&pr->ndpr_advrtrs, new, pfr_entry); @@ -868,10 +858,9 @@ nd6_prelist_add(struct nd_prefixctl *pr, struct nd_defrouter *dr, int i; char ip6buf[INET6_ADDRSTRLEN]; - new = (struct nd_prefix *)malloc(sizeof(*new), M_IP6NDP, M_NOWAIT); + new = malloc(sizeof(*new), M_IP6NDP, M_NOWAIT | M_ZERO); if (new == NULL) - return(ENOMEM); - bzero(new, sizeof(*new)); + return (ENOMEM); new->ndpr_ifp = pr->ndpr_ifp; new->ndpr_prefix = pr->ndpr_prefix; new->ndpr_plen = pr->ndpr_plen; -- 2.45.0