2 #define __NET_VXLAN_H 1
5 #include <linux/ipv6.h>
6 #include <linux/if_vlan.h>
7 #include <linux/skbuff.h>
8 #include <linux/netdevice.h>
11 #define VNI_HASH_BITS 10
12 #define VNI_HASH_SIZE (1<<VNI_HASH_BITS)
15 * VXLAN Group Based Policy Extension:
16 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
17 * |1|-|-|-|1|-|-|-|R|D|R|R|A|R|R|R| Group Policy ID |
18 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
19 * | VXLAN Network Identifier (VNI) | Reserved |
20 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
22 * D = Don't Learn bit. When set, this bit indicates that the egress
23 * VTEP MUST NOT learn the source address of the encapsulated frame.
25 * A = Indicates that the group policy has already been applied to
26 * this packet. Policies MUST NOT be applied by devices when the
29 * [0] https://tools.ietf.org/html/draft-smith-vxlan-group-policy
33 #ifdef __LITTLE_ENDIAN_BITFIELD
34 __u8 reserved_flags1
:3,
39 #elif defined(__BIG_ENDIAN_BITFIELD)
40 __u8 reserved_flags1
:1,
46 #error "Please fix <asm/byteorder.h>"
52 #define VXLAN_GBP_USED_BITS (VXLAN_HF_GBP | 0xFFFFFF)
56 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
57 * |R|R|R|R|R|R|R|R|R|D|R|R|A|R|R|R| Group Policy ID |
58 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
60 #define VXLAN_GBP_DONT_LEARN (BIT(6) << 16)
61 #define VXLAN_GBP_POLICY_APPLIED (BIT(3) << 16)
62 #define VXLAN_GBP_ID_MASK (0xFFFF)
64 /* VXLAN protocol header:
65 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
66 * |G|R|R|R|I|R|R|C| Reserved |
67 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
68 * | VXLAN Network Identifier (VNI) | Reserved |
69 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
71 * G = 1 Group Policy (VXLAN-GBP)
72 * I = 1 VXLAN Network Identifier (VNI) present
73 * C = 1 Remote checksum offload (RCO)
80 /* VXLAN header flags. */
81 #define VXLAN_HF_RCO BIT(24)
82 #define VXLAN_HF_VNI BIT(27)
83 #define VXLAN_HF_GBP BIT(31)
85 /* Remote checksum offload header option */
86 #define VXLAN_RCO_MASK 0x7f /* Last byte of vni field */
87 #define VXLAN_RCO_UDP 0x80 /* Indicate UDP RCO (TCP when not set *) */
88 #define VXLAN_RCO_SHIFT 1 /* Left shift of start */
89 #define VXLAN_RCO_SHIFT_MASK ((1 << VXLAN_RCO_SHIFT) - 1)
90 #define VXLAN_MAX_REMCSUM_START (VXLAN_RCO_MASK << VXLAN_RCO_SHIFT)
92 #define VXLAN_N_VID (1u << 24)
93 #define VXLAN_VID_MASK (VXLAN_N_VID - 1)
94 #define VXLAN_VNI_MASK (VXLAN_VID_MASK << 8)
95 #define VXLAN_HLEN (sizeof(struct udphdr) + sizeof(struct vxlanhdr))
97 struct vxlan_metadata
{
103 typedef void (vxlan_rcv_t
)(struct vxlan_sock
*vh
, struct sk_buff
*skb
,
104 struct vxlan_metadata
*md
);
106 /* per UDP socket information */
108 struct hlist_node hlist
;
111 struct work_struct del_work
;
114 struct hlist_head vni_list
[VNI_HASH_SIZE
];
116 struct udp_offload udp_offloads
;
120 #define VXLAN_F_LEARN 0x01
121 #define VXLAN_F_PROXY 0x02
122 #define VXLAN_F_RSC 0x04
123 #define VXLAN_F_L2MISS 0x08
124 #define VXLAN_F_L3MISS 0x10
125 #define VXLAN_F_IPV6 0x20
126 #define VXLAN_F_UDP_CSUM 0x40
127 #define VXLAN_F_UDP_ZERO_CSUM6_TX 0x80
128 #define VXLAN_F_UDP_ZERO_CSUM6_RX 0x100
129 #define VXLAN_F_REMCSUM_TX 0x200
130 #define VXLAN_F_REMCSUM_RX 0x400
131 #define VXLAN_F_GBP 0x800
132 #define VXLAN_F_REMCSUM_NOPARTIAL 0x1000
134 /* Flags that are used in the receive path. These flags must match in
135 * order for a socket to be shareable
137 #define VXLAN_F_RCV_FLAGS (VXLAN_F_GBP | \
138 VXLAN_F_UDP_ZERO_CSUM6_RX | \
139 VXLAN_F_REMCSUM_RX | \
140 VXLAN_F_REMCSUM_NOPARTIAL)
142 struct vxlan_sock
*vxlan_sock_add(struct net
*net
, __be16 port
,
143 vxlan_rcv_t
*rcv
, void *data
,
144 bool no_share
, u32 flags
);
146 void vxlan_sock_release(struct vxlan_sock
*vs
);
148 int vxlan_xmit_skb(struct rtable
*rt
, struct sock
*sk
, struct sk_buff
*skb
,
149 __be32 src
, __be32 dst
, __u8 tos
, __u8 ttl
, __be16 df
,
150 __be16 src_port
, __be16 dst_port
, struct vxlan_metadata
*md
,
151 bool xnet
, u32 vxflags
);
153 static inline netdev_features_t
vxlan_features_check(struct sk_buff
*skb
,
154 netdev_features_t features
)
158 if (!skb
->encapsulation
)
161 switch (vlan_get_protocol(skb
)) {
162 case htons(ETH_P_IP
):
163 l4_hdr
= ip_hdr(skb
)->protocol
;
165 case htons(ETH_P_IPV6
):
166 l4_hdr
= ipv6_hdr(skb
)->nexthdr
;
172 if ((l4_hdr
== IPPROTO_UDP
) &&
173 (skb
->inner_protocol_type
!= ENCAP_TYPE_ETHER
||
174 skb
->inner_protocol
!= htons(ETH_P_TEB
) ||
175 (skb_inner_mac_header(skb
) - skb_transport_header(skb
) !=
176 sizeof(struct udphdr
) + sizeof(struct vxlanhdr
))))
177 return features
& ~(NETIF_F_ALL_CSUM
| NETIF_F_GSO_MASK
);
182 /* IP header + UDP + VXLAN + Ethernet header */
183 #define VXLAN_HEADROOM (20 + 8 + 8 + 14)
184 /* IPv6 header + UDP + VXLAN + Ethernet header */
185 #define VXLAN6_HEADROOM (40 + 8 + 8 + 14)
187 #if IS_ENABLED(CONFIG_VXLAN)
188 void vxlan_get_rx_port(struct net_device
*netdev
);
190 static inline void vxlan_get_rx_port(struct net_device
*netdev
)