diff options
author | 2016-06-07 08:30:01 +0000 | |
---|---|---|
committer | 2016-06-07 08:30:01 +0000 | |
commit | b811b03f891b991a51075d1b0d23b0a3dd36168d (patch) | |
tree | 3fc281c3315c96dfc4506067e46ee32dd73331f7 /sys/net/route.c | |
parent | Adapt compat layers after recent changes: srp_swap() and the GC task (diff) | |
download | wireguard-openbsd-b811b03f891b991a51075d1b0d23b0a3dd36168d.tar.xz wireguard-openbsd-b811b03f891b991a51075d1b0d23b0a3dd36168d.zip |
Use rtalloc(9) instead of ifa_ifwithnet() to find an interface
when adding a route to gateway to ensure a most specific match.
This makes "# route add" coherent to "# route get" even with
p2p interfaces. Fix a problem reported by Mart Tõnso.
ok vgross@
Diffstat (limited to 'sys/net/route.c')
-rw-r--r-- | sys/net/route.c | 20 |
1 files changed, 8 insertions, 12 deletions
diff --git a/sys/net/route.c b/sys/net/route.c index fd7e4620c9c..519d9e01d63 100644 --- a/sys/net/route.c +++ b/sys/net/route.c @@ -1,4 +1,4 @@ -/* $OpenBSD: route.c,v 1.305 2016/06/03 10:34:07 mpi Exp $ */ +/* $OpenBSD: route.c,v 1.306 2016/06/07 08:30:01 mpi Exp $ */ /* $NetBSD: route.c,v 1.14 1996/02/13 22:00:46 christos Exp $ */ /* @@ -744,20 +744,16 @@ ifa_ifwithroute(int flags, struct sockaddr *dst, struct sockaddr *gateway, ifa = ifaof_ifpforaddr(dst, ifp); if_put(ifp); } else { - ifa = ifa_ifwithnet(gateway, rtableid); - } - } - if (ifa == NULL) { - struct rtentry *rt = rtalloc(gateway, 0, rtableid); - /* The gateway must be local if the same address family. */ - if (!rtisvalid(rt) || ((rt->rt_flags & RTF_GATEWAY) && - rt_key(rt)->sa_family == dst->sa_family)) { + struct rtentry *rt; + + rt = rtalloc(gateway, RT_RESOLVE, rtableid); + if (rt != NULL) + ifa = rt->rt_ifa; rtfree(rt); - return (NULL); } - ifa = rt->rt_ifa; - rtfree(rt); } + if (ifa == NULL) + return (NULL); if (ifa->ifa_addr->sa_family != dst->sa_family) { struct ifaddr *oifa = ifa; ifa = ifaof_ifpforaddr(dst, ifa->ifa_ifp); |