1 #ifndef __NET_VXLAN_WRAPPER_H
2 #define __NET_VXLAN_WRAPPER_H 1
4 #include <linux/skbuff.h>
5 #include <linux/netdevice.h>
9 #include <linux/version.h>
11 #ifdef HAVE_VXLAN_METADATA
12 #define USE_UPSTREAM_VXLAN
14 #include_next <net/vxlan.h>
18 /* VXLAN header flags. */
19 #define VXLAN_HF_VNI 0x08000000
21 #define VXLAN_HF_GBP 0x80000000
24 #define VXLAN_N_VID (1u << 24)
25 #define VXLAN_VID_MASK (VXLAN_N_VID - 1)
26 #define VXLAN_HLEN (sizeof(struct udphdr) + sizeof(struct vxlanhdr))
29 #ifndef VXLAN_GBP_USED_BITS
31 * VXLAN Group Based Policy Extension:
32 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
33 * |1|-|-|-|1|-|-|-|R|D|R|R|A|R|R|R| Group Policy ID |
34 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
35 * | VXLAN Network Identifier (VNI) | Reserved |
36 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
38 * D = Don't Learn bit. When set, this bit indicates that the egress
39 * VTEP MUST NOT learn the source address of the encapsulated frame.
41 * A = Indicates that the group policy has already been applied to
42 * this packet. Policies MUST NOT be applied by devices when the
45 * [0] https://tools.ietf.org/html/draft-smith-vxlan-group-policy
49 #ifdef __LITTLE_ENDIAN_BITFIELD
50 __u8 reserved_flags1:3,
55 #elif defined(__BIG_ENDIAN_BITFIELD)
56 __u8 reserved_flags1:1,
62 #error "Please fix <asm/byteorder.h>"
67 #define VXLAN_GBP_USED_BITS (VXLAN_HF_GBP | 0xFFFFFF)
71 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
72 * |R|R|R|R|R|R|R|R|R|D|R|R|A|R|R|R| Group Policy ID |
73 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
75 #define VXLAN_GBP_DONT_LEARN (BIT(6) << 16)
76 #define VXLAN_GBP_POLICY_APPLIED (BIT(3) << 16)
77 #define VXLAN_GBP_ID_MASK (0xFFFF)
79 #define VXLAN_F_GBP 0x800
82 #ifndef VXLAN_F_UDP_CSUM
83 #define VXLAN_F_UDP_CSUM 0x40
86 #ifndef VXLAN_F_RCV_FLAGS
87 #define VXLAN_F_RCV_FLAGS VXLAN_F_GBP
90 #ifdef USE_UPSTREAM_VXLAN
91 static inline int rpl_vxlan_xmit_skb(struct rtable *rt, struct sock *sk,
92 struct sk_buff *skb, __be32 src, __be32 dst, __u8 tos,
93 __u8 ttl, __be16 df, __be16 src_port, __be16 dst_port,
94 struct vxlan_metadata *md, bool xnet, u32 vxflags)
96 if (skb_is_gso(skb) && skb_is_encapsulated(skb)) {
101 #if LINUX_VERSION_CODE < KERNEL_VERSION(4,1,0)
102 return vxlan_xmit_skb(rt, skb, src, dst, tos, ttl, df,
104 return vxlan_xmit_skb(rt, sk, skb, src, dst, tos, ttl, df,
106 src_port, dst_port, md, xnet, vxflags);
109 #define vxlan_xmit_skb rpl_vxlan_xmit_skb
110 #else /* USE_UPSTREAM_VXLAN */
112 struct vxlan_metadata {
117 #define vxlan_sock rpl_vxlan_sock
118 struct rpl_vxlan_sock;
120 #define vxlan_rcv_t rpl_vxlan_rcv_t
121 typedef void (vxlan_rcv_t)(struct vxlan_sock *vh, struct sk_buff *skb,
122 struct vxlan_metadata *md);
124 /* per UDP socket information */
126 struct hlist_node hlist;
129 struct work_struct del_work;
135 #define vxlan_sock_add rpl_vxlan_sock_add
136 struct vxlan_sock *rpl_vxlan_sock_add(struct net *net, __be16 port,
137 vxlan_rcv_t *rcv, void *data,
138 bool no_share, u32 flags);
140 #define vxlan_sock_release rpl_vxlan_sock_release
141 void rpl_vxlan_sock_release(struct vxlan_sock *vs);
143 #define vxlan_xmit_skb rpl_vxlan_xmit_skb
144 int rpl_vxlan_xmit_skb(struct rtable *rt, struct sock *sk, struct sk_buff *skb,
145 __be32 src, __be32 dst, __u8 tos, __u8 ttl, __be16 df,
146 __be16 src_port, __be16 dst_port,
147 struct vxlan_metadata *md, bool xnet, u32 vxflags);
149 #endif /* !HAVE_VXLAN_METADATA */