7270eb153088b9ba97fcd319a2bbfdc569bf0333
[cascardo/ovs.git] / datapath / linux / compat / include / net / vxlan.h
1 #ifndef __NET_VXLAN_WRAPPER_H
2 #define __NET_VXLAN_WRAPPER_H  1
3
4 #include <linux/skbuff.h>
5 #include <linux/netdevice.h>
6 #include <linux/udp.h>
7 #include <net/gre.h>
8
9 #include <linux/version.h>
10
11 #ifdef USE_KERNEL_TUNNEL_API
12 #include_next <net/vxlan.h>
13 #endif
14
15 #ifndef VXLAN_HLEN
16 /* VXLAN header flags. */
17 #define VXLAN_HF_VNI 0x08000000
18 #ifndef VXLAN_HF_GBP
19 #define VXLAN_HF_GBP 0x80000000
20 #endif
21
22 #define VXLAN_N_VID     (1u << 24)
23 #define VXLAN_VID_MASK  (VXLAN_N_VID - 1)
24 #define VXLAN_HLEN (sizeof(struct udphdr) + sizeof(struct vxlanhdr))
25 #endif
26
27 #ifndef VXLAN_GBP_USED_BITS
28 /*
29  * VXLAN Group Based Policy Extension:
30  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
31  * |1|-|-|-|1|-|-|-|R|D|R|R|A|R|R|R|        Group Policy ID        |
32  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
33  * |                VXLAN Network Identifier (VNI) |   Reserved    |
34  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
35  *
36  * D = Don't Learn bit. When set, this bit indicates that the egress
37  *     VTEP MUST NOT learn the source address of the encapsulated frame.
38  *
39  * A = Indicates that the group policy has already been applied to
40  *     this packet. Policies MUST NOT be applied by devices when the
41  *     A bit is set.
42  *
43  * [0] https://tools.ietf.org/html/draft-smith-vxlan-group-policy
44  */
45 struct vxlanhdr_gbp {
46         __u8    vx_flags;
47 #ifdef __LITTLE_ENDIAN_BITFIELD
48         __u8    reserved_flags1:3,
49                 policy_applied:1,
50                 reserved_flags2:2,
51                 dont_learn:1,
52                 reserved_flags3:1;
53 #elif defined(__BIG_ENDIAN_BITFIELD)
54         __u8    reserved_flags1:1,
55                 dont_learn:1,
56                 reserved_flags2:2,
57                 policy_applied:1,
58                 reserved_flags3:3;
59 #else
60 #error  "Please fix <asm/byteorder.h>"
61 #endif
62         __be16  policy_id;
63         __be32  vx_vni;
64 };
65 #define VXLAN_GBP_USED_BITS (VXLAN_HF_GBP | 0xFFFFFF)
66
67 /* skb->mark mapping
68  *
69  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
70  * |R|R|R|R|R|R|R|R|R|D|R|R|A|R|R|R|        Group Policy ID        |
71  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
72  */
73 #define VXLAN_GBP_DONT_LEARN            (BIT(6) << 16)
74 #define VXLAN_GBP_POLICY_APPLIED        (BIT(3) << 16)
75 #define VXLAN_GBP_ID_MASK               (0xFFFF)
76
77 #define VXLAN_F_GBP                     0x800
78 #endif
79
80 #ifndef VXLAN_F_RCV_FLAGS
81 #define VXLAN_F_RCV_FLAGS                       VXLAN_F_GBP
82 #endif
83
84 #ifdef HAVE_VXLAN_METADATA
85 #define USE_UPSTREAM_VXLAN
86
87 static inline int rpl_vxlan_xmit_skb(struct vxlan_sock *vs,
88                    struct rtable *rt, struct sk_buff *skb,
89                    __be32 src, __be32 dst, __u8 tos, __u8 ttl, __be16 df,
90                    __be16 src_port, __be16 dst_port,
91                    struct vxlan_metadata *md, bool xnet, u32 vxflags)
92 {
93         if (skb_is_gso(skb) && skb_is_encapsulated(skb)) {
94                 kfree_skb(skb);
95                 return -ENOSYS;
96         }
97
98         return vxlan_xmit_skb(rt, skb, src, dst, tos, ttl, df,
99                               src_port, dst_port, md, xnet, vxflags);
100 }
101
102 #define vxlan_xmit_skb rpl_vxlan_xmit_skb
103 #else /* HAVE_VXLAN_METADATA */
104
105 struct vxlan_metadata {
106         __be32          vni;
107         u32             gbp;
108 };
109
110 #define vxlan_sock rpl_vxlan_sock
111 struct rpl_vxlan_sock;
112
113 #define vxlan_rcv_t rpl_vxlan_rcv_t
114 typedef void (vxlan_rcv_t)(struct vxlan_sock *vh, struct sk_buff *skb,
115                            struct vxlan_metadata *md);
116
117 /* per UDP socket information */
118 struct vxlan_sock {
119         struct hlist_node hlist;
120         vxlan_rcv_t      *rcv;
121         void             *data;
122         struct work_struct del_work;
123         struct socket    *sock;
124         struct rcu_head   rcu;
125         u32               flags;
126 };
127
128 #define vxlan_sock_add rpl_vxlan_sock_add
129 struct vxlan_sock *vxlan_sock_add(struct net *net, __be16 port,
130                                   vxlan_rcv_t *rcv, void *data,
131                                   bool no_share, u32 flags);
132
133 #define vxlan_sock_release rpl_vxlan_sock_release
134 void vxlan_sock_release(struct vxlan_sock *vs);
135
136 #define vxlan_xmit_skb rpl_vxlan_xmit_skb
137 int vxlan_xmit_skb(struct vxlan_sock *vs,
138                    struct rtable *rt, struct sk_buff *skb,
139                    __be32 src, __be32 dst, __u8 tos, __u8 ttl, __be16 df,
140                    __be16 src_port, __be16 dst_port,
141                    struct vxlan_metadata *md, bool xnet, u32 vxflags);
142
143 #endif /* !HAVE_VXLAN_METADATA */
144 #endif