vxlan.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #ifndef __NET_VXLAN_H
  2. #define __NET_VXLAN_H 1
  3. #include <linux/skbuff.h>
  4. #include <linux/netdevice.h>
  5. #include <linux/udp.h>
  6. #define VNI_HASH_BITS 10
  7. #define VNI_HASH_SIZE (1<<VNI_HASH_BITS)
  8. /* VXLAN protocol header */
  9. struct vxlanhdr {
  10. __be32 vx_flags;
  11. __be32 vx_vni;
  12. };
  13. struct vxlan_sock;
  14. typedef void (vxlan_rcv_t)(struct vxlan_sock *vh, struct sk_buff *skb, __be32 key);
  15. /* per UDP socket information */
  16. struct vxlan_sock {
  17. struct hlist_node hlist;
  18. vxlan_rcv_t *rcv;
  19. void *data;
  20. struct work_struct del_work;
  21. struct socket *sock;
  22. struct rcu_head rcu;
  23. struct hlist_head vni_list[VNI_HASH_SIZE];
  24. atomic_t refcnt;
  25. struct udp_offload udp_offloads;
  26. };
  27. #define VXLAN_F_LEARN 0x01
  28. #define VXLAN_F_PROXY 0x02
  29. #define VXLAN_F_RSC 0x04
  30. #define VXLAN_F_L2MISS 0x08
  31. #define VXLAN_F_L3MISS 0x10
  32. #define VXLAN_F_IPV6 0x20
  33. #define VXLAN_F_UDP_CSUM 0x40
  34. #define VXLAN_F_UDP_ZERO_CSUM6_TX 0x80
  35. #define VXLAN_F_UDP_ZERO_CSUM6_RX 0x100
  36. struct vxlan_sock *vxlan_sock_add(struct net *net, __be16 port,
  37. vxlan_rcv_t *rcv, void *data,
  38. bool no_share, u32 flags);
  39. void vxlan_sock_release(struct vxlan_sock *vs);
  40. int vxlan_xmit_skb(struct vxlan_sock *vs,
  41. struct rtable *rt, struct sk_buff *skb,
  42. __be32 src, __be32 dst, __u8 tos, __u8 ttl, __be16 df,
  43. __be16 src_port, __be16 dst_port, __be32 vni, bool xnet);
  44. static inline bool vxlan_gso_check(struct sk_buff *skb)
  45. {
  46. if ((skb_shinfo(skb)->gso_type & SKB_GSO_UDP_TUNNEL) &&
  47. (skb->inner_protocol_type != ENCAP_TYPE_ETHER ||
  48. skb->inner_protocol != htons(ETH_P_TEB) ||
  49. (skb_inner_mac_header(skb) - skb_transport_header(skb) !=
  50. sizeof(struct udphdr) + sizeof(struct vxlanhdr))))
  51. return false;
  52. return true;
  53. }
  54. /* IP header + UDP + VXLAN + Ethernet header */
  55. #define VXLAN_HEADROOM (20 + 8 + 8 + 14)
  56. /* IPv6 header + UDP + VXLAN + Ethernet header */
  57. #define VXLAN6_HEADROOM (40 + 8 + 8 + 14)
  58. #if IS_ENABLED(CONFIG_VXLAN)
  59. void vxlan_get_rx_port(struct net_device *netdev);
  60. #else
  61. static inline void vxlan_get_rx_port(struct net_device *netdev)
  62. {
  63. }
  64. #endif
  65. #endif