Lines Matching +full:1 +full:br +full:- +full:10

1 // SPDX-License-Identifier: GPL-2.0-or-later
57 return 1; in port_cost()
62 if (!strncmp(dev->name, "lec", 3)) in port_cost()
65 if (!strncmp(dev->name, "plip", 4)) in port_cost()
68 return 100; /* assume old 10Mbps */ in port_cost()
75 struct net_device *dev = p->dev; in br_port_carrier_check()
76 struct net_bridge *br = p->br; in br_port_carrier_check() local
78 if (!(p->flags & BR_ADMIN_COST) && in br_port_carrier_check()
80 p->path_cost = port_cost(dev); in br_port_carrier_check()
83 if (!netif_running(br->dev)) in br_port_carrier_check()
86 spin_lock_bh(&br->lock); in br_port_carrier_check()
88 if (p->state == BR_STATE_DISABLED) { in br_port_carrier_check()
93 if (p->state != BR_STATE_DISABLED) { in br_port_carrier_check()
98 spin_unlock_bh(&br->lock); in br_port_carrier_check()
108 err = dev_set_promiscuity(p->dev, 1); in br_port_set_promisc()
112 br_fdb_unsync_static(p->br, p); in br_port_set_promisc()
113 p->flags |= BR_PROMISC; in br_port_set_promisc()
120 /* Check if the port is already non-promisc or if it doesn't in br_port_clear_promisc()
122 * we'll end up re-enabling promisc mode anyway, so just check for in br_port_clear_promisc()
125 if (!br_promisc_port(p) || !(p->dev->priv_flags & IFF_UNICAST_FLT)) in br_port_clear_promisc()
131 err = br_fdb_sync_static(p->br, p); in br_port_clear_promisc()
135 dev_set_promiscuity(p->dev, -1); in br_port_clear_promisc()
136 p->flags &= ~BR_PROMISC; in br_port_clear_promisc()
144 void br_manage_promisc(struct net_bridge *br) in br_manage_promisc() argument
152 if ((br->dev->flags & IFF_PROMISC) || !br_vlan_enabled(br->dev)) in br_manage_promisc()
155 list_for_each_entry(p, &br->port_list, list) { in br_manage_promisc()
159 /* If the number of auto-ports is <= 1, then all other in br_manage_promisc()
162 * on the auto-port becomes forwarding/egress to other in br_manage_promisc()
165 * auto-port is also statically known. in br_manage_promisc()
169 if ((p->dev->priv_flags & IFF_UNICAST_FLT) && in br_manage_promisc()
170 (br->auto_cnt == 0 || in br_manage_promisc()
171 (br->auto_cnt == 1 && br_auto_port(p)))) in br_manage_promisc()
182 struct net_bridge_port *old_backup = rtnl_dereference(p->backup_port); in nbp_backup_change()
189 return -ENOENT; in nbp_backup_change()
192 if (backup_p->br != p->br) in nbp_backup_change()
193 return -EINVAL; in nbp_backup_change()
197 return -EINVAL; in nbp_backup_change()
204 old_backup->backup_redirected_cnt--; in nbp_backup_change()
207 backup_p->backup_redirected_cnt++; in nbp_backup_change()
208 rcu_assign_pointer(p->backup_port, backup_p); in nbp_backup_change()
216 if (p->backup_redirected_cnt) { in nbp_backup_clear()
219 list_for_each_entry(cur_p, &p->br->port_list, list) { in nbp_backup_clear()
222 backup_p = rtnl_dereference(cur_p->backup_port); in nbp_backup_clear()
228 WARN_ON(rcu_access_pointer(p->backup_port) || p->backup_redirected_cnt); in nbp_backup_clear()
231 static void nbp_update_port_count(struct net_bridge *br) in nbp_update_port_count() argument
236 list_for_each_entry(p, &br->port_list, list) { in nbp_update_port_count()
240 if (br->auto_cnt != cnt) { in nbp_update_port_count()
241 br->auto_cnt = cnt; in nbp_update_port_count()
242 br_manage_promisc(br); in nbp_update_port_count()
252 dev_set_allmulti(p->dev, -1); in nbp_delete_promisc()
254 dev_set_promiscuity(p->dev, -1); in nbp_delete_promisc()
256 br_fdb_unsync_static(p->br, p); in nbp_delete_promisc()
270 net_ns_get_ownership(dev_net(p->dev), uid, gid); in brport_get_ownership()
283 struct net_device *dev = p->dev; in destroy_nbp()
285 p->br = NULL; in destroy_nbp()
286 p->dev = NULL; in destroy_nbp()
287 netdev_put(dev, &p->dev_tracker); in destroy_nbp()
289 kobject_put(&p->kobj); in destroy_nbp()
299 static unsigned get_max_headroom(struct net_bridge *br) in get_max_headroom() argument
304 list_for_each_entry(p, &br->port_list, list) { in get_max_headroom()
305 unsigned dev_headroom = netdev_get_fwd_headroom(p->dev); in get_max_headroom()
314 static void update_headroom(struct net_bridge *br, int new_hr) in update_headroom() argument
318 list_for_each_entry(p, &br->port_list, list) in update_headroom()
319 netdev_set_rx_headroom(p->dev, new_hr); in update_headroom()
321 br->dev->needed_headroom = new_hr; in update_headroom()
335 struct net_bridge *br = p->br; in del_nbp() local
336 struct net_device *dev = p->dev; in del_nbp()
338 sysfs_remove_link(br->ifobj, p->dev->name); in del_nbp()
342 spin_lock_bh(&br->lock); in del_nbp()
344 spin_unlock_bh(&br->lock); in del_nbp()
346 br_mrp_port_del(br, p); in del_nbp()
347 br_cfm_port_del(br, p); in del_nbp()
351 list_del_rcu(&p->list); in del_nbp()
352 if (netdev_get_fwd_headroom(dev) == br->dev->needed_headroom) in del_nbp()
353 update_headroom(br, get_max_headroom(br)); in del_nbp()
357 br_fdb_delete_by_port(br, p, 0, 1); in del_nbp()
361 nbp_update_port_count(br); in del_nbp()
363 netdev_upper_dev_unlink(dev, br->dev); in del_nbp()
365 dev->priv_flags &= ~IFF_BRIDGE_PORT; in del_nbp()
371 kobject_uevent(&p->kobj, KOBJ_REMOVE); in del_nbp()
372 kobject_del(&p->kobj); in del_nbp()
376 call_rcu(&p->rcu, destroy_nbp_rcu); in del_nbp()
382 struct net_bridge *br = netdev_priv(dev); in br_dev_delete() local
385 list_for_each_entry_safe(p, n, &br->port_list, list) { in br_dev_delete()
389 br_recalculate_neigh_suppress_enabled(br); in br_dev_delete()
391 br_fdb_delete_by_port(br, NULL, 0, 1); in br_dev_delete()
393 cancel_delayed_work_sync(&br->gc_work); in br_dev_delete()
395 br_sysfs_delbr(br->dev); in br_dev_delete()
396 unregister_netdevice_queue(br->dev, head); in br_dev_delete()
400 static int find_portno(struct net_bridge *br) in find_portno() argument
408 return -ENOMEM; in find_portno()
411 list_for_each_entry(p, &br->port_list, list) in find_portno()
412 __set_bit(p->port_no, inuse); in find_portno()
417 return (index >= BR_MAX_PORTS) ? -EXFULL : index; in find_portno()
421 static struct net_bridge_port *new_nbp(struct net_bridge *br, in new_nbp() argument
427 index = find_portno(br); in new_nbp()
433 return ERR_PTR(-ENOMEM); in new_nbp()
435 p->br = br; in new_nbp()
436 netdev_hold(dev, &p->dev_tracker, GFP_KERNEL); in new_nbp()
437 p->dev = dev; in new_nbp()
438 p->path_cost = port_cost(dev); in new_nbp()
439 p->priority = 0x8000 >> BR_PORT_BITS; in new_nbp()
440 p->port_no = index; in new_nbp()
441 p->flags = BR_LEARNING | BR_FLOOD | BR_MCAST_FLOOD | BR_BCAST_FLOOD; in new_nbp()
447 netdev_put(dev, &p->dev_tracker); in new_nbp()
464 return -ENOMEM; in br_add_bridge()
467 dev->rtnl_link_ops = &br_link_ops; in br_add_bridge()
482 ret = -ENXIO; /* Could not find device */ in br_del_bridge()
486 ret = -EPERM; in br_del_bridge()
489 else if (dev->flags & IFF_UP) { in br_del_bridge()
491 ret = -EBUSY; in br_del_bridge()
500 /* MTU of the bridge pseudo-device: ETH_DATA_LEN or the minimum of the ports */
501 static int br_mtu_min(const struct net_bridge *br) in br_mtu_min() argument
506 list_for_each_entry(p, &br->port_list, list) in br_mtu_min()
507 if (!ret_mtu || ret_mtu > p->dev->mtu) in br_mtu_min()
508 ret_mtu = p->dev->mtu; in br_mtu_min()
513 void br_mtu_auto_adjust(struct net_bridge *br) in br_mtu_auto_adjust() argument
518 if (br_opt_get(br, BROPT_MTU_SET_BY_USER)) in br_mtu_auto_adjust()
524 dev_set_mtu(br->dev, br_mtu_min(br)); in br_mtu_auto_adjust()
525 br_opt_toggle(br, BROPT_MTU_SET_BY_USER, false); in br_mtu_auto_adjust()
528 static void br_set_gso_limits(struct net_bridge *br) in br_set_gso_limits() argument
534 list_for_each_entry(p, &br->port_list, list) { in br_set_gso_limits()
535 tso_max_size = min(tso_max_size, p->dev->tso_max_size); in br_set_gso_limits()
536 tso_max_segs = min(tso_max_segs, p->dev->tso_max_segs); in br_set_gso_limits()
538 netif_set_tso_max_size(br->dev, tso_max_size); in br_set_gso_limits()
539 netif_set_tso_max_segs(br->dev, tso_max_segs); in br_set_gso_limits()
545 netdev_features_t br_features_recompute(struct net_bridge *br, in br_features_recompute() argument
551 if (list_empty(&br->port_list)) in br_features_recompute()
557 list_for_each_entry(p, &br->port_list, list) { in br_features_recompute()
559 p->dev->features, mask); in br_features_recompute()
567 int br_add_if(struct net_bridge *br, struct net_device *dev, in br_add_if() argument
575 /* Don't allow bridging non-ethernet like devices. */ in br_add_if()
576 if ((dev->flags & IFF_LOOPBACK) || in br_add_if()
577 dev->type != ARPHRD_ETHER || dev->addr_len != ETH_ALEN || in br_add_if()
578 !is_valid_ether_addr(dev->dev_addr)) in br_add_if()
579 return -EINVAL; in br_add_if()
582 if (dev->netdev_ops->ndo_start_xmit == br_dev_xmit) { in br_add_if()
585 return -ELOOP; in br_add_if()
590 return -EBUSY; in br_add_if()
593 if (dev->priv_flags & IFF_DONT_BRIDGE) { in br_add_if()
596 return -EOPNOTSUPP; in br_add_if()
599 p = new_nbp(br, dev); in br_add_if()
605 err = dev_set_allmulti(dev, 1); in br_add_if()
608 netdev_put(dev, &p->dev_tracker); in br_add_if()
613 err = kobject_init_and_add(&p->kobj, &brport_ktype, &(dev->dev.kobj), in br_add_if()
630 dev->priv_flags |= IFF_BRIDGE_PORT; in br_add_if()
632 err = netdev_master_upper_dev_link(dev, br->dev, NULL, NULL, extack); in br_add_if()
638 list_add_rcu(&p->list, &br->port_list); in br_add_if()
640 nbp_update_port_count(br); in br_add_if()
641 if (!br_promisc_port(p) && (p->dev->priv_flags & IFF_UNICAST_FLT)) { in br_add_if()
647 * non-promiscuous ports and *new* ports, so we need to in br_add_if()
650 fdb_synced = br_fdb_sync_static(br, p) == 0; in br_add_if()
655 netdev_update_features(br->dev); in br_add_if()
657 br_hr = br->dev->needed_headroom; in br_add_if()
660 update_headroom(br, dev_hr); in br_add_if()
664 if (br_fdb_add_local(br, p, dev->dev_addr, 0)) in br_add_if()
667 if (br->dev->addr_assign_type != NET_ADDR_SET) { in br_add_if()
671 err = dev_pre_changeaddr_notify(br->dev, dev->dev_addr, extack); in br_add_if()
682 spin_lock_bh(&br->lock); in br_add_if()
683 changed_addr = br_stp_recalculate_bridge_id(br); in br_add_if()
686 (br->dev->flags & IFF_UP)) in br_add_if()
688 spin_unlock_bh(&br->lock); in br_add_if()
693 call_netdevice_notifiers(NETDEV_CHANGEADDR, br->dev); in br_add_if()
695 br_mtu_auto_adjust(br); in br_add_if()
696 br_set_gso_limits(br); in br_add_if()
698 kobject_uevent(&p->kobj, KOBJ_ADD); in br_add_if()
704 br_fdb_unsync_static(br, p); in br_add_if()
705 list_del_rcu(&p->list); in br_add_if()
706 br_fdb_delete_by_port(br, p, 0, 1); in br_add_if()
707 nbp_update_port_count(br); in br_add_if()
708 netdev_upper_dev_unlink(dev, br->dev); in br_add_if()
710 dev->priv_flags &= ~IFF_BRIDGE_PORT; in br_add_if()
715 sysfs_remove_link(br->ifobj, p->dev->name); in br_add_if()
718 netdev_put(dev, &p->dev_tracker); in br_add_if()
719 kobject_put(&p->kobj); in br_add_if()
720 dev_set_allmulti(dev, -1); in br_add_if()
726 int br_del_if(struct net_bridge *br, struct net_device *dev) in br_del_if() argument
732 if (!p || p->br != br) in br_del_if()
733 return -EINVAL; in br_del_if()
741 br_mtu_auto_adjust(br); in br_del_if()
742 br_set_gso_limits(br); in br_del_if()
744 spin_lock_bh(&br->lock); in br_del_if()
745 changed_addr = br_stp_recalculate_bridge_id(br); in br_del_if()
746 spin_unlock_bh(&br->lock); in br_del_if()
749 call_netdevice_notifiers(NETDEV_CHANGEADDR, br->dev); in br_del_if()
751 netdev_update_features(br->dev); in br_del_if()
758 struct net_bridge *br = p->br; in br_port_flags_change() local
761 nbp_update_port_count(br); in br_port_flags_change()
764 br_recalculate_neigh_suppress_enabled(br); in br_port_flags_change()
775 return p->flags & flag; in br_port_flag_is_set()