From cc67c657e094ce118ef3c4b6ab2c7e06e28eee7c Mon Sep 17 00:00:00 2001 From: Bruce M Simpson Date: Mon, 5 Feb 2007 11:15:52 +0000 Subject: [PATCH] Clean up after tun(4) properly; remove routes whose ifp is set to that of the tun instance even for the !AF_INET case, and properly remove configured addresses by calling if_purgeaddrs(). Maintain the TUN_DSTADDR behaviour for compatibility with the OS/390 emulator. MFC after: 3 weeks PR: 100080 Reviewed by: bz --- sys/net/if_tun.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/sys/net/if_tun.c b/sys/net/if_tun.c index efd57a2ce7f..61f08d7ded0 100644 --- a/sys/net/if_tun.c +++ b/sys/net/if_tun.c @@ -458,16 +458,21 @@ tunclose(struct cdev *dev, int foo, int bar, struct thread *td) 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); }