]>
Commit | Line | Data |
---|---|---|
012a5729 PS |
1 | #ifndef __NET_VXLAN_H |
2 | #define __NET_VXLAN_H 1 | |
3 | ||
5f35227e JG |
4 | #include <linux/ip.h> |
5 | #include <linux/ipv6.h> | |
6 | #include <linux/if_vlan.h> | |
012a5729 PS |
7 | #include <linux/skbuff.h> |
8 | #include <linux/netdevice.h> | |
9 | #include <linux/udp.h> | |
10 | ||
11 | #define VNI_HASH_BITS 10 | |
12 | #define VNI_HASH_SIZE (1<<VNI_HASH_BITS) | |
13 | ||
11bf7828 JS |
14 | /* VXLAN protocol header */ |
15 | struct vxlanhdr { | |
16 | __be32 vx_flags; | |
17 | __be32 vx_vni; | |
18 | }; | |
19 | ||
3bf39475 TH |
20 | /* VXLAN header flags. */ |
21 | #define VXLAN_HF_VNI 0x08000000 | |
dfd8645e TH |
22 | #define VXLAN_HF_RCO 0x00200000 |
23 | ||
24 | /* Remote checksum offload header option */ | |
25 | #define VXLAN_RCO_MASK 0x7f /* Last byte of vni field */ | |
26 | #define VXLAN_RCO_UDP 0x80 /* Indicate UDP RCO (TCP when not set *) */ | |
27 | #define VXLAN_RCO_SHIFT 1 /* Left shift of start */ | |
28 | #define VXLAN_RCO_SHIFT_MASK ((1 << VXLAN_RCO_SHIFT) - 1) | |
29 | #define VXLAN_MAX_REMCSUM_START (VXLAN_RCO_MASK << VXLAN_RCO_SHIFT) | |
3bf39475 TH |
30 | |
31 | #define VXLAN_N_VID (1u << 24) | |
32 | #define VXLAN_VID_MASK (VXLAN_N_VID - 1) | |
33 | #define VXLAN_HLEN (sizeof(struct udphdr) + sizeof(struct vxlanhdr)) | |
34 | ||
012a5729 PS |
35 | struct vxlan_sock; |
36 | typedef void (vxlan_rcv_t)(struct vxlan_sock *vh, struct sk_buff *skb, __be32 key); | |
37 | ||
38 | /* per UDP socket information */ | |
39 | struct vxlan_sock { | |
40 | struct hlist_node hlist; | |
41 | vxlan_rcv_t *rcv; | |
42 | void *data; | |
43 | struct work_struct del_work; | |
44 | struct socket *sock; | |
45 | struct rcu_head rcu; | |
46 | struct hlist_head vni_list[VNI_HASH_SIZE]; | |
47 | atomic_t refcnt; | |
dc01e7d3 | 48 | struct udp_offload udp_offloads; |
dfd8645e | 49 | u32 flags; |
012a5729 PS |
50 | }; |
51 | ||
359a0ea9 TH |
52 | #define VXLAN_F_LEARN 0x01 |
53 | #define VXLAN_F_PROXY 0x02 | |
54 | #define VXLAN_F_RSC 0x04 | |
55 | #define VXLAN_F_L2MISS 0x08 | |
56 | #define VXLAN_F_L3MISS 0x10 | |
57 | #define VXLAN_F_IPV6 0x20 | |
58 | #define VXLAN_F_UDP_CSUM 0x40 | |
59 | #define VXLAN_F_UDP_ZERO_CSUM6_TX 0x80 | |
60 | #define VXLAN_F_UDP_ZERO_CSUM6_RX 0x100 | |
dfd8645e TH |
61 | #define VXLAN_F_REMCSUM_TX 0x200 |
62 | #define VXLAN_F_REMCSUM_RX 0x400 | |
359a0ea9 | 63 | |
012a5729 PS |
64 | struct vxlan_sock *vxlan_sock_add(struct net *net, __be16 port, |
65 | vxlan_rcv_t *rcv, void *data, | |
359a0ea9 | 66 | bool no_share, u32 flags); |
012a5729 PS |
67 | |
68 | void vxlan_sock_release(struct vxlan_sock *vs); | |
49560532 | 69 | |
11796187 | 70 | int vxlan_xmit_skb(struct vxlan_sock *vs, |
49560532 PS |
71 | struct rtable *rt, struct sk_buff *skb, |
72 | __be32 src, __be32 dst, __u8 tos, __u8 ttl, __be16 df, | |
f01ec1c0 | 73 | __be16 src_port, __be16 dst_port, __be32 vni, bool xnet); |
49560532 | 74 | |
5f35227e JG |
75 | static inline netdev_features_t vxlan_features_check(struct sk_buff *skb, |
76 | netdev_features_t features) | |
11bf7828 | 77 | { |
5f35227e JG |
78 | u8 l4_hdr = 0; |
79 | ||
80 | if (!skb->encapsulation) | |
81 | return features; | |
82 | ||
83 | switch (vlan_get_protocol(skb)) { | |
84 | case htons(ETH_P_IP): | |
85 | l4_hdr = ip_hdr(skb)->protocol; | |
86 | break; | |
87 | case htons(ETH_P_IPV6): | |
88 | l4_hdr = ipv6_hdr(skb)->nexthdr; | |
89 | break; | |
90 | default: | |
91 | return features;; | |
92 | } | |
93 | ||
94 | if ((l4_hdr == IPPROTO_UDP) && | |
11bf7828 JS |
95 | (skb->inner_protocol_type != ENCAP_TYPE_ETHER || |
96 | skb->inner_protocol != htons(ETH_P_TEB) || | |
97 | (skb_inner_mac_header(skb) - skb_transport_header(skb) != | |
98 | sizeof(struct udphdr) + sizeof(struct vxlanhdr)))) | |
5f35227e | 99 | return features & ~(NETIF_F_ALL_CSUM | NETIF_F_GSO_MASK); |
11bf7828 | 100 | |
5f35227e | 101 | return features; |
11bf7828 | 102 | } |
23e62de3 | 103 | |
e6cd988c JG |
104 | /* IP header + UDP + VXLAN + Ethernet header */ |
105 | #define VXLAN_HEADROOM (20 + 8 + 8 + 14) | |
106 | /* IPv6 header + UDP + VXLAN + Ethernet header */ | |
107 | #define VXLAN6_HEADROOM (40 + 8 + 8 + 14) | |
108 | ||
109 | #if IS_ENABLED(CONFIG_VXLAN) | |
53cf5275 | 110 | void vxlan_get_rx_port(struct net_device *netdev); |
e6cd988c JG |
111 | #else |
112 | static inline void vxlan_get_rx_port(struct net_device *netdev) | |
113 | { | |
114 | } | |
115 | #endif | |
012a5729 | 116 | #endif |