Lines Matching +full:primary +full:- +full:bond

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright(c) 1999 - 2004 Intel Corporation. All rights reserved.
37 u8 padding[ETH_ZLEN - ETH_HLEN];
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,
77 entry->load_history = 1 + entry->tx_bytes /
79 entry->tx_bytes = 0;
82 entry->tx_slave = NULL;
83 entry->next = TLB_NULL_INDEX;
84 entry->prev = TLB_NULL_INDEX;
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));
134 return -ENOMEM;
136 spin_lock_bh(&bond->mode_lock);
138 bond_info->tx_hashtbl = new_hashtbl;
141 tlb_init_table_entry(&bond_info->tx_hashtbl[i], 0);
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);
155 kfree(bond_info->tx_hashtbl);
156 bond_info->tx_hashtbl = NULL;
158 spin_unlock_bh(&bond->mode_lock);
163 return (s64) (slave->speed << 20) - /* Convert to Megabit per sec */
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));
198 hash_table = bond_info->tx_hashtbl;
201 assigned_slave = tlb_get_least_loaded_slave(bond);
206 u32 next_index = slave_info->head;
215 slave_info->head = hash_index;
216 slave_info->load +=
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);
256 hash_index = _simple_hash((u8 *)&(arp->ip_src), sizeof(arp->ip_src));
257 client_info = &(bond_info->rx_hashtbl[hash_index]);
259 if ((client_info->assigned) &&
260 (client_info->ip_src == arp->ip_dst) &&
261 (client_info->ip_dst == arp->ip_src) &&
262 (!ether_addr_equal_64bits(client_info->mac_dst, arp->mac_src))) {
264 ether_addr_copy(client_info->mac_dst, arp->mac_src);
265 client_info->ntt = 1;
266 bond_info->rx_ntt = 1;
269 spin_unlock_bh(&bond->mode_lock);
272 static int rlb_arp_recv(const struct sk_buff *skb, struct bonding *bond,
277 if (skb->protocol != cpu_to_be16(ETH_P_ARP))
284 /* We received an ARP from arp->ip_src.
286 * itself or on a system that is bridged together with the bond).
287 * However, if arp->mac_src is different than what is stored in
294 rlb_purge_src_ip(bond, arp);
296 if (arp->op_code == htons(ARPOP_REPLY)) {
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) {
317 if (!before || before->speed < slave->speed)
320 if (!rx_slave || rx_slave->speed < slave->speed)
323 if (slave == bond_info->rx_slave)
329 if (!rx_slave || (before && rx_slave->speed < before->speed))
333 bond_info->rx_slave = rx_slave;
339 static struct slave *rlb_next_rx_slave(struct bonding *bond)
346 rx_slave = __rlb_next_rx_slave(bond);
353 * on the primary for fault tolerance
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) {
366 if (!dev_set_promiscuity(curr_active->dev, 1))
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);
390 rx_hash_table = bond_info->rx_hashtbl;
391 index = bond_info->rx_hashtbl_used_head;
395 struct slave *assigned_slave = rlb_next_rx_slave(bond);
400 bond_info->rx_hashtbl[index].ntt = 1;
401 bond_info->rx_ntt = 1;
409 bond_info->rlb_update_retry_counter =
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);
428 if (!client_info->slave || !is_valid_ether_addr(client_info->mac_dst))
435 client_info->ip_dst,
436 client_info->slave->dev,
437 client_info->ip_src,
438 client_info->mac_dst,
439 client_info->slave->dev->dev_addr,
440 client_info->mac_dst);
442 slave_err(client_info->slave->bond->dev,
443 client_info->slave->dev,
448 skb->dev = client_info->slave->dev;
450 if (client_info->vlan_id) {
452 client_info->vlan_id);
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);
468 hash_index = bond_info->rx_hashtbl_used_head;
470 hash_index = client_info->used_next) {
471 client_info = &(bond_info->rx_hashtbl[hash_index]);
472 if (client_info->ntt) {
474 if (bond_info->rlb_update_retry_counter == 0)
475 client_info->ntt = 0;
482 bond_info->rlb_update_delay_counter = RLB_UPDATE_DELAY;
484 spin_unlock_bh(&bond->mode_lock);
487 /* The slave was assigned a new mac address - update the clients */
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);
497 hash_index = bond_info->rx_hashtbl_used_head;
499 hash_index = client_info->used_next) {
500 client_info = &(bond_info->rx_hashtbl[hash_index]);
502 if ((client_info->slave == slave) &&
503 is_valid_ether_addr(client_info->mac_dst)) {
504 client_info->ntt = 1;
511 bond_info->rx_ntt = 1;
513 bond_info->rlb_update_retry_counter = RLB_UPDATE_RETRY;
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);
528 hash_index = bond_info->rx_hashtbl_used_head;
530 hash_index = client_info->used_next) {
531 client_info = &(bond_info->rx_hashtbl[hash_index]);
533 if (!client_info->slave) {
534 netdev_err(bond->dev, "found a client with no channel in the client's hash table\n");
541 if ((client_info->ip_src == src_ip) &&
542 !ether_addr_equal_64bits(client_info->slave->dev->dev_addr,
543 bond->dev->dev_addr) &&
544 is_valid_ether_addr(client_info->mac_dst)) {
545 client_info->ntt = 1;
546 bond_info->rx_ntt = 1;
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);
566 hash_index = _simple_hash((u8 *)&arp->ip_dst, sizeof(arp->ip_dst));
567 client_info = &(bond_info->rx_hashtbl[hash_index]);
569 if (client_info->assigned) {
570 if ((client_info->ip_src == arp->ip_src) &&
571 (client_info->ip_dst == arp->ip_dst)) {
573 if (!is_broadcast_ether_addr(arp->mac_dst)) {
575 ether_addr_copy(client_info->mac_dst, arp->mac_dst);
577 ether_addr_copy(client_info->mac_src, arp->mac_src);
579 assigned_slave = client_info->slave;
581 spin_unlock(&bond->mode_lock);
586 * move the old client to primary (curr_active_slave) so
590 client_info->slave != curr_active_slave) {
591 client_info->slave = curr_active_slave;
597 assigned_slave = __rlb_next_rx_slave(bond);
600 if (!(client_info->assigned &&
601 client_info->ip_src == arp->ip_src)) {
605 u32 hash_src = _simple_hash((u8 *)&arp->ip_src,
606 sizeof(arp->ip_src));
607 rlb_src_unlink(bond, hash_index);
608 rlb_src_link(bond, hash_src, hash_index);
611 client_info->ip_src = arp->ip_src;
612 client_info->ip_dst = arp->ip_dst;
613 /* arp->mac_dst is broadcast for arp requests.
617 ether_addr_copy(client_info->mac_dst, arp->mac_dst);
618 ether_addr_copy(client_info->mac_src, arp->mac_src);
619 client_info->slave = assigned_slave;
621 if (is_valid_ether_addr(client_info->mac_dst)) {
622 client_info->ntt = 1;
623 bond->alb_info.rx_ntt = 1;
625 client_info->ntt = 0;
628 if (vlan_get_tag(skb, &client_info->vlan_id))
629 client_info->vlan_id = 0;
631 if (!client_info->assigned) {
632 u32 prev_tbl_head = bond_info->rx_hashtbl_used_head;
634 bond_info->rx_hashtbl_used_head = hash_index;
635 client_info->used_next = prev_tbl_head;
637 bond_info->rx_hashtbl[prev_tbl_head].used_prev =
640 client_info->assigned = 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);
678 if (arp->op_code == htons(ARPOP_REPLY)) {
680 tx_slave = rlb_choose_channel(skb, bond, arp);
682 bond_hw_addr_copy(arp->mac_src, tx_slave->dev->dev_addr,
683 tx_slave->dev->addr_len);
684 netdev_dbg(bond->dev, "(slave %s): Server sent ARP Reply packet\n",
685 tx_slave ? tx_slave->dev->name : "NULL");
686 } else if (arp->op_code == htons(ARPOP_REQUEST)) {
692 tx_slave = rlb_choose_channel(skb, bond, arp);
697 bond->alb_info.rlb_update_delay_counter = RLB_UPDATE_DELAY;
699 /* arp requests are broadcast and are sent on the primary
701 * the primary slave. We must register these clients to be
704 rlb_req_update_subnet_clients(bond, arp->ip_src);
705 netdev_dbg(bond->dev, "(slave %s): Server sent ARP Request packet\n",
706 tx_slave ? tx_slave->dev->name : "NULL");
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);
723 hash_index = bond_info->rx_hashtbl_used_head;
725 hash_index = client_info->used_next) {
726 client_info = &(bond_info->rx_hashtbl[hash_index]);
727 assigned_slave = __rlb_next_rx_slave(bond);
728 if (assigned_slave && (client_info->slave != assigned_slave)) {
729 client_info->slave = assigned_slave;
730 if (!is_zero_ether_addr(client_info->mac_dst)) {
731 client_info->ntt = 1;
739 bond_info->rx_ntt = 1;
740 spin_unlock_bh(&bond->mode_lock);
746 entry->used_next = RLB_NULL_INDEX;
747 entry->used_prev = RLB_NULL_INDEX;
748 entry->assigned = 0;
749 entry->slave = NULL;
750 entry->vlan_id = 0;
754 entry->src_first = RLB_NULL_INDEX;
755 entry->src_prev = RLB_NULL_INDEX;
756 entry->src_next = RLB_NULL_INDEX;
766 static void rlb_delete_table_entry_dst(struct bonding *bond, u32 index)
768 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
769 u32 next_index = bond_info->rx_hashtbl[index].used_next;
770 u32 prev_index = bond_info->rx_hashtbl[index].used_prev;
772 if (index == bond_info->rx_hashtbl_used_head)
773 bond_info->rx_hashtbl_used_head = next_index;
775 bond_info->rx_hashtbl[prev_index].used_next = next_index;
777 bond_info->rx_hashtbl[next_index].used_prev = prev_index;
781 static void rlb_src_unlink(struct bonding *bond, u32 index)
783 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
784 u32 next_index = bond_info->rx_hashtbl[index].src_next;
785 u32 prev_index = bond_info->rx_hashtbl[index].src_prev;
787 bond_info->rx_hashtbl[index].src_next = RLB_NULL_INDEX;
788 bond_info->rx_hashtbl[index].src_prev = RLB_NULL_INDEX;
791 bond_info->rx_hashtbl[next_index].src_prev = prev_index;
797 if (bond_info->rx_hashtbl[prev_index].src_first == index)
798 bond_info->rx_hashtbl[prev_index].src_first = next_index;
800 bond_info->rx_hashtbl[prev_index].src_next = next_index;
804 static void rlb_delete_table_entry(struct bonding *bond, u32 index)
806 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
807 struct rlb_client_info *entry = &(bond_info->rx_hashtbl[index]);
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));
823 bond_info->rx_hashtbl[ip_dst_hash].src_prev = ip_src_hash;
824 next = bond_info->rx_hashtbl[ip_src_hash].src_first;
825 bond_info->rx_hashtbl[ip_dst_hash].src_next = next;
827 bond_info->rx_hashtbl[next].src_prev = ip_dst_hash;
828 bond_info->rx_hashtbl[ip_src_hash].src_first = ip_dst_hash;
831 /* deletes all rx_hashtbl entries with arp->ip_src if their mac_src does
832 * not match arp->mac_src
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));
837 u32 ip_src_hash = _simple_hash((u8 *)&(arp->ip_src), sizeof(arp->ip_src));
840 spin_lock_bh(&bond->mode_lock);
842 index = bond_info->rx_hashtbl[ip_src_hash].src_first;
844 struct rlb_client_info *entry = &(bond_info->rx_hashtbl[index]);
845 u32 next_index = entry->src_next;
847 if (entry->ip_src == arp->ip_src &&
848 !ether_addr_equal_64bits(arp->mac_src, entry->mac_src))
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));
864 return -1;
866 spin_lock_bh(&bond->mode_lock);
868 bond_info->rx_hashtbl = new_hashtbl;
870 bond_info->rx_hashtbl_used_head = RLB_NULL_INDEX;
873 rlb_init_table_entry(bond_info->rx_hashtbl + i);
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);
889 kfree(bond_info->rx_hashtbl);
890 bond_info->rx_hashtbl = NULL;
891 bond_info->rx_hashtbl_used_head = RLB_NULL_INDEX;
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);
903 curr_index = bond_info->rx_hashtbl_used_head;
905 struct rlb_client_info *curr = &(bond_info->rx_hashtbl[curr_index]);
906 u32 next_index = bond_info->rx_hashtbl[curr_index].used_next;
908 if (curr->vlan_id == vlan_id)
909 rlb_delete_table_entry(bond, curr_index);
914 spin_unlock_bh(&bond->mode_lock);
938 skb->network_header = skb->mac_header + ETH_HLEN;
939 skb->protocol = pkt.type;
940 skb->priority = TC_PRIO_CONTROL;
941 skb->dev = slave->dev;
943 slave_dbg(slave->bond->dev, slave->dev,
953 struct bonding *bond;
962 struct alb_walk_data *data = (struct alb_walk_data *)priv->data;
963 bool strict_match = data->strict_match;
964 const u8 *mac_addr = data->mac_addr;
965 struct bonding *bond = data->bond;
966 struct slave *slave = data->slave;
970 bond->dev->lower_level == upper->lower_level - 1) {
971 if (upper->addr_assign_type == NET_ADDR_STOLEN) {
976 alb_send_lp_vid(slave, upper->dev_addr,
986 tags = bond_verify_device_path(bond->dev, upper, 0);
988 return -ENOMEM;
990 alb_send_lp_vid(slave, upper->dev_addr,
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);
1025 struct net_device *dev = slave->dev;
1028 if (BOND_MODE(slave->bond) == BOND_MODE_TLB) {
1037 ss.ss_family = dev->type;
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");
1040 return -EOPNOTSUPP;
1053 bond_hw_addr_copy(tmp_mac_addr, slave1->dev->dev_addr,
1054 slave1->dev->addr_len);
1055 alb_set_slave_mac_addr(slave1, slave2->dev->dev_addr,
1056 slave2->dev->addr_len);
1058 slave1->dev->addr_len);
1066 static void alb_fasten_mac_swap(struct bonding *bond, struct slave *slave1,
1076 alb_send_learning_packets(slave1, slave1->dev->dev_addr, false);
1077 if (bond->alb_info.rlb_enabled) {
1081 rlb_req_update_slave_clients(bond, slave1);
1088 alb_send_learning_packets(slave2, slave2->dev->dev_addr, false);
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,
1102 disabled_slave->dev->dev_addr);
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)
1126 perm_curr_diff = !ether_addr_equal_64bits(slave->perm_hwaddr,
1127 slave->dev->dev_addr);
1128 perm_bond_diff = !ether_addr_equal_64bits(slave->perm_hwaddr,
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)) {
1202 if (ether_addr_equal_64bits(tmp_slave1->dev->dev_addr,
1203 bond->dev->dev_addr)) {
1211 alb_set_slave_mac_addr(slave, free_mac_slave->perm_hwaddr,
1212 free_mac_slave->dev->addr_len);
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",
1215 free_mac_slave->dev->name);
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");
1219 return -EFAULT;
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) {
1252 bond_hw_addr_copy(tmp_addr, slave->dev->dev_addr,
1253 slave->dev->addr_len);
1255 res = dev_set_mac_address(slave->dev, addr, NULL);
1258 dev_addr_set(slave->dev, tmp_addr);
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) {
1274 bond_hw_addr_copy(tmp_addr, rollback_slave->dev->dev_addr,
1275 rollback_slave->dev->addr_len);
1276 dev_set_mac_address(rollback_slave->dev, &ss, NULL);
1277 dev_addr_set(rollback_slave->dev, tmp_addr);
1284 static bool alb_determine_nd(struct sk_buff *skb, struct bonding *bond)
1293 if (ip6hdr->nexthdr != IPPROTO_ICMPV6)
1300 return hdr->icmp6_type == NDISC_NEIGHBOUR_ADVERTISEMENT ||
1301 hdr->icmp6_type == NDISC_NEIGHBOUR_SOLICITATION;
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);
1334 if (bond_info->rlb_enabled)
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));
1345 /* unbalanced or unassigned, send through primary */
1346 tx_slave = rcu_dereference(bond->curr_active_slave);
1347 if (bond->params.tlb_dynamic_lb)
1348 bond_info->unbalanced_load += skb->len;
1352 if (tx_slave != rcu_access_pointer(bond->curr_active_slave)) {
1353 ether_addr_copy(eth_data->h_source,
1354 tx_slave->dev->dev_addr);
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,
1381 if (!is_multicast_ether_addr(eth_data->h_dest)) {
1382 switch (skb->protocol) {
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,
1392 skb->len);
1397 slaves = rcu_dereference(bond->usable_slaves);
1398 count = slaves ? READ_ONCE(slaves->count) : 0;
1400 tx_slave = slaves->arr[hash_index %
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));
1433 switch (ntohs(skb->protocol)) {
1437 if (is_broadcast_ether_addr(eth_data->h_dest) ||
1443 if (iph->daddr == ip_bcast || iph->protocol == IPPROTO_IGMP) {
1447 hash_start = (char *)&(iph->daddr);
1448 hash_size = sizeof(iph->daddr);
1457 if (is_broadcast_ether_addr(eth_data->h_dest)) {
1462 /* IPv6 uses all-nodes multicast as an equivalent to
1465 if (ether_addr_equal_64bits(eth_data->h_dest, mac_v6_allmcast)) {
1470 if (alb_determine_nd(skb, bond)) {
1476 /* Additionally, DAD probes should not be tx-balanced as that
1481 if (ipv6_addr_any(&ip6hdr->saddr)) {
1486 hash_start = (char *)&ip6hdr->daddr;
1487 hash_size = sizeof(ip6hdr->daddr);
1492 if (bond_info->rlb_enabled)
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);
1514 count = slaves ? READ_ONCE(slaves->count) : 0;
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)) {
1541 atomic_set(&bond_info->tx_rebalance_counter, 0);
1542 bond_info->lp_counter = 0;
1548 atomic_inc(&bond_info->tx_rebalance_counter);
1549 bond_info->lp_counter++;
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) ||
1562 bond_info->rlb_enabled);
1563 alb_send_learning_packets(slave, slave->dev->dev_addr,
1566 bond_info->lp_counter = 0;
1570 if (atomic_read(&bond_info->tx_rebalance_counter) >= BOND_TLB_REBALANCE_TICKS) {
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)) {
1575 bond_info->unbalanced_load /
1577 bond_info->unbalanced_load = 0;
1580 atomic_set(&bond_info->tx_rebalance_counter, 0);
1583 if (bond_info->rlb_enabled) {
1584 if (bond_info->primary_is_promisc &&
1585 (++bond_info->rlb_promisc_timeout_counter >= RLB_PROMISC_TIMEOUT)) {
1594 bond_info->rlb_promisc_timeout_counter = 0;
1596 /* If the primary was set to promiscuous mode
1600 dev_set_promiscuity(rtnl_dereference(bond->curr_active_slave)->dev,
1601 -1);
1602 bond_info->primary_is_promisc = 0;
1608 if (bond_info->rlb_rebalance) {
1609 bond_info->rlb_rebalance = 0;
1610 rlb_rebalance(bond);
1614 if (bond_info->rx_ntt) {
1615 if (bond_info->rlb_update_delay_counter) {
1616 --bond_info->rlb_update_delay_counter;
1618 rlb_update_rx_clients(bond);
1619 if (bond_info->rlb_update_retry_counter)
1620 --bond_info->rlb_update_retry_counter;
1622 bond_info->rx_ntt = 0;
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)
1638 res = alb_set_slave_mac_addr(slave, slave->perm_hwaddr,
1639 slave->dev->addr_len);
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);
1688 atomic_set(&bond_info->tx_rebalance_counter,
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))
1702 pr_err("Failed to build slave-array for TLB mode.\n");
1707 * bond_alb_handle_active_change - assign new curr_active_slave
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) {
1726 dev_set_promiscuity(curr_active->dev, -1);
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) {
1758 bond_hw_addr_copy(tmp_addr, new_slave->dev->dev_addr,
1759 new_slave->dev->addr_len);
1761 bond_hw_addr_copy(ss.__data, bond->dev->dev_addr,
1762 bond->dev->addr_len);
1763 ss.ss_family = bond->dev->type;
1765 dev_set_mac_address(new_slave->dev, &ss, NULL);
1767 dev_addr_set(new_slave->dev, tmp_addr);
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);
1793 if (!is_valid_ether_addr(ss->__data))
1794 return -EADDRNOTAVAIL;
1796 res = alb_set_mac_address(bond, addr);
1800 dev_addr_set(bond_dev, ss->__data);
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);
1816 alb_set_slave_mac_addr(curr_active, bond_dev->dev_addr,
1817 bond_dev->addr_len);
1820 bond_dev->dev_addr, false);
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);