Pravin B Shelar | 012a572 | 2013-08-19 11:23:07 -0700 | [diff] [blame] | 1 | #ifndef __NET_VXLAN_H |
| 2 | #define __NET_VXLAN_H 1 |
| 3 | |
Jesse Gross | 5f35227 | 2014-12-23 22:37:26 -0800 | [diff] [blame] | 4 | #include <linux/ip.h> |
| 5 | #include <linux/ipv6.h> |
| 6 | #include <linux/if_vlan.h> |
Pravin B Shelar | 012a572 | 2013-08-19 11:23:07 -0700 | [diff] [blame] | 7 | #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 Stringer | 11bf782 | 2014-11-17 16:24:54 -0800 | [diff] [blame] | 14 | /* VXLAN protocol header */ |
| 15 | struct vxlanhdr { |
| 16 | __be32 vx_flags; |
| 17 | __be32 vx_vni; |
| 18 | }; |
| 19 | |
Tom Herbert | 3bf3947 | 2015-01-08 12:31:18 -0800 | [diff] [blame^] | 20 | /* VXLAN header flags. */ |
| 21 | #define VXLAN_HF_VNI 0x08000000 |
| 22 | |
| 23 | #define VXLAN_N_VID (1u << 24) |
| 24 | #define VXLAN_VID_MASK (VXLAN_N_VID - 1) |
| 25 | #define VXLAN_HLEN (sizeof(struct udphdr) + sizeof(struct vxlanhdr)) |
| 26 | |
Pravin B Shelar | 012a572 | 2013-08-19 11:23:07 -0700 | [diff] [blame] | 27 | struct vxlan_sock; |
| 28 | typedef void (vxlan_rcv_t)(struct vxlan_sock *vh, struct sk_buff *skb, __be32 key); |
| 29 | |
| 30 | /* per UDP socket information */ |
| 31 | struct vxlan_sock { |
| 32 | struct hlist_node hlist; |
| 33 | vxlan_rcv_t *rcv; |
| 34 | void *data; |
| 35 | struct work_struct del_work; |
| 36 | struct socket *sock; |
| 37 | struct rcu_head rcu; |
| 38 | struct hlist_head vni_list[VNI_HASH_SIZE]; |
| 39 | atomic_t refcnt; |
Or Gerlitz | dc01e7d | 2014-01-20 13:59:21 +0200 | [diff] [blame] | 40 | struct udp_offload udp_offloads; |
Pravin B Shelar | 012a572 | 2013-08-19 11:23:07 -0700 | [diff] [blame] | 41 | }; |
| 42 | |
Tom Herbert | 359a0ea | 2014-06-04 17:20:29 -0700 | [diff] [blame] | 43 | #define VXLAN_F_LEARN 0x01 |
| 44 | #define VXLAN_F_PROXY 0x02 |
| 45 | #define VXLAN_F_RSC 0x04 |
| 46 | #define VXLAN_F_L2MISS 0x08 |
| 47 | #define VXLAN_F_L3MISS 0x10 |
| 48 | #define VXLAN_F_IPV6 0x20 |
| 49 | #define VXLAN_F_UDP_CSUM 0x40 |
| 50 | #define VXLAN_F_UDP_ZERO_CSUM6_TX 0x80 |
| 51 | #define VXLAN_F_UDP_ZERO_CSUM6_RX 0x100 |
| 52 | |
Pravin B Shelar | 012a572 | 2013-08-19 11:23:07 -0700 | [diff] [blame] | 53 | struct vxlan_sock *vxlan_sock_add(struct net *net, __be16 port, |
| 54 | vxlan_rcv_t *rcv, void *data, |
Tom Herbert | 359a0ea | 2014-06-04 17:20:29 -0700 | [diff] [blame] | 55 | bool no_share, u32 flags); |
Pravin B Shelar | 012a572 | 2013-08-19 11:23:07 -0700 | [diff] [blame] | 56 | |
| 57 | void vxlan_sock_release(struct vxlan_sock *vs); |
Pravin B Shelar | 4956053 | 2013-08-19 11:23:17 -0700 | [diff] [blame] | 58 | |
Nicolas Dichtel | 1179618 | 2013-09-02 15:34:55 +0200 | [diff] [blame] | 59 | int vxlan_xmit_skb(struct vxlan_sock *vs, |
Pravin B Shelar | 4956053 | 2013-08-19 11:23:17 -0700 | [diff] [blame] | 60 | struct rtable *rt, struct sk_buff *skb, |
| 61 | __be32 src, __be32 dst, __u8 tos, __u8 ttl, __be16 df, |
Nicolas Dichtel | f01ec1c | 2014-04-24 10:02:49 +0200 | [diff] [blame] | 62 | __be16 src_port, __be16 dst_port, __be32 vni, bool xnet); |
Pravin B Shelar | 4956053 | 2013-08-19 11:23:17 -0700 | [diff] [blame] | 63 | |
Jesse Gross | 5f35227 | 2014-12-23 22:37:26 -0800 | [diff] [blame] | 64 | static inline netdev_features_t vxlan_features_check(struct sk_buff *skb, |
| 65 | netdev_features_t features) |
Joe Stringer | 11bf782 | 2014-11-17 16:24:54 -0800 | [diff] [blame] | 66 | { |
Jesse Gross | 5f35227 | 2014-12-23 22:37:26 -0800 | [diff] [blame] | 67 | u8 l4_hdr = 0; |
| 68 | |
| 69 | if (!skb->encapsulation) |
| 70 | return features; |
| 71 | |
| 72 | switch (vlan_get_protocol(skb)) { |
| 73 | case htons(ETH_P_IP): |
| 74 | l4_hdr = ip_hdr(skb)->protocol; |
| 75 | break; |
| 76 | case htons(ETH_P_IPV6): |
| 77 | l4_hdr = ipv6_hdr(skb)->nexthdr; |
| 78 | break; |
| 79 | default: |
| 80 | return features;; |
| 81 | } |
| 82 | |
| 83 | if ((l4_hdr == IPPROTO_UDP) && |
Joe Stringer | 11bf782 | 2014-11-17 16:24:54 -0800 | [diff] [blame] | 84 | (skb->inner_protocol_type != ENCAP_TYPE_ETHER || |
| 85 | skb->inner_protocol != htons(ETH_P_TEB) || |
| 86 | (skb_inner_mac_header(skb) - skb_transport_header(skb) != |
| 87 | sizeof(struct udphdr) + sizeof(struct vxlanhdr)))) |
Jesse Gross | 5f35227 | 2014-12-23 22:37:26 -0800 | [diff] [blame] | 88 | return features & ~(NETIF_F_ALL_CSUM | NETIF_F_GSO_MASK); |
Joe Stringer | 11bf782 | 2014-11-17 16:24:54 -0800 | [diff] [blame] | 89 | |
Jesse Gross | 5f35227 | 2014-12-23 22:37:26 -0800 | [diff] [blame] | 90 | return features; |
Joe Stringer | 11bf782 | 2014-11-17 16:24:54 -0800 | [diff] [blame] | 91 | } |
Joe Stringer | 23e62de | 2014-11-13 16:38:12 -0800 | [diff] [blame] | 92 | |
Joseph Gasparakis | e6cd988 | 2013-10-24 06:27:10 +0000 | [diff] [blame] | 93 | /* IP header + UDP + VXLAN + Ethernet header */ |
| 94 | #define VXLAN_HEADROOM (20 + 8 + 8 + 14) |
| 95 | /* IPv6 header + UDP + VXLAN + Ethernet header */ |
| 96 | #define VXLAN6_HEADROOM (40 + 8 + 8 + 14) |
| 97 | |
| 98 | #if IS_ENABLED(CONFIG_VXLAN) |
Joseph Gasparakis | 53cf5275 | 2013-09-04 02:13:38 -0700 | [diff] [blame] | 99 | void vxlan_get_rx_port(struct net_device *netdev); |
Joseph Gasparakis | e6cd988 | 2013-10-24 06:27:10 +0000 | [diff] [blame] | 100 | #else |
| 101 | static inline void vxlan_get_rx_port(struct net_device *netdev) |
| 102 | { |
| 103 | } |
| 104 | #endif |
Pravin B Shelar | 012a572 | 2013-08-19 11:23:07 -0700 | [diff] [blame] | 105 | #endif |