blob: 02872405d35dc4a53d13473b31d1b517d22610d0 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Copyright(c) 1999 - 2004 Intel Corporation. All rights reserved.
3 *
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.
8 *
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
12 * for more details.
13 *
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.
17 *
18 * The full GNU General Public License is included in this distribution in the
19 * file called LICENSE.
20 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070021 */
22
Joe Perchesa4aee5c2009-12-13 20:06:07 -080023#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
24
Linus Torvalds1da177e2005-04-16 15:20:36 -070025#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>
32#include <linux/ip.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>
38#include <linux/in.h>
39#include <net/ipx.h>
40#include <net/arp.h>
Vlad Yasevich2d1ea192008-08-28 15:38:41 -040041#include <net/ipv6.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070042#include <asm/byteorder.h>
43#include "bonding.h"
44#include "bond_alb.h"
45
46
Linus Torvalds1da177e2005-04-16 15:20:36 -070047
Eric Dumazet885a1362009-09-01 06:31:18 +000048#ifndef __long_aligned
49#define __long_aligned __attribute__((aligned((sizeof(long)))))
50#endif
51static const u8 mac_bcast[ETH_ALEN] __long_aligned = {
52 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
53};
54static const u8 mac_v6_allmcast[ETH_ALEN] __long_aligned = {
55 0x33, 0x33, 0x00, 0x00, 0x00, 0x01
56};
Linus Torvalds1da177e2005-04-16 15:20:36 -070057static const int alb_delta_in_ticks = HZ / ALB_TIMER_TICKS_PER_SEC;
58
59#pragma pack(1)
60struct learning_pkt {
61 u8 mac_dst[ETH_ALEN];
62 u8 mac_src[ETH_ALEN];
Al Virod3bb52b2007-08-22 20:06:58 -040063 __be16 type;
Linus Torvalds1da177e2005-04-16 15:20:36 -070064 u8 padding[ETH_ZLEN - ETH_HLEN];
65};
66
67struct arp_pkt {
Al Virod3bb52b2007-08-22 20:06:58 -040068 __be16 hw_addr_space;
69 __be16 prot_addr_space;
Linus Torvalds1da177e2005-04-16 15:20:36 -070070 u8 hw_addr_len;
71 u8 prot_addr_len;
Al Virod3bb52b2007-08-22 20:06:58 -040072 __be16 op_code;
Linus Torvalds1da177e2005-04-16 15:20:36 -070073 u8 mac_src[ETH_ALEN]; /* sender hardware address */
Al Virod3bb52b2007-08-22 20:06:58 -040074 __be32 ip_src; /* sender IP address */
Linus Torvalds1da177e2005-04-16 15:20:36 -070075 u8 mac_dst[ETH_ALEN]; /* target hardware address */
Al Virod3bb52b2007-08-22 20:06:58 -040076 __be32 ip_dst; /* target IP address */
Linus Torvalds1da177e2005-04-16 15:20:36 -070077};
78#pragma pack()
79
Arnaldo Carvalho de Meloa16aeb32007-03-10 16:07:19 -030080static inline struct arp_pkt *arp_pkt(const struct sk_buff *skb)
81{
Arnaldo Carvalho de Melod56f90a2007-04-10 20:50:43 -070082 return (struct arp_pkt *)skb_network_header(skb);
Arnaldo Carvalho de Meloa16aeb32007-03-10 16:07:19 -030083}
84
Linus Torvalds1da177e2005-04-16 15:20:36 -070085/* Forward declaration */
86static void alb_send_learning_packets(struct slave *slave, u8 mac_addr[]);
Jiri Bohace53665c2012-11-28 04:42:14 +000087static void rlb_purge_src_ip(struct bonding *bond, struct arp_pkt *arp);
88static void rlb_src_unlink(struct bonding *bond, u32 index);
89static void rlb_src_link(struct bonding *bond, u32 ip_src_hash,
90 u32 ip_dst_hash);
Linus Torvalds1da177e2005-04-16 15:20:36 -070091
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -070092static inline u8 _simple_hash(const u8 *hash_start, int hash_size)
Linus Torvalds1da177e2005-04-16 15:20:36 -070093{
94 int i;
95 u8 hash = 0;
96
97 for (i = 0; i < hash_size; i++) {
98 hash ^= hash_start[i];
99 }
100
101 return hash;
102}
103
104/*********************** tlb specific functions ***************************/
105
Maxim Uvarovf515e6b2012-01-09 12:01:37 +0000106static inline void _lock_tx_hashtbl_bh(struct bonding *bond)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107{
Jay Vosburgh6603a6f2007-10-17 17:37:50 -0700108 spin_lock_bh(&(BOND_ALB_INFO(bond).tx_hashtbl_lock));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109}
110
Maxim Uvarovf515e6b2012-01-09 12:01:37 +0000111static inline void _unlock_tx_hashtbl_bh(struct bonding *bond)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112{
Jay Vosburgh6603a6f2007-10-17 17:37:50 -0700113 spin_unlock_bh(&(BOND_ALB_INFO(bond).tx_hashtbl_lock));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114}
115
Maxim Uvarovf515e6b2012-01-09 12:01:37 +0000116static inline void _lock_tx_hashtbl(struct bonding *bond)
117{
118 spin_lock(&(BOND_ALB_INFO(bond).tx_hashtbl_lock));
119}
120
121static inline void _unlock_tx_hashtbl(struct bonding *bond)
122{
123 spin_unlock(&(BOND_ALB_INFO(bond).tx_hashtbl_lock));
124}
125
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126/* Caller must hold tx_hashtbl lock */
127static inline void tlb_init_table_entry(struct tlb_client_info *entry, int save_load)
128{
129 if (save_load) {
130 entry->load_history = 1 + entry->tx_bytes /
131 BOND_TLB_REBALANCE_INTERVAL;
132 entry->tx_bytes = 0;
133 }
134
135 entry->tx_slave = NULL;
136 entry->next = TLB_NULL_INDEX;
137 entry->prev = TLB_NULL_INDEX;
138}
139
140static inline void tlb_init_slave(struct slave *slave)
141{
142 SLAVE_TLB_INFO(slave).load = 0;
143 SLAVE_TLB_INFO(slave).head = TLB_NULL_INDEX;
144}
145
Maxim Uvarovf515e6b2012-01-09 12:01:37 +0000146/* Caller must hold bond lock for read, BH disabled */
147static void __tlb_clear_slave(struct bonding *bond, struct slave *slave,
148 int save_load)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149{
150 struct tlb_client_info *tx_hash_table;
151 u32 index;
152
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153 /* clear slave from tx_hashtbl */
154 tx_hash_table = BOND_ALB_INFO(bond).tx_hashtbl;
155
Andy Gospodarekce39a802008-10-30 17:41:16 -0700156 /* skip this if we've already freed the tx hash table */
157 if (tx_hash_table) {
158 index = SLAVE_TLB_INFO(slave).head;
159 while (index != TLB_NULL_INDEX) {
160 u32 next_index = tx_hash_table[index].next;
161 tlb_init_table_entry(&tx_hash_table[index], save_load);
162 index = next_index;
163 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164 }
165
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166 tlb_init_slave(slave);
Maxim Uvarovf515e6b2012-01-09 12:01:37 +0000167}
Jay Vosburgh5af47b22006-01-09 12:14:00 -0800168
Maxim Uvarovf515e6b2012-01-09 12:01:37 +0000169/* Caller must hold bond lock for read */
170static void tlb_clear_slave(struct bonding *bond, struct slave *slave,
171 int save_load)
172{
173 _lock_tx_hashtbl_bh(bond);
174 __tlb_clear_slave(bond, slave, save_load);
175 _unlock_tx_hashtbl_bh(bond);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176}
177
178/* Must be called before starting the monitor timer */
179static int tlb_initialize(struct bonding *bond)
180{
181 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
182 int size = TLB_HASH_TABLE_SIZE * sizeof(struct tlb_client_info);
Mitch Williams0d206a32005-11-09 10:35:30 -0800183 struct tlb_client_info *new_hashtbl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184 int i;
185
Joe Jin243cb4e2007-02-06 14:16:40 -0800186 new_hashtbl = kzalloc(size, GFP_KERNEL);
Joe Perchese404dec2012-01-29 12:56:23 +0000187 if (!new_hashtbl)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188 return -1;
Joe Perchese404dec2012-01-29 12:56:23 +0000189
Maxim Uvarovf515e6b2012-01-09 12:01:37 +0000190 _lock_tx_hashtbl_bh(bond);
Mitch Williams0d206a32005-11-09 10:35:30 -0800191
192 bond_info->tx_hashtbl = new_hashtbl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194 for (i = 0; i < TLB_HASH_TABLE_SIZE; i++) {
Peter Pan(潘卫平)38dbaf02011-04-08 03:40:19 +0000195 tlb_init_table_entry(&bond_info->tx_hashtbl[i], 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196 }
197
Maxim Uvarovf515e6b2012-01-09 12:01:37 +0000198 _unlock_tx_hashtbl_bh(bond);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199
200 return 0;
201}
202
203/* Must be called only after all slaves have been released */
204static void tlb_deinitialize(struct bonding *bond)
205{
206 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
207
Maxim Uvarovf515e6b2012-01-09 12:01:37 +0000208 _lock_tx_hashtbl_bh(bond);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209
210 kfree(bond_info->tx_hashtbl);
211 bond_info->tx_hashtbl = NULL;
212
Maxim Uvarovf515e6b2012-01-09 12:01:37 +0000213 _unlock_tx_hashtbl_bh(bond);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214}
215
Jiri Pirko097811b2010-05-19 03:26:39 +0000216static long long compute_gap(struct slave *slave)
217{
218 return (s64) (slave->speed << 20) - /* Convert to Megabit per sec */
219 (s64) (SLAVE_TLB_INFO(slave).load << 3); /* Bytes to bits */
220}
221
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222/* Caller must hold bond lock for read */
223static struct slave *tlb_get_least_loaded_slave(struct bonding *bond)
224{
225 struct slave *slave, *least_loaded;
Veaceslav Falico9caff1e72013-09-25 09:20:14 +0200226 struct list_head *iter;
Jiri Pirko097811b2010-05-19 03:26:39 +0000227 long long max_gap;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228
Jiri Pirko097811b2010-05-19 03:26:39 +0000229 least_loaded = NULL;
230 max_gap = LLONG_MIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231
232 /* Find the slave with the largest gap */
dingtianhong28c71922013-10-15 16:28:39 +0800233 bond_for_each_slave_rcu(bond, slave, iter) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234 if (SLAVE_IS_OK(slave)) {
Jiri Pirko097811b2010-05-19 03:26:39 +0000235 long long gap = compute_gap(slave);
236
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237 if (max_gap < gap) {
238 least_loaded = slave;
239 max_gap = gap;
240 }
241 }
242 }
243
244 return least_loaded;
245}
246
Maxim Uvarovf515e6b2012-01-09 12:01:37 +0000247static struct slave *__tlb_choose_channel(struct bonding *bond, u32 hash_index,
248 u32 skb_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249{
250 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
251 struct tlb_client_info *hash_table;
252 struct slave *assigned_slave;
253
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254 hash_table = bond_info->tx_hashtbl;
255 assigned_slave = hash_table[hash_index].tx_slave;
256 if (!assigned_slave) {
257 assigned_slave = tlb_get_least_loaded_slave(bond);
258
259 if (assigned_slave) {
260 struct tlb_slave_info *slave_info =
261 &(SLAVE_TLB_INFO(assigned_slave));
262 u32 next_index = slave_info->head;
263
264 hash_table[hash_index].tx_slave = assigned_slave;
265 hash_table[hash_index].next = next_index;
266 hash_table[hash_index].prev = TLB_NULL_INDEX;
267
268 if (next_index != TLB_NULL_INDEX) {
269 hash_table[next_index].prev = hash_index;
270 }
271
272 slave_info->head = hash_index;
273 slave_info->load +=
274 hash_table[hash_index].load_history;
275 }
276 }
277
278 if (assigned_slave) {
279 hash_table[hash_index].tx_bytes += skb_len;
280 }
281
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282 return assigned_slave;
283}
284
Maxim Uvarovf515e6b2012-01-09 12:01:37 +0000285/* Caller must hold bond lock for read */
286static struct slave *tlb_choose_channel(struct bonding *bond, u32 hash_index,
287 u32 skb_len)
288{
289 struct slave *tx_slave;
290 /*
291 * We don't need to disable softirq here, becase
292 * tlb_choose_channel() is only called by bond_alb_xmit()
293 * which already has softirq disabled.
294 */
295 _lock_tx_hashtbl(bond);
296 tx_slave = __tlb_choose_channel(bond, hash_index, skb_len);
297 _unlock_tx_hashtbl(bond);
298 return tx_slave;
299}
300
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301/*********************** rlb specific functions ***************************/
Maxim Uvarovf515e6b2012-01-09 12:01:37 +0000302static inline void _lock_rx_hashtbl_bh(struct bonding *bond)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303{
Jay Vosburgh6603a6f2007-10-17 17:37:50 -0700304 spin_lock_bh(&(BOND_ALB_INFO(bond).rx_hashtbl_lock));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305}
306
Maxim Uvarovf515e6b2012-01-09 12:01:37 +0000307static inline void _unlock_rx_hashtbl_bh(struct bonding *bond)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308{
Jay Vosburgh6603a6f2007-10-17 17:37:50 -0700309 spin_unlock_bh(&(BOND_ALB_INFO(bond).rx_hashtbl_lock));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310}
311
Maxim Uvarovf515e6b2012-01-09 12:01:37 +0000312static inline void _lock_rx_hashtbl(struct bonding *bond)
313{
314 spin_lock(&(BOND_ALB_INFO(bond).rx_hashtbl_lock));
315}
316
317static inline void _unlock_rx_hashtbl(struct bonding *bond)
318{
319 spin_unlock(&(BOND_ALB_INFO(bond).rx_hashtbl_lock));
320}
321
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322/* when an ARP REPLY is received from a client update its info
323 * in the rx_hashtbl
324 */
325static void rlb_update_entry_from_arp(struct bonding *bond, struct arp_pkt *arp)
326{
327 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
328 struct rlb_client_info *client_info;
329 u32 hash_index;
330
Maxim Uvarovf515e6b2012-01-09 12:01:37 +0000331 _lock_rx_hashtbl_bh(bond);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332
333 hash_index = _simple_hash((u8*)&(arp->ip_src), sizeof(arp->ip_src));
334 client_info = &(bond_info->rx_hashtbl[hash_index]);
335
336 if ((client_info->assigned) &&
337 (client_info->ip_src == arp->ip_dst) &&
Flavio Leitner42d782a2010-06-29 08:24:39 +0000338 (client_info->ip_dst == arp->ip_src) &&
Joe Perchesa6700db2012-05-09 17:04:04 +0000339 (!ether_addr_equal_64bits(client_info->mac_dst, arp->mac_src))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 /* update the clients MAC address */
341 memcpy(client_info->mac_dst, arp->mac_src, ETH_ALEN);
342 client_info->ntt = 1;
343 bond_info->rx_ntt = 1;
344 }
345
Maxim Uvarovf515e6b2012-01-09 12:01:37 +0000346 _unlock_rx_hashtbl_bh(bond);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347}
348
Eric Dumazetde063b72012-06-11 19:23:07 +0000349static int rlb_arp_recv(const struct sk_buff *skb, struct bonding *bond,
350 struct slave *slave)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351{
Eric Dumazetde063b72012-06-11 19:23:07 +0000352 struct arp_pkt *arp, _arp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353
Jiri Pirko3aba8912011-04-19 03:48:16 +0000354 if (skb->protocol != cpu_to_be16(ETH_P_ARP))
David S. Millerb99215c2012-05-13 15:45:13 -0400355 goto out;
Jay Vosburgh6146b1a2008-11-04 17:51:15 -0800356
Eric Dumazetde063b72012-06-11 19:23:07 +0000357 arp = skb_header_pointer(skb, 0, sizeof(_arp), &_arp);
358 if (!arp)
David S. Millerb99215c2012-05-13 15:45:13 -0400359 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360
Jiri Bohace53665c2012-11-28 04:42:14 +0000361 /* We received an ARP from arp->ip_src.
362 * We might have used this IP address previously (on the bonding host
363 * itself or on a system that is bridged together with the bond).
364 * However, if arp->mac_src is different than what is stored in
365 * rx_hashtbl, some other host is now using the IP and we must prevent
366 * sending out client updates with this IP address and the old MAC
367 * address.
368 * Clean up all hash table entries that have this address as ip_src but
369 * have a different mac_src.
370 */
371 rlb_purge_src_ip(bond, arp);
372
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 if (arp->op_code == htons(ARPOP_REPLY)) {
374 /* update rx hash table for this ARP */
375 rlb_update_entry_from_arp(bond, arp);
Holger Eitzenberger5a03cdb2008-12-09 23:09:22 -0800376 pr_debug("Server received an ARP Reply from client\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377 }
David S. Millerb99215c2012-05-13 15:45:13 -0400378out:
379 return RX_HANDLER_ANOTHER;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380}
381
382/* Caller must hold bond lock for read */
383static struct slave *rlb_next_rx_slave(struct bonding *bond)
384{
385 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
Veaceslav Falico6475ae42013-09-25 09:20:17 +0200386 struct slave *before = NULL, *rx_slave = NULL, *slave;
387 struct list_head *iter;
388 bool found = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389
Veaceslav Falico6475ae42013-09-25 09:20:17 +0200390 bond_for_each_slave(bond, slave, iter) {
391 if (!SLAVE_IS_OK(slave))
392 continue;
393 if (!found) {
394 if (!before || before->speed < slave->speed)
395 before = slave;
396 } else {
397 if (!rx_slave || rx_slave->speed < slave->speed)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398 rx_slave = slave;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399 }
Veaceslav Falico6475ae42013-09-25 09:20:17 +0200400 if (slave == bond_info->rx_slave)
401 found = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 }
Veaceslav Falico6475ae42013-09-25 09:20:17 +0200403 /* we didn't find anything after the current or we have something
404 * better before and up to the current slave
405 */
406 if (!rx_slave || (before && rx_slave->speed < before->speed))
407 rx_slave = before;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408
Veaceslav Falico6475ae42013-09-25 09:20:17 +0200409 if (rx_slave)
410 bond_info->rx_slave = rx_slave;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411
412 return rx_slave;
413}
414
dingtianhong28c71922013-10-15 16:28:39 +0800415/* Caller must hold rcu_read_lock() for read */
416static struct slave *__rlb_next_rx_slave(struct bonding *bond)
417{
418 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
419 struct slave *before = NULL, *rx_slave = NULL, *slave;
420 struct list_head *iter;
421 bool found = false;
422
423 bond_for_each_slave_rcu(bond, slave, iter) {
424 if (!SLAVE_IS_OK(slave))
425 continue;
426 if (!found) {
427 if (!before || before->speed < slave->speed)
428 before = slave;
429 } else {
430 if (!rx_slave || rx_slave->speed < slave->speed)
431 rx_slave = slave;
432 }
433 if (slave == bond_info->rx_slave)
434 found = true;
435 }
436 /* we didn't find anything after the current or we have something
437 * better before and up to the current slave
438 */
439 if (!rx_slave || (before && rx_slave->speed < before->speed))
440 rx_slave = before;
441
442 if (rx_slave)
443 bond_info->rx_slave = rx_slave;
444
445 return rx_slave;
446}
447
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448/* teach the switch the mac of a disabled slave
449 * on the primary for fault tolerance
450 *
451 * Caller must hold bond->curr_slave_lock for write or bond lock for write
452 */
453static void rlb_teach_disabled_mac_on_primary(struct bonding *bond, u8 addr[])
454{
455 if (!bond->curr_active_slave) {
456 return;
457 }
458
459 if (!bond->alb_info.primary_is_promisc) {
Wang Chen7e1a1ac2008-07-14 20:51:36 -0700460 if (!dev_set_promiscuity(bond->curr_active_slave->dev, 1))
461 bond->alb_info.primary_is_promisc = 1;
462 else
463 bond->alb_info.primary_is_promisc = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464 }
465
466 bond->alb_info.rlb_promisc_timeout_counter = 0;
467
468 alb_send_learning_packets(bond->curr_active_slave, addr);
469}
470
471/* slave being removed should not be active at this point
472 *
473 * Caller must hold bond lock for read
474 */
475static void rlb_clear_slave(struct bonding *bond, struct slave *slave)
476{
477 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
478 struct rlb_client_info *rx_hash_table;
479 u32 index, next_index;
480
481 /* clear slave from rx_hashtbl */
Maxim Uvarovf515e6b2012-01-09 12:01:37 +0000482 _lock_rx_hashtbl_bh(bond);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483
484 rx_hash_table = bond_info->rx_hashtbl;
Jiri Bohace53665c2012-11-28 04:42:14 +0000485 index = bond_info->rx_hashtbl_used_head;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486 for (; index != RLB_NULL_INDEX; index = next_index) {
Jiri Bohace53665c2012-11-28 04:42:14 +0000487 next_index = rx_hash_table[index].used_next;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488 if (rx_hash_table[index].slave == slave) {
489 struct slave *assigned_slave = rlb_next_rx_slave(bond);
490
491 if (assigned_slave) {
492 rx_hash_table[index].slave = assigned_slave;
Joe Perchesa6700db2012-05-09 17:04:04 +0000493 if (!ether_addr_equal_64bits(rx_hash_table[index].mac_dst,
494 mac_bcast)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495 bond_info->rx_hashtbl[index].ntt = 1;
496 bond_info->rx_ntt = 1;
497 /* A slave has been removed from the
498 * table because it is either disabled
499 * or being released. We must retry the
500 * update to avoid clients from not
501 * being updated & disconnecting when
502 * there is stress
503 */
504 bond_info->rlb_update_retry_counter =
505 RLB_UPDATE_RETRY;
506 }
507 } else { /* there is no active slave */
508 rx_hash_table[index].slave = NULL;
509 }
510 }
511 }
512
Maxim Uvarovf515e6b2012-01-09 12:01:37 +0000513 _unlock_rx_hashtbl_bh(bond);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514
Jay Vosburgh6603a6f2007-10-17 17:37:50 -0700515 write_lock_bh(&bond->curr_slave_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516
517 if (slave != bond->curr_active_slave) {
518 rlb_teach_disabled_mac_on_primary(bond, slave->dev->dev_addr);
519 }
520
Jay Vosburgh6603a6f2007-10-17 17:37:50 -0700521 write_unlock_bh(&bond->curr_slave_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522}
523
524static void rlb_update_client(struct rlb_client_info *client_info)
525{
526 int i;
527
528 if (!client_info->slave) {
529 return;
530 }
531
532 for (i = 0; i < RLB_ARP_BURST_SIZE; i++) {
533 struct sk_buff *skb;
534
535 skb = arp_create(ARPOP_REPLY, ETH_P_ARP,
536 client_info->ip_dst,
537 client_info->slave->dev,
538 client_info->ip_src,
539 client_info->mac_dst,
540 client_info->slave->dev->dev_addr,
541 client_info->mac_dst);
542 if (!skb) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800543 pr_err("%s: Error: failed to create an ARP packet\n",
Jiri Pirko471cb5a2013-01-03 22:49:01 +0000544 client_info->slave->bond->dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545 continue;
546 }
547
548 skb->dev = client_info->slave->dev;
549
Veaceslav Falicod3ab3ff2013-08-29 23:38:57 +0200550 if (client_info->vlan_id) {
Patrick McHardy86a9bad2013-04-19 02:04:30 +0000551 skb = vlan_put_tag(skb, htons(ETH_P_8021Q), client_info->vlan_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552 if (!skb) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800553 pr_err("%s: Error: failed to insert VLAN tag\n",
Jiri Pirko471cb5a2013-01-03 22:49:01 +0000554 client_info->slave->bond->dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555 continue;
556 }
557 }
558
559 arp_xmit(skb);
560 }
561}
562
563/* sends ARP REPLIES that update the clients that need updating */
564static void rlb_update_rx_clients(struct bonding *bond)
565{
566 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
567 struct rlb_client_info *client_info;
568 u32 hash_index;
569
Maxim Uvarovf515e6b2012-01-09 12:01:37 +0000570 _lock_rx_hashtbl_bh(bond);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571
Jiri Bohace53665c2012-11-28 04:42:14 +0000572 hash_index = bond_info->rx_hashtbl_used_head;
573 for (; hash_index != RLB_NULL_INDEX;
574 hash_index = client_info->used_next) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 client_info = &(bond_info->rx_hashtbl[hash_index]);
576 if (client_info->ntt) {
577 rlb_update_client(client_info);
578 if (bond_info->rlb_update_retry_counter == 0) {
579 client_info->ntt = 0;
580 }
581 }
582 }
583
Thadeu Lima de Souza Cascardo94e2bd62009-10-16 15:20:49 +0200584 /* do not update the entries again until this counter is zero so that
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 * not to confuse the clients.
586 */
587 bond_info->rlb_update_delay_counter = RLB_UPDATE_DELAY;
588
Maxim Uvarovf515e6b2012-01-09 12:01:37 +0000589 _unlock_rx_hashtbl_bh(bond);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590}
591
592/* The slave was assigned a new mac address - update the clients */
593static void rlb_req_update_slave_clients(struct bonding *bond, struct slave *slave)
594{
595 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
596 struct rlb_client_info *client_info;
597 int ntt = 0;
598 u32 hash_index;
599
Maxim Uvarovf515e6b2012-01-09 12:01:37 +0000600 _lock_rx_hashtbl_bh(bond);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601
Jiri Bohace53665c2012-11-28 04:42:14 +0000602 hash_index = bond_info->rx_hashtbl_used_head;
603 for (; hash_index != RLB_NULL_INDEX;
604 hash_index = client_info->used_next) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 client_info = &(bond_info->rx_hashtbl[hash_index]);
606
607 if ((client_info->slave == slave) &&
Joe Perchesa6700db2012-05-09 17:04:04 +0000608 !ether_addr_equal_64bits(client_info->mac_dst, mac_bcast)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609 client_info->ntt = 1;
610 ntt = 1;
611 }
612 }
613
614 // update the team's flag only after the whole iteration
615 if (ntt) {
616 bond_info->rx_ntt = 1;
617 //fasten the change
618 bond_info->rlb_update_retry_counter = RLB_UPDATE_RETRY;
619 }
620
Maxim Uvarovf515e6b2012-01-09 12:01:37 +0000621 _unlock_rx_hashtbl_bh(bond);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622}
623
624/* mark all clients using src_ip to be updated */
Al Virod3bb52b2007-08-22 20:06:58 -0400625static void rlb_req_update_subnet_clients(struct bonding *bond, __be32 src_ip)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626{
627 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
628 struct rlb_client_info *client_info;
629 u32 hash_index;
630
631 _lock_rx_hashtbl(bond);
632
Jiri Bohace53665c2012-11-28 04:42:14 +0000633 hash_index = bond_info->rx_hashtbl_used_head;
634 for (; hash_index != RLB_NULL_INDEX;
635 hash_index = client_info->used_next) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 client_info = &(bond_info->rx_hashtbl[hash_index]);
637
638 if (!client_info->slave) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800639 pr_err("%s: Error: found a client with no channel in the client's hash table\n",
Mitch Williams4e0952c2005-11-09 10:34:57 -0800640 bond->dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 continue;
642 }
643 /*update all clients using this src_ip, that are not assigned
644 * to the team's address (curr_active_slave) and have a known
645 * unicast mac address.
646 */
647 if ((client_info->ip_src == src_ip) &&
Joe Perchesa6700db2012-05-09 17:04:04 +0000648 !ether_addr_equal_64bits(client_info->slave->dev->dev_addr,
649 bond->dev->dev_addr) &&
650 !ether_addr_equal_64bits(client_info->mac_dst, mac_bcast)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651 client_info->ntt = 1;
652 bond_info->rx_ntt = 1;
653 }
654 }
655
656 _unlock_rx_hashtbl(bond);
657}
658
659/* Caller must hold both bond and ptr locks for read */
660static struct slave *rlb_choose_channel(struct sk_buff *skb, struct bonding *bond)
661{
662 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
Arnaldo Carvalho de Meloa16aeb32007-03-10 16:07:19 -0300663 struct arp_pkt *arp = arp_pkt(skb);
dingtianhong28c71922013-10-15 16:28:39 +0800664 struct slave *assigned_slave, *curr_active_slave;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665 struct rlb_client_info *client_info;
666 u32 hash_index = 0;
667
668 _lock_rx_hashtbl(bond);
669
dingtianhong28c71922013-10-15 16:28:39 +0800670 curr_active_slave = rcu_dereference(bond->curr_active_slave);
671
Amerigo Wange364a342011-02-27 23:34:28 +0000672 hash_index = _simple_hash((u8 *)&arp->ip_dst, sizeof(arp->ip_dst));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673 client_info = &(bond_info->rx_hashtbl[hash_index]);
674
675 if (client_info->assigned) {
676 if ((client_info->ip_src == arp->ip_src) &&
677 (client_info->ip_dst == arp->ip_dst)) {
678 /* the entry is already assigned to this client */
Joe Perchesa6700db2012-05-09 17:04:04 +0000679 if (!ether_addr_equal_64bits(arp->mac_dst, mac_bcast)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680 /* update mac address from arp */
681 memcpy(client_info->mac_dst, arp->mac_dst, ETH_ALEN);
682 }
Jiri Bohace53665c2012-11-28 04:42:14 +0000683 memcpy(client_info->mac_src, arp->mac_src, ETH_ALEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684
685 assigned_slave = client_info->slave;
686 if (assigned_slave) {
687 _unlock_rx_hashtbl(bond);
688 return assigned_slave;
689 }
690 } else {
691 /* the entry is already assigned to some other client,
692 * move the old client to primary (curr_active_slave) so
693 * that the new client can be assigned to this entry.
694 */
695 if (bond->curr_active_slave &&
dingtianhong28c71922013-10-15 16:28:39 +0800696 client_info->slave != curr_active_slave) {
697 client_info->slave = curr_active_slave;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698 rlb_update_client(client_info);
699 }
700 }
701 }
702 /* assign a new slave */
dingtianhong28c71922013-10-15 16:28:39 +0800703 assigned_slave = __rlb_next_rx_slave(bond);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704
705 if (assigned_slave) {
Jiri Bohace53665c2012-11-28 04:42:14 +0000706 if (!(client_info->assigned &&
707 client_info->ip_src == arp->ip_src)) {
708 /* ip_src is going to be updated,
709 * fix the src hash list
710 */
711 u32 hash_src = _simple_hash((u8 *)&arp->ip_src,
712 sizeof(arp->ip_src));
713 rlb_src_unlink(bond, hash_index);
714 rlb_src_link(bond, hash_src, hash_index);
715 }
716
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717 client_info->ip_src = arp->ip_src;
718 client_info->ip_dst = arp->ip_dst;
719 /* arp->mac_dst is broadcast for arp reqeusts.
720 * will be updated with clients actual unicast mac address
721 * upon receiving an arp reply.
722 */
723 memcpy(client_info->mac_dst, arp->mac_dst, ETH_ALEN);
Jiri Bohace53665c2012-11-28 04:42:14 +0000724 memcpy(client_info->mac_src, arp->mac_src, ETH_ALEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725 client_info->slave = assigned_slave;
726
Joe Perchesa6700db2012-05-09 17:04:04 +0000727 if (!ether_addr_equal_64bits(client_info->mac_dst, mac_bcast)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728 client_info->ntt = 1;
729 bond->alb_info.rx_ntt = 1;
730 } else {
731 client_info->ntt = 0;
732 }
733
Veaceslav Falico6f477d42013-08-29 23:38:56 +0200734 if (!vlan_get_tag(skb, &client_info->vlan_id))
Veaceslav Falicod3ab3ff2013-08-29 23:38:57 +0200735 client_info->vlan_id = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736
737 if (!client_info->assigned) {
Jiri Bohace53665c2012-11-28 04:42:14 +0000738 u32 prev_tbl_head = bond_info->rx_hashtbl_used_head;
739 bond_info->rx_hashtbl_used_head = hash_index;
740 client_info->used_next = prev_tbl_head;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741 if (prev_tbl_head != RLB_NULL_INDEX) {
Jiri Bohace53665c2012-11-28 04:42:14 +0000742 bond_info->rx_hashtbl[prev_tbl_head].used_prev =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743 hash_index;
744 }
745 client_info->assigned = 1;
746 }
747 }
748
749 _unlock_rx_hashtbl(bond);
750
751 return assigned_slave;
752}
753
754/* chooses (and returns) transmit channel for arp reply
755 * does not choose channel for other arp types since they are
756 * sent on the curr_active_slave
757 */
758static struct slave *rlb_arp_xmit(struct sk_buff *skb, struct bonding *bond)
759{
Arnaldo Carvalho de Meloa16aeb32007-03-10 16:07:19 -0300760 struct arp_pkt *arp = arp_pkt(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761 struct slave *tx_slave = NULL;
762
zheng.li567b8712012-11-27 23:57:04 +0000763 /* Don't modify or load balance ARPs that do not originate locally
764 * (e.g.,arrive via a bridge).
765 */
dingtianhong28c71922013-10-15 16:28:39 +0800766 if (!bond_slave_has_mac_rcu(bond, arp->mac_src))
zheng.li567b8712012-11-27 23:57:04 +0000767 return NULL;
768
Brian Haleyf14c4e42008-09-02 10:08:08 -0400769 if (arp->op_code == htons(ARPOP_REPLY)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770 /* the arp must be sent on the selected
771 * rx channel
772 */
773 tx_slave = rlb_choose_channel(skb, bond);
774 if (tx_slave) {
775 memcpy(arp->mac_src,tx_slave->dev->dev_addr, ETH_ALEN);
776 }
Holger Eitzenberger5a03cdb2008-12-09 23:09:22 -0800777 pr_debug("Server sent ARP Reply packet\n");
Brian Haleyf14c4e42008-09-02 10:08:08 -0400778 } else if (arp->op_code == htons(ARPOP_REQUEST)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779 /* Create an entry in the rx_hashtbl for this client as a
780 * place holder.
781 * When the arp reply is received the entry will be updated
782 * with the correct unicast address of the client.
783 */
784 rlb_choose_channel(skb, bond);
785
Peter Pan(潘卫平)77c8e2c2011-04-11 00:16:32 +0000786 /* The ARP reply packets must be delayed so that
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787 * they can cancel out the influence of the ARP request.
788 */
789 bond->alb_info.rlb_update_delay_counter = RLB_UPDATE_DELAY;
790
791 /* arp requests are broadcast and are sent on the primary
792 * the arp request will collapse all clients on the subnet to
793 * the primary slave. We must register these clients to be
794 * updated with their assigned mac.
795 */
796 rlb_req_update_subnet_clients(bond, arp->ip_src);
Holger Eitzenberger5a03cdb2008-12-09 23:09:22 -0800797 pr_debug("Server sent ARP Request packet\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798 }
799
800 return tx_slave;
801}
802
803/* Caller must hold bond lock for read */
804static void rlb_rebalance(struct bonding *bond)
805{
806 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
807 struct slave *assigned_slave;
808 struct rlb_client_info *client_info;
809 int ntt;
810 u32 hash_index;
811
Maxim Uvarovf515e6b2012-01-09 12:01:37 +0000812 _lock_rx_hashtbl_bh(bond);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813
814 ntt = 0;
Jiri Bohace53665c2012-11-28 04:42:14 +0000815 hash_index = bond_info->rx_hashtbl_used_head;
816 for (; hash_index != RLB_NULL_INDEX;
817 hash_index = client_info->used_next) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818 client_info = &(bond_info->rx_hashtbl[hash_index]);
819 assigned_slave = rlb_next_rx_slave(bond);
820 if (assigned_slave && (client_info->slave != assigned_slave)) {
821 client_info->slave = assigned_slave;
822 client_info->ntt = 1;
823 ntt = 1;
824 }
825 }
826
827 /* update the team's flag only after the whole iteration */
828 if (ntt) {
829 bond_info->rx_ntt = 1;
830 }
Maxim Uvarovf515e6b2012-01-09 12:01:37 +0000831 _unlock_rx_hashtbl_bh(bond);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832}
833
834/* Caller must hold rx_hashtbl lock */
Jiri Bohace53665c2012-11-28 04:42:14 +0000835static void rlb_init_table_entry_dst(struct rlb_client_info *entry)
836{
837 entry->used_next = RLB_NULL_INDEX;
838 entry->used_prev = RLB_NULL_INDEX;
839 entry->assigned = 0;
840 entry->slave = NULL;
Veaceslav Falicod3ab3ff2013-08-29 23:38:57 +0200841 entry->vlan_id = 0;
Jiri Bohace53665c2012-11-28 04:42:14 +0000842}
843static void rlb_init_table_entry_src(struct rlb_client_info *entry)
844{
845 entry->src_first = RLB_NULL_INDEX;
846 entry->src_prev = RLB_NULL_INDEX;
847 entry->src_next = RLB_NULL_INDEX;
848}
849
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850static void rlb_init_table_entry(struct rlb_client_info *entry)
851{
852 memset(entry, 0, sizeof(struct rlb_client_info));
Jiri Bohace53665c2012-11-28 04:42:14 +0000853 rlb_init_table_entry_dst(entry);
854 rlb_init_table_entry_src(entry);
855}
856
857static void rlb_delete_table_entry_dst(struct bonding *bond, u32 index)
858{
859 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
860 u32 next_index = bond_info->rx_hashtbl[index].used_next;
861 u32 prev_index = bond_info->rx_hashtbl[index].used_prev;
862
863 if (index == bond_info->rx_hashtbl_used_head)
864 bond_info->rx_hashtbl_used_head = next_index;
865 if (prev_index != RLB_NULL_INDEX)
866 bond_info->rx_hashtbl[prev_index].used_next = next_index;
867 if (next_index != RLB_NULL_INDEX)
868 bond_info->rx_hashtbl[next_index].used_prev = prev_index;
869}
870
871/* unlink a rlb hash table entry from the src list */
872static void rlb_src_unlink(struct bonding *bond, u32 index)
873{
874 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
875 u32 next_index = bond_info->rx_hashtbl[index].src_next;
876 u32 prev_index = bond_info->rx_hashtbl[index].src_prev;
877
878 bond_info->rx_hashtbl[index].src_next = RLB_NULL_INDEX;
879 bond_info->rx_hashtbl[index].src_prev = RLB_NULL_INDEX;
880
881 if (next_index != RLB_NULL_INDEX)
882 bond_info->rx_hashtbl[next_index].src_prev = prev_index;
883
884 if (prev_index == RLB_NULL_INDEX)
885 return;
886
887 /* is prev_index pointing to the head of this list? */
888 if (bond_info->rx_hashtbl[prev_index].src_first == index)
889 bond_info->rx_hashtbl[prev_index].src_first = next_index;
890 else
891 bond_info->rx_hashtbl[prev_index].src_next = next_index;
892
893}
894
895static void rlb_delete_table_entry(struct bonding *bond, u32 index)
896{
897 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
898 struct rlb_client_info *entry = &(bond_info->rx_hashtbl[index]);
899
900 rlb_delete_table_entry_dst(bond, index);
901 rlb_init_table_entry_dst(entry);
902
903 rlb_src_unlink(bond, index);
904}
905
906/* add the rx_hashtbl[ip_dst_hash] entry to the list
907 * of entries with identical ip_src_hash
908 */
909static void rlb_src_link(struct bonding *bond, u32 ip_src_hash, u32 ip_dst_hash)
910{
911 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
912 u32 next;
913
914 bond_info->rx_hashtbl[ip_dst_hash].src_prev = ip_src_hash;
915 next = bond_info->rx_hashtbl[ip_src_hash].src_first;
916 bond_info->rx_hashtbl[ip_dst_hash].src_next = next;
917 if (next != RLB_NULL_INDEX)
918 bond_info->rx_hashtbl[next].src_prev = ip_dst_hash;
919 bond_info->rx_hashtbl[ip_src_hash].src_first = ip_dst_hash;
920}
921
922/* deletes all rx_hashtbl entries with arp->ip_src if their mac_src does
923 * not match arp->mac_src */
924static void rlb_purge_src_ip(struct bonding *bond, struct arp_pkt *arp)
925{
926 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
927 u32 ip_src_hash = _simple_hash((u8*)&(arp->ip_src), sizeof(arp->ip_src));
928 u32 index;
929
930 _lock_rx_hashtbl_bh(bond);
931
932 index = bond_info->rx_hashtbl[ip_src_hash].src_first;
933 while (index != RLB_NULL_INDEX) {
934 struct rlb_client_info *entry = &(bond_info->rx_hashtbl[index]);
935 u32 next_index = entry->src_next;
936 if (entry->ip_src == arp->ip_src &&
937 !ether_addr_equal_64bits(arp->mac_src, entry->mac_src))
938 rlb_delete_table_entry(bond, index);
939 index = next_index;
940 }
941 _unlock_rx_hashtbl_bh(bond);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700942}
943
944static int rlb_initialize(struct bonding *bond)
945{
946 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
Mitch Williams0d206a32005-11-09 10:35:30 -0800947 struct rlb_client_info *new_hashtbl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700948 int size = RLB_HASH_TABLE_SIZE * sizeof(struct rlb_client_info);
949 int i;
950
Mitch Williams0d206a32005-11-09 10:35:30 -0800951 new_hashtbl = kmalloc(size, GFP_KERNEL);
Joe Perchese404dec2012-01-29 12:56:23 +0000952 if (!new_hashtbl)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700953 return -1;
Joe Perchese404dec2012-01-29 12:56:23 +0000954
Maxim Uvarovf515e6b2012-01-09 12:01:37 +0000955 _lock_rx_hashtbl_bh(bond);
Mitch Williams0d206a32005-11-09 10:35:30 -0800956
957 bond_info->rx_hashtbl = new_hashtbl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958
Jiri Bohace53665c2012-11-28 04:42:14 +0000959 bond_info->rx_hashtbl_used_head = RLB_NULL_INDEX;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960
961 for (i = 0; i < RLB_HASH_TABLE_SIZE; i++) {
962 rlb_init_table_entry(bond_info->rx_hashtbl + i);
963 }
964
Maxim Uvarovf515e6b2012-01-09 12:01:37 +0000965 _unlock_rx_hashtbl_bh(bond);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700966
Linus Torvalds1da177e2005-04-16 15:20:36 -0700967 /* register to receive ARPs */
Jiri Pirko3aba8912011-04-19 03:48:16 +0000968 bond->recv_probe = rlb_arp_recv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969
970 return 0;
971}
972
973static void rlb_deinitialize(struct bonding *bond)
974{
975 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
976
Maxim Uvarovf515e6b2012-01-09 12:01:37 +0000977 _lock_rx_hashtbl_bh(bond);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978
979 kfree(bond_info->rx_hashtbl);
980 bond_info->rx_hashtbl = NULL;
Jiri Bohace53665c2012-11-28 04:42:14 +0000981 bond_info->rx_hashtbl_used_head = RLB_NULL_INDEX;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700982
Maxim Uvarovf515e6b2012-01-09 12:01:37 +0000983 _unlock_rx_hashtbl_bh(bond);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984}
985
986static void rlb_clear_vlan(struct bonding *bond, unsigned short vlan_id)
987{
988 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
989 u32 curr_index;
990
Maxim Uvarovf515e6b2012-01-09 12:01:37 +0000991 _lock_rx_hashtbl_bh(bond);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700992
Jiri Bohace53665c2012-11-28 04:42:14 +0000993 curr_index = bond_info->rx_hashtbl_used_head;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994 while (curr_index != RLB_NULL_INDEX) {
995 struct rlb_client_info *curr = &(bond_info->rx_hashtbl[curr_index]);
Jiri Bohace53665c2012-11-28 04:42:14 +0000996 u32 next_index = bond_info->rx_hashtbl[curr_index].used_next;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700997
Veaceslav Falicod3ab3ff2013-08-29 23:38:57 +0200998 if (curr->vlan_id == vlan_id)
Jiri Bohace53665c2012-11-28 04:42:14 +0000999 rlb_delete_table_entry(bond, curr_index);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001000
1001 curr_index = next_index;
1002 }
1003
Maxim Uvarovf515e6b2012-01-09 12:01:37 +00001004 _unlock_rx_hashtbl_bh(bond);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001005}
1006
1007/*********************** tlb/rlb shared functions *********************/
1008
Veaceslav Falico7aa64982013-08-28 23:25:13 +02001009static void alb_send_lp_vid(struct slave *slave, u8 mac_addr[],
1010 u16 vid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001012 struct learning_pkt pkt;
Veaceslav Falico7aa64982013-08-28 23:25:13 +02001013 struct sk_buff *skb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014 int size = sizeof(struct learning_pkt);
Veaceslav Falico7aa64982013-08-28 23:25:13 +02001015 char *data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016
1017 memset(&pkt, 0, size);
1018 memcpy(pkt.mac_dst, mac_addr, ETH_ALEN);
1019 memcpy(pkt.mac_src, mac_addr, ETH_ALEN);
Harvey Harrison09640e632009-02-01 00:45:17 -08001020 pkt.type = cpu_to_be16(ETH_P_LOOP);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001021
Veaceslav Falico7aa64982013-08-28 23:25:13 +02001022 skb = dev_alloc_skb(size);
1023 if (!skb)
1024 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001025
Veaceslav Falico7aa64982013-08-28 23:25:13 +02001026 data = skb_put(skb, size);
1027 memcpy(data, &pkt, size);
1028
1029 skb_reset_mac_header(skb);
1030 skb->network_header = skb->mac_header + ETH_HLEN;
1031 skb->protocol = pkt.type;
1032 skb->priority = TC_PRIO_CONTROL;
1033 skb->dev = slave->dev;
1034
1035 if (vid) {
1036 skb = vlan_put_tag(skb, htons(ETH_P_8021Q), vid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001037 if (!skb) {
Veaceslav Falico7aa64982013-08-28 23:25:13 +02001038 pr_err("%s: Error: failed to insert VLAN tag\n",
1039 slave->bond->dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001040 return;
1041 }
Veaceslav Falico7aa64982013-08-28 23:25:13 +02001042 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001043
Veaceslav Falico7aa64982013-08-28 23:25:13 +02001044 dev_queue_xmit(skb);
1045}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001046
Veaceslav Falico7aa64982013-08-28 23:25:13 +02001047
1048static void alb_send_learning_packets(struct slave *slave, u8 mac_addr[])
1049{
1050 struct bonding *bond = bond_get_bond_by_slave(slave);
Veaceslav Falico5bf94b82013-08-28 23:25:14 +02001051 struct net_device *upper;
1052 struct list_head *iter;
Veaceslav Falico7aa64982013-08-28 23:25:13 +02001053
Veaceslav Falico5bf94b82013-08-28 23:25:14 +02001054 /* send untagged */
1055 alb_send_lp_vid(slave, mac_addr, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001056
Veaceslav Falico5bf94b82013-08-28 23:25:14 +02001057 /* loop through vlans and send one packet for each */
1058 rcu_read_lock();
Veaceslav Falico2f268f12013-09-25 09:20:07 +02001059 netdev_for_each_all_upper_dev_rcu(bond->dev, upper, iter) {
Veaceslav Falico5bf94b82013-08-28 23:25:14 +02001060 if (upper->priv_flags & IFF_802_1Q_VLAN)
1061 alb_send_lp_vid(slave, mac_addr,
1062 vlan_dev_vlan_id(upper));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063 }
Veaceslav Falico5bf94b82013-08-28 23:25:14 +02001064 rcu_read_unlock();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065}
1066
Jiri Bohacb9245512012-01-18 12:24:54 +00001067static int alb_set_slave_mac_addr(struct slave *slave, u8 addr[])
Linus Torvalds1da177e2005-04-16 15:20:36 -07001068{
1069 struct net_device *dev = slave->dev;
1070 struct sockaddr s_addr;
1071
Jiri Bohacb9245512012-01-18 12:24:54 +00001072 if (slave->bond->params.mode == BOND_MODE_TLB) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001073 memcpy(dev->dev_addr, addr, dev->addr_len);
1074 return 0;
1075 }
1076
1077 /* for rlb each slave must have a unique hw mac addresses so that */
1078 /* each slave will receive packets destined to a different mac */
1079 memcpy(s_addr.sa_data, addr, dev->addr_len);
1080 s_addr.sa_family = dev->type;
1081 if (dev_set_mac_address(dev, &s_addr)) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -08001082 pr_err("%s: Error: dev_set_mac_address of dev %s failed!\n"
1083 "ALB mode requires that the base driver support setting the hw address also when the network device's interface is open\n",
Jiri Pirko471cb5a2013-01-03 22:49:01 +00001084 slave->bond->dev->name, dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085 return -EOPNOTSUPP;
1086 }
1087 return 0;
1088}
1089
Jay Vosburgh059fe7a2007-10-17 17:37:49 -07001090/*
1091 * Swap MAC addresses between two slaves.
1092 *
1093 * Called with RTNL held, and no other locks.
1094 *
1095 */
1096
Veaceslav Falico43547ea2013-05-27 23:14:51 +00001097static void alb_swap_mac_addr(struct slave *slave1, struct slave *slave2)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001098{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099 u8 tmp_mac_addr[ETH_ALEN];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001100
1101 memcpy(tmp_mac_addr, slave1->dev->dev_addr, ETH_ALEN);
Jiri Bohacb9245512012-01-18 12:24:54 +00001102 alb_set_slave_mac_addr(slave1, slave2->dev->dev_addr);
1103 alb_set_slave_mac_addr(slave2, tmp_mac_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001104
Jay Vosburgh059fe7a2007-10-17 17:37:49 -07001105}
1106
1107/*
1108 * Send learning packets after MAC address swap.
1109 *
Jay Vosburgh25433312008-01-17 16:24:59 -08001110 * Called with RTNL and no other locks
Jay Vosburgh059fe7a2007-10-17 17:37:49 -07001111 */
1112static void alb_fasten_mac_swap(struct bonding *bond, struct slave *slave1,
1113 struct slave *slave2)
1114{
1115 int slaves_state_differ = (SLAVE_IS_OK(slave1) != SLAVE_IS_OK(slave2));
1116 struct slave *disabled_slave = NULL;
1117
Jay Vosburgh25433312008-01-17 16:24:59 -08001118 ASSERT_RTNL();
1119
Linus Torvalds1da177e2005-04-16 15:20:36 -07001120 /* fasten the change in the switch */
1121 if (SLAVE_IS_OK(slave1)) {
1122 alb_send_learning_packets(slave1, slave1->dev->dev_addr);
1123 if (bond->alb_info.rlb_enabled) {
1124 /* inform the clients that the mac address
1125 * has changed
1126 */
1127 rlb_req_update_slave_clients(bond, slave1);
1128 }
1129 } else {
1130 disabled_slave = slave1;
1131 }
1132
1133 if (SLAVE_IS_OK(slave2)) {
1134 alb_send_learning_packets(slave2, slave2->dev->dev_addr);
1135 if (bond->alb_info.rlb_enabled) {
1136 /* inform the clients that the mac address
1137 * has changed
1138 */
1139 rlb_req_update_slave_clients(bond, slave2);
1140 }
1141 } else {
1142 disabled_slave = slave2;
1143 }
1144
1145 if (bond->alb_info.rlb_enabled && slaves_state_differ) {
1146 /* A disabled slave was assigned an active mac addr */
1147 rlb_teach_disabled_mac_on_primary(bond,
1148 disabled_slave->dev->dev_addr);
1149 }
1150}
1151
1152/**
1153 * alb_change_hw_addr_on_detach
1154 * @bond: bonding we're working on
1155 * @slave: the slave that was just detached
1156 *
1157 * We assume that @slave was already detached from the slave list.
1158 *
1159 * If @slave's permanent hw address is different both from its current
1160 * address and from @bond's address, then somewhere in the bond there's
1161 * a slave that has @slave's permanet address as its current address.
1162 * We'll make sure that that slave no longer uses @slave's permanent address.
1163 *
Jay Vosburgh25433312008-01-17 16:24:59 -08001164 * Caller must hold RTNL and no other locks
Linus Torvalds1da177e2005-04-16 15:20:36 -07001165 */
1166static void alb_change_hw_addr_on_detach(struct bonding *bond, struct slave *slave)
1167{
1168 int perm_curr_diff;
1169 int perm_bond_diff;
Veaceslav Falicob88ec382013-06-18 13:44:52 +02001170 struct slave *found_slave;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001171
Joe Perchesa6700db2012-05-09 17:04:04 +00001172 perm_curr_diff = !ether_addr_equal_64bits(slave->perm_hwaddr,
1173 slave->dev->dev_addr);
1174 perm_bond_diff = !ether_addr_equal_64bits(slave->perm_hwaddr,
1175 bond->dev->dev_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001176
1177 if (perm_curr_diff && perm_bond_diff) {
Veaceslav Falicob88ec382013-06-18 13:44:52 +02001178 found_slave = bond_slave_has_mac(bond, slave->perm_hwaddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001179
Veaceslav Falicob88ec382013-06-18 13:44:52 +02001180 if (found_slave) {
Jay Vosburgh059fe7a2007-10-17 17:37:49 -07001181 /* locking: needs RTNL and nothing else */
Veaceslav Falicob88ec382013-06-18 13:44:52 +02001182 alb_swap_mac_addr(slave, found_slave);
1183 alb_fasten_mac_swap(bond, slave, found_slave);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001184 }
1185 }
1186}
1187
1188/**
1189 * alb_handle_addr_collision_on_attach
1190 * @bond: bonding we're working on
1191 * @slave: the slave that was just attached
1192 *
1193 * checks uniqueness of slave's mac address and handles the case the
1194 * new slave uses the bonds mac address.
1195 *
1196 * If the permanent hw address of @slave is @bond's hw address, we need to
1197 * find a different hw address to give @slave, that isn't in use by any other
Peter Pan(潘卫平)77c8e2c2011-04-11 00:16:32 +00001198 * slave in the bond. This address must be, of course, one of the permanent
Linus Torvalds1da177e2005-04-16 15:20:36 -07001199 * addresses of the other slaves.
1200 *
1201 * We go over the slave list, and for each slave there we compare its
1202 * permanent hw address with the current address of all the other slaves.
1203 * If no match was found, then we've found a slave with a permanent address
1204 * that isn't used by any other slave in the bond, so we can assign it to
1205 * @slave.
1206 *
1207 * assumption: this function is called before @slave is attached to the
Veaceslav Falicocedb7432013-06-17 19:30:35 +02001208 * bond slave list.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001209 */
1210static int alb_handle_addr_collision_on_attach(struct bonding *bond, struct slave *slave)
1211{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001212 struct slave *has_bond_addr = bond->curr_active_slave;
Veaceslav Falico9caff1e72013-09-25 09:20:14 +02001213 struct slave *tmp_slave1, *free_mac_slave = NULL;
1214 struct list_head *iter;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001215
Veaceslav Falico0965a1f2013-09-25 09:20:21 +02001216 if (!bond_has_slaves(bond)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001217 /* this is the first slave */
1218 return 0;
1219 }
1220
1221 /* if slave's mac address differs from bond's mac address
1222 * check uniqueness of slave's mac address against the other
1223 * slaves in the bond.
1224 */
Joe Perchesa6700db2012-05-09 17:04:04 +00001225 if (!ether_addr_equal_64bits(slave->perm_hwaddr, bond->dev->dev_addr)) {
Veaceslav Falicocedb7432013-06-17 19:30:35 +02001226 if (!bond_slave_has_mac(bond, slave->dev->dev_addr))
John W. Linville6b38aef2005-07-28 15:00:15 -04001227 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001228
John W. Linville6b38aef2005-07-28 15:00:15 -04001229 /* Try setting slave mac to bond address and fall-through
1230 to code handling that situation below... */
Jiri Bohacb9245512012-01-18 12:24:54 +00001231 alb_set_slave_mac_addr(slave, bond->dev->dev_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001232 }
1233
1234 /* The slave's address is equal to the address of the bond.
1235 * Search for a spare address in the bond for this slave.
1236 */
Veaceslav Falico9caff1e72013-09-25 09:20:14 +02001237 bond_for_each_slave(bond, tmp_slave1, iter) {
Veaceslav Falicocedb7432013-06-17 19:30:35 +02001238 if (!bond_slave_has_mac(bond, tmp_slave1->perm_hwaddr)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001239 /* no slave has tmp_slave1's perm addr
1240 * as its curr addr
1241 */
1242 free_mac_slave = tmp_slave1;
1243 break;
1244 }
1245
1246 if (!has_bond_addr) {
Joe Perchesa6700db2012-05-09 17:04:04 +00001247 if (ether_addr_equal_64bits(tmp_slave1->dev->dev_addr,
1248 bond->dev->dev_addr)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001249
1250 has_bond_addr = tmp_slave1;
1251 }
1252 }
1253 }
1254
1255 if (free_mac_slave) {
Jiri Bohacb9245512012-01-18 12:24:54 +00001256 alb_set_slave_mac_addr(slave, free_mac_slave->perm_hwaddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001257
Joe Perchesa4aee5c2009-12-13 20:06:07 -08001258 pr_warning("%s: Warning: the hw address of slave %s is in use by the bond; giving it the hw address of %s\n",
Jiri Pirkoe5e2a8f2009-08-13 04:11:52 +00001259 bond->dev->name, slave->dev->name,
1260 free_mac_slave->dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001261
1262 } else if (has_bond_addr) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -08001263 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",
Mitch Williams4e0952c2005-11-09 10:34:57 -08001264 bond->dev->name, slave->dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001265 return -EFAULT;
1266 }
1267
1268 return 0;
1269}
1270
1271/**
1272 * alb_set_mac_address
1273 * @bond:
1274 * @addr:
1275 *
1276 * In TLB mode all slaves are configured to the bond's hw address, but set
1277 * their dev_addr field to different addresses (based on their permanent hw
1278 * addresses).
1279 *
1280 * For each slave, this function sets the interface to the new address and then
1281 * changes its dev_addr field to its previous value.
1282 *
1283 * Unwinding assumes bond's mac address has not yet changed.
1284 */
1285static int alb_set_mac_address(struct bonding *bond, void *addr)
1286{
Veaceslav Falico81f23b12013-09-25 09:20:13 +02001287 struct slave *slave, *rollback_slave;
Veaceslav Falico9caff1e72013-09-25 09:20:14 +02001288 struct list_head *iter;
nikolay@redhat.comdec1e902013-08-01 16:54:47 +02001289 struct sockaddr sa;
Veaceslav Falico81f23b12013-09-25 09:20:13 +02001290 char tmp_addr[ETH_ALEN];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001291 int res;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001292
nikolay@redhat.comdec1e902013-08-01 16:54:47 +02001293 if (bond->alb_info.rlb_enabled)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001294 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001295
Veaceslav Falico9caff1e72013-09-25 09:20:14 +02001296 bond_for_each_slave(bond, slave, iter) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001297 /* save net_device's current hw address */
1298 memcpy(tmp_addr, slave->dev->dev_addr, ETH_ALEN);
1299
1300 res = dev_set_mac_address(slave->dev, addr);
1301
1302 /* restore net_device's hw address */
1303 memcpy(slave->dev->dev_addr, tmp_addr, ETH_ALEN);
1304
Stephen Hemmingereb7cc592008-11-19 21:56:05 -08001305 if (res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001306 goto unwind;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001307 }
1308
1309 return 0;
1310
1311unwind:
1312 memcpy(sa.sa_data, bond->dev->dev_addr, bond->dev->addr_len);
1313 sa.sa_family = bond->dev->type;
1314
1315 /* unwind from head to the slave that failed */
Veaceslav Falico9caff1e72013-09-25 09:20:14 +02001316 bond_for_each_slave(bond, rollback_slave, iter) {
Veaceslav Falico81f23b12013-09-25 09:20:13 +02001317 if (rollback_slave == slave)
1318 break;
1319 memcpy(tmp_addr, rollback_slave->dev->dev_addr, ETH_ALEN);
1320 dev_set_mac_address(rollback_slave->dev, &sa);
1321 memcpy(rollback_slave->dev->dev_addr, tmp_addr, ETH_ALEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001322 }
1323
1324 return res;
1325}
1326
1327/************************ exported alb funcions ************************/
1328
1329int bond_alb_initialize(struct bonding *bond, int rlb_enabled)
1330{
1331 int res;
1332
1333 res = tlb_initialize(bond);
1334 if (res) {
1335 return res;
1336 }
1337
1338 if (rlb_enabled) {
1339 bond->alb_info.rlb_enabled = 1;
1340 /* initialize rlb */
1341 res = rlb_initialize(bond);
1342 if (res) {
1343 tlb_deinitialize(bond);
1344 return res;
1345 }
Mitch Williamsb76850a2005-11-09 10:35:35 -08001346 } else {
1347 bond->alb_info.rlb_enabled = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001348 }
1349
1350 return 0;
1351}
1352
1353void bond_alb_deinitialize(struct bonding *bond)
1354{
1355 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
1356
1357 tlb_deinitialize(bond);
1358
1359 if (bond_info->rlb_enabled) {
1360 rlb_deinitialize(bond);
1361 }
1362}
1363
1364int bond_alb_xmit(struct sk_buff *skb, struct net_device *bond_dev)
1365{
Wang Chen454d7c92008-11-12 23:37:49 -08001366 struct bonding *bond = netdev_priv(bond_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001367 struct ethhdr *eth_data;
1368 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
1369 struct slave *tx_slave = NULL;
Al Virod3bb52b2007-08-22 20:06:58 -04001370 static const __be32 ip_bcast = htonl(0xffffffff);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001371 int hash_size = 0;
1372 int do_tx_balance = 1;
1373 u32 hash_index = 0;
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07001374 const u8 *hash_start = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001375 int res = 1;
Vlad Yasevich2d1ea192008-08-28 15:38:41 -04001376 struct ipv6hdr *ip6hdr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001377
Arnaldo Carvalho de Melo459a98e2007-03-19 15:30:44 -07001378 skb_reset_mac_header(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001379 eth_data = eth_hdr(skb);
1380
Linus Torvalds1da177e2005-04-16 15:20:36 -07001381 switch (ntohs(skb->protocol)) {
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07001382 case ETH_P_IP: {
1383 const struct iphdr *iph = ip_hdr(skb);
1384
Joe Perchesa6700db2012-05-09 17:04:04 +00001385 if (ether_addr_equal_64bits(eth_data->h_dest, mac_bcast) ||
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07001386 (iph->daddr == ip_bcast) ||
1387 (iph->protocol == IPPROTO_IGMP)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001388 do_tx_balance = 0;
1389 break;
1390 }
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07001391 hash_start = (char *)&(iph->daddr);
1392 hash_size = sizeof(iph->daddr);
1393 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001394 break;
1395 case ETH_P_IPV6:
Vlad Yasevich2d1ea192008-08-28 15:38:41 -04001396 /* IPv6 doesn't really use broadcast mac address, but leave
1397 * that here just in case.
1398 */
Joe Perchesa6700db2012-05-09 17:04:04 +00001399 if (ether_addr_equal_64bits(eth_data->h_dest, mac_bcast)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001400 do_tx_balance = 0;
1401 break;
1402 }
1403
Vlad Yasevich2d1ea192008-08-28 15:38:41 -04001404 /* IPv6 uses all-nodes multicast as an equivalent to
1405 * broadcasts in IPv4.
1406 */
Joe Perchesa6700db2012-05-09 17:04:04 +00001407 if (ether_addr_equal_64bits(eth_data->h_dest, mac_v6_allmcast)) {
Vlad Yasevich2d1ea192008-08-28 15:38:41 -04001408 do_tx_balance = 0;
1409 break;
1410 }
1411
1412 /* Additianally, DAD probes should not be tx-balanced as that
1413 * will lead to false positives for duplicate addresses and
1414 * prevent address configuration from working.
1415 */
1416 ip6hdr = ipv6_hdr(skb);
1417 if (ipv6_addr_any(&ip6hdr->saddr)) {
1418 do_tx_balance = 0;
1419 break;
1420 }
1421
Arnaldo Carvalho de Melo0660e032007-04-25 17:54:47 -07001422 hash_start = (char *)&(ipv6_hdr(skb)->daddr);
1423 hash_size = sizeof(ipv6_hdr(skb)->daddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001424 break;
1425 case ETH_P_IPX:
Al Virod3bb52b2007-08-22 20:06:58 -04001426 if (ipx_hdr(skb)->ipx_checksum != IPX_NO_CHECKSUM) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001427 /* something is wrong with this packet */
1428 do_tx_balance = 0;
1429 break;
1430 }
1431
1432 if (ipx_hdr(skb)->ipx_type != IPX_TYPE_NCP) {
1433 /* The only protocol worth balancing in
1434 * this family since it has an "ARP" like
1435 * mechanism
1436 */
1437 do_tx_balance = 0;
1438 break;
1439 }
1440
1441 hash_start = (char*)eth_data->h_dest;
1442 hash_size = ETH_ALEN;
1443 break;
1444 case ETH_P_ARP:
1445 do_tx_balance = 0;
1446 if (bond_info->rlb_enabled) {
1447 tx_slave = rlb_arp_xmit(skb, bond);
1448 }
1449 break;
1450 default:
1451 do_tx_balance = 0;
1452 break;
1453 }
1454
1455 if (do_tx_balance) {
1456 hash_index = _simple_hash(hash_start, hash_size);
1457 tx_slave = tlb_choose_channel(bond, hash_index, skb->len);
1458 }
1459
1460 if (!tx_slave) {
1461 /* unbalanced or unassigned, send through primary */
dingtianhong28c71922013-10-15 16:28:39 +08001462 tx_slave = rcu_dereference(bond->curr_active_slave);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001463 bond_info->unbalanced_load += skb->len;
1464 }
1465
1466 if (tx_slave && SLAVE_IS_OK(tx_slave)) {
dingtianhong28c71922013-10-15 16:28:39 +08001467 if (tx_slave != rcu_dereference(bond->curr_active_slave)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001468 memcpy(eth_data->h_source,
1469 tx_slave->dev->dev_addr,
1470 ETH_ALEN);
1471 }
1472
1473 res = bond_dev_queue_xmit(bond, skb, tx_slave->dev);
1474 } else {
1475 if (tx_slave) {
Maxim Uvarovf515e6b2012-01-09 12:01:37 +00001476 _lock_tx_hashtbl(bond);
1477 __tlb_clear_slave(bond, tx_slave, 0);
1478 _unlock_tx_hashtbl(bond);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001479 }
1480 }
1481
Eric Dumazet04502432012-06-13 05:30:07 +00001482 if (res) {
1483 /* no suitable interface, frame not sent */
1484 kfree_skb(skb);
1485 }
nikolay@redhat.com278b2082013-08-01 16:54:51 +02001486
Patrick McHardyec634fe2009-07-05 19:23:38 -07001487 return NETDEV_TX_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001488}
1489
Jay Vosburgh1b76b312007-10-17 17:37:45 -07001490void bond_alb_monitor(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001491{
Jay Vosburgh1b76b312007-10-17 17:37:45 -07001492 struct bonding *bond = container_of(work, struct bonding,
1493 alb_work.work);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001494 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
Veaceslav Falico9caff1e72013-09-25 09:20:14 +02001495 struct list_head *iter;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001496 struct slave *slave;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001497
1498 read_lock(&bond->lock);
1499
Veaceslav Falico0965a1f2013-09-25 09:20:21 +02001500 if (!bond_has_slaves(bond)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001501 bond_info->tx_rebalance_counter = 0;
1502 bond_info->lp_counter = 0;
1503 goto re_arm;
1504 }
1505
1506 bond_info->tx_rebalance_counter++;
1507 bond_info->lp_counter++;
1508
1509 /* send learning packets */
Neil Horman7eacd032013-09-13 11:05:33 -04001510 if (bond_info->lp_counter >= BOND_ALB_LP_TICKS(bond)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001511 /* change of curr_active_slave involves swapping of mac addresses.
1512 * in order to avoid this swapping from happening while
1513 * sending the learning packets, the curr_slave_lock must be held for
1514 * read.
1515 */
1516 read_lock(&bond->curr_slave_lock);
1517
Veaceslav Falico9caff1e72013-09-25 09:20:14 +02001518 bond_for_each_slave(bond, slave, iter)
Mitch Williamse944ef72005-11-09 10:36:50 -08001519 alb_send_learning_packets(slave, slave->dev->dev_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001520
1521 read_unlock(&bond->curr_slave_lock);
1522
1523 bond_info->lp_counter = 0;
1524 }
1525
1526 /* rebalance tx traffic */
1527 if (bond_info->tx_rebalance_counter >= BOND_TLB_REBALANCE_TICKS) {
1528
1529 read_lock(&bond->curr_slave_lock);
1530
Veaceslav Falico9caff1e72013-09-25 09:20:14 +02001531 bond_for_each_slave(bond, slave, iter) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001532 tlb_clear_slave(bond, slave, 1);
1533 if (slave == bond->curr_active_slave) {
1534 SLAVE_TLB_INFO(slave).load =
1535 bond_info->unbalanced_load /
1536 BOND_TLB_REBALANCE_INTERVAL;
1537 bond_info->unbalanced_load = 0;
1538 }
1539 }
1540
1541 read_unlock(&bond->curr_slave_lock);
1542
1543 bond_info->tx_rebalance_counter = 0;
1544 }
1545
1546 /* handle rlb stuff */
1547 if (bond_info->rlb_enabled) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001548 if (bond_info->primary_is_promisc &&
1549 (++bond_info->rlb_promisc_timeout_counter >= RLB_PROMISC_TIMEOUT)) {
1550
Jay Vosburghd0e81b72007-10-17 17:37:51 -07001551 /*
1552 * dev_set_promiscuity requires rtnl and
Jay Vosburghe6d265e2011-10-28 15:42:50 +00001553 * nothing else. Avoid race with bond_close.
Jay Vosburghd0e81b72007-10-17 17:37:51 -07001554 */
1555 read_unlock(&bond->lock);
Jay Vosburghe6d265e2011-10-28 15:42:50 +00001556 if (!rtnl_trylock()) {
1557 read_lock(&bond->lock);
1558 goto re_arm;
1559 }
Jay Vosburghd0e81b72007-10-17 17:37:51 -07001560
Linus Torvalds1da177e2005-04-16 15:20:36 -07001561 bond_info->rlb_promisc_timeout_counter = 0;
1562
1563 /* If the primary was set to promiscuous mode
1564 * because a slave was disabled then
1565 * it can now leave promiscuous mode.
1566 */
1567 dev_set_promiscuity(bond->curr_active_slave->dev, -1);
1568 bond_info->primary_is_promisc = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001569
Jay Vosburghd0e81b72007-10-17 17:37:51 -07001570 rtnl_unlock();
1571 read_lock(&bond->lock);
1572 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001573
1574 if (bond_info->rlb_rebalance) {
1575 bond_info->rlb_rebalance = 0;
1576 rlb_rebalance(bond);
1577 }
1578
1579 /* check if clients need updating */
1580 if (bond_info->rx_ntt) {
1581 if (bond_info->rlb_update_delay_counter) {
1582 --bond_info->rlb_update_delay_counter;
1583 } else {
1584 rlb_update_rx_clients(bond);
1585 if (bond_info->rlb_update_retry_counter) {
1586 --bond_info->rlb_update_retry_counter;
1587 } else {
1588 bond_info->rx_ntt = 0;
1589 }
1590 }
1591 }
1592 }
1593
1594re_arm:
Jay Vosburghe6d265e2011-10-28 15:42:50 +00001595 queue_delayed_work(bond->wq, &bond->alb_work, alb_delta_in_ticks);
1596
Linus Torvalds1da177e2005-04-16 15:20:36 -07001597 read_unlock(&bond->lock);
1598}
1599
1600/* assumption: called before the slave is attached to the bond
1601 * and not locked by the bond lock
1602 */
1603int bond_alb_init_slave(struct bonding *bond, struct slave *slave)
1604{
1605 int res;
1606
Jiri Bohacb9245512012-01-18 12:24:54 +00001607 res = alb_set_slave_mac_addr(slave, slave->perm_hwaddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001608 if (res) {
1609 return res;
1610 }
1611
Linus Torvalds1da177e2005-04-16 15:20:36 -07001612 res = alb_handle_addr_collision_on_attach(bond, slave);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001613 if (res) {
1614 return res;
1615 }
1616
1617 tlb_init_slave(slave);
1618
1619 /* order a rebalance ASAP */
1620 bond->alb_info.tx_rebalance_counter = BOND_TLB_REBALANCE_TICKS;
1621
1622 if (bond->alb_info.rlb_enabled) {
1623 bond->alb_info.rlb_rebalance = 1;
1624 }
1625
1626 return 0;
1627}
1628
Jay Vosburgh25433312008-01-17 16:24:59 -08001629/*
1630 * Remove slave from tlb and rlb hash tables, and fix up MAC addresses
1631 * if necessary.
1632 *
1633 * Caller must hold RTNL and no other locks
1634 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001635void bond_alb_deinit_slave(struct bonding *bond, struct slave *slave)
1636{
Veaceslav Falico0965a1f2013-09-25 09:20:21 +02001637 if (bond_has_slaves(bond))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001638 alb_change_hw_addr_on_detach(bond, slave);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001639
1640 tlb_clear_slave(bond, slave, 0);
1641
1642 if (bond->alb_info.rlb_enabled) {
Veaceslav Falico6475ae42013-09-25 09:20:17 +02001643 bond->alb_info.rx_slave = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001644 rlb_clear_slave(bond, slave);
1645 }
1646}
1647
1648/* Caller must hold bond lock for read */
1649void bond_alb_handle_link_change(struct bonding *bond, struct slave *slave, char link)
1650{
1651 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
1652
1653 if (link == BOND_LINK_DOWN) {
1654 tlb_clear_slave(bond, slave, 0);
1655 if (bond->alb_info.rlb_enabled) {
1656 rlb_clear_slave(bond, slave);
1657 }
1658 } else if (link == BOND_LINK_UP) {
1659 /* order a rebalance ASAP */
1660 bond_info->tx_rebalance_counter = BOND_TLB_REBALANCE_TICKS;
1661 if (bond->alb_info.rlb_enabled) {
1662 bond->alb_info.rlb_rebalance = 1;
1663 /* If the updelay module parameter is smaller than the
1664 * forwarding delay of the switch the rebalance will
1665 * not work because the rebalance arp replies will
1666 * not be forwarded to the clients..
1667 */
1668 }
1669 }
1670}
1671
1672/**
1673 * bond_alb_handle_active_change - assign new curr_active_slave
1674 * @bond: our bonding struct
1675 * @new_slave: new slave to assign
1676 *
1677 * Set the bond->curr_active_slave to @new_slave and handle
1678 * mac address swapping and promiscuity changes as needed.
1679 *
Jay Vosburgh059fe7a2007-10-17 17:37:49 -07001680 * If new_slave is NULL, caller must hold curr_slave_lock or
1681 * bond->lock for write.
1682 *
1683 * If new_slave is not NULL, caller must hold RTNL, bond->lock for
1684 * read and curr_slave_lock for write. Processing here may sleep, so
1685 * no other locks may be held.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001686 */
1687void bond_alb_handle_active_change(struct bonding *bond, struct slave *new_slave)
Hannes Eder1f78d9f2009-02-14 11:15:33 +00001688 __releases(&bond->curr_slave_lock)
1689 __releases(&bond->lock)
1690 __acquires(&bond->lock)
1691 __acquires(&bond->curr_slave_lock)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001692{
1693 struct slave *swap_slave;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001694
nikolay@redhat.comdec1e902013-08-01 16:54:47 +02001695 if (bond->curr_active_slave == new_slave)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001696 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001697
1698 if (bond->curr_active_slave && bond->alb_info.primary_is_promisc) {
1699 dev_set_promiscuity(bond->curr_active_slave->dev, -1);
1700 bond->alb_info.primary_is_promisc = 0;
1701 bond->alb_info.rlb_promisc_timeout_counter = 0;
1702 }
1703
1704 swap_slave = bond->curr_active_slave;
nikolay@redhat.com278b2082013-08-01 16:54:51 +02001705 rcu_assign_pointer(bond->curr_active_slave, new_slave);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001706
Veaceslav Falico0965a1f2013-09-25 09:20:21 +02001707 if (!new_slave || !bond_has_slaves(bond))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001708 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001709
1710 /* set the new curr_active_slave to the bonds mac address
1711 * i.e. swap mac addresses of old curr_active_slave and new curr_active_slave
1712 */
Veaceslav Falicob88ec382013-06-18 13:44:52 +02001713 if (!swap_slave)
1714 swap_slave = bond_slave_has_mac(bond, bond->dev->dev_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001715
Jay Vosburgh059fe7a2007-10-17 17:37:49 -07001716 /*
1717 * Arrange for swap_slave and new_slave to temporarily be
1718 * ignored so we can mess with their MAC addresses without
1719 * fear of interference from transmit activity.
1720 */
nikolay@redhat.comdec1e902013-08-01 16:54:47 +02001721 if (swap_slave)
Jay Vosburgh059fe7a2007-10-17 17:37:49 -07001722 tlb_clear_slave(bond, swap_slave, 1);
Jay Vosburgh059fe7a2007-10-17 17:37:49 -07001723 tlb_clear_slave(bond, new_slave, 1);
1724
1725 write_unlock_bh(&bond->curr_slave_lock);
1726 read_unlock(&bond->lock);
1727
Jay Vosburghe0138a62008-01-17 16:24:58 -08001728 ASSERT_RTNL();
1729
Veaceslav Falico4996b902013-10-07 09:17:20 +02001730 /* in TLB mode, the slave might flip down/up with the old dev_addr,
1731 * and thus filter bond->dev_addr's packets, so force bond's mac
1732 */
1733 if (bond->params.mode == BOND_MODE_TLB) {
1734 struct sockaddr sa;
1735 u8 tmp_addr[ETH_ALEN];
1736
1737 memcpy(tmp_addr, new_slave->dev->dev_addr, ETH_ALEN);
1738
1739 memcpy(sa.sa_data, bond->dev->dev_addr, bond->dev->addr_len);
1740 sa.sa_family = bond->dev->type;
1741 /* we don't care if it can't change its mac, best effort */
1742 dev_set_mac_address(new_slave->dev, &sa);
1743
1744 memcpy(new_slave->dev->dev_addr, tmp_addr, ETH_ALEN);
1745 }
1746
Linus Torvalds1da177e2005-04-16 15:20:36 -07001747 /* curr_active_slave must be set before calling alb_swap_mac_addr */
1748 if (swap_slave) {
1749 /* swap mac address */
Veaceslav Falico43547ea2013-05-27 23:14:51 +00001750 alb_swap_mac_addr(swap_slave, new_slave);
Jay Vosburgh059fe7a2007-10-17 17:37:49 -07001751 alb_fasten_mac_swap(bond, swap_slave, new_slave);
Jay Vosburgh25433312008-01-17 16:24:59 -08001752 read_lock(&bond->lock);
Jay Vosburgh059fe7a2007-10-17 17:37:49 -07001753 } else {
Veaceslav Falicob88ec382013-06-18 13:44:52 +02001754 /* set the new_slave to the bond mac address */
1755 alb_set_slave_mac_addr(new_slave, bond->dev->dev_addr);
Jay Vosburgh25433312008-01-17 16:24:59 -08001756 read_lock(&bond->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001757 alb_send_learning_packets(new_slave, bond->dev->dev_addr);
1758 }
Jay Vosburgh059fe7a2007-10-17 17:37:49 -07001759
1760 write_lock_bh(&bond->curr_slave_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001761}
1762
Jay Vosburgh059fe7a2007-10-17 17:37:49 -07001763/*
1764 * Called with RTNL
1765 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001766int bond_alb_set_mac_address(struct net_device *bond_dev, void *addr)
Hannes Eder1f78d9f2009-02-14 11:15:33 +00001767 __acquires(&bond->lock)
Jay Vosburgh815bcc22009-05-04 09:03:37 +00001768 __releases(&bond->lock)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001769{
Wang Chen454d7c92008-11-12 23:37:49 -08001770 struct bonding *bond = netdev_priv(bond_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001771 struct sockaddr *sa = addr;
Veaceslav Falicob88ec382013-06-18 13:44:52 +02001772 struct slave *swap_slave;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001773 int res;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001774
1775 if (!is_valid_ether_addr(sa->sa_data)) {
1776 return -EADDRNOTAVAIL;
1777 }
1778
1779 res = alb_set_mac_address(bond, addr);
1780 if (res) {
1781 return res;
1782 }
1783
1784 memcpy(bond_dev->dev_addr, sa->sa_data, bond_dev->addr_len);
1785
1786 /* If there is no curr_active_slave there is nothing else to do.
1787 * Otherwise we'll need to pass the new address to it and handle
1788 * duplications.
1789 */
1790 if (!bond->curr_active_slave) {
1791 return 0;
1792 }
1793
Veaceslav Falicob88ec382013-06-18 13:44:52 +02001794 swap_slave = bond_slave_has_mac(bond, bond_dev->dev_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001795
1796 if (swap_slave) {
Veaceslav Falico43547ea2013-05-27 23:14:51 +00001797 alb_swap_mac_addr(swap_slave, bond->curr_active_slave);
Jay Vosburgh059fe7a2007-10-17 17:37:49 -07001798 alb_fasten_mac_swap(bond, swap_slave, bond->curr_active_slave);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001799 } else {
Jiri Bohacb9245512012-01-18 12:24:54 +00001800 alb_set_slave_mac_addr(bond->curr_active_slave, bond_dev->dev_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001801
Jay Vosburgh815bcc22009-05-04 09:03:37 +00001802 read_lock(&bond->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001803 alb_send_learning_packets(bond->curr_active_slave, bond_dev->dev_addr);
1804 if (bond->alb_info.rlb_enabled) {
1805 /* inform clients mac address has changed */
1806 rlb_req_update_slave_clients(bond, bond->curr_active_slave);
1807 }
Jay Vosburgh815bcc22009-05-04 09:03:37 +00001808 read_unlock(&bond->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001809 }
1810
Linus Torvalds1da177e2005-04-16 15:20:36 -07001811 return 0;
1812}
1813
1814void bond_alb_clear_vlan(struct bonding *bond, unsigned short vlan_id)
1815{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001816 if (bond->alb_info.rlb_enabled) {
1817 rlb_clear_vlan(bond, vlan_id);
1818 }
1819}
1820