^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) #ifndef __NET_IP_TUNNELS_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) #define __NET_IP_TUNNELS_H 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) #include <linux/if_tunnel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) #include <linux/netdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #include <linux/skbuff.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/socket.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/u64_stats_sync.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/bitops.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <net/dsfield.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <net/gro_cells.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <net/inet_ecn.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <net/netns/generic.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <net/rtnetlink.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <net/lwtunnel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <net/dst_cache.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #if IS_ENABLED(CONFIG_IPV6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <net/ipv6.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <net/ip6_fib.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <net/ip6_route.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) /* Keep error state on tunnel for 30 sec */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #define IPTUNNEL_ERR_TIMEO (30*HZ)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) /* Used to memset ip_tunnel padding. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #define IP_TUNNEL_KEY_SIZE offsetofend(struct ip_tunnel_key, tp_dst)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) /* Used to memset ipv4 address padding. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #define IP_TUNNEL_KEY_IPV4_PAD offsetofend(struct ip_tunnel_key, u.ipv4.dst)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #define IP_TUNNEL_KEY_IPV4_PAD_LEN \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) (sizeof_field(struct ip_tunnel_key, u) - \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) sizeof_field(struct ip_tunnel_key, u.ipv4))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) struct ip_tunnel_key {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) __be64 tun_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) union {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) __be32 src;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) __be32 dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) } ipv4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) struct in6_addr src;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) struct in6_addr dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) } ipv6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) } u;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) __be16 tun_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) u8 tos; /* TOS for IPv4, TC for IPv6 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) u8 ttl; /* TTL for IPv4, HL for IPv6 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) __be32 label; /* Flow Label for IPv6 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) __be16 tp_src;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) __be16 tp_dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) /* Flags for ip_tunnel_info mode. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) #define IP_TUNNEL_INFO_TX 0x01 /* represents tx tunnel parameters */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) #define IP_TUNNEL_INFO_IPV6 0x02 /* key contains IPv6 addresses */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) #define IP_TUNNEL_INFO_BRIDGE 0x04 /* represents a bridged tunnel id */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) /* Maximum tunnel options length. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) #define IP_TUNNEL_OPTS_MAX \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) GENMASK((sizeof_field(struct ip_tunnel_info, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) options_len) * BITS_PER_BYTE) - 1, 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) struct ip_tunnel_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) struct ip_tunnel_key key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) #ifdef CONFIG_DST_CACHE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) struct dst_cache dst_cache;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) u8 options_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) u8 mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) /* 6rd prefix/relay information */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) #ifdef CONFIG_IPV6_SIT_6RD
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) struct ip_tunnel_6rd_parm {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) struct in6_addr prefix;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) __be32 relay_prefix;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) u16 prefixlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) u16 relay_prefixlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) struct ip_tunnel_encap {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) u16 type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) u16 flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) __be16 sport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) __be16 dport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) struct ip_tunnel_prl_entry {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) struct ip_tunnel_prl_entry __rcu *next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) __be32 addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) u16 flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) struct rcu_head rcu_head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) struct metadata_dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) struct ip_tunnel {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) struct ip_tunnel __rcu *next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) struct hlist_node hash_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) struct net_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) struct net *net; /* netns for packet i/o */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) unsigned long err_time; /* Time when the last ICMP error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) * arrived */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) int err_count; /* Number of arrived ICMP errors */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) /* These four fields used only by GRE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) u32 i_seqno; /* The last seen seqno */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) u32 o_seqno; /* The last output seqno */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) int tun_hlen; /* Precalculated header length */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) /* These four fields used only by ERSPAN */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) u32 index; /* ERSPAN type II index */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) u8 erspan_ver; /* ERSPAN version */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) u8 dir; /* ERSPAN direction */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) u16 hwid; /* ERSPAN hardware ID */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) struct dst_cache dst_cache;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) struct ip_tunnel_parm parms;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) int mlink;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) int encap_hlen; /* Encap header length (FOU,GUE) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) int hlen; /* tun_hlen + encap_hlen */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) struct ip_tunnel_encap encap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) /* for SIT */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) #ifdef CONFIG_IPV6_SIT_6RD
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) struct ip_tunnel_6rd_parm ip6rd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) struct ip_tunnel_prl_entry __rcu *prl; /* potential router list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) unsigned int prl_count; /* # of entries in PRL */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) unsigned int ip_tnl_net_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) struct gro_cells gro_cells;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) __u32 fwmark;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) bool collect_md;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) bool ignore_df;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) struct tnl_ptk_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) __be16 flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) __be16 proto;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) __be32 key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) __be32 seq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) int hdr_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) #define PACKET_RCVD 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) #define PACKET_REJECT 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) #define PACKET_NEXT 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) #define IP_TNL_HASH_BITS 7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) #define IP_TNL_HASH_SIZE (1 << IP_TNL_HASH_BITS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) struct ip_tunnel_net {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) struct net_device *fb_tunnel_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) struct rtnl_link_ops *rtnl_link_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) struct hlist_head tunnels[IP_TNL_HASH_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) struct ip_tunnel __rcu *collect_md_tun;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) int type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) static inline void ip_tunnel_key_init(struct ip_tunnel_key *key,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) __be32 saddr, __be32 daddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) u8 tos, u8 ttl, __be32 label,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) __be16 tp_src, __be16 tp_dst,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) __be64 tun_id, __be16 tun_flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) key->tun_id = tun_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) key->u.ipv4.src = saddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) key->u.ipv4.dst = daddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) memset((unsigned char *)key + IP_TUNNEL_KEY_IPV4_PAD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 0, IP_TUNNEL_KEY_IPV4_PAD_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) key->tos = tos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) key->ttl = ttl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) key->label = label;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) key->tun_flags = tun_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) /* For the tunnel types on the top of IPsec, the tp_src and tp_dst of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) * the upper tunnel are used.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) * E.g: GRE over IPSEC, the tp_src and tp_port are zero.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) key->tp_src = tp_src;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) key->tp_dst = tp_dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) /* Clear struct padding. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) if (sizeof(*key) != IP_TUNNEL_KEY_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) memset((unsigned char *)key + IP_TUNNEL_KEY_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 0, sizeof(*key) - IP_TUNNEL_KEY_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) static inline bool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) ip_tunnel_dst_cache_usable(const struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) const struct ip_tunnel_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) if (skb->mark)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) if (!info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) if (info->key.tun_flags & TUNNEL_NOCACHE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) static inline unsigned short ip_tunnel_info_af(const struct ip_tunnel_info
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) *tun_info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) return tun_info->mode & IP_TUNNEL_INFO_IPV6 ? AF_INET6 : AF_INET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) static inline __be64 key32_to_tunnel_id(__be32 key)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) #ifdef __BIG_ENDIAN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) return (__force __be64)key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) return (__force __be64)((__force u64)key << 32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) /* Returns the least-significant 32 bits of a __be64. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) static inline __be32 tunnel_id_to_key32(__be64 tun_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) #ifdef __BIG_ENDIAN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) return (__force __be32)tun_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) return (__force __be32)((__force u64)tun_id >> 32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) #ifdef CONFIG_INET
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) static inline void ip_tunnel_init_flow(struct flowi4 *fl4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) int proto,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) __be32 daddr, __be32 saddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) __be32 key, __u8 tos, int oif,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) __u32 mark, __u32 tun_inner_hash)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) memset(fl4, 0, sizeof(*fl4));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) fl4->flowi4_oif = oif;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) fl4->daddr = daddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) fl4->saddr = saddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) fl4->flowi4_tos = tos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) fl4->flowi4_proto = proto;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) fl4->fl4_gre_key = key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) fl4->flowi4_mark = mark;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) fl4->flowi4_multipath_hash = tun_inner_hash;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) int ip_tunnel_init(struct net_device *dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) void ip_tunnel_uninit(struct net_device *dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) void ip_tunnel_dellink(struct net_device *dev, struct list_head *head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) struct net *ip_tunnel_get_link_net(const struct net_device *dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) int ip_tunnel_get_iflink(const struct net_device *dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) int ip_tunnel_init_net(struct net *net, unsigned int ip_tnl_net_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) struct rtnl_link_ops *ops, char *devname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) void ip_tunnel_delete_nets(struct list_head *list_net, unsigned int id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) struct rtnl_link_ops *ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) void ip_tunnel_xmit(struct sk_buff *skb, struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) const struct iphdr *tnl_params, const u8 protocol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) void ip_md_tunnel_xmit(struct sk_buff *skb, struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) const u8 proto, int tunnel_hlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) int ip_tunnel_ctl(struct net_device *dev, struct ip_tunnel_parm *p, int cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) int ip_tunnel_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) int __ip_tunnel_change_mtu(struct net_device *dev, int new_mtu, bool strict);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) int ip_tunnel_change_mtu(struct net_device *dev, int new_mtu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) void ip_tunnel_get_stats64(struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) struct rtnl_link_stats64 *tot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) struct ip_tunnel *ip_tunnel_lookup(struct ip_tunnel_net *itn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) int link, __be16 flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) __be32 remote, __be32 local,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) __be32 key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) int ip_tunnel_rcv(struct ip_tunnel *tunnel, struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) const struct tnl_ptk_info *tpi, struct metadata_dst *tun_dst,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) bool log_ecn_error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) int ip_tunnel_changelink(struct net_device *dev, struct nlattr *tb[],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) struct ip_tunnel_parm *p, __u32 fwmark);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) int ip_tunnel_newlink(struct net_device *dev, struct nlattr *tb[],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) struct ip_tunnel_parm *p, __u32 fwmark);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) void ip_tunnel_setup(struct net_device *dev, unsigned int net_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) extern const struct header_ops ip_tunnel_header_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) __be16 ip_tunnel_parse_protocol(const struct sk_buff *skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) struct ip_tunnel_encap_ops {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) size_t (*encap_hlen)(struct ip_tunnel_encap *e);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) int (*build_header)(struct sk_buff *skb, struct ip_tunnel_encap *e,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) u8 *protocol, struct flowi4 *fl4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) int (*err_handler)(struct sk_buff *skb, u32 info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) #define MAX_IPTUN_ENCAP_OPS 8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) extern const struct ip_tunnel_encap_ops __rcu *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) iptun_encaps[MAX_IPTUN_ENCAP_OPS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) int ip_tunnel_encap_add_ops(const struct ip_tunnel_encap_ops *op,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) unsigned int num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) int ip_tunnel_encap_del_ops(const struct ip_tunnel_encap_ops *op,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) unsigned int num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) int ip_tunnel_encap_setup(struct ip_tunnel *t,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) struct ip_tunnel_encap *ipencap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) static inline bool pskb_inet_may_pull(struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) int nhlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) switch (skb->protocol) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) #if IS_ENABLED(CONFIG_IPV6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) case htons(ETH_P_IPV6):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) nhlen = sizeof(struct ipv6hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) case htons(ETH_P_IP):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) nhlen = sizeof(struct iphdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) nhlen = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) return pskb_network_may_pull(skb, nhlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) static inline int ip_encap_hlen(struct ip_tunnel_encap *e)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) const struct ip_tunnel_encap_ops *ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) int hlen = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) if (e->type == TUNNEL_ENCAP_NONE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) if (e->type >= MAX_IPTUN_ENCAP_OPS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) ops = rcu_dereference(iptun_encaps[e->type]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) if (likely(ops && ops->encap_hlen))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) hlen = ops->encap_hlen(e);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) return hlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) static inline int ip_tunnel_encap(struct sk_buff *skb, struct ip_tunnel *t,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) u8 *protocol, struct flowi4 *fl4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) const struct ip_tunnel_encap_ops *ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) int ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) if (t->encap.type == TUNNEL_ENCAP_NONE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) if (t->encap.type >= MAX_IPTUN_ENCAP_OPS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) ops = rcu_dereference(iptun_encaps[t->encap.type]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) if (likely(ops && ops->build_header))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) ret = ops->build_header(skb, &t->encap, protocol, fl4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) /* Extract dsfield from inner protocol */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) static inline u8 ip_tunnel_get_dsfield(const struct iphdr *iph,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) const struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) if (skb->protocol == htons(ETH_P_IP))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) return iph->tos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) else if (skb->protocol == htons(ETH_P_IPV6))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) return ipv6_get_dsfield((const struct ipv6hdr *)iph);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) static inline u8 ip_tunnel_get_ttl(const struct iphdr *iph,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) const struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) if (skb->protocol == htons(ETH_P_IP))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) return iph->ttl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) else if (skb->protocol == htons(ETH_P_IPV6))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) return ((const struct ipv6hdr *)iph)->hop_limit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) /* Propogate ECN bits out */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) static inline u8 ip_tunnel_ecn_encap(u8 tos, const struct iphdr *iph,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) const struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) u8 inner = ip_tunnel_get_dsfield(iph, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) return INET_ECN_encapsulate(tos, inner);
^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) int __iptunnel_pull_header(struct sk_buff *skb, int hdr_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) __be16 inner_proto, bool raw_proto, bool xnet);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) static inline int iptunnel_pull_header(struct sk_buff *skb, int hdr_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) __be16 inner_proto, bool xnet)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) return __iptunnel_pull_header(skb, hdr_len, inner_proto, false, xnet);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) void iptunnel_xmit(struct sock *sk, struct rtable *rt, struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) __be32 src, __be32 dst, u8 proto,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) u8 tos, u8 ttl, __be16 df, bool xnet);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) struct metadata_dst *iptunnel_metadata_reply(struct metadata_dst *md,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) gfp_t flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) int skb_tunnel_check_pmtu(struct sk_buff *skb, struct dst_entry *encap_dst,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) int headroom, bool reply);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) int iptunnel_handle_offloads(struct sk_buff *skb, int gso_type_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) static inline int iptunnel_pull_offloads(struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) if (skb_is_gso(skb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) err = skb_unclone(skb, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) if (unlikely(err))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) skb_shinfo(skb)->gso_type &= ~(NETIF_F_GSO_ENCAP_ALL >>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) NETIF_F_GSO_SHIFT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) skb->encapsulation = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) static inline void iptunnel_xmit_stats(struct net_device *dev, int pkt_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) if (pkt_len > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) struct pcpu_sw_netstats *tstats = get_cpu_ptr(dev->tstats);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) u64_stats_update_begin(&tstats->syncp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) tstats->tx_bytes += pkt_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) tstats->tx_packets++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) u64_stats_update_end(&tstats->syncp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) put_cpu_ptr(tstats);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) struct net_device_stats *err_stats = &dev->stats;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) if (pkt_len < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) err_stats->tx_errors++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) err_stats->tx_aborted_errors++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) err_stats->tx_dropped++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) static inline void *ip_tunnel_info_opts(struct ip_tunnel_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) return info + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) static inline void ip_tunnel_info_opts_get(void *to,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) const struct ip_tunnel_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) memcpy(to, info + 1, info->options_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) static inline void ip_tunnel_info_opts_set(struct ip_tunnel_info *info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) const void *from, int len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) __be16 flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) info->options_len = len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) if (len > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) memcpy(ip_tunnel_info_opts(info), from, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) info->key.tun_flags |= flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) static inline struct ip_tunnel_info *lwt_tun_info(struct lwtunnel_state *lwtstate)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) return (struct ip_tunnel_info *)lwtstate->data;
^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) DECLARE_STATIC_KEY_FALSE(ip_tunnel_metadata_cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) /* Returns > 0 if metadata should be collected */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) static inline int ip_tunnel_collect_metadata(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) return static_branch_unlikely(&ip_tunnel_metadata_cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) void __init ip_tunnel_core_init(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) void ip_tunnel_need_metadata(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) void ip_tunnel_unneed_metadata(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) #else /* CONFIG_INET */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) static inline struct ip_tunnel_info *lwt_tun_info(struct lwtunnel_state *lwtstate)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) static inline void ip_tunnel_need_metadata(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) static inline void ip_tunnel_unneed_metadata(void)
^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)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) static inline void ip_tunnel_info_opts_get(void *to,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) const struct ip_tunnel_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) {
^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 inline void ip_tunnel_info_opts_set(struct ip_tunnel_info *info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) const void *from, int len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) __be16 flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) info->options_len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) #endif /* CONFIG_INET */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) #endif /* __NET_IP_TUNNELS_H */