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