^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * IPv6 virtual tunneling interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 2013 secunet Security Networks AG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Author:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * Steffen Klassert <steffen.klassert@secunet.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * Based on:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * net/ipv6/ip6_tunnel.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/capability.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/sockios.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/icmp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/if.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/in.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/ip.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <linux/net.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <linux/in6.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <linux/netdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <linux/if_arp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <linux/icmpv6.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #include <linux/route.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #include <linux/rtnetlink.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #include <linux/netfilter_ipv6.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #include <linux/hash.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #include <linux/atomic.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #include <net/icmp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #include <net/ip.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #include <net/ip_tunnels.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) #include <net/ipv6.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) #include <net/ip6_route.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) #include <net/addrconf.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) #include <net/ip6_tunnel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) #include <net/xfrm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) #include <net/net_namespace.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) #include <net/netns/generic.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) #include <linux/etherdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) #define IP6_VTI_HASH_SIZE_SHIFT 5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) #define IP6_VTI_HASH_SIZE (1 << IP6_VTI_HASH_SIZE_SHIFT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) u32 hash = ipv6_addr_hash(addr1) ^ ipv6_addr_hash(addr2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) return hash_32(hash, IP6_VTI_HASH_SIZE_SHIFT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) static int vti6_dev_init(struct net_device *dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) static void vti6_dev_setup(struct net_device *dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) static struct rtnl_link_ops vti6_link_ops __read_mostly;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) static unsigned int vti6_net_id __read_mostly;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) struct vti6_net {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) /* the vti6 tunnel fallback device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) struct net_device *fb_tnl_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) /* lists for storing tunnels in use */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) struct ip6_tnl __rcu *tnls_r_l[IP6_VTI_HASH_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) struct ip6_tnl __rcu *tnls_wc[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) struct ip6_tnl __rcu **tnls[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) #define for_each_vti6_tunnel_rcu(start) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) for (t = rcu_dereference(start); t; t = rcu_dereference(t->next))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) * vti6_tnl_lookup - fetch tunnel matching the end-point addresses
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) * @net: network namespace
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) * @remote: the address of the tunnel exit-point
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) * @local: the address of the tunnel entry-point
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) * Return:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) * tunnel matching given end-points if found,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) * else fallback tunnel if its device is up,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) * else %NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) static struct ip6_tnl *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) vti6_tnl_lookup(struct net *net, const struct in6_addr *remote,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) const struct in6_addr *local)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) unsigned int hash = HASH(remote, local);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) struct ip6_tnl *t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) struct vti6_net *ip6n = net_generic(net, vti6_net_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) struct in6_addr any;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) for_each_vti6_tunnel_rcu(ip6n->tnls_r_l[hash]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) if (ipv6_addr_equal(local, &t->parms.laddr) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) ipv6_addr_equal(remote, &t->parms.raddr) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) (t->dev->flags & IFF_UP))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) return t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) memset(&any, 0, sizeof(any));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) hash = HASH(&any, local);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) for_each_vti6_tunnel_rcu(ip6n->tnls_r_l[hash]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) if (ipv6_addr_equal(local, &t->parms.laddr) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) (t->dev->flags & IFF_UP))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) return t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) hash = HASH(remote, &any);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) for_each_vti6_tunnel_rcu(ip6n->tnls_r_l[hash]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) if (ipv6_addr_equal(remote, &t->parms.raddr) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) (t->dev->flags & IFF_UP))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) return t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) t = rcu_dereference(ip6n->tnls_wc[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) if (t && (t->dev->flags & IFF_UP))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) return t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) * vti6_tnl_bucket - get head of list matching given tunnel parameters
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) * @p: parameters containing tunnel end-points
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) * Description:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) * vti6_tnl_bucket() returns the head of the list matching the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) * &struct in6_addr entries laddr and raddr in @p.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) * Return: head of IPv6 tunnel list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) static struct ip6_tnl __rcu **
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) vti6_tnl_bucket(struct vti6_net *ip6n, const struct __ip6_tnl_parm *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) const struct in6_addr *remote = &p->raddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) const struct in6_addr *local = &p->laddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) unsigned int h = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) int prio = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) if (!ipv6_addr_any(remote) || !ipv6_addr_any(local)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) prio = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) h = HASH(remote, local);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) return &ip6n->tnls[prio][h];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) vti6_tnl_link(struct vti6_net *ip6n, struct ip6_tnl *t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) struct ip6_tnl __rcu **tp = vti6_tnl_bucket(ip6n, &t->parms);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) rcu_assign_pointer(t->next , rtnl_dereference(*tp));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) rcu_assign_pointer(*tp, t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) vti6_tnl_unlink(struct vti6_net *ip6n, struct ip6_tnl *t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) struct ip6_tnl __rcu **tp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) struct ip6_tnl *iter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) for (tp = vti6_tnl_bucket(ip6n, &t->parms);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) (iter = rtnl_dereference(*tp)) != NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) tp = &iter->next) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) if (t == iter) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) rcu_assign_pointer(*tp, t->next);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) static void vti6_dev_free(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) free_percpu(dev->tstats);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) static int vti6_tnl_create2(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) struct ip6_tnl *t = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) struct net *net = dev_net(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) struct vti6_net *ip6n = net_generic(net, vti6_net_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) dev->rtnl_link_ops = &vti6_link_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) err = register_netdevice(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) strcpy(t->parms.name, dev->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) vti6_tnl_link(ip6n, t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) static struct ip6_tnl *vti6_tnl_create(struct net *net, struct __ip6_tnl_parm *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) struct net_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) struct ip6_tnl *t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) char name[IFNAMSIZ];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) if (p->name[0]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) if (!dev_valid_name(p->name))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) goto failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) strlcpy(name, p->name, IFNAMSIZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) sprintf(name, "ip6_vti%%d");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) dev = alloc_netdev(sizeof(*t), name, NET_NAME_UNKNOWN, vti6_dev_setup);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) if (!dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) goto failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) dev_net_set(dev, net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) t = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) t->parms = *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) t->net = dev_net(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) err = vti6_tnl_create2(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) goto failed_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) return t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) failed_free:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) free_netdev(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) failed:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) * vti6_locate - find or create tunnel matching given parameters
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) * @net: network namespace
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) * @p: tunnel parameters
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) * @create: != 0 if allowed to create new tunnel if no match found
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) * Description:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) * vti6_locate() first tries to locate an existing tunnel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) * based on @parms. If this is unsuccessful, but @create is set a new
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) * tunnel device is created and registered for use.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) * Return:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) * matching tunnel or NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) static struct ip6_tnl *vti6_locate(struct net *net, struct __ip6_tnl_parm *p,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) int create)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) const struct in6_addr *remote = &p->raddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) const struct in6_addr *local = &p->laddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) struct ip6_tnl __rcu **tp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) struct ip6_tnl *t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) struct vti6_net *ip6n = net_generic(net, vti6_net_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) for (tp = vti6_tnl_bucket(ip6n, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) (t = rtnl_dereference(*tp)) != NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) tp = &t->next) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) if (ipv6_addr_equal(local, &t->parms.laddr) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) ipv6_addr_equal(remote, &t->parms.raddr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) if (create)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) return t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) if (!create)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) return vti6_tnl_create(net, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) * vti6_dev_uninit - tunnel device uninitializer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) * @dev: the device to be destroyed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) * Description:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) * vti6_dev_uninit() removes tunnel from its list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) static void vti6_dev_uninit(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) struct ip6_tnl *t = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) struct vti6_net *ip6n = net_generic(t->net, vti6_net_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) if (dev == ip6n->fb_tnl_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) RCU_INIT_POINTER(ip6n->tnls_wc[0], NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) vti6_tnl_unlink(ip6n, t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) dev_put(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) static int vti6_input_proto(struct sk_buff *skb, int nexthdr, __be32 spi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) int encap_type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) struct ip6_tnl *t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) const struct ipv6hdr *ipv6h = ipv6_hdr(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) t = vti6_tnl_lookup(dev_net(skb->dev), &ipv6h->saddr, &ipv6h->daddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) if (t) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) if (t->parms.proto != IPPROTO_IPV6 && t->parms.proto != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) goto discard;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) if (!xfrm6_policy_check(NULL, XFRM_POLICY_IN, skb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) goto discard;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) ipv6h = ipv6_hdr(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) if (!ip6_tnl_rcv_ctl(t, &ipv6h->daddr, &ipv6h->saddr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) t->dev->stats.rx_dropped++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) goto discard;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) XFRM_TUNNEL_SKB_CB(skb)->tunnel.ip6 = t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) XFRM_SPI_SKB_CB(skb)->family = AF_INET6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) XFRM_SPI_SKB_CB(skb)->daddroff = offsetof(struct ipv6hdr, daddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) return xfrm_input(skb, nexthdr, spi, encap_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) discard:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) static int vti6_rcv(struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) int nexthdr = skb_network_header(skb)[IP6CB(skb)->nhoff];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) return vti6_input_proto(skb, nexthdr, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) static int vti6_rcv_cb(struct sk_buff *skb, int err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) unsigned short family;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) struct net_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) struct xfrm_state *x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) const struct xfrm_mode *inner_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) struct ip6_tnl *t = XFRM_TUNNEL_SKB_CB(skb)->tunnel.ip6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) u32 orig_mark = skb->mark;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) if (!t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) dev = t->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) dev->stats.rx_errors++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) dev->stats.rx_dropped++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) x = xfrm_input_state(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) inner_mode = &x->inner_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) if (x->sel.family == AF_UNSPEC) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) inner_mode = xfrm_ip2inner_mode(x, XFRM_MODE_SKB_CB(skb)->protocol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) if (inner_mode == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) XFRM_INC_STATS(dev_net(skb->dev),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) LINUX_MIB_XFRMINSTATEMODEERROR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) family = inner_mode->family;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) skb->mark = be32_to_cpu(t->parms.i_key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) ret = xfrm_policy_check(NULL, XFRM_POLICY_IN, skb, family);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) skb->mark = orig_mark;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) return -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) skb_scrub_packet(skb, !net_eq(t->net, dev_net(skb->dev)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) skb->dev = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) dev_sw_netstats_rx_add(dev, skb->len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) * vti6_addr_conflict - compare packet addresses to tunnel's own
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) * @t: the outgoing tunnel device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) * @hdr: IPv6 header from the incoming packet
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) * Description:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) * Avoid trivial tunneling loop by checking that tunnel exit-point
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) * doesn't match source of incoming packet.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) * Return:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) * 1 if conflict,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) * 0 else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) static inline bool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) vti6_addr_conflict(const struct ip6_tnl *t, const struct ipv6hdr *hdr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) return ipv6_addr_equal(&t->parms.raddr, &hdr->saddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) static bool vti6_state_check(const struct xfrm_state *x,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) const struct in6_addr *dst,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) const struct in6_addr *src)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) xfrm_address_t *daddr = (xfrm_address_t *)dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) xfrm_address_t *saddr = (xfrm_address_t *)src;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) /* if there is no transform then this tunnel is not functional.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) * Or if the xfrm is not mode tunnel.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) if (!x || x->props.mode != XFRM_MODE_TUNNEL ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) x->props.family != AF_INET6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) if (ipv6_addr_any(dst))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) return xfrm_addr_equal(saddr, &x->props.saddr, AF_INET6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) if (!xfrm_state_addr_check(x, daddr, saddr, AF_INET6))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) * vti6_xmit - send a packet
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) * @skb: the outgoing socket buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) * @dev: the outgoing tunnel device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) * @fl: the flow informations for the xfrm_lookup
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) vti6_xmit(struct sk_buff *skb, struct net_device *dev, struct flowi *fl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) struct ip6_tnl *t = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) struct net_device_stats *stats = &t->dev->stats;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) struct dst_entry *dst = skb_dst(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) struct net_device *tdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) struct xfrm_state *x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) int pkt_len = skb->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) int err = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) int mtu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) if (!dst) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) switch (skb->protocol) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) case htons(ETH_P_IP): {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) struct rtable *rt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) fl->u.ip4.flowi4_oif = dev->ifindex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) fl->u.ip4.flowi4_flags |= FLOWI_FLAG_ANYSRC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) rt = __ip_route_output_key(dev_net(dev), &fl->u.ip4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) if (IS_ERR(rt))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) goto tx_err_link_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) dst = &rt->dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) skb_dst_set(skb, dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) case htons(ETH_P_IPV6):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) fl->u.ip6.flowi6_oif = dev->ifindex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) fl->u.ip6.flowi6_flags |= FLOWI_FLAG_ANYSRC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) dst = ip6_route_output(dev_net(dev), NULL, &fl->u.ip6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) if (dst->error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) dst_release(dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) dst = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) goto tx_err_link_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) skb_dst_set(skb, dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) goto tx_err_link_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) dst_hold(dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) dst = xfrm_lookup_route(t->net, dst, fl, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) if (IS_ERR(dst)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) err = PTR_ERR(dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) dst = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) goto tx_err_link_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) if (dst->flags & DST_XFRM_QUEUE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) goto queued;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) x = dst->xfrm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) if (!vti6_state_check(x, &t->parms.raddr, &t->parms.laddr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) goto tx_err_link_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) if (!ip6_tnl_xmit_ctl(t, (const struct in6_addr *)&x->props.saddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) (const struct in6_addr *)&x->id.daddr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) goto tx_err_link_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) tdev = dst->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) if (tdev == dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) stats->collisions++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) net_warn_ratelimited("%s: Local routing loop detected!\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) t->parms.name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) goto tx_err_dst_release;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) mtu = dst_mtu(dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) if (skb->len > mtu) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) skb_dst_update_pmtu_no_confirm(skb, mtu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) if (skb->protocol == htons(ETH_P_IPV6)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) if (mtu < IPV6_MIN_MTU)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) mtu = IPV6_MIN_MTU;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) icmpv6_ndo_send(skb, ICMPV6_PKT_TOOBIG, 0, mtu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) icmp_ndo_send(skb, ICMP_DEST_UNREACH, ICMP_FRAG_NEEDED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) htonl(mtu));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) err = -EMSGSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) goto tx_err_dst_release;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) queued:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) skb_scrub_packet(skb, !net_eq(t->net, dev_net(dev)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) skb_dst_set(skb, dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) skb->dev = skb_dst(skb)->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) err = dst_output(t->net, skb->sk, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) if (net_xmit_eval(err) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) err = pkt_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) iptunnel_xmit_stats(dev, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) tx_err_link_failure:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) stats->tx_carrier_errors++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) dst_link_failure(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) tx_err_dst_release:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) dst_release(dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) static netdev_tx_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) vti6_tnl_xmit(struct sk_buff *skb, struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) struct ip6_tnl *t = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) struct net_device_stats *stats = &t->dev->stats;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) struct flowi fl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) if (!pskb_inet_may_pull(skb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) goto tx_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) memset(&fl, 0, sizeof(fl));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) switch (skb->protocol) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) case htons(ETH_P_IPV6):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) if ((t->parms.proto != IPPROTO_IPV6 && t->parms.proto != 0) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) vti6_addr_conflict(t, ipv6_hdr(skb)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) goto tx_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) xfrm_decode_session(skb, &fl, AF_INET6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) memset(IP6CB(skb), 0, sizeof(*IP6CB(skb)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) case htons(ETH_P_IP):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) xfrm_decode_session(skb, &fl, AF_INET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) memset(IPCB(skb), 0, sizeof(*IPCB(skb)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) goto tx_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) /* override mark with tunnel output key */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) fl.flowi_mark = be32_to_cpu(t->parms.o_key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) ret = vti6_xmit(skb, dev, &fl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) goto tx_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) return NETDEV_TX_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) tx_err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) stats->tx_errors++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) stats->tx_dropped++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) return NETDEV_TX_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) static int vti6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) u8 type, u8 code, int offset, __be32 info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) __be32 spi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) __u32 mark;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) struct xfrm_state *x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) struct ip6_tnl *t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) struct ip_esp_hdr *esph;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) struct ip_auth_hdr *ah;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) struct ip_comp_hdr *ipch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) struct net *net = dev_net(skb->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) const struct ipv6hdr *iph = (const struct ipv6hdr *)skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) int protocol = iph->nexthdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) t = vti6_tnl_lookup(dev_net(skb->dev), &iph->daddr, &iph->saddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) if (!t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) mark = be32_to_cpu(t->parms.o_key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) switch (protocol) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) case IPPROTO_ESP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) esph = (struct ip_esp_hdr *)(skb->data + offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) spi = esph->spi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) case IPPROTO_AH:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) ah = (struct ip_auth_hdr *)(skb->data + offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) spi = ah->spi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) case IPPROTO_COMP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) ipch = (struct ip_comp_hdr *)(skb->data + offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) spi = htonl(ntohs(ipch->cpi));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) if (type != ICMPV6_PKT_TOOBIG &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) type != NDISC_REDIRECT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) x = xfrm_state_lookup(net, mark, (const xfrm_address_t *)&iph->daddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) spi, protocol, AF_INET6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) if (!x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) if (type == NDISC_REDIRECT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) ip6_redirect(skb, net, skb->dev->ifindex, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) sock_net_uid(net, NULL));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) ip6_update_pmtu(skb, net, info, 0, 0, sock_net_uid(net, NULL));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) xfrm_state_put(x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) static void vti6_link_config(struct ip6_tnl *t, bool keep_mtu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) struct net_device *dev = t->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) struct __ip6_tnl_parm *p = &t->parms;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) struct net_device *tdev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) int mtu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) memcpy(dev->dev_addr, &p->laddr, sizeof(struct in6_addr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) memcpy(dev->broadcast, &p->raddr, sizeof(struct in6_addr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) p->flags &= ~(IP6_TNL_F_CAP_XMIT | IP6_TNL_F_CAP_RCV |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) IP6_TNL_F_CAP_PER_PACKET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) p->flags |= ip6_tnl_get_cap(t, &p->laddr, &p->raddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) if (p->flags & IP6_TNL_F_CAP_XMIT && p->flags & IP6_TNL_F_CAP_RCV)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) dev->flags |= IFF_POINTOPOINT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) dev->flags &= ~IFF_POINTOPOINT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) if (keep_mtu && dev->mtu) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) dev->mtu = clamp(dev->mtu, dev->min_mtu, dev->max_mtu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) if (p->flags & IP6_TNL_F_CAP_XMIT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) int strict = (ipv6_addr_type(&p->raddr) &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) (IPV6_ADDR_MULTICAST | IPV6_ADDR_LINKLOCAL));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) struct rt6_info *rt = rt6_lookup(t->net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) &p->raddr, &p->laddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) p->link, NULL, strict);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) if (rt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) tdev = rt->dst.dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) ip6_rt_put(rt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) if (!tdev && p->link)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) tdev = __dev_get_by_index(t->net, p->link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) if (tdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) mtu = tdev->mtu - sizeof(struct ipv6hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) mtu = ETH_DATA_LEN - LL_MAX_HEADER - sizeof(struct ipv6hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) dev->mtu = max_t(int, mtu, IPV4_MIN_MTU);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) * vti6_tnl_change - update the tunnel parameters
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) * @t: tunnel to be changed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) * @p: tunnel configuration parameters
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) * @keep_mtu: MTU was set from userspace, don't re-compute it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) * Description:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) * vti6_tnl_change() updates the tunnel parameters
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) vti6_tnl_change(struct ip6_tnl *t, const struct __ip6_tnl_parm *p,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) bool keep_mtu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) t->parms.laddr = p->laddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) t->parms.raddr = p->raddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) t->parms.link = p->link;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) t->parms.i_key = p->i_key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) t->parms.o_key = p->o_key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) t->parms.proto = p->proto;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) t->parms.fwmark = p->fwmark;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) dst_cache_reset(&t->dst_cache);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) vti6_link_config(t, keep_mtu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) static int vti6_update(struct ip6_tnl *t, struct __ip6_tnl_parm *p,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) bool keep_mtu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) struct net *net = dev_net(t->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) struct vti6_net *ip6n = net_generic(net, vti6_net_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) vti6_tnl_unlink(ip6n, t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) synchronize_net();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) err = vti6_tnl_change(t, p, keep_mtu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) vti6_tnl_link(ip6n, t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) netdev_state_change(t->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) vti6_parm_from_user(struct __ip6_tnl_parm *p, const struct ip6_tnl_parm2 *u)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) p->laddr = u->laddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) p->raddr = u->raddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) p->link = u->link;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) p->i_key = u->i_key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) p->o_key = u->o_key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) p->proto = u->proto;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) memcpy(p->name, u->name, sizeof(u->name));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) vti6_parm_to_user(struct ip6_tnl_parm2 *u, const struct __ip6_tnl_parm *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) u->laddr = p->laddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) u->raddr = p->raddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) u->link = p->link;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) u->i_key = p->i_key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) u->o_key = p->o_key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) if (u->i_key)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) u->i_flags |= GRE_KEY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) if (u->o_key)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) u->o_flags |= GRE_KEY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) u->proto = p->proto;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) memcpy(u->name, p->name, sizeof(u->name));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) * vti6_ioctl - configure vti6 tunnels from userspace
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) * @dev: virtual device associated with tunnel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) * @ifr: parameters passed from userspace
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) * @cmd: command to be performed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) * Description:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) * vti6_ioctl() is used for managing vti6 tunnels
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) * from userspace.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) * The possible commands are the following:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) * %SIOCGETTUNNEL: get tunnel parameters for device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) * %SIOCADDTUNNEL: add tunnel matching given tunnel parameters
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) * %SIOCCHGTUNNEL: change tunnel parameters to those given
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) * %SIOCDELTUNNEL: delete tunnel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) * The fallback device "ip6_vti0", created during module
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) * initialization, can be used for creating other tunnel devices.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) * Return:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) * 0 on success,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) * %-EFAULT if unable to copy data to or from userspace,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) * %-EPERM if current process hasn't %CAP_NET_ADMIN set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) * %-EINVAL if passed tunnel parameters are invalid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) * %-EEXIST if changing a tunnel's parameters would cause a conflict
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) * %-ENODEV if attempting to change or delete a nonexisting device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) vti6_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) struct ip6_tnl_parm2 p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) struct __ip6_tnl_parm p1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) struct ip6_tnl *t = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) struct net *net = dev_net(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) struct vti6_net *ip6n = net_generic(net, vti6_net_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) memset(&p1, 0, sizeof(p1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) switch (cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) case SIOCGETTUNNEL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) if (dev == ip6n->fb_tnl_dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) if (copy_from_user(&p, ifr->ifr_ifru.ifru_data, sizeof(p))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) err = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) vti6_parm_from_user(&p1, &p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) t = vti6_locate(net, &p1, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) memset(&p, 0, sizeof(p));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) if (!t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) t = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) vti6_parm_to_user(&p, &t->parms);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) if (copy_to_user(ifr->ifr_ifru.ifru_data, &p, sizeof(p)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) err = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) case SIOCADDTUNNEL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) case SIOCCHGTUNNEL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) err = -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) err = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) if (copy_from_user(&p, ifr->ifr_ifru.ifru_data, sizeof(p)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) if (p.proto != IPPROTO_IPV6 && p.proto != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) vti6_parm_from_user(&p1, &p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) t = vti6_locate(net, &p1, cmd == SIOCADDTUNNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) if (dev != ip6n->fb_tnl_dev && cmd == SIOCCHGTUNNEL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) if (t) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) if (t->dev != dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) err = -EEXIST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) t = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) err = vti6_update(t, &p1, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) if (t) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) vti6_parm_to_user(&p, &t->parms);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) if (copy_to_user(ifr->ifr_ifru.ifru_data, &p, sizeof(p)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) err = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) err = (cmd == SIOCADDTUNNEL ? -ENOBUFS : -ENOENT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) case SIOCDELTUNNEL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) err = -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) if (dev == ip6n->fb_tnl_dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) err = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) if (copy_from_user(&p, ifr->ifr_ifru.ifru_data, sizeof(p)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) err = -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) vti6_parm_from_user(&p1, &p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) t = vti6_locate(net, &p1, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) if (!t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) err = -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) if (t->dev == ip6n->fb_tnl_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) dev = t->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) unregister_netdevice(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) static const struct net_device_ops vti6_netdev_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) .ndo_init = vti6_dev_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) .ndo_uninit = vti6_dev_uninit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) .ndo_start_xmit = vti6_tnl_xmit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) .ndo_do_ioctl = vti6_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) .ndo_get_stats64 = ip_tunnel_get_stats64,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) .ndo_get_iflink = ip6_tnl_get_iflink,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) * vti6_dev_setup - setup virtual tunnel device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) * @dev: virtual device associated with tunnel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) * Description:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) * Initialize function pointers and device parameters
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904) static void vti6_dev_setup(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) dev->netdev_ops = &vti6_netdev_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) dev->header_ops = &ip_tunnel_header_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908) dev->needs_free_netdev = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) dev->priv_destructor = vti6_dev_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) dev->type = ARPHRD_TUNNEL6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) dev->min_mtu = IPV4_MIN_MTU;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) dev->max_mtu = IP_MAX_MTU - sizeof(struct ipv6hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) dev->flags |= IFF_NOARP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) dev->addr_len = sizeof(struct in6_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916) netif_keep_dst(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) /* This perm addr will be used as interface identifier by IPv6 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918) dev->addr_assign_type = NET_ADDR_RANDOM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) eth_random_addr(dev->perm_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923) * vti6_dev_init_gen - general initializer for all tunnel devices
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924) * @dev: virtual device associated with tunnel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925) **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) static inline int vti6_dev_init_gen(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) struct ip6_tnl *t = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930) t->dev = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931) t->net = dev_net(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932) dev->tstats = netdev_alloc_pcpu_stats(struct pcpu_sw_netstats);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933) if (!dev->tstats)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935) dev_hold(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940) * vti6_dev_init - initializer for all non fallback tunnel devices
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941) * @dev: virtual device associated with tunnel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942) **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943) static int vti6_dev_init(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945) struct ip6_tnl *t = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946) int err = vti6_dev_init_gen(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950) vti6_link_config(t, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955) * vti6_fb_tnl_dev_init - initializer for fallback tunnel device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956) * @dev: fallback device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 957) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 958) * Return: 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 959) **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960) static int __net_init vti6_fb_tnl_dev_init(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962) struct ip6_tnl *t = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 963) struct net *net = dev_net(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 964) struct vti6_net *ip6n = net_generic(net, vti6_net_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 965)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 966) t->parms.proto = IPPROTO_IPV6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 967)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 968) rcu_assign_pointer(ip6n->tnls_wc[0], t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 969) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 970) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 971)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 972) static int vti6_validate(struct nlattr *tb[], struct nlattr *data[],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 973) struct netlink_ext_ack *extack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 974) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 975) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 976) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 977)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 978) static void vti6_netlink_parms(struct nlattr *data[],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 979) struct __ip6_tnl_parm *parms)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 980) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 981) memset(parms, 0, sizeof(*parms));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 982)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 983) if (!data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 984) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 985)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 986) if (data[IFLA_VTI_LINK])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 987) parms->link = nla_get_u32(data[IFLA_VTI_LINK]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 988)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 989) if (data[IFLA_VTI_LOCAL])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 990) parms->laddr = nla_get_in6_addr(data[IFLA_VTI_LOCAL]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 991)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 992) if (data[IFLA_VTI_REMOTE])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 993) parms->raddr = nla_get_in6_addr(data[IFLA_VTI_REMOTE]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 994)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 995) if (data[IFLA_VTI_IKEY])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 996) parms->i_key = nla_get_be32(data[IFLA_VTI_IKEY]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 997)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 998) if (data[IFLA_VTI_OKEY])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 999) parms->o_key = nla_get_be32(data[IFLA_VTI_OKEY]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) if (data[IFLA_VTI_FWMARK])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) parms->fwmark = nla_get_u32(data[IFLA_VTI_FWMARK]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) static int vti6_newlink(struct net *src_net, struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) struct nlattr *tb[], struct nlattr *data[],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) struct netlink_ext_ack *extack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) struct net *net = dev_net(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) struct ip6_tnl *nt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) nt = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) vti6_netlink_parms(data, &nt->parms);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) nt->parms.proto = IPPROTO_IPV6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) if (vti6_locate(net, &nt->parms, 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) return -EEXIST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) return vti6_tnl_create2(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) static void vti6_dellink(struct net_device *dev, struct list_head *head)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) struct net *net = dev_net(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) struct vti6_net *ip6n = net_generic(net, vti6_net_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) if (dev != ip6n->fb_tnl_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) unregister_netdevice_queue(dev, head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) static int vti6_changelink(struct net_device *dev, struct nlattr *tb[],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) struct nlattr *data[],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) struct netlink_ext_ack *extack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) struct ip6_tnl *t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) struct __ip6_tnl_parm p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) struct net *net = dev_net(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) struct vti6_net *ip6n = net_generic(net, vti6_net_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) if (dev == ip6n->fb_tnl_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) vti6_netlink_parms(data, &p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) t = vti6_locate(net, &p, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) if (t) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) if (t->dev != dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) return -EEXIST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) t = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) return vti6_update(t, &p, tb && tb[IFLA_MTU]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) static size_t vti6_get_size(const struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) return
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) /* IFLA_VTI_LINK */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) nla_total_size(4) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) /* IFLA_VTI_LOCAL */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) nla_total_size(sizeof(struct in6_addr)) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) /* IFLA_VTI_REMOTE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) nla_total_size(sizeof(struct in6_addr)) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) /* IFLA_VTI_IKEY */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) nla_total_size(4) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) /* IFLA_VTI_OKEY */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) nla_total_size(4) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) /* IFLA_VTI_FWMARK */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) nla_total_size(4) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) static int vti6_fill_info(struct sk_buff *skb, const struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) struct ip6_tnl *tunnel = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) struct __ip6_tnl_parm *parm = &tunnel->parms;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) if (nla_put_u32(skb, IFLA_VTI_LINK, parm->link) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) nla_put_in6_addr(skb, IFLA_VTI_LOCAL, &parm->laddr) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) nla_put_in6_addr(skb, IFLA_VTI_REMOTE, &parm->raddr) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) nla_put_be32(skb, IFLA_VTI_IKEY, parm->i_key) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) nla_put_be32(skb, IFLA_VTI_OKEY, parm->o_key) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) nla_put_u32(skb, IFLA_VTI_FWMARK, parm->fwmark))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) nla_put_failure:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) return -EMSGSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) static const struct nla_policy vti6_policy[IFLA_VTI_MAX + 1] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) [IFLA_VTI_LINK] = { .type = NLA_U32 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) [IFLA_VTI_LOCAL] = { .len = sizeof(struct in6_addr) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) [IFLA_VTI_REMOTE] = { .len = sizeof(struct in6_addr) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) [IFLA_VTI_IKEY] = { .type = NLA_U32 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) [IFLA_VTI_OKEY] = { .type = NLA_U32 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) [IFLA_VTI_FWMARK] = { .type = NLA_U32 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) static struct rtnl_link_ops vti6_link_ops __read_mostly = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) .kind = "vti6",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) .maxtype = IFLA_VTI_MAX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) .policy = vti6_policy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) .priv_size = sizeof(struct ip6_tnl),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) .setup = vti6_dev_setup,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) .validate = vti6_validate,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) .newlink = vti6_newlink,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) .dellink = vti6_dellink,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) .changelink = vti6_changelink,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) .get_size = vti6_get_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) .fill_info = vti6_fill_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) .get_link_net = ip6_tnl_get_link_net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) static void __net_exit vti6_destroy_tunnels(struct vti6_net *ip6n,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) struct list_head *list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) int h;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) struct ip6_tnl *t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) for (h = 0; h < IP6_VTI_HASH_SIZE; h++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) t = rtnl_dereference(ip6n->tnls_r_l[h]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) while (t) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) unregister_netdevice_queue(t->dev, list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) t = rtnl_dereference(t->next);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) t = rtnl_dereference(ip6n->tnls_wc[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) if (t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) unregister_netdevice_queue(t->dev, list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) static int __net_init vti6_init_net(struct net *net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) struct vti6_net *ip6n = net_generic(net, vti6_net_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) struct ip6_tnl *t = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) ip6n->tnls[0] = ip6n->tnls_wc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) ip6n->tnls[1] = ip6n->tnls_r_l;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) if (!net_has_fallback_tunnels(net))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) ip6n->fb_tnl_dev = alloc_netdev(sizeof(struct ip6_tnl), "ip6_vti0",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) NET_NAME_UNKNOWN, vti6_dev_setup);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) if (!ip6n->fb_tnl_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) goto err_alloc_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) dev_net_set(ip6n->fb_tnl_dev, net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) ip6n->fb_tnl_dev->rtnl_link_ops = &vti6_link_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) err = vti6_fb_tnl_dev_init(ip6n->fb_tnl_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) goto err_register;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) err = register_netdev(ip6n->fb_tnl_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) goto err_register;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) t = netdev_priv(ip6n->fb_tnl_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) strcpy(t->parms.name, ip6n->fb_tnl_dev->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) err_register:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) free_netdev(ip6n->fb_tnl_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) err_alloc_dev:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) static void __net_exit vti6_exit_batch_net(struct list_head *net_list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) struct vti6_net *ip6n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) struct net *net;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) LIST_HEAD(list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) rtnl_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) list_for_each_entry(net, net_list, exit_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) ip6n = net_generic(net, vti6_net_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) vti6_destroy_tunnels(ip6n, &list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) unregister_netdevice_many(&list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) rtnl_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) static struct pernet_operations vti6_net_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) .init = vti6_init_net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) .exit_batch = vti6_exit_batch_net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) .id = &vti6_net_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) .size = sizeof(struct vti6_net),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) static struct xfrm6_protocol vti_esp6_protocol __read_mostly = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) .handler = vti6_rcv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) .input_handler = vti6_input_proto,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) .cb_handler = vti6_rcv_cb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) .err_handler = vti6_err,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) .priority = 100,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) static struct xfrm6_protocol vti_ah6_protocol __read_mostly = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) .handler = vti6_rcv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) .input_handler = vti6_input_proto,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) .cb_handler = vti6_rcv_cb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) .err_handler = vti6_err,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) .priority = 100,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) static struct xfrm6_protocol vti_ipcomp6_protocol __read_mostly = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) .handler = vti6_rcv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) .input_handler = vti6_input_proto,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) .cb_handler = vti6_rcv_cb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) .err_handler = vti6_err,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) .priority = 100,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) #if IS_REACHABLE(CONFIG_INET6_XFRM_TUNNEL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) static int vti6_rcv_tunnel(struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) const xfrm_address_t *saddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) __be32 spi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) saddr = (const xfrm_address_t *)&ipv6_hdr(skb)->saddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) spi = xfrm6_tunnel_spi_lookup(dev_net(skb->dev), saddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) return vti6_input_proto(skb, IPPROTO_IPV6, spi, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) static struct xfrm6_tunnel vti_ipv6_handler __read_mostly = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) .handler = vti6_rcv_tunnel,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) .cb_handler = vti6_rcv_cb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) .err_handler = vti6_err,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) .priority = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) static struct xfrm6_tunnel vti_ip6ip_handler __read_mostly = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) .handler = vti6_rcv_tunnel,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) .cb_handler = vti6_rcv_cb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) .err_handler = vti6_err,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) .priority = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) * vti6_tunnel_init - register protocol and reserve needed resources
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) * Return: 0 on success
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) static int __init vti6_tunnel_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) const char *msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) msg = "tunnel device";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) err = register_pernet_device(&vti6_net_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) goto pernet_dev_failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) msg = "tunnel protocols";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) err = xfrm6_protocol_register(&vti_esp6_protocol, IPPROTO_ESP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) goto xfrm_proto_esp_failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) err = xfrm6_protocol_register(&vti_ah6_protocol, IPPROTO_AH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) goto xfrm_proto_ah_failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) err = xfrm6_protocol_register(&vti_ipcomp6_protocol, IPPROTO_COMP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) goto xfrm_proto_comp_failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) #if IS_REACHABLE(CONFIG_INET6_XFRM_TUNNEL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) msg = "ipv6 tunnel";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) err = xfrm6_tunnel_register(&vti_ipv6_handler, AF_INET6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) goto vti_tunnel_ipv6_failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) err = xfrm6_tunnel_register(&vti_ip6ip_handler, AF_INET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) goto vti_tunnel_ip6ip_failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) msg = "netlink interface";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) err = rtnl_link_register(&vti6_link_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) goto rtnl_link_failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) rtnl_link_failed:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) #if IS_REACHABLE(CONFIG_INET6_XFRM_TUNNEL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) err = xfrm6_tunnel_deregister(&vti_ip6ip_handler, AF_INET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) vti_tunnel_ip6ip_failed:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) err = xfrm6_tunnel_deregister(&vti_ipv6_handler, AF_INET6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) vti_tunnel_ipv6_failed:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) xfrm6_protocol_deregister(&vti_ipcomp6_protocol, IPPROTO_COMP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) xfrm_proto_comp_failed:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) xfrm6_protocol_deregister(&vti_ah6_protocol, IPPROTO_AH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) xfrm_proto_ah_failed:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) xfrm6_protocol_deregister(&vti_esp6_protocol, IPPROTO_ESP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) xfrm_proto_esp_failed:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) unregister_pernet_device(&vti6_net_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) pernet_dev_failed:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) pr_err("vti6 init: failed to register %s\n", msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) * vti6_tunnel_cleanup - free resources and unregister protocol
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) static void __exit vti6_tunnel_cleanup(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) rtnl_link_unregister(&vti6_link_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) #if IS_REACHABLE(CONFIG_INET6_XFRM_TUNNEL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) xfrm6_tunnel_deregister(&vti_ip6ip_handler, AF_INET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) xfrm6_tunnel_deregister(&vti_ipv6_handler, AF_INET6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) xfrm6_protocol_deregister(&vti_ipcomp6_protocol, IPPROTO_COMP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) xfrm6_protocol_deregister(&vti_ah6_protocol, IPPROTO_AH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) xfrm6_protocol_deregister(&vti_esp6_protocol, IPPROTO_ESP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) unregister_pernet_device(&vti6_net_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) module_init(vti6_tunnel_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) module_exit(vti6_tunnel_cleanup);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) MODULE_ALIAS_RTNL_LINK("vti6");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329) MODULE_ALIAS_NETDEV("ip6_vti0");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330) MODULE_AUTHOR("Steffen Klassert");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) MODULE_DESCRIPTION("IPv6 virtual tunnel interface");