diff options
author | Andy Zhou <azhou@nicira.com> | 2014-09-16 20:31:16 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2014-09-19 15:57:15 -0400 |
commit | fd384412e199b62c3ddaabd18dce86d0e164c5b9 (patch) | |
tree | 88c3a930da306688b23767a2be6ac2826e5826b5 /net/ipv6/ip6_udp_tunnel.c | |
parent | 79ba2b4c5d3779d68b4cd3a569d483f1778f2b5a (diff) |
udp_tunnel: Seperate ipv6 functions into its own file.
Add ip6_udp_tunnel.c for ipv6 UDP tunnel functions to avoid ifdefs
in udp_tunnel.c
Signed-off-by: Andy Zhou <azhou@nicira.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/ipv6/ip6_udp_tunnel.c')
-rw-r--r-- | net/ipv6/ip6_udp_tunnel.c | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/net/ipv6/ip6_udp_tunnel.c b/net/ipv6/ip6_udp_tunnel.c new file mode 100644 index 000000000000..bcfbb4b496fc --- /dev/null +++ b/net/ipv6/ip6_udp_tunnel.c | |||
@@ -0,0 +1,63 @@ | |||
1 | #include <linux/module.h> | ||
2 | #include <linux/errno.h> | ||
3 | #include <linux/socket.h> | ||
4 | #include <linux/udp.h> | ||
5 | #include <linux/types.h> | ||
6 | #include <linux/kernel.h> | ||
7 | #include <linux/in6.h> | ||
8 | #include <net/udp.h> | ||
9 | #include <net/udp_tunnel.h> | ||
10 | #include <net/net_namespace.h> | ||
11 | #include <net/netns/generic.h> | ||
12 | #include <net/ip6_tunnel.h> | ||
13 | #include <net/ip6_checksum.h> | ||
14 | |||
15 | int udp_sock_create6(struct net *net, struct udp_port_cfg *cfg, | ||
16 | struct socket **sockp) | ||
17 | { | ||
18 | struct sockaddr_in6 udp6_addr; | ||
19 | int err; | ||
20 | struct socket *sock = NULL; | ||
21 | |||
22 | err = sock_create_kern(AF_INET6, SOCK_DGRAM, 0, &sock); | ||
23 | if (err < 0) | ||
24 | goto error; | ||
25 | |||
26 | sk_change_net(sock->sk, net); | ||
27 | |||
28 | udp6_addr.sin6_family = AF_INET6; | ||
29 | memcpy(&udp6_addr.sin6_addr, &cfg->local_ip6, | ||
30 | sizeof(udp6_addr.sin6_addr)); | ||
31 | udp6_addr.sin6_port = cfg->local_udp_port; | ||
32 | err = kernel_bind(sock, (struct sockaddr *)&udp6_addr, | ||
33 | sizeof(udp6_addr)); | ||
34 | if (err < 0) | ||
35 | goto error; | ||
36 | |||
37 | if (cfg->peer_udp_port) { | ||
38 | udp6_addr.sin6_family = AF_INET6; | ||
39 | memcpy(&udp6_addr.sin6_addr, &cfg->peer_ip6, | ||
40 | sizeof(udp6_addr.sin6_addr)); | ||
41 | udp6_addr.sin6_port = cfg->peer_udp_port; | ||
42 | err = kernel_connect(sock, | ||
43 | (struct sockaddr *)&udp6_addr, | ||
44 | sizeof(udp6_addr), 0); | ||
45 | } | ||
46 | if (err < 0) | ||
47 | goto error; | ||
48 | |||
49 | udp_set_no_check6_tx(sock->sk, !cfg->use_udp6_tx_checksums); | ||
50 | udp_set_no_check6_rx(sock->sk, !cfg->use_udp6_rx_checksums); | ||
51 | |||
52 | *sockp = sock; | ||
53 | return 0; | ||
54 | |||
55 | error: | ||
56 | if (sock) { | ||
57 | kernel_sock_shutdown(sock, SHUT_RDWR); | ||
58 | sk_release_kernel(sock->sk); | ||
59 | } | ||
60 | *sockp = NULL; | ||
61 | return err; | ||
62 | } | ||
63 | EXPORT_SYMBOL_GPL(udp_sock_create6); | ||