vxlan.h 15 KB

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