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