Lines Matching refs:bond
258 static bool bond_time_in_interval(struct bonding *bond, unsigned long last_act,
285 * @bond: bond device that got this skb for tx.
289 netdev_tx_t bond_dev_queue_xmit(struct bonding *bond, struct sk_buff *skb,
298 if (unlikely(netpoll_tx_running(bond->dev)))
299 return bond_netpoll_send_skb(bond_get_slave_by_dev(bond, slave_dev), skb);
331 struct bonding *bond = netdev_priv(bond_dev);
336 bond_for_each_slave(bond, slave, iter) {
346 bond_for_each_slave(bond, rollback_slave, iter) {
365 struct bonding *bond = netdev_priv(bond_dev);
369 bond_for_each_slave(bond, slave, iter)
372 if (bond_is_lb(bond))
373 bond_alb_clear_vlan(bond, vid);
389 struct bonding *bond;
397 bond = netdev_priv(bond_dev);
398 slave = rcu_dereference(bond->curr_active_slave);
423 spin_lock_bh(&bond->ipsec_lock);
424 list_add(&ipsec->list, &bond->ipsec_list);
425 spin_unlock_bh(&bond->ipsec_lock);
433 static void bond_ipsec_add_sa_all(struct bonding *bond)
435 struct net_device *bond_dev = bond->dev;
440 slave = rcu_dereference(bond->curr_active_slave);
447 spin_lock_bh(&bond->ipsec_lock);
448 if (!list_empty(&bond->ipsec_list))
452 spin_unlock_bh(&bond->ipsec_lock);
456 spin_lock_bh(&bond->ipsec_lock);
457 list_for_each_entry(ipsec, &bond->ipsec_list, list) {
464 spin_unlock_bh(&bond->ipsec_lock);
477 struct bonding *bond;
484 bond = netdev_priv(bond_dev);
485 slave = rcu_dereference(bond->curr_active_slave);
504 spin_lock_bh(&bond->ipsec_lock);
505 list_for_each_entry(ipsec, &bond->ipsec_list, list) {
512 spin_unlock_bh(&bond->ipsec_lock);
516 static void bond_ipsec_del_sa_all(struct bonding *bond)
518 struct net_device *bond_dev = bond->dev;
523 slave = rcu_dereference(bond->curr_active_slave);
529 spin_lock_bh(&bond->ipsec_lock);
530 list_for_each_entry(ipsec, &bond->ipsec_list, list) {
544 spin_unlock_bh(&bond->ipsec_lock);
558 struct bonding *bond;
561 bond = netdev_priv(bond_dev);
563 curr_active = rcu_dereference(bond->curr_active_slave);
568 if (BOND_MODE(bond) != BOND_MODE_ACTIVEBACKUP) {
606 int bond_set_carrier(struct bonding *bond)
611 if (!bond_has_slaves(bond))
614 if (BOND_MODE(bond) == BOND_MODE_8023AD)
615 return bond_3ad_set_carrier(bond);
617 bond_for_each_slave(bond, slave, iter) {
619 if (!netif_carrier_ok(bond->dev)) {
620 netif_carrier_on(bond->dev);
628 if (netif_carrier_ok(bond->dev)) {
629 netif_carrier_off(bond->dev);
700 static int bond_check_dev_link(struct bonding *bond,
711 if (bond->params.use_carrier)
755 static int bond_set_promiscuity(struct bonding *bond, int inc)
760 if (bond_uses_primary(bond)) {
761 struct slave *curr_active = rtnl_dereference(bond->curr_active_slave);
768 bond_for_each_slave(bond, slave, iter) {
778 static int bond_set_allmulti(struct bonding *bond, int inc)
783 if (bond_uses_primary(bond)) {
784 struct slave *curr_active = rtnl_dereference(bond->curr_active_slave);
791 bond_for_each_slave(bond, slave, iter) {
806 struct bonding *bond = container_of(work, struct bonding,
810 queue_delayed_work(bond->wq, &bond->mcast_work, 1);
813 call_netdevice_notifiers(NETDEV_RESEND_IGMP, bond->dev);
815 if (bond->igmp_retrans > 1) {
816 bond->igmp_retrans--;
817 queue_delayed_work(bond->wq, &bond->mcast_work, HZ/5);
822 /* Flush bond's hardware addresses from slave */
826 struct bonding *bond = netdev_priv(bond_dev);
831 if (BOND_MODE(bond) == BOND_MODE_8023AD)
842 static void bond_hw_addr_swap(struct bonding *bond, struct slave *new_active,
846 if (bond->dev->flags & IFF_PROMISC)
849 if (bond->dev->flags & IFF_ALLMULTI)
852 if (bond->dev->flags & IFF_UP)
853 bond_hw_addr_flush(bond->dev, old_active->dev);
858 if (bond->dev->flags & IFF_PROMISC)
861 if (bond->dev->flags & IFF_ALLMULTI)
864 if (bond->dev->flags & IFF_UP) {
865 netif_addr_lock_bh(bond->dev);
866 dev_uc_sync(new_active->dev, bond->dev);
867 dev_mc_sync(new_active->dev, bond->dev);
868 netif_addr_unlock_bh(bond->dev);
874 * bond_set_dev_addr - clone slave's address to bond
875 * @bond_dev: bond net device
897 static struct slave *bond_get_old_active(struct bonding *bond,
903 bond_for_each_slave(bond, slave, iter) {
907 if (ether_addr_equal(bond->dev->dev_addr, slave->dev->dev_addr))
920 static void bond_do_fail_over_mac(struct bonding *bond,
928 switch (bond->params.fail_over_mac) {
931 rv = bond_set_dev_addr(bond->dev, new_active->dev);
933 slave_err(bond->dev, new_active->dev, "Error %d setting bond MAC from slave\n",
940 * if just new_active, set new_active to bond's MAC
946 old_active = bond_get_old_active(bond, new_active);
956 bond_hw_addr_copy(ss.__data, bond->dev->dev_addr,
957 bond->dev->addr_len);
958 ss.ss_family = bond->dev->type;
964 slave_err(bond->dev, new_active->dev, "Error %d setting MAC of new active slave\n",
979 slave_err(bond->dev, old_active->dev, "Error %d setting MAC of old active slave\n",
984 netdev_err(bond->dev, "bond_do_fail_over_mac impossible: bad policy %d\n",
985 bond->params.fail_over_mac);
991 static struct slave *bond_choose_primary_or_current(struct bonding *bond)
993 struct slave *prim = rtnl_dereference(bond->primary_slave);
994 struct slave *curr = rtnl_dereference(bond->curr_active_slave);
1002 if (bond->force_primary) {
1003 bond->force_primary = false;
1011 switch (bond->params.primary_reselect) {
1023 netdev_err(bond->dev, "impossible primary_reselect %d\n",
1024 bond->params.primary_reselect);
1031 * @bond: our bonding struct
1033 static struct slave *bond_find_best_slave(struct bonding *bond)
1037 int mintime = bond->params.updelay;
1039 slave = bond_choose_primary_or_current(bond);
1043 bond_for_each_slave(bond, slave, iter) {
1056 static bool bond_should_notify_peers(struct bonding *bond)
1061 slave = rcu_dereference(bond->curr_active_slave);
1064 if (!slave || !bond->send_peer_notif ||
1065 bond->send_peer_notif %
1066 max(1, bond->params.peer_notif_delay) != 0 ||
1067 !netif_carrier_ok(bond->dev) ||
1071 netdev_dbg(bond->dev, "bond_should_notify_peers: slave %s\n",
1079 * @bond: our bonding struct
1082 * Set the new slave to the bond's settings and unset them on the old
1092 void bond_change_active_slave(struct bonding *bond, struct slave *new_active)
1098 old_active = rtnl_dereference(bond->curr_active_slave);
1104 bond_ipsec_del_sa_all(bond);
1111 if (bond_uses_primary(bond)) {
1112 slave_info(bond->dev, new_active->dev, "making interface the new active one %d ms earlier\n",
1113 (bond->params.updelay - new_active->delay) * bond->params.miimon);
1120 if (BOND_MODE(bond) == BOND_MODE_8023AD)
1123 if (bond_is_lb(bond))
1124 bond_alb_handle_link_change(bond, new_active, BOND_LINK_UP);
1126 if (bond_uses_primary(bond)) {
1127 slave_info(bond->dev, new_active->dev, "making interface the new active one\n");
1132 if (bond_uses_primary(bond))
1133 bond_hw_addr_swap(bond, new_active, old_active);
1135 if (bond_is_lb(bond)) {
1136 bond_alb_handle_active_change(bond, new_active);
1144 rcu_assign_pointer(bond->curr_active_slave, new_active);
1147 if (BOND_MODE(bond) == BOND_MODE_ACTIVEBACKUP) {
1158 if (bond->params.fail_over_mac)
1159 bond_do_fail_over_mac(bond, new_active,
1162 if (netif_running(bond->dev)) {
1163 bond->send_peer_notif =
1164 bond->params.num_peer_notif *
1165 max(1, bond->params.peer_notif_delay);
1167 bond_should_notify_peers(bond);
1170 call_netdevice_notifiers(NETDEV_BONDING_FAILOVER, bond->dev);
1172 bond->send_peer_notif--;
1174 bond->dev);
1180 bond_ipsec_add_sa_all(bond);
1185 * resend only if bond is brought up with the affected
1188 if (netif_running(bond->dev) && (bond->params.resend_igmp > 0) &&
1189 ((bond_uses_primary(bond) && new_active) ||
1190 BOND_MODE(bond) == BOND_MODE_ROUNDROBIN)) {
1191 bond->igmp_retrans = bond->params.resend_igmp;
1192 queue_delayed_work(bond->wq, &bond->mcast_work, 1);
1198 * @bond: our bonding struct
1207 void bond_select_active_slave(struct bonding *bond)
1214 best_slave = bond_find_best_slave(bond);
1215 if (best_slave != rtnl_dereference(bond->curr_active_slave)) {
1216 bond_change_active_slave(bond, best_slave);
1217 rv = bond_set_carrier(bond);
1221 if (netif_carrier_ok(bond->dev))
1222 netdev_info(bond->dev, "active interface up!\n");
1224 netdev_info(bond->dev, "now running without any active interface!\n");
1262 struct bonding *bond = netdev_priv(bond_dev);
1267 if (BOND_MODE(bond) == BOND_MODE_8023AD)
1268 if (bond_3ad_get_active_agg_info(bond, &ad_info))
1271 bond_for_each_slave_rcu(bond, slave, iter) {
1275 if (BOND_MODE(bond) == BOND_MODE_8023AD) {
1290 struct bonding *bond = netdev_priv(bond_dev);
1294 bond_for_each_slave(bond, slave, iter)
1301 struct bonding *bond = netdev_priv(dev);
1306 bond_for_each_slave(bond, slave, iter) {
1333 struct bonding *bond = netdev_priv(dev);
1343 bond_for_each_slave(bond, slave, iter) {
1364 static void bond_compute_features(struct bonding *bond)
1374 struct net_device *bond_dev = bond->dev;
1381 if (!bond_has_slaves(bond))
1386 bond_for_each_slave(bond, slave, iter) {
1464 struct bonding *bond)
1467 if (BOND_MODE(bond) == BOND_MODE_ALB &&
1480 struct bonding *bond;
1492 bond = slave->bond;
1494 recv_probe = READ_ONCE(bond->recv_probe);
1496 ret = recv_probe(skb, bond, slave);
1514 if (bond_should_deliver_exact_match(skb, slave, bond)) {
1520 skb->dev = bond->dev;
1522 if (BOND_MODE(bond) == BOND_MODE_ALB &&
1523 netif_is_bridge_port(bond->dev) &&
1531 bond_hw_addr_copy(eth_hdr(skb)->h_dest, bond->dev->dev_addr,
1532 bond->dev->addr_len);
1538 static enum netdev_lag_tx_type bond_lag_tx_type(struct bonding *bond)
1540 switch (BOND_MODE(bond)) {
1555 static enum netdev_lag_hash bond_lag_hash_type(struct bonding *bond,
1561 switch (bond->params.xmit_policy) {
1577 static int bond_master_upper_dev_link(struct bonding *bond, struct slave *slave,
1583 type = bond_lag_tx_type(bond);
1585 lag_upper_info.hash_type = bond_lag_hash_type(bond, type);
1587 return netdev_master_upper_dev_link(slave->dev, bond->dev, slave,
1591 static void bond_upper_dev_unlink(struct bonding *bond, struct slave *slave)
1593 netdev_upper_dev_unlink(slave->dev, bond->dev);
1600 struct bonding *bond = bond_get_bond_by_slave(slave);
1603 if (BOND_MODE(bond) == BOND_MODE_8023AD)
1628 static struct slave *bond_alloc_slave(struct bonding *bond,
1637 slave->bond = bond;
1644 if (BOND_MODE(bond) == BOND_MODE_8023AD) {
1656 static void bond_fill_ifbond(struct bonding *bond, struct ifbond *info)
1658 info->bond_mode = BOND_MODE(bond);
1659 info->miimon = bond->params.miimon;
1660 info->num_slaves = bond->slave_cnt;
1680 bond_fill_ifbond(slave->bond, &binfo.master);
1684 queue_delayed_work(slave->bond->wq, &slave->notify_work, 1);
1690 queue_delayed_work(slave->bond->wq, &slave->notify_work, 0);
1703 /* enslave device <slave> to bond device <master> */
1707 struct bonding *bond = netdev_priv(bond_dev);
1714 if (!bond->params.use_carrier &&
1729 NL_SET_ERR_MSG(extack, "Cannot enslave bond to itself.");
1730 netdev_err(bond_dev, "cannot enslave bond to itself.\n");
1739 NL_SET_ERR_MSG(extack, "Can not enslave VLAN challenged device to VLAN enabled bond");
1740 slave_err(bond_dev, slave_dev, "Error: cannot enslave VLAN challenged slave on VLAN enabled bond\n");
1743 slave_warn(bond_dev, slave_dev, "enslaved VLAN challenged slave. Adding VLANs will be blocked as long as it is part of bond.\n");
1767 * bond ether type mutual exclusion - don't allow slaves of dissimilar
1768 * ether type (eg ARPHRD_ETHER and ARPHRD_INFINIBAND) share the same bond
1770 if (!bond_has_slaves(bond)) {
1805 BOND_MODE(bond) != BOND_MODE_ACTIVEBACKUP) {
1816 if (BOND_MODE(bond) == BOND_MODE_ACTIVEBACKUP &&
1817 bond->params.fail_over_mac != BOND_FOM_ACTIVE) {
1818 if (!bond_has_slaves(bond)) {
1819 bond->params.fail_over_mac = BOND_FOM_ACTIVE;
1835 if (!bond_has_slaves(bond) &&
1836 bond->dev->addr_assign_type == NET_ADDR_RANDOM) {
1837 res = bond_set_dev_addr(bond->dev, slave_dev);
1842 new_slave = bond_alloc_slave(bond, slave_dev);
1853 /* Save slave's original mtu and then set it to match the bond */
1855 res = dev_set_mtu(slave_dev, bond->dev->mtu);
1868 if (!bond->params.fail_over_mac ||
1869 BOND_MODE(bond) != BOND_MODE_ACTIVEBACKUP) {
1897 if (bond_is_lb(bond)) {
1901 res = bond_alb_init_slave(bond, new_slave);
1908 slave_err(bond_dev, slave_dev, "Couldn't add bond vlan ids\n");
1912 prev_slave = bond_last_slave(bond);
1918 bond_needs_speed_duplex(bond))
1922 (msecs_to_jiffies(bond->params.arp_interval) + 1);
1926 if (bond->params.miimon && !bond->params.use_carrier) {
1927 link_reporting = bond_check_dev_link(bond, slave_dev, 1);
1929 if ((link_reporting == -1) && !bond->params.arp_interval) {
1947 if (bond->params.miimon) {
1948 if (bond_check_dev_link(bond, slave_dev, 0) == BMSR_LSTATUS) {
1949 if (bond->params.updelay) {
1953 new_slave->delay = bond->params.updelay;
1963 } else if (bond->params.arp_interval) {
1979 if (bond_uses_primary(bond) && bond->params.primary[0]) {
1981 if (strcmp(bond->params.primary, new_slave->dev->name) == 0) {
1982 rcu_assign_pointer(bond->primary_slave, new_slave);
1983 bond->force_primary = true;
1987 switch (BOND_MODE(bond)) {
2002 * can be called only after the mac address of the bond is set
2004 bond_3ad_initialize(bond, 1000/AD_TIMER_INTERVAL);
2024 * anyway (it holds no special properties of the bond device),
2027 if (!rcu_access_pointer(bond->curr_active_slave) &&
2029 rcu_assign_pointer(bond->curr_active_slave, new_slave);
2035 if (bond->dev->npinfo) {
2054 res = bond_master_upper_dev_link(bond, new_slave, extack);
2069 if (!bond_uses_primary(bond)) {
2093 if (BOND_MODE(bond) == BOND_MODE_8023AD)
2098 bond->slave_cnt++;
2099 bond_compute_features(bond);
2100 bond_set_carrier(bond);
2102 if (bond_uses_primary(bond)) {
2104 bond_select_active_slave(bond);
2108 if (bond_mode_can_use_xmit_hash(bond))
2109 bond_update_slave_arr(bond, NULL);
2125 bond_upper_dev_unlink(bond, new_slave);
2132 if (rcu_access_pointer(bond->primary_slave) == new_slave)
2133 RCU_INIT_POINTER(bond->primary_slave, NULL);
2134 if (rcu_access_pointer(bond->curr_active_slave) == new_slave) {
2136 bond_change_active_slave(bond, NULL);
2137 bond_select_active_slave(bond);
2151 if (!bond->params.fail_over_mac ||
2152 BOND_MODE(bond) != BOND_MODE_ACTIVEBACKUP) {
2154 * MAC if this slave's MAC is in use by the bond, or at
2171 if (!bond_has_slaves(bond)) {
2186 /* Try to release the slave device <slave> from the bond device <master>
2189 * while destroying a bond interface and all slaves are being released.
2201 struct bonding *bond = netdev_priv(bond_dev);
2216 slave = bond_get_slave_by_dev(bond, slave_dev);
2218 /* not a slave of this bond */
2229 bond_get_stats(bond->dev, &bond->bond_stats);
2236 if (BOND_MODE(bond) == BOND_MODE_8023AD)
2239 bond_upper_dev_unlink(bond, slave);
2241 if (bond_mode_can_use_xmit_hash(bond))
2242 bond_update_slave_arr(bond, slave);
2247 oldcurrent = rcu_access_pointer(bond->curr_active_slave);
2249 RCU_INIT_POINTER(bond->current_arp_slave, NULL);
2251 if (!all && (!bond->params.fail_over_mac ||
2252 BOND_MODE(bond) != BOND_MODE_ACTIVEBACKUP)) {
2254 bond_has_slaves(bond))
2255 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",
2259 if (rtnl_dereference(bond->primary_slave) == slave)
2260 RCU_INIT_POINTER(bond->primary_slave, NULL);
2263 bond_change_active_slave(bond, NULL);
2265 if (bond_is_lb(bond)) {
2271 bond_alb_deinit_slave(bond, slave);
2275 RCU_INIT_POINTER(bond->curr_active_slave, NULL);
2281 bond_select_active_slave(bond);
2284 bond_set_carrier(bond);
2285 if (!bond_has_slaves(bond))
2290 bond->slave_cnt--;
2292 if (!bond_has_slaves(bond)) {
2293 call_netdevice_notifiers(NETDEV_CHANGEADDR, bond->dev);
2294 call_netdevice_notifiers(NETDEV_RELEASE, bond->dev);
2297 bond_compute_features(bond);
2300 slave_info(bond_dev, slave_dev, "last VLAN challenged slave left bond - VLAN blocking is removed\n");
2307 if (!bond_uses_primary(bond)) {
2331 if (bond->params.fail_over_mac != BOND_FOM_ACTIVE ||
2332 BOND_MODE(bond) != BOND_MODE_ACTIVEBACKUP) {
2359 /* First release a slave and then destroy the bond if no more slaves are left.
2365 struct bonding *bond = netdev_priv(bond_dev);
2369 if (ret == 0 && !bond_has_slaves(bond) &&
2372 netdev_info(bond_dev, "Destroying bond\n");
2373 bond_remove_proc_entry(bond);
2381 struct bonding *bond = netdev_priv(bond_dev);
2382 bond_fill_ifbond(bond, info);
2387 struct bonding *bond = netdev_priv(bond_dev);
2392 bond_for_each_slave(bond, slave, iter) {
2406 static int bond_miimon_inspect(struct bonding *bond)
2413 if (BOND_MODE(bond) == BOND_MODE_ACTIVEBACKUP) {
2414 ignore_updelay = !rcu_dereference(bond->curr_active_slave);
2418 usable_slaves = rcu_dereference(bond->usable_slaves);
2424 bond_for_each_slave_rcu(bond, slave, iter) {
2427 link_state = bond_check_dev_link(bond, slave->dev, 0);
2436 slave->delay = bond->params.downdelay;
2438 slave_info(bond->dev, slave->dev, "link status down for %sinterface, disabling it in %d ms\n",
2439 (BOND_MODE(bond) ==
2443 bond->params.downdelay * bond->params.miimon);
2451 slave_info(bond->dev, slave->dev, "link status up again after %d ms\n",
2452 (bond->params.downdelay - slave->delay) *
2453 bond->params.miimon);
2473 slave->delay = bond->params.updelay;
2476 slave_info(bond->dev, slave->dev, "link status up, enabling it in %d ms\n",
2478 bond->params.updelay *
2479 bond->params.miimon);
2485 slave_info(bond->dev, slave->dev, "link status down again after %d ms\n",
2486 (bond->params.updelay - slave->delay) *
2487 bond->params.miimon);
2510 static void bond_miimon_link_change(struct bonding *bond,
2514 switch (BOND_MODE(bond)) {
2520 bond_alb_handle_link_change(bond, slave, link);
2523 bond_update_slave_arr(bond, NULL);
2528 static void bond_miimon_commit(struct bonding *bond)
2533 bond_for_each_slave(bond, slave, iter) {
2542 if (BOND_MODE(bond) == BOND_MODE_8023AD &&
2549 bond_needs_speed_duplex(bond)) {
2552 slave_warn(bond->dev, slave->dev,
2560 primary = rtnl_dereference(bond->primary_slave);
2561 if (BOND_MODE(bond) == BOND_MODE_8023AD) {
2564 } else if (BOND_MODE(bond) != BOND_MODE_ACTIVEBACKUP) {
2569 slave_info(bond->dev, slave->dev, "link status definitely up, %u Mbps %s duplex\n",
2573 bond_miimon_link_change(bond, slave, BOND_LINK_UP);
2575 if (!bond->curr_active_slave || slave == primary)
2587 if (BOND_MODE(bond) == BOND_MODE_ACTIVEBACKUP ||
2588 BOND_MODE(bond) == BOND_MODE_8023AD)
2592 slave_info(bond->dev, slave->dev, "link status definitely down, disabling slave\n");
2594 bond_miimon_link_change(bond, slave, BOND_LINK_DOWN);
2596 if (slave == rcu_access_pointer(bond->curr_active_slave))
2602 slave_err(bond->dev, slave->dev, "invalid new link %d on slave\n",
2611 bond_select_active_slave(bond);
2615 bond_set_carrier(bond);
2627 struct bonding *bond = container_of(work, struct bonding,
2635 delay = msecs_to_jiffies(bond->params.miimon);
2637 if (!bond_has_slaves(bond))
2641 should_notify_peers = bond_should_notify_peers(bond);
2642 commit = !!bond_miimon_inspect(bond);
2643 if (bond->send_peer_notif) {
2646 bond->send_peer_notif--;
2661 bond_for_each_slave(bond, slave, iter) {
2664 bond_miimon_commit(bond);
2670 if (bond->params.miimon)
2671 queue_delayed_work(bond->wq, &bond->mii_work, delay);
2676 call_netdevice_notifiers(NETDEV_NOTIFY_PEERS, bond->dev);
2689 static bool bond_has_this_ip(struct bonding *bond, __be32 ip)
2696 if (ip == bond_confirm_addr(bond->dev, 0, ip))
2700 if (netdev_walk_all_upper_dev_rcu(bond->dev, bond_upper_dev_walk, &priv))
2717 struct net_device *bond_dev = slave->bond->dev;
2805 static void bond_arp_send_all(struct bonding *bond, struct slave *slave)
2809 __be32 *targets = bond->params.arp_targets, addr;
2813 slave_dbg(bond->dev, slave->dev, "%s: target %pI4\n",
2818 rt = ip_route_output(dev_net(bond->dev), targets[i], 0,
2824 if (bond->params.arp_validate)
2826 bond->dev->name,
2833 /* bond device itself */
2834 if (rt->dst.dev == bond->dev)
2838 tags = bond_verify_device_path(bond->dev, rt->dst.dev, 0);
2845 slave_dbg(bond->dev, slave->dev, "no path to arp_ip_target %pI4 via rt.dev %s\n",
2859 static void bond_validate_arp(struct bonding *bond, struct slave *slave, __be32 sip, __be32 tip)
2863 if (!sip || !bond_has_this_ip(bond, tip)) {
2864 slave_dbg(bond->dev, slave->dev, "%s: sip %pI4 tip %pI4 not found\n",
2869 i = bond_get_targets_ip(bond->params.arp_targets, sip);
2871 slave_dbg(bond->dev, slave->dev, "%s: sip %pI4 not found in targets\n",
2879 int bond_arp_rcv(const struct sk_buff *skb, struct bonding *bond,
2889 if (!slave_do_arp_validate(bond, slave)) {
2890 if ((slave_do_arp_validate_only(bond) && is_arp) ||
2891 !slave_do_arp_validate_only(bond))
2898 alen = arp_hdr_len(bond->dev);
2900 slave_dbg(bond->dev, slave->dev, "%s: skb->dev %s\n",
2911 if (arp->ar_hln != bond->dev->addr_len ||
2920 arp_ptr += bond->dev->addr_len;
2922 arp_ptr += 4 + bond->dev->addr_len;
2925 slave_dbg(bond->dev, slave->dev, "%s: %s/%d av %d sv %d sip %pI4 tip %pI4\n",
2927 bond->params.arp_validate, slave_do_arp_validate(bond, slave),
2930 curr_active_slave = rcu_dereference(bond->curr_active_slave);
2931 curr_arp_slave = rcu_dereference(bond->current_arp_slave);
2957 bond_validate_arp(bond, slave, sip, tip);
2959 time_after(slave_last_rx(bond, curr_active_slave),
2961 bond_validate_arp(bond, slave, tip, sip);
2963 bond_time_in_interval(bond,
2965 bond_validate_arp(bond, slave, sip, tip);
2977 static bool bond_time_in_interval(struct bonding *bond, unsigned long last_act,
2980 int delta_in_ticks = msecs_to_jiffies(bond->params.arp_interval);
2993 static void bond_loadbalance_arp_mon(struct bonding *bond)
2999 if (!bond_has_slaves(bond))
3004 oldcurrent = rcu_dereference(bond->curr_active_slave);
3013 bond_for_each_slave_rcu(bond, slave, iter) {
3019 if (bond_time_in_interval(bond, trans_start, 1) &&
3020 bond_time_in_interval(bond, slave->last_rx, 1)) {
3031 slave_info(bond->dev, slave->dev, "link status definitely up\n");
3034 slave_info(bond->dev, slave->dev, "interface is now up\n");
3044 if (!bond_time_in_interval(bond, trans_start, 2) ||
3045 !bond_time_in_interval(bond, slave->last_rx, 2)) {
3053 slave_info(bond->dev, slave->dev, "interface is now down\n");
3068 bond_arp_send_all(bond, slave);
3077 bond_for_each_slave(bond, slave, iter) {
3083 bond_slave_state_change(bond);
3084 if (BOND_MODE(bond) == BOND_MODE_XOR)
3085 bond_update_slave_arr(bond, NULL);
3089 bond_select_active_slave(bond);
3096 if (bond->params.arp_interval)
3097 queue_delayed_work(bond->wq, &bond->arp_work,
3098 msecs_to_jiffies(bond->params.arp_interval));
3108 static int bond_ab_arp_inspect(struct bonding *bond)
3115 bond_for_each_slave_rcu(bond, slave, iter) {
3117 last_rx = slave_last_rx(bond, slave);
3120 if (bond_time_in_interval(bond, last_rx, 1)) {
3134 if (bond_time_in_interval(bond, slave->last_link_up, 2))
3140 * - the bond has an IP address
3150 !rcu_access_pointer(bond->current_arp_slave) &&
3151 !bond_time_in_interval(bond, last_rx, 3)) {
3159 * the bond has an IP address)
3163 (!bond_time_in_interval(bond, trans_start, 2) ||
3164 !bond_time_in_interval(bond, last_rx, 2))) {
3178 static void bond_ab_arp_commit(struct bonding *bond)
3184 bond_for_each_slave(bond, slave, iter) {
3191 if (rtnl_dereference(bond->curr_active_slave) != slave ||
3192 (!rtnl_dereference(bond->curr_active_slave) &&
3193 bond_time_in_interval(bond, trans_start, 1))) {
3196 current_arp_slave = rtnl_dereference(bond->current_arp_slave);
3203 RCU_INIT_POINTER(bond->current_arp_slave, NULL);
3206 slave_info(bond->dev, slave->dev, "link status definitely up\n");
3208 if (!rtnl_dereference(bond->curr_active_slave) ||
3209 slave == rtnl_dereference(bond->primary_slave))
3225 slave_info(bond->dev, slave->dev, "link status definitely down, disabling slave\n");
3227 if (slave == rtnl_dereference(bond->curr_active_slave)) {
3228 RCU_INIT_POINTER(bond->current_arp_slave, NULL);
3243 if (rtnl_dereference(bond->curr_active_slave))
3244 RCU_INIT_POINTER(bond->current_arp_slave, NULL);
3248 slave_err(bond->dev, slave->dev,
3256 bond_select_active_slave(bond);
3260 bond_set_carrier(bond);
3267 static bool bond_ab_arp_probe(struct bonding *bond)
3270 *curr_arp_slave = rcu_dereference(bond->current_arp_slave),
3271 *curr_active_slave = rcu_dereference(bond->curr_active_slave);
3277 netdev_info(bond->dev, "PROBE: c_arp %s && cas %s BAD\n",
3282 bond_arp_send_all(bond, curr_active_slave);
3292 curr_arp_slave = bond_first_slave_rcu(bond);
3297 bond_for_each_slave_rcu(bond, slave, iter) {
3319 slave_info(bond->dev, slave->dev, "backup interface is now down\n");
3334 bond_arp_send_all(bond, new_slave);
3336 rcu_assign_pointer(bond->current_arp_slave, new_slave);
3339 bond_for_each_slave_rcu(bond, slave, iter) {
3348 static void bond_activebackup_arp_mon(struct bonding *bond)
3354 delta_in_ticks = msecs_to_jiffies(bond->params.arp_interval);
3356 if (!bond_has_slaves(bond))
3361 should_notify_peers = bond_should_notify_peers(bond);
3363 if (bond_ab_arp_inspect(bond)) {
3373 bond_ab_arp_commit(bond);
3379 should_notify_rtnl = bond_ab_arp_probe(bond);
3383 if (bond->params.arp_interval)
3384 queue_delayed_work(bond->wq, &bond->arp_work, delta_in_ticks);
3391 bond->send_peer_notif--;
3393 bond->dev);
3396 bond_slave_state_notify(bond);
3397 bond_slave_link_notify(bond);
3406 struct bonding *bond = container_of(work, struct bonding,
3409 if (BOND_MODE(bond) == BOND_MODE_ACTIVEBACKUP)
3410 bond_activebackup_arp_mon(bond);
3412 bond_loadbalance_arp_mon(bond);
3418 static int bond_event_changename(struct bonding *bond)
3420 bond_remove_proc_entry(bond);
3421 bond_create_proc_entry(bond);
3423 bond_debug_reregister(bond);
3458 struct bonding *bond;
3470 bond_dev = slave->bond->dev;
3471 bond = slave->bond;
3472 primary = rtnl_dereference(bond->primary_slave);
3493 BOND_MODE(bond) == BOND_MODE_8023AD) {
3500 if (BOND_MODE(bond) == BOND_MODE_8023AD)
3512 if (bond_mode_can_use_xmit_hash(bond))
3513 bond_update_slave_arr(bond, NULL);
3518 * an active-backup bond, slaves need
3530 if (!bond_uses_primary(bond) ||
3531 !bond->params.primary[0])
3536 RCU_INIT_POINTER(bond->primary_slave, NULL);
3537 } else if (!strcmp(slave_dev->name, bond->params.primary)) {
3539 rcu_assign_pointer(bond->primary_slave, slave);
3544 netdev_info(bond->dev, "Primary slave changed to %s, reselecting active slave\n",
3548 bond_select_active_slave(bond);
3552 if (!bond->notifier_ctx) {
3553 bond->notifier_ctx = true;
3554 bond_compute_features(bond);
3555 bond->notifier_ctx = false;
3560 call_netdevice_notifiers(event, slave->bond->dev);
3649 /* Extract the appropriate headers based on bond's xmit policy */
3650 static bool bond_flow_dissect(struct bonding *bond, struct sk_buff *skb,
3653 bool l34 = bond->params.xmit_policy == BOND_XMIT_POLICY_LAYER34;
3656 if (bond->params.xmit_policy > BOND_XMIT_POLICY_LAYER23) {
3696 * @bond: bonding device
3702 u32 bond_xmit_hash(struct bonding *bond, struct sk_buff *skb)
3707 if (bond->params.xmit_policy == BOND_XMIT_POLICY_ENCAP34 &&
3711 if (bond->params.xmit_policy == BOND_XMIT_POLICY_LAYER2 ||
3712 !bond_flow_dissect(bond, skb, &flow))
3715 if (bond->params.xmit_policy == BOND_XMIT_POLICY_LAYER23 ||
3716 bond->params.xmit_policy == BOND_XMIT_POLICY_ENCAP23) {
3734 void bond_work_init_all(struct bonding *bond)
3736 INIT_DELAYED_WORK(&bond->mcast_work,
3738 INIT_DELAYED_WORK(&bond->alb_work, bond_alb_monitor);
3739 INIT_DELAYED_WORK(&bond->mii_work, bond_mii_monitor);
3740 INIT_DELAYED_WORK(&bond->arp_work, bond_arp_monitor);
3741 INIT_DELAYED_WORK(&bond->ad_work, bond_3ad_state_machine_handler);
3742 INIT_DELAYED_WORK(&bond->slave_arr_work, bond_slave_arr_handler);
3745 static void bond_work_cancel_all(struct bonding *bond)
3747 cancel_delayed_work_sync(&bond->mii_work);
3748 cancel_delayed_work_sync(&bond->arp_work);
3749 cancel_delayed_work_sync(&bond->alb_work);
3750 cancel_delayed_work_sync(&bond->ad_work);
3751 cancel_delayed_work_sync(&bond->mcast_work);
3752 cancel_delayed_work_sync(&bond->slave_arr_work);
3757 struct bonding *bond = netdev_priv(bond_dev);
3762 if (bond_has_slaves(bond)) {
3763 bond_for_each_slave(bond, slave, iter) {
3764 if (bond_uses_primary(bond) &&
3765 slave != rcu_access_pointer(bond->curr_active_slave)) {
3768 } else if (BOND_MODE(bond) != BOND_MODE_8023AD) {
3775 if (bond_is_lb(bond)) {
3779 if (bond_alb_initialize(bond, (BOND_MODE(bond) == BOND_MODE_ALB)))
3781 if (bond->params.tlb_dynamic_lb || BOND_MODE(bond) == BOND_MODE_ALB)
3782 queue_delayed_work(bond->wq, &bond->alb_work, 0);
3785 if (bond->params.miimon) /* link check interval, in milliseconds. */
3786 queue_delayed_work(bond->wq, &bond->mii_work, 0);
3788 if (bond->params.arp_interval) { /* arp interval, in milliseconds. */
3789 queue_delayed_work(bond->wq, &bond->arp_work, 0);
3790 bond->recv_probe = bond_arp_rcv;
3793 if (BOND_MODE(bond) == BOND_MODE_8023AD) {
3794 queue_delayed_work(bond->wq, &bond->ad_work, 0);
3796 bond->recv_probe = bond_3ad_lacpdu_recv;
3797 bond_3ad_initiate_agg_selection(bond, 1);
3799 bond_for_each_slave(bond, slave, iter)
3803 if (bond_mode_can_use_xmit_hash(bond))
3804 bond_update_slave_arr(bond, NULL);
3811 struct bonding *bond = netdev_priv(bond_dev);
3814 bond_work_cancel_all(bond);
3815 bond->send_peer_notif = 0;
3816 if (bond_is_lb(bond))
3817 bond_alb_deinitialize(bond);
3818 bond->recv_probe = NULL;
3820 if (bond_uses_primary(bond)) {
3822 slave = rcu_dereference(bond->curr_active_slave);
3829 bond_for_each_slave(bond, slave, iter)
3909 struct bonding *bond = netdev_priv(bond_dev);
3921 spin_lock_nested(&bond->stats_lock, nest_level);
3922 memcpy(stats, &bond->bond_stats, sizeof(*stats));
3924 bond_for_each_slave_rcu(bond, slave, iter) {
3934 memcpy(&bond->bond_stats, stats, sizeof(*stats));
3935 spin_unlock(&bond->stats_lock);
3941 struct bonding *bond = netdev_priv(bond_dev);
3972 if (netif_carrier_ok(bond->dev))
4034 res = __bond_opt_set_notify(bond, BOND_OPT_ACTIVE_SLAVE,
4046 struct bonding *bond = netdev_priv(bond_dev);
4049 bond_set_promiscuity(bond,
4053 bond_set_allmulti(bond,
4059 struct bonding *bond = netdev_priv(bond_dev);
4064 if (bond_uses_primary(bond)) {
4065 slave = rcu_dereference(bond->curr_active_slave);
4071 bond_for_each_slave_rcu(bond, slave, iter) {
4081 struct bonding *bond = netdev_priv(n->dev);
4088 slave = bond_first_slave_rcu(bond);
4137 struct bonding *bond = netdev_priv(bond_dev);
4142 netdev_dbg(bond_dev, "bond=%p, new_mtu=%d\n", bond, new_mtu);
4144 bond_for_each_slave(bond, slave, iter) {
4171 bond_for_each_slave(bond, rollback_slave, iter) {
4194 struct bonding *bond = netdev_priv(bond_dev);
4200 if (BOND_MODE(bond) == BOND_MODE_ALB)
4204 netdev_dbg(bond_dev, "%s: bond=%p\n", __func__, bond);
4209 if (bond->params.fail_over_mac &&
4210 BOND_MODE(bond) == BOND_MODE_ACTIVEBACKUP)
4216 bond_for_each_slave(bond, slave, iter) {
4242 bond_for_each_slave(bond, rollback_slave, iter) {
4261 * @bond: bonding device that is transmitting
4267 static struct slave *bond_get_slave_by_id(struct bonding *bond,
4275 bond_for_each_slave_rcu(bond, slave, iter) {
4284 bond_for_each_slave_rcu(bond, slave, iter) {
4296 * @bond: bonding device to use
4302 static u32 bond_rr_gen_slave_id(struct bonding *bond)
4306 int packets_per_slave = bond->params.packets_per_slave;
4313 slave_id = bond->rr_tx_counter;
4317 bond->params.reciprocal_packets_per_slave;
4318 slave_id = reciprocal_divide(bond->rr_tx_counter,
4322 bond->rr_tx_counter++;
4327 static struct slave *bond_xmit_roundrobin_slave_get(struct bonding *bond,
4334 /* Start with the curr_active_slave that joined the bond as the
4349 slave = rcu_dereference(bond->curr_active_slave);
4352 return bond_get_slave_by_id(bond, 0);
4357 slave_cnt = READ_ONCE(bond->slave_cnt);
4359 slave_id = bond_rr_gen_slave_id(bond) % slave_cnt;
4360 return bond_get_slave_by_id(bond, slave_id);
4368 struct bonding *bond = netdev_priv(bond_dev);
4371 slave = bond_xmit_roundrobin_slave_get(bond, skb);
4373 return bond_dev_queue_xmit(bond, skb, slave->dev);
4378 static struct slave *bond_xmit_activebackup_slave_get(struct bonding *bond,
4381 return rcu_dereference(bond->curr_active_slave);
4384 /* In active-backup mode, we know that bond->curr_active_slave is always valid if
4385 * the bond has a usable interface.
4390 struct bonding *bond = netdev_priv(bond_dev);
4393 slave = bond_xmit_activebackup_slave_get(bond, skb);
4395 return bond_dev_queue_xmit(bond, skb, slave->dev);
4404 void bond_slave_arr_work_rearm(struct bonding *bond, unsigned long delay)
4406 queue_delayed_work(bond->wq, &bond->slave_arr_work, delay);
4412 struct bonding *bond = container_of(work, struct bonding,
4419 ret = bond_update_slave_arr(bond, NULL);
4428 bond_slave_arr_work_rearm(bond, 1);
4454 static void bond_set_slave_arr(struct bonding *bond,
4460 usable = rtnl_dereference(bond->usable_slaves);
4461 rcu_assign_pointer(bond->usable_slaves, usable_slaves);
4464 all = rtnl_dereference(bond->all_slaves);
4465 rcu_assign_pointer(bond->all_slaves, all_slaves);
4469 static void bond_reset_slave_arr(struct bonding *bond)
4473 usable = rtnl_dereference(bond->usable_slaves);
4475 RCU_INIT_POINTER(bond->usable_slaves, NULL);
4479 all = rtnl_dereference(bond->all_slaves);
4481 RCU_INIT_POINTER(bond->all_slaves, NULL);
4494 int bond_update_slave_arr(struct bonding *bond, struct slave *skipslave)
4503 WARN_ON(lockdep_is_held(&bond->mode_lock));
4507 bond->slave_cnt), GFP_KERNEL);
4509 bond->slave_cnt), GFP_KERNEL);
4514 if (BOND_MODE(bond) == BOND_MODE_8023AD) {
4517 if (bond_3ad_get_active_agg_info(bond, &ad_info)) {
4522 bond_reset_slave_arr(bond);
4527 bond_for_each_slave(bond, slave, iter) {
4532 if (BOND_MODE(bond) == BOND_MODE_8023AD) {
4542 slave_dbg(bond->dev, slave->dev, "Adding slave to tx hash array[%d]\n",
4548 bond_set_slave_arr(bond, usable_slaves, all_slaves);
4552 bond_skip_slave(rtnl_dereference(bond->all_slaves),
4554 bond_skip_slave(rtnl_dereference(bond->usable_slaves),
4563 static struct slave *bond_xmit_3ad_xor_slave_get(struct bonding *bond,
4571 hash = bond_xmit_hash(bond, skb);
4587 struct bonding *bond = netdev_priv(dev);
4591 slaves = rcu_dereference(bond->usable_slaves);
4592 slave = bond_xmit_3ad_xor_slave_get(bond, skb, slaves);
4594 return bond_dev_queue_xmit(bond, skb, slave->dev);
4603 struct bonding *bond = netdev_priv(bond_dev);
4609 bond_for_each_slave_rcu(bond, slave, iter) {
4615 if (bond_is_last_slave(bond, slave)) {
4627 if (bond_dev_queue_xmit(bond, skb2, slave->dev) == NETDEV_TX_OK)
4644 static inline int bond_slave_override(struct bonding *bond,
4654 bond_for_each_slave_rcu(bond, slave, iter) {
4658 bond_dev_queue_xmit(bond, skb, slave->dev);
4695 struct bonding *bond = netdev_priv(master_dev);
4699 switch (BOND_MODE(bond)) {
4701 slave = bond_xmit_roundrobin_slave_get(bond, skb);
4704 slave = bond_xmit_activebackup_slave_get(bond, skb);
4709 slaves = rcu_dereference(bond->all_slaves);
4711 slaves = rcu_dereference(bond->usable_slaves);
4712 slave = bond_xmit_3ad_xor_slave_get(bond, skb, slaves);
4717 slave = bond_xmit_alb_slave_get(bond, skb);
4720 slave = bond_xmit_tlb_slave_get(bond, skb);
4735 struct bonding *bond = netdev_priv(dev);
4737 if (bond_should_override_tx_queue(bond) &&
4738 !bond_slave_override(bond, skb))
4741 switch (BOND_MODE(bond)) {
4757 netdev_err(dev, "Unknown bonding mode %d\n", BOND_MODE(bond));
4765 struct bonding *bond = netdev_priv(dev);
4775 if (bond_has_slaves(bond))
4797 struct bonding *bond = netdev_priv(bond_dev);
4810 bond_for_each_slave(bond, slave, iter) {
4813 if (BOND_MODE(bond) == BOND_MODE_BROADCAST)
4872 .name = "bond",
4877 struct bonding *bond = netdev_priv(bond_dev);
4878 if (bond->wq)
4879 destroy_workqueue(bond->wq);
4884 struct bonding *bond = netdev_priv(bond_dev);
4886 spin_lock_init(&bond->mode_lock);
4887 bond->params = bonding_defaults;
4890 bond->dev = bond_dev;
4911 INIT_LIST_HEAD(&bond->ipsec_list);
4912 spin_lock_init(&bond->ipsec_lock);
4915 /* don't acquire bond device's netif_tx_lock when transmitting */
4918 /* By default, we declare the bond to be fully
4925 /* Don't allow bond devices to change network namespaces. */
4942 if (BOND_MODE(bond) != BOND_MODE_ACTIVEBACKUP)
4952 struct bonding *bond = netdev_priv(bond_dev);
4960 bond_for_each_slave(bond, slave, iter)
4964 usable = rtnl_dereference(bond->usable_slaves);
4966 RCU_INIT_POINTER(bond->usable_slaves, NULL);
4970 all = rtnl_dereference(bond->all_slaves);
4972 RCU_INIT_POINTER(bond->all_slaves, NULL);
4976 list_del(&bond->bond_list);
4978 bond_debug_unregister(bond);
5372 struct bonding *bond = netdev_priv(bond_dev);
5377 bond->wq = alloc_ordered_workqueue(bond_dev->name, WQ_MEM_RECLAIM);
5378 if (!bond->wq)
5381 bond->notifier_ctx = false;
5383 spin_lock_init(&bond->stats_lock);
5386 list_add_tail(&bond->bond_list, &bn->dev_list);
5388 bond_prepare_sysfs_group(bond);
5390 bond_debug_register(bond);
5405 /* Create a new bond based on the specified name and bonding parameters.
5406 * If name is NULL, obtain a suitable "bond%d" name for us.
5413 struct bonding *bond;
5420 name ? name : "bond%d", NET_NAME_UNKNOWN,
5432 bond = netdev_priv(bond_dev);
5433 bond_info = &(BOND_ALB_INFO(bond));
5449 bond_work_init_all(bond);
5471 struct bonding *bond, *tmp_bond;
5476 /* Kill off any bonds created after unregistering bond rtnl ops */
5478 list_for_each_entry_safe(bond, tmp_bond, &bn->dev_list, bond_list)
5479 unregister_netdevice_queue(bond->dev, &list);