diff options
author | 2016-05-02 22:15:49 +0000 | |
---|---|---|
committer | 2016-05-02 22:15:49 +0000 | |
commit | 30b29ff5a79bfc997320671434a72686b189a101 (patch) | |
tree | cee638dc22c5377120c9e8bb7bcc7785240f1649 | |
parent | Remove pointless comment. getcwd(3) is safe. (diff) | |
download | wireguard-openbsd-30b29ff5a79bfc997320671434a72686b189a101.tar.xz wireguard-openbsd-30b29ff5a79bfc997320671434a72686b189a101.zip |
Simplify life for routing table implementations by requiring that rtable_walk
callbacks return EAGAIN if they modify the routing table. While we're here,
simplify life for rtable_walk callers by moving the loop that restarts the
walk on EAGAIN into rtable_walk itself.
Flushing cloned routes on interface state changes becomes a bit more
inefficient, but this can be improved later.
ok mpi@ dlg@
-rw-r--r-- | sys/net/if_spppsubr.c | 6 | ||||
-rw-r--r-- | sys/net/route.c | 20 | ||||
-rw-r--r-- | sys/net/rtable.c | 14 | ||||
-rw-r--r-- | sys/netinet6/nd6_rtr.c | 9 |
4 files changed, 30 insertions, 19 deletions
diff --git a/sys/net/if_spppsubr.c b/sys/net/if_spppsubr.c index 0f32d19ced9..d2ad8c5d80d 100644 --- a/sys/net/if_spppsubr.c +++ b/sys/net/if_spppsubr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_spppsubr.c,v 1.151 2016/05/01 14:08:39 sthen Exp $ */ +/* $OpenBSD: if_spppsubr.c,v 1.152 2016/05/02 22:15:49 jmatthew Exp $ */ /* * Synchronous PPP link level subroutines. * @@ -4171,9 +4171,7 @@ sppp_update_gw(struct ifnet *ifp) /* update routing table */ for (tid = 0; tid <= RT_TABLEID_MAX; tid++) { - while (rtable_walk(tid, AF_INET, sppp_update_gw_walker, - ifp) == EAGAIN) - ; /* nothing */ + rtable_walk(tid, AF_INET, sppp_update_gw_walker, ifp); } } diff --git a/sys/net/route.c b/sys/net/route.c index 3517ef5c679..33f9a42a43b 100644 --- a/sys/net/route.c +++ b/sys/net/route.c @@ -1,4 +1,4 @@ -/* $OpenBSD: route.c,v 1.299 2016/04/27 14:47:27 mpi Exp $ */ +/* $OpenBSD: route.c,v 1.300 2016/05/02 22:15:49 jmatthew Exp $ */ /* $NetBSD: route.c,v 1.14 1996/02/13 22:00:46 christos Exp $ */ /* @@ -669,6 +669,7 @@ rtflushclone1(struct rtentry *rt, void *arg, u_int id) { struct rtentry *parent = arg; struct ifnet *ifp; + int error; ifp = if_get(rt->rt_ifidx); @@ -680,11 +681,14 @@ rtflushclone1(struct rtentry *rt, void *arg, u_int id) if (ifp == NULL) return 0; - if (ISSET(rt->rt_flags, RTF_CLONED) && rtequal(rt->rt_parent, parent)) + if (ISSET(rt->rt_flags, RTF_CLONED) && rtequal(rt->rt_parent, parent)) { rtdeletemsg(rt, ifp, id); + error = EAGAIN; + } else + error = 0; if_put(ifp); - return 0; + return error; } void @@ -1708,9 +1712,7 @@ rt_if_remove(struct ifnet *ifp) if (rtable_l2(tid) != ifp->if_rdomain) continue; for (i = 1; i <= AF_MAX; i++) { - while (rtable_walk(tid, i, rt_if_remove_rtdelete, - ifp) == EAGAIN) - ; /* nothing */ + rtable_walk(tid, i, rt_if_remove_rtdelete, ifp); } } } @@ -1751,9 +1753,7 @@ rt_if_track(struct ifnet *ifp) if (!rtable_mpath_capable(tid, i)) continue; - while (rtable_walk(tid, i, - rt_if_linkstate_change, ifp) == EAGAIN) - ; /* nothing */ + rtable_walk(tid, i, rt_if_linkstate_change, ifp); } } } @@ -1790,7 +1790,7 @@ rt_if_linkstate_change(struct rtentry *rt, void *arg, u_int id) */ if (rt->rt_flags & RTF_CLONED) { rtdeletemsg(rt, ifp, id); - return (0); + return (EAGAIN); } /* take route down */ rt->rt_flags &= ~RTF_UP; diff --git a/sys/net/rtable.c b/sys/net/rtable.c index 2221a492a23..0a3a09e0111 100644 --- a/sys/net/rtable.c +++ b/sys/net/rtable.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rtable.c,v 1.40 2016/04/13 08:04:14 mpi Exp $ */ +/* $OpenBSD: rtable.c,v 1.41 2016/05/02 22:15:49 jmatthew Exp $ */ /* * Copyright (c) 2014-2015 Martin Pieuchot @@ -459,12 +459,16 @@ rtable_walk(unsigned int rtableid, sa_family_t af, { struct radix_node_head *rnh; int (*f)(struct radix_node *, void *, unsigned int) = (void *)func; + int error; rnh = rtable_get(rtableid, af); if (rnh == NULL) return (EAFNOSUPPORT); - return (rn_walktree(rnh, f, arg)); + while ((error = rn_walktree(rnh, f, arg)) == EAGAIN) + ; /* nothing */ + + return (error); } #ifndef SMALL_KERNEL @@ -846,6 +850,7 @@ rtable_walk(unsigned int rtableid, sa_family_t af, { struct art_root *ar; struct rtable_walk_cookie rwc; + int error; ar = rtable_get(rtableid, af); if (ar == NULL) @@ -855,7 +860,10 @@ rtable_walk(unsigned int rtableid, sa_family_t af, rwc.rwc_arg = arg; rwc.rwc_rid = rtableid; - return (art_walk(ar, rtable_walk_helper, &rwc)); + while ((error = art_walk(ar, rtable_walk_helper, &rwc)) == EAGAIN) + ; /* nothing */ + + return (error); } #ifndef SMALL_KERNEL diff --git a/sys/netinet6/nd6_rtr.c b/sys/netinet6/nd6_rtr.c index 17babf2c472..0058711a2cd 100644 --- a/sys/netinet6/nd6_rtr.c +++ b/sys/netinet6/nd6_rtr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: nd6_rtr.c,v 1.138 2016/01/12 09:37:44 mpi Exp $ */ +/* $OpenBSD: nd6_rtr.c,v 1.139 2016/05/02 22:15:49 jmatthew Exp $ */ /* $KAME: nd6_rtr.c,v 1.97 2001/02/07 11:09:13 itojun Exp $ */ /* @@ -2056,6 +2056,7 @@ rt6_deleteroute(struct rtentry *rt, void *arg, unsigned int id) struct rt_addrinfo info; struct in6_addr *gate = (struct in6_addr *)arg; struct sockaddr_in6 sa_mask; + int error; if (rt->rt_gateway == NULL || rt->rt_gateway->sa_family != AF_INET6) return (0); @@ -2083,5 +2084,9 @@ rt6_deleteroute(struct rtentry *rt, void *arg, unsigned int id) info.rti_info[RTAX_DST] = rt_key(rt); info.rti_info[RTAX_GATEWAY] = rt->rt_gateway; info.rti_info[RTAX_NETMASK] = rt_plen2mask(rt, &sa_mask); - return (rtrequest(RTM_DELETE, &info, RTP_ANY, NULL, id)); + error = rtrequest(RTM_DELETE, &info, RTP_ANY, NULL, id); + if (error != 0) + return (error); + + return (EAGAIN); } |