summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorMartin Pieuchot <mpi@cvs.openbsd.org>2016-04-19 08:23:14 +0000
committerMartin Pieuchot <mpi@cvs.openbsd.org>2016-04-19 08:23:14 +0000
commit97c55638692ca49b78b34b6b09a24864767d8dd0 (patch)
tree6268187d7e7b8852529c87dc67918e9326b74726 /sys
parent0a851c56f2f6d600c64a908b72be7e46e48faf62 (diff)
Instead of freeing a cached RTF_MPATH route after using it, free it
when the next packet needs to be forwarded, just like if the route was invalid. ok mikeb@, claudio@
Diffstat (limited to 'sys')
-rw-r--r--sys/netinet/ip_input.c20
-rw-r--r--sys/netinet6/ip6_forward.c29
-rw-r--r--sys/netinet6/ip6_input.c3
3 files changed, 19 insertions, 33 deletions
diff --git a/sys/netinet/ip_input.c b/sys/netinet/ip_input.c
index 2dd0b36056c..4da9325a738 100644
--- a/sys/netinet/ip_input.c
+++ b/sys/netinet/ip_input.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ip_input.c,v 1.272 2016/04/18 12:10:34 mpi Exp $ */
+/* $OpenBSD: ip_input.c,v 1.273 2016/04/19 08:23:13 mpi Exp $ */
/* $NetBSD: ip_input.c,v 1.30 1996/03/16 23:53:58 christos Exp $ */
/*
@@ -1416,8 +1416,9 @@ ip_forward(struct mbuf *m, struct ifnet *ifp, int srcrt)
rtableid = m->m_pkthdr.ph_rtableid;
+ rt = ipforward_rt.ro_rt;
sin = satosin(&ipforward_rt.ro_dst);
- if ((rt = ipforward_rt.ro_rt) == NULL ||
+ if (rt == NULL || ISSET(rt->rt_flags, RTF_MPATH) ||
ip->ip_dst.s_addr != sin->sin_addr.s_addr ||
rtableid != ipforward_rt.ro_tableid) {
if (ipforward_rt.ro_rt) {
@@ -1500,7 +1501,7 @@ ip_forward(struct mbuf *m, struct ifnet *ifp, int srcrt)
goto freecopy;
}
if (!fake)
- goto freert;
+ return;
switch (error) {
@@ -1522,9 +1523,7 @@ ip_forward(struct mbuf *m, struct ifnet *ifp, int srcrt)
code = ICMP_UNREACH_NEEDFRAG;
#ifdef IPSEC
- if (ipforward_rt.ro_rt) {
- struct rtentry *rt = ipforward_rt.ro_rt;
-
+ if (rt != NULL) {
if (rt->rt_rmx.rmx_mtu)
destmtu = rt->rt_rmx.rmx_mtu;
else {
@@ -1563,15 +1562,6 @@ ip_forward(struct mbuf *m, struct ifnet *ifp, int srcrt)
freecopy:
if (fake)
m_tag_delete_chain(&mfake);
- freert:
-#ifndef SMALL_KERNEL
- if (ipmultipath && ipforward_rt.ro_rt &&
- (ipforward_rt.ro_rt->rt_flags & RTF_MPATH)) {
- rtfree(ipforward_rt.ro_rt);
- ipforward_rt.ro_rt = NULL;
- }
-#endif
- return;
}
int
diff --git a/sys/netinet6/ip6_forward.c b/sys/netinet6/ip6_forward.c
index 3a837ff3703..b836849fa24 100644
--- a/sys/netinet6/ip6_forward.c
+++ b/sys/netinet6/ip6_forward.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ip6_forward.c,v 1.87 2016/03/29 11:57:51 chl Exp $ */
+/* $OpenBSD: ip6_forward.c,v 1.88 2016/04/19 08:23:13 mpi Exp $ */
/* $KAME: ip6_forward.c,v 1.75 2001/06/29 12:42:13 jinmei Exp $ */
/*
@@ -225,6 +225,7 @@ reroute:
* ip6_forward_rt.ro_dst.sin6_addr is equal to ip6->ip6_dst
*/
if (!rtisvalid(ip6_forward_rt.ro_rt) ||
+ ISSET(ip6_forward_rt.ro_rt->rt_flags, RTF_MPATH) ||
ip6_forward_rt.ro_tableid != rtableid) {
if (ip6_forward_rt.ro_rt) {
rtfree(ip6_forward_rt.ro_rt);
@@ -248,6 +249,7 @@ reroute:
return;
}
} else if (!rtisvalid(ip6_forward_rt.ro_rt) ||
+ ISSET(ip6_forward_rt.ro_rt->rt_flags, RTF_MPATH) ||
!IN6_ARE_ADDR_EQUAL(&ip6->ip6_dst, &dst->sin6_addr) ||
ip6_forward_rt.ro_tableid != rtableid) {
if (ip6_forward_rt.ro_rt) {
@@ -303,7 +305,7 @@ reroute:
icmp6_error(mcopy, ICMP6_DST_UNREACH,
ICMP6_DST_UNREACH_BEYONDSCOPE, 0);
m_freem(m);
- goto freert;
+ goto out;
}
#ifdef IPSEC
@@ -346,7 +348,7 @@ reroute:
/* Callee frees mbuf */
error = ipsp_process_packet(m, tdb, AF_INET6, 0);
m_freem(mcopy);
- goto freert;
+ goto out;
}
#endif /* IPSEC */
@@ -387,7 +389,7 @@ reroute:
icmp6_error(mcopy, ICMP6_DST_UNREACH,
ICMP6_DST_UNREACH_ADDR, 0);
m_freem(m);
- goto freert;
+ goto out;
}
type = ND_REDIRECT;
}
@@ -434,7 +436,7 @@ reroute:
icmp6_error(mcopy, ICMP6_PACKET_TOO_BIG, 0,
ifp->if_mtu);
m_freem(m);
- goto freert;
+ goto out;
}
error = nd6_output(ifp, m, dst, rt);
@@ -454,12 +456,12 @@ reroute:
senderr:
#endif
if (mcopy == NULL)
- goto freert;
+ goto out;
switch (error) {
case 0:
if (type == ND_REDIRECT) {
icmp6_redirect_output(mcopy, rt);
- goto freert;
+ goto out;
}
goto freecopy;
@@ -481,17 +483,10 @@ senderr:
break;
}
icmp6_error(mcopy, type, code, 0);
- goto freert;
+ goto out;
- freecopy:
+freecopy:
m_freem(mcopy);
- freert:
-#ifndef SMALL_KERNEL
- if (ip6_multipath && ip6_forward_rt.ro_rt &&
- (ip6_forward_rt.ro_rt->rt_flags & RTF_MPATH)) {
- rtfree(ip6_forward_rt.ro_rt);
- ip6_forward_rt.ro_rt = NULL;
- }
-#endif
+out:
if_put(ifp);
}
diff --git a/sys/netinet6/ip6_input.c b/sys/netinet6/ip6_input.c
index 7a0441a036b..e9d318cf489 100644
--- a/sys/netinet6/ip6_input.c
+++ b/sys/netinet6/ip6_input.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ip6_input.c,v 1.157 2016/04/11 13:02:35 mpi Exp $ */
+/* $OpenBSD: ip6_input.c,v 1.158 2016/04/19 08:23:13 mpi Exp $ */
/* $KAME: ip6_input.c,v 1.188 2001/03/29 05:34:31 itojun Exp $ */
/*
@@ -422,6 +422,7 @@ ip6_input(struct mbuf *m)
* Unicast check
*/
if (rtisvalid(ip6_forward_rt.ro_rt) &&
+ !ISSET(ip6_forward_rt.ro_rt->rt_flags, RTF_MPATH) &&
IN6_ARE_ADDR_EQUAL(&ip6->ip6_dst,
&ip6_forward_rt.ro_dst.sin6_addr) &&
rtableid == ip6_forward_rt.ro_tableid)