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 inline int ip6_tnl_mpls_supported(void)
94 return IS_ENABLED(CONFIG_MPLS);
97 static struct net_device_stats *ip6_get_stats(struct net_device *dev)
99 struct pcpu_sw_netstats tmp, sum = { 0 };
102 for_each_possible_cpu(i) {
104 const struct pcpu_sw_netstats *tstats =
105 per_cpu_ptr(dev->tstats, i);
108 start = u64_stats_fetch_begin_irq(&tstats->syncp);
109 tmp.rx_packets = tstats->rx_packets;
110 tmp.rx_bytes = tstats->rx_bytes;
111 tmp.tx_packets = tstats->tx_packets;
112 tmp.tx_bytes = tstats->tx_bytes;
113 } while (u64_stats_fetch_retry_irq(&tstats->syncp, start));
115 sum.rx_packets += tmp.rx_packets;
116 sum.rx_bytes += tmp.rx_bytes;
117 sum.tx_packets += tmp.tx_packets;
118 sum.tx_bytes += tmp.tx_bytes;
120 dev->stats.rx_packets = sum.rx_packets;
121 dev->stats.rx_bytes = sum.rx_bytes;
122 dev->stats.tx_packets = sum.tx_packets;
123 dev->stats.tx_bytes = sum.tx_bytes;
128 * ip6_tnl_lookup - fetch tunnel matching the end-point addresses
129 * @link: ifindex of underlying interface
130 * @remote: the address of the tunnel exit-point
131 * @local: the address of the tunnel entry-point
134 * tunnel matching given end-points if found,
135 * else fallback tunnel if its device is up,
139 #define for_each_ip6_tunnel_rcu(start) \
140 for (t = rcu_dereference(start); t; t = rcu_dereference(t->next))
142 static struct ip6_tnl *
143 ip6_tnl_lookup(struct net *net, int link,
144 const struct in6_addr *remote, const struct in6_addr *local)
146 unsigned int hash = HASH(remote, local);
147 struct ip6_tnl *t, *cand = NULL;
148 struct ip6_tnl_net *ip6n = net_generic(net, ip6_tnl_net_id);
151 for_each_ip6_tunnel_rcu(ip6n->tnls_r_l[hash]) {
152 if (!ipv6_addr_equal(local, &t->parms.laddr) ||
153 !ipv6_addr_equal(remote, &t->parms.raddr) ||
154 !(t->dev->flags & IFF_UP))
157 if (link == t->parms.link)
163 memset(&any, 0, sizeof(any));
164 hash = HASH(&any, local);
165 for_each_ip6_tunnel_rcu(ip6n->tnls_r_l[hash]) {
166 if (!ipv6_addr_equal(local, &t->parms.laddr) ||
167 !ipv6_addr_any(&t->parms.raddr) ||
168 !(t->dev->flags & IFF_UP))
171 if (link == t->parms.link)
177 hash = HASH(remote, &any);
178 for_each_ip6_tunnel_rcu(ip6n->tnls_r_l[hash]) {
179 if (!ipv6_addr_equal(remote, &t->parms.raddr) ||
180 !ipv6_addr_any(&t->parms.laddr) ||
181 !(t->dev->flags & IFF_UP))
184 if (link == t->parms.link)
193 t = rcu_dereference(ip6n->collect_md_tun);
194 if (t && t->dev->flags & IFF_UP)
197 t = rcu_dereference(ip6n->tnls_wc[0]);
198 if (t && (t->dev->flags & IFF_UP))
205 * ip6_tnl_bucket - get head of list matching given tunnel parameters
206 * @p: parameters containing tunnel end-points
209 * ip6_tnl_bucket() returns the head of the list matching the
210 * &struct in6_addr entries laddr and raddr in @p.
212 * Return: head of IPv6 tunnel list
215 static struct ip6_tnl __rcu **
216 ip6_tnl_bucket(struct ip6_tnl_net *ip6n, const struct __ip6_tnl_parm *p)
218 const struct in6_addr *remote = &p->raddr;
219 const struct in6_addr *local = &p->laddr;
223 if (!ipv6_addr_any(remote) || !ipv6_addr_any(local)) {
225 h = HASH(remote, local);
227 return &ip6n->tnls[prio][h];
231 * ip6_tnl_link - add tunnel to hash table
232 * @t: tunnel to be added
236 ip6_tnl_link(struct ip6_tnl_net *ip6n, struct ip6_tnl *t)
238 struct ip6_tnl __rcu **tp = ip6_tnl_bucket(ip6n, &t->parms);
240 if (t->parms.collect_md)
241 rcu_assign_pointer(ip6n->collect_md_tun, t);
242 rcu_assign_pointer(t->next , rtnl_dereference(*tp));
243 rcu_assign_pointer(*tp, t);
247 * ip6_tnl_unlink - remove tunnel from hash table
248 * @t: tunnel to be removed
252 ip6_tnl_unlink(struct ip6_tnl_net *ip6n, struct ip6_tnl *t)
254 struct ip6_tnl __rcu **tp;
255 struct ip6_tnl *iter;
257 if (t->parms.collect_md)
258 rcu_assign_pointer(ip6n->collect_md_tun, NULL);
260 for (tp = ip6_tnl_bucket(ip6n, &t->parms);
261 (iter = rtnl_dereference(*tp)) != NULL;
264 rcu_assign_pointer(*tp, t->next);
270 static void ip6_dev_free(struct net_device *dev)
272 struct ip6_tnl *t = netdev_priv(dev);
274 gro_cells_destroy(&t->gro_cells);
275 dst_cache_destroy(&t->dst_cache);
276 free_percpu(dev->tstats);
279 static int ip6_tnl_create2(struct net_device *dev)
281 struct ip6_tnl *t = netdev_priv(dev);
282 struct net *net = dev_net(dev);
283 struct ip6_tnl_net *ip6n = net_generic(net, ip6_tnl_net_id);
286 t = netdev_priv(dev);
288 dev->rtnl_link_ops = &ip6_link_ops;
289 err = register_netdevice(dev);
293 strcpy(t->parms.name, dev->name);
296 ip6_tnl_link(ip6n, t);
304 * ip6_tnl_create - create a new tunnel
305 * @p: tunnel parameters
306 * @pt: pointer to new tunnel
309 * Create tunnel matching given parameters.
312 * created tunnel or error pointer
315 static struct ip6_tnl *ip6_tnl_create(struct net *net, struct __ip6_tnl_parm *p)
317 struct net_device *dev;
323 if (!dev_valid_name(p->name))
325 strlcpy(name, p->name, IFNAMSIZ);
327 sprintf(name, "ip6tnl%%d");
330 dev = alloc_netdev(sizeof(*t), name, NET_NAME_UNKNOWN,
335 dev_net_set(dev, net);
337 t = netdev_priv(dev);
339 t->net = dev_net(dev);
340 err = ip6_tnl_create2(dev);
353 * ip6_tnl_locate - find or create tunnel matching given parameters
354 * @p: tunnel parameters
355 * @create: != 0 if allowed to create new tunnel if no match found
358 * ip6_tnl_locate() first tries to locate an existing tunnel
359 * based on @parms. If this is unsuccessful, but @create is set a new
360 * tunnel device is created and registered for use.
363 * matching tunnel or error pointer
366 static struct ip6_tnl *ip6_tnl_locate(struct net *net,
367 struct __ip6_tnl_parm *p, int create)
369 const struct in6_addr *remote = &p->raddr;
370 const struct in6_addr *local = &p->laddr;
371 struct ip6_tnl __rcu **tp;
373 struct ip6_tnl_net *ip6n = net_generic(net, ip6_tnl_net_id);
375 for (tp = ip6_tnl_bucket(ip6n, p);
376 (t = rtnl_dereference(*tp)) != NULL;
378 if (ipv6_addr_equal(local, &t->parms.laddr) &&
379 ipv6_addr_equal(remote, &t->parms.raddr) &&
380 p->link == t->parms.link) {
382 return ERR_PTR(-EEXIST);
388 return ERR_PTR(-ENODEV);
389 return ip6_tnl_create(net, p);
393 * ip6_tnl_dev_uninit - tunnel device uninitializer
394 * @dev: the device to be destroyed
397 * ip6_tnl_dev_uninit() removes tunnel from its list
401 ip6_tnl_dev_uninit(struct net_device *dev)
403 struct ip6_tnl *t = netdev_priv(dev);
404 struct net *net = t->net;
405 struct ip6_tnl_net *ip6n = net_generic(net, ip6_tnl_net_id);
407 if (dev == ip6n->fb_tnl_dev)
408 RCU_INIT_POINTER(ip6n->tnls_wc[0], NULL);
410 ip6_tnl_unlink(ip6n, t);
411 dst_cache_reset(&t->dst_cache);
416 * parse_tvl_tnl_enc_lim - handle encapsulation limit option
417 * @skb: received socket buffer
420 * 0 if none was found,
421 * else index to encapsulation limit
424 __u16 ip6_tnl_parse_tlv_enc_lim(struct sk_buff *skb, __u8 *raw)
426 const struct ipv6hdr *ipv6h = (const struct ipv6hdr *)raw;
427 unsigned int nhoff = raw - skb->data;
428 unsigned int off = nhoff + sizeof(*ipv6h);
429 u8 next, nexthdr = ipv6h->nexthdr;
431 while (ipv6_ext_hdr(nexthdr) && nexthdr != NEXTHDR_NONE) {
432 struct ipv6_opt_hdr *hdr;
435 if (!pskb_may_pull(skb, off + sizeof(*hdr)))
438 hdr = (struct ipv6_opt_hdr *)(skb->data + off);
439 if (nexthdr == NEXTHDR_FRAGMENT) {
440 struct frag_hdr *frag_hdr = (struct frag_hdr *) hdr;
441 if (frag_hdr->frag_off)
444 } else if (nexthdr == NEXTHDR_AUTH) {
445 optlen = ipv6_authlen(hdr);
447 optlen = ipv6_optlen(hdr);
449 /* cache hdr->nexthdr, since pskb_may_pull() might
453 if (nexthdr == NEXTHDR_DEST) {
456 /* Remember : hdr is no longer valid at this point. */
457 if (!pskb_may_pull(skb, off + optlen))
461 struct ipv6_tlv_tnl_enc_lim *tel;
463 /* No more room for encapsulation limit */
464 if (i + sizeof(*tel) > optlen)
467 tel = (struct ipv6_tlv_tnl_enc_lim *)(skb->data + off + i);
468 /* return index of option if found and valid */
469 if (tel->type == IPV6_TLV_TNL_ENCAP_LIMIT &&
471 return i + off - nhoff;
472 /* else jump to next option */
474 i += tel->length + 2;
484 EXPORT_SYMBOL(ip6_tnl_parse_tlv_enc_lim);
487 * ip6_tnl_err - tunnel error handler
490 * ip6_tnl_err() should handle errors in the tunnel according
491 * to the specifications in RFC 2473.
495 ip6_tnl_err(struct sk_buff *skb, __u8 ipproto, struct inet6_skb_parm *opt,
496 u8 *type, u8 *code, int *msg, __u32 *info, int offset)
498 const struct ipv6hdr *ipv6h = (const struct ipv6hdr *)skb->data;
499 struct net *net = dev_net(skb->dev);
500 u8 rel_type = ICMPV6_DEST_UNREACH;
501 u8 rel_code = ICMPV6_ADDR_UNREACH;
509 /* If the packet doesn't contain the original IPv6 header we are
510 in trouble since we might need the source address for further
511 processing of the error. */
514 t = ip6_tnl_lookup(dev_net(skb->dev), skb->dev->ifindex, &ipv6h->daddr, &ipv6h->saddr);
518 tproto = READ_ONCE(t->parms.proto);
519 if (tproto != ipproto && tproto != 0)
525 case ICMPV6_DEST_UNREACH:
526 net_dbg_ratelimited("%s: Path to destination invalid or inactive!\n",
530 case ICMPV6_TIME_EXCEED:
531 if ((*code) == ICMPV6_EXC_HOPLIMIT) {
532 net_dbg_ratelimited("%s: Too small hop limit or routing loop in tunnel!\n",
537 case ICMPV6_PARAMPROB: {
538 struct ipv6_tlv_tnl_enc_lim *tel;
542 if ((*code) == ICMPV6_HDR_FIELD)
543 teli = ip6_tnl_parse_tlv_enc_lim(skb, skb->data);
545 if (teli && teli == *info - 2) {
546 tel = (struct ipv6_tlv_tnl_enc_lim *) &skb->data[teli];
547 if (tel->encap_limit == 0) {
548 net_dbg_ratelimited("%s: Too small encapsulation limit or routing loop in tunnel!\n",
553 net_dbg_ratelimited("%s: Recipient unable to parse tunneled packet!\n",
558 case ICMPV6_PKT_TOOBIG: {
561 ip6_update_pmtu(skb, net, htonl(*info), 0, 0,
562 sock_net_uid(net, NULL));
563 mtu = *info - offset;
564 if (mtu < IPV6_MIN_MTU)
566 len = sizeof(*ipv6h) + ntohs(ipv6h->payload_len);
568 rel_type = ICMPV6_PKT_TOOBIG;
576 ip6_redirect(skb, net, skb->dev->ifindex, 0,
577 sock_net_uid(net, NULL));
592 ip4ip6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
593 u8 type, u8 code, int offset, __be32 info)
595 __u32 rel_info = ntohl(info);
596 const struct iphdr *eiph;
597 struct sk_buff *skb2;
598 int err, rel_msg = 0;
604 err = ip6_tnl_err(skb, IPPROTO_IPIP, opt, &rel_type, &rel_code,
605 &rel_msg, &rel_info, offset);
613 case ICMPV6_DEST_UNREACH:
614 if (rel_code != ICMPV6_ADDR_UNREACH)
616 rel_type = ICMP_DEST_UNREACH;
617 rel_code = ICMP_HOST_UNREACH;
619 case ICMPV6_PKT_TOOBIG:
622 rel_type = ICMP_DEST_UNREACH;
623 rel_code = ICMP_FRAG_NEEDED;
629 if (!pskb_may_pull(skb, offset + sizeof(struct iphdr)))
632 skb2 = skb_clone(skb, GFP_ATOMIC);
638 skb_pull(skb2, offset);
639 skb_reset_network_header(skb2);
642 /* Try to guess incoming interface */
643 rt = ip_route_output_ports(dev_net(skb->dev), &fl4, NULL, eiph->saddr,
644 0, 0, 0, IPPROTO_IPIP, RT_TOS(eiph->tos), 0);
648 skb2->dev = rt->dst.dev;
651 /* route "incoming" packet */
652 if (rt->rt_flags & RTCF_LOCAL) {
653 rt = ip_route_output_ports(dev_net(skb->dev), &fl4, NULL,
654 eiph->daddr, eiph->saddr, 0, 0,
655 IPPROTO_IPIP, RT_TOS(eiph->tos), 0);
656 if (IS_ERR(rt) || rt->dst.dev->type != ARPHRD_TUNNEL6) {
661 skb_dst_set(skb2, &rt->dst);
663 if (ip_route_input(skb2, eiph->daddr, eiph->saddr, eiph->tos,
665 skb_dst(skb2)->dev->type != ARPHRD_TUNNEL6)
669 /* change mtu on this route */
670 if (rel_type == ICMP_DEST_UNREACH && rel_code == ICMP_FRAG_NEEDED) {
671 if (rel_info > dst_mtu(skb_dst(skb2)))
674 skb_dst_update_pmtu_no_confirm(skb2, rel_info);
677 icmp_send(skb2, rel_type, rel_code, htonl(rel_info));
685 ip6ip6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
686 u8 type, u8 code, int offset, __be32 info)
688 __u32 rel_info = ntohl(info);
689 int err, rel_msg = 0;
693 err = ip6_tnl_err(skb, IPPROTO_IPV6, opt, &rel_type, &rel_code,
694 &rel_msg, &rel_info, offset);
698 if (rel_msg && pskb_may_pull(skb, offset + sizeof(struct ipv6hdr))) {
700 struct sk_buff *skb2 = skb_clone(skb, GFP_ATOMIC);
706 skb_pull(skb2, offset);
707 skb_reset_network_header(skb2);
709 /* Try to guess incoming interface */
710 rt = rt6_lookup(dev_net(skb->dev), &ipv6_hdr(skb2)->saddr,
713 if (rt && rt->dst.dev)
714 skb2->dev = rt->dst.dev;
716 icmpv6_send(skb2, rel_type, rel_code, rel_info);
727 mplsip6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
728 u8 type, u8 code, int offset, __be32 info)
730 __u32 rel_info = ntohl(info);
731 int err, rel_msg = 0;
735 err = ip6_tnl_err(skb, IPPROTO_MPLS, opt, &rel_type, &rel_code,
736 &rel_msg, &rel_info, offset);
740 static int ip4ip6_dscp_ecn_decapsulate(const struct ip6_tnl *t,
741 const struct ipv6hdr *ipv6h,
744 __u8 dsfield = ipv6_get_dsfield(ipv6h) & ~INET_ECN_MASK;
746 if (t->parms.flags & IP6_TNL_F_RCV_DSCP_COPY)
747 ipv4_change_dsfield(ip_hdr(skb), INET_ECN_MASK, dsfield);
749 return IP6_ECN_decapsulate(ipv6h, skb);
752 static int ip6ip6_dscp_ecn_decapsulate(const struct ip6_tnl *t,
753 const struct ipv6hdr *ipv6h,
756 if (t->parms.flags & IP6_TNL_F_RCV_DSCP_COPY)
757 ipv6_copy_dscp(ipv6_get_dsfield(ipv6h), ipv6_hdr(skb));
759 return IP6_ECN_decapsulate(ipv6h, skb);
762 static inline int mplsip6_dscp_ecn_decapsulate(const struct ip6_tnl *t,
763 const struct ipv6hdr *ipv6h,
766 /* ECN is not supported in AF_MPLS */
770 __u32 ip6_tnl_get_cap(struct ip6_tnl *t,
771 const struct in6_addr *laddr,
772 const struct in6_addr *raddr)
774 struct __ip6_tnl_parm *p = &t->parms;
775 int ltype = ipv6_addr_type(laddr);
776 int rtype = ipv6_addr_type(raddr);
779 if (ltype == IPV6_ADDR_ANY || rtype == IPV6_ADDR_ANY) {
780 flags = IP6_TNL_F_CAP_PER_PACKET;
781 } else if (ltype & (IPV6_ADDR_UNICAST|IPV6_ADDR_MULTICAST) &&
782 rtype & (IPV6_ADDR_UNICAST|IPV6_ADDR_MULTICAST) &&
783 !((ltype|rtype) & IPV6_ADDR_LOOPBACK) &&
784 (!((ltype|rtype) & IPV6_ADDR_LINKLOCAL) || p->link)) {
785 if (ltype&IPV6_ADDR_UNICAST)
786 flags |= IP6_TNL_F_CAP_XMIT;
787 if (rtype&IPV6_ADDR_UNICAST)
788 flags |= IP6_TNL_F_CAP_RCV;
792 EXPORT_SYMBOL(ip6_tnl_get_cap);
794 /* called with rcu_read_lock() */
795 int ip6_tnl_rcv_ctl(struct ip6_tnl *t,
796 const struct in6_addr *laddr,
797 const struct in6_addr *raddr)
799 struct __ip6_tnl_parm *p = &t->parms;
801 struct net *net = t->net;
803 if ((p->flags & IP6_TNL_F_CAP_RCV) ||
804 ((p->flags & IP6_TNL_F_CAP_PER_PACKET) &&
805 (ip6_tnl_get_cap(t, laddr, raddr) & IP6_TNL_F_CAP_RCV))) {
806 struct net_device *ldev = NULL;
809 ldev = dev_get_by_index_rcu(net, p->link);
811 if ((ipv6_addr_is_multicast(laddr) ||
812 likely(ipv6_chk_addr_and_flags(net, laddr, ldev, false,
813 0, IFA_F_TENTATIVE))) &&
814 ((p->flags & IP6_TNL_F_ALLOW_LOCAL_REMOTE) ||
815 likely(!ipv6_chk_addr_and_flags(net, raddr, ldev, true,
816 0, IFA_F_TENTATIVE))))
821 EXPORT_SYMBOL_GPL(ip6_tnl_rcv_ctl);
823 static int __ip6_tnl_rcv(struct ip6_tnl *tunnel, struct sk_buff *skb,
824 const struct tnl_ptk_info *tpi,
825 struct metadata_dst *tun_dst,
826 int (*dscp_ecn_decapsulate)(const struct ip6_tnl *t,
827 const struct ipv6hdr *ipv6h,
828 struct sk_buff *skb),
831 struct pcpu_sw_netstats *tstats;
832 const struct ipv6hdr *ipv6h = ipv6_hdr(skb);
835 if ((!(tpi->flags & TUNNEL_CSUM) &&
836 (tunnel->parms.i_flags & TUNNEL_CSUM)) ||
837 ((tpi->flags & TUNNEL_CSUM) &&
838 !(tunnel->parms.i_flags & TUNNEL_CSUM))) {
839 tunnel->dev->stats.rx_crc_errors++;
840 tunnel->dev->stats.rx_errors++;
844 if (tunnel->parms.i_flags & TUNNEL_SEQ) {
845 if (!(tpi->flags & TUNNEL_SEQ) ||
847 (s32)(ntohl(tpi->seq) - tunnel->i_seqno) < 0)) {
848 tunnel->dev->stats.rx_fifo_errors++;
849 tunnel->dev->stats.rx_errors++;
852 tunnel->i_seqno = ntohl(tpi->seq) + 1;
855 skb->protocol = tpi->proto;
857 /* Warning: All skb pointers will be invalidated! */
858 if (tunnel->dev->type == ARPHRD_ETHER) {
859 if (!pskb_may_pull(skb, ETH_HLEN)) {
860 tunnel->dev->stats.rx_length_errors++;
861 tunnel->dev->stats.rx_errors++;
865 ipv6h = ipv6_hdr(skb);
866 skb->protocol = eth_type_trans(skb, tunnel->dev);
867 skb_postpull_rcsum(skb, eth_hdr(skb), ETH_HLEN);
869 skb->dev = tunnel->dev;
872 skb_reset_network_header(skb);
873 memset(skb->cb, 0, sizeof(struct inet6_skb_parm));
875 __skb_tunnel_rx(skb, tunnel->dev, tunnel->net);
877 err = dscp_ecn_decapsulate(tunnel, ipv6h, skb);
880 net_info_ratelimited("non-ECT from %pI6 with DS=%#x\n",
882 ipv6_get_dsfield(ipv6h));
884 ++tunnel->dev->stats.rx_frame_errors;
885 ++tunnel->dev->stats.rx_errors;
890 tstats = this_cpu_ptr(tunnel->dev->tstats);
891 u64_stats_update_begin(&tstats->syncp);
892 tstats->rx_packets++;
893 tstats->rx_bytes += skb->len;
894 u64_stats_update_end(&tstats->syncp);
896 skb_scrub_packet(skb, !net_eq(tunnel->net, dev_net(tunnel->dev)));
899 skb_dst_set(skb, (struct dst_entry *)tun_dst);
901 gro_cells_receive(&tunnel->gro_cells, skb);
906 dst_release((struct dst_entry *)tun_dst);
911 int ip6_tnl_rcv(struct ip6_tnl *t, struct sk_buff *skb,
912 const struct tnl_ptk_info *tpi,
913 struct metadata_dst *tun_dst,
916 return __ip6_tnl_rcv(t, skb, tpi, tun_dst, ip6ip6_dscp_ecn_decapsulate,
919 EXPORT_SYMBOL(ip6_tnl_rcv);
921 static const struct tnl_ptk_info tpi_v6 = {
922 /* no tunnel info required for ipxip6. */
923 .proto = htons(ETH_P_IPV6),
926 static const struct tnl_ptk_info tpi_v4 = {
927 /* no tunnel info required for ipxip6. */
928 .proto = htons(ETH_P_IP),
931 static const struct tnl_ptk_info tpi_mpls = {
932 /* no tunnel info required for mplsip6. */
933 .proto = htons(ETH_P_MPLS_UC),
936 static int ipxip6_rcv(struct sk_buff *skb, u8 ipproto,
937 const struct tnl_ptk_info *tpi,
938 int (*dscp_ecn_decapsulate)(const struct ip6_tnl *t,
939 const struct ipv6hdr *ipv6h,
940 struct sk_buff *skb))
943 const struct ipv6hdr *ipv6h = ipv6_hdr(skb);
944 struct metadata_dst *tun_dst = NULL;
948 t = ip6_tnl_lookup(dev_net(skb->dev), skb->dev->ifindex, &ipv6h->saddr, &ipv6h->daddr);
951 u8 tproto = READ_ONCE(t->parms.proto);
953 if (tproto != ipproto && tproto != 0)
955 if (!xfrm6_policy_check(NULL, XFRM_POLICY_IN, skb))
957 ipv6h = ipv6_hdr(skb);
958 if (!ip6_tnl_rcv_ctl(t, &ipv6h->daddr, &ipv6h->saddr))
960 if (iptunnel_pull_header(skb, 0, tpi->proto, false))
962 if (t->parms.collect_md) {
963 tun_dst = ipv6_tun_rx_dst(skb, 0, 0, 0);
967 ret = __ip6_tnl_rcv(t, skb, tpi, tun_dst, dscp_ecn_decapsulate,
981 static int ip4ip6_rcv(struct sk_buff *skb)
983 return ipxip6_rcv(skb, IPPROTO_IPIP, &tpi_v4,
984 ip4ip6_dscp_ecn_decapsulate);
987 static int ip6ip6_rcv(struct sk_buff *skb)
989 return ipxip6_rcv(skb, IPPROTO_IPV6, &tpi_v6,
990 ip6ip6_dscp_ecn_decapsulate);
993 static int mplsip6_rcv(struct sk_buff *skb)
995 return ipxip6_rcv(skb, IPPROTO_MPLS, &tpi_mpls,
996 mplsip6_dscp_ecn_decapsulate);
999 struct ipv6_tel_txoption {
1000 struct ipv6_txoptions ops;
1004 static void init_tel_txopt(struct ipv6_tel_txoption *opt, __u8 encap_limit)
1006 memset(opt, 0, sizeof(struct ipv6_tel_txoption));
1008 opt->dst_opt[2] = IPV6_TLV_TNL_ENCAP_LIMIT;
1009 opt->dst_opt[3] = 1;
1010 opt->dst_opt[4] = encap_limit;
1011 opt->dst_opt[5] = IPV6_TLV_PADN;
1012 opt->dst_opt[6] = 1;
1014 opt->ops.dst1opt = (struct ipv6_opt_hdr *) opt->dst_opt;
1015 opt->ops.opt_nflen = 8;
1019 * ip6_tnl_addr_conflict - compare packet addresses to tunnel's own
1020 * @t: the outgoing tunnel device
1021 * @hdr: IPv6 header from the incoming packet
1024 * Avoid trivial tunneling loop by checking that tunnel exit-point
1025 * doesn't match source of incoming packet.
1033 ip6_tnl_addr_conflict(const struct ip6_tnl *t, const struct ipv6hdr *hdr)
1035 return ipv6_addr_equal(&t->parms.raddr, &hdr->saddr);
1038 int ip6_tnl_xmit_ctl(struct ip6_tnl *t,
1039 const struct in6_addr *laddr,
1040 const struct in6_addr *raddr)
1042 struct __ip6_tnl_parm *p = &t->parms;
1044 struct net *net = t->net;
1046 if (t->parms.collect_md)
1049 if ((p->flags & IP6_TNL_F_CAP_XMIT) ||
1050 ((p->flags & IP6_TNL_F_CAP_PER_PACKET) &&
1051 (ip6_tnl_get_cap(t, laddr, raddr) & IP6_TNL_F_CAP_XMIT))) {
1052 struct net_device *ldev = NULL;
1056 ldev = dev_get_by_index_rcu(net, p->link);
1058 if (unlikely(!ipv6_chk_addr_and_flags(net, laddr, ldev, false,
1059 0, IFA_F_TENTATIVE)))
1060 pr_warn("%s xmit: Local address not yet configured!\n",
1062 else if (!(p->flags & IP6_TNL_F_ALLOW_LOCAL_REMOTE) &&
1063 !ipv6_addr_is_multicast(raddr) &&
1064 unlikely(ipv6_chk_addr_and_flags(net, raddr, ldev,
1065 true, 0, IFA_F_TENTATIVE)))
1066 pr_warn("%s xmit: Routing loop! Remote address found on this node!\n",
1074 EXPORT_SYMBOL_GPL(ip6_tnl_xmit_ctl);
1077 * ip6_tnl_xmit - encapsulate packet and send
1078 * @skb: the outgoing socket buffer
1079 * @dev: the outgoing tunnel device
1080 * @dsfield: dscp code for outer header
1081 * @fl6: flow of tunneled packet
1082 * @encap_limit: encapsulation limit
1083 * @pmtu: Path MTU is stored if packet is too big
1084 * @proto: next header value
1087 * Build new header and do some sanity checks on the packet before sending
1093 * %-EMSGSIZE message too big. return mtu in this case.
1096 int ip6_tnl_xmit(struct sk_buff *skb, struct net_device *dev, __u8 dsfield,
1097 struct flowi6 *fl6, int encap_limit, __u32 *pmtu,
1100 struct ip6_tnl *t = netdev_priv(dev);
1101 struct net *net = t->net;
1102 struct net_device_stats *stats = &t->dev->stats;
1103 struct ipv6hdr *ipv6h;
1104 struct ipv6_tel_txoption opt;
1105 struct dst_entry *dst = NULL, *ndst = NULL;
1106 struct net_device *tdev;
1108 unsigned int eth_hlen = t->dev->type == ARPHRD_ETHER ? ETH_HLEN : 0;
1109 unsigned int psh_hlen = sizeof(struct ipv6hdr) + t->encap_hlen;
1110 unsigned int max_headroom = psh_hlen;
1111 bool use_cache = false;
1115 if (t->parms.collect_md) {
1116 hop_limit = skb_tunnel_info(skb)->key.ttl;
1119 hop_limit = t->parms.hop_limit;
1123 if (ipv6_addr_any(&t->parms.raddr)) {
1124 if (skb->protocol == htons(ETH_P_IPV6)) {
1125 struct in6_addr *addr6;
1126 struct neighbour *neigh;
1130 goto tx_err_link_failure;
1132 neigh = dst_neigh_lookup(skb_dst(skb),
1133 &ipv6_hdr(skb)->daddr);
1135 goto tx_err_link_failure;
1137 addr6 = (struct in6_addr *)&neigh->primary_key;
1138 addr_type = ipv6_addr_type(addr6);
1140 if (addr_type == IPV6_ADDR_ANY)
1141 addr6 = &ipv6_hdr(skb)->daddr;
1143 memcpy(&fl6->daddr, addr6, sizeof(fl6->daddr));
1144 neigh_release(neigh);
1146 } else if (t->parms.proto != 0 && !(t->parms.flags &
1147 (IP6_TNL_F_USE_ORIG_TCLASS |
1148 IP6_TNL_F_USE_ORIG_FWMARK))) {
1149 /* enable the cache only if neither the outer protocol nor the
1150 * routing decision depends on the current inner header value
1156 dst = dst_cache_get(&t->dst_cache);
1158 if (!ip6_tnl_xmit_ctl(t, &fl6->saddr, &fl6->daddr))
1159 goto tx_err_link_failure;
1163 /* add dsfield to flowlabel for route lookup */
1164 fl6->flowlabel = ip6_make_flowinfo(dsfield, fl6->flowlabel);
1166 dst = ip6_route_output(net, NULL, fl6);
1169 goto tx_err_link_failure;
1170 dst = xfrm_lookup(net, dst, flowi6_to_flowi(fl6), NULL, 0);
1174 goto tx_err_link_failure;
1176 if (t->parms.collect_md && ipv6_addr_any(&fl6->saddr) &&
1177 ipv6_dev_get_saddr(net, ip6_dst_idev(dst)->dev,
1178 &fl6->daddr, 0, &fl6->saddr))
1179 goto tx_err_link_failure;
1186 stats->collisions++;
1187 net_warn_ratelimited("%s: Local routing loop detected!\n",
1189 goto tx_err_dst_release;
1191 mtu = dst_mtu(dst) - eth_hlen - psh_hlen - t->tun_hlen;
1192 if (encap_limit >= 0) {
1196 mtu = max(mtu, skb->protocol == htons(ETH_P_IPV6) ?
1197 IPV6_MIN_MTU : IPV4_MIN_MTU);
1199 skb_dst_update_pmtu_no_confirm(skb, mtu);
1200 if (skb->len - t->tun_hlen - eth_hlen > mtu && !skb_is_gso(skb)) {
1203 goto tx_err_dst_release;
1206 if (t->err_count > 0) {
1207 if (time_before(jiffies,
1208 t->err_time + IP6TUNNEL_ERR_TIMEO)) {
1211 dst_link_failure(skb);
1217 skb_scrub_packet(skb, !net_eq(t->net, dev_net(dev)));
1220 * Okay, now see if we can stuff it in the buffer as-is.
1222 max_headroom += LL_RESERVED_SPACE(tdev);
1224 if (skb_headroom(skb) < max_headroom || skb_shared(skb) ||
1225 (skb_cloned(skb) && !skb_clone_writable(skb, 0))) {
1226 struct sk_buff *new_skb;
1228 new_skb = skb_realloc_headroom(skb, max_headroom);
1230 goto tx_err_dst_release;
1233 skb_set_owner_w(new_skb, skb->sk);
1238 if (t->parms.collect_md) {
1239 if (t->encap.type != TUNNEL_ENCAP_NONE)
1240 goto tx_err_dst_release;
1242 if (use_cache && ndst)
1243 dst_cache_set_ip6(&t->dst_cache, ndst, &fl6->saddr);
1245 skb_dst_set(skb, dst);
1247 if (hop_limit == 0) {
1248 if (skb->protocol == htons(ETH_P_IP))
1249 hop_limit = ip_hdr(skb)->ttl;
1250 else if (skb->protocol == htons(ETH_P_IPV6))
1251 hop_limit = ipv6_hdr(skb)->hop_limit;
1253 hop_limit = ip6_dst_hoplimit(dst);
1256 /* Calculate max headroom for all the headers and adjust
1257 * needed_headroom if necessary.
1259 max_headroom = LL_RESERVED_SPACE(dst->dev) + sizeof(struct ipv6hdr)
1260 + dst->header_len + t->hlen;
1261 if (max_headroom > dev->needed_headroom)
1262 dev->needed_headroom = max_headroom;
1264 err = ip6_tnl_encap(skb, t, &proto, fl6);
1268 if (encap_limit >= 0) {
1269 init_tel_txopt(&opt, encap_limit);
1270 ipv6_push_frag_opts(skb, &opt.ops, &proto);
1273 skb_set_inner_ipproto(skb, proto);
1275 skb_push(skb, sizeof(struct ipv6hdr));
1276 skb_reset_network_header(skb);
1277 ipv6h = ipv6_hdr(skb);
1278 ip6_flow_hdr(ipv6h, dsfield,
1279 ip6_make_flowlabel(net, skb, fl6->flowlabel, true, fl6));
1280 ipv6h->hop_limit = hop_limit;
1281 ipv6h->nexthdr = proto;
1282 ipv6h->saddr = fl6->saddr;
1283 ipv6h->daddr = fl6->daddr;
1284 ip6tunnel_xmit(NULL, skb, dev);
1286 tx_err_link_failure:
1287 stats->tx_carrier_errors++;
1288 dst_link_failure(skb);
1293 EXPORT_SYMBOL(ip6_tnl_xmit);
1296 ipxip6_tnl_xmit(struct sk_buff *skb, struct net_device *dev,
1299 struct ip6_tnl *t = netdev_priv(dev);
1300 struct ipv6hdr *ipv6h;
1301 const struct iphdr *iph;
1302 int encap_limit = -1;
1305 __u8 dsfield, orig_dsfield;
1310 tproto = READ_ONCE(t->parms.proto);
1311 if (tproto != protocol && tproto != 0)
1314 if (t->parms.collect_md) {
1315 struct ip_tunnel_info *tun_info;
1316 const struct ip_tunnel_key *key;
1318 tun_info = skb_tunnel_info(skb);
1319 if (unlikely(!tun_info || !(tun_info->mode & IP_TUNNEL_INFO_TX) ||
1320 ip_tunnel_info_af(tun_info) != AF_INET6))
1322 key = &tun_info->key;
1323 memset(&fl6, 0, sizeof(fl6));
1324 fl6.flowi6_proto = protocol;
1325 fl6.saddr = key->u.ipv6.src;
1326 fl6.daddr = key->u.ipv6.dst;
1327 fl6.flowlabel = key->label;
1332 orig_dsfield = ipv4_get_dsfield(iph);
1335 ipv6h = ipv6_hdr(skb);
1336 orig_dsfield = ipv6_get_dsfield(ipv6h);
1339 orig_dsfield = dsfield;
1343 if (!(t->parms.flags & IP6_TNL_F_IGN_ENCAP_LIMIT))
1344 encap_limit = t->parms.encap_limit;
1345 if (protocol == IPPROTO_IPV6) {
1346 offset = ip6_tnl_parse_tlv_enc_lim(skb,
1347 skb_network_header(skb));
1348 /* ip6_tnl_parse_tlv_enc_lim() might have
1349 * reallocated skb->head
1352 struct ipv6_tlv_tnl_enc_lim *tel;
1354 tel = (void *)&skb_network_header(skb)[offset];
1355 if (tel->encap_limit == 0) {
1356 icmpv6_send(skb, ICMPV6_PARAMPROB,
1357 ICMPV6_HDR_FIELD, offset + 2);
1360 encap_limit = tel->encap_limit - 1;
1364 memcpy(&fl6, &t->fl.u.ip6, sizeof(fl6));
1365 fl6.flowi6_proto = protocol;
1367 if (t->parms.flags & IP6_TNL_F_USE_ORIG_FWMARK)
1368 fl6.flowi6_mark = skb->mark;
1370 fl6.flowi6_mark = t->parms.fwmark;
1374 orig_dsfield = ipv4_get_dsfield(iph);
1375 if (t->parms.flags & IP6_TNL_F_USE_ORIG_TCLASS)
1376 dsfield = orig_dsfield;
1378 dsfield = ip6_tclass(t->parms.flowinfo);
1381 ipv6h = ipv6_hdr(skb);
1382 orig_dsfield = ipv6_get_dsfield(ipv6h);
1383 if (t->parms.flags & IP6_TNL_F_USE_ORIG_TCLASS)
1384 dsfield = orig_dsfield;
1386 dsfield = ip6_tclass(t->parms.flowinfo);
1387 if (t->parms.flags & IP6_TNL_F_USE_ORIG_FLOWLABEL)
1388 fl6.flowlabel |= ip6_flowlabel(ipv6h);
1391 orig_dsfield = dsfield = ip6_tclass(t->parms.flowinfo);
1396 fl6.flowi6_uid = sock_net_uid(dev_net(dev), NULL);
1397 dsfield = INET_ECN_encapsulate(dsfield, orig_dsfield);
1399 if (iptunnel_handle_offloads(skb, SKB_GSO_IPXIP6))
1402 err = ip6_tnl_xmit(skb, dev, dsfield, &fl6, encap_limit, &mtu,
1405 /* XXX: send ICMP error even if DF is not set. */
1406 if (err == -EMSGSIZE)
1409 icmp_send(skb, ICMP_DEST_UNREACH,
1410 ICMP_FRAG_NEEDED, htonl(mtu));
1413 icmpv6_send(skb, ICMPV6_PKT_TOOBIG, 0, mtu);
1425 ip6_tnl_start_xmit(struct sk_buff *skb, struct net_device *dev)
1427 struct ip6_tnl *t = netdev_priv(dev);
1428 struct net_device_stats *stats = &t->dev->stats;
1432 if (!pskb_inet_may_pull(skb))
1435 switch (skb->protocol) {
1436 case htons(ETH_P_IP):
1437 ipproto = IPPROTO_IPIP;
1439 case htons(ETH_P_IPV6):
1440 if (ip6_tnl_addr_conflict(t, ipv6_hdr(skb)))
1442 ipproto = IPPROTO_IPV6;
1444 case htons(ETH_P_MPLS_UC):
1445 ipproto = IPPROTO_MPLS;
1451 ret = ipxip6_tnl_xmit(skb, dev, ipproto);
1455 return NETDEV_TX_OK;
1459 stats->tx_dropped++;
1461 return NETDEV_TX_OK;
1464 static void ip6_tnl_link_config(struct ip6_tnl *t)
1466 struct net_device *dev = t->dev;
1467 struct net_device *tdev = NULL;
1468 struct __ip6_tnl_parm *p = &t->parms;
1469 struct flowi6 *fl6 = &t->fl.u.ip6;
1473 memcpy(dev->dev_addr, &p->laddr, sizeof(struct in6_addr));
1474 memcpy(dev->broadcast, &p->raddr, sizeof(struct in6_addr));
1476 /* Set up flowi template */
1477 fl6->saddr = p->laddr;
1478 fl6->daddr = p->raddr;
1479 fl6->flowi6_oif = p->link;
1482 if (!(p->flags&IP6_TNL_F_USE_ORIG_TCLASS))
1483 fl6->flowlabel |= IPV6_TCLASS_MASK & p->flowinfo;
1484 if (!(p->flags&IP6_TNL_F_USE_ORIG_FLOWLABEL))
1485 fl6->flowlabel |= IPV6_FLOWLABEL_MASK & p->flowinfo;
1487 p->flags &= ~(IP6_TNL_F_CAP_XMIT|IP6_TNL_F_CAP_RCV|IP6_TNL_F_CAP_PER_PACKET);
1488 p->flags |= ip6_tnl_get_cap(t, &p->laddr, &p->raddr);
1490 if (p->flags&IP6_TNL_F_CAP_XMIT && p->flags&IP6_TNL_F_CAP_RCV)
1491 dev->flags |= IFF_POINTOPOINT;
1493 dev->flags &= ~IFF_POINTOPOINT;
1496 t->hlen = t->encap_hlen + t->tun_hlen;
1497 t_hlen = t->hlen + sizeof(struct ipv6hdr);
1499 if (p->flags & IP6_TNL_F_CAP_XMIT) {
1500 int strict = (ipv6_addr_type(&p->raddr) &
1501 (IPV6_ADDR_MULTICAST|IPV6_ADDR_LINKLOCAL));
1503 struct rt6_info *rt = rt6_lookup(t->net,
1504 &p->raddr, &p->laddr,
1505 p->link, NULL, strict);
1511 if (!tdev && p->link)
1512 tdev = __dev_get_by_index(t->net, p->link);
1515 dev->hard_header_len = tdev->hard_header_len + t_hlen;
1516 mtu = min_t(unsigned int, tdev->mtu, IP6_MAX_MTU);
1518 dev->mtu = mtu - t_hlen;
1519 if (!(t->parms.flags & IP6_TNL_F_IGN_ENCAP_LIMIT))
1522 if (dev->mtu < IPV6_MIN_MTU)
1523 dev->mtu = IPV6_MIN_MTU;
1529 * ip6_tnl_change - update the tunnel parameters
1530 * @t: tunnel to be changed
1531 * @p: tunnel configuration parameters
1534 * ip6_tnl_change() updates the tunnel parameters
1538 ip6_tnl_change(struct ip6_tnl *t, const struct __ip6_tnl_parm *p)
1540 t->parms.laddr = p->laddr;
1541 t->parms.raddr = p->raddr;
1542 t->parms.flags = p->flags;
1543 t->parms.hop_limit = p->hop_limit;
1544 t->parms.encap_limit = p->encap_limit;
1545 t->parms.flowinfo = p->flowinfo;
1546 t->parms.link = p->link;
1547 t->parms.proto = p->proto;
1548 t->parms.fwmark = p->fwmark;
1549 dst_cache_reset(&t->dst_cache);
1550 ip6_tnl_link_config(t);
1554 static int ip6_tnl_update(struct ip6_tnl *t, struct __ip6_tnl_parm *p)
1556 struct net *net = t->net;
1557 struct ip6_tnl_net *ip6n = net_generic(net, ip6_tnl_net_id);
1560 ip6_tnl_unlink(ip6n, t);
1562 err = ip6_tnl_change(t, p);
1563 ip6_tnl_link(ip6n, t);
1564 netdev_state_change(t->dev);
1568 static int ip6_tnl0_update(struct ip6_tnl *t, struct __ip6_tnl_parm *p)
1570 /* for default tnl0 device allow to change only the proto */
1571 t->parms.proto = p->proto;
1572 netdev_state_change(t->dev);
1577 ip6_tnl_parm_from_user(struct __ip6_tnl_parm *p, const struct ip6_tnl_parm *u)
1579 p->laddr = u->laddr;
1580 p->raddr = u->raddr;
1581 p->flags = u->flags;
1582 p->hop_limit = u->hop_limit;
1583 p->encap_limit = u->encap_limit;
1584 p->flowinfo = u->flowinfo;
1586 p->proto = u->proto;
1587 memcpy(p->name, u->name, sizeof(u->name));
1591 ip6_tnl_parm_to_user(struct ip6_tnl_parm *u, const struct __ip6_tnl_parm *p)
1593 u->laddr = p->laddr;
1594 u->raddr = p->raddr;
1595 u->flags = p->flags;
1596 u->hop_limit = p->hop_limit;
1597 u->encap_limit = p->encap_limit;
1598 u->flowinfo = p->flowinfo;
1600 u->proto = p->proto;
1601 memcpy(u->name, p->name, sizeof(u->name));
1605 * ip6_tnl_ioctl - configure ipv6 tunnels from userspace
1606 * @dev: virtual device associated with tunnel
1607 * @ifr: parameters passed from userspace
1608 * @cmd: command to be performed
1611 * ip6_tnl_ioctl() is used for managing IPv6 tunnels
1614 * The possible commands are the following:
1615 * %SIOCGETTUNNEL: get tunnel parameters for device
1616 * %SIOCADDTUNNEL: add tunnel matching given tunnel parameters
1617 * %SIOCCHGTUNNEL: change tunnel parameters to those given
1618 * %SIOCDELTUNNEL: delete tunnel
1620 * The fallback device "ip6tnl0", created during module
1621 * initialization, can be used for creating other tunnel devices.
1625 * %-EFAULT if unable to copy data to or from userspace,
1626 * %-EPERM if current process hasn't %CAP_NET_ADMIN set
1627 * %-EINVAL if passed tunnel parameters are invalid,
1628 * %-EEXIST if changing a tunnel's parameters would cause a conflict
1629 * %-ENODEV if attempting to change or delete a nonexisting device
1633 ip6_tnl_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
1636 struct ip6_tnl_parm p;
1637 struct __ip6_tnl_parm p1;
1638 struct ip6_tnl *t = netdev_priv(dev);
1639 struct net *net = t->net;
1640 struct ip6_tnl_net *ip6n = net_generic(net, ip6_tnl_net_id);
1642 memset(&p1, 0, sizeof(p1));
1646 if (dev == ip6n->fb_tnl_dev) {
1647 if (copy_from_user(&p, ifr->ifr_ifru.ifru_data, sizeof(p))) {
1651 ip6_tnl_parm_from_user(&p1, &p);
1652 t = ip6_tnl_locate(net, &p1, 0);
1654 t = netdev_priv(dev);
1656 memset(&p, 0, sizeof(p));
1658 ip6_tnl_parm_to_user(&p, &t->parms);
1659 if (copy_to_user(ifr->ifr_ifru.ifru_data, &p, sizeof(p))) {
1666 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
1669 if (copy_from_user(&p, ifr->ifr_ifru.ifru_data, sizeof(p)))
1672 if (p.proto != IPPROTO_IPV6 && p.proto != IPPROTO_IPIP &&
1675 ip6_tnl_parm_from_user(&p1, &p);
1676 t = ip6_tnl_locate(net, &p1, cmd == SIOCADDTUNNEL);
1677 if (cmd == SIOCCHGTUNNEL) {
1679 if (t->dev != dev) {
1684 t = netdev_priv(dev);
1685 if (dev == ip6n->fb_tnl_dev)
1686 err = ip6_tnl0_update(t, &p1);
1688 err = ip6_tnl_update(t, &p1);
1692 ip6_tnl_parm_to_user(&p, &t->parms);
1693 if (copy_to_user(ifr->ifr_ifru.ifru_data, &p, sizeof(p)))
1702 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
1705 if (dev == ip6n->fb_tnl_dev) {
1707 if (copy_from_user(&p, ifr->ifr_ifru.ifru_data, sizeof(p)))
1710 ip6_tnl_parm_from_user(&p1, &p);
1711 t = ip6_tnl_locate(net, &p1, 0);
1715 if (t->dev == ip6n->fb_tnl_dev)
1720 unregister_netdevice(dev);
1729 * ip6_tnl_change_mtu - change mtu manually for tunnel device
1730 * @dev: virtual device associated with tunnel
1731 * @new_mtu: the new mtu
1735 * %-EINVAL if mtu too small
1738 int ip6_tnl_change_mtu(struct net_device *dev, int new_mtu)
1740 struct ip6_tnl *tnl = netdev_priv(dev);
1742 if (tnl->parms.proto == IPPROTO_IPV6) {
1743 if (new_mtu < IPV6_MIN_MTU)
1746 if (new_mtu < ETH_MIN_MTU)
1749 if (tnl->parms.proto == IPPROTO_IPV6 || tnl->parms.proto == 0) {
1750 if (new_mtu > IP6_MAX_MTU - dev->hard_header_len)
1753 if (new_mtu > IP_MAX_MTU - dev->hard_header_len)
1759 EXPORT_SYMBOL(ip6_tnl_change_mtu);
1761 int ip6_tnl_get_iflink(const struct net_device *dev)
1763 struct ip6_tnl *t = netdev_priv(dev);
1765 return t->parms.link;
1767 EXPORT_SYMBOL(ip6_tnl_get_iflink);
1769 int ip6_tnl_encap_add_ops(const struct ip6_tnl_encap_ops *ops,
1772 if (num >= MAX_IPTUN_ENCAP_OPS)
1775 return !cmpxchg((const struct ip6_tnl_encap_ops **)
1776 &ip6tun_encaps[num],
1777 NULL, ops) ? 0 : -1;
1779 EXPORT_SYMBOL(ip6_tnl_encap_add_ops);
1781 int ip6_tnl_encap_del_ops(const struct ip6_tnl_encap_ops *ops,
1786 if (num >= MAX_IPTUN_ENCAP_OPS)
1789 ret = (cmpxchg((const struct ip6_tnl_encap_ops **)
1790 &ip6tun_encaps[num],
1791 ops, NULL) == ops) ? 0 : -1;
1797 EXPORT_SYMBOL(ip6_tnl_encap_del_ops);
1799 int ip6_tnl_encap_setup(struct ip6_tnl *t,
1800 struct ip_tunnel_encap *ipencap)
1804 memset(&t->encap, 0, sizeof(t->encap));
1806 hlen = ip6_encap_hlen(ipencap);
1810 t->encap.type = ipencap->type;
1811 t->encap.sport = ipencap->sport;
1812 t->encap.dport = ipencap->dport;
1813 t->encap.flags = ipencap->flags;
1815 t->encap_hlen = hlen;
1816 t->hlen = t->encap_hlen + t->tun_hlen;
1820 EXPORT_SYMBOL_GPL(ip6_tnl_encap_setup);
1822 static const struct net_device_ops ip6_tnl_netdev_ops = {
1823 .ndo_init = ip6_tnl_dev_init,
1824 .ndo_uninit = ip6_tnl_dev_uninit,
1825 .ndo_start_xmit = ip6_tnl_start_xmit,
1826 .ndo_do_ioctl = ip6_tnl_ioctl,
1827 .ndo_change_mtu = ip6_tnl_change_mtu,
1828 .ndo_get_stats = ip6_get_stats,
1829 .ndo_get_iflink = ip6_tnl_get_iflink,
1832 #define IPXIPX_FEATURES (NETIF_F_SG | \
1833 NETIF_F_FRAGLIST | \
1835 NETIF_F_GSO_SOFTWARE | \
1839 * ip6_tnl_dev_setup - setup virtual tunnel device
1840 * @dev: virtual device associated with tunnel
1843 * Initialize function pointers and device parameters
1846 static void ip6_tnl_dev_setup(struct net_device *dev)
1848 dev->netdev_ops = &ip6_tnl_netdev_ops;
1849 dev->needs_free_netdev = true;
1850 dev->priv_destructor = ip6_dev_free;
1852 dev->type = ARPHRD_TUNNEL6;
1853 dev->flags |= IFF_NOARP;
1854 dev->addr_len = sizeof(struct in6_addr);
1855 dev->features |= NETIF_F_LLTX;
1856 netif_keep_dst(dev);
1858 dev->features |= IPXIPX_FEATURES;
1859 dev->hw_features |= IPXIPX_FEATURES;
1861 /* This perm addr will be used as interface identifier by IPv6 */
1862 dev->addr_assign_type = NET_ADDR_RANDOM;
1863 eth_random_addr(dev->perm_addr);
1868 * ip6_tnl_dev_init_gen - general initializer for all tunnel devices
1869 * @dev: virtual device associated with tunnel
1873 ip6_tnl_dev_init_gen(struct net_device *dev)
1875 struct ip6_tnl *t = netdev_priv(dev);
1880 t->net = dev_net(dev);
1881 dev->tstats = netdev_alloc_pcpu_stats(struct pcpu_sw_netstats);
1885 ret = dst_cache_init(&t->dst_cache, GFP_KERNEL);
1889 ret = gro_cells_init(&t->gro_cells, dev);
1894 t->hlen = t->encap_hlen + t->tun_hlen;
1895 t_hlen = t->hlen + sizeof(struct ipv6hdr);
1897 dev->type = ARPHRD_TUNNEL6;
1898 dev->hard_header_len = LL_MAX_HEADER + t_hlen;
1899 dev->mtu = ETH_DATA_LEN - t_hlen;
1900 if (!(t->parms.flags & IP6_TNL_F_IGN_ENCAP_LIMIT))
1902 dev->min_mtu = ETH_MIN_MTU;
1903 dev->max_mtu = IP6_MAX_MTU - dev->hard_header_len;
1908 dst_cache_destroy(&t->dst_cache);
1910 free_percpu(dev->tstats);
1917 * ip6_tnl_dev_init - initializer for all non fallback tunnel devices
1918 * @dev: virtual device associated with tunnel
1921 static int ip6_tnl_dev_init(struct net_device *dev)
1923 struct ip6_tnl *t = netdev_priv(dev);
1924 int err = ip6_tnl_dev_init_gen(dev);
1928 ip6_tnl_link_config(t);
1929 if (t->parms.collect_md)
1930 netif_keep_dst(dev);
1935 * ip6_fb_tnl_dev_init - initializer for fallback tunnel device
1936 * @dev: fallback device
1941 static int __net_init ip6_fb_tnl_dev_init(struct net_device *dev)
1943 struct ip6_tnl *t = netdev_priv(dev);
1944 struct net *net = dev_net(dev);
1945 struct ip6_tnl_net *ip6n = net_generic(net, ip6_tnl_net_id);
1947 t->parms.proto = IPPROTO_IPV6;
1950 rcu_assign_pointer(ip6n->tnls_wc[0], t);
1954 static int ip6_tnl_validate(struct nlattr *tb[], struct nlattr *data[],
1955 struct netlink_ext_ack *extack)
1959 if (!data || !data[IFLA_IPTUN_PROTO])
1962 proto = nla_get_u8(data[IFLA_IPTUN_PROTO]);
1963 if (proto != IPPROTO_IPV6 &&
1964 proto != IPPROTO_IPIP &&
1971 static void ip6_tnl_netlink_parms(struct nlattr *data[],
1972 struct __ip6_tnl_parm *parms)
1974 memset(parms, 0, sizeof(*parms));
1979 if (data[IFLA_IPTUN_LINK])
1980 parms->link = nla_get_u32(data[IFLA_IPTUN_LINK]);
1982 if (data[IFLA_IPTUN_LOCAL])
1983 parms->laddr = nla_get_in6_addr(data[IFLA_IPTUN_LOCAL]);
1985 if (data[IFLA_IPTUN_REMOTE])
1986 parms->raddr = nla_get_in6_addr(data[IFLA_IPTUN_REMOTE]);
1988 if (data[IFLA_IPTUN_TTL])
1989 parms->hop_limit = nla_get_u8(data[IFLA_IPTUN_TTL]);
1991 if (data[IFLA_IPTUN_ENCAP_LIMIT])
1992 parms->encap_limit = nla_get_u8(data[IFLA_IPTUN_ENCAP_LIMIT]);
1994 if (data[IFLA_IPTUN_FLOWINFO])
1995 parms->flowinfo = nla_get_be32(data[IFLA_IPTUN_FLOWINFO]);
1997 if (data[IFLA_IPTUN_FLAGS])
1998 parms->flags = nla_get_u32(data[IFLA_IPTUN_FLAGS]);
2000 if (data[IFLA_IPTUN_PROTO])
2001 parms->proto = nla_get_u8(data[IFLA_IPTUN_PROTO]);
2003 if (data[IFLA_IPTUN_COLLECT_METADATA])
2004 parms->collect_md = true;
2006 if (data[IFLA_IPTUN_FWMARK])
2007 parms->fwmark = nla_get_u32(data[IFLA_IPTUN_FWMARK]);
2010 static bool ip6_tnl_netlink_encap_parms(struct nlattr *data[],
2011 struct ip_tunnel_encap *ipencap)
2015 memset(ipencap, 0, sizeof(*ipencap));
2020 if (data[IFLA_IPTUN_ENCAP_TYPE]) {
2022 ipencap->type = nla_get_u16(data[IFLA_IPTUN_ENCAP_TYPE]);
2025 if (data[IFLA_IPTUN_ENCAP_FLAGS]) {
2027 ipencap->flags = nla_get_u16(data[IFLA_IPTUN_ENCAP_FLAGS]);
2030 if (data[IFLA_IPTUN_ENCAP_SPORT]) {
2032 ipencap->sport = nla_get_be16(data[IFLA_IPTUN_ENCAP_SPORT]);
2035 if (data[IFLA_IPTUN_ENCAP_DPORT]) {
2037 ipencap->dport = nla_get_be16(data[IFLA_IPTUN_ENCAP_DPORT]);
2043 static int ip6_tnl_newlink(struct net *src_net, struct net_device *dev,
2044 struct nlattr *tb[], struct nlattr *data[],
2045 struct netlink_ext_ack *extack)
2047 struct net *net = dev_net(dev);
2048 struct ip6_tnl_net *ip6n = net_generic(net, ip6_tnl_net_id);
2049 struct ip_tunnel_encap ipencap;
2050 struct ip6_tnl *nt, *t;
2053 nt = netdev_priv(dev);
2055 if (ip6_tnl_netlink_encap_parms(data, &ipencap)) {
2056 err = ip6_tnl_encap_setup(nt, &ipencap);
2061 ip6_tnl_netlink_parms(data, &nt->parms);
2063 if (nt->parms.collect_md) {
2064 if (rtnl_dereference(ip6n->collect_md_tun))
2067 t = ip6_tnl_locate(net, &nt->parms, 0);
2072 err = ip6_tnl_create2(dev);
2073 if (!err && tb[IFLA_MTU])
2074 ip6_tnl_change_mtu(dev, nla_get_u32(tb[IFLA_MTU]));
2079 static int ip6_tnl_changelink(struct net_device *dev, struct nlattr *tb[],
2080 struct nlattr *data[],
2081 struct netlink_ext_ack *extack)
2083 struct ip6_tnl *t = netdev_priv(dev);
2084 struct __ip6_tnl_parm p;
2085 struct net *net = t->net;
2086 struct ip6_tnl_net *ip6n = net_generic(net, ip6_tnl_net_id);
2087 struct ip_tunnel_encap ipencap;
2089 if (dev == ip6n->fb_tnl_dev)
2092 if (ip6_tnl_netlink_encap_parms(data, &ipencap)) {
2093 int err = ip6_tnl_encap_setup(t, &ipencap);
2098 ip6_tnl_netlink_parms(data, &p);
2102 t = ip6_tnl_locate(net, &p, 0);
2107 t = netdev_priv(dev);
2109 return ip6_tnl_update(t, &p);
2112 static void ip6_tnl_dellink(struct net_device *dev, struct list_head *head)
2114 struct net *net = dev_net(dev);
2115 struct ip6_tnl_net *ip6n = net_generic(net, ip6_tnl_net_id);
2117 if (dev != ip6n->fb_tnl_dev)
2118 unregister_netdevice_queue(dev, head);
2121 static size_t ip6_tnl_get_size(const struct net_device *dev)
2124 /* IFLA_IPTUN_LINK */
2126 /* IFLA_IPTUN_LOCAL */
2127 nla_total_size(sizeof(struct in6_addr)) +
2128 /* IFLA_IPTUN_REMOTE */
2129 nla_total_size(sizeof(struct in6_addr)) +
2130 /* IFLA_IPTUN_TTL */
2132 /* IFLA_IPTUN_ENCAP_LIMIT */
2134 /* IFLA_IPTUN_FLOWINFO */
2136 /* IFLA_IPTUN_FLAGS */
2138 /* IFLA_IPTUN_PROTO */
2140 /* IFLA_IPTUN_ENCAP_TYPE */
2142 /* IFLA_IPTUN_ENCAP_FLAGS */
2144 /* IFLA_IPTUN_ENCAP_SPORT */
2146 /* IFLA_IPTUN_ENCAP_DPORT */
2148 /* IFLA_IPTUN_COLLECT_METADATA */
2150 /* IFLA_IPTUN_FWMARK */
2155 static int ip6_tnl_fill_info(struct sk_buff *skb, const struct net_device *dev)
2157 struct ip6_tnl *tunnel = netdev_priv(dev);
2158 struct __ip6_tnl_parm *parm = &tunnel->parms;
2160 if (nla_put_u32(skb, IFLA_IPTUN_LINK, parm->link) ||
2161 nla_put_in6_addr(skb, IFLA_IPTUN_LOCAL, &parm->laddr) ||
2162 nla_put_in6_addr(skb, IFLA_IPTUN_REMOTE, &parm->raddr) ||
2163 nla_put_u8(skb, IFLA_IPTUN_TTL, parm->hop_limit) ||
2164 nla_put_u8(skb, IFLA_IPTUN_ENCAP_LIMIT, parm->encap_limit) ||
2165 nla_put_be32(skb, IFLA_IPTUN_FLOWINFO, parm->flowinfo) ||
2166 nla_put_u32(skb, IFLA_IPTUN_FLAGS, parm->flags) ||
2167 nla_put_u8(skb, IFLA_IPTUN_PROTO, parm->proto) ||
2168 nla_put_u32(skb, IFLA_IPTUN_FWMARK, parm->fwmark))
2169 goto nla_put_failure;
2171 if (nla_put_u16(skb, IFLA_IPTUN_ENCAP_TYPE, tunnel->encap.type) ||
2172 nla_put_be16(skb, IFLA_IPTUN_ENCAP_SPORT, tunnel->encap.sport) ||
2173 nla_put_be16(skb, IFLA_IPTUN_ENCAP_DPORT, tunnel->encap.dport) ||
2174 nla_put_u16(skb, IFLA_IPTUN_ENCAP_FLAGS, tunnel->encap.flags))
2175 goto nla_put_failure;
2177 if (parm->collect_md)
2178 if (nla_put_flag(skb, IFLA_IPTUN_COLLECT_METADATA))
2179 goto nla_put_failure;
2187 struct net *ip6_tnl_get_link_net(const struct net_device *dev)
2189 struct ip6_tnl *tunnel = netdev_priv(dev);
2193 EXPORT_SYMBOL(ip6_tnl_get_link_net);
2195 static const struct nla_policy ip6_tnl_policy[IFLA_IPTUN_MAX + 1] = {
2196 [IFLA_IPTUN_LINK] = { .type = NLA_U32 },
2197 [IFLA_IPTUN_LOCAL] = { .len = sizeof(struct in6_addr) },
2198 [IFLA_IPTUN_REMOTE] = { .len = sizeof(struct in6_addr) },
2199 [IFLA_IPTUN_TTL] = { .type = NLA_U8 },
2200 [IFLA_IPTUN_ENCAP_LIMIT] = { .type = NLA_U8 },
2201 [IFLA_IPTUN_FLOWINFO] = { .type = NLA_U32 },
2202 [IFLA_IPTUN_FLAGS] = { .type = NLA_U32 },
2203 [IFLA_IPTUN_PROTO] = { .type = NLA_U8 },
2204 [IFLA_IPTUN_ENCAP_TYPE] = { .type = NLA_U16 },
2205 [IFLA_IPTUN_ENCAP_FLAGS] = { .type = NLA_U16 },
2206 [IFLA_IPTUN_ENCAP_SPORT] = { .type = NLA_U16 },
2207 [IFLA_IPTUN_ENCAP_DPORT] = { .type = NLA_U16 },
2208 [IFLA_IPTUN_COLLECT_METADATA] = { .type = NLA_FLAG },
2209 [IFLA_IPTUN_FWMARK] = { .type = NLA_U32 },
2212 static struct rtnl_link_ops ip6_link_ops __read_mostly = {
2214 .maxtype = IFLA_IPTUN_MAX,
2215 .policy = ip6_tnl_policy,
2216 .priv_size = sizeof(struct ip6_tnl),
2217 .setup = ip6_tnl_dev_setup,
2218 .validate = ip6_tnl_validate,
2219 .newlink = ip6_tnl_newlink,
2220 .changelink = ip6_tnl_changelink,
2221 .dellink = ip6_tnl_dellink,
2222 .get_size = ip6_tnl_get_size,
2223 .fill_info = ip6_tnl_fill_info,
2224 .get_link_net = ip6_tnl_get_link_net,
2227 static struct xfrm6_tunnel ip4ip6_handler __read_mostly = {
2228 .handler = ip4ip6_rcv,
2229 .err_handler = ip4ip6_err,
2233 static struct xfrm6_tunnel ip6ip6_handler __read_mostly = {
2234 .handler = ip6ip6_rcv,
2235 .err_handler = ip6ip6_err,
2239 static struct xfrm6_tunnel mplsip6_handler __read_mostly = {
2240 .handler = mplsip6_rcv,
2241 .err_handler = mplsip6_err,
2245 static void __net_exit ip6_tnl_destroy_tunnels(struct net *net, struct list_head *list)
2247 struct ip6_tnl_net *ip6n = net_generic(net, ip6_tnl_net_id);
2248 struct net_device *dev, *aux;
2252 for_each_netdev_safe(net, dev, aux)
2253 if (dev->rtnl_link_ops == &ip6_link_ops)
2254 unregister_netdevice_queue(dev, list);
2256 for (h = 0; h < IP6_TUNNEL_HASH_SIZE; h++) {
2257 t = rtnl_dereference(ip6n->tnls_r_l[h]);
2259 /* If dev is in the same netns, it has already
2260 * been added to the list by the previous loop.
2262 if (!net_eq(dev_net(t->dev), net))
2263 unregister_netdevice_queue(t->dev, list);
2264 t = rtnl_dereference(t->next);
2269 static int __net_init ip6_tnl_init_net(struct net *net)
2271 struct ip6_tnl_net *ip6n = net_generic(net, ip6_tnl_net_id);
2272 struct ip6_tnl *t = NULL;
2275 ip6n->tnls[0] = ip6n->tnls_wc;
2276 ip6n->tnls[1] = ip6n->tnls_r_l;
2278 if (!net_has_fallback_tunnels(net))
2281 ip6n->fb_tnl_dev = alloc_netdev(sizeof(struct ip6_tnl), "ip6tnl0",
2282 NET_NAME_UNKNOWN, ip6_tnl_dev_setup);
2284 if (!ip6n->fb_tnl_dev)
2286 dev_net_set(ip6n->fb_tnl_dev, net);
2287 ip6n->fb_tnl_dev->rtnl_link_ops = &ip6_link_ops;
2288 /* FB netdevice is special: we have one, and only one per netns.
2289 * Allowing to move it to another netns is clearly unsafe.
2291 ip6n->fb_tnl_dev->features |= NETIF_F_NETNS_LOCAL;
2293 err = ip6_fb_tnl_dev_init(ip6n->fb_tnl_dev);
2297 err = register_netdev(ip6n->fb_tnl_dev);
2301 t = netdev_priv(ip6n->fb_tnl_dev);
2303 strcpy(t->parms.name, ip6n->fb_tnl_dev->name);
2307 free_netdev(ip6n->fb_tnl_dev);
2312 static void __net_exit ip6_tnl_exit_batch_net(struct list_head *net_list)
2318 list_for_each_entry(net, net_list, exit_list)
2319 ip6_tnl_destroy_tunnels(net, &list);
2320 unregister_netdevice_many(&list);
2324 static struct pernet_operations ip6_tnl_net_ops = {
2325 .init = ip6_tnl_init_net,
2326 .exit_batch = ip6_tnl_exit_batch_net,
2327 .id = &ip6_tnl_net_id,
2328 .size = sizeof(struct ip6_tnl_net),
2332 * ip6_tunnel_init - register protocol and reserve needed resources
2334 * Return: 0 on success
2337 static int __init ip6_tunnel_init(void)
2341 if (!ipv6_mod_enabled())
2344 err = register_pernet_device(&ip6_tnl_net_ops);
2348 err = xfrm6_tunnel_register(&ip4ip6_handler, AF_INET);
2350 pr_err("%s: can't register ip4ip6\n", __func__);
2354 err = xfrm6_tunnel_register(&ip6ip6_handler, AF_INET6);
2356 pr_err("%s: can't register ip6ip6\n", __func__);
2360 if (ip6_tnl_mpls_supported()) {
2361 err = xfrm6_tunnel_register(&mplsip6_handler, AF_MPLS);
2363 pr_err("%s: can't register mplsip6\n", __func__);
2368 err = rtnl_link_register(&ip6_link_ops);
2370 goto rtnl_link_failed;
2375 if (ip6_tnl_mpls_supported())
2376 xfrm6_tunnel_deregister(&mplsip6_handler, AF_MPLS);
2378 xfrm6_tunnel_deregister(&ip6ip6_handler, AF_INET6);
2380 xfrm6_tunnel_deregister(&ip4ip6_handler, AF_INET);
2382 unregister_pernet_device(&ip6_tnl_net_ops);
2388 * ip6_tunnel_cleanup - free resources and unregister protocol
2391 static void __exit ip6_tunnel_cleanup(void)
2393 rtnl_link_unregister(&ip6_link_ops);
2394 if (xfrm6_tunnel_deregister(&ip4ip6_handler, AF_INET))
2395 pr_info("%s: can't deregister ip4ip6\n", __func__);
2397 if (xfrm6_tunnel_deregister(&ip6ip6_handler, AF_INET6))
2398 pr_info("%s: can't deregister ip6ip6\n", __func__);
2400 if (ip6_tnl_mpls_supported() &&
2401 xfrm6_tunnel_deregister(&mplsip6_handler, AF_MPLS))
2402 pr_info("%s: can't deregister mplsip6\n", __func__);
2403 unregister_pernet_device(&ip6_tnl_net_ops);
2406 module_init(ip6_tunnel_init);
2407 module_exit(ip6_tunnel_cleanup);