Lines Matching defs: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) {
1285 static bool alb_determine_nd(struct sk_buff *skb, struct bonding *bond)
1307 int bond_alb_initialize(struct bonding *bond, int rlb_enabled)
1311 res = tlb_initialize(bond);
1316 res = rlb_initialize(bond);
1318 tlb_deinitialize(bond);
1321 bond->alb_info.rlb_enabled = 1;
1323 bond->alb_info.rlb_enabled = 0;
1329 void bond_alb_deinitialize(struct bonding *bond)
1331 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
1333 tlb_deinitialize(bond);
1336 rlb_deinitialize(bond);
1339 static netdev_tx_t bond_do_alb_xmit(struct sk_buff *skb, struct bonding *bond,
1342 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
1347 tx_slave = rcu_dereference(bond->curr_active_slave);
1348 if (bond->params.tlb_dynamic_lb)
1353 if (tx_slave != rcu_access_pointer(bond->curr_active_slave)) {
1358 return bond_dev_queue_xmit(bond, skb, tx_slave->dev);
1361 if (tx_slave && bond->params.tlb_dynamic_lb) {
1362 spin_lock(&bond->mode_lock);
1363 __tlb_clear_slave(bond, tx_slave, 0);
1364 spin_unlock(&bond->mode_lock);
1368 return bond_tx_drop(bond->dev, skb);
1371 struct slave *bond_xmit_tlb_slave_get(struct bonding *bond,
1385 if (alb_determine_nd(skb, bond))
1389 hash_index = bond_xmit_hash(bond, skb);
1390 if (bond->params.tlb_dynamic_lb) {
1391 tx_slave = tlb_choose_channel(bond,
1398 slaves = rcu_dereference(bond->usable_slaves);
1412 struct bonding *bond = netdev_priv(bond_dev);
1415 tx_slave = bond_xmit_tlb_slave_get(bond, skb);
1416 return bond_do_alb_xmit(skb, bond, tx_slave);
1419 struct slave *bond_xmit_alb_slave_get(struct bonding *bond,
1422 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
1471 if (alb_determine_nd(skb, bond)) {
1494 tx_slave = rlb_arp_xmit(skb, bond);
1502 if (bond->params.tlb_dynamic_lb) {
1504 tx_slave = tlb_choose_channel(bond, hash_index, skb->len);
1514 slaves = rcu_dereference(bond->usable_slaves);
1517 tx_slave = slaves->arr[bond_xmit_hash(bond, skb) %
1526 struct bonding *bond = netdev_priv(bond_dev);
1529 tx_slave = bond_xmit_alb_slave_get(bond, skb);
1530 return bond_do_alb_xmit(skb, bond, tx_slave);
1535 struct bonding *bond = container_of(work, struct bonding,
1537 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
1541 if (!bond_has_slaves(bond)) {
1553 if (bond_info->lp_counter >= BOND_ALB_LP_TICKS(bond)) {
1556 bond_for_each_slave_rcu(bond, slave, iter) {
1562 strict_match = (slave != rcu_access_pointer(bond->curr_active_slave) ||
1572 bond_for_each_slave_rcu(bond, slave, iter) {
1573 tlb_clear_slave(bond, slave, 1);
1574 if (slave == rcu_access_pointer(bond->curr_active_slave)) {
1601 dev_set_promiscuity(rtnl_dereference(bond->curr_active_slave)->dev,
1611 rlb_rebalance(bond);
1619 rlb_update_rx_clients(bond);
1629 queue_delayed_work(bond->wq, &bond->alb_work, alb_delta_in_ticks);
1632 /* assumption: called before the slave is attached to the bond
1633 * and not locked by the bond lock
1635 int bond_alb_init_slave(struct bonding *bond, struct slave *slave)
1644 res = alb_handle_addr_collision_on_attach(bond, slave);
1651 atomic_set(&bond->alb_info.tx_rebalance_counter,
1654 if (bond->alb_info.rlb_enabled)
1655 bond->alb_info.rlb_rebalance = 1;
1665 void bond_alb_deinit_slave(struct bonding *bond, struct slave *slave)
1667 if (bond_has_slaves(bond))
1668 alb_change_hw_addr_on_detach(bond, slave);
1670 tlb_clear_slave(bond, slave, 0);
1672 if (bond->alb_info.rlb_enabled) {
1673 bond->alb_info.rx_slave = NULL;
1674 rlb_clear_slave(bond, slave);
1679 void bond_alb_handle_link_change(struct bonding *bond, struct slave *slave, char link)
1681 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
1684 tlb_clear_slave(bond, slave, 0);
1685 if (bond->alb_info.rlb_enabled)
1686 rlb_clear_slave(bond, slave);
1691 if (bond->alb_info.rlb_enabled) {
1692 bond->alb_info.rlb_rebalance = 1;
1701 if (bond_is_nondyn_tlb(bond)) {
1702 if (bond_update_slave_arr(bond, NULL))
1709 * @bond: our bonding struct
1712 * Set the bond->curr_active_slave to @new_slave and handle
1717 void bond_alb_handle_active_change(struct bonding *bond, struct slave *new_slave)
1722 curr_active = rtnl_dereference(bond->curr_active_slave);
1726 if (curr_active && bond->alb_info.primary_is_promisc) {
1728 bond->alb_info.primary_is_promisc = 0;
1729 bond->alb_info.rlb_promisc_timeout_counter = 0;
1733 rcu_assign_pointer(bond->curr_active_slave, new_slave);
1735 if (!new_slave || !bond_has_slaves(bond))
1742 swap_slave = bond_slave_has_mac(bond, bond->dev->dev_addr);
1749 tlb_clear_slave(bond, swap_slave, 1);
1750 tlb_clear_slave(bond, new_slave, 1);
1753 * and thus filter bond->dev_addr's packets, so force bond's mac
1755 if (BOND_MODE(bond) == BOND_MODE_TLB) {
1762 bond_hw_addr_copy(ss.__data, bond->dev->dev_addr,
1763 bond->dev->addr_len);
1764 ss.ss_family = bond->dev->type;
1776 alb_fasten_mac_swap(bond, swap_slave, new_slave);
1778 /* set the new_slave to the bond mac address */
1779 alb_set_slave_mac_addr(new_slave, bond->dev->dev_addr,
1780 bond->dev->addr_len);
1781 alb_send_learning_packets(new_slave, bond->dev->dev_addr,
1789 struct bonding *bond = netdev_priv(bond_dev);
1798 res = alb_set_mac_address(bond, addr);
1808 curr_active = rtnl_dereference(bond->curr_active_slave);
1812 swap_slave = bond_slave_has_mac(bond, bond_dev->dev_addr);
1816 alb_fasten_mac_swap(bond, swap_slave, curr_active);
1823 if (bond->alb_info.rlb_enabled) {
1825 rlb_req_update_slave_clients(bond, curr_active);
1832 void bond_alb_clear_vlan(struct bonding *bond, unsigned short vlan_id)
1834 if (bond->alb_info.rlb_enabled)
1835 rlb_clear_vlan(bond, vlan_id);