diff options
author | 2016-09-07 09:19:38 +0000 | |
---|---|---|
committer | 2016-09-07 09:19:38 +0000 | |
commit | ff42bc9df9182fe74d0e7638f258cb13118fa2c4 (patch) | |
tree | 929623dc5b89e1cc4389e61fda57a192d8b3c0a3 /sys/net/route.c | |
parent | Backport https://reviews.llvm.org/rL279449 from upstream (diff) | |
download | wireguard-openbsd-ff42bc9df9182fe74d0e7638f258cb13118fa2c4.tar.xz wireguard-openbsd-ff42bc9df9182fe74d0e7638f258cb13118fa2c4.zip |
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.c | 11 |
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); } |