Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 02 Feb 2007 23:35:51 +0000
From:      Bruce M Simpson <bms@incunabulum.net>
To:        freebsd-net@freebsd.org
Subject:   [PATCH] tun(4) does not clean up after itself
Message-ID:  <45C3CAD7.8040704@incunabulum.net>

next in thread | raw e-mail | index | archive | help
This is a multi-part message in MIME format.
--------------030709000202000402000806
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Hi,

I just saw this PR:
    http://www.freebsd.org/cgi/query-pr.cgi?pr=kern/100080

This patch appears to fix the problem. Any obvious glaring errors?

Testers please?

Regards,
BMS

--------------030709000202000402000806
Content-Type: text/x-patch;
 name="tun-cleanup.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="tun-cleanup.diff"

Index: if_tun.c
===================================================================
RCS file: /home/ncvs/src/sys/net/if_tun.c,v
retrieving revision 1.161
diff -u -p -r1.161 if_tun.c
--- if_tun.c	6 Nov 2006 13:42:02 -0000	1.161
+++ if_tun.c	2 Feb 2007 23:30:04 -0000
@@ -388,16 +388,21 @@ tunclose(struct cdev *dev, int foo, int 
 		splx(s);
 	}
 
+	/* Delete all addresses and routes which reference this interface. */
 	if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
 		struct ifaddr *ifa;
 
 		s = splimp();
-		/* find internet addresses and delete routes */
-		TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link)
-			if (ifa->ifa_addr->sa_family == AF_INET)
-				/* Unlocked read. */
+		TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) {
+			/* deal w/IPv4 PtP destination; unlocked read */
+			if (ifa->ifa_addr->sa_family == AF_INET) {
 				rtinit(ifa, (int)RTM_DELETE,
 				    tp->tun_flags & TUN_DSTADDR ? RTF_HOST : 0);
+			} else {
+				rtinit(ifa, (int)RTM_DELETE, 0);
+			}
+		}
+		if_purgeaddrs(ifp);
 		ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
 		splx(s);
 	}

--------------030709000202000402000806--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?45C3CAD7.8040704>