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_VERSION "2.3" 33 34 /* Control of forwarding link local multicast */ 35 #define BR_GROUPFWD_DEFAULT 0 36 /* Don't allow forwarding of control protocols like STP, MAC PAUSE and LACP */ 37 enum { 38 BR_GROUPFWD_STP = BIT(0), 39 BR_GROUPFWD_MACPAUSE = BIT(1), 40 BR_GROUPFWD_LACP = BIT(2), 41 }; 42 43 #define BR_GROUPFWD_RESTRICTED (BR_GROUPFWD_STP | BR_GROUPFWD_MACPAUSE | \ 44 BR_GROUPFWD_LACP) 45 /* The Nearest Customer Bridge Group Address, 01-80-C2-00-00-[00,0B,0C,0D,0F] */ 46 #define BR_GROUPFWD_8021AD 0xB801u 47 48 /* Path to usermode spanning tree program */ 49 #define BR_STP_PROG "/sbin/bridge-stp" 50 51 typedef struct bridge_id bridge_id; 52 typedef struct mac_addr mac_addr; 53 typedef __u16 port_id; 54 55 struct bridge_id { 56 unsigned char prio[2]; 57 unsigned char addr[ETH_ALEN]; 58 }; 59 60 struct mac_addr { 61 unsigned char addr[ETH_ALEN]; 62 }; 63 64 #ifdef CONFIG_BRIDGE_IGMP_SNOOPING 65 /* our own querier */ 66 struct bridge_mcast_own_query { 67 struct timer_list timer; 68 u32 startup_sent; 69 }; 70 71 /* other querier */ 72 struct bridge_mcast_other_query { 73 struct timer_list timer; 74 unsigned long delay_time; 75 }; 76 77 /* selected querier */ 78 struct bridge_mcast_querier { 79 struct br_ip addr; 80 struct net_bridge_port __rcu *port; 81 }; 82 83 /* IGMP/MLD statistics */ 84 struct bridge_mcast_stats { 85 struct br_mcast_stats mstats; 86 struct u64_stats_sync syncp; 87 }; 88 #endif 89 90 struct br_vlan_stats { 91 u64 rx_bytes; 92 u64 rx_packets; 93 u64 tx_bytes; 94 u64 tx_packets; 95 struct u64_stats_sync syncp; 96 }; 97 98 struct br_tunnel_info { 99 __be64 tunnel_id; 100 struct metadata_dst *tunnel_dst; 101 }; 102 103 /* private vlan flags */ 104 enum { 105 BR_VLFLAG_PER_PORT_STATS = BIT(0), 106 BR_VLFLAG_ADDED_BY_SWITCHDEV = BIT(1), 107 }; 108 109 /** 110 * struct net_bridge_vlan - per-vlan entry 111 * 112 * @vnode: rhashtable member 113 * @vid: VLAN id 114 * @flags: bridge vlan flags 115 * @priv_flags: private (in-kernel) bridge vlan flags 116 * @state: STP state (e.g. blocking, learning, forwarding) 117 * @stats: per-cpu VLAN statistics 118 * @br: if MASTER flag set, this points to a bridge struct 119 * @port: if MASTER flag unset, this points to a port struct 120 * @refcnt: if MASTER flag set, this is bumped for each port referencing it 121 * @brvlan: if MASTER flag unset, this points to the global per-VLAN context 122 * for this VLAN entry 123 * @vlist: sorted list of VLAN entries 124 * @rcu: used for entry destruction 125 * 126 * This structure is shared between the global per-VLAN entries contained in 127 * the bridge rhashtable and the local per-port per-VLAN entries contained in 128 * the port's rhashtable. The union entries should be interpreted depending on 129 * the entry flags that are set. 130 */ 131 struct net_bridge_vlan { 132 struct rhash_head vnode; 133 struct rhash_head tnode; 134 u16 vid; 135 u16 flags; 136 u16 priv_flags; 137 u8 state; 138 struct br_vlan_stats __percpu *stats; 139 union { 140 struct net_bridge *br; 141 struct net_bridge_port *port; 142 }; 143 union { 144 refcount_t refcnt; 145 struct net_bridge_vlan *brvlan; 146 }; 147 148 struct br_tunnel_info tinfo; 149 150 struct list_head vlist; 151 152 struct rcu_head rcu; 153 }; 154 155 /** 156 * struct net_bridge_vlan_group 157 * 158 * @vlan_hash: VLAN entry rhashtable 159 * @vlan_list: sorted VLAN entry list 160 * @num_vlans: number of total VLAN entries 161 * @pvid: PVID VLAN id 162 * @pvid_state: PVID's STP state (e.g. forwarding, learning, blocking) 163 * 164 * IMPORTANT: Be careful when checking if there're VLAN entries using list 165 * primitives because the bridge can have entries in its list which 166 * are just for global context but not for filtering, i.e. they have 167 * the master flag set but not the brentry flag. If you have to check 168 * if there're "real" entries in the bridge please test @num_vlans 169 */ 170 struct net_bridge_vlan_group { 171 struct rhashtable vlan_hash; 172 struct rhashtable tunnel_hash; 173 struct list_head vlan_list; 174 u16 num_vlans; 175 u16 pvid; 176 u8 pvid_state; 177 }; 178 179 /* bridge fdb flags */ 180 enum { 181 BR_FDB_LOCAL, 182 BR_FDB_STATIC, 183 BR_FDB_STICKY, 184 BR_FDB_ADDED_BY_USER, 185 BR_FDB_ADDED_BY_EXT_LEARN, 186 BR_FDB_OFFLOADED, 187 }; 188 189 struct net_bridge_fdb_key { 190 mac_addr addr; 191 u16 vlan_id; 192 }; 193 194 struct net_bridge_fdb_entry { 195 struct rhash_head rhnode; 196 struct net_bridge_port *dst; 197 198 struct net_bridge_fdb_key key; 199 struct hlist_node fdb_node; 200 unsigned long flags; 201 202 /* write-heavy members should not affect lookups */ 203 unsigned long updated ____cacheline_aligned_in_smp; 204 unsigned long used; 205 206 struct rcu_head rcu; 207 }; 208 209 #define MDB_PG_FLAGS_PERMANENT BIT(0) 210 #define MDB_PG_FLAGS_OFFLOAD BIT(1) 211 #define MDB_PG_FLAGS_FAST_LEAVE BIT(2) 212 213 struct net_bridge_port_group { 214 struct net_bridge_port *port; 215 struct net_bridge_port_group __rcu *next; 216 struct hlist_node mglist; 217 struct rcu_head rcu; 218 struct timer_list timer; 219 struct br_ip addr; 220 unsigned char eth_addr[ETH_ALEN] __aligned(2); 221 unsigned char flags; 222 }; 223 224 struct net_bridge_mdb_entry { 225 struct rhash_head rhnode; 226 struct net_bridge *br; 227 struct net_bridge_port_group __rcu *ports; 228 struct rcu_head rcu; 229 struct timer_list timer; 230 struct br_ip addr; 231 bool host_joined; 232 struct hlist_node mdb_node; 233 }; 234 235 struct net_bridge_port { 236 struct net_bridge *br; 237 struct net_device *dev; 238 struct list_head list; 239 240 unsigned long flags; 241 #ifdef CONFIG_BRIDGE_VLAN_FILTERING 242 struct net_bridge_vlan_group __rcu *vlgrp; 243 #endif 244 struct net_bridge_port __rcu *backup_port; 245 246 /* STP */ 247 u8 priority; 248 u8 state; 249 u16 port_no; 250 unsigned char topology_change_ack; 251 unsigned char config_pending; 252 port_id port_id; 253 port_id designated_port; 254 bridge_id designated_root; 255 bridge_id designated_bridge; 256 u32 path_cost; 257 u32 designated_cost; 258 unsigned long designated_age; 259 260 struct timer_list forward_delay_timer; 261 struct timer_list hold_timer; 262 struct timer_list message_age_timer; 263 struct kobject kobj; 264 struct rcu_head rcu; 265 266 #ifdef CONFIG_BRIDGE_IGMP_SNOOPING 267 struct bridge_mcast_own_query ip4_own_query; 268 #if IS_ENABLED(CONFIG_IPV6) 269 struct bridge_mcast_own_query ip6_own_query; 270 #endif /* IS_ENABLED(CONFIG_IPV6) */ 271 unsigned char multicast_router; 272 struct bridge_mcast_stats __percpu *mcast_stats; 273 struct timer_list multicast_router_timer; 274 struct hlist_head mglist; 275 struct hlist_node rlist; 276 #endif 277 278 #ifdef CONFIG_SYSFS 279 char sysfs_name[IFNAMSIZ]; 280 #endif 281 282 #ifdef CONFIG_NET_POLL_CONTROLLER 283 struct netpoll *np; 284 #endif 285 #ifdef CONFIG_NET_SWITCHDEV 286 int offload_fwd_mark; 287 #endif 288 u16 group_fwd_mask; 289 u16 backup_redirected_cnt; 290 291 struct bridge_stp_xstats stp_xstats; 292 }; 293 294 #define kobj_to_brport(obj) container_of(obj, struct net_bridge_port, kobj) 295 296 #define br_auto_port(p) ((p)->flags & BR_AUTO_MASK) 297 #define br_promisc_port(p) ((p)->flags & BR_PROMISC) 298 299 static inline struct net_bridge_port *br_port_get_rcu(const struct net_device *dev) 300 { 301 return rcu_dereference(dev->rx_handler_data); 302 } 303 304 static inline struct net_bridge_port *br_port_get_rtnl(const struct net_device *dev) 305 { 306 return netif_is_bridge_port(dev) ? 307 rtnl_dereference(dev->rx_handler_data) : NULL; 308 } 309 310 static inline struct net_bridge_port *br_port_get_rtnl_rcu(const struct net_device *dev) 311 { 312 return netif_is_bridge_port(dev) ? 313 rcu_dereference_rtnl(dev->rx_handler_data) : NULL; 314 } 315 316 enum net_bridge_opts { 317 BROPT_VLAN_ENABLED, 318 BROPT_VLAN_STATS_ENABLED, 319 BROPT_NF_CALL_IPTABLES, 320 BROPT_NF_CALL_IP6TABLES, 321 BROPT_NF_CALL_ARPTABLES, 322 BROPT_GROUP_ADDR_SET, 323 BROPT_MULTICAST_ENABLED, 324 BROPT_MULTICAST_QUERIER, 325 BROPT_MULTICAST_QUERY_USE_IFADDR, 326 BROPT_MULTICAST_STATS_ENABLED, 327 BROPT_HAS_IPV6_ADDR, 328 BROPT_NEIGH_SUPPRESS_ENABLED, 329 BROPT_MTU_SET_BY_USER, 330 BROPT_VLAN_STATS_PER_PORT, 331 BROPT_NO_LL_LEARN, 332 BROPT_VLAN_BRIDGE_BINDING, 333 }; 334 335 struct net_bridge { 336 spinlock_t lock; 337 spinlock_t hash_lock; 338 struct list_head port_list; 339 struct net_device *dev; 340 struct pcpu_sw_netstats __percpu *stats; 341 unsigned long options; 342 /* These fields are accessed on each packet */ 343 #ifdef CONFIG_BRIDGE_VLAN_FILTERING 344 __be16 vlan_proto; 345 u16 default_pvid; 346 struct net_bridge_vlan_group __rcu *vlgrp; 347 #endif 348 349 struct rhashtable fdb_hash_tbl; 350 #if IS_ENABLED(CONFIG_BRIDGE_NETFILTER) 351 union { 352 struct rtable fake_rtable; 353 struct rt6_info fake_rt6_info; 354 }; 355 #endif 356 u16 group_fwd_mask; 357 u16 group_fwd_mask_required; 358 359 /* STP */ 360 bridge_id designated_root; 361 bridge_id bridge_id; 362 unsigned char topology_change; 363 unsigned char topology_change_detected; 364 u16 root_port; 365 unsigned long max_age; 366 unsigned long hello_time; 367 unsigned long forward_delay; 368 unsigned long ageing_time; 369 unsigned long bridge_max_age; 370 unsigned long bridge_hello_time; 371 unsigned long bridge_forward_delay; 372 unsigned long bridge_ageing_time; 373 u32 root_path_cost; 374 375 u8 group_addr[ETH_ALEN]; 376 377 enum { 378 BR_NO_STP, /* no spanning tree */ 379 BR_KERNEL_STP, /* old STP in kernel */ 380 BR_USER_STP, /* new RSTP in userspace */ 381 } stp_enabled; 382 383 #ifdef CONFIG_BRIDGE_IGMP_SNOOPING 384 385 u32 hash_max; 386 387 u32 multicast_last_member_count; 388 u32 multicast_startup_query_count; 389 390 u8 multicast_igmp_version; 391 u8 multicast_router; 392 #if IS_ENABLED(CONFIG_IPV6) 393 u8 multicast_mld_version; 394 #endif 395 spinlock_t multicast_lock; 396 unsigned long multicast_last_member_interval; 397 unsigned long multicast_membership_interval; 398 unsigned long multicast_querier_interval; 399 unsigned long multicast_query_interval; 400 unsigned long multicast_query_response_interval; 401 unsigned long multicast_startup_query_interval; 402 403 struct rhashtable mdb_hash_tbl; 404 405 struct hlist_head mdb_list; 406 struct hlist_head router_list; 407 408 struct timer_list multicast_router_timer; 409 struct bridge_mcast_other_query ip4_other_query; 410 struct bridge_mcast_own_query ip4_own_query; 411 struct bridge_mcast_querier ip4_querier; 412 struct bridge_mcast_stats __percpu *mcast_stats; 413 #if IS_ENABLED(CONFIG_IPV6) 414 struct bridge_mcast_other_query ip6_other_query; 415 struct bridge_mcast_own_query ip6_own_query; 416 struct bridge_mcast_querier ip6_querier; 417 #endif /* IS_ENABLED(CONFIG_IPV6) */ 418 #endif 419 420 struct timer_list hello_timer; 421 struct timer_list tcn_timer; 422 struct timer_list topology_change_timer; 423 struct delayed_work gc_work; 424 struct kobject *ifobj; 425 u32 auto_cnt; 426 427 #ifdef CONFIG_NET_SWITCHDEV 428 int offload_fwd_mark; 429 #endif 430 struct hlist_head fdb_list; 431 432 #if IS_ENABLED(CONFIG_BRIDGE_MRP) 433 struct list_head __rcu mrp_list; 434 #endif 435 }; 436 437 struct br_input_skb_cb { 438 struct net_device *brdev; 439 440 u16 frag_max_size; 441 #ifdef CONFIG_BRIDGE_IGMP_SNOOPING 442 u8 igmp; 443 u8 mrouters_only:1; 444 #endif 445 u8 proxyarp_replied:1; 446 u8 src_port_isolated:1; 447 #ifdef CONFIG_BRIDGE_VLAN_FILTERING 448 u8 vlan_filtered:1; 449 #endif 450 #ifdef CONFIG_NETFILTER_FAMILY_BRIDGE 451 u8 br_netfilter_broute:1; 452 #endif 453 454 #ifdef CONFIG_NET_SWITCHDEV 455 int offload_fwd_mark; 456 #endif 457 }; 458 459 #define BR_INPUT_SKB_CB(__skb) ((struct br_input_skb_cb *)(__skb)->cb) 460 461 #ifdef CONFIG_BRIDGE_IGMP_SNOOPING 462 # define BR_INPUT_SKB_CB_MROUTERS_ONLY(__skb) (BR_INPUT_SKB_CB(__skb)->mrouters_only) 463 #else 464 # define BR_INPUT_SKB_CB_MROUTERS_ONLY(__skb) (0) 465 #endif 466 467 #define br_printk(level, br, format, args...) \ 468 printk(level "%s: " format, (br)->dev->name, ##args) 469 470 #define br_err(__br, format, args...) \ 471 br_printk(KERN_ERR, __br, format, ##args) 472 #define br_warn(__br, format, args...) \ 473 br_printk(KERN_WARNING, __br, format, ##args) 474 #define br_notice(__br, format, args...) \ 475 br_printk(KERN_NOTICE, __br, format, ##args) 476 #define br_info(__br, format, args...) \ 477 br_printk(KERN_INFO, __br, format, ##args) 478 479 #define br_debug(br, format, args...) \ 480 pr_debug("%s: " format, (br)->dev->name, ##args) 481 482 /* called under bridge lock */ 483 static inline int br_is_root_bridge(const struct net_bridge *br) 484 { 485 return !memcmp(&br->bridge_id, &br->designated_root, 8); 486 } 487 488 /* check if a VLAN entry is global */ 489 static inline bool br_vlan_is_master(const struct net_bridge_vlan *v) 490 { 491 return v->flags & BRIDGE_VLAN_INFO_MASTER; 492 } 493 494 /* check if a VLAN entry is used by the bridge */ 495 static inline bool br_vlan_is_brentry(const struct net_bridge_vlan *v) 496 { 497 return v->flags & BRIDGE_VLAN_INFO_BRENTRY; 498 } 499 500 /* check if we should use the vlan entry, returns false if it's only context */ 501 static inline bool br_vlan_should_use(const struct net_bridge_vlan *v) 502 { 503 if (br_vlan_is_master(v)) { 504 if (br_vlan_is_brentry(v)) 505 return true; 506 else 507 return false; 508 } 509 510 return true; 511 } 512 513 static inline bool nbp_state_should_learn(const struct net_bridge_port *p) 514 { 515 return p->state == BR_STATE_LEARNING || p->state == BR_STATE_FORWARDING; 516 } 517 518 static inline bool br_vlan_valid_id(u16 vid, struct netlink_ext_ack *extack) 519 { 520 bool ret = vid > 0 && vid < VLAN_VID_MASK; 521 522 if (!ret) 523 NL_SET_ERR_MSG_MOD(extack, "Vlan id is invalid"); 524 525 return ret; 526 } 527 528 static inline bool br_vlan_valid_range(const struct bridge_vlan_info *cur, 529 const struct bridge_vlan_info *last, 530 struct netlink_ext_ack *extack) 531 { 532 /* pvid flag is not allowed in ranges */ 533 if (cur->flags & BRIDGE_VLAN_INFO_PVID) { 534 NL_SET_ERR_MSG_MOD(extack, "Pvid isn't allowed in a range"); 535 return false; 536 } 537 538 /* when cur is the range end, check if: 539 * - it has range start flag 540 * - range ids are invalid (end is equal to or before start) 541 */ 542 if (last) { 543 if (cur->flags & BRIDGE_VLAN_INFO_RANGE_BEGIN) { 544 NL_SET_ERR_MSG_MOD(extack, "Found a new vlan range start while processing one"); 545 return false; 546 } else if (!(cur->flags & BRIDGE_VLAN_INFO_RANGE_END)) { 547 NL_SET_ERR_MSG_MOD(extack, "Vlan range end flag is missing"); 548 return false; 549 } else if (cur->vid <= last->vid) { 550 NL_SET_ERR_MSG_MOD(extack, "End vlan id is less than or equal to start vlan id"); 551 return false; 552 } 553 } 554 555 /* check for required range flags */ 556 if (!(cur->flags & (BRIDGE_VLAN_INFO_RANGE_BEGIN | 557 BRIDGE_VLAN_INFO_RANGE_END))) { 558 NL_SET_ERR_MSG_MOD(extack, "Both vlan range flags are missing"); 559 return false; 560 } 561 562 return true; 563 } 564 565 static inline int br_afspec_cmd_to_rtm(int cmd) 566 { 567 switch (cmd) { 568 case RTM_SETLINK: 569 return RTM_NEWVLAN; 570 case RTM_DELLINK: 571 return RTM_DELVLAN; 572 } 573 574 return 0; 575 } 576 577 static inline int br_opt_get(const struct net_bridge *br, 578 enum net_bridge_opts opt) 579 { 580 return test_bit(opt, &br->options); 581 } 582 583 int br_boolopt_toggle(struct net_bridge *br, enum br_boolopt_id opt, bool on, 584 struct netlink_ext_ack *extack); 585 int br_boolopt_get(const struct net_bridge *br, enum br_boolopt_id opt); 586 int br_boolopt_multi_toggle(struct net_bridge *br, 587 struct br_boolopt_multi *bm, 588 struct netlink_ext_ack *extack); 589 void br_boolopt_multi_get(const struct net_bridge *br, 590 struct br_boolopt_multi *bm); 591 void br_opt_toggle(struct net_bridge *br, enum net_bridge_opts opt, bool on); 592 593 /* br_device.c */ 594 void br_dev_setup(struct net_device *dev); 595 void br_dev_delete(struct net_device *dev, struct list_head *list); 596 netdev_tx_t br_dev_xmit(struct sk_buff *skb, struct net_device *dev); 597 #ifdef CONFIG_NET_POLL_CONTROLLER 598 static inline void br_netpoll_send_skb(const struct net_bridge_port *p, 599 struct sk_buff *skb) 600 { 601 netpoll_send_skb(p->np, skb); 602 } 603 604 int br_netpoll_enable(struct net_bridge_port *p); 605 void br_netpoll_disable(struct net_bridge_port *p); 606 #else 607 static inline void br_netpoll_send_skb(const struct net_bridge_port *p, 608 struct sk_buff *skb) 609 { 610 } 611 612 static inline int br_netpoll_enable(struct net_bridge_port *p) 613 { 614 return 0; 615 } 616 617 static inline void br_netpoll_disable(struct net_bridge_port *p) 618 { 619 } 620 #endif 621 622 /* br_fdb.c */ 623 int br_fdb_init(void); 624 void br_fdb_fini(void); 625 int br_fdb_hash_init(struct net_bridge *br); 626 void br_fdb_hash_fini(struct net_bridge *br); 627 void br_fdb_flush(struct net_bridge *br); 628 void br_fdb_find_delete_local(struct net_bridge *br, 629 const struct net_bridge_port *p, 630 const unsigned char *addr, u16 vid); 631 void br_fdb_changeaddr(struct net_bridge_port *p, const unsigned char *newaddr); 632 void br_fdb_change_mac_address(struct net_bridge *br, const u8 *newaddr); 633 void br_fdb_cleanup(struct work_struct *work); 634 void br_fdb_delete_by_port(struct net_bridge *br, 635 const struct net_bridge_port *p, u16 vid, int do_all); 636 struct net_bridge_fdb_entry *br_fdb_find_rcu(struct net_bridge *br, 637 const unsigned char *addr, 638 __u16 vid); 639 int br_fdb_test_addr(struct net_device *dev, unsigned char *addr); 640 int br_fdb_fillbuf(struct net_bridge *br, void *buf, unsigned long count, 641 unsigned long off); 642 int br_fdb_insert(struct net_bridge *br, struct net_bridge_port *source, 643 const unsigned char *addr, u16 vid); 644 void br_fdb_update(struct net_bridge *br, struct net_bridge_port *source, 645 const unsigned char *addr, u16 vid, unsigned long flags); 646 647 int br_fdb_delete(struct ndmsg *ndm, struct nlattr *tb[], 648 struct net_device *dev, const unsigned char *addr, u16 vid); 649 int br_fdb_add(struct ndmsg *nlh, struct nlattr *tb[], struct net_device *dev, 650 const unsigned char *addr, u16 vid, u16 nlh_flags, 651 struct netlink_ext_ack *extack); 652 int br_fdb_dump(struct sk_buff *skb, struct netlink_callback *cb, 653 struct net_device *dev, struct net_device *fdev, int *idx); 654 int br_fdb_get(struct sk_buff *skb, struct nlattr *tb[], struct net_device *dev, 655 const unsigned char *addr, u16 vid, u32 portid, u32 seq, 656 struct netlink_ext_ack *extack); 657 int br_fdb_sync_static(struct net_bridge *br, struct net_bridge_port *p); 658 void br_fdb_unsync_static(struct net_bridge *br, struct net_bridge_port *p); 659 int br_fdb_external_learn_add(struct net_bridge *br, struct net_bridge_port *p, 660 const unsigned char *addr, u16 vid, 661 bool swdev_notify); 662 int br_fdb_external_learn_del(struct net_bridge *br, struct net_bridge_port *p, 663 const unsigned char *addr, u16 vid, 664 bool swdev_notify); 665 void br_fdb_offloaded_set(struct net_bridge *br, struct net_bridge_port *p, 666 const unsigned char *addr, u16 vid, bool offloaded); 667 668 /* br_forward.c */ 669 enum br_pkt_type { 670 BR_PKT_UNICAST, 671 BR_PKT_MULTICAST, 672 BR_PKT_BROADCAST 673 }; 674 int br_dev_queue_push_xmit(struct net *net, struct sock *sk, struct sk_buff *skb); 675 void br_forward(const struct net_bridge_port *to, struct sk_buff *skb, 676 bool local_rcv, bool local_orig); 677 int br_forward_finish(struct net *net, struct sock *sk, struct sk_buff *skb); 678 void br_flood(struct net_bridge *br, struct sk_buff *skb, 679 enum br_pkt_type pkt_type, bool local_rcv, bool local_orig); 680 681 /* return true if both source port and dest port are isolated */ 682 static inline bool br_skb_isolated(const struct net_bridge_port *to, 683 const struct sk_buff *skb) 684 { 685 return BR_INPUT_SKB_CB(skb)->src_port_isolated && 686 (to->flags & BR_ISOLATED); 687 } 688 689 /* br_if.c */ 690 void br_port_carrier_check(struct net_bridge_port *p, bool *notified); 691 int br_add_bridge(struct net *net, const char *name); 692 int br_del_bridge(struct net *net, const char *name); 693 int br_add_if(struct net_bridge *br, struct net_device *dev, 694 struct netlink_ext_ack *extack); 695 int br_del_if(struct net_bridge *br, struct net_device *dev); 696 void br_mtu_auto_adjust(struct net_bridge *br); 697 netdev_features_t br_features_recompute(struct net_bridge *br, 698 netdev_features_t features); 699 void br_port_flags_change(struct net_bridge_port *port, unsigned long mask); 700 void br_manage_promisc(struct net_bridge *br); 701 int nbp_backup_change(struct net_bridge_port *p, struct net_device *backup_dev); 702 703 /* br_input.c */ 704 int br_handle_frame_finish(struct net *net, struct sock *sk, struct sk_buff *skb); 705 rx_handler_func_t *br_get_rx_handler(const struct net_device *dev); 706 707 static inline bool br_rx_handler_check_rcu(const struct net_device *dev) 708 { 709 return rcu_dereference(dev->rx_handler) == br_get_rx_handler(dev); 710 } 711 712 static inline bool br_rx_handler_check_rtnl(const struct net_device *dev) 713 { 714 return rcu_dereference_rtnl(dev->rx_handler) == br_get_rx_handler(dev); 715 } 716 717 static inline struct net_bridge_port *br_port_get_check_rcu(const struct net_device *dev) 718 { 719 return br_rx_handler_check_rcu(dev) ? br_port_get_rcu(dev) : NULL; 720 } 721 722 static inline struct net_bridge_port * 723 br_port_get_check_rtnl(const struct net_device *dev) 724 { 725 return br_rx_handler_check_rtnl(dev) ? br_port_get_rtnl_rcu(dev) : NULL; 726 } 727 728 /* br_ioctl.c */ 729 int br_dev_ioctl(struct net_device *dev, struct ifreq *rq, int cmd); 730 int br_ioctl_deviceless_stub(struct net *net, unsigned int cmd, 731 void __user *arg); 732 733 /* br_multicast.c */ 734 #ifdef CONFIG_BRIDGE_IGMP_SNOOPING 735 int br_multicast_rcv(struct net_bridge *br, struct net_bridge_port *port, 736 struct sk_buff *skb, u16 vid); 737 struct net_bridge_mdb_entry *br_mdb_get(struct net_bridge *br, 738 struct sk_buff *skb, u16 vid); 739 int br_multicast_add_port(struct net_bridge_port *port); 740 void br_multicast_del_port(struct net_bridge_port *port); 741 void br_multicast_enable_port(struct net_bridge_port *port); 742 void br_multicast_disable_port(struct net_bridge_port *port); 743 void br_multicast_init(struct net_bridge *br); 744 void br_multicast_open(struct net_bridge *br); 745 void br_multicast_stop(struct net_bridge *br); 746 void br_multicast_dev_del(struct net_bridge *br); 747 void br_multicast_flood(struct net_bridge_mdb_entry *mdst, 748 struct sk_buff *skb, bool local_rcv, bool local_orig); 749 int br_multicast_set_router(struct net_bridge *br, unsigned long val); 750 int br_multicast_set_port_router(struct net_bridge_port *p, unsigned long val); 751 int br_multicast_toggle(struct net_bridge *br, unsigned long val); 752 int br_multicast_set_querier(struct net_bridge *br, unsigned long val); 753 int br_multicast_set_hash_max(struct net_bridge *br, unsigned long val); 754 int br_multicast_set_igmp_version(struct net_bridge *br, unsigned long val); 755 #if IS_ENABLED(CONFIG_IPV6) 756 int br_multicast_set_mld_version(struct net_bridge *br, unsigned long val); 757 #endif 758 struct net_bridge_mdb_entry * 759 br_mdb_ip_get(struct net_bridge *br, struct br_ip *dst); 760 struct net_bridge_mdb_entry * 761 br_multicast_new_group(struct net_bridge *br, struct br_ip *group); 762 struct net_bridge_port_group * 763 br_multicast_new_port_group(struct net_bridge_port *port, struct br_ip *group, 764 struct net_bridge_port_group __rcu *next, 765 unsigned char flags, const unsigned char *src); 766 int br_mdb_hash_init(struct net_bridge *br); 767 void br_mdb_hash_fini(struct net_bridge *br); 768 void br_mdb_notify(struct net_device *dev, struct net_bridge_port *port, 769 struct br_ip *group, int type, u8 flags); 770 void br_rtr_notify(struct net_device *dev, struct net_bridge_port *port, 771 int type); 772 void br_multicast_count(struct net_bridge *br, const struct net_bridge_port *p, 773 const struct sk_buff *skb, u8 type, u8 dir); 774 int br_multicast_init_stats(struct net_bridge *br); 775 void br_multicast_uninit_stats(struct net_bridge *br); 776 void br_multicast_get_stats(const struct net_bridge *br, 777 const struct net_bridge_port *p, 778 struct br_mcast_stats *dest); 779 void br_mdb_init(void); 780 void br_mdb_uninit(void); 781 void br_multicast_host_join(struct net_bridge_mdb_entry *mp, bool notify); 782 void br_multicast_host_leave(struct net_bridge_mdb_entry *mp, bool notify); 783 784 #define mlock_dereference(X, br) \ 785 rcu_dereference_protected(X, lockdep_is_held(&br->multicast_lock)) 786 787 static inline bool br_multicast_is_router(struct net_bridge *br) 788 { 789 return br->multicast_router == 2 || 790 (br->multicast_router == 1 && 791 timer_pending(&br->multicast_router_timer)); 792 } 793 794 static inline bool 795 __br_multicast_querier_exists(struct net_bridge *br, 796 struct bridge_mcast_other_query *querier, 797 const bool is_ipv6) 798 { 799 bool own_querier_enabled; 800 801 if (br_opt_get(br, BROPT_MULTICAST_QUERIER)) { 802 if (is_ipv6 && !br_opt_get(br, BROPT_HAS_IPV6_ADDR)) 803 own_querier_enabled = false; 804 else 805 own_querier_enabled = true; 806 } else { 807 own_querier_enabled = false; 808 } 809 810 return time_is_before_jiffies(querier->delay_time) && 811 (own_querier_enabled || timer_pending(&querier->timer)); 812 } 813 814 static inline bool br_multicast_querier_exists(struct net_bridge *br, 815 struct ethhdr *eth) 816 { 817 switch (eth->h_proto) { 818 case (htons(ETH_P_IP)): 819 return __br_multicast_querier_exists(br, 820 &br->ip4_other_query, false); 821 #if IS_ENABLED(CONFIG_IPV6) 822 case (htons(ETH_P_IPV6)): 823 return __br_multicast_querier_exists(br, 824 &br->ip6_other_query, true); 825 #endif 826 default: 827 return false; 828 } 829 } 830 831 static inline int br_multicast_igmp_type(const struct sk_buff *skb) 832 { 833 return BR_INPUT_SKB_CB(skb)->igmp; 834 } 835 #else 836 static inline int br_multicast_rcv(struct net_bridge *br, 837 struct net_bridge_port *port, 838 struct sk_buff *skb, 839 u16 vid) 840 { 841 return 0; 842 } 843 844 static inline struct net_bridge_mdb_entry *br_mdb_get(struct net_bridge *br, 845 struct sk_buff *skb, u16 vid) 846 { 847 return NULL; 848 } 849 850 static inline int br_multicast_add_port(struct net_bridge_port *port) 851 { 852 return 0; 853 } 854 855 static inline void br_multicast_del_port(struct net_bridge_port *port) 856 { 857 } 858 859 static inline void br_multicast_enable_port(struct net_bridge_port *port) 860 { 861 } 862 863 static inline void br_multicast_disable_port(struct net_bridge_port *port) 864 { 865 } 866 867 static inline void br_multicast_init(struct net_bridge *br) 868 { 869 } 870 871 static inline void br_multicast_open(struct net_bridge *br) 872 { 873 } 874 875 static inline void br_multicast_stop(struct net_bridge *br) 876 { 877 } 878 879 static inline void br_multicast_dev_del(struct net_bridge *br) 880 { 881 } 882 883 static inline void br_multicast_flood(struct net_bridge_mdb_entry *mdst, 884 struct sk_buff *skb, 885 bool local_rcv, bool local_orig) 886 { 887 } 888 889 static inline bool br_multicast_is_router(struct net_bridge *br) 890 { 891 return false; 892 } 893 894 static inline bool br_multicast_querier_exists(struct net_bridge *br, 895 struct ethhdr *eth) 896 { 897 return false; 898 } 899 900 static inline void br_mdb_init(void) 901 { 902 } 903 904 static inline void br_mdb_uninit(void) 905 { 906 } 907 908 static inline int br_mdb_hash_init(struct net_bridge *br) 909 { 910 return 0; 911 } 912 913 static inline void br_mdb_hash_fini(struct net_bridge *br) 914 { 915 } 916 917 static inline void br_multicast_count(struct net_bridge *br, 918 const struct net_bridge_port *p, 919 const struct sk_buff *skb, 920 u8 type, u8 dir) 921 { 922 } 923 924 static inline int br_multicast_init_stats(struct net_bridge *br) 925 { 926 return 0; 927 } 928 929 static inline void br_multicast_uninit_stats(struct net_bridge *br) 930 { 931 } 932 933 static inline int br_multicast_igmp_type(const struct sk_buff *skb) 934 { 935 return 0; 936 } 937 #endif 938 939 /* br_vlan.c */ 940 #ifdef CONFIG_BRIDGE_VLAN_FILTERING 941 bool br_allowed_ingress(const struct net_bridge *br, 942 struct net_bridge_vlan_group *vg, struct sk_buff *skb, 943 u16 *vid, u8 *state); 944 bool br_allowed_egress(struct net_bridge_vlan_group *vg, 945 const struct sk_buff *skb); 946 bool br_should_learn(struct net_bridge_port *p, struct sk_buff *skb, u16 *vid); 947 struct sk_buff *br_handle_vlan(struct net_bridge *br, 948 const struct net_bridge_port *port, 949 struct net_bridge_vlan_group *vg, 950 struct sk_buff *skb); 951 int br_vlan_add(struct net_bridge *br, u16 vid, u16 flags, 952 bool *changed, struct netlink_ext_ack *extack); 953 int br_vlan_delete(struct net_bridge *br, u16 vid); 954 void br_vlan_flush(struct net_bridge *br); 955 struct net_bridge_vlan *br_vlan_find(struct net_bridge_vlan_group *vg, u16 vid); 956 void br_recalculate_fwd_mask(struct net_bridge *br); 957 int __br_vlan_filter_toggle(struct net_bridge *br, unsigned long val); 958 int br_vlan_filter_toggle(struct net_bridge *br, unsigned long val); 959 int __br_vlan_set_proto(struct net_bridge *br, __be16 proto); 960 int br_vlan_set_proto(struct net_bridge *br, unsigned long val); 961 int br_vlan_set_stats(struct net_bridge *br, unsigned long val); 962 int br_vlan_set_stats_per_port(struct net_bridge *br, unsigned long val); 963 int br_vlan_init(struct net_bridge *br); 964 int br_vlan_set_default_pvid(struct net_bridge *br, unsigned long val); 965 int __br_vlan_set_default_pvid(struct net_bridge *br, u16 pvid, 966 struct netlink_ext_ack *extack); 967 int nbp_vlan_add(struct net_bridge_port *port, u16 vid, u16 flags, 968 bool *changed, struct netlink_ext_ack *extack); 969 int nbp_vlan_delete(struct net_bridge_port *port, u16 vid); 970 void nbp_vlan_flush(struct net_bridge_port *port); 971 int nbp_vlan_init(struct net_bridge_port *port, struct netlink_ext_ack *extack); 972 int nbp_get_num_vlan_infos(struct net_bridge_port *p, u32 filter_mask); 973 void br_vlan_get_stats(const struct net_bridge_vlan *v, 974 struct br_vlan_stats *stats); 975 void br_vlan_port_event(struct net_bridge_port *p, unsigned long event); 976 int br_vlan_bridge_event(struct net_device *dev, unsigned long event, 977 void *ptr); 978 void br_vlan_rtnl_init(void); 979 void br_vlan_rtnl_uninit(void); 980 void br_vlan_notify(const struct net_bridge *br, 981 const struct net_bridge_port *p, 982 u16 vid, u16 vid_range, 983 int cmd); 984 bool br_vlan_can_enter_range(const struct net_bridge_vlan *v_curr, 985 const struct net_bridge_vlan *range_end); 986 987 static inline struct net_bridge_vlan_group *br_vlan_group( 988 const struct net_bridge *br) 989 { 990 return rtnl_dereference(br->vlgrp); 991 } 992 993 static inline struct net_bridge_vlan_group *nbp_vlan_group( 994 const struct net_bridge_port *p) 995 { 996 return rtnl_dereference(p->vlgrp); 997 } 998 999 static inline struct net_bridge_vlan_group *br_vlan_group_rcu( 1000 const struct net_bridge *br) 1001 { 1002 return rcu_dereference(br->vlgrp); 1003 } 1004 1005 static inline struct net_bridge_vlan_group *nbp_vlan_group_rcu( 1006 const struct net_bridge_port *p) 1007 { 1008 return rcu_dereference(p->vlgrp); 1009 } 1010 1011 /* Since bridge now depends on 8021Q module, but the time bridge sees the 1012 * skb, the vlan tag will always be present if the frame was tagged. 1013 */ 1014 static inline int br_vlan_get_tag(const struct sk_buff *skb, u16 *vid) 1015 { 1016 int err = 0; 1017 1018 if (skb_vlan_tag_present(skb)) { 1019 *vid = skb_vlan_tag_get_id(skb); 1020 } else { 1021 *vid = 0; 1022 err = -EINVAL; 1023 } 1024 1025 return err; 1026 } 1027 1028 static inline u16 br_get_pvid(const struct net_bridge_vlan_group *vg) 1029 { 1030 if (!vg) 1031 return 0; 1032 1033 smp_rmb(); 1034 return vg->pvid; 1035 } 1036 1037 static inline u16 br_vlan_flags(const struct net_bridge_vlan *v, u16 pvid) 1038 { 1039 return v->vid == pvid ? v->flags | BRIDGE_VLAN_INFO_PVID : v->flags; 1040 } 1041 #else 1042 static inline bool br_allowed_ingress(const struct net_bridge *br, 1043 struct net_bridge_vlan_group *vg, 1044 struct sk_buff *skb, 1045 u16 *vid, u8 *state) 1046 { 1047 return true; 1048 } 1049 1050 static inline bool br_allowed_egress(struct net_bridge_vlan_group *vg, 1051 const struct sk_buff *skb) 1052 { 1053 return true; 1054 } 1055 1056 static inline bool br_should_learn(struct net_bridge_port *p, 1057 struct sk_buff *skb, u16 *vid) 1058 { 1059 return true; 1060 } 1061 1062 static inline struct sk_buff *br_handle_vlan(struct net_bridge *br, 1063 const struct net_bridge_port *port, 1064 struct net_bridge_vlan_group *vg, 1065 struct sk_buff *skb) 1066 { 1067 return skb; 1068 } 1069 1070 static inline int br_vlan_add(struct net_bridge *br, u16 vid, u16 flags, 1071 bool *changed, struct netlink_ext_ack *extack) 1072 { 1073 *changed = false; 1074 return -EOPNOTSUPP; 1075 } 1076 1077 static inline int br_vlan_delete(struct net_bridge *br, u16 vid) 1078 { 1079 return -EOPNOTSUPP; 1080 } 1081 1082 static inline void br_vlan_flush(struct net_bridge *br) 1083 { 1084 } 1085 1086 static inline void br_recalculate_fwd_mask(struct net_bridge *br) 1087 { 1088 } 1089 1090 static inline int br_vlan_init(struct net_bridge *br) 1091 { 1092 return 0; 1093 } 1094 1095 static inline int nbp_vlan_add(struct net_bridge_port *port, u16 vid, u16 flags, 1096 bool *changed, struct netlink_ext_ack *extack) 1097 { 1098 *changed = false; 1099 return -EOPNOTSUPP; 1100 } 1101 1102 static inline int nbp_vlan_delete(struct net_bridge_port *port, u16 vid) 1103 { 1104 return -EOPNOTSUPP; 1105 } 1106 1107 static inline void nbp_vlan_flush(struct net_bridge_port *port) 1108 { 1109 } 1110 1111 static inline struct net_bridge_vlan *br_vlan_find(struct net_bridge_vlan_group *vg, 1112 u16 vid) 1113 { 1114 return NULL; 1115 } 1116 1117 static inline int nbp_vlan_init(struct net_bridge_port *port, 1118 struct netlink_ext_ack *extack) 1119 { 1120 return 0; 1121 } 1122 1123 static inline u16 br_vlan_get_tag(const struct sk_buff *skb, u16 *tag) 1124 { 1125 return 0; 1126 } 1127 1128 static inline u16 br_get_pvid(const struct net_bridge_vlan_group *vg) 1129 { 1130 return 0; 1131 } 1132 1133 static inline int __br_vlan_filter_toggle(struct net_bridge *br, 1134 unsigned long val) 1135 { 1136 return -EOPNOTSUPP; 1137 } 1138 1139 static inline int nbp_get_num_vlan_infos(struct net_bridge_port *p, 1140 u32 filter_mask) 1141 { 1142 return 0; 1143 } 1144 1145 static inline struct net_bridge_vlan_group *br_vlan_group( 1146 const struct net_bridge *br) 1147 { 1148 return NULL; 1149 } 1150 1151 static inline struct net_bridge_vlan_group *nbp_vlan_group( 1152 const struct net_bridge_port *p) 1153 { 1154 return NULL; 1155 } 1156 1157 static inline struct net_bridge_vlan_group *br_vlan_group_rcu( 1158 const struct net_bridge *br) 1159 { 1160 return NULL; 1161 } 1162 1163 static inline struct net_bridge_vlan_group *nbp_vlan_group_rcu( 1164 const struct net_bridge_port *p) 1165 { 1166 return NULL; 1167 } 1168 1169 static inline void br_vlan_get_stats(const struct net_bridge_vlan *v, 1170 struct br_vlan_stats *stats) 1171 { 1172 } 1173 1174 static inline void br_vlan_port_event(struct net_bridge_port *p, 1175 unsigned long event) 1176 { 1177 } 1178 1179 static inline int br_vlan_bridge_event(struct net_device *dev, 1180 unsigned long event, void *ptr) 1181 { 1182 return 0; 1183 } 1184 1185 static inline void br_vlan_rtnl_init(void) 1186 { 1187 } 1188 1189 static inline void br_vlan_rtnl_uninit(void) 1190 { 1191 } 1192 1193 static inline void br_vlan_notify(const struct net_bridge *br, 1194 const struct net_bridge_port *p, 1195 u16 vid, u16 vid_range, 1196 int cmd) 1197 { 1198 } 1199 #endif 1200 1201 /* br_vlan_options.c */ 1202 #ifdef CONFIG_BRIDGE_VLAN_FILTERING 1203 bool br_vlan_opts_eq_range(const struct net_bridge_vlan *v_curr, 1204 const struct net_bridge_vlan *range_end); 1205 bool br_vlan_opts_fill(struct sk_buff *skb, const struct net_bridge_vlan *v); 1206 size_t br_vlan_opts_nl_size(void); 1207 int br_vlan_process_options(const struct net_bridge *br, 1208 const struct net_bridge_port *p, 1209 struct net_bridge_vlan *range_start, 1210 struct net_bridge_vlan *range_end, 1211 struct nlattr **tb, 1212 struct netlink_ext_ack *extack); 1213 1214 /* vlan state manipulation helpers using *_ONCE to annotate lock-free access */ 1215 static inline u8 br_vlan_get_state(const struct net_bridge_vlan *v) 1216 { 1217 return READ_ONCE(v->state); 1218 } 1219 1220 static inline void br_vlan_set_state(struct net_bridge_vlan *v, u8 state) 1221 { 1222 WRITE_ONCE(v->state, state); 1223 } 1224 1225 static inline u8 br_vlan_get_pvid_state(const struct net_bridge_vlan_group *vg) 1226 { 1227 return READ_ONCE(vg->pvid_state); 1228 } 1229 1230 static inline void br_vlan_set_pvid_state(struct net_bridge_vlan_group *vg, 1231 u8 state) 1232 { 1233 WRITE_ONCE(vg->pvid_state, state); 1234 } 1235 1236 /* learn_allow is true at ingress and false at egress */ 1237 static inline bool br_vlan_state_allowed(u8 state, bool learn_allow) 1238 { 1239 switch (state) { 1240 case BR_STATE_LEARNING: 1241 return learn_allow; 1242 case BR_STATE_FORWARDING: 1243 return true; 1244 default: 1245 return false; 1246 } 1247 } 1248 #endif 1249 1250 struct nf_br_ops { 1251 int (*br_dev_xmit_hook)(struct sk_buff *skb); 1252 }; 1253 extern const struct nf_br_ops __rcu *nf_br_ops; 1254 1255 /* br_netfilter.c */ 1256 #if IS_ENABLED(CONFIG_BRIDGE_NETFILTER) 1257 int br_nf_core_init(void); 1258 void br_nf_core_fini(void); 1259 void br_netfilter_rtable_init(struct net_bridge *); 1260 #else 1261 static inline int br_nf_core_init(void) { return 0; } 1262 static inline void br_nf_core_fini(void) {} 1263 #define br_netfilter_rtable_init(x) 1264 #endif 1265 1266 /* br_stp.c */ 1267 void br_set_state(struct net_bridge_port *p, unsigned int state); 1268 struct net_bridge_port *br_get_port(struct net_bridge *br, u16 port_no); 1269 void br_init_port(struct net_bridge_port *p); 1270 void br_become_designated_port(struct net_bridge_port *p); 1271 1272 void __br_set_forward_delay(struct net_bridge *br, unsigned long t); 1273 int br_set_forward_delay(struct net_bridge *br, unsigned long x); 1274 int br_set_hello_time(struct net_bridge *br, unsigned long x); 1275 int br_set_max_age(struct net_bridge *br, unsigned long x); 1276 int __set_ageing_time(struct net_device *dev, unsigned long t); 1277 int br_set_ageing_time(struct net_bridge *br, clock_t ageing_time); 1278 1279 1280 /* br_stp_if.c */ 1281 void br_stp_enable_bridge(struct net_bridge *br); 1282 void br_stp_disable_bridge(struct net_bridge *br); 1283 int br_stp_set_enabled(struct net_bridge *br, unsigned long val, 1284 struct netlink_ext_ack *extack); 1285 void br_stp_enable_port(struct net_bridge_port *p); 1286 void br_stp_disable_port(struct net_bridge_port *p); 1287 bool br_stp_recalculate_bridge_id(struct net_bridge *br); 1288 void br_stp_change_bridge_id(struct net_bridge *br, const unsigned char *a); 1289 void br_stp_set_bridge_priority(struct net_bridge *br, u16 newprio); 1290 int br_stp_set_port_priority(struct net_bridge_port *p, unsigned long newprio); 1291 int br_stp_set_path_cost(struct net_bridge_port *p, unsigned long path_cost); 1292 ssize_t br_show_bridge_id(char *buf, const struct bridge_id *id); 1293 1294 /* br_stp_bpdu.c */ 1295 struct stp_proto; 1296 void br_stp_rcv(const struct stp_proto *proto, struct sk_buff *skb, 1297 struct net_device *dev); 1298 1299 /* br_stp_timer.c */ 1300 void br_stp_timer_init(struct net_bridge *br); 1301 void br_stp_port_timer_init(struct net_bridge_port *p); 1302 unsigned long br_timer_value(const struct timer_list *timer); 1303 1304 /* br.c */ 1305 #if IS_ENABLED(CONFIG_ATM_LANE) 1306 extern int (*br_fdb_test_addr_hook)(struct net_device *dev, unsigned char *addr); 1307 #endif 1308 1309 /* br_mrp.c */ 1310 #if IS_ENABLED(CONFIG_BRIDGE_MRP) 1311 int br_mrp_parse(struct net_bridge *br, struct net_bridge_port *p, 1312 struct nlattr *attr, int cmd, struct netlink_ext_ack *extack); 1313 int br_mrp_process(struct net_bridge_port *p, struct sk_buff *skb); 1314 bool br_mrp_enabled(struct net_bridge *br); 1315 void br_mrp_port_del(struct net_bridge *br, struct net_bridge_port *p); 1316 #else 1317 static inline int br_mrp_parse(struct net_bridge *br, struct net_bridge_port *p, 1318 struct nlattr *attr, int cmd, 1319 struct netlink_ext_ack *extack) 1320 { 1321 return -EOPNOTSUPP; 1322 } 1323 1324 static inline int br_mrp_process(struct net_bridge_port *p, struct sk_buff *skb) 1325 { 1326 return 0; 1327 } 1328 1329 static inline bool br_mrp_enabled(struct net_bridge *br) 1330 { 1331 return false; 1332 } 1333 1334 static inline void br_mrp_port_del(struct net_bridge *br, 1335 struct net_bridge_port *p) 1336 { 1337 } 1338 #endif 1339 1340 /* br_netlink.c */ 1341 extern struct rtnl_link_ops br_link_ops; 1342 int br_netlink_init(void); 1343 void br_netlink_fini(void); 1344 void br_ifinfo_notify(int event, const struct net_bridge *br, 1345 const struct net_bridge_port *port); 1346 int br_setlink(struct net_device *dev, struct nlmsghdr *nlmsg, u16 flags, 1347 struct netlink_ext_ack *extack); 1348 int br_dellink(struct net_device *dev, struct nlmsghdr *nlmsg, u16 flags); 1349 int br_getlink(struct sk_buff *skb, u32 pid, u32 seq, struct net_device *dev, 1350 u32 filter_mask, int nlflags); 1351 int br_process_vlan_info(struct net_bridge *br, 1352 struct net_bridge_port *p, int cmd, 1353 struct bridge_vlan_info *vinfo_curr, 1354 struct bridge_vlan_info **vinfo_last, 1355 bool *changed, 1356 struct netlink_ext_ack *extack); 1357 1358 #ifdef CONFIG_SYSFS 1359 /* br_sysfs_if.c */ 1360 extern const struct sysfs_ops brport_sysfs_ops; 1361 int br_sysfs_addif(struct net_bridge_port *p); 1362 int br_sysfs_renameif(struct net_bridge_port *p); 1363 1364 /* br_sysfs_br.c */ 1365 int br_sysfs_addbr(struct net_device *dev); 1366 void br_sysfs_delbr(struct net_device *dev); 1367 1368 #else 1369 1370 static inline int br_sysfs_addif(struct net_bridge_port *p) { return 0; } 1371 static inline int br_sysfs_renameif(struct net_bridge_port *p) { return 0; } 1372 static inline int br_sysfs_addbr(struct net_device *dev) { return 0; } 1373 static inline void br_sysfs_delbr(struct net_device *dev) { return; } 1374 #endif /* CONFIG_SYSFS */ 1375 1376 /* br_switchdev.c */ 1377 #ifdef CONFIG_NET_SWITCHDEV 1378 int nbp_switchdev_mark_set(struct net_bridge_port *p); 1379 void nbp_switchdev_frame_mark(const struct net_bridge_port *p, 1380 struct sk_buff *skb); 1381 bool nbp_switchdev_allowed_egress(const struct net_bridge_port *p, 1382 const struct sk_buff *skb); 1383 int br_switchdev_set_port_flag(struct net_bridge_port *p, 1384 unsigned long flags, 1385 unsigned long mask); 1386 void br_switchdev_fdb_notify(const struct net_bridge_fdb_entry *fdb, 1387 int type); 1388 int br_switchdev_port_vlan_add(struct net_device *dev, u16 vid, u16 flags, 1389 struct netlink_ext_ack *extack); 1390 int br_switchdev_port_vlan_del(struct net_device *dev, u16 vid); 1391 1392 static inline void br_switchdev_frame_unmark(struct sk_buff *skb) 1393 { 1394 skb->offload_fwd_mark = 0; 1395 } 1396 #else 1397 static inline int nbp_switchdev_mark_set(struct net_bridge_port *p) 1398 { 1399 return 0; 1400 } 1401 1402 static inline void nbp_switchdev_frame_mark(const struct net_bridge_port *p, 1403 struct sk_buff *skb) 1404 { 1405 } 1406 1407 static inline bool nbp_switchdev_allowed_egress(const struct net_bridge_port *p, 1408 const struct sk_buff *skb) 1409 { 1410 return true; 1411 } 1412 1413 static inline int br_switchdev_set_port_flag(struct net_bridge_port *p, 1414 unsigned long flags, 1415 unsigned long mask) 1416 { 1417 return 0; 1418 } 1419 1420 static inline int br_switchdev_port_vlan_add(struct net_device *dev, 1421 u16 vid, u16 flags, 1422 struct netlink_ext_ack *extack) 1423 { 1424 return -EOPNOTSUPP; 1425 } 1426 1427 static inline int br_switchdev_port_vlan_del(struct net_device *dev, u16 vid) 1428 { 1429 return -EOPNOTSUPP; 1430 } 1431 1432 static inline void 1433 br_switchdev_fdb_notify(const struct net_bridge_fdb_entry *fdb, int type) 1434 { 1435 } 1436 1437 static inline void br_switchdev_frame_unmark(struct sk_buff *skb) 1438 { 1439 } 1440 #endif /* CONFIG_NET_SWITCHDEV */ 1441 1442 /* br_arp_nd_proxy.c */ 1443 void br_recalculate_neigh_suppress_enabled(struct net_bridge *br); 1444 void br_do_proxy_suppress_arp(struct sk_buff *skb, struct net_bridge *br, 1445 u16 vid, struct net_bridge_port *p); 1446 void br_do_suppress_nd(struct sk_buff *skb, struct net_bridge *br, 1447 u16 vid, struct net_bridge_port *p, struct nd_msg *msg); 1448 struct nd_msg *br_is_nd_neigh_msg(struct sk_buff *skb, struct nd_msg *m); 1449 #endif 1450