2 * IPv6 virtual tunneling interface
4 * Copyright (C) 2013 secunet Security Networks AG
7 * Steffen Klassert <steffen.klassert@secunet.com>
10 * net/ipv6/ip6_tunnel.c
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version
15 * 2 of the License, or (at your option) any later version.
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/if_tunnel.h>
28 #include <linux/net.h>
29 #include <linux/in6.h>
30 #include <linux/netdevice.h>
31 #include <linux/if_arp.h>
32 #include <linux/icmpv6.h>
33 #include <linux/init.h>
34 #include <linux/route.h>
35 #include <linux/rtnetlink.h>
36 #include <linux/netfilter_ipv6.h>
37 #include <linux/slab.h>
38 #include <linux/hash.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/net_namespace.h>
52 #include <net/netns/generic.h>
54 #define HASH_SIZE_SHIFT 5
55 #define HASH_SIZE (1 << HASH_SIZE_SHIFT)
57 static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
59 u32 hash = ipv6_addr_hash(addr1) ^ ipv6_addr_hash(addr2);
61 return hash_32(hash, HASH_SIZE_SHIFT);
64 static int vti6_dev_init(struct net_device *dev);
65 static void vti6_dev_setup(struct net_device *dev);
66 static struct rtnl_link_ops vti6_link_ops __read_mostly;
68 static int vti6_net_id __read_mostly;
70 /* the vti6 tunnel fallback device */
71 struct net_device *fb_tnl_dev;
72 /* lists for storing tunnels in use */
73 struct ip6_tnl __rcu *tnls_r_l[HASH_SIZE];
74 struct ip6_tnl __rcu *tnls_wc[1];
75 struct ip6_tnl __rcu **tnls[2];
78 #define for_each_vti6_tunnel_rcu(start) \
79 for (t = rcu_dereference(start); t; t = rcu_dereference(t->next))
82 * vti6_tnl_lookup - fetch tunnel matching the end-point addresses
83 * @net: network namespace
84 * @remote: the address of the tunnel exit-point
85 * @local: the address of the tunnel entry-point
88 * tunnel matching given end-points if found,
89 * else fallback tunnel if its device is up,
92 static struct ip6_tnl *
93 vti6_tnl_lookup(struct net *net, const struct in6_addr *remote,
94 const struct in6_addr *local)
96 unsigned int hash = HASH(remote, local);
98 struct vti6_net *ip6n = net_generic(net, vti6_net_id);
100 for_each_vti6_tunnel_rcu(ip6n->tnls_r_l[hash]) {
101 if (ipv6_addr_equal(local, &t->parms.laddr) &&
102 ipv6_addr_equal(remote, &t->parms.raddr) &&
103 (t->dev->flags & IFF_UP))
106 t = rcu_dereference(ip6n->tnls_wc[0]);
107 if (t && (t->dev->flags & IFF_UP))
114 * vti6_tnl_bucket - get head of list matching given tunnel parameters
115 * @p: parameters containing tunnel end-points
118 * vti6_tnl_bucket() returns the head of the list matching the
119 * &struct in6_addr entries laddr and raddr in @p.
121 * Return: head of IPv6 tunnel list
123 static struct ip6_tnl __rcu **
124 vti6_tnl_bucket(struct vti6_net *ip6n, const struct __ip6_tnl_parm *p)
126 const struct in6_addr *remote = &p->raddr;
127 const struct in6_addr *local = &p->laddr;
131 if (!ipv6_addr_any(remote) || !ipv6_addr_any(local)) {
133 h = HASH(remote, local);
135 return &ip6n->tnls[prio][h];
139 vti6_tnl_link(struct vti6_net *ip6n, struct ip6_tnl *t)
141 struct ip6_tnl __rcu **tp = vti6_tnl_bucket(ip6n, &t->parms);
143 rcu_assign_pointer(t->next , rtnl_dereference(*tp));
144 rcu_assign_pointer(*tp, t);
148 vti6_tnl_unlink(struct vti6_net *ip6n, struct ip6_tnl *t)
150 struct ip6_tnl __rcu **tp;
151 struct ip6_tnl *iter;
153 for (tp = vti6_tnl_bucket(ip6n, &t->parms);
154 (iter = rtnl_dereference(*tp)) != NULL;
157 rcu_assign_pointer(*tp, t->next);
163 static void vti6_dev_free(struct net_device *dev)
165 free_percpu(dev->tstats);
169 static int vti6_tnl_create2(struct net_device *dev)
171 struct ip6_tnl *t = netdev_priv(dev);
172 struct net *net = dev_net(dev);
173 struct vti6_net *ip6n = net_generic(net, vti6_net_id);
176 err = vti6_dev_init(dev);
180 err = register_netdevice(dev);
184 strcpy(t->parms.name, dev->name);
185 dev->rtnl_link_ops = &vti6_link_ops;
188 vti6_tnl_link(ip6n, t);
196 static struct ip6_tnl *vti6_tnl_create(struct net *net, struct __ip6_tnl_parm *p)
198 struct net_device *dev;
204 strlcpy(name, p->name, IFNAMSIZ);
206 sprintf(name, "ip6_vti%%d");
208 dev = alloc_netdev(sizeof(*t), name, vti6_dev_setup);
212 dev_net_set(dev, net);
214 t = netdev_priv(dev);
216 t->net = dev_net(dev);
218 err = vti6_tnl_create2(dev);
231 * vti6_locate - find or create tunnel matching given parameters
232 * @net: network namespace
233 * @p: tunnel parameters
234 * @create: != 0 if allowed to create new tunnel if no match found
237 * vti6_locate() first tries to locate an existing tunnel
238 * based on @parms. If this is unsuccessful, but @create is set a new
239 * tunnel device is created and registered for use.
242 * matching tunnel or NULL
244 static struct ip6_tnl *vti6_locate(struct net *net, struct __ip6_tnl_parm *p,
247 const struct in6_addr *remote = &p->raddr;
248 const struct in6_addr *local = &p->laddr;
249 struct ip6_tnl __rcu **tp;
251 struct vti6_net *ip6n = net_generic(net, vti6_net_id);
253 for (tp = vti6_tnl_bucket(ip6n, p);
254 (t = rtnl_dereference(*tp)) != NULL;
256 if (ipv6_addr_equal(local, &t->parms.laddr) &&
257 ipv6_addr_equal(remote, &t->parms.raddr))
262 return vti6_tnl_create(net, p);
266 * vti6_dev_uninit - tunnel device uninitializer
267 * @dev: the device to be destroyed
270 * vti6_dev_uninit() removes tunnel from its list
272 static void vti6_dev_uninit(struct net_device *dev)
274 struct ip6_tnl *t = netdev_priv(dev);
275 struct net *net = dev_net(dev);
276 struct vti6_net *ip6n = net_generic(net, vti6_net_id);
278 if (dev == ip6n->fb_tnl_dev)
279 RCU_INIT_POINTER(ip6n->tnls_wc[0], NULL);
281 vti6_tnl_unlink(ip6n, t);
282 ip6_tnl_dst_reset(t);
286 static int vti6_rcv(struct sk_buff *skb)
289 const struct ipv6hdr *ipv6h = ipv6_hdr(skb);
293 if ((t = vti6_tnl_lookup(dev_net(skb->dev), &ipv6h->saddr,
294 &ipv6h->daddr)) != NULL) {
295 struct pcpu_tstats *tstats;
297 if (t->parms.proto != IPPROTO_IPV6 && t->parms.proto != 0) {
302 if (!xfrm6_policy_check(NULL, XFRM_POLICY_IN, skb)) {
307 if (!ip6_tnl_rcv_ctl(t, &ipv6h->daddr, &ipv6h->saddr)) {
308 t->dev->stats.rx_dropped++;
313 tstats = this_cpu_ptr(t->dev->tstats);
314 u64_stats_update_begin(&tstats->syncp);
315 tstats->rx_packets++;
316 tstats->rx_bytes += skb->len;
317 u64_stats_update_end(&tstats->syncp);
335 * vti6_addr_conflict - compare packet addresses to tunnel's own
336 * @t: the outgoing tunnel device
337 * @hdr: IPv6 header from the incoming packet
340 * Avoid trivial tunneling loop by checking that tunnel exit-point
341 * doesn't match source of incoming packet.
348 vti6_addr_conflict(const struct ip6_tnl *t, const struct ipv6hdr *hdr)
350 return ipv6_addr_equal(&t->parms.raddr, &hdr->saddr);
354 * vti6_xmit - send a packet
355 * @skb: the outgoing socket buffer
356 * @dev: the outgoing tunnel device
358 static int vti6_xmit(struct sk_buff *skb, struct net_device *dev)
360 struct net *net = dev_net(dev);
361 struct ip6_tnl *t = netdev_priv(dev);
362 struct net_device_stats *stats = &t->dev->stats;
363 struct dst_entry *dst = NULL, *ndst = NULL;
365 struct ipv6hdr *ipv6h = ipv6_hdr(skb);
366 struct net_device *tdev;
369 if ((t->parms.proto != IPPROTO_IPV6 && t->parms.proto != 0) ||
370 !ip6_tnl_xmit_ctl(t) || vti6_addr_conflict(t, ipv6h))
373 dst = ip6_tnl_dst_check(t);
375 memcpy(&fl6, &t->fl.u.ip6, sizeof(fl6));
377 ndst = ip6_route_output(net, NULL, &fl6);
380 goto tx_err_link_failure;
381 ndst = xfrm_lookup(net, ndst, flowi6_to_flowi(&fl6), NULL, 0);
385 goto tx_err_link_failure;
390 if (!dst->xfrm || dst->xfrm->props.mode != XFRM_MODE_TUNNEL)
391 goto tx_err_link_failure;
397 net_warn_ratelimited("%s: Local routing loop detected!\n",
399 goto tx_err_dst_release;
404 skb_dst_set_noref(skb, dst);
406 ip6tunnel_xmit(skb, dev);
408 dev->mtu = dst_mtu(ndst);
409 ip6_tnl_dst_store(t, ndst);
414 stats->tx_carrier_errors++;
415 dst_link_failure(skb);
422 vti6_tnl_xmit(struct sk_buff *skb, struct net_device *dev)
424 struct ip6_tnl *t = netdev_priv(dev);
425 struct net_device_stats *stats = &t->dev->stats;
428 switch (skb->protocol) {
429 case htons(ETH_P_IPV6):
430 ret = vti6_xmit(skb, dev);
448 static void vti6_link_config(struct ip6_tnl *t)
450 struct dst_entry *dst;
451 struct net_device *dev = t->dev;
452 struct __ip6_tnl_parm *p = &t->parms;
453 struct flowi6 *fl6 = &t->fl.u.ip6;
455 memcpy(dev->dev_addr, &p->laddr, sizeof(struct in6_addr));
456 memcpy(dev->broadcast, &p->raddr, sizeof(struct in6_addr));
458 /* Set up flowi template */
459 fl6->saddr = p->laddr;
460 fl6->daddr = p->raddr;
461 fl6->flowi6_oif = p->link;
462 fl6->flowi6_mark = be32_to_cpu(p->i_key);
463 fl6->flowi6_proto = p->proto;
466 p->flags &= ~(IP6_TNL_F_CAP_XMIT | IP6_TNL_F_CAP_RCV |
467 IP6_TNL_F_CAP_PER_PACKET);
468 p->flags |= ip6_tnl_get_cap(t, &p->laddr, &p->raddr);
470 if (p->flags & IP6_TNL_F_CAP_XMIT && p->flags & IP6_TNL_F_CAP_RCV)
471 dev->flags |= IFF_POINTOPOINT;
473 dev->flags &= ~IFF_POINTOPOINT;
475 dev->iflink = p->link;
477 if (p->flags & IP6_TNL_F_CAP_XMIT) {
479 dst = ip6_route_output(dev_net(dev), NULL, fl6);
483 dst = xfrm_lookup(dev_net(dev), dst, flowi6_to_flowi(fl6),
489 dev->hard_header_len = dst->dev->hard_header_len;
491 dev->mtu = dst_mtu(dst);
493 if (dev->mtu < IPV6_MIN_MTU)
494 dev->mtu = IPV6_MIN_MTU;
501 * vti6_tnl_change - update the tunnel parameters
502 * @t: tunnel to be changed
503 * @p: tunnel configuration parameters
506 * vti6_tnl_change() updates the tunnel parameters
509 vti6_tnl_change(struct ip6_tnl *t, const struct __ip6_tnl_parm *p)
511 t->parms.laddr = p->laddr;
512 t->parms.raddr = p->raddr;
513 t->parms.link = p->link;
514 t->parms.i_key = p->i_key;
515 t->parms.o_key = p->o_key;
516 t->parms.proto = p->proto;
517 ip6_tnl_dst_reset(t);
522 static int vti6_update(struct ip6_tnl *t, struct __ip6_tnl_parm *p)
524 struct net *net = dev_net(t->dev);
525 struct vti6_net *ip6n = net_generic(net, vti6_net_id);
528 vti6_tnl_unlink(ip6n, t);
530 err = vti6_tnl_change(t, p);
531 vti6_tnl_link(ip6n, t);
532 netdev_state_change(t->dev);
537 vti6_parm_from_user(struct __ip6_tnl_parm *p, const struct ip6_tnl_parm2 *u)
546 memcpy(p->name, u->name, sizeof(u->name));
550 vti6_parm_to_user(struct ip6_tnl_parm2 *u, const struct __ip6_tnl_parm *p)
559 memcpy(u->name, p->name, sizeof(u->name));
563 * vti6_tnl_ioctl - configure vti6 tunnels from userspace
564 * @dev: virtual device associated with tunnel
565 * @ifr: parameters passed from userspace
566 * @cmd: command to be performed
569 * vti6_ioctl() is used for managing vti6 tunnels
572 * The possible commands are the following:
573 * %SIOCGETTUNNEL: get tunnel parameters for device
574 * %SIOCADDTUNNEL: add tunnel matching given tunnel parameters
575 * %SIOCCHGTUNNEL: change tunnel parameters to those given
576 * %SIOCDELTUNNEL: delete tunnel
578 * The fallback device "ip6_vti0", created during module
579 * initialization, can be used for creating other tunnel devices.
583 * %-EFAULT if unable to copy data to or from userspace,
584 * %-EPERM if current process hasn't %CAP_NET_ADMIN set
585 * %-EINVAL if passed tunnel parameters are invalid,
586 * %-EEXIST if changing a tunnel's parameters would cause a conflict
587 * %-ENODEV if attempting to change or delete a nonexisting device
590 vti6_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
593 struct ip6_tnl_parm2 p;
594 struct __ip6_tnl_parm p1;
595 struct ip6_tnl *t = NULL;
596 struct net *net = dev_net(dev);
597 struct vti6_net *ip6n = net_generic(net, vti6_net_id);
601 if (dev == ip6n->fb_tnl_dev) {
602 if (copy_from_user(&p, ifr->ifr_ifru.ifru_data, sizeof(p))) {
606 vti6_parm_from_user(&p1, &p);
607 t = vti6_locate(net, &p1, 0);
609 memset(&p, 0, sizeof(p));
612 t = netdev_priv(dev);
613 vti6_parm_to_user(&p, &t->parms);
614 if (copy_to_user(ifr->ifr_ifru.ifru_data, &p, sizeof(p)))
620 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
623 if (copy_from_user(&p, ifr->ifr_ifru.ifru_data, sizeof(p)))
626 if (p.proto != IPPROTO_IPV6 && p.proto != 0)
628 vti6_parm_from_user(&p1, &p);
629 t = vti6_locate(net, &p1, cmd == SIOCADDTUNNEL);
630 if (dev != ip6n->fb_tnl_dev && cmd == SIOCCHGTUNNEL) {
637 t = netdev_priv(dev);
639 err = vti6_update(t, &p1);
643 vti6_parm_to_user(&p, &t->parms);
644 if (copy_to_user(ifr->ifr_ifru.ifru_data, &p, sizeof(p)))
648 err = (cmd == SIOCADDTUNNEL ? -ENOBUFS : -ENOENT);
652 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
655 if (dev == ip6n->fb_tnl_dev) {
657 if (copy_from_user(&p, ifr->ifr_ifru.ifru_data, sizeof(p)))
660 vti6_parm_from_user(&p1, &p);
661 t = vti6_locate(net, &p1, 0);
665 if (t->dev == ip6n->fb_tnl_dev)
670 unregister_netdevice(dev);
679 * vti6_tnl_change_mtu - change mtu manually for tunnel device
680 * @dev: virtual device associated with tunnel
681 * @new_mtu: the new mtu
685 * %-EINVAL if mtu too small
687 static int vti6_change_mtu(struct net_device *dev, int new_mtu)
689 if (new_mtu < IPV6_MIN_MTU)
696 static const struct net_device_ops vti6_netdev_ops = {
697 .ndo_uninit = vti6_dev_uninit,
698 .ndo_start_xmit = vti6_tnl_xmit,
699 .ndo_do_ioctl = vti6_ioctl,
700 .ndo_change_mtu = vti6_change_mtu,
701 .ndo_get_stats64 = ip_tunnel_get_stats64,
705 * vti6_dev_setup - setup virtual tunnel device
706 * @dev: virtual device associated with tunnel
709 * Initialize function pointers and device parameters
711 static void vti6_dev_setup(struct net_device *dev)
715 dev->netdev_ops = &vti6_netdev_ops;
716 dev->destructor = vti6_dev_free;
718 dev->type = ARPHRD_TUNNEL6;
719 dev->hard_header_len = LL_MAX_HEADER + sizeof(struct ipv6hdr);
720 dev->mtu = ETH_DATA_LEN;
721 t = netdev_priv(dev);
722 dev->flags |= IFF_NOARP;
723 dev->addr_len = sizeof(struct in6_addr);
724 dev->features |= NETIF_F_NETNS_LOCAL;
725 dev->priv_flags &= ~IFF_XMIT_DST_RELEASE;
729 * vti6_dev_init_gen - general initializer for all tunnel devices
730 * @dev: virtual device associated with tunnel
732 static inline int vti6_dev_init_gen(struct net_device *dev)
734 struct ip6_tnl *t = netdev_priv(dev);
738 t->net = dev_net(dev);
739 dev->tstats = alloc_percpu(struct pcpu_tstats);
742 for_each_possible_cpu(i) {
743 struct pcpu_tstats *stats;
744 stats = per_cpu_ptr(dev->tstats, i);
745 u64_stats_init(&stats->syncp);
751 * vti6_dev_init - initializer for all non fallback tunnel devices
752 * @dev: virtual device associated with tunnel
754 static int vti6_dev_init(struct net_device *dev)
756 struct ip6_tnl *t = netdev_priv(dev);
757 int err = vti6_dev_init_gen(dev);
766 * vti6_fb_tnl_dev_init - initializer for fallback tunnel device
767 * @dev: fallback device
771 static int __net_init vti6_fb_tnl_dev_init(struct net_device *dev)
773 struct ip6_tnl *t = netdev_priv(dev);
774 struct net *net = dev_net(dev);
775 struct vti6_net *ip6n = net_generic(net, vti6_net_id);
776 int err = vti6_dev_init_gen(dev);
781 t->parms.proto = IPPROTO_IPV6;
786 rcu_assign_pointer(ip6n->tnls_wc[0], t);
790 static int vti6_validate(struct nlattr *tb[], struct nlattr *data[])
795 static void vti6_netlink_parms(struct nlattr *data[],
796 struct __ip6_tnl_parm *parms)
798 memset(parms, 0, sizeof(*parms));
803 if (data[IFLA_VTI_LINK])
804 parms->link = nla_get_u32(data[IFLA_VTI_LINK]);
806 if (data[IFLA_VTI_LOCAL])
807 nla_memcpy(&parms->laddr, data[IFLA_VTI_LOCAL],
808 sizeof(struct in6_addr));
810 if (data[IFLA_VTI_REMOTE])
811 nla_memcpy(&parms->raddr, data[IFLA_VTI_REMOTE],
812 sizeof(struct in6_addr));
814 if (data[IFLA_VTI_IKEY])
815 parms->i_key = nla_get_be32(data[IFLA_VTI_IKEY]);
817 if (data[IFLA_VTI_OKEY])
818 parms->o_key = nla_get_be32(data[IFLA_VTI_OKEY]);
821 static int vti6_newlink(struct net *src_net, struct net_device *dev,
822 struct nlattr *tb[], struct nlattr *data[])
824 struct net *net = dev_net(dev);
827 nt = netdev_priv(dev);
828 vti6_netlink_parms(data, &nt->parms);
830 nt->parms.proto = IPPROTO_IPV6;
832 if (vti6_locate(net, &nt->parms, 0))
835 return vti6_tnl_create2(dev);
838 static int vti6_changelink(struct net_device *dev, struct nlattr *tb[],
839 struct nlattr *data[])
842 struct __ip6_tnl_parm p;
843 struct net *net = dev_net(dev);
844 struct vti6_net *ip6n = net_generic(net, vti6_net_id);
846 if (dev == ip6n->fb_tnl_dev)
849 vti6_netlink_parms(data, &p);
851 t = vti6_locate(net, &p, 0);
857 t = netdev_priv(dev);
859 return vti6_update(t, &p);
862 static size_t vti6_get_size(const struct net_device *dev)
868 nla_total_size(sizeof(struct in6_addr)) +
869 /* IFLA_VTI_REMOTE */
870 nla_total_size(sizeof(struct in6_addr)) +
878 static int vti6_fill_info(struct sk_buff *skb, const struct net_device *dev)
880 struct ip6_tnl *tunnel = netdev_priv(dev);
881 struct __ip6_tnl_parm *parm = &tunnel->parms;
883 if (nla_put_u32(skb, IFLA_VTI_LINK, parm->link) ||
884 nla_put(skb, IFLA_VTI_LOCAL, sizeof(struct in6_addr),
886 nla_put(skb, IFLA_VTI_REMOTE, sizeof(struct in6_addr),
888 nla_put_be32(skb, IFLA_VTI_IKEY, parm->i_key) ||
889 nla_put_be32(skb, IFLA_VTI_OKEY, parm->o_key))
890 goto nla_put_failure;
897 static const struct nla_policy vti6_policy[IFLA_VTI_MAX + 1] = {
898 [IFLA_VTI_LINK] = { .type = NLA_U32 },
899 [IFLA_VTI_LOCAL] = { .len = sizeof(struct in6_addr) },
900 [IFLA_VTI_REMOTE] = { .len = sizeof(struct in6_addr) },
901 [IFLA_VTI_IKEY] = { .type = NLA_U32 },
902 [IFLA_VTI_OKEY] = { .type = NLA_U32 },
905 static struct rtnl_link_ops vti6_link_ops __read_mostly = {
907 .maxtype = IFLA_VTI_MAX,
908 .policy = vti6_policy,
909 .priv_size = sizeof(struct ip6_tnl),
910 .setup = vti6_dev_setup,
911 .validate = vti6_validate,
912 .newlink = vti6_newlink,
913 .changelink = vti6_changelink,
914 .get_size = vti6_get_size,
915 .fill_info = vti6_fill_info,
918 static struct xfrm_tunnel_notifier vti6_handler __read_mostly = {
923 static void __net_exit vti6_destroy_tunnels(struct vti6_net *ip6n)
929 for (h = 0; h < HASH_SIZE; h++) {
930 t = rtnl_dereference(ip6n->tnls_r_l[h]);
932 unregister_netdevice_queue(t->dev, &list);
933 t = rtnl_dereference(t->next);
937 t = rtnl_dereference(ip6n->tnls_wc[0]);
938 unregister_netdevice_queue(t->dev, &list);
939 unregister_netdevice_many(&list);
942 static int __net_init vti6_init_net(struct net *net)
944 struct vti6_net *ip6n = net_generic(net, vti6_net_id);
945 struct ip6_tnl *t = NULL;
948 ip6n->tnls[0] = ip6n->tnls_wc;
949 ip6n->tnls[1] = ip6n->tnls_r_l;
952 ip6n->fb_tnl_dev = alloc_netdev(sizeof(struct ip6_tnl), "ip6_vti0",
955 if (!ip6n->fb_tnl_dev)
957 dev_net_set(ip6n->fb_tnl_dev, net);
959 err = vti6_fb_tnl_dev_init(ip6n->fb_tnl_dev);
963 err = register_netdev(ip6n->fb_tnl_dev);
967 t = netdev_priv(ip6n->fb_tnl_dev);
969 strcpy(t->parms.name, ip6n->fb_tnl_dev->name);
973 vti6_dev_free(ip6n->fb_tnl_dev);
978 static void __net_exit vti6_exit_net(struct net *net)
980 struct vti6_net *ip6n = net_generic(net, vti6_net_id);
983 vti6_destroy_tunnels(ip6n);
987 static struct pernet_operations vti6_net_ops = {
988 .init = vti6_init_net,
989 .exit = vti6_exit_net,
991 .size = sizeof(struct vti6_net),
995 * vti6_tunnel_init - register protocol and reserve needed resources
997 * Return: 0 on success
999 static int __init vti6_tunnel_init(void)
1003 err = register_pernet_device(&vti6_net_ops);
1007 err = xfrm6_mode_tunnel_input_register(&vti6_handler);
1009 pr_err("%s: can't register vti6\n", __func__);
1012 err = rtnl_link_register(&vti6_link_ops);
1014 goto rtnl_link_failed;
1019 xfrm6_mode_tunnel_input_deregister(&vti6_handler);
1021 unregister_pernet_device(&vti6_net_ops);
1027 * vti6_tunnel_cleanup - free resources and unregister protocol
1029 static void __exit vti6_tunnel_cleanup(void)
1031 rtnl_link_unregister(&vti6_link_ops);
1032 if (xfrm6_mode_tunnel_input_deregister(&vti6_handler))
1033 pr_info("%s: can't deregister vti6\n", __func__);
1035 unregister_pernet_device(&vti6_net_ops);
1038 module_init(vti6_tunnel_init);
1039 module_exit(vti6_tunnel_cleanup);
1040 MODULE_LICENSE("GPL");
1041 MODULE_ALIAS_RTNL_LINK("vti6");
1042 MODULE_ALIAS_NETDEV("ip6_vti0");
1043 MODULE_AUTHOR("Steffen Klassert");
1044 MODULE_DESCRIPTION("IPv6 virtual tunnel interface");