From nobody@FreeBSD.org  Thu Nov  8 15:22:04 2012
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52])
	by hub.freebsd.org (Postfix) with ESMTP id DCF7A438
	for <freebsd-gnats-submit@FreeBSD.org>; Thu,  8 Nov 2012 15:22:04 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from red.freebsd.org (red.freebsd.org [IPv6:2001:4f8:fff6::22])
	by mx1.freebsd.org (Postfix) with ESMTP id C50298FC14
	for <freebsd-gnats-submit@FreeBSD.org>; Thu,  8 Nov 2012 15:22:04 +0000 (UTC)
Received: from red.freebsd.org (localhost [127.0.0.1])
	by red.freebsd.org (8.14.5/8.14.5) with ESMTP id qA8FM4jA052815
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 8 Nov 2012 15:22:04 GMT
	(envelope-from nobody@red.freebsd.org)
Received: (from nobody@localhost)
	by red.freebsd.org (8.14.5/8.14.5/Submit) id qA8FM3Lr052814;
	Thu, 8 Nov 2012 15:22:03 GMT
	(envelope-from nobody)
Message-Id: <201211081522.qA8FM3Lr052814@red.freebsd.org>
Date: Thu, 8 Nov 2012 15:22:03 GMT
From: Ralf Wenk <IZ-FreeBSD0701@hs-karlsruhe.de>
To: freebsd-gnats-submit@FreeBSD.org
Subject: /dev/tun stayes opened by PID after process is terminated
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         173475
>Category:       kern
>Synopsis:       [tun] tun(4) stays opened by PID after process is terminated
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-net
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Nov 08 15:30:01 UTC 2012
>Closed-Date:    
>Last-Modified:  Tue Feb 12 11:30:00 UTC 2013
>Originator:     Ralf Wenk
>Release:        FreeBSD 10.0-CURRENT i386
>Organization:
Hochschule Karlsruhe, University of Applied Sciences
>Environment:
FreeBSD IZ-T193196065251a 10.0-CURRENT FreeBSD 10.0-CURRENT #0: Thu Nov  8 11:48:33 CET 2012     root@IZ-T193196065251a:/usr/obj/usr/src/sys/E4300  i386
>Description:
After the first use of a tun interface with vpnc I am unable to reuse it,
getting the error message "Failed to bind to 0.0.0.0:500: Address already in use".

netstat shows the connection as active:
# netstat -anf inet
Active Internet connections (including servers)
Proto Recv-Q Send-Q Local Address          Foreign Address        (state)
udp4       0      0 193.196.65.251.500     193.196.64.233.500     

ifconfig tun0 and tun1 showed tun0 is still opened by the PID of the vpnc-process:
tun0: flags=8051<UP,POINTOPOINT,RUNNING,MULTICAST> metric 0 mtu 1412
        options=80000<LINKSTATE>
        inet 192.168.120.10 --> 192.168.120.10 netmask 0xffffffff 
        nd6 options=29<PERFORMNUD,IFDISABLED,AUTO_LINKLOCAL>
        Opened by PID 1469
tun1: flags=8010<POINTOPOINT,MULTICAST> metric 0 mtu 1500
        options=80000<LINKSTATE>
        nd6 options=29<PERFORMNUD,IFDISABLED,AUTO_LINKLOCAL>

but the process has been terminated:

# ps ax | grep 1469
1916  3  S+    0:00.01 grep 1469

This could be a regession because I was using vpnc on FreeBSD 8 without such
a problem.
>How-To-Repeat:
Generate the tun-interfaces by starting vpnc. Then terminate vpnc and try to
restart vpnc. The address is and stays in use.
If there was network traffic over the VPN tunnel when the vpnc-process terminates
netstat shows Send-Q is not zero and that stays till the next reboot as well.
>Fix:


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->freebsd-net 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Thu Nov 8 23:43:39 UTC 2012 
Responsible-Changed-Why:  
Over to maintainer(s). 

http://www.freebsd.org/cgi/query-pr.cgi?pr=173475 

From: Emanuel Haupt <ehaupt@FreeBSD.org>
To: bug-followup@FreeBSD.org, IZ-FreeBSD0701@hs-karlsruhe.de
Cc:  
Subject: Re: kern/173475: [tun] tun(4) stays opened by PID after process is
 terminated
Date: Wed, 23 Jan 2013 07:59:07 +0100

 Could you please try the following vpnc patch? It tries to work around
 this deadlock situation:
 
 http://www.freebsd.org/cgi/query-pr.cgi?pr=ports/175067
 
 However, the underlying problem with if_tun should be looked at
 separately in this PR.
 
 Emanuel

From: Ralf Wenk <IZ-FreeBSD0701@hs-karlsruhe.de>
To: Emanuel Haupt <ehaupt@FreeBSD.org>
Cc: bug-followup@FreeBSD.org
Subject: Re: kern/173475: [tun] tun(4) stays opened by PID after process is 
 terminated
Date: Tue, 12 Feb 2013 12:27:12 +0100

 > Could you please try the following vpnc patch? It tries to work around
 > this deadlock situation:
 > 
 > http://www.freebsd.org/cgi/query-pr.cgi?pr=ports/175067
 > 
 > However, the underlying problem with if_tun should be looked at
 > separately in this PR.
 > 
 > Emanuel
 
 Tried today with a newer (r245247) kernel than at the date of the bug report.
 
 Without the patch the behavior was as described.
 With the patch repeated use of vpnc, vpnc-disconnect works again. So this
 patch is a sufficient workaround.
 
 Ralf
 
>Unformatted:
