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>
48 #ifndef __long_aligned
49 #define __long_aligned __attribute__((aligned((sizeof(long)))))
51 static const u8 mac_bcast
[ETH_ALEN
] __long_aligned
= {
52 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
54 static const u8 mac_v6_allmcast
[ETH_ALEN
] __long_aligned
= {
55 0x33, 0x33, 0x00, 0x00, 0x00, 0x01
57 static const int alb_delta_in_ticks
= HZ
/ ALB_TIMER_TICKS_PER_SEC
;
64 u8 padding
[ETH_ZLEN
- ETH_HLEN
];
69 __be16 prot_addr_space
;
73 u8 mac_src
[ETH_ALEN
]; /* sender hardware address */
74 __be32 ip_src
; /* sender IP address */
75 u8 mac_dst
[ETH_ALEN
]; /* target hardware address */
76 __be32 ip_dst
; /* target IP address */
80 static inline struct arp_pkt
*arp_pkt(const struct sk_buff
*skb
)
82 return (struct arp_pkt
*)skb_network_header(skb
);
85 /* Forward declaration */
86 static void alb_send_learning_packets(struct slave
*slave
, u8 mac_addr
[]);
88 static inline u8
_simple_hash(const u8
*hash_start
, int hash_size
)
93 for (i
= 0; i
< hash_size
; i
++) {
94 hash
^= hash_start
[i
];
100 /*********************** tlb specific functions ***************************/
102 static inline void _lock_tx_hashtbl(struct bonding
*bond
)
104 spin_lock_bh(&(BOND_ALB_INFO(bond
).tx_hashtbl_lock
));
107 static inline void _unlock_tx_hashtbl(struct bonding
*bond
)
109 spin_unlock_bh(&(BOND_ALB_INFO(bond
).tx_hashtbl_lock
));
112 /* Caller must hold tx_hashtbl lock */
113 static inline void tlb_init_table_entry(struct tlb_client_info
*entry
, int save_load
)
116 entry
->load_history
= 1 + entry
->tx_bytes
/
117 BOND_TLB_REBALANCE_INTERVAL
;
121 entry
->tx_slave
= NULL
;
122 entry
->next
= TLB_NULL_INDEX
;
123 entry
->prev
= TLB_NULL_INDEX
;
126 static inline void tlb_init_slave(struct slave
*slave
)
128 SLAVE_TLB_INFO(slave
).load
= 0;
129 SLAVE_TLB_INFO(slave
).head
= TLB_NULL_INDEX
;
132 /* Caller must hold bond lock for read */
133 static void tlb_clear_slave(struct bonding
*bond
, struct slave
*slave
, int save_load
)
135 struct tlb_client_info
*tx_hash_table
;
138 _lock_tx_hashtbl(bond
);
140 /* clear slave from tx_hashtbl */
141 tx_hash_table
= BOND_ALB_INFO(bond
).tx_hashtbl
;
143 /* skip this if we've already freed the tx hash table */
145 index
= SLAVE_TLB_INFO(slave
).head
;
146 while (index
!= TLB_NULL_INDEX
) {
147 u32 next_index
= tx_hash_table
[index
].next
;
148 tlb_init_table_entry(&tx_hash_table
[index
], save_load
);
153 tlb_init_slave(slave
);
155 _unlock_tx_hashtbl(bond
);
158 /* Must be called before starting the monitor timer */
159 static int tlb_initialize(struct bonding
*bond
)
161 struct alb_bond_info
*bond_info
= &(BOND_ALB_INFO(bond
));
162 int size
= TLB_HASH_TABLE_SIZE
* sizeof(struct tlb_client_info
);
163 struct tlb_client_info
*new_hashtbl
;
166 spin_lock_init(&(bond_info
->tx_hashtbl_lock
));
168 new_hashtbl
= kzalloc(size
, GFP_KERNEL
);
170 pr_err("%s: Error: Failed to allocate TLB hash table\n",
174 _lock_tx_hashtbl(bond
);
176 bond_info
->tx_hashtbl
= new_hashtbl
;
178 for (i
= 0; i
< TLB_HASH_TABLE_SIZE
; i
++) {
179 tlb_init_table_entry(&bond_info
->tx_hashtbl
[i
], 0);
182 _unlock_tx_hashtbl(bond
);
187 /* Must be called only after all slaves have been released */
188 static void tlb_deinitialize(struct bonding
*bond
)
190 struct alb_bond_info
*bond_info
= &(BOND_ALB_INFO(bond
));
192 _lock_tx_hashtbl(bond
);
194 kfree(bond_info
->tx_hashtbl
);
195 bond_info
->tx_hashtbl
= NULL
;
197 _unlock_tx_hashtbl(bond
);
200 static long long compute_gap(struct slave
*slave
)
202 return (s64
) (slave
->speed
<< 20) - /* Convert to Megabit per sec */
203 (s64
) (SLAVE_TLB_INFO(slave
).load
<< 3); /* Bytes to bits */
206 /* Caller must hold bond lock for read */
207 static struct slave
*tlb_get_least_loaded_slave(struct bonding
*bond
)
209 struct slave
*slave
, *least_loaded
;
216 /* Find the slave with the largest gap */
217 bond_for_each_slave(bond
, slave
, i
) {
218 if (SLAVE_IS_OK(slave
)) {
219 long long gap
= compute_gap(slave
);
222 least_loaded
= slave
;
231 /* Caller must hold bond lock for read */
232 static struct slave
*tlb_choose_channel(struct bonding
*bond
, u32 hash_index
, u32 skb_len
)
234 struct alb_bond_info
*bond_info
= &(BOND_ALB_INFO(bond
));
235 struct tlb_client_info
*hash_table
;
236 struct slave
*assigned_slave
;
238 _lock_tx_hashtbl(bond
);
240 hash_table
= bond_info
->tx_hashtbl
;
241 assigned_slave
= hash_table
[hash_index
].tx_slave
;
242 if (!assigned_slave
) {
243 assigned_slave
= tlb_get_least_loaded_slave(bond
);
245 if (assigned_slave
) {
246 struct tlb_slave_info
*slave_info
=
247 &(SLAVE_TLB_INFO(assigned_slave
));
248 u32 next_index
= slave_info
->head
;
250 hash_table
[hash_index
].tx_slave
= assigned_slave
;
251 hash_table
[hash_index
].next
= next_index
;
252 hash_table
[hash_index
].prev
= TLB_NULL_INDEX
;
254 if (next_index
!= TLB_NULL_INDEX
) {
255 hash_table
[next_index
].prev
= hash_index
;
258 slave_info
->head
= hash_index
;
260 hash_table
[hash_index
].load_history
;
264 if (assigned_slave
) {
265 hash_table
[hash_index
].tx_bytes
+= skb_len
;
268 _unlock_tx_hashtbl(bond
);
270 return assigned_slave
;
273 /*********************** rlb specific functions ***************************/
274 static inline void _lock_rx_hashtbl(struct bonding
*bond
)
276 spin_lock_bh(&(BOND_ALB_INFO(bond
).rx_hashtbl_lock
));
279 static inline void _unlock_rx_hashtbl(struct bonding
*bond
)
281 spin_unlock_bh(&(BOND_ALB_INFO(bond
).rx_hashtbl_lock
));
284 /* when an ARP REPLY is received from a client update its info
287 static void rlb_update_entry_from_arp(struct bonding
*bond
, struct arp_pkt
*arp
)
289 struct alb_bond_info
*bond_info
= &(BOND_ALB_INFO(bond
));
290 struct rlb_client_info
*client_info
;
293 _lock_rx_hashtbl(bond
);
295 hash_index
= _simple_hash((u8
*)&(arp
->ip_src
), sizeof(arp
->ip_src
));
296 client_info
= &(bond_info
->rx_hashtbl
[hash_index
]);
298 if ((client_info
->assigned
) &&
299 (client_info
->ip_src
== arp
->ip_dst
) &&
300 (client_info
->ip_dst
== arp
->ip_src
) &&
301 (compare_ether_addr_64bits(client_info
->mac_dst
, arp
->mac_src
))) {
302 /* update the clients MAC address */
303 memcpy(client_info
->mac_dst
, arp
->mac_src
, ETH_ALEN
);
304 client_info
->ntt
= 1;
305 bond_info
->rx_ntt
= 1;
308 _unlock_rx_hashtbl(bond
);
311 static int rlb_arp_recv(struct sk_buff
*skb
, struct net_device
*bond_dev
, struct packet_type
*ptype
, struct net_device
*orig_dev
)
313 struct bonding
*bond
;
314 struct arp_pkt
*arp
= (struct arp_pkt
*)skb
->data
;
315 int res
= NET_RX_DROP
;
317 while (bond_dev
->priv_flags
& IFF_802_1Q_VLAN
)
318 bond_dev
= vlan_dev_real_dev(bond_dev
);
320 if (!(bond_dev
->priv_flags
& IFF_BONDING
) ||
321 !(bond_dev
->flags
& IFF_MASTER
))
325 pr_debug("Packet has no ARP data\n");
329 skb
= skb_share_check(skb
, GFP_ATOMIC
);
333 if (!pskb_may_pull(skb
, arp_hdr_len(bond_dev
)))
336 if (skb
->len
< sizeof(struct arp_pkt
)) {
337 pr_debug("Packet is too small to be an ARP\n");
341 if (arp
->op_code
== htons(ARPOP_REPLY
)) {
342 /* update rx hash table for this ARP */
343 bond
= netdev_priv(bond_dev
);
344 rlb_update_entry_from_arp(bond
, arp
);
345 pr_debug("Server received an ARP Reply from client\n");
348 res
= NET_RX_SUCCESS
;
356 /* Caller must hold bond lock for read */
357 static struct slave
*rlb_next_rx_slave(struct bonding
*bond
)
359 struct alb_bond_info
*bond_info
= &(BOND_ALB_INFO(bond
));
360 struct slave
*rx_slave
, *slave
, *start_at
;
363 if (bond_info
->next_rx_slave
) {
364 start_at
= bond_info
->next_rx_slave
;
366 start_at
= bond
->first_slave
;
371 bond_for_each_slave_from(bond
, slave
, i
, start_at
) {
372 if (SLAVE_IS_OK(slave
)) {
375 } else if (slave
->speed
> rx_slave
->speed
) {
382 bond_info
->next_rx_slave
= rx_slave
->next
;
388 /* teach the switch the mac of a disabled slave
389 * on the primary for fault tolerance
391 * Caller must hold bond->curr_slave_lock for write or bond lock for write
393 static void rlb_teach_disabled_mac_on_primary(struct bonding
*bond
, u8 addr
[])
395 if (!bond
->curr_active_slave
) {
399 if (!bond
->alb_info
.primary_is_promisc
) {
400 if (!dev_set_promiscuity(bond
->curr_active_slave
->dev
, 1))
401 bond
->alb_info
.primary_is_promisc
= 1;
403 bond
->alb_info
.primary_is_promisc
= 0;
406 bond
->alb_info
.rlb_promisc_timeout_counter
= 0;
408 alb_send_learning_packets(bond
->curr_active_slave
, addr
);
411 /* slave being removed should not be active at this point
413 * Caller must hold bond lock for read
415 static void rlb_clear_slave(struct bonding
*bond
, struct slave
*slave
)
417 struct alb_bond_info
*bond_info
= &(BOND_ALB_INFO(bond
));
418 struct rlb_client_info
*rx_hash_table
;
419 u32 index
, next_index
;
421 /* clear slave from rx_hashtbl */
422 _lock_rx_hashtbl(bond
);
424 rx_hash_table
= bond_info
->rx_hashtbl
;
425 index
= bond_info
->rx_hashtbl_head
;
426 for (; index
!= RLB_NULL_INDEX
; index
= next_index
) {
427 next_index
= rx_hash_table
[index
].next
;
428 if (rx_hash_table
[index
].slave
== slave
) {
429 struct slave
*assigned_slave
= rlb_next_rx_slave(bond
);
431 if (assigned_slave
) {
432 rx_hash_table
[index
].slave
= assigned_slave
;
433 if (compare_ether_addr_64bits(rx_hash_table
[index
].mac_dst
,
435 bond_info
->rx_hashtbl
[index
].ntt
= 1;
436 bond_info
->rx_ntt
= 1;
437 /* A slave has been removed from the
438 * table because it is either disabled
439 * or being released. We must retry the
440 * update to avoid clients from not
441 * being updated & disconnecting when
444 bond_info
->rlb_update_retry_counter
=
447 } else { /* there is no active slave */
448 rx_hash_table
[index
].slave
= NULL
;
453 _unlock_rx_hashtbl(bond
);
455 write_lock_bh(&bond
->curr_slave_lock
);
457 if (slave
!= bond
->curr_active_slave
) {
458 rlb_teach_disabled_mac_on_primary(bond
, slave
->dev
->dev_addr
);
461 write_unlock_bh(&bond
->curr_slave_lock
);
464 static void rlb_update_client(struct rlb_client_info
*client_info
)
468 if (!client_info
->slave
) {
472 for (i
= 0; i
< RLB_ARP_BURST_SIZE
; i
++) {
475 skb
= arp_create(ARPOP_REPLY
, ETH_P_ARP
,
477 client_info
->slave
->dev
,
479 client_info
->mac_dst
,
480 client_info
->slave
->dev
->dev_addr
,
481 client_info
->mac_dst
);
483 pr_err("%s: Error: failed to create an ARP packet\n",
484 client_info
->slave
->dev
->master
->name
);
488 skb
->dev
= client_info
->slave
->dev
;
490 if (client_info
->tag
) {
491 skb
= vlan_put_tag(skb
, client_info
->vlan_id
);
493 pr_err("%s: Error: failed to insert VLAN tag\n",
494 client_info
->slave
->dev
->master
->name
);
503 /* sends ARP REPLIES that update the clients that need updating */
504 static void rlb_update_rx_clients(struct bonding
*bond
)
506 struct alb_bond_info
*bond_info
= &(BOND_ALB_INFO(bond
));
507 struct rlb_client_info
*client_info
;
510 _lock_rx_hashtbl(bond
);
512 hash_index
= bond_info
->rx_hashtbl_head
;
513 for (; hash_index
!= RLB_NULL_INDEX
; hash_index
= client_info
->next
) {
514 client_info
= &(bond_info
->rx_hashtbl
[hash_index
]);
515 if (client_info
->ntt
) {
516 rlb_update_client(client_info
);
517 if (bond_info
->rlb_update_retry_counter
== 0) {
518 client_info
->ntt
= 0;
523 /* do not update the entries again until this counter is zero so that
524 * not to confuse the clients.
526 bond_info
->rlb_update_delay_counter
= RLB_UPDATE_DELAY
;
528 _unlock_rx_hashtbl(bond
);
531 /* The slave was assigned a new mac address - update the clients */
532 static void rlb_req_update_slave_clients(struct bonding
*bond
, struct slave
*slave
)
534 struct alb_bond_info
*bond_info
= &(BOND_ALB_INFO(bond
));
535 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
]);
545 if ((client_info
->slave
== slave
) &&
546 compare_ether_addr_64bits(client_info
->mac_dst
, mac_bcast
)) {
547 client_info
->ntt
= 1;
552 // update the team's flag only after the whole iteration
554 bond_info
->rx_ntt
= 1;
556 bond_info
->rlb_update_retry_counter
= RLB_UPDATE_RETRY
;
559 _unlock_rx_hashtbl(bond
);
562 /* mark all clients using src_ip to be updated */
563 static void rlb_req_update_subnet_clients(struct bonding
*bond
, __be32 src_ip
)
565 struct alb_bond_info
*bond_info
= &(BOND_ALB_INFO(bond
));
566 struct rlb_client_info
*client_info
;
569 _lock_rx_hashtbl(bond
);
571 hash_index
= bond_info
->rx_hashtbl_head
;
572 for (; hash_index
!= RLB_NULL_INDEX
; hash_index
= client_info
->next
) {
573 client_info
= &(bond_info
->rx_hashtbl
[hash_index
]);
575 if (!client_info
->slave
) {
576 pr_err("%s: Error: found a client with no channel in the client's hash table\n",
580 /*update all clients using this src_ip, that are not assigned
581 * to the team's address (curr_active_slave) and have a known
582 * unicast mac address.
584 if ((client_info
->ip_src
== src_ip
) &&
585 compare_ether_addr_64bits(client_info
->slave
->dev
->dev_addr
,
586 bond
->dev
->dev_addr
) &&
587 compare_ether_addr_64bits(client_info
->mac_dst
, mac_bcast
)) {
588 client_info
->ntt
= 1;
589 bond_info
->rx_ntt
= 1;
593 _unlock_rx_hashtbl(bond
);
596 /* Caller must hold both bond and ptr locks for read */
597 static struct slave
*rlb_choose_channel(struct sk_buff
*skb
, struct bonding
*bond
)
599 struct alb_bond_info
*bond_info
= &(BOND_ALB_INFO(bond
));
600 struct arp_pkt
*arp
= arp_pkt(skb
);
601 struct slave
*assigned_slave
;
602 struct rlb_client_info
*client_info
;
605 _lock_rx_hashtbl(bond
);
607 hash_index
= _simple_hash((u8
*)&arp
->ip_dst
, sizeof(arp
->ip_dst
));
608 client_info
= &(bond_info
->rx_hashtbl
[hash_index
]);
610 if (client_info
->assigned
) {
611 if ((client_info
->ip_src
== arp
->ip_src
) &&
612 (client_info
->ip_dst
== arp
->ip_dst
)) {
613 /* the entry is already assigned to this client */
614 if (compare_ether_addr_64bits(arp
->mac_dst
, mac_bcast
)) {
615 /* update mac address from arp */
616 memcpy(client_info
->mac_dst
, arp
->mac_dst
, ETH_ALEN
);
619 assigned_slave
= client_info
->slave
;
620 if (assigned_slave
) {
621 _unlock_rx_hashtbl(bond
);
622 return assigned_slave
;
625 /* the entry is already assigned to some other client,
626 * move the old client to primary (curr_active_slave) so
627 * that the new client can be assigned to this entry.
629 if (bond
->curr_active_slave
&&
630 client_info
->slave
!= bond
->curr_active_slave
) {
631 client_info
->slave
= bond
->curr_active_slave
;
632 rlb_update_client(client_info
);
636 /* assign a new slave */
637 assigned_slave
= rlb_next_rx_slave(bond
);
639 if (assigned_slave
) {
640 client_info
->ip_src
= arp
->ip_src
;
641 client_info
->ip_dst
= arp
->ip_dst
;
642 /* arp->mac_dst is broadcast for arp reqeusts.
643 * will be updated with clients actual unicast mac address
644 * upon receiving an arp reply.
646 memcpy(client_info
->mac_dst
, arp
->mac_dst
, ETH_ALEN
);
647 client_info
->slave
= assigned_slave
;
649 if (compare_ether_addr_64bits(client_info
->mac_dst
, mac_bcast
)) {
650 client_info
->ntt
= 1;
651 bond
->alb_info
.rx_ntt
= 1;
653 client_info
->ntt
= 0;
657 if (!vlan_get_tag(skb
, &client_info
->vlan_id
))
658 client_info
->tag
= 1;
661 if (!client_info
->assigned
) {
662 u32 prev_tbl_head
= bond_info
->rx_hashtbl_head
;
663 bond_info
->rx_hashtbl_head
= hash_index
;
664 client_info
->next
= prev_tbl_head
;
665 if (prev_tbl_head
!= RLB_NULL_INDEX
) {
666 bond_info
->rx_hashtbl
[prev_tbl_head
].prev
=
669 client_info
->assigned
= 1;
673 _unlock_rx_hashtbl(bond
);
675 return assigned_slave
;
678 /* chooses (and returns) transmit channel for arp reply
679 * does not choose channel for other arp types since they are
680 * sent on the curr_active_slave
682 static struct slave
*rlb_arp_xmit(struct sk_buff
*skb
, struct bonding
*bond
)
684 struct arp_pkt
*arp
= arp_pkt(skb
);
685 struct slave
*tx_slave
= NULL
;
687 if (arp
->op_code
== htons(ARPOP_REPLY
)) {
688 /* the arp must be sent on the selected
691 tx_slave
= rlb_choose_channel(skb
, bond
);
693 memcpy(arp
->mac_src
,tx_slave
->dev
->dev_addr
, ETH_ALEN
);
695 pr_debug("Server sent ARP Reply packet\n");
696 } else if (arp
->op_code
== htons(ARPOP_REQUEST
)) {
697 /* Create an entry in the rx_hashtbl for this client as a
699 * When the arp reply is received the entry will be updated
700 * with the correct unicast address of the client.
702 rlb_choose_channel(skb
, bond
);
704 /* The ARP reply packets must be delayed so that
705 * they can cancel out the influence of the ARP request.
707 bond
->alb_info
.rlb_update_delay_counter
= RLB_UPDATE_DELAY
;
709 /* arp requests are broadcast and are sent on the primary
710 * the arp request will collapse all clients on the subnet to
711 * the primary slave. We must register these clients to be
712 * updated with their assigned mac.
714 rlb_req_update_subnet_clients(bond
, arp
->ip_src
);
715 pr_debug("Server sent ARP Request packet\n");
721 /* Caller must hold bond lock for read */
722 static void rlb_rebalance(struct bonding
*bond
)
724 struct alb_bond_info
*bond_info
= &(BOND_ALB_INFO(bond
));
725 struct slave
*assigned_slave
;
726 struct rlb_client_info
*client_info
;
730 _lock_rx_hashtbl(bond
);
733 hash_index
= bond_info
->rx_hashtbl_head
;
734 for (; hash_index
!= RLB_NULL_INDEX
; hash_index
= client_info
->next
) {
735 client_info
= &(bond_info
->rx_hashtbl
[hash_index
]);
736 assigned_slave
= rlb_next_rx_slave(bond
);
737 if (assigned_slave
&& (client_info
->slave
!= assigned_slave
)) {
738 client_info
->slave
= assigned_slave
;
739 client_info
->ntt
= 1;
744 /* update the team's flag only after the whole iteration */
746 bond_info
->rx_ntt
= 1;
748 _unlock_rx_hashtbl(bond
);
751 /* Caller must hold rx_hashtbl lock */
752 static void rlb_init_table_entry(struct rlb_client_info
*entry
)
754 memset(entry
, 0, sizeof(struct rlb_client_info
));
755 entry
->next
= RLB_NULL_INDEX
;
756 entry
->prev
= RLB_NULL_INDEX
;
759 static int rlb_initialize(struct bonding
*bond
)
761 struct alb_bond_info
*bond_info
= &(BOND_ALB_INFO(bond
));
762 struct packet_type
*pk_type
= &(BOND_ALB_INFO(bond
).rlb_pkt_type
);
763 struct rlb_client_info
*new_hashtbl
;
764 int size
= RLB_HASH_TABLE_SIZE
* sizeof(struct rlb_client_info
);
767 spin_lock_init(&(bond_info
->rx_hashtbl_lock
));
769 new_hashtbl
= kmalloc(size
, GFP_KERNEL
);
771 pr_err("%s: Error: Failed to allocate RLB hash table\n",
775 _lock_rx_hashtbl(bond
);
777 bond_info
->rx_hashtbl
= new_hashtbl
;
779 bond_info
->rx_hashtbl_head
= RLB_NULL_INDEX
;
781 for (i
= 0; i
< RLB_HASH_TABLE_SIZE
; i
++) {
782 rlb_init_table_entry(bond_info
->rx_hashtbl
+ i
);
785 _unlock_rx_hashtbl(bond
);
787 /*initialize packet type*/
788 pk_type
->type
= cpu_to_be16(ETH_P_ARP
);
789 pk_type
->dev
= bond
->dev
;
790 pk_type
->func
= rlb_arp_recv
;
792 /* register to receive ARPs */
793 dev_add_pack(pk_type
);
798 static void rlb_deinitialize(struct bonding
*bond
)
800 struct alb_bond_info
*bond_info
= &(BOND_ALB_INFO(bond
));
802 dev_remove_pack(&(bond_info
->rlb_pkt_type
));
804 _lock_rx_hashtbl(bond
);
806 kfree(bond_info
->rx_hashtbl
);
807 bond_info
->rx_hashtbl
= NULL
;
808 bond_info
->rx_hashtbl_head
= RLB_NULL_INDEX
;
810 _unlock_rx_hashtbl(bond
);
813 static void rlb_clear_vlan(struct bonding
*bond
, unsigned short vlan_id
)
815 struct alb_bond_info
*bond_info
= &(BOND_ALB_INFO(bond
));
818 _lock_rx_hashtbl(bond
);
820 curr_index
= bond_info
->rx_hashtbl_head
;
821 while (curr_index
!= RLB_NULL_INDEX
) {
822 struct rlb_client_info
*curr
= &(bond_info
->rx_hashtbl
[curr_index
]);
823 u32 next_index
= bond_info
->rx_hashtbl
[curr_index
].next
;
824 u32 prev_index
= bond_info
->rx_hashtbl
[curr_index
].prev
;
826 if (curr
->tag
&& (curr
->vlan_id
== vlan_id
)) {
827 if (curr_index
== bond_info
->rx_hashtbl_head
) {
828 bond_info
->rx_hashtbl_head
= next_index
;
830 if (prev_index
!= RLB_NULL_INDEX
) {
831 bond_info
->rx_hashtbl
[prev_index
].next
= next_index
;
833 if (next_index
!= RLB_NULL_INDEX
) {
834 bond_info
->rx_hashtbl
[next_index
].prev
= prev_index
;
837 rlb_init_table_entry(curr
);
840 curr_index
= next_index
;
843 _unlock_rx_hashtbl(bond
);
846 /*********************** tlb/rlb shared functions *********************/
848 static void alb_send_learning_packets(struct slave
*slave
, u8 mac_addr
[])
850 struct bonding
*bond
= bond_get_bond_by_slave(slave
);
851 struct learning_pkt pkt
;
852 int size
= sizeof(struct learning_pkt
);
855 memset(&pkt
, 0, size
);
856 memcpy(pkt
.mac_dst
, mac_addr
, ETH_ALEN
);
857 memcpy(pkt
.mac_src
, mac_addr
, ETH_ALEN
);
858 pkt
.type
= cpu_to_be16(ETH_P_LOOP
);
860 for (i
= 0; i
< MAX_LP_BURST
; i
++) {
864 skb
= dev_alloc_skb(size
);
869 data
= skb_put(skb
, size
);
870 memcpy(data
, &pkt
, size
);
872 skb_reset_mac_header(skb
);
873 skb
->network_header
= skb
->mac_header
+ ETH_HLEN
;
874 skb
->protocol
= pkt
.type
;
875 skb
->priority
= TC_PRIO_CONTROL
;
876 skb
->dev
= slave
->dev
;
879 struct vlan_entry
*vlan
;
881 vlan
= bond_next_vlan(bond
,
882 bond
->alb_info
.current_alb_vlan
);
884 bond
->alb_info
.current_alb_vlan
= vlan
;
890 skb
= vlan_put_tag(skb
, vlan
->vlan_id
);
892 pr_err("%s: Error: failed to insert VLAN tag\n",
902 /* hw is a boolean parameter that determines whether we should try and
903 * set the hw address of the device as well as the hw address of the
906 static int alb_set_slave_mac_addr(struct slave
*slave
, u8 addr
[], int hw
)
908 struct net_device
*dev
= slave
->dev
;
909 struct sockaddr s_addr
;
912 memcpy(dev
->dev_addr
, addr
, dev
->addr_len
);
916 /* for rlb each slave must have a unique hw mac addresses so that */
917 /* each slave will receive packets destined to a different mac */
918 memcpy(s_addr
.sa_data
, addr
, dev
->addr_len
);
919 s_addr
.sa_family
= dev
->type
;
920 if (dev_set_mac_address(dev
, &s_addr
)) {
921 pr_err("%s: Error: dev_set_mac_address of dev %s failed!\n"
922 "ALB mode requires that the base driver support setting the hw address also when the network device's interface is open\n",
923 dev
->master
->name
, dev
->name
);
930 * Swap MAC addresses between two slaves.
932 * Called with RTNL held, and no other locks.
936 static void alb_swap_mac_addr(struct bonding
*bond
, struct slave
*slave1
, struct slave
*slave2
)
938 u8 tmp_mac_addr
[ETH_ALEN
];
940 memcpy(tmp_mac_addr
, slave1
->dev
->dev_addr
, ETH_ALEN
);
941 alb_set_slave_mac_addr(slave1
, slave2
->dev
->dev_addr
, bond
->alb_info
.rlb_enabled
);
942 alb_set_slave_mac_addr(slave2
, tmp_mac_addr
, bond
->alb_info
.rlb_enabled
);
947 * Send learning packets after MAC address swap.
949 * Called with RTNL and no other locks
951 static void alb_fasten_mac_swap(struct bonding
*bond
, struct slave
*slave1
,
952 struct slave
*slave2
)
954 int slaves_state_differ
= (SLAVE_IS_OK(slave1
) != SLAVE_IS_OK(slave2
));
955 struct slave
*disabled_slave
= NULL
;
959 /* fasten the change in the switch */
960 if (SLAVE_IS_OK(slave1
)) {
961 alb_send_learning_packets(slave1
, slave1
->dev
->dev_addr
);
962 if (bond
->alb_info
.rlb_enabled
) {
963 /* inform the clients that the mac address
966 rlb_req_update_slave_clients(bond
, slave1
);
969 disabled_slave
= slave1
;
972 if (SLAVE_IS_OK(slave2
)) {
973 alb_send_learning_packets(slave2
, slave2
->dev
->dev_addr
);
974 if (bond
->alb_info
.rlb_enabled
) {
975 /* inform the clients that the mac address
978 rlb_req_update_slave_clients(bond
, slave2
);
981 disabled_slave
= slave2
;
984 if (bond
->alb_info
.rlb_enabled
&& slaves_state_differ
) {
985 /* A disabled slave was assigned an active mac addr */
986 rlb_teach_disabled_mac_on_primary(bond
,
987 disabled_slave
->dev
->dev_addr
);
992 * alb_change_hw_addr_on_detach
993 * @bond: bonding we're working on
994 * @slave: the slave that was just detached
996 * We assume that @slave was already detached from the slave list.
998 * If @slave's permanent hw address is different both from its current
999 * address and from @bond's address, then somewhere in the bond there's
1000 * a slave that has @slave's permanet address as its current address.
1001 * We'll make sure that that slave no longer uses @slave's permanent address.
1003 * Caller must hold RTNL and no other locks
1005 static void alb_change_hw_addr_on_detach(struct bonding
*bond
, struct slave
*slave
)
1010 perm_curr_diff
= compare_ether_addr_64bits(slave
->perm_hwaddr
,
1011 slave
->dev
->dev_addr
);
1012 perm_bond_diff
= compare_ether_addr_64bits(slave
->perm_hwaddr
,
1013 bond
->dev
->dev_addr
);
1015 if (perm_curr_diff
&& perm_bond_diff
) {
1016 struct slave
*tmp_slave
;
1019 bond_for_each_slave(bond
, tmp_slave
, i
) {
1020 if (!compare_ether_addr_64bits(slave
->perm_hwaddr
,
1021 tmp_slave
->dev
->dev_addr
)) {
1028 /* locking: needs RTNL and nothing else */
1029 alb_swap_mac_addr(bond
, slave
, tmp_slave
);
1030 alb_fasten_mac_swap(bond
, slave
, tmp_slave
);
1036 * alb_handle_addr_collision_on_attach
1037 * @bond: bonding we're working on
1038 * @slave: the slave that was just attached
1040 * checks uniqueness of slave's mac address and handles the case the
1041 * new slave uses the bonds mac address.
1043 * If the permanent hw address of @slave is @bond's hw address, we need to
1044 * find a different hw address to give @slave, that isn't in use by any other
1045 * slave in the bond. This address must be, of course, one of the permanent
1046 * addresses of the other slaves.
1048 * We go over the slave list, and for each slave there we compare its
1049 * permanent hw address with the current address of all the other slaves.
1050 * If no match was found, then we've found a slave with a permanent address
1051 * that isn't used by any other slave in the bond, so we can assign it to
1054 * assumption: this function is called before @slave is attached to the
1057 * caller must hold the bond lock for write since the mac addresses are compared
1058 * and may be swapped.
1060 static int alb_handle_addr_collision_on_attach(struct bonding
*bond
, struct slave
*slave
)
1062 struct slave
*tmp_slave1
, *tmp_slave2
, *free_mac_slave
;
1063 struct slave
*has_bond_addr
= bond
->curr_active_slave
;
1064 int i
, j
, found
= 0;
1066 if (bond
->slave_cnt
== 0) {
1067 /* this is the first slave */
1071 /* if slave's mac address differs from bond's mac address
1072 * check uniqueness of slave's mac address against the other
1073 * slaves in the bond.
1075 if (compare_ether_addr_64bits(slave
->perm_hwaddr
, bond
->dev
->dev_addr
)) {
1076 bond_for_each_slave(bond
, tmp_slave1
, i
) {
1077 if (!compare_ether_addr_64bits(tmp_slave1
->dev
->dev_addr
,
1078 slave
->dev
->dev_addr
)) {
1087 /* Try setting slave mac to bond address and fall-through
1088 to code handling that situation below... */
1089 alb_set_slave_mac_addr(slave
, bond
->dev
->dev_addr
,
1090 bond
->alb_info
.rlb_enabled
);
1093 /* The slave's address is equal to the address of the bond.
1094 * Search for a spare address in the bond for this slave.
1096 free_mac_slave
= NULL
;
1098 bond_for_each_slave(bond
, tmp_slave1
, i
) {
1100 bond_for_each_slave(bond
, tmp_slave2
, j
) {
1101 if (!compare_ether_addr_64bits(tmp_slave1
->perm_hwaddr
,
1102 tmp_slave2
->dev
->dev_addr
)) {
1109 /* no slave has tmp_slave1's perm addr
1112 free_mac_slave
= tmp_slave1
;
1116 if (!has_bond_addr
) {
1117 if (!compare_ether_addr_64bits(tmp_slave1
->dev
->dev_addr
,
1118 bond
->dev
->dev_addr
)) {
1120 has_bond_addr
= tmp_slave1
;
1125 if (free_mac_slave
) {
1126 alb_set_slave_mac_addr(slave
, free_mac_slave
->perm_hwaddr
,
1127 bond
->alb_info
.rlb_enabled
);
1129 pr_warning("%s: Warning: the hw address of slave %s is in use by the bond; giving it the hw address of %s\n",
1130 bond
->dev
->name
, slave
->dev
->name
,
1131 free_mac_slave
->dev
->name
);
1133 } else if (has_bond_addr
) {
1134 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",
1135 bond
->dev
->name
, slave
->dev
->name
);
1143 * alb_set_mac_address
1147 * In TLB mode all slaves are configured to the bond's hw address, but set
1148 * their dev_addr field to different addresses (based on their permanent hw
1151 * For each slave, this function sets the interface to the new address and then
1152 * changes its dev_addr field to its previous value.
1154 * Unwinding assumes bond's mac address has not yet changed.
1156 static int alb_set_mac_address(struct bonding
*bond
, void *addr
)
1159 struct slave
*slave
, *stop_at
;
1160 char tmp_addr
[ETH_ALEN
];
1164 if (bond
->alb_info
.rlb_enabled
) {
1168 bond_for_each_slave(bond
, slave
, i
) {
1169 /* save net_device's current hw address */
1170 memcpy(tmp_addr
, slave
->dev
->dev_addr
, ETH_ALEN
);
1172 res
= dev_set_mac_address(slave
->dev
, addr
);
1174 /* restore net_device's hw address */
1175 memcpy(slave
->dev
->dev_addr
, tmp_addr
, ETH_ALEN
);
1184 memcpy(sa
.sa_data
, bond
->dev
->dev_addr
, bond
->dev
->addr_len
);
1185 sa
.sa_family
= bond
->dev
->type
;
1187 /* unwind from head to the slave that failed */
1189 bond_for_each_slave_from_to(bond
, slave
, i
, bond
->first_slave
, stop_at
) {
1190 memcpy(tmp_addr
, slave
->dev
->dev_addr
, ETH_ALEN
);
1191 dev_set_mac_address(slave
->dev
, &sa
);
1192 memcpy(slave
->dev
->dev_addr
, tmp_addr
, ETH_ALEN
);
1198 /************************ exported alb funcions ************************/
1200 int bond_alb_initialize(struct bonding
*bond
, int rlb_enabled
)
1204 res
= tlb_initialize(bond
);
1210 bond
->alb_info
.rlb_enabled
= 1;
1211 /* initialize rlb */
1212 res
= rlb_initialize(bond
);
1214 tlb_deinitialize(bond
);
1218 bond
->alb_info
.rlb_enabled
= 0;
1224 void bond_alb_deinitialize(struct bonding
*bond
)
1226 struct alb_bond_info
*bond_info
= &(BOND_ALB_INFO(bond
));
1228 tlb_deinitialize(bond
);
1230 if (bond_info
->rlb_enabled
) {
1231 rlb_deinitialize(bond
);
1235 int bond_alb_xmit(struct sk_buff
*skb
, struct net_device
*bond_dev
)
1237 struct bonding
*bond
= netdev_priv(bond_dev
);
1238 struct ethhdr
*eth_data
;
1239 struct alb_bond_info
*bond_info
= &(BOND_ALB_INFO(bond
));
1240 struct slave
*tx_slave
= NULL
;
1241 static const __be32 ip_bcast
= htonl(0xffffffff);
1243 int do_tx_balance
= 1;
1245 const u8
*hash_start
= NULL
;
1247 struct ipv6hdr
*ip6hdr
;
1249 skb_reset_mac_header(skb
);
1250 eth_data
= eth_hdr(skb
);
1252 /* make sure that the curr_active_slave and the slaves list do
1253 * not change during tx
1255 read_lock(&bond
->lock
);
1256 read_lock(&bond
->curr_slave_lock
);
1258 if (!BOND_IS_OK(bond
)) {
1262 switch (ntohs(skb
->protocol
)) {
1264 const struct iphdr
*iph
= ip_hdr(skb
);
1266 if (!compare_ether_addr_64bits(eth_data
->h_dest
, mac_bcast
) ||
1267 (iph
->daddr
== ip_bcast
) ||
1268 (iph
->protocol
== IPPROTO_IGMP
)) {
1272 hash_start
= (char *)&(iph
->daddr
);
1273 hash_size
= sizeof(iph
->daddr
);
1277 /* IPv6 doesn't really use broadcast mac address, but leave
1278 * that here just in case.
1280 if (!compare_ether_addr_64bits(eth_data
->h_dest
, mac_bcast
)) {
1285 /* IPv6 uses all-nodes multicast as an equivalent to
1286 * broadcasts in IPv4.
1288 if (!compare_ether_addr_64bits(eth_data
->h_dest
, mac_v6_allmcast
)) {
1293 /* Additianally, DAD probes should not be tx-balanced as that
1294 * will lead to false positives for duplicate addresses and
1295 * prevent address configuration from working.
1297 ip6hdr
= ipv6_hdr(skb
);
1298 if (ipv6_addr_any(&ip6hdr
->saddr
)) {
1303 hash_start
= (char *)&(ipv6_hdr(skb
)->daddr
);
1304 hash_size
= sizeof(ipv6_hdr(skb
)->daddr
);
1307 if (ipx_hdr(skb
)->ipx_checksum
!= IPX_NO_CHECKSUM
) {
1308 /* something is wrong with this packet */
1313 if (ipx_hdr(skb
)->ipx_type
!= IPX_TYPE_NCP
) {
1314 /* The only protocol worth balancing in
1315 * this family since it has an "ARP" like
1322 hash_start
= (char*)eth_data
->h_dest
;
1323 hash_size
= ETH_ALEN
;
1327 if (bond_info
->rlb_enabled
) {
1328 tx_slave
= rlb_arp_xmit(skb
, bond
);
1336 if (do_tx_balance
) {
1337 hash_index
= _simple_hash(hash_start
, hash_size
);
1338 tx_slave
= tlb_choose_channel(bond
, hash_index
, skb
->len
);
1342 /* unbalanced or unassigned, send through primary */
1343 tx_slave
= bond
->curr_active_slave
;
1344 bond_info
->unbalanced_load
+= skb
->len
;
1347 if (tx_slave
&& SLAVE_IS_OK(tx_slave
)) {
1348 if (tx_slave
!= bond
->curr_active_slave
) {
1349 memcpy(eth_data
->h_source
,
1350 tx_slave
->dev
->dev_addr
,
1354 res
= bond_dev_queue_xmit(bond
, skb
, tx_slave
->dev
);
1357 tlb_clear_slave(bond
, tx_slave
, 0);
1363 /* no suitable interface, frame not sent */
1366 read_unlock(&bond
->curr_slave_lock
);
1367 read_unlock(&bond
->lock
);
1368 return NETDEV_TX_OK
;
1371 void bond_alb_monitor(struct work_struct
*work
)
1373 struct bonding
*bond
= container_of(work
, struct bonding
,
1375 struct alb_bond_info
*bond_info
= &(BOND_ALB_INFO(bond
));
1376 struct slave
*slave
;
1379 read_lock(&bond
->lock
);
1381 if (bond
->kill_timers
) {
1385 if (bond
->slave_cnt
== 0) {
1386 bond_info
->tx_rebalance_counter
= 0;
1387 bond_info
->lp_counter
= 0;
1391 bond_info
->tx_rebalance_counter
++;
1392 bond_info
->lp_counter
++;
1394 /* send learning packets */
1395 if (bond_info
->lp_counter
>= BOND_ALB_LP_TICKS
) {
1396 /* change of curr_active_slave involves swapping of mac addresses.
1397 * in order to avoid this swapping from happening while
1398 * sending the learning packets, the curr_slave_lock must be held for
1401 read_lock(&bond
->curr_slave_lock
);
1403 bond_for_each_slave(bond
, slave
, i
) {
1404 alb_send_learning_packets(slave
, slave
->dev
->dev_addr
);
1407 read_unlock(&bond
->curr_slave_lock
);
1409 bond_info
->lp_counter
= 0;
1412 /* rebalance tx traffic */
1413 if (bond_info
->tx_rebalance_counter
>= BOND_TLB_REBALANCE_TICKS
) {
1415 read_lock(&bond
->curr_slave_lock
);
1417 bond_for_each_slave(bond
, slave
, i
) {
1418 tlb_clear_slave(bond
, slave
, 1);
1419 if (slave
== bond
->curr_active_slave
) {
1420 SLAVE_TLB_INFO(slave
).load
=
1421 bond_info
->unbalanced_load
/
1422 BOND_TLB_REBALANCE_INTERVAL
;
1423 bond_info
->unbalanced_load
= 0;
1427 read_unlock(&bond
->curr_slave_lock
);
1429 bond_info
->tx_rebalance_counter
= 0;
1432 /* handle rlb stuff */
1433 if (bond_info
->rlb_enabled
) {
1434 if (bond_info
->primary_is_promisc
&&
1435 (++bond_info
->rlb_promisc_timeout_counter
>= RLB_PROMISC_TIMEOUT
)) {
1438 * dev_set_promiscuity requires rtnl and
1441 read_unlock(&bond
->lock
);
1444 bond_info
->rlb_promisc_timeout_counter
= 0;
1446 /* If the primary was set to promiscuous mode
1447 * because a slave was disabled then
1448 * it can now leave promiscuous mode.
1450 dev_set_promiscuity(bond
->curr_active_slave
->dev
, -1);
1451 bond_info
->primary_is_promisc
= 0;
1454 read_lock(&bond
->lock
);
1457 if (bond_info
->rlb_rebalance
) {
1458 bond_info
->rlb_rebalance
= 0;
1459 rlb_rebalance(bond
);
1462 /* check if clients need updating */
1463 if (bond_info
->rx_ntt
) {
1464 if (bond_info
->rlb_update_delay_counter
) {
1465 --bond_info
->rlb_update_delay_counter
;
1467 rlb_update_rx_clients(bond
);
1468 if (bond_info
->rlb_update_retry_counter
) {
1469 --bond_info
->rlb_update_retry_counter
;
1471 bond_info
->rx_ntt
= 0;
1478 queue_delayed_work(bond
->wq
, &bond
->alb_work
, alb_delta_in_ticks
);
1480 read_unlock(&bond
->lock
);
1483 /* assumption: called before the slave is attached to the bond
1484 * and not locked by the bond lock
1486 int bond_alb_init_slave(struct bonding
*bond
, struct slave
*slave
)
1490 res
= alb_set_slave_mac_addr(slave
, slave
->perm_hwaddr
,
1491 bond
->alb_info
.rlb_enabled
);
1496 /* caller must hold the bond lock for write since the mac addresses
1497 * are compared and may be swapped.
1499 read_lock(&bond
->lock
);
1501 res
= alb_handle_addr_collision_on_attach(bond
, slave
);
1503 read_unlock(&bond
->lock
);
1509 tlb_init_slave(slave
);
1511 /* order a rebalance ASAP */
1512 bond
->alb_info
.tx_rebalance_counter
= BOND_TLB_REBALANCE_TICKS
;
1514 if (bond
->alb_info
.rlb_enabled
) {
1515 bond
->alb_info
.rlb_rebalance
= 1;
1522 * Remove slave from tlb and rlb hash tables, and fix up MAC addresses
1525 * Caller must hold RTNL and no other locks
1527 void bond_alb_deinit_slave(struct bonding
*bond
, struct slave
*slave
)
1529 if (bond
->slave_cnt
> 1) {
1530 alb_change_hw_addr_on_detach(bond
, slave
);
1533 tlb_clear_slave(bond
, slave
, 0);
1535 if (bond
->alb_info
.rlb_enabled
) {
1536 bond
->alb_info
.next_rx_slave
= NULL
;
1537 rlb_clear_slave(bond
, slave
);
1541 /* Caller must hold bond lock for read */
1542 void bond_alb_handle_link_change(struct bonding
*bond
, struct slave
*slave
, char link
)
1544 struct alb_bond_info
*bond_info
= &(BOND_ALB_INFO(bond
));
1546 if (link
== BOND_LINK_DOWN
) {
1547 tlb_clear_slave(bond
, slave
, 0);
1548 if (bond
->alb_info
.rlb_enabled
) {
1549 rlb_clear_slave(bond
, slave
);
1551 } else if (link
== BOND_LINK_UP
) {
1552 /* order a rebalance ASAP */
1553 bond_info
->tx_rebalance_counter
= BOND_TLB_REBALANCE_TICKS
;
1554 if (bond
->alb_info
.rlb_enabled
) {
1555 bond
->alb_info
.rlb_rebalance
= 1;
1556 /* If the updelay module parameter is smaller than the
1557 * forwarding delay of the switch the rebalance will
1558 * not work because the rebalance arp replies will
1559 * not be forwarded to the clients..
1566 * bond_alb_handle_active_change - assign new curr_active_slave
1567 * @bond: our bonding struct
1568 * @new_slave: new slave to assign
1570 * Set the bond->curr_active_slave to @new_slave and handle
1571 * mac address swapping and promiscuity changes as needed.
1573 * If new_slave is NULL, caller must hold curr_slave_lock or
1574 * bond->lock for write.
1576 * If new_slave is not NULL, caller must hold RTNL, bond->lock for
1577 * read and curr_slave_lock for write. Processing here may sleep, so
1578 * no other locks may be held.
1580 void bond_alb_handle_active_change(struct bonding
*bond
, struct slave
*new_slave
)
1581 __releases(&bond
->curr_slave_lock
)
1582 __releases(&bond
->lock
)
1583 __acquires(&bond
->lock
)
1584 __acquires(&bond
->curr_slave_lock
)
1586 struct slave
*swap_slave
;
1589 if (bond
->curr_active_slave
== new_slave
) {
1593 if (bond
->curr_active_slave
&& bond
->alb_info
.primary_is_promisc
) {
1594 dev_set_promiscuity(bond
->curr_active_slave
->dev
, -1);
1595 bond
->alb_info
.primary_is_promisc
= 0;
1596 bond
->alb_info
.rlb_promisc_timeout_counter
= 0;
1599 swap_slave
= bond
->curr_active_slave
;
1600 bond
->curr_active_slave
= new_slave
;
1602 if (!new_slave
|| (bond
->slave_cnt
== 0)) {
1606 /* set the new curr_active_slave to the bonds mac address
1607 * i.e. swap mac addresses of old curr_active_slave and new curr_active_slave
1610 struct slave
*tmp_slave
;
1611 /* find slave that is holding the bond's mac address */
1612 bond_for_each_slave(bond
, tmp_slave
, i
) {
1613 if (!compare_ether_addr_64bits(tmp_slave
->dev
->dev_addr
,
1614 bond
->dev
->dev_addr
)) {
1615 swap_slave
= tmp_slave
;
1622 * Arrange for swap_slave and new_slave to temporarily be
1623 * ignored so we can mess with their MAC addresses without
1624 * fear of interference from transmit activity.
1627 tlb_clear_slave(bond
, swap_slave
, 1);
1629 tlb_clear_slave(bond
, new_slave
, 1);
1631 write_unlock_bh(&bond
->curr_slave_lock
);
1632 read_unlock(&bond
->lock
);
1636 /* curr_active_slave must be set before calling alb_swap_mac_addr */
1638 /* swap mac address */
1639 alb_swap_mac_addr(bond
, swap_slave
, new_slave
);
1641 /* set the new_slave to the bond mac address */
1642 alb_set_slave_mac_addr(new_slave
, bond
->dev
->dev_addr
,
1643 bond
->alb_info
.rlb_enabled
);
1647 alb_fasten_mac_swap(bond
, swap_slave
, new_slave
);
1648 read_lock(&bond
->lock
);
1650 read_lock(&bond
->lock
);
1651 alb_send_learning_packets(new_slave
, bond
->dev
->dev_addr
);
1654 write_lock_bh(&bond
->curr_slave_lock
);
1660 int bond_alb_set_mac_address(struct net_device
*bond_dev
, void *addr
)
1661 __acquires(&bond
->lock
)
1662 __releases(&bond
->lock
)
1664 struct bonding
*bond
= netdev_priv(bond_dev
);
1665 struct sockaddr
*sa
= addr
;
1666 struct slave
*slave
, *swap_slave
;
1670 if (!is_valid_ether_addr(sa
->sa_data
)) {
1671 return -EADDRNOTAVAIL
;
1674 res
= alb_set_mac_address(bond
, addr
);
1679 memcpy(bond_dev
->dev_addr
, sa
->sa_data
, bond_dev
->addr_len
);
1681 /* If there is no curr_active_slave there is nothing else to do.
1682 * Otherwise we'll need to pass the new address to it and handle
1685 if (!bond
->curr_active_slave
) {
1691 bond_for_each_slave(bond
, slave
, i
) {
1692 if (!compare_ether_addr_64bits(slave
->dev
->dev_addr
,
1693 bond_dev
->dev_addr
)) {
1700 alb_swap_mac_addr(bond
, swap_slave
, bond
->curr_active_slave
);
1701 alb_fasten_mac_swap(bond
, swap_slave
, bond
->curr_active_slave
);
1703 alb_set_slave_mac_addr(bond
->curr_active_slave
, bond_dev
->dev_addr
,
1704 bond
->alb_info
.rlb_enabled
);
1706 read_lock(&bond
->lock
);
1707 alb_send_learning_packets(bond
->curr_active_slave
, bond_dev
->dev_addr
);
1708 if (bond
->alb_info
.rlb_enabled
) {
1709 /* inform clients mac address has changed */
1710 rlb_req_update_slave_clients(bond
, bond
->curr_active_slave
);
1712 read_unlock(&bond
->lock
);
1718 void bond_alb_clear_vlan(struct bonding
*bond
, unsigned short vlan_id
)
1720 if (bond
->alb_info
.current_alb_vlan
&&
1721 (bond
->alb_info
.current_alb_vlan
->vlan_id
== vlan_id
)) {
1722 bond
->alb_info
.current_alb_vlan
= NULL
;
1725 if (bond
->alb_info
.rlb_enabled
) {
1726 rlb_clear_vlan(bond
, vlan_id
);