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