Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys Do rt_refcnt++ when set a rtentry to another rtentry's r...



details:   https://anonhg.NetBSD.org/src/rev/8b43c58f555b
branches:  trunk
changeset: 810519:8b43c58f555b
user:      ozaki-r <ozaki-r%NetBSD.org@localhost>
date:      Wed Sep 02 11:35:11 2015 +0000

description:
Do rt_refcnt++ when set a rtentry to another rtentry's rt_gwroute

And also do rtfree when deref a rtentry from rt_gwroute.

diffstat:

 sys/net/route.h         |  11 ++++++++++-
 sys/netinet/ip_output.c |   9 ++++++---
 sys/netinet6/nd6.c      |  10 ++++++----
 3 files changed, 22 insertions(+), 8 deletions(-)

diffs (100 lines):

diff -r 71f6d1c51cce -r 8b43c58f555b sys/net/route.h
--- a/sys/net/route.h   Wed Sep 02 11:33:30 2015 +0000
+++ b/sys/net/route.h   Wed Sep 02 11:35:11 2015 +0000
@@ -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 @@
 }
 
 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)
 {
 
diff -r 71f6d1c51cce -r 8b43c58f555b sys/netinet/ip_output.c
--- a/sys/netinet/ip_output.c   Wed Sep 02 11:33:30 2015 +0000
+++ b/sys/netinet/ip_output.c   Wed Sep 02 11:35:11 2015 +0000
@@ -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 @@
                        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 @@
                }
                /* 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;
diff -r 71f6d1c51cce -r 8b43c58f555b sys/netinet6/nd6.c
--- a/sys/netinet6/nd6.c        Wed Sep 02 11:33:30 2015 +0000
+++ b/sys/netinet6/nd6.c        Wed Sep 02 11:35:11 2015 +0000
@@ -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 @@
                                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 @@
                                /* 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);
                                }



Home | Main Index | Thread Index | Old Index