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 flags; 221 unsigned char eth_addr[ETH_ALEN]; 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 433 struct br_input_skb_cb { 434 struct net_device *brdev; 435 436 u16 frag_max_size; 437 #ifdef CONFIG_BRIDGE_IGMP_SNOOPING 438 u8 igmp; 439 u8 mrouters_only:1; 440 #endif 441 u8 proxyarp_replied:1; 442 u8 src_port_isolated:1; 443 #ifdef CONFIG_BRIDGE_VLAN_FILTERING 444 u8 vlan_filtered:1; 445 #endif 446 #ifdef CONFIG_NETFILTER_FAMILY_BRIDGE 447 u8 br_netfilter_broute:1; 448 #endif 449 450 #ifdef CONFIG_NET_SWITCHDEV 451 int offload_fwd_mark; 452 #endif 453 }; 454 455 #define BR_INPUT_SKB_CB(__skb) ((struct br_input_skb_cb *)(__skb)->cb) 456 457 #ifdef CONFIG_BRIDGE_IGMP_SNOOPING 458 # define BR_INPUT_SKB_CB_MROUTERS_ONLY(__skb) (BR_INPUT_SKB_CB(__skb)->mrouters_only) 459 #else 460 # define BR_INPUT_SKB_CB_MROUTERS_ONLY(__skb) (0) 461 #endif 462 463 #define br_printk(level, br, format, args...) \ 464 printk(level "%s: " format, (br)->dev->name, ##args) 465 466 #define br_err(__br, format, args...) \ 467 br_printk(KERN_ERR, __br, format, ##args) 468 #define br_warn(__br, format, args...) \ 469 br_printk(KERN_WARNING, __br, format, ##args) 470 #define br_notice(__br, format, args...) \ 471 br_printk(KERN_NOTICE, __br, format, ##args) 472 #define br_info(__br, format, args...) \ 473 br_printk(KERN_INFO, __br, format, ##args) 474 475 #define br_debug(br, format, args...) \ 476 pr_debug("%s: " format, (br)->dev->name, ##args) 477 478 /* called under bridge lock */ 479 static inline int br_is_root_bridge(const struct net_bridge *br) 480 { 481 return !memcmp(&br->bridge_id, &br->designated_root, 8); 482 } 483 484 /* check if a VLAN entry is global */ 485 static inline bool br_vlan_is_master(const struct net_bridge_vlan *v) 486 { 487 return v->flags & BRIDGE_VLAN_INFO_MASTER; 488 } 489 490 /* check if a VLAN entry is used by the bridge */ 491 static inline bool br_vlan_is_brentry(const struct net_bridge_vlan *v) 492 { 493 return v->flags & BRIDGE_VLAN_INFO_BRENTRY; 494 } 495 496 /* check if we should use the vlan entry, returns false if it's only context */ 497 static inline bool br_vlan_should_use(const struct net_bridge_vlan *v) 498 { 499 if (br_vlan_is_master(v)) { 500 if (br_vlan_is_brentry(v)) 501 return true; 502 else 503 return false; 504 } 505 506 return true; 507 } 508 509 static inline bool nbp_state_should_learn(const struct net_bridge_port *p) 510 { 511 return p->state == BR_STATE_LEARNING || p->state == BR_STATE_FORWARDING; 512 } 513 514 static inline bool br_vlan_valid_id(u16 vid, struct netlink_ext_ack *extack) 515 { 516 bool ret = vid > 0 && vid < VLAN_VID_MASK; 517 518 if (!ret) 519 NL_SET_ERR_MSG_MOD(extack, "Vlan id is invalid"); 520 521 return ret; 522 } 523 524 static inline bool br_vlan_valid_range(const struct bridge_vlan_info *cur, 525 const struct bridge_vlan_info *last, 526 struct netlink_ext_ack *extack) 527 { 528 /* pvid flag is not allowed in ranges */ 529 if (cur->flags & BRIDGE_VLAN_INFO_PVID) { 530 NL_SET_ERR_MSG_MOD(extack, "Pvid isn't allowed in a range"); 531 return false; 532 } 533 534 /* when cur is the range end, check if: 535 * - it has range start flag 536 * - range ids are invalid (end is equal to or before start) 537 */ 538 if (last) { 539 if (cur->flags & BRIDGE_VLAN_INFO_RANGE_BEGIN) { 540 NL_SET_ERR_MSG_MOD(extack, "Found a new vlan range start while processing one"); 541 return false; 542 } else if (!(cur->flags & BRIDGE_VLAN_INFO_RANGE_END)) { 543 NL_SET_ERR_MSG_MOD(extack, "Vlan range end flag is missing"); 544 return false; 545 } else if (cur->vid <= last->vid) { 546 NL_SET_ERR_MSG_MOD(extack, "End vlan id is less than or equal to start vlan id"); 547 return false; 548 } 549 } 550 551 /* check for required range flags */ 552 if (!(cur->flags & (BRIDGE_VLAN_INFO_RANGE_BEGIN | 553 BRIDGE_VLAN_INFO_RANGE_END))) { 554 NL_SET_ERR_MSG_MOD(extack, "Both vlan range flags are missing"); 555 return false; 556 } 557 558 return true; 559 } 560 561 static inline int br_afspec_cmd_to_rtm(int cmd) 562 { 563 switch (cmd) { 564 case RTM_SETLINK: 565 return RTM_NEWVLAN; 566 case RTM_DELLINK: 567 return RTM_DELVLAN; 568 } 569 570 return 0; 571 } 572 573 static inline int br_opt_get(const struct net_bridge *br, 574 enum net_bridge_opts opt) 575 { 576 return test_bit(opt, &br->options); 577 } 578 579 int br_boolopt_toggle(struct net_bridge *br, enum br_boolopt_id opt, bool on, 580 struct netlink_ext_ack *extack); 581 int br_boolopt_get(const struct net_bridge *br, enum br_boolopt_id opt); 582 int br_boolopt_multi_toggle(struct net_bridge *br, 583 struct br_boolopt_multi *bm, 584 struct netlink_ext_ack *extack); 585 void br_boolopt_multi_get(const struct net_bridge *br, 586 struct br_boolopt_multi *bm); 587 void br_opt_toggle(struct net_bridge *br, enum net_bridge_opts opt, bool on); 588 589 /* br_device.c */ 590 void br_dev_setup(struct net_device *dev); 591 void br_dev_delete(struct net_device *dev, struct list_head *list); 592 netdev_tx_t br_dev_xmit(struct sk_buff *skb, struct net_device *dev); 593 #ifdef CONFIG_NET_POLL_CONTROLLER 594 static inline void br_netpoll_send_skb(const struct net_bridge_port *p, 595 struct sk_buff *skb) 596 { 597 struct netpoll *np = p->np; 598 599 if (np) 600 netpoll_send_skb(np, skb); 601 } 602 603 int br_netpoll_enable(struct net_bridge_port *p); 604 void br_netpoll_disable(struct net_bridge_port *p); 605 #else 606 static inline void br_netpoll_send_skb(const struct net_bridge_port *p, 607 struct sk_buff *skb) 608 { 609 } 610 611 static inline int br_netpoll_enable(struct net_bridge_port *p) 612 { 613 return 0; 614 } 615 616 static inline void br_netpoll_disable(struct net_bridge_port *p) 617 { 618 } 619 #endif 620 621 /* br_fdb.c */ 622 int br_fdb_init(void); 623 void br_fdb_fini(void); 624 int br_fdb_hash_init(struct net_bridge *br); 625 void br_fdb_hash_fini(struct net_bridge *br); 626 void br_fdb_flush(struct net_bridge *br); 627 void br_fdb_find_delete_local(struct net_bridge *br, 628 const struct net_bridge_port *p, 629 const unsigned char *addr, u16 vid); 630 void br_fdb_changeaddr(struct net_bridge_port *p, const unsigned char *newaddr); 631 void br_fdb_change_mac_address(struct net_bridge *br, const u8 *newaddr); 632 void br_fdb_cleanup(struct work_struct *work); 633 void br_fdb_delete_by_port(struct net_bridge *br, 634 const struct net_bridge_port *p, u16 vid, int do_all); 635 struct net_bridge_fdb_entry *br_fdb_find_rcu(struct net_bridge *br, 636 const unsigned char *addr, 637 __u16 vid); 638 int br_fdb_test_addr(struct net_device *dev, unsigned char *addr); 639 int br_fdb_fillbuf(struct net_bridge *br, void *buf, unsigned long count, 640 unsigned long off); 641 int br_fdb_insert(struct net_bridge *br, struct net_bridge_port *source, 642 const unsigned char *addr, u16 vid); 643 void br_fdb_update(struct net_bridge *br, struct net_bridge_port *source, 644 const unsigned char *addr, u16 vid, unsigned long flags); 645 646 int br_fdb_delete(struct ndmsg *ndm, struct nlattr *tb[], 647 struct net_device *dev, const unsigned char *addr, u16 vid); 648 int br_fdb_add(struct ndmsg *nlh, struct nlattr *tb[], struct net_device *dev, 649 const unsigned char *addr, u16 vid, u16 nlh_flags, 650 struct netlink_ext_ack *extack); 651 int br_fdb_dump(struct sk_buff *skb, struct netlink_callback *cb, 652 struct net_device *dev, struct net_device *fdev, int *idx); 653 int br_fdb_get(struct sk_buff *skb, struct nlattr *tb[], struct net_device *dev, 654 const unsigned char *addr, u16 vid, u32 portid, u32 seq, 655 struct netlink_ext_ack *extack); 656 int br_fdb_sync_static(struct net_bridge *br, struct net_bridge_port *p); 657 void br_fdb_unsync_static(struct net_bridge *br, struct net_bridge_port *p); 658 int br_fdb_external_learn_add(struct net_bridge *br, struct net_bridge_port *p, 659 const unsigned char *addr, u16 vid, 660 bool swdev_notify); 661 int br_fdb_external_learn_del(struct net_bridge *br, struct net_bridge_port *p, 662 const unsigned char *addr, u16 vid, 663 bool swdev_notify); 664 void br_fdb_offloaded_set(struct net_bridge *br, struct net_bridge_port *p, 665 const unsigned char *addr, u16 vid, bool offloaded); 666 667 /* br_forward.c */ 668 enum br_pkt_type { 669 BR_PKT_UNICAST, 670 BR_PKT_MULTICAST, 671 BR_PKT_BROADCAST 672 }; 673 int br_dev_queue_push_xmit(struct net *net, struct sock *sk, struct sk_buff *skb); 674 void br_forward(const struct net_bridge_port *to, struct sk_buff *skb, 675 bool local_rcv, bool local_orig); 676 int br_forward_finish(struct net *net, struct sock *sk, struct sk_buff *skb); 677 void br_flood(struct net_bridge *br, struct sk_buff *skb, 678 enum br_pkt_type pkt_type, bool local_rcv, bool local_orig); 679 680 /* return true if both source port and dest port are isolated */ 681 static inline bool br_skb_isolated(const struct net_bridge_port *to, 682 const struct sk_buff *skb) 683 { 684 return BR_INPUT_SKB_CB(skb)->src_port_isolated && 685 (to->flags & BR_ISOLATED); 686 } 687 688 /* br_if.c */ 689 void br_port_carrier_check(struct net_bridge_port *p, bool *notified); 690 int br_add_bridge(struct net *net, const char *name); 691 int br_del_bridge(struct net *net, const char *name); 692 int br_add_if(struct net_bridge *br, struct net_device *dev, 693 struct netlink_ext_ack *extack); 694 int br_del_if(struct net_bridge *br, struct net_device *dev); 695 void br_mtu_auto_adjust(struct net_bridge *br); 696 netdev_features_t br_features_recompute(struct net_bridge *br, 697 netdev_features_t features); 698 void br_port_flags_change(struct net_bridge_port *port, unsigned long mask); 699 void br_manage_promisc(struct net_bridge *br); 700 int nbp_backup_change(struct net_bridge_port *p, struct net_device *backup_dev); 701 702 /* br_input.c */ 703 int br_handle_frame_finish(struct net *net, struct sock *sk, struct sk_buff *skb); 704 rx_handler_result_t br_handle_frame(struct sk_buff **pskb); 705 706 static inline bool br_rx_handler_check_rcu(const struct net_device *dev) 707 { 708 return rcu_dereference(dev->rx_handler) == br_handle_frame; 709 } 710 711 static inline bool br_rx_handler_check_rtnl(const struct net_device *dev) 712 { 713 return rcu_dereference_rtnl(dev->rx_handler) == br_handle_frame; 714 } 715 716 static inline struct net_bridge_port *br_port_get_check_rcu(const struct net_device *dev) 717 { 718 return br_rx_handler_check_rcu(dev) ? br_port_get_rcu(dev) : NULL; 719 } 720 721 static inline struct net_bridge_port * 722 br_port_get_check_rtnl(const struct net_device *dev) 723 { 724 return br_rx_handler_check_rtnl(dev) ? br_port_get_rtnl_rcu(dev) : NULL; 725 } 726 727 /* br_ioctl.c */ 728 int br_dev_ioctl(struct net_device *dev, struct ifreq *rq, int cmd); 729 int br_ioctl_deviceless_stub(struct net *net, unsigned int cmd, 730 void __user *arg); 731 732 /* br_multicast.c */ 733 #ifdef CONFIG_BRIDGE_IGMP_SNOOPING 734 int br_multicast_rcv(struct net_bridge *br, struct net_bridge_port *port, 735 struct sk_buff *skb, u16 vid); 736 struct net_bridge_mdb_entry *br_mdb_get(struct net_bridge *br, 737 struct sk_buff *skb, u16 vid); 738 int br_multicast_add_port(struct net_bridge_port *port); 739 void br_multicast_del_port(struct net_bridge_port *port); 740 void br_multicast_enable_port(struct net_bridge_port *port); 741 void br_multicast_disable_port(struct net_bridge_port *port); 742 void br_multicast_init(struct net_bridge *br); 743 void br_multicast_open(struct net_bridge *br); 744 void br_multicast_stop(struct net_bridge *br); 745 void br_multicast_dev_del(struct net_bridge *br); 746 void br_multicast_flood(struct net_bridge_mdb_entry *mdst, 747 struct sk_buff *skb, bool local_rcv, bool local_orig); 748 int br_multicast_set_router(struct net_bridge *br, unsigned long val); 749 int br_multicast_set_port_router(struct net_bridge_port *p, unsigned long val); 750 int br_multicast_toggle(struct net_bridge *br, unsigned long val); 751 int br_multicast_set_querier(struct net_bridge *br, unsigned long val); 752 int br_multicast_set_hash_max(struct net_bridge *br, unsigned long val); 753 int br_multicast_set_igmp_version(struct net_bridge *br, unsigned long val); 754 #if IS_ENABLED(CONFIG_IPV6) 755 int br_multicast_set_mld_version(struct net_bridge *br, unsigned long val); 756 #endif 757 struct net_bridge_mdb_entry * 758 br_mdb_ip_get(struct net_bridge *br, struct br_ip *dst); 759 struct net_bridge_mdb_entry * 760 br_multicast_new_group(struct net_bridge *br, struct br_ip *group); 761 struct net_bridge_port_group * 762 br_multicast_new_port_group(struct net_bridge_port *port, struct br_ip *group, 763 struct net_bridge_port_group __rcu *next, 764 unsigned char flags, const unsigned char *src); 765 int br_mdb_hash_init(struct net_bridge *br); 766 void br_mdb_hash_fini(struct net_bridge *br); 767 void br_mdb_notify(struct net_device *dev, struct net_bridge_port *port, 768 struct br_ip *group, int type, u8 flags); 769 void br_rtr_notify(struct net_device *dev, struct net_bridge_port *port, 770 int type); 771 void br_multicast_count(struct net_bridge *br, const struct net_bridge_port *p, 772 const struct sk_buff *skb, u8 type, u8 dir); 773 int br_multicast_init_stats(struct net_bridge *br); 774 void br_multicast_uninit_stats(struct net_bridge *br); 775 void br_multicast_get_stats(const struct net_bridge *br, 776 const struct net_bridge_port *p, 777 struct br_mcast_stats *dest); 778 void br_mdb_init(void); 779 void br_mdb_uninit(void); 780 void br_multicast_host_join(struct net_bridge_mdb_entry *mp, bool notify); 781 void br_multicast_host_leave(struct net_bridge_mdb_entry *mp, bool notify); 782 783 #define mlock_dereference(X, br) \ 784 rcu_dereference_protected(X, lockdep_is_held(&br->multicast_lock)) 785 786 static inline bool br_multicast_is_router(struct net_bridge *br) 787 { 788 return br->multicast_router == 2 || 789 (br->multicast_router == 1 && 790 timer_pending(&br->multicast_router_timer)); 791 } 792 793 static inline bool 794 __br_multicast_querier_exists(struct net_bridge *br, 795 struct bridge_mcast_other_query *querier, 796 const bool is_ipv6) 797 { 798 bool own_querier_enabled; 799 800 if (br_opt_get(br, BROPT_MULTICAST_QUERIER)) { 801 if (is_ipv6 && !br_opt_get(br, BROPT_HAS_IPV6_ADDR)) 802 own_querier_enabled = false; 803 else 804 own_querier_enabled = true; 805 } else { 806 own_querier_enabled = false; 807 } 808 809 return time_is_before_jiffies(querier->delay_time) && 810 (own_querier_enabled || timer_pending(&querier->timer)); 811 } 812 813 static inline bool br_multicast_querier_exists(struct net_bridge *br, 814 struct ethhdr *eth) 815 { 816 switch (eth->h_proto) { 817 case (htons(ETH_P_IP)): 818 return __br_multicast_querier_exists(br, 819 &br->ip4_other_query, false); 820 #if IS_ENABLED(CONFIG_IPV6) 821 case (htons(ETH_P_IPV6)): 822 return __br_multicast_querier_exists(br, 823 &br->ip6_other_query, true); 824 #endif 825 default: 826 return false; 827 } 828 } 829 830 static inline int br_multicast_igmp_type(const struct sk_buff *skb) 831 { 832 return BR_INPUT_SKB_CB(skb)->igmp; 833 } 834 #else 835 static inline int br_multicast_rcv(struct net_bridge *br, 836 struct net_bridge_port *port, 837 struct sk_buff *skb, 838 u16 vid) 839 { 840 return 0; 841 } 842 843 static inline struct net_bridge_mdb_entry *br_mdb_get(struct net_bridge *br, 844 struct sk_buff *skb, u16 vid) 845 { 846 return NULL; 847 } 848 849 static inline int br_multicast_add_port(struct net_bridge_port *port) 850 { 851 return 0; 852 } 853 854 static inline void br_multicast_del_port(struct net_bridge_port *port) 855 { 856 } 857 858 static inline void br_multicast_enable_port(struct net_bridge_port *port) 859 { 860 } 861 862 static inline void br_multicast_disable_port(struct net_bridge_port *port) 863 { 864 } 865 866 static inline void br_multicast_init(struct net_bridge *br) 867 { 868 } 869 870 static inline void br_multicast_open(struct net_bridge *br) 871 { 872 } 873 874 static inline void br_multicast_stop(struct net_bridge *br) 875 { 876 } 877 878 static inline void br_multicast_dev_del(struct net_bridge *br) 879 { 880 } 881 882 static inline void br_multicast_flood(struct net_bridge_mdb_entry *mdst, 883 struct sk_buff *skb, 884 bool local_rcv, bool local_orig) 885 { 886 } 887 888 static inline bool br_multicast_is_router(struct net_bridge *br) 889 { 890 return false; 891 } 892 893 static inline bool br_multicast_querier_exists(struct net_bridge *br, 894 struct ethhdr *eth) 895 { 896 return false; 897 } 898 899 static inline void br_mdb_init(void) 900 { 901 } 902 903 static inline void br_mdb_uninit(void) 904 { 905 } 906 907 static inline int br_mdb_hash_init(struct net_bridge *br) 908 { 909 return 0; 910 } 911 912 static inline void br_mdb_hash_fini(struct net_bridge *br) 913 { 914 } 915 916 static inline void br_multicast_count(struct net_bridge *br, 917 const struct net_bridge_port *p, 918 const struct sk_buff *skb, 919 u8 type, u8 dir) 920 { 921 } 922 923 static inline int br_multicast_init_stats(struct net_bridge *br) 924 { 925 return 0; 926 } 927 928 static inline void br_multicast_uninit_stats(struct net_bridge *br) 929 { 930 } 931 932 static inline int br_multicast_igmp_type(const struct sk_buff *skb) 933 { 934 return 0; 935 } 936 #endif 937 938 /* br_vlan.c */ 939 #ifdef CONFIG_BRIDGE_VLAN_FILTERING 940 bool br_allowed_ingress(const struct net_bridge *br, 941 struct net_bridge_vlan_group *vg, struct sk_buff *skb, 942 u16 *vid, u8 *state); 943 bool br_allowed_egress(struct net_bridge_vlan_group *vg, 944 const struct sk_buff *skb); 945 bool br_should_learn(struct net_bridge_port *p, struct sk_buff *skb, u16 *vid); 946 struct sk_buff *br_handle_vlan(struct net_bridge *br, 947 const struct net_bridge_port *port, 948 struct net_bridge_vlan_group *vg, 949 struct sk_buff *skb); 950 int br_vlan_add(struct net_bridge *br, u16 vid, u16 flags, 951 bool *changed, struct netlink_ext_ack *extack); 952 int br_vlan_delete(struct net_bridge *br, u16 vid); 953 void br_vlan_flush(struct net_bridge *br); 954 struct net_bridge_vlan *br_vlan_find(struct net_bridge_vlan_group *vg, u16 vid); 955 void br_recalculate_fwd_mask(struct net_bridge *br); 956 int __br_vlan_filter_toggle(struct net_bridge *br, unsigned long val); 957 int br_vlan_filter_toggle(struct net_bridge *br, unsigned long val); 958 int __br_vlan_set_proto(struct net_bridge *br, __be16 proto); 959 int br_vlan_set_proto(struct net_bridge *br, unsigned long val); 960 int br_vlan_set_stats(struct net_bridge *br, unsigned long val); 961 int br_vlan_set_stats_per_port(struct net_bridge *br, unsigned long val); 962 int br_vlan_init(struct net_bridge *br); 963 int br_vlan_set_default_pvid(struct net_bridge *br, unsigned long val); 964 int __br_vlan_set_default_pvid(struct net_bridge *br, u16 pvid, 965 struct netlink_ext_ack *extack); 966 int nbp_vlan_add(struct net_bridge_port *port, u16 vid, u16 flags, 967 bool *changed, struct netlink_ext_ack *extack); 968 int nbp_vlan_delete(struct net_bridge_port *port, u16 vid); 969 void nbp_vlan_flush(struct net_bridge_port *port); 970 int nbp_vlan_init(struct net_bridge_port *port, struct netlink_ext_ack *extack); 971 int nbp_get_num_vlan_infos(struct net_bridge_port *p, u32 filter_mask); 972 void br_vlan_get_stats(const struct net_bridge_vlan *v, 973 struct br_vlan_stats *stats); 974 void br_vlan_port_event(struct net_bridge_port *p, unsigned long event); 975 int br_vlan_bridge_event(struct net_device *dev, unsigned long event, 976 void *ptr); 977 void br_vlan_rtnl_init(void); 978 void br_vlan_rtnl_uninit(void); 979 void br_vlan_notify(const struct net_bridge *br, 980 const struct net_bridge_port *p, 981 u16 vid, u16 vid_range, 982 int cmd); 983 bool br_vlan_can_enter_range(const struct net_bridge_vlan *v_curr, 984 const struct net_bridge_vlan *range_end); 985 986 static inline struct net_bridge_vlan_group *br_vlan_group( 987 const struct net_bridge *br) 988 { 989 return rtnl_dereference(br->vlgrp); 990 } 991 992 static inline struct net_bridge_vlan_group *nbp_vlan_group( 993 const struct net_bridge_port *p) 994 { 995 return rtnl_dereference(p->vlgrp); 996 } 997 998 static inline struct net_bridge_vlan_group *br_vlan_group_rcu( 999 const struct net_bridge *br) 1000 { 1001 return rcu_dereference(br->vlgrp); 1002 } 1003 1004 static inline struct net_bridge_vlan_group *nbp_vlan_group_rcu( 1005 const struct net_bridge_port *p) 1006 { 1007 return rcu_dereference(p->vlgrp); 1008 } 1009 1010 /* Since bridge now depends on 8021Q module, but the time bridge sees the 1011 * skb, the vlan tag will always be present if the frame was tagged. 1012 */ 1013 static inline int br_vlan_get_tag(const struct sk_buff *skb, u16 *vid) 1014 { 1015 int err = 0; 1016 1017 if (skb_vlan_tag_present(skb)) { 1018 *vid = skb_vlan_tag_get_id(skb); 1019 } else { 1020 *vid = 0; 1021 err = -EINVAL; 1022 } 1023 1024 return err; 1025 } 1026 1027 static inline u16 br_get_pvid(const struct net_bridge_vlan_group *vg) 1028 { 1029 if (!vg) 1030 return 0; 1031 1032 smp_rmb(); 1033 return vg->pvid; 1034 } 1035 1036 static inline u16 br_vlan_flags(const struct net_bridge_vlan *v, u16 pvid) 1037 { 1038 return v->vid == pvid ? v->flags | BRIDGE_VLAN_INFO_PVID : v->flags; 1039 } 1040 #else 1041 static inline bool br_allowed_ingress(const struct net_bridge *br, 1042 struct net_bridge_vlan_group *vg, 1043 struct sk_buff *skb, 1044 u16 *vid, u8 *state) 1045 { 1046 return true; 1047 } 1048 1049 static inline bool br_allowed_egress(struct net_bridge_vlan_group *vg, 1050 const struct sk_buff *skb) 1051 { 1052 return true; 1053 } 1054 1055 static inline bool br_should_learn(struct net_bridge_port *p, 1056 struct sk_buff *skb, u16 *vid) 1057 { 1058 return true; 1059 } 1060 1061 static inline struct sk_buff *br_handle_vlan(struct net_bridge *br, 1062 const struct net_bridge_port *port, 1063 struct net_bridge_vlan_group *vg, 1064 struct sk_buff *skb) 1065 { 1066 return skb; 1067 } 1068 1069 static inline int br_vlan_add(struct net_bridge *br, u16 vid, u16 flags, 1070 bool *changed, struct netlink_ext_ack *extack) 1071 { 1072 *changed = false; 1073 return -EOPNOTSUPP; 1074 } 1075 1076 static inline int br_vlan_delete(struct net_bridge *br, u16 vid) 1077 { 1078 return -EOPNOTSUPP; 1079 } 1080 1081 static inline void br_vlan_flush(struct net_bridge *br) 1082 { 1083 } 1084 1085 static inline void br_recalculate_fwd_mask(struct net_bridge *br) 1086 { 1087 } 1088 1089 static inline int br_vlan_init(struct net_bridge *br) 1090 { 1091 return 0; 1092 } 1093 1094 static inline int nbp_vlan_add(struct net_bridge_port *port, u16 vid, u16 flags, 1095 bool *changed, struct netlink_ext_ack *extack) 1096 { 1097 *changed = false; 1098 return -EOPNOTSUPP; 1099 } 1100 1101 static inline int nbp_vlan_delete(struct net_bridge_port *port, u16 vid) 1102 { 1103 return -EOPNOTSUPP; 1104 } 1105 1106 static inline void nbp_vlan_flush(struct net_bridge_port *port) 1107 { 1108 } 1109 1110 static inline struct net_bridge_vlan *br_vlan_find(struct net_bridge_vlan_group *vg, 1111 u16 vid) 1112 { 1113 return NULL; 1114 } 1115 1116 static inline int nbp_vlan_init(struct net_bridge_port *port, 1117 struct netlink_ext_ack *extack) 1118 { 1119 return 0; 1120 } 1121 1122 static inline u16 br_vlan_get_tag(const struct sk_buff *skb, u16 *tag) 1123 { 1124 return 0; 1125 } 1126 1127 static inline u16 br_get_pvid(const struct net_bridge_vlan_group *vg) 1128 { 1129 return 0; 1130 } 1131 1132 static inline int __br_vlan_filter_toggle(struct net_bridge *br, 1133 unsigned long val) 1134 { 1135 return -EOPNOTSUPP; 1136 } 1137 1138 static inline int nbp_get_num_vlan_infos(struct net_bridge_port *p, 1139 u32 filter_mask) 1140 { 1141 return 0; 1142 } 1143 1144 static inline struct net_bridge_vlan_group *br_vlan_group( 1145 const struct net_bridge *br) 1146 { 1147 return NULL; 1148 } 1149 1150 static inline struct net_bridge_vlan_group *nbp_vlan_group( 1151 const struct net_bridge_port *p) 1152 { 1153 return NULL; 1154 } 1155 1156 static inline struct net_bridge_vlan_group *br_vlan_group_rcu( 1157 const struct net_bridge *br) 1158 { 1159 return NULL; 1160 } 1161 1162 static inline struct net_bridge_vlan_group *nbp_vlan_group_rcu( 1163 const struct net_bridge_port *p) 1164 { 1165 return NULL; 1166 } 1167 1168 static inline void br_vlan_get_stats(const struct net_bridge_vlan *v, 1169 struct br_vlan_stats *stats) 1170 { 1171 } 1172 1173 static inline void br_vlan_port_event(struct net_bridge_port *p, 1174 unsigned long event) 1175 { 1176 } 1177 1178 static inline int br_vlan_bridge_event(struct net_device *dev, 1179 unsigned long event, void *ptr) 1180 { 1181 return 0; 1182 } 1183 1184 static inline void br_vlan_rtnl_init(void) 1185 { 1186 } 1187 1188 static inline void br_vlan_rtnl_uninit(void) 1189 { 1190 } 1191 1192 static inline void br_vlan_notify(const struct net_bridge *br, 1193 const struct net_bridge_port *p, 1194 u16 vid, u16 vid_range, 1195 int cmd) 1196 { 1197 } 1198 #endif 1199 1200 /* br_vlan_options.c */ 1201 #ifdef CONFIG_BRIDGE_VLAN_FILTERING 1202 bool br_vlan_opts_eq(const struct net_bridge_vlan *v1, 1203 const struct net_bridge_vlan *v2); 1204 bool br_vlan_opts_fill(struct sk_buff *skb, const struct net_bridge_vlan *v); 1205 size_t br_vlan_opts_nl_size(void); 1206 int br_vlan_process_options(const struct net_bridge *br, 1207 const struct net_bridge_port *p, 1208 struct net_bridge_vlan *range_start, 1209 struct net_bridge_vlan *range_end, 1210 struct nlattr **tb, 1211 struct netlink_ext_ack *extack); 1212 1213 /* vlan state manipulation helpers using *_ONCE to annotate lock-free access */ 1214 static inline u8 br_vlan_get_state(const struct net_bridge_vlan *v) 1215 { 1216 return READ_ONCE(v->state); 1217 } 1218 1219 static inline void br_vlan_set_state(struct net_bridge_vlan *v, u8 state) 1220 { 1221 WRITE_ONCE(v->state, state); 1222 } 1223 1224 static inline u8 br_vlan_get_pvid_state(const struct net_bridge_vlan_group *vg) 1225 { 1226 return READ_ONCE(vg->pvid_state); 1227 } 1228 1229 static inline void br_vlan_set_pvid_state(struct net_bridge_vlan_group *vg, 1230 u8 state) 1231 { 1232 WRITE_ONCE(vg->pvid_state, state); 1233 } 1234 1235 /* learn_allow is true at ingress and false at egress */ 1236 static inline bool br_vlan_state_allowed(u8 state, bool learn_allow) 1237 { 1238 switch (state) { 1239 case BR_STATE_LEARNING: 1240 return learn_allow; 1241 case BR_STATE_FORWARDING: 1242 return true; 1243 default: 1244 return false; 1245 } 1246 } 1247 #endif 1248 1249 struct nf_br_ops { 1250 int (*br_dev_xmit_hook)(struct sk_buff *skb); 1251 }; 1252 extern const struct nf_br_ops __rcu *nf_br_ops; 1253 1254 /* br_netfilter.c */ 1255 #if IS_ENABLED(CONFIG_BRIDGE_NETFILTER) 1256 int br_nf_core_init(void); 1257 void br_nf_core_fini(void); 1258 void br_netfilter_rtable_init(struct net_bridge *); 1259 #else 1260 static inline int br_nf_core_init(void) { return 0; } 1261 static inline void br_nf_core_fini(void) {} 1262 #define br_netfilter_rtable_init(x) 1263 #endif 1264 1265 /* br_stp.c */ 1266 void br_set_state(struct net_bridge_port *p, unsigned int state); 1267 struct net_bridge_port *br_get_port(struct net_bridge *br, u16 port_no); 1268 void br_init_port(struct net_bridge_port *p); 1269 void br_become_designated_port(struct net_bridge_port *p); 1270 1271 void __br_set_forward_delay(struct net_bridge *br, unsigned long t); 1272 int br_set_forward_delay(struct net_bridge *br, unsigned long x); 1273 int br_set_hello_time(struct net_bridge *br, unsigned long x); 1274 int br_set_max_age(struct net_bridge *br, unsigned long x); 1275 int __set_ageing_time(struct net_device *dev, unsigned long t); 1276 int br_set_ageing_time(struct net_bridge *br, clock_t ageing_time); 1277 1278 1279 /* br_stp_if.c */ 1280 void br_stp_enable_bridge(struct net_bridge *br); 1281 void br_stp_disable_bridge(struct net_bridge *br); 1282 void br_stp_set_enabled(struct net_bridge *br, unsigned long val); 1283 void br_stp_enable_port(struct net_bridge_port *p); 1284 void br_stp_disable_port(struct net_bridge_port *p); 1285 bool br_stp_recalculate_bridge_id(struct net_bridge *br); 1286 void br_stp_change_bridge_id(struct net_bridge *br, const unsigned char *a); 1287 void br_stp_set_bridge_priority(struct net_bridge *br, u16 newprio); 1288 int br_stp_set_port_priority(struct net_bridge_port *p, unsigned long newprio); 1289 int br_stp_set_path_cost(struct net_bridge_port *p, unsigned long path_cost); 1290 ssize_t br_show_bridge_id(char *buf, const struct bridge_id *id); 1291 1292 /* br_stp_bpdu.c */ 1293 struct stp_proto; 1294 void br_stp_rcv(const struct stp_proto *proto, struct sk_buff *skb, 1295 struct net_device *dev); 1296 1297 /* br_stp_timer.c */ 1298 void br_stp_timer_init(struct net_bridge *br); 1299 void br_stp_port_timer_init(struct net_bridge_port *p); 1300 unsigned long br_timer_value(const struct timer_list *timer); 1301 1302 /* br.c */ 1303 #if IS_ENABLED(CONFIG_ATM_LANE) 1304 extern int (*br_fdb_test_addr_hook)(struct net_device *dev, unsigned char *addr); 1305 #endif 1306 1307 /* br_netlink.c */ 1308 extern struct rtnl_link_ops br_link_ops; 1309 int br_netlink_init(void); 1310 void br_netlink_fini(void); 1311 void br_ifinfo_notify(int event, const struct net_bridge *br, 1312 const struct net_bridge_port *port); 1313 int br_setlink(struct net_device *dev, struct nlmsghdr *nlmsg, u16 flags, 1314 struct netlink_ext_ack *extack); 1315 int br_dellink(struct net_device *dev, struct nlmsghdr *nlmsg, u16 flags); 1316 int br_getlink(struct sk_buff *skb, u32 pid, u32 seq, struct net_device *dev, 1317 u32 filter_mask, int nlflags); 1318 int br_process_vlan_info(struct net_bridge *br, 1319 struct net_bridge_port *p, int cmd, 1320 struct bridge_vlan_info *vinfo_curr, 1321 struct bridge_vlan_info **vinfo_last, 1322 bool *changed, 1323 struct netlink_ext_ack *extack); 1324 1325 #ifdef CONFIG_SYSFS 1326 /* br_sysfs_if.c */ 1327 extern const struct sysfs_ops brport_sysfs_ops; 1328 int br_sysfs_addif(struct net_bridge_port *p); 1329 int br_sysfs_renameif(struct net_bridge_port *p); 1330 1331 /* br_sysfs_br.c */ 1332 int br_sysfs_addbr(struct net_device *dev); 1333 void br_sysfs_delbr(struct net_device *dev); 1334 1335 #else 1336 1337 static inline int br_sysfs_addif(struct net_bridge_port *p) { return 0; } 1338 static inline int br_sysfs_renameif(struct net_bridge_port *p) { return 0; } 1339 static inline int br_sysfs_addbr(struct net_device *dev) { return 0; } 1340 static inline void br_sysfs_delbr(struct net_device *dev) { return; } 1341 #endif /* CONFIG_SYSFS */ 1342 1343 /* br_switchdev.c */ 1344 #ifdef CONFIG_NET_SWITCHDEV 1345 int nbp_switchdev_mark_set(struct net_bridge_port *p); 1346 void nbp_switchdev_frame_mark(const struct net_bridge_port *p, 1347 struct sk_buff *skb); 1348 bool nbp_switchdev_allowed_egress(const struct net_bridge_port *p, 1349 const struct sk_buff *skb); 1350 int br_switchdev_set_port_flag(struct net_bridge_port *p, 1351 unsigned long flags, 1352 unsigned long mask); 1353 void br_switchdev_fdb_notify(const struct net_bridge_fdb_entry *fdb, 1354 int type); 1355 int br_switchdev_port_vlan_add(struct net_device *dev, u16 vid, u16 flags, 1356 struct netlink_ext_ack *extack); 1357 int br_switchdev_port_vlan_del(struct net_device *dev, u16 vid); 1358 1359 static inline void br_switchdev_frame_unmark(struct sk_buff *skb) 1360 { 1361 skb->offload_fwd_mark = 0; 1362 } 1363 #else 1364 static inline int nbp_switchdev_mark_set(struct net_bridge_port *p) 1365 { 1366 return 0; 1367 } 1368 1369 static inline void nbp_switchdev_frame_mark(const struct net_bridge_port *p, 1370 struct sk_buff *skb) 1371 { 1372 } 1373 1374 static inline bool nbp_switchdev_allowed_egress(const struct net_bridge_port *p, 1375 const struct sk_buff *skb) 1376 { 1377 return true; 1378 } 1379 1380 static inline int br_switchdev_set_port_flag(struct net_bridge_port *p, 1381 unsigned long flags, 1382 unsigned long mask) 1383 { 1384 return 0; 1385 } 1386 1387 static inline int br_switchdev_port_vlan_add(struct net_device *dev, 1388 u16 vid, u16 flags, 1389 struct netlink_ext_ack *extack) 1390 { 1391 return -EOPNOTSUPP; 1392 } 1393 1394 static inline int br_switchdev_port_vlan_del(struct net_device *dev, u16 vid) 1395 { 1396 return -EOPNOTSUPP; 1397 } 1398 1399 static inline void 1400 br_switchdev_fdb_notify(const struct net_bridge_fdb_entry *fdb, int type) 1401 { 1402 } 1403 1404 static inline void br_switchdev_frame_unmark(struct sk_buff *skb) 1405 { 1406 } 1407 #endif /* CONFIG_NET_SWITCHDEV */ 1408 1409 /* br_arp_nd_proxy.c */ 1410 void br_recalculate_neigh_suppress_enabled(struct net_bridge *br); 1411 void br_do_proxy_suppress_arp(struct sk_buff *skb, struct net_bridge *br, 1412 u16 vid, struct net_bridge_port *p); 1413 void br_do_suppress_nd(struct sk_buff *skb, struct net_bridge *br, 1414 u16 vid, struct net_bridge_port *p, struct nd_msg *msg); 1415 struct nd_msg *br_is_nd_neigh_msg(struct sk_buff *skb, struct nd_msg *m); 1416 #endif 1417