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