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