diff options
author | Martin Pieuchot <mpi@cvs.openbsd.org> | 2015-11-18 13:58:03 +0000 |
---|---|---|
committer | Martin Pieuchot <mpi@cvs.openbsd.org> | 2015-11-18 13:58:03 +0000 |
commit | 1b5b0a48a70bb823fa605244f12bac59c59ba29c (patch) | |
tree | a7301d7733650b513f5a1517159f605dfdaf339c /sys/net | |
parent | 349255e55fb00e0ec1720b2775d046471821a9f4 (diff) |
Factorize the bits to check if a L2 route is connected, wether it is
attached to a carp(4) or bridge(4) member, to not dereference rt_ifp
directly.
ok visa@
Diffstat (limited to 'sys/net')
-rw-r--r-- | sys/net/if.c | 32 | ||||
-rw-r--r-- | sys/net/if_var.h | 4 |
2 files changed, 34 insertions, 2 deletions
diff --git a/sys/net/if.c b/sys/net/if.c index b4662375189..2f4d0399f6f 100644 --- a/sys/net/if.c +++ b/sys/net/if.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if.c,v 1.406 2015/11/13 10:18:04 mpi Exp $ */ +/* $OpenBSD: if.c,v 1.407 2015/11/18 13:58:02 mpi Exp $ */ /* $NetBSD: if.c,v 1.35 1996/05/07 05:26:04 thorpej Exp $ */ /* @@ -945,6 +945,36 @@ if_detach(struct ifnet *ifp) } /* + * Returns true if ``ifp0'' is connected to the interface with index ``ifidx''. + */ +int +if_isconnected(const struct ifnet *ifp0, unsigned int ifidx) +{ + struct ifnet *ifp; + int connected = 0; + + ifp = if_get(ifidx); + if (ifp == NULL) + return (0); + + if (ifp0->if_index == ifp->if_index) + connected = 1; + +#if NBRIDGE > 0 + if (SAME_BRIDGE(ifp0->if_bridgeport, ifp->if_bridgeport)) + connected = 1; +#endif +#if NCARP > 0 + if ((ifp0->if_type == IFT_CARP && ifp0->if_carpdev == ifp) || + (ifp->if_type == IFT_CARP && ifp->if_carpdev == ifp0)) + connected = 1; +#endif + + if_put(ifp); + return (connected); +} + +/* * Create a clone network interface. */ int diff --git a/sys/net/if_var.h b/sys/net/if_var.h index b2e70e50a1b..abc6af69dbc 100644 --- a/sys/net/if_var.h +++ b/sys/net/if_var.h @@ -1,4 +1,4 @@ -/* $OpenBSD: if_var.h,v 1.52 2015/11/11 10:23:23 mpi Exp $ */ +/* $OpenBSD: if_var.h,v 1.53 2015/11/18 13:58:02 mpi Exp $ */ /* $NetBSD: if.h,v 1.23 1996/05/07 02:40:27 thorpej Exp $ */ /* @@ -426,6 +426,8 @@ struct ifaddr *ifa_ifwithnet(struct sockaddr *, u_int); struct ifaddr *ifaof_ifpforaddr(struct sockaddr *, struct ifnet *); void ifafree(struct ifaddr *); +int if_isconnected(const struct ifnet *, unsigned int); + void if_clone_attach(struct if_clone *); void if_clone_detach(struct if_clone *); |