Lines Matching +full:slave +full:- +full:addr
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];
54 static void alb_send_learning_packets(struct slave *slave, const u8 mac_addr[],
77 entry->load_history = 1 + entry->tx_bytes / in tlb_init_table_entry()
79 entry->tx_bytes = 0; in tlb_init_table_entry()
82 entry->tx_slave = NULL; in tlb_init_table_entry()
83 entry->next = TLB_NULL_INDEX; in tlb_init_table_entry()
84 entry->prev = TLB_NULL_INDEX; in tlb_init_table_entry()
87 static inline void tlb_init_slave(struct slave *slave) in tlb_init_slave() argument
89 SLAVE_TLB_INFO(slave).load = 0; in tlb_init_slave()
90 SLAVE_TLB_INFO(slave).head = TLB_NULL_INDEX; in tlb_init_slave()
93 static void __tlb_clear_slave(struct bonding *bond, struct slave *slave, in __tlb_clear_slave() argument
99 /* clear slave from tx_hashtbl */ in __tlb_clear_slave()
104 index = SLAVE_TLB_INFO(slave).head; in __tlb_clear_slave()
113 tlb_init_slave(slave); in __tlb_clear_slave()
116 static void tlb_clear_slave(struct bonding *bond, struct slave *slave, in tlb_clear_slave() argument
119 spin_lock_bh(&bond->mode_lock); in tlb_clear_slave()
120 __tlb_clear_slave(bond, slave, save_load); in tlb_clear_slave()
121 spin_unlock_bh(&bond->mode_lock); in tlb_clear_slave()
134 return -ENOMEM; in tlb_initialize()
136 spin_lock_bh(&bond->mode_lock); in tlb_initialize()
138 bond_info->tx_hashtbl = new_hashtbl; in tlb_initialize()
141 tlb_init_table_entry(&bond_info->tx_hashtbl[i], 0); in tlb_initialize()
143 spin_unlock_bh(&bond->mode_lock); in tlb_initialize()
153 spin_lock_bh(&bond->mode_lock); in tlb_deinitialize()
155 kfree(bond_info->tx_hashtbl); in tlb_deinitialize()
156 bond_info->tx_hashtbl = NULL; in tlb_deinitialize()
158 spin_unlock_bh(&bond->mode_lock); in tlb_deinitialize()
161 static long long compute_gap(struct slave *slave) in compute_gap() argument
163 return (s64) (slave->speed << 20) - /* Convert to Megabit per sec */ in compute_gap()
164 (s64) (SLAVE_TLB_INFO(slave).load << 3); /* Bytes to bits */ in compute_gap()
167 static struct slave *tlb_get_least_loaded_slave(struct bonding *bond) in tlb_get_least_loaded_slave()
169 struct slave *slave, *least_loaded; in tlb_get_least_loaded_slave() local
176 /* Find the slave with the largest gap */ in tlb_get_least_loaded_slave()
177 bond_for_each_slave_rcu(bond, slave, iter) { in tlb_get_least_loaded_slave()
178 if (bond_slave_can_tx(slave)) { in tlb_get_least_loaded_slave()
179 long long gap = compute_gap(slave); in tlb_get_least_loaded_slave()
182 least_loaded = slave; in tlb_get_least_loaded_slave()
191 static struct slave *__tlb_choose_channel(struct bonding *bond, u32 hash_index, in __tlb_choose_channel()
196 struct slave *assigned_slave; in __tlb_choose_channel()
198 hash_table = bond_info->tx_hashtbl; in __tlb_choose_channel()
206 u32 next_index = slave_info->head; in __tlb_choose_channel()
215 slave_info->head = hash_index; in __tlb_choose_channel()
216 slave_info->load += in __tlb_choose_channel()
227 static struct slave *tlb_choose_channel(struct bonding *bond, u32 hash_index, in tlb_choose_channel()
230 struct slave *tx_slave; in tlb_choose_channel()
236 spin_lock(&bond->mode_lock); in tlb_choose_channel()
238 spin_unlock(&bond->mode_lock); in tlb_choose_channel()
254 spin_lock_bh(&bond->mode_lock); in rlb_update_entry_from_arp()
256 hash_index = _simple_hash((u8 *)&(arp->ip_src), sizeof(arp->ip_src)); in rlb_update_entry_from_arp()
257 client_info = &(bond_info->rx_hashtbl[hash_index]); in rlb_update_entry_from_arp()
259 if ((client_info->assigned) && in rlb_update_entry_from_arp()
260 (client_info->ip_src == arp->ip_dst) && in rlb_update_entry_from_arp()
261 (client_info->ip_dst == arp->ip_src) && in rlb_update_entry_from_arp()
262 (!ether_addr_equal_64bits(client_info->mac_dst, arp->mac_src))) { in rlb_update_entry_from_arp()
264 ether_addr_copy(client_info->mac_dst, arp->mac_src); in rlb_update_entry_from_arp()
265 client_info->ntt = 1; in rlb_update_entry_from_arp()
266 bond_info->rx_ntt = 1; in rlb_update_entry_from_arp()
269 spin_unlock_bh(&bond->mode_lock); in rlb_update_entry_from_arp()
273 struct slave *slave) in rlb_arp_recv() argument
277 if (skb->protocol != cpu_to_be16(ETH_P_ARP)) in rlb_arp_recv()
284 /* We received an ARP from arp->ip_src. in rlb_arp_recv()
287 * However, if arp->mac_src is different than what is stored in in rlb_arp_recv()
296 if (arp->op_code == htons(ARPOP_REPLY)) { in rlb_arp_recv()
299 slave_dbg(bond->dev, slave->dev, "Server received an ARP Reply from client\n"); in rlb_arp_recv()
306 static struct slave *__rlb_next_rx_slave(struct bonding *bond) in __rlb_next_rx_slave()
309 struct slave *before = NULL, *rx_slave = NULL, *slave; in __rlb_next_rx_slave() local
313 bond_for_each_slave_rcu(bond, slave, iter) { in __rlb_next_rx_slave()
314 if (!bond_slave_can_tx(slave)) in __rlb_next_rx_slave()
317 if (!before || before->speed < slave->speed) in __rlb_next_rx_slave()
318 before = slave; in __rlb_next_rx_slave()
320 if (!rx_slave || rx_slave->speed < slave->speed) in __rlb_next_rx_slave()
321 rx_slave = slave; in __rlb_next_rx_slave()
323 if (slave == bond_info->rx_slave) in __rlb_next_rx_slave()
327 * better before and up to the current slave in __rlb_next_rx_slave()
329 if (!rx_slave || (before && rx_slave->speed < before->speed)) in __rlb_next_rx_slave()
333 bond_info->rx_slave = rx_slave; in __rlb_next_rx_slave()
339 static struct slave *rlb_next_rx_slave(struct bonding *bond) in rlb_next_rx_slave()
341 struct slave *rx_slave; in rlb_next_rx_slave()
352 /* teach the switch the mac of a disabled slave
358 const u8 addr[]) in rlb_teach_disabled_mac_on_primary() argument
360 struct slave *curr_active = rtnl_dereference(bond->curr_active_slave); in rlb_teach_disabled_mac_on_primary()
365 if (!bond->alb_info.primary_is_promisc) { in rlb_teach_disabled_mac_on_primary()
366 if (!dev_set_promiscuity(curr_active->dev, 1)) in rlb_teach_disabled_mac_on_primary()
367 bond->alb_info.primary_is_promisc = 1; in rlb_teach_disabled_mac_on_primary()
369 bond->alb_info.primary_is_promisc = 0; in rlb_teach_disabled_mac_on_primary()
372 bond->alb_info.rlb_promisc_timeout_counter = 0; in rlb_teach_disabled_mac_on_primary()
374 alb_send_learning_packets(curr_active, addr, true); in rlb_teach_disabled_mac_on_primary()
377 /* slave being removed should not be active at this point
381 static void rlb_clear_slave(struct bonding *bond, struct slave *slave) in rlb_clear_slave() argument
387 /* clear slave from rx_hashtbl */ in rlb_clear_slave()
388 spin_lock_bh(&bond->mode_lock); in rlb_clear_slave()
390 rx_hash_table = bond_info->rx_hashtbl; in rlb_clear_slave()
391 index = bond_info->rx_hashtbl_used_head; in rlb_clear_slave()
394 if (rx_hash_table[index].slave == slave) { in rlb_clear_slave()
395 struct slave *assigned_slave = rlb_next_rx_slave(bond); in rlb_clear_slave()
398 rx_hash_table[index].slave = assigned_slave; in rlb_clear_slave()
400 bond_info->rx_hashtbl[index].ntt = 1; in rlb_clear_slave()
401 bond_info->rx_ntt = 1; in rlb_clear_slave()
402 /* A slave has been removed from the in rlb_clear_slave()
409 bond_info->rlb_update_retry_counter = in rlb_clear_slave()
412 } else { /* there is no active slave */ in rlb_clear_slave()
413 rx_hash_table[index].slave = NULL; in rlb_clear_slave()
418 spin_unlock_bh(&bond->mode_lock); in rlb_clear_slave()
420 if (slave != rtnl_dereference(bond->curr_active_slave)) in rlb_clear_slave()
421 rlb_teach_disabled_mac_on_primary(bond, slave->dev->dev_addr); in rlb_clear_slave()
428 if (!client_info->slave || !is_valid_ether_addr(client_info->mac_dst)) in rlb_update_client()
435 client_info->ip_dst, in rlb_update_client()
436 client_info->slave->dev, in rlb_update_client()
437 client_info->ip_src, in rlb_update_client()
438 client_info->mac_dst, in rlb_update_client()
439 client_info->slave->dev->dev_addr, in rlb_update_client()
440 client_info->mac_dst); in rlb_update_client()
442 slave_err(client_info->slave->bond->dev, in rlb_update_client()
443 client_info->slave->dev, in rlb_update_client()
448 skb->dev = client_info->slave->dev; in rlb_update_client()
450 if (client_info->vlan_id) { in rlb_update_client()
452 client_info->vlan_id); in rlb_update_client()
466 spin_lock_bh(&bond->mode_lock); in rlb_update_rx_clients()
468 hash_index = bond_info->rx_hashtbl_used_head; in rlb_update_rx_clients()
470 hash_index = client_info->used_next) { in rlb_update_rx_clients()
471 client_info = &(bond_info->rx_hashtbl[hash_index]); in rlb_update_rx_clients()
472 if (client_info->ntt) { in rlb_update_rx_clients()
474 if (bond_info->rlb_update_retry_counter == 0) in rlb_update_rx_clients()
475 client_info->ntt = 0; in rlb_update_rx_clients()
482 bond_info->rlb_update_delay_counter = RLB_UPDATE_DELAY; in rlb_update_rx_clients()
484 spin_unlock_bh(&bond->mode_lock); in rlb_update_rx_clients()
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) in rlb_req_update_slave_clients() argument
495 spin_lock_bh(&bond->mode_lock); in rlb_req_update_slave_clients()
497 hash_index = bond_info->rx_hashtbl_used_head; in rlb_req_update_slave_clients()
499 hash_index = client_info->used_next) { in rlb_req_update_slave_clients()
500 client_info = &(bond_info->rx_hashtbl[hash_index]); in rlb_req_update_slave_clients()
502 if ((client_info->slave == slave) && in rlb_req_update_slave_clients()
503 is_valid_ether_addr(client_info->mac_dst)) { in rlb_req_update_slave_clients()
504 client_info->ntt = 1; in rlb_req_update_slave_clients()
511 bond_info->rx_ntt = 1; in rlb_req_update_slave_clients()
513 bond_info->rlb_update_retry_counter = RLB_UPDATE_RETRY; in rlb_req_update_slave_clients()
516 spin_unlock_bh(&bond->mode_lock); in rlb_req_update_slave_clients()
526 spin_lock(&bond->mode_lock); in rlb_req_update_subnet_clients()
528 hash_index = bond_info->rx_hashtbl_used_head; in rlb_req_update_subnet_clients()
530 hash_index = client_info->used_next) { in rlb_req_update_subnet_clients()
531 client_info = &(bond_info->rx_hashtbl[hash_index]); in rlb_req_update_subnet_clients()
533 if (!client_info->slave) { in rlb_req_update_subnet_clients()
534 netdev_err(bond->dev, "found a client with no channel in the client's hash table\n"); in rlb_req_update_subnet_clients()
541 if ((client_info->ip_src == src_ip) && in rlb_req_update_subnet_clients()
542 !ether_addr_equal_64bits(client_info->slave->dev->dev_addr, in rlb_req_update_subnet_clients()
543 bond->dev->dev_addr) && in rlb_req_update_subnet_clients()
544 is_valid_ether_addr(client_info->mac_dst)) { in rlb_req_update_subnet_clients()
545 client_info->ntt = 1; in rlb_req_update_subnet_clients()
546 bond_info->rx_ntt = 1; in rlb_req_update_subnet_clients()
550 spin_unlock(&bond->mode_lock); in rlb_req_update_subnet_clients()
553 static struct slave *rlb_choose_channel(struct sk_buff *skb, in rlb_choose_channel()
558 struct slave *assigned_slave, *curr_active_slave; in rlb_choose_channel()
562 spin_lock(&bond->mode_lock); in rlb_choose_channel()
564 curr_active_slave = rcu_dereference(bond->curr_active_slave); in rlb_choose_channel()
566 hash_index = _simple_hash((u8 *)&arp->ip_dst, sizeof(arp->ip_dst)); in rlb_choose_channel()
567 client_info = &(bond_info->rx_hashtbl[hash_index]); in rlb_choose_channel()
569 if (client_info->assigned) { in rlb_choose_channel()
570 if ((client_info->ip_src == arp->ip_src) && in rlb_choose_channel()
571 (client_info->ip_dst == arp->ip_dst)) { in rlb_choose_channel()
573 if (!is_broadcast_ether_addr(arp->mac_dst)) { in rlb_choose_channel()
575 ether_addr_copy(client_info->mac_dst, arp->mac_dst); in rlb_choose_channel()
577 ether_addr_copy(client_info->mac_src, arp->mac_src); in rlb_choose_channel()
579 assigned_slave = client_info->slave; in rlb_choose_channel()
581 spin_unlock(&bond->mode_lock); in rlb_choose_channel()
590 client_info->slave != curr_active_slave) { in rlb_choose_channel()
591 client_info->slave = curr_active_slave; in rlb_choose_channel()
596 /* assign a new slave */ in rlb_choose_channel()
600 if (!(client_info->assigned && in rlb_choose_channel()
601 client_info->ip_src == arp->ip_src)) { in rlb_choose_channel()
605 u32 hash_src = _simple_hash((u8 *)&arp->ip_src, in rlb_choose_channel()
606 sizeof(arp->ip_src)); in rlb_choose_channel()
611 client_info->ip_src = arp->ip_src; in rlb_choose_channel()
612 client_info->ip_dst = arp->ip_dst; in rlb_choose_channel()
613 /* arp->mac_dst is broadcast for arp requests. in rlb_choose_channel()
617 ether_addr_copy(client_info->mac_dst, arp->mac_dst); in rlb_choose_channel()
618 ether_addr_copy(client_info->mac_src, arp->mac_src); in rlb_choose_channel()
619 client_info->slave = assigned_slave; in rlb_choose_channel()
621 if (is_valid_ether_addr(client_info->mac_dst)) { in rlb_choose_channel()
622 client_info->ntt = 1; in rlb_choose_channel()
623 bond->alb_info.rx_ntt = 1; in rlb_choose_channel()
625 client_info->ntt = 0; in rlb_choose_channel()
628 if (vlan_get_tag(skb, &client_info->vlan_id)) in rlb_choose_channel()
629 client_info->vlan_id = 0; in rlb_choose_channel()
631 if (!client_info->assigned) { in rlb_choose_channel()
632 u32 prev_tbl_head = bond_info->rx_hashtbl_used_head; in rlb_choose_channel()
634 bond_info->rx_hashtbl_used_head = hash_index; in rlb_choose_channel()
635 client_info->used_next = prev_tbl_head; in rlb_choose_channel()
637 bond_info->rx_hashtbl[prev_tbl_head].used_prev = in rlb_choose_channel()
640 client_info->assigned = 1; in rlb_choose_channel()
644 spin_unlock(&bond->mode_lock); in rlb_choose_channel()
653 static struct slave *rlb_arp_xmit(struct sk_buff *skb, struct bonding *bond) in rlb_arp_xmit()
655 struct slave *tx_slave = NULL; in rlb_arp_xmit()
666 if (!bond_slave_has_mac_rcu(bond, arp->mac_src)) in rlb_arp_xmit()
669 dev = ip_dev_find(dev_net(bond->dev), arp->ip_src); in rlb_arp_xmit()
678 if (arp->op_code == htons(ARPOP_REPLY)) { in rlb_arp_xmit()
682 bond_hw_addr_copy(arp->mac_src, tx_slave->dev->dev_addr, in rlb_arp_xmit()
683 tx_slave->dev->addr_len); in rlb_arp_xmit()
684 netdev_dbg(bond->dev, "(slave %s): Server sent ARP Reply packet\n", in rlb_arp_xmit()
685 tx_slave ? tx_slave->dev->name : "NULL"); in rlb_arp_xmit()
686 } else if (arp->op_code == htons(ARPOP_REQUEST)) { in rlb_arp_xmit()
697 bond->alb_info.rlb_update_delay_counter = RLB_UPDATE_DELAY; in rlb_arp_xmit()
701 * the primary slave. We must register these clients to be in rlb_arp_xmit()
704 rlb_req_update_subnet_clients(bond, arp->ip_src); in rlb_arp_xmit()
705 netdev_dbg(bond->dev, "(slave %s): Server sent ARP Request packet\n", in rlb_arp_xmit()
706 tx_slave ? tx_slave->dev->name : "NULL"); in rlb_arp_xmit()
715 struct slave *assigned_slave; in rlb_rebalance()
720 spin_lock_bh(&bond->mode_lock); in rlb_rebalance()
723 hash_index = bond_info->rx_hashtbl_used_head; in rlb_rebalance()
725 hash_index = client_info->used_next) { in rlb_rebalance()
726 client_info = &(bond_info->rx_hashtbl[hash_index]); in rlb_rebalance()
728 if (assigned_slave && (client_info->slave != assigned_slave)) { in rlb_rebalance()
729 client_info->slave = assigned_slave; in rlb_rebalance()
730 if (!is_zero_ether_addr(client_info->mac_dst)) { in rlb_rebalance()
731 client_info->ntt = 1; in rlb_rebalance()
739 bond_info->rx_ntt = 1; in rlb_rebalance()
740 spin_unlock_bh(&bond->mode_lock); in rlb_rebalance()
746 entry->used_next = RLB_NULL_INDEX; in rlb_init_table_entry_dst()
747 entry->used_prev = RLB_NULL_INDEX; in rlb_init_table_entry_dst()
748 entry->assigned = 0; in rlb_init_table_entry_dst()
749 entry->slave = NULL; in rlb_init_table_entry_dst()
750 entry->vlan_id = 0; in rlb_init_table_entry_dst()
754 entry->src_first = RLB_NULL_INDEX; in rlb_init_table_entry_src()
755 entry->src_prev = RLB_NULL_INDEX; in rlb_init_table_entry_src()
756 entry->src_next = RLB_NULL_INDEX; in rlb_init_table_entry_src()
769 u32 next_index = bond_info->rx_hashtbl[index].used_next; in rlb_delete_table_entry_dst()
770 u32 prev_index = bond_info->rx_hashtbl[index].used_prev; in rlb_delete_table_entry_dst()
772 if (index == bond_info->rx_hashtbl_used_head) in rlb_delete_table_entry_dst()
773 bond_info->rx_hashtbl_used_head = next_index; in rlb_delete_table_entry_dst()
775 bond_info->rx_hashtbl[prev_index].used_next = next_index; in rlb_delete_table_entry_dst()
777 bond_info->rx_hashtbl[next_index].used_prev = prev_index; in rlb_delete_table_entry_dst()
784 u32 next_index = bond_info->rx_hashtbl[index].src_next; in rlb_src_unlink()
785 u32 prev_index = bond_info->rx_hashtbl[index].src_prev; in rlb_src_unlink()
787 bond_info->rx_hashtbl[index].src_next = RLB_NULL_INDEX; in rlb_src_unlink()
788 bond_info->rx_hashtbl[index].src_prev = RLB_NULL_INDEX; in rlb_src_unlink()
791 bond_info->rx_hashtbl[next_index].src_prev = prev_index; in rlb_src_unlink()
797 if (bond_info->rx_hashtbl[prev_index].src_first == index) in rlb_src_unlink()
798 bond_info->rx_hashtbl[prev_index].src_first = next_index; in rlb_src_unlink()
800 bond_info->rx_hashtbl[prev_index].src_next = next_index; in rlb_src_unlink()
807 struct rlb_client_info *entry = &(bond_info->rx_hashtbl[index]); in rlb_delete_table_entry()
823 bond_info->rx_hashtbl[ip_dst_hash].src_prev = ip_src_hash; in rlb_src_link()
824 next = bond_info->rx_hashtbl[ip_src_hash].src_first; in rlb_src_link()
825 bond_info->rx_hashtbl[ip_dst_hash].src_next = next; in rlb_src_link()
827 bond_info->rx_hashtbl[next].src_prev = ip_dst_hash; in rlb_src_link()
828 bond_info->rx_hashtbl[ip_src_hash].src_first = ip_dst_hash; in rlb_src_link()
831 /* deletes all rx_hashtbl entries with arp->ip_src if their mac_src does
832 * not match arp->mac_src
837 u32 ip_src_hash = _simple_hash((u8 *)&(arp->ip_src), sizeof(arp->ip_src)); in rlb_purge_src_ip()
840 spin_lock_bh(&bond->mode_lock); in rlb_purge_src_ip()
842 index = bond_info->rx_hashtbl[ip_src_hash].src_first; in rlb_purge_src_ip()
844 struct rlb_client_info *entry = &(bond_info->rx_hashtbl[index]); in rlb_purge_src_ip()
845 u32 next_index = entry->src_next; in rlb_purge_src_ip()
847 if (entry->ip_src == arp->ip_src && in rlb_purge_src_ip()
848 !ether_addr_equal_64bits(arp->mac_src, entry->mac_src)) in rlb_purge_src_ip()
852 spin_unlock_bh(&bond->mode_lock); in rlb_purge_src_ip()
864 return -1; in rlb_initialize()
866 spin_lock_bh(&bond->mode_lock); in rlb_initialize()
868 bond_info->rx_hashtbl = new_hashtbl; in rlb_initialize()
870 bond_info->rx_hashtbl_used_head = RLB_NULL_INDEX; in rlb_initialize()
873 rlb_init_table_entry(bond_info->rx_hashtbl + i); in rlb_initialize()
875 spin_unlock_bh(&bond->mode_lock); in rlb_initialize()
878 bond->recv_probe = rlb_arp_recv; in rlb_initialize()
887 spin_lock_bh(&bond->mode_lock); in rlb_deinitialize()
889 kfree(bond_info->rx_hashtbl); in rlb_deinitialize()
890 bond_info->rx_hashtbl = NULL; in rlb_deinitialize()
891 bond_info->rx_hashtbl_used_head = RLB_NULL_INDEX; in rlb_deinitialize()
893 spin_unlock_bh(&bond->mode_lock); in rlb_deinitialize()
901 spin_lock_bh(&bond->mode_lock); in rlb_clear_vlan()
903 curr_index = bond_info->rx_hashtbl_used_head; in rlb_clear_vlan()
905 struct rlb_client_info *curr = &(bond_info->rx_hashtbl[curr_index]); in rlb_clear_vlan()
906 u32 next_index = bond_info->rx_hashtbl[curr_index].used_next; in rlb_clear_vlan()
908 if (curr->vlan_id == vlan_id) in rlb_clear_vlan()
914 spin_unlock_bh(&bond->mode_lock); in rlb_clear_vlan()
919 static void alb_send_lp_vid(struct slave *slave, const u8 mac_addr[], in alb_send_lp_vid() argument
938 skb->network_header = skb->mac_header + ETH_HLEN; in alb_send_lp_vid()
939 skb->protocol = pkt.type; in alb_send_lp_vid()
940 skb->priority = TC_PRIO_CONTROL; in alb_send_lp_vid()
941 skb->dev = slave->dev; in alb_send_lp_vid()
943 slave_dbg(slave->bond->dev, slave->dev, in alb_send_lp_vid()
954 struct slave *slave; member
962 struct alb_walk_data *data = (struct alb_walk_data *)priv->data; in alb_upper_dev_walk()
963 bool strict_match = data->strict_match; in alb_upper_dev_walk()
964 const u8 *mac_addr = data->mac_addr; in alb_upper_dev_walk()
965 struct bonding *bond = data->bond; in alb_upper_dev_walk()
966 struct slave *slave = data->slave; in alb_upper_dev_walk() local
970 bond->dev->lower_level == upper->lower_level - 1) { in alb_upper_dev_walk()
971 if (upper->addr_assign_type == NET_ADDR_STOLEN) { in alb_upper_dev_walk()
972 alb_send_lp_vid(slave, mac_addr, in alb_upper_dev_walk()
976 alb_send_lp_vid(slave, upper->dev_addr, in alb_upper_dev_walk()
986 tags = bond_verify_device_path(bond->dev, upper, 0); in alb_upper_dev_walk()
988 return -ENOMEM; in alb_upper_dev_walk()
990 alb_send_lp_vid(slave, upper->dev_addr, in alb_upper_dev_walk()
998 static void alb_send_learning_packets(struct slave *slave, const u8 mac_addr[], in alb_send_learning_packets() argument
1001 struct bonding *bond = bond_get_bond_by_slave(slave); in alb_send_learning_packets()
1006 .slave = slave, in alb_send_learning_packets()
1012 alb_send_lp_vid(slave, mac_addr, 0, 0); in alb_send_learning_packets()
1018 netdev_walk_all_upper_dev_rcu(bond->dev, alb_upper_dev_walk, &priv); in alb_send_learning_packets()
1022 static int alb_set_slave_mac_addr(struct slave *slave, const u8 addr[], in alb_set_slave_mac_addr() argument
1025 struct net_device *dev = slave->dev; in alb_set_slave_mac_addr()
1028 if (BOND_MODE(slave->bond) == BOND_MODE_TLB) { in alb_set_slave_mac_addr()
1029 __dev_addr_set(dev, addr, len); in alb_set_slave_mac_addr()
1033 /* for rlb each slave must have a unique hw mac addresses so that in alb_set_slave_mac_addr()
1034 * each slave will receive packets destined to a different mac in alb_set_slave_mac_addr()
1036 memcpy(ss.__data, addr, len); in alb_set_slave_mac_addr()
1037 ss.ss_family = dev->type; in alb_set_slave_mac_addr()
1039 …slave_err(slave->bond->dev, dev, "dev_set_mac_address on slave failed! ALB mode requires that the … in alb_set_slave_mac_addr()
1040 return -EOPNOTSUPP; in alb_set_slave_mac_addr()
1049 static void alb_swap_mac_addr(struct slave *slave1, struct slave *slave2) in alb_swap_mac_addr()
1053 bond_hw_addr_copy(tmp_mac_addr, slave1->dev->dev_addr, in alb_swap_mac_addr()
1054 slave1->dev->addr_len); in alb_swap_mac_addr()
1055 alb_set_slave_mac_addr(slave1, slave2->dev->dev_addr, in alb_swap_mac_addr()
1056 slave2->dev->addr_len); in alb_swap_mac_addr()
1058 slave1->dev->addr_len); in alb_swap_mac_addr()
1066 static void alb_fasten_mac_swap(struct bonding *bond, struct slave *slave1, in alb_fasten_mac_swap()
1067 struct slave *slave2) in alb_fasten_mac_swap()
1070 struct slave *disabled_slave = NULL; in alb_fasten_mac_swap()
1076 alb_send_learning_packets(slave1, slave1->dev->dev_addr, false); in alb_fasten_mac_swap()
1077 if (bond->alb_info.rlb_enabled) { in alb_fasten_mac_swap()
1088 alb_send_learning_packets(slave2, slave2->dev->dev_addr, false); in alb_fasten_mac_swap()
1089 if (bond->alb_info.rlb_enabled) { in alb_fasten_mac_swap()
1099 if (bond->alb_info.rlb_enabled && slaves_state_differ) { in alb_fasten_mac_swap()
1100 /* A disabled slave was assigned an active mac addr */ in alb_fasten_mac_swap()
1102 disabled_slave->dev->dev_addr); in alb_fasten_mac_swap()
1109 * @slave: the slave that was just detached
1111 * We assume that @slave was already detached from the slave list.
1113 * If @slave's permanent hw address is different both from its current
1115 * a slave that has @slave's permanet address as its current address.
1116 * We'll make sure that slave no longer uses @slave's permanent address.
1120 static void alb_change_hw_addr_on_detach(struct bonding *bond, struct slave *slave) in alb_change_hw_addr_on_detach() argument
1124 struct slave *found_slave; in alb_change_hw_addr_on_detach()
1126 perm_curr_diff = !ether_addr_equal_64bits(slave->perm_hwaddr, in alb_change_hw_addr_on_detach()
1127 slave->dev->dev_addr); in alb_change_hw_addr_on_detach()
1128 perm_bond_diff = !ether_addr_equal_64bits(slave->perm_hwaddr, in alb_change_hw_addr_on_detach()
1129 bond->dev->dev_addr); in alb_change_hw_addr_on_detach()
1132 found_slave = bond_slave_has_mac(bond, slave->perm_hwaddr); in alb_change_hw_addr_on_detach()
1135 alb_swap_mac_addr(slave, found_slave); in alb_change_hw_addr_on_detach()
1136 alb_fasten_mac_swap(bond, slave, found_slave); in alb_change_hw_addr_on_detach()
1144 * @slave: the slave that was just attached
1146 * checks uniqueness of slave's mac address and handles the case the
1147 * new slave uses the bonds mac address.
1149 * If the permanent hw address of @slave is @bond's hw address, we need to
1150 * find a different hw address to give @slave, that isn't in use by any other
1151 * slave in the bond. This address must be, of course, one of the permanent
1154 * We go over the slave list, and for each slave there we compare its
1156 * If no match was found, then we've found a slave with a permanent address
1157 * that isn't used by any other slave in the bond, so we can assign it to
1158 * @slave.
1160 * assumption: this function is called before @slave is attached to the
1161 * bond slave list.
1163 static int alb_handle_addr_collision_on_attach(struct bonding *bond, struct slave *slave) in alb_handle_addr_collision_on_attach() argument
1165 struct slave *has_bond_addr = rcu_access_pointer(bond->curr_active_slave); in alb_handle_addr_collision_on_attach()
1166 struct slave *tmp_slave1, *free_mac_slave = NULL; in alb_handle_addr_collision_on_attach()
1170 /* this is the first slave */ in alb_handle_addr_collision_on_attach()
1174 /* if slave's mac address differs from bond's mac address in alb_handle_addr_collision_on_attach()
1175 * check uniqueness of slave's mac address against the other in alb_handle_addr_collision_on_attach()
1178 if (!ether_addr_equal_64bits(slave->perm_hwaddr, bond->dev->dev_addr)) { in alb_handle_addr_collision_on_attach()
1179 if (!bond_slave_has_mac(bond, slave->dev->dev_addr)) in alb_handle_addr_collision_on_attach()
1182 /* Try setting slave mac to bond address and fall-through in alb_handle_addr_collision_on_attach()
1185 alb_set_slave_mac_addr(slave, bond->dev->dev_addr, in alb_handle_addr_collision_on_attach()
1186 bond->dev->addr_len); in alb_handle_addr_collision_on_attach()
1189 /* The slave's address is equal to the address of the bond. in alb_handle_addr_collision_on_attach()
1190 * Search for a spare address in the bond for this slave. in alb_handle_addr_collision_on_attach()
1193 if (!bond_slave_has_mac(bond, tmp_slave1->perm_hwaddr)) { in alb_handle_addr_collision_on_attach()
1194 /* no slave has tmp_slave1's perm addr in alb_handle_addr_collision_on_attach()
1195 * as its curr addr in alb_handle_addr_collision_on_attach()
1202 if (ether_addr_equal_64bits(tmp_slave1->dev->dev_addr, in alb_handle_addr_collision_on_attach()
1203 bond->dev->dev_addr)) { in alb_handle_addr_collision_on_attach()
1211 alb_set_slave_mac_addr(slave, free_mac_slave->perm_hwaddr, in alb_handle_addr_collision_on_attach()
1212 free_mac_slave->dev->addr_len); in alb_handle_addr_collision_on_attach()
1214 …slave_warn(bond->dev, slave->dev, "the slave hw address is in use by the bond; giving it the hw ad… in alb_handle_addr_collision_on_attach()
1215 free_mac_slave->dev->name); in alb_handle_addr_collision_on_attach()
1218 …slave_err(bond->dev, slave->dev, "the slave hw address is in use by the bond; couldn't find a slav… in alb_handle_addr_collision_on_attach()
1219 return -EFAULT; in alb_handle_addr_collision_on_attach()
1228 * @addr: MAC address to set
1234 * For each slave, this function sets the interface to the new address and then
1239 static int alb_set_mac_address(struct bonding *bond, void *addr) in alb_set_mac_address() argument
1241 struct slave *slave, *rollback_slave; in alb_set_mac_address() local
1247 if (bond->alb_info.rlb_enabled) in alb_set_mac_address()
1250 bond_for_each_slave(bond, slave, iter) { in alb_set_mac_address()
1252 bond_hw_addr_copy(tmp_addr, slave->dev->dev_addr, in alb_set_mac_address()
1253 slave->dev->addr_len); in alb_set_mac_address()
1255 res = dev_set_mac_address(slave->dev, addr, NULL); in alb_set_mac_address()
1258 dev_addr_set(slave->dev, tmp_addr); in alb_set_mac_address()
1267 memcpy(ss.__data, bond->dev->dev_addr, bond->dev->addr_len); in alb_set_mac_address()
1268 ss.ss_family = bond->dev->type; in alb_set_mac_address()
1270 /* unwind from head to the slave that failed */ in alb_set_mac_address()
1272 if (rollback_slave == slave) in alb_set_mac_address()
1274 bond_hw_addr_copy(tmp_addr, rollback_slave->dev->dev_addr, in alb_set_mac_address()
1275 rollback_slave->dev->addr_len); in alb_set_mac_address()
1276 dev_set_mac_address(rollback_slave->dev, in alb_set_mac_address()
1278 dev_addr_set(rollback_slave->dev, tmp_addr); in alb_set_mac_address()
1294 if (ip6hdr->nexthdr != IPPROTO_ICMPV6) in alb_determine_nd()
1301 return hdr->icmp6_type == NDISC_NEIGHBOUR_ADVERTISEMENT || in alb_determine_nd()
1302 hdr->icmp6_type == NDISC_NEIGHBOUR_SOLICITATION; in alb_determine_nd()
1321 bond->alb_info.rlb_enabled = 1; in bond_alb_initialize()
1323 bond->alb_info.rlb_enabled = 0; in bond_alb_initialize()
1335 if (bond_info->rlb_enabled) in bond_alb_deinitialize()
1340 struct slave *tx_slave) in bond_do_alb_xmit()
1347 tx_slave = rcu_dereference(bond->curr_active_slave); in bond_do_alb_xmit()
1348 if (bond->params.tlb_dynamic_lb) in bond_do_alb_xmit()
1349 bond_info->unbalanced_load += skb->len; in bond_do_alb_xmit()
1353 if (tx_slave != rcu_access_pointer(bond->curr_active_slave)) { in bond_do_alb_xmit()
1354 ether_addr_copy(eth_data->h_source, in bond_do_alb_xmit()
1355 tx_slave->dev->dev_addr); in bond_do_alb_xmit()
1358 return bond_dev_queue_xmit(bond, skb, tx_slave->dev); in bond_do_alb_xmit()
1361 if (tx_slave && bond->params.tlb_dynamic_lb) { in bond_do_alb_xmit()
1362 spin_lock(&bond->mode_lock); in bond_do_alb_xmit()
1364 spin_unlock(&bond->mode_lock); in bond_do_alb_xmit()
1368 return bond_tx_drop(bond->dev, skb); in bond_do_alb_xmit()
1371 struct slave *bond_xmit_tlb_slave_get(struct bonding *bond, in bond_xmit_tlb_slave_get()
1374 struct slave *tx_slave = NULL; in bond_xmit_tlb_slave_get()
1382 if (!is_multicast_ether_addr(eth_data->h_dest)) { in bond_xmit_tlb_slave_get()
1383 switch (skb->protocol) { in bond_xmit_tlb_slave_get()
1390 if (bond->params.tlb_dynamic_lb) { in bond_xmit_tlb_slave_get()
1393 skb->len); in bond_xmit_tlb_slave_get()
1398 slaves = rcu_dereference(bond->usable_slaves); in bond_xmit_tlb_slave_get()
1399 count = slaves ? READ_ONCE(slaves->count) : 0; in bond_xmit_tlb_slave_get()
1401 tx_slave = slaves->arr[hash_index % in bond_xmit_tlb_slave_get()
1413 struct slave *tx_slave; in bond_tlb_xmit()
1419 struct slave *bond_xmit_alb_slave_get(struct bonding *bond, in bond_xmit_alb_slave_get()
1424 struct slave *tx_slave = NULL; in bond_xmit_alb_slave_get()
1434 switch (ntohs(skb->protocol)) { in bond_xmit_alb_slave_get()
1438 if (is_broadcast_ether_addr(eth_data->h_dest) || in bond_xmit_alb_slave_get()
1444 if (iph->daddr == ip_bcast || iph->protocol == IPPROTO_IGMP) { in bond_xmit_alb_slave_get()
1448 hash_start = (char *)&(iph->daddr); in bond_xmit_alb_slave_get()
1449 hash_size = sizeof(iph->daddr); in bond_xmit_alb_slave_get()
1458 if (is_broadcast_ether_addr(eth_data->h_dest)) { in bond_xmit_alb_slave_get()
1463 /* IPv6 uses all-nodes multicast as an equivalent to in bond_xmit_alb_slave_get()
1466 if (ether_addr_equal_64bits(eth_data->h_dest, mac_v6_allmcast)) { in bond_xmit_alb_slave_get()
1477 /* Additionally, DAD probes should not be tx-balanced as that in bond_xmit_alb_slave_get()
1482 if (ipv6_addr_any(&ip6hdr->saddr)) { in bond_xmit_alb_slave_get()
1487 hash_start = (char *)&ip6hdr->daddr; in bond_xmit_alb_slave_get()
1488 hash_size = sizeof(ip6hdr->daddr); in bond_xmit_alb_slave_get()
1493 if (bond_info->rlb_enabled) in bond_xmit_alb_slave_get()
1502 if (bond->params.tlb_dynamic_lb) { in bond_xmit_alb_slave_get()
1504 tx_slave = tlb_choose_channel(bond, hash_index, skb->len); in bond_xmit_alb_slave_get()
1514 slaves = rcu_dereference(bond->usable_slaves); in bond_xmit_alb_slave_get()
1515 count = slaves ? READ_ONCE(slaves->count) : 0; in bond_xmit_alb_slave_get()
1517 tx_slave = slaves->arr[bond_xmit_hash(bond, skb) % in bond_xmit_alb_slave_get()
1527 struct slave *tx_slave = NULL; in bond_alb_xmit()
1539 struct slave *slave; in bond_alb_monitor() local
1542 atomic_set(&bond_info->tx_rebalance_counter, 0); in bond_alb_monitor()
1543 bond_info->lp_counter = 0; in bond_alb_monitor()
1549 atomic_inc(&bond_info->tx_rebalance_counter); in bond_alb_monitor()
1550 bond_info->lp_counter++; in bond_alb_monitor()
1553 if (bond_info->lp_counter >= BOND_ALB_LP_TICKS(bond)) { in bond_alb_monitor()
1556 bond_for_each_slave_rcu(bond, slave, iter) { in bond_alb_monitor()
1559 * use mac of the slave device. in bond_alb_monitor()
1562 strict_match = (slave != rcu_access_pointer(bond->curr_active_slave) || in bond_alb_monitor()
1563 bond_info->rlb_enabled); in bond_alb_monitor()
1564 alb_send_learning_packets(slave, slave->dev->dev_addr, in bond_alb_monitor()
1567 bond_info->lp_counter = 0; in bond_alb_monitor()
1571 if (atomic_read(&bond_info->tx_rebalance_counter) >= BOND_TLB_REBALANCE_TICKS) { in bond_alb_monitor()
1572 bond_for_each_slave_rcu(bond, slave, iter) { in bond_alb_monitor()
1573 tlb_clear_slave(bond, slave, 1); in bond_alb_monitor()
1574 if (slave == rcu_access_pointer(bond->curr_active_slave)) { in bond_alb_monitor()
1575 SLAVE_TLB_INFO(slave).load = in bond_alb_monitor()
1576 bond_info->unbalanced_load / in bond_alb_monitor()
1578 bond_info->unbalanced_load = 0; in bond_alb_monitor()
1581 atomic_set(&bond_info->tx_rebalance_counter, 0); in bond_alb_monitor()
1584 if (bond_info->rlb_enabled) { in bond_alb_monitor()
1585 if (bond_info->primary_is_promisc && in bond_alb_monitor()
1586 (++bond_info->rlb_promisc_timeout_counter >= RLB_PROMISC_TIMEOUT)) { in bond_alb_monitor()
1595 bond_info->rlb_promisc_timeout_counter = 0; in bond_alb_monitor()
1598 * because a slave was disabled then in bond_alb_monitor()
1601 dev_set_promiscuity(rtnl_dereference(bond->curr_active_slave)->dev, in bond_alb_monitor()
1602 -1); in bond_alb_monitor()
1603 bond_info->primary_is_promisc = 0; in bond_alb_monitor()
1609 if (bond_info->rlb_rebalance) { in bond_alb_monitor()
1610 bond_info->rlb_rebalance = 0; in bond_alb_monitor()
1615 if (bond_info->rx_ntt) { in bond_alb_monitor()
1616 if (bond_info->rlb_update_delay_counter) { in bond_alb_monitor()
1617 --bond_info->rlb_update_delay_counter; in bond_alb_monitor()
1620 if (bond_info->rlb_update_retry_counter) in bond_alb_monitor()
1621 --bond_info->rlb_update_retry_counter; in bond_alb_monitor()
1623 bond_info->rx_ntt = 0; in bond_alb_monitor()
1629 queue_delayed_work(bond->wq, &bond->alb_work, alb_delta_in_ticks); in bond_alb_monitor()
1632 /* assumption: called before the slave is attached to the bond
1635 int bond_alb_init_slave(struct bonding *bond, struct slave *slave) in bond_alb_init_slave() argument
1639 res = alb_set_slave_mac_addr(slave, slave->perm_hwaddr, in bond_alb_init_slave()
1640 slave->dev->addr_len); in bond_alb_init_slave()
1644 res = alb_handle_addr_collision_on_attach(bond, slave); in bond_alb_init_slave()
1648 tlb_init_slave(slave); in bond_alb_init_slave()
1651 atomic_set(&bond->alb_info.tx_rebalance_counter, in bond_alb_init_slave()
1654 if (bond->alb_info.rlb_enabled) in bond_alb_init_slave()
1655 bond->alb_info.rlb_rebalance = 1; in bond_alb_init_slave()
1660 /* Remove slave from tlb and rlb hash tables, and fix up MAC addresses
1665 void bond_alb_deinit_slave(struct bonding *bond, struct slave *slave) in bond_alb_deinit_slave() argument
1668 alb_change_hw_addr_on_detach(bond, slave); in bond_alb_deinit_slave()
1670 tlb_clear_slave(bond, slave, 0); in bond_alb_deinit_slave()
1672 if (bond->alb_info.rlb_enabled) { in bond_alb_deinit_slave()
1673 bond->alb_info.rx_slave = NULL; in bond_alb_deinit_slave()
1674 rlb_clear_slave(bond, slave); in bond_alb_deinit_slave()
1679 void bond_alb_handle_link_change(struct bonding *bond, struct slave *slave, char link) in bond_alb_handle_link_change() argument
1684 tlb_clear_slave(bond, slave, 0); in bond_alb_handle_link_change()
1685 if (bond->alb_info.rlb_enabled) in bond_alb_handle_link_change()
1686 rlb_clear_slave(bond, slave); in bond_alb_handle_link_change()
1689 atomic_set(&bond_info->tx_rebalance_counter, in bond_alb_handle_link_change()
1691 if (bond->alb_info.rlb_enabled) { in bond_alb_handle_link_change()
1692 bond->alb_info.rlb_rebalance = 1; in bond_alb_handle_link_change()
1703 pr_err("Failed to build slave-array for TLB mode.\n"); in bond_alb_handle_link_change()
1708 * bond_alb_handle_active_change - assign new curr_active_slave
1710 * @new_slave: new slave to assign
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) in bond_alb_handle_active_change()
1719 struct slave *swap_slave; in bond_alb_handle_active_change()
1720 struct slave *curr_active; in bond_alb_handle_active_change()
1722 curr_active = rtnl_dereference(bond->curr_active_slave); in bond_alb_handle_active_change()
1726 if (curr_active && bond->alb_info.primary_is_promisc) { in bond_alb_handle_active_change()
1727 dev_set_promiscuity(curr_active->dev, -1); in bond_alb_handle_active_change()
1728 bond->alb_info.primary_is_promisc = 0; in bond_alb_handle_active_change()
1729 bond->alb_info.rlb_promisc_timeout_counter = 0; in bond_alb_handle_active_change()
1733 rcu_assign_pointer(bond->curr_active_slave, new_slave); in bond_alb_handle_active_change()
1742 swap_slave = bond_slave_has_mac(bond, bond->dev->dev_addr); in bond_alb_handle_active_change()
1752 /* in TLB mode, the slave might flip down/up with the old dev_addr, in bond_alb_handle_active_change()
1753 * and thus filter bond->dev_addr's packets, so force bond's mac in bond_alb_handle_active_change()
1759 bond_hw_addr_copy(tmp_addr, new_slave->dev->dev_addr, in bond_alb_handle_active_change()
1760 new_slave->dev->addr_len); in bond_alb_handle_active_change()
1762 bond_hw_addr_copy(ss.__data, bond->dev->dev_addr, in bond_alb_handle_active_change()
1763 bond->dev->addr_len); in bond_alb_handle_active_change()
1764 ss.ss_family = bond->dev->type; in bond_alb_handle_active_change()
1766 dev_set_mac_address(new_slave->dev, (struct sockaddr *)&ss, in bond_alb_handle_active_change()
1769 dev_addr_set(new_slave->dev, tmp_addr); in bond_alb_handle_active_change()
1779 alb_set_slave_mac_addr(new_slave, bond->dev->dev_addr, in bond_alb_handle_active_change()
1780 bond->dev->addr_len); in bond_alb_handle_active_change()
1781 alb_send_learning_packets(new_slave, bond->dev->dev_addr, in bond_alb_handle_active_change()
1787 int bond_alb_set_mac_address(struct net_device *bond_dev, void *addr) in bond_alb_set_mac_address() argument
1790 struct sockaddr_storage *ss = addr; in bond_alb_set_mac_address()
1791 struct slave *curr_active; in bond_alb_set_mac_address()
1792 struct slave *swap_slave; in bond_alb_set_mac_address()
1795 if (!is_valid_ether_addr(ss->__data)) in bond_alb_set_mac_address()
1796 return -EADDRNOTAVAIL; in bond_alb_set_mac_address()
1798 res = alb_set_mac_address(bond, addr); in bond_alb_set_mac_address()
1802 dev_addr_set(bond_dev, ss->__data); in bond_alb_set_mac_address()
1808 curr_active = rtnl_dereference(bond->curr_active_slave); in bond_alb_set_mac_address()
1812 swap_slave = bond_slave_has_mac(bond, bond_dev->dev_addr); in bond_alb_set_mac_address()
1818 alb_set_slave_mac_addr(curr_active, bond_dev->dev_addr, in bond_alb_set_mac_address()
1819 bond_dev->addr_len); in bond_alb_set_mac_address()
1822 bond_dev->dev_addr, false); in bond_alb_set_mac_address()
1823 if (bond->alb_info.rlb_enabled) { in bond_alb_set_mac_address()
1834 if (bond->alb_info.rlb_enabled) in bond_alb_clear_vlan()