Re: [PATCHv4] PPPoL2TP: Add more code snippets

From: Samuel Thibault
Date: Tue Feb 13 2024 - 06:53:21 EST


Tom Parkin, le mar. 13 févr. 2024 10:51:08 +0000, a ecrit:
> > + ret = ioctl(session_fd1, PPPIOCGCHAN, &chindx1);
> > + if (ret < 0)
> > + return -errno;
> > +
> > + ret = ioctl(session_fd2, PPPIOCGCHAN, &chindx2);
> > + if (ret < 0)
> > + return -errno;
> > +
> > + ppp_chan_fd = open("/dev/ppp", O_RDWR);
> > + if (ppp_chan_fd < 0) {
> > + return -errno;
> > + }
> > +
> > + ret = ioctl(ppp_chan_fd, PPPIOCATTCHAN, &chindx1);
> > + if (ret < 0) {
> > + close(ppp_chan_fd);
> > + return -errno;
> > + }
>
> I think we should drop the PPPIOCATTCHAN ioctl call here.
>
> The input file descriptors are called out as being PPPoX sockets
> created as described earlier, in which case they should both
> already be attached to a channel.
>
> It would make more sense IMO to call out the two ppp_chan_fd file
> descriptors as being input parameters alongside the PPPoX session file
> descriptors.
>
> > +
> > + ret = ioctl(ppp_chan_fd, PPPIOCBRIDGECHAN, &chindx2);
> > + close(ppp_chan_fd);
> > + if (ret < 0)
> > + return -errno;
> > +
> > +It can be noted that in this case no PPP interface is needed, and the PPP
> > +channel does not need to be kept open. Only the session PPPoX data sockets need
> > +to be kept open.
>
> Is it true to say that the PPP channel file descriptors can be closed
> by userspace?

In our code we do it
https://code.ffdn.org/sthibaul/l2tpns/-/blob/kernel/l2tpns.c?ref_type=heads#L1295
and it works all fine indeed (and avoids that fd per session).

That's actually one of the reason why I made the snipped only take the
pppox sockets, and make it create the ppp chan fd only temporarily. AIUI
the pppox socket already has a ppp chan (returned by PPPIOCGCHAN), and
the ppp chan fd is there only for performing the bridging ioctl.

Samuel