diff options
Diffstat (limited to 'net/l2tp')
-rw-r--r-- | net/l2tp/l2tp_core.c | 179 | ||||
-rw-r--r-- | net/l2tp/l2tp_core.h | 2 | ||||
-rw-r--r-- | net/l2tp/l2tp_ip.c | 16 | ||||
-rw-r--r-- | net/l2tp/l2tp_netlink.c | 1 |
4 files changed, 124 insertions, 74 deletions
diff --git a/net/l2tp/l2tp_core.c b/net/l2tp/l2tp_core.c index 2ac884d0e89b..dcfd64e83ab7 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 | */ |
@@ -1271,6 +1271,7 @@ EXPORT_SYMBOL_GPL(l2tp_xmit_skb); | |||
1271 | static void l2tp_tunnel_destruct(struct sock *sk) | 1271 | static void l2tp_tunnel_destruct(struct sock *sk) |
1272 | { | 1272 | { |
1273 | struct l2tp_tunnel *tunnel; | 1273 | struct l2tp_tunnel *tunnel; |
1274 | struct l2tp_net *pn; | ||
1274 | 1275 | ||
1275 | tunnel = sk->sk_user_data; | 1276 | tunnel = sk->sk_user_data; |
1276 | if (tunnel == NULL) | 1277 | if (tunnel == NULL) |
@@ -1278,9 +1279,8 @@ static void l2tp_tunnel_destruct(struct sock *sk) | |||
1278 | 1279 | ||
1279 | l2tp_info(tunnel, L2TP_MSG_CONTROL, "%s: closing...\n", tunnel->name); | 1280 | l2tp_info(tunnel, L2TP_MSG_CONTROL, "%s: closing...\n", tunnel->name); |
1280 | 1281 | ||
1281 | /* Close all sessions */ | ||
1282 | l2tp_tunnel_closeall(tunnel); | ||
1283 | 1282 | ||
1283 | /* Disable udp encapsulation */ | ||
1284 | switch (tunnel->encap) { | 1284 | switch (tunnel->encap) { |
1285 | case L2TP_ENCAPTYPE_UDP: | 1285 | case L2TP_ENCAPTYPE_UDP: |
1286 | /* No longer an encapsulation socket. See net/ipv4/udp.c */ | 1286 | /* No longer an encapsulation socket. See net/ipv4/udp.c */ |
@@ -1292,17 +1292,23 @@ static void l2tp_tunnel_destruct(struct sock *sk) | |||
1292 | } | 1292 | } |
1293 | 1293 | ||
1294 | /* Remove hooks into tunnel socket */ | 1294 | /* Remove hooks into tunnel socket */ |
1295 | tunnel->sock = NULL; | ||
1296 | sk->sk_destruct = tunnel->old_sk_destruct; | 1295 | sk->sk_destruct = tunnel->old_sk_destruct; |
1297 | sk->sk_user_data = NULL; | 1296 | sk->sk_user_data = NULL; |
1297 | tunnel->sock = NULL; | ||
1298 | 1298 | ||
1299 | /* Call the original destructor */ | 1299 | /* Remove the tunnel struct from the tunnel list */ |
1300 | if (sk->sk_destruct) | 1300 | pn = l2tp_pernet(tunnel->l2tp_net); |
1301 | (*sk->sk_destruct)(sk); | 1301 | spin_lock_bh(&pn->l2tp_tunnel_list_lock); |
1302 | list_del_rcu(&tunnel->list); | ||
1303 | spin_unlock_bh(&pn->l2tp_tunnel_list_lock); | ||
1304 | atomic_dec(&l2tp_tunnel_count); | ||
1302 | 1305 | ||
1303 | /* We're finished with the socket */ | 1306 | l2tp_tunnel_closeall(tunnel); |
1304 | l2tp_tunnel_dec_refcount(tunnel); | 1307 | l2tp_tunnel_dec_refcount(tunnel); |
1305 | 1308 | ||
1309 | /* Call the original destructor */ | ||
1310 | if (sk->sk_destruct) | ||
1311 | (*sk->sk_destruct)(sk); | ||
1306 | end: | 1312 | end: |
1307 | return; | 1313 | return; |
1308 | } | 1314 | } |
@@ -1376,48 +1382,77 @@ again: | |||
1376 | */ | 1382 | */ |
1377 | static void l2tp_tunnel_free(struct l2tp_tunnel *tunnel) | 1383 | static void l2tp_tunnel_free(struct l2tp_tunnel *tunnel) |
1378 | { | 1384 | { |
1379 | struct l2tp_net *pn = l2tp_pernet(tunnel->l2tp_net); | ||
1380 | |||
1381 | BUG_ON(atomic_read(&tunnel->ref_count) != 0); | 1385 | BUG_ON(atomic_read(&tunnel->ref_count) != 0); |
1382 | BUG_ON(tunnel->sock != NULL); | 1386 | BUG_ON(tunnel->sock != NULL); |
1383 | |||
1384 | l2tp_info(tunnel, L2TP_MSG_CONTROL, "%s: free...\n", tunnel->name); | 1387 | 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); | 1388 | kfree_rcu(tunnel, rcu); |
1390 | spin_unlock_bh(&pn->l2tp_tunnel_list_lock); | 1389 | } |
1391 | 1390 | ||
1392 | atomic_dec(&l2tp_tunnel_count); | 1391 | /* Workqueue tunnel deletion function */ |
1392 | static void l2tp_tunnel_del_work(struct work_struct *work) | ||
1393 | { | ||
1394 | struct l2tp_tunnel *tunnel = NULL; | ||
1395 | struct socket *sock = NULL; | ||
1396 | struct sock *sk = NULL; | ||
1397 | |||
1398 | tunnel = container_of(work, struct l2tp_tunnel, del_work); | ||
1399 | sk = l2tp_tunnel_sock_lookup(tunnel); | ||
1400 | if (!sk) | ||
1401 | return; | ||
1402 | |||
1403 | sock = sk->sk_socket; | ||
1404 | BUG_ON(!sock); | ||
1405 | |||
1406 | /* If the tunnel socket was created directly by the kernel, use the | ||
1407 | * sk_* API to release the socket now. Otherwise go through the | ||
1408 | * inet_* layer to shut the socket down, and let userspace close it. | ||
1409 | * In either case the tunnel resources are freed in the socket | ||
1410 | * destructor when the tunnel socket goes away. | ||
1411 | */ | ||
1412 | if (sock->file == NULL) { | ||
1413 | kernel_sock_shutdown(sock, SHUT_RDWR); | ||
1414 | sk_release_kernel(sk); | ||
1415 | } else { | ||
1416 | inet_shutdown(sock, 2); | ||
1417 | } | ||
1418 | |||
1419 | l2tp_tunnel_sock_put(sk); | ||
1393 | } | 1420 | } |
1394 | 1421 | ||
1395 | /* Create a socket for the tunnel, if one isn't set up by | 1422 | /* 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 | 1423 | * userspace. This is used for static tunnels where there is no |
1397 | * managing L2TP daemon. | 1424 | * managing L2TP daemon. |
1425 | * | ||
1426 | * Since we don't want these sockets to keep a namespace alive by | ||
1427 | * themselves, we drop the socket's namespace refcount after creation. | ||
1428 | * These sockets are freed when the namespace exits using the pernet | ||
1429 | * exit hook. | ||
1398 | */ | 1430 | */ |
1399 | static int l2tp_tunnel_sock_create(u32 tunnel_id, u32 peer_tunnel_id, struct l2tp_tunnel_cfg *cfg, struct socket **sockp) | 1431 | static int l2tp_tunnel_sock_create(struct net *net, |
1432 | u32 tunnel_id, | ||
1433 | u32 peer_tunnel_id, | ||
1434 | struct l2tp_tunnel_cfg *cfg, | ||
1435 | struct socket **sockp) | ||
1400 | { | 1436 | { |
1401 | int err = -EINVAL; | 1437 | int err = -EINVAL; |
1402 | struct sockaddr_in udp_addr; | 1438 | struct socket *sock = NULL; |
1439 | struct sockaddr_in udp_addr = {0}; | ||
1440 | struct sockaddr_l2tpip ip_addr = {0}; | ||
1403 | #if IS_ENABLED(CONFIG_IPV6) | 1441 | #if IS_ENABLED(CONFIG_IPV6) |
1404 | struct sockaddr_in6 udp6_addr; | 1442 | struct sockaddr_in6 udp6_addr = {0}; |
1405 | struct sockaddr_l2tpip6 ip6_addr; | 1443 | struct sockaddr_l2tpip6 ip6_addr = {0}; |
1406 | #endif | 1444 | #endif |
1407 | struct sockaddr_l2tpip ip_addr; | ||
1408 | struct socket *sock = NULL; | ||
1409 | 1445 | ||
1410 | switch (cfg->encap) { | 1446 | switch (cfg->encap) { |
1411 | case L2TP_ENCAPTYPE_UDP: | 1447 | case L2TP_ENCAPTYPE_UDP: |
1412 | #if IS_ENABLED(CONFIG_IPV6) | 1448 | #if IS_ENABLED(CONFIG_IPV6) |
1413 | if (cfg->local_ip6 && cfg->peer_ip6) { | 1449 | if (cfg->local_ip6 && cfg->peer_ip6) { |
1414 | err = sock_create(AF_INET6, SOCK_DGRAM, 0, sockp); | 1450 | err = sock_create_kern(AF_INET6, SOCK_DGRAM, 0, &sock); |
1415 | if (err < 0) | 1451 | if (err < 0) |
1416 | goto out; | 1452 | goto out; |
1417 | 1453 | ||
1418 | sock = *sockp; | 1454 | sk_change_net(sock->sk, net); |
1419 | 1455 | ||
1420 | memset(&udp6_addr, 0, sizeof(udp6_addr)); | ||
1421 | udp6_addr.sin6_family = AF_INET6; | 1456 | udp6_addr.sin6_family = AF_INET6; |
1422 | memcpy(&udp6_addr.sin6_addr, cfg->local_ip6, | 1457 | memcpy(&udp6_addr.sin6_addr, cfg->local_ip6, |
1423 | sizeof(udp6_addr.sin6_addr)); | 1458 | sizeof(udp6_addr.sin6_addr)); |
@@ -1439,13 +1474,12 @@ static int l2tp_tunnel_sock_create(u32 tunnel_id, u32 peer_tunnel_id, struct l2t | |||
1439 | } else | 1474 | } else |
1440 | #endif | 1475 | #endif |
1441 | { | 1476 | { |
1442 | err = sock_create(AF_INET, SOCK_DGRAM, 0, sockp); | 1477 | err = sock_create_kern(AF_INET, SOCK_DGRAM, 0, &sock); |
1443 | if (err < 0) | 1478 | if (err < 0) |
1444 | goto out; | 1479 | goto out; |
1445 | 1480 | ||
1446 | sock = *sockp; | 1481 | sk_change_net(sock->sk, net); |
1447 | 1482 | ||
1448 | memset(&udp_addr, 0, sizeof(udp_addr)); | ||
1449 | udp_addr.sin_family = AF_INET; | 1483 | udp_addr.sin_family = AF_INET; |
1450 | udp_addr.sin_addr = cfg->local_ip; | 1484 | udp_addr.sin_addr = cfg->local_ip; |
1451 | udp_addr.sin_port = htons(cfg->local_udp_port); | 1485 | udp_addr.sin_port = htons(cfg->local_udp_port); |
@@ -1472,14 +1506,13 @@ static int l2tp_tunnel_sock_create(u32 tunnel_id, u32 peer_tunnel_id, struct l2t | |||
1472 | case L2TP_ENCAPTYPE_IP: | 1506 | case L2TP_ENCAPTYPE_IP: |
1473 | #if IS_ENABLED(CONFIG_IPV6) | 1507 | #if IS_ENABLED(CONFIG_IPV6) |
1474 | if (cfg->local_ip6 && cfg->peer_ip6) { | 1508 | if (cfg->local_ip6 && cfg->peer_ip6) { |
1475 | err = sock_create(AF_INET6, SOCK_DGRAM, IPPROTO_L2TP, | 1509 | err = sock_create_kern(AF_INET6, SOCK_DGRAM, |
1476 | sockp); | 1510 | IPPROTO_L2TP, &sock); |
1477 | if (err < 0) | 1511 | if (err < 0) |
1478 | goto out; | 1512 | goto out; |
1479 | 1513 | ||
1480 | sock = *sockp; | 1514 | sk_change_net(sock->sk, net); |
1481 | 1515 | ||
1482 | memset(&ip6_addr, 0, sizeof(ip6_addr)); | ||
1483 | ip6_addr.l2tp_family = AF_INET6; | 1516 | ip6_addr.l2tp_family = AF_INET6; |
1484 | memcpy(&ip6_addr.l2tp_addr, cfg->local_ip6, | 1517 | memcpy(&ip6_addr.l2tp_addr, cfg->local_ip6, |
1485 | sizeof(ip6_addr.l2tp_addr)); | 1518 | sizeof(ip6_addr.l2tp_addr)); |
@@ -1501,14 +1534,13 @@ static int l2tp_tunnel_sock_create(u32 tunnel_id, u32 peer_tunnel_id, struct l2t | |||
1501 | } else | 1534 | } else |
1502 | #endif | 1535 | #endif |
1503 | { | 1536 | { |
1504 | err = sock_create(AF_INET, SOCK_DGRAM, IPPROTO_L2TP, | 1537 | err = sock_create_kern(AF_INET, SOCK_DGRAM, |
1505 | sockp); | 1538 | IPPROTO_L2TP, &sock); |
1506 | if (err < 0) | 1539 | if (err < 0) |
1507 | goto out; | 1540 | goto out; |
1508 | 1541 | ||
1509 | sock = *sockp; | 1542 | sk_change_net(sock->sk, net); |
1510 | 1543 | ||
1511 | memset(&ip_addr, 0, sizeof(ip_addr)); | ||
1512 | ip_addr.l2tp_family = AF_INET; | 1544 | ip_addr.l2tp_family = AF_INET; |
1513 | ip_addr.l2tp_addr = cfg->local_ip; | 1545 | ip_addr.l2tp_addr = cfg->local_ip; |
1514 | ip_addr.l2tp_conn_id = tunnel_id; | 1546 | ip_addr.l2tp_conn_id = tunnel_id; |
@@ -1532,8 +1564,10 @@ static int l2tp_tunnel_sock_create(u32 tunnel_id, u32 peer_tunnel_id, struct l2t | |||
1532 | } | 1564 | } |
1533 | 1565 | ||
1534 | out: | 1566 | out: |
1567 | *sockp = sock; | ||
1535 | if ((err < 0) && sock) { | 1568 | if ((err < 0) && sock) { |
1536 | sock_release(sock); | 1569 | kernel_sock_shutdown(sock, SHUT_RDWR); |
1570 | sk_release_kernel(sock->sk); | ||
1537 | *sockp = NULL; | 1571 | *sockp = NULL; |
1538 | } | 1572 | } |
1539 | 1573 | ||
@@ -1556,15 +1590,23 @@ int l2tp_tunnel_create(struct net *net, int fd, int version, u32 tunnel_id, u32 | |||
1556 | * kernel socket. | 1590 | * kernel socket. |
1557 | */ | 1591 | */ |
1558 | if (fd < 0) { | 1592 | if (fd < 0) { |
1559 | err = l2tp_tunnel_sock_create(tunnel_id, peer_tunnel_id, cfg, &sock); | 1593 | err = l2tp_tunnel_sock_create(net, tunnel_id, peer_tunnel_id, |
1594 | cfg, &sock); | ||
1560 | if (err < 0) | 1595 | if (err < 0) |
1561 | goto err; | 1596 | goto err; |
1562 | } else { | 1597 | } else { |
1563 | err = -EBADF; | ||
1564 | sock = sockfd_lookup(fd, &err); | 1598 | sock = sockfd_lookup(fd, &err); |
1565 | if (!sock) { | 1599 | if (!sock) { |
1566 | pr_err("tunl %hu: sockfd_lookup(fd=%d) returned %d\n", | 1600 | pr_err("tunl %u: sockfd_lookup(fd=%d) returned %d\n", |
1567 | tunnel_id, fd, err); | 1601 | tunnel_id, fd, err); |
1602 | err = -EBADF; | ||
1603 | goto err; | ||
1604 | } | ||
1605 | |||
1606 | /* Reject namespace mismatches */ | ||
1607 | if (!net_eq(sock_net(sock->sk), net)) { | ||
1608 | pr_err("tunl %u: netns mismatch\n", tunnel_id); | ||
1609 | err = -EINVAL; | ||
1568 | goto err; | 1610 | goto err; |
1569 | } | 1611 | } |
1570 | } | 1612 | } |
@@ -1651,6 +1693,9 @@ int l2tp_tunnel_create(struct net *net, int fd, int version, u32 tunnel_id, u32 | |||
1651 | 1693 | ||
1652 | sk->sk_allocation = GFP_ATOMIC; | 1694 | sk->sk_allocation = GFP_ATOMIC; |
1653 | 1695 | ||
1696 | /* Init delete workqueue struct */ | ||
1697 | INIT_WORK(&tunnel->del_work, l2tp_tunnel_del_work); | ||
1698 | |||
1654 | /* Add tunnel to our list */ | 1699 | /* Add tunnel to our list */ |
1655 | INIT_LIST_HEAD(&tunnel->list); | 1700 | INIT_LIST_HEAD(&tunnel->list); |
1656 | atomic_inc(&l2tp_tunnel_count); | 1701 | atomic_inc(&l2tp_tunnel_count); |
@@ -1682,33 +1727,7 @@ EXPORT_SYMBOL_GPL(l2tp_tunnel_create); | |||
1682 | */ | 1727 | */ |
1683 | int l2tp_tunnel_delete(struct l2tp_tunnel *tunnel) | 1728 | int l2tp_tunnel_delete(struct l2tp_tunnel *tunnel) |
1684 | { | 1729 | { |
1685 | int err = -EBADF; | 1730 | 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 | } | 1731 | } |
1713 | EXPORT_SYMBOL_GPL(l2tp_tunnel_delete); | 1732 | EXPORT_SYMBOL_GPL(l2tp_tunnel_delete); |
1714 | 1733 | ||
@@ -1892,8 +1911,21 @@ static __net_init int l2tp_init_net(struct net *net) | |||
1892 | return 0; | 1911 | return 0; |
1893 | } | 1912 | } |
1894 | 1913 | ||
1914 | static __net_exit void l2tp_exit_net(struct net *net) | ||
1915 | { | ||
1916 | struct l2tp_net *pn = l2tp_pernet(net); | ||
1917 | struct l2tp_tunnel *tunnel = NULL; | ||
1918 | |||
1919 | rcu_read_lock_bh(); | ||
1920 | list_for_each_entry_rcu(tunnel, &pn->l2tp_tunnel_list, list) { | ||
1921 | (void)l2tp_tunnel_delete(tunnel); | ||
1922 | } | ||
1923 | rcu_read_unlock_bh(); | ||
1924 | } | ||
1925 | |||
1895 | static struct pernet_operations l2tp_net_ops = { | 1926 | static struct pernet_operations l2tp_net_ops = { |
1896 | .init = l2tp_init_net, | 1927 | .init = l2tp_init_net, |
1928 | .exit = l2tp_exit_net, | ||
1897 | .id = &l2tp_net_id, | 1929 | .id = &l2tp_net_id, |
1898 | .size = sizeof(struct l2tp_net), | 1930 | .size = sizeof(struct l2tp_net), |
1899 | }; | 1931 | }; |
@@ -1906,6 +1938,13 @@ static int __init l2tp_init(void) | |||
1906 | if (rc) | 1938 | if (rc) |
1907 | goto out; | 1939 | goto out; |
1908 | 1940 | ||
1941 | l2tp_wq = alloc_workqueue("l2tp", WQ_NON_REENTRANT | WQ_UNBOUND, 0); | ||
1942 | if (!l2tp_wq) { | ||
1943 | pr_err("alloc_workqueue failed\n"); | ||
1944 | rc = -ENOMEM; | ||
1945 | goto out; | ||
1946 | } | ||
1947 | |||
1909 | pr_info("L2TP core driver, %s\n", L2TP_DRV_VERSION); | 1948 | pr_info("L2TP core driver, %s\n", L2TP_DRV_VERSION); |
1910 | 1949 | ||
1911 | out: | 1950 | out: |
@@ -1915,6 +1954,10 @@ out: | |||
1915 | static void __exit l2tp_exit(void) | 1954 | static void __exit l2tp_exit(void) |
1916 | { | 1955 | { |
1917 | unregister_pernet_device(&l2tp_net_ops); | 1956 | unregister_pernet_device(&l2tp_net_ops); |
1957 | if (l2tp_wq) { | ||
1958 | destroy_workqueue(l2tp_wq); | ||
1959 | l2tp_wq = NULL; | ||
1960 | } | ||
1918 | } | 1961 | } |
1919 | 1962 | ||
1920 | module_init(l2tp_init); | 1963 | 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..f7ac8f42fee2 100644 --- a/net/l2tp/l2tp_ip.c +++ b/net/l2tp/l2tp_ip.c | |||
@@ -115,6 +115,7 @@ static inline struct sock *l2tp_ip_bind_lookup(struct net *net, __be32 laddr, in | |||
115 | */ | 115 | */ |
116 | static int l2tp_ip_recv(struct sk_buff *skb) | 116 | static int l2tp_ip_recv(struct sk_buff *skb) |
117 | { | 117 | { |
118 | struct net *net = dev_net(skb->dev); | ||
118 | struct sock *sk; | 119 | struct sock *sk; |
119 | u32 session_id; | 120 | u32 session_id; |
120 | u32 tunnel_id; | 121 | u32 tunnel_id; |
@@ -142,7 +143,7 @@ static int l2tp_ip_recv(struct sk_buff *skb) | |||
142 | } | 143 | } |
143 | 144 | ||
144 | /* Ok, this is a data packet. Lookup the session. */ | 145 | /* Ok, this is a data packet. Lookup the session. */ |
145 | session = l2tp_session_find(&init_net, NULL, session_id); | 146 | session = l2tp_session_find(net, NULL, session_id); |
146 | if (session == NULL) | 147 | if (session == NULL) |
147 | goto discard; | 148 | goto discard; |
148 | 149 | ||
@@ -173,14 +174,14 @@ pass_up: | |||
173 | goto discard; | 174 | goto discard; |
174 | 175 | ||
175 | tunnel_id = ntohl(*(__be32 *) &skb->data[4]); | 176 | tunnel_id = ntohl(*(__be32 *) &skb->data[4]); |
176 | tunnel = l2tp_tunnel_find(&init_net, tunnel_id); | 177 | tunnel = l2tp_tunnel_find(net, tunnel_id); |
177 | if (tunnel != NULL) | 178 | if (tunnel != NULL) |
178 | sk = tunnel->sock; | 179 | sk = tunnel->sock; |
179 | else { | 180 | else { |
180 | struct iphdr *iph = (struct iphdr *) skb_network_header(skb); | 181 | struct iphdr *iph = (struct iphdr *) skb_network_header(skb); |
181 | 182 | ||
182 | read_lock_bh(&l2tp_ip_lock); | 183 | read_lock_bh(&l2tp_ip_lock); |
183 | sk = __l2tp_ip_bind_lookup(&init_net, iph->daddr, 0, tunnel_id); | 184 | sk = __l2tp_ip_bind_lookup(net, iph->daddr, 0, tunnel_id); |
184 | read_unlock_bh(&l2tp_ip_lock); | 185 | read_unlock_bh(&l2tp_ip_lock); |
185 | } | 186 | } |
186 | 187 | ||
@@ -239,6 +240,7 @@ static int l2tp_ip_bind(struct sock *sk, struct sockaddr *uaddr, int addr_len) | |||
239 | { | 240 | { |
240 | struct inet_sock *inet = inet_sk(sk); | 241 | struct inet_sock *inet = inet_sk(sk); |
241 | struct sockaddr_l2tpip *addr = (struct sockaddr_l2tpip *) uaddr; | 242 | struct sockaddr_l2tpip *addr = (struct sockaddr_l2tpip *) uaddr; |
243 | struct net *net = sock_net(sk); | ||
242 | int ret; | 244 | int ret; |
243 | int chk_addr_ret; | 245 | int chk_addr_ret; |
244 | 246 | ||
@@ -251,7 +253,8 @@ static int l2tp_ip_bind(struct sock *sk, struct sockaddr *uaddr, int addr_len) | |||
251 | 253 | ||
252 | ret = -EADDRINUSE; | 254 | ret = -EADDRINUSE; |
253 | read_lock_bh(&l2tp_ip_lock); | 255 | 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)) | 256 | if (__l2tp_ip_bind_lookup(net, addr->l2tp_addr.s_addr, |
257 | sk->sk_bound_dev_if, addr->l2tp_conn_id)) | ||
255 | goto out_in_use; | 258 | goto out_in_use; |
256 | 259 | ||
257 | read_unlock_bh(&l2tp_ip_lock); | 260 | read_unlock_bh(&l2tp_ip_lock); |
@@ -260,7 +263,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)) | 263 | if (sk->sk_state != TCP_CLOSE || addr_len < sizeof(struct sockaddr_l2tpip)) |
261 | goto out; | 264 | goto out; |
262 | 265 | ||
263 | chk_addr_ret = inet_addr_type(&init_net, addr->l2tp_addr.s_addr); | 266 | chk_addr_ret = inet_addr_type(net, addr->l2tp_addr.s_addr); |
264 | ret = -EADDRNOTAVAIL; | 267 | ret = -EADDRNOTAVAIL; |
265 | if (addr->l2tp_addr.s_addr && chk_addr_ret != RTN_LOCAL && | 268 | if (addr->l2tp_addr.s_addr && chk_addr_ret != RTN_LOCAL && |
266 | chk_addr_ret != RTN_MULTICAST && chk_addr_ret != RTN_BROADCAST) | 269 | chk_addr_ret != RTN_MULTICAST && chk_addr_ret != RTN_BROADCAST) |
@@ -369,7 +372,7 @@ static int l2tp_ip_backlog_recv(struct sock *sk, struct sk_buff *skb) | |||
369 | return 0; | 372 | return 0; |
370 | 373 | ||
371 | drop: | 374 | drop: |
372 | IP_INC_STATS(&init_net, IPSTATS_MIB_INDISCARDS); | 375 | IP_INC_STATS(sock_net(sk), IPSTATS_MIB_INDISCARDS); |
373 | kfree_skb(skb); | 376 | kfree_skb(skb); |
374 | return -1; | 377 | return -1; |
375 | } | 378 | } |
@@ -605,6 +608,7 @@ static struct inet_protosw l2tp_ip_protosw = { | |||
605 | 608 | ||
606 | static struct net_protocol l2tp_ip_protocol __read_mostly = { | 609 | static struct net_protocol l2tp_ip_protocol __read_mostly = { |
607 | .handler = l2tp_ip_recv, | 610 | .handler = l2tp_ip_recv, |
611 | .netns_ok = 1, | ||
608 | }; | 612 | }; |
609 | 613 | ||
610 | static int __init l2tp_ip_init(void) | 614 | static int __init l2tp_ip_init(void) |
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 */ |