Lines Matching refs:tunnel
143 static void l2tp_tunnel_free(struct l2tp_tunnel *tunnel) in l2tp_tunnel_free() argument
145 struct sock *sk = tunnel->sock; in l2tp_tunnel_free()
147 trace_free_tunnel(tunnel); in l2tp_tunnel_free()
151 switch (tunnel->encap) { in l2tp_tunnel_free()
162 tunnel->sock = NULL; in l2tp_tunnel_free()
166 kfree_rcu(tunnel, rcu); in l2tp_tunnel_free()
172 if (session->tunnel) in l2tp_session_free()
173 l2tp_tunnel_put(session->tunnel); in l2tp_session_free()
181 struct l2tp_tunnel *tunnel; in l2tp_sk_to_tunnel() local
186 idr_for_each_entry_ul(&pn->l2tp_tunnel_idr, tunnel, tmp, tunnel_id) { in l2tp_sk_to_tunnel()
187 if (tunnel && in l2tp_sk_to_tunnel()
188 tunnel->sock == sk && in l2tp_sk_to_tunnel()
189 refcount_inc_not_zero(&tunnel->ref_count)) { in l2tp_sk_to_tunnel()
191 return tunnel; in l2tp_sk_to_tunnel()
200 void l2tp_tunnel_put(struct l2tp_tunnel *tunnel) in l2tp_tunnel_put() argument
202 if (refcount_dec_and_test(&tunnel->ref_count)) in l2tp_tunnel_put()
203 l2tp_tunnel_free(tunnel); in l2tp_tunnel_put()
218 struct l2tp_tunnel *tunnel; in l2tp_tunnel_get() local
221 tunnel = idr_find(&pn->l2tp_tunnel_idr, tunnel_id); in l2tp_tunnel_get()
222 if (tunnel && refcount_inc_not_zero(&tunnel->ref_count)) { in l2tp_tunnel_get()
224 return tunnel; in l2tp_tunnel_get()
235 struct l2tp_tunnel *tunnel = NULL; in l2tp_tunnel_get_next() local
239 tunnel = idr_get_next_ul(&pn->l2tp_tunnel_idr, key); in l2tp_tunnel_get_next()
240 if (tunnel) { in l2tp_tunnel_get_next()
241 if (refcount_inc_not_zero(&tunnel->ref_count)) { in l2tp_tunnel_get_next()
243 return tunnel; in l2tp_tunnel_get_next()
281 struct l2tp_tunnel *tunnel = READ_ONCE(session->tunnel); in l2tp_v3_session_get() local
284 tunnel && tunnel->sock == sk && in l2tp_v3_session_get()
340 struct l2tp_tunnel *tunnel = READ_ONCE(session->tunnel); in l2tp_v2_session_get_next() local
348 if (tunnel->tunnel_id == tid && in l2tp_v2_session_get_next()
355 if (tunnel->tunnel_id == tid) in l2tp_v2_session_get_next()
374 struct l2tp_tunnel *tunnel = READ_ONCE(session->tunnel); in l2tp_v3_session_get_next() local
376 if (tunnel && tunnel->tunnel_id == tid && in l2tp_v3_session_get_next()
397 struct l2tp_tunnel *tunnel = READ_ONCE(session->tunnel); in l2tp_v3_session_get_next() local
400 tunnel && tunnel->tunnel_id == tid && in l2tp_v3_session_get_next()
438 struct l2tp_tunnel *tunnel; in l2tp_session_get_by_ifname() local
441 idr_for_each_entry_ul(&pn->l2tp_tunnel_idr, tunnel, tmp, tunnel_id) { in l2tp_session_get_by_ifname()
442 if (tunnel) { in l2tp_session_get_by_ifname()
443 list_for_each_entry_rcu(session, &tunnel->session_list, list) { in l2tp_session_get_by_ifname()
482 if (session2->tunnel->encap == L2TP_ENCAPTYPE_IP) in l2tp_session_collision_add()
553 struct l2tp_tunnel *tunnel) in l2tp_session_register() argument
555 struct l2tp_net *pn = l2tp_pernet(tunnel->l2tp_net); in l2tp_session_register()
561 spin_lock_bh(&tunnel->list_lock); in l2tp_session_register()
564 if (!tunnel->acpt_newsess) { in l2tp_session_register()
569 if (tunnel->version == L2TP_HDR_VER_3) { in l2tp_session_register()
578 if (err == -ENOSPC && tunnel->encap == L2TP_ENCAPTYPE_UDP) { in l2tp_session_register()
585 session_key = l2tp_v2_session_key(tunnel->tunnel_id, in l2tp_session_register()
597 refcount_inc(&tunnel->ref_count); in l2tp_session_register()
598 WRITE_ONCE(session->tunnel, tunnel); in l2tp_session_register()
599 list_add_rcu(&session->list, &tunnel->session_list); in l2tp_session_register()
602 if (tunnel->version == L2TP_HDR_VER_3) { in l2tp_session_register()
616 spin_unlock_bh(&tunnel->list_lock); in l2tp_session_register()
657 struct l2tp_tunnel *tunnel = session->tunnel; in l2tp_recv_dequeue_skb() local
665 atomic_long_inc(&tunnel->stats.rx_packets); in l2tp_recv_dequeue_skb()
666 atomic_long_add(length, &tunnel->stats.rx_bytes); in l2tp_recv_dequeue_skb()
868 struct l2tp_tunnel *tunnel = session->tunnel; in l2tp_recv_common() local
875 tunnel->name, tunnel->tunnel_id, in l2tp_recv_common()
891 if (tunnel->version == L2TP_HDR_VER_2) { in l2tp_recv_common()
920 l2tp_session_set_header_len(session, tunnel->version, in l2tp_recv_common()
921 tunnel->encap); in l2tp_recv_common()
942 l2tp_session_set_header_len(session, tunnel->version, in l2tp_recv_common()
943 tunnel->encap); in l2tp_recv_common()
955 if (tunnel->version == L2TP_HDR_VER_2) { in l2tp_recv_common()
1018 struct l2tp_tunnel *tunnel = NULL; in l2tp_udp_encap_recv() local
1086 tunnel = session->tunnel; in l2tp_udp_encap_recv()
1089 if (version != tunnel->version) in l2tp_udp_encap_recv()
1104 atomic_long_inc(&tunnel->stats.rx_invalid); in l2tp_udp_encap_recv()
1140 struct l2tp_tunnel *tunnel = session->tunnel; in l2tp_build_l2tpv2_header() local
1144 u32 tunnel_id = tunnel->peer_tunnel_id; in l2tp_build_l2tpv2_header()
1167 struct l2tp_tunnel *tunnel = session->tunnel; in l2tp_build_l2tpv3_header() local
1174 if (tunnel->encap == L2TP_ENCAPTYPE_UDP) { in l2tp_build_l2tpv3_header()
1206 static int l2tp_xmit_queue(struct l2tp_tunnel *tunnel, struct sk_buff *skb, struct flowi *fl) in l2tp_xmit_queue() argument
1213 if (l2tp_sk_is_v6(tunnel->sock)) in l2tp_xmit_queue()
1214 err = inet6_csk_xmit(tunnel->sock, skb, NULL); in l2tp_xmit_queue()
1217 err = ip_queue_xmit(tunnel->sock, skb, fl); in l2tp_xmit_queue()
1224 struct l2tp_tunnel *tunnel = session->tunnel; in l2tp_xmit_core() local
1226 struct sock *sk = tunnel->sock; in l2tp_xmit_core()
1236 uhlen = (tunnel->encap == L2TP_ENCAPTYPE_UDP) ? sizeof(*uh) : 0; in l2tp_xmit_core()
1244 if (tunnel->version == L2TP_HDR_VER_2) in l2tp_xmit_core()
1270 if (tunnel->fd >= 0 && sk->sk_state != TCP_ESTABLISHED) { in l2tp_xmit_core()
1282 switch (tunnel->encap) { in l2tp_xmit_core()
1309 ret = l2tp_xmit_queue(tunnel, skb, &inet->cork.fl); in l2tp_xmit_core()
1327 atomic_long_inc(&session->tunnel->stats.tx_packets); in l2tp_xmit_skb()
1328 atomic_long_add(len, &session->tunnel->stats.tx_bytes); in l2tp_xmit_skb()
1332 atomic_long_inc(&session->tunnel->stats.tx_errors); in l2tp_xmit_skb()
1346 struct l2tp_tunnel *tunnel = session->tunnel; in l2tp_session_unhash() local
1348 if (tunnel) { in l2tp_session_unhash()
1349 struct l2tp_net *pn = l2tp_pernet(tunnel->l2tp_net); in l2tp_session_unhash()
1352 spin_lock_bh(&tunnel->list_lock); in l2tp_session_unhash()
1359 if (tunnel->version == L2TP_HDR_VER_3) { in l2tp_session_unhash()
1366 u32 session_key = l2tp_v2_session_key(tunnel->tunnel_id, in l2tp_session_unhash()
1374 spin_unlock_bh(&tunnel->list_lock); in l2tp_session_unhash()
1380 static void l2tp_tunnel_closeall(struct l2tp_tunnel *tunnel) in l2tp_tunnel_closeall() argument
1384 spin_lock_bh(&tunnel->list_lock); in l2tp_tunnel_closeall()
1385 tunnel->acpt_newsess = false; in l2tp_tunnel_closeall()
1386 list_for_each_entry(session, &tunnel->session_list, list) in l2tp_tunnel_closeall()
1388 spin_unlock_bh(&tunnel->list_lock); in l2tp_tunnel_closeall()
1394 struct l2tp_tunnel *tunnel; in l2tp_udp_encap_destroy() local
1396 tunnel = l2tp_sk_to_tunnel(sk); in l2tp_udp_encap_destroy()
1397 if (tunnel) { in l2tp_udp_encap_destroy()
1398 l2tp_tunnel_delete(tunnel); in l2tp_udp_encap_destroy()
1399 l2tp_tunnel_put(tunnel); in l2tp_udp_encap_destroy()
1403 static void l2tp_tunnel_remove(struct net *net, struct l2tp_tunnel *tunnel) in l2tp_tunnel_remove() argument
1408 idr_remove(&pn->l2tp_tunnel_idr, tunnel->tunnel_id); in l2tp_tunnel_remove()
1415 struct l2tp_tunnel *tunnel = container_of(work, struct l2tp_tunnel, in l2tp_tunnel_del_work() local
1417 struct sock *sk = tunnel->sock; in l2tp_tunnel_del_work()
1420 l2tp_tunnel_closeall(tunnel); in l2tp_tunnel_del_work()
1425 if (tunnel->fd < 0) { in l2tp_tunnel_del_work()
1432 l2tp_tunnel_remove(tunnel->l2tp_net, tunnel); in l2tp_tunnel_del_work()
1434 l2tp_tunnel_put(tunnel); in l2tp_tunnel_del_work()
1437 l2tp_tunnel_put(tunnel); in l2tp_tunnel_del_work()
1566 struct l2tp_tunnel *tunnel = NULL; in l2tp_tunnel_create() local
1573 tunnel = kzalloc(sizeof(*tunnel), GFP_KERNEL); in l2tp_tunnel_create()
1574 if (!tunnel) { in l2tp_tunnel_create()
1579 tunnel->version = version; in l2tp_tunnel_create()
1580 tunnel->tunnel_id = tunnel_id; in l2tp_tunnel_create()
1581 tunnel->peer_tunnel_id = peer_tunnel_id; in l2tp_tunnel_create()
1583 sprintf(&tunnel->name[0], "tunl %u", tunnel_id); in l2tp_tunnel_create()
1584 spin_lock_init(&tunnel->list_lock); in l2tp_tunnel_create()
1585 tunnel->acpt_newsess = true; in l2tp_tunnel_create()
1586 INIT_LIST_HEAD(&tunnel->session_list); in l2tp_tunnel_create()
1588 tunnel->encap = encap; in l2tp_tunnel_create()
1590 refcount_set(&tunnel->ref_count, 1); in l2tp_tunnel_create()
1591 tunnel->fd = fd; in l2tp_tunnel_create()
1594 INIT_WORK(&tunnel->del_work, l2tp_tunnel_del_work); in l2tp_tunnel_create()
1599 *tunnelp = tunnel; in l2tp_tunnel_create()
1608 struct l2tp_tunnel *tunnel; in l2tp_validate_socket() local
1626 tunnel = l2tp_sk_to_tunnel(sk); in l2tp_validate_socket()
1627 if (tunnel) { in l2tp_validate_socket()
1628 l2tp_tunnel_put(tunnel); in l2tp_validate_socket()
1635 int l2tp_tunnel_register(struct l2tp_tunnel *tunnel, struct net *net, in l2tp_tunnel_register() argument
1639 u32 tunnel_id = tunnel->tunnel_id; in l2tp_tunnel_register()
1651 if (tunnel->fd < 0) { in l2tp_tunnel_register()
1652 ret = l2tp_tunnel_sock_create(net, tunnel->tunnel_id, in l2tp_tunnel_register()
1653 tunnel->peer_tunnel_id, cfg, in l2tp_tunnel_register()
1658 sock = sockfd_lookup(tunnel->fd, &ret); in l2tp_tunnel_register()
1666 ret = l2tp_validate_socket(sk, net, tunnel->encap); in l2tp_tunnel_register()
1671 if (tunnel->encap == L2TP_ENCAPTYPE_UDP) { in l2tp_tunnel_register()
1686 tunnel->sock = sk; in l2tp_tunnel_register()
1687 tunnel->l2tp_net = net; in l2tp_tunnel_register()
1690 idr_replace(&pn->l2tp_tunnel_idr, tunnel, tunnel->tunnel_id); in l2tp_tunnel_register()
1693 trace_register_tunnel(tunnel); in l2tp_tunnel_register()
1695 if (tunnel->fd >= 0) in l2tp_tunnel_register()
1704 if (tunnel->fd < 0) in l2tp_tunnel_register()
1709 l2tp_tunnel_remove(net, tunnel); in l2tp_tunnel_register()
1716 void l2tp_tunnel_delete(struct l2tp_tunnel *tunnel) in l2tp_tunnel_delete() argument
1718 if (!test_and_set_bit(0, &tunnel->dead)) { in l2tp_tunnel_delete()
1719 trace_delete_tunnel(tunnel); in l2tp_tunnel_delete()
1720 refcount_inc(&tunnel->ref_count); in l2tp_tunnel_delete()
1721 queue_work(l2tp_wq, &tunnel->del_work); in l2tp_tunnel_delete()
1773 struct l2tp_session *l2tp_session_create(int priv_size, struct l2tp_tunnel *tunnel, u32 session_id, in l2tp_session_create() argument
1785 if (tunnel->version == L2TP_HDR_VER_2) in l2tp_session_create()
1796 tunnel->tunnel_id, session->session_id); in l2tp_session_create()
1800 session->hlist_key = l2tp_v3_session_hashkey(tunnel->sock, session->session_id); in l2tp_session_create()
1819 l2tp_session_set_header_len(session, tunnel->version, tunnel->encap); in l2tp_session_create()
1851 struct l2tp_tunnel *tunnel = NULL; in l2tp_pre_exit_net() local
1855 idr_for_each_entry_ul(&pn->l2tp_tunnel_idr, tunnel, tmp, tunnel_id) { in l2tp_pre_exit_net()
1856 if (tunnel) in l2tp_pre_exit_net()
1857 l2tp_tunnel_delete(tunnel); in l2tp_pre_exit_net()