All of lore.kernel.org
 help / color / mirror / Atom feed
From: Guillaume Nault <gnault@redhat.com>
To: Simon Chopin <s.chopin@alphalink.fr>
Cc: Tom Parkin <tparkin@katalix.com>, netdev@vger.kernel.org
Subject: Re: [PATCH v4 net-next 1/2] ppp: add PPPIOCBRIDGECHAN and PPPIOCUNBRIDGECHAN ioctls
Date: Mon, 11 Jan 2021 15:26:21 +0100	[thread overview]
Message-ID: <20210111142621.GB13412@linux.home> (raw)
In-Reply-To: <ebc3b218-ab1c-30b1-144b-413b168631b1@alphalink.fr>

On Mon, Jan 11, 2021 at 02:17:13PM +0100, Simon Chopin wrote:
> Hello,
> 
> Le 10/12/2020 à 16:50, Tom Parkin a écrit :
> > This new ioctl pair allows two ppp channels to be bridged together:
> > frames arriving in one channel are transmitted in the other channel
> > and vice versa.
> > 
> > The practical use for this is primarily to support the L2TP Access
> > Concentrator use-case.  The end-user session is presented as a ppp
> > channel (typically PPPoE, although it could be e.g. PPPoA, or even PPP
> > over a serial link) and is switched into a PPPoL2TP session for
> > transmission to the LNS.  At the LNS the PPP session is terminated in
> > the ISP's network.
> > 
> > When a PPP channel is bridged to another it takes a reference on the
> > other's struct ppp_file.  This reference is dropped when the channels
> > are unbridged, which can occur either explicitly on userspace calling
> > the PPPIOCUNBRIDGECHAN ioctl, or implicitly when either channel in the
> > bridge is unregistered.
> > 
> > In order to implement the channel bridge, struct channel is extended
> > with a new field, 'bridge', which points to the other struct channel
> > making up the bridge.
> > 
> > This pointer is RCU protected to avoid adding another lock to the data
> > path.
> > 
> > To guard against concurrent writes to the pointer, the existing struct
> > channel lock 'upl' coverage is extended rather than adding a new lock.
> > 
> > The 'upl' lock is used to protect the existing unit pointer.  Since the
> > bridge effectively replaces the unit (they're mutually exclusive for a
> > channel) it makes coding easier to use the same lock to cover them
> > both.
> > 
> > Signed-off-by: Tom Parkin <tparkin@katalix.com>
> > ---
> >  drivers/net/ppp/ppp_generic.c  | 152 ++++++++++++++++++++++++++++++++-
> >  include/uapi/linux/ppp-ioctl.h |   2 +
> >  2 files changed, 151 insertions(+), 3 deletions(-)
> > 
> > diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
> > index 7d005896a0f9..09c27f7773f9 100644
> > --- a/drivers/net/ppp/ppp_generic.c
> > +++ b/drivers/net/ppp/ppp_generic.c
> > @@ -174,7 +174,8 @@ struct channel {
> >  	struct ppp	*ppp;		/* ppp unit we're connected to */
> >  	struct net	*chan_net;	/* the net channel belongs to */
> >  	struct list_head clist;		/* link in list of channels per unit */
> > -	rwlock_t	upl;		/* protects `ppp' */
> > +	rwlock_t	upl;		/* protects `ppp' and 'bridge' */
> > +	struct channel __rcu *bridge;	/* "bridged" ppp channel */
> >  #ifdef CONFIG_PPP_MULTILINK
> >  	u8		avail;		/* flag used in multilink stuff */
> >  	u8		had_frag;	/* >= 1 fragments have been sent */
> > @@ -606,6 +607,83 @@ static struct bpf_prog *compat_ppp_get_filter(struct sock_fprog32 __user *p)
> >  #endif
> >  #endif
> >  
> > +/* Bridge one PPP channel to another.
> > + * When two channels are bridged, ppp_input on one channel is redirected to
> > + * the other's ops->start_xmit handler.
> > + * In order to safely bridge channels we must reject channels which are already
> > + * part of a bridge instance, or which form part of an existing unit.
> > + * Once successfully bridged, each channel holds a reference on the other
> > + * to prevent it being freed while the bridge is extant.
> > + */
> > +static int ppp_bridge_channels(struct channel *pch, struct channel *pchb)
> > +{
> > +	write_lock_bh(&pch->upl);
> > +	if (pch->ppp ||
> > +	    rcu_dereference_protected(pch->bridge, lockdep_is_held(&pch->upl))) {
> > +		write_unlock_bh(&pch->upl);
> > +		return -EALREADY;
> > +	}
> > +	rcu_assign_pointer(pch->bridge, pchb);
> > +	write_unlock_bh(&pch->upl);
> > +
> This is mostly for my own education:
> 
> I might be misunderstanding something, but is there anything
> that would prevent a packet from being forwarded from pch to pchb at this
> precise moment? If not, then it might be theoretically possible to have
> any answer to said packet (say, a LCP ACK) to be received before the 
> pchb->bridge is set?

That's possible in theory. But I can't see any problem in practice,
because:

  * It's unlikely the round trip time would be small enough to trigger
    this situation.

  * If this situation ever happens, the reply is passed to user space,
    which is free to forward it to the other channel. If the user
    space implementation isn't prepared for this situation and just
    drops the packet, that's fine too. It's just a transient packet
    drop, which PPP peers are supposed to handle just fine (this can
    happen anywhere in the network after all).

  * Any use case I know for channel bridging involves a "live" channel
    (where LCP and authentication protocols are running) and an "idle"
    channel (where no protocol is running at all yet). So the problem
    can be avoided entirely by calling the PPPIOCBRIDGECHAN ioctl on
    the idle channel file descriptor, rather than on the live channel.

Or did you have any other possible problem in mind?

> > +	write_lock_bh(&pchb->upl);
> > +	if (pchb->ppp ||
> > +	    rcu_dereference_protected(pchb->bridge, lockdep_is_held(&pchb->upl))) {
> > +		write_unlock_bh(&pchb->upl);
> > +		goto err_unset;
> > +	}
> > +	rcu_assign_pointer(pchb->bridge, pch);
> > +	write_unlock_bh(&pchb->upl);
> > +
> > +	refcount_inc(&pch->file.refcnt);
> > +	refcount_inc(&pchb->file.refcnt);
> > +
> > +	return 0;
> > +
> > +err_unset:
> > +	write_lock_bh(&pch->upl);
> > +	RCU_INIT_POINTER(pch->bridge, NULL);
> > +	write_unlock_bh(&pch->upl);
> > +	synchronize_rcu();
> > +	return -EALREADY;
> > +}
> 


  reply	other threads:[~2021-01-11 14:28 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-10 15:50 [PATCH v4 net-next 0/2] add ppp_generic ioctl(s) to bridge channels Tom Parkin
2020-12-10 15:50 ` [PATCH v4 net-next 1/2] ppp: add PPPIOCBRIDGECHAN and PPPIOCUNBRIDGECHAN ioctls Tom Parkin
2021-01-11 13:17   ` Simon Chopin
2021-01-11 14:26     ` Guillaume Nault [this message]
2020-12-10 15:50 ` [PATCH v4 net-next 2/2] docs: update ppp_generic.rst to document new ioctls Tom Parkin
2020-12-10 17:13 ` [PATCH v4 net-next 0/2] add ppp_generic ioctl(s) to bridge channels Guillaume Nault
2020-12-10 17:16   ` Tom Parkin
2020-12-10 22:21     ` David Miller
2020-12-11  9:36       ` Tom Parkin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210111142621.GB13412@linux.home \
    --to=gnault@redhat.com \
    --cc=netdev@vger.kernel.org \
    --cc=s.chopin@alphalink.fr \
    --cc=tparkin@katalix.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.