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 vxlan_sock *vs,
92 struct rtable *rt, struct sk_buff *skb,
93 __be32 src, __be32 dst, __u8 tos, __u8 ttl, __be16 df,
94 __be16 src_port, __be16 dst_port,
95 struct vxlan_metadata *md, bool xnet, u32 vxflags)
97 if (skb_is_gso(skb) && skb_is_encapsulated(skb)) {
102 return vxlan_xmit_skb(rt, skb, src, dst, tos, ttl, df,
103 src_port, dst_port, md, xnet, vxflags);
106 #define vxlan_xmit_skb rpl_vxlan_xmit_skb
107 #else /* USE_UPSTREAM_VXLAN */
109 struct vxlan_metadata {
114 #define vxlan_sock rpl_vxlan_sock
115 struct rpl_vxlan_sock;
117 #define vxlan_rcv_t rpl_vxlan_rcv_t
118 typedef void (vxlan_rcv_t)(struct vxlan_sock *vh, struct sk_buff *skb,
119 struct vxlan_metadata *md);
121 /* per UDP socket information */
123 struct hlist_node hlist;
126 struct work_struct del_work;
132 #define vxlan_sock_add rpl_vxlan_sock_add
133 struct vxlan_sock *rpl_vxlan_sock_add(struct net *net, __be16 port,
134 vxlan_rcv_t *rcv, void *data,
135 bool no_share, u32 flags);
137 #define vxlan_sock_release rpl_vxlan_sock_release
138 void rpl_vxlan_sock_release(struct vxlan_sock *vs);
140 #define vxlan_xmit_skb rpl_vxlan_xmit_skb
141 int rpl_vxlan_xmit_skb(struct vxlan_sock *vs,
142 struct rtable *rt, struct sk_buff *skb,
143 __be32 src, __be32 dst, __u8 tos, __u8 ttl, __be16 df,
144 __be16 src_port, __be16 dst_port,
145 struct vxlan_metadata *md, bool xnet, u32 vxflags);
147 #endif /* !HAVE_VXLAN_METADATA */