tech-net archive

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

Re: destroy ppp(4) on closing tty



On Sun, 06 Apr 2008 20:48:28 -0400
Greg Troxel <gdt%ir.bbn.com@localhost> wrote:
> Yasuoka Masahiko <yasuoka%iij.ad.jp@localhost> writes:
> > As far as my test, current behavior is
> >
> >   -----------  -----------  ---------------
> >                created by
> >                ifconfig     device/tty open
> >   -----------  -----------  ---------------
> >   tun(4)       remain       remain
> >   ppp(4)       destroyed    destroyed
> >   -----------  -----------  ---------------
> >
> > and after the patch,
> >
> >   -----------  -----------  ---------------
> >                created by
> >                ifconfig     device/tty open
> >   -----------  -----------  ---------------
> >   tun(4)       remain       remain
> >   ppp(4)       remain       destroyed
> >   -----------  -----------  ---------------
> >
> > Their behaviors sould be consistent?
> 
> Patching ppp(4) so that interfaces created by ifconfig create remain
> after clossing the tty seems like the right thing to do.

I thought we should consider compatibility with other OSs, so I looked
FreeBSD and Linux.  FreeBSD 7.0 remains ppp on all cases, and CentOS
4.5 destroys on all cases, there is nothing we learn from these OSs.
I think now our patch is the best.

> I don't understand why a tun(4) device created when /dev/tunN is written
> to should remain after last close.  But that's really a separate issue.

I think there is no reason to remain tun(4) after last close if we can
keep it remain by 'ifconfig create'.

A patch for tun(4) is attached.

--yasuoka

Index: if_tun.c
===================================================================
RCS file: /vol/cvs/NetBSD/src/sys/net/if_tun.c,v
retrieving revision 1.1.1.1
diff -u -p -r1.1.1.1 if_tun.c
--- if_tun.c    2 Nov 2006 05:14:42 -0000       1.1.1.1
+++ if_tun.c    7 Apr 2008 15:54:21 -0000
@@ -300,6 +300,7 @@ tunopen(dev, flag, mode, p)
                        error = ENXIO;
                        goto out_nolock;
                }
+               tp->tun_flags |= TUN_DEVCLONE;
        }
 
        if (tp->tun_flags & TUN_OPEN) {
@@ -371,6 +372,9 @@ tunclose(dev, flag, mode, p)
        tp->tun_pgid = 0;
        selnotify(&tp->tun_rsel, 0);
 
+       if ((tp->tun_flags & TUN_DEVCLONE) != 0)
+               tun_clone_destroy(ifp);
+
        TUNDEBUG ("%s: closed\n", ifp->if_xname);
        simple_unlock(&tp->tun_lock);
 out_nolock:
Index: if_tun.h
===================================================================
RCS file: /vol/cvs/NetBSD/src/sys/net/if_tun.h,v
retrieving revision 1.1.1.1
diff -u -p -r1.1.1.1 if_tun.h
--- if_tun.h    2 Nov 2006 05:14:42 -0000       1.1.1.1
+++ if_tun.h    7 Apr 2008 15:51:34 -0000
@@ -33,6 +33,7 @@ struct tun_softc {
 #define        TUN_ASYNC       0x0080
 #define        TUN_NBIO        0x0100
 #define        TUN_PREPADDR    0x0200
+#define        TUN_DEVCLONE    0x0400          /* created by device open */
 
 #define        TUN_READY       (TUN_OPEN | TUN_INITED | TUN_IASET)
 


Home | Main Index | Thread Index | Old Index