diff options
Diffstat (limited to 'net/l2tp')
-rw-r--r-- | net/l2tp/Kconfig | 4 | ||||
-rw-r--r-- | net/l2tp/l2tp_core.c | 191 | ||||
-rw-r--r-- | net/l2tp/l2tp_core.h | 2 | ||||
-rw-r--r-- | net/l2tp/l2tp_ip.c | 19 | ||||
-rw-r--r-- | net/l2tp/l2tp_ip6.c | 3 | ||||
-rw-r--r-- | net/l2tp/l2tp_netlink.c | 1 | ||||
-rw-r--r-- | net/l2tp/l2tp_ppp.c | 5 |
7 files changed, 135 insertions, 90 deletions
diff --git a/net/l2tp/Kconfig b/net/l2tp/Kconfig index 147a8fd47a17..adb9843dd7cf 100644 --- a/net/l2tp/Kconfig +++ b/net/l2tp/Kconfig | |||
@@ -46,8 +46,8 @@ config L2TP_DEBUGFS | |||
46 | will be called l2tp_debugfs. | 46 | will be called l2tp_debugfs. |
47 | 47 | ||
48 | config L2TP_V3 | 48 | config L2TP_V3 |
49 | bool "L2TPv3 support (EXPERIMENTAL)" | 49 | bool "L2TPv3 support" |
50 | depends on EXPERIMENTAL && L2TP | 50 | depends on L2TP |
51 | help | 51 | help |
52 | Layer Two Tunneling Protocol Version 3 | 52 | Layer Two Tunneling Protocol Version 3 |
53 | 53 | ||
diff --git a/net/l2tp/l2tp_core.c b/net/l2tp/l2tp_core.c index 2ac884d0e89b..d36875f3427e 100644 --- a/net/l2tp/l2tp_core.c +++ b/net/l2tp/l2tp_core.c | |||
@@ -101,6 +101,7 @@ struct l2tp_skb_cb { | |||
101 | 101 | ||
102 | static atomic_t l2tp_tunnel_count; | 102 | static atomic_t l2tp_tunnel_count; |
103 | static atomic_t l2tp_session_count; | 103 | static atomic_t l2tp_session_count; |
104 | static struct workqueue_struct *l2tp_wq; | ||
104 | 105 | ||
105 | /* per-net private data for this module */ | 106 | /* per-net private data for this module */ |
106 | static unsigned int l2tp_net_id; | 107 | static unsigned int l2tp_net_id; |
@@ -122,7 +123,6 @@ static inline struct l2tp_net *l2tp_pernet(struct net *net) | |||
122 | return net_generic(net, l2tp_net_id); | 123 | return net_generic(net, l2tp_net_id); |
123 | } | 124 | } |
124 | 125 | ||
125 | |||
126 | /* Tunnel reference counts. Incremented per session that is added to | 126 | /* Tunnel reference counts. Incremented per session that is added to |
127 | * the tunnel. | 127 | * the tunnel. |
128 | */ | 128 | */ |
@@ -221,10 +221,9 @@ static struct l2tp_session *l2tp_session_find_2(struct net *net, u32 session_id) | |||
221 | struct hlist_head *session_list = | 221 | struct hlist_head *session_list = |
222 | l2tp_session_id_hash_2(pn, session_id); | 222 | l2tp_session_id_hash_2(pn, session_id); |
223 | struct l2tp_session *session; | 223 | struct l2tp_session *session; |
224 | struct hlist_node *walk; | ||
225 | 224 | ||
226 | rcu_read_lock_bh(); | 225 | rcu_read_lock_bh(); |
227 | hlist_for_each_entry_rcu(session, walk, session_list, global_hlist) { | 226 | hlist_for_each_entry_rcu(session, session_list, global_hlist) { |
228 | if (session->session_id == session_id) { | 227 | if (session->session_id == session_id) { |
229 | rcu_read_unlock_bh(); | 228 | rcu_read_unlock_bh(); |
230 | return session; | 229 | return session; |
@@ -253,7 +252,6 @@ struct l2tp_session *l2tp_session_find(struct net *net, struct l2tp_tunnel *tunn | |||
253 | { | 252 | { |
254 | struct hlist_head *session_list; | 253 | struct hlist_head *session_list; |
255 | struct l2tp_session *session; | 254 | struct l2tp_session *session; |
256 | struct hlist_node *walk; | ||
257 | 255 | ||
258 | /* In L2TPv3, session_ids are unique over all tunnels and we | 256 | /* In L2TPv3, session_ids are unique over all tunnels and we |
259 | * sometimes need to look them up before we know the | 257 | * sometimes need to look them up before we know the |
@@ -264,7 +262,7 @@ struct l2tp_session *l2tp_session_find(struct net *net, struct l2tp_tunnel *tunn | |||
264 | 262 | ||
265 | session_list = l2tp_session_id_hash(tunnel, session_id); | 263 | session_list = l2tp_session_id_hash(tunnel, session_id); |
266 | read_lock_bh(&tunnel->hlist_lock); | 264 | read_lock_bh(&tunnel->hlist_lock); |
267 | hlist_for_each_entry(session, walk, session_list, hlist) { | 265 | hlist_for_each_entry(session, session_list, hlist) { |
268 | if (session->session_id == session_id) { | 266 | if (session->session_id == session_id) { |
269 | read_unlock_bh(&tunnel->hlist_lock); | 267 | read_unlock_bh(&tunnel->hlist_lock); |
270 | return session; | 268 | return session; |
@@ -279,13 +277,12 @@ EXPORT_SYMBOL_GPL(l2tp_session_find); | |||
279 | struct l2tp_session *l2tp_session_find_nth(struct l2tp_tunnel *tunnel, int nth) | 277 | struct l2tp_session *l2tp_session_find_nth(struct l2tp_tunnel *tunnel, int nth) |
280 | { | 278 | { |
281 | int hash; | 279 | int hash; |
282 | struct hlist_node *walk; | ||
283 | struct l2tp_session *session; | 280 | struct l2tp_session *session; |
284 | int count = 0; | 281 | int count = 0; |
285 | 282 | ||
286 | read_lock_bh(&tunnel->hlist_lock); | 283 | read_lock_bh(&tunnel->hlist_lock); |
287 | for (hash = 0; hash < L2TP_HASH_SIZE; hash++) { | 284 | for (hash = 0; hash < L2TP_HASH_SIZE; hash++) { |
288 | hlist_for_each_entry(session, walk, &tunnel->session_hlist[hash], hlist) { | 285 | hlist_for_each_entry(session, &tunnel->session_hlist[hash], hlist) { |
289 | if (++count > nth) { | 286 | if (++count > nth) { |
290 | read_unlock_bh(&tunnel->hlist_lock); | 287 | read_unlock_bh(&tunnel->hlist_lock); |
291 | return session; | 288 | return session; |
@@ -306,12 +303,11 @@ struct l2tp_session *l2tp_session_find_by_ifname(struct net *net, char *ifname) | |||
306 | { | 303 | { |
307 | struct l2tp_net *pn = l2tp_pernet(net); | 304 | struct l2tp_net *pn = l2tp_pernet(net); |
308 | int hash; | 305 | int hash; |
309 | struct hlist_node *walk; | ||
310 | struct l2tp_session *session; | 306 | struct l2tp_session *session; |
311 | 307 | ||
312 | rcu_read_lock_bh(); | 308 | rcu_read_lock_bh(); |
313 | for (hash = 0; hash < L2TP_HASH_SIZE_2; hash++) { | 309 | for (hash = 0; hash < L2TP_HASH_SIZE_2; hash++) { |
314 | hlist_for_each_entry_rcu(session, walk, &pn->l2tp_session_hlist[hash], global_hlist) { | 310 | hlist_for_each_entry_rcu(session, &pn->l2tp_session_hlist[hash], global_hlist) { |
315 | if (!strcmp(session->ifname, ifname)) { | 311 | if (!strcmp(session->ifname, ifname)) { |
316 | rcu_read_unlock_bh(); | 312 | rcu_read_unlock_bh(); |
317 | return session; | 313 | return session; |
@@ -1271,6 +1267,7 @@ EXPORT_SYMBOL_GPL(l2tp_xmit_skb); | |||
1271 | static void l2tp_tunnel_destruct(struct sock *sk) | 1267 | static void l2tp_tunnel_destruct(struct sock *sk) |
1272 | { | 1268 | { |
1273 | struct l2tp_tunnel *tunnel; | 1269 | struct l2tp_tunnel *tunnel; |
1270 | struct l2tp_net *pn; | ||
1274 | 1271 | ||
1275 | tunnel = sk->sk_user_data; | 1272 | tunnel = sk->sk_user_data; |
1276 | if (tunnel == NULL) | 1273 | if (tunnel == NULL) |
@@ -1278,9 +1275,8 @@ static void l2tp_tunnel_destruct(struct sock *sk) | |||
1278 | 1275 | ||
1279 | l2tp_info(tunnel, L2TP_MSG_CONTROL, "%s: closing...\n", tunnel->name); | 1276 | l2tp_info(tunnel, L2TP_MSG_CONTROL, "%s: closing...\n", tunnel->name); |
1280 | 1277 | ||
1281 | /* Close all sessions */ | ||
1282 | l2tp_tunnel_closeall(tunnel); | ||
1283 | 1278 | ||
1279 | /* Disable udp encapsulation */ | ||
1284 | switch (tunnel->encap) { | 1280 | switch (tunnel->encap) { |
1285 | case L2TP_ENCAPTYPE_UDP: | 1281 | case L2TP_ENCAPTYPE_UDP: |
1286 | /* No longer an encapsulation socket. See net/ipv4/udp.c */ | 1282 | /* No longer an encapsulation socket. See net/ipv4/udp.c */ |
@@ -1292,17 +1288,23 @@ static void l2tp_tunnel_destruct(struct sock *sk) | |||
1292 | } | 1288 | } |
1293 | 1289 | ||
1294 | /* Remove hooks into tunnel socket */ | 1290 | /* Remove hooks into tunnel socket */ |
1295 | tunnel->sock = NULL; | ||
1296 | sk->sk_destruct = tunnel->old_sk_destruct; | 1291 | sk->sk_destruct = tunnel->old_sk_destruct; |
1297 | sk->sk_user_data = NULL; | 1292 | sk->sk_user_data = NULL; |
1293 | tunnel->sock = NULL; | ||
1298 | 1294 | ||
1299 | /* Call the original destructor */ | 1295 | /* Remove the tunnel struct from the tunnel list */ |
1300 | if (sk->sk_destruct) | 1296 | pn = l2tp_pernet(tunnel->l2tp_net); |
1301 | (*sk->sk_destruct)(sk); | 1297 | spin_lock_bh(&pn->l2tp_tunnel_list_lock); |
1298 | list_del_rcu(&tunnel->list); | ||
1299 | spin_unlock_bh(&pn->l2tp_tunnel_list_lock); | ||
1300 | atomic_dec(&l2tp_tunnel_count); | ||
1302 | 1301 | ||
1303 | /* We're finished with the socket */ | 1302 | l2tp_tunnel_closeall(tunnel); |
1304 | l2tp_tunnel_dec_refcount(tunnel); | 1303 | l2tp_tunnel_dec_refcount(tunnel); |
1305 | 1304 | ||
1305 | /* Call the original destructor */ | ||
1306 | if (sk->sk_destruct) | ||
1307 | (*sk->sk_destruct)(sk); | ||
1306 | end: | 1308 | end: |
1307 | return; | 1309 | return; |
1308 | } | 1310 | } |
@@ -1376,48 +1378,77 @@ again: | |||
1376 | */ | 1378 | */ |
1377 | static void l2tp_tunnel_free(struct l2tp_tunnel *tunnel) | 1379 | static void l2tp_tunnel_free(struct l2tp_tunnel *tunnel) |
1378 | { | 1380 | { |
1379 | struct l2tp_net *pn = l2tp_pernet(tunnel->l2tp_net); | ||
1380 | |||
1381 | BUG_ON(atomic_read(&tunnel->ref_count) != 0); | 1381 | BUG_ON(atomic_read(&tunnel->ref_count) != 0); |
1382 | BUG_ON(tunnel->sock != NULL); | 1382 | BUG_ON(tunnel->sock != NULL); |
1383 | |||
1384 | l2tp_info(tunnel, L2TP_MSG_CONTROL, "%s: free...\n", tunnel->name); | 1383 | l2tp_info(tunnel, L2TP_MSG_CONTROL, "%s: free...\n", tunnel->name); |
1385 | |||
1386 | /* Remove from tunnel list */ | ||
1387 | spin_lock_bh(&pn->l2tp_tunnel_list_lock); | ||
1388 | list_del_rcu(&tunnel->list); | ||
1389 | kfree_rcu(tunnel, rcu); | 1384 | kfree_rcu(tunnel, rcu); |
1390 | spin_unlock_bh(&pn->l2tp_tunnel_list_lock); | 1385 | } |
1391 | 1386 | ||
1392 | atomic_dec(&l2tp_tunnel_count); | 1387 | /* Workqueue tunnel deletion function */ |
1388 | static void l2tp_tunnel_del_work(struct work_struct *work) | ||
1389 | { | ||
1390 | struct l2tp_tunnel *tunnel = NULL; | ||
1391 | struct socket *sock = NULL; | ||
1392 | struct sock *sk = NULL; | ||
1393 | |||
1394 | tunnel = container_of(work, struct l2tp_tunnel, del_work); | ||
1395 | sk = l2tp_tunnel_sock_lookup(tunnel); | ||
1396 | if (!sk) | ||
1397 | return; | ||
1398 | |||
1399 | sock = sk->sk_socket; | ||
1400 | BUG_ON(!sock); | ||
1401 | |||
1402 | /* If the tunnel socket was created directly by the kernel, use the | ||
1403 | * sk_* API to release the socket now. Otherwise go through the | ||
1404 | * inet_* layer to shut the socket down, and let userspace close it. | ||
1405 | * In either case the tunnel resources are freed in the socket | ||
1406 | * destructor when the tunnel socket goes away. | ||
1407 | */ | ||
1408 | if (sock->file == NULL) { | ||
1409 | kernel_sock_shutdown(sock, SHUT_RDWR); | ||
1410 | sk_release_kernel(sk); | ||
1411 | } else { | ||
1412 | inet_shutdown(sock, 2); | ||
1413 | } | ||
1414 | |||
1415 | l2tp_tunnel_sock_put(sk); | ||
1393 | } | 1416 | } |
1394 | 1417 | ||
1395 | /* Create a socket for the tunnel, if one isn't set up by | 1418 | /* Create a socket for the tunnel, if one isn't set up by |
1396 | * userspace. This is used for static tunnels where there is no | 1419 | * userspace. This is used for static tunnels where there is no |
1397 | * managing L2TP daemon. | 1420 | * managing L2TP daemon. |
1421 | * | ||
1422 | * Since we don't want these sockets to keep a namespace alive by | ||
1423 | * themselves, we drop the socket's namespace refcount after creation. | ||
1424 | * These sockets are freed when the namespace exits using the pernet | ||
1425 | * exit hook. | ||
1398 | */ | 1426 | */ |
1399 | static int l2tp_tunnel_sock_create(u32 tunnel_id, u32 peer_tunnel_id, struct l2tp_tunnel_cfg *cfg, struct socket **sockp) | 1427 | static int l2tp_tunnel_sock_create(struct net *net, |
1428 | u32 tunnel_id, | ||
1429 | u32 peer_tunnel_id, | ||
1430 | struct l2tp_tunnel_cfg *cfg, | ||
1431 | struct socket **sockp) | ||
1400 | { | 1432 | { |
1401 | int err = -EINVAL; | 1433 | int err = -EINVAL; |
1402 | struct sockaddr_in udp_addr; | 1434 | struct socket *sock = NULL; |
1435 | struct sockaddr_in udp_addr = {0}; | ||
1436 | struct sockaddr_l2tpip ip_addr = {0}; | ||
1403 | #if IS_ENABLED(CONFIG_IPV6) | 1437 | #if IS_ENABLED(CONFIG_IPV6) |
1404 | struct sockaddr_in6 udp6_addr; | 1438 | struct sockaddr_in6 udp6_addr = {0}; |
1405 | struct sockaddr_l2tpip6 ip6_addr; | 1439 | struct sockaddr_l2tpip6 ip6_addr = {0}; |
1406 | #endif | 1440 | #endif |
1407 | struct sockaddr_l2tpip ip_addr; | ||
1408 | struct socket *sock = NULL; | ||
1409 | 1441 | ||
1410 | switch (cfg->encap) { | 1442 | switch (cfg->encap) { |
1411 | case L2TP_ENCAPTYPE_UDP: | 1443 | case L2TP_ENCAPTYPE_UDP: |
1412 | #if IS_ENABLED(CONFIG_IPV6) | 1444 | #if IS_ENABLED(CONFIG_IPV6) |
1413 | if (cfg->local_ip6 && cfg->peer_ip6) { | 1445 | if (cfg->local_ip6 && cfg->peer_ip6) { |
1414 | err = sock_create(AF_INET6, SOCK_DGRAM, 0, sockp); | 1446 | err = sock_create_kern(AF_INET6, SOCK_DGRAM, 0, &sock); |
1415 | if (err < 0) | 1447 | if (err < 0) |
1416 | goto out; | 1448 | goto out; |
1417 | 1449 | ||
1418 | sock = *sockp; | 1450 | sk_change_net(sock->sk, net); |
1419 | 1451 | ||
1420 | memset(&udp6_addr, 0, sizeof(udp6_addr)); | ||
1421 | udp6_addr.sin6_family = AF_INET6; | 1452 | udp6_addr.sin6_family = AF_INET6; |
1422 | memcpy(&udp6_addr.sin6_addr, cfg->local_ip6, | 1453 | memcpy(&udp6_addr.sin6_addr, cfg->local_ip6, |
1423 | sizeof(udp6_addr.sin6_addr)); | 1454 | sizeof(udp6_addr.sin6_addr)); |
@@ -1439,13 +1470,12 @@ static int l2tp_tunnel_sock_create(u32 tunnel_id, u32 peer_tunnel_id, struct l2t | |||
1439 | } else | 1470 | } else |
1440 | #endif | 1471 | #endif |
1441 | { | 1472 | { |
1442 | err = sock_create(AF_INET, SOCK_DGRAM, 0, sockp); | 1473 | err = sock_create_kern(AF_INET, SOCK_DGRAM, 0, &sock); |
1443 | if (err < 0) | 1474 | if (err < 0) |
1444 | goto out; | 1475 | goto out; |
1445 | 1476 | ||
1446 | sock = *sockp; | 1477 | sk_change_net(sock->sk, net); |
1447 | 1478 | ||
1448 | memset(&udp_addr, 0, sizeof(udp_addr)); | ||
1449 | udp_addr.sin_family = AF_INET; | 1479 | udp_addr.sin_family = AF_INET; |
1450 | udp_addr.sin_addr = cfg->local_ip; | 1480 | udp_addr.sin_addr = cfg->local_ip; |
1451 | udp_addr.sin_port = htons(cfg->local_udp_port); | 1481 | udp_addr.sin_port = htons(cfg->local_udp_port); |
@@ -1472,14 +1502,13 @@ static int l2tp_tunnel_sock_create(u32 tunnel_id, u32 peer_tunnel_id, struct l2t | |||
1472 | case L2TP_ENCAPTYPE_IP: | 1502 | case L2TP_ENCAPTYPE_IP: |
1473 | #if IS_ENABLED(CONFIG_IPV6) | 1503 | #if IS_ENABLED(CONFIG_IPV6) |
1474 | if (cfg->local_ip6 && cfg->peer_ip6) { | 1504 | if (cfg->local_ip6 && cfg->peer_ip6) { |
1475 | err = sock_create(AF_INET6, SOCK_DGRAM, IPPROTO_L2TP, | 1505 | err = sock_create_kern(AF_INET6, SOCK_DGRAM, |
1476 | sockp); | 1506 | IPPROTO_L2TP, &sock); |
1477 | if (err < 0) | 1507 | if (err < 0) |
1478 | goto out; | 1508 | goto out; |
1479 | 1509 | ||
1480 | sock = *sockp; | 1510 | sk_change_net(sock->sk, net); |
1481 | 1511 | ||
1482 | memset(&ip6_addr, 0, sizeof(ip6_addr)); | ||
1483 | ip6_addr.l2tp_family = AF_INET6; | 1512 | ip6_addr.l2tp_family = AF_INET6; |
1484 | memcpy(&ip6_addr.l2tp_addr, cfg->local_ip6, | 1513 | memcpy(&ip6_addr.l2tp_addr, cfg->local_ip6, |
1485 | sizeof(ip6_addr.l2tp_addr)); | 1514 | sizeof(ip6_addr.l2tp_addr)); |
@@ -1501,14 +1530,13 @@ static int l2tp_tunnel_sock_create(u32 tunnel_id, u32 peer_tunnel_id, struct l2t | |||
1501 | } else | 1530 | } else |
1502 | #endif | 1531 | #endif |
1503 | { | 1532 | { |
1504 | err = sock_create(AF_INET, SOCK_DGRAM, IPPROTO_L2TP, | 1533 | err = sock_create_kern(AF_INET, SOCK_DGRAM, |
1505 | sockp); | 1534 | IPPROTO_L2TP, &sock); |
1506 | if (err < 0) | 1535 | if (err < 0) |
1507 | goto out; | 1536 | goto out; |
1508 | 1537 | ||
1509 | sock = *sockp; | 1538 | sk_change_net(sock->sk, net); |
1510 | 1539 | ||
1511 | memset(&ip_addr, 0, sizeof(ip_addr)); | ||
1512 | ip_addr.l2tp_family = AF_INET; | 1540 | ip_addr.l2tp_family = AF_INET; |
1513 | ip_addr.l2tp_addr = cfg->local_ip; | 1541 | ip_addr.l2tp_addr = cfg->local_ip; |
1514 | ip_addr.l2tp_conn_id = tunnel_id; | 1542 | ip_addr.l2tp_conn_id = tunnel_id; |
@@ -1532,8 +1560,10 @@ static int l2tp_tunnel_sock_create(u32 tunnel_id, u32 peer_tunnel_id, struct l2t | |||
1532 | } | 1560 | } |
1533 | 1561 | ||
1534 | out: | 1562 | out: |
1563 | *sockp = sock; | ||
1535 | if ((err < 0) && sock) { | 1564 | if ((err < 0) && sock) { |
1536 | sock_release(sock); | 1565 | kernel_sock_shutdown(sock, SHUT_RDWR); |
1566 | sk_release_kernel(sock->sk); | ||
1537 | *sockp = NULL; | 1567 | *sockp = NULL; |
1538 | } | 1568 | } |
1539 | 1569 | ||
@@ -1556,15 +1586,23 @@ int l2tp_tunnel_create(struct net *net, int fd, int version, u32 tunnel_id, u32 | |||
1556 | * kernel socket. | 1586 | * kernel socket. |
1557 | */ | 1587 | */ |
1558 | if (fd < 0) { | 1588 | if (fd < 0) { |
1559 | err = l2tp_tunnel_sock_create(tunnel_id, peer_tunnel_id, cfg, &sock); | 1589 | err = l2tp_tunnel_sock_create(net, tunnel_id, peer_tunnel_id, |
1590 | cfg, &sock); | ||
1560 | if (err < 0) | 1591 | if (err < 0) |
1561 | goto err; | 1592 | goto err; |
1562 | } else { | 1593 | } else { |
1563 | err = -EBADF; | ||
1564 | sock = sockfd_lookup(fd, &err); | 1594 | sock = sockfd_lookup(fd, &err); |
1565 | if (!sock) { | 1595 | if (!sock) { |
1566 | pr_err("tunl %hu: sockfd_lookup(fd=%d) returned %d\n", | 1596 | pr_err("tunl %u: sockfd_lookup(fd=%d) returned %d\n", |
1567 | tunnel_id, fd, err); | 1597 | tunnel_id, fd, err); |
1598 | err = -EBADF; | ||
1599 | goto err; | ||
1600 | } | ||
1601 | |||
1602 | /* Reject namespace mismatches */ | ||
1603 | if (!net_eq(sock_net(sock->sk), net)) { | ||
1604 | pr_err("tunl %u: netns mismatch\n", tunnel_id); | ||
1605 | err = -EINVAL; | ||
1568 | goto err; | 1606 | goto err; |
1569 | } | 1607 | } |
1570 | } | 1608 | } |
@@ -1651,6 +1689,9 @@ int l2tp_tunnel_create(struct net *net, int fd, int version, u32 tunnel_id, u32 | |||
1651 | 1689 | ||
1652 | sk->sk_allocation = GFP_ATOMIC; | 1690 | sk->sk_allocation = GFP_ATOMIC; |
1653 | 1691 | ||
1692 | /* Init delete workqueue struct */ | ||
1693 | INIT_WORK(&tunnel->del_work, l2tp_tunnel_del_work); | ||
1694 | |||
1654 | /* Add tunnel to our list */ | 1695 | /* Add tunnel to our list */ |
1655 | INIT_LIST_HEAD(&tunnel->list); | 1696 | INIT_LIST_HEAD(&tunnel->list); |
1656 | atomic_inc(&l2tp_tunnel_count); | 1697 | atomic_inc(&l2tp_tunnel_count); |
@@ -1682,33 +1723,7 @@ EXPORT_SYMBOL_GPL(l2tp_tunnel_create); | |||
1682 | */ | 1723 | */ |
1683 | int l2tp_tunnel_delete(struct l2tp_tunnel *tunnel) | 1724 | int l2tp_tunnel_delete(struct l2tp_tunnel *tunnel) |
1684 | { | 1725 | { |
1685 | int err = -EBADF; | 1726 | return (false == queue_work(l2tp_wq, &tunnel->del_work)); |
1686 | struct socket *sock = NULL; | ||
1687 | struct sock *sk = NULL; | ||
1688 | |||
1689 | sk = l2tp_tunnel_sock_lookup(tunnel); | ||
1690 | if (!sk) | ||
1691 | goto out; | ||
1692 | |||
1693 | sock = sk->sk_socket; | ||
1694 | BUG_ON(!sock); | ||
1695 | |||
1696 | /* Force the tunnel socket to close. This will eventually | ||
1697 | * cause the tunnel to be deleted via the normal socket close | ||
1698 | * mechanisms when userspace closes the tunnel socket. | ||
1699 | */ | ||
1700 | err = inet_shutdown(sock, 2); | ||
1701 | |||
1702 | /* If the tunnel's socket was created by the kernel, | ||
1703 | * close the socket here since the socket was not | ||
1704 | * created by userspace. | ||
1705 | */ | ||
1706 | if (sock->file == NULL) | ||
1707 | err = inet_release(sock); | ||
1708 | |||
1709 | l2tp_tunnel_sock_put(sk); | ||
1710 | out: | ||
1711 | return err; | ||
1712 | } | 1727 | } |
1713 | EXPORT_SYMBOL_GPL(l2tp_tunnel_delete); | 1728 | EXPORT_SYMBOL_GPL(l2tp_tunnel_delete); |
1714 | 1729 | ||
@@ -1892,8 +1907,21 @@ static __net_init int l2tp_init_net(struct net *net) | |||
1892 | return 0; | 1907 | return 0; |
1893 | } | 1908 | } |
1894 | 1909 | ||
1910 | static __net_exit void l2tp_exit_net(struct net *net) | ||
1911 | { | ||
1912 | struct l2tp_net *pn = l2tp_pernet(net); | ||
1913 | struct l2tp_tunnel *tunnel = NULL; | ||
1914 | |||
1915 | rcu_read_lock_bh(); | ||
1916 | list_for_each_entry_rcu(tunnel, &pn->l2tp_tunnel_list, list) { | ||
1917 | (void)l2tp_tunnel_delete(tunnel); | ||
1918 | } | ||
1919 | rcu_read_unlock_bh(); | ||
1920 | } | ||
1921 | |||
1895 | static struct pernet_operations l2tp_net_ops = { | 1922 | static struct pernet_operations l2tp_net_ops = { |
1896 | .init = l2tp_init_net, | 1923 | .init = l2tp_init_net, |
1924 | .exit = l2tp_exit_net, | ||
1897 | .id = &l2tp_net_id, | 1925 | .id = &l2tp_net_id, |
1898 | .size = sizeof(struct l2tp_net), | 1926 | .size = sizeof(struct l2tp_net), |
1899 | }; | 1927 | }; |
@@ -1906,6 +1934,13 @@ static int __init l2tp_init(void) | |||
1906 | if (rc) | 1934 | if (rc) |
1907 | goto out; | 1935 | goto out; |
1908 | 1936 | ||
1937 | l2tp_wq = alloc_workqueue("l2tp", WQ_NON_REENTRANT | WQ_UNBOUND, 0); | ||
1938 | if (!l2tp_wq) { | ||
1939 | pr_err("alloc_workqueue failed\n"); | ||
1940 | rc = -ENOMEM; | ||
1941 | goto out; | ||
1942 | } | ||
1943 | |||
1909 | pr_info("L2TP core driver, %s\n", L2TP_DRV_VERSION); | 1944 | pr_info("L2TP core driver, %s\n", L2TP_DRV_VERSION); |
1910 | 1945 | ||
1911 | out: | 1946 | out: |
@@ -1915,6 +1950,10 @@ out: | |||
1915 | static void __exit l2tp_exit(void) | 1950 | static void __exit l2tp_exit(void) |
1916 | { | 1951 | { |
1917 | unregister_pernet_device(&l2tp_net_ops); | 1952 | unregister_pernet_device(&l2tp_net_ops); |
1953 | if (l2tp_wq) { | ||
1954 | destroy_workqueue(l2tp_wq); | ||
1955 | l2tp_wq = NULL; | ||
1956 | } | ||
1918 | } | 1957 | } |
1919 | 1958 | ||
1920 | module_init(l2tp_init); | 1959 | module_init(l2tp_init); |
diff --git a/net/l2tp/l2tp_core.h b/net/l2tp/l2tp_core.h index e62204cad4fe..8eb8f1d47f3a 100644 --- a/net/l2tp/l2tp_core.h +++ b/net/l2tp/l2tp_core.h | |||
@@ -191,6 +191,8 @@ struct l2tp_tunnel { | |||
191 | int fd; /* Parent fd, if tunnel socket | 191 | int fd; /* Parent fd, if tunnel socket |
192 | * was created by userspace */ | 192 | * was created by userspace */ |
193 | 193 | ||
194 | struct work_struct del_work; | ||
195 | |||
194 | uint8_t priv[0]; /* private data */ | 196 | uint8_t priv[0]; /* private data */ |
195 | }; | 197 | }; |
196 | 198 | ||
diff --git a/net/l2tp/l2tp_ip.c b/net/l2tp/l2tp_ip.c index 61d8b75d2686..7f41b7051269 100644 --- a/net/l2tp/l2tp_ip.c +++ b/net/l2tp/l2tp_ip.c | |||
@@ -49,10 +49,9 @@ static inline struct l2tp_ip_sock *l2tp_ip_sk(const struct sock *sk) | |||
49 | 49 | ||
50 | static struct sock *__l2tp_ip_bind_lookup(struct net *net, __be32 laddr, int dif, u32 tunnel_id) | 50 | static struct sock *__l2tp_ip_bind_lookup(struct net *net, __be32 laddr, int dif, u32 tunnel_id) |
51 | { | 51 | { |
52 | struct hlist_node *node; | ||
53 | struct sock *sk; | 52 | struct sock *sk; |
54 | 53 | ||
55 | sk_for_each_bound(sk, node, &l2tp_ip_bind_table) { | 54 | sk_for_each_bound(sk, &l2tp_ip_bind_table) { |
56 | struct inet_sock *inet = inet_sk(sk); | 55 | struct inet_sock *inet = inet_sk(sk); |
57 | struct l2tp_ip_sock *l2tp = l2tp_ip_sk(sk); | 56 | struct l2tp_ip_sock *l2tp = l2tp_ip_sk(sk); |
58 | 57 | ||
@@ -115,6 +114,7 @@ static inline struct sock *l2tp_ip_bind_lookup(struct net *net, __be32 laddr, in | |||
115 | */ | 114 | */ |
116 | static int l2tp_ip_recv(struct sk_buff *skb) | 115 | static int l2tp_ip_recv(struct sk_buff *skb) |
117 | { | 116 | { |
117 | struct net *net = dev_net(skb->dev); | ||
118 | struct sock *sk; | 118 | struct sock *sk; |
119 | u32 session_id; | 119 | u32 session_id; |
120 | u32 tunnel_id; | 120 | u32 tunnel_id; |
@@ -142,7 +142,7 @@ static int l2tp_ip_recv(struct sk_buff *skb) | |||
142 | } | 142 | } |
143 | 143 | ||
144 | /* Ok, this is a data packet. Lookup the session. */ | 144 | /* Ok, this is a data packet. Lookup the session. */ |
145 | session = l2tp_session_find(&init_net, NULL, session_id); | 145 | session = l2tp_session_find(net, NULL, session_id); |
146 | if (session == NULL) | 146 | if (session == NULL) |
147 | goto discard; | 147 | goto discard; |
148 | 148 | ||
@@ -173,14 +173,14 @@ pass_up: | |||
173 | goto discard; | 173 | goto discard; |
174 | 174 | ||
175 | tunnel_id = ntohl(*(__be32 *) &skb->data[4]); | 175 | tunnel_id = ntohl(*(__be32 *) &skb->data[4]); |
176 | tunnel = l2tp_tunnel_find(&init_net, tunnel_id); | 176 | tunnel = l2tp_tunnel_find(net, tunnel_id); |
177 | if (tunnel != NULL) | 177 | if (tunnel != NULL) |
178 | sk = tunnel->sock; | 178 | sk = tunnel->sock; |
179 | else { | 179 | else { |
180 | struct iphdr *iph = (struct iphdr *) skb_network_header(skb); | 180 | struct iphdr *iph = (struct iphdr *) skb_network_header(skb); |
181 | 181 | ||
182 | read_lock_bh(&l2tp_ip_lock); | 182 | read_lock_bh(&l2tp_ip_lock); |
183 | sk = __l2tp_ip_bind_lookup(&init_net, iph->daddr, 0, tunnel_id); | 183 | sk = __l2tp_ip_bind_lookup(net, iph->daddr, 0, tunnel_id); |
184 | read_unlock_bh(&l2tp_ip_lock); | 184 | read_unlock_bh(&l2tp_ip_lock); |
185 | } | 185 | } |
186 | 186 | ||
@@ -239,6 +239,7 @@ static int l2tp_ip_bind(struct sock *sk, struct sockaddr *uaddr, int addr_len) | |||
239 | { | 239 | { |
240 | struct inet_sock *inet = inet_sk(sk); | 240 | struct inet_sock *inet = inet_sk(sk); |
241 | struct sockaddr_l2tpip *addr = (struct sockaddr_l2tpip *) uaddr; | 241 | struct sockaddr_l2tpip *addr = (struct sockaddr_l2tpip *) uaddr; |
242 | struct net *net = sock_net(sk); | ||
242 | int ret; | 243 | int ret; |
243 | int chk_addr_ret; | 244 | int chk_addr_ret; |
244 | 245 | ||
@@ -251,7 +252,8 @@ static int l2tp_ip_bind(struct sock *sk, struct sockaddr *uaddr, int addr_len) | |||
251 | 252 | ||
252 | ret = -EADDRINUSE; | 253 | ret = -EADDRINUSE; |
253 | read_lock_bh(&l2tp_ip_lock); | 254 | read_lock_bh(&l2tp_ip_lock); |
254 | if (__l2tp_ip_bind_lookup(&init_net, addr->l2tp_addr.s_addr, sk->sk_bound_dev_if, addr->l2tp_conn_id)) | 255 | if (__l2tp_ip_bind_lookup(net, addr->l2tp_addr.s_addr, |
256 | sk->sk_bound_dev_if, addr->l2tp_conn_id)) | ||
255 | goto out_in_use; | 257 | goto out_in_use; |
256 | 258 | ||
257 | read_unlock_bh(&l2tp_ip_lock); | 259 | read_unlock_bh(&l2tp_ip_lock); |
@@ -260,7 +262,7 @@ static int l2tp_ip_bind(struct sock *sk, struct sockaddr *uaddr, int addr_len) | |||
260 | if (sk->sk_state != TCP_CLOSE || addr_len < sizeof(struct sockaddr_l2tpip)) | 262 | if (sk->sk_state != TCP_CLOSE || addr_len < sizeof(struct sockaddr_l2tpip)) |
261 | goto out; | 263 | goto out; |
262 | 264 | ||
263 | chk_addr_ret = inet_addr_type(&init_net, addr->l2tp_addr.s_addr); | 265 | chk_addr_ret = inet_addr_type(net, addr->l2tp_addr.s_addr); |
264 | ret = -EADDRNOTAVAIL; | 266 | ret = -EADDRNOTAVAIL; |
265 | if (addr->l2tp_addr.s_addr && chk_addr_ret != RTN_LOCAL && | 267 | if (addr->l2tp_addr.s_addr && chk_addr_ret != RTN_LOCAL && |
266 | chk_addr_ret != RTN_MULTICAST && chk_addr_ret != RTN_BROADCAST) | 268 | chk_addr_ret != RTN_MULTICAST && chk_addr_ret != RTN_BROADCAST) |
@@ -369,7 +371,7 @@ static int l2tp_ip_backlog_recv(struct sock *sk, struct sk_buff *skb) | |||
369 | return 0; | 371 | return 0; |
370 | 372 | ||
371 | drop: | 373 | drop: |
372 | IP_INC_STATS(&init_net, IPSTATS_MIB_INDISCARDS); | 374 | IP_INC_STATS(sock_net(sk), IPSTATS_MIB_INDISCARDS); |
373 | kfree_skb(skb); | 375 | kfree_skb(skb); |
374 | return -1; | 376 | return -1; |
375 | } | 377 | } |
@@ -605,6 +607,7 @@ static struct inet_protosw l2tp_ip_protosw = { | |||
605 | 607 | ||
606 | static struct net_protocol l2tp_ip_protocol __read_mostly = { | 608 | static struct net_protocol l2tp_ip_protocol __read_mostly = { |
607 | .handler = l2tp_ip_recv, | 609 | .handler = l2tp_ip_recv, |
610 | .netns_ok = 1, | ||
608 | }; | 611 | }; |
609 | 612 | ||
610 | static int __init l2tp_ip_init(void) | 613 | static int __init l2tp_ip_init(void) |
diff --git a/net/l2tp/l2tp_ip6.c b/net/l2tp/l2tp_ip6.c index 8ee4a86ae996..41f2f8126ebc 100644 --- a/net/l2tp/l2tp_ip6.c +++ b/net/l2tp/l2tp_ip6.c | |||
@@ -60,10 +60,9 @@ static struct sock *__l2tp_ip6_bind_lookup(struct net *net, | |||
60 | struct in6_addr *laddr, | 60 | struct in6_addr *laddr, |
61 | int dif, u32 tunnel_id) | 61 | int dif, u32 tunnel_id) |
62 | { | 62 | { |
63 | struct hlist_node *node; | ||
64 | struct sock *sk; | 63 | struct sock *sk; |
65 | 64 | ||
66 | sk_for_each_bound(sk, node, &l2tp_ip6_bind_table) { | 65 | sk_for_each_bound(sk, &l2tp_ip6_bind_table) { |
67 | struct in6_addr *addr = inet6_rcv_saddr(sk); | 66 | struct in6_addr *addr = inet6_rcv_saddr(sk); |
68 | struct l2tp_ip6_sock *l2tp = l2tp_ip6_sk(sk); | 67 | struct l2tp_ip6_sock *l2tp = l2tp_ip6_sk(sk); |
69 | 68 | ||
diff --git a/net/l2tp/l2tp_netlink.c b/net/l2tp/l2tp_netlink.c index bbba3a19e944..c1bab22db85e 100644 --- a/net/l2tp/l2tp_netlink.c +++ b/net/l2tp/l2tp_netlink.c | |||
@@ -37,6 +37,7 @@ static struct genl_family l2tp_nl_family = { | |||
37 | .version = L2TP_GENL_VERSION, | 37 | .version = L2TP_GENL_VERSION, |
38 | .hdrsize = 0, | 38 | .hdrsize = 0, |
39 | .maxattr = L2TP_ATTR_MAX, | 39 | .maxattr = L2TP_ATTR_MAX, |
40 | .netnsok = true, | ||
40 | }; | 41 | }; |
41 | 42 | ||
42 | /* Accessed under genl lock */ | 43 | /* Accessed under genl lock */ |
diff --git a/net/l2tp/l2tp_ppp.c b/net/l2tp/l2tp_ppp.c index 716605c241f4..3f4e3afc191a 100644 --- a/net/l2tp/l2tp_ppp.c +++ b/net/l2tp/l2tp_ppp.c | |||
@@ -1783,7 +1783,8 @@ static __net_init int pppol2tp_init_net(struct net *net) | |||
1783 | struct proc_dir_entry *pde; | 1783 | struct proc_dir_entry *pde; |
1784 | int err = 0; | 1784 | int err = 0; |
1785 | 1785 | ||
1786 | pde = proc_net_fops_create(net, "pppol2tp", S_IRUGO, &pppol2tp_proc_fops); | 1786 | pde = proc_create("pppol2tp", S_IRUGO, net->proc_net, |
1787 | &pppol2tp_proc_fops); | ||
1787 | if (!pde) { | 1788 | if (!pde) { |
1788 | err = -ENOMEM; | 1789 | err = -ENOMEM; |
1789 | goto out; | 1790 | goto out; |
@@ -1795,7 +1796,7 @@ out: | |||
1795 | 1796 | ||
1796 | static __net_exit void pppol2tp_exit_net(struct net *net) | 1797 | static __net_exit void pppol2tp_exit_net(struct net *net) |
1797 | { | 1798 | { |
1798 | proc_net_remove(net, "pppol2tp"); | 1799 | remove_proc_entry("pppol2tp", net->proc_net); |
1799 | } | 1800 | } |
1800 | 1801 | ||
1801 | static struct pernet_operations pppol2tp_net_ops = { | 1802 | static struct pernet_operations pppol2tp_net_ops = { |