hc
2024-10-22 8ac6c7a54ed1b98d142dce24b11c6de6a1e239a5
kernel/net/bridge/br_private.h
....@@ -1,13 +1,9 @@
1
+/* SPDX-License-Identifier: GPL-2.0-or-later */
12 /*
23 * Linux ethernet bridge
34 *
45 * Authors:
56 * Lennert Buytenhek <buytenh@gnu.org>
6
- *
7
- * This program is free software; you can redistribute it and/or
8
- * modify it under the terms of the GNU General Public License
9
- * as published by the Free Software Foundation; either version
10
- * 2 of the License, or (at your option) any later version.
117 */
128
139 #ifndef _BR_PRIVATE_H
....@@ -31,6 +27,8 @@
3127 #define BR_PORT_BITS 10
3228 #define BR_MAX_PORTS (1<<BR_PORT_BITS)
3329
30
+#define BR_MULTICAST_DEFAULT_HASH_MAX 4096
31
+
3432 #define BR_VERSION "2.3"
3533
3634 /* Control of forwarding link local multicast */
....@@ -50,18 +48,18 @@
5048 /* Path to usermode spanning tree program */
5149 #define BR_STP_PROG "/sbin/bridge-stp"
5250
51
+#define BR_FDB_NOTIFY_SETTABLE_BITS (FDB_NOTIFY_BIT | FDB_NOTIFY_INACTIVE_BIT)
52
+
5353 typedef struct bridge_id bridge_id;
5454 typedef struct mac_addr mac_addr;
5555 typedef __u16 port_id;
5656
57
-struct bridge_id
58
-{
57
+struct bridge_id {
5958 unsigned char prio[2];
6059 unsigned char addr[ETH_ALEN];
6160 };
6261
63
-struct mac_addr
64
-{
62
+struct mac_addr {
6563 unsigned char addr[ETH_ALEN];
6664 };
6765
....@@ -104,12 +102,20 @@
104102 struct metadata_dst __rcu *tunnel_dst;
105103 };
106104
105
+/* private vlan flags */
106
+enum {
107
+ BR_VLFLAG_PER_PORT_STATS = BIT(0),
108
+ BR_VLFLAG_ADDED_BY_SWITCHDEV = BIT(1),
109
+};
110
+
107111 /**
108112 * struct net_bridge_vlan - per-vlan entry
109113 *
110114 * @vnode: rhashtable member
111115 * @vid: VLAN id
112116 * @flags: bridge vlan flags
117
+ * @priv_flags: private (in-kernel) bridge vlan flags
118
+ * @state: STP state (e.g. blocking, learning, forwarding)
113119 * @stats: per-cpu VLAN statistics
114120 * @br: if MASTER flag set, this points to a bridge struct
115121 * @port: if MASTER flag unset, this points to a port struct
....@@ -129,6 +135,8 @@
129135 struct rhash_head tnode;
130136 u16 vid;
131137 u16 flags;
138
+ u16 priv_flags;
139
+ u8 state;
132140 struct br_vlan_stats __percpu *stats;
133141 union {
134142 struct net_bridge *br;
....@@ -153,6 +161,7 @@
153161 * @vlan_list: sorted VLAN entry list
154162 * @num_vlans: number of total VLAN entries
155163 * @pvid: PVID VLAN id
164
+ * @pvid_state: PVID's STP state (e.g. forwarding, learning, blocking)
156165 *
157166 * IMPORTANT: Be careful when checking if there're VLAN entries using list
158167 * primitives because the bridge can have entries in its list which
....@@ -166,6 +175,19 @@
166175 struct list_head vlan_list;
167176 u16 num_vlans;
168177 u16 pvid;
178
+ u8 pvid_state;
179
+};
180
+
181
+/* bridge fdb flags */
182
+enum {
183
+ BR_FDB_LOCAL,
184
+ BR_FDB_STATIC,
185
+ BR_FDB_STICKY,
186
+ BR_FDB_ADDED_BY_USER,
187
+ BR_FDB_ADDED_BY_EXT_LEARN,
188
+ BR_FDB_OFFLOADED,
189
+ BR_FDB_NOTIFY,
190
+ BR_FDB_NOTIFY_INACTIVE
169191 };
170192
171193 struct net_bridge_fdb_key {
....@@ -179,11 +201,7 @@
179201
180202 struct net_bridge_fdb_key key;
181203 struct hlist_node fdb_node;
182
- unsigned char is_local:1,
183
- is_static:1,
184
- added_by_user:1,
185
- added_by_external_learn:1,
186
- offloaded:1;
204
+ unsigned long flags;
187205
188206 /* write-heavy members should not affect lookups */
189207 unsigned long updated ____cacheline_aligned_in_smp;
....@@ -194,38 +212,72 @@
194212
195213 #define MDB_PG_FLAGS_PERMANENT BIT(0)
196214 #define MDB_PG_FLAGS_OFFLOAD BIT(1)
215
+#define MDB_PG_FLAGS_FAST_LEAVE BIT(2)
216
+#define MDB_PG_FLAGS_STAR_EXCL BIT(3)
217
+#define MDB_PG_FLAGS_BLOCKED BIT(4)
218
+
219
+#define PG_SRC_ENT_LIMIT 32
220
+
221
+#define BR_SGRP_F_DELETE BIT(0)
222
+#define BR_SGRP_F_SEND BIT(1)
223
+#define BR_SGRP_F_INSTALLED BIT(2)
224
+
225
+struct net_bridge_mcast_gc {
226
+ struct hlist_node gc_node;
227
+ void (*destroy)(struct net_bridge_mcast_gc *gc);
228
+};
229
+
230
+struct net_bridge_group_src {
231
+ struct hlist_node node;
232
+
233
+ struct br_ip addr;
234
+ struct net_bridge_port_group *pg;
235
+ u8 flags;
236
+ u8 src_query_rexmit_cnt;
237
+ struct timer_list timer;
238
+
239
+ struct net_bridge *br;
240
+ struct net_bridge_mcast_gc mcast_gc;
241
+ struct rcu_head rcu;
242
+};
243
+
244
+struct net_bridge_port_group_sg_key {
245
+ struct net_bridge_port *port;
246
+ struct br_ip addr;
247
+};
197248
198249 struct net_bridge_port_group {
199
- struct net_bridge_port *port;
200250 struct net_bridge_port_group __rcu *next;
201
- struct hlist_node mglist;
202
- struct rcu_head rcu;
203
- struct timer_list timer;
204
- struct br_ip addr;
251
+ struct net_bridge_port_group_sg_key key;
205252 unsigned char eth_addr[ETH_ALEN] __aligned(2);
206253 unsigned char flags;
254
+ unsigned char filter_mode;
255
+ unsigned char grp_query_rexmit_cnt;
256
+ unsigned char rt_protocol;
257
+
258
+ struct hlist_head src_list;
259
+ unsigned int src_ents;
260
+ struct timer_list timer;
261
+ struct timer_list rexmit_timer;
262
+ struct hlist_node mglist;
263
+
264
+ struct rhash_head rhnode;
265
+ struct net_bridge_mcast_gc mcast_gc;
266
+ struct rcu_head rcu;
207267 };
208268
209
-struct net_bridge_mdb_entry
210
-{
211
- struct hlist_node hlist[2];
269
+struct net_bridge_mdb_entry {
270
+ struct rhash_head rhnode;
212271 struct net_bridge *br;
213272 struct net_bridge_port_group __rcu *ports;
214
- struct rcu_head rcu;
215
- struct timer_list timer;
216273 struct br_ip addr;
217274 bool host_joined;
218
-};
219275
220
-struct net_bridge_mdb_htable
221
-{
222
- struct hlist_head *mhash;
276
+ struct timer_list timer;
277
+ struct hlist_node mdb_node;
278
+
279
+ struct net_bridge_mcast_gc mcast_gc;
223280 struct rcu_head rcu;
224
- struct net_bridge_mdb_htable *old;
225
- u32 size;
226
- u32 max;
227
- u32 secret;
228
- u32 ver;
229281 };
230282
231283 struct net_bridge_port {
....@@ -283,14 +335,14 @@
283335 #endif
284336 u16 group_fwd_mask;
285337 u16 backup_redirected_cnt;
338
+
339
+ struct bridge_stp_xstats stp_xstats;
286340 };
287341
288342 #define kobj_to_brport(obj) container_of(obj, struct net_bridge_port, kobj)
289343
290344 #define br_auto_port(p) ((p)->flags & BR_AUTO_MASK)
291345 #define br_promisc_port(p) ((p)->flags & BR_PROMISC)
292
-
293
-#define br_port_exists(dev) (dev->priv_flags & IFF_BRIDGE_PORT)
294346
295347 static inline struct net_bridge_port *br_port_get_rcu(const struct net_device *dev)
296348 {
....@@ -299,15 +351,34 @@
299351
300352 static inline struct net_bridge_port *br_port_get_rtnl(const struct net_device *dev)
301353 {
302
- return br_port_exists(dev) ?
354
+ return netif_is_bridge_port(dev) ?
303355 rtnl_dereference(dev->rx_handler_data) : NULL;
304356 }
305357
306358 static inline struct net_bridge_port *br_port_get_rtnl_rcu(const struct net_device *dev)
307359 {
308
- return br_port_exists(dev) ?
360
+ return netif_is_bridge_port(dev) ?
309361 rcu_dereference_rtnl(dev->rx_handler_data) : NULL;
310362 }
363
+
364
+enum net_bridge_opts {
365
+ BROPT_VLAN_ENABLED,
366
+ BROPT_VLAN_STATS_ENABLED,
367
+ BROPT_NF_CALL_IPTABLES,
368
+ BROPT_NF_CALL_IP6TABLES,
369
+ BROPT_NF_CALL_ARPTABLES,
370
+ BROPT_GROUP_ADDR_SET,
371
+ BROPT_MULTICAST_ENABLED,
372
+ BROPT_MULTICAST_QUERIER,
373
+ BROPT_MULTICAST_QUERY_USE_IFADDR,
374
+ BROPT_MULTICAST_STATS_ENABLED,
375
+ BROPT_HAS_IPV6_ADDR,
376
+ BROPT_NEIGH_SUPPRESS_ENABLED,
377
+ BROPT_MTU_SET_BY_USER,
378
+ BROPT_VLAN_STATS_PER_PORT,
379
+ BROPT_NO_LL_LEARN,
380
+ BROPT_VLAN_BRIDGE_BINDING,
381
+};
311382
312383 struct net_bridge {
313384 spinlock_t lock;
....@@ -315,10 +386,9 @@
315386 struct list_head port_list;
316387 struct net_device *dev;
317388 struct pcpu_sw_netstats __percpu *stats;
389
+ unsigned long options;
318390 /* These fields are accessed on each packet */
319391 #ifdef CONFIG_BRIDGE_VLAN_FILTERING
320
- u8 vlan_enabled;
321
- u8 vlan_stats_enabled;
322392 __be16 vlan_proto;
323393 u16 default_pvid;
324394 struct net_bridge_vlan_group __rcu *vlgrp;
....@@ -330,9 +400,6 @@
330400 struct rtable fake_rtable;
331401 struct rt6_info fake_rt6_info;
332402 };
333
- bool nf_call_iptables;
334
- bool nf_call_ip6tables;
335
- bool nf_call_arptables;
336403 #endif
337404 u16 group_fwd_mask;
338405 u16 group_fwd_mask_required;
....@@ -340,7 +407,6 @@
340407 /* STP */
341408 bridge_id designated_root;
342409 bridge_id bridge_id;
343
- u32 root_path_cost;
344410 unsigned char topology_change;
345411 unsigned char topology_change_detected;
346412 u16 root_port;
....@@ -352,9 +418,9 @@
352418 unsigned long bridge_hello_time;
353419 unsigned long bridge_forward_delay;
354420 unsigned long bridge_ageing_time;
421
+ u32 root_path_cost;
355422
356423 u8 group_addr[ETH_ALEN];
357
- bool group_addr_set;
358424
359425 enum {
360426 BR_NO_STP, /* no spanning tree */
....@@ -363,22 +429,18 @@
363429 } stp_enabled;
364430
365431 #ifdef CONFIG_BRIDGE_IGMP_SNOOPING
366
- unsigned char multicast_router;
367432
368
- u8 multicast_disabled:1;
369
- u8 multicast_querier:1;
370
- u8 multicast_query_use_ifaddr:1;
371
- u8 has_ipv6_addr:1;
372
- u8 multicast_stats_enabled:1;
373
-
374
- u32 hash_elasticity;
375433 u32 hash_max;
376434
377435 u32 multicast_last_member_count;
378436 u32 multicast_startup_query_count;
379437
380438 u8 multicast_igmp_version;
381
-
439
+ u8 multicast_router;
440
+#if IS_ENABLED(CONFIG_IPV6)
441
+ u8 multicast_mld_version;
442
+#endif
443
+ spinlock_t multicast_lock;
382444 unsigned long multicast_last_member_interval;
383445 unsigned long multicast_membership_interval;
384446 unsigned long multicast_querier_interval;
....@@ -386,8 +448,11 @@
386448 unsigned long multicast_query_response_interval;
387449 unsigned long multicast_startup_query_interval;
388450
389
- spinlock_t multicast_lock;
390
- struct net_bridge_mdb_htable __rcu *mdb;
451
+ struct rhashtable mdb_hash_tbl;
452
+ struct rhashtable sg_port_tbl;
453
+
454
+ struct hlist_head mcast_gc_list;
455
+ struct hlist_head mdb_list;
391456 struct hlist_head router_list;
392457
393458 struct timer_list multicast_router_timer;
....@@ -399,8 +464,8 @@
399464 struct bridge_mcast_other_query ip6_other_query;
400465 struct bridge_mcast_own_query ip6_own_query;
401466 struct bridge_mcast_querier ip6_querier;
402
- u8 multicast_mld_version;
403467 #endif /* IS_ENABLED(CONFIG_IPV6) */
468
+ struct work_struct mcast_gc_work;
404469 #endif
405470
406471 struct timer_list hello_timer;
....@@ -413,24 +478,28 @@
413478 #ifdef CONFIG_NET_SWITCHDEV
414479 int offload_fwd_mark;
415480 #endif
416
- bool neigh_suppress_enabled;
417
- bool mtu_set_by_user;
418481 struct hlist_head fdb_list;
482
+
483
+#if IS_ENABLED(CONFIG_BRIDGE_MRP)
484
+ struct list_head mrp_list;
485
+#endif
419486 };
420487
421488 struct br_input_skb_cb {
422489 struct net_device *brdev;
423490
491
+ u16 frag_max_size;
424492 #ifdef CONFIG_BRIDGE_IGMP_SNOOPING
425
- int igmp;
426
- int mrouters_only;
493
+ u8 igmp;
494
+ u8 mrouters_only:1;
427495 #endif
428
-
429
- bool proxyarp_replied;
430
- bool src_port_isolated;
431
-
496
+ u8 proxyarp_replied:1;
497
+ u8 src_port_isolated:1;
432498 #ifdef CONFIG_BRIDGE_VLAN_FILTERING
433
- bool vlan_filtered;
499
+ u8 vlan_filtered:1;
500
+#endif
501
+#ifdef CONFIG_NETFILTER_FAMILY_BRIDGE
502
+ u8 br_netfilter_broute:1;
434503 #endif
435504
436505 #ifdef CONFIG_NET_SWITCHDEV
....@@ -492,6 +561,86 @@
492561 return true;
493562 }
494563
564
+static inline bool nbp_state_should_learn(const struct net_bridge_port *p)
565
+{
566
+ return p->state == BR_STATE_LEARNING || p->state == BR_STATE_FORWARDING;
567
+}
568
+
569
+static inline bool br_vlan_valid_id(u16 vid, struct netlink_ext_ack *extack)
570
+{
571
+ bool ret = vid > 0 && vid < VLAN_VID_MASK;
572
+
573
+ if (!ret)
574
+ NL_SET_ERR_MSG_MOD(extack, "Vlan id is invalid");
575
+
576
+ return ret;
577
+}
578
+
579
+static inline bool br_vlan_valid_range(const struct bridge_vlan_info *cur,
580
+ const struct bridge_vlan_info *last,
581
+ struct netlink_ext_ack *extack)
582
+{
583
+ /* pvid flag is not allowed in ranges */
584
+ if (cur->flags & BRIDGE_VLAN_INFO_PVID) {
585
+ NL_SET_ERR_MSG_MOD(extack, "Pvid isn't allowed in a range");
586
+ return false;
587
+ }
588
+
589
+ /* when cur is the range end, check if:
590
+ * - it has range start flag
591
+ * - range ids are invalid (end is equal to or before start)
592
+ */
593
+ if (last) {
594
+ if (cur->flags & BRIDGE_VLAN_INFO_RANGE_BEGIN) {
595
+ NL_SET_ERR_MSG_MOD(extack, "Found a new vlan range start while processing one");
596
+ return false;
597
+ } else if (!(cur->flags & BRIDGE_VLAN_INFO_RANGE_END)) {
598
+ NL_SET_ERR_MSG_MOD(extack, "Vlan range end flag is missing");
599
+ return false;
600
+ } else if (cur->vid <= last->vid) {
601
+ NL_SET_ERR_MSG_MOD(extack, "End vlan id is less than or equal to start vlan id");
602
+ return false;
603
+ }
604
+ }
605
+
606
+ /* check for required range flags */
607
+ if (!(cur->flags & (BRIDGE_VLAN_INFO_RANGE_BEGIN |
608
+ BRIDGE_VLAN_INFO_RANGE_END))) {
609
+ NL_SET_ERR_MSG_MOD(extack, "Both vlan range flags are missing");
610
+ return false;
611
+ }
612
+
613
+ return true;
614
+}
615
+
616
+static inline int br_afspec_cmd_to_rtm(int cmd)
617
+{
618
+ switch (cmd) {
619
+ case RTM_SETLINK:
620
+ return RTM_NEWVLAN;
621
+ case RTM_DELLINK:
622
+ return RTM_DELVLAN;
623
+ }
624
+
625
+ return 0;
626
+}
627
+
628
+static inline int br_opt_get(const struct net_bridge *br,
629
+ enum net_bridge_opts opt)
630
+{
631
+ return test_bit(opt, &br->options);
632
+}
633
+
634
+int br_boolopt_toggle(struct net_bridge *br, enum br_boolopt_id opt, bool on,
635
+ struct netlink_ext_ack *extack);
636
+int br_boolopt_get(const struct net_bridge *br, enum br_boolopt_id opt);
637
+int br_boolopt_multi_toggle(struct net_bridge *br,
638
+ struct br_boolopt_multi *bm,
639
+ struct netlink_ext_ack *extack);
640
+void br_boolopt_multi_get(const struct net_bridge *br,
641
+ struct br_boolopt_multi *bm);
642
+void br_opt_toggle(struct net_bridge *br, enum net_bridge_opts opt, bool on);
643
+
495644 /* br_device.c */
496645 void br_dev_setup(struct net_device *dev);
497646 void br_dev_delete(struct net_device *dev, struct list_head *list);
....@@ -500,10 +649,7 @@
500649 static inline void br_netpoll_send_skb(const struct net_bridge_port *p,
501650 struct sk_buff *skb)
502651 {
503
- struct netpoll *np = p->np;
504
-
505
- if (np)
506
- netpoll_send_skb(np, skb);
652
+ netpoll_send_skb(p->np, skb);
507653 }
508654
509655 int br_netpoll_enable(struct net_bridge_port *p);
....@@ -547,14 +693,18 @@
547693 int br_fdb_insert(struct net_bridge *br, struct net_bridge_port *source,
548694 const unsigned char *addr, u16 vid);
549695 void br_fdb_update(struct net_bridge *br, struct net_bridge_port *source,
550
- const unsigned char *addr, u16 vid, bool added_by_user);
696
+ const unsigned char *addr, u16 vid, unsigned long flags);
551697
552698 int br_fdb_delete(struct ndmsg *ndm, struct nlattr *tb[],
553699 struct net_device *dev, const unsigned char *addr, u16 vid);
554700 int br_fdb_add(struct ndmsg *nlh, struct nlattr *tb[], struct net_device *dev,
555
- const unsigned char *addr, u16 vid, u16 nlh_flags);
701
+ const unsigned char *addr, u16 vid, u16 nlh_flags,
702
+ struct netlink_ext_ack *extack);
556703 int br_fdb_dump(struct sk_buff *skb, struct netlink_callback *cb,
557704 struct net_device *dev, struct net_device *fdev, int *idx);
705
+int br_fdb_get(struct sk_buff *skb, struct nlattr *tb[], struct net_device *dev,
706
+ const unsigned char *addr, u16 vid, u32 portid, u32 seq,
707
+ struct netlink_ext_ack *extack);
558708 int br_fdb_sync_static(struct net_bridge *br, struct net_bridge_port *p);
559709 void br_fdb_unsync_static(struct net_bridge *br, struct net_bridge_port *p);
560710 int br_fdb_external_learn_add(struct net_bridge *br, struct net_bridge_port *p,
....@@ -564,7 +714,7 @@
564714 const unsigned char *addr, u16 vid,
565715 bool swdev_notify);
566716 void br_fdb_offloaded_set(struct net_bridge *br, struct net_bridge_port *p,
567
- const unsigned char *addr, u16 vid);
717
+ const unsigned char *addr, u16 vid, bool offloaded);
568718
569719 /* br_forward.c */
570720 enum br_pkt_type {
....@@ -603,16 +753,16 @@
603753
604754 /* br_input.c */
605755 int br_handle_frame_finish(struct net *net, struct sock *sk, struct sk_buff *skb);
606
-rx_handler_result_t br_handle_frame(struct sk_buff **pskb);
756
+rx_handler_func_t *br_get_rx_handler(const struct net_device *dev);
607757
608758 static inline bool br_rx_handler_check_rcu(const struct net_device *dev)
609759 {
610
- return rcu_dereference(dev->rx_handler) == br_handle_frame;
760
+ return rcu_dereference(dev->rx_handler) == br_get_rx_handler(dev);
611761 }
612762
613763 static inline bool br_rx_handler_check_rtnl(const struct net_device *dev)
614764 {
615
- return rcu_dereference_rtnl(dev->rx_handler) == br_handle_frame;
765
+ return rcu_dereference_rtnl(dev->rx_handler) == br_get_rx_handler(dev);
616766 }
617767
618768 static inline struct net_bridge_port *br_port_get_check_rcu(const struct net_device *dev)
....@@ -633,7 +783,6 @@
633783
634784 /* br_multicast.c */
635785 #ifdef CONFIG_BRIDGE_IGMP_SNOOPING
636
-extern unsigned int br_mdb_rehash_seq;
637786 int br_multicast_rcv(struct net_bridge *br, struct net_bridge_port *port,
638787 struct sk_buff *skb, u16 vid);
639788 struct net_bridge_mdb_entry *br_mdb_get(struct net_bridge *br,
....@@ -643,6 +792,8 @@
643792 void br_multicast_enable_port(struct net_bridge_port *port);
644793 void br_multicast_disable_port(struct net_bridge_port *port);
645794 void br_multicast_init(struct net_bridge *br);
795
+void br_multicast_join_snoopers(struct net_bridge *br);
796
+void br_multicast_leave_snoopers(struct net_bridge *br);
646797 void br_multicast_open(struct net_bridge *br);
647798 void br_multicast_stop(struct net_bridge *br);
648799 void br_multicast_dev_del(struct net_bridge *br);
....@@ -658,21 +809,23 @@
658809 int br_multicast_set_mld_version(struct net_bridge *br, unsigned long val);
659810 #endif
660811 struct net_bridge_mdb_entry *
661
-br_mdb_ip_get(struct net_bridge_mdb_htable *mdb, struct br_ip *dst);
812
+br_mdb_ip_get(struct net_bridge *br, struct br_ip *dst);
662813 struct net_bridge_mdb_entry *
663
-br_multicast_new_group(struct net_bridge *br, struct net_bridge_port *port,
664
- struct br_ip *group);
665
-void br_multicast_free_pg(struct rcu_head *head);
814
+br_multicast_new_group(struct net_bridge *br, struct br_ip *group);
666815 struct net_bridge_port_group *
667816 br_multicast_new_port_group(struct net_bridge_port *port, struct br_ip *group,
668817 struct net_bridge_port_group __rcu *next,
669
- unsigned char flags, const unsigned char *src);
670
-void br_mdb_init(void);
671
-void br_mdb_uninit(void);
672
-void br_mdb_notify(struct net_device *dev, struct net_bridge_port *port,
673
- struct br_ip *group, int type, u8 flags);
818
+ unsigned char flags, const unsigned char *src,
819
+ u8 filter_mode, u8 rt_protocol);
820
+int br_mdb_hash_init(struct net_bridge *br);
821
+void br_mdb_hash_fini(struct net_bridge *br);
822
+void br_mdb_notify(struct net_device *dev, struct net_bridge_mdb_entry *mp,
823
+ struct net_bridge_port_group *pg, int type);
674824 void br_rtr_notify(struct net_device *dev, struct net_bridge_port *port,
675825 int type);
826
+void br_multicast_del_pg(struct net_bridge_mdb_entry *mp,
827
+ struct net_bridge_port_group *pg,
828
+ struct net_bridge_port_group __rcu **pp);
676829 void br_multicast_count(struct net_bridge *br, const struct net_bridge_port *p,
677830 const struct sk_buff *skb, u8 type, u8 dir);
678831 int br_multicast_init_stats(struct net_bridge *br);
....@@ -680,6 +833,14 @@
680833 void br_multicast_get_stats(const struct net_bridge *br,
681834 const struct net_bridge_port *p,
682835 struct br_mcast_stats *dest);
836
+void br_mdb_init(void);
837
+void br_mdb_uninit(void);
838
+void br_multicast_host_join(struct net_bridge_mdb_entry *mp, bool notify);
839
+void br_multicast_host_leave(struct net_bridge_mdb_entry *mp, bool notify);
840
+void br_multicast_star_g_handle_mode(struct net_bridge_port_group *pg,
841
+ u8 filter_mode);
842
+void br_multicast_sg_add_exclude_ports(struct net_bridge_mdb_entry *star_mp,
843
+ struct net_bridge_port_group *sg);
683844
684845 #define mlock_dereference(X, br) \
685846 rcu_dereference_protected(X, lockdep_is_held(&br->multicast_lock))
....@@ -698,8 +859,8 @@
698859 {
699860 bool own_querier_enabled;
700861
701
- if (br->multicast_querier) {
702
- if (is_ipv6 && !br->has_ipv6_addr)
862
+ if (br_opt_get(br, BROPT_MULTICAST_QUERIER)) {
863
+ if (is_ipv6 && !br_opt_get(br, BROPT_HAS_IPV6_ADDR))
703864 own_querier_enabled = false;
704865 else
705866 own_querier_enabled = true;
....@@ -728,9 +889,49 @@
728889 }
729890 }
730891
892
+static inline bool br_multicast_is_star_g(const struct br_ip *ip)
893
+{
894
+ switch (ip->proto) {
895
+ case htons(ETH_P_IP):
896
+ return ipv4_is_zeronet(ip->src.ip4);
897
+#if IS_ENABLED(CONFIG_IPV6)
898
+ case htons(ETH_P_IPV6):
899
+ return ipv6_addr_any(&ip->src.ip6);
900
+#endif
901
+ default:
902
+ return false;
903
+ }
904
+}
905
+
906
+static inline bool br_multicast_should_handle_mode(const struct net_bridge *br,
907
+ __be16 proto)
908
+{
909
+ switch (proto) {
910
+ case htons(ETH_P_IP):
911
+ return !!(br->multicast_igmp_version == 3);
912
+#if IS_ENABLED(CONFIG_IPV6)
913
+ case htons(ETH_P_IPV6):
914
+ return !!(br->multicast_mld_version == 2);
915
+#endif
916
+ default:
917
+ return false;
918
+ }
919
+}
920
+
731921 static inline int br_multicast_igmp_type(const struct sk_buff *skb)
732922 {
733923 return BR_INPUT_SKB_CB(skb)->igmp;
924
+}
925
+
926
+static inline unsigned long br_multicast_lmqt(const struct net_bridge *br)
927
+{
928
+ return br->multicast_last_member_interval *
929
+ br->multicast_last_member_count;
930
+}
931
+
932
+static inline unsigned long br_multicast_gmi(const struct net_bridge *br)
933
+{
934
+ return br->multicast_membership_interval;
734935 }
735936 #else
736937 static inline int br_multicast_rcv(struct net_bridge *br,
....@@ -765,6 +966,14 @@
765966 }
766967
767968 static inline void br_multicast_init(struct net_bridge *br)
969
+{
970
+}
971
+
972
+static inline void br_multicast_join_snoopers(struct net_bridge *br)
973
+{
974
+}
975
+
976
+static inline void br_multicast_leave_snoopers(struct net_bridge *br)
768977 {
769978 }
770979
....@@ -805,6 +1014,15 @@
8051014 {
8061015 }
8071016
1017
+static inline int br_mdb_hash_init(struct net_bridge *br)
1018
+{
1019
+ return 0;
1020
+}
1021
+
1022
+static inline void br_mdb_hash_fini(struct net_bridge *br)
1023
+{
1024
+}
1025
+
8081026 static inline void br_multicast_count(struct net_bridge *br,
8091027 const struct net_bridge_port *p,
8101028 const struct sk_buff *skb,
....@@ -831,7 +1049,7 @@
8311049 #ifdef CONFIG_BRIDGE_VLAN_FILTERING
8321050 bool br_allowed_ingress(const struct net_bridge *br,
8331051 struct net_bridge_vlan_group *vg, struct sk_buff *skb,
834
- u16 *vid);
1052
+ u16 *vid, u8 *state);
8351053 bool br_allowed_egress(struct net_bridge_vlan_group *vg,
8361054 const struct sk_buff *skb);
8371055 bool br_should_learn(struct net_bridge_port *p, struct sk_buff *skb, u16 *vid);
....@@ -840,7 +1058,7 @@
8401058 struct net_bridge_vlan_group *vg,
8411059 struct sk_buff *skb);
8421060 int br_vlan_add(struct net_bridge *br, u16 vid, u16 flags,
843
- bool *changed);
1061
+ bool *changed, struct netlink_ext_ack *extack);
8441062 int br_vlan_delete(struct net_bridge *br, u16 vid);
8451063 void br_vlan_flush(struct net_bridge *br);
8461064 struct net_bridge_vlan *br_vlan_find(struct net_bridge_vlan_group *vg, u16 vid);
....@@ -850,17 +1068,30 @@
8501068 int __br_vlan_set_proto(struct net_bridge *br, __be16 proto);
8511069 int br_vlan_set_proto(struct net_bridge *br, unsigned long val);
8521070 int br_vlan_set_stats(struct net_bridge *br, unsigned long val);
1071
+int br_vlan_set_stats_per_port(struct net_bridge *br, unsigned long val);
8531072 int br_vlan_init(struct net_bridge *br);
8541073 int br_vlan_set_default_pvid(struct net_bridge *br, unsigned long val);
855
-int __br_vlan_set_default_pvid(struct net_bridge *br, u16 pvid);
1074
+int __br_vlan_set_default_pvid(struct net_bridge *br, u16 pvid,
1075
+ struct netlink_ext_ack *extack);
8561076 int nbp_vlan_add(struct net_bridge_port *port, u16 vid, u16 flags,
857
- bool *changed);
1077
+ bool *changed, struct netlink_ext_ack *extack);
8581078 int nbp_vlan_delete(struct net_bridge_port *port, u16 vid);
8591079 void nbp_vlan_flush(struct net_bridge_port *port);
860
-int nbp_vlan_init(struct net_bridge_port *port);
1080
+int nbp_vlan_init(struct net_bridge_port *port, struct netlink_ext_ack *extack);
8611081 int nbp_get_num_vlan_infos(struct net_bridge_port *p, u32 filter_mask);
8621082 void br_vlan_get_stats(const struct net_bridge_vlan *v,
8631083 struct br_vlan_stats *stats);
1084
+void br_vlan_port_event(struct net_bridge_port *p, unsigned long event);
1085
+int br_vlan_bridge_event(struct net_device *dev, unsigned long event,
1086
+ void *ptr);
1087
+void br_vlan_rtnl_init(void);
1088
+void br_vlan_rtnl_uninit(void);
1089
+void br_vlan_notify(const struct net_bridge *br,
1090
+ const struct net_bridge_port *p,
1091
+ u16 vid, u16 vid_range,
1092
+ int cmd);
1093
+bool br_vlan_can_enter_range(const struct net_bridge_vlan *v_curr,
1094
+ const struct net_bridge_vlan *range_end);
8641095
8651096 static inline struct net_bridge_vlan_group *br_vlan_group(
8661097 const struct net_bridge *br)
....@@ -894,7 +1125,7 @@
8941125 int err = 0;
8951126
8961127 if (skb_vlan_tag_present(skb)) {
897
- *vid = skb_vlan_tag_get(skb) & VLAN_VID_MASK;
1128
+ *vid = skb_vlan_tag_get_id(skb);
8981129 } else {
8991130 *vid = 0;
9001131 err = -EINVAL;
....@@ -912,11 +1143,15 @@
9121143 return vg->pvid;
9131144 }
9141145
1146
+static inline u16 br_vlan_flags(const struct net_bridge_vlan *v, u16 pvid)
1147
+{
1148
+ return v->vid == pvid ? v->flags | BRIDGE_VLAN_INFO_PVID : v->flags;
1149
+}
9151150 #else
9161151 static inline bool br_allowed_ingress(const struct net_bridge *br,
9171152 struct net_bridge_vlan_group *vg,
9181153 struct sk_buff *skb,
919
- u16 *vid)
1154
+ u16 *vid, u8 *state)
9201155 {
9211156 return true;
9221157 }
....@@ -942,7 +1177,7 @@
9421177 }
9431178
9441179 static inline int br_vlan_add(struct net_bridge *br, u16 vid, u16 flags,
945
- bool *changed)
1180
+ bool *changed, struct netlink_ext_ack *extack)
9461181 {
9471182 *changed = false;
9481183 return -EOPNOTSUPP;
....@@ -967,7 +1202,7 @@
9671202 }
9681203
9691204 static inline int nbp_vlan_add(struct net_bridge_port *port, u16 vid, u16 flags,
970
- bool *changed)
1205
+ bool *changed, struct netlink_ext_ack *extack)
9711206 {
9721207 *changed = false;
9731208 return -EOPNOTSUPP;
....@@ -988,7 +1223,8 @@
9881223 return NULL;
9891224 }
9901225
991
-static inline int nbp_vlan_init(struct net_bridge_port *port)
1226
+static inline int nbp_vlan_init(struct net_bridge_port *port,
1227
+ struct netlink_ext_ack *extack)
9921228 {
9931229 return 0;
9941230 }
....@@ -1043,6 +1279,87 @@
10431279 struct br_vlan_stats *stats)
10441280 {
10451281 }
1282
+
1283
+static inline void br_vlan_port_event(struct net_bridge_port *p,
1284
+ unsigned long event)
1285
+{
1286
+}
1287
+
1288
+static inline int br_vlan_bridge_event(struct net_device *dev,
1289
+ unsigned long event, void *ptr)
1290
+{
1291
+ return 0;
1292
+}
1293
+
1294
+static inline void br_vlan_rtnl_init(void)
1295
+{
1296
+}
1297
+
1298
+static inline void br_vlan_rtnl_uninit(void)
1299
+{
1300
+}
1301
+
1302
+static inline void br_vlan_notify(const struct net_bridge *br,
1303
+ const struct net_bridge_port *p,
1304
+ u16 vid, u16 vid_range,
1305
+ int cmd)
1306
+{
1307
+}
1308
+
1309
+static inline bool br_vlan_can_enter_range(const struct net_bridge_vlan *v_curr,
1310
+ const struct net_bridge_vlan *range_end)
1311
+{
1312
+ return true;
1313
+}
1314
+#endif
1315
+
1316
+/* br_vlan_options.c */
1317
+#ifdef CONFIG_BRIDGE_VLAN_FILTERING
1318
+bool br_vlan_opts_eq_range(const struct net_bridge_vlan *v_curr,
1319
+ const struct net_bridge_vlan *range_end);
1320
+bool br_vlan_opts_fill(struct sk_buff *skb, const struct net_bridge_vlan *v);
1321
+size_t br_vlan_opts_nl_size(void);
1322
+int br_vlan_process_options(const struct net_bridge *br,
1323
+ const struct net_bridge_port *p,
1324
+ struct net_bridge_vlan *range_start,
1325
+ struct net_bridge_vlan *range_end,
1326
+ struct nlattr **tb,
1327
+ struct netlink_ext_ack *extack);
1328
+
1329
+/* vlan state manipulation helpers using *_ONCE to annotate lock-free access */
1330
+static inline u8 br_vlan_get_state(const struct net_bridge_vlan *v)
1331
+{
1332
+ return READ_ONCE(v->state);
1333
+}
1334
+
1335
+static inline void br_vlan_set_state(struct net_bridge_vlan *v, u8 state)
1336
+{
1337
+ WRITE_ONCE(v->state, state);
1338
+}
1339
+
1340
+static inline u8 br_vlan_get_pvid_state(const struct net_bridge_vlan_group *vg)
1341
+{
1342
+ return READ_ONCE(vg->pvid_state);
1343
+}
1344
+
1345
+static inline void br_vlan_set_pvid_state(struct net_bridge_vlan_group *vg,
1346
+ u8 state)
1347
+{
1348
+ WRITE_ONCE(vg->pvid_state, state);
1349
+}
1350
+
1351
+/* learn_allow is true at ingress and false at egress */
1352
+static inline bool br_vlan_state_allowed(u8 state, bool learn_allow)
1353
+{
1354
+ switch (state) {
1355
+ case BR_STATE_LEARNING:
1356
+ return learn_allow;
1357
+ case BR_STATE_FORWARDING:
1358
+ return true;
1359
+ default:
1360
+ return false;
1361
+ }
1362
+}
10461363 #endif
10471364
10481365 struct nf_br_ops {
....@@ -1078,7 +1395,8 @@
10781395 /* br_stp_if.c */
10791396 void br_stp_enable_bridge(struct net_bridge *br);
10801397 void br_stp_disable_bridge(struct net_bridge *br);
1081
-void br_stp_set_enabled(struct net_bridge *br, unsigned long val);
1398
+int br_stp_set_enabled(struct net_bridge *br, unsigned long val,
1399
+ struct netlink_ext_ack *extack);
10821400 void br_stp_enable_port(struct net_bridge_port *p);
10831401 void br_stp_disable_port(struct net_bridge_port *p);
10841402 bool br_stp_recalculate_bridge_id(struct net_bridge *br);
....@@ -1103,16 +1421,61 @@
11031421 extern int (*br_fdb_test_addr_hook)(struct net_device *dev, unsigned char *addr);
11041422 #endif
11051423
1424
+/* br_mrp.c */
1425
+#if IS_ENABLED(CONFIG_BRIDGE_MRP)
1426
+int br_mrp_parse(struct net_bridge *br, struct net_bridge_port *p,
1427
+ struct nlattr *attr, int cmd, struct netlink_ext_ack *extack);
1428
+int br_mrp_process(struct net_bridge_port *p, struct sk_buff *skb);
1429
+bool br_mrp_enabled(struct net_bridge *br);
1430
+void br_mrp_port_del(struct net_bridge *br, struct net_bridge_port *p);
1431
+int br_mrp_fill_info(struct sk_buff *skb, struct net_bridge *br);
1432
+#else
1433
+static inline int br_mrp_parse(struct net_bridge *br, struct net_bridge_port *p,
1434
+ struct nlattr *attr, int cmd,
1435
+ struct netlink_ext_ack *extack)
1436
+{
1437
+ return -EOPNOTSUPP;
1438
+}
1439
+
1440
+static inline int br_mrp_process(struct net_bridge_port *p, struct sk_buff *skb)
1441
+{
1442
+ return 0;
1443
+}
1444
+
1445
+static inline bool br_mrp_enabled(struct net_bridge *br)
1446
+{
1447
+ return false;
1448
+}
1449
+
1450
+static inline void br_mrp_port_del(struct net_bridge *br,
1451
+ struct net_bridge_port *p)
1452
+{
1453
+}
1454
+
1455
+static inline int br_mrp_fill_info(struct sk_buff *skb, struct net_bridge *br)
1456
+{
1457
+ return 0;
1458
+}
1459
+
1460
+#endif
1461
+
11061462 /* br_netlink.c */
11071463 extern struct rtnl_link_ops br_link_ops;
11081464 int br_netlink_init(void);
11091465 void br_netlink_fini(void);
11101466 void br_ifinfo_notify(int event, const struct net_bridge *br,
11111467 const struct net_bridge_port *port);
1112
-int br_setlink(struct net_device *dev, struct nlmsghdr *nlmsg, u16 flags);
1468
+int br_setlink(struct net_device *dev, struct nlmsghdr *nlmsg, u16 flags,
1469
+ struct netlink_ext_ack *extack);
11131470 int br_dellink(struct net_device *dev, struct nlmsghdr *nlmsg, u16 flags);
11141471 int br_getlink(struct sk_buff *skb, u32 pid, u32 seq, struct net_device *dev,
11151472 u32 filter_mask, int nlflags);
1473
+int br_process_vlan_info(struct net_bridge *br,
1474
+ struct net_bridge_port *p, int cmd,
1475
+ struct bridge_vlan_info *vinfo_curr,
1476
+ struct bridge_vlan_info **vinfo_last,
1477
+ bool *changed,
1478
+ struct netlink_ext_ack *extack);
11161479
11171480 #ifdef CONFIG_SYSFS
11181481 /* br_sysfs_if.c */
....@@ -1144,7 +1507,8 @@
11441507 unsigned long mask);
11451508 void br_switchdev_fdb_notify(const struct net_bridge_fdb_entry *fdb,
11461509 int type);
1147
-int br_switchdev_port_vlan_add(struct net_device *dev, u16 vid, u16 flags);
1510
+int br_switchdev_port_vlan_add(struct net_device *dev, u16 vid, u16 flags,
1511
+ struct netlink_ext_ack *extack);
11481512 int br_switchdev_port_vlan_del(struct net_device *dev, u16 vid);
11491513
11501514 static inline void br_switchdev_frame_unmark(struct sk_buff *skb)
....@@ -1176,7 +1540,8 @@
11761540 }
11771541
11781542 static inline int br_switchdev_port_vlan_add(struct net_device *dev,
1179
- u16 vid, u16 flags)
1543
+ u16 vid, u16 flags,
1544
+ struct netlink_ext_ack *extack)
11801545 {
11811546 return -EOPNOTSUPP;
11821547 }