• James Chapman's avatar
    l2tp: simplify tunnel and socket cleanup · 29717a4f
    James Chapman authored
    When the l2tp tunnel socket used sk_user_data to point to its
    associated l2tp tunnel, socket and tunnel cleanup had to make use of
    the socket's destructor to free the tunnel only when the socket could
    no longer be accessed.
    
    Now that sk_user_data is no longer used, we can simplify socket and
    tunnel cleanup:
    
      * If the tunnel closes first, it cleans up and drops its socket ref
        when the tunnel refcount drops to zero. If its socket was provided
        by userspace, the socket is closed and freed asynchronously, when
        userspace closes it. If its socket is a kernel socket, the tunnel
        closes the socket itself during cleanup and drops its socket ref
        when the tunnel's refcount drops to zero.
    
      * If the socket closes first, we initiate the closing of its
        associated tunnel. For UDP sockets, this is via the socket's
        encap_destroy hook. For L2TPIP sockets, this is via the socket's
        destroy callback. The tunnel holds a socket ref while it
        references the sock. When the tunnel is freed, it drops its socket
        ref and the socket will be cleaned up when its own refcount drops
        to zero, asynchronous to the tunnel free.
    
      * The tunnel socket destructor is no longer needed since the tunnel
        is no longer freed through the socket destructor.
    Signed-off-by: default avatarJames Chapman <jchapman@katalix.com>
    Signed-off-by: default avatarTom Parkin <tparkin@katalix.com>
    Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
    29717a4f
l2tp_core.c 47.3 KB