aboutsummaryrefslogtreecommitdiff
path: root/sys/net
diff options
context:
space:
mode:
authorAlan Somers <asomers@FreeBSD.org>2014-05-29 21:03:49 +0000
committerAlan Somers <asomers@FreeBSD.org>2014-05-29 21:03:49 +0000
commit2f308a343f533308059f6a78d1e2908129eb2f16 (patch)
treeed9260026601a89dc26686a804ac2c527bebd5a4 /sys/net
parentda4d5bb79b5ab339a421012aec52297408218e0d (diff)
downloadsrc-2f308a343f533308059f6a78d1e2908129eb2f16.tar.gz
src-2f308a343f533308059f6a78d1e2908129eb2f16.zip
Fix unintended KBI change from r264905. Add _fib versions of
ifa_ifwithnet() and ifa_ifwithdstaddr() The legacy functions will call the _fib() versions with RT_ALL_FIBS, preserving legacy behavior. sys/net/if_var.h sys/net/if.c Add legacy-compatible functions as described above. Ensure legacy behavior when RT_ALL_FIBS is passed as fibnum. sys/netinet/in_pcb.c sys/netinet/ip_output.c sys/netinet/ip_options.c sys/net/route.c sys/net/rtsock.c sys/netinet6/nd6.c Call with _fib() functions if we must use a specific fib, or the legacy functions otherwise. tests/sys/netinet/fibs_test.sh tests/sys/netinet/udp_dontroute.c Improve the udp_dontroute test. The bug that this test exercises is that ifa_ifwithnet() will return the wrong address, if multiple interfaces have addresses on the same subnet but with different fibs. The previous version of the test only considered one possible failure mode: that ifa_ifwithnet_fib() might fail to find any suitable address at all. The new version also checks whether ifa_ifwithnet_fib() finds the correct address by checking where the ARP request goes. Reported by: bz, hrs Reviewed by: hrs MFC after: 1 week X-MFC-with: 264905 Sponsored by: Spectra Logic
Notes
Notes: svn path=/head/; revision=266860
Diffstat (limited to 'sys/net')
-rw-r--r--sys/net/if.c22
-rw-r--r--sys/net/if_var.h6
-rw-r--r--sys/net/route.c10
-rw-r--r--sys/net/rtsock.c3
4 files changed, 28 insertions, 13 deletions
diff --git a/sys/net/if.c b/sys/net/if.c
index 585269a2c93b..134a6d08fa80 100644
--- a/sys/net/if.c
+++ b/sys/net/if.c
@@ -1650,7 +1650,7 @@ done:
*/
/*ARGSUSED*/
struct ifaddr *
-ifa_ifwithdstaddr(struct sockaddr *addr, int fibnum)
+ifa_ifwithdstaddr_fib(struct sockaddr *addr, int fibnum)
{
struct ifnet *ifp;
struct ifaddr *ifa;
@@ -1659,7 +1659,7 @@ ifa_ifwithdstaddr(struct sockaddr *addr, int fibnum)
TAILQ_FOREACH(ifp, &V_ifnet, if_link) {
if ((ifp->if_flags & IFF_POINTOPOINT) == 0)
continue;
- if ((ifp->if_fib != fibnum))
+ if ((fibnum != RT_ALL_FIBS) && (ifp->if_fib != fibnum))
continue;
IF_ADDR_RLOCK(ifp);
TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) {
@@ -1680,12 +1680,19 @@ done:
return (ifa);
}
+struct ifaddr *
+ifa_ifwithdstaddr(struct sockaddr *addr)
+{
+
+ return (ifa_ifwithdstaddr_fib(addr, RT_ALL_FIBS));
+}
+
/*
* Find an interface on a specific network. If many, choice
* is most specific found.
*/
struct ifaddr *
-ifa_ifwithnet(struct sockaddr *addr, int ignore_ptp, int fibnum)
+ifa_ifwithnet_fib(struct sockaddr *addr, int ignore_ptp, int fibnum)
{
struct ifnet *ifp;
struct ifaddr *ifa;
@@ -1711,7 +1718,7 @@ ifa_ifwithnet(struct sockaddr *addr, int ignore_ptp, int fibnum)
*/
IFNET_RLOCK_NOSLEEP();
TAILQ_FOREACH(ifp, &V_ifnet, if_link) {
- if (ifp->if_fib != fibnum)
+ if ((fibnum != RT_ALL_FIBS) && (ifp->if_fib != fibnum))
continue;
IF_ADDR_RLOCK(ifp);
TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) {
@@ -1796,6 +1803,13 @@ done:
return (ifa);
}
+struct ifaddr *
+ifa_ifwithnet(struct sockaddr *addr, int ignore_ptp)
+{
+
+ return (ifa_ifwithnet_fib(addr, ignore_ptp, RT_ALL_FIBS));
+}
+
/*
* Find an interface address specific to an interface best matching
* a given address.
diff --git a/sys/net/if_var.h b/sys/net/if_var.h
index c7d98a0a1fed..0e3225cde568 100644
--- a/sys/net/if_var.h
+++ b/sys/net/if_var.h
@@ -495,8 +495,10 @@ int ifa_switch_loopback_route(struct ifaddr *, struct sockaddr *, int fib);
struct ifaddr *ifa_ifwithaddr(struct sockaddr *);
int ifa_ifwithaddr_check(struct sockaddr *);
struct ifaddr *ifa_ifwithbroadaddr(struct sockaddr *);
-struct ifaddr *ifa_ifwithdstaddr(struct sockaddr *, int);
-struct ifaddr *ifa_ifwithnet(struct sockaddr *, int, int);
+struct ifaddr *ifa_ifwithdstaddr(struct sockaddr *);
+struct ifaddr *ifa_ifwithdstaddr_fib(struct sockaddr *, int);
+struct ifaddr *ifa_ifwithnet(struct sockaddr *, int);
+struct ifaddr *ifa_ifwithnet_fib(struct sockaddr *, int, int);
struct ifaddr *ifa_ifwithroute(int, struct sockaddr *, struct sockaddr *);
struct ifaddr *ifa_ifwithroute_fib(int, struct sockaddr *, struct sockaddr *, u_int);
struct ifaddr *ifaof_ifpforaddr(struct sockaddr *, struct ifnet *);
diff --git a/sys/net/route.c b/sys/net/route.c
index d6e6d932ed52..83cc857ef7b2 100644
--- a/sys/net/route.c
+++ b/sys/net/route.c
@@ -573,7 +573,7 @@ rtredirect_fib(struct sockaddr *dst,
}
/* verify the gateway is directly reachable */
- if ((ifa = ifa_ifwithnet(gateway, 0, fibnum)) == NULL) {
+ if ((ifa = ifa_ifwithnet_fib(gateway, 0, fibnum)) == NULL) {
error = ENETUNREACH;
goto out;
}
@@ -730,7 +730,7 @@ ifa_ifwithroute_fib(int flags, struct sockaddr *dst, struct sockaddr *gateway,
*/
ifa = NULL;
if (flags & RTF_HOST)
- ifa = ifa_ifwithdstaddr(dst, fibnum);
+ ifa = ifa_ifwithdstaddr_fib(dst, fibnum);
if (ifa == NULL)
ifa = ifa_ifwithaddr(gateway);
} else {
@@ -739,10 +739,10 @@ ifa_ifwithroute_fib(int flags, struct sockaddr *dst, struct sockaddr *gateway,
* or host, the gateway may still be on the
* other end of a pt to pt link.
*/
- ifa = ifa_ifwithdstaddr(gateway, fibnum);
+ ifa = ifa_ifwithdstaddr_fib(gateway, fibnum);
}
if (ifa == NULL)
- ifa = ifa_ifwithnet(gateway, 0, fibnum);
+ ifa = ifa_ifwithnet_fib(gateway, 0, fibnum);
if (ifa == NULL) {
struct rtentry *rt = rtalloc1_fib(gateway, 0, RTF_RNH_LOCKED, fibnum);
if (rt == NULL)
@@ -856,7 +856,7 @@ rt_getifa_fib(struct rt_addrinfo *info, u_int fibnum)
*/
if (info->rti_ifp == NULL && ifpaddr != NULL &&
ifpaddr->sa_family == AF_LINK &&
- (ifa = ifa_ifwithnet(ifpaddr, 0, fibnum)) != NULL) {
+ (ifa = ifa_ifwithnet_fib(ifpaddr, 0, fibnum)) != NULL) {
info->rti_ifp = ifa->ifa_ifp;
ifa_free(ifa);
}
diff --git a/sys/net/rtsock.c b/sys/net/rtsock.c
index 3a6afcaba6d7..f745f69061e1 100644
--- a/sys/net/rtsock.c
+++ b/sys/net/rtsock.c
@@ -752,8 +752,7 @@ route_output(struct mbuf *m, struct socket *so)
rt->rt_ifp->if_type == IFT_PROPVIRTUAL) {
struct ifaddr *ifa;
- ifa = ifa_ifwithnet(info.rti_info[RTAX_DST], 1,
- RT_DEFAULT_FIB);
+ ifa = ifa_ifwithnet(info.rti_info[RTAX_DST], 1);
if (ifa != NULL)
rt_maskedcopy(ifa->ifa_addr,
&laddr,