From 6f326bf774f6709eca8f585b28402773d502cace Mon Sep 17 00:00:00 2001 From: mpi Date: Tue, 13 Oct 2015 10:29:16 +0000 Subject: [PATCH] Make use of rtisvalid(9) to check if local route entries match existing configured addressses. ok mikeb@ --- sys/netinet/ip_input.c | 12 ++++-------- sys/netinet6/ip6_input.c | 4 ++-- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/sys/netinet/ip_input.c b/sys/netinet/ip_input.c index b630e798a3d..2d8cc521d8d 100644 --- a/sys/netinet/ip_input.c +++ b/sys/netinet/ip_input.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_input.c,v 1.256 2015/09/25 09:51:20 mpi Exp $ */ +/* $OpenBSD: ip_input.c,v 1.257 2015/10/13 10:29:16 mpi Exp $ */ /* $NetBSD: ip_input.c,v 1.30 1996/03/16 23:53:58 christos Exp $ */ /* @@ -671,13 +671,9 @@ in_ouraddr(struct mbuf *m, struct ifnet *ifp, struct in_addr ina) sin.sin_family = AF_INET; sin.sin_addr = ina; rt = rtalloc(sintosa(&sin), 0, m->m_pkthdr.ph_rtableid); - if (rt != NULL) { - /* only use non-stale local address, check before route free */ - if ((rt->rt_flags & (RTF_LOCAL|RTF_BROADCAST)) && - rt->rt_ifa != NULL && rt->rt_ifa->ifa_ifp != NULL) - ia = ifatoia(rt->rt_ifa); - rtfree(rt); - } + if (rtisvalid(rt) && ISSET(rt->rt_flags, RTF_LOCAL|RTF_BROADCAST)) + ia = ifatoia(rt->rt_ifa); + rtfree(rt); if (ia == NULL) { struct ifaddr *ifa; diff --git a/sys/netinet6/ip6_input.c b/sys/netinet6/ip6_input.c index b5fd24a3e96..e1d5ea58707 100644 --- a/sys/netinet6/ip6_input.c +++ b/sys/netinet6/ip6_input.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip6_input.c,v 1.146 2015/09/11 09:54:46 claudio Exp $ */ +/* $OpenBSD: ip6_input.c,v 1.147 2015/10/13 10:29:16 mpi Exp $ */ /* $KAME: ip6_input.c,v 1.188 2001/03/29 05:34:31 itojun Exp $ */ /* @@ -445,7 +445,7 @@ ip6_input(struct mbuf *m) * Accept the packet if the route to the destination is marked * as local. */ - if (ip6_forward_rt.ro_rt && + if (rtisvalid(ip6_forward_rt.ro_rt) && ISSET(ip6_forward_rt.ro_rt->rt_flags, RTF_LOCAL)) { struct in6_ifaddr *ia6 = ifatoia6(ip6_forward_rt.ro_rt->rt_ifa); -- 2.20.1