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 && net_ratelimit()) {
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;
2629 slave_info(bond->dev, slave->dev, "link status up again after %d ms\n",
2630 (bond->params.downdelay - slave->delay) *
2636 if (slave->delay <= 0) {
2637 bond_propose_link_state(slave, BOND_LINK_DOWN);
2642 slave->delay--;
2649 bond_propose_link_state(slave, BOND_LINK_BACK);
2651 slave->delay = bond->params.updelay;
2653 if (slave->delay && net_ratelimit()) {
2654 slave_info(bond->dev, slave->dev, "link status up, enabling it in %d ms\n",
2662 bond_propose_link_state(slave, BOND_LINK_DOWN);
2664 slave_info(bond->dev, slave->dev, "link status down again after %d ms\n",
2665 (bond->params.updelay - slave->delay) *
2672 slave->delay = 0;
2674 if (slave->delay <= 0) {
2675 bond_propose_link_state(slave, BOND_LINK_UP);
2681 slave->delay--;
2690 struct slave *slave,
2695 bond_3ad_handle_link_change(slave, link);
2699 bond_alb_handle_link_change(bond, slave, link);
2709 struct slave *slave, *primary, *active;
2715 bond_for_each_slave(bond, slave, iter) {
2716 switch (slave->link_new_state) {
2718 /* For 802.3ad mode, check current slave speed and
2725 slave->link == BOND_LINK_UP)
2726 bond_3ad_adapter_speed_duplex_changed(slave);
2730 if (bond_update_speed_duplex(slave) &&
2732 slave->link = BOND_LINK_DOWN;
2734 slave_warn(bond->dev, slave->dev,
2738 bond_set_slave_link_state(slave, BOND_LINK_UP,
2740 slave->last_link_up = jiffies;
2745 bond_set_backup_slave(slave);
2748 bond_set_active_slave(slave);
2751 slave_info(bond->dev, slave->dev, "link status definitely up, %u Mbps %s duplex\n",
2752 slave->speed == SPEED_UNKNOWN ? 0 : slave->speed,
2753 slave->duplex ? "full" : "half");
2755 bond_miimon_link_change(bond, slave, BOND_LINK_UP);
2758 if (!active || slave == primary || slave->prio > active->prio)
2764 if (slave->link_failure_count < UINT_MAX)
2765 slave->link_failure_count++;
2767 bond_set_slave_link_state(slave, BOND_LINK_DOWN,
2772 bond_set_slave_inactive_flags(slave,
2775 slave_info(bond->dev, slave->dev, "link status definitely down, disabling slave\n");
2777 bond_miimon_link_change(bond, slave, BOND_LINK_DOWN);
2779 if (slave == rcu_access_pointer(bond->curr_active_slave))
2785 slave_err(bond->dev, slave->dev, "invalid new link %d on slave\n",
2786 slave->link_new_state);
2787 bond_propose_link_state(slave, BOND_LINK_NOCHANGE);
2816 struct slave *slave;
2845 bond_for_each_slave(bond, slave, iter) {
2846 bond_commit_link_state(slave, BOND_SLAVE_NOTIFY_LATER);
2893 static bool bond_handle_vlan(struct slave *slave, struct bond_vlan_tag *tags,
2896 struct net_device *bond_dev = slave->bond->dev;
2897 struct net_device *slave_dev = slave->dev;
2938 static void bond_arp_send(struct slave *slave, int arp_op, __be32 dest_ip,
2941 struct net_device *bond_dev = slave->bond->dev;
2942 struct net_device *slave_dev = slave->dev;
2945 slave_dbg(bond_dev, slave_dev, "arp %d on slave: dst %pI4 src %pI4\n",
2956 if (bond_handle_vlan(slave, tags, skb)) {
2957 slave_update_last_tx(slave);
3004 static void bond_arp_send_all(struct bonding *bond, struct slave *slave)
3012 slave_dbg(bond->dev, slave->dev, "%s: target %pI4\n",
3027 bond_arp_send(slave, ARPOP_REQUEST, targets[i],
3044 slave_dbg(bond->dev, slave->dev, "no path to arp_ip_target %pI4 via rt.dev %s\n",
3053 bond_arp_send(slave, ARPOP_REQUEST, targets[i], addr, tags);
3058 static void bond_validate_arp(struct bonding *bond, struct slave *slave, __be32 sip, __be32 tip)
3063 slave_dbg(bond->dev, slave->dev, "%s: sip %pI4 tip %pI4 not found\n",
3070 slave_dbg(bond->dev, slave->dev, "%s: sip %pI4 not found in targets\n",
3074 slave->last_rx = jiffies;
3075 slave->target_last_arp_rx[i] = jiffies;
3079 struct slave *slave)
3082 struct slave *curr_active_slave, *curr_arp_slave;
3111 slave_dbg(bond->dev, slave->dev, "%s: %s/%d av %d sv %d sip %pI4 tip %pI4\n",
3112 __func__, slave->dev->name, bond_slave_state(slave),
3113 bond->params.arp_validate, slave_do_arp_validate(bond, slave),
3121 * (a) the slave receiving the ARP is active (which includes the
3122 * current ARP slave, if any), or
3124 * (b) the receiving slave isn't active, but there is a currently
3125 * active slave and it received valid arp reply(s) after it became
3126 * the currently active slave, or
3128 * (c) there is an ARP slave that sent an ARP during the prior ARP
3129 * interval, and we receive an ARP reply on any slave. We accept
3131 * reply to a slave other than the sender of the ARP request.
3135 * slave through the L2 switch(es) to the receiving slave. Since
3142 if (bond_is_active_slave(slave))
3143 bond_validate_arp(bond, slave, sip, tip);
3147 bond_validate_arp(bond, slave, tip, sip);
3150 bond_validate_arp(bond, slave, sip, tip);
3159 static void bond_ns_send(struct slave *slave, const struct in6_addr *daddr,
3162 struct net_device *bond_dev = slave->bond->dev;
3163 struct net_device *slave_dev = slave->dev;
3167 slave_dbg(bond_dev, slave_dev, "NS on slave: dst %pI6c src %pI6c\n",
3177 if (bond_handle_vlan(slave, tags, skb)) {
3178 slave_update_last_tx(slave);
3183 static void bond_ns_send_all(struct bonding *bond, struct slave *slave)
3193 slave_dbg(bond->dev, slave->dev, "%s: target %pI6c\n",
3212 bond_ns_send(slave, &targets[i], &in6addr_any, tags);
3228 slave_dbg(bond->dev, slave->dev, "no path to ns_ip6_target %pI6c via dst->dev %s\n",
3236 bond_ns_send(slave, &targets[i], &saddr, tags);
3238 bond_ns_send(slave, &targets[i], &in6addr_any, tags);
3271 static void bond_validate_na(struct bonding *bond, struct slave *slave,
3284 slave_dbg(bond->dev, slave->dev, "%s: sip %pI6c tip %pI6c not found\n",
3291 slave_dbg(bond->dev, slave->dev, "%s: sip %pI6c not found in targets\n",
3295 slave->last_rx = jiffies;
3296 slave->target_last_arp_rx[i] = jiffies;
3300 struct slave *slave)
3302 struct slave *curr_active_slave, *curr_arp_slave;
3322 slave_dbg(bond->dev, slave->dev, "%s: %s/%d av %d sv %d sip %pI6c tip %pI6c\n",
3323 __func__, slave->dev->name, bond_slave_state(slave),
3324 bond->params.arp_validate, slave_do_arp_validate(bond, slave),
3333 if (bond_is_active_slave(slave))
3334 bond_validate_na(bond, slave, saddr, daddr);
3338 bond_validate_na(bond, slave, daddr, saddr);
3341 bond_validate_na(bond, slave, saddr, daddr);
3349 struct slave *slave)
3356 slave_dbg(bond->dev, slave->dev, "%s: skb->dev %s\n",
3360 if (!slave_do_arp_validate(bond, slave)) {
3366 slave->last_rx = jiffies;
3369 return bond_arp_rcv(skb, bond, slave);
3372 return bond_na_rcv(skb, bond, slave);
3379 static void bond_send_validate(struct bonding *bond, struct slave *slave)
3381 bond_arp_send_all(bond, slave);
3383 bond_ns_send_all(bond, slave);
3401 /* This function is called regularly to monitor each slave's link
3409 struct slave *slave, *oldcurrent;
3421 * the picture unless it is null. also, slave->last_link_up is not
3422 * needed here because we send an arp on each slave and give a slave
3427 bond_for_each_slave_rcu(bond, slave, iter) {
3428 unsigned long last_tx = slave_last_tx(slave);
3430 bond_propose_link_state(slave, BOND_LINK_NOCHANGE);
3432 if (slave->link != BOND_LINK_UP) {
3434 bond_time_in_interval(bond, slave->last_rx, 1)) {
3436 bond_propose_link_state(slave, BOND_LINK_UP);
3440 * mode. the window of a slave being up and
3445 slave_info(bond->dev, slave->dev, "link status definitely up\n");
3448 slave_info(bond->dev, slave->dev, "interface is now up\n");
3452 /* slave->link == BOND_LINK_UP */
3459 !bond_time_in_interval(bond, slave->last_rx, bond->params.missed_max)) {
3461 bond_propose_link_state(slave, BOND_LINK_DOWN);
3464 if (slave->link_failure_count < UINT_MAX)
3465 slave->link_failure_count++;
3467 slave_info(bond->dev, slave->dev, "interface is now down\n");
3469 if (slave == oldcurrent)
3481 if (bond_slave_is_up(slave))
3482 bond_send_validate(bond, slave);
3491 bond_for_each_slave(bond, slave, iter) {
3492 if (slave->link_new_state != BOND_LINK_NOCHANGE)
3493 slave->link = slave->link_new_state;
3517 * should take place for the slave. Returns 0 if no changes are found, >0
3526 struct slave *slave;
3529 bond_for_each_slave_rcu(bond, slave, iter) {
3530 bond_propose_link_state(slave, BOND_LINK_NOCHANGE);
3531 last_rx = slave_last_rx(bond, slave);
3533 if (slave->link != BOND_LINK_UP) {
3535 bond_propose_link_state(slave, BOND_LINK_UP);
3537 } else if (slave->link == BOND_LINK_BACK) {
3538 bond_propose_link_state(slave, BOND_LINK_FAIL);
3548 if (bond_time_in_interval(bond, slave->last_link_up, 2))
3551 /* Backup slave is down if:
3560 * gives each slave a chance to tx/rx traffic
3563 if (!bond_is_active_slave(slave) &&
3566 bond_propose_link_state(slave, BOND_LINK_DOWN);
3570 /* Active slave is down if:
3575 last_tx = slave_last_tx(slave);
3576 if (bond_is_active_slave(slave) &&
3579 bond_propose_link_state(slave, BOND_LINK_DOWN);
3597 struct slave *slave;
3599 bond_for_each_slave(bond, slave, iter) {
3600 switch (slave->link_new_state) {
3605 last_tx = slave_last_tx(slave);
3606 if (rtnl_dereference(bond->curr_active_slave) != slave ||
3609 struct slave *current_arp_slave;
3612 bond_set_slave_link_state(slave, BOND_LINK_UP,
3621 slave_info(bond->dev, slave->dev, "link status definitely up\n");
3624 slave == rtnl_dereference(bond->primary_slave) ||
3625 slave->prio > rtnl_dereference(bond->curr_active_slave)->prio)
3633 if (slave->link_failure_count < UINT_MAX)
3634 slave->link_failure_count++;
3636 bond_set_slave_link_state(slave, BOND_LINK_DOWN,
3638 bond_set_slave_inactive_flags(slave,
3641 slave_info(bond->dev, slave->dev, "link status definitely down, disabling slave\n");
3643 if (slave == rtnl_dereference(bond->curr_active_slave)) {
3651 bond_set_slave_link_state(slave, BOND_LINK_FAIL,
3653 bond_set_slave_inactive_flags(slave,
3656 /* A slave has just been enslaved and has become
3657 * the current active slave.
3664 slave_err(bond->dev, slave->dev,
3665 "impossible: link_new_state %d on slave\n",
3666 slave->link_new_state);
3686 struct slave *slave, *before = NULL, *new_slave = NULL,
3704 * backup slave from the current_arp_slave and make it the candidate
3714 bond_for_each_slave_rcu(bond, slave, iter) {
3715 if (!found && !before && bond_slave_is_up(slave))
3716 before = slave;
3718 if (found && !new_slave && bond_slave_is_up(slave))
3719 new_slave = slave;
3724 * one the current slave so it is still marked
3727 if (!bond_slave_is_up(slave) && slave->link == BOND_LINK_UP) {
3728 bond_set_slave_link_state(slave, BOND_LINK_DOWN,
3730 if (slave->link_failure_count < UINT_MAX)
3731 slave->link_failure_count++;
3733 bond_set_slave_inactive_flags(slave,
3736 slave_info(bond->dev, slave->dev, "backup interface is now down\n");
3738 if (slave == curr_arp_slave)
3756 bond_for_each_slave_rcu(bond, slave, iter) {
3757 if (slave->should_notify || slave->should_notify_link) {
3874 struct slave *slave = bond_slave_get_rtnl(slave_dev), *primary;
3880 * slave will be NULL
3882 if (!slave) {
3883 netdev_dbg(slave_dev, "%s called on NULL slave\n", __func__);
3887 bond_dev = slave->bond->dev;
3888 bond = slave->bond;
3903 * Getting invalid Speed/Duplex values here will put slave
3909 if (bond_update_speed_duplex(slave) &&
3911 if (slave->last_link_up)
3912 slave->link = BOND_LINK_FAIL;
3914 slave->link = BOND_LINK_DOWN;
3918 bond_3ad_adapter_speed_duplex_changed(slave);
3921 /* Refresh slave-array if applicable!
3923 * then these events will not cause the slave-array to be
3924 * refreshed. This will cause xmit to use a slave that is not
3940 * take over the slave's change_mtu
3951 if (slave == primary) {
3952 /* slave's name changed - he's no longer primary */
3955 /* we have a new primary slave */
3956 rcu_assign_pointer(bond->primary_slave, slave);
3961 netdev_info(bond->dev, "Primary slave changed to %s, reselecting active slave\n",
3977 call_netdevice_notifiers(event, slave->bond->dev);
3993 * locks for us to safely manipulate the slave devices (RTNL lock,
4270 struct slave *slave;
4278 /* reset slave->backup and slave->inactive */
4280 bond_for_each_slave(bond, slave, iter) {
4282 slave != rcu_access_pointer(bond->curr_active_slave)) {
4283 bond_set_slave_inactive_flags(slave,
4286 bond_set_slave_active_flags(slave,
4316 bond_for_each_slave(bond, slave, iter)
4317 dev_mc_add(slave->dev, lacpdu_mcast_addr);
4329 struct slave *slave;
4339 slave = rcu_dereference(bond->curr_active_slave);
4340 if (slave)
4341 bond_hw_addr_flush(bond_dev, slave->dev);
4346 bond_for_each_slave(bond, slave, iter)
4347 bond_hw_addr_flush(bond_dev, slave->dev);
4429 struct slave *slave;
4441 bond_for_each_slave_rcu(bond, slave, iter) {
4443 dev_get_stats(slave->dev, &temp);
4445 bond_fold_stats(stats, new, &slave->slave_stats);
4447 /* save off the slave stats for the next run */
4448 memcpy(&slave->slave_stats, new, sizeof(*new));
4609 struct slave *slave;
4613 slave = rcu_dereference(bond->curr_active_slave);
4614 if (slave) {
4615 dev_uc_sync(slave->dev, bond_dev);
4616 dev_mc_sync(slave->dev, bond_dev);
4619 bond_for_each_slave_rcu(bond, slave, iter) {
4620 dev_uc_sync_multiple(slave->dev, bond_dev);
4621 dev_mc_sync_multiple(slave->dev, bond_dev);
4632 struct slave *slave;
4636 slave = bond_first_slave_rcu(bond);
4637 if (!slave)
4639 slave_ops = slave->dev->netdev_ops;
4652 ret = slave_ops->ndo_neigh_setup(slave->dev, &parms);
4665 * slave exists. So we must declare proxy setup function which will
4666 * be used at run time to resolve the actual slave neigh param setup.
4686 struct slave *slave, *rollback_slave;
4692 bond_for_each_slave(bond, slave, iter) {
4693 slave_dbg(bond_dev, slave->dev, "s %p c_m %p\n",
4694 slave, slave->dev->netdev_ops->ndo_change_mtu);
4696 res = dev_set_mtu(slave->dev, new_mtu);
4699 /* If we failed to set the slave's mtu to the new value
4702 * different mtu values than the active slave we'll
4707 slave_dbg(bond_dev, slave->dev, "err %d setting mtu to %d\n",
4718 /* unwind from head to the slave that failed */
4722 if (rollback_slave == slave)
4743 struct slave *slave, *rollback_slave;
4764 bond_for_each_slave(bond, slave, iter) {
4765 slave_dbg(bond_dev, slave->dev, "%s: slave=%p\n",
4766 __func__, slave);
4767 res = dev_set_mac_address(slave->dev, addr, NULL);
4769 /* TODO: consider downing the slave
4775 slave_dbg(bond_dev, slave->dev, "%s: err %d\n",
4789 /* unwind from head to the slave that failed */
4793 if (rollback_slave == slave)
4808 * bond_get_slave_by_id - get xmit slave with slave_id
4810 * @slave_id: slave id up to slave_cnt-1 through which to transmit
4812 * This function tries to get slave with slave_id but in case
4813 * it fails, it tries to find the first available slave for transmission.
4815 static struct slave *bond_get_slave_by_id(struct bonding *bond,
4819 struct slave *slave;
4822 /* Here we start from the slave with slave_id */
4823 bond_for_each_slave_rcu(bond, slave, iter) {
4825 if (bond_slave_can_tx(slave))
4826 return slave;
4830 /* Here we start from the first slave up to slave_id */
4832 bond_for_each_slave_rcu(bond, slave, iter) {
4835 if (bond_slave_can_tx(slave))
4836 return slave;
4838 /* no slave that can tx has been found */
4843 * bond_rr_gen_slave_id - generate slave id based on packets_per_slave
4847 * this function generates a slave id, which is usually used as the next
4848 * slave to transmit through.
4875 static struct slave *bond_xmit_roundrobin_slave_get(struct bonding *bond,
4878 struct slave *slave;
4897 slave = rcu_dereference(bond->curr_active_slave);
4898 if (slave)
4899 return slave;
4913 static struct slave *bond_xdp_xmit_roundrobin_slave_get(struct bonding *bond,
4916 struct slave *slave;
4938 slave = rcu_dereference(bond->curr_active_slave);
4939 if (slave)
4940 return slave;
4958 struct slave *slave;
4960 slave = bond_xmit_roundrobin_slave_get(bond, skb);
4961 if (likely(slave))
4962 return bond_dev_queue_xmit(bond, skb, slave->dev);
4967 static struct slave *bond_xmit_activebackup_slave_get(struct bonding *bond)
4979 struct slave *slave;
4981 slave = bond_xmit_activebackup_slave_get(bond);
4982 if (slave)
4983 return bond_dev_queue_xmit(bond, skb, slave->dev);
5010 pr_warn_ratelimited("Failed to update slave array from WT\n");
5020 struct slave *skipslave)
5025 * slave but allocation failed (most likely!). BTW this is
5030 * this to-be-skipped slave to send a packet out.
5063 * to determine the slave interface -
5070 int bond_update_slave_arr(struct bonding *bond, struct slave *skipslave)
5073 struct slave *slave;
5104 bond_for_each_slave(bond, slave, iter) {
5105 if (skipslave == slave)
5108 all_slaves->arr[all_slaves->count++] = slave;
5112 agg = SLAVE_AD_INFO(slave)->port.aggregator;
5116 if (!bond_slave_can_tx(slave))
5119 slave_dbg(bond->dev, slave->dev, "Adding slave to tx hash array[%d]\n",
5122 usable_slaves->arr[usable_slaves->count++] = slave;
5140 static struct slave *bond_xmit_3ad_xor_slave_get(struct bonding *bond,
5144 struct slave *slave;
5153 slave = slaves->arr[hash % count];
5154 return slave;
5157 static struct slave *bond_xdp_xmit_3ad_xor_slave_get(struct bonding *bond,
5174 * usable slave array is formed in the control path. The xmit function
5182 struct slave *slave;
5185 slave = bond_xmit_3ad_xor_slave_get(bond, skb, slaves);
5186 if (likely(slave))
5187 return bond_dev_queue_xmit(bond, skb, slave->dev);
5197 struct slave *slave = NULL;
5202 bond_for_each_slave_rcu(bond, slave, iter) {
5205 if (!(bond_slave_is_up(slave) && slave->link == BOND_LINK_UP))
5208 if (bond_is_last_slave(bond, slave)) {
5220 if (bond_dev_queue_xmit(bond, skb2, slave->dev) == NETDEV_TX_OK)
5236 /* Lookup the slave that corresponds to a qid */
5240 struct slave *slave = NULL;
5247 bond_for_each_slave_rcu(bond, slave, iter) {
5248 if (slave->queue_id == skb_get_queue_mapping(skb)) {
5249 if (bond_slave_is_up(slave) &&
5250 slave->link == BOND_LINK_UP) {
5251 bond_dev_queue_xmit(bond, skb, slave->dev);
5254 /* If the slave isn't UP, use default transmit policy. */
5290 struct slave *slave = NULL;
5294 slave = bond_xmit_roundrobin_slave_get(bond, skb);
5297 slave = bond_xmit_activebackup_slave_get(bond);
5305 slave = bond_xmit_3ad_xor_slave_get(bond, skb, slaves);
5310 slave = bond_xmit_alb_slave_get(bond, skb);
5313 slave = bond_xmit_tlb_slave_get(bond, skb);
5321 if (slave)
5322 return slave->dev;
5376 struct slave *slave;
5386 slave = slaves->arr[hash % count];
5388 return slave->dev;
5481 struct slave *slave;
5487 slave = bond_xdp_xmit_roundrobin_slave_get(bond, xdp);
5491 slave = bond_xmit_activebackup_slave_get(bond);
5496 slave = bond_xdp_xmit_3ad_xor_slave_get(bond, xdp);
5506 if (slave)
5507 return slave->dev;
5554 struct slave *slave, *rollback_slave;
5572 bond_for_each_slave(bond, slave, iter) {
5573 struct net_device *slave_dev = slave->dev;
5619 if (slave == rollback_slave)
5642 static u32 bond_mode_bcast_speed(struct slave *slave, u32 speed)
5645 speed = slave->speed;
5647 speed = min(speed, slave->speed);
5718 struct slave *slave;
5729 bond_for_each_slave(bond, slave, iter) {
5730 if (bond_slave_can_tx(slave)) {
5731 bond_update_speed_duplex(slave);
5732 if (slave->speed != SPEED_UNKNOWN) {
5734 speed = bond_mode_bcast_speed(slave,
5737 speed += slave->speed;
5740 slave->duplex != DUPLEX_UNKNOWN)
5741 cmd->base.duplex = slave->duplex;
5765 struct slave *slave;
5778 bond_for_each_slave_rcu(bond, slave, iter) {
5779 ret = ethtool_get_ts_info_by_layer(slave->dev, &ts_info);
5925 struct slave *slave;
5930 bond_for_each_slave(bond, slave, iter)
5931 __bond_release_one(bond_dev, slave->dev, true, true);