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 struct net_bridge_group_src * 978 br_multicast_new_group_src(struct net_bridge_port_group *pg, 979 struct br_ip *src_ip); 980 void br_multicast_del_group_src(struct net_bridge_group_src *src, 981 bool fastleave); 982 void br_multicast_ctx_init(struct net_bridge *br, 983 struct net_bridge_vlan *vlan, 984 struct net_bridge_mcast *brmctx); 985 void br_multicast_ctx_deinit(struct net_bridge_mcast *brmctx); 986 void br_multicast_port_ctx_init(struct net_bridge_port *port, 987 struct net_bridge_vlan *vlan, 988 struct net_bridge_mcast_port *pmctx); 989 void br_multicast_port_ctx_deinit(struct net_bridge_mcast_port *pmctx); 990 void br_multicast_toggle_one_vlan(struct net_bridge_vlan *vlan, bool on); 991 int br_multicast_toggle_vlan_snooping(struct net_bridge *br, bool on, 992 struct netlink_ext_ack *extack); 993 bool br_multicast_toggle_global_vlan(struct net_bridge_vlan *vlan, bool on); 994 995 int br_rports_fill_info(struct sk_buff *skb, 996 const struct net_bridge_mcast *brmctx); 997 int br_multicast_dump_querier_state(struct sk_buff *skb, 998 const struct net_bridge_mcast *brmctx, 999 int nest_attr); 1000 size_t br_multicast_querier_state_size(void); 1001 size_t br_rports_size(const struct net_bridge_mcast *brmctx); 1002 void br_multicast_set_query_intvl(struct net_bridge_mcast *brmctx, 1003 unsigned long val); 1004 void br_multicast_set_startup_query_intvl(struct net_bridge_mcast *brmctx, 1005 unsigned long val); 1006 1007 static inline bool br_group_is_l2(const struct br_ip *group) 1008 { 1009 return group->proto == 0; 1010 } 1011 1012 #define mlock_dereference(X, br) \ 1013 rcu_dereference_protected(X, lockdep_is_held(&br->multicast_lock)) 1014 1015 static inline struct hlist_node * 1016 br_multicast_get_first_rport_node(struct net_bridge_mcast *brmctx, 1017 struct sk_buff *skb) 1018 { 1019 #if IS_ENABLED(CONFIG_IPV6) 1020 if (skb->protocol == htons(ETH_P_IPV6)) 1021 return rcu_dereference(hlist_first_rcu(&brmctx->ip6_mc_router_list)); 1022 #endif 1023 return rcu_dereference(hlist_first_rcu(&brmctx->ip4_mc_router_list)); 1024 } 1025 1026 static inline struct net_bridge_port * 1027 br_multicast_rport_from_node_skb(struct hlist_node *rp, struct sk_buff *skb) 1028 { 1029 struct net_bridge_mcast_port *mctx; 1030 1031 #if IS_ENABLED(CONFIG_IPV6) 1032 if (skb->protocol == htons(ETH_P_IPV6)) 1033 mctx = hlist_entry_safe(rp, struct net_bridge_mcast_port, 1034 ip6_rlist); 1035 else 1036 #endif 1037 mctx = hlist_entry_safe(rp, struct net_bridge_mcast_port, 1038 ip4_rlist); 1039 1040 if (mctx) 1041 return mctx->port; 1042 else 1043 return NULL; 1044 } 1045 1046 static inline bool br_ip4_multicast_is_router(struct net_bridge_mcast *brmctx) 1047 { 1048 return timer_pending(&brmctx->ip4_mc_router_timer); 1049 } 1050 1051 static inline bool br_ip6_multicast_is_router(struct net_bridge_mcast *brmctx) 1052 { 1053 #if IS_ENABLED(CONFIG_IPV6) 1054 return timer_pending(&brmctx->ip6_mc_router_timer); 1055 #else 1056 return false; 1057 #endif 1058 } 1059 1060 static inline bool 1061 br_multicast_is_router(struct net_bridge_mcast *brmctx, struct sk_buff *skb) 1062 { 1063 switch (brmctx->multicast_router) { 1064 case MDB_RTR_TYPE_PERM: 1065 return true; 1066 case MDB_RTR_TYPE_TEMP_QUERY: 1067 if (skb) { 1068 if (skb->protocol == htons(ETH_P_IP)) 1069 return br_ip4_multicast_is_router(brmctx); 1070 else if (skb->protocol == htons(ETH_P_IPV6)) 1071 return br_ip6_multicast_is_router(brmctx); 1072 } else { 1073 return br_ip4_multicast_is_router(brmctx) || 1074 br_ip6_multicast_is_router(brmctx); 1075 } 1076 fallthrough; 1077 default: 1078 return false; 1079 } 1080 } 1081 1082 static inline bool 1083 __br_multicast_querier_exists(struct net_bridge_mcast *brmctx, 1084 struct bridge_mcast_other_query *querier, 1085 const bool is_ipv6) 1086 { 1087 bool own_querier_enabled; 1088 1089 if (brmctx->multicast_querier) { 1090 if (is_ipv6 && !br_opt_get(brmctx->br, BROPT_HAS_IPV6_ADDR)) 1091 own_querier_enabled = false; 1092 else 1093 own_querier_enabled = true; 1094 } else { 1095 own_querier_enabled = false; 1096 } 1097 1098 return time_is_before_jiffies(querier->delay_time) && 1099 (own_querier_enabled || timer_pending(&querier->timer)); 1100 } 1101 1102 static inline bool br_multicast_querier_exists(struct net_bridge_mcast *brmctx, 1103 struct ethhdr *eth, 1104 const struct net_bridge_mdb_entry *mdb) 1105 { 1106 switch (eth->h_proto) { 1107 case (htons(ETH_P_IP)): 1108 return __br_multicast_querier_exists(brmctx, 1109 &brmctx->ip4_other_query, false); 1110 #if IS_ENABLED(CONFIG_IPV6) 1111 case (htons(ETH_P_IPV6)): 1112 return __br_multicast_querier_exists(brmctx, 1113 &brmctx->ip6_other_query, true); 1114 #endif 1115 default: 1116 return !!mdb && br_group_is_l2(&mdb->addr); 1117 } 1118 } 1119 1120 static inline bool br_multicast_is_star_g(const struct br_ip *ip) 1121 { 1122 switch (ip->proto) { 1123 case htons(ETH_P_IP): 1124 return ipv4_is_zeronet(ip->src.ip4); 1125 #if IS_ENABLED(CONFIG_IPV6) 1126 case htons(ETH_P_IPV6): 1127 return ipv6_addr_any(&ip->src.ip6); 1128 #endif 1129 default: 1130 return false; 1131 } 1132 } 1133 1134 static inline bool 1135 br_multicast_should_handle_mode(const struct net_bridge_mcast *brmctx, 1136 __be16 proto) 1137 { 1138 switch (proto) { 1139 case htons(ETH_P_IP): 1140 return !!(brmctx->multicast_igmp_version == 3); 1141 #if IS_ENABLED(CONFIG_IPV6) 1142 case htons(ETH_P_IPV6): 1143 return !!(brmctx->multicast_mld_version == 2); 1144 #endif 1145 default: 1146 return false; 1147 } 1148 } 1149 1150 static inline int br_multicast_igmp_type(const struct sk_buff *skb) 1151 { 1152 return BR_INPUT_SKB_CB(skb)->igmp; 1153 } 1154 1155 static inline unsigned long br_multicast_lmqt(const struct net_bridge_mcast *brmctx) 1156 { 1157 return brmctx->multicast_last_member_interval * 1158 brmctx->multicast_last_member_count; 1159 } 1160 1161 static inline unsigned long br_multicast_gmi(const struct net_bridge_mcast *brmctx) 1162 { 1163 return brmctx->multicast_membership_interval; 1164 } 1165 1166 static inline bool 1167 br_multicast_ctx_is_vlan(const struct net_bridge_mcast *brmctx) 1168 { 1169 return !!brmctx->vlan; 1170 } 1171 1172 static inline bool 1173 br_multicast_port_ctx_is_vlan(const struct net_bridge_mcast_port *pmctx) 1174 { 1175 return !!pmctx->vlan; 1176 } 1177 1178 static inline struct net_bridge_mcast * 1179 br_multicast_port_ctx_get_global(const struct net_bridge_mcast_port *pmctx) 1180 { 1181 if (!br_multicast_port_ctx_is_vlan(pmctx)) 1182 return &pmctx->port->br->multicast_ctx; 1183 else 1184 return &pmctx->vlan->brvlan->br_mcast_ctx; 1185 } 1186 1187 static inline bool 1188 br_multicast_ctx_vlan_global_disabled(const struct net_bridge_mcast *brmctx) 1189 { 1190 return br_multicast_ctx_is_vlan(brmctx) && 1191 (!br_opt_get(brmctx->br, BROPT_MCAST_VLAN_SNOOPING_ENABLED) || 1192 !(brmctx->vlan->priv_flags & BR_VLFLAG_GLOBAL_MCAST_ENABLED)); 1193 } 1194 1195 static inline bool 1196 br_multicast_ctx_vlan_disabled(const struct net_bridge_mcast *brmctx) 1197 { 1198 return br_multicast_ctx_is_vlan(brmctx) && 1199 !(brmctx->vlan->priv_flags & BR_VLFLAG_MCAST_ENABLED); 1200 } 1201 1202 static inline bool 1203 br_multicast_port_ctx_vlan_disabled(const struct net_bridge_mcast_port *pmctx) 1204 { 1205 return br_multicast_port_ctx_is_vlan(pmctx) && 1206 !(pmctx->vlan->priv_flags & BR_VLFLAG_MCAST_ENABLED); 1207 } 1208 1209 static inline bool 1210 br_multicast_port_ctx_state_disabled(const struct net_bridge_mcast_port *pmctx) 1211 { 1212 return pmctx->port->state == BR_STATE_DISABLED || 1213 (br_multicast_port_ctx_is_vlan(pmctx) && 1214 (br_multicast_port_ctx_vlan_disabled(pmctx) || 1215 pmctx->vlan->state == BR_STATE_DISABLED)); 1216 } 1217 1218 static inline bool 1219 br_multicast_port_ctx_state_stopped(const struct net_bridge_mcast_port *pmctx) 1220 { 1221 return br_multicast_port_ctx_state_disabled(pmctx) || 1222 pmctx->port->state == BR_STATE_BLOCKING || 1223 (br_multicast_port_ctx_is_vlan(pmctx) && 1224 pmctx->vlan->state == BR_STATE_BLOCKING); 1225 } 1226 1227 static inline bool 1228 br_rports_have_mc_router(const struct net_bridge_mcast *brmctx) 1229 { 1230 #if IS_ENABLED(CONFIG_IPV6) 1231 return !hlist_empty(&brmctx->ip4_mc_router_list) || 1232 !hlist_empty(&brmctx->ip6_mc_router_list); 1233 #else 1234 return !hlist_empty(&brmctx->ip4_mc_router_list); 1235 #endif 1236 } 1237 1238 static inline bool 1239 br_multicast_ctx_options_equal(const struct net_bridge_mcast *brmctx1, 1240 const struct net_bridge_mcast *brmctx2) 1241 { 1242 return brmctx1->multicast_igmp_version == 1243 brmctx2->multicast_igmp_version && 1244 brmctx1->multicast_last_member_count == 1245 brmctx2->multicast_last_member_count && 1246 brmctx1->multicast_startup_query_count == 1247 brmctx2->multicast_startup_query_count && 1248 brmctx1->multicast_last_member_interval == 1249 brmctx2->multicast_last_member_interval && 1250 brmctx1->multicast_membership_interval == 1251 brmctx2->multicast_membership_interval && 1252 brmctx1->multicast_querier_interval == 1253 brmctx2->multicast_querier_interval && 1254 brmctx1->multicast_query_interval == 1255 brmctx2->multicast_query_interval && 1256 brmctx1->multicast_query_response_interval == 1257 brmctx2->multicast_query_response_interval && 1258 brmctx1->multicast_startup_query_interval == 1259 brmctx2->multicast_startup_query_interval && 1260 brmctx1->multicast_querier == brmctx2->multicast_querier && 1261 brmctx1->multicast_router == brmctx2->multicast_router && 1262 !br_rports_have_mc_router(brmctx1) && 1263 !br_rports_have_mc_router(brmctx2) && 1264 #if IS_ENABLED(CONFIG_IPV6) 1265 brmctx1->multicast_mld_version == 1266 brmctx2->multicast_mld_version && 1267 #endif 1268 true; 1269 } 1270 1271 static inline bool 1272 br_multicast_ctx_matches_vlan_snooping(const struct net_bridge_mcast *brmctx) 1273 { 1274 bool vlan_snooping_enabled; 1275 1276 vlan_snooping_enabled = !!br_opt_get(brmctx->br, 1277 BROPT_MCAST_VLAN_SNOOPING_ENABLED); 1278 1279 return !!(vlan_snooping_enabled == br_multicast_ctx_is_vlan(brmctx)); 1280 } 1281 #else 1282 static inline int br_multicast_rcv(struct net_bridge_mcast **brmctx, 1283 struct net_bridge_mcast_port **pmctx, 1284 struct net_bridge_vlan *vlan, 1285 struct sk_buff *skb, 1286 u16 vid) 1287 { 1288 return 0; 1289 } 1290 1291 static inline struct net_bridge_mdb_entry *br_mdb_get(struct net_bridge_mcast *brmctx, 1292 struct sk_buff *skb, u16 vid) 1293 { 1294 return NULL; 1295 } 1296 1297 static inline int br_multicast_add_port(struct net_bridge_port *port) 1298 { 1299 return 0; 1300 } 1301 1302 static inline void br_multicast_del_port(struct net_bridge_port *port) 1303 { 1304 } 1305 1306 static inline void br_multicast_enable_port(struct net_bridge_port *port) 1307 { 1308 } 1309 1310 static inline void br_multicast_disable_port(struct net_bridge_port *port) 1311 { 1312 } 1313 1314 static inline void br_multicast_init(struct net_bridge *br) 1315 { 1316 } 1317 1318 static inline void br_multicast_join_snoopers(struct net_bridge *br) 1319 { 1320 } 1321 1322 static inline void br_multicast_leave_snoopers(struct net_bridge *br) 1323 { 1324 } 1325 1326 static inline void br_multicast_open(struct net_bridge *br) 1327 { 1328 } 1329 1330 static inline void br_multicast_stop(struct net_bridge *br) 1331 { 1332 } 1333 1334 static inline void br_multicast_dev_del(struct net_bridge *br) 1335 { 1336 } 1337 1338 static inline void br_multicast_flood(struct net_bridge_mdb_entry *mdst, 1339 struct sk_buff *skb, 1340 struct net_bridge_mcast *brmctx, 1341 bool local_rcv, bool local_orig) 1342 { 1343 } 1344 1345 static inline bool br_multicast_is_router(struct net_bridge_mcast *brmctx, 1346 struct sk_buff *skb) 1347 { 1348 return false; 1349 } 1350 1351 static inline bool br_multicast_querier_exists(struct net_bridge_mcast *brmctx, 1352 struct ethhdr *eth, 1353 const struct net_bridge_mdb_entry *mdb) 1354 { 1355 return false; 1356 } 1357 1358 static inline void br_mdb_init(void) 1359 { 1360 } 1361 1362 static inline void br_mdb_uninit(void) 1363 { 1364 } 1365 1366 static inline int br_mdb_hash_init(struct net_bridge *br) 1367 { 1368 return 0; 1369 } 1370 1371 static inline void br_mdb_hash_fini(struct net_bridge *br) 1372 { 1373 } 1374 1375 static inline void br_multicast_count(struct net_bridge *br, 1376 const struct net_bridge_port *p, 1377 const struct sk_buff *skb, 1378 u8 type, u8 dir) 1379 { 1380 } 1381 1382 static inline int br_multicast_init_stats(struct net_bridge *br) 1383 { 1384 return 0; 1385 } 1386 1387 static inline void br_multicast_uninit_stats(struct net_bridge *br) 1388 { 1389 } 1390 1391 static inline int br_multicast_igmp_type(const struct sk_buff *skb) 1392 { 1393 return 0; 1394 } 1395 1396 static inline void br_multicast_ctx_init(struct net_bridge *br, 1397 struct net_bridge_vlan *vlan, 1398 struct net_bridge_mcast *brmctx) 1399 { 1400 } 1401 1402 static inline void br_multicast_ctx_deinit(struct net_bridge_mcast *brmctx) 1403 { 1404 } 1405 1406 static inline void br_multicast_port_ctx_init(struct net_bridge_port *port, 1407 struct net_bridge_vlan *vlan, 1408 struct net_bridge_mcast_port *pmctx) 1409 { 1410 } 1411 1412 static inline void br_multicast_port_ctx_deinit(struct net_bridge_mcast_port *pmctx) 1413 { 1414 } 1415 1416 static inline void br_multicast_toggle_one_vlan(struct net_bridge_vlan *vlan, 1417 bool on) 1418 { 1419 } 1420 1421 static inline int br_multicast_toggle_vlan_snooping(struct net_bridge *br, 1422 bool on, 1423 struct netlink_ext_ack *extack) 1424 { 1425 return -EOPNOTSUPP; 1426 } 1427 1428 static inline bool br_multicast_toggle_global_vlan(struct net_bridge_vlan *vlan, 1429 bool on) 1430 { 1431 return false; 1432 } 1433 1434 static inline bool 1435 br_multicast_ctx_options_equal(const struct net_bridge_mcast *brmctx1, 1436 const struct net_bridge_mcast *brmctx2) 1437 { 1438 return true; 1439 } 1440 #endif 1441 1442 /* br_vlan.c */ 1443 #ifdef CONFIG_BRIDGE_VLAN_FILTERING 1444 bool br_allowed_ingress(const struct net_bridge *br, 1445 struct net_bridge_vlan_group *vg, struct sk_buff *skb, 1446 u16 *vid, u8 *state, 1447 struct net_bridge_vlan **vlan); 1448 bool br_allowed_egress(struct net_bridge_vlan_group *vg, 1449 const struct sk_buff *skb); 1450 bool br_should_learn(struct net_bridge_port *p, struct sk_buff *skb, u16 *vid); 1451 struct sk_buff *br_handle_vlan(struct net_bridge *br, 1452 const struct net_bridge_port *port, 1453 struct net_bridge_vlan_group *vg, 1454 struct sk_buff *skb); 1455 int br_vlan_add(struct net_bridge *br, u16 vid, u16 flags, 1456 bool *changed, struct netlink_ext_ack *extack); 1457 int br_vlan_delete(struct net_bridge *br, u16 vid); 1458 void br_vlan_flush(struct net_bridge *br); 1459 struct net_bridge_vlan *br_vlan_find(struct net_bridge_vlan_group *vg, u16 vid); 1460 void br_recalculate_fwd_mask(struct net_bridge *br); 1461 int br_vlan_filter_toggle(struct net_bridge *br, unsigned long val, 1462 struct netlink_ext_ack *extack); 1463 int __br_vlan_set_proto(struct net_bridge *br, __be16 proto, 1464 struct netlink_ext_ack *extack); 1465 int br_vlan_set_proto(struct net_bridge *br, unsigned long val, 1466 struct netlink_ext_ack *extack); 1467 int br_vlan_set_stats(struct net_bridge *br, unsigned long val); 1468 int br_vlan_set_stats_per_port(struct net_bridge *br, unsigned long val); 1469 int br_vlan_init(struct net_bridge *br); 1470 int br_vlan_set_default_pvid(struct net_bridge *br, unsigned long val, 1471 struct netlink_ext_ack *extack); 1472 int __br_vlan_set_default_pvid(struct net_bridge *br, u16 pvid, 1473 struct netlink_ext_ack *extack); 1474 int nbp_vlan_add(struct net_bridge_port *port, u16 vid, u16 flags, 1475 bool *changed, struct netlink_ext_ack *extack); 1476 int nbp_vlan_delete(struct net_bridge_port *port, u16 vid); 1477 void nbp_vlan_flush(struct net_bridge_port *port); 1478 int nbp_vlan_init(struct net_bridge_port *port, struct netlink_ext_ack *extack); 1479 int nbp_get_num_vlan_infos(struct net_bridge_port *p, u32 filter_mask); 1480 void br_vlan_get_stats(const struct net_bridge_vlan *v, 1481 struct pcpu_sw_netstats *stats); 1482 void br_vlan_port_event(struct net_bridge_port *p, unsigned long event); 1483 int br_vlan_bridge_event(struct net_device *dev, unsigned long event, 1484 void *ptr); 1485 void br_vlan_rtnl_init(void); 1486 void br_vlan_rtnl_uninit(void); 1487 void br_vlan_notify(const struct net_bridge *br, 1488 const struct net_bridge_port *p, 1489 u16 vid, u16 vid_range, 1490 int cmd); 1491 bool br_vlan_can_enter_range(const struct net_bridge_vlan *v_curr, 1492 const struct net_bridge_vlan *range_end); 1493 1494 void br_vlan_fill_forward_path_pvid(struct net_bridge *br, 1495 struct net_device_path_ctx *ctx, 1496 struct net_device_path *path); 1497 int br_vlan_fill_forward_path_mode(struct net_bridge *br, 1498 struct net_bridge_port *dst, 1499 struct net_device_path *path); 1500 1501 static inline struct net_bridge_vlan_group *br_vlan_group( 1502 const struct net_bridge *br) 1503 { 1504 return rtnl_dereference(br->vlgrp); 1505 } 1506 1507 static inline struct net_bridge_vlan_group *nbp_vlan_group( 1508 const struct net_bridge_port *p) 1509 { 1510 return rtnl_dereference(p->vlgrp); 1511 } 1512 1513 static inline struct net_bridge_vlan_group *br_vlan_group_rcu( 1514 const struct net_bridge *br) 1515 { 1516 return rcu_dereference(br->vlgrp); 1517 } 1518 1519 static inline struct net_bridge_vlan_group *nbp_vlan_group_rcu( 1520 const struct net_bridge_port *p) 1521 { 1522 return rcu_dereference(p->vlgrp); 1523 } 1524 1525 /* Since bridge now depends on 8021Q module, but the time bridge sees the 1526 * skb, the vlan tag will always be present if the frame was tagged. 1527 */ 1528 static inline int br_vlan_get_tag(const struct sk_buff *skb, u16 *vid) 1529 { 1530 int err = 0; 1531 1532 if (skb_vlan_tag_present(skb)) { 1533 *vid = skb_vlan_tag_get_id(skb); 1534 } else { 1535 *vid = 0; 1536 err = -EINVAL; 1537 } 1538 1539 return err; 1540 } 1541 1542 static inline u16 br_get_pvid(const struct net_bridge_vlan_group *vg) 1543 { 1544 if (!vg) 1545 return 0; 1546 1547 smp_rmb(); 1548 return vg->pvid; 1549 } 1550 1551 static inline u16 br_vlan_flags(const struct net_bridge_vlan *v, u16 pvid) 1552 { 1553 return v->vid == pvid ? v->flags | BRIDGE_VLAN_INFO_PVID : v->flags; 1554 } 1555 #else 1556 static inline bool br_allowed_ingress(const struct net_bridge *br, 1557 struct net_bridge_vlan_group *vg, 1558 struct sk_buff *skb, 1559 u16 *vid, u8 *state, 1560 struct net_bridge_vlan **vlan) 1561 1562 { 1563 *vlan = NULL; 1564 return true; 1565 } 1566 1567 static inline bool br_allowed_egress(struct net_bridge_vlan_group *vg, 1568 const struct sk_buff *skb) 1569 { 1570 return true; 1571 } 1572 1573 static inline bool br_should_learn(struct net_bridge_port *p, 1574 struct sk_buff *skb, u16 *vid) 1575 { 1576 return true; 1577 } 1578 1579 static inline struct sk_buff *br_handle_vlan(struct net_bridge *br, 1580 const struct net_bridge_port *port, 1581 struct net_bridge_vlan_group *vg, 1582 struct sk_buff *skb) 1583 { 1584 return skb; 1585 } 1586 1587 static inline int br_vlan_add(struct net_bridge *br, u16 vid, u16 flags, 1588 bool *changed, struct netlink_ext_ack *extack) 1589 { 1590 *changed = false; 1591 return -EOPNOTSUPP; 1592 } 1593 1594 static inline int br_vlan_delete(struct net_bridge *br, u16 vid) 1595 { 1596 return -EOPNOTSUPP; 1597 } 1598 1599 static inline void br_vlan_flush(struct net_bridge *br) 1600 { 1601 } 1602 1603 static inline void br_recalculate_fwd_mask(struct net_bridge *br) 1604 { 1605 } 1606 1607 static inline int br_vlan_init(struct net_bridge *br) 1608 { 1609 return 0; 1610 } 1611 1612 static inline int nbp_vlan_add(struct net_bridge_port *port, u16 vid, u16 flags, 1613 bool *changed, struct netlink_ext_ack *extack) 1614 { 1615 *changed = false; 1616 return -EOPNOTSUPP; 1617 } 1618 1619 static inline int nbp_vlan_delete(struct net_bridge_port *port, u16 vid) 1620 { 1621 return -EOPNOTSUPP; 1622 } 1623 1624 static inline void nbp_vlan_flush(struct net_bridge_port *port) 1625 { 1626 } 1627 1628 static inline struct net_bridge_vlan *br_vlan_find(struct net_bridge_vlan_group *vg, 1629 u16 vid) 1630 { 1631 return NULL; 1632 } 1633 1634 static inline int nbp_vlan_init(struct net_bridge_port *port, 1635 struct netlink_ext_ack *extack) 1636 { 1637 return 0; 1638 } 1639 1640 static inline u16 br_vlan_get_tag(const struct sk_buff *skb, u16 *tag) 1641 { 1642 return 0; 1643 } 1644 1645 static inline u16 br_get_pvid(const struct net_bridge_vlan_group *vg) 1646 { 1647 return 0; 1648 } 1649 1650 static inline int br_vlan_filter_toggle(struct net_bridge *br, 1651 unsigned long val, 1652 struct netlink_ext_ack *extack) 1653 { 1654 return -EOPNOTSUPP; 1655 } 1656 1657 static inline int nbp_get_num_vlan_infos(struct net_bridge_port *p, 1658 u32 filter_mask) 1659 { 1660 return 0; 1661 } 1662 1663 static inline void br_vlan_fill_forward_path_pvid(struct net_bridge *br, 1664 struct net_device_path_ctx *ctx, 1665 struct net_device_path *path) 1666 { 1667 } 1668 1669 static inline int br_vlan_fill_forward_path_mode(struct net_bridge *br, 1670 struct net_bridge_port *dst, 1671 struct net_device_path *path) 1672 { 1673 return 0; 1674 } 1675 1676 static inline struct net_bridge_vlan_group *br_vlan_group( 1677 const struct net_bridge *br) 1678 { 1679 return NULL; 1680 } 1681 1682 static inline struct net_bridge_vlan_group *nbp_vlan_group( 1683 const struct net_bridge_port *p) 1684 { 1685 return NULL; 1686 } 1687 1688 static inline struct net_bridge_vlan_group *br_vlan_group_rcu( 1689 const struct net_bridge *br) 1690 { 1691 return NULL; 1692 } 1693 1694 static inline struct net_bridge_vlan_group *nbp_vlan_group_rcu( 1695 const struct net_bridge_port *p) 1696 { 1697 return NULL; 1698 } 1699 1700 static inline void br_vlan_get_stats(const struct net_bridge_vlan *v, 1701 struct pcpu_sw_netstats *stats) 1702 { 1703 } 1704 1705 static inline void br_vlan_port_event(struct net_bridge_port *p, 1706 unsigned long event) 1707 { 1708 } 1709 1710 static inline int br_vlan_bridge_event(struct net_device *dev, 1711 unsigned long event, void *ptr) 1712 { 1713 return 0; 1714 } 1715 1716 static inline void br_vlan_rtnl_init(void) 1717 { 1718 } 1719 1720 static inline void br_vlan_rtnl_uninit(void) 1721 { 1722 } 1723 1724 static inline void br_vlan_notify(const struct net_bridge *br, 1725 const struct net_bridge_port *p, 1726 u16 vid, u16 vid_range, 1727 int cmd) 1728 { 1729 } 1730 1731 static inline bool br_vlan_can_enter_range(const struct net_bridge_vlan *v_curr, 1732 const struct net_bridge_vlan *range_end) 1733 { 1734 return true; 1735 } 1736 1737 static inline u16 br_vlan_flags(const struct net_bridge_vlan *v, u16 pvid) 1738 { 1739 return 0; 1740 } 1741 1742 #endif 1743 1744 /* br_vlan_options.c */ 1745 #ifdef CONFIG_BRIDGE_VLAN_FILTERING 1746 bool br_vlan_opts_eq_range(const struct net_bridge_vlan *v_curr, 1747 const struct net_bridge_vlan *range_end); 1748 bool br_vlan_opts_fill(struct sk_buff *skb, const struct net_bridge_vlan *v); 1749 size_t br_vlan_opts_nl_size(void); 1750 int br_vlan_process_options(const struct net_bridge *br, 1751 const struct net_bridge_port *p, 1752 struct net_bridge_vlan *range_start, 1753 struct net_bridge_vlan *range_end, 1754 struct nlattr **tb, 1755 struct netlink_ext_ack *extack); 1756 int br_vlan_rtm_process_global_options(struct net_device *dev, 1757 const struct nlattr *attr, 1758 int cmd, 1759 struct netlink_ext_ack *extack); 1760 bool br_vlan_global_opts_can_enter_range(const struct net_bridge_vlan *v_curr, 1761 const struct net_bridge_vlan *r_end); 1762 bool br_vlan_global_opts_fill(struct sk_buff *skb, u16 vid, u16 vid_range, 1763 const struct net_bridge_vlan *v_opts); 1764 1765 /* vlan state manipulation helpers using *_ONCE to annotate lock-free access */ 1766 static inline u8 br_vlan_get_state(const struct net_bridge_vlan *v) 1767 { 1768 return READ_ONCE(v->state); 1769 } 1770 1771 static inline void br_vlan_set_state(struct net_bridge_vlan *v, u8 state) 1772 { 1773 WRITE_ONCE(v->state, state); 1774 } 1775 1776 static inline u8 br_vlan_get_pvid_state(const struct net_bridge_vlan_group *vg) 1777 { 1778 return READ_ONCE(vg->pvid_state); 1779 } 1780 1781 static inline void br_vlan_set_pvid_state(struct net_bridge_vlan_group *vg, 1782 u8 state) 1783 { 1784 WRITE_ONCE(vg->pvid_state, state); 1785 } 1786 1787 /* learn_allow is true at ingress and false at egress */ 1788 static inline bool br_vlan_state_allowed(u8 state, bool learn_allow) 1789 { 1790 switch (state) { 1791 case BR_STATE_LEARNING: 1792 return learn_allow; 1793 case BR_STATE_FORWARDING: 1794 return true; 1795 default: 1796 return false; 1797 } 1798 } 1799 #endif 1800 1801 /* br_mst.c */ 1802 #ifdef CONFIG_BRIDGE_VLAN_FILTERING 1803 DECLARE_STATIC_KEY_FALSE(br_mst_used); 1804 static inline bool br_mst_is_enabled(struct net_bridge *br) 1805 { 1806 return static_branch_unlikely(&br_mst_used) && 1807 br_opt_get(br, BROPT_MST_ENABLED); 1808 } 1809 1810 int br_mst_set_state(struct net_bridge_port *p, u16 msti, u8 state, 1811 struct netlink_ext_ack *extack); 1812 int br_mst_vlan_set_msti(struct net_bridge_vlan *v, u16 msti); 1813 void br_mst_vlan_init_state(struct net_bridge_vlan *v); 1814 int br_mst_set_enabled(struct net_bridge *br, bool on, 1815 struct netlink_ext_ack *extack); 1816 size_t br_mst_info_size(const struct net_bridge_vlan_group *vg); 1817 int br_mst_fill_info(struct sk_buff *skb, 1818 const struct net_bridge_vlan_group *vg); 1819 int br_mst_process(struct net_bridge_port *p, const struct nlattr *mst_attr, 1820 struct netlink_ext_ack *extack); 1821 #else 1822 static inline bool br_mst_is_enabled(struct net_bridge *br) 1823 { 1824 return false; 1825 } 1826 1827 static inline int br_mst_set_state(struct net_bridge_port *p, u16 msti, 1828 u8 state, struct netlink_ext_ack *extack) 1829 { 1830 return -EOPNOTSUPP; 1831 } 1832 1833 static inline int br_mst_set_enabled(struct net_bridge *br, bool on, 1834 struct netlink_ext_ack *extack) 1835 { 1836 return -EOPNOTSUPP; 1837 } 1838 1839 static inline size_t br_mst_info_size(const struct net_bridge_vlan_group *vg) 1840 { 1841 return 0; 1842 } 1843 1844 static inline int br_mst_fill_info(struct sk_buff *skb, 1845 const struct net_bridge_vlan_group *vg) 1846 { 1847 return -EOPNOTSUPP; 1848 } 1849 1850 static inline int br_mst_process(struct net_bridge_port *p, 1851 const struct nlattr *mst_attr, 1852 struct netlink_ext_ack *extack) 1853 { 1854 return -EOPNOTSUPP; 1855 } 1856 #endif 1857 1858 struct nf_br_ops { 1859 int (*br_dev_xmit_hook)(struct sk_buff *skb); 1860 }; 1861 extern const struct nf_br_ops __rcu *nf_br_ops; 1862 1863 /* br_netfilter.c */ 1864 #if IS_ENABLED(CONFIG_BRIDGE_NETFILTER) 1865 int br_nf_core_init(void); 1866 void br_nf_core_fini(void); 1867 void br_netfilter_rtable_init(struct net_bridge *); 1868 #else 1869 static inline int br_nf_core_init(void) { return 0; } 1870 static inline void br_nf_core_fini(void) {} 1871 #define br_netfilter_rtable_init(x) 1872 #endif 1873 1874 /* br_stp.c */ 1875 void br_set_state(struct net_bridge_port *p, unsigned int state); 1876 struct net_bridge_port *br_get_port(struct net_bridge *br, u16 port_no); 1877 void br_init_port(struct net_bridge_port *p); 1878 void br_become_designated_port(struct net_bridge_port *p); 1879 1880 void __br_set_forward_delay(struct net_bridge *br, unsigned long t); 1881 int br_set_forward_delay(struct net_bridge *br, unsigned long x); 1882 int br_set_hello_time(struct net_bridge *br, unsigned long x); 1883 int br_set_max_age(struct net_bridge *br, unsigned long x); 1884 int __set_ageing_time(struct net_device *dev, unsigned long t); 1885 int br_set_ageing_time(struct net_bridge *br, clock_t ageing_time); 1886 1887 1888 /* br_stp_if.c */ 1889 void br_stp_enable_bridge(struct net_bridge *br); 1890 void br_stp_disable_bridge(struct net_bridge *br); 1891 int br_stp_set_enabled(struct net_bridge *br, unsigned long val, 1892 struct netlink_ext_ack *extack); 1893 void br_stp_enable_port(struct net_bridge_port *p); 1894 void br_stp_disable_port(struct net_bridge_port *p); 1895 bool br_stp_recalculate_bridge_id(struct net_bridge *br); 1896 void br_stp_change_bridge_id(struct net_bridge *br, const unsigned char *a); 1897 void br_stp_set_bridge_priority(struct net_bridge *br, u16 newprio); 1898 int br_stp_set_port_priority(struct net_bridge_port *p, unsigned long newprio); 1899 int br_stp_set_path_cost(struct net_bridge_port *p, unsigned long path_cost); 1900 ssize_t br_show_bridge_id(char *buf, const struct bridge_id *id); 1901 1902 /* br_stp_bpdu.c */ 1903 struct stp_proto; 1904 void br_stp_rcv(const struct stp_proto *proto, struct sk_buff *skb, 1905 struct net_device *dev); 1906 1907 /* br_stp_timer.c */ 1908 void br_stp_timer_init(struct net_bridge *br); 1909 void br_stp_port_timer_init(struct net_bridge_port *p); 1910 unsigned long br_timer_value(const struct timer_list *timer); 1911 1912 /* br.c */ 1913 #if IS_ENABLED(CONFIG_ATM_LANE) 1914 extern int (*br_fdb_test_addr_hook)(struct net_device *dev, unsigned char *addr); 1915 #endif 1916 1917 /* br_mrp.c */ 1918 #if IS_ENABLED(CONFIG_BRIDGE_MRP) 1919 int br_mrp_parse(struct net_bridge *br, struct net_bridge_port *p, 1920 struct nlattr *attr, int cmd, struct netlink_ext_ack *extack); 1921 bool br_mrp_enabled(struct net_bridge *br); 1922 void br_mrp_port_del(struct net_bridge *br, struct net_bridge_port *p); 1923 int br_mrp_fill_info(struct sk_buff *skb, struct net_bridge *br); 1924 #else 1925 static inline int br_mrp_parse(struct net_bridge *br, struct net_bridge_port *p, 1926 struct nlattr *attr, int cmd, 1927 struct netlink_ext_ack *extack) 1928 { 1929 return -EOPNOTSUPP; 1930 } 1931 1932 static inline bool br_mrp_enabled(struct net_bridge *br) 1933 { 1934 return false; 1935 } 1936 1937 static inline void br_mrp_port_del(struct net_bridge *br, 1938 struct net_bridge_port *p) 1939 { 1940 } 1941 1942 static inline int br_mrp_fill_info(struct sk_buff *skb, struct net_bridge *br) 1943 { 1944 return 0; 1945 } 1946 1947 #endif 1948 1949 /* br_cfm.c */ 1950 #if IS_ENABLED(CONFIG_BRIDGE_CFM) 1951 int br_cfm_parse(struct net_bridge *br, struct net_bridge_port *p, 1952 struct nlattr *attr, int cmd, struct netlink_ext_ack *extack); 1953 bool br_cfm_created(struct net_bridge *br); 1954 void br_cfm_port_del(struct net_bridge *br, struct net_bridge_port *p); 1955 int br_cfm_config_fill_info(struct sk_buff *skb, struct net_bridge *br); 1956 int br_cfm_status_fill_info(struct sk_buff *skb, 1957 struct net_bridge *br, 1958 bool getlink); 1959 int br_cfm_mep_count(struct net_bridge *br, u32 *count); 1960 int br_cfm_peer_mep_count(struct net_bridge *br, u32 *count); 1961 #else 1962 static inline int br_cfm_parse(struct net_bridge *br, struct net_bridge_port *p, 1963 struct nlattr *attr, int cmd, 1964 struct netlink_ext_ack *extack) 1965 { 1966 return -EOPNOTSUPP; 1967 } 1968 1969 static inline bool br_cfm_created(struct net_bridge *br) 1970 { 1971 return false; 1972 } 1973 1974 static inline void br_cfm_port_del(struct net_bridge *br, 1975 struct net_bridge_port *p) 1976 { 1977 } 1978 1979 static inline int br_cfm_config_fill_info(struct sk_buff *skb, struct net_bridge *br) 1980 { 1981 return -EOPNOTSUPP; 1982 } 1983 1984 static inline int br_cfm_status_fill_info(struct sk_buff *skb, 1985 struct net_bridge *br, 1986 bool getlink) 1987 { 1988 return -EOPNOTSUPP; 1989 } 1990 1991 static inline int br_cfm_mep_count(struct net_bridge *br, u32 *count) 1992 { 1993 *count = 0; 1994 return -EOPNOTSUPP; 1995 } 1996 1997 static inline int br_cfm_peer_mep_count(struct net_bridge *br, u32 *count) 1998 { 1999 *count = 0; 2000 return -EOPNOTSUPP; 2001 } 2002 #endif 2003 2004 /* br_netlink.c */ 2005 extern struct rtnl_link_ops br_link_ops; 2006 int br_netlink_init(void); 2007 void br_netlink_fini(void); 2008 void br_ifinfo_notify(int event, const struct net_bridge *br, 2009 const struct net_bridge_port *port); 2010 void br_info_notify(int event, const struct net_bridge *br, 2011 const struct net_bridge_port *port, u32 filter); 2012 int br_setlink(struct net_device *dev, struct nlmsghdr *nlmsg, u16 flags, 2013 struct netlink_ext_ack *extack); 2014 int br_dellink(struct net_device *dev, struct nlmsghdr *nlmsg, u16 flags); 2015 int br_getlink(struct sk_buff *skb, u32 pid, u32 seq, struct net_device *dev, 2016 u32 filter_mask, int nlflags); 2017 int br_process_vlan_info(struct net_bridge *br, 2018 struct net_bridge_port *p, int cmd, 2019 struct bridge_vlan_info *vinfo_curr, 2020 struct bridge_vlan_info **vinfo_last, 2021 bool *changed, 2022 struct netlink_ext_ack *extack); 2023 2024 #ifdef CONFIG_SYSFS 2025 /* br_sysfs_if.c */ 2026 extern const struct sysfs_ops brport_sysfs_ops; 2027 int br_sysfs_addif(struct net_bridge_port *p); 2028 int br_sysfs_renameif(struct net_bridge_port *p); 2029 2030 /* br_sysfs_br.c */ 2031 int br_sysfs_addbr(struct net_device *dev); 2032 void br_sysfs_delbr(struct net_device *dev); 2033 2034 #else 2035 2036 static inline int br_sysfs_addif(struct net_bridge_port *p) { return 0; } 2037 static inline int br_sysfs_renameif(struct net_bridge_port *p) { return 0; } 2038 static inline int br_sysfs_addbr(struct net_device *dev) { return 0; } 2039 static inline void br_sysfs_delbr(struct net_device *dev) { return; } 2040 #endif /* CONFIG_SYSFS */ 2041 2042 /* br_switchdev.c */ 2043 #ifdef CONFIG_NET_SWITCHDEV 2044 int br_switchdev_port_offload(struct net_bridge_port *p, 2045 struct net_device *dev, const void *ctx, 2046 struct notifier_block *atomic_nb, 2047 struct notifier_block *blocking_nb, 2048 bool tx_fwd_offload, 2049 struct netlink_ext_ack *extack); 2050 2051 void br_switchdev_port_unoffload(struct net_bridge_port *p, const void *ctx, 2052 struct notifier_block *atomic_nb, 2053 struct notifier_block *blocking_nb); 2054 2055 bool br_switchdev_frame_uses_tx_fwd_offload(struct sk_buff *skb); 2056 2057 void br_switchdev_frame_set_offload_fwd_mark(struct sk_buff *skb); 2058 2059 void nbp_switchdev_frame_mark_tx_fwd_offload(const struct net_bridge_port *p, 2060 struct sk_buff *skb); 2061 void nbp_switchdev_frame_mark_tx_fwd_to_hwdom(const struct net_bridge_port *p, 2062 struct sk_buff *skb); 2063 void nbp_switchdev_frame_mark(const struct net_bridge_port *p, 2064 struct sk_buff *skb); 2065 bool nbp_switchdev_allowed_egress(const struct net_bridge_port *p, 2066 const struct sk_buff *skb); 2067 int br_switchdev_set_port_flag(struct net_bridge_port *p, 2068 unsigned long flags, 2069 unsigned long mask, 2070 struct netlink_ext_ack *extack); 2071 void br_switchdev_fdb_notify(struct net_bridge *br, 2072 const struct net_bridge_fdb_entry *fdb, int type); 2073 void br_switchdev_mdb_notify(struct net_device *dev, 2074 struct net_bridge_mdb_entry *mp, 2075 struct net_bridge_port_group *pg, 2076 int type); 2077 int br_switchdev_port_vlan_add(struct net_device *dev, u16 vid, u16 flags, 2078 bool changed, struct netlink_ext_ack *extack); 2079 int br_switchdev_port_vlan_del(struct net_device *dev, u16 vid); 2080 void br_switchdev_init(struct net_bridge *br); 2081 2082 static inline void br_switchdev_frame_unmark(struct sk_buff *skb) 2083 { 2084 skb->offload_fwd_mark = 0; 2085 } 2086 #else 2087 static inline int 2088 br_switchdev_port_offload(struct net_bridge_port *p, 2089 struct net_device *dev, const void *ctx, 2090 struct notifier_block *atomic_nb, 2091 struct notifier_block *blocking_nb, 2092 bool tx_fwd_offload, 2093 struct netlink_ext_ack *extack) 2094 { 2095 return -EOPNOTSUPP; 2096 } 2097 2098 static inline void 2099 br_switchdev_port_unoffload(struct net_bridge_port *p, const void *ctx, 2100 struct notifier_block *atomic_nb, 2101 struct notifier_block *blocking_nb) 2102 { 2103 } 2104 2105 static inline bool br_switchdev_frame_uses_tx_fwd_offload(struct sk_buff *skb) 2106 { 2107 return false; 2108 } 2109 2110 static inline void br_switchdev_frame_set_offload_fwd_mark(struct sk_buff *skb) 2111 { 2112 } 2113 2114 static inline void 2115 nbp_switchdev_frame_mark_tx_fwd_offload(const struct net_bridge_port *p, 2116 struct sk_buff *skb) 2117 { 2118 } 2119 2120 static inline void 2121 nbp_switchdev_frame_mark_tx_fwd_to_hwdom(const struct net_bridge_port *p, 2122 struct sk_buff *skb) 2123 { 2124 } 2125 2126 static inline void nbp_switchdev_frame_mark(const struct net_bridge_port *p, 2127 struct sk_buff *skb) 2128 { 2129 } 2130 2131 static inline bool nbp_switchdev_allowed_egress(const struct net_bridge_port *p, 2132 const struct sk_buff *skb) 2133 { 2134 return true; 2135 } 2136 2137 static inline int br_switchdev_set_port_flag(struct net_bridge_port *p, 2138 unsigned long flags, 2139 unsigned long mask, 2140 struct netlink_ext_ack *extack) 2141 { 2142 return 0; 2143 } 2144 2145 static inline int br_switchdev_port_vlan_add(struct net_device *dev, u16 vid, 2146 u16 flags, bool changed, 2147 struct netlink_ext_ack *extack) 2148 { 2149 return -EOPNOTSUPP; 2150 } 2151 2152 static inline int br_switchdev_port_vlan_del(struct net_device *dev, u16 vid) 2153 { 2154 return -EOPNOTSUPP; 2155 } 2156 2157 static inline void 2158 br_switchdev_fdb_notify(struct net_bridge *br, 2159 const struct net_bridge_fdb_entry *fdb, int type) 2160 { 2161 } 2162 2163 static inline void br_switchdev_mdb_notify(struct net_device *dev, 2164 struct net_bridge_mdb_entry *mp, 2165 struct net_bridge_port_group *pg, 2166 int type) 2167 { 2168 } 2169 2170 static inline void br_switchdev_frame_unmark(struct sk_buff *skb) 2171 { 2172 } 2173 2174 static inline void br_switchdev_init(struct net_bridge *br) 2175 { 2176 } 2177 2178 #endif /* CONFIG_NET_SWITCHDEV */ 2179 2180 /* br_arp_nd_proxy.c */ 2181 void br_recalculate_neigh_suppress_enabled(struct net_bridge *br); 2182 void br_do_proxy_suppress_arp(struct sk_buff *skb, struct net_bridge *br, 2183 u16 vid, struct net_bridge_port *p); 2184 void br_do_suppress_nd(struct sk_buff *skb, struct net_bridge *br, 2185 u16 vid, struct net_bridge_port *p, struct nd_msg *msg); 2186 struct nd_msg *br_is_nd_neigh_msg(struct sk_buff *skb, struct nd_msg *m); 2187 #endif 2188