vxlan.h 2.4 KB

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