vxlan.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef __NET_VXLAN_H
  3. #define __NET_VXLAN_H 1
  4. #include <linux/if_vlan.h>
  5. #include <linux/rhashtable-types.h>
  6. #include <net/udp_tunnel.h>
  7. #include <net/dst_metadata.h>
  8. #include <net/rtnetlink.h>
  9. #include <net/switchdev.h>
  10. #include <net/nexthop.h>
  11. #define IANA_VXLAN_UDP_PORT 4789
  12. #define IANA_VXLAN_GPE_UDP_PORT 4790
  13. /* VXLAN protocol (RFC 7348) header:
  14. * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  15. * |R|R|R|R|I|R|R|R| Reserved |
  16. * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  17. * | VXLAN Network Identifier (VNI) | Reserved |
  18. * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  19. *
  20. * I = VXLAN Network Identifier (VNI) present.
  21. */
  22. struct vxlanhdr {
  23. __be32 vx_flags;
  24. __be32 vx_vni;
  25. };
  26. /* VXLAN header flags. */
  27. #define VXLAN_HF_VNI cpu_to_be32(BIT(27))
  28. #define VXLAN_N_VID (1u << 24)
  29. #define VXLAN_VID_MASK (VXLAN_N_VID - 1)
  30. #define VXLAN_VNI_MASK cpu_to_be32(VXLAN_VID_MASK << 8)
  31. #define VXLAN_HLEN (sizeof(struct udphdr) + sizeof(struct vxlanhdr))
  32. #define VNI_HASH_BITS 10
  33. #define VNI_HASH_SIZE (1<<VNI_HASH_BITS)
  34. #define FDB_HASH_BITS 8
  35. #define FDB_HASH_SIZE (1<<FDB_HASH_BITS)
  36. /* Remote checksum offload for VXLAN (VXLAN_F_REMCSUM_[RT]X):
  37. * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  38. * |R|R|R|R|I|R|R|R|R|R|C| Reserved |
  39. * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  40. * | VXLAN Network Identifier (VNI) |O| Csum start |
  41. * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  42. *
  43. * C = Remote checksum offload bit. When set indicates that the
  44. * remote checksum offload data is present.
  45. *
  46. * O = Offset bit. Indicates the checksum offset relative to
  47. * checksum start.
  48. *
  49. * Csum start = Checksum start divided by two.
  50. *
  51. * http://tools.ietf.org/html/draft-herbert-vxlan-rco
  52. */
  53. /* VXLAN-RCO header flags. */
  54. #define VXLAN_HF_RCO cpu_to_be32(BIT(21))
  55. /* Remote checksum offload header option */
  56. #define VXLAN_RCO_MASK cpu_to_be32(0x7f) /* Last byte of vni field */
  57. #define VXLAN_RCO_UDP cpu_to_be32(0x80) /* Indicate UDP RCO (TCP when not set *) */
  58. #define VXLAN_RCO_SHIFT 1 /* Left shift of start */
  59. #define VXLAN_RCO_SHIFT_MASK ((1 << VXLAN_RCO_SHIFT) - 1)
  60. #define VXLAN_MAX_REMCSUM_START (0x7f << VXLAN_RCO_SHIFT)
  61. /*
  62. * VXLAN Group Based Policy Extension (VXLAN_F_GBP):
  63. * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  64. * |G|R|R|R|I|R|R|R|R|D|R|R|A|R|R|R| Group Policy ID |
  65. * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  66. * | VXLAN Network Identifier (VNI) | Reserved |
  67. * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  68. *
  69. * G = Group Policy ID present.
  70. *
  71. * D = Don't Learn bit. When set, this bit indicates that the egress
  72. * VTEP MUST NOT learn the source address of the encapsulated frame.
  73. *
  74. * A = Indicates that the group policy has already been applied to
  75. * this packet. Policies MUST NOT be applied by devices when the
  76. * A bit is set.
  77. *
  78. * https://tools.ietf.org/html/draft-smith-vxlan-group-policy
  79. */
  80. struct vxlanhdr_gbp {
  81. u8 vx_flags;
  82. #ifdef __LITTLE_ENDIAN_BITFIELD
  83. u8 reserved_flags1:3,
  84. policy_applied:1,
  85. reserved_flags2:2,
  86. dont_learn:1,
  87. reserved_flags3:1;
  88. #elif defined(__BIG_ENDIAN_BITFIELD)
  89. u8 reserved_flags1:1,
  90. dont_learn:1,
  91. reserved_flags2:2,
  92. policy_applied:1,
  93. reserved_flags3:3;
  94. #else
  95. #error "Please fix <asm/byteorder.h>"
  96. #endif
  97. __be16 policy_id;
  98. __be32 vx_vni;
  99. };
  100. /* VXLAN-GBP header flags. */
  101. #define VXLAN_HF_GBP cpu_to_be32(BIT(31))
  102. #define VXLAN_GBP_USED_BITS (VXLAN_HF_GBP | cpu_to_be32(0xFFFFFF))
  103. /* skb->mark mapping
  104. *
  105. * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  106. * |R|R|R|R|R|R|R|R|R|D|R|R|A|R|R|R| Group Policy ID |
  107. * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  108. */
  109. #define VXLAN_GBP_DONT_LEARN (BIT(6) << 16)
  110. #define VXLAN_GBP_POLICY_APPLIED (BIT(3) << 16)
  111. #define VXLAN_GBP_ID_MASK (0xFFFF)
  112. #define VXLAN_GBP_MASK (VXLAN_GBP_DONT_LEARN | VXLAN_GBP_POLICY_APPLIED | \
  113. VXLAN_GBP_ID_MASK)
  114. /*
  115. * VXLAN Generic Protocol Extension (VXLAN_F_GPE):
  116. * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  117. * |R|R|Ver|I|P|R|O| Reserved |Next Protocol |
  118. * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  119. * | VXLAN Network Identifier (VNI) | Reserved |
  120. * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  121. *
  122. * Ver = Version. Indicates VXLAN GPE protocol version.
  123. *
  124. * P = Next Protocol Bit. The P bit is set to indicate that the
  125. * Next Protocol field is present.
  126. *
  127. * O = OAM Flag Bit. The O bit is set to indicate that the packet
  128. * is an OAM packet.
  129. *
  130. * Next Protocol = This 8 bit field indicates the protocol header
  131. * immediately following the VXLAN GPE header.
  132. *
  133. * https://tools.ietf.org/html/draft-ietf-nvo3-vxlan-gpe-01
  134. */
  135. struct vxlanhdr_gpe {
  136. #if defined(__LITTLE_ENDIAN_BITFIELD)
  137. u8 oam_flag:1,
  138. reserved_flags1:1,
  139. np_applied:1,
  140. instance_applied:1,
  141. version:2,
  142. reserved_flags2:2;
  143. #elif defined(__BIG_ENDIAN_BITFIELD)
  144. u8 reserved_flags2:2,
  145. version:2,
  146. instance_applied:1,
  147. np_applied:1,
  148. reserved_flags1:1,
  149. oam_flag:1;
  150. #endif
  151. u8 reserved_flags3;
  152. u8 reserved_flags4;
  153. u8 next_protocol;
  154. __be32 vx_vni;
  155. };
  156. /* VXLAN-GPE header flags. */
  157. #define VXLAN_HF_VER cpu_to_be32(BIT(29) | BIT(28))
  158. #define VXLAN_HF_NP cpu_to_be32(BIT(26))
  159. #define VXLAN_HF_OAM cpu_to_be32(BIT(24))
  160. #define VXLAN_GPE_USED_BITS (VXLAN_HF_VER | VXLAN_HF_NP | VXLAN_HF_OAM | \
  161. cpu_to_be32(0xff))
  162. struct vxlan_metadata {
  163. u32 gbp;
  164. };
  165. /* per UDP socket information */
  166. struct vxlan_sock {
  167. struct hlist_node hlist;
  168. struct socket *sock;
  169. struct hlist_head vni_list[VNI_HASH_SIZE];
  170. refcount_t refcnt;
  171. u32 flags;
  172. };
  173. union vxlan_addr {
  174. struct sockaddr_in sin;
  175. struct sockaddr_in6 sin6;
  176. struct sockaddr sa;
  177. };
  178. struct vxlan_rdst {
  179. union vxlan_addr remote_ip;
  180. __be16 remote_port;
  181. u8 offloaded:1;
  182. __be32 remote_vni;
  183. u32 remote_ifindex;
  184. struct net_device *remote_dev;
  185. struct list_head list;
  186. struct rcu_head rcu;
  187. struct dst_cache dst_cache;
  188. };
  189. struct vxlan_config {
  190. union vxlan_addr remote_ip;
  191. union vxlan_addr saddr;
  192. __be32 vni;
  193. int remote_ifindex;
  194. int mtu;
  195. __be16 dst_port;
  196. u16 port_min;
  197. u16 port_max;
  198. u8 tos;
  199. u8 ttl;
  200. __be32 label;
  201. enum ifla_vxlan_label_policy label_policy;
  202. u32 flags;
  203. unsigned long age_interval;
  204. unsigned int addrmax;
  205. bool no_share;
  206. enum ifla_vxlan_df df;
  207. struct vxlanhdr reserved_bits;
  208. };
  209. enum {
  210. VXLAN_VNI_STATS_RX,
  211. VXLAN_VNI_STATS_RX_DROPS,
  212. VXLAN_VNI_STATS_RX_ERRORS,
  213. VXLAN_VNI_STATS_TX,
  214. VXLAN_VNI_STATS_TX_DROPS,
  215. VXLAN_VNI_STATS_TX_ERRORS,
  216. };
  217. struct vxlan_vni_stats {
  218. u64 rx_packets;
  219. u64 rx_bytes;
  220. u64 rx_drops;
  221. u64 rx_errors;
  222. u64 tx_packets;
  223. u64 tx_bytes;
  224. u64 tx_drops;
  225. u64 tx_errors;
  226. };
  227. struct vxlan_vni_stats_pcpu {
  228. struct vxlan_vni_stats stats;
  229. struct u64_stats_sync syncp;
  230. };
  231. struct vxlan_dev_node {
  232. struct hlist_node hlist;
  233. struct vxlan_dev *vxlan;
  234. };
  235. struct vxlan_vni_node {
  236. struct rhash_head vnode;
  237. struct vxlan_dev_node hlist4; /* vni hash table for IPv4 socket */
  238. #if IS_ENABLED(CONFIG_IPV6)
  239. struct vxlan_dev_node hlist6; /* vni hash table for IPv6 socket */
  240. #endif
  241. struct list_head vlist;
  242. __be32 vni;
  243. union vxlan_addr remote_ip; /* default remote ip for this vni */
  244. struct vxlan_vni_stats_pcpu __percpu *stats;
  245. struct rcu_head rcu;
  246. };
  247. struct vxlan_vni_group {
  248. struct rhashtable vni_hash;
  249. struct list_head vni_list;
  250. u32 num_vnis;
  251. };
  252. /* Pseudo network device */
  253. struct vxlan_dev {
  254. struct vxlan_dev_node hlist4; /* vni hash table for IPv4 socket */
  255. #if IS_ENABLED(CONFIG_IPV6)
  256. struct vxlan_dev_node hlist6; /* vni hash table for IPv6 socket */
  257. #endif
  258. struct list_head next; /* vxlan's per namespace list */
  259. struct vxlan_sock __rcu *vn4_sock; /* listening socket for IPv4 */
  260. #if IS_ENABLED(CONFIG_IPV6)
  261. struct vxlan_sock __rcu *vn6_sock; /* listening socket for IPv6 */
  262. #endif
  263. struct net_device *dev;
  264. struct net *net; /* netns for packet i/o */
  265. struct vxlan_rdst default_dst; /* default destination */
  266. struct timer_list age_timer;
  267. spinlock_t hash_lock;
  268. unsigned int addrcnt;
  269. struct gro_cells gro_cells;
  270. struct vxlan_config cfg;
  271. struct vxlan_vni_group __rcu *vnigrp;
  272. struct rhashtable fdb_hash_tbl;
  273. struct rhashtable mdb_tbl;
  274. struct hlist_head fdb_list;
  275. struct hlist_head mdb_list;
  276. unsigned int mdb_seq;
  277. };
  278. #define VXLAN_F_LEARN 0x01
  279. #define VXLAN_F_PROXY 0x02
  280. #define VXLAN_F_RSC 0x04
  281. #define VXLAN_F_L2MISS 0x08
  282. #define VXLAN_F_L3MISS 0x10
  283. #define VXLAN_F_IPV6 0x20
  284. #define VXLAN_F_UDP_ZERO_CSUM_TX 0x40
  285. #define VXLAN_F_UDP_ZERO_CSUM6_TX 0x80
  286. #define VXLAN_F_UDP_ZERO_CSUM6_RX 0x100
  287. #define VXLAN_F_REMCSUM_TX 0x200
  288. #define VXLAN_F_REMCSUM_RX 0x400
  289. #define VXLAN_F_GBP 0x800
  290. #define VXLAN_F_REMCSUM_NOPARTIAL 0x1000
  291. #define VXLAN_F_COLLECT_METADATA 0x2000
  292. #define VXLAN_F_GPE 0x4000
  293. #define VXLAN_F_IPV6_LINKLOCAL 0x8000
  294. #define VXLAN_F_TTL_INHERIT 0x10000
  295. #define VXLAN_F_VNIFILTER 0x20000
  296. #define VXLAN_F_MDB 0x40000
  297. #define VXLAN_F_LOCALBYPASS 0x80000
  298. #define VXLAN_F_MC_ROUTE 0x100000
  299. /* Flags that are used in the receive path. These flags must match in
  300. * order for a socket to be shareable
  301. */
  302. #define VXLAN_F_RCV_FLAGS (VXLAN_F_GBP | \
  303. VXLAN_F_GPE | \
  304. VXLAN_F_UDP_ZERO_CSUM6_RX | \
  305. VXLAN_F_REMCSUM_RX | \
  306. VXLAN_F_REMCSUM_NOPARTIAL | \
  307. VXLAN_F_COLLECT_METADATA | \
  308. VXLAN_F_VNIFILTER)
  309. /* Flags that can be set together with VXLAN_F_GPE. */
  310. #define VXLAN_F_ALLOWED_GPE (VXLAN_F_GPE | \
  311. VXLAN_F_IPV6 | \
  312. VXLAN_F_IPV6_LINKLOCAL | \
  313. VXLAN_F_UDP_ZERO_CSUM_TX | \
  314. VXLAN_F_UDP_ZERO_CSUM6_TX | \
  315. VXLAN_F_UDP_ZERO_CSUM6_RX | \
  316. VXLAN_F_COLLECT_METADATA | \
  317. VXLAN_F_VNIFILTER | \
  318. VXLAN_F_LOCALBYPASS | \
  319. VXLAN_F_MC_ROUTE | \
  320. 0)
  321. struct net_device *vxlan_dev_create(struct net *net, const char *name,
  322. u8 name_assign_type, struct vxlan_config *conf);
  323. static inline netdev_features_t vxlan_features_check(struct sk_buff *skb,
  324. netdev_features_t features)
  325. {
  326. u8 l4_hdr = 0;
  327. if (!skb->encapsulation)
  328. return features;
  329. switch (vlan_get_protocol(skb)) {
  330. case htons(ETH_P_IP):
  331. l4_hdr = ip_hdr(skb)->protocol;
  332. break;
  333. case htons(ETH_P_IPV6):
  334. l4_hdr = ipv6_hdr(skb)->nexthdr;
  335. break;
  336. default:
  337. return features;
  338. }
  339. if ((l4_hdr == IPPROTO_UDP) &&
  340. (skb->inner_protocol_type != ENCAP_TYPE_ETHER ||
  341. skb->inner_protocol != htons(ETH_P_TEB) ||
  342. (skb_inner_mac_header(skb) - skb_transport_header(skb) !=
  343. sizeof(struct udphdr) + sizeof(struct vxlanhdr)) ||
  344. (skb->ip_summed != CHECKSUM_NONE &&
  345. !can_checksum_protocol(features, inner_eth_hdr(skb)->h_proto))))
  346. return features & ~(NETIF_F_CSUM_MASK | NETIF_F_GSO_MASK);
  347. return features;
  348. }
  349. static inline int vxlan_headroom(u32 flags)
  350. {
  351. /* VXLAN: IP4/6 header + UDP + VXLAN + Ethernet header */
  352. /* VXLAN-GPE: IP4/6 header + UDP + VXLAN */
  353. return (flags & VXLAN_F_IPV6 ? sizeof(struct ipv6hdr) :
  354. sizeof(struct iphdr)) +
  355. sizeof(struct udphdr) + sizeof(struct vxlanhdr) +
  356. (flags & VXLAN_F_GPE ? 0 : ETH_HLEN);
  357. }
  358. static inline struct vxlanhdr *vxlan_hdr(struct sk_buff *skb)
  359. {
  360. return (struct vxlanhdr *)(udp_hdr(skb) + 1);
  361. }
  362. static inline __be32 vxlan_vni(__be32 vni_field)
  363. {
  364. #if defined(__BIG_ENDIAN)
  365. return (__force __be32)((__force u32)vni_field >> 8);
  366. #else
  367. return (__force __be32)((__force u32)(vni_field & VXLAN_VNI_MASK) << 8);
  368. #endif
  369. }
  370. static inline __be32 vxlan_vni_field(__be32 vni)
  371. {
  372. #if defined(__BIG_ENDIAN)
  373. return (__force __be32)((__force u32)vni << 8);
  374. #else
  375. return (__force __be32)((__force u32)vni >> 8);
  376. #endif
  377. }
  378. static inline size_t vxlan_rco_start(__be32 vni_field)
  379. {
  380. return be32_to_cpu(vni_field & VXLAN_RCO_MASK) << VXLAN_RCO_SHIFT;
  381. }
  382. static inline size_t vxlan_rco_offset(__be32 vni_field)
  383. {
  384. return (vni_field & VXLAN_RCO_UDP) ?
  385. offsetof(struct udphdr, check) :
  386. offsetof(struct tcphdr, check);
  387. }
  388. static inline __be32 vxlan_compute_rco(unsigned int start, unsigned int offset)
  389. {
  390. __be32 vni_field = cpu_to_be32(start >> VXLAN_RCO_SHIFT);
  391. if (offset == offsetof(struct udphdr, check))
  392. vni_field |= VXLAN_RCO_UDP;
  393. return vni_field;
  394. }
  395. static inline unsigned short vxlan_get_sk_family(struct vxlan_sock *vs)
  396. {
  397. return vs->sock->sk->sk_family;
  398. }
  399. #if IS_ENABLED(CONFIG_IPV6)
  400. static inline bool vxlan_addr_any(const union vxlan_addr *ipa)
  401. {
  402. if (ipa->sa.sa_family == AF_INET6)
  403. return ipv6_addr_any(&ipa->sin6.sin6_addr);
  404. else
  405. return ipa->sin.sin_addr.s_addr == htonl(INADDR_ANY);
  406. }
  407. static inline bool vxlan_addr_multicast(const union vxlan_addr *ipa)
  408. {
  409. if (ipa->sa.sa_family == AF_INET6)
  410. return ipv6_addr_is_multicast(&ipa->sin6.sin6_addr);
  411. else
  412. return ipv4_is_multicast(ipa->sin.sin_addr.s_addr);
  413. }
  414. #else /* !IS_ENABLED(CONFIG_IPV6) */
  415. static inline bool vxlan_addr_any(const union vxlan_addr *ipa)
  416. {
  417. return ipa->sin.sin_addr.s_addr == htonl(INADDR_ANY);
  418. }
  419. static inline bool vxlan_addr_multicast(const union vxlan_addr *ipa)
  420. {
  421. return ipv4_is_multicast(ipa->sin.sin_addr.s_addr);
  422. }
  423. #endif /* IS_ENABLED(CONFIG_IPV6) */
  424. static inline bool netif_is_vxlan(const struct net_device *dev)
  425. {
  426. return dev->rtnl_link_ops &&
  427. !strcmp(dev->rtnl_link_ops->kind, "vxlan");
  428. }
  429. struct switchdev_notifier_vxlan_fdb_info {
  430. struct switchdev_notifier_info info; /* must be first */
  431. union vxlan_addr remote_ip;
  432. __be16 remote_port;
  433. __be32 remote_vni;
  434. u32 remote_ifindex;
  435. u8 eth_addr[ETH_ALEN];
  436. __be32 vni;
  437. bool offloaded;
  438. bool added_by_user;
  439. };
  440. #if IS_ENABLED(CONFIG_VXLAN)
  441. int vxlan_fdb_find_uc(struct net_device *dev, const u8 *mac, __be32 vni,
  442. struct switchdev_notifier_vxlan_fdb_info *fdb_info);
  443. int vxlan_fdb_replay(const struct net_device *dev, __be32 vni,
  444. struct notifier_block *nb,
  445. struct netlink_ext_ack *extack);
  446. void vxlan_fdb_clear_offload(const struct net_device *dev, __be32 vni);
  447. #else
  448. static inline int
  449. vxlan_fdb_find_uc(struct net_device *dev, const u8 *mac, __be32 vni,
  450. struct switchdev_notifier_vxlan_fdb_info *fdb_info)
  451. {
  452. return -ENOENT;
  453. }
  454. static inline int vxlan_fdb_replay(const struct net_device *dev, __be32 vni,
  455. struct notifier_block *nb,
  456. struct netlink_ext_ack *extack)
  457. {
  458. return -EOPNOTSUPP;
  459. }
  460. static inline void
  461. vxlan_fdb_clear_offload(const struct net_device *dev, __be32 vni)
  462. {
  463. }
  464. #endif
  465. static inline void vxlan_flag_attr_error(int attrtype,
  466. struct netlink_ext_ack *extack)
  467. {
  468. #define VXLAN_FLAG(flg) \
  469. case IFLA_VXLAN_##flg: \
  470. NL_SET_ERR_MSG_MOD(extack, \
  471. "cannot change " #flg " flag"); \
  472. break
  473. switch (attrtype) {
  474. VXLAN_FLAG(TTL_INHERIT);
  475. VXLAN_FLAG(LEARNING);
  476. VXLAN_FLAG(PROXY);
  477. VXLAN_FLAG(RSC);
  478. VXLAN_FLAG(L2MISS);
  479. VXLAN_FLAG(L3MISS);
  480. VXLAN_FLAG(COLLECT_METADATA);
  481. VXLAN_FLAG(UDP_ZERO_CSUM6_TX);
  482. VXLAN_FLAG(UDP_ZERO_CSUM6_RX);
  483. VXLAN_FLAG(REMCSUM_TX);
  484. VXLAN_FLAG(REMCSUM_RX);
  485. VXLAN_FLAG(GBP);
  486. VXLAN_FLAG(GPE);
  487. VXLAN_FLAG(REMCSUM_NOPARTIAL);
  488. default:
  489. NL_SET_ERR_MSG_MOD(extack, \
  490. "cannot change flag");
  491. break;
  492. }
  493. #undef VXLAN_FLAG
  494. }
  495. static inline bool vxlan_fdb_nh_path_select(struct nexthop *nh,
  496. u32 hash,
  497. struct vxlan_rdst *rdst)
  498. {
  499. struct fib_nh_common *nhc;
  500. nhc = nexthop_path_fdb_result(nh, hash >> 1);
  501. if (unlikely(!nhc))
  502. return false;
  503. switch (nhc->nhc_gw_family) {
  504. case AF_INET:
  505. rdst->remote_ip.sin.sin_addr.s_addr = nhc->nhc_gw.ipv4;
  506. rdst->remote_ip.sa.sa_family = AF_INET;
  507. break;
  508. case AF_INET6:
  509. rdst->remote_ip.sin6.sin6_addr = nhc->nhc_gw.ipv6;
  510. rdst->remote_ip.sa.sa_family = AF_INET6;
  511. break;
  512. }
  513. return true;
  514. }
  515. static inline void vxlan_build_gbp_hdr(struct vxlanhdr *vxh, const struct vxlan_metadata *md)
  516. {
  517. struct vxlanhdr_gbp *gbp;
  518. if (!md->gbp)
  519. return;
  520. gbp = (struct vxlanhdr_gbp *)vxh;
  521. vxh->vx_flags |= VXLAN_HF_GBP;
  522. if (md->gbp & VXLAN_GBP_DONT_LEARN)
  523. gbp->dont_learn = 1;
  524. if (md->gbp & VXLAN_GBP_POLICY_APPLIED)
  525. gbp->policy_applied = 1;
  526. gbp->policy_id = htons(md->gbp & VXLAN_GBP_ID_MASK);
  527. }
  528. #endif