Lines Matching refs:bond
266 static bool bond_time_in_interval(struct bonding *bond, unsigned long last_act,
293 * @bond: bond device that got this skb for tx.
297 netdev_tx_t bond_dev_queue_xmit(struct bonding *bond, struct sk_buff *skb,
306 if (unlikely(netpoll_tx_running(bond->dev)))
307 return bond_netpoll_send_skb(bond_get_slave_by_dev(bond, slave_dev), skb);
312 static bool bond_sk_check(struct bonding *bond)
314 switch (BOND_MODE(bond)) {
317 if (bond->params.xmit_policy == BOND_XMIT_POLICY_LAYER34)
325 static bool bond_xdp_check(struct bonding *bond)
327 switch (BOND_MODE(bond)) {
336 if (bond->params.xmit_policy != BOND_XMIT_POLICY_VLAN_SRCMAC)
371 struct bonding *bond = netdev_priv(bond_dev);
376 bond_for_each_slave(bond, slave, iter) {
386 bond_for_each_slave(bond, rollback_slave, iter) {
405 struct bonding *bond = netdev_priv(bond_dev);
409 bond_for_each_slave(bond, slave, iter)
412 if (bond_is_lb(bond))
413 bond_alb_clear_vlan(bond, vid);
431 struct bonding *bond;
439 bond = netdev_priv(bond_dev);
440 slave = rcu_dereference(bond->curr_active_slave);
465 spin_lock_bh(&bond->ipsec_lock);
466 list_add(&ipsec->list, &bond->ipsec_list);
467 spin_unlock_bh(&bond->ipsec_lock);
475 static void bond_ipsec_add_sa_all(struct bonding *bond)
477 struct net_device *bond_dev = bond->dev;
482 slave = rcu_dereference(bond->curr_active_slave);
489 spin_lock_bh(&bond->ipsec_lock);
490 if (!list_empty(&bond->ipsec_list))
494 spin_unlock_bh(&bond->ipsec_lock);
498 spin_lock_bh(&bond->ipsec_lock);
499 list_for_each_entry(ipsec, &bond->ipsec_list, list) {
506 spin_unlock_bh(&bond->ipsec_lock);
519 struct bonding *bond;
526 bond = netdev_priv(bond_dev);
527 slave = rcu_dereference(bond->curr_active_slave);
546 spin_lock_bh(&bond->ipsec_lock);
547 list_for_each_entry(ipsec, &bond->ipsec_list, list) {
554 spin_unlock_bh(&bond->ipsec_lock);
558 static void bond_ipsec_del_sa_all(struct bonding *bond)
560 struct net_device *bond_dev = bond->dev;
565 slave = rcu_dereference(bond->curr_active_slave);
571 spin_lock_bh(&bond->ipsec_lock);
572 list_for_each_entry(ipsec, &bond->ipsec_list, list) {
587 spin_unlock_bh(&bond->ipsec_lock);
601 struct bonding *bond;
604 bond = netdev_priv(bond_dev);
606 curr_active = rcu_dereference(bond->curr_active_slave);
609 if (BOND_MODE(bond) != BOND_MODE_ACTIVEBACKUP) {
647 int bond_set_carrier(struct bonding *bond)
652 if (!bond_has_slaves(bond))
655 if (BOND_MODE(bond) == BOND_MODE_8023AD)
656 return bond_3ad_set_carrier(bond);
658 bond_for_each_slave(bond, slave, iter) {
660 if (!netif_carrier_ok(bond->dev)) {
661 netif_carrier_on(bond->dev);
669 if (netif_carrier_ok(bond->dev)) {
670 netif_carrier_off(bond->dev);
741 static int bond_check_dev_link(struct bonding *bond,
752 if (bond->params.use_carrier)
796 static int bond_set_promiscuity(struct bonding *bond, int inc)
801 if (bond_uses_primary(bond)) {
802 struct slave *curr_active = rtnl_dereference(bond->curr_active_slave);
809 bond_for_each_slave(bond, slave, iter) {
819 static int bond_set_allmulti(struct bonding *bond, int inc)
824 if (bond_uses_primary(bond)) {
825 struct slave *curr_active = rtnl_dereference(bond->curr_active_slave);
832 bond_for_each_slave(bond, slave, iter) {
847 struct bonding *bond = container_of(work, struct bonding,
851 queue_delayed_work(bond->wq, &bond->mcast_work, 1);
854 call_netdevice_notifiers(NETDEV_RESEND_IGMP, bond->dev);
856 if (bond->igmp_retrans > 1) {
857 bond->igmp_retrans--;
858 queue_delayed_work(bond->wq, &bond->mcast_work, HZ/5);
863 /* Flush bond's hardware addresses from slave */
867 struct bonding *bond = netdev_priv(bond_dev);
872 if (BOND_MODE(bond) == BOND_MODE_8023AD)
883 static void bond_hw_addr_swap(struct bonding *bond, struct slave *new_active,
887 if (bond->dev->flags & IFF_PROMISC)
890 if (bond->dev->flags & IFF_ALLMULTI)
893 if (bond->dev->flags & IFF_UP)
894 bond_hw_addr_flush(bond->dev, old_active->dev);
899 if (bond->dev->flags & IFF_PROMISC)
902 if (bond->dev->flags & IFF_ALLMULTI)
905 if (bond->dev->flags & IFF_UP) {
906 netif_addr_lock_bh(bond->dev);
907 dev_uc_sync(new_active->dev, bond->dev);
908 dev_mc_sync(new_active->dev, bond->dev);
909 netif_addr_unlock_bh(bond->dev);
915 * bond_set_dev_addr - clone slave's address to bond
916 * @bond_dev: bond net device
938 static struct slave *bond_get_old_active(struct bonding *bond,
944 bond_for_each_slave(bond, slave, iter) {
948 if (ether_addr_equal(bond->dev->dev_addr, slave->dev->dev_addr))
961 static void bond_do_fail_over_mac(struct bonding *bond,
969 switch (bond->params.fail_over_mac) {
972 rv = bond_set_dev_addr(bond->dev, new_active->dev);
974 slave_err(bond->dev, new_active->dev, "Error %d setting bond MAC from slave\n",
981 * if just new_active, set new_active to bond's MAC
987 old_active = bond_get_old_active(bond, new_active);
997 bond_hw_addr_copy(ss.__data, bond->dev->dev_addr,
998 bond->dev->addr_len);
999 ss.ss_family = bond->dev->type;
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",
1025 netdev_err(bond->dev, "bond_do_fail_over_mac impossible: bad policy %d\n",
1026 bond->params.fail_over_mac);
1034 * @bond: our bonding struct
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);
1051 bond_for_each_slave(bond, slave, iter) {
1069 if (bond->force_primary) {
1070 bond->force_primary = false;
1079 switch (bond->params.primary_reselect) {
1091 netdev_err(bond->dev, "impossible primary_reselect %d\n",
1092 bond->params.primary_reselect);
1099 * @bond: our bonding struct
1101 static struct slave *bond_find_best_slave(struct bonding *bond)
1105 int mintime = bond->params.updelay;
1107 slave = bond_choose_primary_or_current(bond);
1111 bond_for_each_slave(bond, slave, iter) {
1124 static bool bond_should_notify_peers(struct bonding *bond)
1129 slave = rcu_dereference(bond->curr_active_slave);
1132 if (!slave || !bond->send_peer_notif ||
1133 bond->send_peer_notif %
1134 max(1, bond->params.peer_notif_delay) != 0 ||
1135 !netif_carrier_ok(bond->dev) ||
1139 netdev_dbg(bond->dev, "bond_should_notify_peers: slave %s\n",
1147 * @bond: our bonding struct
1150 * Set the new slave to the bond's settings and unset them on the old
1160 void bond_change_active_slave(struct bonding *bond, struct slave *new_active)
1166 old_active = rtnl_dereference(bond->curr_active_slave);
1172 bond_ipsec_del_sa_all(bond);
1179 if (bond_uses_primary(bond)) {
1180 slave_info(bond->dev, new_active->dev, "making interface the new active one %d ms earlier\n",
1181 (bond->params.updelay - new_active->delay) * bond->params.miimon);
1188 if (BOND_MODE(bond) == BOND_MODE_8023AD)
1191 if (bond_is_lb(bond))
1192 bond_alb_handle_link_change(bond, new_active, BOND_LINK_UP);
1194 if (bond_uses_primary(bond))
1195 slave_info(bond->dev, new_active->dev, "making interface the new active one\n");
1199 if (bond_uses_primary(bond))
1200 bond_hw_addr_swap(bond, new_active, old_active);
1202 if (bond_is_lb(bond)) {
1203 bond_alb_handle_active_change(bond, new_active);
1211 rcu_assign_pointer(bond->curr_active_slave, new_active);
1214 if (BOND_MODE(bond) == BOND_MODE_ACTIVEBACKUP) {
1225 if (bond->params.fail_over_mac)
1226 bond_do_fail_over_mac(bond, new_active,
1229 if (netif_running(bond->dev)) {
1230 bond->send_peer_notif =
1231 bond->params.num_peer_notif *
1232 max(1, bond->params.peer_notif_delay);
1234 bond_should_notify_peers(bond);
1237 call_netdevice_notifiers(NETDEV_BONDING_FAILOVER, bond->dev);
1239 bond->send_peer_notif--;
1241 bond->dev);
1247 bond_ipsec_add_sa_all(bond);
1252 * resend only if bond is brought up with the affected
1255 if (netif_running(bond->dev) && (bond->params.resend_igmp > 0) &&
1256 ((bond_uses_primary(bond) && new_active) ||
1257 BOND_MODE(bond) == BOND_MODE_ROUNDROBIN)) {
1258 bond->igmp_retrans = bond->params.resend_igmp;
1259 queue_delayed_work(bond->wq, &bond->mcast_work, 1);
1265 * @bond: our bonding struct
1274 void bond_select_active_slave(struct bonding *bond)
1281 best_slave = bond_find_best_slave(bond);
1282 if (best_slave != rtnl_dereference(bond->curr_active_slave)) {
1283 bond_change_active_slave(bond, best_slave);
1284 rv = bond_set_carrier(bond);
1288 if (netif_carrier_ok(bond->dev))
1289 netdev_info(bond->dev, "active interface up!\n");
1291 netdev_info(bond->dev, "now running without any active interface!\n");
1329 struct bonding *bond = netdev_priv(bond_dev);
1334 if (BOND_MODE(bond) == BOND_MODE_8023AD)
1335 if (bond_3ad_get_active_agg_info(bond, &ad_info))
1338 bond_for_each_slave_rcu(bond, slave, iter) {
1342 if (BOND_MODE(bond) == BOND_MODE_8023AD) {
1357 struct bonding *bond = netdev_priv(bond_dev);
1361 bond_for_each_slave(bond, slave, iter)
1368 struct bonding *bond = netdev_priv(dev);
1373 bond_for_each_slave(bond, slave, iter) {
1400 struct bonding *bond = netdev_priv(dev);
1410 bond_for_each_slave(bond, slave, iter) {
1431 static void bond_compute_features(struct bonding *bond)
1441 struct net_device *bond_dev = bond->dev;
1448 if (!bond_has_slaves(bond))
1453 bond_for_each_slave(bond, slave, iter) {
1530 struct bonding *bond)
1533 if (BOND_MODE(bond) == BOND_MODE_ALB &&
1546 struct bonding *bond;
1558 bond = slave->bond;
1560 recv_probe = READ_ONCE(bond->recv_probe);
1562 ret = recv_probe(skb, bond, slave);
1580 if (bond_should_deliver_exact_match(skb, slave, bond)) {
1586 skb->dev = bond->dev;
1588 if (BOND_MODE(bond) == BOND_MODE_ALB &&
1589 netif_is_bridge_port(bond->dev) &&
1597 bond_hw_addr_copy(eth_hdr(skb)->h_dest, bond->dev->dev_addr,
1598 bond->dev->addr_len);
1604 static enum netdev_lag_tx_type bond_lag_tx_type(struct bonding *bond)
1606 switch (BOND_MODE(bond)) {
1621 static enum netdev_lag_hash bond_lag_hash_type(struct bonding *bond,
1627 switch (bond->params.xmit_policy) {
1645 static int bond_master_upper_dev_link(struct bonding *bond, struct slave *slave,
1652 type = bond_lag_tx_type(bond);
1654 lag_upper_info.hash_type = bond_lag_hash_type(bond, type);
1656 err = netdev_master_upper_dev_link(slave->dev, bond->dev, slave,
1665 static void bond_upper_dev_unlink(struct bonding *bond, struct slave *slave)
1667 netdev_upper_dev_unlink(slave->dev, bond->dev);
1674 struct bonding *bond = bond_get_bond_by_slave(slave);
1677 if (BOND_MODE(bond) == BOND_MODE_8023AD)
1702 static struct slave *bond_alloc_slave(struct bonding *bond,
1711 slave->bond = bond;
1718 if (BOND_MODE(bond) == BOND_MODE_8023AD) {
1730 static void bond_fill_ifbond(struct bonding *bond, struct ifbond *info)
1732 info->bond_mode = BOND_MODE(bond);
1733 info->miimon = bond->params.miimon;
1734 info->num_slaves = bond->slave_cnt;
1754 bond_fill_ifbond(slave->bond, &binfo.master);
1758 queue_delayed_work(slave->bond->wq, &slave->notify_work, 1);
1764 queue_delayed_work(slave->bond->wq, &slave->notify_work, 0);
1791 /* The bonding driver uses ether_setup() to convert a master bond device
1807 struct bonding *bond = netdev_priv(bond_dev);
1814 if (!bond_xdp_check(bond) || !bond_has_slaves(bond)) {
1819 bond_for_each_slave(bond, slave, iter)
1827 /* enslave device <slave> to bond device <master> */
1831 struct bonding *bond = netdev_priv(bond_dev);
1845 if (!bond->params.use_carrier &&
1859 BOND_NL_ERR(bond_dev, extack, "Cannot enslave bond to itself.");
1869 "Can not enslave VLAN challenged device to VLAN enabled bond");
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");
1896 * bond ether type mutual exclusion - don't allow slaves of dissimilar
1897 * ether type (eg ARPHRD_ETHER and ARPHRD_INFINIBAND) share the same bond
1899 if (!bond_has_slaves(bond)) {
1931 BOND_MODE(bond) != BOND_MODE_ACTIVEBACKUP) {
1941 if (BOND_MODE(bond) == BOND_MODE_ACTIVEBACKUP &&
1942 bond->params.fail_over_mac != BOND_FOM_ACTIVE) {
1943 if (!bond_has_slaves(bond)) {
1944 bond->params.fail_over_mac = BOND_FOM_ACTIVE;
1960 if (!bond_has_slaves(bond) &&
1961 bond->dev->addr_assign_type == NET_ADDR_RANDOM) {
1962 res = bond_set_dev_addr(bond->dev, slave_dev);
1967 new_slave = bond_alloc_slave(bond, slave_dev);
1978 /* Save slave's original mtu and then set it to match the bond */
1980 res = dev_set_mtu(slave_dev, bond->dev->mtu);
1993 if (!bond->params.fail_over_mac ||
1994 BOND_MODE(bond) != BOND_MODE_ACTIVEBACKUP) {
2022 if (bond_is_lb(bond)) {
2026 res = bond_alb_init_slave(bond, new_slave);
2033 slave_err(bond_dev, slave_dev, "Couldn't add bond vlan ids\n");
2037 prev_slave = bond_last_slave(bond);
2043 bond_needs_speed_duplex(bond))
2047 (msecs_to_jiffies(bond->params.arp_interval) + 1);
2053 if (bond->params.miimon && !bond->params.use_carrier) {
2054 link_reporting = bond_check_dev_link(bond, slave_dev, 1);
2056 if ((link_reporting == -1) && !bond->params.arp_interval) {
2074 if (bond->params.miimon) {
2075 if (bond_check_dev_link(bond, slave_dev, 0) == BMSR_LSTATUS) {
2076 if (bond->params.updelay) {
2080 new_slave->delay = bond->params.updelay;
2090 } else if (bond->params.arp_interval) {
2106 if (bond_uses_primary(bond) && bond->params.primary[0]) {
2108 if (strcmp(bond->params.primary, new_slave->dev->name) == 0) {
2109 rcu_assign_pointer(bond->primary_slave, new_slave);
2110 bond->force_primary = true;
2114 switch (BOND_MODE(bond)) {
2129 * can be called only after the mac address of the bond is set
2131 bond_3ad_initialize(bond);
2151 * anyway (it holds no special properties of the bond device),
2154 if (!rcu_access_pointer(bond->curr_active_slave) &&
2156 rcu_assign_pointer(bond->curr_active_slave, new_slave);
2162 if (bond->dev->npinfo) {
2181 res = bond_master_upper_dev_link(bond, new_slave, extack);
2198 if (!bond_uses_primary(bond)) {
2222 if (BOND_MODE(bond) == BOND_MODE_8023AD)
2227 bond->slave_cnt++;
2228 bond_compute_features(bond);
2229 bond_set_carrier(bond);
2231 if (bond_uses_primary(bond)) {
2233 bond_select_active_slave(bond);
2237 if (bond_mode_can_use_xmit_hash(bond))
2238 bond_update_slave_arr(bond, NULL);
2243 if (bond->xdp_prog) {
2249 } else if (bond->xdp_prog) {
2253 .prog = bond->xdp_prog,
2270 if (bond->xdp_prog)
2271 bpf_prog_inc(bond->xdp_prog);
2289 bond_upper_dev_unlink(bond, new_slave);
2296 if (rcu_access_pointer(bond->primary_slave) == new_slave)
2297 RCU_INIT_POINTER(bond->primary_slave, NULL);
2298 if (rcu_access_pointer(bond->curr_active_slave) == new_slave) {
2300 bond_change_active_slave(bond, NULL);
2301 bond_select_active_slave(bond);
2315 if (!bond->params.fail_over_mac ||
2316 BOND_MODE(bond) != BOND_MODE_ACTIVEBACKUP) {
2318 * MAC if this slave's MAC is in use by the bond, or at
2335 if (!bond_has_slaves(bond)) {
2348 /* Try to release the slave device <slave> from the bond device <master>
2351 * while destroying a bond interface and all slaves are being released.
2363 struct bonding *bond = netdev_priv(bond_dev);
2378 slave = bond_get_slave_by_dev(bond, slave_dev);
2380 /* not a slave of this bond */
2391 bond_get_stats(bond->dev, &bond->bond_stats);
2393 if (bond->xdp_prog) {
2409 if (BOND_MODE(bond) == BOND_MODE_8023AD)
2412 bond_upper_dev_unlink(bond, slave);
2414 if (bond_mode_can_use_xmit_hash(bond))
2415 bond_update_slave_arr(bond, slave);
2420 oldcurrent = rcu_access_pointer(bond->curr_active_slave);
2422 RCU_INIT_POINTER(bond->current_arp_slave, NULL);
2424 if (!all && (!bond->params.fail_over_mac ||
2425 BOND_MODE(bond) != BOND_MODE_ACTIVEBACKUP)) {
2427 bond_has_slaves(bond))
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",
2432 if (rtnl_dereference(bond->primary_slave) == slave)
2433 RCU_INIT_POINTER(bond->primary_slave, NULL);
2436 bond_change_active_slave(bond, NULL);
2438 if (bond_is_lb(bond)) {
2444 bond_alb_deinit_slave(bond, slave);
2448 RCU_INIT_POINTER(bond->curr_active_slave, NULL);
2454 bond_select_active_slave(bond);
2457 bond_set_carrier(bond);
2458 if (!bond_has_slaves(bond))
2463 bond->slave_cnt--;
2465 if (!bond_has_slaves(bond)) {
2466 call_netdevice_notifiers(NETDEV_CHANGEADDR, bond->dev);
2467 call_netdevice_notifiers(NETDEV_RELEASE, bond->dev);
2470 bond_compute_features(bond);
2473 slave_info(bond_dev, slave_dev, "last VLAN challenged slave left bond - VLAN blocking is removed\n");
2480 if (!bond_uses_primary(bond)) {
2506 if (bond->params.fail_over_mac != BOND_FOM_ACTIVE ||
2507 BOND_MODE(bond) != BOND_MODE_ACTIVEBACKUP) {
2535 /* First release a slave and then destroy the bond if no more slaves are left.
2541 struct bonding *bond = netdev_priv(bond_dev);
2545 if (ret == 0 && !bond_has_slaves(bond) &&
2548 netdev_info(bond_dev, "Destroying bond\n");
2549 bond_remove_proc_entry(bond);
2557 struct bonding *bond = netdev_priv(bond_dev);
2559 bond_fill_ifbond(bond, info);
2564 struct bonding *bond = netdev_priv(bond_dev);
2569 bond_for_each_slave(bond, slave, iter) {
2583 static int bond_miimon_inspect(struct bonding *bond)
2590 if (BOND_MODE(bond) == BOND_MODE_ACTIVEBACKUP) {
2591 ignore_updelay = !rcu_dereference(bond->curr_active_slave);
2595 usable_slaves = rcu_dereference(bond->usable_slaves);
2601 bond_for_each_slave_rcu(bond, slave, iter) {
2604 link_state = bond_check_dev_link(bond, slave->dev, 0);
2613 slave->delay = bond->params.downdelay;
2615 slave_info(bond->dev, slave->dev, "link status down for %sinterface, disabling it in %d ms\n",
2616 (BOND_MODE(bond) ==
2620 bond->params.downdelay * bond->params.miimon);
2628 slave_info(bond->dev, slave->dev, "link status up again after %d ms\n",
2629 (bond->params.downdelay - slave->delay) *
2630 bond->params.miimon);
2650 slave->delay = bond->params.updelay;
2653 slave_info(bond->dev, slave->dev, "link status up, enabling it in %d ms\n",
2655 bond->params.updelay *
2656 bond->params.miimon);
2662 slave_info(bond->dev, slave->dev, "link status down again after %d ms\n",
2663 (bond->params.updelay - slave->delay) *
2664 bond->params.miimon);
2687 static void bond_miimon_link_change(struct bonding *bond,
2691 switch (BOND_MODE(bond)) {
2697 bond_alb_handle_link_change(bond, slave, link);
2700 bond_update_slave_arr(bond, NULL);
2705 static void bond_miimon_commit(struct bonding *bond)
2713 bond_for_each_slave(bond, slave, iter) {
2722 if (BOND_MODE(bond) == BOND_MODE_8023AD &&
2729 bond_needs_speed_duplex(bond)) {
2732 slave_warn(bond->dev, slave->dev,
2740 primary = rtnl_dereference(bond->primary_slave);
2741 if (BOND_MODE(bond) == BOND_MODE_8023AD) {
2744 } else if (BOND_MODE(bond) != BOND_MODE_ACTIVEBACKUP) {
2749 slave_info(bond->dev, slave->dev, "link status definitely up, %u Mbps %s duplex\n",
2753 bond_miimon_link_change(bond, slave, BOND_LINK_UP);
2755 active = rtnl_dereference(bond->curr_active_slave);
2768 if (BOND_MODE(bond) == BOND_MODE_ACTIVEBACKUP ||
2769 BOND_MODE(bond) == BOND_MODE_8023AD)
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",
2793 bond_select_active_slave(bond);
2797 bond_set_carrier(bond);
2809 struct bonding *bond = container_of(work, struct bonding,
2817 delay = msecs_to_jiffies(bond->params.miimon);
2819 if (!bond_has_slaves(bond))
2823 should_notify_peers = bond_should_notify_peers(bond);
2824 commit = !!bond_miimon_inspect(bond);
2825 if (bond->send_peer_notif) {
2828 bond->send_peer_notif--;
2843 bond_for_each_slave(bond, slave, iter) {
2846 bond_miimon_commit(bond);
2852 if (bond->params.miimon)
2853 queue_delayed_work(bond->wq, &bond->mii_work, delay);
2858 call_netdevice_notifiers(NETDEV_NOTIFY_PEERS, bond->dev);
2871 static bool bond_has_this_ip(struct bonding *bond, __be32 ip)
2878 if (ip == bond_confirm_addr(bond->dev, 0, ip))
2882 if (netdev_walk_all_upper_dev_rcu(bond->dev, bond_upper_dev_walk, &priv))
2894 struct net_device *bond_dev = slave->bond->dev;
2939 struct net_device *bond_dev = slave->bond->dev;
3002 static void bond_arp_send_all(struct bonding *bond, struct slave *slave)
3006 __be32 *targets = bond->params.arp_targets, addr;
3010 slave_dbg(bond->dev, slave->dev, "%s: target %pI4\n",
3015 rt = ip_route_output(dev_net(bond->dev), targets[i], 0,
3021 if (bond->params.arp_validate)
3023 bond->dev->name,
3030 /* bond device itself */
3031 if (rt->dst.dev == bond->dev)
3035 tags = bond_verify_device_path(bond->dev, rt->dst.dev, 0);
3042 slave_dbg(bond->dev, slave->dev, "no path to arp_ip_target %pI4 via rt.dev %s\n",
3056 static void bond_validate_arp(struct bonding *bond, struct slave *slave, __be32 sip, __be32 tip)
3060 if (!sip || !bond_has_this_ip(bond, tip)) {
3061 slave_dbg(bond->dev, slave->dev, "%s: sip %pI4 tip %pI4 not found\n",
3066 i = bond_get_targets_ip(bond->params.arp_targets, sip);
3068 slave_dbg(bond->dev, slave->dev, "%s: sip %pI4 not found in targets\n",
3076 static int bond_arp_rcv(const struct sk_buff *skb, struct bonding *bond,
3085 alen = arp_hdr_len(bond->dev);
3095 if (arp->ar_hln != bond->dev->addr_len ||
3104 arp_ptr += bond->dev->addr_len;
3106 arp_ptr += 4 + bond->dev->addr_len;
3109 slave_dbg(bond->dev, slave->dev, "%s: %s/%d av %d sv %d sip %pI4 tip %pI4\n",
3111 bond->params.arp_validate, slave_do_arp_validate(bond, slave),
3114 curr_active_slave = rcu_dereference(bond->curr_active_slave);
3115 curr_arp_slave = rcu_dereference(bond->current_arp_slave);
3141 bond_validate_arp(bond, slave, sip, tip);
3143 time_after(slave_last_rx(bond, curr_active_slave),
3145 bond_validate_arp(bond, slave, tip, sip);
3147 bond_time_in_interval(bond, slave_last_tx(curr_arp_slave), 1))
3148 bond_validate_arp(bond, slave, sip, tip);
3160 struct net_device *bond_dev = slave->bond->dev;
3181 static void bond_ns_send_all(struct bonding *bond, struct slave *slave)
3183 struct in6_addr *targets = bond->params.ns_targets;
3191 slave_dbg(bond->dev, slave->dev, "%s: target %pI6c\n",
3198 fl6.flowi6_oif = bond->dev->ifindex;
3200 dst = ip6_route_output(dev_net(bond->dev), NULL, &fl6);
3206 if (bond->params.arp_validate)
3208 bond->dev->name,
3214 /* bond device itself */
3215 if (dst->dev == bond->dev)
3219 tags = bond_verify_device_path(bond->dev, dst->dev, 0);
3226 slave_dbg(bond->dev, slave->dev, "no path to ns_ip6_target %pI6c via dst->dev %s\n",
3251 static bool bond_has_this_ip6(struct bonding *bond, struct in6_addr *addr)
3258 if (bond_confirm_addr6(bond->dev, &priv))
3262 if (netdev_walk_all_upper_dev_rcu(bond->dev, bond_confirm_addr6, &priv))
3269 static void bond_validate_na(struct bonding *bond, struct slave *slave,
3277 * exist on bond interface.
3281 !bond_has_this_ip6(bond, daddr))) {
3282 slave_dbg(bond->dev, slave->dev, "%s: sip %pI6c tip %pI6c not found\n",
3287 i = bond_get_targets_ip6(bond->params.ns_targets, saddr);
3289 slave_dbg(bond->dev, slave->dev, "%s: sip %pI6c not found in targets\n",
3297 static int bond_na_rcv(const struct sk_buff *skb, struct bonding *bond,
3320 slave_dbg(bond->dev, slave->dev, "%s: %s/%d av %d sv %d sip %pI6c tip %pI6c\n",
3322 bond->params.arp_validate, slave_do_arp_validate(bond, slave),
3325 curr_active_slave = rcu_dereference(bond->curr_active_slave);
3326 curr_arp_slave = rcu_dereference(bond->current_arp_slave);
3332 bond_validate_na(bond, slave, saddr, daddr);
3334 time_after(slave_last_rx(bond, curr_active_slave),
3336 bond_validate_na(bond, slave, daddr, saddr);
3338 bond_time_in_interval(bond, slave_last_tx(curr_arp_slave), 1))
3339 bond_validate_na(bond, slave, saddr, daddr);
3346 int bond_rcv_validate(const struct sk_buff *skb, struct bonding *bond,
3354 slave_dbg(bond->dev, slave->dev, "%s: skb->dev %s\n",
3358 if (!slave_do_arp_validate(bond, slave)) {
3359 if ((slave_do_arp_validate_only(bond) && is_arp) ||
3361 (slave_do_arp_validate_only(bond) && is_ipv6) ||
3363 !slave_do_arp_validate_only(bond))
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);
3389 static bool bond_time_in_interval(struct bonding *bond, unsigned long last_act,
3392 int delta_in_ticks = msecs_to_jiffies(bond->params.arp_interval);
3405 static void bond_loadbalance_arp_mon(struct bonding *bond)
3411 if (!bond_has_slaves(bond))
3416 oldcurrent = rcu_dereference(bond->curr_active_slave);
3425 bond_for_each_slave_rcu(bond, slave, iter) {
3431 if (bond_time_in_interval(bond, last_tx, 1) &&
3432 bond_time_in_interval(bond, slave->last_rx, 1)) {
3443 slave_info(bond->dev, slave->dev, "link status definitely up\n");
3446 slave_info(bond->dev, slave->dev, "interface is now up\n");
3456 if (!bond_time_in_interval(bond, last_tx, bond->params.missed_max) ||
3457 !bond_time_in_interval(bond, slave->last_rx, bond->params.missed_max)) {
3465 slave_info(bond->dev, slave->dev, "interface is now down\n");
3480 bond_send_validate(bond, slave);
3489 bond_for_each_slave(bond, slave, iter) {
3495 bond_slave_state_change(bond);
3496 if (BOND_MODE(bond) == BOND_MODE_XOR)
3497 bond_update_slave_arr(bond, NULL);
3501 bond_select_active_slave(bond);
3508 if (bond->params.arp_interval)
3509 queue_delayed_work(bond->wq, &bond->arp_work,
3510 msecs_to_jiffies(bond->params.arp_interval));
3520 static int bond_ab_arp_inspect(struct bonding *bond)
3527 bond_for_each_slave_rcu(bond, slave, iter) {
3529 last_rx = slave_last_rx(bond, slave);
3532 if (bond_time_in_interval(bond, last_rx, 1)) {
3546 if (bond_time_in_interval(bond, slave->last_link_up, 2))
3552 * - the bond has an IP address
3562 !rcu_access_pointer(bond->current_arp_slave) &&
3563 !bond_time_in_interval(bond, last_rx, bond->params.missed_max + 1)) {
3571 * the bond has an IP address)
3575 (!bond_time_in_interval(bond, last_tx, bond->params.missed_max) ||
3576 !bond_time_in_interval(bond, last_rx, bond->params.missed_max))) {
3590 static void bond_ab_arp_commit(struct bonding *bond)
3597 bond_for_each_slave(bond, slave, iter) {
3604 if (rtnl_dereference(bond->curr_active_slave) != slave ||
3605 (!rtnl_dereference(bond->curr_active_slave) &&
3606 bond_time_in_interval(bond, last_tx, 1))) {
3609 current_arp_slave = rtnl_dereference(bond->current_arp_slave);
3616 RCU_INIT_POINTER(bond->current_arp_slave, NULL);
3619 slave_info(bond->dev, slave->dev, "link status definitely up\n");
3621 if (!rtnl_dereference(bond->curr_active_slave) ||
3622 slave == rtnl_dereference(bond->primary_slave) ||
3623 slave->prio > rtnl_dereference(bond->curr_active_slave)->prio)
3639 slave_info(bond->dev, slave->dev, "link status definitely down, disabling slave\n");
3641 if (slave == rtnl_dereference(bond->curr_active_slave)) {
3642 RCU_INIT_POINTER(bond->current_arp_slave, NULL);
3657 if (rtnl_dereference(bond->curr_active_slave))
3658 RCU_INIT_POINTER(bond->current_arp_slave, NULL);
3662 slave_err(bond->dev, slave->dev,
3671 bond_select_active_slave(bond);
3675 bond_set_carrier(bond);
3682 static bool bond_ab_arp_probe(struct bonding *bond)
3685 *curr_arp_slave = rcu_dereference(bond->current_arp_slave),
3686 *curr_active_slave = rcu_dereference(bond->curr_active_slave);
3692 netdev_info(bond->dev, "PROBE: c_arp %s && cas %s BAD\n",
3697 bond_send_validate(bond, curr_active_slave);
3707 curr_arp_slave = bond_first_slave_rcu(bond);
3712 bond_for_each_slave_rcu(bond, slave, iter) {
3734 slave_info(bond->dev, slave->dev, "backup interface is now down\n");
3749 bond_send_validate(bond, new_slave);
3751 rcu_assign_pointer(bond->current_arp_slave, new_slave);
3754 bond_for_each_slave_rcu(bond, slave, iter) {
3763 static void bond_activebackup_arp_mon(struct bonding *bond)
3769 delta_in_ticks = msecs_to_jiffies(bond->params.arp_interval);
3771 if (!bond_has_slaves(bond))
3776 should_notify_peers = bond_should_notify_peers(bond);
3778 if (bond_ab_arp_inspect(bond)) {
3788 bond_ab_arp_commit(bond);
3794 should_notify_rtnl = bond_ab_arp_probe(bond);
3798 if (bond->params.arp_interval)
3799 queue_delayed_work(bond->wq, &bond->arp_work, delta_in_ticks);
3806 bond->send_peer_notif--;
3808 bond->dev);
3811 bond_slave_state_notify(bond);
3812 bond_slave_link_notify(bond);
3821 struct bonding *bond = container_of(work, struct bonding,
3824 if (BOND_MODE(bond) == BOND_MODE_ACTIVEBACKUP)
3825 bond_activebackup_arp_mon(bond);
3827 bond_loadbalance_arp_mon(bond);
3833 static int bond_event_changename(struct bonding *bond)
3835 bond_remove_proc_entry(bond);
3836 bond_create_proc_entry(bond);
3838 bond_debug_reregister(bond);
3873 struct bonding *bond;
3885 bond_dev = slave->bond->dev;
3886 bond = slave->bond;
3887 primary = rtnl_dereference(bond->primary_slave);
3908 BOND_MODE(bond) == BOND_MODE_8023AD) {
3915 if (BOND_MODE(bond) == BOND_MODE_8023AD)
3927 if (bond_mode_can_use_xmit_hash(bond))
3928 bond_update_slave_arr(bond, NULL);
3933 * an active-backup bond, slaves need
3945 if (!bond_uses_primary(bond) ||
3946 !bond->params.primary[0])
3951 RCU_INIT_POINTER(bond->primary_slave, NULL);
3952 } else if (!strcmp(slave_dev->name, bond->params.primary)) {
3954 rcu_assign_pointer(bond->primary_slave, slave);
3959 netdev_info(bond->dev, "Primary slave changed to %s, reselecting active slave\n",
3963 bond_select_active_slave(bond);
3967 if (!bond->notifier_ctx) {
3968 bond->notifier_ctx = true;
3969 bond_compute_features(bond);
3970 bond->notifier_ctx = false;
3975 call_netdevice_notifiers(event, slave->bond->dev);
4111 /* Extract the appropriate headers based on bond's xmit policy */
4112 static bool bond_flow_dissect(struct bonding *bond, struct sk_buff *skb, const void *data,
4115 bool l34 = bond->params.xmit_policy == BOND_XMIT_POLICY_LAYER34;
4118 switch (bond->params.xmit_policy) {
4176 static u32 __bond_xmit_hash(struct bonding *bond, struct sk_buff *skb, const void *data,
4182 if (bond->params.xmit_policy == BOND_XMIT_POLICY_VLAN_SRCMAC)
4185 if (bond->params.xmit_policy == BOND_XMIT_POLICY_LAYER2 ||
4186 !bond_flow_dissect(bond, skb, data, l2_proto, nhoff, hlen, &flow))
4189 if (bond->params.xmit_policy == BOND_XMIT_POLICY_LAYER23 ||
4190 bond->params.xmit_policy == BOND_XMIT_POLICY_ENCAP23) {
4199 return bond_ip_hash(hash, &flow, bond->params.xmit_policy);
4204 * @bond: bonding device
4210 u32 bond_xmit_hash(struct bonding *bond, struct sk_buff *skb)
4212 if (bond->params.xmit_policy == BOND_XMIT_POLICY_ENCAP34 &&
4216 return __bond_xmit_hash(bond, skb, skb->data, skb->protocol,
4223 * @bond: bonding device
4228 static u32 bond_xmit_hash_xdp(struct bonding *bond, struct xdp_buff *xdp)
4237 return __bond_xmit_hash(bond, NULL, xdp->data, eth->h_proto, 0,
4243 void bond_work_init_all(struct bonding *bond)
4245 INIT_DELAYED_WORK(&bond->mcast_work,
4247 INIT_DELAYED_WORK(&bond->alb_work, bond_alb_monitor);
4248 INIT_DELAYED_WORK(&bond->mii_work, bond_mii_monitor);
4249 INIT_DELAYED_WORK(&bond->arp_work, bond_arp_monitor);
4250 INIT_DELAYED_WORK(&bond->ad_work, bond_3ad_state_machine_handler);
4251 INIT_DELAYED_WORK(&bond->slave_arr_work, bond_slave_arr_handler);
4254 static void bond_work_cancel_all(struct bonding *bond)
4256 cancel_delayed_work_sync(&bond->mii_work);
4257 cancel_delayed_work_sync(&bond->arp_work);
4258 cancel_delayed_work_sync(&bond->alb_work);
4259 cancel_delayed_work_sync(&bond->ad_work);
4260 cancel_delayed_work_sync(&bond->mcast_work);
4261 cancel_delayed_work_sync(&bond->slave_arr_work);
4266 struct bonding *bond = netdev_priv(bond_dev);
4270 if (BOND_MODE(bond) == BOND_MODE_ROUNDROBIN && !bond->rr_tx_counter) {
4271 bond->rr_tx_counter = alloc_percpu(u32);
4272 if (!bond->rr_tx_counter)
4277 if (bond_has_slaves(bond)) {
4278 bond_for_each_slave(bond, slave, iter) {
4279 if (bond_uses_primary(bond) &&
4280 slave != rcu_access_pointer(bond->curr_active_slave)) {
4283 } else if (BOND_MODE(bond) != BOND_MODE_8023AD) {
4290 if (bond_is_lb(bond)) {
4294 if (bond_alb_initialize(bond, (BOND_MODE(bond) == BOND_MODE_ALB)))
4296 if (bond->params.tlb_dynamic_lb || BOND_MODE(bond) == BOND_MODE_ALB)
4297 queue_delayed_work(bond->wq, &bond->alb_work, 0);
4300 if (bond->params.miimon) /* link check interval, in milliseconds. */
4301 queue_delayed_work(bond->wq, &bond->mii_work, 0);
4303 if (bond->params.arp_interval) { /* arp interval, in milliseconds. */
4304 queue_delayed_work(bond->wq, &bond->arp_work, 0);
4305 bond->recv_probe = bond_rcv_validate;
4308 if (BOND_MODE(bond) == BOND_MODE_8023AD) {
4309 queue_delayed_work(bond->wq, &bond->ad_work, 0);
4311 bond->recv_probe = bond_3ad_lacpdu_recv;
4312 bond_3ad_initiate_agg_selection(bond, 1);
4314 bond_for_each_slave(bond, slave, iter)
4318 if (bond_mode_can_use_xmit_hash(bond))
4319 bond_update_slave_arr(bond, NULL);
4326 struct bonding *bond = netdev_priv(bond_dev);
4329 bond_work_cancel_all(bond);
4330 bond->send_peer_notif = 0;
4331 if (bond_is_lb(bond))
4332 bond_alb_deinitialize(bond);
4333 bond->recv_probe = NULL;
4335 if (bond_uses_primary(bond)) {
4337 slave = rcu_dereference(bond->curr_active_slave);
4344 bond_for_each_slave(bond, slave, iter)
4424 struct bonding *bond = netdev_priv(bond_dev);
4436 spin_lock_nested(&bond->stats_lock, nest_level);
4437 memcpy(stats, &bond->bond_stats, sizeof(*stats));
4439 bond_for_each_slave_rcu(bond, slave, iter) {
4449 memcpy(&bond->bond_stats, stats, sizeof(*stats));
4450 spin_unlock(&bond->stats_lock);
4456 struct bonding *bond = netdev_priv(bond_dev);
4479 if (netif_carrier_ok(bond->dev))
4493 struct bonding *bond = netdev_priv(bond_dev);
4557 res = __bond_opt_set_notify(bond, BOND_OPT_ACTIVE_SLAVE,
4592 struct bonding *bond = netdev_priv(bond_dev);
4595 bond_set_promiscuity(bond,
4599 bond_set_allmulti(bond,
4605 struct bonding *bond = netdev_priv(bond_dev);
4610 if (bond_uses_primary(bond)) {
4611 slave = rcu_dereference(bond->curr_active_slave);
4617 bond_for_each_slave_rcu(bond, slave, iter) {
4627 struct bonding *bond = netdev_priv(n->dev);
4634 slave = bond_first_slave_rcu(bond);
4683 struct bonding *bond = netdev_priv(bond_dev);
4688 netdev_dbg(bond_dev, "bond=%p, new_mtu=%d\n", bond, new_mtu);
4690 bond_for_each_slave(bond, slave, iter) {
4717 bond_for_each_slave(bond, rollback_slave, iter) {
4740 struct bonding *bond = netdev_priv(bond_dev);
4746 if (BOND_MODE(bond) == BOND_MODE_ALB)
4750 netdev_dbg(bond_dev, "%s: bond=%p\n", __func__, bond);
4755 if (bond->params.fail_over_mac &&
4756 BOND_MODE(bond) == BOND_MODE_ACTIVEBACKUP)
4762 bond_for_each_slave(bond, slave, iter) {
4788 bond_for_each_slave(bond, rollback_slave, iter) {
4807 * @bond: bonding device that is transmitting
4813 static struct slave *bond_get_slave_by_id(struct bonding *bond,
4821 bond_for_each_slave_rcu(bond, slave, iter) {
4830 bond_for_each_slave_rcu(bond, slave, iter) {
4842 * @bond: bonding device to use
4848 static u32 bond_rr_gen_slave_id(struct bonding *bond)
4852 int packets_per_slave = bond->params.packets_per_slave;
4859 slave_id = this_cpu_inc_return(*bond->rr_tx_counter);
4863 bond->params.reciprocal_packets_per_slave;
4864 slave_id = this_cpu_inc_return(*bond->rr_tx_counter);
4873 static struct slave *bond_xmit_roundrobin_slave_get(struct bonding *bond,
4880 /* Start with the curr_active_slave that joined the bond as the
4895 slave = rcu_dereference(bond->curr_active_slave);
4898 return bond_get_slave_by_id(bond, 0);
4903 slave_cnt = READ_ONCE(bond->slave_cnt);
4905 slave_id = bond_rr_gen_slave_id(bond) % slave_cnt;
4906 return bond_get_slave_by_id(bond, slave_id);
4911 static struct slave *bond_xdp_xmit_roundrobin_slave_get(struct bonding *bond,
4936 slave = rcu_dereference(bond->curr_active_slave);
4939 return bond_get_slave_by_id(bond, 0);
4944 slave_cnt = READ_ONCE(bond->slave_cnt);
4946 slave_id = bond_rr_gen_slave_id(bond) % slave_cnt;
4947 return bond_get_slave_by_id(bond, slave_id);
4955 struct bonding *bond = netdev_priv(bond_dev);
4958 slave = bond_xmit_roundrobin_slave_get(bond, skb);
4960 return bond_dev_queue_xmit(bond, skb, slave->dev);
4965 static struct slave *bond_xmit_activebackup_slave_get(struct bonding *bond)
4967 return rcu_dereference(bond->curr_active_slave);
4970 /* In active-backup mode, we know that bond->curr_active_slave is always valid if
4971 * the bond has a usable interface.
4976 struct bonding *bond = netdev_priv(bond_dev);
4979 slave = bond_xmit_activebackup_slave_get(bond);
4981 return bond_dev_queue_xmit(bond, skb, slave->dev);
4990 void bond_slave_arr_work_rearm(struct bonding *bond, unsigned long delay)
4992 queue_delayed_work(bond->wq, &bond->slave_arr_work, delay);
4998 struct bonding *bond = container_of(work, struct bonding,
5005 ret = bond_update_slave_arr(bond, NULL);
5014 bond_slave_arr_work_rearm(bond, 1);
5040 static void bond_set_slave_arr(struct bonding *bond,
5046 usable = rtnl_dereference(bond->usable_slaves);
5047 rcu_assign_pointer(bond->usable_slaves, usable_slaves);
5050 all = rtnl_dereference(bond->all_slaves);
5051 rcu_assign_pointer(bond->all_slaves, all_slaves);
5055 static void bond_reset_slave_arr(struct bonding *bond)
5057 bond_set_slave_arr(bond, NULL, NULL);
5068 int bond_update_slave_arr(struct bonding *bond, struct slave *skipslave)
5079 bond->slave_cnt), GFP_KERNEL);
5081 bond->slave_cnt), GFP_KERNEL);
5086 if (BOND_MODE(bond) == BOND_MODE_8023AD) {
5089 spin_lock_bh(&bond->mode_lock);
5090 if (bond_3ad_get_active_agg_info(bond, &ad_info)) {
5091 spin_unlock_bh(&bond->mode_lock);
5096 bond_reset_slave_arr(bond);
5099 spin_unlock_bh(&bond->mode_lock);
5102 bond_for_each_slave(bond, slave, iter) {
5107 if (BOND_MODE(bond) == BOND_MODE_8023AD) {
5117 slave_dbg(bond->dev, slave->dev, "Adding slave to tx hash array[%d]\n",
5123 bond_set_slave_arr(bond, usable_slaves, all_slaves);
5127 bond_skip_slave(rtnl_dereference(bond->all_slaves),
5129 bond_skip_slave(rtnl_dereference(bond->usable_slaves),
5138 static struct slave *bond_xmit_3ad_xor_slave_get(struct bonding *bond,
5146 hash = bond_xmit_hash(bond, skb);
5155 static struct slave *bond_xdp_xmit_3ad_xor_slave_get(struct bonding *bond,
5162 hash = bond_xmit_hash_xdp(bond, xdp);
5163 slaves = rcu_dereference(bond->usable_slaves);
5178 struct bonding *bond = netdev_priv(dev);
5182 slaves = rcu_dereference(bond->usable_slaves);
5183 slave = bond_xmit_3ad_xor_slave_get(bond, skb, slaves);
5185 return bond_dev_queue_xmit(bond, skb, slave->dev);
5194 struct bonding *bond = netdev_priv(bond_dev);
5200 bond_for_each_slave_rcu(bond, slave, iter) {
5206 if (bond_is_last_slave(bond, slave)) {
5218 if (bond_dev_queue_xmit(bond, skb2, slave->dev) == NETDEV_TX_OK)
5235 static inline int bond_slave_override(struct bonding *bond,
5245 bond_for_each_slave_rcu(bond, slave, iter) {
5249 bond_dev_queue_xmit(bond, skb, slave->dev);
5286 struct bonding *bond = netdev_priv(master_dev);
5290 switch (BOND_MODE(bond)) {
5292 slave = bond_xmit_roundrobin_slave_get(bond, skb);
5295 slave = bond_xmit_activebackup_slave_get(bond);
5300 slaves = rcu_dereference(bond->all_slaves);
5302 slaves = rcu_dereference(bond->usable_slaves);
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);
5370 static struct net_device *__bond_sk_get_lower_dev(struct bonding *bond,
5378 slaves = rcu_dereference(bond->usable_slaves);
5392 struct bonding *bond = netdev_priv(dev);
5396 if (bond_sk_check(bond))
5397 lower = __bond_sk_get_lower_dev(bond, sk);
5404 static netdev_tx_t bond_tls_device_xmit(struct bonding *bond, struct sk_buff *skb,
5413 if (likely(bond_get_slave_by_dev(bond, tls_netdev)))
5414 return bond_dev_queue_xmit(bond, skb, tls_netdev);
5421 struct bonding *bond = netdev_priv(dev);
5423 if (bond_should_override_tx_queue(bond) &&
5424 !bond_slave_override(bond, skb))
5429 return bond_tls_device_xmit(bond, skb, dev);
5432 switch (BOND_MODE(bond)) {
5448 netdev_err(dev, "Unknown bonding mode %d\n", BOND_MODE(bond));
5456 struct bonding *bond = netdev_priv(dev);
5466 if (bond_has_slaves(bond))
5478 struct bonding *bond = netdev_priv(bond_dev);
5483 switch (BOND_MODE(bond)) {
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);
5499 netdev_err(bond_dev, "Unknown bonding mode %d for xdp xmit\n", BOND_MODE(bond));
5550 struct bonding *bond = netdev_priv(dev);
5564 if (!bond_xdp_check(bond))
5567 old_prog = bond->xdp_prog;
5568 bond->xdp_prog = prog;
5570 bond_for_each_slave(bond, slave, iter) {
5609 bond->xdp_prog = old_prog;
5613 bond_for_each_slave(bond, rollback_slave, iter) {
5674 struct bonding *bond = netdev_priv(dev);
5678 real_dev = bond_option_active_slave_get_rcu(bond);
5693 struct bonding *bond = netdev_priv(dev);
5700 real_dev = bond_option_active_slave_get_rcu(bond);
5714 struct bonding *bond = netdev_priv(bond_dev);
5727 bond_for_each_slave(bond, slave, iter) {
5731 if (BOND_MODE(bond) == BOND_MODE_BROADCAST)
5758 struct bonding *bond = netdev_priv(bond_dev);
5769 real_dev = bond_option_active_slave_get_rcu(bond);
5787 bond_for_each_slave_rcu(bond, slave, iter) {
5865 .name = "bond",
5870 struct bonding *bond = netdev_priv(bond_dev);
5872 if (bond->wq)
5873 destroy_workqueue(bond->wq);
5875 free_percpu(bond->rr_tx_counter);
5880 struct bonding *bond = netdev_priv(bond_dev);
5882 spin_lock_init(&bond->mode_lock);
5883 bond->params = bonding_defaults;
5886 bond->dev = bond_dev;
5907 INIT_LIST_HEAD(&bond->ipsec_list);
5908 spin_lock_init(&bond->ipsec_lock);
5911 /* don't acquire bond device's netif_tx_lock when transmitting */
5914 /* By default, we declare the bond to be fully
5921 /* Don't allow bond devices to change network namespaces. */
5936 if (BOND_MODE(bond) == BOND_MODE_ACTIVEBACKUP)
5946 struct bonding *bond = netdev_priv(bond_dev);
5953 bond_for_each_slave(bond, slave, iter)
5957 bond_set_slave_arr(bond, NULL, NULL);
5959 list_del(&bond->bond_list);
5961 bond_debug_unregister(bond);
6358 struct bonding *bond = netdev_priv(bond_dev);
6363 bond->wq = alloc_ordered_workqueue(bond_dev->name, WQ_MEM_RECLAIM);
6364 if (!bond->wq)
6367 bond->notifier_ctx = false;
6369 spin_lock_init(&bond->stats_lock);
6372 list_add_tail(&bond->bond_list, &bn->dev_list);
6374 bond_prepare_sysfs_group(bond);
6376 bond_debug_register(bond);
6391 /* Create a new bond based on the specified name and bonding parameters.
6392 * If name is NULL, obtain a suitable "bond%d" name for us.
6399 struct bonding *bond;
6405 name ? name : "bond%d", NET_NAME_UNKNOWN,
6410 bond = netdev_priv(bond_dev);
6422 bond_work_init_all(bond);
6453 /* Kill off any bonds created after unregistering bond rtnl ops */
6456 struct bonding *bond, *tmp_bond;
6459 list_for_each_entry_safe(bond, tmp_bond, &bn->dev_list, bond_list)
6460 unregister_netdevice_queue(bond->dev, &list);