blob: 903461aa5644ce9d1e366818fa6cbda1ba0cc1b1 [file] [log] [blame]
Pravin B Shelar012a5722013-08-19 11:23:07 -07001#ifndef __NET_VXLAN_H
2#define __NET_VXLAN_H 1
3
Jesse Gross5f352272014-12-23 22:37:26 -08004#include <linux/ip.h>
5#include <linux/ipv6.h>
6#include <linux/if_vlan.h>
Pravin B Shelar012a5722013-08-19 11:23:07 -07007#include <linux/skbuff.h>
8#include <linux/netdevice.h>
9#include <linux/udp.h>
10
11#define VNI_HASH_BITS 10
12#define VNI_HASH_SIZE (1<<VNI_HASH_BITS)
13
Joe Stringer11bf7822014-11-17 16:24:54 -080014/* VXLAN protocol header */
15struct vxlanhdr {
16 __be32 vx_flags;
17 __be32 vx_vni;
18};
19
Pravin B Shelar012a5722013-08-19 11:23:07 -070020struct vxlan_sock;
21typedef void (vxlan_rcv_t)(struct vxlan_sock *vh, struct sk_buff *skb, __be32 key);
22
23/* per UDP socket information */
24struct vxlan_sock {
25 struct hlist_node hlist;
26 vxlan_rcv_t *rcv;
27 void *data;
28 struct work_struct del_work;
29 struct socket *sock;
30 struct rcu_head rcu;
31 struct hlist_head vni_list[VNI_HASH_SIZE];
32 atomic_t refcnt;
Or Gerlitzdc01e7d2014-01-20 13:59:21 +020033 struct udp_offload udp_offloads;
Pravin B Shelar012a5722013-08-19 11:23:07 -070034};
35
Tom Herbert359a0ea2014-06-04 17:20:29 -070036#define VXLAN_F_LEARN 0x01
37#define VXLAN_F_PROXY 0x02
38#define VXLAN_F_RSC 0x04
39#define VXLAN_F_L2MISS 0x08
40#define VXLAN_F_L3MISS 0x10
41#define VXLAN_F_IPV6 0x20
42#define VXLAN_F_UDP_CSUM 0x40
43#define VXLAN_F_UDP_ZERO_CSUM6_TX 0x80
44#define VXLAN_F_UDP_ZERO_CSUM6_RX 0x100
45
Pravin B Shelar012a5722013-08-19 11:23:07 -070046struct vxlan_sock *vxlan_sock_add(struct net *net, __be16 port,
47 vxlan_rcv_t *rcv, void *data,
Tom Herbert359a0ea2014-06-04 17:20:29 -070048 bool no_share, u32 flags);
Pravin B Shelar012a5722013-08-19 11:23:07 -070049
50void vxlan_sock_release(struct vxlan_sock *vs);
Pravin B Shelar49560532013-08-19 11:23:17 -070051
Nicolas Dichtel11796182013-09-02 15:34:55 +020052int vxlan_xmit_skb(struct vxlan_sock *vs,
Pravin B Shelar49560532013-08-19 11:23:17 -070053 struct rtable *rt, struct sk_buff *skb,
54 __be32 src, __be32 dst, __u8 tos, __u8 ttl, __be16 df,
Nicolas Dichtelf01ec1c2014-04-24 10:02:49 +020055 __be16 src_port, __be16 dst_port, __be32 vni, bool xnet);
Pravin B Shelar49560532013-08-19 11:23:17 -070056
Jesse Gross5f352272014-12-23 22:37:26 -080057static inline netdev_features_t vxlan_features_check(struct sk_buff *skb,
58 netdev_features_t features)
Joe Stringer11bf7822014-11-17 16:24:54 -080059{
Jesse Gross5f352272014-12-23 22:37:26 -080060 u8 l4_hdr = 0;
61
62 if (!skb->encapsulation)
63 return features;
64
65 switch (vlan_get_protocol(skb)) {
66 case htons(ETH_P_IP):
67 l4_hdr = ip_hdr(skb)->protocol;
68 break;
69 case htons(ETH_P_IPV6):
70 l4_hdr = ipv6_hdr(skb)->nexthdr;
71 break;
72 default:
73 return features;;
74 }
75
76 if ((l4_hdr == IPPROTO_UDP) &&
Joe Stringer11bf7822014-11-17 16:24:54 -080077 (skb->inner_protocol_type != ENCAP_TYPE_ETHER ||
78 skb->inner_protocol != htons(ETH_P_TEB) ||
79 (skb_inner_mac_header(skb) - skb_transport_header(skb) !=
80 sizeof(struct udphdr) + sizeof(struct vxlanhdr))))
Jesse Gross5f352272014-12-23 22:37:26 -080081 return features & ~(NETIF_F_ALL_CSUM | NETIF_F_GSO_MASK);
Joe Stringer11bf7822014-11-17 16:24:54 -080082
Jesse Gross5f352272014-12-23 22:37:26 -080083 return features;
Joe Stringer11bf7822014-11-17 16:24:54 -080084}
Joe Stringer23e62de2014-11-13 16:38:12 -080085
Joseph Gasparakise6cd9882013-10-24 06:27:10 +000086/* IP header + UDP + VXLAN + Ethernet header */
87#define VXLAN_HEADROOM (20 + 8 + 8 + 14)
88/* IPv6 header + UDP + VXLAN + Ethernet header */
89#define VXLAN6_HEADROOM (40 + 8 + 8 + 14)
90
91#if IS_ENABLED(CONFIG_VXLAN)
Joseph Gasparakis53cf52752013-09-04 02:13:38 -070092void vxlan_get_rx_port(struct net_device *netdev);
Joseph Gasparakise6cd9882013-10-24 06:27:10 +000093#else
94static inline void vxlan_get_rx_port(struct net_device *netdev)
95{
96}
97#endif
Pravin B Shelar012a5722013-08-19 11:23:07 -070098#endif