if_vxlan.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /*-
  2. * Copyright (c) 2014, Bryan Venteicher <bryanv@FreeBSD.org>
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions
  7. * are met:
  8. * 1. Redistributions of source code must retain the above copyright
  9. * notice unmodified, this list of conditions, and the following
  10. * disclaimer.
  11. * 2. Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. *
  15. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  16. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  17. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  18. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  19. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  20. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  21. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  22. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  23. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  24. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. */
  26. #ifndef _NET_IF_VXLAN_H_
  27. #define _NET_IF_VXLAN_H_
  28. #include <sys/types.h>
  29. #include <sys/socket.h>
  30. #include <net/ethernet.h>
  31. #include <net/if.h>
  32. #include <netinet/in.h>
  33. struct vxlan_header {
  34. uint32_t vxlh_flags;
  35. uint32_t vxlh_vni;
  36. };
  37. #define VXLAN_HDR_FLAGS_VALID_VNI 0x08000000
  38. #define VXLAN_HDR_VNI_SHIFT 8
  39. #define VXLAN_VNI_MAX (1 << 24)
  40. #define VXLAN_VNI_MASK (VXLAN_VNI_MAX - 1)
  41. /*
  42. * The port assigned by IANA is 4789, but some early implementations
  43. * (like Linux) use 8472 instead. If not specified, we default to
  44. * the IANA port.
  45. */
  46. #define VXLAN_PORT 4789
  47. #define VXLAN_LEGACY_PORT 8472
  48. union vxlan_sockaddr {
  49. struct sockaddr sa;
  50. struct sockaddr_in in4;
  51. struct sockaddr_in6 in6;
  52. };
  53. struct ifvxlanparam {
  54. uint64_t vxlp_with;
  55. #define VXLAN_PARAM_WITH_VNI 0x0001
  56. #define VXLAN_PARAM_WITH_LOCAL_ADDR4 0x0002
  57. #define VXLAN_PARAM_WITH_LOCAL_ADDR6 0x0004
  58. #define VXLAN_PARAM_WITH_REMOTE_ADDR4 0x0008
  59. #define VXLAN_PARAM_WITH_REMOTE_ADDR6 0x0010
  60. #define VXLAN_PARAM_WITH_LOCAL_PORT 0x0020
  61. #define VXLAN_PARAM_WITH_REMOTE_PORT 0x0040
  62. #define VXLAN_PARAM_WITH_PORT_RANGE 0x0080
  63. #define VXLAN_PARAM_WITH_FTABLE_TIMEOUT 0x0100
  64. #define VXLAN_PARAM_WITH_FTABLE_MAX 0x0200
  65. #define VXLAN_PARAM_WITH_MULTICAST_IF 0x0400
  66. #define VXLAN_PARAM_WITH_TTL 0x0800
  67. #define VXLAN_PARAM_WITH_LEARN 0x1000
  68. uint32_t vxlp_vni;
  69. union vxlan_sockaddr vxlp_local_sa;
  70. union vxlan_sockaddr vxlp_remote_sa;
  71. uint16_t vxlp_local_port;
  72. uint16_t vxlp_remote_port;
  73. uint16_t vxlp_min_port;
  74. uint16_t vxlp_max_port;
  75. char vxlp_mc_ifname[IFNAMSIZ];
  76. uint32_t vxlp_ftable_timeout;
  77. uint32_t vxlp_ftable_max;
  78. uint8_t vxlp_ttl;
  79. uint8_t vxlp_learn;
  80. };
  81. #define VXLAN_SOCKADDR_IS_IPV4(_vxsin) ((_vxsin)->sa.sa_family == AF_INET)
  82. #define VXLAN_SOCKADDR_IS_IPV6(_vxsin) ((_vxsin)->sa.sa_family == AF_INET6)
  83. #define VXLAN_SOCKADDR_IS_IPV46(_vxsin) \
  84. (VXLAN_SOCKADDR_IS_IPV4(_vxsin) || VXLAN_SOCKADDR_IS_IPV6(_vxsin))
  85. #define VXLAN_CMD_GET_CONFIG 0
  86. #define VXLAN_CMD_SET_VNI 1
  87. #define VXLAN_CMD_SET_LOCAL_ADDR 2
  88. #define VXLAN_CMD_SET_REMOTE_ADDR 4
  89. #define VXLAN_CMD_SET_LOCAL_PORT 5
  90. #define VXLAN_CMD_SET_REMOTE_PORT 6
  91. #define VXLAN_CMD_SET_PORT_RANGE 7
  92. #define VXLAN_CMD_SET_FTABLE_TIMEOUT 8
  93. #define VXLAN_CMD_SET_FTABLE_MAX 9
  94. #define VXLAN_CMD_SET_MULTICAST_IF 10
  95. #define VXLAN_CMD_SET_TTL 11
  96. #define VXLAN_CMD_SET_LEARN 12
  97. #define VXLAN_CMD_FTABLE_ENTRY_ADD 13
  98. #define VXLAN_CMD_FTABLE_ENTRY_REM 14
  99. #define VXLAN_CMD_FLUSH 15
  100. struct ifvxlancfg {
  101. uint32_t vxlc_vni;
  102. union vxlan_sockaddr vxlc_local_sa;
  103. union vxlan_sockaddr vxlc_remote_sa;
  104. uint32_t vxlc_mc_ifindex;
  105. uint32_t vxlc_ftable_cnt;
  106. uint32_t vxlc_ftable_max;
  107. uint32_t vxlc_ftable_timeout;
  108. uint16_t vxlc_port_min;
  109. uint16_t vxlc_port_max;
  110. uint8_t vxlc_learn;
  111. uint8_t vxlc_ttl;
  112. };
  113. struct ifvxlancmd {
  114. uint32_t vxlcmd_flags;
  115. #define VXLAN_CMD_FLAG_FLUSH_ALL 0x0001
  116. #define VXLAN_CMD_FLAG_LEARN 0x0002
  117. uint32_t vxlcmd_vni;
  118. uint32_t vxlcmd_ftable_timeout;
  119. uint32_t vxlcmd_ftable_max;
  120. uint16_t vxlcmd_port;
  121. uint16_t vxlcmd_port_min;
  122. uint16_t vxlcmd_port_max;
  123. uint8_t vxlcmd_mac[ETHER_ADDR_LEN];
  124. uint8_t vxlcmd_ttl;
  125. union vxlan_sockaddr vxlcmd_sa;
  126. char vxlcmd_ifname[IFNAMSIZ];
  127. };
  128. #ifdef _KERNEL
  129. typedef void (*vxlan_event_handler_t)(void *, struct ifnet *, sa_family_t,
  130. u_int);
  131. EVENTHANDLER_DECLARE(vxlan_start, vxlan_event_handler_t);
  132. EVENTHANDLER_DECLARE(vxlan_stop, vxlan_event_handler_t);
  133. #endif
  134. #endif /* _NET_IF_VXLAN_H_ */