^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) * GRE over IPv6 protocol decoder.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Authors: Dmitry Kozlov (xeb@mail.ru)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/capability.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/skbuff.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/netdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/in.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/tcp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/udp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/if_arp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <linux/in6.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <linux/inetdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <linux/igmp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <linux/netfilter_ipv4.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <linux/etherdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include <linux/if_ether.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #include <linux/hash.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #include <linux/if_tunnel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #include <linux/ip6_tunnel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #include <net/sock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #include <net/ip.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #include <net/ip_tunnels.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #include <net/icmp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #include <net/protocol.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #include <net/addrconf.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #include <net/arp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #include <net/checksum.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) #include <net/dsfield.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) #include <net/inet_ecn.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) #include <net/xfrm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) #include <net/net_namespace.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) #include <net/netns/generic.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) #include <net/rtnetlink.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) #include <net/ipv6.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) #include <net/ip6_fib.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) #include <net/ip6_route.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) #include <net/ip6_tunnel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) #include <net/gre.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) #include <net/erspan.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) #include <net/dst_metadata.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) static bool log_ecn_error = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) module_param(log_ecn_error, bool, 0644);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) #define IP6_GRE_HASH_SIZE_SHIFT 5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) #define IP6_GRE_HASH_SIZE (1 << IP6_GRE_HASH_SIZE_SHIFT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) static unsigned int ip6gre_net_id __read_mostly;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) struct ip6gre_net {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) struct ip6_tnl __rcu *tunnels[4][IP6_GRE_HASH_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) struct ip6_tnl __rcu *collect_md_tun;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) struct ip6_tnl __rcu *collect_md_tun_erspan;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) struct net_device *fb_tunnel_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) static struct rtnl_link_ops ip6gre_link_ops __read_mostly;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) static struct rtnl_link_ops ip6gre_tap_ops __read_mostly;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) static struct rtnl_link_ops ip6erspan_tap_ops __read_mostly;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) static int ip6gre_tunnel_init(struct net_device *dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) static void ip6gre_tunnel_setup(struct net_device *dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) static void ip6gre_tunnel_link(struct ip6gre_net *ign, struct ip6_tnl *t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) static void ip6gre_tnl_link_config(struct ip6_tnl *t, int set_mtu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) static void ip6erspan_tnl_link_config(struct ip6_tnl *t, int set_mtu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) /* Tunnel hash table */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) 4 hash tables:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) 3: (remote,local)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) 2: (remote,*)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) 1: (*,local)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) 0: (*,*)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) We require exact key match i.e. if a key is present in packet
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) it will match only tunnel with the same key; if it is not present,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) it will match only keyless tunnel.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) All keysless packets, if not matched configured keyless tunnels
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) will match fallback tunnel.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) #define HASH_KEY(key) (((__force u32)key^((__force u32)key>>4))&(IP6_GRE_HASH_SIZE - 1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) static u32 HASH_ADDR(const struct in6_addr *addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) u32 hash = ipv6_addr_hash(addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) return hash_32(hash, IP6_GRE_HASH_SIZE_SHIFT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) #define tunnels_r_l tunnels[3]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) #define tunnels_r tunnels[2]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) #define tunnels_l tunnels[1]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) #define tunnels_wc tunnels[0]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) /* Given src, dst and key, find appropriate for input tunnel. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) static struct ip6_tnl *ip6gre_tunnel_lookup(struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) const struct in6_addr *remote, const struct in6_addr *local,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) __be32 key, __be16 gre_proto)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) struct net *net = dev_net(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) int link = dev->ifindex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) unsigned int h0 = HASH_ADDR(remote);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) unsigned int h1 = HASH_KEY(key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) struct ip6_tnl *t, *cand = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) struct ip6gre_net *ign = net_generic(net, ip6gre_net_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) int dev_type = (gre_proto == htons(ETH_P_TEB) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) gre_proto == htons(ETH_P_ERSPAN) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) gre_proto == htons(ETH_P_ERSPAN2)) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) ARPHRD_ETHER : ARPHRD_IP6GRE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) int score, cand_score = 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) struct net_device *ndev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) for_each_ip_tunnel_rcu(t, ign->tunnels_r_l[h0 ^ h1]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) if (!ipv6_addr_equal(local, &t->parms.laddr) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) !ipv6_addr_equal(remote, &t->parms.raddr) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) key != t->parms.i_key ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) !(t->dev->flags & IFF_UP))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) if (t->dev->type != ARPHRD_IP6GRE &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) t->dev->type != dev_type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) score = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) if (t->parms.link != link)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) score |= 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) if (t->dev->type != dev_type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) score |= 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) if (score == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) return t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) if (score < cand_score) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) cand = t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) cand_score = score;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) for_each_ip_tunnel_rcu(t, ign->tunnels_r[h0 ^ h1]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) if (!ipv6_addr_equal(remote, &t->parms.raddr) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) key != t->parms.i_key ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) !(t->dev->flags & IFF_UP))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) if (t->dev->type != ARPHRD_IP6GRE &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) t->dev->type != dev_type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) score = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) if (t->parms.link != link)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) score |= 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) if (t->dev->type != dev_type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) score |= 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) if (score == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) return t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) if (score < cand_score) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) cand = t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) cand_score = score;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) }
^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) for_each_ip_tunnel_rcu(t, ign->tunnels_l[h1]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) if ((!ipv6_addr_equal(local, &t->parms.laddr) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) (!ipv6_addr_equal(local, &t->parms.raddr) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) !ipv6_addr_is_multicast(local))) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) key != t->parms.i_key ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) !(t->dev->flags & IFF_UP))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) if (t->dev->type != ARPHRD_IP6GRE &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) t->dev->type != dev_type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) score = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) if (t->parms.link != link)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) score |= 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) if (t->dev->type != dev_type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) score |= 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) if (score == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) return t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) if (score < cand_score) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) cand = t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) cand_score = score;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) for_each_ip_tunnel_rcu(t, ign->tunnels_wc[h1]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) if (t->parms.i_key != key ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) !(t->dev->flags & IFF_UP))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) if (t->dev->type != ARPHRD_IP6GRE &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) t->dev->type != dev_type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) score = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) if (t->parms.link != link)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) score |= 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) if (t->dev->type != dev_type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) score |= 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) if (score == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) return t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) if (score < cand_score) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) cand = t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) cand_score = score;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) if (cand)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) return cand;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) if (gre_proto == htons(ETH_P_ERSPAN) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) gre_proto == htons(ETH_P_ERSPAN2))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) t = rcu_dereference(ign->collect_md_tun_erspan);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) t = rcu_dereference(ign->collect_md_tun);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) if (t && t->dev->flags & IFF_UP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) return t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) ndev = READ_ONCE(ign->fb_tunnel_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) if (ndev && ndev->flags & IFF_UP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) return netdev_priv(ndev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) static struct ip6_tnl __rcu **__ip6gre_bucket(struct ip6gre_net *ign,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) const struct __ip6_tnl_parm *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) const struct in6_addr *remote = &p->raddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) const struct in6_addr *local = &p->laddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) unsigned int h = HASH_KEY(p->i_key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) int prio = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) if (!ipv6_addr_any(local))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) prio |= 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) if (!ipv6_addr_any(remote) && !ipv6_addr_is_multicast(remote)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) prio |= 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) h ^= HASH_ADDR(remote);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) return &ign->tunnels[prio][h];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) static void ip6gre_tunnel_link_md(struct ip6gre_net *ign, struct ip6_tnl *t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) if (t->parms.collect_md)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) rcu_assign_pointer(ign->collect_md_tun, t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) static void ip6erspan_tunnel_link_md(struct ip6gre_net *ign, struct ip6_tnl *t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) if (t->parms.collect_md)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) rcu_assign_pointer(ign->collect_md_tun_erspan, t);
^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) static void ip6gre_tunnel_unlink_md(struct ip6gre_net *ign, struct ip6_tnl *t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) if (t->parms.collect_md)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) rcu_assign_pointer(ign->collect_md_tun, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) static void ip6erspan_tunnel_unlink_md(struct ip6gre_net *ign,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) struct ip6_tnl *t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) if (t->parms.collect_md)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) rcu_assign_pointer(ign->collect_md_tun_erspan, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) static inline struct ip6_tnl __rcu **ip6gre_bucket(struct ip6gre_net *ign,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) const struct ip6_tnl *t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) return __ip6gre_bucket(ign, &t->parms);
^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 void ip6gre_tunnel_link(struct ip6gre_net *ign, struct ip6_tnl *t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) struct ip6_tnl __rcu **tp = ip6gre_bucket(ign, t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) rcu_assign_pointer(t->next, rtnl_dereference(*tp));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) rcu_assign_pointer(*tp, t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) static void ip6gre_tunnel_unlink(struct ip6gre_net *ign, struct ip6_tnl *t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) struct ip6_tnl __rcu **tp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) struct ip6_tnl *iter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) for (tp = ip6gre_bucket(ign, t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) (iter = rtnl_dereference(*tp)) != NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) tp = &iter->next) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) if (t == iter) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) rcu_assign_pointer(*tp, t->next);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) static struct ip6_tnl *ip6gre_tunnel_find(struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) const struct __ip6_tnl_parm *parms,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) int type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) const struct in6_addr *remote = &parms->raddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) const struct in6_addr *local = &parms->laddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) __be32 key = parms->i_key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) int link = parms->link;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) struct ip6_tnl *t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) struct ip6_tnl __rcu **tp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) struct ip6gre_net *ign = net_generic(net, ip6gre_net_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) for (tp = __ip6gre_bucket(ign, parms);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) (t = rtnl_dereference(*tp)) != NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) tp = &t->next)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) if (ipv6_addr_equal(local, &t->parms.laddr) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) ipv6_addr_equal(remote, &t->parms.raddr) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) key == t->parms.i_key &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) link == t->parms.link &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) type == t->dev->type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) return t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) static struct ip6_tnl *ip6gre_tunnel_locate(struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) const struct __ip6_tnl_parm *parms, int create)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) struct ip6_tnl *t, *nt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) struct net_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) char name[IFNAMSIZ];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) struct ip6gre_net *ign = net_generic(net, ip6gre_net_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) t = ip6gre_tunnel_find(net, parms, ARPHRD_IP6GRE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) if (t && create)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) if (t || !create)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) return t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) if (parms->name[0]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) if (!dev_valid_name(parms->name))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) strlcpy(name, parms->name, IFNAMSIZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) strcpy(name, "ip6gre%d");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) dev = alloc_netdev(sizeof(*t), name, NET_NAME_UNKNOWN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) ip6gre_tunnel_setup);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) if (!dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) dev_net_set(dev, net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) nt = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) nt->parms = *parms;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) dev->rtnl_link_ops = &ip6gre_link_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) nt->dev = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) nt->net = dev_net(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) if (register_netdevice(dev) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) goto failed_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) ip6gre_tnl_link_config(nt, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) /* Can use a lockless transmit, unless we generate output sequences */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) if (!(nt->parms.o_flags & TUNNEL_SEQ))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) dev->features |= NETIF_F_LLTX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) ip6gre_tunnel_link(ign, nt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) return nt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) failed_free:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) free_netdev(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) static void ip6erspan_tunnel_uninit(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) struct ip6_tnl *t = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) struct ip6gre_net *ign = net_generic(t->net, ip6gre_net_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) ip6erspan_tunnel_unlink_md(ign, t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) ip6gre_tunnel_unlink(ign, t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) dst_cache_reset(&t->dst_cache);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) dev_put(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) static void ip6gre_tunnel_uninit(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) struct ip6_tnl *t = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) struct ip6gre_net *ign = net_generic(t->net, ip6gre_net_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) ip6gre_tunnel_unlink_md(ign, t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) ip6gre_tunnel_unlink(ign, t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) if (ign->fb_tunnel_dev == dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) WRITE_ONCE(ign->fb_tunnel_dev, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) dst_cache_reset(&t->dst_cache);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) dev_put(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) static int ip6gre_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) u8 type, u8 code, int offset, __be32 info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) struct net *net = dev_net(skb->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) const struct ipv6hdr *ipv6h;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) struct tnl_ptk_info tpi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) struct ip6_tnl *t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) if (gre_parse_header(skb, &tpi, NULL, htons(ETH_P_IPV6),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) offset) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) ipv6h = (const struct ipv6hdr *)skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) t = ip6gre_tunnel_lookup(skb->dev, &ipv6h->daddr, &ipv6h->saddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) tpi.key, tpi.proto);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) if (!t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) switch (type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) case ICMPV6_DEST_UNREACH:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) net_dbg_ratelimited("%s: Path to destination invalid or inactive!\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) t->parms.name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) if (code != ICMPV6_PORT_UNREACH)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) case ICMPV6_TIME_EXCEED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) if (code == ICMPV6_EXC_HOPLIMIT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) net_dbg_ratelimited("%s: Too small hop limit or routing loop in tunnel!\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) t->parms.name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) case ICMPV6_PARAMPROB: {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) struct ipv6_tlv_tnl_enc_lim *tel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) __u32 teli;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) teli = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) if (code == ICMPV6_HDR_FIELD)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) teli = ip6_tnl_parse_tlv_enc_lim(skb, skb->data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) if (teli && teli == be32_to_cpu(info) - 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) tel = (struct ipv6_tlv_tnl_enc_lim *) &skb->data[teli];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) if (tel->encap_limit == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) net_dbg_ratelimited("%s: Too small encapsulation limit or routing loop in tunnel!\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) t->parms.name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) net_dbg_ratelimited("%s: Recipient unable to parse tunneled packet!\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) t->parms.name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) case ICMPV6_PKT_TOOBIG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) ip6_update_pmtu(skb, net, info, 0, 0, sock_net_uid(net, NULL));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) case NDISC_REDIRECT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) ip6_redirect(skb, net, skb->dev->ifindex, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) sock_net_uid(net, NULL));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) if (time_before(jiffies, t->err_time + IP6TUNNEL_ERR_TIMEO))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) t->err_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) t->err_count = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) t->err_time = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) static int ip6gre_rcv(struct sk_buff *skb, const struct tnl_ptk_info *tpi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) const struct ipv6hdr *ipv6h;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) struct ip6_tnl *tunnel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) ipv6h = ipv6_hdr(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) tunnel = ip6gre_tunnel_lookup(skb->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) &ipv6h->saddr, &ipv6h->daddr, tpi->key,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) tpi->proto);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) if (tunnel) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) if (tunnel->parms.collect_md) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) struct metadata_dst *tun_dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) __be64 tun_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) __be16 flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) flags = tpi->flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) tun_id = key32_to_tunnel_id(tpi->key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) tun_dst = ipv6_tun_rx_dst(skb, flags, tun_id, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) if (!tun_dst)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) return PACKET_REJECT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) ip6_tnl_rcv(tunnel, skb, tpi, tun_dst, log_ecn_error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) ip6_tnl_rcv(tunnel, skb, tpi, NULL, log_ecn_error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) return PACKET_RCVD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) return PACKET_REJECT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) static int ip6erspan_rcv(struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) struct tnl_ptk_info *tpi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) int gre_hdr_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) struct erspan_base_hdr *ershdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) const struct ipv6hdr *ipv6h;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) struct erspan_md2 *md2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) struct ip6_tnl *tunnel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) u8 ver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) ipv6h = ipv6_hdr(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) ershdr = (struct erspan_base_hdr *)skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) ver = ershdr->ver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) tunnel = ip6gre_tunnel_lookup(skb->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) &ipv6h->saddr, &ipv6h->daddr, tpi->key,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) tpi->proto);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) if (tunnel) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) int len = erspan_hdr_len(ver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) if (unlikely(!pskb_may_pull(skb, len)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) return PACKET_REJECT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) if (__iptunnel_pull_header(skb, len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) htons(ETH_P_TEB),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) false, false) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) return PACKET_REJECT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) if (tunnel->parms.collect_md) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) struct erspan_metadata *pkt_md, *md;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) struct metadata_dst *tun_dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) struct ip_tunnel_info *info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) unsigned char *gh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) __be64 tun_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) __be16 flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) tpi->flags |= TUNNEL_KEY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) flags = tpi->flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) tun_id = key32_to_tunnel_id(tpi->key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) tun_dst = ipv6_tun_rx_dst(skb, flags, tun_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) sizeof(*md));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) if (!tun_dst)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) return PACKET_REJECT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) /* skb can be uncloned in __iptunnel_pull_header, so
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) * old pkt_md is no longer valid and we need to reset
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) * it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) gh = skb_network_header(skb) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) skb_network_header_len(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) pkt_md = (struct erspan_metadata *)(gh + gre_hdr_len +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) sizeof(*ershdr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) info = &tun_dst->u.tun_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) md = ip_tunnel_info_opts(info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) md->version = ver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) md2 = &md->u.md2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) memcpy(md2, pkt_md, ver == 1 ? ERSPAN_V1_MDSIZE :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) ERSPAN_V2_MDSIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) info->key.tun_flags |= TUNNEL_ERSPAN_OPT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) info->options_len = sizeof(*md);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) ip6_tnl_rcv(tunnel, skb, tpi, tun_dst, log_ecn_error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) ip6_tnl_rcv(tunnel, skb, tpi, NULL, log_ecn_error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) return PACKET_RCVD;
^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) return PACKET_REJECT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) static int gre_rcv(struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) struct tnl_ptk_info tpi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) bool csum_err = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) int hdr_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) hdr_len = gre_parse_header(skb, &tpi, &csum_err, htons(ETH_P_IPV6), 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) if (hdr_len < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) goto drop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) if (iptunnel_pull_header(skb, hdr_len, tpi.proto, false))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) goto drop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) if (unlikely(tpi.proto == htons(ETH_P_ERSPAN) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) tpi.proto == htons(ETH_P_ERSPAN2))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) if (ip6erspan_rcv(skb, &tpi, hdr_len) == PACKET_RCVD)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) if (ip6gre_rcv(skb, &tpi) == PACKET_RCVD)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) drop:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) static int gre_handle_offloads(struct sk_buff *skb, bool csum)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) return iptunnel_handle_offloads(skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) csum ? SKB_GSO_GRE_CSUM : SKB_GSO_GRE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) static void prepare_ip6gre_xmit_ipv4(struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) struct flowi6 *fl6, __u8 *dsfield,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) int *encap_limit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) const struct iphdr *iph = ip_hdr(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) struct ip6_tnl *t = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) if (!(t->parms.flags & IP6_TNL_F_IGN_ENCAP_LIMIT))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) *encap_limit = t->parms.encap_limit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) memcpy(fl6, &t->fl.u.ip6, sizeof(*fl6));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) if (t->parms.flags & IP6_TNL_F_USE_ORIG_TCLASS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) *dsfield = ipv4_get_dsfield(iph);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) *dsfield = ip6_tclass(t->parms.flowinfo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) if (t->parms.flags & IP6_TNL_F_USE_ORIG_FWMARK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) fl6->flowi6_mark = skb->mark;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) fl6->flowi6_mark = t->parms.fwmark;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) fl6->flowi6_uid = sock_net_uid(dev_net(dev), NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) static int prepare_ip6gre_xmit_ipv6(struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) struct flowi6 *fl6, __u8 *dsfield,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) int *encap_limit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) struct ipv6hdr *ipv6h;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) struct ip6_tnl *t = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) __u16 offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) offset = ip6_tnl_parse_tlv_enc_lim(skb, skb_network_header(skb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) /* ip6_tnl_parse_tlv_enc_lim() might have reallocated skb->head */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) ipv6h = ipv6_hdr(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) if (offset > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) struct ipv6_tlv_tnl_enc_lim *tel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) tel = (struct ipv6_tlv_tnl_enc_lim *)&skb_network_header(skb)[offset];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) if (tel->encap_limit == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) icmpv6_ndo_send(skb, ICMPV6_PARAMPROB,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) ICMPV6_HDR_FIELD, offset + 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) *encap_limit = tel->encap_limit - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) } else if (!(t->parms.flags & IP6_TNL_F_IGN_ENCAP_LIMIT)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) *encap_limit = t->parms.encap_limit;
^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) memcpy(fl6, &t->fl.u.ip6, sizeof(*fl6));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) if (t->parms.flags & IP6_TNL_F_USE_ORIG_TCLASS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) *dsfield = ipv6_get_dsfield(ipv6h);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) *dsfield = ip6_tclass(t->parms.flowinfo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) if (t->parms.flags & IP6_TNL_F_USE_ORIG_FLOWLABEL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) fl6->flowlabel |= ip6_flowlabel(ipv6h);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) if (t->parms.flags & IP6_TNL_F_USE_ORIG_FWMARK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) fl6->flowi6_mark = skb->mark;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) fl6->flowi6_mark = t->parms.fwmark;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) fl6->flowi6_uid = sock_net_uid(dev_net(dev), NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) static struct ip_tunnel_info *skb_tunnel_info_txcheck(struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) struct ip_tunnel_info *tun_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) tun_info = skb_tunnel_info(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) if (unlikely(!tun_info || !(tun_info->mode & IP_TUNNEL_INFO_TX)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) return ERR_PTR(-EINVAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) return tun_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) static netdev_tx_t __gre6_xmit(struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) struct net_device *dev, __u8 dsfield,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) struct flowi6 *fl6, int encap_limit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) __u32 *pmtu, __be16 proto)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) struct ip6_tnl *tunnel = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) __be16 protocol;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) if (dev->type == ARPHRD_ETHER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) IPCB(skb)->flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) if (dev->header_ops && dev->type == ARPHRD_IP6GRE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) fl6->daddr = ((struct ipv6hdr *)skb->data)->daddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) fl6->daddr = tunnel->parms.raddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) if (skb_cow_head(skb, dev->needed_headroom ?: tunnel->hlen))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) /* Push GRE header. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) protocol = (dev->type == ARPHRD_ETHER) ? htons(ETH_P_TEB) : proto;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) if (tunnel->parms.collect_md) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) struct ip_tunnel_info *tun_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) const struct ip_tunnel_key *key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) __be16 flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) tun_info = skb_tunnel_info_txcheck(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) if (IS_ERR(tun_info) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) unlikely(ip_tunnel_info_af(tun_info) != AF_INET6))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) key = &tun_info->key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) memset(fl6, 0, sizeof(*fl6));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) fl6->flowi6_proto = IPPROTO_GRE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) fl6->daddr = key->u.ipv6.dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) fl6->flowlabel = key->label;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) fl6->flowi6_uid = sock_net_uid(dev_net(dev), NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) fl6->fl6_gre_key = tunnel_id_to_key32(key->tun_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) dsfield = key->tos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) flags = key->tun_flags &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) (TUNNEL_CSUM | TUNNEL_KEY | TUNNEL_SEQ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) tunnel->tun_hlen = gre_calc_hlen(flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) gre_build_header(skb, tunnel->tun_hlen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) flags, protocol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) tunnel_id_to_key32(tun_info->key.tun_id),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) (flags & TUNNEL_SEQ) ? htonl(tunnel->o_seqno++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) : 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) if (tunnel->parms.o_flags & TUNNEL_SEQ)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) tunnel->o_seqno++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) gre_build_header(skb, tunnel->tun_hlen, tunnel->parms.o_flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) protocol, tunnel->parms.o_key,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) htonl(tunnel->o_seqno));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) return ip6_tnl_xmit(skb, dev, dsfield, fl6, encap_limit, pmtu,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) NEXTHDR_GRE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) static inline int ip6gre_xmit_ipv4(struct sk_buff *skb, struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) struct ip6_tnl *t = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) int encap_limit = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) struct flowi6 fl6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) __u8 dsfield = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) __u32 mtu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) memset(&(IPCB(skb)->opt), 0, sizeof(IPCB(skb)->opt));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) if (!t->parms.collect_md)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) prepare_ip6gre_xmit_ipv4(skb, dev, &fl6,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) &dsfield, &encap_limit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) err = gre_handle_offloads(skb, !!(t->parms.o_flags & TUNNEL_CSUM));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) err = __gre6_xmit(skb, dev, dsfield, &fl6, encap_limit, &mtu,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) skb->protocol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) if (err != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) /* XXX: send ICMP error even if DF is not set. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) if (err == -EMSGSIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) icmp_ndo_send(skb, ICMP_DEST_UNREACH, ICMP_FRAG_NEEDED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) htonl(mtu));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) static inline int ip6gre_xmit_ipv6(struct sk_buff *skb, struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) struct ip6_tnl *t = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) struct ipv6hdr *ipv6h = ipv6_hdr(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) int encap_limit = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) struct flowi6 fl6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) __u8 dsfield = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) __u32 mtu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) if (ipv6_addr_equal(&t->parms.raddr, &ipv6h->saddr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) if (!t->parms.collect_md &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) prepare_ip6gre_xmit_ipv6(skb, dev, &fl6, &dsfield, &encap_limit))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) if (gre_handle_offloads(skb, !!(t->parms.o_flags & TUNNEL_CSUM)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) err = __gre6_xmit(skb, dev, dsfield, &fl6, encap_limit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) &mtu, skb->protocol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) if (err != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) if (err == -EMSGSIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) icmpv6_ndo_send(skb, ICMPV6_PKT_TOOBIG, 0, mtu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) * ip6gre_tnl_addr_conflict - compare packet addresses to tunnel's own
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) * @t: the outgoing tunnel device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) * @hdr: IPv6 header from the incoming packet
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) * Description:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) * Avoid trivial tunneling loop by checking that tunnel exit-point
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) * doesn't match source of incoming packet.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) * Return:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) * 1 if conflict,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) * 0 else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) static inline bool ip6gre_tnl_addr_conflict(const struct ip6_tnl *t,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) const struct ipv6hdr *hdr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) return ipv6_addr_equal(&t->parms.raddr, &hdr->saddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) static int ip6gre_xmit_other(struct sk_buff *skb, struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) struct ip6_tnl *t = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) int encap_limit = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) struct flowi6 fl6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) __u32 mtu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) if (!(t->parms.flags & IP6_TNL_F_IGN_ENCAP_LIMIT))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) encap_limit = t->parms.encap_limit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) if (!t->parms.collect_md)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) memcpy(&fl6, &t->fl.u.ip6, sizeof(fl6));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) err = gre_handle_offloads(skb, !!(t->parms.o_flags & TUNNEL_CSUM));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) err = __gre6_xmit(skb, dev, 0, &fl6, encap_limit, &mtu, skb->protocol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) static netdev_tx_t ip6gre_tunnel_xmit(struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) struct ip6_tnl *t = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) struct net_device_stats *stats = &t->dev->stats;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) if (!pskb_inet_may_pull(skb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) goto tx_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) if (!ip6_tnl_xmit_ctl(t, &t->parms.laddr, &t->parms.raddr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) goto tx_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) switch (skb->protocol) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904) case htons(ETH_P_IP):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) ret = ip6gre_xmit_ipv4(skb, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) case htons(ETH_P_IPV6):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908) ret = ip6gre_xmit_ipv6(skb, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) ret = ip6gre_xmit_other(skb, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916) goto tx_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918) return NETDEV_TX_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) tx_err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921) if (!t->parms.collect_md || !IS_ERR(skb_tunnel_info_txcheck(skb)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) stats->tx_errors++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923) stats->tx_dropped++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924) kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925) return NETDEV_TX_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) static netdev_tx_t ip6erspan_tunnel_xmit(struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929) struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931) struct ip_tunnel_info *tun_info = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932) struct ip6_tnl *t = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933) struct dst_entry *dst = skb_dst(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934) struct net_device_stats *stats;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935) bool truncate = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936) int encap_limit = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937) __u8 dsfield = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938) struct flowi6 fl6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939) int err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940) __be16 proto;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941) __u32 mtu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942) int nhoff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943) int thoff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945) if (!pskb_inet_may_pull(skb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946) goto tx_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948) if (!ip6_tnl_xmit_ctl(t, &t->parms.laddr, &t->parms.raddr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949) goto tx_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951) if (gre_handle_offloads(skb, false))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952) goto tx_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954) if (skb->len > dev->mtu + dev->hard_header_len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955) pskb_trim(skb, dev->mtu + dev->hard_header_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956) truncate = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 957) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 958)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 959) nhoff = skb_network_header(skb) - skb_mac_header(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960) if (skb->protocol == htons(ETH_P_IP) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961) (ntohs(ip_hdr(skb)->tot_len) > skb->len - nhoff))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962) truncate = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 963)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 964) thoff = skb_transport_header(skb) - skb_mac_header(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 965) if (skb->protocol == htons(ETH_P_IPV6) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 966) (ntohs(ipv6_hdr(skb)->payload_len) > skb->len - thoff))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 967) truncate = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 968)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 969) if (skb_cow_head(skb, dev->needed_headroom ?: t->hlen))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 970) goto tx_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 971)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 972) t->parms.o_flags &= ~TUNNEL_KEY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 973) IPCB(skb)->flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 974)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 975) /* For collect_md mode, derive fl6 from the tunnel key,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 976) * for native mode, call prepare_ip6gre_xmit_{ipv4,ipv6}.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 977) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 978) if (t->parms.collect_md) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 979) const struct ip_tunnel_key *key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 980) struct erspan_metadata *md;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 981) __be32 tun_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 982)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 983) tun_info = skb_tunnel_info_txcheck(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 984) if (IS_ERR(tun_info) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 985) unlikely(ip_tunnel_info_af(tun_info) != AF_INET6))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 986) goto tx_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 987)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 988) key = &tun_info->key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 989) memset(&fl6, 0, sizeof(fl6));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 990) fl6.flowi6_proto = IPPROTO_GRE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 991) fl6.daddr = key->u.ipv6.dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 992) fl6.flowlabel = key->label;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 993) fl6.flowi6_uid = sock_net_uid(dev_net(dev), NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 994) fl6.fl6_gre_key = tunnel_id_to_key32(key->tun_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 995)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 996) dsfield = key->tos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 997) if (!(tun_info->key.tun_flags & TUNNEL_ERSPAN_OPT))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 998) goto tx_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 999) if (tun_info->options_len < sizeof(*md))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) goto tx_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) md = ip_tunnel_info_opts(tun_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) tun_id = tunnel_id_to_key32(key->tun_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) if (md->version == 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) erspan_build_header(skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) ntohl(tun_id),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) ntohl(md->u.index), truncate,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) } else if (md->version == 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) erspan_build_header_v2(skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) ntohl(tun_id),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) md->u.md2.dir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) get_hwid(&md->u.md2),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) truncate, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) goto tx_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) switch (skb->protocol) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) case htons(ETH_P_IP):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) memset(&(IPCB(skb)->opt), 0, sizeof(IPCB(skb)->opt));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) prepare_ip6gre_xmit_ipv4(skb, dev, &fl6,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) &dsfield, &encap_limit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) case htons(ETH_P_IPV6):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) if (ipv6_addr_equal(&t->parms.raddr, &ipv6_hdr(skb)->saddr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) goto tx_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) if (prepare_ip6gre_xmit_ipv6(skb, dev, &fl6,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) &dsfield, &encap_limit))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) goto tx_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) memcpy(&fl6, &t->fl.u.ip6, sizeof(fl6));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) if (t->parms.erspan_ver == 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) erspan_build_header(skb, ntohl(t->parms.o_key),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) t->parms.index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) truncate, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) else if (t->parms.erspan_ver == 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) erspan_build_header_v2(skb, ntohl(t->parms.o_key),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) t->parms.dir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) t->parms.hwid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) truncate, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) goto tx_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) fl6.daddr = t->parms.raddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) /* Push GRE header. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) proto = (t->parms.erspan_ver == 1) ? htons(ETH_P_ERSPAN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) : htons(ETH_P_ERSPAN2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) gre_build_header(skb, 8, TUNNEL_SEQ, proto, 0, htonl(t->o_seqno++));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) /* TooBig packet may have updated dst->dev's mtu */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) if (!t->parms.collect_md && dst && dst_mtu(dst) > dst->dev->mtu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) dst->ops->update_pmtu(dst, NULL, skb, dst->dev->mtu, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) err = ip6_tnl_xmit(skb, dev, dsfield, &fl6, encap_limit, &mtu,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) NEXTHDR_GRE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) if (err != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) /* XXX: send ICMP error even if DF is not set. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) if (err == -EMSGSIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) if (skb->protocol == htons(ETH_P_IP))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) icmp_ndo_send(skb, ICMP_DEST_UNREACH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) ICMP_FRAG_NEEDED, htonl(mtu));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) icmpv6_ndo_send(skb, ICMPV6_PKT_TOOBIG, 0, mtu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) goto tx_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) return NETDEV_TX_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) tx_err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) stats = &t->dev->stats;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) if (!IS_ERR(tun_info))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) stats->tx_errors++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) stats->tx_dropped++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) return NETDEV_TX_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) static void ip6gre_tnl_link_config_common(struct ip6_tnl *t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) struct net_device *dev = t->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) struct __ip6_tnl_parm *p = &t->parms;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) struct flowi6 *fl6 = &t->fl.u.ip6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) if (dev->type != ARPHRD_ETHER) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) memcpy(dev->dev_addr, &p->laddr, sizeof(struct in6_addr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) memcpy(dev->broadcast, &p->raddr, sizeof(struct in6_addr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) /* Set up flowi template */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) fl6->saddr = p->laddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) fl6->daddr = p->raddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) fl6->flowi6_oif = p->link;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) fl6->flowlabel = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) fl6->flowi6_proto = IPPROTO_GRE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) fl6->fl6_gre_key = t->parms.o_key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) if (!(p->flags&IP6_TNL_F_USE_ORIG_TCLASS))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) fl6->flowlabel |= IPV6_TCLASS_MASK & p->flowinfo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) if (!(p->flags&IP6_TNL_F_USE_ORIG_FLOWLABEL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) fl6->flowlabel |= IPV6_FLOWLABEL_MASK & p->flowinfo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) p->flags &= ~(IP6_TNL_F_CAP_XMIT|IP6_TNL_F_CAP_RCV|IP6_TNL_F_CAP_PER_PACKET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) p->flags |= ip6_tnl_get_cap(t, &p->laddr, &p->raddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) if (p->flags&IP6_TNL_F_CAP_XMIT &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) p->flags&IP6_TNL_F_CAP_RCV && dev->type != ARPHRD_ETHER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) dev->flags |= IFF_POINTOPOINT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) dev->flags &= ~IFF_POINTOPOINT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) static void ip6gre_tnl_link_config_route(struct ip6_tnl *t, int set_mtu,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) int t_hlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) const struct __ip6_tnl_parm *p = &t->parms;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) struct net_device *dev = t->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) if (p->flags & IP6_TNL_F_CAP_XMIT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) int strict = (ipv6_addr_type(&p->raddr) &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) (IPV6_ADDR_MULTICAST|IPV6_ADDR_LINKLOCAL));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) struct rt6_info *rt = rt6_lookup(t->net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) &p->raddr, &p->laddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) p->link, NULL, strict);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) if (!rt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) if (rt->dst.dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) unsigned short dst_len = rt->dst.dev->hard_header_len +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) t_hlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) if (t->dev->header_ops)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) dev->hard_header_len = dst_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) dev->needed_headroom = dst_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) if (set_mtu) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) dev->mtu = rt->dst.dev->mtu - t_hlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) if (!(t->parms.flags & IP6_TNL_F_IGN_ENCAP_LIMIT))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) dev->mtu -= 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) if (dev->type == ARPHRD_ETHER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) dev->mtu -= ETH_HLEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) if (dev->mtu < IPV6_MIN_MTU)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) dev->mtu = IPV6_MIN_MTU;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) ip6_rt_put(rt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) static int ip6gre_calc_hlen(struct ip6_tnl *tunnel)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) int t_hlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) tunnel->tun_hlen = gre_calc_hlen(tunnel->parms.o_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) tunnel->hlen = tunnel->tun_hlen + tunnel->encap_hlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) t_hlen = tunnel->hlen + sizeof(struct ipv6hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) if (tunnel->dev->header_ops)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) tunnel->dev->hard_header_len = LL_MAX_HEADER + t_hlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) tunnel->dev->needed_headroom = LL_MAX_HEADER + t_hlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) return t_hlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) static void ip6gre_tnl_link_config(struct ip6_tnl *t, int set_mtu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) ip6gre_tnl_link_config_common(t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) ip6gre_tnl_link_config_route(t, set_mtu, ip6gre_calc_hlen(t));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) static void ip6gre_tnl_copy_tnl_parm(struct ip6_tnl *t,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) const struct __ip6_tnl_parm *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) t->parms.laddr = p->laddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) t->parms.raddr = p->raddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) t->parms.flags = p->flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) t->parms.hop_limit = p->hop_limit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) t->parms.encap_limit = p->encap_limit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) t->parms.flowinfo = p->flowinfo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) t->parms.link = p->link;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) t->parms.proto = p->proto;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) t->parms.i_key = p->i_key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) t->parms.o_key = p->o_key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) t->parms.i_flags = p->i_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) t->parms.o_flags = p->o_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) t->parms.fwmark = p->fwmark;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) t->parms.erspan_ver = p->erspan_ver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) t->parms.index = p->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) t->parms.dir = p->dir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) t->parms.hwid = p->hwid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) dst_cache_reset(&t->dst_cache);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) static int ip6gre_tnl_change(struct ip6_tnl *t, const struct __ip6_tnl_parm *p,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) int set_mtu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) ip6gre_tnl_copy_tnl_parm(t, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) ip6gre_tnl_link_config(t, set_mtu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) static void ip6gre_tnl_parm_from_user(struct __ip6_tnl_parm *p,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) const struct ip6_tnl_parm2 *u)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) p->laddr = u->laddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) p->raddr = u->raddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) p->flags = u->flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) p->hop_limit = u->hop_limit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) p->encap_limit = u->encap_limit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) p->flowinfo = u->flowinfo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) p->link = u->link;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) p->i_key = u->i_key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) p->o_key = u->o_key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) p->i_flags = gre_flags_to_tnl_flags(u->i_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) p->o_flags = gre_flags_to_tnl_flags(u->o_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) memcpy(p->name, u->name, sizeof(u->name));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) static void ip6gre_tnl_parm_to_user(struct ip6_tnl_parm2 *u,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) const struct __ip6_tnl_parm *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) u->proto = IPPROTO_GRE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) u->laddr = p->laddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) u->raddr = p->raddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) u->flags = p->flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) u->hop_limit = p->hop_limit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) u->encap_limit = p->encap_limit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) u->flowinfo = p->flowinfo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) u->link = p->link;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) u->i_key = p->i_key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) u->o_key = p->o_key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) u->i_flags = gre_tnl_flags_to_gre_flags(p->i_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) u->o_flags = gre_tnl_flags_to_gre_flags(p->o_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) memcpy(u->name, p->name, sizeof(u->name));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) static int ip6gre_tunnel_ioctl(struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) struct ifreq *ifr, int cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) struct ip6_tnl_parm2 p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) struct __ip6_tnl_parm p1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) struct ip6_tnl *t = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) struct net *net = t->net;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) struct ip6gre_net *ign = net_generic(net, ip6gre_net_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) memset(&p1, 0, sizeof(p1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) switch (cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) case SIOCGETTUNNEL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) if (dev == ign->fb_tunnel_dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) if (copy_from_user(&p, ifr->ifr_ifru.ifru_data, sizeof(p))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) err = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) ip6gre_tnl_parm_from_user(&p1, &p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) t = ip6gre_tunnel_locate(net, &p1, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) if (!t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) t = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) memset(&p, 0, sizeof(p));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) ip6gre_tnl_parm_to_user(&p, &t->parms);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) if (copy_to_user(ifr->ifr_ifru.ifru_data, &p, sizeof(p)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) err = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) case SIOCADDTUNNEL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) case SIOCCHGTUNNEL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) err = -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) err = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287) if (copy_from_user(&p, ifr->ifr_ifru.ifru_data, sizeof(p)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) if ((p.i_flags|p.o_flags)&(GRE_VERSION|GRE_ROUTING))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) if (!(p.i_flags&GRE_KEY))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) p.i_key = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) if (!(p.o_flags&GRE_KEY))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) p.o_key = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) ip6gre_tnl_parm_from_user(&p1, &p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) t = ip6gre_tunnel_locate(net, &p1, cmd == SIOCADDTUNNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) if (dev != ign->fb_tunnel_dev && cmd == SIOCCHGTUNNEL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) if (t) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) if (t->dev != dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) err = -EEXIST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) t = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) ip6gre_tunnel_unlink(ign, t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) synchronize_net();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) ip6gre_tnl_change(t, &p1, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) ip6gre_tunnel_link(ign, t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) netdev_state_change(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) if (t) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) memset(&p, 0, sizeof(p));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) ip6gre_tnl_parm_to_user(&p, &t->parms);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324) if (copy_to_user(ifr->ifr_ifru.ifru_data, &p, sizeof(p)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) err = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) err = (cmd == SIOCADDTUNNEL ? -ENOBUFS : -ENOENT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330) case SIOCDELTUNNEL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) err = -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332) if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333) goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335) if (dev == ign->fb_tunnel_dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336) err = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) if (copy_from_user(&p, ifr->ifr_ifru.ifru_data, sizeof(p)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339) err = -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) ip6gre_tnl_parm_from_user(&p1, &p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341) t = ip6gre_tunnel_locate(net, &p1, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342) if (!t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) err = -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345) if (t == netdev_priv(ign->fb_tunnel_dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346) goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347) dev = t->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349) unregister_netdevice(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350) err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354) err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357) done:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361) static int ip6gre_header(struct sk_buff *skb, struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362) unsigned short type, const void *daddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363) const void *saddr, unsigned int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365) struct ip6_tnl *t = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366) struct ipv6hdr *ipv6h;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) __be16 *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369) ipv6h = skb_push(skb, t->hlen + sizeof(*ipv6h));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370) ip6_flow_hdr(ipv6h, 0, ip6_make_flowlabel(dev_net(dev), skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371) t->fl.u.ip6.flowlabel,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372) true, &t->fl.u.ip6));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373) ipv6h->hop_limit = t->parms.hop_limit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374) ipv6h->nexthdr = NEXTHDR_GRE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375) ipv6h->saddr = t->parms.laddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376) ipv6h->daddr = t->parms.raddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378) p = (__be16 *)(ipv6h + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379) p[0] = t->parms.o_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) p[1] = htons(type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383) * Set the source hardware address.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386) if (saddr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387) memcpy(&ipv6h->saddr, saddr, sizeof(struct in6_addr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388) if (daddr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389) memcpy(&ipv6h->daddr, daddr, sizeof(struct in6_addr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390) if (!ipv6_addr_any(&ipv6h->daddr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391) return t->hlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393) return -t->hlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396) static const struct header_ops ip6gre_header_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397) .create = ip6gre_header,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400) static const struct net_device_ops ip6gre_netdev_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401) .ndo_init = ip6gre_tunnel_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402) .ndo_uninit = ip6gre_tunnel_uninit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403) .ndo_start_xmit = ip6gre_tunnel_xmit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404) .ndo_do_ioctl = ip6gre_tunnel_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405) .ndo_change_mtu = ip6_tnl_change_mtu,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406) .ndo_get_stats64 = ip_tunnel_get_stats64,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407) .ndo_get_iflink = ip6_tnl_get_iflink,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410) static void ip6gre_dev_free(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412) struct ip6_tnl *t = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414) gro_cells_destroy(&t->gro_cells);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415) dst_cache_destroy(&t->dst_cache);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1416) free_percpu(dev->tstats);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1417) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1418)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1419) static void ip6gre_tunnel_setup(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1420) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1421) dev->netdev_ops = &ip6gre_netdev_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1422) dev->needs_free_netdev = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1423) dev->priv_destructor = ip6gre_dev_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1424)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1425) dev->type = ARPHRD_IP6GRE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1426)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1427) dev->flags |= IFF_NOARP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1428) dev->addr_len = sizeof(struct in6_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1429) netif_keep_dst(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1430) /* This perm addr will be used as interface identifier by IPv6 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1431) dev->addr_assign_type = NET_ADDR_RANDOM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1432) eth_random_addr(dev->perm_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1433) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1434)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1435) #define GRE6_FEATURES (NETIF_F_SG | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1436) NETIF_F_FRAGLIST | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1437) NETIF_F_HIGHDMA | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1438) NETIF_F_HW_CSUM)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1439)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1440) static void ip6gre_tnl_init_features(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1441) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1442) struct ip6_tnl *nt = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1443)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1444) dev->features |= GRE6_FEATURES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1445) dev->hw_features |= GRE6_FEATURES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1446)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1447) if (!(nt->parms.o_flags & TUNNEL_SEQ)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1448) /* TCP offload with GRE SEQ is not supported, nor
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1449) * can we support 2 levels of outer headers requiring
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1450) * an update.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1451) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1452) if (!(nt->parms.o_flags & TUNNEL_CSUM) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1453) nt->encap.type == TUNNEL_ENCAP_NONE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1454) dev->features |= NETIF_F_GSO_SOFTWARE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1455) dev->hw_features |= NETIF_F_GSO_SOFTWARE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1456) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1457)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1458) /* Can use a lockless transmit, unless we generate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1459) * output sequences
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1460) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1461) dev->features |= NETIF_F_LLTX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1462) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1463) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1464)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1465) static int ip6gre_tunnel_init_common(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1466) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1467) struct ip6_tnl *tunnel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1468) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1469) int t_hlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1470)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1471) tunnel = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1472)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1473) tunnel->dev = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1474) tunnel->net = dev_net(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1475) strcpy(tunnel->parms.name, dev->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1476)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1477) dev->tstats = netdev_alloc_pcpu_stats(struct pcpu_sw_netstats);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1478) if (!dev->tstats)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1479) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1480)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1481) ret = dst_cache_init(&tunnel->dst_cache, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1482) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1483) goto cleanup_alloc_pcpu_stats;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1484)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1485) ret = gro_cells_init(&tunnel->gro_cells, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1486) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1487) goto cleanup_dst_cache_init;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1488)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1489) t_hlen = ip6gre_calc_hlen(tunnel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1490) dev->mtu = ETH_DATA_LEN - t_hlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1491) if (dev->type == ARPHRD_ETHER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1492) dev->mtu -= ETH_HLEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1493) if (!(tunnel->parms.flags & IP6_TNL_F_IGN_ENCAP_LIMIT))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1494) dev->mtu -= 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1495)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1496) if (tunnel->parms.collect_md) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1497) netif_keep_dst(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1498) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1499) ip6gre_tnl_init_features(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1500)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1501) dev_hold(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1502) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1503)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1504) cleanup_dst_cache_init:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1505) dst_cache_destroy(&tunnel->dst_cache);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1506) cleanup_alloc_pcpu_stats:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1507) free_percpu(dev->tstats);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1508) dev->tstats = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1509) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1510) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1511)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1512) static int ip6gre_tunnel_init(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1513) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1514) struct ip6_tnl *tunnel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1515) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1516)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1517) ret = ip6gre_tunnel_init_common(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1518) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1519) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1520)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1521) tunnel = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1522)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1523) if (tunnel->parms.collect_md)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1524) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1525)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1526) memcpy(dev->dev_addr, &tunnel->parms.laddr, sizeof(struct in6_addr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1527) memcpy(dev->broadcast, &tunnel->parms.raddr, sizeof(struct in6_addr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1528)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1529) if (ipv6_addr_any(&tunnel->parms.raddr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1530) dev->header_ops = &ip6gre_header_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1531)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1532) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1533) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1534)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1535) static void ip6gre_fb_tunnel_init(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1536) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1537) struct ip6_tnl *tunnel = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1538)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1539) tunnel->dev = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1540) tunnel->net = dev_net(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1541) strcpy(tunnel->parms.name, dev->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1542)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1543) tunnel->hlen = sizeof(struct ipv6hdr) + 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1544) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1545)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1546) static struct inet6_protocol ip6gre_protocol __read_mostly = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1547) .handler = gre_rcv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1548) .err_handler = ip6gre_err,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1549) .flags = INET6_PROTO_FINAL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1550) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1551)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1552) static void ip6gre_destroy_tunnels(struct net *net, struct list_head *head)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1553) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1554) struct ip6gre_net *ign = net_generic(net, ip6gre_net_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1555) struct net_device *dev, *aux;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1556) int prio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1557)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1558) for_each_netdev_safe(net, dev, aux)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1559) if (dev->rtnl_link_ops == &ip6gre_link_ops ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1560) dev->rtnl_link_ops == &ip6gre_tap_ops ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1561) dev->rtnl_link_ops == &ip6erspan_tap_ops)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1562) unregister_netdevice_queue(dev, head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1563)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1564) for (prio = 0; prio < 4; prio++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1565) int h;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1566) for (h = 0; h < IP6_GRE_HASH_SIZE; h++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1567) struct ip6_tnl *t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1568)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1569) t = rtnl_dereference(ign->tunnels[prio][h]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1570)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1571) while (t) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1572) /* If dev is in the same netns, it has already
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1573) * been added to the list by the previous loop.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1574) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1575) if (!net_eq(dev_net(t->dev), net))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1576) unregister_netdevice_queue(t->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1577) head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1578) t = rtnl_dereference(t->next);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1579) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1580) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1581) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1582) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1583)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1584) static int __net_init ip6gre_init_net(struct net *net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1585) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1586) struct ip6gre_net *ign = net_generic(net, ip6gre_net_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1587) struct net_device *ndev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1588) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1589)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1590) if (!net_has_fallback_tunnels(net))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1591) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1592) ndev = alloc_netdev(sizeof(struct ip6_tnl), "ip6gre0",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1593) NET_NAME_UNKNOWN, ip6gre_tunnel_setup);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1594) if (!ndev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1595) err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1596) goto err_alloc_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1597) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1598) ign->fb_tunnel_dev = ndev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1599) dev_net_set(ign->fb_tunnel_dev, net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1600) /* FB netdevice is special: we have one, and only one per netns.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1601) * Allowing to move it to another netns is clearly unsafe.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1602) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1603) ign->fb_tunnel_dev->features |= NETIF_F_NETNS_LOCAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1604)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1605)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1606) ip6gre_fb_tunnel_init(ign->fb_tunnel_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1607) ign->fb_tunnel_dev->rtnl_link_ops = &ip6gre_link_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1608)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1609) err = register_netdev(ign->fb_tunnel_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1610) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1611) goto err_reg_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1612)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1613) rcu_assign_pointer(ign->tunnels_wc[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1614) netdev_priv(ign->fb_tunnel_dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1615) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1616)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1617) err_reg_dev:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1618) free_netdev(ndev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1619) err_alloc_dev:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1620) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1621) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1622)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1623) static void __net_exit ip6gre_exit_batch_net(struct list_head *net_list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1624) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1625) struct net *net;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1626) LIST_HEAD(list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1627)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1628) rtnl_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1629) list_for_each_entry(net, net_list, exit_list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1630) ip6gre_destroy_tunnels(net, &list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1631) unregister_netdevice_many(&list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1632) rtnl_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1633) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1634)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1635) static struct pernet_operations ip6gre_net_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1636) .init = ip6gre_init_net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1637) .exit_batch = ip6gre_exit_batch_net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1638) .id = &ip6gre_net_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1639) .size = sizeof(struct ip6gre_net),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1640) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1641)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1642) static int ip6gre_tunnel_validate(struct nlattr *tb[], struct nlattr *data[],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1643) struct netlink_ext_ack *extack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1644) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1645) __be16 flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1646)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1647) if (!data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1648) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1649)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1650) flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1651) if (data[IFLA_GRE_IFLAGS])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1652) flags |= nla_get_be16(data[IFLA_GRE_IFLAGS]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1653) if (data[IFLA_GRE_OFLAGS])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1654) flags |= nla_get_be16(data[IFLA_GRE_OFLAGS]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1655) if (flags & (GRE_VERSION|GRE_ROUTING))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1656) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1657)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1658) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1659) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1660)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1661) static int ip6gre_tap_validate(struct nlattr *tb[], struct nlattr *data[],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1662) struct netlink_ext_ack *extack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1663) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1664) struct in6_addr daddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1665)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1666) if (tb[IFLA_ADDRESS]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1667) if (nla_len(tb[IFLA_ADDRESS]) != ETH_ALEN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1668) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1669) if (!is_valid_ether_addr(nla_data(tb[IFLA_ADDRESS])))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1670) return -EADDRNOTAVAIL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1671) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1672)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1673) if (!data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1674) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1675)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1676) if (data[IFLA_GRE_REMOTE]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1677) daddr = nla_get_in6_addr(data[IFLA_GRE_REMOTE]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1678) if (ipv6_addr_any(&daddr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1679) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1680) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1681)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1682) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1683) return ip6gre_tunnel_validate(tb, data, extack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1684) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1685)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1686) static int ip6erspan_tap_validate(struct nlattr *tb[], struct nlattr *data[],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1687) struct netlink_ext_ack *extack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1688) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1689) __be16 flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1690) int ret, ver = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1691)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1692) if (!data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1693) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1694)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1695) ret = ip6gre_tap_validate(tb, data, extack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1696) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1697) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1698)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1699) /* ERSPAN should only have GRE sequence and key flag */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1700) if (data[IFLA_GRE_OFLAGS])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1701) flags |= nla_get_be16(data[IFLA_GRE_OFLAGS]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1702) if (data[IFLA_GRE_IFLAGS])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1703) flags |= nla_get_be16(data[IFLA_GRE_IFLAGS]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1704) if (!data[IFLA_GRE_COLLECT_METADATA] &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1705) flags != (GRE_SEQ | GRE_KEY))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1706) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1707)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1708) /* ERSPAN Session ID only has 10-bit. Since we reuse
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1709) * 32-bit key field as ID, check it's range.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1710) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1711) if (data[IFLA_GRE_IKEY] &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1712) (ntohl(nla_get_be32(data[IFLA_GRE_IKEY])) & ~ID_MASK))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1713) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1714)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1715) if (data[IFLA_GRE_OKEY] &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1716) (ntohl(nla_get_be32(data[IFLA_GRE_OKEY])) & ~ID_MASK))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1717) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1718)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1719) if (data[IFLA_GRE_ERSPAN_VER]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1720) ver = nla_get_u8(data[IFLA_GRE_ERSPAN_VER]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1721) if (ver != 1 && ver != 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1722) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1723) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1724)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1725) if (ver == 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1726) if (data[IFLA_GRE_ERSPAN_INDEX]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1727) u32 index = nla_get_u32(data[IFLA_GRE_ERSPAN_INDEX]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1728)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1729) if (index & ~INDEX_MASK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1730) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1731) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1732) } else if (ver == 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1733) if (data[IFLA_GRE_ERSPAN_DIR]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1734) u16 dir = nla_get_u8(data[IFLA_GRE_ERSPAN_DIR]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1735)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1736) if (dir & ~(DIR_MASK >> DIR_OFFSET))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1737) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1738) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1739)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1740) if (data[IFLA_GRE_ERSPAN_HWID]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1741) u16 hwid = nla_get_u16(data[IFLA_GRE_ERSPAN_HWID]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1742)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1743) if (hwid & ~(HWID_MASK >> HWID_OFFSET))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1744) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1745) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1746) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1747)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1748) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1749) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1750)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1751) static void ip6erspan_set_version(struct nlattr *data[],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1752) struct __ip6_tnl_parm *parms)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1753) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1754) if (!data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1755) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1756)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1757) parms->erspan_ver = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1758) if (data[IFLA_GRE_ERSPAN_VER])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1759) parms->erspan_ver = nla_get_u8(data[IFLA_GRE_ERSPAN_VER]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1760)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1761) if (parms->erspan_ver == 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1762) if (data[IFLA_GRE_ERSPAN_INDEX])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1763) parms->index = nla_get_u32(data[IFLA_GRE_ERSPAN_INDEX]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1764) } else if (parms->erspan_ver == 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1765) if (data[IFLA_GRE_ERSPAN_DIR])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1766) parms->dir = nla_get_u8(data[IFLA_GRE_ERSPAN_DIR]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1767) if (data[IFLA_GRE_ERSPAN_HWID])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1768) parms->hwid = nla_get_u16(data[IFLA_GRE_ERSPAN_HWID]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1769) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1770) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1771)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1772) static void ip6gre_netlink_parms(struct nlattr *data[],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1773) struct __ip6_tnl_parm *parms)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1774) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1775) memset(parms, 0, sizeof(*parms));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1776)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1777) if (!data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1778) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1779)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1780) if (data[IFLA_GRE_LINK])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1781) parms->link = nla_get_u32(data[IFLA_GRE_LINK]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1782)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1783) if (data[IFLA_GRE_IFLAGS])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1784) parms->i_flags = gre_flags_to_tnl_flags(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1785) nla_get_be16(data[IFLA_GRE_IFLAGS]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1786)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1787) if (data[IFLA_GRE_OFLAGS])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1788) parms->o_flags = gre_flags_to_tnl_flags(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1789) nla_get_be16(data[IFLA_GRE_OFLAGS]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1790)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1791) if (data[IFLA_GRE_IKEY])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1792) parms->i_key = nla_get_be32(data[IFLA_GRE_IKEY]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1793)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1794) if (data[IFLA_GRE_OKEY])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1795) parms->o_key = nla_get_be32(data[IFLA_GRE_OKEY]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1796)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1797) if (data[IFLA_GRE_LOCAL])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1798) parms->laddr = nla_get_in6_addr(data[IFLA_GRE_LOCAL]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1799)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1800) if (data[IFLA_GRE_REMOTE])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1801) parms->raddr = nla_get_in6_addr(data[IFLA_GRE_REMOTE]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1802)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1803) if (data[IFLA_GRE_TTL])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1804) parms->hop_limit = nla_get_u8(data[IFLA_GRE_TTL]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1805)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1806) if (data[IFLA_GRE_ENCAP_LIMIT])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1807) parms->encap_limit = nla_get_u8(data[IFLA_GRE_ENCAP_LIMIT]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1808)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1809) if (data[IFLA_GRE_FLOWINFO])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1810) parms->flowinfo = nla_get_be32(data[IFLA_GRE_FLOWINFO]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1811)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1812) if (data[IFLA_GRE_FLAGS])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1813) parms->flags = nla_get_u32(data[IFLA_GRE_FLAGS]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1814)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1815) if (data[IFLA_GRE_FWMARK])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1816) parms->fwmark = nla_get_u32(data[IFLA_GRE_FWMARK]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1817)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1818) if (data[IFLA_GRE_COLLECT_METADATA])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1819) parms->collect_md = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1820) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1821)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1822) static int ip6gre_tap_init(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1823) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1824) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1825)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1826) ret = ip6gre_tunnel_init_common(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1827) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1828) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1829)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1830) dev->priv_flags |= IFF_LIVE_ADDR_CHANGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1831)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1832) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1833) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1834)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1835) static const struct net_device_ops ip6gre_tap_netdev_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1836) .ndo_init = ip6gre_tap_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1837) .ndo_uninit = ip6gre_tunnel_uninit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1838) .ndo_start_xmit = ip6gre_tunnel_xmit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1839) .ndo_set_mac_address = eth_mac_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1840) .ndo_validate_addr = eth_validate_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1841) .ndo_change_mtu = ip6_tnl_change_mtu,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1842) .ndo_get_stats64 = ip_tunnel_get_stats64,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1843) .ndo_get_iflink = ip6_tnl_get_iflink,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1844) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1845)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1846) static int ip6erspan_calc_hlen(struct ip6_tnl *tunnel)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1847) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1848) int t_hlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1849)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1850) tunnel->tun_hlen = 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1851) tunnel->hlen = tunnel->tun_hlen + tunnel->encap_hlen +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1852) erspan_hdr_len(tunnel->parms.erspan_ver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1853)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1854) t_hlen = tunnel->hlen + sizeof(struct ipv6hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1855) tunnel->dev->needed_headroom = LL_MAX_HEADER + t_hlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1856) return t_hlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1857) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1858)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1859) static int ip6erspan_tap_init(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1860) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1861) struct ip6_tnl *tunnel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1862) int t_hlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1863) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1864)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1865) tunnel = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1866)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1867) tunnel->dev = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1868) tunnel->net = dev_net(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1869) strcpy(tunnel->parms.name, dev->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1870)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1871) dev->tstats = netdev_alloc_pcpu_stats(struct pcpu_sw_netstats);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1872) if (!dev->tstats)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1873) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1874)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1875) ret = dst_cache_init(&tunnel->dst_cache, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1876) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1877) goto cleanup_alloc_pcpu_stats;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1878)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1879) ret = gro_cells_init(&tunnel->gro_cells, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1880) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1881) goto cleanup_dst_cache_init;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1882)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1883) t_hlen = ip6erspan_calc_hlen(tunnel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1884) dev->mtu = ETH_DATA_LEN - t_hlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1885) if (dev->type == ARPHRD_ETHER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1886) dev->mtu -= ETH_HLEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1887) if (!(tunnel->parms.flags & IP6_TNL_F_IGN_ENCAP_LIMIT))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1888) dev->mtu -= 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1889)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1890) dev->priv_flags |= IFF_LIVE_ADDR_CHANGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1891) ip6erspan_tnl_link_config(tunnel, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1892)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1893) dev_hold(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1894) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1895)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1896) cleanup_dst_cache_init:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1897) dst_cache_destroy(&tunnel->dst_cache);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1898) cleanup_alloc_pcpu_stats:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1899) free_percpu(dev->tstats);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1900) dev->tstats = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1901) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1902) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1903)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1904) static const struct net_device_ops ip6erspan_netdev_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1905) .ndo_init = ip6erspan_tap_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1906) .ndo_uninit = ip6erspan_tunnel_uninit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1907) .ndo_start_xmit = ip6erspan_tunnel_xmit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1908) .ndo_set_mac_address = eth_mac_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1909) .ndo_validate_addr = eth_validate_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1910) .ndo_change_mtu = ip6_tnl_change_mtu,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1911) .ndo_get_stats64 = ip_tunnel_get_stats64,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1912) .ndo_get_iflink = ip6_tnl_get_iflink,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1913) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1914)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1915) static void ip6gre_tap_setup(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1916) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1917)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1918) ether_setup(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1919)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1920) dev->max_mtu = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1921) dev->netdev_ops = &ip6gre_tap_netdev_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1922) dev->needs_free_netdev = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1923) dev->priv_destructor = ip6gre_dev_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1924)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1925) dev->priv_flags &= ~IFF_TX_SKB_SHARING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1926) dev->priv_flags |= IFF_LIVE_ADDR_CHANGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1927) netif_keep_dst(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1928) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1929)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1930) static bool ip6gre_netlink_encap_parms(struct nlattr *data[],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1931) struct ip_tunnel_encap *ipencap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1932) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1933) bool ret = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1934)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1935) memset(ipencap, 0, sizeof(*ipencap));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1936)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1937) if (!data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1938) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1939)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1940) if (data[IFLA_GRE_ENCAP_TYPE]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1941) ret = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1942) ipencap->type = nla_get_u16(data[IFLA_GRE_ENCAP_TYPE]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1943) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1944)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1945) if (data[IFLA_GRE_ENCAP_FLAGS]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1946) ret = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1947) ipencap->flags = nla_get_u16(data[IFLA_GRE_ENCAP_FLAGS]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1948) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1949)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1950) if (data[IFLA_GRE_ENCAP_SPORT]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1951) ret = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1952) ipencap->sport = nla_get_be16(data[IFLA_GRE_ENCAP_SPORT]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1953) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1954)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1955) if (data[IFLA_GRE_ENCAP_DPORT]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1956) ret = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1957) ipencap->dport = nla_get_be16(data[IFLA_GRE_ENCAP_DPORT]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1958) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1959)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1960) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1961) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1962)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1963) static int ip6gre_newlink_common(struct net *src_net, struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1964) struct nlattr *tb[], struct nlattr *data[],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1965) struct netlink_ext_ack *extack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1966) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1967) struct ip6_tnl *nt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1968) struct ip_tunnel_encap ipencap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1969) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1970)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1971) nt = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1972)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1973) if (ip6gre_netlink_encap_parms(data, &ipencap)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1974) int err = ip6_tnl_encap_setup(nt, &ipencap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1975)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1976) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1977) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1978) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1979)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1980) if (dev->type == ARPHRD_ETHER && !tb[IFLA_ADDRESS])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1981) eth_hw_addr_random(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1982)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1983) nt->dev = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1984) nt->net = dev_net(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1985)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1986) err = register_netdevice(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1987) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1988) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1989)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1990) if (tb[IFLA_MTU])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1991) ip6_tnl_change_mtu(dev, nla_get_u32(tb[IFLA_MTU]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1992)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1993) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1994) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1995) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1996)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1997) static int ip6gre_newlink(struct net *src_net, struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1998) struct nlattr *tb[], struct nlattr *data[],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1999) struct netlink_ext_ack *extack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2000) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2001) struct ip6_tnl *nt = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2002) struct net *net = dev_net(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2003) struct ip6gre_net *ign;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2004) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2005)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2006) ip6gre_netlink_parms(data, &nt->parms);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2007) ign = net_generic(net, ip6gre_net_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2008)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2009) if (nt->parms.collect_md) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2010) if (rtnl_dereference(ign->collect_md_tun))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2011) return -EEXIST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2012) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2013) if (ip6gre_tunnel_find(net, &nt->parms, dev->type))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2014) return -EEXIST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2015) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2016)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2017) err = ip6gre_newlink_common(src_net, dev, tb, data, extack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2018) if (!err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2019) ip6gre_tnl_link_config(nt, !tb[IFLA_MTU]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2020) ip6gre_tunnel_link_md(ign, nt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2021) ip6gre_tunnel_link(net_generic(net, ip6gre_net_id), nt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2022) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2023) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2024) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2025)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2026) static struct ip6_tnl *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2027) ip6gre_changelink_common(struct net_device *dev, struct nlattr *tb[],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2028) struct nlattr *data[], struct __ip6_tnl_parm *p_p,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2029) struct netlink_ext_ack *extack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2030) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2031) struct ip6_tnl *t, *nt = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2032) struct net *net = nt->net;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2033) struct ip6gre_net *ign = net_generic(net, ip6gre_net_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2034) struct ip_tunnel_encap ipencap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2035)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2036) if (dev == ign->fb_tunnel_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2037) return ERR_PTR(-EINVAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2038)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2039) if (ip6gre_netlink_encap_parms(data, &ipencap)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2040) int err = ip6_tnl_encap_setup(nt, &ipencap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2041)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2042) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2043) return ERR_PTR(err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2044) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2045)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2046) ip6gre_netlink_parms(data, p_p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2047)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2048) t = ip6gre_tunnel_locate(net, p_p, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2049)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2050) if (t) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2051) if (t->dev != dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2052) return ERR_PTR(-EEXIST);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2053) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2054) t = nt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2055) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2056)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2057) return t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2058) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2059)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2060) static int ip6gre_changelink(struct net_device *dev, struct nlattr *tb[],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2061) struct nlattr *data[],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2062) struct netlink_ext_ack *extack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2063) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2064) struct ip6_tnl *t = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2065) struct ip6gre_net *ign = net_generic(t->net, ip6gre_net_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2066) struct __ip6_tnl_parm p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2067)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2068) t = ip6gre_changelink_common(dev, tb, data, &p, extack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2069) if (IS_ERR(t))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2070) return PTR_ERR(t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2071)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2072) ip6gre_tunnel_unlink_md(ign, t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2073) ip6gre_tunnel_unlink(ign, t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2074) ip6gre_tnl_change(t, &p, !tb[IFLA_MTU]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2075) ip6gre_tunnel_link_md(ign, t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2076) ip6gre_tunnel_link(ign, t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2077) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2078) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2079)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2080) static void ip6gre_dellink(struct net_device *dev, struct list_head *head)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2081) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2082) struct net *net = dev_net(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2083) struct ip6gre_net *ign = net_generic(net, ip6gre_net_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2084)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2085) if (dev != ign->fb_tunnel_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2086) unregister_netdevice_queue(dev, head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2087) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2088)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2089) static size_t ip6gre_get_size(const struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2090) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2091) return
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2092) /* IFLA_GRE_LINK */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2093) nla_total_size(4) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2094) /* IFLA_GRE_IFLAGS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2095) nla_total_size(2) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2096) /* IFLA_GRE_OFLAGS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2097) nla_total_size(2) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2098) /* IFLA_GRE_IKEY */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2099) nla_total_size(4) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2100) /* IFLA_GRE_OKEY */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2101) nla_total_size(4) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2102) /* IFLA_GRE_LOCAL */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2103) nla_total_size(sizeof(struct in6_addr)) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2104) /* IFLA_GRE_REMOTE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2105) nla_total_size(sizeof(struct in6_addr)) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2106) /* IFLA_GRE_TTL */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2107) nla_total_size(1) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2108) /* IFLA_GRE_ENCAP_LIMIT */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2109) nla_total_size(1) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2110) /* IFLA_GRE_FLOWINFO */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2111) nla_total_size(4) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2112) /* IFLA_GRE_FLAGS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2113) nla_total_size(4) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2114) /* IFLA_GRE_ENCAP_TYPE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2115) nla_total_size(2) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2116) /* IFLA_GRE_ENCAP_FLAGS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2117) nla_total_size(2) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2118) /* IFLA_GRE_ENCAP_SPORT */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2119) nla_total_size(2) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2120) /* IFLA_GRE_ENCAP_DPORT */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2121) nla_total_size(2) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2122) /* IFLA_GRE_COLLECT_METADATA */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2123) nla_total_size(0) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2124) /* IFLA_GRE_FWMARK */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2125) nla_total_size(4) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2126) /* IFLA_GRE_ERSPAN_INDEX */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2127) nla_total_size(4) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2128) 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2129) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2131) static int ip6gre_fill_info(struct sk_buff *skb, const struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2132) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2133) struct ip6_tnl *t = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2134) struct __ip6_tnl_parm *p = &t->parms;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2135) __be16 o_flags = p->o_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2137) if (p->erspan_ver == 1 || p->erspan_ver == 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2138) if (!p->collect_md)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2139) o_flags |= TUNNEL_KEY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2141) if (nla_put_u8(skb, IFLA_GRE_ERSPAN_VER, p->erspan_ver))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2142) goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2144) if (p->erspan_ver == 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2145) if (nla_put_u32(skb, IFLA_GRE_ERSPAN_INDEX, p->index))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2146) goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2147) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2148) if (nla_put_u8(skb, IFLA_GRE_ERSPAN_DIR, p->dir))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2149) goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2150) if (nla_put_u16(skb, IFLA_GRE_ERSPAN_HWID, p->hwid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2151) goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2152) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2153) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2154)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2155) if (nla_put_u32(skb, IFLA_GRE_LINK, p->link) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2156) nla_put_be16(skb, IFLA_GRE_IFLAGS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2157) gre_tnl_flags_to_gre_flags(p->i_flags)) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2158) nla_put_be16(skb, IFLA_GRE_OFLAGS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2159) gre_tnl_flags_to_gre_flags(o_flags)) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2160) nla_put_be32(skb, IFLA_GRE_IKEY, p->i_key) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2161) nla_put_be32(skb, IFLA_GRE_OKEY, p->o_key) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2162) nla_put_in6_addr(skb, IFLA_GRE_LOCAL, &p->laddr) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2163) nla_put_in6_addr(skb, IFLA_GRE_REMOTE, &p->raddr) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2164) nla_put_u8(skb, IFLA_GRE_TTL, p->hop_limit) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2165) nla_put_u8(skb, IFLA_GRE_ENCAP_LIMIT, p->encap_limit) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2166) nla_put_be32(skb, IFLA_GRE_FLOWINFO, p->flowinfo) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2167) nla_put_u32(skb, IFLA_GRE_FLAGS, p->flags) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2168) nla_put_u32(skb, IFLA_GRE_FWMARK, p->fwmark))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2169) goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2170)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2171) if (nla_put_u16(skb, IFLA_GRE_ENCAP_TYPE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2172) t->encap.type) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2173) nla_put_be16(skb, IFLA_GRE_ENCAP_SPORT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2174) t->encap.sport) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2175) nla_put_be16(skb, IFLA_GRE_ENCAP_DPORT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2176) t->encap.dport) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2177) nla_put_u16(skb, IFLA_GRE_ENCAP_FLAGS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2178) t->encap.flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2179) goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2181) if (p->collect_md) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2182) if (nla_put_flag(skb, IFLA_GRE_COLLECT_METADATA))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2183) goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2184) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2185)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2186) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2187)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2188) nla_put_failure:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2189) return -EMSGSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2190) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2191)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2192) static const struct nla_policy ip6gre_policy[IFLA_GRE_MAX + 1] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2193) [IFLA_GRE_LINK] = { .type = NLA_U32 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2194) [IFLA_GRE_IFLAGS] = { .type = NLA_U16 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2195) [IFLA_GRE_OFLAGS] = { .type = NLA_U16 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2196) [IFLA_GRE_IKEY] = { .type = NLA_U32 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2197) [IFLA_GRE_OKEY] = { .type = NLA_U32 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2198) [IFLA_GRE_LOCAL] = { .len = sizeof_field(struct ipv6hdr, saddr) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2199) [IFLA_GRE_REMOTE] = { .len = sizeof_field(struct ipv6hdr, daddr) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2200) [IFLA_GRE_TTL] = { .type = NLA_U8 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2201) [IFLA_GRE_ENCAP_LIMIT] = { .type = NLA_U8 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2202) [IFLA_GRE_FLOWINFO] = { .type = NLA_U32 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2203) [IFLA_GRE_FLAGS] = { .type = NLA_U32 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2204) [IFLA_GRE_ENCAP_TYPE] = { .type = NLA_U16 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2205) [IFLA_GRE_ENCAP_FLAGS] = { .type = NLA_U16 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2206) [IFLA_GRE_ENCAP_SPORT] = { .type = NLA_U16 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2207) [IFLA_GRE_ENCAP_DPORT] = { .type = NLA_U16 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2208) [IFLA_GRE_COLLECT_METADATA] = { .type = NLA_FLAG },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2209) [IFLA_GRE_FWMARK] = { .type = NLA_U32 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2210) [IFLA_GRE_ERSPAN_INDEX] = { .type = NLA_U32 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2211) [IFLA_GRE_ERSPAN_VER] = { .type = NLA_U8 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2212) [IFLA_GRE_ERSPAN_DIR] = { .type = NLA_U8 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2213) [IFLA_GRE_ERSPAN_HWID] = { .type = NLA_U16 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2214) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2215)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2216) static void ip6erspan_tap_setup(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2217) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2218) ether_setup(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2219)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2220) dev->max_mtu = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2221) dev->netdev_ops = &ip6erspan_netdev_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2222) dev->needs_free_netdev = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2223) dev->priv_destructor = ip6gre_dev_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2224)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2225) dev->priv_flags &= ~IFF_TX_SKB_SHARING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2226) dev->priv_flags |= IFF_LIVE_ADDR_CHANGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2227) netif_keep_dst(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2228) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2229)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2230) static int ip6erspan_newlink(struct net *src_net, struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2231) struct nlattr *tb[], struct nlattr *data[],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2232) struct netlink_ext_ack *extack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2233) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2234) struct ip6_tnl *nt = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2235) struct net *net = dev_net(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2236) struct ip6gre_net *ign;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2237) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2238)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2239) ip6gre_netlink_parms(data, &nt->parms);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2240) ip6erspan_set_version(data, &nt->parms);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2241) ign = net_generic(net, ip6gre_net_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2242)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2243) if (nt->parms.collect_md) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2244) if (rtnl_dereference(ign->collect_md_tun_erspan))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2245) return -EEXIST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2246) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2247) if (ip6gre_tunnel_find(net, &nt->parms, dev->type))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2248) return -EEXIST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2249) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2250)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2251) err = ip6gre_newlink_common(src_net, dev, tb, data, extack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2252) if (!err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2253) ip6erspan_tnl_link_config(nt, !tb[IFLA_MTU]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2254) ip6erspan_tunnel_link_md(ign, nt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2255) ip6gre_tunnel_link(net_generic(net, ip6gre_net_id), nt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2256) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2257) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2258) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2259)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2260) static void ip6erspan_tnl_link_config(struct ip6_tnl *t, int set_mtu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2261) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2262) ip6gre_tnl_link_config_common(t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2263) ip6gre_tnl_link_config_route(t, set_mtu, ip6erspan_calc_hlen(t));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2264) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2265)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2266) static int ip6erspan_tnl_change(struct ip6_tnl *t,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2267) const struct __ip6_tnl_parm *p, int set_mtu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2268) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2269) ip6gre_tnl_copy_tnl_parm(t, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2270) ip6erspan_tnl_link_config(t, set_mtu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2271) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2272) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2273)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2274) static int ip6erspan_changelink(struct net_device *dev, struct nlattr *tb[],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2275) struct nlattr *data[],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2276) struct netlink_ext_ack *extack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2277) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2278) struct ip6gre_net *ign = net_generic(dev_net(dev), ip6gre_net_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2279) struct __ip6_tnl_parm p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2280) struct ip6_tnl *t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2281)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2282) t = ip6gre_changelink_common(dev, tb, data, &p, extack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2283) if (IS_ERR(t))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2284) return PTR_ERR(t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2285)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2286) ip6erspan_set_version(data, &p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2287) ip6gre_tunnel_unlink_md(ign, t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2288) ip6gre_tunnel_unlink(ign, t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2289) ip6erspan_tnl_change(t, &p, !tb[IFLA_MTU]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2290) ip6erspan_tunnel_link_md(ign, t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2291) ip6gre_tunnel_link(ign, t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2292) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2293) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2294)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2295) static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2296) .kind = "ip6gre",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2297) .maxtype = IFLA_GRE_MAX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2298) .policy = ip6gre_policy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2299) .priv_size = sizeof(struct ip6_tnl),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2300) .setup = ip6gre_tunnel_setup,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2301) .validate = ip6gre_tunnel_validate,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2302) .newlink = ip6gre_newlink,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2303) .changelink = ip6gre_changelink,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2304) .dellink = ip6gre_dellink,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2305) .get_size = ip6gre_get_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2306) .fill_info = ip6gre_fill_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2307) .get_link_net = ip6_tnl_get_link_net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2308) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2309)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2310) static struct rtnl_link_ops ip6gre_tap_ops __read_mostly = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2311) .kind = "ip6gretap",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2312) .maxtype = IFLA_GRE_MAX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2313) .policy = ip6gre_policy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2314) .priv_size = sizeof(struct ip6_tnl),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2315) .setup = ip6gre_tap_setup,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2316) .validate = ip6gre_tap_validate,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2317) .newlink = ip6gre_newlink,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2318) .changelink = ip6gre_changelink,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2319) .get_size = ip6gre_get_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2320) .fill_info = ip6gre_fill_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2321) .get_link_net = ip6_tnl_get_link_net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2322) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2323)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2324) static struct rtnl_link_ops ip6erspan_tap_ops __read_mostly = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2325) .kind = "ip6erspan",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2326) .maxtype = IFLA_GRE_MAX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2327) .policy = ip6gre_policy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2328) .priv_size = sizeof(struct ip6_tnl),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2329) .setup = ip6erspan_tap_setup,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2330) .validate = ip6erspan_tap_validate,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2331) .newlink = ip6erspan_newlink,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2332) .changelink = ip6erspan_changelink,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2333) .get_size = ip6gre_get_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2334) .fill_info = ip6gre_fill_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2335) .get_link_net = ip6_tnl_get_link_net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2336) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2337)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2338) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2339) * And now the modules code and kernel interface.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2340) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2341)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2342) static int __init ip6gre_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2343) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2344) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2345)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2346) pr_info("GRE over IPv6 tunneling driver\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2347)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2348) err = register_pernet_device(&ip6gre_net_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2349) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2350) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2351)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2352) err = inet6_add_protocol(&ip6gre_protocol, IPPROTO_GRE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2353) if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2354) pr_info("%s: can't add protocol\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2355) goto add_proto_failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2356) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2357)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2358) err = rtnl_link_register(&ip6gre_link_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2359) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2360) goto rtnl_link_failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2361)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2362) err = rtnl_link_register(&ip6gre_tap_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2363) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2364) goto tap_ops_failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2365)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2366) err = rtnl_link_register(&ip6erspan_tap_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2367) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2368) goto erspan_link_failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2369)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2370) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2371) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2372)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2373) erspan_link_failed:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2374) rtnl_link_unregister(&ip6gre_tap_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2375) tap_ops_failed:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2376) rtnl_link_unregister(&ip6gre_link_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2377) rtnl_link_failed:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2378) inet6_del_protocol(&ip6gre_protocol, IPPROTO_GRE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2379) add_proto_failed:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2380) unregister_pernet_device(&ip6gre_net_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2381) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2382) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2383)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2384) static void __exit ip6gre_fini(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2385) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2386) rtnl_link_unregister(&ip6gre_tap_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2387) rtnl_link_unregister(&ip6gre_link_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2388) rtnl_link_unregister(&ip6erspan_tap_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2389) inet6_del_protocol(&ip6gre_protocol, IPPROTO_GRE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2390) unregister_pernet_device(&ip6gre_net_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2391) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2392)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2393) module_init(ip6gre_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2394) module_exit(ip6gre_fini);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2395) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2396) MODULE_AUTHOR("D. Kozlov (xeb@mail.ru)");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2397) MODULE_DESCRIPTION("GRE over IPv6 tunneling device");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2398) MODULE_ALIAS_RTNL_LINK("ip6gre");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2399) MODULE_ALIAS_RTNL_LINK("ip6gretap");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2400) MODULE_ALIAS_RTNL_LINK("ip6erspan");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2401) MODULE_ALIAS_NETDEV("ip6gre0");