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/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>
39 #include <linux/uaccess.h>
40 #include <linux/atomic.h>
44 #include <net/ip_tunnels.h>
46 #include <net/ip6_route.h>
47 #include <net/addrconf.h>
48 #include <net/ip6_tunnel.h>
50 #include <net/net_namespace.h>
51 #include <net/netns/generic.h>
53 #define HASH_SIZE_SHIFT 5
54 #define HASH_SIZE (1 << HASH_SIZE_SHIFT)
56 static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
58 u32 hash = ipv6_addr_hash(addr1) ^ ipv6_addr_hash(addr2);
60 return hash_32(hash, HASH_SIZE_SHIFT);
63 static int vti6_dev_init(struct net_device *dev);
64 static void vti6_dev_setup(struct net_device *dev);
65 static struct rtnl_link_ops vti6_link_ops __read_mostly;
67 static int vti6_net_id __read_mostly;
69 /* the vti6 tunnel fallback device */
70 struct net_device *fb_tnl_dev;
71 /* lists for storing tunnels in use */
72 struct ip6_tnl __rcu *tnls_r_l[HASH_SIZE];
73 struct ip6_tnl __rcu *tnls_wc[1];
74 struct ip6_tnl __rcu **tnls[2];
77 #define for_each_vti6_tunnel_rcu(start) \
78 for (t = rcu_dereference(start); t; t = rcu_dereference(t->next))
81 * vti6_tnl_lookup - fetch tunnel matching the end-point addresses
82 * @net: network namespace
83 * @remote: the address of the tunnel exit-point
84 * @local: the address of the tunnel entry-point
87 * tunnel matching given end-points if found,
88 * else fallback tunnel if its device is up,
91 static struct ip6_tnl *
92 vti6_tnl_lookup(struct net *net, const struct in6_addr *remote,
93 const struct in6_addr *local)
95 unsigned int hash = HASH(remote, local);
97 struct vti6_net *ip6n = net_generic(net, vti6_net_id);
99 for_each_vti6_tunnel_rcu(ip6n->tnls_r_l[hash]) {
100 if (ipv6_addr_equal(local, &t->parms.laddr) &&
101 ipv6_addr_equal(remote, &t->parms.raddr) &&
102 (t->dev->flags & IFF_UP))
105 t = rcu_dereference(ip6n->tnls_wc[0]);
106 if (t && (t->dev->flags & IFF_UP))
113 * vti6_tnl_bucket - get head of list matching given tunnel parameters
114 * @p: parameters containing tunnel end-points
117 * vti6_tnl_bucket() returns the head of the list matching the
118 * &struct in6_addr entries laddr and raddr in @p.
120 * Return: head of IPv6 tunnel list
122 static struct ip6_tnl __rcu **
123 vti6_tnl_bucket(struct vti6_net *ip6n, const struct __ip6_tnl_parm *p)
125 const struct in6_addr *remote = &p->raddr;
126 const struct in6_addr *local = &p->laddr;
130 if (!ipv6_addr_any(remote) || !ipv6_addr_any(local)) {
132 h = HASH(remote, local);
134 return &ip6n->tnls[prio][h];
138 vti6_tnl_link(struct vti6_net *ip6n, struct ip6_tnl *t)
140 struct ip6_tnl __rcu **tp = vti6_tnl_bucket(ip6n, &t->parms);
142 rcu_assign_pointer(t->next , rtnl_dereference(*tp));
143 rcu_assign_pointer(*tp, t);
147 vti6_tnl_unlink(struct vti6_net *ip6n, struct ip6_tnl *t)
149 struct ip6_tnl __rcu **tp;
150 struct ip6_tnl *iter;
152 for (tp = vti6_tnl_bucket(ip6n, &t->parms);
153 (iter = rtnl_dereference(*tp)) != NULL;
156 rcu_assign_pointer(*tp, t->next);
162 static void vti6_dev_free(struct net_device *dev)
164 free_percpu(dev->tstats);
168 static int vti6_tnl_create2(struct net_device *dev)
170 struct ip6_tnl *t = netdev_priv(dev);
171 struct net *net = dev_net(dev);
172 struct vti6_net *ip6n = net_generic(net, vti6_net_id);
175 err = register_netdevice(dev);
179 strcpy(t->parms.name, dev->name);
180 dev->rtnl_link_ops = &vti6_link_ops;
183 vti6_tnl_link(ip6n, t);
191 static struct ip6_tnl *vti6_tnl_create(struct net *net, struct __ip6_tnl_parm *p)
193 struct net_device *dev;
199 strlcpy(name, p->name, IFNAMSIZ);
201 sprintf(name, "ip6_vti%%d");
203 dev = alloc_netdev(sizeof(*t), name, vti6_dev_setup);
207 dev_net_set(dev, net);
209 t = netdev_priv(dev);
211 t->net = dev_net(dev);
213 err = vti6_tnl_create2(dev);
226 * vti6_locate - find or create tunnel matching given parameters
227 * @net: network namespace
228 * @p: tunnel parameters
229 * @create: != 0 if allowed to create new tunnel if no match found
232 * vti6_locate() first tries to locate an existing tunnel
233 * based on @parms. If this is unsuccessful, but @create is set a new
234 * tunnel device is created and registered for use.
237 * matching tunnel or NULL
239 static struct ip6_tnl *vti6_locate(struct net *net, struct __ip6_tnl_parm *p,
242 const struct in6_addr *remote = &p->raddr;
243 const struct in6_addr *local = &p->laddr;
244 struct ip6_tnl __rcu **tp;
246 struct vti6_net *ip6n = net_generic(net, vti6_net_id);
248 for (tp = vti6_tnl_bucket(ip6n, p);
249 (t = rtnl_dereference(*tp)) != NULL;
251 if (ipv6_addr_equal(local, &t->parms.laddr) &&
252 ipv6_addr_equal(remote, &t->parms.raddr))
257 return vti6_tnl_create(net, p);
261 * vti6_dev_uninit - tunnel device uninitializer
262 * @dev: the device to be destroyed
265 * vti6_dev_uninit() removes tunnel from its list
267 static void vti6_dev_uninit(struct net_device *dev)
269 struct ip6_tnl *t = netdev_priv(dev);
270 struct net *net = dev_net(dev);
271 struct vti6_net *ip6n = net_generic(net, vti6_net_id);
273 if (dev == ip6n->fb_tnl_dev)
274 RCU_INIT_POINTER(ip6n->tnls_wc[0], NULL);
276 vti6_tnl_unlink(ip6n, t);
277 ip6_tnl_dst_reset(t);
281 static int vti6_rcv(struct sk_buff *skb)
284 const struct ipv6hdr *ipv6h = ipv6_hdr(skb);
288 if ((t = vti6_tnl_lookup(dev_net(skb->dev), &ipv6h->saddr,
289 &ipv6h->daddr)) != NULL) {
290 struct pcpu_sw_netstats *tstats;
292 if (t->parms.proto != IPPROTO_IPV6 && t->parms.proto != 0) {
297 if (!xfrm6_policy_check(NULL, XFRM_POLICY_IN, skb)) {
302 if (!ip6_tnl_rcv_ctl(t, &ipv6h->daddr, &ipv6h->saddr)) {
303 t->dev->stats.rx_dropped++;
308 tstats = this_cpu_ptr(t->dev->tstats);
309 u64_stats_update_begin(&tstats->syncp);
310 tstats->rx_packets++;
311 tstats->rx_bytes += skb->len;
312 u64_stats_update_end(&tstats->syncp);
330 * vti6_addr_conflict - compare packet addresses to tunnel's own
331 * @t: the outgoing tunnel device
332 * @hdr: IPv6 header from the incoming packet
335 * Avoid trivial tunneling loop by checking that tunnel exit-point
336 * doesn't match source of incoming packet.
343 vti6_addr_conflict(const struct ip6_tnl *t, const struct ipv6hdr *hdr)
345 return ipv6_addr_equal(&t->parms.raddr, &hdr->saddr);
349 * vti6_xmit - send a packet
350 * @skb: the outgoing socket buffer
351 * @dev: the outgoing tunnel device
353 static int vti6_xmit(struct sk_buff *skb, struct net_device *dev)
355 struct net *net = dev_net(dev);
356 struct ip6_tnl *t = netdev_priv(dev);
357 struct net_device_stats *stats = &t->dev->stats;
358 struct dst_entry *dst = NULL, *ndst = NULL;
360 struct ipv6hdr *ipv6h = ipv6_hdr(skb);
361 struct net_device *tdev;
364 if ((t->parms.proto != IPPROTO_IPV6 && t->parms.proto != 0) ||
365 !ip6_tnl_xmit_ctl(t) || vti6_addr_conflict(t, ipv6h))
368 dst = ip6_tnl_dst_check(t);
370 memcpy(&fl6, &t->fl.u.ip6, sizeof(fl6));
372 ndst = ip6_route_output(net, NULL, &fl6);
375 goto tx_err_link_failure;
376 ndst = xfrm_lookup(net, ndst, flowi6_to_flowi(&fl6), NULL, 0);
380 goto tx_err_link_failure;
385 if (!dst->xfrm || dst->xfrm->props.mode != XFRM_MODE_TUNNEL)
386 goto tx_err_link_failure;
392 net_warn_ratelimited("%s: Local routing loop detected!\n",
394 goto tx_err_dst_release;
399 skb_dst_set_noref(skb, dst);
401 ip6tunnel_xmit(skb, dev);
403 dev->mtu = dst_mtu(ndst);
404 ip6_tnl_dst_store(t, ndst);
409 stats->tx_carrier_errors++;
410 dst_link_failure(skb);
417 vti6_tnl_xmit(struct sk_buff *skb, struct net_device *dev)
419 struct ip6_tnl *t = netdev_priv(dev);
420 struct net_device_stats *stats = &t->dev->stats;
423 switch (skb->protocol) {
424 case htons(ETH_P_IPV6):
425 ret = vti6_xmit(skb, dev);
443 static void vti6_link_config(struct ip6_tnl *t)
445 struct dst_entry *dst;
446 struct net_device *dev = t->dev;
447 struct __ip6_tnl_parm *p = &t->parms;
448 struct flowi6 *fl6 = &t->fl.u.ip6;
450 memcpy(dev->dev_addr, &p->laddr, sizeof(struct in6_addr));
451 memcpy(dev->broadcast, &p->raddr, sizeof(struct in6_addr));
453 /* Set up flowi template */
454 fl6->saddr = p->laddr;
455 fl6->daddr = p->raddr;
456 fl6->flowi6_oif = p->link;
457 fl6->flowi6_mark = be32_to_cpu(p->i_key);
458 fl6->flowi6_proto = p->proto;
461 p->flags &= ~(IP6_TNL_F_CAP_XMIT | IP6_TNL_F_CAP_RCV |
462 IP6_TNL_F_CAP_PER_PACKET);
463 p->flags |= ip6_tnl_get_cap(t, &p->laddr, &p->raddr);
465 if (p->flags & IP6_TNL_F_CAP_XMIT && p->flags & IP6_TNL_F_CAP_RCV)
466 dev->flags |= IFF_POINTOPOINT;
468 dev->flags &= ~IFF_POINTOPOINT;
470 dev->iflink = p->link;
472 if (p->flags & IP6_TNL_F_CAP_XMIT) {
474 dst = ip6_route_output(dev_net(dev), NULL, fl6);
478 dst = xfrm_lookup(dev_net(dev), dst, flowi6_to_flowi(fl6),
484 dev->hard_header_len = dst->dev->hard_header_len;
486 dev->mtu = dst_mtu(dst);
488 if (dev->mtu < IPV6_MIN_MTU)
489 dev->mtu = IPV6_MIN_MTU;
496 * vti6_tnl_change - update the tunnel parameters
497 * @t: tunnel to be changed
498 * @p: tunnel configuration parameters
501 * vti6_tnl_change() updates the tunnel parameters
504 vti6_tnl_change(struct ip6_tnl *t, const struct __ip6_tnl_parm *p)
506 t->parms.laddr = p->laddr;
507 t->parms.raddr = p->raddr;
508 t->parms.link = p->link;
509 t->parms.i_key = p->i_key;
510 t->parms.o_key = p->o_key;
511 t->parms.proto = p->proto;
512 ip6_tnl_dst_reset(t);
517 static int vti6_update(struct ip6_tnl *t, struct __ip6_tnl_parm *p)
519 struct net *net = dev_net(t->dev);
520 struct vti6_net *ip6n = net_generic(net, vti6_net_id);
523 vti6_tnl_unlink(ip6n, t);
525 err = vti6_tnl_change(t, p);
526 vti6_tnl_link(ip6n, t);
527 netdev_state_change(t->dev);
532 vti6_parm_from_user(struct __ip6_tnl_parm *p, const struct ip6_tnl_parm2 *u)
541 memcpy(p->name, u->name, sizeof(u->name));
545 vti6_parm_to_user(struct ip6_tnl_parm2 *u, const struct __ip6_tnl_parm *p)
554 memcpy(u->name, p->name, sizeof(u->name));
558 * vti6_tnl_ioctl - configure vti6 tunnels from userspace
559 * @dev: virtual device associated with tunnel
560 * @ifr: parameters passed from userspace
561 * @cmd: command to be performed
564 * vti6_ioctl() is used for managing vti6 tunnels
567 * The possible commands are the following:
568 * %SIOCGETTUNNEL: get tunnel parameters for device
569 * %SIOCADDTUNNEL: add tunnel matching given tunnel parameters
570 * %SIOCCHGTUNNEL: change tunnel parameters to those given
571 * %SIOCDELTUNNEL: delete tunnel
573 * The fallback device "ip6_vti0", created during module
574 * initialization, can be used for creating other tunnel devices.
578 * %-EFAULT if unable to copy data to or from userspace,
579 * %-EPERM if current process hasn't %CAP_NET_ADMIN set
580 * %-EINVAL if passed tunnel parameters are invalid,
581 * %-EEXIST if changing a tunnel's parameters would cause a conflict
582 * %-ENODEV if attempting to change or delete a nonexisting device
585 vti6_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
588 struct ip6_tnl_parm2 p;
589 struct __ip6_tnl_parm p1;
590 struct ip6_tnl *t = NULL;
591 struct net *net = dev_net(dev);
592 struct vti6_net *ip6n = net_generic(net, vti6_net_id);
596 if (dev == ip6n->fb_tnl_dev) {
597 if (copy_from_user(&p, ifr->ifr_ifru.ifru_data, sizeof(p))) {
601 vti6_parm_from_user(&p1, &p);
602 t = vti6_locate(net, &p1, 0);
604 memset(&p, 0, sizeof(p));
607 t = netdev_priv(dev);
608 vti6_parm_to_user(&p, &t->parms);
609 if (copy_to_user(ifr->ifr_ifru.ifru_data, &p, sizeof(p)))
615 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
618 if (copy_from_user(&p, ifr->ifr_ifru.ifru_data, sizeof(p)))
621 if (p.proto != IPPROTO_IPV6 && p.proto != 0)
623 vti6_parm_from_user(&p1, &p);
624 t = vti6_locate(net, &p1, cmd == SIOCADDTUNNEL);
625 if (dev != ip6n->fb_tnl_dev && cmd == SIOCCHGTUNNEL) {
632 t = netdev_priv(dev);
634 err = vti6_update(t, &p1);
638 vti6_parm_to_user(&p, &t->parms);
639 if (copy_to_user(ifr->ifr_ifru.ifru_data, &p, sizeof(p)))
643 err = (cmd == SIOCADDTUNNEL ? -ENOBUFS : -ENOENT);
647 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
650 if (dev == ip6n->fb_tnl_dev) {
652 if (copy_from_user(&p, ifr->ifr_ifru.ifru_data, sizeof(p)))
655 vti6_parm_from_user(&p1, &p);
656 t = vti6_locate(net, &p1, 0);
660 if (t->dev == ip6n->fb_tnl_dev)
665 unregister_netdevice(dev);
674 * vti6_tnl_change_mtu - change mtu manually for tunnel device
675 * @dev: virtual device associated with tunnel
676 * @new_mtu: the new mtu
680 * %-EINVAL if mtu too small
682 static int vti6_change_mtu(struct net_device *dev, int new_mtu)
684 if (new_mtu < IPV6_MIN_MTU)
691 static const struct net_device_ops vti6_netdev_ops = {
692 .ndo_init = vti6_dev_init,
693 .ndo_uninit = vti6_dev_uninit,
694 .ndo_start_xmit = vti6_tnl_xmit,
695 .ndo_do_ioctl = vti6_ioctl,
696 .ndo_change_mtu = vti6_change_mtu,
697 .ndo_get_stats64 = ip_tunnel_get_stats64,
701 * vti6_dev_setup - setup virtual tunnel device
702 * @dev: virtual device associated with tunnel
705 * Initialize function pointers and device parameters
707 static void vti6_dev_setup(struct net_device *dev)
711 dev->netdev_ops = &vti6_netdev_ops;
712 dev->destructor = vti6_dev_free;
714 dev->type = ARPHRD_TUNNEL6;
715 dev->hard_header_len = LL_MAX_HEADER + sizeof(struct ipv6hdr);
716 dev->mtu = ETH_DATA_LEN;
717 t = netdev_priv(dev);
718 dev->flags |= IFF_NOARP;
719 dev->addr_len = sizeof(struct in6_addr);
720 dev->features |= NETIF_F_NETNS_LOCAL;
721 dev->priv_flags &= ~IFF_XMIT_DST_RELEASE;
725 * vti6_dev_init_gen - general initializer for all tunnel devices
726 * @dev: virtual device associated with tunnel
728 static inline int vti6_dev_init_gen(struct net_device *dev)
730 struct ip6_tnl *t = netdev_priv(dev);
734 t->net = dev_net(dev);
735 dev->tstats = alloc_percpu(struct pcpu_sw_netstats);
738 for_each_possible_cpu(i) {
739 struct pcpu_sw_netstats *stats;
740 stats = per_cpu_ptr(dev->tstats, i);
741 u64_stats_init(&stats->syncp);
747 * vti6_dev_init - initializer for all non fallback tunnel devices
748 * @dev: virtual device associated with tunnel
750 static int vti6_dev_init(struct net_device *dev)
752 struct ip6_tnl *t = netdev_priv(dev);
753 int err = vti6_dev_init_gen(dev);
762 * vti6_fb_tnl_dev_init - initializer for fallback tunnel device
763 * @dev: fallback device
767 static int __net_init vti6_fb_tnl_dev_init(struct net_device *dev)
769 struct ip6_tnl *t = netdev_priv(dev);
770 struct net *net = dev_net(dev);
771 struct vti6_net *ip6n = net_generic(net, vti6_net_id);
773 t->parms.proto = IPPROTO_IPV6;
776 rcu_assign_pointer(ip6n->tnls_wc[0], t);
780 static int vti6_validate(struct nlattr *tb[], struct nlattr *data[])
785 static void vti6_netlink_parms(struct nlattr *data[],
786 struct __ip6_tnl_parm *parms)
788 memset(parms, 0, sizeof(*parms));
793 if (data[IFLA_VTI_LINK])
794 parms->link = nla_get_u32(data[IFLA_VTI_LINK]);
796 if (data[IFLA_VTI_LOCAL])
797 nla_memcpy(&parms->laddr, data[IFLA_VTI_LOCAL],
798 sizeof(struct in6_addr));
800 if (data[IFLA_VTI_REMOTE])
801 nla_memcpy(&parms->raddr, data[IFLA_VTI_REMOTE],
802 sizeof(struct in6_addr));
804 if (data[IFLA_VTI_IKEY])
805 parms->i_key = nla_get_be32(data[IFLA_VTI_IKEY]);
807 if (data[IFLA_VTI_OKEY])
808 parms->o_key = nla_get_be32(data[IFLA_VTI_OKEY]);
811 static int vti6_newlink(struct net *src_net, struct net_device *dev,
812 struct nlattr *tb[], struct nlattr *data[])
814 struct net *net = dev_net(dev);
817 nt = netdev_priv(dev);
818 vti6_netlink_parms(data, &nt->parms);
820 nt->parms.proto = IPPROTO_IPV6;
822 if (vti6_locate(net, &nt->parms, 0))
825 return vti6_tnl_create2(dev);
828 static int vti6_changelink(struct net_device *dev, struct nlattr *tb[],
829 struct nlattr *data[])
832 struct __ip6_tnl_parm p;
833 struct net *net = dev_net(dev);
834 struct vti6_net *ip6n = net_generic(net, vti6_net_id);
836 if (dev == ip6n->fb_tnl_dev)
839 vti6_netlink_parms(data, &p);
841 t = vti6_locate(net, &p, 0);
847 t = netdev_priv(dev);
849 return vti6_update(t, &p);
852 static size_t vti6_get_size(const struct net_device *dev)
858 nla_total_size(sizeof(struct in6_addr)) +
859 /* IFLA_VTI_REMOTE */
860 nla_total_size(sizeof(struct in6_addr)) +
868 static int vti6_fill_info(struct sk_buff *skb, const struct net_device *dev)
870 struct ip6_tnl *tunnel = netdev_priv(dev);
871 struct __ip6_tnl_parm *parm = &tunnel->parms;
873 if (nla_put_u32(skb, IFLA_VTI_LINK, parm->link) ||
874 nla_put(skb, IFLA_VTI_LOCAL, sizeof(struct in6_addr),
876 nla_put(skb, IFLA_VTI_REMOTE, sizeof(struct in6_addr),
878 nla_put_be32(skb, IFLA_VTI_IKEY, parm->i_key) ||
879 nla_put_be32(skb, IFLA_VTI_OKEY, parm->o_key))
880 goto nla_put_failure;
887 static const struct nla_policy vti6_policy[IFLA_VTI_MAX + 1] = {
888 [IFLA_VTI_LINK] = { .type = NLA_U32 },
889 [IFLA_VTI_LOCAL] = { .len = sizeof(struct in6_addr) },
890 [IFLA_VTI_REMOTE] = { .len = sizeof(struct in6_addr) },
891 [IFLA_VTI_IKEY] = { .type = NLA_U32 },
892 [IFLA_VTI_OKEY] = { .type = NLA_U32 },
895 static struct rtnl_link_ops vti6_link_ops __read_mostly = {
897 .maxtype = IFLA_VTI_MAX,
898 .policy = vti6_policy,
899 .priv_size = sizeof(struct ip6_tnl),
900 .setup = vti6_dev_setup,
901 .validate = vti6_validate,
902 .newlink = vti6_newlink,
903 .changelink = vti6_changelink,
904 .get_size = vti6_get_size,
905 .fill_info = vti6_fill_info,
908 static struct xfrm_tunnel_notifier vti6_handler __read_mostly = {
913 static void __net_exit vti6_destroy_tunnels(struct vti6_net *ip6n)
919 for (h = 0; h < HASH_SIZE; h++) {
920 t = rtnl_dereference(ip6n->tnls_r_l[h]);
922 unregister_netdevice_queue(t->dev, &list);
923 t = rtnl_dereference(t->next);
927 t = rtnl_dereference(ip6n->tnls_wc[0]);
928 unregister_netdevice_queue(t->dev, &list);
929 unregister_netdevice_many(&list);
932 static int __net_init vti6_init_net(struct net *net)
934 struct vti6_net *ip6n = net_generic(net, vti6_net_id);
935 struct ip6_tnl *t = NULL;
938 ip6n->tnls[0] = ip6n->tnls_wc;
939 ip6n->tnls[1] = ip6n->tnls_r_l;
942 ip6n->fb_tnl_dev = alloc_netdev(sizeof(struct ip6_tnl), "ip6_vti0",
945 if (!ip6n->fb_tnl_dev)
947 dev_net_set(ip6n->fb_tnl_dev, net);
949 err = vti6_fb_tnl_dev_init(ip6n->fb_tnl_dev);
953 err = register_netdev(ip6n->fb_tnl_dev);
957 t = netdev_priv(ip6n->fb_tnl_dev);
959 strcpy(t->parms.name, ip6n->fb_tnl_dev->name);
963 vti6_dev_free(ip6n->fb_tnl_dev);
968 static void __net_exit vti6_exit_net(struct net *net)
970 struct vti6_net *ip6n = net_generic(net, vti6_net_id);
973 vti6_destroy_tunnels(ip6n);
977 static struct pernet_operations vti6_net_ops = {
978 .init = vti6_init_net,
979 .exit = vti6_exit_net,
981 .size = sizeof(struct vti6_net),
985 * vti6_tunnel_init - register protocol and reserve needed resources
987 * Return: 0 on success
989 static int __init vti6_tunnel_init(void)
993 err = register_pernet_device(&vti6_net_ops);
997 err = xfrm6_mode_tunnel_input_register(&vti6_handler);
999 pr_err("%s: can't register vti6\n", __func__);
1002 err = rtnl_link_register(&vti6_link_ops);
1004 goto rtnl_link_failed;
1009 xfrm6_mode_tunnel_input_deregister(&vti6_handler);
1011 unregister_pernet_device(&vti6_net_ops);
1017 * vti6_tunnel_cleanup - free resources and unregister protocol
1019 static void __exit vti6_tunnel_cleanup(void)
1021 rtnl_link_unregister(&vti6_link_ops);
1022 if (xfrm6_mode_tunnel_input_deregister(&vti6_handler))
1023 pr_info("%s: can't deregister vti6\n", __func__);
1025 unregister_pernet_device(&vti6_net_ops);
1028 module_init(vti6_tunnel_init);
1029 module_exit(vti6_tunnel_cleanup);
1030 MODULE_LICENSE("GPL");
1031 MODULE_ALIAS_RTNL_LINK("vti6");
1032 MODULE_ALIAS_NETDEV("ip6_vti0");
1033 MODULE_AUTHOR("Steffen Klassert");
1034 MODULE_DESCRIPTION("IPv6 virtual tunnel interface");