Lines Matching refs:bond
56 static void rlb_purge_src_ip(struct bonding *bond, struct arp_pkt *arp);
57 static void rlb_src_unlink(struct bonding *bond, u32 index);
58 static void rlb_src_link(struct bonding *bond, u32 ip_src_hash,
93 static void __tlb_clear_slave(struct bonding *bond, struct slave *slave,
100 tx_hash_table = BOND_ALB_INFO(bond).tx_hashtbl;
116 static void tlb_clear_slave(struct bonding *bond, struct slave *slave,
119 spin_lock_bh(&bond->mode_lock);
120 __tlb_clear_slave(bond, slave, save_load);
121 spin_unlock_bh(&bond->mode_lock);
125 static int tlb_initialize(struct bonding *bond)
127 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
136 spin_lock_bh(&bond->mode_lock);
143 spin_unlock_bh(&bond->mode_lock);
149 static void tlb_deinitialize(struct bonding *bond)
151 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
153 spin_lock_bh(&bond->mode_lock);
158 spin_unlock_bh(&bond->mode_lock);
167 static struct slave *tlb_get_least_loaded_slave(struct bonding *bond)
177 bond_for_each_slave_rcu(bond, slave, iter) {
191 static struct slave *__tlb_choose_channel(struct bonding *bond, u32 hash_index,
194 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
201 assigned_slave = tlb_get_least_loaded_slave(bond);
227 static struct slave *tlb_choose_channel(struct bonding *bond, u32 hash_index,
236 spin_lock(&bond->mode_lock);
237 tx_slave = __tlb_choose_channel(bond, hash_index, skb_len);
238 spin_unlock(&bond->mode_lock);
248 static void rlb_update_entry_from_arp(struct bonding *bond, struct arp_pkt *arp)
250 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
254 spin_lock_bh(&bond->mode_lock);
269 spin_unlock_bh(&bond->mode_lock);
272 static int rlb_arp_recv(const struct sk_buff *skb, struct bonding *bond,
286 * itself or on a system that is bridged together with the bond).
294 rlb_purge_src_ip(bond, arp);
298 rlb_update_entry_from_arp(bond, arp);
299 slave_dbg(bond->dev, slave->dev, "Server received an ARP Reply from client\n");
306 static struct slave *__rlb_next_rx_slave(struct bonding *bond)
308 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
313 bond_for_each_slave_rcu(bond, slave, iter) {
339 static struct slave *rlb_next_rx_slave(struct bonding *bond)
346 rx_slave = __rlb_next_rx_slave(bond);
357 static void rlb_teach_disabled_mac_on_primary(struct bonding *bond,
360 struct slave *curr_active = rtnl_dereference(bond->curr_active_slave);
365 if (!bond->alb_info.primary_is_promisc) {
367 bond->alb_info.primary_is_promisc = 1;
369 bond->alb_info.primary_is_promisc = 0;
372 bond->alb_info.rlb_promisc_timeout_counter = 0;
381 static void rlb_clear_slave(struct bonding *bond, struct slave *slave)
383 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
388 spin_lock_bh(&bond->mode_lock);
395 struct slave *assigned_slave = rlb_next_rx_slave(bond);
418 spin_unlock_bh(&bond->mode_lock);
420 if (slave != rtnl_dereference(bond->curr_active_slave))
421 rlb_teach_disabled_mac_on_primary(bond, slave->dev->dev_addr);
442 slave_err(client_info->slave->bond->dev,
460 static void rlb_update_rx_clients(struct bonding *bond)
462 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
466 spin_lock_bh(&bond->mode_lock);
484 spin_unlock_bh(&bond->mode_lock);
488 static void rlb_req_update_slave_clients(struct bonding *bond, struct slave *slave)
490 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
495 spin_lock_bh(&bond->mode_lock);
516 spin_unlock_bh(&bond->mode_lock);
520 static void rlb_req_update_subnet_clients(struct bonding *bond, __be32 src_ip)
522 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
526 spin_lock(&bond->mode_lock);
534 netdev_err(bond->dev, "found a client with no channel in the client's hash table\n");
543 bond->dev->dev_addr) &&
550 spin_unlock(&bond->mode_lock);
554 struct bonding *bond,
557 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
562 spin_lock(&bond->mode_lock);
564 curr_active_slave = rcu_dereference(bond->curr_active_slave);
581 spin_unlock(&bond->mode_lock);
597 assigned_slave = __rlb_next_rx_slave(bond);
607 rlb_src_unlink(bond, hash_index);
608 rlb_src_link(bond, hash_src, hash_index);
623 bond->alb_info.rx_ntt = 1;
644 spin_unlock(&bond->mode_lock);
653 static struct slave *rlb_arp_xmit(struct sk_buff *skb, struct bonding *bond)
664 * from the bond itself or a VLAN directly above the bond.
666 if (!bond_slave_has_mac_rcu(bond, arp->mac_src))
669 dev = ip_dev_find(dev_net(bond->dev), arp->ip_src);
680 tx_slave = rlb_choose_channel(skb, bond, arp);
684 netdev_dbg(bond->dev, "(slave %s): Server sent ARP Reply packet\n",
692 tx_slave = rlb_choose_channel(skb, bond, arp);
697 bond->alb_info.rlb_update_delay_counter = RLB_UPDATE_DELAY;
704 rlb_req_update_subnet_clients(bond, arp->ip_src);
705 netdev_dbg(bond->dev, "(slave %s): Server sent ARP Request packet\n",
712 static void rlb_rebalance(struct bonding *bond)
714 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
720 spin_lock_bh(&bond->mode_lock);
727 assigned_slave = __rlb_next_rx_slave(bond);
740 spin_unlock_bh(&bond->mode_lock);
766 static void rlb_delete_table_entry_dst(struct bonding *bond, u32 index)
768 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
781 static void rlb_src_unlink(struct bonding *bond, u32 index)
783 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
804 static void rlb_delete_table_entry(struct bonding *bond, u32 index)
806 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
809 rlb_delete_table_entry_dst(bond, index);
812 rlb_src_unlink(bond, index);
818 static void rlb_src_link(struct bonding *bond, u32 ip_src_hash, u32 ip_dst_hash)
820 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
834 static void rlb_purge_src_ip(struct bonding *bond, struct arp_pkt *arp)
836 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
840 spin_lock_bh(&bond->mode_lock);
849 rlb_delete_table_entry(bond, index);
852 spin_unlock_bh(&bond->mode_lock);
855 static int rlb_initialize(struct bonding *bond)
857 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
866 spin_lock_bh(&bond->mode_lock);
875 spin_unlock_bh(&bond->mode_lock);
878 bond->recv_probe = rlb_arp_recv;
883 static void rlb_deinitialize(struct bonding *bond)
885 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
887 spin_lock_bh(&bond->mode_lock);
893 spin_unlock_bh(&bond->mode_lock);
896 static void rlb_clear_vlan(struct bonding *bond, unsigned short vlan_id)
898 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
901 spin_lock_bh(&bond->mode_lock);
909 rlb_delete_table_entry(bond, curr_index);
914 spin_unlock_bh(&bond->mode_lock);
943 slave_dbg(slave->bond->dev, slave->dev,
953 struct bonding *bond;
965 struct bonding *bond = data->bond;
970 bond->dev->lower_level == upper->lower_level - 1) {
986 tags = bond_verify_device_path(bond->dev, upper, 0);
1001 struct bonding *bond = bond_get_bond_by_slave(slave);
1007 .bond = bond,
1018 netdev_walk_all_upper_dev_rcu(bond->dev, alb_upper_dev_walk, &priv);
1028 if (BOND_MODE(slave->bond) == BOND_MODE_TLB) {
1039 slave_err(slave->bond->dev, dev, "dev_set_mac_address on slave failed! ALB mode requires that the base driver support setting the hw address also when the network device's interface is open\n");
1066 static void alb_fasten_mac_swap(struct bonding *bond, struct slave *slave1,
1077 if (bond->alb_info.rlb_enabled) {
1081 rlb_req_update_slave_clients(bond, slave1);
1089 if (bond->alb_info.rlb_enabled) {
1093 rlb_req_update_slave_clients(bond, slave2);
1099 if (bond->alb_info.rlb_enabled && slaves_state_differ) {
1101 rlb_teach_disabled_mac_on_primary(bond,
1108 * @bond: bonding we're working on
1114 * address and from @bond's address, then somewhere in the bond there's
1120 static void alb_change_hw_addr_on_detach(struct bonding *bond, struct slave *slave)
1129 bond->dev->dev_addr);
1132 found_slave = bond_slave_has_mac(bond, slave->perm_hwaddr);
1136 alb_fasten_mac_swap(bond, slave, found_slave);
1143 * @bond: bonding we're working on
1149 * If the permanent hw address of @slave is @bond's hw address, we need to
1151 * slave in the bond. This address must be, of course, one of the permanent
1157 * that isn't used by any other slave in the bond, so we can assign it to
1161 * bond slave list.
1163 static int alb_handle_addr_collision_on_attach(struct bonding *bond, struct slave *slave)
1165 struct slave *has_bond_addr = rcu_access_pointer(bond->curr_active_slave);
1169 if (!bond_has_slaves(bond)) {
1174 /* if slave's mac address differs from bond's mac address
1176 * slaves in the bond.
1178 if (!ether_addr_equal_64bits(slave->perm_hwaddr, bond->dev->dev_addr)) {
1179 if (!bond_slave_has_mac(bond, slave->dev->dev_addr))
1182 /* Try setting slave mac to bond address and fall-through
1185 alb_set_slave_mac_addr(slave, bond->dev->dev_addr,
1186 bond->dev->addr_len);
1189 /* The slave's address is equal to the address of the bond.
1190 * Search for a spare address in the bond for this slave.
1192 bond_for_each_slave(bond, tmp_slave1, iter) {
1193 if (!bond_slave_has_mac(bond, tmp_slave1->perm_hwaddr)) {
1203 bond->dev->dev_addr)) {
1214 slave_warn(bond->dev, slave->dev, "the slave hw address is in use by the bond; giving it the hw address of %s\n",
1218 slave_err(bond->dev, slave->dev, "the slave hw address is in use by the bond; couldn't find a slave with a free hw address to give it (this should not have happened)\n");
1227 * @bond: bonding we're working on
1230 * In TLB mode all slaves are configured to the bond's hw address, but set
1237 * Unwinding assumes bond's mac address has not yet changed.
1239 static int alb_set_mac_address(struct bonding *bond, void *addr)
1247 if (bond->alb_info.rlb_enabled)
1250 bond_for_each_slave(bond, slave, iter) {
1267 memcpy(ss.__data, bond->dev->dev_addr, bond->dev->addr_len);
1268 ss.ss_family = bond->dev->type;
1271 bond_for_each_slave(bond, rollback_slave, iter) {
1284 static bool alb_determine_nd(struct sk_buff *skb, struct bonding *bond)
1306 int bond_alb_initialize(struct bonding *bond, int rlb_enabled)
1310 res = tlb_initialize(bond);
1315 res = rlb_initialize(bond);
1317 tlb_deinitialize(bond);
1320 bond->alb_info.rlb_enabled = 1;
1322 bond->alb_info.rlb_enabled = 0;
1328 void bond_alb_deinitialize(struct bonding *bond)
1330 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
1332 tlb_deinitialize(bond);
1335 rlb_deinitialize(bond);
1338 static netdev_tx_t bond_do_alb_xmit(struct sk_buff *skb, struct bonding *bond,
1341 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
1346 tx_slave = rcu_dereference(bond->curr_active_slave);
1347 if (bond->params.tlb_dynamic_lb)
1352 if (tx_slave != rcu_access_pointer(bond->curr_active_slave)) {
1357 return bond_dev_queue_xmit(bond, skb, tx_slave->dev);
1360 if (tx_slave && bond->params.tlb_dynamic_lb) {
1361 spin_lock(&bond->mode_lock);
1362 __tlb_clear_slave(bond, tx_slave, 0);
1363 spin_unlock(&bond->mode_lock);
1367 return bond_tx_drop(bond->dev, skb);
1370 struct slave *bond_xmit_tlb_slave_get(struct bonding *bond,
1384 if (alb_determine_nd(skb, bond))
1388 hash_index = bond_xmit_hash(bond, skb);
1389 if (bond->params.tlb_dynamic_lb) {
1390 tx_slave = tlb_choose_channel(bond,
1397 slaves = rcu_dereference(bond->usable_slaves);
1411 struct bonding *bond = netdev_priv(bond_dev);
1414 tx_slave = bond_xmit_tlb_slave_get(bond, skb);
1415 return bond_do_alb_xmit(skb, bond, tx_slave);
1418 struct slave *bond_xmit_alb_slave_get(struct bonding *bond,
1421 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
1470 if (alb_determine_nd(skb, bond)) {
1493 tx_slave = rlb_arp_xmit(skb, bond);
1501 if (bond->params.tlb_dynamic_lb) {
1503 tx_slave = tlb_choose_channel(bond, hash_index, skb->len);
1513 slaves = rcu_dereference(bond->usable_slaves);
1516 tx_slave = slaves->arr[bond_xmit_hash(bond, skb) %
1525 struct bonding *bond = netdev_priv(bond_dev);
1528 tx_slave = bond_xmit_alb_slave_get(bond, skb);
1529 return bond_do_alb_xmit(skb, bond, tx_slave);
1534 struct bonding *bond = container_of(work, struct bonding,
1536 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
1540 if (!bond_has_slaves(bond)) {
1552 if (bond_info->lp_counter >= BOND_ALB_LP_TICKS(bond)) {
1555 bond_for_each_slave_rcu(bond, slave, iter) {
1561 strict_match = (slave != rcu_access_pointer(bond->curr_active_slave) ||
1571 bond_for_each_slave_rcu(bond, slave, iter) {
1572 tlb_clear_slave(bond, slave, 1);
1573 if (slave == rcu_access_pointer(bond->curr_active_slave)) {
1600 dev_set_promiscuity(rtnl_dereference(bond->curr_active_slave)->dev,
1610 rlb_rebalance(bond);
1618 rlb_update_rx_clients(bond);
1628 queue_delayed_work(bond->wq, &bond->alb_work, alb_delta_in_ticks);
1631 /* assumption: called before the slave is attached to the bond
1632 * and not locked by the bond lock
1634 int bond_alb_init_slave(struct bonding *bond, struct slave *slave)
1643 res = alb_handle_addr_collision_on_attach(bond, slave);
1650 atomic_set(&bond->alb_info.tx_rebalance_counter,
1653 if (bond->alb_info.rlb_enabled)
1654 bond->alb_info.rlb_rebalance = 1;
1664 void bond_alb_deinit_slave(struct bonding *bond, struct slave *slave)
1666 if (bond_has_slaves(bond))
1667 alb_change_hw_addr_on_detach(bond, slave);
1669 tlb_clear_slave(bond, slave, 0);
1671 if (bond->alb_info.rlb_enabled) {
1672 bond->alb_info.rx_slave = NULL;
1673 rlb_clear_slave(bond, slave);
1678 void bond_alb_handle_link_change(struct bonding *bond, struct slave *slave, char link)
1680 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
1683 tlb_clear_slave(bond, slave, 0);
1684 if (bond->alb_info.rlb_enabled)
1685 rlb_clear_slave(bond, slave);
1690 if (bond->alb_info.rlb_enabled) {
1691 bond->alb_info.rlb_rebalance = 1;
1700 if (bond_is_nondyn_tlb(bond)) {
1701 if (bond_update_slave_arr(bond, NULL))
1708 * @bond: our bonding struct
1711 * Set the bond->curr_active_slave to @new_slave and handle
1716 void bond_alb_handle_active_change(struct bonding *bond, struct slave *new_slave)
1721 curr_active = rtnl_dereference(bond->curr_active_slave);
1725 if (curr_active && bond->alb_info.primary_is_promisc) {
1727 bond->alb_info.primary_is_promisc = 0;
1728 bond->alb_info.rlb_promisc_timeout_counter = 0;
1732 rcu_assign_pointer(bond->curr_active_slave, new_slave);
1734 if (!new_slave || !bond_has_slaves(bond))
1741 swap_slave = bond_slave_has_mac(bond, bond->dev->dev_addr);
1748 tlb_clear_slave(bond, swap_slave, 1);
1749 tlb_clear_slave(bond, new_slave, 1);
1752 * and thus filter bond->dev_addr's packets, so force bond's mac
1754 if (BOND_MODE(bond) == BOND_MODE_TLB) {
1761 bond_hw_addr_copy(ss.__data, bond->dev->dev_addr,
1762 bond->dev->addr_len);
1763 ss.ss_family = bond->dev->type;
1774 alb_fasten_mac_swap(bond, swap_slave, new_slave);
1776 /* set the new_slave to the bond mac address */
1777 alb_set_slave_mac_addr(new_slave, bond->dev->dev_addr,
1778 bond->dev->addr_len);
1779 alb_send_learning_packets(new_slave, bond->dev->dev_addr,
1787 struct bonding *bond = netdev_priv(bond_dev);
1796 res = alb_set_mac_address(bond, addr);
1806 curr_active = rtnl_dereference(bond->curr_active_slave);
1810 swap_slave = bond_slave_has_mac(bond, bond_dev->dev_addr);
1814 alb_fasten_mac_swap(bond, swap_slave, curr_active);
1821 if (bond->alb_info.rlb_enabled) {
1823 rlb_req_update_slave_clients(bond, curr_active);
1830 void bond_alb_clear_vlan(struct bonding *bond, unsigned short vlan_id)
1832 if (bond->alb_info.rlb_enabled)
1833 rlb_clear_vlan(bond, vlan_id);