1 #include <linux/module.h>
2 #include <linux/errno.h>
3 #include <linux/socket.h>
5 #include <linux/types.h>
6 #include <linux/kernel.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>
15 int udp_sock_create6(struct net
*net
, struct udp_port_cfg
*cfg
,
16 struct socket
**sockp
)
18 struct sockaddr_in6 udp6_addr
;
20 struct socket
*sock
= NULL
;
22 err
= sock_create_kern(AF_INET6
, SOCK_DGRAM
, 0, &sock
);
26 sk_change_net(sock
->sk
, net
);
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
,
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);
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
);
57 kernel_sock_shutdown(sock
, SHUT_RDWR
);
58 sk_release_kernel(sock
->sk
);
63 EXPORT_SYMBOL_GPL(udp_sock_create6
);
65 int udp_tunnel6_xmit_skb(struct dst_entry
*dst
, struct sock
*sk
,
67 struct net_device
*dev
, struct in6_addr
*saddr
,
68 struct in6_addr
*daddr
,
69 __u8 prio
, __u8 ttl
, __be16 src_port
,
70 __be16 dst_port
, bool nocheck
)
75 __skb_push(skb
, sizeof(*uh
));
76 skb_reset_transport_header(skb
);
80 uh
->source
= src_port
;
82 uh
->len
= htons(skb
->len
);
84 memset(&(IPCB(skb
)->opt
), 0, sizeof(IPCB(skb
)->opt
));
85 IPCB(skb
)->flags
&= ~(IPSKB_XFRM_TUNNEL_SIZE
| IPSKB_XFRM_TRANSFORMED
87 skb_dst_set(skb
, dst
);
89 udp6_set_csum(nocheck
, skb
, saddr
, daddr
, skb
->len
);
91 __skb_push(skb
, sizeof(*ip6h
));
92 skb_reset_network_header(skb
);
94 ip6_flow_hdr(ip6h
, prio
, htonl(0));
95 ip6h
->payload_len
= htons(skb
->len
);
96 ip6h
->nexthdr
= IPPROTO_UDP
;
97 ip6h
->hop_limit
= ttl
;
101 ip6tunnel_xmit(sk
, skb
, dev
);
104 EXPORT_SYMBOL_GPL(udp_tunnel6_xmit_skb
);
106 MODULE_LICENSE("GPL");