forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-11 1f93a7dfd1f8d5ff7a5c53246c7534fe2332d6f4
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
....@@ -371,4 +381,138 @@
371381 return vs->sock->sk->sk_family;
372382 }
373383
384
+#if IS_ENABLED(CONFIG_IPV6)
385
+
386
+static inline bool vxlan_addr_any(const union vxlan_addr *ipa)
387
+{
388
+ if (ipa->sa.sa_family == AF_INET6)
389
+ return ipv6_addr_any(&ipa->sin6.sin6_addr);
390
+ else
391
+ return ipa->sin.sin_addr.s_addr == htonl(INADDR_ANY);
392
+}
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
+
402
+#else /* !IS_ENABLED(CONFIG_IPV6) */
403
+
404
+static inline bool vxlan_addr_any(const union vxlan_addr *ipa)
405
+{
406
+ return ipa->sin.sin_addr.s_addr == htonl(INADDR_ANY);
407
+}
408
+
409
+static inline bool vxlan_addr_multicast(const union vxlan_addr *ipa)
410
+{
411
+ return ipv4_is_multicast(ipa->sin.sin_addr.s_addr);
412
+}
413
+
414
+#endif /* IS_ENABLED(CONFIG_IPV6) */
415
+
416
+static inline bool netif_is_vxlan(const struct net_device *dev)
417
+{
418
+ return dev->rtnl_link_ops &&
419
+ !strcmp(dev->rtnl_link_ops->kind, "vxlan");
420
+}
421
+
422
+struct switchdev_notifier_vxlan_fdb_info {
423
+ struct switchdev_notifier_info info; /* must be first */
424
+ union vxlan_addr remote_ip;
425
+ __be16 remote_port;
426
+ __be32 remote_vni;
427
+ u32 remote_ifindex;
428
+ u8 eth_addr[ETH_ALEN];
429
+ __be32 vni;
430
+ bool offloaded;
431
+ bool added_by_user;
432
+};
433
+
434
+#if IS_ENABLED(CONFIG_VXLAN)
435
+int vxlan_fdb_find_uc(struct net_device *dev, const u8 *mac, __be32 vni,
436
+ struct switchdev_notifier_vxlan_fdb_info *fdb_info);
437
+int vxlan_fdb_replay(const struct net_device *dev, __be32 vni,
438
+ struct notifier_block *nb,
439
+ struct netlink_ext_ack *extack);
440
+void vxlan_fdb_clear_offload(const struct net_device *dev, __be32 vni);
441
+
442
+#else
443
+static inline int
444
+vxlan_fdb_find_uc(struct net_device *dev, const u8 *mac, __be32 vni,
445
+ struct switchdev_notifier_vxlan_fdb_info *fdb_info)
446
+{
447
+ return -ENOENT;
448
+}
449
+
450
+static inline int vxlan_fdb_replay(const struct net_device *dev, __be32 vni,
451
+ struct notifier_block *nb,
452
+ struct netlink_ext_ack *extack)
453
+{
454
+ return -EOPNOTSUPP;
455
+}
456
+
457
+static inline void
458
+vxlan_fdb_clear_offload(const struct net_device *dev, __be32 vni)
459
+{
460
+}
461
+#endif
462
+
463
+static inline void vxlan_flag_attr_error(int attrtype,
464
+ struct netlink_ext_ack *extack)
465
+{
466
+#define VXLAN_FLAG(flg) \
467
+ case IFLA_VXLAN_##flg: \
468
+ NL_SET_ERR_MSG_MOD(extack, \
469
+ "cannot change " #flg " flag"); \
470
+ break
471
+ switch (attrtype) {
472
+ VXLAN_FLAG(TTL_INHERIT);
473
+ VXLAN_FLAG(LEARNING);
474
+ VXLAN_FLAG(PROXY);
475
+ VXLAN_FLAG(RSC);
476
+ VXLAN_FLAG(L2MISS);
477
+ VXLAN_FLAG(L3MISS);
478
+ VXLAN_FLAG(COLLECT_METADATA);
479
+ VXLAN_FLAG(UDP_ZERO_CSUM6_TX);
480
+ VXLAN_FLAG(UDP_ZERO_CSUM6_RX);
481
+ VXLAN_FLAG(REMCSUM_TX);
482
+ VXLAN_FLAG(REMCSUM_RX);
483
+ VXLAN_FLAG(GBP);
484
+ VXLAN_FLAG(GPE);
485
+ VXLAN_FLAG(REMCSUM_NOPARTIAL);
486
+ default:
487
+ NL_SET_ERR_MSG_MOD(extack, \
488
+ "cannot change flag");
489
+ break;
490
+ }
491
+#undef VXLAN_FLAG
492
+}
493
+
494
+static inline bool vxlan_fdb_nh_path_select(struct nexthop *nh,
495
+ int hash,
496
+ struct vxlan_rdst *rdst)
497
+{
498
+ struct fib_nh_common *nhc;
499
+
500
+ nhc = nexthop_path_fdb_result(nh, hash);
501
+ if (unlikely(!nhc))
502
+ return false;
503
+
504
+ switch (nhc->nhc_gw_family) {
505
+ case AF_INET:
506
+ rdst->remote_ip.sin.sin_addr.s_addr = nhc->nhc_gw.ipv4;
507
+ rdst->remote_ip.sa.sa_family = AF_INET;
508
+ break;
509
+ case AF_INET6:
510
+ rdst->remote_ip.sin6.sin6_addr = nhc->nhc_gw.ipv6;
511
+ rdst->remote_ip.sa.sa_family = AF_INET6;
512
+ break;
513
+ }
514
+
515
+ return true;
516
+}
517
+
374518 #endif