]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - include/net/vxlan.h
fib: Add fib rule match on tunnel id
[mirror_ubuntu-bionic-kernel.git] / include / net / vxlan.h
CommitLineData
012a5729
PS
1#ifndef __NET_VXLAN_H
2#define __NET_VXLAN_H 1
3
5f35227e
JG
4#include <linux/ip.h>
5#include <linux/ipv6.h>
6#include <linux/if_vlan.h>
012a5729
PS
7#include <linux/skbuff.h>
8#include <linux/netdevice.h>
9#include <linux/udp.h>
ee122c79 10#include <net/dst_metadata.h>
012a5729
PS
11
12#define VNI_HASH_BITS 10
13#define VNI_HASH_SIZE (1<<VNI_HASH_BITS)
14
3511494c
TG
15/*
16 * VXLAN Group Based Policy Extension:
17 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
18 * |1|-|-|-|1|-|-|-|R|D|R|R|A|R|R|R| Group Policy ID |
19 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
20 * | VXLAN Network Identifier (VNI) | Reserved |
21 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
22 *
23 * D = Don't Learn bit. When set, this bit indicates that the egress
24 * VTEP MUST NOT learn the source address of the encapsulated frame.
25 *
26 * A = Indicates that the group policy has already been applied to
27 * this packet. Policies MUST NOT be applied by devices when the
28 * A bit is set.
29 *
30 * [0] https://tools.ietf.org/html/draft-smith-vxlan-group-policy
31 */
32struct vxlanhdr_gbp {
33 __u8 vx_flags;
34#ifdef __LITTLE_ENDIAN_BITFIELD
35 __u8 reserved_flags1:3,
36 policy_applied:1,
37 reserved_flags2:2,
38 dont_learn:1,
39 reserved_flags3:1;
40#elif defined(__BIG_ENDIAN_BITFIELD)
41 __u8 reserved_flags1:1,
42 dont_learn:1,
43 reserved_flags2:2,
44 policy_applied:1,
45 reserved_flags3:3;
46#else
47#error "Please fix <asm/byteorder.h>"
48#endif
49 __be16 policy_id;
50 __be32 vx_vni;
51};
52
53#define VXLAN_GBP_USED_BITS (VXLAN_HF_GBP | 0xFFFFFF)
54
55/* skb->mark mapping
56 *
57 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
58 * |R|R|R|R|R|R|R|R|R|D|R|R|A|R|R|R| Group Policy ID |
59 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
60 */
61#define VXLAN_GBP_DONT_LEARN (BIT(6) << 16)
62#define VXLAN_GBP_POLICY_APPLIED (BIT(3) << 16)
63#define VXLAN_GBP_ID_MASK (0xFFFF)
64
65/* VXLAN protocol header:
66 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
67 * |G|R|R|R|I|R|R|C| Reserved |
68 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
69 * | VXLAN Network Identifier (VNI) | Reserved |
70 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
71 *
72 * G = 1 Group Policy (VXLAN-GBP)
73 * I = 1 VXLAN Network Identifier (VNI) present
74 * C = 1 Remote checksum offload (RCO)
75 */
11bf7828
JS
76struct vxlanhdr {
77 __be32 vx_flags;
78 __be32 vx_vni;
79};
80
3bf39475 81/* VXLAN header flags. */
3511494c
TG
82#define VXLAN_HF_RCO BIT(24)
83#define VXLAN_HF_VNI BIT(27)
84#define VXLAN_HF_GBP BIT(31)
dfd8645e
TH
85
86/* Remote checksum offload header option */
87#define VXLAN_RCO_MASK 0x7f /* Last byte of vni field */
88#define VXLAN_RCO_UDP 0x80 /* Indicate UDP RCO (TCP when not set *) */
89#define VXLAN_RCO_SHIFT 1 /* Left shift of start */
90#define VXLAN_RCO_SHIFT_MASK ((1 << VXLAN_RCO_SHIFT) - 1)
91#define VXLAN_MAX_REMCSUM_START (VXLAN_RCO_MASK << VXLAN_RCO_SHIFT)
3bf39475
TH
92
93#define VXLAN_N_VID (1u << 24)
94#define VXLAN_VID_MASK (VXLAN_N_VID - 1)
40fb70f3 95#define VXLAN_VNI_MASK (VXLAN_VID_MASK << 8)
3bf39475
TH
96#define VXLAN_HLEN (sizeof(struct udphdr) + sizeof(struct vxlanhdr))
97
3511494c
TG
98struct vxlan_metadata {
99 __be32 vni;
100 u32 gbp;
ee122c79
TG
101
102 /* Temporary until vxlan_rcv() API is gone */
103 struct metadata_dst *tun_dst;
3511494c
TG
104};
105
012a5729 106struct vxlan_sock;
3511494c
TG
107typedef void (vxlan_rcv_t)(struct vxlan_sock *vh, struct sk_buff *skb,
108 struct vxlan_metadata *md);
012a5729
PS
109
110/* per UDP socket information */
111struct vxlan_sock {
112 struct hlist_node hlist;
113 vxlan_rcv_t *rcv;
114 void *data;
115 struct work_struct del_work;
116 struct socket *sock;
117 struct rcu_head rcu;
118 struct hlist_head vni_list[VNI_HASH_SIZE];
119 atomic_t refcnt;
dc01e7d3 120 struct udp_offload udp_offloads;
dfd8645e 121 u32 flags;
012a5729
PS
122};
123
359a0ea9
TH
124#define VXLAN_F_LEARN 0x01
125#define VXLAN_F_PROXY 0x02
126#define VXLAN_F_RSC 0x04
127#define VXLAN_F_L2MISS 0x08
128#define VXLAN_F_L3MISS 0x10
129#define VXLAN_F_IPV6 0x20
130#define VXLAN_F_UDP_CSUM 0x40
131#define VXLAN_F_UDP_ZERO_CSUM6_TX 0x80
132#define VXLAN_F_UDP_ZERO_CSUM6_RX 0x100
dfd8645e
TH
133#define VXLAN_F_REMCSUM_TX 0x200
134#define VXLAN_F_REMCSUM_RX 0x400
3511494c 135#define VXLAN_F_GBP 0x800
0ace2ca8 136#define VXLAN_F_REMCSUM_NOPARTIAL 0x1000
ee122c79
TG
137#define VXLAN_F_COLLECT_METADATA 0x2000
138#define VXLAN_F_FLOW_BASED 0x4000
359a0ea9 139
d299ce14 140/* Flags that are used in the receive path. These flags must match in
af33c1ad
TH
141 * order for a socket to be shareable
142 */
143#define VXLAN_F_RCV_FLAGS (VXLAN_F_GBP | \
144 VXLAN_F_UDP_ZERO_CSUM6_RX | \
0ace2ca8 145 VXLAN_F_REMCSUM_RX | \
ee122c79
TG
146 VXLAN_F_REMCSUM_NOPARTIAL | \
147 VXLAN_F_COLLECT_METADATA | \
148 VXLAN_F_FLOW_BASED)
ac5132d1 149
012a5729
PS
150struct vxlan_sock *vxlan_sock_add(struct net *net, __be16 port,
151 vxlan_rcv_t *rcv, void *data,
359a0ea9 152 bool no_share, u32 flags);
012a5729
PS
153
154void vxlan_sock_release(struct vxlan_sock *vs);
49560532 155
79b16aad 156int vxlan_xmit_skb(struct rtable *rt, struct sock *sk, struct sk_buff *skb,
49560532 157 __be32 src, __be32 dst, __u8 tos, __u8 ttl, __be16 df,
3511494c 158 __be16 src_port, __be16 dst_port, struct vxlan_metadata *md,
af33c1ad 159 bool xnet, u32 vxflags);
49560532 160
5f35227e
JG
161static inline netdev_features_t vxlan_features_check(struct sk_buff *skb,
162 netdev_features_t features)
11bf7828 163{
5f35227e
JG
164 u8 l4_hdr = 0;
165
166 if (!skb->encapsulation)
167 return features;
168
169 switch (vlan_get_protocol(skb)) {
170 case htons(ETH_P_IP):
171 l4_hdr = ip_hdr(skb)->protocol;
172 break;
173 case htons(ETH_P_IPV6):
174 l4_hdr = ipv6_hdr(skb)->nexthdr;
175 break;
176 default:
177 return features;;
178 }
179
180 if ((l4_hdr == IPPROTO_UDP) &&
11bf7828
JS
181 (skb->inner_protocol_type != ENCAP_TYPE_ETHER ||
182 skb->inner_protocol != htons(ETH_P_TEB) ||
183 (skb_inner_mac_header(skb) - skb_transport_header(skb) !=
184 sizeof(struct udphdr) + sizeof(struct vxlanhdr))))
5f35227e 185 return features & ~(NETIF_F_ALL_CSUM | NETIF_F_GSO_MASK);
11bf7828 186
5f35227e 187 return features;
11bf7828 188}
23e62de3 189
e6cd988c
JG
190/* IP header + UDP + VXLAN + Ethernet header */
191#define VXLAN_HEADROOM (20 + 8 + 8 + 14)
192/* IPv6 header + UDP + VXLAN + Ethernet header */
193#define VXLAN6_HEADROOM (40 + 8 + 8 + 14)
194
195#if IS_ENABLED(CONFIG_VXLAN)
53cf5275 196void vxlan_get_rx_port(struct net_device *netdev);
e6cd988c
JG
197#else
198static inline void vxlan_get_rx_port(struct net_device *netdev)
199{
200}
201#endif
012a5729 202#endif