diff options
author | Tom Herbert <therbert@google.com> | 2014-07-13 22:49:48 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2014-07-14 19:12:15 -0400 |
commit | 85644b4d0c6f7be64dad461057d78a484b45bf5b (patch) | |
tree | f99939516f412d44db99c588027b291c1ac16a73 /net/l2tp | |
parent | 3ee64f39bebe1a181a1af3e4b641a9b0aae1799a (diff) |
l2tp: Call udp_sock_create
In l2tp driver call common function udp_sock_create to create the
listener UDP port.
Signed-off-by: Tom Herbert <therbert@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/l2tp')
-rw-r--r-- | net/l2tp/Kconfig | 1 | ||||
-rw-r--r-- | net/l2tp/l2tp_core.c | 86 |
2 files changed, 28 insertions, 59 deletions
diff --git a/net/l2tp/Kconfig b/net/l2tp/Kconfig index adb9843dd7cf..378c73b26093 100644 --- a/net/l2tp/Kconfig +++ b/net/l2tp/Kconfig | |||
@@ -6,6 +6,7 @@ menuconfig L2TP | |||
6 | tristate "Layer Two Tunneling Protocol (L2TP)" | 6 | tristate "Layer Two Tunneling Protocol (L2TP)" |
7 | depends on (IPV6 || IPV6=n) | 7 | depends on (IPV6 || IPV6=n) |
8 | depends on INET | 8 | depends on INET |
9 | select NET_UDP_TUNNEL | ||
9 | ---help--- | 10 | ---help--- |
10 | Layer Two Tunneling Protocol | 11 | Layer Two Tunneling Protocol |
11 | 12 | ||
diff --git a/net/l2tp/l2tp_core.c b/net/l2tp/l2tp_core.c index bea259043205..1109d3bb8dac 100644 --- a/net/l2tp/l2tp_core.c +++ b/net/l2tp/l2tp_core.c | |||
@@ -52,6 +52,7 @@ | |||
52 | #include <net/dst.h> | 52 | #include <net/dst.h> |
53 | #include <net/ip.h> | 53 | #include <net/ip.h> |
54 | #include <net/udp.h> | 54 | #include <net/udp.h> |
55 | #include <net/udp_tunnel.h> | ||
55 | #include <net/inet_common.h> | 56 | #include <net/inet_common.h> |
56 | #include <net/xfrm.h> | 57 | #include <net/xfrm.h> |
57 | #include <net/protocol.h> | 58 | #include <net/protocol.h> |
@@ -1358,81 +1359,46 @@ static int l2tp_tunnel_sock_create(struct net *net, | |||
1358 | { | 1359 | { |
1359 | int err = -EINVAL; | 1360 | int err = -EINVAL; |
1360 | struct socket *sock = NULL; | 1361 | struct socket *sock = NULL; |
1361 | struct sockaddr_in udp_addr = {0}; | 1362 | struct udp_port_cfg udp_conf; |
1362 | struct sockaddr_l2tpip ip_addr = {0}; | ||
1363 | #if IS_ENABLED(CONFIG_IPV6) | ||
1364 | struct sockaddr_in6 udp6_addr = {0}; | ||
1365 | struct sockaddr_l2tpip6 ip6_addr = {0}; | ||
1366 | #endif | ||
1367 | 1363 | ||
1368 | switch (cfg->encap) { | 1364 | switch (cfg->encap) { |
1369 | case L2TP_ENCAPTYPE_UDP: | 1365 | case L2TP_ENCAPTYPE_UDP: |
1366 | memset(&udp_conf, 0, sizeof(udp_conf)); | ||
1367 | |||
1370 | #if IS_ENABLED(CONFIG_IPV6) | 1368 | #if IS_ENABLED(CONFIG_IPV6) |
1371 | if (cfg->local_ip6 && cfg->peer_ip6) { | 1369 | if (cfg->local_ip6 && cfg->peer_ip6) { |
1372 | err = sock_create_kern(AF_INET6, SOCK_DGRAM, 0, &sock); | 1370 | udp_conf.family = AF_INET6; |
1373 | if (err < 0) | 1371 | memcpy(&udp_conf.local_ip6, cfg->local_ip6, |
1374 | goto out; | 1372 | sizeof(udp_conf.local_ip6)); |
1375 | 1373 | memcpy(&udp_conf.peer_ip6, cfg->peer_ip6, | |
1376 | sk_change_net(sock->sk, net); | 1374 | sizeof(udp_conf.peer_ip6)); |
1377 | 1375 | udp_conf.use_udp6_tx_checksums = | |
1378 | udp6_addr.sin6_family = AF_INET6; | 1376 | cfg->udp6_zero_tx_checksums; |
1379 | memcpy(&udp6_addr.sin6_addr, cfg->local_ip6, | 1377 | udp_conf.use_udp6_rx_checksums = |
1380 | sizeof(udp6_addr.sin6_addr)); | 1378 | cfg->udp6_zero_rx_checksums; |
1381 | udp6_addr.sin6_port = htons(cfg->local_udp_port); | ||
1382 | err = kernel_bind(sock, (struct sockaddr *) &udp6_addr, | ||
1383 | sizeof(udp6_addr)); | ||
1384 | if (err < 0) | ||
1385 | goto out; | ||
1386 | |||
1387 | udp6_addr.sin6_family = AF_INET6; | ||
1388 | memcpy(&udp6_addr.sin6_addr, cfg->peer_ip6, | ||
1389 | sizeof(udp6_addr.sin6_addr)); | ||
1390 | udp6_addr.sin6_port = htons(cfg->peer_udp_port); | ||
1391 | err = kernel_connect(sock, | ||
1392 | (struct sockaddr *) &udp6_addr, | ||
1393 | sizeof(udp6_addr), 0); | ||
1394 | if (err < 0) | ||
1395 | goto out; | ||
1396 | |||
1397 | if (cfg->udp6_zero_tx_checksums) | ||
1398 | udp_set_no_check6_tx(sock->sk, true); | ||
1399 | if (cfg->udp6_zero_rx_checksums) | ||
1400 | udp_set_no_check6_rx(sock->sk, true); | ||
1401 | } else | 1379 | } else |
1402 | #endif | 1380 | #endif |
1403 | { | 1381 | { |
1404 | err = sock_create_kern(AF_INET, SOCK_DGRAM, 0, &sock); | 1382 | udp_conf.family = AF_INET; |
1405 | if (err < 0) | 1383 | udp_conf.local_ip = cfg->local_ip; |
1406 | goto out; | 1384 | udp_conf.peer_ip = cfg->peer_ip; |
1407 | 1385 | udp_conf.use_udp_checksums = cfg->use_udp_checksums; | |
1408 | sk_change_net(sock->sk, net); | ||
1409 | |||
1410 | udp_addr.sin_family = AF_INET; | ||
1411 | udp_addr.sin_addr = cfg->local_ip; | ||
1412 | udp_addr.sin_port = htons(cfg->local_udp_port); | ||
1413 | err = kernel_bind(sock, (struct sockaddr *) &udp_addr, | ||
1414 | sizeof(udp_addr)); | ||
1415 | if (err < 0) | ||
1416 | goto out; | ||
1417 | |||
1418 | udp_addr.sin_family = AF_INET; | ||
1419 | udp_addr.sin_addr = cfg->peer_ip; | ||
1420 | udp_addr.sin_port = htons(cfg->peer_udp_port); | ||
1421 | err = kernel_connect(sock, | ||
1422 | (struct sockaddr *) &udp_addr, | ||
1423 | sizeof(udp_addr), 0); | ||
1424 | if (err < 0) | ||
1425 | goto out; | ||
1426 | } | 1386 | } |
1427 | 1387 | ||
1428 | if (!cfg->use_udp_checksums) | 1388 | udp_conf.local_udp_port = htons(cfg->local_udp_port); |
1429 | sock->sk->sk_no_check_tx = 1; | 1389 | udp_conf.peer_udp_port = htons(cfg->peer_udp_port); |
1390 | |||
1391 | err = udp_sock_create(net, &udp_conf, &sock); | ||
1392 | if (err < 0) | ||
1393 | goto out; | ||
1430 | 1394 | ||
1431 | break; | 1395 | break; |
1432 | 1396 | ||
1433 | case L2TP_ENCAPTYPE_IP: | 1397 | case L2TP_ENCAPTYPE_IP: |
1434 | #if IS_ENABLED(CONFIG_IPV6) | 1398 | #if IS_ENABLED(CONFIG_IPV6) |
1435 | if (cfg->local_ip6 && cfg->peer_ip6) { | 1399 | if (cfg->local_ip6 && cfg->peer_ip6) { |
1400 | struct sockaddr_l2tpip6 ip6_addr = {0}; | ||
1401 | |||
1436 | err = sock_create_kern(AF_INET6, SOCK_DGRAM, | 1402 | err = sock_create_kern(AF_INET6, SOCK_DGRAM, |
1437 | IPPROTO_L2TP, &sock); | 1403 | IPPROTO_L2TP, &sock); |
1438 | if (err < 0) | 1404 | if (err < 0) |
@@ -1461,6 +1427,8 @@ static int l2tp_tunnel_sock_create(struct net *net, | |||
1461 | } else | 1427 | } else |
1462 | #endif | 1428 | #endif |
1463 | { | 1429 | { |
1430 | struct sockaddr_l2tpip ip_addr = {0}; | ||
1431 | |||
1464 | err = sock_create_kern(AF_INET, SOCK_DGRAM, | 1432 | err = sock_create_kern(AF_INET, SOCK_DGRAM, |
1465 | IPPROTO_L2TP, &sock); | 1433 | IPPROTO_L2TP, &sock); |
1466 | if (err < 0) | 1434 | if (err < 0) |