1 /* SPDX-License-Identifier: GPL-2.0-or-later */ 2 /* 3 * Linux ethernet bridge 4 * 5 * Authors: 6 * Lennert Buytenhek <buytenh@gnu.org> 7 */ 8 9 #ifndef _BR_PRIVATE_H 10 #define _BR_PRIVATE_H 11 12 #include <linux/netdevice.h> 13 #include <linux/if_bridge.h> 14 #include <linux/netpoll.h> 15 #include <linux/u64_stats_sync.h> 16 #include <net/route.h> 17 #include <net/ip6_fib.h> 18 #include <linux/if_vlan.h> 19 #include <linux/rhashtable.h> 20 #include <linux/refcount.h> 21 22 #define BR_HASH_BITS 8 23 #define BR_HASH_SIZE (1 << BR_HASH_BITS) 24 25 #define BR_HOLD_TIME (1*HZ) 26 27 #define BR_PORT_BITS 10 28 #define BR_MAX_PORTS (1<<BR_PORT_BITS) 29 30 #define BR_MULTICAST_DEFAULT_HASH_MAX 4096 31 #define BR_MULTICAST_QUERY_INTVL_MIN msecs_to_jiffies(1000) 32 #define BR_MULTICAST_STARTUP_QUERY_INTVL_MIN BR_MULTICAST_QUERY_INTVL_MIN 33 34 #define BR_HWDOM_MAX BITS_PER_LONG 35 36 #define BR_VERSION "2.3" 37 38 /* Control of forwarding link local multicast */ 39 #define BR_GROUPFWD_DEFAULT 0 40 /* Don't allow forwarding of control protocols like STP, MAC PAUSE and LACP */ 41 enum { 42 BR_GROUPFWD_STP = BIT(0), 43 BR_GROUPFWD_MACPAUSE = BIT(1), 44 BR_GROUPFWD_LACP = BIT(2), 45 }; 46 47 #define BR_GROUPFWD_RESTRICTED (BR_GROUPFWD_STP | BR_GROUPFWD_MACPAUSE | \ 48 BR_GROUPFWD_LACP) 49 /* The Nearest Customer Bridge Group Address, 01-80-C2-00-00-[00,0B,0C,0D,0F] */ 50 #define BR_GROUPFWD_8021AD 0xB801u 51 52 /* Path to usermode spanning tree program */ 53 #define BR_STP_PROG "/sbin/bridge-stp" 54 55 #define BR_FDB_NOTIFY_SETTABLE_BITS (FDB_NOTIFY_BIT | FDB_NOTIFY_INACTIVE_BIT) 56 57 typedef struct bridge_id bridge_id; 58 typedef struct mac_addr mac_addr; 59 typedef __u16 port_id; 60 61 struct bridge_id { 62 unsigned char prio[2]; 63 unsigned char addr[ETH_ALEN]; 64 }; 65 66 struct mac_addr { 67 unsigned char addr[ETH_ALEN]; 68 }; 69 70 #ifdef CONFIG_BRIDGE_IGMP_SNOOPING 71 /* our own querier */ 72 struct bridge_mcast_own_query { 73 struct timer_list timer; 74 u32 startup_sent; 75 }; 76 77 /* other querier */ 78 struct bridge_mcast_other_query { 79 struct timer_list timer; 80 unsigned long delay_time; 81 }; 82 83 /* selected querier */ 84 struct bridge_mcast_querier { 85 struct br_ip addr; 86 int port_ifidx; 87 seqcount_spinlock_t seq; 88 }; 89 90 /* IGMP/MLD statistics */ 91 struct bridge_mcast_stats { 92 struct br_mcast_stats mstats; 93 struct u64_stats_sync syncp; 94 }; 95 #endif 96 97 /* net_bridge_mcast_port must be always defined due to forwarding stubs */ 98 struct net_bridge_mcast_port { 99 #ifdef CONFIG_BRIDGE_IGMP_SNOOPING 100 struct net_bridge_port *port; 101 struct net_bridge_vlan *vlan; 102 103 struct bridge_mcast_own_query ip4_own_query; 104 struct timer_list ip4_mc_router_timer; 105 struct hlist_node ip4_rlist; 106 #if IS_ENABLED(CONFIG_IPV6) 107 struct bridge_mcast_own_query ip6_own_query; 108 struct timer_list ip6_mc_router_timer; 109 struct hlist_node ip6_rlist; 110 #endif /* IS_ENABLED(CONFIG_IPV6) */ 111 unsigned char multicast_router; 112 #endif /* CONFIG_BRIDGE_IGMP_SNOOPING */ 113 }; 114 115 /* net_bridge_mcast must be always defined due to forwarding stubs */ 116 struct net_bridge_mcast { 117 #ifdef CONFIG_BRIDGE_IGMP_SNOOPING 118 struct net_bridge *br; 119 struct net_bridge_vlan *vlan; 120 121 u32 multicast_last_member_count; 122 u32 multicast_startup_query_count; 123 124 u8 multicast_querier; 125 u8 multicast_igmp_version; 126 u8 multicast_router; 127 #if IS_ENABLED(CONFIG_IPV6) 128 u8 multicast_mld_version; 129 #endif 130 unsigned long multicast_last_member_interval; 131 unsigned long multicast_membership_interval; 132 unsigned long multicast_querier_interval; 133 unsigned long multicast_query_interval; 134 unsigned long multicast_query_response_interval; 135 unsigned long multicast_startup_query_interval; 136 struct hlist_head ip4_mc_router_list; 137 struct timer_list ip4_mc_router_timer; 138 struct bridge_mcast_other_query ip4_other_query; 139 struct bridge_mcast_own_query ip4_own_query; 140 struct bridge_mcast_querier ip4_querier; 141 #if IS_ENABLED(CONFIG_IPV6) 142 struct hlist_head ip6_mc_router_list; 143 struct timer_list ip6_mc_router_timer; 144 struct bridge_mcast_other_query ip6_other_query; 145 struct bridge_mcast_own_query ip6_own_query; 146 struct bridge_mcast_querier ip6_querier; 147 #endif /* IS_ENABLED(CONFIG_IPV6) */ 148 #endif /* CONFIG_BRIDGE_IGMP_SNOOPING */ 149 }; 150 151 struct br_tunnel_info { 152 __be64 tunnel_id; 153 struct metadata_dst __rcu *tunnel_dst; 154 }; 155 156 /* private vlan flags */ 157 enum { 158 BR_VLFLAG_PER_PORT_STATS = BIT(0), 159 BR_VLFLAG_ADDED_BY_SWITCHDEV = BIT(1), 160 BR_VLFLAG_MCAST_ENABLED = BIT(2), 161 BR_VLFLAG_GLOBAL_MCAST_ENABLED = BIT(3), 162 }; 163 164 /** 165 * struct net_bridge_vlan - per-vlan entry 166 * 167 * @vnode: rhashtable member 168 * @vid: VLAN id 169 * @flags: bridge vlan flags 170 * @priv_flags: private (in-kernel) bridge vlan flags 171 * @state: STP state (e.g. blocking, learning, forwarding) 172 * @stats: per-cpu VLAN statistics 173 * @br: if MASTER flag set, this points to a bridge struct 174 * @port: if MASTER flag unset, this points to a port struct 175 * @refcnt: if MASTER flag set, this is bumped for each port referencing it 176 * @brvlan: if MASTER flag unset, this points to the global per-VLAN context 177 * for this VLAN entry 178 * @br_mcast_ctx: if MASTER flag set, this is the global vlan multicast context 179 * @port_mcast_ctx: if MASTER flag unset, this is the per-port/vlan multicast 180 * context 181 * @msti: if MASTER flag set, this holds the VLANs MST instance 182 * @vlist: sorted list of VLAN entries 183 * @rcu: used for entry destruction 184 * 185 * This structure is shared between the global per-VLAN entries contained in 186 * the bridge rhashtable and the local per-port per-VLAN entries contained in 187 * the port's rhashtable. The union entries should be interpreted depending on 188 * the entry flags that are set. 189 */ 190 struct net_bridge_vlan { 191 struct rhash_head vnode; 192 struct rhash_head tnode; 193 u16 vid; 194 u16 flags; 195 u16 priv_flags; 196 u8 state; 197 struct pcpu_sw_netstats __percpu *stats; 198 union { 199 struct net_bridge *br; 200 struct net_bridge_port *port; 201 }; 202 union { 203 refcount_t refcnt; 204 struct net_bridge_vlan *brvlan; 205 }; 206 207 struct br_tunnel_info tinfo; 208 209 union { 210 struct net_bridge_mcast br_mcast_ctx; 211 struct net_bridge_mcast_port port_mcast_ctx; 212 }; 213 214 u16 msti; 215 216 struct list_head vlist; 217 218 struct rcu_head rcu; 219 }; 220 221 /** 222 * struct net_bridge_vlan_group 223 * 224 * @vlan_hash: VLAN entry rhashtable 225 * @vlan_list: sorted VLAN entry list 226 * @num_vlans: number of total VLAN entries 227 * @pvid: PVID VLAN id 228 * @pvid_state: PVID's STP state (e.g. forwarding, learning, blocking) 229 * 230 * IMPORTANT: Be careful when checking if there're VLAN entries using list 231 * primitives because the bridge can have entries in its list which 232 * are just for global context but not for filtering, i.e. they have 233 * the master flag set but not the brentry flag. If you have to check 234 * if there're "real" entries in the bridge please test @num_vlans 235 */ 236 struct net_bridge_vlan_group { 237 struct rhashtable vlan_hash; 238 struct rhashtable tunnel_hash; 239 struct list_head vlan_list; 240 u16 num_vlans; 241 u16 pvid; 242 u8 pvid_state; 243 }; 244 245 /* bridge fdb flags */ 246 enum { 247 BR_FDB_LOCAL, 248 BR_FDB_STATIC, 249 BR_FDB_STICKY, 250 BR_FDB_ADDED_BY_USER, 251 BR_FDB_ADDED_BY_EXT_LEARN, 252 BR_FDB_OFFLOADED, 253 BR_FDB_NOTIFY, 254 BR_FDB_NOTIFY_INACTIVE 255 }; 256 257 struct net_bridge_fdb_key { 258 mac_addr addr; 259 u16 vlan_id; 260 }; 261 262 struct net_bridge_fdb_entry { 263 struct rhash_head rhnode; 264 struct net_bridge_port *dst; 265 266 struct net_bridge_fdb_key key; 267 struct hlist_node fdb_node; 268 unsigned long flags; 269 270 /* write-heavy members should not affect lookups */ 271 unsigned long updated ____cacheline_aligned_in_smp; 272 unsigned long used; 273 274 struct rcu_head rcu; 275 }; 276 277 #define MDB_PG_FLAGS_PERMANENT BIT(0) 278 #define MDB_PG_FLAGS_OFFLOAD BIT(1) 279 #define MDB_PG_FLAGS_FAST_LEAVE BIT(2) 280 #define MDB_PG_FLAGS_STAR_EXCL BIT(3) 281 #define MDB_PG_FLAGS_BLOCKED BIT(4) 282 283 #define PG_SRC_ENT_LIMIT 32 284 285 #define BR_SGRP_F_DELETE BIT(0) 286 #define BR_SGRP_F_SEND BIT(1) 287 #define BR_SGRP_F_INSTALLED BIT(2) 288 289 struct net_bridge_mcast_gc { 290 struct hlist_node gc_node; 291 void (*destroy)(struct net_bridge_mcast_gc *gc); 292 }; 293 294 struct net_bridge_group_src { 295 struct hlist_node node; 296 297 struct br_ip addr; 298 struct net_bridge_port_group *pg; 299 u8 flags; 300 u8 src_query_rexmit_cnt; 301 struct timer_list timer; 302 303 struct net_bridge *br; 304 struct net_bridge_mcast_gc mcast_gc; 305 struct rcu_head rcu; 306 }; 307 308 struct net_bridge_port_group_sg_key { 309 struct net_bridge_port *port; 310 struct br_ip addr; 311 }; 312 313 struct net_bridge_port_group { 314 struct net_bridge_port_group __rcu *next; 315 struct net_bridge_port_group_sg_key key; 316 unsigned char eth_addr[ETH_ALEN] __aligned(2); 317 unsigned char flags; 318 unsigned char filter_mode; 319 unsigned char grp_query_rexmit_cnt; 320 unsigned char rt_protocol; 321 322 struct hlist_head src_list; 323 unsigned int src_ents; 324 struct timer_list timer; 325 struct timer_list rexmit_timer; 326 struct hlist_node mglist; 327 struct rb_root eht_set_tree; 328 struct rb_root eht_host_tree; 329 330 struct rhash_head rhnode; 331 struct net_bridge_mcast_gc mcast_gc; 332 struct rcu_head rcu; 333 }; 334 335 struct net_bridge_mdb_entry { 336 struct rhash_head rhnode; 337 struct net_bridge *br; 338 struct net_bridge_port_group __rcu *ports; 339 struct br_ip addr; 340 bool host_joined; 341 342 struct timer_list timer; 343 struct hlist_node mdb_node; 344 345 struct net_bridge_mcast_gc mcast_gc; 346 struct rcu_head rcu; 347 }; 348 349 struct net_bridge_port { 350 struct net_bridge *br; 351 struct net_device *dev; 352 netdevice_tracker dev_tracker; 353 struct list_head list; 354 355 unsigned long flags; 356 #ifdef CONFIG_BRIDGE_VLAN_FILTERING 357 struct net_bridge_vlan_group __rcu *vlgrp; 358 #endif 359 struct net_bridge_port __rcu *backup_port; 360 361 /* STP */ 362 u8 priority; 363 u8 state; 364 u16 port_no; 365 unsigned char topology_change_ack; 366 unsigned char config_pending; 367 port_id port_id; 368 port_id designated_port; 369 bridge_id designated_root; 370 bridge_id designated_bridge; 371 u32 path_cost; 372 u32 designated_cost; 373 unsigned long designated_age; 374 375 struct timer_list forward_delay_timer; 376 struct timer_list hold_timer; 377 struct timer_list message_age_timer; 378 struct kobject kobj; 379 struct rcu_head rcu; 380 381 struct net_bridge_mcast_port multicast_ctx; 382 383 #ifdef CONFIG_BRIDGE_IGMP_SNOOPING 384 struct bridge_mcast_stats __percpu *mcast_stats; 385 386 u32 multicast_eht_hosts_limit; 387 u32 multicast_eht_hosts_cnt; 388 struct hlist_head mglist; 389 #endif 390 391 #ifdef CONFIG_SYSFS 392 char sysfs_name[IFNAMSIZ]; 393 #endif 394 395 #ifdef CONFIG_NET_POLL_CONTROLLER 396 struct netpoll *np; 397 #endif 398 #ifdef CONFIG_NET_SWITCHDEV 399 /* Identifier used to group ports that share the same switchdev 400 * hardware domain. 401 */ 402 int hwdom; 403 int offload_count; 404 struct netdev_phys_item_id ppid; 405 #endif 406 u16 group_fwd_mask; 407 u16 backup_redirected_cnt; 408 409 struct bridge_stp_xstats stp_xstats; 410 }; 411 412 #define kobj_to_brport(obj) container_of(obj, struct net_bridge_port, kobj) 413 414 #define br_auto_port(p) ((p)->flags & BR_AUTO_MASK) 415 #define br_promisc_port(p) ((p)->flags & BR_PROMISC) 416 417 static inline struct net_bridge_port *br_port_get_rcu(const struct net_device *dev) 418 { 419 return rcu_dereference(dev->rx_handler_data); 420 } 421 422 static inline struct net_bridge_port *br_port_get_rtnl(const struct net_device *dev) 423 { 424 return netif_is_bridge_port(dev) ? 425 rtnl_dereference(dev->rx_handler_data) : NULL; 426 } 427 428 static inline struct net_bridge_port *br_port_get_rtnl_rcu(const struct net_device *dev) 429 { 430 return netif_is_bridge_port(dev) ? 431 rcu_dereference_rtnl(dev->rx_handler_data) : NULL; 432 } 433 434 enum net_bridge_opts { 435 BROPT_VLAN_ENABLED, 436 BROPT_VLAN_STATS_ENABLED, 437 BROPT_NF_CALL_IPTABLES, 438 BROPT_NF_CALL_IP6TABLES, 439 BROPT_NF_CALL_ARPTABLES, 440 BROPT_GROUP_ADDR_SET, 441 BROPT_MULTICAST_ENABLED, 442 BROPT_MULTICAST_QUERY_USE_IFADDR, 443 BROPT_MULTICAST_STATS_ENABLED, 444 BROPT_HAS_IPV6_ADDR, 445 BROPT_NEIGH_SUPPRESS_ENABLED, 446 BROPT_MTU_SET_BY_USER, 447 BROPT_VLAN_STATS_PER_PORT, 448 BROPT_NO_LL_LEARN, 449 BROPT_VLAN_BRIDGE_BINDING, 450 BROPT_MCAST_VLAN_SNOOPING_ENABLED, 451 BROPT_MST_ENABLED, 452 }; 453 454 struct net_bridge { 455 spinlock_t lock; 456 spinlock_t hash_lock; 457 struct hlist_head frame_type_list; 458 struct net_device *dev; 459 unsigned long options; 460 /* These fields are accessed on each packet */ 461 #ifdef CONFIG_BRIDGE_VLAN_FILTERING 462 __be16 vlan_proto; 463 u16 default_pvid; 464 struct net_bridge_vlan_group __rcu *vlgrp; 465 #endif 466 467 struct rhashtable fdb_hash_tbl; 468 struct list_head port_list; 469 #if IS_ENABLED(CONFIG_BRIDGE_NETFILTER) 470 union { 471 struct rtable fake_rtable; 472 struct rt6_info fake_rt6_info; 473 }; 474 #endif 475 u16 group_fwd_mask; 476 u16 group_fwd_mask_required; 477 478 /* STP */ 479 bridge_id designated_root; 480 bridge_id bridge_id; 481 unsigned char topology_change; 482 unsigned char topology_change_detected; 483 u16 root_port; 484 unsigned long max_age; 485 unsigned long hello_time; 486 unsigned long forward_delay; 487 unsigned long ageing_time; 488 unsigned long bridge_max_age; 489 unsigned long bridge_hello_time; 490 unsigned long bridge_forward_delay; 491 unsigned long bridge_ageing_time; 492 u32 root_path_cost; 493 494 u8 group_addr[ETH_ALEN]; 495 496 enum { 497 BR_NO_STP, /* no spanning tree */ 498 BR_KERNEL_STP, /* old STP in kernel */ 499 BR_USER_STP, /* new RSTP in userspace */ 500 } stp_enabled; 501 502 struct net_bridge_mcast multicast_ctx; 503 504 #ifdef CONFIG_BRIDGE_IGMP_SNOOPING 505 struct bridge_mcast_stats __percpu *mcast_stats; 506 507 u32 hash_max; 508 509 spinlock_t multicast_lock; 510 511 struct rhashtable mdb_hash_tbl; 512 struct rhashtable sg_port_tbl; 513 514 struct hlist_head mcast_gc_list; 515 struct hlist_head mdb_list; 516 517 struct work_struct mcast_gc_work; 518 #endif 519 520 struct timer_list hello_timer; 521 struct timer_list tcn_timer; 522 struct timer_list topology_change_timer; 523 struct delayed_work gc_work; 524 struct kobject *ifobj; 525 u32 auto_cnt; 526 527 #ifdef CONFIG_NET_SWITCHDEV 528 /* Counter used to make sure that hardware domains get unique 529 * identifiers in case a bridge spans multiple switchdev instances. 530 */ 531 int last_hwdom; 532 /* Bit mask of hardware domain numbers in use */ 533 unsigned long busy_hwdoms; 534 #endif 535 struct hlist_head fdb_list; 536 537 #if IS_ENABLED(CONFIG_BRIDGE_MRP) 538 struct hlist_head mrp_list; 539 #endif 540 #if IS_ENABLED(CONFIG_BRIDGE_CFM) 541 struct hlist_head mep_list; 542 #endif 543 }; 544 545 struct br_input_skb_cb { 546 struct net_device *brdev; 547 548 u16 frag_max_size; 549 #ifdef CONFIG_BRIDGE_IGMP_SNOOPING 550 u8 igmp; 551 u8 mrouters_only:1; 552 #endif 553 u8 proxyarp_replied:1; 554 u8 src_port_isolated:1; 555 #ifdef CONFIG_BRIDGE_VLAN_FILTERING 556 u8 vlan_filtered:1; 557 #endif 558 #ifdef CONFIG_NETFILTER_FAMILY_BRIDGE 559 u8 br_netfilter_broute:1; 560 #endif 561 562 #ifdef CONFIG_NET_SWITCHDEV 563 /* Set if TX data plane offloading is used towards at least one 564 * hardware domain. 565 */ 566 u8 tx_fwd_offload:1; 567 /* The switchdev hardware domain from which this packet was received. 568 * If skb->offload_fwd_mark was set, then this packet was already 569 * forwarded by hardware to the other ports in the source hardware 570 * domain, otherwise it wasn't. 571 */ 572 int src_hwdom; 573 /* Bit mask of hardware domains towards this packet has already been 574 * transmitted using the TX data plane offload. 575 */ 576 unsigned long fwd_hwdoms; 577 #endif 578 }; 579 580 #define BR_INPUT_SKB_CB(__skb) ((struct br_input_skb_cb *)(__skb)->cb) 581 582 #ifdef CONFIG_BRIDGE_IGMP_SNOOPING 583 # define BR_INPUT_SKB_CB_MROUTERS_ONLY(__skb) (BR_INPUT_SKB_CB(__skb)->mrouters_only) 584 #else 585 # define BR_INPUT_SKB_CB_MROUTERS_ONLY(__skb) (0) 586 #endif 587 588 #define br_printk(level, br, format, args...) \ 589 printk(level "%s: " format, (br)->dev->name, ##args) 590 591 #define br_err(__br, format, args...) \ 592 br_printk(KERN_ERR, __br, format, ##args) 593 #define br_warn(__br, format, args...) \ 594 br_printk(KERN_WARNING, __br, format, ##args) 595 #define br_notice(__br, format, args...) \ 596 br_printk(KERN_NOTICE, __br, format, ##args) 597 #define br_info(__br, format, args...) \ 598 br_printk(KERN_INFO, __br, format, ##args) 599 600 #define br_debug(br, format, args...) \ 601 pr_debug("%s: " format, (br)->dev->name, ##args) 602 603 /* called under bridge lock */ 604 static inline int br_is_root_bridge(const struct net_bridge *br) 605 { 606 return !memcmp(&br->bridge_id, &br->designated_root, 8); 607 } 608 609 /* check if a VLAN entry is global */ 610 static inline bool br_vlan_is_master(const struct net_bridge_vlan *v) 611 { 612 return v->flags & BRIDGE_VLAN_INFO_MASTER; 613 } 614 615 /* check if a VLAN entry is used by the bridge */ 616 static inline bool br_vlan_is_brentry(const struct net_bridge_vlan *v) 617 { 618 return v->flags & BRIDGE_VLAN_INFO_BRENTRY; 619 } 620 621 /* check if we should use the vlan entry, returns false if it's only context */ 622 static inline bool br_vlan_should_use(const struct net_bridge_vlan *v) 623 { 624 if (br_vlan_is_master(v)) { 625 if (br_vlan_is_brentry(v)) 626 return true; 627 else 628 return false; 629 } 630 631 return true; 632 } 633 634 static inline bool nbp_state_should_learn(const struct net_bridge_port *p) 635 { 636 return p->state == BR_STATE_LEARNING || p->state == BR_STATE_FORWARDING; 637 } 638 639 static inline bool br_vlan_valid_id(u16 vid, struct netlink_ext_ack *extack) 640 { 641 bool ret = vid > 0 && vid < VLAN_VID_MASK; 642 643 if (!ret) 644 NL_SET_ERR_MSG_MOD(extack, "Vlan id is invalid"); 645 646 return ret; 647 } 648 649 static inline bool br_vlan_valid_range(const struct bridge_vlan_info *cur, 650 const struct bridge_vlan_info *last, 651 struct netlink_ext_ack *extack) 652 { 653 /* pvid flag is not allowed in ranges */ 654 if (cur->flags & BRIDGE_VLAN_INFO_PVID) { 655 NL_SET_ERR_MSG_MOD(extack, "Pvid isn't allowed in a range"); 656 return false; 657 } 658 659 /* when cur is the range end, check if: 660 * - it has range start flag 661 * - range ids are invalid (end is equal to or before start) 662 */ 663 if (last) { 664 if (cur->flags & BRIDGE_VLAN_INFO_RANGE_BEGIN) { 665 NL_SET_ERR_MSG_MOD(extack, "Found a new vlan range start while processing one"); 666 return false; 667 } else if (!(cur->flags & BRIDGE_VLAN_INFO_RANGE_END)) { 668 NL_SET_ERR_MSG_MOD(extack, "Vlan range end flag is missing"); 669 return false; 670 } else if (cur->vid <= last->vid) { 671 NL_SET_ERR_MSG_MOD(extack, "End vlan id is less than or equal to start vlan id"); 672 return false; 673 } 674 } 675 676 /* check for required range flags */ 677 if (!(cur->flags & (BRIDGE_VLAN_INFO_RANGE_BEGIN | 678 BRIDGE_VLAN_INFO_RANGE_END))) { 679 NL_SET_ERR_MSG_MOD(extack, "Both vlan range flags are missing"); 680 return false; 681 } 682 683 return true; 684 } 685 686 static inline u8 br_vlan_multicast_router(const struct net_bridge_vlan *v) 687 { 688 u8 mcast_router = MDB_RTR_TYPE_DISABLED; 689 690 #ifdef CONFIG_BRIDGE_IGMP_SNOOPING 691 if (!br_vlan_is_master(v)) 692 mcast_router = v->port_mcast_ctx.multicast_router; 693 else 694 mcast_router = v->br_mcast_ctx.multicast_router; 695 #endif 696 697 return mcast_router; 698 } 699 700 static inline int br_afspec_cmd_to_rtm(int cmd) 701 { 702 switch (cmd) { 703 case RTM_SETLINK: 704 return RTM_NEWVLAN; 705 case RTM_DELLINK: 706 return RTM_DELVLAN; 707 } 708 709 return 0; 710 } 711 712 static inline int br_opt_get(const struct net_bridge *br, 713 enum net_bridge_opts opt) 714 { 715 return test_bit(opt, &br->options); 716 } 717 718 int br_boolopt_toggle(struct net_bridge *br, enum br_boolopt_id opt, bool on, 719 struct netlink_ext_ack *extack); 720 int br_boolopt_get(const struct net_bridge *br, enum br_boolopt_id opt); 721 int br_boolopt_multi_toggle(struct net_bridge *br, 722 struct br_boolopt_multi *bm, 723 struct netlink_ext_ack *extack); 724 void br_boolopt_multi_get(const struct net_bridge *br, 725 struct br_boolopt_multi *bm); 726 void br_opt_toggle(struct net_bridge *br, enum net_bridge_opts opt, bool on); 727 728 /* br_device.c */ 729 void br_dev_setup(struct net_device *dev); 730 void br_dev_delete(struct net_device *dev, struct list_head *list); 731 netdev_tx_t br_dev_xmit(struct sk_buff *skb, struct net_device *dev); 732 #ifdef CONFIG_NET_POLL_CONTROLLER 733 static inline void br_netpoll_send_skb(const struct net_bridge_port *p, 734 struct sk_buff *skb) 735 { 736 netpoll_send_skb(p->np, skb); 737 } 738 739 int br_netpoll_enable(struct net_bridge_port *p); 740 void br_netpoll_disable(struct net_bridge_port *p); 741 #else 742 static inline void br_netpoll_send_skb(const struct net_bridge_port *p, 743 struct sk_buff *skb) 744 { 745 } 746 747 static inline int br_netpoll_enable(struct net_bridge_port *p) 748 { 749 return 0; 750 } 751 752 static inline void br_netpoll_disable(struct net_bridge_port *p) 753 { 754 } 755 #endif 756 757 /* br_fdb.c */ 758 int br_fdb_init(void); 759 void br_fdb_fini(void); 760 int br_fdb_hash_init(struct net_bridge *br); 761 void br_fdb_hash_fini(struct net_bridge *br); 762 void br_fdb_flush(struct net_bridge *br); 763 void br_fdb_find_delete_local(struct net_bridge *br, 764 const struct net_bridge_port *p, 765 const unsigned char *addr, u16 vid); 766 void br_fdb_changeaddr(struct net_bridge_port *p, const unsigned char *newaddr); 767 void br_fdb_change_mac_address(struct net_bridge *br, const u8 *newaddr); 768 void br_fdb_cleanup(struct work_struct *work); 769 void br_fdb_delete_by_port(struct net_bridge *br, 770 const struct net_bridge_port *p, u16 vid, int do_all); 771 struct net_bridge_fdb_entry *br_fdb_find_rcu(struct net_bridge *br, 772 const unsigned char *addr, 773 __u16 vid); 774 int br_fdb_test_addr(struct net_device *dev, unsigned char *addr); 775 int br_fdb_fillbuf(struct net_bridge *br, void *buf, unsigned long count, 776 unsigned long off); 777 int br_fdb_add_local(struct net_bridge *br, struct net_bridge_port *source, 778 const unsigned char *addr, u16 vid); 779 void br_fdb_update(struct net_bridge *br, struct net_bridge_port *source, 780 const unsigned char *addr, u16 vid, unsigned long flags); 781 782 int br_fdb_delete(struct ndmsg *ndm, struct nlattr *tb[], 783 struct net_device *dev, const unsigned char *addr, u16 vid); 784 int br_fdb_add(struct ndmsg *nlh, struct nlattr *tb[], struct net_device *dev, 785 const unsigned char *addr, u16 vid, u16 nlh_flags, 786 struct netlink_ext_ack *extack); 787 int br_fdb_dump(struct sk_buff *skb, struct netlink_callback *cb, 788 struct net_device *dev, struct net_device *fdev, int *idx); 789 int br_fdb_get(struct sk_buff *skb, struct nlattr *tb[], struct net_device *dev, 790 const unsigned char *addr, u16 vid, u32 portid, u32 seq, 791 struct netlink_ext_ack *extack); 792 int br_fdb_sync_static(struct net_bridge *br, struct net_bridge_port *p); 793 void br_fdb_unsync_static(struct net_bridge *br, struct net_bridge_port *p); 794 int br_fdb_external_learn_add(struct net_bridge *br, struct net_bridge_port *p, 795 const unsigned char *addr, u16 vid, 796 bool swdev_notify); 797 int br_fdb_external_learn_del(struct net_bridge *br, struct net_bridge_port *p, 798 const unsigned char *addr, u16 vid, 799 bool swdev_notify); 800 void br_fdb_offloaded_set(struct net_bridge *br, struct net_bridge_port *p, 801 const unsigned char *addr, u16 vid, bool offloaded); 802 803 /* br_forward.c */ 804 enum br_pkt_type { 805 BR_PKT_UNICAST, 806 BR_PKT_MULTICAST, 807 BR_PKT_BROADCAST 808 }; 809 int br_dev_queue_push_xmit(struct net *net, struct sock *sk, struct sk_buff *skb); 810 void br_forward(const struct net_bridge_port *to, struct sk_buff *skb, 811 bool local_rcv, bool local_orig); 812 int br_forward_finish(struct net *net, struct sock *sk, struct sk_buff *skb); 813 void br_flood(struct net_bridge *br, struct sk_buff *skb, 814 enum br_pkt_type pkt_type, bool local_rcv, bool local_orig); 815 816 /* return true if both source port and dest port are isolated */ 817 static inline bool br_skb_isolated(const struct net_bridge_port *to, 818 const struct sk_buff *skb) 819 { 820 return BR_INPUT_SKB_CB(skb)->src_port_isolated && 821 (to->flags & BR_ISOLATED); 822 } 823 824 /* br_if.c */ 825 void br_port_carrier_check(struct net_bridge_port *p, bool *notified); 826 int br_add_bridge(struct net *net, const char *name); 827 int br_del_bridge(struct net *net, const char *name); 828 int br_add_if(struct net_bridge *br, struct net_device *dev, 829 struct netlink_ext_ack *extack); 830 int br_del_if(struct net_bridge *br, struct net_device *dev); 831 void br_mtu_auto_adjust(struct net_bridge *br); 832 netdev_features_t br_features_recompute(struct net_bridge *br, 833 netdev_features_t features); 834 void br_port_flags_change(struct net_bridge_port *port, unsigned long mask); 835 void br_manage_promisc(struct net_bridge *br); 836 int nbp_backup_change(struct net_bridge_port *p, struct net_device *backup_dev); 837 838 /* br_input.c */ 839 int br_handle_frame_finish(struct net *net, struct sock *sk, struct sk_buff *skb); 840 rx_handler_func_t *br_get_rx_handler(const struct net_device *dev); 841 842 struct br_frame_type { 843 __be16 type; 844 int (*frame_handler)(struct net_bridge_port *port, 845 struct sk_buff *skb); 846 struct hlist_node list; 847 }; 848 849 void br_add_frame(struct net_bridge *br, struct br_frame_type *ft); 850 void br_del_frame(struct net_bridge *br, struct br_frame_type *ft); 851 852 static inline bool br_rx_handler_check_rcu(const struct net_device *dev) 853 { 854 return rcu_dereference(dev->rx_handler) == br_get_rx_handler(dev); 855 } 856 857 static inline bool br_rx_handler_check_rtnl(const struct net_device *dev) 858 { 859 return rcu_dereference_rtnl(dev->rx_handler) == br_get_rx_handler(dev); 860 } 861 862 static inline struct net_bridge_port *br_port_get_check_rcu(const struct net_device *dev) 863 { 864 return br_rx_handler_check_rcu(dev) ? br_port_get_rcu(dev) : NULL; 865 } 866 867 static inline struct net_bridge_port * 868 br_port_get_check_rtnl(const struct net_device *dev) 869 { 870 return br_rx_handler_check_rtnl(dev) ? br_port_get_rtnl_rcu(dev) : NULL; 871 } 872 873 /* br_ioctl.c */ 874 int br_dev_siocdevprivate(struct net_device *dev, struct ifreq *rq, 875 void __user *data, int cmd); 876 int br_ioctl_stub(struct net *net, struct net_bridge *br, unsigned int cmd, 877 struct ifreq *ifr, void __user *uarg); 878 879 /* br_multicast.c */ 880 #ifdef CONFIG_BRIDGE_IGMP_SNOOPING 881 int br_multicast_rcv(struct net_bridge_mcast **brmctx, 882 struct net_bridge_mcast_port **pmctx, 883 struct net_bridge_vlan *vlan, 884 struct sk_buff *skb, u16 vid); 885 struct net_bridge_mdb_entry *br_mdb_get(struct net_bridge_mcast *brmctx, 886 struct sk_buff *skb, u16 vid); 887 int br_multicast_add_port(struct net_bridge_port *port); 888 void br_multicast_del_port(struct net_bridge_port *port); 889 void br_multicast_enable_port(struct net_bridge_port *port); 890 void br_multicast_disable_port(struct net_bridge_port *port); 891 void br_multicast_init(struct net_bridge *br); 892 void br_multicast_join_snoopers(struct net_bridge *br); 893 void br_multicast_leave_snoopers(struct net_bridge *br); 894 void br_multicast_open(struct net_bridge *br); 895 void br_multicast_stop(struct net_bridge *br); 896 void br_multicast_dev_del(struct net_bridge *br); 897 void br_multicast_flood(struct net_bridge_mdb_entry *mdst, struct sk_buff *skb, 898 struct net_bridge_mcast *brmctx, 899 bool local_rcv, bool local_orig); 900 int br_multicast_set_router(struct net_bridge_mcast *brmctx, unsigned long val); 901 int br_multicast_set_port_router(struct net_bridge_mcast_port *pmctx, 902 unsigned long val); 903 int br_multicast_set_vlan_router(struct net_bridge_vlan *v, u8 mcast_router); 904 int br_multicast_toggle(struct net_bridge *br, unsigned long val, 905 struct netlink_ext_ack *extack); 906 int br_multicast_set_querier(struct net_bridge_mcast *brmctx, unsigned long val); 907 int br_multicast_set_hash_max(struct net_bridge *br, unsigned long val); 908 int br_multicast_set_igmp_version(struct net_bridge_mcast *brmctx, 909 unsigned long val); 910 #if IS_ENABLED(CONFIG_IPV6) 911 int br_multicast_set_mld_version(struct net_bridge_mcast *brmctx, 912 unsigned long val); 913 #endif 914 struct net_bridge_mdb_entry * 915 br_mdb_ip_get(struct net_bridge *br, struct br_ip *dst); 916 struct net_bridge_mdb_entry * 917 br_multicast_new_group(struct net_bridge *br, struct br_ip *group); 918 struct net_bridge_port_group * 919 br_multicast_new_port_group(struct net_bridge_port *port, struct br_ip *group, 920 struct net_bridge_port_group __rcu *next, 921 unsigned char flags, const unsigned char *src, 922 u8 filter_mode, u8 rt_protocol); 923 int br_mdb_hash_init(struct net_bridge *br); 924 void br_mdb_hash_fini(struct net_bridge *br); 925 void br_mdb_notify(struct net_device *dev, struct net_bridge_mdb_entry *mp, 926 struct net_bridge_port_group *pg, int type); 927 void br_rtr_notify(struct net_device *dev, struct net_bridge_mcast_port *pmctx, 928 int type); 929 void br_multicast_del_pg(struct net_bridge_mdb_entry *mp, 930 struct net_bridge_port_group *pg, 931 struct net_bridge_port_group __rcu **pp); 932 void br_multicast_count(struct net_bridge *br, 933 const struct net_bridge_port *p, 934 const struct sk_buff *skb, u8 type, u8 dir); 935 int br_multicast_init_stats(struct net_bridge *br); 936 void br_multicast_uninit_stats(struct net_bridge *br); 937 void br_multicast_get_stats(const struct net_bridge *br, 938 const struct net_bridge_port *p, 939 struct br_mcast_stats *dest); 940 void br_mdb_init(void); 941 void br_mdb_uninit(void); 942 void br_multicast_host_join(const struct net_bridge_mcast *brmctx, 943 struct net_bridge_mdb_entry *mp, bool notify); 944 void br_multicast_host_leave(struct net_bridge_mdb_entry *mp, bool notify); 945 void br_multicast_star_g_handle_mode(struct net_bridge_port_group *pg, 946 u8 filter_mode); 947 void br_multicast_sg_add_exclude_ports(struct net_bridge_mdb_entry *star_mp, 948 struct net_bridge_port_group *sg); 949 struct net_bridge_group_src * 950 br_multicast_find_group_src(struct net_bridge_port_group *pg, struct br_ip *ip); 951 void br_multicast_del_group_src(struct net_bridge_group_src *src, 952 bool fastleave); 953 void br_multicast_ctx_init(struct net_bridge *br, 954 struct net_bridge_vlan *vlan, 955 struct net_bridge_mcast *brmctx); 956 void br_multicast_ctx_deinit(struct net_bridge_mcast *brmctx); 957 void br_multicast_port_ctx_init(struct net_bridge_port *port, 958 struct net_bridge_vlan *vlan, 959 struct net_bridge_mcast_port *pmctx); 960 void br_multicast_port_ctx_deinit(struct net_bridge_mcast_port *pmctx); 961 void br_multicast_toggle_one_vlan(struct net_bridge_vlan *vlan, bool on); 962 int br_multicast_toggle_vlan_snooping(struct net_bridge *br, bool on, 963 struct netlink_ext_ack *extack); 964 bool br_multicast_toggle_global_vlan(struct net_bridge_vlan *vlan, bool on); 965 966 int br_rports_fill_info(struct sk_buff *skb, 967 const struct net_bridge_mcast *brmctx); 968 int br_multicast_dump_querier_state(struct sk_buff *skb, 969 const struct net_bridge_mcast *brmctx, 970 int nest_attr); 971 size_t br_multicast_querier_state_size(void); 972 size_t br_rports_size(const struct net_bridge_mcast *brmctx); 973 void br_multicast_set_query_intvl(struct net_bridge_mcast *brmctx, 974 unsigned long val); 975 void br_multicast_set_startup_query_intvl(struct net_bridge_mcast *brmctx, 976 unsigned long val); 977 978 static inline bool br_group_is_l2(const struct br_ip *group) 979 { 980 return group->proto == 0; 981 } 982 983 #define mlock_dereference(X, br) \ 984 rcu_dereference_protected(X, lockdep_is_held(&br->multicast_lock)) 985 986 static inline struct hlist_node * 987 br_multicast_get_first_rport_node(struct net_bridge_mcast *brmctx, 988 struct sk_buff *skb) 989 { 990 #if IS_ENABLED(CONFIG_IPV6) 991 if (skb->protocol == htons(ETH_P_IPV6)) 992 return rcu_dereference(hlist_first_rcu(&brmctx->ip6_mc_router_list)); 993 #endif 994 return rcu_dereference(hlist_first_rcu(&brmctx->ip4_mc_router_list)); 995 } 996 997 static inline struct net_bridge_port * 998 br_multicast_rport_from_node_skb(struct hlist_node *rp, struct sk_buff *skb) 999 { 1000 struct net_bridge_mcast_port *mctx; 1001 1002 #if IS_ENABLED(CONFIG_IPV6) 1003 if (skb->protocol == htons(ETH_P_IPV6)) 1004 mctx = hlist_entry_safe(rp, struct net_bridge_mcast_port, 1005 ip6_rlist); 1006 else 1007 #endif 1008 mctx = hlist_entry_safe(rp, struct net_bridge_mcast_port, 1009 ip4_rlist); 1010 1011 if (mctx) 1012 return mctx->port; 1013 else 1014 return NULL; 1015 } 1016 1017 static inline bool br_ip4_multicast_is_router(struct net_bridge_mcast *brmctx) 1018 { 1019 return timer_pending(&brmctx->ip4_mc_router_timer); 1020 } 1021 1022 static inline bool br_ip6_multicast_is_router(struct net_bridge_mcast *brmctx) 1023 { 1024 #if IS_ENABLED(CONFIG_IPV6) 1025 return timer_pending(&brmctx->ip6_mc_router_timer); 1026 #else 1027 return false; 1028 #endif 1029 } 1030 1031 static inline bool 1032 br_multicast_is_router(struct net_bridge_mcast *brmctx, struct sk_buff *skb) 1033 { 1034 switch (brmctx->multicast_router) { 1035 case MDB_RTR_TYPE_PERM: 1036 return true; 1037 case MDB_RTR_TYPE_TEMP_QUERY: 1038 if (skb) { 1039 if (skb->protocol == htons(ETH_P_IP)) 1040 return br_ip4_multicast_is_router(brmctx); 1041 else if (skb->protocol == htons(ETH_P_IPV6)) 1042 return br_ip6_multicast_is_router(brmctx); 1043 } else { 1044 return br_ip4_multicast_is_router(brmctx) || 1045 br_ip6_multicast_is_router(brmctx); 1046 } 1047 fallthrough; 1048 default: 1049 return false; 1050 } 1051 } 1052 1053 static inline bool 1054 __br_multicast_querier_exists(struct net_bridge_mcast *brmctx, 1055 struct bridge_mcast_other_query *querier, 1056 const bool is_ipv6) 1057 { 1058 bool own_querier_enabled; 1059 1060 if (brmctx->multicast_querier) { 1061 if (is_ipv6 && !br_opt_get(brmctx->br, BROPT_HAS_IPV6_ADDR)) 1062 own_querier_enabled = false; 1063 else 1064 own_querier_enabled = true; 1065 } else { 1066 own_querier_enabled = false; 1067 } 1068 1069 return time_is_before_jiffies(querier->delay_time) && 1070 (own_querier_enabled || timer_pending(&querier->timer)); 1071 } 1072 1073 static inline bool br_multicast_querier_exists(struct net_bridge_mcast *brmctx, 1074 struct ethhdr *eth, 1075 const struct net_bridge_mdb_entry *mdb) 1076 { 1077 switch (eth->h_proto) { 1078 case (htons(ETH_P_IP)): 1079 return __br_multicast_querier_exists(brmctx, 1080 &brmctx->ip4_other_query, false); 1081 #if IS_ENABLED(CONFIG_IPV6) 1082 case (htons(ETH_P_IPV6)): 1083 return __br_multicast_querier_exists(brmctx, 1084 &brmctx->ip6_other_query, true); 1085 #endif 1086 default: 1087 return !!mdb && br_group_is_l2(&mdb->addr); 1088 } 1089 } 1090 1091 static inline bool br_multicast_is_star_g(const struct br_ip *ip) 1092 { 1093 switch (ip->proto) { 1094 case htons(ETH_P_IP): 1095 return ipv4_is_zeronet(ip->src.ip4); 1096 #if IS_ENABLED(CONFIG_IPV6) 1097 case htons(ETH_P_IPV6): 1098 return ipv6_addr_any(&ip->src.ip6); 1099 #endif 1100 default: 1101 return false; 1102 } 1103 } 1104 1105 static inline bool 1106 br_multicast_should_handle_mode(const struct net_bridge_mcast *brmctx, 1107 __be16 proto) 1108 { 1109 switch (proto) { 1110 case htons(ETH_P_IP): 1111 return !!(brmctx->multicast_igmp_version == 3); 1112 #if IS_ENABLED(CONFIG_IPV6) 1113 case htons(ETH_P_IPV6): 1114 return !!(brmctx->multicast_mld_version == 2); 1115 #endif 1116 default: 1117 return false; 1118 } 1119 } 1120 1121 static inline int br_multicast_igmp_type(const struct sk_buff *skb) 1122 { 1123 return BR_INPUT_SKB_CB(skb)->igmp; 1124 } 1125 1126 static inline unsigned long br_multicast_lmqt(const struct net_bridge_mcast *brmctx) 1127 { 1128 return brmctx->multicast_last_member_interval * 1129 brmctx->multicast_last_member_count; 1130 } 1131 1132 static inline unsigned long br_multicast_gmi(const struct net_bridge_mcast *brmctx) 1133 { 1134 return brmctx->multicast_membership_interval; 1135 } 1136 1137 static inline bool 1138 br_multicast_ctx_is_vlan(const struct net_bridge_mcast *brmctx) 1139 { 1140 return !!brmctx->vlan; 1141 } 1142 1143 static inline bool 1144 br_multicast_port_ctx_is_vlan(const struct net_bridge_mcast_port *pmctx) 1145 { 1146 return !!pmctx->vlan; 1147 } 1148 1149 static inline struct net_bridge_mcast * 1150 br_multicast_port_ctx_get_global(const struct net_bridge_mcast_port *pmctx) 1151 { 1152 if (!br_multicast_port_ctx_is_vlan(pmctx)) 1153 return &pmctx->port->br->multicast_ctx; 1154 else 1155 return &pmctx->vlan->brvlan->br_mcast_ctx; 1156 } 1157 1158 static inline bool 1159 br_multicast_ctx_vlan_global_disabled(const struct net_bridge_mcast *brmctx) 1160 { 1161 return br_multicast_ctx_is_vlan(brmctx) && 1162 (!br_opt_get(brmctx->br, BROPT_MCAST_VLAN_SNOOPING_ENABLED) || 1163 !(brmctx->vlan->priv_flags & BR_VLFLAG_GLOBAL_MCAST_ENABLED)); 1164 } 1165 1166 static inline bool 1167 br_multicast_ctx_vlan_disabled(const struct net_bridge_mcast *brmctx) 1168 { 1169 return br_multicast_ctx_is_vlan(brmctx) && 1170 !(brmctx->vlan->priv_flags & BR_VLFLAG_MCAST_ENABLED); 1171 } 1172 1173 static inline bool 1174 br_multicast_port_ctx_vlan_disabled(const struct net_bridge_mcast_port *pmctx) 1175 { 1176 return br_multicast_port_ctx_is_vlan(pmctx) && 1177 !(pmctx->vlan->priv_flags & BR_VLFLAG_MCAST_ENABLED); 1178 } 1179 1180 static inline bool 1181 br_multicast_port_ctx_state_disabled(const struct net_bridge_mcast_port *pmctx) 1182 { 1183 return pmctx->port->state == BR_STATE_DISABLED || 1184 (br_multicast_port_ctx_is_vlan(pmctx) && 1185 (br_multicast_port_ctx_vlan_disabled(pmctx) || 1186 pmctx->vlan->state == BR_STATE_DISABLED)); 1187 } 1188 1189 static inline bool 1190 br_multicast_port_ctx_state_stopped(const struct net_bridge_mcast_port *pmctx) 1191 { 1192 return br_multicast_port_ctx_state_disabled(pmctx) || 1193 pmctx->port->state == BR_STATE_BLOCKING || 1194 (br_multicast_port_ctx_is_vlan(pmctx) && 1195 pmctx->vlan->state == BR_STATE_BLOCKING); 1196 } 1197 1198 static inline bool 1199 br_rports_have_mc_router(const struct net_bridge_mcast *brmctx) 1200 { 1201 #if IS_ENABLED(CONFIG_IPV6) 1202 return !hlist_empty(&brmctx->ip4_mc_router_list) || 1203 !hlist_empty(&brmctx->ip6_mc_router_list); 1204 #else 1205 return !hlist_empty(&brmctx->ip4_mc_router_list); 1206 #endif 1207 } 1208 1209 static inline bool 1210 br_multicast_ctx_options_equal(const struct net_bridge_mcast *brmctx1, 1211 const struct net_bridge_mcast *brmctx2) 1212 { 1213 return brmctx1->multicast_igmp_version == 1214 brmctx2->multicast_igmp_version && 1215 brmctx1->multicast_last_member_count == 1216 brmctx2->multicast_last_member_count && 1217 brmctx1->multicast_startup_query_count == 1218 brmctx2->multicast_startup_query_count && 1219 brmctx1->multicast_last_member_interval == 1220 brmctx2->multicast_last_member_interval && 1221 brmctx1->multicast_membership_interval == 1222 brmctx2->multicast_membership_interval && 1223 brmctx1->multicast_querier_interval == 1224 brmctx2->multicast_querier_interval && 1225 brmctx1->multicast_query_interval == 1226 brmctx2->multicast_query_interval && 1227 brmctx1->multicast_query_response_interval == 1228 brmctx2->multicast_query_response_interval && 1229 brmctx1->multicast_startup_query_interval == 1230 brmctx2->multicast_startup_query_interval && 1231 brmctx1->multicast_querier == brmctx2->multicast_querier && 1232 brmctx1->multicast_router == brmctx2->multicast_router && 1233 !br_rports_have_mc_router(brmctx1) && 1234 !br_rports_have_mc_router(brmctx2) && 1235 #if IS_ENABLED(CONFIG_IPV6) 1236 brmctx1->multicast_mld_version == 1237 brmctx2->multicast_mld_version && 1238 #endif 1239 true; 1240 } 1241 1242 static inline bool 1243 br_multicast_ctx_matches_vlan_snooping(const struct net_bridge_mcast *brmctx) 1244 { 1245 bool vlan_snooping_enabled; 1246 1247 vlan_snooping_enabled = !!br_opt_get(brmctx->br, 1248 BROPT_MCAST_VLAN_SNOOPING_ENABLED); 1249 1250 return !!(vlan_snooping_enabled == br_multicast_ctx_is_vlan(brmctx)); 1251 } 1252 #else 1253 static inline int br_multicast_rcv(struct net_bridge_mcast **brmctx, 1254 struct net_bridge_mcast_port **pmctx, 1255 struct net_bridge_vlan *vlan, 1256 struct sk_buff *skb, 1257 u16 vid) 1258 { 1259 return 0; 1260 } 1261 1262 static inline struct net_bridge_mdb_entry *br_mdb_get(struct net_bridge_mcast *brmctx, 1263 struct sk_buff *skb, u16 vid) 1264 { 1265 return NULL; 1266 } 1267 1268 static inline int br_multicast_add_port(struct net_bridge_port *port) 1269 { 1270 return 0; 1271 } 1272 1273 static inline void br_multicast_del_port(struct net_bridge_port *port) 1274 { 1275 } 1276 1277 static inline void br_multicast_enable_port(struct net_bridge_port *port) 1278 { 1279 } 1280 1281 static inline void br_multicast_disable_port(struct net_bridge_port *port) 1282 { 1283 } 1284 1285 static inline void br_multicast_init(struct net_bridge *br) 1286 { 1287 } 1288 1289 static inline void br_multicast_join_snoopers(struct net_bridge *br) 1290 { 1291 } 1292 1293 static inline void br_multicast_leave_snoopers(struct net_bridge *br) 1294 { 1295 } 1296 1297 static inline void br_multicast_open(struct net_bridge *br) 1298 { 1299 } 1300 1301 static inline void br_multicast_stop(struct net_bridge *br) 1302 { 1303 } 1304 1305 static inline void br_multicast_dev_del(struct net_bridge *br) 1306 { 1307 } 1308 1309 static inline void br_multicast_flood(struct net_bridge_mdb_entry *mdst, 1310 struct sk_buff *skb, 1311 struct net_bridge_mcast *brmctx, 1312 bool local_rcv, bool local_orig) 1313 { 1314 } 1315 1316 static inline bool br_multicast_is_router(struct net_bridge_mcast *brmctx, 1317 struct sk_buff *skb) 1318 { 1319 return false; 1320 } 1321 1322 static inline bool br_multicast_querier_exists(struct net_bridge_mcast *brmctx, 1323 struct ethhdr *eth, 1324 const struct net_bridge_mdb_entry *mdb) 1325 { 1326 return false; 1327 } 1328 1329 static inline void br_mdb_init(void) 1330 { 1331 } 1332 1333 static inline void br_mdb_uninit(void) 1334 { 1335 } 1336 1337 static inline int br_mdb_hash_init(struct net_bridge *br) 1338 { 1339 return 0; 1340 } 1341 1342 static inline void br_mdb_hash_fini(struct net_bridge *br) 1343 { 1344 } 1345 1346 static inline void br_multicast_count(struct net_bridge *br, 1347 const struct net_bridge_port *p, 1348 const struct sk_buff *skb, 1349 u8 type, u8 dir) 1350 { 1351 } 1352 1353 static inline int br_multicast_init_stats(struct net_bridge *br) 1354 { 1355 return 0; 1356 } 1357 1358 static inline void br_multicast_uninit_stats(struct net_bridge *br) 1359 { 1360 } 1361 1362 static inline int br_multicast_igmp_type(const struct sk_buff *skb) 1363 { 1364 return 0; 1365 } 1366 1367 static inline void br_multicast_ctx_init(struct net_bridge *br, 1368 struct net_bridge_vlan *vlan, 1369 struct net_bridge_mcast *brmctx) 1370 { 1371 } 1372 1373 static inline void br_multicast_ctx_deinit(struct net_bridge_mcast *brmctx) 1374 { 1375 } 1376 1377 static inline void br_multicast_port_ctx_init(struct net_bridge_port *port, 1378 struct net_bridge_vlan *vlan, 1379 struct net_bridge_mcast_port *pmctx) 1380 { 1381 } 1382 1383 static inline void br_multicast_port_ctx_deinit(struct net_bridge_mcast_port *pmctx) 1384 { 1385 } 1386 1387 static inline void br_multicast_toggle_one_vlan(struct net_bridge_vlan *vlan, 1388 bool on) 1389 { 1390 } 1391 1392 static inline int br_multicast_toggle_vlan_snooping(struct net_bridge *br, 1393 bool on, 1394 struct netlink_ext_ack *extack) 1395 { 1396 return -EOPNOTSUPP; 1397 } 1398 1399 static inline bool br_multicast_toggle_global_vlan(struct net_bridge_vlan *vlan, 1400 bool on) 1401 { 1402 return false; 1403 } 1404 1405 static inline bool 1406 br_multicast_ctx_options_equal(const struct net_bridge_mcast *brmctx1, 1407 const struct net_bridge_mcast *brmctx2) 1408 { 1409 return true; 1410 } 1411 #endif 1412 1413 /* br_vlan.c */ 1414 #ifdef CONFIG_BRIDGE_VLAN_FILTERING 1415 bool br_allowed_ingress(const struct net_bridge *br, 1416 struct net_bridge_vlan_group *vg, struct sk_buff *skb, 1417 u16 *vid, u8 *state, 1418 struct net_bridge_vlan **vlan); 1419 bool br_allowed_egress(struct net_bridge_vlan_group *vg, 1420 const struct sk_buff *skb); 1421 bool br_should_learn(struct net_bridge_port *p, struct sk_buff *skb, u16 *vid); 1422 struct sk_buff *br_handle_vlan(struct net_bridge *br, 1423 const struct net_bridge_port *port, 1424 struct net_bridge_vlan_group *vg, 1425 struct sk_buff *skb); 1426 int br_vlan_add(struct net_bridge *br, u16 vid, u16 flags, 1427 bool *changed, struct netlink_ext_ack *extack); 1428 int br_vlan_delete(struct net_bridge *br, u16 vid); 1429 void br_vlan_flush(struct net_bridge *br); 1430 struct net_bridge_vlan *br_vlan_find(struct net_bridge_vlan_group *vg, u16 vid); 1431 void br_recalculate_fwd_mask(struct net_bridge *br); 1432 int br_vlan_filter_toggle(struct net_bridge *br, unsigned long val, 1433 struct netlink_ext_ack *extack); 1434 int __br_vlan_set_proto(struct net_bridge *br, __be16 proto, 1435 struct netlink_ext_ack *extack); 1436 int br_vlan_set_proto(struct net_bridge *br, unsigned long val, 1437 struct netlink_ext_ack *extack); 1438 int br_vlan_set_stats(struct net_bridge *br, unsigned long val); 1439 int br_vlan_set_stats_per_port(struct net_bridge *br, unsigned long val); 1440 int br_vlan_init(struct net_bridge *br); 1441 int br_vlan_set_default_pvid(struct net_bridge *br, unsigned long val, 1442 struct netlink_ext_ack *extack); 1443 int __br_vlan_set_default_pvid(struct net_bridge *br, u16 pvid, 1444 struct netlink_ext_ack *extack); 1445 int nbp_vlan_add(struct net_bridge_port *port, u16 vid, u16 flags, 1446 bool *changed, struct netlink_ext_ack *extack); 1447 int nbp_vlan_delete(struct net_bridge_port *port, u16 vid); 1448 void nbp_vlan_flush(struct net_bridge_port *port); 1449 int nbp_vlan_init(struct net_bridge_port *port, struct netlink_ext_ack *extack); 1450 int nbp_get_num_vlan_infos(struct net_bridge_port *p, u32 filter_mask); 1451 void br_vlan_get_stats(const struct net_bridge_vlan *v, 1452 struct pcpu_sw_netstats *stats); 1453 void br_vlan_port_event(struct net_bridge_port *p, unsigned long event); 1454 int br_vlan_bridge_event(struct net_device *dev, unsigned long event, 1455 void *ptr); 1456 void br_vlan_rtnl_init(void); 1457 void br_vlan_rtnl_uninit(void); 1458 void br_vlan_notify(const struct net_bridge *br, 1459 const struct net_bridge_port *p, 1460 u16 vid, u16 vid_range, 1461 int cmd); 1462 bool br_vlan_can_enter_range(const struct net_bridge_vlan *v_curr, 1463 const struct net_bridge_vlan *range_end); 1464 1465 void br_vlan_fill_forward_path_pvid(struct net_bridge *br, 1466 struct net_device_path_ctx *ctx, 1467 struct net_device_path *path); 1468 int br_vlan_fill_forward_path_mode(struct net_bridge *br, 1469 struct net_bridge_port *dst, 1470 struct net_device_path *path); 1471 1472 static inline struct net_bridge_vlan_group *br_vlan_group( 1473 const struct net_bridge *br) 1474 { 1475 return rtnl_dereference(br->vlgrp); 1476 } 1477 1478 static inline struct net_bridge_vlan_group *nbp_vlan_group( 1479 const struct net_bridge_port *p) 1480 { 1481 return rtnl_dereference(p->vlgrp); 1482 } 1483 1484 static inline struct net_bridge_vlan_group *br_vlan_group_rcu( 1485 const struct net_bridge *br) 1486 { 1487 return rcu_dereference(br->vlgrp); 1488 } 1489 1490 static inline struct net_bridge_vlan_group *nbp_vlan_group_rcu( 1491 const struct net_bridge_port *p) 1492 { 1493 return rcu_dereference(p->vlgrp); 1494 } 1495 1496 /* Since bridge now depends on 8021Q module, but the time bridge sees the 1497 * skb, the vlan tag will always be present if the frame was tagged. 1498 */ 1499 static inline int br_vlan_get_tag(const struct sk_buff *skb, u16 *vid) 1500 { 1501 int err = 0; 1502 1503 if (skb_vlan_tag_present(skb)) { 1504 *vid = skb_vlan_tag_get_id(skb); 1505 } else { 1506 *vid = 0; 1507 err = -EINVAL; 1508 } 1509 1510 return err; 1511 } 1512 1513 static inline u16 br_get_pvid(const struct net_bridge_vlan_group *vg) 1514 { 1515 if (!vg) 1516 return 0; 1517 1518 smp_rmb(); 1519 return vg->pvid; 1520 } 1521 1522 static inline u16 br_vlan_flags(const struct net_bridge_vlan *v, u16 pvid) 1523 { 1524 return v->vid == pvid ? v->flags | BRIDGE_VLAN_INFO_PVID : v->flags; 1525 } 1526 #else 1527 static inline bool br_allowed_ingress(const struct net_bridge *br, 1528 struct net_bridge_vlan_group *vg, 1529 struct sk_buff *skb, 1530 u16 *vid, u8 *state, 1531 struct net_bridge_vlan **vlan) 1532 1533 { 1534 *vlan = NULL; 1535 return true; 1536 } 1537 1538 static inline bool br_allowed_egress(struct net_bridge_vlan_group *vg, 1539 const struct sk_buff *skb) 1540 { 1541 return true; 1542 } 1543 1544 static inline bool br_should_learn(struct net_bridge_port *p, 1545 struct sk_buff *skb, u16 *vid) 1546 { 1547 return true; 1548 } 1549 1550 static inline struct sk_buff *br_handle_vlan(struct net_bridge *br, 1551 const struct net_bridge_port *port, 1552 struct net_bridge_vlan_group *vg, 1553 struct sk_buff *skb) 1554 { 1555 return skb; 1556 } 1557 1558 static inline int br_vlan_add(struct net_bridge *br, u16 vid, u16 flags, 1559 bool *changed, struct netlink_ext_ack *extack) 1560 { 1561 *changed = false; 1562 return -EOPNOTSUPP; 1563 } 1564 1565 static inline int br_vlan_delete(struct net_bridge *br, u16 vid) 1566 { 1567 return -EOPNOTSUPP; 1568 } 1569 1570 static inline void br_vlan_flush(struct net_bridge *br) 1571 { 1572 } 1573 1574 static inline void br_recalculate_fwd_mask(struct net_bridge *br) 1575 { 1576 } 1577 1578 static inline int br_vlan_init(struct net_bridge *br) 1579 { 1580 return 0; 1581 } 1582 1583 static inline int nbp_vlan_add(struct net_bridge_port *port, u16 vid, u16 flags, 1584 bool *changed, struct netlink_ext_ack *extack) 1585 { 1586 *changed = false; 1587 return -EOPNOTSUPP; 1588 } 1589 1590 static inline int nbp_vlan_delete(struct net_bridge_port *port, u16 vid) 1591 { 1592 return -EOPNOTSUPP; 1593 } 1594 1595 static inline void nbp_vlan_flush(struct net_bridge_port *port) 1596 { 1597 } 1598 1599 static inline struct net_bridge_vlan *br_vlan_find(struct net_bridge_vlan_group *vg, 1600 u16 vid) 1601 { 1602 return NULL; 1603 } 1604 1605 static inline int nbp_vlan_init(struct net_bridge_port *port, 1606 struct netlink_ext_ack *extack) 1607 { 1608 return 0; 1609 } 1610 1611 static inline u16 br_vlan_get_tag(const struct sk_buff *skb, u16 *tag) 1612 { 1613 return 0; 1614 } 1615 1616 static inline u16 br_get_pvid(const struct net_bridge_vlan_group *vg) 1617 { 1618 return 0; 1619 } 1620 1621 static inline int br_vlan_filter_toggle(struct net_bridge *br, 1622 unsigned long val, 1623 struct netlink_ext_ack *extack) 1624 { 1625 return -EOPNOTSUPP; 1626 } 1627 1628 static inline int nbp_get_num_vlan_infos(struct net_bridge_port *p, 1629 u32 filter_mask) 1630 { 1631 return 0; 1632 } 1633 1634 static inline void br_vlan_fill_forward_path_pvid(struct net_bridge *br, 1635 struct net_device_path_ctx *ctx, 1636 struct net_device_path *path) 1637 { 1638 } 1639 1640 static inline int br_vlan_fill_forward_path_mode(struct net_bridge *br, 1641 struct net_bridge_port *dst, 1642 struct net_device_path *path) 1643 { 1644 return 0; 1645 } 1646 1647 static inline struct net_bridge_vlan_group *br_vlan_group( 1648 const struct net_bridge *br) 1649 { 1650 return NULL; 1651 } 1652 1653 static inline struct net_bridge_vlan_group *nbp_vlan_group( 1654 const struct net_bridge_port *p) 1655 { 1656 return NULL; 1657 } 1658 1659 static inline struct net_bridge_vlan_group *br_vlan_group_rcu( 1660 const struct net_bridge *br) 1661 { 1662 return NULL; 1663 } 1664 1665 static inline struct net_bridge_vlan_group *nbp_vlan_group_rcu( 1666 const struct net_bridge_port *p) 1667 { 1668 return NULL; 1669 } 1670 1671 static inline void br_vlan_get_stats(const struct net_bridge_vlan *v, 1672 struct pcpu_sw_netstats *stats) 1673 { 1674 } 1675 1676 static inline void br_vlan_port_event(struct net_bridge_port *p, 1677 unsigned long event) 1678 { 1679 } 1680 1681 static inline int br_vlan_bridge_event(struct net_device *dev, 1682 unsigned long event, void *ptr) 1683 { 1684 return 0; 1685 } 1686 1687 static inline void br_vlan_rtnl_init(void) 1688 { 1689 } 1690 1691 static inline void br_vlan_rtnl_uninit(void) 1692 { 1693 } 1694 1695 static inline void br_vlan_notify(const struct net_bridge *br, 1696 const struct net_bridge_port *p, 1697 u16 vid, u16 vid_range, 1698 int cmd) 1699 { 1700 } 1701 1702 static inline bool br_vlan_can_enter_range(const struct net_bridge_vlan *v_curr, 1703 const struct net_bridge_vlan *range_end) 1704 { 1705 return true; 1706 } 1707 1708 static inline u16 br_vlan_flags(const struct net_bridge_vlan *v, u16 pvid) 1709 { 1710 return 0; 1711 } 1712 1713 #endif 1714 1715 /* br_vlan_options.c */ 1716 #ifdef CONFIG_BRIDGE_VLAN_FILTERING 1717 bool br_vlan_opts_eq_range(const struct net_bridge_vlan *v_curr, 1718 const struct net_bridge_vlan *range_end); 1719 bool br_vlan_opts_fill(struct sk_buff *skb, const struct net_bridge_vlan *v); 1720 size_t br_vlan_opts_nl_size(void); 1721 int br_vlan_process_options(const struct net_bridge *br, 1722 const struct net_bridge_port *p, 1723 struct net_bridge_vlan *range_start, 1724 struct net_bridge_vlan *range_end, 1725 struct nlattr **tb, 1726 struct netlink_ext_ack *extack); 1727 int br_vlan_rtm_process_global_options(struct net_device *dev, 1728 const struct nlattr *attr, 1729 int cmd, 1730 struct netlink_ext_ack *extack); 1731 bool br_vlan_global_opts_can_enter_range(const struct net_bridge_vlan *v_curr, 1732 const struct net_bridge_vlan *r_end); 1733 bool br_vlan_global_opts_fill(struct sk_buff *skb, u16 vid, u16 vid_range, 1734 const struct net_bridge_vlan *v_opts); 1735 1736 /* vlan state manipulation helpers using *_ONCE to annotate lock-free access */ 1737 static inline u8 br_vlan_get_state(const struct net_bridge_vlan *v) 1738 { 1739 return READ_ONCE(v->state); 1740 } 1741 1742 static inline void br_vlan_set_state(struct net_bridge_vlan *v, u8 state) 1743 { 1744 WRITE_ONCE(v->state, state); 1745 } 1746 1747 static inline u8 br_vlan_get_pvid_state(const struct net_bridge_vlan_group *vg) 1748 { 1749 return READ_ONCE(vg->pvid_state); 1750 } 1751 1752 static inline void br_vlan_set_pvid_state(struct net_bridge_vlan_group *vg, 1753 u8 state) 1754 { 1755 WRITE_ONCE(vg->pvid_state, state); 1756 } 1757 1758 /* learn_allow is true at ingress and false at egress */ 1759 static inline bool br_vlan_state_allowed(u8 state, bool learn_allow) 1760 { 1761 switch (state) { 1762 case BR_STATE_LEARNING: 1763 return learn_allow; 1764 case BR_STATE_FORWARDING: 1765 return true; 1766 default: 1767 return false; 1768 } 1769 } 1770 #endif 1771 1772 /* br_mst.c */ 1773 #ifdef CONFIG_BRIDGE_VLAN_FILTERING 1774 DECLARE_STATIC_KEY_FALSE(br_mst_used); 1775 static inline bool br_mst_is_enabled(struct net_bridge *br) 1776 { 1777 return static_branch_unlikely(&br_mst_used) && 1778 br_opt_get(br, BROPT_MST_ENABLED); 1779 } 1780 1781 int br_mst_set_state(struct net_bridge_port *p, u16 msti, u8 state, 1782 struct netlink_ext_ack *extack); 1783 int br_mst_vlan_set_msti(struct net_bridge_vlan *v, u16 msti); 1784 void br_mst_vlan_init_state(struct net_bridge_vlan *v); 1785 int br_mst_set_enabled(struct net_bridge *br, bool on, 1786 struct netlink_ext_ack *extack); 1787 size_t br_mst_info_size(const struct net_bridge_vlan_group *vg); 1788 int br_mst_fill_info(struct sk_buff *skb, 1789 const struct net_bridge_vlan_group *vg); 1790 int br_mst_process(struct net_bridge_port *p, const struct nlattr *mst_attr, 1791 struct netlink_ext_ack *extack); 1792 #else 1793 static inline bool br_mst_is_enabled(struct net_bridge *br) 1794 { 1795 return false; 1796 } 1797 1798 static inline int br_mst_set_state(struct net_bridge_port *p, u16 msti, 1799 u8 state, struct netlink_ext_ack *extack) 1800 { 1801 return -EOPNOTSUPP; 1802 } 1803 1804 static inline int br_mst_set_enabled(struct net_bridge *br, bool on, 1805 struct netlink_ext_ack *extack) 1806 { 1807 return -EOPNOTSUPP; 1808 } 1809 1810 static inline size_t br_mst_info_size(const struct net_bridge_vlan_group *vg) 1811 { 1812 return 0; 1813 } 1814 1815 static inline int br_mst_fill_info(struct sk_buff *skb, 1816 const struct net_bridge_vlan_group *vg) 1817 { 1818 return -EOPNOTSUPP; 1819 } 1820 1821 static inline int br_mst_process(struct net_bridge_port *p, 1822 const struct nlattr *mst_attr, 1823 struct netlink_ext_ack *extack) 1824 { 1825 return -EOPNOTSUPP; 1826 } 1827 #endif 1828 1829 struct nf_br_ops { 1830 int (*br_dev_xmit_hook)(struct sk_buff *skb); 1831 }; 1832 extern const struct nf_br_ops __rcu *nf_br_ops; 1833 1834 /* br_netfilter.c */ 1835 #if IS_ENABLED(CONFIG_BRIDGE_NETFILTER) 1836 int br_nf_core_init(void); 1837 void br_nf_core_fini(void); 1838 void br_netfilter_rtable_init(struct net_bridge *); 1839 #else 1840 static inline int br_nf_core_init(void) { return 0; } 1841 static inline void br_nf_core_fini(void) {} 1842 #define br_netfilter_rtable_init(x) 1843 #endif 1844 1845 /* br_stp.c */ 1846 void br_set_state(struct net_bridge_port *p, unsigned int state); 1847 struct net_bridge_port *br_get_port(struct net_bridge *br, u16 port_no); 1848 void br_init_port(struct net_bridge_port *p); 1849 void br_become_designated_port(struct net_bridge_port *p); 1850 1851 void __br_set_forward_delay(struct net_bridge *br, unsigned long t); 1852 int br_set_forward_delay(struct net_bridge *br, unsigned long x); 1853 int br_set_hello_time(struct net_bridge *br, unsigned long x); 1854 int br_set_max_age(struct net_bridge *br, unsigned long x); 1855 int __set_ageing_time(struct net_device *dev, unsigned long t); 1856 int br_set_ageing_time(struct net_bridge *br, clock_t ageing_time); 1857 1858 1859 /* br_stp_if.c */ 1860 void br_stp_enable_bridge(struct net_bridge *br); 1861 void br_stp_disable_bridge(struct net_bridge *br); 1862 int br_stp_set_enabled(struct net_bridge *br, unsigned long val, 1863 struct netlink_ext_ack *extack); 1864 void br_stp_enable_port(struct net_bridge_port *p); 1865 void br_stp_disable_port(struct net_bridge_port *p); 1866 bool br_stp_recalculate_bridge_id(struct net_bridge *br); 1867 void br_stp_change_bridge_id(struct net_bridge *br, const unsigned char *a); 1868 void br_stp_set_bridge_priority(struct net_bridge *br, u16 newprio); 1869 int br_stp_set_port_priority(struct net_bridge_port *p, unsigned long newprio); 1870 int br_stp_set_path_cost(struct net_bridge_port *p, unsigned long path_cost); 1871 ssize_t br_show_bridge_id(char *buf, const struct bridge_id *id); 1872 1873 /* br_stp_bpdu.c */ 1874 struct stp_proto; 1875 void br_stp_rcv(const struct stp_proto *proto, struct sk_buff *skb, 1876 struct net_device *dev); 1877 1878 /* br_stp_timer.c */ 1879 void br_stp_timer_init(struct net_bridge *br); 1880 void br_stp_port_timer_init(struct net_bridge_port *p); 1881 unsigned long br_timer_value(const struct timer_list *timer); 1882 1883 /* br.c */ 1884 #if IS_ENABLED(CONFIG_ATM_LANE) 1885 extern int (*br_fdb_test_addr_hook)(struct net_device *dev, unsigned char *addr); 1886 #endif 1887 1888 /* br_mrp.c */ 1889 #if IS_ENABLED(CONFIG_BRIDGE_MRP) 1890 int br_mrp_parse(struct net_bridge *br, struct net_bridge_port *p, 1891 struct nlattr *attr, int cmd, struct netlink_ext_ack *extack); 1892 bool br_mrp_enabled(struct net_bridge *br); 1893 void br_mrp_port_del(struct net_bridge *br, struct net_bridge_port *p); 1894 int br_mrp_fill_info(struct sk_buff *skb, struct net_bridge *br); 1895 #else 1896 static inline int br_mrp_parse(struct net_bridge *br, struct net_bridge_port *p, 1897 struct nlattr *attr, int cmd, 1898 struct netlink_ext_ack *extack) 1899 { 1900 return -EOPNOTSUPP; 1901 } 1902 1903 static inline bool br_mrp_enabled(struct net_bridge *br) 1904 { 1905 return false; 1906 } 1907 1908 static inline void br_mrp_port_del(struct net_bridge *br, 1909 struct net_bridge_port *p) 1910 { 1911 } 1912 1913 static inline int br_mrp_fill_info(struct sk_buff *skb, struct net_bridge *br) 1914 { 1915 return 0; 1916 } 1917 1918 #endif 1919 1920 /* br_cfm.c */ 1921 #if IS_ENABLED(CONFIG_BRIDGE_CFM) 1922 int br_cfm_parse(struct net_bridge *br, struct net_bridge_port *p, 1923 struct nlattr *attr, int cmd, struct netlink_ext_ack *extack); 1924 bool br_cfm_created(struct net_bridge *br); 1925 void br_cfm_port_del(struct net_bridge *br, struct net_bridge_port *p); 1926 int br_cfm_config_fill_info(struct sk_buff *skb, struct net_bridge *br); 1927 int br_cfm_status_fill_info(struct sk_buff *skb, 1928 struct net_bridge *br, 1929 bool getlink); 1930 int br_cfm_mep_count(struct net_bridge *br, u32 *count); 1931 int br_cfm_peer_mep_count(struct net_bridge *br, u32 *count); 1932 #else 1933 static inline int br_cfm_parse(struct net_bridge *br, struct net_bridge_port *p, 1934 struct nlattr *attr, int cmd, 1935 struct netlink_ext_ack *extack) 1936 { 1937 return -EOPNOTSUPP; 1938 } 1939 1940 static inline bool br_cfm_created(struct net_bridge *br) 1941 { 1942 return false; 1943 } 1944 1945 static inline void br_cfm_port_del(struct net_bridge *br, 1946 struct net_bridge_port *p) 1947 { 1948 } 1949 1950 static inline int br_cfm_config_fill_info(struct sk_buff *skb, struct net_bridge *br) 1951 { 1952 return -EOPNOTSUPP; 1953 } 1954 1955 static inline int br_cfm_status_fill_info(struct sk_buff *skb, 1956 struct net_bridge *br, 1957 bool getlink) 1958 { 1959 return -EOPNOTSUPP; 1960 } 1961 1962 static inline int br_cfm_mep_count(struct net_bridge *br, u32 *count) 1963 { 1964 *count = 0; 1965 return -EOPNOTSUPP; 1966 } 1967 1968 static inline int br_cfm_peer_mep_count(struct net_bridge *br, u32 *count) 1969 { 1970 *count = 0; 1971 return -EOPNOTSUPP; 1972 } 1973 #endif 1974 1975 /* br_netlink.c */ 1976 extern struct rtnl_link_ops br_link_ops; 1977 int br_netlink_init(void); 1978 void br_netlink_fini(void); 1979 void br_ifinfo_notify(int event, const struct net_bridge *br, 1980 const struct net_bridge_port *port); 1981 void br_info_notify(int event, const struct net_bridge *br, 1982 const struct net_bridge_port *port, u32 filter); 1983 int br_setlink(struct net_device *dev, struct nlmsghdr *nlmsg, u16 flags, 1984 struct netlink_ext_ack *extack); 1985 int br_dellink(struct net_device *dev, struct nlmsghdr *nlmsg, u16 flags); 1986 int br_getlink(struct sk_buff *skb, u32 pid, u32 seq, struct net_device *dev, 1987 u32 filter_mask, int nlflags); 1988 int br_process_vlan_info(struct net_bridge *br, 1989 struct net_bridge_port *p, int cmd, 1990 struct bridge_vlan_info *vinfo_curr, 1991 struct bridge_vlan_info **vinfo_last, 1992 bool *changed, 1993 struct netlink_ext_ack *extack); 1994 1995 #ifdef CONFIG_SYSFS 1996 /* br_sysfs_if.c */ 1997 extern const struct sysfs_ops brport_sysfs_ops; 1998 int br_sysfs_addif(struct net_bridge_port *p); 1999 int br_sysfs_renameif(struct net_bridge_port *p); 2000 2001 /* br_sysfs_br.c */ 2002 int br_sysfs_addbr(struct net_device *dev); 2003 void br_sysfs_delbr(struct net_device *dev); 2004 2005 #else 2006 2007 static inline int br_sysfs_addif(struct net_bridge_port *p) { return 0; } 2008 static inline int br_sysfs_renameif(struct net_bridge_port *p) { return 0; } 2009 static inline int br_sysfs_addbr(struct net_device *dev) { return 0; } 2010 static inline void br_sysfs_delbr(struct net_device *dev) { return; } 2011 #endif /* CONFIG_SYSFS */ 2012 2013 /* br_switchdev.c */ 2014 #ifdef CONFIG_NET_SWITCHDEV 2015 int br_switchdev_port_offload(struct net_bridge_port *p, 2016 struct net_device *dev, const void *ctx, 2017 struct notifier_block *atomic_nb, 2018 struct notifier_block *blocking_nb, 2019 bool tx_fwd_offload, 2020 struct netlink_ext_ack *extack); 2021 2022 void br_switchdev_port_unoffload(struct net_bridge_port *p, const void *ctx, 2023 struct notifier_block *atomic_nb, 2024 struct notifier_block *blocking_nb); 2025 2026 bool br_switchdev_frame_uses_tx_fwd_offload(struct sk_buff *skb); 2027 2028 void br_switchdev_frame_set_offload_fwd_mark(struct sk_buff *skb); 2029 2030 void nbp_switchdev_frame_mark_tx_fwd_offload(const struct net_bridge_port *p, 2031 struct sk_buff *skb); 2032 void nbp_switchdev_frame_mark_tx_fwd_to_hwdom(const struct net_bridge_port *p, 2033 struct sk_buff *skb); 2034 void nbp_switchdev_frame_mark(const struct net_bridge_port *p, 2035 struct sk_buff *skb); 2036 bool nbp_switchdev_allowed_egress(const struct net_bridge_port *p, 2037 const struct sk_buff *skb); 2038 int br_switchdev_set_port_flag(struct net_bridge_port *p, 2039 unsigned long flags, 2040 unsigned long mask, 2041 struct netlink_ext_ack *extack); 2042 void br_switchdev_fdb_notify(struct net_bridge *br, 2043 const struct net_bridge_fdb_entry *fdb, int type); 2044 void br_switchdev_mdb_notify(struct net_device *dev, 2045 struct net_bridge_mdb_entry *mp, 2046 struct net_bridge_port_group *pg, 2047 int type); 2048 int br_switchdev_port_vlan_add(struct net_device *dev, u16 vid, u16 flags, 2049 bool changed, struct netlink_ext_ack *extack); 2050 int br_switchdev_port_vlan_del(struct net_device *dev, u16 vid); 2051 void br_switchdev_init(struct net_bridge *br); 2052 2053 static inline void br_switchdev_frame_unmark(struct sk_buff *skb) 2054 { 2055 skb->offload_fwd_mark = 0; 2056 } 2057 #else 2058 static inline int 2059 br_switchdev_port_offload(struct net_bridge_port *p, 2060 struct net_device *dev, const void *ctx, 2061 struct notifier_block *atomic_nb, 2062 struct notifier_block *blocking_nb, 2063 bool tx_fwd_offload, 2064 struct netlink_ext_ack *extack) 2065 { 2066 return -EOPNOTSUPP; 2067 } 2068 2069 static inline void 2070 br_switchdev_port_unoffload(struct net_bridge_port *p, const void *ctx, 2071 struct notifier_block *atomic_nb, 2072 struct notifier_block *blocking_nb) 2073 { 2074 } 2075 2076 static inline bool br_switchdev_frame_uses_tx_fwd_offload(struct sk_buff *skb) 2077 { 2078 return false; 2079 } 2080 2081 static inline void br_switchdev_frame_set_offload_fwd_mark(struct sk_buff *skb) 2082 { 2083 } 2084 2085 static inline void 2086 nbp_switchdev_frame_mark_tx_fwd_offload(const struct net_bridge_port *p, 2087 struct sk_buff *skb) 2088 { 2089 } 2090 2091 static inline void 2092 nbp_switchdev_frame_mark_tx_fwd_to_hwdom(const struct net_bridge_port *p, 2093 struct sk_buff *skb) 2094 { 2095 } 2096 2097 static inline void nbp_switchdev_frame_mark(const struct net_bridge_port *p, 2098 struct sk_buff *skb) 2099 { 2100 } 2101 2102 static inline bool nbp_switchdev_allowed_egress(const struct net_bridge_port *p, 2103 const struct sk_buff *skb) 2104 { 2105 return true; 2106 } 2107 2108 static inline int br_switchdev_set_port_flag(struct net_bridge_port *p, 2109 unsigned long flags, 2110 unsigned long mask, 2111 struct netlink_ext_ack *extack) 2112 { 2113 return 0; 2114 } 2115 2116 static inline int br_switchdev_port_vlan_add(struct net_device *dev, u16 vid, 2117 u16 flags, bool changed, 2118 struct netlink_ext_ack *extack) 2119 { 2120 return -EOPNOTSUPP; 2121 } 2122 2123 static inline int br_switchdev_port_vlan_del(struct net_device *dev, u16 vid) 2124 { 2125 return -EOPNOTSUPP; 2126 } 2127 2128 static inline void 2129 br_switchdev_fdb_notify(struct net_bridge *br, 2130 const struct net_bridge_fdb_entry *fdb, int type) 2131 { 2132 } 2133 2134 static inline void br_switchdev_mdb_notify(struct net_device *dev, 2135 struct net_bridge_mdb_entry *mp, 2136 struct net_bridge_port_group *pg, 2137 int type) 2138 { 2139 } 2140 2141 static inline void br_switchdev_frame_unmark(struct sk_buff *skb) 2142 { 2143 } 2144 2145 static inline void br_switchdev_init(struct net_bridge *br) 2146 { 2147 } 2148 2149 #endif /* CONFIG_NET_SWITCHDEV */ 2150 2151 /* br_arp_nd_proxy.c */ 2152 void br_recalculate_neigh_suppress_enabled(struct net_bridge *br); 2153 void br_do_proxy_suppress_arp(struct sk_buff *skb, struct net_bridge *br, 2154 u16 vid, struct net_bridge_port *p); 2155 void br_do_suppress_nd(struct sk_buff *skb, struct net_bridge *br, 2156 u16 vid, struct net_bridge_port *p, struct nd_msg *msg); 2157 struct nd_msg *br_is_nd_neigh_msg(struct sk_buff *skb, struct nd_msg *m); 2158 #endif 2159