1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * IPv6 tunneling device
4 * Linux INET6 implementation
7 * Ville Nuorvala <vnuorval@tcs.hut.fi>
8 * Yasuyuki Kozakai <kozakai@linux-ipv6.org>
11 * linux/net/ipv6/sit.c and linux/net/ipv4/ipip.c
16 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
18 #include <linux/module.h>
19 #include <linux/capability.h>
20 #include <linux/errno.h>
21 #include <linux/types.h>
22 #include <linux/sockios.h>
23 #include <linux/icmp.h>
27 #include <linux/net.h>
28 #include <linux/in6.h>
29 #include <linux/netdevice.h>
30 #include <linux/if_arp.h>
31 #include <linux/icmpv6.h>
32 #include <linux/init.h>
33 #include <linux/route.h>
34 #include <linux/rtnetlink.h>
35 #include <linux/netfilter_ipv6.h>
36 #include <linux/slab.h>
37 #include <linux/hash.h>
38 #include <linux/etherdevice.h>
40 #include <linux/uaccess.h>
41 #include <linux/atomic.h>
45 #include <net/ip_tunnels.h>
47 #include <net/ip6_route.h>
48 #include <net/addrconf.h>
49 #include <net/ip6_tunnel.h>
51 #include <net/dsfield.h>
52 #include <net/inet_ecn.h>
53 #include <net/net_namespace.h>
54 #include <net/netns/generic.h>
55 #include <net/dst_metadata.h>
57 MODULE_AUTHOR("Ville Nuorvala");
58 MODULE_DESCRIPTION("IPv6 tunneling device");
59 MODULE_LICENSE("GPL");
60 MODULE_ALIAS_RTNL_LINK("ip6tnl");
61 MODULE_ALIAS_NETDEV("ip6tnl0");
63 #define IP6_TUNNEL_HASH_SIZE_SHIFT 5
64 #define IP6_TUNNEL_HASH_SIZE (1 << IP6_TUNNEL_HASH_SIZE_SHIFT)
66 static bool log_ecn_error = true;
67 module_param(log_ecn_error, bool, 0644);
68 MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
70 static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
72 u32 hash = ipv6_addr_hash(addr1) ^ ipv6_addr_hash(addr2);
74 return hash_32(hash, IP6_TUNNEL_HASH_SIZE_SHIFT);
77 static int ip6_tnl_dev_init(struct net_device *dev);
78 static void ip6_tnl_dev_setup(struct net_device *dev);
79 static struct rtnl_link_ops ip6_link_ops __read_mostly;
81 static unsigned int ip6_tnl_net_id __read_mostly;
83 /* the IPv6 tunnel fallback device */
84 struct net_device *fb_tnl_dev;
85 /* lists for storing tunnels in use */
86 struct ip6_tnl __rcu *tnls_r_l[IP6_TUNNEL_HASH_SIZE];
87 struct ip6_tnl __rcu *tnls_wc[1];
88 struct ip6_tnl __rcu **tnls[2];
89 struct ip6_tnl __rcu *collect_md_tun;
92 static struct net_device_stats *ip6_get_stats(struct net_device *dev)
94 struct pcpu_sw_netstats tmp, sum = { 0 };
97 for_each_possible_cpu(i) {
99 const struct pcpu_sw_netstats *tstats =
100 per_cpu_ptr(dev->tstats, i);
103 start = u64_stats_fetch_begin_irq(&tstats->syncp);
104 tmp.rx_packets = tstats->rx_packets;
105 tmp.rx_bytes = tstats->rx_bytes;
106 tmp.tx_packets = tstats->tx_packets;
107 tmp.tx_bytes = tstats->tx_bytes;
108 } while (u64_stats_fetch_retry_irq(&tstats->syncp, start));
110 sum.rx_packets += tmp.rx_packets;
111 sum.rx_bytes += tmp.rx_bytes;
112 sum.tx_packets += tmp.tx_packets;
113 sum.tx_bytes += tmp.tx_bytes;
115 dev->stats.rx_packets = sum.rx_packets;
116 dev->stats.rx_bytes = sum.rx_bytes;
117 dev->stats.tx_packets = sum.tx_packets;
118 dev->stats.tx_bytes = sum.tx_bytes;
123 * ip6_tnl_lookup - fetch tunnel matching the end-point addresses
124 * @link: ifindex of underlying interface
125 * @remote: the address of the tunnel exit-point
126 * @local: the address of the tunnel entry-point
129 * tunnel matching given end-points if found,
130 * else fallback tunnel if its device is up,
134 #define for_each_ip6_tunnel_rcu(start) \
135 for (t = rcu_dereference(start); t; t = rcu_dereference(t->next))
137 static struct ip6_tnl *
138 ip6_tnl_lookup(struct net *net, int link,
139 const struct in6_addr *remote, const struct in6_addr *local)
141 unsigned int hash = HASH(remote, local);
142 struct ip6_tnl *t, *cand = NULL;
143 struct ip6_tnl_net *ip6n = net_generic(net, ip6_tnl_net_id);
146 for_each_ip6_tunnel_rcu(ip6n->tnls_r_l[hash]) {
147 if (!ipv6_addr_equal(local, &t->parms.laddr) ||
148 !ipv6_addr_equal(remote, &t->parms.raddr) ||
149 !(t->dev->flags & IFF_UP))
152 if (link == t->parms.link)
158 memset(&any, 0, sizeof(any));
159 hash = HASH(&any, local);
160 for_each_ip6_tunnel_rcu(ip6n->tnls_r_l[hash]) {
161 if (!ipv6_addr_equal(local, &t->parms.laddr) ||
162 !ipv6_addr_any(&t->parms.raddr) ||
163 !(t->dev->flags & IFF_UP))
166 if (link == t->parms.link)
172 hash = HASH(remote, &any);
173 for_each_ip6_tunnel_rcu(ip6n->tnls_r_l[hash]) {
174 if (!ipv6_addr_equal(remote, &t->parms.raddr) ||
175 !ipv6_addr_any(&t->parms.laddr) ||
176 !(t->dev->flags & IFF_UP))
179 if (link == t->parms.link)
188 t = rcu_dereference(ip6n->collect_md_tun);
189 if (t && t->dev->flags & IFF_UP)
192 t = rcu_dereference(ip6n->tnls_wc[0]);
193 if (t && (t->dev->flags & IFF_UP))
200 * ip6_tnl_bucket - get head of list matching given tunnel parameters
201 * @p: parameters containing tunnel end-points
204 * ip6_tnl_bucket() returns the head of the list matching the
205 * &struct in6_addr entries laddr and raddr in @p.
207 * Return: head of IPv6 tunnel list
210 static struct ip6_tnl __rcu **
211 ip6_tnl_bucket(struct ip6_tnl_net *ip6n, const struct __ip6_tnl_parm *p)
213 const struct in6_addr *remote = &p->raddr;
214 const struct in6_addr *local = &p->laddr;
218 if (!ipv6_addr_any(remote) || !ipv6_addr_any(local)) {
220 h = HASH(remote, local);
222 return &ip6n->tnls[prio][h];
226 * ip6_tnl_link - add tunnel to hash table
227 * @t: tunnel to be added
231 ip6_tnl_link(struct ip6_tnl_net *ip6n, struct ip6_tnl *t)
233 struct ip6_tnl __rcu **tp = ip6_tnl_bucket(ip6n, &t->parms);
235 if (t->parms.collect_md)
236 rcu_assign_pointer(ip6n->collect_md_tun, t);
237 rcu_assign_pointer(t->next , rtnl_dereference(*tp));
238 rcu_assign_pointer(*tp, t);
242 * ip6_tnl_unlink - remove tunnel from hash table
243 * @t: tunnel to be removed
247 ip6_tnl_unlink(struct ip6_tnl_net *ip6n, struct ip6_tnl *t)
249 struct ip6_tnl __rcu **tp;
250 struct ip6_tnl *iter;
252 if (t->parms.collect_md)
253 rcu_assign_pointer(ip6n->collect_md_tun, NULL);
255 for (tp = ip6_tnl_bucket(ip6n, &t->parms);
256 (iter = rtnl_dereference(*tp)) != NULL;
259 rcu_assign_pointer(*tp, t->next);
265 static void ip6_dev_free(struct net_device *dev)
267 struct ip6_tnl *t = netdev_priv(dev);
269 gro_cells_destroy(&t->gro_cells);
270 dst_cache_destroy(&t->dst_cache);
271 free_percpu(dev->tstats);
274 static int ip6_tnl_create2(struct net_device *dev)
276 struct ip6_tnl *t = netdev_priv(dev);
277 struct net *net = dev_net(dev);
278 struct ip6_tnl_net *ip6n = net_generic(net, ip6_tnl_net_id);
281 t = netdev_priv(dev);
283 dev->rtnl_link_ops = &ip6_link_ops;
284 err = register_netdevice(dev);
288 strcpy(t->parms.name, dev->name);
291 ip6_tnl_link(ip6n, t);
299 * ip6_tnl_create - create a new tunnel
300 * @p: tunnel parameters
301 * @pt: pointer to new tunnel
304 * Create tunnel matching given parameters.
307 * created tunnel or error pointer
310 static struct ip6_tnl *ip6_tnl_create(struct net *net, struct __ip6_tnl_parm *p)
312 struct net_device *dev;
318 if (!dev_valid_name(p->name))
320 strlcpy(name, p->name, IFNAMSIZ);
322 sprintf(name, "ip6tnl%%d");
325 dev = alloc_netdev(sizeof(*t), name, NET_NAME_UNKNOWN,
330 dev_net_set(dev, net);
332 t = netdev_priv(dev);
334 t->net = dev_net(dev);
335 err = ip6_tnl_create2(dev);
348 * ip6_tnl_locate - find or create tunnel matching given parameters
349 * @p: tunnel parameters
350 * @create: != 0 if allowed to create new tunnel if no match found
353 * ip6_tnl_locate() first tries to locate an existing tunnel
354 * based on @parms. If this is unsuccessful, but @create is set a new
355 * tunnel device is created and registered for use.
358 * matching tunnel or error pointer
361 static struct ip6_tnl *ip6_tnl_locate(struct net *net,
362 struct __ip6_tnl_parm *p, int create)
364 const struct in6_addr *remote = &p->raddr;
365 const struct in6_addr *local = &p->laddr;
366 struct ip6_tnl __rcu **tp;
368 struct ip6_tnl_net *ip6n = net_generic(net, ip6_tnl_net_id);
370 for (tp = ip6_tnl_bucket(ip6n, p);
371 (t = rtnl_dereference(*tp)) != NULL;
373 if (ipv6_addr_equal(local, &t->parms.laddr) &&
374 ipv6_addr_equal(remote, &t->parms.raddr) &&
375 p->link == t->parms.link) {
377 return ERR_PTR(-EEXIST);
383 return ERR_PTR(-ENODEV);
384 return ip6_tnl_create(net, p);
388 * ip6_tnl_dev_uninit - tunnel device uninitializer
389 * @dev: the device to be destroyed
392 * ip6_tnl_dev_uninit() removes tunnel from its list
396 ip6_tnl_dev_uninit(struct net_device *dev)
398 struct ip6_tnl *t = netdev_priv(dev);
399 struct net *net = t->net;
400 struct ip6_tnl_net *ip6n = net_generic(net, ip6_tnl_net_id);
402 if (dev == ip6n->fb_tnl_dev)
403 RCU_INIT_POINTER(ip6n->tnls_wc[0], NULL);
405 ip6_tnl_unlink(ip6n, t);
406 dst_cache_reset(&t->dst_cache);
411 * parse_tvl_tnl_enc_lim - handle encapsulation limit option
412 * @skb: received socket buffer
415 * 0 if none was found,
416 * else index to encapsulation limit
419 __u16 ip6_tnl_parse_tlv_enc_lim(struct sk_buff *skb, __u8 *raw)
421 const struct ipv6hdr *ipv6h = (const struct ipv6hdr *)raw;
422 unsigned int nhoff = raw - skb->data;
423 unsigned int off = nhoff + sizeof(*ipv6h);
424 u8 next, nexthdr = ipv6h->nexthdr;
426 while (ipv6_ext_hdr(nexthdr) && nexthdr != NEXTHDR_NONE) {
427 struct ipv6_opt_hdr *hdr;
430 if (!pskb_may_pull(skb, off + sizeof(*hdr)))
433 hdr = (struct ipv6_opt_hdr *)(skb->data + off);
434 if (nexthdr == NEXTHDR_FRAGMENT) {
435 struct frag_hdr *frag_hdr = (struct frag_hdr *) hdr;
436 if (frag_hdr->frag_off)
439 } else if (nexthdr == NEXTHDR_AUTH) {
440 optlen = ipv6_authlen(hdr);
442 optlen = ipv6_optlen(hdr);
444 /* cache hdr->nexthdr, since pskb_may_pull() might
448 if (nexthdr == NEXTHDR_DEST) {
451 /* Remember : hdr is no longer valid at this point. */
452 if (!pskb_may_pull(skb, off + optlen))
456 struct ipv6_tlv_tnl_enc_lim *tel;
458 /* No more room for encapsulation limit */
459 if (i + sizeof(*tel) > optlen)
462 tel = (struct ipv6_tlv_tnl_enc_lim *)(skb->data + off + i);
463 /* return index of option if found and valid */
464 if (tel->type == IPV6_TLV_TNL_ENCAP_LIMIT &&
466 return i + off - nhoff;
467 /* else jump to next option */
469 i += tel->length + 2;
479 EXPORT_SYMBOL(ip6_tnl_parse_tlv_enc_lim);
482 * ip6_tnl_err - tunnel error handler
485 * ip6_tnl_err() should handle errors in the tunnel according
486 * to the specifications in RFC 2473.
490 ip6_tnl_err(struct sk_buff *skb, __u8 ipproto, struct inet6_skb_parm *opt,
491 u8 *type, u8 *code, int *msg, __u32 *info, int offset)
493 const struct ipv6hdr *ipv6h = (const struct ipv6hdr *)skb->data;
494 struct net *net = dev_net(skb->dev);
495 u8 rel_type = ICMPV6_DEST_UNREACH;
496 u8 rel_code = ICMPV6_ADDR_UNREACH;
504 /* If the packet doesn't contain the original IPv6 header we are
505 in trouble since we might need the source address for further
506 processing of the error. */
509 t = ip6_tnl_lookup(dev_net(skb->dev), skb->dev->ifindex, &ipv6h->daddr, &ipv6h->saddr);
513 tproto = READ_ONCE(t->parms.proto);
514 if (tproto != ipproto && tproto != 0)
520 struct ipv6_tlv_tnl_enc_lim *tel;
522 case ICMPV6_DEST_UNREACH:
523 net_dbg_ratelimited("%s: Path to destination invalid or inactive!\n",
527 case ICMPV6_TIME_EXCEED:
528 if ((*code) == ICMPV6_EXC_HOPLIMIT) {
529 net_dbg_ratelimited("%s: Too small hop limit or routing loop in tunnel!\n",
534 case ICMPV6_PARAMPROB:
536 if ((*code) == ICMPV6_HDR_FIELD)
537 teli = ip6_tnl_parse_tlv_enc_lim(skb, skb->data);
539 if (teli && teli == *info - 2) {
540 tel = (struct ipv6_tlv_tnl_enc_lim *) &skb->data[teli];
541 if (tel->encap_limit == 0) {
542 net_dbg_ratelimited("%s: Too small encapsulation limit or routing loop in tunnel!\n",
547 net_dbg_ratelimited("%s: Recipient unable to parse tunneled packet!\n",
551 case ICMPV6_PKT_TOOBIG:
552 ip6_update_pmtu(skb, net, htonl(*info), 0, 0,
553 sock_net_uid(net, NULL));
554 mtu = *info - offset;
555 if (mtu < IPV6_MIN_MTU)
557 len = sizeof(*ipv6h) + ntohs(ipv6h->payload_len);
559 rel_type = ICMPV6_PKT_TOOBIG;
566 ip6_redirect(skb, net, skb->dev->ifindex, 0,
567 sock_net_uid(net, NULL));
582 ip4ip6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
583 u8 type, u8 code, int offset, __be32 info)
585 __u32 rel_info = ntohl(info);
586 const struct iphdr *eiph;
587 struct sk_buff *skb2;
588 int err, rel_msg = 0;
594 err = ip6_tnl_err(skb, IPPROTO_IPIP, opt, &rel_type, &rel_code,
595 &rel_msg, &rel_info, offset);
603 case ICMPV6_DEST_UNREACH:
604 if (rel_code != ICMPV6_ADDR_UNREACH)
606 rel_type = ICMP_DEST_UNREACH;
607 rel_code = ICMP_HOST_UNREACH;
609 case ICMPV6_PKT_TOOBIG:
612 rel_type = ICMP_DEST_UNREACH;
613 rel_code = ICMP_FRAG_NEEDED;
619 if (!pskb_may_pull(skb, offset + sizeof(struct iphdr)))
622 skb2 = skb_clone(skb, GFP_ATOMIC);
628 skb_pull(skb2, offset);
629 skb_reset_network_header(skb2);
632 /* Try to guess incoming interface */
633 rt = ip_route_output_ports(dev_net(skb->dev), &fl4, NULL, eiph->saddr,
634 0, 0, 0, IPPROTO_IPIP, RT_TOS(eiph->tos), 0);
638 skb2->dev = rt->dst.dev;
641 /* route "incoming" packet */
642 if (rt->rt_flags & RTCF_LOCAL) {
643 rt = ip_route_output_ports(dev_net(skb->dev), &fl4, NULL,
644 eiph->daddr, eiph->saddr, 0, 0,
645 IPPROTO_IPIP, RT_TOS(eiph->tos), 0);
646 if (IS_ERR(rt) || rt->dst.dev->type != ARPHRD_TUNNEL6) {
651 skb_dst_set(skb2, &rt->dst);
653 if (ip_route_input(skb2, eiph->daddr, eiph->saddr, eiph->tos,
655 skb_dst(skb2)->dev->type != ARPHRD_TUNNEL6)
659 /* change mtu on this route */
660 if (rel_type == ICMP_DEST_UNREACH && rel_code == ICMP_FRAG_NEEDED) {
661 if (rel_info > dst_mtu(skb_dst(skb2)))
664 skb_dst_update_pmtu_no_confirm(skb2, rel_info);
667 icmp_send(skb2, rel_type, rel_code, htonl(rel_info));
675 ip6ip6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
676 u8 type, u8 code, int offset, __be32 info)
678 __u32 rel_info = ntohl(info);
679 int err, rel_msg = 0;
683 err = ip6_tnl_err(skb, IPPROTO_IPV6, opt, &rel_type, &rel_code,
684 &rel_msg, &rel_info, offset);
688 if (rel_msg && pskb_may_pull(skb, offset + sizeof(struct ipv6hdr))) {
690 struct sk_buff *skb2 = skb_clone(skb, GFP_ATOMIC);
696 skb_pull(skb2, offset);
697 skb_reset_network_header(skb2);
699 /* Try to guess incoming interface */
700 rt = rt6_lookup(dev_net(skb->dev), &ipv6_hdr(skb2)->saddr,
703 if (rt && rt->dst.dev)
704 skb2->dev = rt->dst.dev;
706 icmpv6_send(skb2, rel_type, rel_code, rel_info);
716 static int ip4ip6_dscp_ecn_decapsulate(const struct ip6_tnl *t,
717 const struct ipv6hdr *ipv6h,
720 __u8 dsfield = ipv6_get_dsfield(ipv6h) & ~INET_ECN_MASK;
722 if (t->parms.flags & IP6_TNL_F_RCV_DSCP_COPY)
723 ipv4_change_dsfield(ip_hdr(skb), INET_ECN_MASK, dsfield);
725 return IP6_ECN_decapsulate(ipv6h, skb);
728 static int ip6ip6_dscp_ecn_decapsulate(const struct ip6_tnl *t,
729 const struct ipv6hdr *ipv6h,
732 if (t->parms.flags & IP6_TNL_F_RCV_DSCP_COPY)
733 ipv6_copy_dscp(ipv6_get_dsfield(ipv6h), ipv6_hdr(skb));
735 return IP6_ECN_decapsulate(ipv6h, skb);
738 __u32 ip6_tnl_get_cap(struct ip6_tnl *t,
739 const struct in6_addr *laddr,
740 const struct in6_addr *raddr)
742 struct __ip6_tnl_parm *p = &t->parms;
743 int ltype = ipv6_addr_type(laddr);
744 int rtype = ipv6_addr_type(raddr);
747 if (ltype == IPV6_ADDR_ANY || rtype == IPV6_ADDR_ANY) {
748 flags = IP6_TNL_F_CAP_PER_PACKET;
749 } else if (ltype & (IPV6_ADDR_UNICAST|IPV6_ADDR_MULTICAST) &&
750 rtype & (IPV6_ADDR_UNICAST|IPV6_ADDR_MULTICAST) &&
751 !((ltype|rtype) & IPV6_ADDR_LOOPBACK) &&
752 (!((ltype|rtype) & IPV6_ADDR_LINKLOCAL) || p->link)) {
753 if (ltype&IPV6_ADDR_UNICAST)
754 flags |= IP6_TNL_F_CAP_XMIT;
755 if (rtype&IPV6_ADDR_UNICAST)
756 flags |= IP6_TNL_F_CAP_RCV;
760 EXPORT_SYMBOL(ip6_tnl_get_cap);
762 /* called with rcu_read_lock() */
763 int ip6_tnl_rcv_ctl(struct ip6_tnl *t,
764 const struct in6_addr *laddr,
765 const struct in6_addr *raddr)
767 struct __ip6_tnl_parm *p = &t->parms;
769 struct net *net = t->net;
771 if ((p->flags & IP6_TNL_F_CAP_RCV) ||
772 ((p->flags & IP6_TNL_F_CAP_PER_PACKET) &&
773 (ip6_tnl_get_cap(t, laddr, raddr) & IP6_TNL_F_CAP_RCV))) {
774 struct net_device *ldev = NULL;
777 ldev = dev_get_by_index_rcu(net, p->link);
779 if ((ipv6_addr_is_multicast(laddr) ||
780 likely(ipv6_chk_addr_and_flags(net, laddr, ldev, false,
781 0, IFA_F_TENTATIVE))) &&
782 ((p->flags & IP6_TNL_F_ALLOW_LOCAL_REMOTE) ||
783 likely(!ipv6_chk_addr_and_flags(net, raddr, ldev, true,
784 0, IFA_F_TENTATIVE))))
789 EXPORT_SYMBOL_GPL(ip6_tnl_rcv_ctl);
791 static int __ip6_tnl_rcv(struct ip6_tnl *tunnel, struct sk_buff *skb,
792 const struct tnl_ptk_info *tpi,
793 struct metadata_dst *tun_dst,
794 int (*dscp_ecn_decapsulate)(const struct ip6_tnl *t,
795 const struct ipv6hdr *ipv6h,
796 struct sk_buff *skb),
799 struct pcpu_sw_netstats *tstats;
800 const struct ipv6hdr *ipv6h = ipv6_hdr(skb);
803 if ((!(tpi->flags & TUNNEL_CSUM) &&
804 (tunnel->parms.i_flags & TUNNEL_CSUM)) ||
805 ((tpi->flags & TUNNEL_CSUM) &&
806 !(tunnel->parms.i_flags & TUNNEL_CSUM))) {
807 tunnel->dev->stats.rx_crc_errors++;
808 tunnel->dev->stats.rx_errors++;
812 if (tunnel->parms.i_flags & TUNNEL_SEQ) {
813 if (!(tpi->flags & TUNNEL_SEQ) ||
815 (s32)(ntohl(tpi->seq) - tunnel->i_seqno) < 0)) {
816 tunnel->dev->stats.rx_fifo_errors++;
817 tunnel->dev->stats.rx_errors++;
820 tunnel->i_seqno = ntohl(tpi->seq) + 1;
823 skb->protocol = tpi->proto;
825 /* Warning: All skb pointers will be invalidated! */
826 if (tunnel->dev->type == ARPHRD_ETHER) {
827 if (!pskb_may_pull(skb, ETH_HLEN)) {
828 tunnel->dev->stats.rx_length_errors++;
829 tunnel->dev->stats.rx_errors++;
833 ipv6h = ipv6_hdr(skb);
834 skb->protocol = eth_type_trans(skb, tunnel->dev);
835 skb_postpull_rcsum(skb, eth_hdr(skb), ETH_HLEN);
837 skb->dev = tunnel->dev;
840 skb_reset_network_header(skb);
841 memset(skb->cb, 0, sizeof(struct inet6_skb_parm));
843 __skb_tunnel_rx(skb, tunnel->dev, tunnel->net);
845 err = dscp_ecn_decapsulate(tunnel, ipv6h, skb);
848 net_info_ratelimited("non-ECT from %pI6 with DS=%#x\n",
850 ipv6_get_dsfield(ipv6h));
852 ++tunnel->dev->stats.rx_frame_errors;
853 ++tunnel->dev->stats.rx_errors;
858 tstats = this_cpu_ptr(tunnel->dev->tstats);
859 u64_stats_update_begin(&tstats->syncp);
860 tstats->rx_packets++;
861 tstats->rx_bytes += skb->len;
862 u64_stats_update_end(&tstats->syncp);
864 skb_scrub_packet(skb, !net_eq(tunnel->net, dev_net(tunnel->dev)));
867 skb_dst_set(skb, (struct dst_entry *)tun_dst);
869 gro_cells_receive(&tunnel->gro_cells, skb);
874 dst_release((struct dst_entry *)tun_dst);
879 int ip6_tnl_rcv(struct ip6_tnl *t, struct sk_buff *skb,
880 const struct tnl_ptk_info *tpi,
881 struct metadata_dst *tun_dst,
884 return __ip6_tnl_rcv(t, skb, tpi, tun_dst, ip6ip6_dscp_ecn_decapsulate,
887 EXPORT_SYMBOL(ip6_tnl_rcv);
889 static const struct tnl_ptk_info tpi_v6 = {
890 /* no tunnel info required for ipxip6. */
891 .proto = htons(ETH_P_IPV6),
894 static const struct tnl_ptk_info tpi_v4 = {
895 /* no tunnel info required for ipxip6. */
896 .proto = htons(ETH_P_IP),
899 static int ipxip6_rcv(struct sk_buff *skb, u8 ipproto,
900 const struct tnl_ptk_info *tpi,
901 int (*dscp_ecn_decapsulate)(const struct ip6_tnl *t,
902 const struct ipv6hdr *ipv6h,
903 struct sk_buff *skb))
906 const struct ipv6hdr *ipv6h = ipv6_hdr(skb);
907 struct metadata_dst *tun_dst = NULL;
911 t = ip6_tnl_lookup(dev_net(skb->dev), skb->dev->ifindex, &ipv6h->saddr, &ipv6h->daddr);
914 u8 tproto = READ_ONCE(t->parms.proto);
916 if (tproto != ipproto && tproto != 0)
918 if (!xfrm6_policy_check(NULL, XFRM_POLICY_IN, skb))
920 ipv6h = ipv6_hdr(skb);
921 if (!ip6_tnl_rcv_ctl(t, &ipv6h->daddr, &ipv6h->saddr))
923 if (iptunnel_pull_header(skb, 0, tpi->proto, false))
925 if (t->parms.collect_md) {
926 tun_dst = ipv6_tun_rx_dst(skb, 0, 0, 0);
930 ret = __ip6_tnl_rcv(t, skb, tpi, tun_dst, dscp_ecn_decapsulate,
944 static int ip4ip6_rcv(struct sk_buff *skb)
946 return ipxip6_rcv(skb, IPPROTO_IPIP, &tpi_v4,
947 ip4ip6_dscp_ecn_decapsulate);
950 static int ip6ip6_rcv(struct sk_buff *skb)
952 return ipxip6_rcv(skb, IPPROTO_IPV6, &tpi_v6,
953 ip6ip6_dscp_ecn_decapsulate);
956 struct ipv6_tel_txoption {
957 struct ipv6_txoptions ops;
961 static void init_tel_txopt(struct ipv6_tel_txoption *opt, __u8 encap_limit)
963 memset(opt, 0, sizeof(struct ipv6_tel_txoption));
965 opt->dst_opt[2] = IPV6_TLV_TNL_ENCAP_LIMIT;
967 opt->dst_opt[4] = encap_limit;
968 opt->dst_opt[5] = IPV6_TLV_PADN;
971 opt->ops.dst1opt = (struct ipv6_opt_hdr *) opt->dst_opt;
972 opt->ops.opt_nflen = 8;
976 * ip6_tnl_addr_conflict - compare packet addresses to tunnel's own
977 * @t: the outgoing tunnel device
978 * @hdr: IPv6 header from the incoming packet
981 * Avoid trivial tunneling loop by checking that tunnel exit-point
982 * doesn't match source of incoming packet.
990 ip6_tnl_addr_conflict(const struct ip6_tnl *t, const struct ipv6hdr *hdr)
992 return ipv6_addr_equal(&t->parms.raddr, &hdr->saddr);
995 int ip6_tnl_xmit_ctl(struct ip6_tnl *t,
996 const struct in6_addr *laddr,
997 const struct in6_addr *raddr)
999 struct __ip6_tnl_parm *p = &t->parms;
1001 struct net *net = t->net;
1003 if (t->parms.collect_md)
1006 if ((p->flags & IP6_TNL_F_CAP_XMIT) ||
1007 ((p->flags & IP6_TNL_F_CAP_PER_PACKET) &&
1008 (ip6_tnl_get_cap(t, laddr, raddr) & IP6_TNL_F_CAP_XMIT))) {
1009 struct net_device *ldev = NULL;
1013 ldev = dev_get_by_index_rcu(net, p->link);
1015 if (unlikely(!ipv6_chk_addr_and_flags(net, laddr, ldev, false,
1016 0, IFA_F_TENTATIVE)))
1017 pr_warn("%s xmit: Local address not yet configured!\n",
1019 else if (!(p->flags & IP6_TNL_F_ALLOW_LOCAL_REMOTE) &&
1020 !ipv6_addr_is_multicast(raddr) &&
1021 unlikely(ipv6_chk_addr_and_flags(net, raddr, ldev,
1022 true, 0, IFA_F_TENTATIVE)))
1023 pr_warn("%s xmit: Routing loop! Remote address found on this node!\n",
1031 EXPORT_SYMBOL_GPL(ip6_tnl_xmit_ctl);
1034 * ip6_tnl_xmit - encapsulate packet and send
1035 * @skb: the outgoing socket buffer
1036 * @dev: the outgoing tunnel device
1037 * @dsfield: dscp code for outer header
1038 * @fl6: flow of tunneled packet
1039 * @encap_limit: encapsulation limit
1040 * @pmtu: Path MTU is stored if packet is too big
1041 * @proto: next header value
1044 * Build new header and do some sanity checks on the packet before sending
1050 * %-EMSGSIZE message too big. return mtu in this case.
1053 int ip6_tnl_xmit(struct sk_buff *skb, struct net_device *dev, __u8 dsfield,
1054 struct flowi6 *fl6, int encap_limit, __u32 *pmtu,
1057 struct ip6_tnl *t = netdev_priv(dev);
1058 struct net *net = t->net;
1059 struct net_device_stats *stats = &t->dev->stats;
1060 struct ipv6hdr *ipv6h;
1061 struct ipv6_tel_txoption opt;
1062 struct dst_entry *dst = NULL, *ndst = NULL;
1063 struct net_device *tdev;
1065 unsigned int eth_hlen = t->dev->type == ARPHRD_ETHER ? ETH_HLEN : 0;
1066 unsigned int psh_hlen = sizeof(struct ipv6hdr) + t->encap_hlen;
1067 unsigned int max_headroom = psh_hlen;
1068 bool use_cache = false;
1072 if (t->parms.collect_md) {
1073 hop_limit = skb_tunnel_info(skb)->key.ttl;
1076 hop_limit = t->parms.hop_limit;
1080 if (ipv6_addr_any(&t->parms.raddr)) {
1081 if (skb->protocol == htons(ETH_P_IPV6)) {
1082 struct in6_addr *addr6;
1083 struct neighbour *neigh;
1087 goto tx_err_link_failure;
1089 neigh = dst_neigh_lookup(skb_dst(skb),
1090 &ipv6_hdr(skb)->daddr);
1092 goto tx_err_link_failure;
1094 addr6 = (struct in6_addr *)&neigh->primary_key;
1095 addr_type = ipv6_addr_type(addr6);
1097 if (addr_type == IPV6_ADDR_ANY)
1098 addr6 = &ipv6_hdr(skb)->daddr;
1100 memcpy(&fl6->daddr, addr6, sizeof(fl6->daddr));
1101 neigh_release(neigh);
1103 } else if (t->parms.proto != 0 && !(t->parms.flags &
1104 (IP6_TNL_F_USE_ORIG_TCLASS |
1105 IP6_TNL_F_USE_ORIG_FWMARK))) {
1106 /* enable the cache only if neither the outer protocol nor the
1107 * routing decision depends on the current inner header value
1113 dst = dst_cache_get(&t->dst_cache);
1115 if (!ip6_tnl_xmit_ctl(t, &fl6->saddr, &fl6->daddr))
1116 goto tx_err_link_failure;
1120 /* add dsfield to flowlabel for route lookup */
1121 fl6->flowlabel = ip6_make_flowinfo(dsfield, fl6->flowlabel);
1123 dst = ip6_route_output(net, NULL, fl6);
1126 goto tx_err_link_failure;
1127 dst = xfrm_lookup(net, dst, flowi6_to_flowi(fl6), NULL, 0);
1131 goto tx_err_link_failure;
1133 if (t->parms.collect_md && ipv6_addr_any(&fl6->saddr) &&
1134 ipv6_dev_get_saddr(net, ip6_dst_idev(dst)->dev,
1135 &fl6->daddr, 0, &fl6->saddr))
1136 goto tx_err_link_failure;
1143 stats->collisions++;
1144 net_warn_ratelimited("%s: Local routing loop detected!\n",
1146 goto tx_err_dst_release;
1148 mtu = dst_mtu(dst) - eth_hlen - psh_hlen - t->tun_hlen;
1149 if (encap_limit >= 0) {
1153 mtu = max(mtu, skb->protocol == htons(ETH_P_IPV6) ?
1154 IPV6_MIN_MTU : IPV4_MIN_MTU);
1156 skb_dst_update_pmtu_no_confirm(skb, mtu);
1157 if (skb->len - t->tun_hlen - eth_hlen > mtu && !skb_is_gso(skb)) {
1160 goto tx_err_dst_release;
1163 if (t->err_count > 0) {
1164 if (time_before(jiffies,
1165 t->err_time + IP6TUNNEL_ERR_TIMEO)) {
1168 dst_link_failure(skb);
1174 skb_scrub_packet(skb, !net_eq(t->net, dev_net(dev)));
1177 * Okay, now see if we can stuff it in the buffer as-is.
1179 max_headroom += LL_RESERVED_SPACE(tdev);
1181 if (skb_headroom(skb) < max_headroom || skb_shared(skb) ||
1182 (skb_cloned(skb) && !skb_clone_writable(skb, 0))) {
1183 struct sk_buff *new_skb;
1185 new_skb = skb_realloc_headroom(skb, max_headroom);
1187 goto tx_err_dst_release;
1190 skb_set_owner_w(new_skb, skb->sk);
1195 if (t->parms.collect_md) {
1196 if (t->encap.type != TUNNEL_ENCAP_NONE)
1197 goto tx_err_dst_release;
1199 if (use_cache && ndst)
1200 dst_cache_set_ip6(&t->dst_cache, ndst, &fl6->saddr);
1202 skb_dst_set(skb, dst);
1204 if (hop_limit == 0) {
1205 if (skb->protocol == htons(ETH_P_IP))
1206 hop_limit = ip_hdr(skb)->ttl;
1207 else if (skb->protocol == htons(ETH_P_IPV6))
1208 hop_limit = ipv6_hdr(skb)->hop_limit;
1210 hop_limit = ip6_dst_hoplimit(dst);
1213 /* Calculate max headroom for all the headers and adjust
1214 * needed_headroom if necessary.
1216 max_headroom = LL_RESERVED_SPACE(dst->dev) + sizeof(struct ipv6hdr)
1217 + dst->header_len + t->hlen;
1218 if (max_headroom > dev->needed_headroom)
1219 dev->needed_headroom = max_headroom;
1221 err = ip6_tnl_encap(skb, t, &proto, fl6);
1225 if (encap_limit >= 0) {
1226 init_tel_txopt(&opt, encap_limit);
1227 ipv6_push_frag_opts(skb, &opt.ops, &proto);
1230 skb_push(skb, sizeof(struct ipv6hdr));
1231 skb_reset_network_header(skb);
1232 ipv6h = ipv6_hdr(skb);
1233 ip6_flow_hdr(ipv6h, dsfield,
1234 ip6_make_flowlabel(net, skb, fl6->flowlabel, true, fl6));
1235 ipv6h->hop_limit = hop_limit;
1236 ipv6h->nexthdr = proto;
1237 ipv6h->saddr = fl6->saddr;
1238 ipv6h->daddr = fl6->daddr;
1239 ip6tunnel_xmit(NULL, skb, dev);
1241 tx_err_link_failure:
1242 stats->tx_carrier_errors++;
1243 dst_link_failure(skb);
1248 EXPORT_SYMBOL(ip6_tnl_xmit);
1251 ip4ip6_tnl_xmit(struct sk_buff *skb, struct net_device *dev)
1253 struct ip6_tnl *t = netdev_priv(dev);
1254 const struct iphdr *iph;
1255 int encap_limit = -1;
1263 memset(&(IPCB(skb)->opt), 0, sizeof(IPCB(skb)->opt));
1265 tproto = READ_ONCE(t->parms.proto);
1266 if (tproto != IPPROTO_IPIP && tproto != 0)
1269 if (t->parms.collect_md) {
1270 struct ip_tunnel_info *tun_info;
1271 const struct ip_tunnel_key *key;
1273 tun_info = skb_tunnel_info(skb);
1274 if (unlikely(!tun_info || !(tun_info->mode & IP_TUNNEL_INFO_TX) ||
1275 ip_tunnel_info_af(tun_info) != AF_INET6))
1277 key = &tun_info->key;
1278 memset(&fl6, 0, sizeof(fl6));
1279 fl6.flowi6_proto = IPPROTO_IPIP;
1280 fl6.saddr = key->u.ipv6.src;
1281 fl6.daddr = key->u.ipv6.dst;
1282 fl6.flowlabel = key->label;
1285 if (!(t->parms.flags & IP6_TNL_F_IGN_ENCAP_LIMIT))
1286 encap_limit = t->parms.encap_limit;
1288 memcpy(&fl6, &t->fl.u.ip6, sizeof(fl6));
1289 fl6.flowi6_proto = IPPROTO_IPIP;
1291 if (t->parms.flags & IP6_TNL_F_USE_ORIG_TCLASS)
1292 dsfield = ipv4_get_dsfield(iph);
1294 dsfield = ip6_tclass(t->parms.flowinfo);
1295 if (t->parms.flags & IP6_TNL_F_USE_ORIG_FWMARK)
1296 fl6.flowi6_mark = skb->mark;
1298 fl6.flowi6_mark = t->parms.fwmark;
1301 fl6.flowi6_uid = sock_net_uid(dev_net(dev), NULL);
1302 dsfield = INET_ECN_encapsulate(dsfield, ipv4_get_dsfield(iph));
1304 if (iptunnel_handle_offloads(skb, SKB_GSO_IPXIP6))
1307 skb_set_inner_ipproto(skb, IPPROTO_IPIP);
1309 err = ip6_tnl_xmit(skb, dev, dsfield, &fl6, encap_limit, &mtu,
1312 /* XXX: send ICMP error even if DF is not set. */
1313 if (err == -EMSGSIZE)
1314 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_FRAG_NEEDED,
1323 ip6ip6_tnl_xmit(struct sk_buff *skb, struct net_device *dev)
1325 struct ip6_tnl *t = netdev_priv(dev);
1326 struct ipv6hdr *ipv6h;
1327 int encap_limit = -1;
1335 ipv6h = ipv6_hdr(skb);
1336 tproto = READ_ONCE(t->parms.proto);
1337 if ((tproto != IPPROTO_IPV6 && tproto != 0) ||
1338 ip6_tnl_addr_conflict(t, ipv6h))
1341 if (t->parms.collect_md) {
1342 struct ip_tunnel_info *tun_info;
1343 const struct ip_tunnel_key *key;
1345 tun_info = skb_tunnel_info(skb);
1346 if (unlikely(!tun_info || !(tun_info->mode & IP_TUNNEL_INFO_TX) ||
1347 ip_tunnel_info_af(tun_info) != AF_INET6))
1349 key = &tun_info->key;
1350 memset(&fl6, 0, sizeof(fl6));
1351 fl6.flowi6_proto = IPPROTO_IPV6;
1352 fl6.saddr = key->u.ipv6.src;
1353 fl6.daddr = key->u.ipv6.dst;
1354 fl6.flowlabel = key->label;
1357 offset = ip6_tnl_parse_tlv_enc_lim(skb, skb_network_header(skb));
1358 /* ip6_tnl_parse_tlv_enc_lim() might have reallocated skb->head */
1359 ipv6h = ipv6_hdr(skb);
1361 struct ipv6_tlv_tnl_enc_lim *tel;
1363 tel = (void *)&skb_network_header(skb)[offset];
1364 if (tel->encap_limit == 0) {
1365 icmpv6_send(skb, ICMPV6_PARAMPROB,
1366 ICMPV6_HDR_FIELD, offset + 2);
1369 encap_limit = tel->encap_limit - 1;
1370 } else if (!(t->parms.flags & IP6_TNL_F_IGN_ENCAP_LIMIT)) {
1371 encap_limit = t->parms.encap_limit;
1374 memcpy(&fl6, &t->fl.u.ip6, sizeof(fl6));
1375 fl6.flowi6_proto = IPPROTO_IPV6;
1377 if (t->parms.flags & IP6_TNL_F_USE_ORIG_TCLASS)
1378 dsfield = ipv6_get_dsfield(ipv6h);
1380 dsfield = ip6_tclass(t->parms.flowinfo);
1381 if (t->parms.flags & IP6_TNL_F_USE_ORIG_FLOWLABEL)
1382 fl6.flowlabel |= ip6_flowlabel(ipv6h);
1383 if (t->parms.flags & IP6_TNL_F_USE_ORIG_FWMARK)
1384 fl6.flowi6_mark = skb->mark;
1386 fl6.flowi6_mark = t->parms.fwmark;
1389 fl6.flowi6_uid = sock_net_uid(dev_net(dev), NULL);
1390 dsfield = INET_ECN_encapsulate(dsfield, ipv6_get_dsfield(ipv6h));
1392 if (iptunnel_handle_offloads(skb, SKB_GSO_IPXIP6))
1395 skb_set_inner_ipproto(skb, IPPROTO_IPV6);
1397 err = ip6_tnl_xmit(skb, dev, dsfield, &fl6, encap_limit, &mtu,
1400 if (err == -EMSGSIZE)
1401 icmpv6_send(skb, ICMPV6_PKT_TOOBIG, 0, mtu);
1409 ip6_tnl_start_xmit(struct sk_buff *skb, struct net_device *dev)
1411 struct ip6_tnl *t = netdev_priv(dev);
1412 struct net_device_stats *stats = &t->dev->stats;
1415 if (!pskb_inet_may_pull(skb))
1418 switch (skb->protocol) {
1419 case htons(ETH_P_IP):
1420 ret = ip4ip6_tnl_xmit(skb, dev);
1422 case htons(ETH_P_IPV6):
1423 ret = ip6ip6_tnl_xmit(skb, dev);
1432 return NETDEV_TX_OK;
1436 stats->tx_dropped++;
1438 return NETDEV_TX_OK;
1441 static void ip6_tnl_link_config(struct ip6_tnl *t)
1443 struct net_device *dev = t->dev;
1444 struct net_device *tdev = NULL;
1445 struct __ip6_tnl_parm *p = &t->parms;
1446 struct flowi6 *fl6 = &t->fl.u.ip6;
1450 memcpy(dev->dev_addr, &p->laddr, sizeof(struct in6_addr));
1451 memcpy(dev->broadcast, &p->raddr, sizeof(struct in6_addr));
1453 /* Set up flowi template */
1454 fl6->saddr = p->laddr;
1455 fl6->daddr = p->raddr;
1456 fl6->flowi6_oif = p->link;
1459 if (!(p->flags&IP6_TNL_F_USE_ORIG_TCLASS))
1460 fl6->flowlabel |= IPV6_TCLASS_MASK & p->flowinfo;
1461 if (!(p->flags&IP6_TNL_F_USE_ORIG_FLOWLABEL))
1462 fl6->flowlabel |= IPV6_FLOWLABEL_MASK & p->flowinfo;
1464 p->flags &= ~(IP6_TNL_F_CAP_XMIT|IP6_TNL_F_CAP_RCV|IP6_TNL_F_CAP_PER_PACKET);
1465 p->flags |= ip6_tnl_get_cap(t, &p->laddr, &p->raddr);
1467 if (p->flags&IP6_TNL_F_CAP_XMIT && p->flags&IP6_TNL_F_CAP_RCV)
1468 dev->flags |= IFF_POINTOPOINT;
1470 dev->flags &= ~IFF_POINTOPOINT;
1473 t->hlen = t->encap_hlen + t->tun_hlen;
1474 t_hlen = t->hlen + sizeof(struct ipv6hdr);
1476 if (p->flags & IP6_TNL_F_CAP_XMIT) {
1477 int strict = (ipv6_addr_type(&p->raddr) &
1478 (IPV6_ADDR_MULTICAST|IPV6_ADDR_LINKLOCAL));
1480 struct rt6_info *rt = rt6_lookup(t->net,
1481 &p->raddr, &p->laddr,
1482 p->link, NULL, strict);
1488 if (!tdev && p->link)
1489 tdev = __dev_get_by_index(t->net, p->link);
1492 dev->hard_header_len = tdev->hard_header_len + t_hlen;
1493 mtu = min_t(unsigned int, tdev->mtu, IP6_MAX_MTU);
1495 dev->mtu = mtu - t_hlen;
1496 if (!(t->parms.flags & IP6_TNL_F_IGN_ENCAP_LIMIT))
1499 if (dev->mtu < IPV6_MIN_MTU)
1500 dev->mtu = IPV6_MIN_MTU;
1506 * ip6_tnl_change - update the tunnel parameters
1507 * @t: tunnel to be changed
1508 * @p: tunnel configuration parameters
1511 * ip6_tnl_change() updates the tunnel parameters
1515 ip6_tnl_change(struct ip6_tnl *t, const struct __ip6_tnl_parm *p)
1517 t->parms.laddr = p->laddr;
1518 t->parms.raddr = p->raddr;
1519 t->parms.flags = p->flags;
1520 t->parms.hop_limit = p->hop_limit;
1521 t->parms.encap_limit = p->encap_limit;
1522 t->parms.flowinfo = p->flowinfo;
1523 t->parms.link = p->link;
1524 t->parms.proto = p->proto;
1525 t->parms.fwmark = p->fwmark;
1526 dst_cache_reset(&t->dst_cache);
1527 ip6_tnl_link_config(t);
1531 static int ip6_tnl_update(struct ip6_tnl *t, struct __ip6_tnl_parm *p)
1533 struct net *net = t->net;
1534 struct ip6_tnl_net *ip6n = net_generic(net, ip6_tnl_net_id);
1537 ip6_tnl_unlink(ip6n, t);
1539 err = ip6_tnl_change(t, p);
1540 ip6_tnl_link(ip6n, t);
1541 netdev_state_change(t->dev);
1545 static int ip6_tnl0_update(struct ip6_tnl *t, struct __ip6_tnl_parm *p)
1547 /* for default tnl0 device allow to change only the proto */
1548 t->parms.proto = p->proto;
1549 netdev_state_change(t->dev);
1554 ip6_tnl_parm_from_user(struct __ip6_tnl_parm *p, const struct ip6_tnl_parm *u)
1556 p->laddr = u->laddr;
1557 p->raddr = u->raddr;
1558 p->flags = u->flags;
1559 p->hop_limit = u->hop_limit;
1560 p->encap_limit = u->encap_limit;
1561 p->flowinfo = u->flowinfo;
1563 p->proto = u->proto;
1564 memcpy(p->name, u->name, sizeof(u->name));
1568 ip6_tnl_parm_to_user(struct ip6_tnl_parm *u, const struct __ip6_tnl_parm *p)
1570 u->laddr = p->laddr;
1571 u->raddr = p->raddr;
1572 u->flags = p->flags;
1573 u->hop_limit = p->hop_limit;
1574 u->encap_limit = p->encap_limit;
1575 u->flowinfo = p->flowinfo;
1577 u->proto = p->proto;
1578 memcpy(u->name, p->name, sizeof(u->name));
1582 * ip6_tnl_ioctl - configure ipv6 tunnels from userspace
1583 * @dev: virtual device associated with tunnel
1584 * @ifr: parameters passed from userspace
1585 * @cmd: command to be performed
1588 * ip6_tnl_ioctl() is used for managing IPv6 tunnels
1591 * The possible commands are the following:
1592 * %SIOCGETTUNNEL: get tunnel parameters for device
1593 * %SIOCADDTUNNEL: add tunnel matching given tunnel parameters
1594 * %SIOCCHGTUNNEL: change tunnel parameters to those given
1595 * %SIOCDELTUNNEL: delete tunnel
1597 * The fallback device "ip6tnl0", created during module
1598 * initialization, can be used for creating other tunnel devices.
1602 * %-EFAULT if unable to copy data to or from userspace,
1603 * %-EPERM if current process hasn't %CAP_NET_ADMIN set
1604 * %-EINVAL if passed tunnel parameters are invalid,
1605 * %-EEXIST if changing a tunnel's parameters would cause a conflict
1606 * %-ENODEV if attempting to change or delete a nonexisting device
1610 ip6_tnl_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
1613 struct ip6_tnl_parm p;
1614 struct __ip6_tnl_parm p1;
1615 struct ip6_tnl *t = netdev_priv(dev);
1616 struct net *net = t->net;
1617 struct ip6_tnl_net *ip6n = net_generic(net, ip6_tnl_net_id);
1619 memset(&p1, 0, sizeof(p1));
1623 if (dev == ip6n->fb_tnl_dev) {
1624 if (copy_from_user(&p, ifr->ifr_ifru.ifru_data, sizeof(p))) {
1628 ip6_tnl_parm_from_user(&p1, &p);
1629 t = ip6_tnl_locate(net, &p1, 0);
1631 t = netdev_priv(dev);
1633 memset(&p, 0, sizeof(p));
1635 ip6_tnl_parm_to_user(&p, &t->parms);
1636 if (copy_to_user(ifr->ifr_ifru.ifru_data, &p, sizeof(p))) {
1643 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
1646 if (copy_from_user(&p, ifr->ifr_ifru.ifru_data, sizeof(p)))
1649 if (p.proto != IPPROTO_IPV6 && p.proto != IPPROTO_IPIP &&
1652 ip6_tnl_parm_from_user(&p1, &p);
1653 t = ip6_tnl_locate(net, &p1, cmd == SIOCADDTUNNEL);
1654 if (cmd == SIOCCHGTUNNEL) {
1656 if (t->dev != dev) {
1661 t = netdev_priv(dev);
1662 if (dev == ip6n->fb_tnl_dev)
1663 err = ip6_tnl0_update(t, &p1);
1665 err = ip6_tnl_update(t, &p1);
1669 ip6_tnl_parm_to_user(&p, &t->parms);
1670 if (copy_to_user(ifr->ifr_ifru.ifru_data, &p, sizeof(p)))
1679 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
1682 if (dev == ip6n->fb_tnl_dev) {
1684 if (copy_from_user(&p, ifr->ifr_ifru.ifru_data, sizeof(p)))
1687 ip6_tnl_parm_from_user(&p1, &p);
1688 t = ip6_tnl_locate(net, &p1, 0);
1692 if (t->dev == ip6n->fb_tnl_dev)
1697 unregister_netdevice(dev);
1706 * ip6_tnl_change_mtu - change mtu manually for tunnel device
1707 * @dev: virtual device associated with tunnel
1708 * @new_mtu: the new mtu
1712 * %-EINVAL if mtu too small
1715 int ip6_tnl_change_mtu(struct net_device *dev, int new_mtu)
1717 struct ip6_tnl *tnl = netdev_priv(dev);
1719 if (tnl->parms.proto == IPPROTO_IPV6) {
1720 if (new_mtu < IPV6_MIN_MTU)
1723 if (new_mtu < ETH_MIN_MTU)
1726 if (tnl->parms.proto == IPPROTO_IPV6 || tnl->parms.proto == 0) {
1727 if (new_mtu > IP6_MAX_MTU - dev->hard_header_len)
1730 if (new_mtu > IP_MAX_MTU - dev->hard_header_len)
1736 EXPORT_SYMBOL(ip6_tnl_change_mtu);
1738 int ip6_tnl_get_iflink(const struct net_device *dev)
1740 struct ip6_tnl *t = netdev_priv(dev);
1742 return t->parms.link;
1744 EXPORT_SYMBOL(ip6_tnl_get_iflink);
1746 int ip6_tnl_encap_add_ops(const struct ip6_tnl_encap_ops *ops,
1749 if (num >= MAX_IPTUN_ENCAP_OPS)
1752 return !cmpxchg((const struct ip6_tnl_encap_ops **)
1753 &ip6tun_encaps[num],
1754 NULL, ops) ? 0 : -1;
1756 EXPORT_SYMBOL(ip6_tnl_encap_add_ops);
1758 int ip6_tnl_encap_del_ops(const struct ip6_tnl_encap_ops *ops,
1763 if (num >= MAX_IPTUN_ENCAP_OPS)
1766 ret = (cmpxchg((const struct ip6_tnl_encap_ops **)
1767 &ip6tun_encaps[num],
1768 ops, NULL) == ops) ? 0 : -1;
1774 EXPORT_SYMBOL(ip6_tnl_encap_del_ops);
1776 int ip6_tnl_encap_setup(struct ip6_tnl *t,
1777 struct ip_tunnel_encap *ipencap)
1781 memset(&t->encap, 0, sizeof(t->encap));
1783 hlen = ip6_encap_hlen(ipencap);
1787 t->encap.type = ipencap->type;
1788 t->encap.sport = ipencap->sport;
1789 t->encap.dport = ipencap->dport;
1790 t->encap.flags = ipencap->flags;
1792 t->encap_hlen = hlen;
1793 t->hlen = t->encap_hlen + t->tun_hlen;
1797 EXPORT_SYMBOL_GPL(ip6_tnl_encap_setup);
1799 static const struct net_device_ops ip6_tnl_netdev_ops = {
1800 .ndo_init = ip6_tnl_dev_init,
1801 .ndo_uninit = ip6_tnl_dev_uninit,
1802 .ndo_start_xmit = ip6_tnl_start_xmit,
1803 .ndo_do_ioctl = ip6_tnl_ioctl,
1804 .ndo_change_mtu = ip6_tnl_change_mtu,
1805 .ndo_get_stats = ip6_get_stats,
1806 .ndo_get_iflink = ip6_tnl_get_iflink,
1809 #define IPXIPX_FEATURES (NETIF_F_SG | \
1810 NETIF_F_FRAGLIST | \
1812 NETIF_F_GSO_SOFTWARE | \
1816 * ip6_tnl_dev_setup - setup virtual tunnel device
1817 * @dev: virtual device associated with tunnel
1820 * Initialize function pointers and device parameters
1823 static void ip6_tnl_dev_setup(struct net_device *dev)
1825 dev->netdev_ops = &ip6_tnl_netdev_ops;
1826 dev->needs_free_netdev = true;
1827 dev->priv_destructor = ip6_dev_free;
1829 dev->type = ARPHRD_TUNNEL6;
1830 dev->flags |= IFF_NOARP;
1831 dev->addr_len = sizeof(struct in6_addr);
1832 dev->features |= NETIF_F_LLTX;
1833 netif_keep_dst(dev);
1835 dev->features |= IPXIPX_FEATURES;
1836 dev->hw_features |= IPXIPX_FEATURES;
1838 /* This perm addr will be used as interface identifier by IPv6 */
1839 dev->addr_assign_type = NET_ADDR_RANDOM;
1840 eth_random_addr(dev->perm_addr);
1845 * ip6_tnl_dev_init_gen - general initializer for all tunnel devices
1846 * @dev: virtual device associated with tunnel
1850 ip6_tnl_dev_init_gen(struct net_device *dev)
1852 struct ip6_tnl *t = netdev_priv(dev);
1857 t->net = dev_net(dev);
1858 dev->tstats = netdev_alloc_pcpu_stats(struct pcpu_sw_netstats);
1862 ret = dst_cache_init(&t->dst_cache, GFP_KERNEL);
1866 ret = gro_cells_init(&t->gro_cells, dev);
1871 t->hlen = t->encap_hlen + t->tun_hlen;
1872 t_hlen = t->hlen + sizeof(struct ipv6hdr);
1874 dev->type = ARPHRD_TUNNEL6;
1875 dev->hard_header_len = LL_MAX_HEADER + t_hlen;
1876 dev->mtu = ETH_DATA_LEN - t_hlen;
1877 if (!(t->parms.flags & IP6_TNL_F_IGN_ENCAP_LIMIT))
1879 dev->min_mtu = ETH_MIN_MTU;
1880 dev->max_mtu = IP6_MAX_MTU - dev->hard_header_len;
1885 dst_cache_destroy(&t->dst_cache);
1887 free_percpu(dev->tstats);
1894 * ip6_tnl_dev_init - initializer for all non fallback tunnel devices
1895 * @dev: virtual device associated with tunnel
1898 static int ip6_tnl_dev_init(struct net_device *dev)
1900 struct ip6_tnl *t = netdev_priv(dev);
1901 int err = ip6_tnl_dev_init_gen(dev);
1905 ip6_tnl_link_config(t);
1906 if (t->parms.collect_md)
1907 netif_keep_dst(dev);
1912 * ip6_fb_tnl_dev_init - initializer for fallback tunnel device
1913 * @dev: fallback device
1918 static int __net_init ip6_fb_tnl_dev_init(struct net_device *dev)
1920 struct ip6_tnl *t = netdev_priv(dev);
1921 struct net *net = dev_net(dev);
1922 struct ip6_tnl_net *ip6n = net_generic(net, ip6_tnl_net_id);
1924 t->parms.proto = IPPROTO_IPV6;
1927 rcu_assign_pointer(ip6n->tnls_wc[0], t);
1931 static int ip6_tnl_validate(struct nlattr *tb[], struct nlattr *data[],
1932 struct netlink_ext_ack *extack)
1936 if (!data || !data[IFLA_IPTUN_PROTO])
1939 proto = nla_get_u8(data[IFLA_IPTUN_PROTO]);
1940 if (proto != IPPROTO_IPV6 &&
1941 proto != IPPROTO_IPIP &&
1948 static void ip6_tnl_netlink_parms(struct nlattr *data[],
1949 struct __ip6_tnl_parm *parms)
1951 memset(parms, 0, sizeof(*parms));
1956 if (data[IFLA_IPTUN_LINK])
1957 parms->link = nla_get_u32(data[IFLA_IPTUN_LINK]);
1959 if (data[IFLA_IPTUN_LOCAL])
1960 parms->laddr = nla_get_in6_addr(data[IFLA_IPTUN_LOCAL]);
1962 if (data[IFLA_IPTUN_REMOTE])
1963 parms->raddr = nla_get_in6_addr(data[IFLA_IPTUN_REMOTE]);
1965 if (data[IFLA_IPTUN_TTL])
1966 parms->hop_limit = nla_get_u8(data[IFLA_IPTUN_TTL]);
1968 if (data[IFLA_IPTUN_ENCAP_LIMIT])
1969 parms->encap_limit = nla_get_u8(data[IFLA_IPTUN_ENCAP_LIMIT]);
1971 if (data[IFLA_IPTUN_FLOWINFO])
1972 parms->flowinfo = nla_get_be32(data[IFLA_IPTUN_FLOWINFO]);
1974 if (data[IFLA_IPTUN_FLAGS])
1975 parms->flags = nla_get_u32(data[IFLA_IPTUN_FLAGS]);
1977 if (data[IFLA_IPTUN_PROTO])
1978 parms->proto = nla_get_u8(data[IFLA_IPTUN_PROTO]);
1980 if (data[IFLA_IPTUN_COLLECT_METADATA])
1981 parms->collect_md = true;
1983 if (data[IFLA_IPTUN_FWMARK])
1984 parms->fwmark = nla_get_u32(data[IFLA_IPTUN_FWMARK]);
1987 static bool ip6_tnl_netlink_encap_parms(struct nlattr *data[],
1988 struct ip_tunnel_encap *ipencap)
1992 memset(ipencap, 0, sizeof(*ipencap));
1997 if (data[IFLA_IPTUN_ENCAP_TYPE]) {
1999 ipencap->type = nla_get_u16(data[IFLA_IPTUN_ENCAP_TYPE]);
2002 if (data[IFLA_IPTUN_ENCAP_FLAGS]) {
2004 ipencap->flags = nla_get_u16(data[IFLA_IPTUN_ENCAP_FLAGS]);
2007 if (data[IFLA_IPTUN_ENCAP_SPORT]) {
2009 ipencap->sport = nla_get_be16(data[IFLA_IPTUN_ENCAP_SPORT]);
2012 if (data[IFLA_IPTUN_ENCAP_DPORT]) {
2014 ipencap->dport = nla_get_be16(data[IFLA_IPTUN_ENCAP_DPORT]);
2020 static int ip6_tnl_newlink(struct net *src_net, struct net_device *dev,
2021 struct nlattr *tb[], struct nlattr *data[],
2022 struct netlink_ext_ack *extack)
2024 struct net *net = dev_net(dev);
2025 struct ip6_tnl_net *ip6n = net_generic(net, ip6_tnl_net_id);
2026 struct ip_tunnel_encap ipencap;
2027 struct ip6_tnl *nt, *t;
2030 nt = netdev_priv(dev);
2032 if (ip6_tnl_netlink_encap_parms(data, &ipencap)) {
2033 err = ip6_tnl_encap_setup(nt, &ipencap);
2038 ip6_tnl_netlink_parms(data, &nt->parms);
2040 if (nt->parms.collect_md) {
2041 if (rtnl_dereference(ip6n->collect_md_tun))
2044 t = ip6_tnl_locate(net, &nt->parms, 0);
2049 err = ip6_tnl_create2(dev);
2050 if (!err && tb[IFLA_MTU])
2051 ip6_tnl_change_mtu(dev, nla_get_u32(tb[IFLA_MTU]));
2056 static int ip6_tnl_changelink(struct net_device *dev, struct nlattr *tb[],
2057 struct nlattr *data[],
2058 struct netlink_ext_ack *extack)
2060 struct ip6_tnl *t = netdev_priv(dev);
2061 struct __ip6_tnl_parm p;
2062 struct net *net = t->net;
2063 struct ip6_tnl_net *ip6n = net_generic(net, ip6_tnl_net_id);
2064 struct ip_tunnel_encap ipencap;
2066 if (dev == ip6n->fb_tnl_dev)
2069 if (ip6_tnl_netlink_encap_parms(data, &ipencap)) {
2070 int err = ip6_tnl_encap_setup(t, &ipencap);
2075 ip6_tnl_netlink_parms(data, &p);
2079 t = ip6_tnl_locate(net, &p, 0);
2084 t = netdev_priv(dev);
2086 return ip6_tnl_update(t, &p);
2089 static void ip6_tnl_dellink(struct net_device *dev, struct list_head *head)
2091 struct net *net = dev_net(dev);
2092 struct ip6_tnl_net *ip6n = net_generic(net, ip6_tnl_net_id);
2094 if (dev != ip6n->fb_tnl_dev)
2095 unregister_netdevice_queue(dev, head);
2098 static size_t ip6_tnl_get_size(const struct net_device *dev)
2101 /* IFLA_IPTUN_LINK */
2103 /* IFLA_IPTUN_LOCAL */
2104 nla_total_size(sizeof(struct in6_addr)) +
2105 /* IFLA_IPTUN_REMOTE */
2106 nla_total_size(sizeof(struct in6_addr)) +
2107 /* IFLA_IPTUN_TTL */
2109 /* IFLA_IPTUN_ENCAP_LIMIT */
2111 /* IFLA_IPTUN_FLOWINFO */
2113 /* IFLA_IPTUN_FLAGS */
2115 /* IFLA_IPTUN_PROTO */
2117 /* IFLA_IPTUN_ENCAP_TYPE */
2119 /* IFLA_IPTUN_ENCAP_FLAGS */
2121 /* IFLA_IPTUN_ENCAP_SPORT */
2123 /* IFLA_IPTUN_ENCAP_DPORT */
2125 /* IFLA_IPTUN_COLLECT_METADATA */
2127 /* IFLA_IPTUN_FWMARK */
2132 static int ip6_tnl_fill_info(struct sk_buff *skb, const struct net_device *dev)
2134 struct ip6_tnl *tunnel = netdev_priv(dev);
2135 struct __ip6_tnl_parm *parm = &tunnel->parms;
2137 if (nla_put_u32(skb, IFLA_IPTUN_LINK, parm->link) ||
2138 nla_put_in6_addr(skb, IFLA_IPTUN_LOCAL, &parm->laddr) ||
2139 nla_put_in6_addr(skb, IFLA_IPTUN_REMOTE, &parm->raddr) ||
2140 nla_put_u8(skb, IFLA_IPTUN_TTL, parm->hop_limit) ||
2141 nla_put_u8(skb, IFLA_IPTUN_ENCAP_LIMIT, parm->encap_limit) ||
2142 nla_put_be32(skb, IFLA_IPTUN_FLOWINFO, parm->flowinfo) ||
2143 nla_put_u32(skb, IFLA_IPTUN_FLAGS, parm->flags) ||
2144 nla_put_u8(skb, IFLA_IPTUN_PROTO, parm->proto) ||
2145 nla_put_u32(skb, IFLA_IPTUN_FWMARK, parm->fwmark))
2146 goto nla_put_failure;
2148 if (nla_put_u16(skb, IFLA_IPTUN_ENCAP_TYPE, tunnel->encap.type) ||
2149 nla_put_be16(skb, IFLA_IPTUN_ENCAP_SPORT, tunnel->encap.sport) ||
2150 nla_put_be16(skb, IFLA_IPTUN_ENCAP_DPORT, tunnel->encap.dport) ||
2151 nla_put_u16(skb, IFLA_IPTUN_ENCAP_FLAGS, tunnel->encap.flags))
2152 goto nla_put_failure;
2154 if (parm->collect_md)
2155 if (nla_put_flag(skb, IFLA_IPTUN_COLLECT_METADATA))
2156 goto nla_put_failure;
2164 struct net *ip6_tnl_get_link_net(const struct net_device *dev)
2166 struct ip6_tnl *tunnel = netdev_priv(dev);
2170 EXPORT_SYMBOL(ip6_tnl_get_link_net);
2172 static const struct nla_policy ip6_tnl_policy[IFLA_IPTUN_MAX + 1] = {
2173 [IFLA_IPTUN_LINK] = { .type = NLA_U32 },
2174 [IFLA_IPTUN_LOCAL] = { .len = sizeof(struct in6_addr) },
2175 [IFLA_IPTUN_REMOTE] = { .len = sizeof(struct in6_addr) },
2176 [IFLA_IPTUN_TTL] = { .type = NLA_U8 },
2177 [IFLA_IPTUN_ENCAP_LIMIT] = { .type = NLA_U8 },
2178 [IFLA_IPTUN_FLOWINFO] = { .type = NLA_U32 },
2179 [IFLA_IPTUN_FLAGS] = { .type = NLA_U32 },
2180 [IFLA_IPTUN_PROTO] = { .type = NLA_U8 },
2181 [IFLA_IPTUN_ENCAP_TYPE] = { .type = NLA_U16 },
2182 [IFLA_IPTUN_ENCAP_FLAGS] = { .type = NLA_U16 },
2183 [IFLA_IPTUN_ENCAP_SPORT] = { .type = NLA_U16 },
2184 [IFLA_IPTUN_ENCAP_DPORT] = { .type = NLA_U16 },
2185 [IFLA_IPTUN_COLLECT_METADATA] = { .type = NLA_FLAG },
2186 [IFLA_IPTUN_FWMARK] = { .type = NLA_U32 },
2189 static struct rtnl_link_ops ip6_link_ops __read_mostly = {
2191 .maxtype = IFLA_IPTUN_MAX,
2192 .policy = ip6_tnl_policy,
2193 .priv_size = sizeof(struct ip6_tnl),
2194 .setup = ip6_tnl_dev_setup,
2195 .validate = ip6_tnl_validate,
2196 .newlink = ip6_tnl_newlink,
2197 .changelink = ip6_tnl_changelink,
2198 .dellink = ip6_tnl_dellink,
2199 .get_size = ip6_tnl_get_size,
2200 .fill_info = ip6_tnl_fill_info,
2201 .get_link_net = ip6_tnl_get_link_net,
2204 static struct xfrm6_tunnel ip4ip6_handler __read_mostly = {
2205 .handler = ip4ip6_rcv,
2206 .err_handler = ip4ip6_err,
2210 static struct xfrm6_tunnel ip6ip6_handler __read_mostly = {
2211 .handler = ip6ip6_rcv,
2212 .err_handler = ip6ip6_err,
2216 static void __net_exit ip6_tnl_destroy_tunnels(struct net *net, struct list_head *list)
2218 struct ip6_tnl_net *ip6n = net_generic(net, ip6_tnl_net_id);
2219 struct net_device *dev, *aux;
2223 for_each_netdev_safe(net, dev, aux)
2224 if (dev->rtnl_link_ops == &ip6_link_ops)
2225 unregister_netdevice_queue(dev, list);
2227 for (h = 0; h < IP6_TUNNEL_HASH_SIZE; h++) {
2228 t = rtnl_dereference(ip6n->tnls_r_l[h]);
2230 /* If dev is in the same netns, it has already
2231 * been added to the list by the previous loop.
2233 if (!net_eq(dev_net(t->dev), net))
2234 unregister_netdevice_queue(t->dev, list);
2235 t = rtnl_dereference(t->next);
2240 static int __net_init ip6_tnl_init_net(struct net *net)
2242 struct ip6_tnl_net *ip6n = net_generic(net, ip6_tnl_net_id);
2243 struct ip6_tnl *t = NULL;
2246 ip6n->tnls[0] = ip6n->tnls_wc;
2247 ip6n->tnls[1] = ip6n->tnls_r_l;
2249 if (!net_has_fallback_tunnels(net))
2252 ip6n->fb_tnl_dev = alloc_netdev(sizeof(struct ip6_tnl), "ip6tnl0",
2253 NET_NAME_UNKNOWN, ip6_tnl_dev_setup);
2255 if (!ip6n->fb_tnl_dev)
2257 dev_net_set(ip6n->fb_tnl_dev, net);
2258 ip6n->fb_tnl_dev->rtnl_link_ops = &ip6_link_ops;
2259 /* FB netdevice is special: we have one, and only one per netns.
2260 * Allowing to move it to another netns is clearly unsafe.
2262 ip6n->fb_tnl_dev->features |= NETIF_F_NETNS_LOCAL;
2264 err = ip6_fb_tnl_dev_init(ip6n->fb_tnl_dev);
2268 err = register_netdev(ip6n->fb_tnl_dev);
2272 t = netdev_priv(ip6n->fb_tnl_dev);
2274 strcpy(t->parms.name, ip6n->fb_tnl_dev->name);
2278 free_netdev(ip6n->fb_tnl_dev);
2283 static void __net_exit ip6_tnl_exit_batch_net(struct list_head *net_list)
2289 list_for_each_entry(net, net_list, exit_list)
2290 ip6_tnl_destroy_tunnels(net, &list);
2291 unregister_netdevice_many(&list);
2295 static struct pernet_operations ip6_tnl_net_ops = {
2296 .init = ip6_tnl_init_net,
2297 .exit_batch = ip6_tnl_exit_batch_net,
2298 .id = &ip6_tnl_net_id,
2299 .size = sizeof(struct ip6_tnl_net),
2303 * ip6_tunnel_init - register protocol and reserve needed resources
2305 * Return: 0 on success
2308 static int __init ip6_tunnel_init(void)
2312 if (!ipv6_mod_enabled())
2315 err = register_pernet_device(&ip6_tnl_net_ops);
2319 err = xfrm6_tunnel_register(&ip4ip6_handler, AF_INET);
2321 pr_err("%s: can't register ip4ip6\n", __func__);
2325 err = xfrm6_tunnel_register(&ip6ip6_handler, AF_INET6);
2327 pr_err("%s: can't register ip6ip6\n", __func__);
2330 err = rtnl_link_register(&ip6_link_ops);
2332 goto rtnl_link_failed;
2337 xfrm6_tunnel_deregister(&ip6ip6_handler, AF_INET6);
2339 xfrm6_tunnel_deregister(&ip4ip6_handler, AF_INET);
2341 unregister_pernet_device(&ip6_tnl_net_ops);
2347 * ip6_tunnel_cleanup - free resources and unregister protocol
2350 static void __exit ip6_tunnel_cleanup(void)
2352 rtnl_link_unregister(&ip6_link_ops);
2353 if (xfrm6_tunnel_deregister(&ip4ip6_handler, AF_INET))
2354 pr_info("%s: can't deregister ip4ip6\n", __func__);
2356 if (xfrm6_tunnel_deregister(&ip6ip6_handler, AF_INET6))
2357 pr_info("%s: can't deregister ip6ip6\n", __func__);
2359 unregister_pernet_device(&ip6_tnl_net_ops);
2362 module_init(ip6_tunnel_init);
2363 module_exit(ip6_tunnel_cleanup);