Module Name: src
Committed By: ozaki-r
Date: Wed Sep 2 11:35:12 UTC 2015
Modified Files:
src/sys/net: route.h
src/sys/netinet: ip_output.c
src/sys/netinet6: nd6.c
Log Message:
Do rt_refcnt++ when set a rtentry to another rtentry's rt_gwroute
And also do rtfree when deref a rtentry from rt_gwroute.
To generate a diff of this commit:
cvs rdiff -u -r1.95 -r1.96 src/sys/net/route.h
cvs rdiff -u -r1.246 -r1.247 src/sys/netinet/ip_output.c
cvs rdiff -u -r1.173 -r1.174 src/sys/netinet6/nd6.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/net/route.h
diff -u src/sys/net/route.h:1.95 src/sys/net/route.h:1.96
--- src/sys/net/route.h:1.95 Mon Aug 31 08:02:44 2015
+++ src/sys/net/route.h Wed Sep 2 11:35:11 2015
@@ -1,4 +1,4 @@
-/* $NetBSD: route.h,v 1.95 2015/08/31 08:02:44 ozaki-r Exp $ */
+/* $NetBSD: route.h,v 1.96 2015/09/02 11:35:11 ozaki-r Exp $ */
/*
* Copyright (c) 1980, 1986, 1993
@@ -414,6 +414,15 @@ rt_get_gwroute(struct rtentry *rt)
}
static inline void
+rt_set_gwroute(struct rtentry *rt, struct rtentry *gwrt)
+{
+
+ rt->rt_gwroute = gwrt;
+ if (rt->rt_gwroute != NULL)
+ rt->rt_gwroute->rt_refcnt++;
+}
+
+static inline void
rt_assert_referenced(const struct rtentry *rt)
{
Index: src/sys/netinet/ip_output.c
diff -u src/sys/netinet/ip_output.c:1.246 src/sys/netinet/ip_output.c:1.247
--- src/sys/netinet/ip_output.c:1.246 Mon Aug 24 22:21:26 2015
+++ src/sys/netinet/ip_output.c Wed Sep 2 11:35:11 2015
@@ -1,4 +1,4 @@
-/* $NetBSD: ip_output.c,v 1.246 2015/08/24 22:21:26 pooka Exp $ */
+/* $NetBSD: ip_output.c,v 1.247 2015/09/02 11:35:11 ozaki-r Exp $ */
/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -91,7 +91,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ip_output.c,v 1.246 2015/08/24 22:21:26 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip_output.c,v 1.247 2015/09/02 11:35:11 ozaki-r Exp $");
#ifdef _KERNEL_OPT
#include "opt_inet.h"
@@ -260,7 +260,8 @@ retry:
error = EHOSTUNREACH;
goto bad;
}
- gwrt = rt->rt_gwroute = rtalloc1(rt->rt_gateway, 1);
+ gwrt = rtalloc1(rt->rt_gateway, 1);
+ rt_set_gwroute(rt, gwrt);
RTFREE_IF_NEEDED(rt);
rt = gwrt;
if (rt == NULL) {
@@ -269,6 +270,8 @@ retry:
}
/* the "G" test below also prevents rt == rt0 */
if ((rt->rt_flags & RTF_GATEWAY) != 0 || rt->rt_ifp != ifp) {
+ if (rt0->rt_gwroute != NULL)
+ rtfree(rt0->rt_gwroute);
rt0->rt_gwroute = NULL;
error = EHOSTUNREACH;
goto bad;
Index: src/sys/netinet6/nd6.c
diff -u src/sys/netinet6/nd6.c:1.173 src/sys/netinet6/nd6.c:1.174
--- src/sys/netinet6/nd6.c:1.173 Wed Sep 2 08:03:10 2015
+++ src/sys/netinet6/nd6.c Wed Sep 2 11:35:11 2015
@@ -1,4 +1,4 @@
-/* $NetBSD: nd6.c,v 1.173 2015/09/02 08:03:10 ozaki-r Exp $ */
+/* $NetBSD: nd6.c,v 1.174 2015/09/02 11:35:11 ozaki-r Exp $ */
/* $KAME: nd6.c,v 1.279 2002/06/08 11:16:51 itojun Exp $ */
/*
@@ -31,7 +31,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: nd6.c,v 1.173 2015/09/02 08:03:10 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nd6.c,v 1.174 2015/09/02 11:35:11 ozaki-r Exp $");
#ifdef _KERNEL_OPT
#include "opt_net_mpsafe.h"
@@ -2215,8 +2215,8 @@ nd6_output(struct ifnet *ifp, struct ifn
rtfree(rt);
rt = rt0;
lookup:
- gwrt = rt->rt_gwroute =
- rtalloc1(rt->rt_gateway, 1);
+ gwrt = rtalloc1(rt->rt_gateway, 1);
+ rt_set_gwroute(rt, gwrt);
rtfree(rt);
rt = gwrt;
if (rt == NULL)
@@ -2224,6 +2224,8 @@ nd6_output(struct ifnet *ifp, struct ifn
/* the "G" test below also prevents rt == rt0 */
if ((rt->rt_flags & RTF_GATEWAY) ||
(rt->rt_ifp != ifp)) {
+ if (rt0->rt_gwroute != NULL)
+ rtfree(rt0->rt_gwroute);
rt0->rt_gwroute = NULL;
senderr(EHOSTUNREACH);
}