hc
2024-01-31 f9004dbfff8a3fbbd7e2a88c8a4327c7f2f8e5b2
kernel/include/net/vxlan.h
....@@ -5,7 +5,11 @@
55 #include <linux/if_vlan.h>
66 #include <net/udp_tunnel.h>
77 #include <net/dst_metadata.h>
8
-#include <net/udp_tunnel.h>
8
+#include <net/rtnetlink.h>
9
+#include <net/switchdev.h>
10
+#include <net/nexthop.h>
11
+
12
+#define IANA_VXLAN_UDP_PORT 4789
913
1014 /* VXLAN protocol (RFC 7348) header:
1115 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
....@@ -117,6 +121,9 @@
117121 #define VXLAN_GBP_POLICY_APPLIED (BIT(3) << 16)
118122 #define VXLAN_GBP_ID_MASK (0xFFFF)
119123
124
+#define VXLAN_GBP_MASK (VXLAN_GBP_DONT_LEARN | VXLAN_GBP_POLICY_APPLIED | \
125
+ VXLAN_GBP_ID_MASK)
126
+
120127 /*
121128 * VXLAN Generic Protocol Extension (VXLAN_F_GPE):
122129 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
....@@ -191,8 +198,10 @@
191198 struct vxlan_rdst {
192199 union vxlan_addr remote_ip;
193200 __be16 remote_port;
201
+ u8 offloaded:1;
194202 __be32 remote_vni;
195203 u32 remote_ifindex;
204
+ struct net_device *remote_dev;
196205 struct list_head list;
197206 struct rcu_head rcu;
198207 struct dst_cache dst_cache;
....@@ -214,6 +223,7 @@
214223 unsigned long age_interval;
215224 unsigned int addrmax;
216225 bool no_share;
226
+ enum ifla_vxlan_df df;
217227 };
218228
219229 struct vxlan_dev_node {
....@@ -237,7 +247,7 @@
237247 struct vxlan_rdst default_dst; /* default destination */
238248
239249 struct timer_list age_timer;
240
- spinlock_t hash_lock;
250
+ spinlock_t hash_lock[FDB_HASH_SIZE];
241251 unsigned int addrcnt;
242252 struct gro_cells gro_cells;
243253
....@@ -317,10 +327,15 @@
317327 return features;
318328 }
319329
320
-/* IP header + UDP + VXLAN + Ethernet header */
321
-#define VXLAN_HEADROOM (20 + 8 + 8 + 14)
322
-/* IPv6 header + UDP + VXLAN + Ethernet header */
323
-#define VXLAN6_HEADROOM (40 + 8 + 8 + 14)
330
+static inline int vxlan_headroom(u32 flags)
331
+{
332
+ /* VXLAN: IP4/6 header + UDP + VXLAN + Ethernet header */
333
+ /* VXLAN-GPE: IP4/6 header + UDP + VXLAN */
334
+ return (flags & VXLAN_F_IPV6 ? sizeof(struct ipv6hdr) :
335
+ sizeof(struct iphdr)) +
336
+ sizeof(struct udphdr) + sizeof(struct vxlanhdr) +
337
+ (flags & VXLAN_F_GPE ? 0 : ETH_HLEN);
338
+}
324339
325340 static inline struct vxlanhdr *vxlan_hdr(struct sk_buff *skb)
326341 {
....@@ -371,4 +386,138 @@
371386 return vs->sock->sk->sk_family;
372387 }
373388
389
+#if IS_ENABLED(CONFIG_IPV6)
390
+
391
+static inline bool vxlan_addr_any(const union vxlan_addr *ipa)
392
+{
393
+ if (ipa->sa.sa_family == AF_INET6)
394
+ return ipv6_addr_any(&ipa->sin6.sin6_addr);
395
+ else
396
+ return ipa->sin.sin_addr.s_addr == htonl(INADDR_ANY);
397
+}
398
+
399
+static inline bool vxlan_addr_multicast(const union vxlan_addr *ipa)
400
+{
401
+ if (ipa->sa.sa_family == AF_INET6)
402
+ return ipv6_addr_is_multicast(&ipa->sin6.sin6_addr);
403
+ else
404
+ return ipv4_is_multicast(ipa->sin.sin_addr.s_addr);
405
+}
406
+
407
+#else /* !IS_ENABLED(CONFIG_IPV6) */
408
+
409
+static inline bool vxlan_addr_any(const union vxlan_addr *ipa)
410
+{
411
+ return ipa->sin.sin_addr.s_addr == htonl(INADDR_ANY);
412
+}
413
+
414
+static inline bool vxlan_addr_multicast(const union vxlan_addr *ipa)
415
+{
416
+ return ipv4_is_multicast(ipa->sin.sin_addr.s_addr);
417
+}
418
+
419
+#endif /* IS_ENABLED(CONFIG_IPV6) */
420
+
421
+static inline bool netif_is_vxlan(const struct net_device *dev)
422
+{
423
+ return dev->rtnl_link_ops &&
424
+ !strcmp(dev->rtnl_link_ops->kind, "vxlan");
425
+}
426
+
427
+struct switchdev_notifier_vxlan_fdb_info {
428
+ struct switchdev_notifier_info info; /* must be first */
429
+ union vxlan_addr remote_ip;
430
+ __be16 remote_port;
431
+ __be32 remote_vni;
432
+ u32 remote_ifindex;
433
+ u8 eth_addr[ETH_ALEN];
434
+ __be32 vni;
435
+ bool offloaded;
436
+ bool added_by_user;
437
+};
438
+
439
+#if IS_ENABLED(CONFIG_VXLAN)
440
+int vxlan_fdb_find_uc(struct net_device *dev, const u8 *mac, __be32 vni,
441
+ struct switchdev_notifier_vxlan_fdb_info *fdb_info);
442
+int vxlan_fdb_replay(const struct net_device *dev, __be32 vni,
443
+ struct notifier_block *nb,
444
+ struct netlink_ext_ack *extack);
445
+void vxlan_fdb_clear_offload(const struct net_device *dev, __be32 vni);
446
+
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
+
455
+static inline int vxlan_fdb_replay(const struct net_device *dev, __be32 vni,
456
+ struct notifier_block *nb,
457
+ struct netlink_ext_ack *extack)
458
+{
459
+ return -EOPNOTSUPP;
460
+}
461
+
462
+static inline void
463
+vxlan_fdb_clear_offload(const struct net_device *dev, __be32 vni)
464
+{
465
+}
466
+#endif
467
+
468
+static inline void vxlan_flag_attr_error(int attrtype,
469
+ struct netlink_ext_ack *extack)
470
+{
471
+#define VXLAN_FLAG(flg) \
472
+ case IFLA_VXLAN_##flg: \
473
+ NL_SET_ERR_MSG_MOD(extack, \
474
+ "cannot change " #flg " flag"); \
475
+ break
476
+ switch (attrtype) {
477
+ VXLAN_FLAG(TTL_INHERIT);
478
+ VXLAN_FLAG(LEARNING);
479
+ VXLAN_FLAG(PROXY);
480
+ VXLAN_FLAG(RSC);
481
+ VXLAN_FLAG(L2MISS);
482
+ VXLAN_FLAG(L3MISS);
483
+ VXLAN_FLAG(COLLECT_METADATA);
484
+ VXLAN_FLAG(UDP_ZERO_CSUM6_TX);
485
+ VXLAN_FLAG(UDP_ZERO_CSUM6_RX);
486
+ VXLAN_FLAG(REMCSUM_TX);
487
+ VXLAN_FLAG(REMCSUM_RX);
488
+ VXLAN_FLAG(GBP);
489
+ VXLAN_FLAG(GPE);
490
+ VXLAN_FLAG(REMCSUM_NOPARTIAL);
491
+ default:
492
+ NL_SET_ERR_MSG_MOD(extack, \
493
+ "cannot change flag");
494
+ break;
495
+ }
496
+#undef VXLAN_FLAG
497
+}
498
+
499
+static inline bool vxlan_fdb_nh_path_select(struct nexthop *nh,
500
+ u32 hash,
501
+ struct vxlan_rdst *rdst)
502
+{
503
+ struct fib_nh_common *nhc;
504
+
505
+ nhc = nexthop_path_fdb_result(nh, hash >> 1);
506
+ if (unlikely(!nhc))
507
+ return false;
508
+
509
+ switch (nhc->nhc_gw_family) {
510
+ case AF_INET:
511
+ rdst->remote_ip.sin.sin_addr.s_addr = nhc->nhc_gw.ipv4;
512
+ rdst->remote_ip.sa.sa_family = AF_INET;
513
+ break;
514
+ case AF_INET6:
515
+ rdst->remote_ip.sin6.sin6_addr = nhc->nhc_gw.ipv6;
516
+ rdst->remote_ip.sa.sa_family = AF_INET6;
517
+ break;
518
+ }
519
+
520
+ return true;
521
+}
522
+
374523 #endif