diff options
author | Henning Brauer <henning@cvs.openbsd.org> | 2005-11-25 13:45:03 +0000 |
---|---|---|
committer | Henning Brauer <henning@cvs.openbsd.org> | 2005-11-25 13:45:03 +0000 |
commit | 4115ee1e7a003ec8c26c17a5957895349b137054 (patch) | |
tree | 3902e31eb3aec4245ea2add71add2678ca41722d | |
parent | 6b0088d6a406e956151371889f75860d1f8e6de3 (diff) |
move the code to delete routes having a specific interface as output
when the interface is deleted to a function in route.c, and replace
the copies of that code by calls to that function
from basel almost-hackathon
-rw-r--r-- | sys/net/if.c | 51 | ||||
-rw-r--r-- | sys/net/if_tun.c | 18 | ||||
-rw-r--r-- | sys/net/route.c | 48 | ||||
-rw-r--r-- | sys/net/route.h | 3 |
4 files changed, 57 insertions, 63 deletions
diff --git a/sys/net/if.c b/sys/net/if.c index 698ee18947e..c7d12ad3f0e 100644 --- a/sys/net/if.c +++ b/sys/net/if.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if.c,v 1.137 2005/07/04 09:52:33 henning Exp $ */ +/* $OpenBSD: if.c,v 1.138 2005/11/25 13:45:02 henning Exp $ */ /* $NetBSD: if.c,v 1.35 1996/05/07 05:26:04 thorpej Exp $ */ /* @@ -126,7 +126,6 @@ void if_attachsetup(struct ifnet *); void if_attachdomain1(struct ifnet *); -int if_detach_rtdelete(struct radix_node *, void *); int ifqmaxlen = IFQ_MAXLEN; @@ -449,37 +448,6 @@ if_attach(struct ifnet *ifp) } /* - * Delete a route if it has a specific interface for output. - * This function complies to the rn_walktree callback API. - * - * Note that deleting a RTF_CLONING route can trigger the - * deletion of more entries, so we need to cancel the walk - * and return EAGAIN. The caller should restart the walk - * as long as EAGAIN is returned. - */ -int -if_detach_rtdelete(struct radix_node *rn, void *vifp) -{ - struct ifnet *ifp = vifp; - struct rtentry *rt = (struct rtentry *)rn; - - if (rt->rt_ifp == ifp) { - int cloning = (rt->rt_flags & RTF_CLONING); - - if (rtrequest(RTM_DELETE, rt_key(rt), rt->rt_gateway, - rt_mask(rt), 0, NULL) == 0 && cloning) - return (EAGAIN); - } - - /* - * XXX There should be no need to check for rt_ifa belonging to this - * interface, because then rt_ifp is set, right? - */ - - return (0); -} - -/* * Detach an interface from everything in the kernel. Also deallocate * private resources. * XXX So far only the INET protocol family has been looked over @@ -490,10 +458,11 @@ if_detach(struct ifnet *ifp) { struct ifaddr *ifa; struct ifg_list *ifg; - int i, s = splimp(); - struct radix_node_head *rnh; + int s; struct domain *dp; + s = splimp(); + ifp->if_flags &= ~IFF_OACTIVE; ifp->if_start = if_detached_start; ifp->if_ioctl = if_detached_ioctl; @@ -529,17 +498,7 @@ if_detach(struct ifnet *ifp) altq_detach(&ifp->if_snd); #endif - /* - * Find and remove all routes which is using this interface. - * XXX Factor out into a route.c function? - */ - for (i = 1; i <= AF_MAX; i++) { - rnh = rt_tables[i]; - if (rnh) - while ((*rnh->rnh_walktree)(rnh, - if_detach_rtdelete, ifp) == EAGAIN) - ; - } + rt_if_remove(ifp); #ifdef INET rti_delete(ifp); diff --git a/sys/net/if_tun.c b/sys/net/if_tun.c index 1ec1a51b3d3..8e89ff70d1e 100644 --- a/sys/net/if_tun.c +++ b/sys/net/if_tun.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_tun.c,v 1.71 2005/11/21 18:16:45 millert Exp $ */ +/* $OpenBSD: if_tun.c,v 1.72 2005/11/25 13:45:02 henning Exp $ */ /* $NetBSD: if_tun.c,v 1.24 1996/05/07 02:40:48 thorpej Exp $ */ /* @@ -346,11 +346,9 @@ tunopen(dev_t dev, int flag, int mode, struct proc *p) int tunclose(dev_t dev, int flag, int mode, struct proc *p) { - extern int if_detach_rtdelete(struct radix_node *, void *); - int s, i; + int s; struct tun_softc *tp; struct ifnet *ifp; - struct radix_node_head *rnh; if ((tp = tun_lookup(minor(dev))) == NULL) return (ENXIO); @@ -382,17 +380,7 @@ tunclose(dev_t dev, int flag, int mode, struct proc *p) /* XXX INET6 */ #endif } - /* - * Find and remove all routes which is using this - * interface. Stolen from if.c if_detach(). - */ - for (i = 1; i <= AF_MAX; i++) { - rnh = rt_tables[i]; - if (rnh) - while ((*rnh->rnh_walktree)(rnh, - if_detach_rtdelete, ifp) == EAGAIN) - ; - } + rt_if_remove(ifp); ifp->if_flags &= ~IFF_RUNNING; } splx(s); diff --git a/sys/net/route.c b/sys/net/route.c index 8202938999e..8382d634d71 100644 --- a/sys/net/route.c +++ b/sys/net/route.c @@ -1,4 +1,4 @@ -/* $OpenBSD: route.c,v 1.57 2005/11/25 13:33:47 henning Exp $ */ +/* $OpenBSD: route.c,v 1.58 2005/11/25 13:45:02 henning Exp $ */ /* $NetBSD: route.c,v 1.14 1996/02/13 22:00:46 christos Exp $ */ /* @@ -144,6 +144,7 @@ int okaytoclone(u_int, int); int rtdeletemsg(struct rtentry *); int rtflushclone1(struct radix_node *, void *); void rtflushclone(struct radix_node_head *, struct rtentry *); +int rt_if_remove_rtdelete(struct radix_node *, void *); #define LABELID_MAX 50000 @@ -1234,3 +1235,48 @@ rtlabel_unref(u_int16_t id) } } } + +void +rt_if_remove(struct ifnet *ifp) +{ + struct radix_node_head *rnh; + int i; + + for (i = 1; i <= AF_MAX; i++) + if ((rnh = rt_tables[i]) != NULL) + while ((*rnh->rnh_walktree)(rnh, + rt_if_remove_rtdelete, ifp) == EAGAIN) + ; +} + +/* + * Delete a route if it has a specific interface for output. + * This function complies to the rn_walktree callback API. + * + * Note that deleting a RTF_CLONING route can trigger the + * deletion of more entries, so we need to cancel the walk + * and return EAGAIN. The caller should restart the walk + * as long as EAGAIN is returned. + */ +int +rt_if_remove_rtdelete(struct radix_node *rn, void *vifp) +{ + struct ifnet *ifp = vifp; + struct rtentry *rt = (struct rtentry *)rn; + + if (rt->rt_ifp == ifp) { + int cloning = (rt->rt_flags & RTF_CLONING); + + if (rtrequest(RTM_DELETE, rt_key(rt), rt->rt_gateway, + rt_mask(rt), 0, NULL) == 0 && cloning) + return (EAGAIN); + } + + /* + * XXX There should be no need to check for rt_ifa belonging to this + * interface, because then rt_ifp is set, right? + */ + + return (0); +} + diff --git a/sys/net/route.h b/sys/net/route.h index 1b3abd8156c..dd15a362b2f 100644 --- a/sys/net/route.h +++ b/sys/net/route.h @@ -1,4 +1,4 @@ -/* $OpenBSD: route.h,v 1.31 2005/06/25 19:25:06 henning Exp $ */ +/* $OpenBSD: route.h,v 1.32 2005/11/25 13:45:02 henning Exp $ */ /* $NetBSD: route.h,v 1.9 1996/02/13 22:00:49 christos Exp $ */ /* @@ -346,6 +346,7 @@ int rtrequest(int, struct sockaddr *, struct sockaddr *, struct sockaddr *, int, struct rtentry **); int rtrequest1(int, struct rt_addrinfo *, struct rtentry **); +void rt_if_remove(struct ifnet *); #endif /* _KERNEL */ #endif /* _NET_ROUTE_H_ */ |