diff options
author | Martin Pieuchot <mpi@cvs.openbsd.org> | 2016-08-22 16:54:00 +0000 |
---|---|---|
committer | Martin Pieuchot <mpi@cvs.openbsd.org> | 2016-08-22 16:54:00 +0000 |
commit | c915ea048607278aaac5b0ebb4b7812d802e9b6b (patch) | |
tree | 52cfe4f4518cb2cfd950d248a2df5194c4d13c8f /sys | |
parent | b33e54f98ab86c22ddd359a345d653c50713d8c8 (diff) |
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.
This also fix rttest20 after the introduction of RTF_CACHED.
ok vgross@
Diffstat (limited to 'sys')
-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 eed062d2b42..bfa5925e1da 100644 --- a/sys/net/route.c +++ b/sys/net/route.c @@ -1,4 +1,4 @@ -/* $OpenBSD: route.c,v 1.316 2016/08/22 16:01:52 mpi Exp $ */ +/* $OpenBSD: route.c,v 1.317 2016/08/22 16:53:59 mpi Exp $ */ /* $NetBSD: route.c,v 1.14 1996/02/13 22:00:46 christos Exp $ */ /* @@ -797,20 +797,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); |