1012a5729SPravin B Shelar #ifndef __NET_VXLAN_H 2012a5729SPravin B Shelar #define __NET_VXLAN_H 1 3012a5729SPravin B Shelar 45f35227eSJesse Gross #include <linux/if_vlan.h> 586a98057SAlexander Duyck #include <net/udp_tunnel.h> 6ee122c79SThomas Graf #include <net/dst_metadata.h> 77c46a640SAlexander Duyck #include <net/udp_tunnel.h> 8012a5729SPravin B Shelar 9828788acSJiri Benc /* VXLAN protocol (RFC 7348) header: 103511494cSThomas Graf * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 11828788acSJiri Benc * |R|R|R|R|I|R|R|R| Reserved | 123511494cSThomas Graf * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 133511494cSThomas Graf * | VXLAN Network Identifier (VNI) | Reserved | 143511494cSThomas Graf * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 153511494cSThomas Graf * 16828788acSJiri Benc * I = VXLAN Network Identifier (VNI) present. 17828788acSJiri Benc */ 18828788acSJiri Benc struct vxlanhdr { 19828788acSJiri Benc __be32 vx_flags; 20828788acSJiri Benc __be32 vx_vni; 21828788acSJiri Benc }; 22828788acSJiri Benc 23828788acSJiri Benc /* VXLAN header flags. */ 2454bfd872SJiri Benc #define VXLAN_HF_VNI cpu_to_be32(BIT(27)) 25828788acSJiri Benc 26828788acSJiri Benc #define VXLAN_N_VID (1u << 24) 27828788acSJiri Benc #define VXLAN_VID_MASK (VXLAN_N_VID - 1) 2854bfd872SJiri Benc #define VXLAN_VNI_MASK cpu_to_be32(VXLAN_VID_MASK << 8) 29828788acSJiri Benc #define VXLAN_HLEN (sizeof(struct udphdr) + sizeof(struct vxlanhdr)) 30828788acSJiri Benc 31828788acSJiri Benc #define VNI_HASH_BITS 10 32828788acSJiri Benc #define VNI_HASH_SIZE (1<<VNI_HASH_BITS) 33828788acSJiri Benc #define FDB_HASH_BITS 8 34828788acSJiri Benc #define FDB_HASH_SIZE (1<<FDB_HASH_BITS) 35828788acSJiri Benc 36828788acSJiri Benc /* Remote checksum offload for VXLAN (VXLAN_F_REMCSUM_[RT]X): 37828788acSJiri Benc * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 38828788acSJiri Benc * |R|R|R|R|I|R|R|R|R|R|C| Reserved | 39828788acSJiri Benc * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 40828788acSJiri Benc * | VXLAN Network Identifier (VNI) |O| Csum start | 41828788acSJiri Benc * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 42828788acSJiri Benc * 43828788acSJiri Benc * C = Remote checksum offload bit. When set indicates that the 44828788acSJiri Benc * remote checksum offload data is present. 45828788acSJiri Benc * 46828788acSJiri Benc * O = Offset bit. Indicates the checksum offset relative to 47828788acSJiri Benc * checksum start. 48828788acSJiri Benc * 49828788acSJiri Benc * Csum start = Checksum start divided by two. 50828788acSJiri Benc * 51828788acSJiri Benc * http://tools.ietf.org/html/draft-herbert-vxlan-rco 52828788acSJiri Benc */ 53828788acSJiri Benc 54828788acSJiri Benc /* VXLAN-RCO header flags. */ 5554bfd872SJiri Benc #define VXLAN_HF_RCO cpu_to_be32(BIT(21)) 56828788acSJiri Benc 57828788acSJiri Benc /* Remote checksum offload header option */ 5854bfd872SJiri Benc #define VXLAN_RCO_MASK cpu_to_be32(0x7f) /* Last byte of vni field */ 5954bfd872SJiri Benc #define VXLAN_RCO_UDP cpu_to_be32(0x80) /* Indicate UDP RCO (TCP when not set *) */ 60828788acSJiri Benc #define VXLAN_RCO_SHIFT 1 /* Left shift of start */ 61828788acSJiri Benc #define VXLAN_RCO_SHIFT_MASK ((1 << VXLAN_RCO_SHIFT) - 1) 6254bfd872SJiri Benc #define VXLAN_MAX_REMCSUM_START (0x7f << VXLAN_RCO_SHIFT) 63828788acSJiri Benc 64828788acSJiri Benc /* 65828788acSJiri Benc * VXLAN Group Based Policy Extension (VXLAN_F_GBP): 66828788acSJiri Benc * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 67828788acSJiri Benc * |G|R|R|R|I|R|R|R|R|D|R|R|A|R|R|R| Group Policy ID | 68828788acSJiri Benc * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 69828788acSJiri Benc * | VXLAN Network Identifier (VNI) | Reserved | 70828788acSJiri Benc * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 71828788acSJiri Benc * 72828788acSJiri Benc * G = Group Policy ID present. 73828788acSJiri Benc * 743511494cSThomas Graf * D = Don't Learn bit. When set, this bit indicates that the egress 753511494cSThomas Graf * VTEP MUST NOT learn the source address of the encapsulated frame. 763511494cSThomas Graf * 773511494cSThomas Graf * A = Indicates that the group policy has already been applied to 783511494cSThomas Graf * this packet. Policies MUST NOT be applied by devices when the 793511494cSThomas Graf * A bit is set. 803511494cSThomas Graf * 81828788acSJiri Benc * https://tools.ietf.org/html/draft-smith-vxlan-group-policy 823511494cSThomas Graf */ 833511494cSThomas Graf struct vxlanhdr_gbp { 840e715d6fSJiri Benc u8 vx_flags; 853511494cSThomas Graf #ifdef __LITTLE_ENDIAN_BITFIELD 860e715d6fSJiri Benc u8 reserved_flags1:3, 873511494cSThomas Graf policy_applied:1, 883511494cSThomas Graf reserved_flags2:2, 893511494cSThomas Graf dont_learn:1, 903511494cSThomas Graf reserved_flags3:1; 913511494cSThomas Graf #elif defined(__BIG_ENDIAN_BITFIELD) 920e715d6fSJiri Benc u8 reserved_flags1:1, 933511494cSThomas Graf dont_learn:1, 943511494cSThomas Graf reserved_flags2:2, 953511494cSThomas Graf policy_applied:1, 963511494cSThomas Graf reserved_flags3:3; 973511494cSThomas Graf #else 983511494cSThomas Graf #error "Please fix <asm/byteorder.h>" 993511494cSThomas Graf #endif 1003511494cSThomas Graf __be16 policy_id; 1013511494cSThomas Graf __be32 vx_vni; 1023511494cSThomas Graf }; 1033511494cSThomas Graf 104828788acSJiri Benc /* VXLAN-GBP header flags. */ 10554bfd872SJiri Benc #define VXLAN_HF_GBP cpu_to_be32(BIT(31)) 106828788acSJiri Benc 10754bfd872SJiri Benc #define VXLAN_GBP_USED_BITS (VXLAN_HF_GBP | cpu_to_be32(0xFFFFFF)) 1083511494cSThomas Graf 1093511494cSThomas Graf /* skb->mark mapping 1103511494cSThomas Graf * 1113511494cSThomas Graf * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1123511494cSThomas Graf * |R|R|R|R|R|R|R|R|R|D|R|R|A|R|R|R| Group Policy ID | 1133511494cSThomas Graf * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1143511494cSThomas Graf */ 1153511494cSThomas Graf #define VXLAN_GBP_DONT_LEARN (BIT(6) << 16) 1163511494cSThomas Graf #define VXLAN_GBP_POLICY_APPLIED (BIT(3) << 16) 1173511494cSThomas Graf #define VXLAN_GBP_ID_MASK (0xFFFF) 1183511494cSThomas Graf 119e1e5314dSJiri Benc /* 120e1e5314dSJiri Benc * VXLAN Generic Protocol Extension (VXLAN_F_GPE): 121e1e5314dSJiri Benc * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 122e1e5314dSJiri Benc * |R|R|Ver|I|P|R|O| Reserved |Next Protocol | 123e1e5314dSJiri Benc * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 124e1e5314dSJiri Benc * | VXLAN Network Identifier (VNI) | Reserved | 125e1e5314dSJiri Benc * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 126e1e5314dSJiri Benc * 127e1e5314dSJiri Benc * Ver = Version. Indicates VXLAN GPE protocol version. 128e1e5314dSJiri Benc * 129e1e5314dSJiri Benc * P = Next Protocol Bit. The P bit is set to indicate that the 130e1e5314dSJiri Benc * Next Protocol field is present. 131e1e5314dSJiri Benc * 132e1e5314dSJiri Benc * O = OAM Flag Bit. The O bit is set to indicate that the packet 133e1e5314dSJiri Benc * is an OAM packet. 134e1e5314dSJiri Benc * 135e1e5314dSJiri Benc * Next Protocol = This 8 bit field indicates the protocol header 136e1e5314dSJiri Benc * immediately following the VXLAN GPE header. 137e1e5314dSJiri Benc * 138e1e5314dSJiri Benc * https://tools.ietf.org/html/draft-ietf-nvo3-vxlan-gpe-01 139e1e5314dSJiri Benc */ 140e1e5314dSJiri Benc 141e1e5314dSJiri Benc struct vxlanhdr_gpe { 142e1e5314dSJiri Benc #if defined(__LITTLE_ENDIAN_BITFIELD) 143e1e5314dSJiri Benc u8 oam_flag:1, 144e1e5314dSJiri Benc reserved_flags1:1, 145e1e5314dSJiri Benc np_applied:1, 146e1e5314dSJiri Benc instance_applied:1, 147e1e5314dSJiri Benc version:2, 148e1e5314dSJiri Benc reserved_flags2:2; 149e1e5314dSJiri Benc #elif defined(__BIG_ENDIAN_BITFIELD) 150e1e5314dSJiri Benc u8 reserved_flags2:2, 151e1e5314dSJiri Benc version:2, 152e1e5314dSJiri Benc instance_applied:1, 153e1e5314dSJiri Benc np_applied:1, 154e1e5314dSJiri Benc reserved_flags1:1, 155e1e5314dSJiri Benc oam_flag:1; 156e1e5314dSJiri Benc #endif 157e1e5314dSJiri Benc u8 reserved_flags3; 158e1e5314dSJiri Benc u8 reserved_flags4; 159e1e5314dSJiri Benc u8 next_protocol; 160e1e5314dSJiri Benc __be32 vx_vni; 161e1e5314dSJiri Benc }; 162e1e5314dSJiri Benc 163e1e5314dSJiri Benc /* VXLAN-GPE header flags. */ 164e1e5314dSJiri Benc #define VXLAN_HF_VER cpu_to_be32(BIT(29) | BIT(28)) 165e1e5314dSJiri Benc #define VXLAN_HF_NP cpu_to_be32(BIT(26)) 166e1e5314dSJiri Benc #define VXLAN_HF_OAM cpu_to_be32(BIT(24)) 167e1e5314dSJiri Benc 168e1e5314dSJiri Benc #define VXLAN_GPE_USED_BITS (VXLAN_HF_VER | VXLAN_HF_NP | VXLAN_HF_OAM | \ 169e1e5314dSJiri Benc cpu_to_be32(0xff)) 170e1e5314dSJiri Benc 171e1e5314dSJiri Benc /* VXLAN-GPE header Next Protocol. */ 172e1e5314dSJiri Benc #define VXLAN_GPE_NP_IPV4 0x01 173e1e5314dSJiri Benc #define VXLAN_GPE_NP_IPV6 0x02 174e1e5314dSJiri Benc #define VXLAN_GPE_NP_ETHERNET 0x03 175e1e5314dSJiri Benc #define VXLAN_GPE_NP_NSH 0x04 176e1e5314dSJiri Benc 1773511494cSThomas Graf struct vxlan_metadata { 1783511494cSThomas Graf u32 gbp; 1793511494cSThomas Graf }; 1803511494cSThomas Graf 181012a5729SPravin B Shelar /* per UDP socket information */ 182012a5729SPravin B Shelar struct vxlan_sock { 183012a5729SPravin B Shelar struct hlist_node hlist; 184012a5729SPravin B Shelar struct socket *sock; 185012a5729SPravin B Shelar struct hlist_head vni_list[VNI_HASH_SIZE]; 186012a5729SPravin B Shelar atomic_t refcnt; 187dfd8645eSTom Herbert u32 flags; 188012a5729SPravin B Shelar }; 189012a5729SPravin B Shelar 1900dfbdf41SThomas Graf union vxlan_addr { 1910dfbdf41SThomas Graf struct sockaddr_in sin; 1920dfbdf41SThomas Graf struct sockaddr_in6 sin6; 1930dfbdf41SThomas Graf struct sockaddr sa; 1940dfbdf41SThomas Graf }; 1950dfbdf41SThomas Graf 1960dfbdf41SThomas Graf struct vxlan_rdst { 1970dfbdf41SThomas Graf union vxlan_addr remote_ip; 1980dfbdf41SThomas Graf __be16 remote_port; 19954bfd872SJiri Benc __be32 remote_vni; 2000dfbdf41SThomas Graf u32 remote_ifindex; 2010dfbdf41SThomas Graf struct list_head list; 2020dfbdf41SThomas Graf struct rcu_head rcu; 2030c1d70afSPaolo Abeni struct dst_cache dst_cache; 2040dfbdf41SThomas Graf }; 2050dfbdf41SThomas Graf 2060dfbdf41SThomas Graf struct vxlan_config { 2070dfbdf41SThomas Graf union vxlan_addr remote_ip; 2080dfbdf41SThomas Graf union vxlan_addr saddr; 20954bfd872SJiri Benc __be32 vni; 2100dfbdf41SThomas Graf int remote_ifindex; 2110dfbdf41SThomas Graf int mtu; 2120dfbdf41SThomas Graf __be16 dst_port; 2130e715d6fSJiri Benc u16 port_min; 2140e715d6fSJiri Benc u16 port_max; 2150e715d6fSJiri Benc u8 tos; 2160e715d6fSJiri Benc u8 ttl; 217e7f70af1SDaniel Borkmann __be32 label; 2180dfbdf41SThomas Graf u32 flags; 2190dfbdf41SThomas Graf unsigned long age_interval; 2200dfbdf41SThomas Graf unsigned int addrmax; 2210dfbdf41SThomas Graf bool no_share; 2220dfbdf41SThomas Graf }; 2230dfbdf41SThomas Graf 2240dfbdf41SThomas Graf /* Pseudo network device */ 2250dfbdf41SThomas Graf struct vxlan_dev { 2260dfbdf41SThomas Graf struct hlist_node hlist; /* vni hash table */ 2270dfbdf41SThomas Graf struct list_head next; /* vxlan's per namespace list */ 228c6fcc4fcSpravin shelar struct vxlan_sock __rcu *vn4_sock; /* listening socket for IPv4 */ 229b1be00a6SJiri Benc #if IS_ENABLED(CONFIG_IPV6) 230c6fcc4fcSpravin shelar struct vxlan_sock __rcu *vn6_sock; /* listening socket for IPv6 */ 231b1be00a6SJiri Benc #endif 2320dfbdf41SThomas Graf struct net_device *dev; 2330dfbdf41SThomas Graf struct net *net; /* netns for packet i/o */ 2340dfbdf41SThomas Graf struct vxlan_rdst default_dst; /* default destination */ 2350dfbdf41SThomas Graf u32 flags; /* VXLAN_F_* in vxlan.h */ 2360dfbdf41SThomas Graf 2370dfbdf41SThomas Graf struct timer_list age_timer; 2380dfbdf41SThomas Graf spinlock_t hash_lock; 2390dfbdf41SThomas Graf unsigned int addrcnt; 24058ce31ccSTom Herbert struct gro_cells gro_cells; 2410dfbdf41SThomas Graf 2420dfbdf41SThomas Graf struct vxlan_config cfg; 2430dfbdf41SThomas Graf 2440dfbdf41SThomas Graf struct hlist_head fdb_head[FDB_HASH_SIZE]; 2450dfbdf41SThomas Graf }; 2460dfbdf41SThomas Graf 247359a0ea9STom Herbert #define VXLAN_F_LEARN 0x01 248359a0ea9STom Herbert #define VXLAN_F_PROXY 0x02 249359a0ea9STom Herbert #define VXLAN_F_RSC 0x04 250359a0ea9STom Herbert #define VXLAN_F_L2MISS 0x08 251359a0ea9STom Herbert #define VXLAN_F_L3MISS 0x10 252359a0ea9STom Herbert #define VXLAN_F_IPV6 0x20 2536ceb31caSAlexander Duyck #define VXLAN_F_UDP_ZERO_CSUM_TX 0x40 254359a0ea9STom Herbert #define VXLAN_F_UDP_ZERO_CSUM6_TX 0x80 255359a0ea9STom Herbert #define VXLAN_F_UDP_ZERO_CSUM6_RX 0x100 256dfd8645eSTom Herbert #define VXLAN_F_REMCSUM_TX 0x200 257dfd8645eSTom Herbert #define VXLAN_F_REMCSUM_RX 0x400 2583511494cSThomas Graf #define VXLAN_F_GBP 0x800 2590ace2ca8STom Herbert #define VXLAN_F_REMCSUM_NOPARTIAL 0x1000 260ee122c79SThomas Graf #define VXLAN_F_COLLECT_METADATA 0x2000 261e1e5314dSJiri Benc #define VXLAN_F_GPE 0x4000 262359a0ea9STom Herbert 263d299ce14SSimon Horman /* Flags that are used in the receive path. These flags must match in 264af33c1adSTom Herbert * order for a socket to be shareable 265af33c1adSTom Herbert */ 266af33c1adSTom Herbert #define VXLAN_F_RCV_FLAGS (VXLAN_F_GBP | \ 267e1e5314dSJiri Benc VXLAN_F_GPE | \ 268af33c1adSTom Herbert VXLAN_F_UDP_ZERO_CSUM6_RX | \ 2690ace2ca8STom Herbert VXLAN_F_REMCSUM_RX | \ 270ee122c79SThomas Graf VXLAN_F_REMCSUM_NOPARTIAL | \ 271da8b43c0SAlexei Starovoitov VXLAN_F_COLLECT_METADATA) 272ac5132d1SThomas Graf 273e1e5314dSJiri Benc /* Flags that can be set together with VXLAN_F_GPE. */ 274e1e5314dSJiri Benc #define VXLAN_F_ALLOWED_GPE (VXLAN_F_GPE | \ 275e1e5314dSJiri Benc VXLAN_F_IPV6 | \ 276e1e5314dSJiri Benc VXLAN_F_UDP_ZERO_CSUM_TX | \ 277e1e5314dSJiri Benc VXLAN_F_UDP_ZERO_CSUM6_TX | \ 278e1e5314dSJiri Benc VXLAN_F_UDP_ZERO_CSUM6_RX | \ 279e1e5314dSJiri Benc VXLAN_F_COLLECT_METADATA) 280e1e5314dSJiri Benc 2810dfbdf41SThomas Graf struct net_device *vxlan_dev_create(struct net *net, const char *name, 2820dfbdf41SThomas Graf u8 name_assign_type, struct vxlan_config *conf); 2830dfbdf41SThomas Graf 284b1be00a6SJiri Benc static inline __be16 vxlan_dev_dst_port(struct vxlan_dev *vxlan, 285b1be00a6SJiri Benc unsigned short family) 286614732eaSThomas Graf { 287b1be00a6SJiri Benc #if IS_ENABLED(CONFIG_IPV6) 288b1be00a6SJiri Benc if (family == AF_INET6) 289b1be00a6SJiri Benc return inet_sk(vxlan->vn6_sock->sock->sk)->inet_sport; 290b1be00a6SJiri Benc #endif 291b1be00a6SJiri Benc return inet_sk(vxlan->vn4_sock->sock->sk)->inet_sport; 292614732eaSThomas Graf } 29349560532SPravin B Shelar 2945f35227eSJesse Gross static inline netdev_features_t vxlan_features_check(struct sk_buff *skb, 2955f35227eSJesse Gross netdev_features_t features) 29611bf7828SJoe Stringer { 2975f35227eSJesse Gross u8 l4_hdr = 0; 2985f35227eSJesse Gross 2995f35227eSJesse Gross if (!skb->encapsulation) 3005f35227eSJesse Gross return features; 3015f35227eSJesse Gross 3025f35227eSJesse Gross switch (vlan_get_protocol(skb)) { 3035f35227eSJesse Gross case htons(ETH_P_IP): 3045f35227eSJesse Gross l4_hdr = ip_hdr(skb)->protocol; 3055f35227eSJesse Gross break; 3065f35227eSJesse Gross case htons(ETH_P_IPV6): 3075f35227eSJesse Gross l4_hdr = ipv6_hdr(skb)->nexthdr; 3085f35227eSJesse Gross break; 3095f35227eSJesse Gross default: 3105f35227eSJesse Gross return features;; 3115f35227eSJesse Gross } 3125f35227eSJesse Gross 3135f35227eSJesse Gross if ((l4_hdr == IPPROTO_UDP) && 31411bf7828SJoe Stringer (skb->inner_protocol_type != ENCAP_TYPE_ETHER || 31511bf7828SJoe Stringer skb->inner_protocol != htons(ETH_P_TEB) || 31611bf7828SJoe Stringer (skb_inner_mac_header(skb) - skb_transport_header(skb) != 317af67eb9eSAlexander Duyck sizeof(struct udphdr) + sizeof(struct vxlanhdr)) || 318af67eb9eSAlexander Duyck (skb->ip_summed != CHECKSUM_NONE && 319af67eb9eSAlexander Duyck !can_checksum_protocol(features, inner_eth_hdr(skb)->h_proto)))) 320a188222bSTom Herbert return features & ~(NETIF_F_CSUM_MASK | NETIF_F_GSO_MASK); 32111bf7828SJoe Stringer 3225f35227eSJesse Gross return features; 32311bf7828SJoe Stringer } 32423e62de3SJoe Stringer 325e6cd988cSJoseph Gasparakis /* IP header + UDP + VXLAN + Ethernet header */ 326e6cd988cSJoseph Gasparakis #define VXLAN_HEADROOM (20 + 8 + 8 + 14) 327e6cd988cSJoseph Gasparakis /* IPv6 header + UDP + VXLAN + Ethernet header */ 328e6cd988cSJoseph Gasparakis #define VXLAN6_HEADROOM (40 + 8 + 8 + 14) 329e6cd988cSJoseph Gasparakis 330d4ac05ffSJiri Benc static inline struct vxlanhdr *vxlan_hdr(struct sk_buff *skb) 331d4ac05ffSJiri Benc { 332d4ac05ffSJiri Benc return (struct vxlanhdr *)(udp_hdr(skb) + 1); 333d4ac05ffSJiri Benc } 334d4ac05ffSJiri Benc 33554bfd872SJiri Benc static inline __be32 vxlan_vni(__be32 vni_field) 33654bfd872SJiri Benc { 33754bfd872SJiri Benc #if defined(__BIG_ENDIAN) 3385692d7eaSJiri Benc return (__force __be32)((__force u32)vni_field >> 8); 33954bfd872SJiri Benc #else 3405692d7eaSJiri Benc return (__force __be32)((__force u32)(vni_field & VXLAN_VNI_MASK) << 8); 34154bfd872SJiri Benc #endif 34254bfd872SJiri Benc } 34354bfd872SJiri Benc 34454bfd872SJiri Benc static inline __be32 vxlan_vni_field(__be32 vni) 34554bfd872SJiri Benc { 34654bfd872SJiri Benc #if defined(__BIG_ENDIAN) 3475692d7eaSJiri Benc return (__force __be32)((__force u32)vni << 8); 34854bfd872SJiri Benc #else 3495692d7eaSJiri Benc return (__force __be32)((__force u32)vni >> 8); 35054bfd872SJiri Benc #endif 35154bfd872SJiri Benc } 35254bfd872SJiri Benc 35354bfd872SJiri Benc static inline size_t vxlan_rco_start(__be32 vni_field) 35454bfd872SJiri Benc { 35554bfd872SJiri Benc return be32_to_cpu(vni_field & VXLAN_RCO_MASK) << VXLAN_RCO_SHIFT; 35654bfd872SJiri Benc } 35754bfd872SJiri Benc 35854bfd872SJiri Benc static inline size_t vxlan_rco_offset(__be32 vni_field) 35954bfd872SJiri Benc { 36054bfd872SJiri Benc return (vni_field & VXLAN_RCO_UDP) ? 36154bfd872SJiri Benc offsetof(struct udphdr, check) : 36254bfd872SJiri Benc offsetof(struct tcphdr, check); 36354bfd872SJiri Benc } 36454bfd872SJiri Benc 36554bfd872SJiri Benc static inline __be32 vxlan_compute_rco(unsigned int start, unsigned int offset) 36654bfd872SJiri Benc { 36754bfd872SJiri Benc __be32 vni_field = cpu_to_be32(start >> VXLAN_RCO_SHIFT); 36854bfd872SJiri Benc 36954bfd872SJiri Benc if (offset == offsetof(struct udphdr, check)) 37054bfd872SJiri Benc vni_field |= VXLAN_RCO_UDP; 37154bfd872SJiri Benc return vni_field; 37254bfd872SJiri Benc } 37354bfd872SJiri Benc 374705cc62fSJiri Benc static inline unsigned short vxlan_get_sk_family(struct vxlan_sock *vs) 375705cc62fSJiri Benc { 376705cc62fSJiri Benc return vs->sock->sk->sk_family; 377705cc62fSJiri Benc } 37848e92c44SJiri Benc 37948e92c44SJiri Benc #endif 380