netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH 0/6] udp: add encapsulation socket destroy hook
@ 2013-02-15 10:25 Tom Parkin
  2013-02-15 10:25 ` [RFC PATCH 1/6] udp: add encap_destroy callback Tom Parkin
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: Tom Parkin @ 2013-02-15 10:25 UTC (permalink / raw)
  To: netdev; +Cc: jchapman, celston, Tom Parkin

While working on an issue in l2tp relating to tunnel cleanup I discovered a
problem which I think may require a new hook in udp core to resolve.  The l2tp
code uses encapsulated udp sockets, and it needs to know when a socket is
being closed in order to clean up.  Since sessions hold a reference to the
tunnel socket, hooking sk_destruct isn't sufficient: any tunnel with sessions
running in it will be pinned open by the sessions.

To resolve this, the first patch in this series adds a .destroy hook to udp, 
while the following patches show how I'd use this feature in l2tp.  Essentially 
the .destroy callback is used to close the sessions in the tunnel, thereby 
dropping the socket references.

Does this seem like a reasonable approach?  I'm reluctant to modify udp, but
I've not managed to discover a safe alternative...

The rest of this email goes into some more detail about the problem I'm trying
to solve.

A bit of background is probably useful for context.

The kernel l2tp code supports two flavours of tunnel socket: managed and
unmanaged.  The managed tunnel socket is created by a userspace daemon which
handles the L2TP control protocol, while the kernel handles L2TP data
encapsulation.  The unmanaged tunnel socket is created by the kernel
and just provides L2TP data encapsulation with no control protocol.

These two flavours of tunnel socket make for a fairly complex set of tunnel
lifetime requirements:

A managed tunnel may be deleted by:

 * userspace using a netlink "delete" command
 * userspace calling close(2) on the tunnel socket
 * userspace dying and the tunnel socket being released as a part of
   the normal tidyup after a process terminates

An unmanaged tunnel may be deleted by:

 * userspace using a netlink "delete" command

In order to satisfy all these deletion mechanisms, l2tp uses sk_destruct to
free tunnel resources when the tunnel socket is being destroyed.  That way we
can catch userspace closing the socket as well as explicit deletion using
netlink.

The problem comes when sessions are added to the tunnel.  Each session holds a
reference to the tunnel socket, in order to prevent the tunnel socket
unexpectedly going away while the session is still active and passing data.
But of course this also keeps the tunnel socket alive even if userspace closes
it!

This is where the protocol .destroy hook comes in.  Because .destroy is called
by sk_common_release before sock_put, the l2tp code is able to use the hook to
close the sessions in the tunnel.  Now that all the session references to the
socket have been dropped, when sk_common_release makes its final sock_put
call, the socket is actually freed and sk_destruct is called.

Tom Parkin (6):
  udp: add encap_destroy callback
  l2tp: add udp encap socket destroy handler
  l2tp: drop session refs in l2tp_tunnel_closeall
  l2tp: export l2tp_tunnel_closeall
  l2tp: close sessions in ip socket destroy callback
  l2tp: close sessions before initiating tunnel delete

 include/linux/udp.h  |    1 +
 net/ipv4/udp.c       |    7 +++++++
 net/ipv6/udp.c       |    8 ++++++++
 net/l2tp/l2tp_core.c |   19 +++++++++++++++++--
 net/l2tp/l2tp_core.h |    1 +
 net/l2tp/l2tp_ip.c   |    6 ++++++
 net/l2tp/l2tp_ip6.c  |    7 +++++++
 7 files changed, 47 insertions(+), 2 deletions(-)

-- 
1.7.9.5

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2013-02-15 21:02 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-02-15 10:25 [RFC PATCH 0/6] udp: add encapsulation socket destroy hook Tom Parkin
2013-02-15 10:25 ` [RFC PATCH 1/6] udp: add encap_destroy callback Tom Parkin
2013-02-15 10:25 ` [RFC PATCH 2/6] l2tp: add udp encap socket destroy handler Tom Parkin
2013-02-15 10:25 ` [RFC PATCH 3/6] l2tp: drop session refs in l2tp_tunnel_closeall Tom Parkin
2013-02-15 10:25 ` [RFC PATCH 4/6] l2tp: export l2tp_tunnel_closeall Tom Parkin
2013-02-15 10:25 ` [RFC PATCH 5/6] l2tp: close sessions in ip socket destroy callback Tom Parkin
2013-02-15 10:25 ` [RFC PATCH 6/6] l2tp: close sessions before initiating tunnel delete Tom Parkin
2013-02-15 21:02 ` [RFC PATCH 0/6] udp: add encapsulation socket destroy hook David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).