diff options
author | 2015-08-19 13:27:38 +0000 | |
---|---|---|
committer | 2015-08-19 13:27:38 +0000 | |
commit | 0ffd01d490e34e2c83872cc1dd6b79b11d9e37fc (patch) | |
tree | 054e643d7d0148e29935b324db316d72e0325225 /sys/netinet6 | |
parent | Halt extra cores on SP kernel, to avoid trashing the system if there (diff) | |
download | wireguard-openbsd-0ffd01d490e34e2c83872cc1dd6b79b11d9e37fc.tar.xz wireguard-openbsd-0ffd01d490e34e2c83872cc1dd6b79b11d9e37fc.zip |
Convert all calls to rtrequest1() and the following error check
into a common pattern. In the man page clarify the usage of the
returned route.
OK mpi@ mikeb@ jmc@
Diffstat (limited to 'sys/netinet6')
-rw-r--r-- | sys/netinet6/in6.c | 6 | ||||
-rw-r--r-- | sys/netinet6/nd6.c | 19 | ||||
-rw-r--r-- | sys/netinet6/nd6_rtr.c | 54 |
3 files changed, 34 insertions, 45 deletions
diff --git a/sys/netinet6/in6.c b/sys/netinet6/in6.c index 95657e3b8bb..866a8a74e91 100644 --- a/sys/netinet6/in6.c +++ b/sys/netinet6/in6.c @@ -1,4 +1,4 @@ -/* $OpenBSD: in6.c,v 1.164 2015/08/19 11:09:24 mpi Exp $ */ +/* $OpenBSD: in6.c,v 1.165 2015/08/19 13:27:38 bluhm Exp $ */ /* $KAME: in6.c,v 1.372 2004/06/14 08:14:21 itojun Exp $ */ /* @@ -895,8 +895,8 @@ in6_update_ifa(struct ifnet *ifp, struct in6_aliasreq *ifra, info.rti_info[RTAX_NETMASK] = sin6tosa(&mltmask); info.rti_info[RTAX_IFA] = sin6tosa(&ia6->ia_addr); info.rti_flags = RTF_UP | RTF_CLONING; - error = rtrequest1(RTM_ADD, &info, RTP_CONNECTED, - NULL, ifp->if_rdomain); + error = rtrequest1(RTM_ADD, &info, RTP_CONNECTED, NULL, + ifp->if_rdomain); if (error) goto cleanup; } else { diff --git a/sys/netinet6/nd6.c b/sys/netinet6/nd6.c index 47ebfc69ef4..31110312523 100644 --- a/sys/netinet6/nd6.c +++ b/sys/netinet6/nd6.c @@ -1,4 +1,4 @@ -/* $OpenBSD: nd6.c,v 1.144 2015/08/17 09:58:10 mpi Exp $ */ +/* $OpenBSD: nd6.c,v 1.145 2015/08/19 13:27:38 bluhm Exp $ */ /* $KAME: nd6.c,v 1.280 2002/06/08 19:52:07 itojun Exp $ */ /* @@ -646,7 +646,7 @@ nd6_lookup(struct in6_addr *addr6, int create, struct ifnet *ifp, if (!rt) { if (create && ifp) { struct rt_addrinfo info; - int e; + int error; /* * If no route is available and create is set, @@ -671,18 +671,9 @@ nd6_lookup(struct in6_addr *addr6, int create, struct ifnet *ifp, info.rti_info[RTAX_DST] = sin6tosa(&sin6); info.rti_info[RTAX_GATEWAY] = (struct sockaddr *)ifp->if_sadl; - if ((e = rtrequest1(RTM_ADD, &info, RTP_CONNECTED, - &rt, rtableid)) != 0) { -#if 0 - char ip[INET6_ADDRSTRLEN]; - log(LOG_ERR, "%s: failed to add route for a " - "neighbor(%s), errno=%d\n", __func__, - inet_ntop(AF_INET6, addr6, ip, sizeof(ip)), - e); -#endif - return (NULL); - } - if (rt == NULL) + error = rtrequest1(RTM_ADD, &info, RTP_CONNECTED, &rt, + rtableid); + if (error) return (NULL); if (rt->rt_llinfo) { struct llinfo_nd6 *ln = diff --git a/sys/netinet6/nd6_rtr.c b/sys/netinet6/nd6_rtr.c index 2dadc22945a..aa88ae17302 100644 --- a/sys/netinet6/nd6_rtr.c +++ b/sys/netinet6/nd6_rtr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: nd6_rtr.c,v 1.115 2015/08/18 08:52:25 mpi Exp $ */ +/* $OpenBSD: nd6_rtr.c,v 1.116 2015/08/19 13:27:38 bluhm Exp $ */ /* $KAME: nd6_rtr.c,v 1.97 2001/02/07 11:09:13 itojun Exp $ */ /* @@ -602,7 +602,7 @@ defrouter_addreq(struct nd_defrouter *new) { struct rt_addrinfo info; struct sockaddr_in6 def, mask, gate; - struct rtentry *rt = NULL; + struct rtentry *rt; int s; int error; @@ -625,12 +625,11 @@ defrouter_addreq(struct nd_defrouter *new) s = splsoftnet(); error = rtrequest1(RTM_ADD, &info, RTP_DEFAULT, &rt, new->ifp->if_rdomain); - if (rt) { + if (error == 0) { rt_sendmsg(rt, RTM_ADD, new->ifp->if_rdomain); rtfree(rt); - } - if (error == 0) new->installed = 1; + } splx(s); return; } @@ -705,7 +704,8 @@ defrouter_delreq(struct nd_defrouter *dr) { struct rt_addrinfo info; struct sockaddr_in6 def, mask, gw; - struct rtentry *oldrt = NULL; + struct rtentry *rt; + int error; #ifdef DIAGNOSTIC if (!dr) @@ -728,17 +728,17 @@ defrouter_delreq(struct nd_defrouter *dr) info.rti_info[RTAX_GATEWAY] = sin6tosa(&gw); info.rti_info[RTAX_NETMASK] = sin6tosa(&mask); - rtrequest1(RTM_DELETE, &info, RTP_DEFAULT, &oldrt, + error = rtrequest1(RTM_DELETE, &info, RTP_DEFAULT, &rt, dr->ifp->if_rdomain); - if (oldrt) { - rt_sendmsg(oldrt, RTM_DELETE, dr->ifp->if_rdomain); - if (oldrt->rt_refcnt <= 0) { + if (error == 0) { + rt_sendmsg(rt, RTM_DELETE, dr->ifp->if_rdomain); + if (rt->rt_refcnt <= 0) { /* * XXX: borrowed from the RTM_DELETE case of * rtrequest1(). */ - oldrt->rt_refcnt++; - rtfree(oldrt); + rt->rt_refcnt++; + rtfree(rt); } } @@ -1778,10 +1778,10 @@ nd6_prefix_onlink(struct nd_prefix *pr) struct ifnet *ifp = pr->ndpr_ifp; struct sockaddr_in6 mask6; struct nd_prefix *opr; - u_long rtflags; - int error = 0; - struct rtentry *rt = NULL; + struct rtentry *rt; char addr[INET6_ADDRSTRLEN]; + u_long rtflags; + int error; /* sanity check */ if ((pr->ndpr_stateflags & NDPRF_ONLINK) != 0) @@ -1856,7 +1856,7 @@ nd6_prefix_onlink(struct nd_prefix *pr) info.rti_info[RTAX_NETMASK] = sin6tosa(&mask6); error = rtrequest1(RTM_ADD, &info, RTP_CONNECTED, &rt, ifp->if_rdomain); - if (error == 0 && rt != NULL) { + if (error == 0) { pr->ndpr_stateflags |= NDPRF_ONLINK; rt_sendmsg(rt, RTM_ADD, ifp->if_rdomain); rtfree(rt); @@ -1869,12 +1869,12 @@ int nd6_prefix_offlink(struct nd_prefix *pr) { struct rt_addrinfo info; - int error = 0; struct ifnet *ifp = pr->ndpr_ifp; struct nd_prefix *opr; struct sockaddr_in6 sa6, mask6; - struct rtentry *rt = NULL; + struct rtentry *rt; char addr[INET6_ADDRSTRLEN]; + int error; /* sanity check */ if ((pr->ndpr_stateflags & NDPRF_ONLINK) == 0) { @@ -1898,14 +1898,14 @@ nd6_prefix_offlink(struct nd_prefix *pr) bzero(&info, sizeof(info)); info.rti_info[RTAX_DST] = sin6tosa(&sa6); info.rti_info[RTAX_NETMASK] = sin6tosa(&mask6); + error = rtrequest1(RTM_DELETE, &info, RTP_CONNECTED, &rt, ifp->if_rdomain); if (error == 0) { pr->ndpr_stateflags &= ~NDPRF_ONLINK; /* report the route deletion to the routing socket. */ - if (rt != NULL) - rt_sendmsg(rt, RTM_DELETE, ifp->if_rdomain); + rt_sendmsg(rt, RTM_DELETE, ifp->if_rdomain); /* * There might be the same prefix on another interface, @@ -1946,6 +1946,12 @@ nd6_prefix_offlink(struct nd_prefix *pr) } } } + + if (rt->rt_refcnt <= 0) { + /* XXX: we should free the entry ourselves. */ + rt->rt_refcnt++; + rtfree(rt); + } } else { /* XXX: can we still set the NDPRF_ONLINK flag? */ nd6log((LOG_ERR, @@ -1955,14 +1961,6 @@ nd6_prefix_offlink(struct nd_prefix *pr) pr->ndpr_plen, ifp->if_xname, error)); } - if (rt != NULL) { - if (rt->rt_refcnt <= 0) { - /* XXX: we should free the entry ourselves. */ - rt->rt_refcnt++; - rtfree(rt); - } - } - return (error); } |