1 #ifndef __NET_VXLAN_WRAPPER_H
2 #define __NET_VXLAN_WRAPPER_H 1
5 #include <net/udp_tunnel.h>
9 #ifdef HAVE_METADATA_DST
10 #include_next <net/vxlan.h>
12 static inline int rpl_vxlan_init_module(void)
16 static inline void rpl_vxlan_cleanup_module(void)
19 #define vxlan_xmit dev_queue_xmit
24 #include <linux/ipv6.h>
25 #include <linux/if_vlan.h>
26 #include <linux/skbuff.h>
27 #include <linux/netdevice.h>
28 #include <linux/udp.h>
29 #include <net/dst_metadata.h>
34 #define VNI_HASH_BITS 10
35 #define VNI_HASH_SIZE (1<<VNI_HASH_BITS)
38 * VXLAN Group Based Policy Extension:
39 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
40 * |1|-|-|-|1|-|-|-|R|D|R|R|A|R|R|R| Group Policy ID |
41 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
42 * | VXLAN Network Identifier (VNI) | Reserved |
43 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
45 * D = Don't Learn bit. When set, this bit indicates that the egress
46 * VTEP MUST NOT learn the source address of the encapsulated frame.
48 * A = Indicates that the group policy has already been applied to
49 * this packet. Policies MUST NOT be applied by devices when the
52 * [0] https://tools.ietf.org/html/draft-smith-vxlan-group-policy
56 #ifdef __LITTLE_ENDIAN_BITFIELD
57 __u8 reserved_flags1
:3,
62 #elif defined(__BIG_ENDIAN_BITFIELD)
63 __u8 reserved_flags1
:1,
69 #error "Please fix <asm/byteorder.h>"
75 #define VXLAN_GBP_USED_BITS (VXLAN_HF_GBP | 0xFFFFFF)
79 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
80 * |R|R|R|R|R|R|R|R|R|D|R|R|A|R|R|R| Group Policy ID |
81 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
83 #define VXLAN_GBP_DONT_LEARN (BIT(6) << 16)
84 #define VXLAN_GBP_POLICY_APPLIED (BIT(3) << 16)
85 #define VXLAN_GBP_ID_MASK (0xFFFF)
87 /* VXLAN protocol header:
88 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
89 * |G|R|R|R|I|R|R|C| Reserved |
90 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
91 * | VXLAN Network Identifier (VNI) | Reserved |
92 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
94 * G = 1 Group Policy (VXLAN-GBP)
95 * I = 1 VXLAN Network Identifier (VNI) present
96 * C = 1 Remote checksum offload (RCO)
103 /* VXLAN header flags. */
104 #define VXLAN_HF_RCO BIT(24)
105 #define VXLAN_HF_VNI BIT(27)
106 #define VXLAN_HF_GBP BIT(31)
108 /* Remote checksum offload header option */
109 #define VXLAN_RCO_MASK 0x7f /* Last byte of vni field */
110 #define VXLAN_RCO_UDP 0x80 /* Indicate UDP RCO (TCP when not set *) */
111 #define VXLAN_RCO_SHIFT 1 /* Left shift of start */
112 #define VXLAN_RCO_SHIFT_MASK ((1 << VXLAN_RCO_SHIFT) - 1)
113 #define VXLAN_MAX_REMCSUM_START (VXLAN_RCO_MASK << VXLAN_RCO_SHIFT)
115 #define VXLAN_N_VID (1u << 24)
116 #define VXLAN_VID_MASK (VXLAN_N_VID - 1)
117 #define VXLAN_VNI_MASK (VXLAN_VID_MASK << 8)
118 #define VXLAN_HLEN (sizeof(struct udphdr) + sizeof(struct vxlanhdr))
120 struct vxlan_metadata
{
125 #define VNI_HASH_BITS 10
126 #define VNI_HASH_SIZE (1<<VNI_HASH_BITS)
127 #define FDB_HASH_BITS 8
128 #define FDB_HASH_SIZE (1<<FDB_HASH_BITS)
130 /* per UDP socket information */
132 struct hlist_node hlist
;
133 struct work_struct del_work
;
136 struct hlist_head vni_list
[VNI_HASH_SIZE
];
138 #ifdef HAVE_UDP_OFFLOAD
139 struct udp_offload udp_offloads
;
145 struct sockaddr_in sin
;
146 struct sockaddr_in6 sin6
;
151 union vxlan_addr remote_ip
;
155 struct list_head list
;
159 struct vxlan_config
{
160 union vxlan_addr remote_ip
;
161 union vxlan_addr saddr
;
171 unsigned long age_interval
;
172 unsigned int addrmax
;
176 /* Pseudo network device */
178 struct hlist_node hlist
; /* vni hash table */
179 struct list_head next
; /* vxlan's per namespace list */
180 struct vxlan_sock
*vn_sock
; /* listening socket */
181 struct net_device
*dev
;
182 struct net
*net
; /* netns for packet i/o */
183 struct vxlan_rdst default_dst
; /* default destination */
184 u32 flags
; /* VXLAN_F_* in vxlan.h */
186 struct timer_list age_timer
;
187 spinlock_t hash_lock
;
188 unsigned int addrcnt
;
190 struct vxlan_config cfg
;
191 struct hlist_head fdb_head
[FDB_HASH_SIZE
];
194 #define VXLAN_F_LEARN 0x01
195 #define VXLAN_F_PROXY 0x02
196 #define VXLAN_F_RSC 0x04
197 #define VXLAN_F_L2MISS 0x08
198 #define VXLAN_F_L3MISS 0x10
199 #define VXLAN_F_IPV6 0x20
200 #define VXLAN_F_UDP_CSUM 0x40
201 #define VXLAN_F_UDP_ZERO_CSUM6_TX 0x80
202 #define VXLAN_F_UDP_ZERO_CSUM6_RX 0x100
203 #define VXLAN_F_REMCSUM_TX 0x200
204 #define VXLAN_F_REMCSUM_RX 0x400
205 #define VXLAN_F_GBP 0x800
206 #define VXLAN_F_REMCSUM_NOPARTIAL 0x1000
207 #define VXLAN_F_COLLECT_METADATA 0x2000
209 /* Flags that are used in the receive path. These flags must match in
210 * order for a socket to be shareable
212 #define VXLAN_F_RCV_FLAGS (VXLAN_F_GBP | \
213 VXLAN_F_UDP_ZERO_CSUM6_RX | \
214 VXLAN_F_REMCSUM_RX | \
215 VXLAN_F_REMCSUM_NOPARTIAL | \
216 VXLAN_F_COLLECT_METADATA)
217 #define vxlan_dev_create rpl_vxlan_dev_create
218 struct net_device
*rpl_vxlan_dev_create(struct net
*net
, const char *name
,
219 u8 name_assign_type
, struct vxlan_config
*conf
);
221 static inline __be16
vxlan_dev_dst_port(struct vxlan_dev
*vxlan
)
223 return inet_sport(vxlan
->vn_sock
->sock
->sk
);
226 static inline netdev_features_t
vxlan_features_check(struct sk_buff
*skb
,
227 netdev_features_t features
)
231 if (!skb_encapsulation(skb
))
234 switch (vlan_get_protocol(skb
)) {
235 case htons(ETH_P_IP
):
236 l4_hdr
= ip_hdr(skb
)->protocol
;
238 case htons(ETH_P_IPV6
):
239 l4_hdr
= ipv6_hdr(skb
)->nexthdr
;
245 if ((l4_hdr
== IPPROTO_UDP
) && (
246 #ifdef ENCAP_TYPE_ETHER
247 skb
->inner_protocol_type
!= ENCAP_TYPE_ETHER
||
249 ovs_skb_get_inner_protocol(skb
) != htons(ETH_P_TEB
) ||
250 (skb_inner_mac_header(skb
) - skb_transport_header(skb
) !=
251 sizeof(struct udphdr
) + sizeof(struct vxlanhdr
))))
252 return features
& ~(NETIF_F_ALL_CSUM
| NETIF_F_GSO_MASK
);
257 /* IP header + UDP + VXLAN + Ethernet header */
258 #define VXLAN_HEADROOM (20 + 8 + 8 + 14)
259 /* IPv6 header + UDP + VXLAN + Ethernet header */
260 #define VXLAN6_HEADROOM (40 + 8 + 8 + 14)
262 static inline unsigned short vxlan_get_sk_family(struct vxlan_sock
*vs
)
264 return vs
->sock
->sk
->sk_family
;
267 int rpl_vxlan_init_module(void);
268 void rpl_vxlan_cleanup_module(void);
270 #define vxlan_xmit rpl_vxlan_xmit
271 netdev_tx_t
rpl_vxlan_xmit(struct sk_buff
*skb
);
274 #define vxlan_init_module rpl_vxlan_init_module
275 #define vxlan_cleanup_module rpl_vxlan_cleanup_module