Commit e0ebcb80 authored by David S. Miller's avatar David S. Miller

Merge branch 'l2tp'

Tom Parkin says:

====================
This l2tp bugfix patchset addresses a number of issues.

The first five patches in the series prevent l2tp sessions pinning an l2tp
tunnel open.  This occurs because the l2tp tunnel is torn down in the tunnel
socket destructor, but each session holds a tunnel socket reference which
prevents tunnels with sessions being deleted.  The solution I've implemented
here involves adding a .destroy hook to udp code, as discussed previously on
netdev[1].

The subsequent seven patches address futher bugs exposed by fixing the problem
above, or exposed through stress testing the implementation above.  Patch 11
(avoid deadlock in l2tp stats update) isn't directly related to tunnel/session
lifetimes, but it does prevent deadlocks on i386 kernels running on 64 bit
hardware.

This patchset has been tested on 32 and 64 bit preempt/non-preempt kernels,
using iproute2, openl2tp, and custom-made stress test code.

[1] http://comments.gmane.org/gmane.linux.network/259169
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents f1e79e20 f6e16b29
...@@ -68,6 +68,7 @@ struct udp_sock { ...@@ -68,6 +68,7 @@ struct udp_sock {
* For encapsulation sockets. * For encapsulation sockets.
*/ */
int (*encap_rcv)(struct sock *sk, struct sk_buff *skb); int (*encap_rcv)(struct sock *sk, struct sk_buff *skb);
void (*encap_destroy)(struct sock *sk);
}; };
static inline struct udp_sock *udp_sk(const struct sock *sk) static inline struct udp_sock *udp_sk(const struct sock *sk)
......
...@@ -1762,9 +1762,16 @@ int udp_rcv(struct sk_buff *skb) ...@@ -1762,9 +1762,16 @@ int udp_rcv(struct sk_buff *skb)
void udp_destroy_sock(struct sock *sk) void udp_destroy_sock(struct sock *sk)
{ {
struct udp_sock *up = udp_sk(sk);
bool slow = lock_sock_fast(sk); bool slow = lock_sock_fast(sk);
udp_flush_pending_frames(sk); udp_flush_pending_frames(sk);
unlock_sock_fast(sk, slow); unlock_sock_fast(sk, slow);
if (static_key_false(&udp_encap_needed) && up->encap_type) {
void (*encap_destroy)(struct sock *sk);
encap_destroy = ACCESS_ONCE(up->encap_destroy);
if (encap_destroy)
encap_destroy(sk);
}
} }
/* /*
......
...@@ -1285,10 +1285,18 @@ int udpv6_sendmsg(struct kiocb *iocb, struct sock *sk, ...@@ -1285,10 +1285,18 @@ int udpv6_sendmsg(struct kiocb *iocb, struct sock *sk,
void udpv6_destroy_sock(struct sock *sk) void udpv6_destroy_sock(struct sock *sk)
{ {
struct udp_sock *up = udp_sk(sk);
lock_sock(sk); lock_sock(sk);
udp_v6_flush_pending_frames(sk); udp_v6_flush_pending_frames(sk);
release_sock(sk); release_sock(sk);
if (static_key_false(&udpv6_encap_needed) && up->encap_type) {
void (*encap_destroy)(struct sock *sk);
encap_destroy = ACCESS_ONCE(up->encap_destroy);
if (encap_destroy)
encap_destroy(sk);
}
inet6_destroy_sock(sk); inet6_destroy_sock(sk);
} }
......
...@@ -114,7 +114,6 @@ struct l2tp_net { ...@@ -114,7 +114,6 @@ struct l2tp_net {
static void l2tp_session_set_header_len(struct l2tp_session *session, int version); static void l2tp_session_set_header_len(struct l2tp_session *session, int version);
static void l2tp_tunnel_free(struct l2tp_tunnel *tunnel); static void l2tp_tunnel_free(struct l2tp_tunnel *tunnel);
static void l2tp_tunnel_closeall(struct l2tp_tunnel *tunnel);
static inline struct l2tp_net *l2tp_pernet(struct net *net) static inline struct l2tp_net *l2tp_pernet(struct net *net)
{ {
...@@ -192,6 +191,7 @@ struct sock *l2tp_tunnel_sock_lookup(struct l2tp_tunnel *tunnel) ...@@ -192,6 +191,7 @@ struct sock *l2tp_tunnel_sock_lookup(struct l2tp_tunnel *tunnel)
} else { } else {
/* Socket is owned by kernelspace */ /* Socket is owned by kernelspace */
sk = tunnel->sock; sk = tunnel->sock;
sock_hold(sk);
} }
out: out:
...@@ -210,6 +210,7 @@ void l2tp_tunnel_sock_put(struct sock *sk) ...@@ -210,6 +210,7 @@ void l2tp_tunnel_sock_put(struct sock *sk)
} }
sock_put(sk); sock_put(sk);
} }
sock_put(sk);
} }
EXPORT_SYMBOL_GPL(l2tp_tunnel_sock_put); EXPORT_SYMBOL_GPL(l2tp_tunnel_sock_put);
...@@ -373,10 +374,8 @@ static void l2tp_recv_queue_skb(struct l2tp_session *session, struct sk_buff *sk ...@@ -373,10 +374,8 @@ static void l2tp_recv_queue_skb(struct l2tp_session *session, struct sk_buff *sk
struct sk_buff *skbp; struct sk_buff *skbp;
struct sk_buff *tmp; struct sk_buff *tmp;
u32 ns = L2TP_SKB_CB(skb)->ns; u32 ns = L2TP_SKB_CB(skb)->ns;
struct l2tp_stats *sstats;
spin_lock_bh(&session->reorder_q.lock); spin_lock_bh(&session->reorder_q.lock);
sstats = &session->stats;
skb_queue_walk_safe(&session->reorder_q, skbp, tmp) { skb_queue_walk_safe(&session->reorder_q, skbp, tmp) {
if (L2TP_SKB_CB(skbp)->ns > ns) { if (L2TP_SKB_CB(skbp)->ns > ns) {
__skb_queue_before(&session->reorder_q, skbp, skb); __skb_queue_before(&session->reorder_q, skbp, skb);
...@@ -384,9 +383,7 @@ static void l2tp_recv_queue_skb(struct l2tp_session *session, struct sk_buff *sk ...@@ -384,9 +383,7 @@ static void l2tp_recv_queue_skb(struct l2tp_session *session, struct sk_buff *sk
"%s: pkt %hu, inserted before %hu, reorder_q len=%d\n", "%s: pkt %hu, inserted before %hu, reorder_q len=%d\n",
session->name, ns, L2TP_SKB_CB(skbp)->ns, session->name, ns, L2TP_SKB_CB(skbp)->ns,
skb_queue_len(&session->reorder_q)); skb_queue_len(&session->reorder_q));
u64_stats_update_begin(&sstats->syncp); atomic_long_inc(&session->stats.rx_oos_packets);
sstats->rx_oos_packets++;
u64_stats_update_end(&sstats->syncp);
goto out; goto out;
} }
} }
...@@ -403,23 +400,16 @@ static void l2tp_recv_dequeue_skb(struct l2tp_session *session, struct sk_buff * ...@@ -403,23 +400,16 @@ static void l2tp_recv_dequeue_skb(struct l2tp_session *session, struct sk_buff *
{ {
struct l2tp_tunnel *tunnel = session->tunnel; struct l2tp_tunnel *tunnel = session->tunnel;
int length = L2TP_SKB_CB(skb)->length; int length = L2TP_SKB_CB(skb)->length;
struct l2tp_stats *tstats, *sstats;
/* We're about to requeue the skb, so return resources /* We're about to requeue the skb, so return resources
* to its current owner (a socket receive buffer). * to its current owner (a socket receive buffer).
*/ */
skb_orphan(skb); skb_orphan(skb);
tstats = &tunnel->stats; atomic_long_inc(&tunnel->stats.rx_packets);
u64_stats_update_begin(&tstats->syncp); atomic_long_add(length, &tunnel->stats.rx_bytes);
sstats = &session->stats; atomic_long_inc(&session->stats.rx_packets);
u64_stats_update_begin(&sstats->syncp); atomic_long_add(length, &session->stats.rx_bytes);
tstats->rx_packets++;
tstats->rx_bytes += length;
sstats->rx_packets++;
sstats->rx_bytes += length;
u64_stats_update_end(&tstats->syncp);
u64_stats_update_end(&sstats->syncp);
if (L2TP_SKB_CB(skb)->has_seq) { if (L2TP_SKB_CB(skb)->has_seq) {
/* Bump our Nr */ /* Bump our Nr */
...@@ -450,7 +440,6 @@ static void l2tp_recv_dequeue(struct l2tp_session *session) ...@@ -450,7 +440,6 @@ static void l2tp_recv_dequeue(struct l2tp_session *session)
{ {
struct sk_buff *skb; struct sk_buff *skb;
struct sk_buff *tmp; struct sk_buff *tmp;
struct l2tp_stats *sstats;
/* If the pkt at the head of the queue has the nr that we /* If the pkt at the head of the queue has the nr that we
* expect to send up next, dequeue it and any other * expect to send up next, dequeue it and any other
...@@ -458,13 +447,10 @@ static void l2tp_recv_dequeue(struct l2tp_session *session) ...@@ -458,13 +447,10 @@ static void l2tp_recv_dequeue(struct l2tp_session *session)
*/ */
start: start:
spin_lock_bh(&session->reorder_q.lock); spin_lock_bh(&session->reorder_q.lock);
sstats = &session->stats;
skb_queue_walk_safe(&session->reorder_q, skb, tmp) { skb_queue_walk_safe(&session->reorder_q, skb, tmp) {
if (time_after(jiffies, L2TP_SKB_CB(skb)->expires)) { if (time_after(jiffies, L2TP_SKB_CB(skb)->expires)) {
u64_stats_update_begin(&sstats->syncp); atomic_long_inc(&session->stats.rx_seq_discards);
sstats->rx_seq_discards++; atomic_long_inc(&session->stats.rx_errors);
sstats->rx_errors++;
u64_stats_update_end(&sstats->syncp);
l2tp_dbg(session, L2TP_MSG_SEQ, l2tp_dbg(session, L2TP_MSG_SEQ,
"%s: oos pkt %u len %d discarded (too old), waiting for %u, reorder_q_len=%d\n", "%s: oos pkt %u len %d discarded (too old), waiting for %u, reorder_q_len=%d\n",
session->name, L2TP_SKB_CB(skb)->ns, session->name, L2TP_SKB_CB(skb)->ns,
...@@ -623,7 +609,6 @@ void l2tp_recv_common(struct l2tp_session *session, struct sk_buff *skb, ...@@ -623,7 +609,6 @@ void l2tp_recv_common(struct l2tp_session *session, struct sk_buff *skb,
struct l2tp_tunnel *tunnel = session->tunnel; struct l2tp_tunnel *tunnel = session->tunnel;
int offset; int offset;
u32 ns, nr; u32 ns, nr;
struct l2tp_stats *sstats = &session->stats;
/* The ref count is increased since we now hold a pointer to /* The ref count is increased since we now hold a pointer to
* the session. Take care to decrement the refcnt when exiting * the session. Take care to decrement the refcnt when exiting
...@@ -640,9 +625,7 @@ void l2tp_recv_common(struct l2tp_session *session, struct sk_buff *skb, ...@@ -640,9 +625,7 @@ void l2tp_recv_common(struct l2tp_session *session, struct sk_buff *skb,
"%s: cookie mismatch (%u/%u). Discarding.\n", "%s: cookie mismatch (%u/%u). Discarding.\n",
tunnel->name, tunnel->tunnel_id, tunnel->name, tunnel->tunnel_id,
session->session_id); session->session_id);
u64_stats_update_begin(&sstats->syncp); atomic_long_inc(&session->stats.rx_cookie_discards);
sstats->rx_cookie_discards++;
u64_stats_update_end(&sstats->syncp);
goto discard; goto discard;
} }
ptr += session->peer_cookie_len; ptr += session->peer_cookie_len;
...@@ -711,9 +694,7 @@ void l2tp_recv_common(struct l2tp_session *session, struct sk_buff *skb, ...@@ -711,9 +694,7 @@ void l2tp_recv_common(struct l2tp_session *session, struct sk_buff *skb,
l2tp_warn(session, L2TP_MSG_SEQ, l2tp_warn(session, L2TP_MSG_SEQ,
"%s: recv data has no seq numbers when required. Discarding.\n", "%s: recv data has no seq numbers when required. Discarding.\n",
session->name); session->name);
u64_stats_update_begin(&sstats->syncp); atomic_long_inc(&session->stats.rx_seq_discards);
sstats->rx_seq_discards++;
u64_stats_update_end(&sstats->syncp);
goto discard; goto discard;
} }
...@@ -732,9 +713,7 @@ void l2tp_recv_common(struct l2tp_session *session, struct sk_buff *skb, ...@@ -732,9 +713,7 @@ void l2tp_recv_common(struct l2tp_session *session, struct sk_buff *skb,
l2tp_warn(session, L2TP_MSG_SEQ, l2tp_warn(session, L2TP_MSG_SEQ,
"%s: recv data has no seq numbers when required. Discarding.\n", "%s: recv data has no seq numbers when required. Discarding.\n",
session->name); session->name);
u64_stats_update_begin(&sstats->syncp); atomic_long_inc(&session->stats.rx_seq_discards);
sstats->rx_seq_discards++;
u64_stats_update_end(&sstats->syncp);
goto discard; goto discard;
} }
} }
...@@ -788,9 +767,7 @@ void l2tp_recv_common(struct l2tp_session *session, struct sk_buff *skb, ...@@ -788,9 +767,7 @@ void l2tp_recv_common(struct l2tp_session *session, struct sk_buff *skb,
* packets * packets
*/ */
if (L2TP_SKB_CB(skb)->ns != session->nr) { if (L2TP_SKB_CB(skb)->ns != session->nr) {
u64_stats_update_begin(&sstats->syncp); atomic_long_inc(&session->stats.rx_seq_discards);
sstats->rx_seq_discards++;
u64_stats_update_end(&sstats->syncp);
l2tp_dbg(session, L2TP_MSG_SEQ, l2tp_dbg(session, L2TP_MSG_SEQ,
"%s: oos pkt %u len %d discarded, waiting for %u, reorder_q_len=%d\n", "%s: oos pkt %u len %d discarded, waiting for %u, reorder_q_len=%d\n",
session->name, L2TP_SKB_CB(skb)->ns, session->name, L2TP_SKB_CB(skb)->ns,
...@@ -816,9 +793,7 @@ void l2tp_recv_common(struct l2tp_session *session, struct sk_buff *skb, ...@@ -816,9 +793,7 @@ void l2tp_recv_common(struct l2tp_session *session, struct sk_buff *skb,
return; return;
discard: discard:
u64_stats_update_begin(&sstats->syncp); atomic_long_inc(&session->stats.rx_errors);
sstats->rx_errors++;
u64_stats_update_end(&sstats->syncp);
kfree_skb(skb); kfree_skb(skb);
if (session->deref) if (session->deref)
...@@ -828,6 +803,23 @@ void l2tp_recv_common(struct l2tp_session *session, struct sk_buff *skb, ...@@ -828,6 +803,23 @@ void l2tp_recv_common(struct l2tp_session *session, struct sk_buff *skb,
} }
EXPORT_SYMBOL(l2tp_recv_common); EXPORT_SYMBOL(l2tp_recv_common);
/* Drop skbs from the session's reorder_q
*/
int l2tp_session_queue_purge(struct l2tp_session *session)
{
struct sk_buff *skb = NULL;
BUG_ON(!session);
BUG_ON(session->magic != L2TP_SESSION_MAGIC);
while ((skb = skb_dequeue(&session->reorder_q))) {
atomic_long_inc(&session->stats.rx_errors);
kfree_skb(skb);
if (session->deref)
(*session->deref)(session);
}
return 0;
}
EXPORT_SYMBOL_GPL(l2tp_session_queue_purge);
/* Internal UDP receive frame. Do the real work of receiving an L2TP data frame /* Internal UDP receive frame. Do the real work of receiving an L2TP data frame
* here. The skb is not on a list when we get here. * here. The skb is not on a list when we get here.
* Returns 0 if the packet was a data packet and was successfully passed on. * Returns 0 if the packet was a data packet and was successfully passed on.
...@@ -843,7 +835,6 @@ static int l2tp_udp_recv_core(struct l2tp_tunnel *tunnel, struct sk_buff *skb, ...@@ -843,7 +835,6 @@ static int l2tp_udp_recv_core(struct l2tp_tunnel *tunnel, struct sk_buff *skb,
u32 tunnel_id, session_id; u32 tunnel_id, session_id;
u16 version; u16 version;
int length; int length;
struct l2tp_stats *tstats;
if (tunnel->sock && l2tp_verify_udp_checksum(tunnel->sock, skb)) if (tunnel->sock && l2tp_verify_udp_checksum(tunnel->sock, skb))
goto discard_bad_csum; goto discard_bad_csum;
...@@ -932,10 +923,7 @@ static int l2tp_udp_recv_core(struct l2tp_tunnel *tunnel, struct sk_buff *skb, ...@@ -932,10 +923,7 @@ static int l2tp_udp_recv_core(struct l2tp_tunnel *tunnel, struct sk_buff *skb,
discard_bad_csum: discard_bad_csum:
LIMIT_NETDEBUG("%s: UDP: bad checksum\n", tunnel->name); LIMIT_NETDEBUG("%s: UDP: bad checksum\n", tunnel->name);
UDP_INC_STATS_USER(tunnel->l2tp_net, UDP_MIB_INERRORS, 0); UDP_INC_STATS_USER(tunnel->l2tp_net, UDP_MIB_INERRORS, 0);
tstats = &tunnel->stats; atomic_long_inc(&tunnel->stats.rx_errors);
u64_stats_update_begin(&tstats->syncp);
tstats->rx_errors++;
u64_stats_update_end(&tstats->syncp);
kfree_skb(skb); kfree_skb(skb);
return 0; return 0;
...@@ -1062,7 +1050,6 @@ static int l2tp_xmit_core(struct l2tp_session *session, struct sk_buff *skb, ...@@ -1062,7 +1050,6 @@ static int l2tp_xmit_core(struct l2tp_session *session, struct sk_buff *skb,
struct l2tp_tunnel *tunnel = session->tunnel; struct l2tp_tunnel *tunnel = session->tunnel;
unsigned int len = skb->len; unsigned int len = skb->len;
int error; int error;
struct l2tp_stats *tstats, *sstats;
/* Debug */ /* Debug */
if (session->send_seq) if (session->send_seq)
...@@ -1091,21 +1078,15 @@ static int l2tp_xmit_core(struct l2tp_session *session, struct sk_buff *skb, ...@@ -1091,21 +1078,15 @@ static int l2tp_xmit_core(struct l2tp_session *session, struct sk_buff *skb,
error = ip_queue_xmit(skb, fl); error = ip_queue_xmit(skb, fl);
/* Update stats */ /* Update stats */
tstats = &tunnel->stats;
u64_stats_update_begin(&tstats->syncp);
sstats = &session->stats;
u64_stats_update_begin(&sstats->syncp);
if (error >= 0) { if (error >= 0) {
tstats->tx_packets++; atomic_long_inc(&tunnel->stats.tx_packets);
tstats->tx_bytes += len; atomic_long_add(len, &tunnel->stats.tx_bytes);
sstats->tx_packets++; atomic_long_inc(&session->stats.tx_packets);
sstats->tx_bytes += len; atomic_long_add(len, &session->stats.tx_bytes);
} else { } else {
tstats->tx_errors++; atomic_long_inc(&tunnel->stats.tx_errors);
sstats->tx_errors++; atomic_long_inc(&session->stats.tx_errors);
} }
u64_stats_update_end(&tstats->syncp);
u64_stats_update_end(&sstats->syncp);
return 0; return 0;
} }
...@@ -1282,6 +1263,7 @@ static void l2tp_tunnel_destruct(struct sock *sk) ...@@ -1282,6 +1263,7 @@ static void l2tp_tunnel_destruct(struct sock *sk)
/* No longer an encapsulation socket. See net/ipv4/udp.c */ /* No longer an encapsulation socket. See net/ipv4/udp.c */
(udp_sk(sk))->encap_type = 0; (udp_sk(sk))->encap_type = 0;
(udp_sk(sk))->encap_rcv = NULL; (udp_sk(sk))->encap_rcv = NULL;
(udp_sk(sk))->encap_destroy = NULL;
break; break;
case L2TP_ENCAPTYPE_IP: case L2TP_ENCAPTYPE_IP:
break; break;
...@@ -1311,7 +1293,7 @@ static void l2tp_tunnel_destruct(struct sock *sk) ...@@ -1311,7 +1293,7 @@ static void l2tp_tunnel_destruct(struct sock *sk)
/* When the tunnel is closed, all the attached sessions need to go too. /* When the tunnel is closed, all the attached sessions need to go too.
*/ */
static void l2tp_tunnel_closeall(struct l2tp_tunnel *tunnel) void l2tp_tunnel_closeall(struct l2tp_tunnel *tunnel)
{ {
int hash; int hash;
struct hlist_node *walk; struct hlist_node *walk;
...@@ -1334,25 +1316,13 @@ static void l2tp_tunnel_closeall(struct l2tp_tunnel *tunnel) ...@@ -1334,25 +1316,13 @@ static void l2tp_tunnel_closeall(struct l2tp_tunnel *tunnel)
hlist_del_init(&session->hlist); hlist_del_init(&session->hlist);
/* Since we should hold the sock lock while
* doing any unbinding, we need to release the
* lock we're holding before taking that lock.
* Hold a reference to the sock so it doesn't
* disappear as we're jumping between locks.
*/
if (session->ref != NULL) if (session->ref != NULL)
(*session->ref)(session); (*session->ref)(session);
write_unlock_bh(&tunnel->hlist_lock); write_unlock_bh(&tunnel->hlist_lock);
if (tunnel->version != L2TP_HDR_VER_2) { __l2tp_session_unhash(session);
struct l2tp_net *pn = l2tp_pernet(tunnel->l2tp_net); l2tp_session_queue_purge(session);
spin_lock_bh(&pn->l2tp_session_hlist_lock);
hlist_del_init_rcu(&session->global_hlist);
spin_unlock_bh(&pn->l2tp_session_hlist_lock);
synchronize_rcu();
}
if (session->session_close != NULL) if (session->session_close != NULL)
(*session->session_close)(session); (*session->session_close)(session);
...@@ -1360,6 +1330,8 @@ static void l2tp_tunnel_closeall(struct l2tp_tunnel *tunnel) ...@@ -1360,6 +1330,8 @@ static void l2tp_tunnel_closeall(struct l2tp_tunnel *tunnel)
if (session->deref != NULL) if (session->deref != NULL)
(*session->deref)(session); (*session->deref)(session);
l2tp_session_dec_refcount(session);
write_lock_bh(&tunnel->hlist_lock); write_lock_bh(&tunnel->hlist_lock);
/* Now restart from the beginning of this hash /* Now restart from the beginning of this hash
...@@ -1372,6 +1344,17 @@ static void l2tp_tunnel_closeall(struct l2tp_tunnel *tunnel) ...@@ -1372,6 +1344,17 @@ static void l2tp_tunnel_closeall(struct l2tp_tunnel *tunnel)
} }
write_unlock_bh(&tunnel->hlist_lock); write_unlock_bh(&tunnel->hlist_lock);
} }
EXPORT_SYMBOL_GPL(l2tp_tunnel_closeall);
/* Tunnel socket destroy hook for UDP encapsulation */
static void l2tp_udp_encap_destroy(struct sock *sk)
{
struct l2tp_tunnel *tunnel = l2tp_sock_to_tunnel(sk);
if (tunnel) {
l2tp_tunnel_closeall(tunnel);
sock_put(sk);
}
}
/* Really kill the tunnel. /* Really kill the tunnel.
* Come here only when all sessions have been cleared from the tunnel. * Come here only when all sessions have been cleared from the tunnel.
...@@ -1397,19 +1380,21 @@ static void l2tp_tunnel_del_work(struct work_struct *work) ...@@ -1397,19 +1380,21 @@ static void l2tp_tunnel_del_work(struct work_struct *work)
return; return;
sock = sk->sk_socket; sock = sk->sk_socket;
BUG_ON(!sock);
/* If the tunnel socket was created directly by the kernel, use the /* If the tunnel socket was created by userspace, then go through the
* sk_* API to release the socket now. Otherwise go through the * inet layer to shut the socket down, and let userspace close it.
* inet_* layer to shut the socket down, and let userspace close it. * Otherwise, if we created the socket directly within the kernel, use
* the sk API to release it here.
* In either case the tunnel resources are freed in the socket * In either case the tunnel resources are freed in the socket
* destructor when the tunnel socket goes away. * destructor when the tunnel socket goes away.
*/ */
if (sock->file == NULL) { if (tunnel->fd >= 0) {
if (sock)
inet_shutdown(sock, 2);
} else {
if (sock)
kernel_sock_shutdown(sock, SHUT_RDWR); kernel_sock_shutdown(sock, SHUT_RDWR);
sk_release_kernel(sk); sk_release_kernel(sk);
} else {
inet_shutdown(sock, 2);
} }
l2tp_tunnel_sock_put(sk); l2tp_tunnel_sock_put(sk);
...@@ -1668,6 +1653,7 @@ int l2tp_tunnel_create(struct net *net, int fd, int version, u32 tunnel_id, u32 ...@@ -1668,6 +1653,7 @@ int l2tp_tunnel_create(struct net *net, int fd, int version, u32 tunnel_id, u32
/* Mark socket as an encapsulation socket. See net/ipv4/udp.c */ /* Mark socket as an encapsulation socket. See net/ipv4/udp.c */
udp_sk(sk)->encap_type = UDP_ENCAP_L2TPINUDP; udp_sk(sk)->encap_type = UDP_ENCAP_L2TPINUDP;
udp_sk(sk)->encap_rcv = l2tp_udp_encap_recv; udp_sk(sk)->encap_rcv = l2tp_udp_encap_recv;
udp_sk(sk)->encap_destroy = l2tp_udp_encap_destroy;
#if IS_ENABLED(CONFIG_IPV6) #if IS_ENABLED(CONFIG_IPV6)
if (sk->sk_family == PF_INET6) if (sk->sk_family == PF_INET6)
udpv6_encap_enable(); udpv6_encap_enable();
...@@ -1723,6 +1709,7 @@ EXPORT_SYMBOL_GPL(l2tp_tunnel_create); ...@@ -1723,6 +1709,7 @@ EXPORT_SYMBOL_GPL(l2tp_tunnel_create);
*/ */
int l2tp_tunnel_delete(struct l2tp_tunnel *tunnel) int l2tp_tunnel_delete(struct l2tp_tunnel *tunnel)
{ {
l2tp_tunnel_closeall(tunnel);
return (false == queue_work(l2tp_wq, &tunnel->del_work)); return (false == queue_work(l2tp_wq, &tunnel->del_work));
} }
EXPORT_SYMBOL_GPL(l2tp_tunnel_delete); EXPORT_SYMBOL_GPL(l2tp_tunnel_delete);
...@@ -1731,62 +1718,71 @@ EXPORT_SYMBOL_GPL(l2tp_tunnel_delete); ...@@ -1731,62 +1718,71 @@ EXPORT_SYMBOL_GPL(l2tp_tunnel_delete);
*/ */
void l2tp_session_free(struct l2tp_session *session) void l2tp_session_free(struct l2tp_session *session)
{ {
struct l2tp_tunnel *tunnel; struct l2tp_tunnel *tunnel = session->tunnel;
BUG_ON(atomic_read(&session->ref_count) != 0); BUG_ON(atomic_read(&session->ref_count) != 0);
tunnel = session->tunnel; if (tunnel) {
if (tunnel != NULL) {
BUG_ON(tunnel->magic != L2TP_TUNNEL_MAGIC); BUG_ON(tunnel->magic != L2TP_TUNNEL_MAGIC);
if (session->session_id != 0)
atomic_dec(&l2tp_session_count);
sock_put(tunnel->sock);
session->tunnel = NULL;
l2tp_tunnel_dec_refcount(tunnel);
}
kfree(session);
return;
}
EXPORT_SYMBOL_GPL(l2tp_session_free);
/* Remove an l2tp session from l2tp_core's hash lists.
* Provides a tidyup interface for pseudowire code which can't just route all
* shutdown via. l2tp_session_delete and a pseudowire-specific session_close
* callback.
*/
void __l2tp_session_unhash(struct l2tp_session *session)
{
struct l2tp_tunnel *tunnel = session->tunnel;
/* Delete the session from the hash */ /* Remove the session from core hashes */
if (tunnel) {
/* Remove from the per-tunnel hash */
write_lock_bh(&tunnel->hlist_lock); write_lock_bh(&tunnel->hlist_lock);
hlist_del_init(&session->hlist); hlist_del_init(&session->hlist);
write_unlock_bh(&tunnel->hlist_lock); write_unlock_bh(&tunnel->hlist_lock);
/* Unlink from the global hash if not L2TPv2 */ /* For L2TPv3 we have a per-net hash: remove from there, too */
if (tunnel->version != L2TP_HDR_VER_2) { if (tunnel->version != L2TP_HDR_VER_2) {
struct l2tp_net *pn = l2tp_pernet(tunnel->l2tp_net); struct l2tp_net *pn = l2tp_pernet(tunnel->l2tp_net);
spin_lock_bh(&pn->l2tp_session_hlist_lock); spin_lock_bh(&pn->l2tp_session_hlist_lock);
hlist_del_init_rcu(&session->global_hlist); hlist_del_init_rcu(&session->global_hlist);
spin_unlock_bh(&pn->l2tp_session_hlist_lock); spin_unlock_bh(&pn->l2tp_session_hlist_lock);
synchronize_rcu(); synchronize_rcu();
} }
if (session->session_id != 0)
atomic_dec(&l2tp_session_count);
sock_put(tunnel->sock);
/* This will delete the tunnel context if this
* is the last session on the tunnel.
*/
session->tunnel = NULL;
l2tp_tunnel_dec_refcount(tunnel);
} }
kfree(session);
return;
} }
EXPORT_SYMBOL_GPL(l2tp_session_free); EXPORT_SYMBOL_GPL(__l2tp_session_unhash);
/* This function is used by the netlink SESSION_DELETE command and by /* This function is used by the netlink SESSION_DELETE command and by
pseudowire modules. pseudowire modules.
*/ */
int l2tp_session_delete(struct l2tp_session *session) int l2tp_session_delete(struct l2tp_session *session)
{ {
if (session->ref)
(*session->ref)(session);
__l2tp_session_unhash(session);
l2tp_session_queue_purge(session);
if (session->session_close != NULL) if (session->session_close != NULL)
(*session->session_close)(session); (*session->session_close)(session);
if (session->deref)
(*session->ref)(session);
l2tp_session_dec_refcount(session); l2tp_session_dec_refcount(session);
return 0; return 0;
} }
EXPORT_SYMBOL_GPL(l2tp_session_delete); EXPORT_SYMBOL_GPL(l2tp_session_delete);
/* We come here whenever a session's send_seq, cookie_len or /* We come here whenever a session's send_seq, cookie_len or
* l2specific_len parameters are set. * l2specific_len parameters are set.
*/ */
......
...@@ -36,16 +36,15 @@ enum { ...@@ -36,16 +36,15 @@ enum {
struct sk_buff; struct sk_buff;
struct l2tp_stats { struct l2tp_stats {
u64 tx_packets; atomic_long_t tx_packets;
u64 tx_bytes; atomic_long_t tx_bytes;
u64 tx_errors; atomic_long_t tx_errors;
u64 rx_packets; atomic_long_t rx_packets;
u64 rx_bytes; atomic_long_t rx_bytes;
u64 rx_seq_discards; atomic_long_t rx_seq_discards;
u64 rx_oos_packets; atomic_long_t rx_oos_packets;
u64 rx_errors; atomic_long_t rx_errors;
u64 rx_cookie_discards; atomic_long_t rx_cookie_discards;
struct u64_stats_sync syncp;
}; };
struct l2tp_tunnel; struct l2tp_tunnel;
...@@ -240,11 +239,14 @@ extern struct l2tp_tunnel *l2tp_tunnel_find(struct net *net, u32 tunnel_id); ...@@ -240,11 +239,14 @@ extern struct l2tp_tunnel *l2tp_tunnel_find(struct net *net, u32 tunnel_id);
extern struct l2tp_tunnel *l2tp_tunnel_find_nth(struct net *net, int nth); extern struct l2tp_tunnel *l2tp_tunnel_find_nth(struct net *net, int nth);
extern int l2tp_tunnel_create(struct net *net, int fd, int version, u32 tunnel_id, u32 peer_tunnel_id, struct l2tp_tunnel_cfg *cfg, struct l2tp_tunnel **tunnelp); extern int l2tp_tunnel_create(struct net *net, int fd, int version, u32 tunnel_id, u32 peer_tunnel_id, struct l2tp_tunnel_cfg *cfg, struct l2tp_tunnel **tunnelp);
extern void l2tp_tunnel_closeall(struct l2tp_tunnel *tunnel);
extern int l2tp_tunnel_delete(struct l2tp_tunnel *tunnel); extern int l2tp_tunnel_delete(struct l2tp_tunnel *tunnel);
extern struct l2tp_session *l2tp_session_create(int priv_size, struct l2tp_tunnel *tunnel, u32 session_id, u32 peer_session_id, struct l2tp_session_cfg *cfg); extern struct l2tp_session *l2tp_session_create(int priv_size, struct l2tp_tunnel *tunnel, u32 session_id, u32 peer_session_id, struct l2tp_session_cfg *cfg);
extern void __l2tp_session_unhash(struct l2tp_session *session);
extern int l2tp_session_delete(struct l2tp_session *session); extern int l2tp_session_delete(struct l2tp_session *session);
extern void l2tp_session_free(struct l2tp_session *session); extern void l2tp_session_free(struct l2tp_session *session);
extern void l2tp_recv_common(struct l2tp_session *session, struct sk_buff *skb, unsigned char *ptr, unsigned char *optr, u16 hdrflags, int length, int (*payload_hook)(struct sk_buff *skb)); extern void l2tp_recv_common(struct l2tp_session *session, struct sk_buff *skb, unsigned char *ptr, unsigned char *optr, u16 hdrflags, int length, int (*payload_hook)(struct sk_buff *skb));
extern int l2tp_session_queue_purge(struct l2tp_session *session);
extern int l2tp_udp_encap_recv(struct sock *sk, struct sk_buff *skb); extern int l2tp_udp_encap_recv(struct sock *sk, struct sk_buff *skb);
extern int l2tp_xmit_skb(struct l2tp_session *session, struct sk_buff *skb, int hdr_len); extern int l2tp_xmit_skb(struct l2tp_session *session, struct sk_buff *skb, int hdr_len);
......
...@@ -146,14 +146,14 @@ static void l2tp_dfs_seq_tunnel_show(struct seq_file *m, void *v) ...@@ -146,14 +146,14 @@ static void l2tp_dfs_seq_tunnel_show(struct seq_file *m, void *v)
tunnel->sock ? atomic_read(&tunnel->sock->sk_refcnt) : 0, tunnel->sock ? atomic_read(&tunnel->sock->sk_refcnt) : 0,
atomic_read(&tunnel->ref_count)); atomic_read(&tunnel->ref_count));
seq_printf(m, " %08x rx %llu/%llu/%llu rx %llu/%llu/%llu\n", seq_printf(m, " %08x rx %ld/%ld/%ld rx %ld/%ld/%ld\n",
tunnel->debug, tunnel->debug,
(unsigned long long)tunnel->stats.tx_packets, atomic_long_read(&tunnel->stats.tx_packets),
(unsigned long long)tunnel->stats.tx_bytes, atomic_long_read(&tunnel->stats.tx_bytes),
(unsigned long long)tunnel->stats.tx_errors, atomic_long_read(&tunnel->stats.tx_errors),
(unsigned long long)tunnel->stats.rx_packets, atomic_long_read(&tunnel->stats.rx_packets),
(unsigned long long)tunnel->stats.rx_bytes, atomic_long_read(&tunnel->stats.rx_bytes),
(unsigned long long)tunnel->stats.rx_errors); atomic_long_read(&tunnel->stats.rx_errors));
if (tunnel->show != NULL) if (tunnel->show != NULL)
tunnel->show(m, tunnel); tunnel->show(m, tunnel);
...@@ -203,14 +203,14 @@ static void l2tp_dfs_seq_session_show(struct seq_file *m, void *v) ...@@ -203,14 +203,14 @@ static void l2tp_dfs_seq_session_show(struct seq_file *m, void *v)
seq_printf(m, "\n"); seq_printf(m, "\n");
} }
seq_printf(m, " %hu/%hu tx %llu/%llu/%llu rx %llu/%llu/%llu\n", seq_printf(m, " %hu/%hu tx %ld/%ld/%ld rx %ld/%ld/%ld\n",
session->nr, session->ns, session->nr, session->ns,
(unsigned long long)session->stats.tx_packets, atomic_long_read(&session->stats.tx_packets),
(unsigned long long)session->stats.tx_bytes, atomic_long_read(&session->stats.tx_bytes),
(unsigned long long)session->stats.tx_errors, atomic_long_read(&session->stats.tx_errors),
(unsigned long long)session->stats.rx_packets, atomic_long_read(&session->stats.rx_packets),
(unsigned long long)session->stats.rx_bytes, atomic_long_read(&session->stats.rx_bytes),
(unsigned long long)session->stats.rx_errors); atomic_long_read(&session->stats.rx_errors));
if (session->show != NULL) if (session->show != NULL)
session->show(m, session); session->show(m, session);
......
...@@ -228,10 +228,16 @@ static void l2tp_ip_close(struct sock *sk, long timeout) ...@@ -228,10 +228,16 @@ static void l2tp_ip_close(struct sock *sk, long timeout)
static void l2tp_ip_destroy_sock(struct sock *sk) static void l2tp_ip_destroy_sock(struct sock *sk)
{ {
struct sk_buff *skb; struct sk_buff *skb;
struct l2tp_tunnel *tunnel = l2tp_sock_to_tunnel(sk);
while ((skb = __skb_dequeue_tail(&sk->sk_write_queue)) != NULL) while ((skb = __skb_dequeue_tail(&sk->sk_write_queue)) != NULL)
kfree_skb(skb); kfree_skb(skb);
if (tunnel) {
l2tp_tunnel_closeall(tunnel);
sock_put(sk);
}
sk_refcnt_debug_dec(sk); sk_refcnt_debug_dec(sk);
} }
......
...@@ -241,10 +241,17 @@ static void l2tp_ip6_close(struct sock *sk, long timeout) ...@@ -241,10 +241,17 @@ static void l2tp_ip6_close(struct sock *sk, long timeout)
static void l2tp_ip6_destroy_sock(struct sock *sk) static void l2tp_ip6_destroy_sock(struct sock *sk)
{ {
struct l2tp_tunnel *tunnel = l2tp_sock_to_tunnel(sk);
lock_sock(sk); lock_sock(sk);
ip6_flush_pending_frames(sk); ip6_flush_pending_frames(sk);
release_sock(sk); release_sock(sk);
if (tunnel) {
l2tp_tunnel_closeall(tunnel);
sock_put(sk);
}
inet6_destroy_sock(sk); inet6_destroy_sock(sk);
} }
......
...@@ -246,8 +246,6 @@ static int l2tp_nl_tunnel_send(struct sk_buff *skb, u32 portid, u32 seq, int fla ...@@ -246,8 +246,6 @@ static int l2tp_nl_tunnel_send(struct sk_buff *skb, u32 portid, u32 seq, int fla
#if IS_ENABLED(CONFIG_IPV6) #if IS_ENABLED(CONFIG_IPV6)
struct ipv6_pinfo *np = NULL; struct ipv6_pinfo *np = NULL;
#endif #endif
struct l2tp_stats stats;
unsigned int start;
hdr = genlmsg_put(skb, portid, seq, &l2tp_nl_family, flags, hdr = genlmsg_put(skb, portid, seq, &l2tp_nl_family, flags,
L2TP_CMD_TUNNEL_GET); L2TP_CMD_TUNNEL_GET);
...@@ -265,28 +263,22 @@ static int l2tp_nl_tunnel_send(struct sk_buff *skb, u32 portid, u32 seq, int fla ...@@ -265,28 +263,22 @@ static int l2tp_nl_tunnel_send(struct sk_buff *skb, u32 portid, u32 seq, int fla
if (nest == NULL) if (nest == NULL)
goto nla_put_failure; goto nla_put_failure;
do { if (nla_put_u64(skb, L2TP_ATTR_TX_PACKETS,
start = u64_stats_fetch_begin(&tunnel->stats.syncp); atomic_long_read(&tunnel->stats.tx_packets)) ||
stats.tx_packets = tunnel->stats.tx_packets; nla_put_u64(skb, L2TP_ATTR_TX_BYTES,
stats.tx_bytes = tunnel->stats.tx_bytes; atomic_long_read(&tunnel->stats.tx_bytes)) ||
stats.tx_errors = tunnel->stats.tx_errors; nla_put_u64(skb, L2TP_ATTR_TX_ERRORS,
stats.rx_packets = tunnel->stats.rx_packets; atomic_long_read(&tunnel->stats.tx_errors)) ||
stats.rx_bytes = tunnel->stats.rx_bytes; nla_put_u64(skb, L2TP_ATTR_RX_PACKETS,
stats.rx_errors = tunnel->stats.rx_errors; atomic_long_read(&tunnel->stats.rx_packets)) ||
stats.rx_seq_discards = tunnel->stats.rx_seq_discards; nla_put_u64(skb, L2TP_ATTR_RX_BYTES,
stats.rx_oos_packets = tunnel->stats.rx_oos_packets; atomic_long_read(&tunnel->stats.rx_bytes)) ||
} while (u64_stats_fetch_retry(&tunnel->stats.syncp, start));
if (nla_put_u64(skb, L2TP_ATTR_TX_PACKETS, stats.tx_packets) ||
nla_put_u64(skb, L2TP_ATTR_TX_BYTES, stats.tx_bytes) ||
nla_put_u64(skb, L2TP_ATTR_TX_ERRORS, stats.tx_errors) ||
nla_put_u64(skb, L2TP_ATTR_RX_PACKETS, stats.rx_packets) ||
nla_put_u64(skb, L2TP_ATTR_RX_BYTES, stats.rx_bytes) ||
nla_put_u64(skb, L2TP_ATTR_RX_SEQ_DISCARDS, nla_put_u64(skb, L2TP_ATTR_RX_SEQ_DISCARDS,
stats.rx_seq_discards) || atomic_long_read(&tunnel->stats.rx_seq_discards)) ||
nla_put_u64(skb, L2TP_ATTR_RX_OOS_PACKETS, nla_put_u64(skb, L2TP_ATTR_RX_OOS_PACKETS,
stats.rx_oos_packets) || atomic_long_read(&tunnel->stats.rx_oos_packets)) ||
nla_put_u64(skb, L2TP_ATTR_RX_ERRORS, stats.rx_errors)) nla_put_u64(skb, L2TP_ATTR_RX_ERRORS,
atomic_long_read(&tunnel->stats.rx_errors)))
goto nla_put_failure; goto nla_put_failure;
nla_nest_end(skb, nest); nla_nest_end(skb, nest);
...@@ -612,8 +604,6 @@ static int l2tp_nl_session_send(struct sk_buff *skb, u32 portid, u32 seq, int fl ...@@ -612,8 +604,6 @@ static int l2tp_nl_session_send(struct sk_buff *skb, u32 portid, u32 seq, int fl
struct nlattr *nest; struct nlattr *nest;
struct l2tp_tunnel *tunnel = session->tunnel; struct l2tp_tunnel *tunnel = session->tunnel;
struct sock *sk = NULL; struct sock *sk = NULL;
struct l2tp_stats stats;
unsigned int start;
sk = tunnel->sock; sk = tunnel->sock;
...@@ -656,28 +646,22 @@ static int l2tp_nl_session_send(struct sk_buff *skb, u32 portid, u32 seq, int fl ...@@ -656,28 +646,22 @@ static int l2tp_nl_session_send(struct sk_buff *skb, u32 portid, u32 seq, int fl
if (nest == NULL) if (nest == NULL)
goto nla_put_failure; goto nla_put_failure;
do { if (nla_put_u64(skb, L2TP_ATTR_TX_PACKETS,
start = u64_stats_fetch_begin(&session->stats.syncp); atomic_long_read(&session->stats.tx_packets)) ||
stats.tx_packets = session->stats.tx_packets; nla_put_u64(skb, L2TP_ATTR_TX_BYTES,
stats.tx_bytes = session->stats.tx_bytes; atomic_long_read(&session->stats.tx_bytes)) ||
stats.tx_errors = session->stats.tx_errors; nla_put_u64(skb, L2TP_ATTR_TX_ERRORS,
stats.rx_packets = session->stats.rx_packets; atomic_long_read(&session->stats.tx_errors)) ||
stats.rx_bytes = session->stats.rx_bytes; nla_put_u64(skb, L2TP_ATTR_RX_PACKETS,
stats.rx_errors = session->stats.rx_errors; atomic_long_read(&session->stats.rx_packets)) ||
stats.rx_seq_discards = session->stats.rx_seq_discards; nla_put_u64(skb, L2TP_ATTR_RX_BYTES,
stats.rx_oos_packets = session->stats.rx_oos_packets; atomic_long_read(&session->stats.rx_bytes)) ||
} while (u64_stats_fetch_retry(&session->stats.syncp, start));
if (nla_put_u64(skb, L2TP_ATTR_TX_PACKETS, stats.tx_packets) ||
nla_put_u64(skb, L2TP_ATTR_TX_BYTES, stats.tx_bytes) ||
nla_put_u64(skb, L2TP_ATTR_TX_ERRORS, stats.tx_errors) ||
nla_put_u64(skb, L2TP_ATTR_RX_PACKETS, stats.rx_packets) ||
nla_put_u64(skb, L2TP_ATTR_RX_BYTES, stats.rx_bytes) ||
nla_put_u64(skb, L2TP_ATTR_RX_SEQ_DISCARDS, nla_put_u64(skb, L2TP_ATTR_RX_SEQ_DISCARDS,
stats.rx_seq_discards) || atomic_long_read(&session->stats.rx_seq_discards)) ||
nla_put_u64(skb, L2TP_ATTR_RX_OOS_PACKETS, nla_put_u64(skb, L2TP_ATTR_RX_OOS_PACKETS,
stats.rx_oos_packets) || atomic_long_read(&session->stats.rx_oos_packets)) ||
nla_put_u64(skb, L2TP_ATTR_RX_ERRORS, stats.rx_errors)) nla_put_u64(skb, L2TP_ATTR_RX_ERRORS,
atomic_long_read(&session->stats.rx_errors)))
goto nla_put_failure; goto nla_put_failure;
nla_nest_end(skb, nest); nla_nest_end(skb, nest);
......
...@@ -97,6 +97,7 @@ ...@@ -97,6 +97,7 @@
#include <net/ip.h> #include <net/ip.h>
#include <net/udp.h> #include <net/udp.h>
#include <net/xfrm.h> #include <net/xfrm.h>
#include <net/inet_common.h>
#include <asm/byteorder.h> #include <asm/byteorder.h>
#include <linux/atomic.h> #include <linux/atomic.h>
...@@ -259,7 +260,7 @@ static void pppol2tp_recv(struct l2tp_session *session, struct sk_buff *skb, int ...@@ -259,7 +260,7 @@ static void pppol2tp_recv(struct l2tp_session *session, struct sk_buff *skb, int
session->name); session->name);
/* Not bound. Nothing we can do, so discard. */ /* Not bound. Nothing we can do, so discard. */
session->stats.rx_errors++; atomic_long_inc(&session->stats.rx_errors);
kfree_skb(skb); kfree_skb(skb);
} }
...@@ -447,34 +448,16 @@ static void pppol2tp_session_close(struct l2tp_session *session) ...@@ -447,34 +448,16 @@ static void pppol2tp_session_close(struct l2tp_session *session)
{ {
struct pppol2tp_session *ps = l2tp_session_priv(session); struct pppol2tp_session *ps = l2tp_session_priv(session);
struct sock *sk = ps->sock; struct sock *sk = ps->sock;
struct sk_buff *skb; struct socket *sock = sk->sk_socket;
BUG_ON(session->magic != L2TP_SESSION_MAGIC); BUG_ON(session->magic != L2TP_SESSION_MAGIC);
if (session->session_id == 0)
goto out;
if (sk != NULL) {
lock_sock(sk);
if (sk->sk_state & (PPPOX_CONNECTED | PPPOX_BOUND)) { if (sock) {
pppox_unbind_sock(sk); inet_shutdown(sock, 2);
sk->sk_state = PPPOX_DEAD; /* Don't let the session go away before our socket does */
sk->sk_state_change(sk); l2tp_session_inc_refcount(session);
} }
/* Purge any queued data */
skb_queue_purge(&sk->sk_receive_queue);
skb_queue_purge(&sk->sk_write_queue);
while ((skb = skb_dequeue(&session->reorder_q))) {
kfree_skb(skb);
sock_put(sk);
}
release_sock(sk);
}
out:
return; return;
} }
...@@ -483,19 +466,12 @@ static void pppol2tp_session_close(struct l2tp_session *session) ...@@ -483,19 +466,12 @@ static void pppol2tp_session_close(struct l2tp_session *session)
*/ */
static void pppol2tp_session_destruct(struct sock *sk) static void pppol2tp_session_destruct(struct sock *sk)
{ {
struct l2tp_session *session; struct l2tp_session *session = sk->sk_user_data;
if (session) {
if (sk->sk_user_data != NULL) {
session = sk->sk_user_data;
if (session == NULL)
goto out;
sk->sk_user_data = NULL; sk->sk_user_data = NULL;
BUG_ON(session->magic != L2TP_SESSION_MAGIC); BUG_ON(session->magic != L2TP_SESSION_MAGIC);
l2tp_session_dec_refcount(session); l2tp_session_dec_refcount(session);
} }
out:
return; return;
} }
...@@ -525,16 +501,13 @@ static int pppol2tp_release(struct socket *sock) ...@@ -525,16 +501,13 @@ static int pppol2tp_release(struct socket *sock)
session = pppol2tp_sock_to_session(sk); session = pppol2tp_sock_to_session(sk);
/* Purge any queued data */ /* Purge any queued data */
skb_queue_purge(&sk->sk_receive_queue);
skb_queue_purge(&sk->sk_write_queue);
if (session != NULL) { if (session != NULL) {
struct sk_buff *skb; __l2tp_session_unhash(session);
while ((skb = skb_dequeue(&session->reorder_q))) { l2tp_session_queue_purge(session);
kfree_skb(skb);
sock_put(sk);
}
sock_put(sk); sock_put(sk);
} }
skb_queue_purge(&sk->sk_receive_queue);
skb_queue_purge(&sk->sk_write_queue);
release_sock(sk); release_sock(sk);
...@@ -880,18 +853,6 @@ static int pppol2tp_session_create(struct net *net, u32 tunnel_id, u32 session_i ...@@ -880,18 +853,6 @@ static int pppol2tp_session_create(struct net *net, u32 tunnel_id, u32 session_i
return error; return error;
} }
/* Called when deleting sessions via the netlink interface.
*/
static int pppol2tp_session_delete(struct l2tp_session *session)
{
struct pppol2tp_session *ps = l2tp_session_priv(session);
if (ps->sock == NULL)
l2tp_session_dec_refcount(session);
return 0;
}
#endif /* CONFIG_L2TP_V3 */ #endif /* CONFIG_L2TP_V3 */
/* getname() support. /* getname() support.
...@@ -1025,14 +986,14 @@ static int pppol2tp_getname(struct socket *sock, struct sockaddr *uaddr, ...@@ -1025,14 +986,14 @@ static int pppol2tp_getname(struct socket *sock, struct sockaddr *uaddr,
static void pppol2tp_copy_stats(struct pppol2tp_ioc_stats *dest, static void pppol2tp_copy_stats(struct pppol2tp_ioc_stats *dest,
struct l2tp_stats *stats) struct l2tp_stats *stats)
{ {
dest->tx_packets = stats->tx_packets; dest->tx_packets = atomic_long_read(&stats->tx_packets);
dest->tx_bytes = stats->tx_bytes; dest->tx_bytes = atomic_long_read(&stats->tx_bytes);
dest->tx_errors = stats->tx_errors; dest->tx_errors = atomic_long_read(&stats->tx_errors);
dest->rx_packets = stats->rx_packets; dest->rx_packets = atomic_long_read(&stats->rx_packets);
dest->rx_bytes = stats->rx_bytes; dest->rx_bytes = atomic_long_read(&stats->rx_bytes);
dest->rx_seq_discards = stats->rx_seq_discards; dest->rx_seq_discards = atomic_long_read(&stats->rx_seq_discards);
dest->rx_oos_packets = stats->rx_oos_packets; dest->rx_oos_packets = atomic_long_read(&stats->rx_oos_packets);
dest->rx_errors = stats->rx_errors; dest->rx_errors = atomic_long_read(&stats->rx_errors);
} }
/* Session ioctl helper. /* Session ioctl helper.
...@@ -1666,14 +1627,14 @@ static void pppol2tp_seq_tunnel_show(struct seq_file *m, void *v) ...@@ -1666,14 +1627,14 @@ static void pppol2tp_seq_tunnel_show(struct seq_file *m, void *v)
tunnel->name, tunnel->name,
(tunnel == tunnel->sock->sk_user_data) ? 'Y' : 'N', (tunnel == tunnel->sock->sk_user_data) ? 'Y' : 'N',
atomic_read(&tunnel->ref_count) - 1); atomic_read(&tunnel->ref_count) - 1);
seq_printf(m, " %08x %llu/%llu/%llu %llu/%llu/%llu\n", seq_printf(m, " %08x %ld/%ld/%ld %ld/%ld/%ld\n",
tunnel->debug, tunnel->debug,
(unsigned long long)tunnel->stats.tx_packets, atomic_long_read(&tunnel->stats.tx_packets),
(unsigned long long)tunnel->stats.tx_bytes, atomic_long_read(&tunnel->stats.tx_bytes),
(unsigned long long)tunnel->stats.tx_errors, atomic_long_read(&tunnel->stats.tx_errors),
(unsigned long long)tunnel->stats.rx_packets, atomic_long_read(&tunnel->stats.rx_packets),
(unsigned long long)tunnel->stats.rx_bytes, atomic_long_read(&tunnel->stats.rx_bytes),
(unsigned long long)tunnel->stats.rx_errors); atomic_long_read(&tunnel->stats.rx_errors));
} }
static void pppol2tp_seq_session_show(struct seq_file *m, void *v) static void pppol2tp_seq_session_show(struct seq_file *m, void *v)
...@@ -1708,14 +1669,14 @@ static void pppol2tp_seq_session_show(struct seq_file *m, void *v) ...@@ -1708,14 +1669,14 @@ static void pppol2tp_seq_session_show(struct seq_file *m, void *v)
session->lns_mode ? "LNS" : "LAC", session->lns_mode ? "LNS" : "LAC",
session->debug, session->debug,
jiffies_to_msecs(session->reorder_timeout)); jiffies_to_msecs(session->reorder_timeout));
seq_printf(m, " %hu/%hu %llu/%llu/%llu %llu/%llu/%llu\n", seq_printf(m, " %hu/%hu %ld/%ld/%ld %ld/%ld/%ld\n",
session->nr, session->ns, session->nr, session->ns,
(unsigned long long)session->stats.tx_packets, atomic_long_read(&session->stats.tx_packets),
(unsigned long long)session->stats.tx_bytes, atomic_long_read(&session->stats.tx_bytes),
(unsigned long long)session->stats.tx_errors, atomic_long_read(&session->stats.tx_errors),
(unsigned long long)session->stats.rx_packets, atomic_long_read(&session->stats.rx_packets),
(unsigned long long)session->stats.rx_bytes, atomic_long_read(&session->stats.rx_bytes),
(unsigned long long)session->stats.rx_errors); atomic_long_read(&session->stats.rx_errors));
if (po) if (po)
seq_printf(m, " interface %s\n", ppp_dev_name(&po->chan)); seq_printf(m, " interface %s\n", ppp_dev_name(&po->chan));
...@@ -1839,7 +1800,7 @@ static const struct pppox_proto pppol2tp_proto = { ...@@ -1839,7 +1800,7 @@ static const struct pppox_proto pppol2tp_proto = {
static const struct l2tp_nl_cmd_ops pppol2tp_nl_cmd_ops = { static const struct l2tp_nl_cmd_ops pppol2tp_nl_cmd_ops = {
.session_create = pppol2tp_session_create, .session_create = pppol2tp_session_create,
.session_delete = pppol2tp_session_delete, .session_delete = l2tp_session_delete,
}; };
#endif /* CONFIG_L2TP_V3 */ #endif /* CONFIG_L2TP_V3 */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment