diff options
-rw-r--r-- | sys/net/if.c | 32 | ||||
-rw-r--r-- | sys/net/if_var.h | 4 | ||||
-rw-r--r-- | sys/netinet/if_ether.c | 15 | ||||
-rw-r--r-- | sys/netinet6/in6.c | 44 | ||||
-rw-r--r-- | sys/netinet6/in6_var.h | 3 | ||||
-rw-r--r-- | sys/netinet6/nd6_nbr.c | 32 |
6 files changed, 67 insertions, 63 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 *); diff --git a/sys/netinet/if_ether.c b/sys/netinet/if_ether.c index 03f7c5562cb..bdb51f35317 100644 --- a/sys/netinet/if_ether.c +++ b/sys/netinet/if_ether.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_ether.c,v 1.187 2015/11/18 13:53:59 mpi Exp $ */ +/* $OpenBSD: if_ether.c,v 1.188 2015/11/18 13:58:02 mpi Exp $ */ /* $NetBSD: if_ether.c,v 1.31 1996/05/11 12:59:58 mycroft Exp $ */ /* @@ -604,18 +604,7 @@ in_arpinput(struct mbuf *m) } changed = 1; } - } else if (rt->rt_ifp != ifp && -#if NBRIDGE > 0 - !SAME_BRIDGE(ifp->if_bridgeport, - rt->rt_ifp->if_bridgeport) && -#endif -#if NCARP > 0 - !(rt->rt_ifp->if_type == IFT_CARP && - rt->rt_ifp->if_carpdev == ifp) && - !(ifp->if_type == IFT_CARP && - ifp->if_carpdev == rt->rt_ifp) && -#endif - 1) { + } else if (!if_isconnected(ifp, rt->rt_ifidx)) { inet_ntop(AF_INET, &isaddr, addr, sizeof(addr)); log(LOG_WARNING, "arp: attempt to add entry for %s " diff --git a/sys/netinet6/in6.c b/sys/netinet6/in6.c index 402199b9ca4..bfc18499ec8 100644 --- a/sys/netinet6/in6.c +++ b/sys/netinet6/in6.c @@ -1,4 +1,4 @@ -/* $OpenBSD: in6.c,v 1.178 2015/11/02 15:05:23 mpi Exp $ */ +/* $OpenBSD: in6.c,v 1.179 2015/11/18 13:58:02 mpi Exp $ */ /* $KAME: in6.c,v 1.372 2004/06/14 08:14:21 itojun Exp $ */ /* @@ -61,7 +61,6 @@ * @(#)in.c 8.2 (Berkeley) 11/15/93 */ -#include "bridge.h" #include "carp.h" #include <sys/param.h> @@ -84,9 +83,6 @@ #include <netinet/in.h> #include <netinet/if_ether.h> -#if NBRIDGE > 0 -#include <net/if_bridge.h> -#endif #include <netinet6/in6_var.h> #include <netinet/ip6.h> @@ -1451,44 +1447,6 @@ in6ifa_ifpwithaddr(struct ifnet *ifp, struct in6_addr *addr) } /* - * Check whether an interface has a prefix by looking up the cloning route. - */ -int -in6_ifpprefix(const struct ifnet *ifp, const struct in6_addr *addr) -{ - struct sockaddr_in6 dst; - struct rtentry *rt; - u_int tableid = ifp->if_rdomain; - - bzero(&dst, sizeof(dst)); - dst.sin6_len = sizeof(struct sockaddr_in6); - dst.sin6_family = AF_INET6; - dst.sin6_addr = *addr; - rt = rtalloc(sin6tosa(&dst), 0, tableid); - - if (rt == NULL) - return (0); - if ((rt->rt_flags & (RTF_CLONING | RTF_CLONED)) == 0 || - (rt->rt_ifp != ifp && -#if NBRIDGE > 0 - !SAME_BRIDGE(rt->rt_ifp->if_bridgeport, ifp->if_bridgeport) && -#endif -#if NCARP > 0 - (ifp->if_type != IFT_CARP || rt->rt_ifp != ifp->if_carpdev) && - (rt->rt_ifp->if_type != IFT_CARP || rt->rt_ifp->if_carpdev != ifp)&& - (ifp->if_type != IFT_CARP || rt->rt_ifp->if_type != IFT_CARP || - rt->rt_ifp->if_carpdev != ifp->if_carpdev) && -#endif - 1)) { - rtfree(rt); - return (0); - } - - rtfree(rt); - return (1); -} - -/* * Get a scope of the address. Node-local, link-local, site-local or global. */ int diff --git a/sys/netinet6/in6_var.h b/sys/netinet6/in6_var.h index fa498bd348c..700b8f4a366 100644 --- a/sys/netinet6/in6_var.h +++ b/sys/netinet6/in6_var.h @@ -1,4 +1,4 @@ -/* $OpenBSD: in6_var.h,v 1.57 2015/10/05 01:22:34 deraadt Exp $ */ +/* $OpenBSD: in6_var.h,v 1.58 2015/11/18 13:58:02 mpi Exp $ */ /* $KAME: in6_var.h,v 1.55 2001/02/16 12:49:45 itojun Exp $ */ /* @@ -506,7 +506,6 @@ void *in6_domifattach(struct ifnet *); void in6_domifdetach(struct ifnet *, void *); struct in6_ifaddr *in6ifa_ifpforlinklocal(struct ifnet *, int); struct in6_ifaddr *in6ifa_ifpwithaddr(struct ifnet *, struct in6_addr *); -int in6_ifpprefix(const struct ifnet *, const struct in6_addr *); int in6_addr2scopeid(unsigned int, struct in6_addr *); int in6_matchlen(struct in6_addr *, struct in6_addr *); int in6_are_prefix_equal(struct in6_addr *, struct in6_addr *, int); diff --git a/sys/netinet6/nd6_nbr.c b/sys/netinet6/nd6_nbr.c index e138d21dcf6..168de6e8a4d 100644 --- a/sys/netinet6/nd6_nbr.c +++ b/sys/netinet6/nd6_nbr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: nd6_nbr.c,v 1.99 2015/11/02 15:05:23 mpi Exp $ */ +/* $OpenBSD: nd6_nbr.c,v 1.100 2015/11/18 13:58:02 mpi Exp $ */ /* $KAME: nd6_nbr.c,v 1.61 2001/02/10 16:06:14 jinmei Exp $ */ /* @@ -81,6 +81,8 @@ void nd6_dad_ns_output(struct dadq *, struct ifaddr *); void nd6_dad_ns_input(struct ifaddr *); void nd6_dad_duplicated(struct dadq *); +int nd6_isneighbor(const struct ifnet *, const struct in6_addr *); + static int dad_maxtry = 15; /* max # of *tries* to transmit DAD packet */ /* @@ -149,7 +151,7 @@ nd6_ns_input(struct mbuf *m, int off, int icmp6len) /* * Make sure the source address is from a neighbor's address. */ - if (!in6_ifpprefix(ifp, &saddr6)) { + if (!nd6_isneighbor(ifp, &saddr6)) { nd6log((LOG_INFO, "nd6_ns_input: " "NS packet from non-neighbor\n")); goto bad; @@ -684,7 +686,7 @@ nd6_na_input(struct mbuf *m, int off, int icmp6len) /* * Make sure the source address is from a neighbor's address. */ - if (!in6_ifpprefix(ifp, &saddr6)) { + if (!nd6_isneighbor(ifp, &saddr6)) { nd6log((LOG_INFO, "nd6_na_input: " "ND packet from non-neighbor\n")); goto bad; @@ -1406,3 +1408,27 @@ nd6_dad_ns_input(struct ifaddr *ifa) dp->dad_ns_icount++; } } + +/* + * Check whether ``addr'' is a neighbor address connected to ``ifp''. + */ +int +nd6_isneighbor(const struct ifnet *ifp, const struct in6_addr *addr) +{ + struct rtentry *rt; + struct sockaddr_in6 sin6; + unsigned int tableid = ifp->if_rdomain; + int rv = 0; + + memset(&sin6, 0, sizeof(sin6)); + sin6.sin6_len = sizeof(struct sockaddr_in6); + sin6.sin6_family = AF_INET6; + sin6.sin6_addr = *addr; + rt = rtalloc(sin6tosa(&sin6), 0, tableid); + + if (rtisvalid(rt) && ISSET(rt->rt_flags, RTF_CLONING|RTF_CLONED)) + rv = if_isconnected(ifp, rt->rt_ifidx); + + rtfree(rt); + return (rv); +} |