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