summaryrefslogtreecommitdiff
path: root/sys/net/route.c
diff options
context:
space:
mode:
authorMartin Pieuchot <mpi@cvs.openbsd.org>2016-09-07 09:19:39 +0000
committerMartin Pieuchot <mpi@cvs.openbsd.org>2016-09-07 09:19:39 +0000
commita0cad255f64ece12c6cb25400c9479dd355dfda5 (patch)
treefeb9d972c9b0e104e052a121126c64c42d5bc15e /sys/net/route.c
parentcb5565b90f1f6f0e664736a60bd1fc144425315b (diff)
Only free the old cached next hop route if the new one is valid.
Leaving a NULL pointer on a RTF_GATEWAY is no longer supported, and a KASSERT() triggers. Found the hardway by and ok sthen@
Diffstat (limited to 'sys/net/route.c')
-rw-r--r--sys/net/route.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/sys/net/route.c b/sys/net/route.c
index 3d91064650a..f0f408faed2 100644
--- a/sys/net/route.c
+++ b/sys/net/route.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: route.c,v 1.325 2016/09/04 15:45:42 bluhm Exp $ */
+/* $OpenBSD: route.c,v 1.326 2016/09/07 09:19:38 mpi Exp $ */
/* $NetBSD: route.c,v 1.14 1996/02/13 22:00:46 christos Exp $ */
/*
@@ -382,7 +382,6 @@ rt_setgwroute(struct rtentry *rt, u_int rtableid)
KERNEL_ASSERT_LOCKED();
KASSERT(ISSET(rt->rt_flags, RTF_GATEWAY));
- KASSERT(rt->rt_gwroute == NULL);
/* If we cannot find a valid next hop bail. */
nhrt = rt_match(rt->rt_gateway, NULL, RT_RESOLVE, rtable_l2(rtableid));
@@ -404,6 +403,10 @@ rt_setgwroute(struct rtentry *rt, u_int rtableid)
return (ELOOP);
}
+ /* Next hop is valid so remove possible old cache. */
+ rt_putgwroute(rt);
+ KASSERT(rt->rt_gwroute == NULL);
+
/*
* If the MTU of next hop is 0, this will reset the MTU of the
* route to run PMTUD again from scratch.
@@ -1139,10 +1142,8 @@ rt_setgate(struct rtentry *rt, struct sockaddr *gate, u_int rtableid)
}
memmove(rt->rt_gateway, gate, glen);
- if (ISSET(rt->rt_flags, RTF_GATEWAY)) {
- rt_putgwroute(rt);
+ if (ISSET(rt->rt_flags, RTF_GATEWAY))
return (rt_setgwroute(rt, rtableid));
- }
return (0);
}