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;
115 static void tlb_clear_slave(struct bonding *bond, struct slave *slave,
118 spin_lock_bh(&bond->mode_lock);
119 __tlb_clear_slave(bond, slave, save_load);
120 spin_unlock_bh(&bond->mode_lock);
124 static int tlb_initialize(struct bonding *bond)
126 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
135 spin_lock_bh(&bond->mode_lock);
142 spin_unlock_bh(&bond->mode_lock);
148 static void tlb_deinitialize(struct bonding *bond)
150 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
152 spin_lock_bh(&bond->mode_lock);
157 spin_unlock_bh(&bond->mode_lock);
166 static struct slave *tlb_get_least_loaded_slave(struct bonding *bond)
176 bond_for_each_slave_rcu(bond, slave, iter) {
190 static struct slave *__tlb_choose_channel(struct bonding *bond, u32 hash_index,
193 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
200 assigned_slave = tlb_get_least_loaded_slave(bond);
226 static struct slave *tlb_choose_channel(struct bonding *bond, u32 hash_index,
235 spin_lock(&bond->mode_lock);
236 tx_slave = __tlb_choose_channel(bond, hash_index, skb_len);
237 spin_unlock(&bond->mode_lock);
247 static void rlb_update_entry_from_arp(struct bonding *bond, struct arp_pkt *arp)
249 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
253 spin_lock_bh(&bond->mode_lock);
268 spin_unlock_bh(&bond->mode_lock);
271 static int rlb_arp_recv(const struct sk_buff *skb, struct bonding *bond,
285 * itself or on a system that is bridged together with the bond).
293 rlb_purge_src_ip(bond, arp);
297 rlb_update_entry_from_arp(bond, arp);
298 slave_dbg(bond->dev, slave->dev, "Server received an ARP Reply from client\n");
305 static struct slave *__rlb_next_rx_slave(struct bonding *bond)
307 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
312 bond_for_each_slave_rcu(bond, slave, iter) {
338 static struct slave *rlb_next_rx_slave(struct bonding *bond)
345 rx_slave = __rlb_next_rx_slave(bond);
356 static void rlb_teach_disabled_mac_on_primary(struct bonding *bond, u8 addr[])
358 struct slave *curr_active = rtnl_dereference(bond->curr_active_slave);
363 if (!bond->alb_info.primary_is_promisc) {
365 bond->alb_info.primary_is_promisc = 1;
367 bond->alb_info.primary_is_promisc = 0;
370 bond->alb_info.rlb_promisc_timeout_counter = 0;
379 static void rlb_clear_slave(struct bonding *bond, struct slave *slave)
381 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
386 spin_lock_bh(&bond->mode_lock);
393 struct slave *assigned_slave = rlb_next_rx_slave(bond);
416 spin_unlock_bh(&bond->mode_lock);
418 if (slave != rtnl_dereference(bond->curr_active_slave))
419 rlb_teach_disabled_mac_on_primary(bond, slave->dev->dev_addr);
440 slave_err(client_info->slave->bond->dev,
458 static void rlb_update_rx_clients(struct bonding *bond)
460 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
464 spin_lock_bh(&bond->mode_lock);
482 spin_unlock_bh(&bond->mode_lock);
486 static void rlb_req_update_slave_clients(struct bonding *bond, struct slave *slave)
488 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
493 spin_lock_bh(&bond->mode_lock);
514 spin_unlock_bh(&bond->mode_lock);
518 static void rlb_req_update_subnet_clients(struct bonding *bond, __be32 src_ip)
520 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
524 spin_lock(&bond->mode_lock);
532 netdev_err(bond->dev, "found a client with no channel in the client's hash table\n");
541 bond->dev->dev_addr) &&
548 spin_unlock(&bond->mode_lock);
552 struct bonding *bond,
555 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
560 spin_lock(&bond->mode_lock);
562 curr_active_slave = rcu_dereference(bond->curr_active_slave);
579 spin_unlock(&bond->mode_lock);
595 assigned_slave = __rlb_next_rx_slave(bond);
605 rlb_src_unlink(bond, hash_index);
606 rlb_src_link(bond, hash_src, hash_index);
621 bond->alb_info.rx_ntt = 1;
641 spin_unlock(&bond->mode_lock);
650 static struct slave *rlb_arp_xmit(struct sk_buff *skb, struct bonding *bond)
660 * from the bond itself or a VLAN directly above the bond.
662 if (!bond_slave_has_mac_rcu(bond, arp->mac_src))
667 tx_slave = rlb_choose_channel(skb, bond, arp);
671 netdev_dbg(bond->dev, "(slave %s): Server sent ARP Reply packet\n",
679 tx_slave = rlb_choose_channel(skb, bond, arp);
684 bond->alb_info.rlb_update_delay_counter = RLB_UPDATE_DELAY;
691 rlb_req_update_subnet_clients(bond, arp->ip_src);
692 netdev_dbg(bond->dev, "(slave %s): Server sent ARP Request packet\n",
699 static void rlb_rebalance(struct bonding *bond)
701 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
707 spin_lock_bh(&bond->mode_lock);
714 assigned_slave = __rlb_next_rx_slave(bond);
727 spin_unlock_bh(&bond->mode_lock);
753 static void rlb_delete_table_entry_dst(struct bonding *bond, u32 index)
755 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
768 static void rlb_src_unlink(struct bonding *bond, u32 index)
770 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
791 static void rlb_delete_table_entry(struct bonding *bond, u32 index)
793 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
796 rlb_delete_table_entry_dst(bond, index);
799 rlb_src_unlink(bond, index);
805 static void rlb_src_link(struct bonding *bond, u32 ip_src_hash, u32 ip_dst_hash)
807 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
821 static void rlb_purge_src_ip(struct bonding *bond, struct arp_pkt *arp)
823 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
827 spin_lock_bh(&bond->mode_lock);
835 rlb_delete_table_entry(bond, index);
838 spin_unlock_bh(&bond->mode_lock);
841 static int rlb_initialize(struct bonding *bond)
843 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
852 spin_lock_bh(&bond->mode_lock);
861 spin_unlock_bh(&bond->mode_lock);
864 bond->recv_probe = rlb_arp_recv;
869 static void rlb_deinitialize(struct bonding *bond)
871 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
873 spin_lock_bh(&bond->mode_lock);
879 spin_unlock_bh(&bond->mode_lock);
882 static void rlb_clear_vlan(struct bonding *bond, unsigned short vlan_id)
884 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
887 spin_lock_bh(&bond->mode_lock);
895 rlb_delete_table_entry(bond, curr_index);
900 spin_unlock_bh(&bond->mode_lock);
929 slave_dbg(slave->bond->dev, slave->dev,
939 struct bonding *bond;
950 struct bonding *bond = data->bond;
956 bond->dev->lower_level == upper->lower_level - 1) {
972 tags = bond_verify_device_path(bond->dev, upper, 0);
987 struct bonding *bond = bond_get_bond_by_slave(slave);
993 .bond = bond,
1004 netdev_walk_all_upper_dev_rcu(bond->dev, alb_upper_dev_walk, &priv);
1014 if (BOND_MODE(slave->bond) == BOND_MODE_TLB) {
1025 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");
1052 static void alb_fasten_mac_swap(struct bonding *bond, struct slave *slave1,
1063 if (bond->alb_info.rlb_enabled) {
1067 rlb_req_update_slave_clients(bond, slave1);
1075 if (bond->alb_info.rlb_enabled) {
1079 rlb_req_update_slave_clients(bond, slave2);
1085 if (bond->alb_info.rlb_enabled && slaves_state_differ) {
1087 rlb_teach_disabled_mac_on_primary(bond,
1094 * @bond: bonding we're working on
1100 * address and from @bond's address, then somewhere in the bond there's
1106 static void alb_change_hw_addr_on_detach(struct bonding *bond, struct slave *slave)
1115 bond->dev->dev_addr);
1118 found_slave = bond_slave_has_mac(bond, slave->perm_hwaddr);
1122 alb_fasten_mac_swap(bond, slave, found_slave);
1129 * @bond: bonding we're working on
1135 * If the permanent hw address of @slave is @bond's hw address, we need to
1137 * slave in the bond. This address must be, of course, one of the permanent
1143 * that isn't used by any other slave in the bond, so we can assign it to
1147 * bond slave list.
1149 static int alb_handle_addr_collision_on_attach(struct bonding *bond, struct slave *slave)
1151 struct slave *has_bond_addr = rcu_access_pointer(bond->curr_active_slave);
1155 if (!bond_has_slaves(bond)) {
1160 /* if slave's mac address differs from bond's mac address
1162 * slaves in the bond.
1164 if (!ether_addr_equal_64bits(slave->perm_hwaddr, bond->dev->dev_addr)) {
1165 if (!bond_slave_has_mac(bond, slave->dev->dev_addr))
1168 /* Try setting slave mac to bond address and fall-through
1171 alb_set_slave_mac_addr(slave, bond->dev->dev_addr,
1172 bond->dev->addr_len);
1175 /* The slave's address is equal to the address of the bond.
1176 * Search for a spare address in the bond for this slave.
1178 bond_for_each_slave(bond, tmp_slave1, iter) {
1179 if (!bond_slave_has_mac(bond, tmp_slave1->perm_hwaddr)) {
1189 bond->dev->dev_addr)) {
1200 slave_warn(bond->dev, slave->dev, "the slave hw address is in use by the bond; giving it the hw address of %s\n",
1204 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");
1213 * @bond: bonding we're working on
1216 * In TLB mode all slaves are configured to the bond's hw address, but set
1223 * Unwinding assumes bond's mac address has not yet changed.
1225 static int alb_set_mac_address(struct bonding *bond, void *addr)
1233 if (bond->alb_info.rlb_enabled)
1236 bond_for_each_slave(bond, slave, iter) {
1254 memcpy(ss.__data, bond->dev->dev_addr, bond->dev->addr_len);
1255 ss.ss_family = bond->dev->type;
1258 bond_for_each_slave(bond, rollback_slave, iter) {
1274 int bond_alb_initialize(struct bonding *bond, int rlb_enabled)
1278 res = tlb_initialize(bond);
1283 res = rlb_initialize(bond);
1285 tlb_deinitialize(bond);
1288 bond->alb_info.rlb_enabled = 1;
1290 bond->alb_info.rlb_enabled = 0;
1296 void bond_alb_deinitialize(struct bonding *bond)
1298 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
1300 tlb_deinitialize(bond);
1303 rlb_deinitialize(bond);
1306 static netdev_tx_t bond_do_alb_xmit(struct sk_buff *skb, struct bonding *bond,
1309 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
1314 tx_slave = rcu_dereference(bond->curr_active_slave);
1315 if (bond->params.tlb_dynamic_lb)
1320 if (tx_slave != rcu_access_pointer(bond->curr_active_slave)) {
1325 return bond_dev_queue_xmit(bond, skb, tx_slave->dev);
1328 if (tx_slave && bond->params.tlb_dynamic_lb) {
1329 spin_lock(&bond->mode_lock);
1330 __tlb_clear_slave(bond, tx_slave, 0);
1331 spin_unlock(&bond->mode_lock);
1335 return bond_tx_drop(bond->dev, skb);
1338 struct slave *bond_xmit_tlb_slave_get(struct bonding *bond,
1355 hash_index = bond_xmit_hash(bond, skb);
1356 if (bond->params.tlb_dynamic_lb) {
1357 tx_slave = tlb_choose_channel(bond,
1364 slaves = rcu_dereference(bond->usable_slaves);
1378 struct bonding *bond = netdev_priv(bond_dev);
1381 tx_slave = bond_xmit_tlb_slave_get(bond, skb);
1382 return bond_do_alb_xmit(skb, bond, tx_slave);
1385 struct slave *bond_xmit_alb_slave_get(struct bonding *bond,
1388 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
1487 tx_slave = rlb_arp_xmit(skb, bond);
1495 if (bond->params.tlb_dynamic_lb) {
1497 tx_slave = tlb_choose_channel(bond, hash_index, skb->len);
1507 slaves = rcu_dereference(bond->usable_slaves);
1510 tx_slave = slaves->arr[bond_xmit_hash(bond, skb) %
1519 struct bonding *bond = netdev_priv(bond_dev);
1522 tx_slave = bond_xmit_alb_slave_get(bond, skb);
1523 return bond_do_alb_xmit(skb, bond, tx_slave);
1528 struct bonding *bond = container_of(work, struct bonding,
1530 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
1534 if (!bond_has_slaves(bond)) {
1546 if (bond_info->lp_counter >= BOND_ALB_LP_TICKS(bond)) {
1549 bond_for_each_slave_rcu(bond, slave, iter) {
1555 strict_match = (slave != rcu_access_pointer(bond->curr_active_slave) ||
1565 bond_for_each_slave_rcu(bond, slave, iter) {
1566 tlb_clear_slave(bond, slave, 1);
1567 if (slave == rcu_access_pointer(bond->curr_active_slave)) {
1594 dev_set_promiscuity(rtnl_dereference(bond->curr_active_slave)->dev,
1604 rlb_rebalance(bond);
1612 rlb_update_rx_clients(bond);
1622 queue_delayed_work(bond->wq, &bond->alb_work, alb_delta_in_ticks);
1625 /* assumption: called before the slave is attached to the bond
1626 * and not locked by the bond lock
1628 int bond_alb_init_slave(struct bonding *bond, struct slave *slave)
1637 res = alb_handle_addr_collision_on_attach(bond, slave);
1644 atomic_set(&bond->alb_info.tx_rebalance_counter,
1647 if (bond->alb_info.rlb_enabled)
1648 bond->alb_info.rlb_rebalance = 1;
1658 void bond_alb_deinit_slave(struct bonding *bond, struct slave *slave)
1660 if (bond_has_slaves(bond))
1661 alb_change_hw_addr_on_detach(bond, slave);
1663 tlb_clear_slave(bond, slave, 0);
1665 if (bond->alb_info.rlb_enabled) {
1666 bond->alb_info.rx_slave = NULL;
1667 rlb_clear_slave(bond, slave);
1672 void bond_alb_handle_link_change(struct bonding *bond, struct slave *slave, char link)
1674 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
1677 tlb_clear_slave(bond, slave, 0);
1678 if (bond->alb_info.rlb_enabled)
1679 rlb_clear_slave(bond, slave);
1684 if (bond->alb_info.rlb_enabled) {
1685 bond->alb_info.rlb_rebalance = 1;
1694 if (bond_is_nondyn_tlb(bond)) {
1695 if (bond_update_slave_arr(bond, NULL))
1702 * @bond: our bonding struct
1705 * Set the bond->curr_active_slave to @new_slave and handle
1710 void bond_alb_handle_active_change(struct bonding *bond, struct slave *new_slave)
1715 curr_active = rtnl_dereference(bond->curr_active_slave);
1719 if (curr_active && bond->alb_info.primary_is_promisc) {
1721 bond->alb_info.primary_is_promisc = 0;
1722 bond->alb_info.rlb_promisc_timeout_counter = 0;
1726 rcu_assign_pointer(bond->curr_active_slave, new_slave);
1728 if (!new_slave || !bond_has_slaves(bond))
1735 swap_slave = bond_slave_has_mac(bond, bond->dev->dev_addr);
1742 tlb_clear_slave(bond, swap_slave, 1);
1743 tlb_clear_slave(bond, new_slave, 1);
1746 * and thus filter bond->dev_addr's packets, so force bond's mac
1748 if (BOND_MODE(bond) == BOND_MODE_TLB) {
1755 bond_hw_addr_copy(ss.__data, bond->dev->dev_addr,
1756 bond->dev->addr_len);
1757 ss.ss_family = bond->dev->type;
1770 alb_fasten_mac_swap(bond, swap_slave, new_slave);
1772 /* set the new_slave to the bond mac address */
1773 alb_set_slave_mac_addr(new_slave, bond->dev->dev_addr,
1774 bond->dev->addr_len);
1775 alb_send_learning_packets(new_slave, bond->dev->dev_addr,
1783 struct bonding *bond = netdev_priv(bond_dev);
1792 res = alb_set_mac_address(bond, addr);
1802 curr_active = rtnl_dereference(bond->curr_active_slave);
1806 swap_slave = bond_slave_has_mac(bond, bond_dev->dev_addr);
1810 alb_fasten_mac_swap(bond, swap_slave, curr_active);
1817 if (bond->alb_info.rlb_enabled) {
1819 rlb_req_update_slave_clients(bond, curr_active);
1826 void bond_alb_clear_vlan(struct bonding *bond, unsigned short vlan_id)
1828 if (bond->alb_info.rlb_enabled)
1829 rlb_clear_vlan(bond, vlan_id);