~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/net/ipv6/ip6_udp_tunnel.c

Version: ~ [ linux-5.16 ] ~ [ linux-5.15.13 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.90 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.170 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.224 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.261 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.296 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.298 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.18.140 ] ~ [ linux-3.16.85 ] ~ [ linux-3.14.79 ] ~ [ linux-3.12.74 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  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(net, AF_INET6, SOCK_DGRAM, 0, &sock);
 23         if (err < 0)
 24                 goto error;
 25 
 26         if (cfg->ipv6_v6only) {
 27                 int val = 1;
 28 
 29                 err = kernel_setsockopt(sock, IPPROTO_IPV6, IPV6_V6ONLY,
 30                                         (char *) &val, sizeof(val));
 31                 if (err < 0)
 32                         goto error;
 33         }
 34         if (cfg->bind_ifindex) {
 35                 err = kernel_setsockopt(sock, SOL_SOCKET, SO_BINDTOIFINDEX,
 36                                         (void *)&cfg->bind_ifindex,
 37                                         sizeof(cfg->bind_ifindex));
 38                 if (err < 0)
 39                         goto error;
 40         }
 41 
 42         udp6_addr.sin6_family = AF_INET6;
 43         memcpy(&udp6_addr.sin6_addr, &cfg->local_ip6,
 44                sizeof(udp6_addr.sin6_addr));
 45         udp6_addr.sin6_port = cfg->local_udp_port;
 46         err = kernel_bind(sock, (struct sockaddr *)&udp6_addr,
 47                           sizeof(udp6_addr));
 48         if (err < 0)
 49                 goto error;
 50 
 51         if (cfg->peer_udp_port) {
 52                 memset(&udp6_addr, 0, sizeof(udp6_addr));
 53                 udp6_addr.sin6_family = AF_INET6;
 54                 memcpy(&udp6_addr.sin6_addr, &cfg->peer_ip6,
 55                        sizeof(udp6_addr.sin6_addr));
 56                 udp6_addr.sin6_port = cfg->peer_udp_port;
 57                 err = kernel_connect(sock,
 58                                      (struct sockaddr *)&udp6_addr,
 59                                      sizeof(udp6_addr), 0);
 60         }
 61         if (err < 0)
 62                 goto error;
 63 
 64         udp_set_no_check6_tx(sock->sk, !cfg->use_udp6_tx_checksums);
 65         udp_set_no_check6_rx(sock->sk, !cfg->use_udp6_rx_checksums);
 66 
 67         *sockp = sock;
 68         return 0;
 69 
 70 error:
 71         if (sock) {
 72                 kernel_sock_shutdown(sock, SHUT_RDWR);
 73                 sock_release(sock);
 74         }
 75         *sockp = NULL;
 76         return err;
 77 }
 78 EXPORT_SYMBOL_GPL(udp_sock_create6);
 79 
 80 int udp_tunnel6_xmit_skb(struct dst_entry *dst, struct sock *sk,
 81                          struct sk_buff *skb,
 82                          struct net_device *dev, struct in6_addr *saddr,
 83                          struct in6_addr *daddr,
 84                          __u8 prio, __u8 ttl, __be32 label,
 85                          __be16 src_port, __be16 dst_port, bool nocheck)
 86 {
 87         struct udphdr *uh;
 88         struct ipv6hdr *ip6h;
 89 
 90         __skb_push(skb, sizeof(*uh));
 91         skb_reset_transport_header(skb);
 92         uh = udp_hdr(skb);
 93 
 94         uh->dest = dst_port;
 95         uh->source = src_port;
 96 
 97         uh->len = htons(skb->len);
 98 
 99         skb_dst_set(skb, dst);
100 
101         udp6_set_csum(nocheck, skb, saddr, daddr, skb->len);
102 
103         __skb_push(skb, sizeof(*ip6h));
104         skb_reset_network_header(skb);
105         ip6h              = ipv6_hdr(skb);
106         ip6_flow_hdr(ip6h, prio, label);
107         ip6h->payload_len = htons(skb->len);
108         ip6h->nexthdr     = IPPROTO_UDP;
109         ip6h->hop_limit   = ttl;
110         ip6h->daddr       = *daddr;
111         ip6h->saddr       = *saddr;
112 
113         ip6tunnel_xmit(sk, skb, dev);
114         return 0;
115 }
116 EXPORT_SYMBOL_GPL(udp_tunnel6_xmit_skb);
117 
118 MODULE_LICENSE("GPL");
119 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp