2 * Copyright(c) 1999 - 2004 Intel Corporation. All rights reserved.
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 * The full GNU General Public License is included in this distribution in the
19 * file called LICENSE.
23 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
25 #include <linux/skbuff.h>
26 #include <linux/netdevice.h>
27 #include <linux/etherdevice.h>
28 #include <linux/pkt_sched.h>
29 #include <linux/spinlock.h>
30 #include <linux/slab.h>
31 #include <linux/timer.h>
33 #include <linux/ipv6.h>
34 #include <linux/if_arp.h>
35 #include <linux/if_ether.h>
36 #include <linux/if_bonding.h>
37 #include <linux/if_vlan.h>
42 #include <asm/byteorder.h>
47 #define ALB_TIMER_TICKS_PER_SEC 10 /* should be a divisor of HZ */
48 #define BOND_TLB_REBALANCE_INTERVAL 10 /* In seconds, periodic re-balancing.
49 * Used for division - never set
52 #define BOND_ALB_LP_INTERVAL 1 /* In seconds, periodic send of
53 * learning packets to the switch
56 #define BOND_TLB_REBALANCE_TICKS (BOND_TLB_REBALANCE_INTERVAL \
57 * ALB_TIMER_TICKS_PER_SEC)
59 #define BOND_ALB_LP_TICKS (BOND_ALB_LP_INTERVAL \
60 * ALB_TIMER_TICKS_PER_SEC)
62 #define TLB_HASH_TABLE_SIZE 256 /* The size of the clients hash table.
63 * Note that this value MUST NOT be smaller
64 * because the key hash table is BYTE wide !
68 #define TLB_NULL_INDEX 0xffffffff
69 #define MAX_LP_BURST 3
72 #define RLB_HASH_TABLE_SIZE 256
73 #define RLB_NULL_INDEX 0xffffffff
74 #define RLB_UPDATE_DELAY 2*ALB_TIMER_TICKS_PER_SEC /* 2 seconds */
75 #define RLB_ARP_BURST_SIZE 2
76 #define RLB_UPDATE_RETRY 3 /* 3-ticks - must be smaller than the rlb
77 * rebalance interval (5 min).
79 /* RLB_PROMISC_TIMEOUT = 10 sec equals the time that the current slave is
80 * promiscuous after failover
82 #define RLB_PROMISC_TIMEOUT 10*ALB_TIMER_TICKS_PER_SEC
84 #ifndef __long_aligned
85 #define __long_aligned __attribute__((aligned((sizeof(long)))))
87 static const u8 mac_bcast[ETH_ALEN] __long_aligned = {
88 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
90 static const u8 mac_v6_allmcast[ETH_ALEN] __long_aligned = {
91 0x33, 0x33, 0x00, 0x00, 0x00, 0x01
93 static const int alb_delta_in_ticks = HZ / ALB_TIMER_TICKS_PER_SEC;
100 u8 padding[ETH_ZLEN - ETH_HLEN];
104 __be16 hw_addr_space;
105 __be16 prot_addr_space;
109 u8 mac_src[ETH_ALEN]; /* sender hardware address */
110 __be32 ip_src; /* sender IP address */
111 u8 mac_dst[ETH_ALEN]; /* target hardware address */
112 __be32 ip_dst; /* target IP address */
116 static inline struct arp_pkt *arp_pkt(const struct sk_buff *skb)
118 return (struct arp_pkt *)skb_network_header(skb);
121 /* Forward declaration */
122 static void alb_send_learning_packets(struct slave *slave, u8 mac_addr[]);
124 static inline u8 _simple_hash(const u8 *hash_start, int hash_size)
129 for (i = 0; i < hash_size; i++) {
130 hash ^= hash_start[i];
136 /*********************** tlb specific functions ***************************/
138 static inline void _lock_tx_hashtbl(struct bonding *bond)
140 spin_lock_bh(&(BOND_ALB_INFO(bond).tx_hashtbl_lock));
143 static inline void _unlock_tx_hashtbl(struct bonding *bond)
145 spin_unlock_bh(&(BOND_ALB_INFO(bond).tx_hashtbl_lock));
148 /* Caller must hold tx_hashtbl lock */
149 static inline void tlb_init_table_entry(struct tlb_client_info *entry, int save_load)
152 entry->load_history = 1 + entry->tx_bytes /
153 BOND_TLB_REBALANCE_INTERVAL;
157 entry->tx_slave = NULL;
158 entry->next = TLB_NULL_INDEX;
159 entry->prev = TLB_NULL_INDEX;
162 static inline void tlb_init_slave(struct slave *slave)
164 SLAVE_TLB_INFO(slave).load = 0;
165 SLAVE_TLB_INFO(slave).head = TLB_NULL_INDEX;
168 /* Caller must hold bond lock for read */
169 static void tlb_clear_slave(struct bonding *bond, struct slave *slave, int save_load)
171 struct tlb_client_info *tx_hash_table;
174 _lock_tx_hashtbl(bond);
176 /* clear slave from tx_hashtbl */
177 tx_hash_table = BOND_ALB_INFO(bond).tx_hashtbl;
179 /* skip this if we've already freed the tx hash table */
181 index = SLAVE_TLB_INFO(slave).head;
182 while (index != TLB_NULL_INDEX) {
183 u32 next_index = tx_hash_table[index].next;
184 tlb_init_table_entry(&tx_hash_table[index], save_load);
189 tlb_init_slave(slave);
191 _unlock_tx_hashtbl(bond);
194 /* Must be called before starting the monitor timer */
195 static int tlb_initialize(struct bonding *bond)
197 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
198 int size = TLB_HASH_TABLE_SIZE * sizeof(struct tlb_client_info);
199 struct tlb_client_info *new_hashtbl;
202 spin_lock_init(&(bond_info->tx_hashtbl_lock));
204 new_hashtbl = kzalloc(size, GFP_KERNEL);
206 pr_err("%s: Error: Failed to allocate TLB hash table\n",
210 _lock_tx_hashtbl(bond);
212 bond_info->tx_hashtbl = new_hashtbl;
214 for (i = 0; i < TLB_HASH_TABLE_SIZE; i++) {
215 tlb_init_table_entry(&bond_info->tx_hashtbl[i], 1);
218 _unlock_tx_hashtbl(bond);
223 /* Must be called only after all slaves have been released */
224 static void tlb_deinitialize(struct bonding *bond)
226 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
228 _lock_tx_hashtbl(bond);
230 kfree(bond_info->tx_hashtbl);
231 bond_info->tx_hashtbl = NULL;
233 _unlock_tx_hashtbl(bond);
236 static long long compute_gap(struct slave *slave)
238 return (s64) (slave->speed << 20) - /* Convert to Megabit per sec */
239 (s64) (SLAVE_TLB_INFO(slave).load << 3); /* Bytes to bits */
242 /* Caller must hold bond lock for read */
243 static struct slave *tlb_get_least_loaded_slave(struct bonding *bond)
245 struct slave *slave, *least_loaded;
252 /* Find the slave with the largest gap */
253 bond_for_each_slave(bond, slave, i) {
254 if (SLAVE_IS_OK(slave)) {
255 long long gap = compute_gap(slave);
258 least_loaded = slave;
267 /* Caller must hold bond lock for read */
268 static struct slave *tlb_choose_channel(struct bonding *bond, u32 hash_index, u32 skb_len)
270 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
271 struct tlb_client_info *hash_table;
272 struct slave *assigned_slave;
274 _lock_tx_hashtbl(bond);
276 hash_table = bond_info->tx_hashtbl;
277 assigned_slave = hash_table[hash_index].tx_slave;
278 if (!assigned_slave) {
279 assigned_slave = tlb_get_least_loaded_slave(bond);
281 if (assigned_slave) {
282 struct tlb_slave_info *slave_info =
283 &(SLAVE_TLB_INFO(assigned_slave));
284 u32 next_index = slave_info->head;
286 hash_table[hash_index].tx_slave = assigned_slave;
287 hash_table[hash_index].next = next_index;
288 hash_table[hash_index].prev = TLB_NULL_INDEX;
290 if (next_index != TLB_NULL_INDEX) {
291 hash_table[next_index].prev = hash_index;
294 slave_info->head = hash_index;
296 hash_table[hash_index].load_history;
300 if (assigned_slave) {
301 hash_table[hash_index].tx_bytes += skb_len;
304 _unlock_tx_hashtbl(bond);
306 return assigned_slave;
309 /*********************** rlb specific functions ***************************/
310 static inline void _lock_rx_hashtbl(struct bonding *bond)
312 spin_lock_bh(&(BOND_ALB_INFO(bond).rx_hashtbl_lock));
315 static inline void _unlock_rx_hashtbl(struct bonding *bond)
317 spin_unlock_bh(&(BOND_ALB_INFO(bond).rx_hashtbl_lock));
320 /* when an ARP REPLY is received from a client update its info
323 static void rlb_update_entry_from_arp(struct bonding *bond, struct arp_pkt *arp)
325 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
326 struct rlb_client_info *client_info;
329 _lock_rx_hashtbl(bond);
331 hash_index = _simple_hash((u8*)&(arp->ip_src), sizeof(arp->ip_src));
332 client_info = &(bond_info->rx_hashtbl[hash_index]);
334 if ((client_info->assigned) &&
335 (client_info->ip_src == arp->ip_dst) &&
336 (client_info->ip_dst == arp->ip_src) &&
337 (compare_ether_addr_64bits(client_info->mac_dst, arp->mac_src))) {
338 /* update the clients MAC address */
339 memcpy(client_info->mac_dst, arp->mac_src, ETH_ALEN);
340 client_info->ntt = 1;
341 bond_info->rx_ntt = 1;
344 _unlock_rx_hashtbl(bond);
347 static int rlb_arp_recv(struct sk_buff *skb, struct net_device *bond_dev, struct packet_type *ptype, struct net_device *orig_dev)
349 struct bonding *bond;
350 struct arp_pkt *arp = (struct arp_pkt *)skb->data;
351 int res = NET_RX_DROP;
353 while (bond_dev->priv_flags & IFF_802_1Q_VLAN)
354 bond_dev = vlan_dev_real_dev(bond_dev);
356 if (!(bond_dev->priv_flags & IFF_BONDING) ||
357 !(bond_dev->flags & IFF_MASTER))
361 pr_debug("Packet has no ARP data\n");
365 if (skb->len < sizeof(struct arp_pkt)) {
366 pr_debug("Packet is too small to be an ARP\n");
370 if (arp->op_code == htons(ARPOP_REPLY)) {
371 /* update rx hash table for this ARP */
372 bond = netdev_priv(bond_dev);
373 rlb_update_entry_from_arp(bond, arp);
374 pr_debug("Server received an ARP Reply from client\n");
377 res = NET_RX_SUCCESS;
385 /* Caller must hold bond lock for read */
386 static struct slave *rlb_next_rx_slave(struct bonding *bond)
388 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
389 struct slave *rx_slave, *slave, *start_at;
392 if (bond_info->next_rx_slave) {
393 start_at = bond_info->next_rx_slave;
395 start_at = bond->first_slave;
400 bond_for_each_slave_from(bond, slave, i, start_at) {
401 if (SLAVE_IS_OK(slave)) {
404 } else if (slave->speed > rx_slave->speed) {
411 bond_info->next_rx_slave = rx_slave->next;
417 /* teach the switch the mac of a disabled slave
418 * on the primary for fault tolerance
420 * Caller must hold bond->curr_slave_lock for write or bond lock for write
422 static void rlb_teach_disabled_mac_on_primary(struct bonding *bond, u8 addr[])
424 if (!bond->curr_active_slave) {
428 if (!bond->alb_info.primary_is_promisc) {
429 if (!dev_set_promiscuity(bond->curr_active_slave->dev, 1))
430 bond->alb_info.primary_is_promisc = 1;
432 bond->alb_info.primary_is_promisc = 0;
435 bond->alb_info.rlb_promisc_timeout_counter = 0;
437 alb_send_learning_packets(bond->curr_active_slave, addr);
440 /* slave being removed should not be active at this point
442 * Caller must hold bond lock for read
444 static void rlb_clear_slave(struct bonding *bond, struct slave *slave)
446 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
447 struct rlb_client_info *rx_hash_table;
448 u32 index, next_index;
450 /* clear slave from rx_hashtbl */
451 _lock_rx_hashtbl(bond);
453 rx_hash_table = bond_info->rx_hashtbl;
454 index = bond_info->rx_hashtbl_head;
455 for (; index != RLB_NULL_INDEX; index = next_index) {
456 next_index = rx_hash_table[index].next;
457 if (rx_hash_table[index].slave == slave) {
458 struct slave *assigned_slave = rlb_next_rx_slave(bond);
460 if (assigned_slave) {
461 rx_hash_table[index].slave = assigned_slave;
462 if (compare_ether_addr_64bits(rx_hash_table[index].mac_dst,
464 bond_info->rx_hashtbl[index].ntt = 1;
465 bond_info->rx_ntt = 1;
466 /* A slave has been removed from the
467 * table because it is either disabled
468 * or being released. We must retry the
469 * update to avoid clients from not
470 * being updated & disconnecting when
473 bond_info->rlb_update_retry_counter =
476 } else { /* there is no active slave */
477 rx_hash_table[index].slave = NULL;
482 _unlock_rx_hashtbl(bond);
484 write_lock_bh(&bond->curr_slave_lock);
486 if (slave != bond->curr_active_slave) {
487 rlb_teach_disabled_mac_on_primary(bond, slave->dev->dev_addr);
490 write_unlock_bh(&bond->curr_slave_lock);
493 static void rlb_update_client(struct rlb_client_info *client_info)
497 if (!client_info->slave) {
501 for (i = 0; i < RLB_ARP_BURST_SIZE; i++) {
504 skb = arp_create(ARPOP_REPLY, ETH_P_ARP,
506 client_info->slave->dev,
508 client_info->mac_dst,
509 client_info->slave->dev->dev_addr,
510 client_info->mac_dst);
512 pr_err("%s: Error: failed to create an ARP packet\n",
513 client_info->slave->dev->master->name);
517 skb->dev = client_info->slave->dev;
519 if (client_info->tag) {
520 skb = vlan_put_tag(skb, client_info->vlan_id);
522 pr_err("%s: Error: failed to insert VLAN tag\n",
523 client_info->slave->dev->master->name);
532 /* sends ARP REPLIES that update the clients that need updating */
533 static void rlb_update_rx_clients(struct bonding *bond)
535 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
536 struct rlb_client_info *client_info;
539 _lock_rx_hashtbl(bond);
541 hash_index = bond_info->rx_hashtbl_head;
542 for (; hash_index != RLB_NULL_INDEX; hash_index = client_info->next) {
543 client_info = &(bond_info->rx_hashtbl[hash_index]);
544 if (client_info->ntt) {
545 rlb_update_client(client_info);
546 if (bond_info->rlb_update_retry_counter == 0) {
547 client_info->ntt = 0;
552 /* do not update the entries again until this counter is zero so that
553 * not to confuse the clients.
555 bond_info->rlb_update_delay_counter = RLB_UPDATE_DELAY;
557 _unlock_rx_hashtbl(bond);
560 /* The slave was assigned a new mac address - update the clients */
561 static void rlb_req_update_slave_clients(struct bonding *bond, struct slave *slave)
563 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
564 struct rlb_client_info *client_info;
568 _lock_rx_hashtbl(bond);
570 hash_index = bond_info->rx_hashtbl_head;
571 for (; hash_index != RLB_NULL_INDEX; hash_index = client_info->next) {
572 client_info = &(bond_info->rx_hashtbl[hash_index]);
574 if ((client_info->slave == slave) &&
575 compare_ether_addr_64bits(client_info->mac_dst, mac_bcast)) {
576 client_info->ntt = 1;
581 // update the team's flag only after the whole iteration
583 bond_info->rx_ntt = 1;
585 bond_info->rlb_update_retry_counter = RLB_UPDATE_RETRY;
588 _unlock_rx_hashtbl(bond);
591 /* mark all clients using src_ip to be updated */
592 static void rlb_req_update_subnet_clients(struct bonding *bond, __be32 src_ip)
594 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
595 struct rlb_client_info *client_info;
598 _lock_rx_hashtbl(bond);
600 hash_index = bond_info->rx_hashtbl_head;
601 for (; hash_index != RLB_NULL_INDEX; hash_index = client_info->next) {
602 client_info = &(bond_info->rx_hashtbl[hash_index]);
604 if (!client_info->slave) {
605 pr_err("%s: Error: found a client with no channel in the client's hash table\n",
609 /*update all clients using this src_ip, that are not assigned
610 * to the team's address (curr_active_slave) and have a known
611 * unicast mac address.
613 if ((client_info->ip_src == src_ip) &&
614 compare_ether_addr_64bits(client_info->slave->dev->dev_addr,
615 bond->dev->dev_addr) &&
616 compare_ether_addr_64bits(client_info->mac_dst, mac_bcast)) {
617 client_info->ntt = 1;
618 bond_info->rx_ntt = 1;
622 _unlock_rx_hashtbl(bond);
625 /* Caller must hold both bond and ptr locks for read */
626 static struct slave *rlb_choose_channel(struct sk_buff *skb, struct bonding *bond)
628 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
629 struct arp_pkt *arp = arp_pkt(skb);
630 struct slave *assigned_slave;
631 struct rlb_client_info *client_info;
634 _lock_rx_hashtbl(bond);
636 hash_index = _simple_hash((u8 *)&arp->ip_dst, sizeof(arp->ip_src));
637 client_info = &(bond_info->rx_hashtbl[hash_index]);
639 if (client_info->assigned) {
640 if ((client_info->ip_src == arp->ip_src) &&
641 (client_info->ip_dst == arp->ip_dst)) {
642 /* the entry is already assigned to this client */
643 if (compare_ether_addr_64bits(arp->mac_dst, mac_bcast)) {
644 /* update mac address from arp */
645 memcpy(client_info->mac_dst, arp->mac_dst, ETH_ALEN);
648 assigned_slave = client_info->slave;
649 if (assigned_slave) {
650 _unlock_rx_hashtbl(bond);
651 return assigned_slave;
654 /* the entry is already assigned to some other client,
655 * move the old client to primary (curr_active_slave) so
656 * that the new client can be assigned to this entry.
658 if (bond->curr_active_slave &&
659 client_info->slave != bond->curr_active_slave) {
660 client_info->slave = bond->curr_active_slave;
661 rlb_update_client(client_info);
665 /* assign a new slave */
666 assigned_slave = rlb_next_rx_slave(bond);
668 if (assigned_slave) {
669 client_info->ip_src = arp->ip_src;
670 client_info->ip_dst = arp->ip_dst;
671 /* arp->mac_dst is broadcast for arp reqeusts.
672 * will be updated with clients actual unicast mac address
673 * upon receiving an arp reply.
675 memcpy(client_info->mac_dst, arp->mac_dst, ETH_ALEN);
676 client_info->slave = assigned_slave;
678 if (compare_ether_addr_64bits(client_info->mac_dst, mac_bcast)) {
679 client_info->ntt = 1;
680 bond->alb_info.rx_ntt = 1;
682 client_info->ntt = 0;
686 if (!vlan_get_tag(skb, &client_info->vlan_id))
687 client_info->tag = 1;
690 if (!client_info->assigned) {
691 u32 prev_tbl_head = bond_info->rx_hashtbl_head;
692 bond_info->rx_hashtbl_head = hash_index;
693 client_info->next = prev_tbl_head;
694 if (prev_tbl_head != RLB_NULL_INDEX) {
695 bond_info->rx_hashtbl[prev_tbl_head].prev =
698 client_info->assigned = 1;
702 _unlock_rx_hashtbl(bond);
704 return assigned_slave;
707 /* chooses (and returns) transmit channel for arp reply
708 * does not choose channel for other arp types since they are
709 * sent on the curr_active_slave
711 static struct slave *rlb_arp_xmit(struct sk_buff *skb, struct bonding *bond)
713 struct arp_pkt *arp = arp_pkt(skb);
714 struct slave *tx_slave = NULL;
716 if (arp->op_code == htons(ARPOP_REPLY)) {
717 /* the arp must be sent on the selected
720 tx_slave = rlb_choose_channel(skb, bond);
722 memcpy(arp->mac_src,tx_slave->dev->dev_addr, ETH_ALEN);
724 pr_debug("Server sent ARP Reply packet\n");
725 } else if (arp->op_code == htons(ARPOP_REQUEST)) {
726 /* Create an entry in the rx_hashtbl for this client as a
728 * When the arp reply is received the entry will be updated
729 * with the correct unicast address of the client.
731 rlb_choose_channel(skb, bond);
733 /* The ARP relpy packets must be delayed so that
734 * they can cancel out the influence of the ARP request.
736 bond->alb_info.rlb_update_delay_counter = RLB_UPDATE_DELAY;
738 /* arp requests are broadcast and are sent on the primary
739 * the arp request will collapse all clients on the subnet to
740 * the primary slave. We must register these clients to be
741 * updated with their assigned mac.
743 rlb_req_update_subnet_clients(bond, arp->ip_src);
744 pr_debug("Server sent ARP Request packet\n");
750 /* Caller must hold bond lock for read */
751 static void rlb_rebalance(struct bonding *bond)
753 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
754 struct slave *assigned_slave;
755 struct rlb_client_info *client_info;
759 _lock_rx_hashtbl(bond);
762 hash_index = bond_info->rx_hashtbl_head;
763 for (; hash_index != RLB_NULL_INDEX; hash_index = client_info->next) {
764 client_info = &(bond_info->rx_hashtbl[hash_index]);
765 assigned_slave = rlb_next_rx_slave(bond);
766 if (assigned_slave && (client_info->slave != assigned_slave)) {
767 client_info->slave = assigned_slave;
768 client_info->ntt = 1;
773 /* update the team's flag only after the whole iteration */
775 bond_info->rx_ntt = 1;
777 _unlock_rx_hashtbl(bond);
780 /* Caller must hold rx_hashtbl lock */
781 static void rlb_init_table_entry(struct rlb_client_info *entry)
783 memset(entry, 0, sizeof(struct rlb_client_info));
784 entry->next = RLB_NULL_INDEX;
785 entry->prev = RLB_NULL_INDEX;
788 static int rlb_initialize(struct bonding *bond)
790 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
791 struct packet_type *pk_type = &(BOND_ALB_INFO(bond).rlb_pkt_type);
792 struct rlb_client_info *new_hashtbl;
793 int size = RLB_HASH_TABLE_SIZE * sizeof(struct rlb_client_info);
796 spin_lock_init(&(bond_info->rx_hashtbl_lock));
798 new_hashtbl = kmalloc(size, GFP_KERNEL);
800 pr_err("%s: Error: Failed to allocate RLB hash table\n",
804 _lock_rx_hashtbl(bond);
806 bond_info->rx_hashtbl = new_hashtbl;
808 bond_info->rx_hashtbl_head = RLB_NULL_INDEX;
810 for (i = 0; i < RLB_HASH_TABLE_SIZE; i++) {
811 rlb_init_table_entry(bond_info->rx_hashtbl + i);
814 _unlock_rx_hashtbl(bond);
816 /*initialize packet type*/
817 pk_type->type = cpu_to_be16(ETH_P_ARP);
818 pk_type->dev = bond->dev;
819 pk_type->func = rlb_arp_recv;
821 /* register to receive ARPs */
822 dev_add_pack(pk_type);
827 static void rlb_deinitialize(struct bonding *bond)
829 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
831 dev_remove_pack(&(bond_info->rlb_pkt_type));
833 _lock_rx_hashtbl(bond);
835 kfree(bond_info->rx_hashtbl);
836 bond_info->rx_hashtbl = NULL;
837 bond_info->rx_hashtbl_head = RLB_NULL_INDEX;
839 _unlock_rx_hashtbl(bond);
842 static void rlb_clear_vlan(struct bonding *bond, unsigned short vlan_id)
844 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
847 _lock_rx_hashtbl(bond);
849 curr_index = bond_info->rx_hashtbl_head;
850 while (curr_index != RLB_NULL_INDEX) {
851 struct rlb_client_info *curr = &(bond_info->rx_hashtbl[curr_index]);
852 u32 next_index = bond_info->rx_hashtbl[curr_index].next;
853 u32 prev_index = bond_info->rx_hashtbl[curr_index].prev;
855 if (curr->tag && (curr->vlan_id == vlan_id)) {
856 if (curr_index == bond_info->rx_hashtbl_head) {
857 bond_info->rx_hashtbl_head = next_index;
859 if (prev_index != RLB_NULL_INDEX) {
860 bond_info->rx_hashtbl[prev_index].next = next_index;
862 if (next_index != RLB_NULL_INDEX) {
863 bond_info->rx_hashtbl[next_index].prev = prev_index;
866 rlb_init_table_entry(curr);
869 curr_index = next_index;
872 _unlock_rx_hashtbl(bond);
875 /*********************** tlb/rlb shared functions *********************/
877 static void alb_send_learning_packets(struct slave *slave, u8 mac_addr[])
879 struct bonding *bond = bond_get_bond_by_slave(slave);
880 struct learning_pkt pkt;
881 int size = sizeof(struct learning_pkt);
884 memset(&pkt, 0, size);
885 memcpy(pkt.mac_dst, mac_addr, ETH_ALEN);
886 memcpy(pkt.mac_src, mac_addr, ETH_ALEN);
887 pkt.type = cpu_to_be16(ETH_P_LOOP);
889 for (i = 0; i < MAX_LP_BURST; i++) {
893 skb = dev_alloc_skb(size);
898 data = skb_put(skb, size);
899 memcpy(data, &pkt, size);
901 skb_reset_mac_header(skb);
902 skb->network_header = skb->mac_header + ETH_HLEN;
903 skb->protocol = pkt.type;
904 skb->priority = TC_PRIO_CONTROL;
905 skb->dev = slave->dev;
908 struct vlan_entry *vlan;
910 vlan = bond_next_vlan(bond,
911 bond->alb_info.current_alb_vlan);
913 bond->alb_info.current_alb_vlan = vlan;
919 skb = vlan_put_tag(skb, vlan->vlan_id);
921 pr_err("%s: Error: failed to insert VLAN tag\n",
931 /* hw is a boolean parameter that determines whether we should try and
932 * set the hw address of the device as well as the hw address of the
935 static int alb_set_slave_mac_addr(struct slave *slave, u8 addr[], int hw)
937 struct net_device *dev = slave->dev;
938 struct sockaddr s_addr;
941 memcpy(dev->dev_addr, addr, dev->addr_len);
945 /* for rlb each slave must have a unique hw mac addresses so that */
946 /* each slave will receive packets destined to a different mac */
947 memcpy(s_addr.sa_data, addr, dev->addr_len);
948 s_addr.sa_family = dev->type;
949 if (dev_set_mac_address(dev, &s_addr)) {
950 pr_err("%s: Error: dev_set_mac_address of dev %s failed!\n"
951 "ALB mode requires that the base driver support setting the hw address also when the network device's interface is open\n",
952 dev->master->name, dev->name);
959 * Swap MAC addresses between two slaves.
961 * Called with RTNL held, and no other locks.
965 static void alb_swap_mac_addr(struct bonding *bond, struct slave *slave1, struct slave *slave2)
967 u8 tmp_mac_addr[ETH_ALEN];
969 memcpy(tmp_mac_addr, slave1->dev->dev_addr, ETH_ALEN);
970 alb_set_slave_mac_addr(slave1, slave2->dev->dev_addr, bond->alb_info.rlb_enabled);
971 alb_set_slave_mac_addr(slave2, tmp_mac_addr, bond->alb_info.rlb_enabled);
976 * Send learning packets after MAC address swap.
978 * Called with RTNL and no other locks
980 static void alb_fasten_mac_swap(struct bonding *bond, struct slave *slave1,
981 struct slave *slave2)
983 int slaves_state_differ = (SLAVE_IS_OK(slave1) != SLAVE_IS_OK(slave2));
984 struct slave *disabled_slave = NULL;
988 /* fasten the change in the switch */
989 if (SLAVE_IS_OK(slave1)) {
990 alb_send_learning_packets(slave1, slave1->dev->dev_addr);
991 if (bond->alb_info.rlb_enabled) {
992 /* inform the clients that the mac address
995 rlb_req_update_slave_clients(bond, slave1);
998 disabled_slave = slave1;
1001 if (SLAVE_IS_OK(slave2)) {
1002 alb_send_learning_packets(slave2, slave2->dev->dev_addr);
1003 if (bond->alb_info.rlb_enabled) {
1004 /* inform the clients that the mac address
1007 rlb_req_update_slave_clients(bond, slave2);
1010 disabled_slave = slave2;
1013 if (bond->alb_info.rlb_enabled && slaves_state_differ) {
1014 /* A disabled slave was assigned an active mac addr */
1015 rlb_teach_disabled_mac_on_primary(bond,
1016 disabled_slave->dev->dev_addr);
1021 * alb_change_hw_addr_on_detach
1022 * @bond: bonding we're working on
1023 * @slave: the slave that was just detached
1025 * We assume that @slave was already detached from the slave list.
1027 * If @slave's permanent hw address is different both from its current
1028 * address and from @bond's address, then somewhere in the bond there's
1029 * a slave that has @slave's permanet address as its current address.
1030 * We'll make sure that that slave no longer uses @slave's permanent address.
1032 * Caller must hold RTNL and no other locks
1034 static void alb_change_hw_addr_on_detach(struct bonding *bond, struct slave *slave)
1039 perm_curr_diff = compare_ether_addr_64bits(slave->perm_hwaddr,
1040 slave->dev->dev_addr);
1041 perm_bond_diff = compare_ether_addr_64bits(slave->perm_hwaddr,
1042 bond->dev->dev_addr);
1044 if (perm_curr_diff && perm_bond_diff) {
1045 struct slave *tmp_slave;
1048 bond_for_each_slave(bond, tmp_slave, i) {
1049 if (!compare_ether_addr_64bits(slave->perm_hwaddr,
1050 tmp_slave->dev->dev_addr)) {
1057 /* locking: needs RTNL and nothing else */
1058 alb_swap_mac_addr(bond, slave, tmp_slave);
1059 alb_fasten_mac_swap(bond, slave, tmp_slave);
1065 * alb_handle_addr_collision_on_attach
1066 * @bond: bonding we're working on
1067 * @slave: the slave that was just attached
1069 * checks uniqueness of slave's mac address and handles the case the
1070 * new slave uses the bonds mac address.
1072 * If the permanent hw address of @slave is @bond's hw address, we need to
1073 * find a different hw address to give @slave, that isn't in use by any other
1074 * slave in the bond. This address must be, of course, one of the premanent
1075 * addresses of the other slaves.
1077 * We go over the slave list, and for each slave there we compare its
1078 * permanent hw address with the current address of all the other slaves.
1079 * If no match was found, then we've found a slave with a permanent address
1080 * that isn't used by any other slave in the bond, so we can assign it to
1083 * assumption: this function is called before @slave is attached to the
1086 * caller must hold the bond lock for write since the mac addresses are compared
1087 * and may be swapped.
1089 static int alb_handle_addr_collision_on_attach(struct bonding *bond, struct slave *slave)
1091 struct slave *tmp_slave1, *tmp_slave2, *free_mac_slave;
1092 struct slave *has_bond_addr = bond->curr_active_slave;
1093 int i, j, found = 0;
1095 if (bond->slave_cnt == 0) {
1096 /* this is the first slave */
1100 /* if slave's mac address differs from bond's mac address
1101 * check uniqueness of slave's mac address against the other
1102 * slaves in the bond.
1104 if (compare_ether_addr_64bits(slave->perm_hwaddr, bond->dev->dev_addr)) {
1105 bond_for_each_slave(bond, tmp_slave1, i) {
1106 if (!compare_ether_addr_64bits(tmp_slave1->dev->dev_addr,
1107 slave->dev->dev_addr)) {
1116 /* Try setting slave mac to bond address and fall-through
1117 to code handling that situation below... */
1118 alb_set_slave_mac_addr(slave, bond->dev->dev_addr,
1119 bond->alb_info.rlb_enabled);
1122 /* The slave's address is equal to the address of the bond.
1123 * Search for a spare address in the bond for this slave.
1125 free_mac_slave = NULL;
1127 bond_for_each_slave(bond, tmp_slave1, i) {
1129 bond_for_each_slave(bond, tmp_slave2, j) {
1130 if (!compare_ether_addr_64bits(tmp_slave1->perm_hwaddr,
1131 tmp_slave2->dev->dev_addr)) {
1138 /* no slave has tmp_slave1's perm addr
1141 free_mac_slave = tmp_slave1;
1145 if (!has_bond_addr) {
1146 if (!compare_ether_addr_64bits(tmp_slave1->dev->dev_addr,
1147 bond->dev->dev_addr)) {
1149 has_bond_addr = tmp_slave1;
1154 if (free_mac_slave) {
1155 alb_set_slave_mac_addr(slave, free_mac_slave->perm_hwaddr,
1156 bond->alb_info.rlb_enabled);
1158 pr_warning("%s: Warning: the hw address of slave %s is in use by the bond; giving it the hw address of %s\n",
1159 bond->dev->name, slave->dev->name,
1160 free_mac_slave->dev->name);
1162 } else if (has_bond_addr) {
1163 pr_err("%s: Error: the hw address of slave %s 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",
1164 bond->dev->name, slave->dev->name);
1172 * alb_set_mac_address
1176 * In TLB mode all slaves are configured to the bond's hw address, but set
1177 * their dev_addr field to different addresses (based on their permanent hw
1180 * For each slave, this function sets the interface to the new address and then
1181 * changes its dev_addr field to its previous value.
1183 * Unwinding assumes bond's mac address has not yet changed.
1185 static int alb_set_mac_address(struct bonding *bond, void *addr)
1188 struct slave *slave, *stop_at;
1189 char tmp_addr[ETH_ALEN];
1193 if (bond->alb_info.rlb_enabled) {
1197 bond_for_each_slave(bond, slave, i) {
1198 /* save net_device's current hw address */
1199 memcpy(tmp_addr, slave->dev->dev_addr, ETH_ALEN);
1201 res = dev_set_mac_address(slave->dev, addr);
1203 /* restore net_device's hw address */
1204 memcpy(slave->dev->dev_addr, tmp_addr, ETH_ALEN);
1213 memcpy(sa.sa_data, bond->dev->dev_addr, bond->dev->addr_len);
1214 sa.sa_family = bond->dev->type;
1216 /* unwind from head to the slave that failed */
1218 bond_for_each_slave_from_to(bond, slave, i, bond->first_slave, stop_at) {
1219 memcpy(tmp_addr, slave->dev->dev_addr, ETH_ALEN);
1220 dev_set_mac_address(slave->dev, &sa);
1221 memcpy(slave->dev->dev_addr, tmp_addr, ETH_ALEN);
1227 /************************ exported alb funcions ************************/
1229 int bond_alb_initialize(struct bonding *bond, int rlb_enabled)
1233 res = tlb_initialize(bond);
1239 bond->alb_info.rlb_enabled = 1;
1240 /* initialize rlb */
1241 res = rlb_initialize(bond);
1243 tlb_deinitialize(bond);
1247 bond->alb_info.rlb_enabled = 0;
1253 void bond_alb_deinitialize(struct bonding *bond)
1255 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
1257 tlb_deinitialize(bond);
1259 if (bond_info->rlb_enabled) {
1260 rlb_deinitialize(bond);
1264 int bond_alb_xmit(struct sk_buff *skb, struct net_device *bond_dev)
1266 struct bonding *bond = netdev_priv(bond_dev);
1267 struct ethhdr *eth_data;
1268 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
1269 struct slave *tx_slave = NULL;
1270 static const __be32 ip_bcast = htonl(0xffffffff);
1272 int do_tx_balance = 1;
1274 const u8 *hash_start = NULL;
1276 struct ipv6hdr *ip6hdr;
1278 skb_reset_mac_header(skb);
1279 eth_data = eth_hdr(skb);
1281 /* make sure that the curr_active_slave and the slaves list do
1282 * not change during tx
1284 read_lock(&bond->lock);
1285 read_lock(&bond->curr_slave_lock);
1287 if (!BOND_IS_OK(bond)) {
1291 switch (ntohs(skb->protocol)) {
1293 const struct iphdr *iph = ip_hdr(skb);
1295 if (!compare_ether_addr_64bits(eth_data->h_dest, mac_bcast) ||
1296 (iph->daddr == ip_bcast) ||
1297 (iph->protocol == IPPROTO_IGMP)) {
1301 hash_start = (char *)&(iph->daddr);
1302 hash_size = sizeof(iph->daddr);
1306 /* IPv6 doesn't really use broadcast mac address, but leave
1307 * that here just in case.
1309 if (!compare_ether_addr_64bits(eth_data->h_dest, mac_bcast)) {
1314 /* IPv6 uses all-nodes multicast as an equivalent to
1315 * broadcasts in IPv4.
1317 if (!compare_ether_addr_64bits(eth_data->h_dest, mac_v6_allmcast)) {
1322 /* Additianally, DAD probes should not be tx-balanced as that
1323 * will lead to false positives for duplicate addresses and
1324 * prevent address configuration from working.
1326 ip6hdr = ipv6_hdr(skb);
1327 if (ipv6_addr_any(&ip6hdr->saddr)) {
1332 hash_start = (char *)&(ipv6_hdr(skb)->daddr);
1333 hash_size = sizeof(ipv6_hdr(skb)->daddr);
1336 if (ipx_hdr(skb)->ipx_checksum != IPX_NO_CHECKSUM) {
1337 /* something is wrong with this packet */
1342 if (ipx_hdr(skb)->ipx_type != IPX_TYPE_NCP) {
1343 /* The only protocol worth balancing in
1344 * this family since it has an "ARP" like
1351 hash_start = (char*)eth_data->h_dest;
1352 hash_size = ETH_ALEN;
1356 if (bond_info->rlb_enabled) {
1357 tx_slave = rlb_arp_xmit(skb, bond);
1365 if (do_tx_balance) {
1366 hash_index = _simple_hash(hash_start, hash_size);
1367 tx_slave = tlb_choose_channel(bond, hash_index, skb->len);
1371 /* unbalanced or unassigned, send through primary */
1372 tx_slave = bond->curr_active_slave;
1373 bond_info->unbalanced_load += skb->len;
1376 if (tx_slave && SLAVE_IS_OK(tx_slave)) {
1377 if (tx_slave != bond->curr_active_slave) {
1378 memcpy(eth_data->h_source,
1379 tx_slave->dev->dev_addr,
1383 res = bond_dev_queue_xmit(bond, skb, tx_slave->dev);
1386 tlb_clear_slave(bond, tx_slave, 0);
1392 /* no suitable interface, frame not sent */
1395 read_unlock(&bond->curr_slave_lock);
1396 read_unlock(&bond->lock);
1397 return NETDEV_TX_OK;
1400 void bond_alb_monitor(struct work_struct *work)
1402 struct bonding *bond = container_of(work, struct bonding,
1404 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
1405 struct slave *slave;
1408 read_lock(&bond->lock);
1410 if (bond->kill_timers) {
1414 if (bond->slave_cnt == 0) {
1415 bond_info->tx_rebalance_counter = 0;
1416 bond_info->lp_counter = 0;
1420 bond_info->tx_rebalance_counter++;
1421 bond_info->lp_counter++;
1423 /* send learning packets */
1424 if (bond_info->lp_counter >= BOND_ALB_LP_TICKS) {
1425 /* change of curr_active_slave involves swapping of mac addresses.
1426 * in order to avoid this swapping from happening while
1427 * sending the learning packets, the curr_slave_lock must be held for
1430 read_lock(&bond->curr_slave_lock);
1432 bond_for_each_slave(bond, slave, i) {
1433 alb_send_learning_packets(slave, slave->dev->dev_addr);
1436 read_unlock(&bond->curr_slave_lock);
1438 bond_info->lp_counter = 0;
1441 /* rebalance tx traffic */
1442 if (bond_info->tx_rebalance_counter >= BOND_TLB_REBALANCE_TICKS) {
1444 read_lock(&bond->curr_slave_lock);
1446 bond_for_each_slave(bond, slave, i) {
1447 tlb_clear_slave(bond, slave, 1);
1448 if (slave == bond->curr_active_slave) {
1449 SLAVE_TLB_INFO(slave).load =
1450 bond_info->unbalanced_load /
1451 BOND_TLB_REBALANCE_INTERVAL;
1452 bond_info->unbalanced_load = 0;
1456 read_unlock(&bond->curr_slave_lock);
1458 bond_info->tx_rebalance_counter = 0;
1461 /* handle rlb stuff */
1462 if (bond_info->rlb_enabled) {
1463 if (bond_info->primary_is_promisc &&
1464 (++bond_info->rlb_promisc_timeout_counter >= RLB_PROMISC_TIMEOUT)) {
1467 * dev_set_promiscuity requires rtnl and
1470 read_unlock(&bond->lock);
1473 bond_info->rlb_promisc_timeout_counter = 0;
1475 /* If the primary was set to promiscuous mode
1476 * because a slave was disabled then
1477 * it can now leave promiscuous mode.
1479 dev_set_promiscuity(bond->curr_active_slave->dev, -1);
1480 bond_info->primary_is_promisc = 0;
1483 read_lock(&bond->lock);
1486 if (bond_info->rlb_rebalance) {
1487 bond_info->rlb_rebalance = 0;
1488 rlb_rebalance(bond);
1491 /* check if clients need updating */
1492 if (bond_info->rx_ntt) {
1493 if (bond_info->rlb_update_delay_counter) {
1494 --bond_info->rlb_update_delay_counter;
1496 rlb_update_rx_clients(bond);
1497 if (bond_info->rlb_update_retry_counter) {
1498 --bond_info->rlb_update_retry_counter;
1500 bond_info->rx_ntt = 0;
1507 queue_delayed_work(bond->wq, &bond->alb_work, alb_delta_in_ticks);
1509 read_unlock(&bond->lock);
1512 /* assumption: called before the slave is attached to the bond
1513 * and not locked by the bond lock
1515 int bond_alb_init_slave(struct bonding *bond, struct slave *slave)
1519 res = alb_set_slave_mac_addr(slave, slave->perm_hwaddr,
1520 bond->alb_info.rlb_enabled);
1525 /* caller must hold the bond lock for write since the mac addresses
1526 * are compared and may be swapped.
1528 read_lock(&bond->lock);
1530 res = alb_handle_addr_collision_on_attach(bond, slave);
1532 read_unlock(&bond->lock);
1538 tlb_init_slave(slave);
1540 /* order a rebalance ASAP */
1541 bond->alb_info.tx_rebalance_counter = BOND_TLB_REBALANCE_TICKS;
1543 if (bond->alb_info.rlb_enabled) {
1544 bond->alb_info.rlb_rebalance = 1;
1551 * Remove slave from tlb and rlb hash tables, and fix up MAC addresses
1554 * Caller must hold RTNL and no other locks
1556 void bond_alb_deinit_slave(struct bonding *bond, struct slave *slave)
1558 if (bond->slave_cnt > 1) {
1559 alb_change_hw_addr_on_detach(bond, slave);
1562 tlb_clear_slave(bond, slave, 0);
1564 if (bond->alb_info.rlb_enabled) {
1565 bond->alb_info.next_rx_slave = NULL;
1566 rlb_clear_slave(bond, slave);
1570 /* Caller must hold bond lock for read */
1571 void bond_alb_handle_link_change(struct bonding *bond, struct slave *slave, char link)
1573 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
1575 if (link == BOND_LINK_DOWN) {
1576 tlb_clear_slave(bond, slave, 0);
1577 if (bond->alb_info.rlb_enabled) {
1578 rlb_clear_slave(bond, slave);
1580 } else if (link == BOND_LINK_UP) {
1581 /* order a rebalance ASAP */
1582 bond_info->tx_rebalance_counter = BOND_TLB_REBALANCE_TICKS;
1583 if (bond->alb_info.rlb_enabled) {
1584 bond->alb_info.rlb_rebalance = 1;
1585 /* If the updelay module parameter is smaller than the
1586 * forwarding delay of the switch the rebalance will
1587 * not work because the rebalance arp replies will
1588 * not be forwarded to the clients..
1595 * bond_alb_handle_active_change - assign new curr_active_slave
1596 * @bond: our bonding struct
1597 * @new_slave: new slave to assign
1599 * Set the bond->curr_active_slave to @new_slave and handle
1600 * mac address swapping and promiscuity changes as needed.
1602 * If new_slave is NULL, caller must hold curr_slave_lock or
1603 * bond->lock for write.
1605 * If new_slave is not NULL, caller must hold RTNL, bond->lock for
1606 * read and curr_slave_lock for write. Processing here may sleep, so
1607 * no other locks may be held.
1609 void bond_alb_handle_active_change(struct bonding *bond, struct slave *new_slave)
1610 __releases(&bond->curr_slave_lock)
1611 __releases(&bond->lock)
1612 __acquires(&bond->lock)
1613 __acquires(&bond->curr_slave_lock)
1615 struct slave *swap_slave;
1618 if (bond->curr_active_slave == new_slave) {
1622 if (bond->curr_active_slave && bond->alb_info.primary_is_promisc) {
1623 dev_set_promiscuity(bond->curr_active_slave->dev, -1);
1624 bond->alb_info.primary_is_promisc = 0;
1625 bond->alb_info.rlb_promisc_timeout_counter = 0;
1628 swap_slave = bond->curr_active_slave;
1629 bond->curr_active_slave = new_slave;
1631 if (!new_slave || (bond->slave_cnt == 0)) {
1635 /* set the new curr_active_slave to the bonds mac address
1636 * i.e. swap mac addresses of old curr_active_slave and new curr_active_slave
1639 struct slave *tmp_slave;
1640 /* find slave that is holding the bond's mac address */
1641 bond_for_each_slave(bond, tmp_slave, i) {
1642 if (!compare_ether_addr_64bits(tmp_slave->dev->dev_addr,
1643 bond->dev->dev_addr)) {
1644 swap_slave = tmp_slave;
1651 * Arrange for swap_slave and new_slave to temporarily be
1652 * ignored so we can mess with their MAC addresses without
1653 * fear of interference from transmit activity.
1656 tlb_clear_slave(bond, swap_slave, 1);
1658 tlb_clear_slave(bond, new_slave, 1);
1660 write_unlock_bh(&bond->curr_slave_lock);
1661 read_unlock(&bond->lock);
1665 /* curr_active_slave must be set before calling alb_swap_mac_addr */
1667 /* swap mac address */
1668 alb_swap_mac_addr(bond, swap_slave, new_slave);
1670 /* set the new_slave to the bond mac address */
1671 alb_set_slave_mac_addr(new_slave, bond->dev->dev_addr,
1672 bond->alb_info.rlb_enabled);
1676 alb_fasten_mac_swap(bond, swap_slave, new_slave);
1677 read_lock(&bond->lock);
1679 read_lock(&bond->lock);
1680 alb_send_learning_packets(new_slave, bond->dev->dev_addr);
1683 write_lock_bh(&bond->curr_slave_lock);
1689 int bond_alb_set_mac_address(struct net_device *bond_dev, void *addr)
1690 __acquires(&bond->lock)
1691 __releases(&bond->lock)
1693 struct bonding *bond = netdev_priv(bond_dev);
1694 struct sockaddr *sa = addr;
1695 struct slave *slave, *swap_slave;
1699 if (!is_valid_ether_addr(sa->sa_data)) {
1700 return -EADDRNOTAVAIL;
1703 res = alb_set_mac_address(bond, addr);
1708 memcpy(bond_dev->dev_addr, sa->sa_data, bond_dev->addr_len);
1710 /* If there is no curr_active_slave there is nothing else to do.
1711 * Otherwise we'll need to pass the new address to it and handle
1714 if (!bond->curr_active_slave) {
1720 bond_for_each_slave(bond, slave, i) {
1721 if (!compare_ether_addr_64bits(slave->dev->dev_addr,
1722 bond_dev->dev_addr)) {
1729 alb_swap_mac_addr(bond, swap_slave, bond->curr_active_slave);
1730 alb_fasten_mac_swap(bond, swap_slave, bond->curr_active_slave);
1732 alb_set_slave_mac_addr(bond->curr_active_slave, bond_dev->dev_addr,
1733 bond->alb_info.rlb_enabled);
1735 read_lock(&bond->lock);
1736 alb_send_learning_packets(bond->curr_active_slave, bond_dev->dev_addr);
1737 if (bond->alb_info.rlb_enabled) {
1738 /* inform clients mac address has changed */
1739 rlb_req_update_slave_clients(bond, bond->curr_active_slave);
1741 read_unlock(&bond->lock);
1747 void bond_alb_clear_vlan(struct bonding *bond, unsigned short vlan_id)
1749 if (bond->alb_info.current_alb_vlan &&
1750 (bond->alb_info.current_alb_vlan->vlan_id == vlan_id)) {
1751 bond->alb_info.current_alb_vlan = NULL;
1754 if (bond->alb_info.rlb_enabled) {
1755 rlb_clear_vlan(bond, vlan_id);