Discussion:
destroy ppp(4) on closing tty
(too old to reply)
Yasuoka Masahiko
2008-04-04 13:21:00 UTC
Permalink
Hi, I'm Yasuoka of IIJ.

I wonder why ppp(4) destroys itself when the attached tty is closed.
tun(4) doesn't destroy itself when the attached device file is closed.

Is there somebody knows the reason?

--yasuoka

--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-***@muc.de
Greg Troxel
2008-04-04 13:50:57 UTC
Permalink
Post by Yasuoka Masahiko
I wonder why ppp(4) destroys itself when the attached tty is closed.
tun(4) doesn't destroy itself when the attached device file is closed.
Is there somebody knows the reason?
Does the ppp(4) get created when something on the tty sets line
discipline to PPP? If so, it makes sense to destroy on close.

If a tun is created by a call on a descriptor, I'd say it too should be
destroyed on close. If it's created by 'ifconfig tun0 create', then it
shouldn't be destroyed on close.

--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-***@muc.de
Quentin Garnier
2008-04-04 14:35:49 UTC
Permalink
Post by Greg Troxel
Post by Yasuoka Masahiko
I wonder why ppp(4) destroys itself when the attached tty is closed.
tun(4) doesn't destroy itself when the attached device file is closed.
Is there somebody knows the reason?
Does the ppp(4) get created when something on the tty sets line
discipline to PPP? If so, it makes sense to destroy on close.
What could be confusing I guess is that you can create a ppp interface
with ifconfig, then get it used by pppd through the line discipline,
which will eventually destroy it on close.

That could be fixed by a simple flag set from the cloner interface. The
only reason ppp(4) is a cloner is so that pppd(8) can check there is
support for it by listing the cloners. Otherwise there's no point in
letting the user do ifconfig ppp0 create.
Post by Greg Troxel
If a tun is created by a call on a descriptor, I'd say it too should be
destroyed on close. If it's created by 'ifconfig tun0 create', then it
shouldn't be destroyed on close.
That's indeed the case.
--
Quentin Garnier - ***@cubidou.net - ***@NetBSD.org
"See the look on my face from staying too long in one place
[...] every time the morning breaks I know I'm closer to falling"
KT Tunstall, Saving My Face, Drastic Fantastic, 2007.
Yasuoka Masahiko
2008-04-05 04:16:49 UTC
Permalink
On Fri, 4 Apr 2008 16:35:49 +0200
Post by Quentin Garnier
Post by Greg Troxel
Post by Yasuoka Masahiko
I wonder why ppp(4) destroys itself when the attached tty is closed.
tun(4) doesn't destroy itself when the attached device file is closed.
Is there somebody knows the reason?
Does the ppp(4) get created when something on the tty sets line
discipline to PPP? If so, it makes sense to destroy on close.
What could be confusing I guess is that you can create a ppp interface
with ifconfig, then get it used by pppd through the line discipline,
which will eventually destroy it on close.
Thank you. Yes, i confused that point. My program can't get ppp
interface's i/o stastics after pppd(8) exits.
Post by Quentin Garnier
That could be fixed by a simple flag set from the cloner interface. The
only reason ppp(4) is a cloner is so that pppd(8) can check there is
support for it by listing the cloners. Otherwise there's no point in
letting the user do ifconfig ppp0 create.
A patch attached at the end of this message.
Post by Quentin Garnier
Post by Greg Troxel
If a tun is created by a call on a descriptor, I'd say it too should be
destroyed on close. If it's created by 'ifconfig tun0 create', then it
shouldn't be destroyed on close.
That's indeed the case.
How about 'device/tty close' case?

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?

--yasuoka

Index: if_ppp.c
===================================================================
RCS file: /vol/cvs/NetBSD/src/sys/net/if_ppp.c,v
retrieving revision 1.1.1.1
diff -u -p -r1.1.1.1 if_ppp.c
--- if_ppp.c 2 Nov 2006 05:14:42 -0000 1.1.1.1
+++ if_ppp.c 5 Apr 2008 03:31:11 -0000
@@ -353,7 +353,7 @@ pppalloc(pid)
pid_t pid;
{
struct ppp_softc *sc = NULL, *scf;
- int i;
+ int i, sc_flags;

simple_lock(&ppp_list_mutex);
for (scf = LIST_FIRST(&ppp_softc_list); scf != NULL;
@@ -368,8 +368,11 @@ pppalloc(pid)
}
simple_unlock(&ppp_list_mutex);

- if (sc == NULL)
+ sc_flags = 0;
+ if (sc == NULL) {
sc = ppp_create(ppp_cloner.ifc_name, -1);
+ sc_flags |= SC_TTYCLONE;
+ }

#ifdef __HAVE_GENERIC_SOFT_INTERRUPTS
sc->sc_si = softintr_establish(IPL_SOFTNET, pppintr, sc);
@@ -378,7 +381,7 @@ pppalloc(pid)
return (NULL);
}
#endif
- sc->sc_flags = 0;
+ sc->sc_flags = sc_flags;
sc->sc_mru = PPP_MRU;
sc->sc_relinq = NULL;
(void)memset(&sc->sc_stats, 0, sizeof(sc->sc_stats));
@@ -476,7 +479,8 @@ pppdealloc(sc)
sc->sc_comp = 0;
}
#endif
- (void)ppp_clone_destroy(&sc->sc_if);
+ if ((sc->sc_flags & SC_TTYCLONE) != 0)
+ (void)ppp_clone_destroy(&sc->sc_if);
}

/*
Index: if_ppp.h
===================================================================
RCS file: /vol/cvs/NetBSD/src/sys/net/if_ppp.h,v
retrieving revision 1.1.1.1
diff -u -p -r1.1.1.1 if_ppp.h
--- if_ppp.h 2 Nov 2006 05:14:42 -0000 1.1.1.1
+++ if_ppp.h 5 Apr 2008 03:41:35 -0000
@@ -73,6 +73,7 @@
/*
* State bits in sc_flags, not changeable by user.
*/
+#define SC_TTYCLONE 0x00000200 /* created by tty open */
#define SC_TIMEOUT 0x00000400 /* timeout is currently pending */
#define SC_VJ_RESET 0x00000800 /* need to reset VJ decomp */
#define SC_COMP_RUN 0x00001000 /* compressor has been inited */

--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-***@muc.de
Christos Zoulas
2008-04-05 15:31:30 UTC
Permalink
On Apr 5, 1:16pm, ***@iij.ad.jp (Yasuoka Masahiko) wrote:
-- Subject: Re: destroy ppp(4) on closing tty

| On Fri, 4 Apr 2008 16:35:49 +0200
| Quentin Garnier <***@cubidou.net> wrote:
| > On Fri, Apr 04, 2008 at 09:50:57AM -0400, Greg Troxel wrote:
| > > Yasuoka Masahiko <***@iij.ad.jp> writes:
| > > > I wonder why ppp(4) destroys itself when the attached tty is closed.
| > > > tun(4) doesn't destroy itself when the attached device file is closed.
| > > >
| > > > Is there somebody knows the reason?
| > >
| > > Does the ppp(4) get created when something on the tty sets line
| > > discipline to PPP? If so, it makes sense to destroy on close.
| >
| > What could be confusing I guess is that you can create a ppp interface
| > with ifconfig, then get it used by pppd through the line discipline,
| > which will eventually destroy it on close.
|
| Thank you. Yes, i confused that point. My program can't get ppp
| interface's i/o stastics after pppd(8) exits.
|
| > That could be fixed by a simple flag set from the cloner interface. The
| > only reason ppp(4) is a cloner is so that pppd(8) can check there is
| > support for it by listing the cloners. Otherwise there's no point in
| > letting the user do ifconfig ppp0 create.
|
| A patch attached at the end of this message.
|
| > > If a tun is created by a call on a descriptor, I'd say it too should be
| > > destroyed on close. If it's created by 'ifconfig tun0 create', then it
| > > shouldn't be destroyed on close.
| >
| > That's indeed the case.
|
| How about 'device/tty close' case?
|
| 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?
|
| --yasuoka
|
| Index: if_ppp.c
| ===================================================================
| RCS file: /vol/cvs/NetBSD/src/sys/net/if_ppp.c,v
| retrieving revision 1.1.1.1
| diff -u -p -r1.1.1.1 if_ppp.c
| --- if_ppp.c 2 Nov 2006 05:14:42 -0000 1.1.1.1
| +++ if_ppp.c 5 Apr 2008 03:31:11 -0000
| @@ -353,7 +353,7 @@ pppalloc(pid)
| pid_t pid;
| {
| struct ppp_softc *sc = NULL, *scf;
| - int i;
| + int i, sc_flags;
|
| simple_lock(&ppp_list_mutex);
| for (scf = LIST_FIRST(&ppp_softc_list); scf != NULL;
| @@ -368,8 +368,11 @@ pppalloc(pid)
| }
| simple_unlock(&ppp_list_mutex);
|
| - if (sc == NULL)
| + sc_flags = 0;
| + if (sc == NULL) {
| sc = ppp_create(ppp_cloner.ifc_name, -1);
| + sc_flags |= SC_TTYCLONE;
| + }
|
| #ifdef __HAVE_GENERIC_SOFT_INTERRUPTS
| sc->sc_si = softintr_establish(IPL_SOFTNET, pppintr, sc);
| @@ -378,7 +381,7 @@ pppalloc(pid)
| return (NULL);
| }
| #endif
| - sc->sc_flags = 0;
| + sc->sc_flags = sc_flags;
| sc->sc_mru = PPP_MRU;
| sc->sc_relinq = NULL;
| (void)memset(&sc->sc_stats, 0, sizeof(sc->sc_stats));
| @@ -476,7 +479,8 @@ pppdealloc(sc)
| sc->sc_comp = 0;
| }
| #endif
| - (void)ppp_clone_destroy(&sc->sc_if);
| + if ((sc->sc_flags & SC_TTYCLONE) != 0)
| + (void)ppp_clone_destroy(&sc->sc_if);
| }
|
| /*
| Index: if_ppp.h
| ===================================================================
| RCS file: /vol/cvs/NetBSD/src/sys/net/if_ppp.h,v
| retrieving revision 1.1.1.1
| diff -u -p -r1.1.1.1 if_ppp.h
| --- if_ppp.h 2 Nov 2006 05:14:42 -0000 1.1.1.1
| +++ if_ppp.h 5 Apr 2008 03:41:35 -0000
| @@ -73,6 +73,7 @@
| /*
| * State bits in sc_flags, not changeable by user.
| */
| +#define SC_TTYCLONE 0x00000200 /* created by tty open */
| #define SC_TIMEOUT 0x00000400 /* timeout is currently pending */
| #define SC_VJ_RESET 0x00000800 /* need to reset VJ decomp */
| #define SC_COMP_RUN 0x00001000 /* compressor has been inited */
|
|

I guess this is better now, why not make it consistent with tun and keep it
after close?

christos

--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-***@muc.de
Greg Troxel
2008-04-07 00:48:28 UTC
Permalink
Post by Yasuoka Masahiko
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 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.

--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-***@muc.de
Yasuoka Masahiko
2008-04-07 17:24:34 UTC
Permalink
On Sun, 06 Apr 2008 20:48:28 -0400
Post by Greg Troxel
Post by Yasuoka Masahiko
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.
Post by Greg Troxel
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)


--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-***@muc.de
Greg Troxel
2008-04-07 17:32:51 UTC
Permalink
I don't know what consequences there are; some programs may expect it to
remain. But I find "who > /dev/tun0" resulting in a permanent interface
to be odd.

--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-***@muc.de
Greg Troxel
2008-04-07 17:33:40 UTC
Permalink
Post by Greg Troxel
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.

Good point, but given that you found out that it varies widely, making
it sensible seems good.
Post by Greg Troxel
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.

I think it's fine to commit your patch if there are no objections for a
few days.

--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-***@muc.de
Martin Husemann
2008-04-07 22:43:32 UTC
Permalink
Post by Yasuoka Masahiko
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 have no strong opinion, but either of those seem more consistent to
me than to make close() behave differently depending on history of the
device.

Martin

--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-***@muc.de
Christos Zoulas
2008-04-08 00:35:52 UTC
Permalink
Post by Martin Husemann
Post by Yasuoka Masahiko
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 have no strong opinion, but either of those seem more consistent to
me than to make close() behave differently depending on history of the
device.
Well, if pppd opened the device and pppd dies/exits/closes the device,
then the device should dissappear, otherwise in a system where you have
many ppp sessions happen dynamically you are end up with a lot of unused
ppp<N> interfaces. Of course you can teach pppd to remove the cloners...

christos


--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-***@muc.de
Quentin Garnier
2008-04-08 00:41:55 UTC
Permalink
Post by Christos Zoulas
Post by Martin Husemann
Post by Yasuoka Masahiko
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 have no strong opinion, but either of those seem more consistent to
me than to make close() behave differently depending on history of the
device.
Well, if pppd opened the device and pppd dies/exits/closes the device,
then the device should dissappear, otherwise in a system where you have
many ppp sessions happen dynamically you are end up with a lot of unused
ppp<N> interfaces. Of course you can teach pppd to remove the cloners...
No, because an unused ppp interface will be re-used, so you only end up
with as many interfaces as the maximum number of concurrent sessions.

I guess we could not make the closing from pppd destroy the interface so
it is consistent.
--
Quentin Garnier - ***@cubidou.net - ***@NetBSD.org
"See the look on my face from staying too long in one place
[...] every time the morning breaks I know I'm closer to falling"
KT Tunstall, Saving My Face, Drastic Fantastic, 2007.
Greg Troxel
2008-04-08 12:25:52 UTC
Permalink
I have no strong opinion, but either of those seem more consistent to
me than to make close() behave differently depending on history of the
device.

The point is that if an open() call caused the device to start existing,
it makes sense for the last close() to destroy it. I would say that if
we don't want this behavior we shouldn't allow create on open.


--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-***@muc.de
Yasuoka Masahiko
2008-04-04 14:33:36 UTC
Permalink
On Fri, 04 Apr 2008 09:50:57 -0400
Post by Greg Troxel
Post by Yasuoka Masahiko
I wonder why ppp(4) destroys itself when the attached tty is closed.
tun(4) doesn't destroy itself when the attached device file is closed.
Is there somebody knows the reason?
Does the ppp(4) get created when something on the tty sets line
discipline to PPP? If so, it makes sense to destroy on close.
When ppp(4) is running, it has some disciplines by the tty. But after
the closing proccess on net/{ppp_tty,if_ppp}.c, it seems to release
all restraints by the tty.
Post by Greg Troxel
If a tun is created by a call on a descriptor, I'd say it too should be
destroyed on close. If it's created by 'ifconfig tun0 create', then it
shouldn't be destroyed on close.
tun(4) is not destroyed on both cases, but ppp(4) is destroyed on both
cases.

I think if ppp(4) has no special reason to be destroyed, it sould do
same behavior as other pseudo interfaces.

--yasuoka

--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-***@muc.de
Christos Zoulas
2008-04-05 01:05:44 UTC
Permalink
Post by Yasuoka Masahiko
Hi, I'm Yasuoka of IIJ.
I wonder why ppp(4) destroys itself when the attached tty is closed.
tun(4) doesn't destroy itself when the attached device file is closed.
Is there somebody knows the reason?
I don't know the reason. I guess they should behave the same way, but
maybe pppd needs to be modified then.

christos


--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-***@muc.de
Christos Zoulas
2008-04-08 00:50:18 UTC
Permalink
On Apr 8, 2:41am, ***@cubidou.net (Quentin Garnier) wrote:
-- Subject: Re: destroy ppp(4) on closing tty

|
| --MIMEStream=_0+273200_2525998081651_98477257936
| Content-Type: multipart/signed; micalg=pgp-sha1;
| protocol="application/pgp-signature"; boundary="poemUeGtc2GQvHuH"
| Content-Disposition: inline
|
|
| --poemUeGtc2GQvHuH
| Content-Type: text/plain; charset=us-ascii
| Content-Disposition: inline
| Content-Transfer-Encoding: quoted-printable
|
| On Tue, Apr 08, 2008 at 12:35:52AM +0000, Christos Zoulas wrote:
| > In article <***@drowsy.duskware.de>,
| > Martin Husemann <***@duskware.de> wrote:
| > >On Tue, Apr 08, 2008 at 02:24:34AM +0900, Yasuoka Masahiko wrote:
| > >> 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 have no strong opinion, but either of those seem more consistent to
| > >me than to make close() behave differently depending on history of the
| > >device.
| >=20
| > Well, if pppd opened the device and pppd dies/exits/closes the device,
| > then the device should dissappear, otherwise in a system where you have
| > many ppp sessions happen dynamically you are end up with a lot of unused
| > ppp<N> interfaces. Of course you can teach pppd to remove the cloners...
|
| No, because an unused ppp interface will be re-used, so you only end up
| with as many interfaces as the maximum number of concurrent sessions.

Which is not good either.

| I guess we could not make the closing from pppd destroy the interface so
| it is consistent.

We could.

christos

--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-***@muc.de
Loading...