Lines Matching refs:slave
21 * the first slave bonded to the channel. All slaves will then use
28 * will attach eth0 to bond0 as a slave. eth0 hw mac address will either
154 MODULE_PARM_DESC(primary_reselect, "Reselect primary slave "
159 "2 for only on active slave "
198 MODULE_PARM_DESC(packets_per_slave, "Packets to send per slave in balance-rr "
199 "mode; 0 for a random slave, 1 packet per "
200 "slave (default), >1 packets per slave.");
295 * @slave_dev: slave that is supposed to xmit this skbuff
347 * We don't protect the slave list iteration with a lock because:
372 struct slave *slave, *rollback_slave;
376 bond_for_each_slave(bond, slave, iter) {
377 res = vlan_vid_add(slave->dev, proto, vid);
385 /* unwind to the slave that failed */
387 if (rollback_slave == slave)
407 struct slave *slave;
409 bond_for_each_slave(bond, slave, iter)
410 vlan_vid_del(slave->dev, proto, vid);
432 struct slave *slave;
440 slave = rcu_dereference(bond->curr_active_slave);
441 if (!slave) {
446 if (!slave->dev->xfrmdev_ops ||
447 !slave->dev->xfrmdev_ops->xdo_dev_state_add ||
448 netif_is_bond_master(slave->dev)) {
459 xs->xso.real_dev = slave->dev;
461 err = slave->dev->xfrmdev_ops->xdo_dev_state_add(xs, extack);
479 struct slave *slave;
482 slave = rcu_dereference(bond->curr_active_slave);
483 if (!slave)
486 if (!slave->dev->xfrmdev_ops ||
487 !slave->dev->xfrmdev_ops->xdo_dev_state_add ||
488 netif_is_bond_master(slave->dev)) {
491 slave_warn(bond_dev, slave->dev,
492 "%s: no slave xdo_dev_state_add\n",
500 ipsec->xs->xso.real_dev = slave->dev;
501 if (slave->dev->xfrmdev_ops->xdo_dev_state_add(ipsec->xs, NULL)) {
502 slave_warn(bond_dev, slave->dev, "%s: failed to add SA\n", __func__);
520 struct slave *slave;
527 slave = rcu_dereference(bond->curr_active_slave);
529 if (!slave)
535 WARN_ON(xs->xso.real_dev != slave->dev);
537 if (!slave->dev->xfrmdev_ops ||
538 !slave->dev->xfrmdev_ops->xdo_dev_state_delete ||
539 netif_is_bond_master(slave->dev)) {
540 slave_warn(bond_dev, slave->dev, "%s: no slave xdo_dev_state_delete\n", __func__);
544 slave->dev->xfrmdev_ops->xdo_dev_state_delete(xs);
562 struct slave *slave;
565 slave = rcu_dereference(bond->curr_active_slave);
566 if (!slave) {
576 if (!slave->dev->xfrmdev_ops ||
577 !slave->dev->xfrmdev_ops->xdo_dev_state_delete ||
578 netif_is_bond_master(slave->dev)) {
579 slave_warn(bond_dev, slave->dev,
580 "%s: no slave xdo_dev_state_delete\n",
583 slave->dev->xfrmdev_ops->xdo_dev_state_delete(ipsec->xs);
600 struct slave *curr_active;
650 struct slave *slave;
658 bond_for_each_slave(bond, slave, iter) {
659 if (slave->link == BOND_LINK_UP) {
676 /* Get link speed and duplex from the slave's base driver
682 static int bond_update_speed_duplex(struct slave *slave)
684 struct net_device *slave_dev = slave->dev;
688 slave->speed = SPEED_UNKNOWN;
689 slave->duplex = DUPLEX_UNKNOWN;
704 slave->speed = ecmd.base.speed;
705 slave->duplex = ecmd.base.duplex;
802 struct slave *curr_active = rtnl_dereference(bond->curr_active_slave);
807 struct slave *slave;
809 bond_for_each_slave(bond, slave, iter) {
810 err = dev_set_promiscuity(slave->dev, inc);
825 struct slave *curr_active = rtnl_dereference(bond->curr_active_slave);
830 struct slave *slave;
832 bond_for_each_slave(bond, slave, iter) {
833 err = dev_set_allmulti(slave->dev, inc);
843 * slave.
863 /* Flush bond's hardware addresses from slave */
876 /*--------------------------- Active slave change ---------------------------*/
883 static void bond_hw_addr_swap(struct bonding *bond, struct slave *new_active,
884 struct slave *old_active)
915 * bond_set_dev_addr - clone slave's address to bond
917 * @slave_dev: slave net device
938 static struct slave *bond_get_old_active(struct bonding *bond,
939 struct slave *new_active)
941 struct slave *slave;
944 bond_for_each_slave(bond, slave, iter) {
945 if (slave == new_active)
948 if (ether_addr_equal(bond->dev->dev_addr, slave->dev->dev_addr))
949 return slave;
962 struct slave *new_active,
963 struct slave *old_active)
974 slave_err(bond->dev, new_active->dev, "Error %d setting bond MAC from slave\n",
980 * if just old_active, do nothing (going to no active slave)
1005 slave_err(bond->dev, new_active->dev, "Error %d setting MAC of new active slave\n",
1020 slave_err(bond->dev, old_active->dev, "Error %d setting MAC of old active slave\n",
1033 * bond_choose_primary_or_current - select the primary or high priority slave
1040 * If the highest priority link is not current slave, set it as primary
1043 static struct slave *bond_choose_primary_or_current(struct bonding *bond)
1045 struct slave *prim = rtnl_dereference(bond->primary_slave);
1046 struct slave *curr = rtnl_dereference(bond->curr_active_slave);
1047 struct slave *slave, *hprio = NULL;
1051 bond_for_each_slave(bond, slave, iter) {
1052 if (slave->link == BOND_LINK_UP) {
1053 hprio = hprio ?: slave;
1054 if (slave->prio > hprio->prio)
1055 hprio = slave;
1098 * bond_find_best_slave - select the best available slave to be the active one
1101 static struct slave *bond_find_best_slave(struct bonding *bond)
1103 struct slave *slave, *bestslave = NULL;
1107 slave = bond_choose_primary_or_current(bond);
1108 if (slave)
1109 return slave;
1111 bond_for_each_slave(bond, slave, iter) {
1112 if (slave->link == BOND_LINK_UP)
1113 return slave;
1114 if (slave->link == BOND_LINK_BACK && bond_slave_is_up(slave) &&
1115 slave->delay < mintime) {
1116 mintime = slave->delay;
1117 bestslave = slave;
1126 struct slave *slave;
1129 slave = rcu_dereference(bond->curr_active_slave);
1132 if (!slave || !bond->send_peer_notif ||
1136 test_bit(__LINK_STATE_LINKWATCH_PENDING, &slave->dev->state))
1139 netdev_dbg(bond->dev, "bond_should_notify_peers: slave %s\n",
1140 slave ? slave->dev->name : "NULL");
1146 * bond_change_active_slave - change the active slave into the specified one
1148 * @new_active: the new slave to make the active one
1150 * Set the new slave to the bond's settings and unset them on the old
1155 * because it is apparently the best available slave we have, even though its
1160 void bond_change_active_slave(struct bonding *bond, struct slave *new_active)
1162 struct slave *old_active;
1250 /* resend IGMP joins since active slave has changed or
1264 * bond_select_active_slave - select a new active slave, if needed
1270 * - A slave has got its link back and there's no old curr_active_slave.
1276 struct slave *best_slave;
1296 static inline int slave_enable_netpoll(struct slave *slave)
1306 err = __netpoll_setup(np, slave->dev);
1311 slave->np = np;
1315 static inline void slave_disable_netpoll(struct slave *slave)
1317 struct netpoll *np = slave->np;
1322 slave->np = NULL;
1330 struct slave *slave = NULL;
1338 bond_for_each_slave_rcu(bond, slave, iter) {
1339 if (!bond_slave_is_up(slave))
1344 SLAVE_AD_INFO(slave)->port.aggregator;
1351 netpoll_poll_dev(slave->dev);
1359 struct slave *slave;
1361 bond_for_each_slave(bond, slave, iter)
1362 if (bond_slave_is_up(slave))
1363 slave_disable_netpoll(slave);
1370 struct slave *slave;
1373 bond_for_each_slave(bond, slave, iter) {
1374 err = slave_enable_netpoll(slave);
1383 static inline int slave_enable_netpoll(struct slave *slave)
1387 static inline void slave_disable_netpoll(struct slave *slave)
1403 struct slave *slave;
1410 bond_for_each_slave(bond, slave, iter) {
1412 slave->dev->features,
1443 struct slave *slave;
1453 bond_for_each_slave(bond, slave, iter) {
1455 slave->dev->vlan_features, BOND_VLAN_FEATURES);
1458 slave->dev->hw_enc_features,
1463 slave->dev->hw_enc_features,
1468 slave->dev->mpls_features,
1471 dst_release_flag &= slave->dev->priv_flags;
1472 if (slave->dev->hard_header_len > max_hard_header_len)
1473 max_hard_header_len = slave->dev->hard_header_len;
1475 tso_max_size = min(tso_max_size, slave->dev->tso_max_size);
1476 tso_max_segs = min(tso_max_segs, slave->dev->tso_max_segs);
1525 /* On bonding slaves other than the currently active slave, suppress
1529 struct slave *slave,
1532 if (bond_is_slave_inactive(slave)) {
1545 struct slave *slave;
1548 struct slave *);
1557 slave = bond_slave_get_rcu(skb->dev);
1558 bond = slave->bond;
1562 ret = recv_probe(skb, bond, slave);
1573 * inactive slave links without being forced to bind to them
1580 if (bond_should_deliver_exact_match(skb, slave, bond)) {
1645 static int bond_master_upper_dev_link(struct bonding *bond, struct slave *slave,
1656 err = netdev_master_upper_dev_link(slave->dev, bond->dev, slave,
1661 slave->dev->flags |= IFF_SLAVE;
1665 static void bond_upper_dev_unlink(struct bonding *bond, struct slave *slave)
1667 netdev_upper_dev_unlink(slave->dev, bond->dev);
1668 slave->dev->flags &= ~IFF_SLAVE;
1673 struct slave *slave = to_slave(kobj);
1674 struct bonding *bond = bond_get_bond_by_slave(slave);
1676 cancel_delayed_work_sync(&slave->notify_work);
1678 kfree(SLAVE_AD_INFO(slave));
1680 kfree(slave);
1690 static int bond_kobj_init(struct slave *slave)
1694 err = kobject_init_and_add(&slave->kobj, &slave_ktype,
1695 &(slave->dev->dev.kobj), "bonding_slave");
1697 kobject_put(&slave->kobj);
1702 static struct slave *bond_alloc_slave(struct bonding *bond,
1705 struct slave *slave = NULL;
1707 slave = kzalloc(sizeof(*slave), GFP_KERNEL);
1708 if (!slave)
1711 slave->bond = bond;
1712 slave->dev = slave_dev;
1713 INIT_DELAYED_WORK(&slave->notify_work, bond_netdev_notify_work);
1715 if (bond_kobj_init(slave))
1719 SLAVE_AD_INFO(slave) = kzalloc(sizeof(struct ad_slave_info),
1721 if (!SLAVE_AD_INFO(slave)) {
1722 kobject_put(&slave->kobj);
1727 return slave;
1737 static void bond_fill_ifslave(struct slave *slave, struct ifslave *info)
1739 strcpy(info->slave_name, slave->dev->name);
1740 info->link = slave->link;
1741 info->state = bond_slave_state(slave);
1742 info->link_failure_count = slave->link_failure_count;
1747 struct slave *slave = container_of(_work, struct slave,
1753 bond_fill_ifslave(slave, &binfo.slave);
1754 bond_fill_ifbond(slave->bond, &binfo.master);
1755 netdev_bonding_info_change(slave->dev, &binfo);
1758 queue_delayed_work(slave->bond->wq, &slave->notify_work, 1);
1762 void bond_queue_slave_event(struct slave *slave)
1764 queue_delayed_work(slave->bond->wq, &slave->notify_work, 0);
1767 void bond_lower_state_changed(struct slave *slave)
1771 info.link_up = slave->link == BOND_LINK_UP ||
1772 slave->link == BOND_LINK_FAIL;
1773 info.tx_enabled = bond_is_active_slave(slave);
1774 netdev_lower_state_changed(slave->dev, &info);
1810 struct slave *slave;
1819 bond_for_each_slave(bond, slave, iter)
1820 val &= slave->dev->xdp_features;
1827 /* enslave device <slave> to bond device <master> */
1833 struct slave *new_slave = NULL, *prev_slave;
1872 slave_warn(bond_dev, slave_dev, "enslaved VLAN challenged slave. Adding VLANs will be blocked as long as it is part of bond.\n");
1882 * be identified with moderate accuracy by the state of the slave:
1892 /* set bonding device ether type by slave - bonding netdevices are
1893 * created with ether_setup, so when the slave type is not ARPHRD_ETHER
1940 slave_warn(bond_dev, slave_dev, "The slave device specified does not support setting the MAC address\n");
1957 /* If this is the first slave, then we need to set the master's hardware
1958 * address to be the same as the slave's.
1978 /* Save slave's original mtu and then set it to match the bond */
1986 /* Save slave's original ("permanent") mac address for modes
1995 /* Set slave to master's mac address. The application already
1996 * set the master's mac address to that of the first slave
2011 /* open the slave since the application closed it */
2014 slave_err(bond_dev, slave_dev, "Opening slave failed\n");
2019 /* initialize slave stats */
2065 slave_warn(bond_dev, slave_dev, "MII and ETHTOOL support not available for slave, and arp_interval/arp_ip_target module parameters not specified, thus bonding will not detect link failures! see bonding.txt for details\n");
2068 slave_warn(bond_dev, slave_dev, "can't get link status from slave; the network driver associated with this interface does not support MII or ETHTOOL link status reporting, thus miimon has no effect on this interface\n");
2102 slave_dbg(bond_dev, slave_dev, "Initial state of slave is BOND_LINK_%s\n",
2107 /* if there is a primary slave, remember it */
2125 /* if this is the first slave */
2145 slave_dbg(bond_dev, slave_dev, "This slave is always active in trunk mode\n");
2164 slave_info(bond_dev, slave_dev, "master_dev is using netpoll, but new slave device does not support netpoll\n");
2199 /* set promiscuity level to new slave */
2206 /* set allmulti level to new slave */
2318 * MAC if this slave's MAC is in use by the bond, or at
2334 /* Enslave of first slave has failed and we need to fix master's mac */
2348 /* Try to release the slave device <slave> from the bond device <master>
2353 * The rules for slave state should be:
2364 struct slave *slave, *oldcurrent;
2369 /* slave is not a slave or master is not master of this slave */
2372 slave_dbg(bond_dev, slave_dev, "cannot release slave\n");
2378 slave = bond_get_slave_by_dev(bond, slave_dev);
2379 if (!slave) {
2380 /* not a slave of this bond */
2386 bond_set_slave_inactive_flags(slave, BOND_SLAVE_NOTIFY_NOW);
2388 bond_sysfs_slave_del(slave);
2390 /* recompute stats just before removing the slave */
2405 * for this slave anymore.
2410 bond_3ad_unbind_slave(slave);
2412 bond_upper_dev_unlink(bond, slave);
2415 bond_update_slave_arr(bond, slave);
2418 bond_is_active_slave(slave) ? "active" : "backup");
2426 if (ether_addr_equal_64bits(bond_dev->dev_addr, slave->perm_hwaddr) &&
2428 slave_warn(bond_dev, slave_dev, "the permanent HWaddr of slave - %pM - is still in use by bond - set the HWaddr of slave to a different address to avoid conflicts\n",
2429 slave->perm_hwaddr);
2432 if (rtnl_dereference(bond->primary_slave) == slave)
2435 if (oldcurrent == slave)
2439 /* Must be called only after the slave has been
2442 * but before a new active slave is selected.
2444 bond_alb_deinit_slave(bond, slave);
2449 } else if (oldcurrent == slave) {
2451 * is no concern that another slave add/remove event
2473 slave_info(bond_dev, slave_dev, "last VLAN challenged slave left bond - VLAN blocking is removed\n");
2481 /* unset promiscuity level from slave
2485 * when this slave was attached, so we cache at the start of the
2491 /* unset allmulti level from slave */
2499 slave_disable_netpoll(slave);
2501 /* close slave before restoring its mac address */
2509 bond_hw_addr_copy(ss.__data, slave->perm_hwaddr,
2510 slave->dev->addr_len);
2516 __dev_set_mtu(slave_dev, slave->original_mtu);
2518 dev_set_mtu(slave_dev, slave->original_mtu);
2524 kobject_put(&slave->kobj);
2535 /* First release a slave and then destroy the bond if no more slaves are left.
2567 struct slave *slave;
2569 bond_for_each_slave(bond, slave, iter) {
2572 bond_fill_ifslave(slave, info);
2588 struct slave *slave;
2601 bond_for_each_slave_rcu(bond, slave, iter) {
2602 bond_propose_link_state(slave, BOND_LINK_NOCHANGE);
2604 link_state = bond_check_dev_link(bond, slave->dev, 0);
2606 switch (slave->link) {
2611 bond_propose_link_state(slave, BOND_LINK_FAIL);
2613 slave->delay = bond->params.downdelay;
2614 if (slave->delay) {
2615 slave_info(bond->dev, slave->dev, "link status down for %sinterface, disabling it in %d ms\n",
2618 (bond_is_active_slave(slave) ?
2626 bond_propose_link_state(slave, BOND_LINK_UP);
2627 slave->last_link_up = jiffies;
2628 slave_info(bond->dev, slave->dev, "link status up again after %d ms\n",
2629 (bond->params.downdelay - slave->delay) *
2635 if (slave->delay <= 0) {
2636 bond_propose_link_state(slave, BOND_LINK_DOWN);
2641 slave->delay--;
2648 bond_propose_link_state(slave, BOND_LINK_BACK);
2650 slave->delay = bond->params.updelay;
2652 if (slave->delay) {
2653 slave_info(bond->dev, slave->dev, "link status up, enabling it in %d ms\n",
2661 bond_propose_link_state(slave, BOND_LINK_DOWN);
2662 slave_info(bond->dev, slave->dev, "link status down again after %d ms\n",
2663 (bond->params.updelay - slave->delay) *
2670 slave->delay = 0;
2672 if (slave->delay <= 0) {
2673 bond_propose_link_state(slave, BOND_LINK_UP);
2679 slave->delay--;
2688 struct slave *slave,
2693 bond_3ad_handle_link_change(slave, link);
2697 bond_alb_handle_link_change(bond, slave, link);
2707 struct slave *slave, *primary, *active;
2713 bond_for_each_slave(bond, slave, iter) {
2714 switch (slave->link_new_state) {
2716 /* For 802.3ad mode, check current slave speed and
2723 slave->link == BOND_LINK_UP)
2724 bond_3ad_adapter_speed_duplex_changed(slave);
2728 if (bond_update_speed_duplex(slave) &&
2730 slave->link = BOND_LINK_DOWN;
2732 slave_warn(bond->dev, slave->dev,
2736 bond_set_slave_link_state(slave, BOND_LINK_UP,
2738 slave->last_link_up = jiffies;
2743 bond_set_backup_slave(slave);
2746 bond_set_active_slave(slave);
2749 slave_info(bond->dev, slave->dev, "link status definitely up, %u Mbps %s duplex\n",
2750 slave->speed == SPEED_UNKNOWN ? 0 : slave->speed,
2751 slave->duplex ? "full" : "half");
2753 bond_miimon_link_change(bond, slave, BOND_LINK_UP);
2756 if (!active || slave == primary || slave->prio > active->prio)
2762 if (slave->link_failure_count < UINT_MAX)
2763 slave->link_failure_count++;
2765 bond_set_slave_link_state(slave, BOND_LINK_DOWN,
2770 bond_set_slave_inactive_flags(slave,
2773 slave_info(bond->dev, slave->dev, "link status definitely down, disabling slave\n");
2775 bond_miimon_link_change(bond, slave, BOND_LINK_DOWN);
2777 if (slave == rcu_access_pointer(bond->curr_active_slave))
2783 slave_err(bond->dev, slave->dev, "invalid new link %d on slave\n",
2784 slave->link_new_state);
2785 bond_propose_link_state(slave, BOND_LINK_NOCHANGE);
2814 struct slave *slave;
2843 bond_for_each_slave(bond, slave, iter) {
2844 bond_commit_link_state(slave, BOND_SLAVE_NOTIFY_LATER);
2891 static bool bond_handle_vlan(struct slave *slave, struct bond_vlan_tag *tags,
2894 struct net_device *bond_dev = slave->bond->dev;
2895 struct net_device *slave_dev = slave->dev;
2936 static void bond_arp_send(struct slave *slave, int arp_op, __be32 dest_ip,
2939 struct net_device *bond_dev = slave->bond->dev;
2940 struct net_device *slave_dev = slave->dev;
2943 slave_dbg(bond_dev, slave_dev, "arp %d on slave: dst %pI4 src %pI4\n",
2954 if (bond_handle_vlan(slave, tags, skb)) {
2955 slave_update_last_tx(slave);
3002 static void bond_arp_send_all(struct bonding *bond, struct slave *slave)
3010 slave_dbg(bond->dev, slave->dev, "%s: target %pI4\n",
3025 bond_arp_send(slave, ARPOP_REQUEST, targets[i],
3042 slave_dbg(bond->dev, slave->dev, "no path to arp_ip_target %pI4 via rt.dev %s\n",
3051 bond_arp_send(slave, ARPOP_REQUEST, targets[i], addr, tags);
3056 static void bond_validate_arp(struct bonding *bond, struct slave *slave, __be32 sip, __be32 tip)
3061 slave_dbg(bond->dev, slave->dev, "%s: sip %pI4 tip %pI4 not found\n",
3068 slave_dbg(bond->dev, slave->dev, "%s: sip %pI4 not found in targets\n",
3072 slave->last_rx = jiffies;
3073 slave->target_last_arp_rx[i] = jiffies;
3077 struct slave *slave)
3080 struct slave *curr_active_slave, *curr_arp_slave;
3109 slave_dbg(bond->dev, slave->dev, "%s: %s/%d av %d sv %d sip %pI4 tip %pI4\n",
3110 __func__, slave->dev->name, bond_slave_state(slave),
3111 bond->params.arp_validate, slave_do_arp_validate(bond, slave),
3119 * (a) the slave receiving the ARP is active (which includes the
3120 * current ARP slave, if any), or
3122 * (b) the receiving slave isn't active, but there is a currently
3123 * active slave and it received valid arp reply(s) after it became
3124 * the currently active slave, or
3126 * (c) there is an ARP slave that sent an ARP during the prior ARP
3127 * interval, and we receive an ARP reply on any slave. We accept
3129 * reply to a slave other than the sender of the ARP request.
3133 * slave through the L2 switch(es) to the receiving slave. Since
3140 if (bond_is_active_slave(slave))
3141 bond_validate_arp(bond, slave, sip, tip);
3145 bond_validate_arp(bond, slave, tip, sip);
3148 bond_validate_arp(bond, slave, sip, tip);
3157 static void bond_ns_send(struct slave *slave, const struct in6_addr *daddr,
3160 struct net_device *bond_dev = slave->bond->dev;
3161 struct net_device *slave_dev = slave->dev;
3165 slave_dbg(bond_dev, slave_dev, "NS on slave: dst %pI6c src %pI6c\n",
3175 if (bond_handle_vlan(slave, tags, skb)) {
3176 slave_update_last_tx(slave);
3181 static void bond_ns_send_all(struct bonding *bond, struct slave *slave)
3191 slave_dbg(bond->dev, slave->dev, "%s: target %pI6c\n",
3210 bond_ns_send(slave, &targets[i], &in6addr_any, tags);
3226 slave_dbg(bond->dev, slave->dev, "no path to ns_ip6_target %pI6c via dst->dev %s\n",
3234 bond_ns_send(slave, &targets[i], &saddr, tags);
3236 bond_ns_send(slave, &targets[i], &in6addr_any, tags);
3269 static void bond_validate_na(struct bonding *bond, struct slave *slave,
3282 slave_dbg(bond->dev, slave->dev, "%s: sip %pI6c tip %pI6c not found\n",
3289 slave_dbg(bond->dev, slave->dev, "%s: sip %pI6c not found in targets\n",
3293 slave->last_rx = jiffies;
3294 slave->target_last_arp_rx[i] = jiffies;
3298 struct slave *slave)
3300 struct slave *curr_active_slave, *curr_arp_slave;
3320 slave_dbg(bond->dev, slave->dev, "%s: %s/%d av %d sv %d sip %pI6c tip %pI6c\n",
3321 __func__, slave->dev->name, bond_slave_state(slave),
3322 bond->params.arp_validate, slave_do_arp_validate(bond, slave),
3331 if (bond_is_active_slave(slave))
3332 bond_validate_na(bond, slave, saddr, daddr);
3336 bond_validate_na(bond, slave, daddr, saddr);
3339 bond_validate_na(bond, slave, saddr, daddr);
3347 struct slave *slave)
3354 slave_dbg(bond->dev, slave->dev, "%s: skb->dev %s\n",
3358 if (!slave_do_arp_validate(bond, slave)) {
3364 slave->last_rx = jiffies;
3367 return bond_arp_rcv(skb, bond, slave);
3370 return bond_na_rcv(skb, bond, slave);
3377 static void bond_send_validate(struct bonding *bond, struct slave *slave)
3379 bond_arp_send_all(bond, slave);
3381 bond_ns_send_all(bond, slave);
3399 /* This function is called regularly to monitor each slave's link
3407 struct slave *slave, *oldcurrent;
3419 * the picture unless it is null. also, slave->last_link_up is not
3420 * needed here because we send an arp on each slave and give a slave
3425 bond_for_each_slave_rcu(bond, slave, iter) {
3426 unsigned long last_tx = slave_last_tx(slave);
3428 bond_propose_link_state(slave, BOND_LINK_NOCHANGE);
3430 if (slave->link != BOND_LINK_UP) {
3432 bond_time_in_interval(bond, slave->last_rx, 1)) {
3434 bond_propose_link_state(slave, BOND_LINK_UP);
3438 * mode. the window of a slave being up and
3443 slave_info(bond->dev, slave->dev, "link status definitely up\n");
3446 slave_info(bond->dev, slave->dev, "interface is now up\n");
3450 /* slave->link == BOND_LINK_UP */
3457 !bond_time_in_interval(bond, slave->last_rx, bond->params.missed_max)) {
3459 bond_propose_link_state(slave, BOND_LINK_DOWN);
3462 if (slave->link_failure_count < UINT_MAX)
3463 slave->link_failure_count++;
3465 slave_info(bond->dev, slave->dev, "interface is now down\n");
3467 if (slave == oldcurrent)
3479 if (bond_slave_is_up(slave))
3480 bond_send_validate(bond, slave);
3489 bond_for_each_slave(bond, slave, iter) {
3490 if (slave->link_new_state != BOND_LINK_NOCHANGE)
3491 slave->link = slave->link_new_state;
3515 * should take place for the slave. Returns 0 if no changes are found, >0
3524 struct slave *slave;
3527 bond_for_each_slave_rcu(bond, slave, iter) {
3528 bond_propose_link_state(slave, BOND_LINK_NOCHANGE);
3529 last_rx = slave_last_rx(bond, slave);
3531 if (slave->link != BOND_LINK_UP) {
3533 bond_propose_link_state(slave, BOND_LINK_UP);
3535 } else if (slave->link == BOND_LINK_BACK) {
3536 bond_propose_link_state(slave, BOND_LINK_FAIL);
3546 if (bond_time_in_interval(bond, slave->last_link_up, 2))
3549 /* Backup slave is down if:
3558 * gives each slave a chance to tx/rx traffic
3561 if (!bond_is_active_slave(slave) &&
3564 bond_propose_link_state(slave, BOND_LINK_DOWN);
3568 /* Active slave is down if:
3573 last_tx = slave_last_tx(slave);
3574 if (bond_is_active_slave(slave) &&
3577 bond_propose_link_state(slave, BOND_LINK_DOWN);
3595 struct slave *slave;
3597 bond_for_each_slave(bond, slave, iter) {
3598 switch (slave->link_new_state) {
3603 last_tx = slave_last_tx(slave);
3604 if (rtnl_dereference(bond->curr_active_slave) != slave ||
3607 struct slave *current_arp_slave;
3610 bond_set_slave_link_state(slave, BOND_LINK_UP,
3619 slave_info(bond->dev, slave->dev, "link status definitely up\n");
3622 slave == rtnl_dereference(bond->primary_slave) ||
3623 slave->prio > rtnl_dereference(bond->curr_active_slave)->prio)
3631 if (slave->link_failure_count < UINT_MAX)
3632 slave->link_failure_count++;
3634 bond_set_slave_link_state(slave, BOND_LINK_DOWN,
3636 bond_set_slave_inactive_flags(slave,
3639 slave_info(bond->dev, slave->dev, "link status definitely down, disabling slave\n");
3641 if (slave == rtnl_dereference(bond->curr_active_slave)) {
3649 bond_set_slave_link_state(slave, BOND_LINK_FAIL,
3651 bond_set_slave_inactive_flags(slave,
3654 /* A slave has just been enslaved and has become
3655 * the current active slave.
3662 slave_err(bond->dev, slave->dev,
3663 "impossible: link_new_state %d on slave\n",
3664 slave->link_new_state);
3684 struct slave *slave, *before = NULL, *new_slave = NULL,
3702 * backup slave from the current_arp_slave and make it the candidate
3712 bond_for_each_slave_rcu(bond, slave, iter) {
3713 if (!found && !before && bond_slave_is_up(slave))
3714 before = slave;
3716 if (found && !new_slave && bond_slave_is_up(slave))
3717 new_slave = slave;
3722 * one the current slave so it is still marked
3725 if (!bond_slave_is_up(slave) && slave->link == BOND_LINK_UP) {
3726 bond_set_slave_link_state(slave, BOND_LINK_DOWN,
3728 if (slave->link_failure_count < UINT_MAX)
3729 slave->link_failure_count++;
3731 bond_set_slave_inactive_flags(slave,
3734 slave_info(bond->dev, slave->dev, "backup interface is now down\n");
3736 if (slave == curr_arp_slave)
3754 bond_for_each_slave_rcu(bond, slave, iter) {
3755 if (slave->should_notify || slave->should_notify_link) {
3872 struct slave *slave = bond_slave_get_rtnl(slave_dev), *primary;
3878 * slave will be NULL
3880 if (!slave) {
3881 netdev_dbg(slave_dev, "%s called on NULL slave\n", __func__);
3885 bond_dev = slave->bond->dev;
3886 bond = slave->bond;
3901 * Getting invalid Speed/Duplex values here will put slave
3907 if (bond_update_speed_duplex(slave) &&
3909 if (slave->last_link_up)
3910 slave->link = BOND_LINK_FAIL;
3912 slave->link = BOND_LINK_DOWN;
3916 bond_3ad_adapter_speed_duplex_changed(slave);
3919 /* Refresh slave-array if applicable!
3921 * then these events will not cause the slave-array to be
3922 * refreshed. This will cause xmit to use a slave that is not
3938 * take over the slave's change_mtu
3949 if (slave == primary) {
3950 /* slave's name changed - he's no longer primary */
3953 /* we have a new primary slave */
3954 rcu_assign_pointer(bond->primary_slave, slave);
3959 netdev_info(bond->dev, "Primary slave changed to %s, reselecting active slave\n",
3975 call_netdevice_notifiers(event, slave->bond->dev);
3991 * locks for us to safely manipulate the slave devices (RTNL lock,
4268 struct slave *slave;
4276 /* reset slave->backup and slave->inactive */
4278 bond_for_each_slave(bond, slave, iter) {
4280 slave != rcu_access_pointer(bond->curr_active_slave)) {
4281 bond_set_slave_inactive_flags(slave,
4284 bond_set_slave_active_flags(slave,
4314 bond_for_each_slave(bond, slave, iter)
4315 dev_mc_add(slave->dev, lacpdu_mcast_addr);
4327 struct slave *slave;
4337 slave = rcu_dereference(bond->curr_active_slave);
4338 if (slave)
4339 bond_hw_addr_flush(bond_dev, slave->dev);
4344 bond_for_each_slave(bond, slave, iter)
4345 bond_hw_addr_flush(bond_dev, slave->dev);
4427 struct slave *slave;
4439 bond_for_each_slave_rcu(bond, slave, iter) {
4441 dev_get_stats(slave->dev, &temp);
4443 bond_fold_stats(stats, new, &slave->slave_stats);
4445 /* save off the slave stats for the next run */
4446 memcpy(&slave->slave_stats, new, sizeof(*new));
4607 struct slave *slave;
4611 slave = rcu_dereference(bond->curr_active_slave);
4612 if (slave) {
4613 dev_uc_sync(slave->dev, bond_dev);
4614 dev_mc_sync(slave->dev, bond_dev);
4617 bond_for_each_slave_rcu(bond, slave, iter) {
4618 dev_uc_sync_multiple(slave->dev, bond_dev);
4619 dev_mc_sync_multiple(slave->dev, bond_dev);
4630 struct slave *slave;
4634 slave = bond_first_slave_rcu(bond);
4635 if (!slave)
4637 slave_ops = slave->dev->netdev_ops;
4650 ret = slave_ops->ndo_neigh_setup(slave->dev, &parms);
4663 * slave exists. So we must declare proxy setup function which will
4664 * be used at run time to resolve the actual slave neigh param setup.
4684 struct slave *slave, *rollback_slave;
4690 bond_for_each_slave(bond, slave, iter) {
4691 slave_dbg(bond_dev, slave->dev, "s %p c_m %p\n",
4692 slave, slave->dev->netdev_ops->ndo_change_mtu);
4694 res = dev_set_mtu(slave->dev, new_mtu);
4697 /* If we failed to set the slave's mtu to the new value
4700 * different mtu values than the active slave we'll
4705 slave_dbg(bond_dev, slave->dev, "err %d setting mtu to %d\n",
4716 /* unwind from head to the slave that failed */
4720 if (rollback_slave == slave)
4741 struct slave *slave, *rollback_slave;
4762 bond_for_each_slave(bond, slave, iter) {
4763 slave_dbg(bond_dev, slave->dev, "%s: slave=%p\n",
4764 __func__, slave);
4765 res = dev_set_mac_address(slave->dev, addr, NULL);
4767 /* TODO: consider downing the slave
4773 slave_dbg(bond_dev, slave->dev, "%s: err %d\n",
4787 /* unwind from head to the slave that failed */
4791 if (rollback_slave == slave)
4806 * bond_get_slave_by_id - get xmit slave with slave_id
4808 * @slave_id: slave id up to slave_cnt-1 through which to transmit
4810 * This function tries to get slave with slave_id but in case
4811 * it fails, it tries to find the first available slave for transmission.
4813 static struct slave *bond_get_slave_by_id(struct bonding *bond,
4817 struct slave *slave;
4820 /* Here we start from the slave with slave_id */
4821 bond_for_each_slave_rcu(bond, slave, iter) {
4823 if (bond_slave_can_tx(slave))
4824 return slave;
4828 /* Here we start from the first slave up to slave_id */
4830 bond_for_each_slave_rcu(bond, slave, iter) {
4833 if (bond_slave_can_tx(slave))
4834 return slave;
4836 /* no slave that can tx has been found */
4841 * bond_rr_gen_slave_id - generate slave id based on packets_per_slave
4845 * this function generates a slave id, which is usually used as the next
4846 * slave to transmit through.
4873 static struct slave *bond_xmit_roundrobin_slave_get(struct bonding *bond,
4876 struct slave *slave;
4895 slave = rcu_dereference(bond->curr_active_slave);
4896 if (slave)
4897 return slave;
4911 static struct slave *bond_xdp_xmit_roundrobin_slave_get(struct bonding *bond,
4914 struct slave *slave;
4936 slave = rcu_dereference(bond->curr_active_slave);
4937 if (slave)
4938 return slave;
4956 struct slave *slave;
4958 slave = bond_xmit_roundrobin_slave_get(bond, skb);
4959 if (likely(slave))
4960 return bond_dev_queue_xmit(bond, skb, slave->dev);
4965 static struct slave *bond_xmit_activebackup_slave_get(struct bonding *bond)
4977 struct slave *slave;
4979 slave = bond_xmit_activebackup_slave_get(bond);
4980 if (slave)
4981 return bond_dev_queue_xmit(bond, skb, slave->dev);
5008 pr_warn_ratelimited("Failed to update slave array from WT\n");
5018 struct slave *skipslave)
5023 * slave but allocation failed (most likely!). BTW this is
5028 * this to-be-skipped slave to send a packet out.
5061 * to determine the slave interface -
5068 int bond_update_slave_arr(struct bonding *bond, struct slave *skipslave)
5071 struct slave *slave;
5102 bond_for_each_slave(bond, slave, iter) {
5103 if (skipslave == slave)
5106 all_slaves->arr[all_slaves->count++] = slave;
5110 agg = SLAVE_AD_INFO(slave)->port.aggregator;
5114 if (!bond_slave_can_tx(slave))
5117 slave_dbg(bond->dev, slave->dev, "Adding slave to tx hash array[%d]\n",
5120 usable_slaves->arr[usable_slaves->count++] = slave;
5138 static struct slave *bond_xmit_3ad_xor_slave_get(struct bonding *bond,
5142 struct slave *slave;
5151 slave = slaves->arr[hash % count];
5152 return slave;
5155 static struct slave *bond_xdp_xmit_3ad_xor_slave_get(struct bonding *bond,
5172 * usable slave array is formed in the control path. The xmit function
5180 struct slave *slave;
5183 slave = bond_xmit_3ad_xor_slave_get(bond, skb, slaves);
5184 if (likely(slave))
5185 return bond_dev_queue_xmit(bond, skb, slave->dev);
5195 struct slave *slave = NULL;
5200 bond_for_each_slave_rcu(bond, slave, iter) {
5203 if (!(bond_slave_is_up(slave) && slave->link == BOND_LINK_UP))
5206 if (bond_is_last_slave(bond, slave)) {
5218 if (bond_dev_queue_xmit(bond, skb2, slave->dev) == NETDEV_TX_OK)
5234 /* Lookup the slave that corresponds to a qid */
5238 struct slave *slave = NULL;
5245 bond_for_each_slave_rcu(bond, slave, iter) {
5246 if (slave->queue_id == skb_get_queue_mapping(skb)) {
5247 if (bond_slave_is_up(slave) &&
5248 slave->link == BOND_LINK_UP) {
5249 bond_dev_queue_xmit(bond, skb, slave->dev);
5252 /* If the slave isn't UP, use default transmit policy. */
5288 struct slave *slave = NULL;
5292 slave = bond_xmit_roundrobin_slave_get(bond, skb);
5295 slave = bond_xmit_activebackup_slave_get(bond);
5303 slave = bond_xmit_3ad_xor_slave_get(bond, skb, slaves);
5308 slave = bond_xmit_alb_slave_get(bond, skb);
5311 slave = bond_xmit_tlb_slave_get(bond, skb);
5319 if (slave)
5320 return slave->dev;
5374 struct slave *slave;
5384 slave = slaves->arr[hash % count];
5386 return slave->dev;
5479 struct slave *slave;
5485 slave = bond_xdp_xmit_roundrobin_slave_get(bond, xdp);
5489 slave = bond_xmit_activebackup_slave_get(bond);
5494 slave = bond_xdp_xmit_3ad_xor_slave_get(bond, xdp);
5504 if (slave)
5505 return slave->dev;
5552 struct slave *slave, *rollback_slave;
5570 bond_for_each_slave(bond, slave, iter) {
5571 struct net_device *slave_dev = slave->dev;
5617 if (slave == rollback_slave)
5640 static u32 bond_mode_bcast_speed(struct slave *slave, u32 speed)
5643 speed = slave->speed;
5645 speed = min(speed, slave->speed);
5716 struct slave *slave;
5727 bond_for_each_slave(bond, slave, iter) {
5728 if (bond_slave_can_tx(slave)) {
5729 bond_update_speed_duplex(slave);
5730 if (slave->speed != SPEED_UNKNOWN) {
5732 speed = bond_mode_bcast_speed(slave,
5735 speed += slave->speed;
5738 slave->duplex != DUPLEX_UNKNOWN)
5739 cmd->base.duplex = slave->duplex;
5765 struct slave *slave;
5787 bond_for_each_slave_rcu(bond, slave, iter) {
5789 ops = slave->dev->ethtool_ops;
5790 phydev = slave->dev->phydev;
5795 ret = ops->get_ts_info(slave->dev, &ts_info);
5948 struct slave *slave;
5953 bond_for_each_slave(bond, slave, iter)
5954 __bond_release_one(bond_dev, slave->dev, true, true);