Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 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 |
Jeff Kirsher | adf8d3f | 2013-12-06 06:28:47 -0800 | [diff] [blame] | 15 | * with this program; if not, see <http://www.gnu.org/licenses/>. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | * |
| 17 | * The full GNU General Public License is included in this distribution in the |
| 18 | * file called LICENSE. |
| 19 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | */ |
| 21 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | #include <linux/skbuff.h> |
| 23 | #include <linux/netdevice.h> |
| 24 | #include <linux/etherdevice.h> |
| 25 | #include <linux/pkt_sched.h> |
| 26 | #include <linux/spinlock.h> |
| 27 | #include <linux/slab.h> |
| 28 | #include <linux/timer.h> |
| 29 | #include <linux/ip.h> |
| 30 | #include <linux/ipv6.h> |
| 31 | #include <linux/if_arp.h> |
| 32 | #include <linux/if_ether.h> |
| 33 | #include <linux/if_bonding.h> |
| 34 | #include <linux/if_vlan.h> |
| 35 | #include <linux/in.h> |
| 36 | #include <net/ipx.h> |
| 37 | #include <net/arp.h> |
Vlad Yasevich | 2d1ea19 | 2008-08-28 15:38:41 -0400 | [diff] [blame] | 38 | #include <net/ipv6.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | #include <asm/byteorder.h> |
| 40 | #include "bonding.h" |
| 41 | #include "bond_alb.h" |
| 42 | |
| 43 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | |
Eric Dumazet | 885a136 | 2009-09-01 06:31:18 +0000 | [diff] [blame] | 45 | #ifndef __long_aligned |
| 46 | #define __long_aligned __attribute__((aligned((sizeof(long))))) |
| 47 | #endif |
| 48 | static const u8 mac_bcast[ETH_ALEN] __long_aligned = { |
| 49 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff |
| 50 | }; |
| 51 | static const u8 mac_v6_allmcast[ETH_ALEN] __long_aligned = { |
| 52 | 0x33, 0x33, 0x00, 0x00, 0x00, 0x01 |
| 53 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | static const int alb_delta_in_ticks = HZ / ALB_TIMER_TICKS_PER_SEC; |
| 55 | |
| 56 | #pragma pack(1) |
| 57 | struct learning_pkt { |
| 58 | u8 mac_dst[ETH_ALEN]; |
| 59 | u8 mac_src[ETH_ALEN]; |
Al Viro | d3bb52b | 2007-08-22 20:06:58 -0400 | [diff] [blame] | 60 | __be16 type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | u8 padding[ETH_ZLEN - ETH_HLEN]; |
| 62 | }; |
| 63 | |
| 64 | struct arp_pkt { |
Al Viro | d3bb52b | 2007-08-22 20:06:58 -0400 | [diff] [blame] | 65 | __be16 hw_addr_space; |
| 66 | __be16 prot_addr_space; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | u8 hw_addr_len; |
| 68 | u8 prot_addr_len; |
Al Viro | d3bb52b | 2007-08-22 20:06:58 -0400 | [diff] [blame] | 69 | __be16 op_code; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | u8 mac_src[ETH_ALEN]; /* sender hardware address */ |
Al Viro | d3bb52b | 2007-08-22 20:06:58 -0400 | [diff] [blame] | 71 | __be32 ip_src; /* sender IP address */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | u8 mac_dst[ETH_ALEN]; /* target hardware address */ |
Al Viro | d3bb52b | 2007-08-22 20:06:58 -0400 | [diff] [blame] | 73 | __be32 ip_dst; /* target IP address */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | }; |
| 75 | #pragma pack() |
| 76 | |
Arnaldo Carvalho de Melo | a16aeb3 | 2007-03-10 16:07:19 -0300 | [diff] [blame] | 77 | static inline struct arp_pkt *arp_pkt(const struct sk_buff *skb) |
| 78 | { |
Arnaldo Carvalho de Melo | d56f90a | 2007-04-10 20:50:43 -0700 | [diff] [blame] | 79 | return (struct arp_pkt *)skb_network_header(skb); |
Arnaldo Carvalho de Melo | a16aeb3 | 2007-03-10 16:07:19 -0300 | [diff] [blame] | 80 | } |
| 81 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | /* Forward declaration */ |
Vlad Yasevich | d0c21d4 | 2014-05-21 13:19:48 -0400 | [diff] [blame] | 83 | static void alb_send_learning_packets(struct slave *slave, u8 mac_addr[], |
| 84 | bool strict_match); |
Jiri Bohac | e53665c | 2012-11-28 04:42:14 +0000 | [diff] [blame] | 85 | static void rlb_purge_src_ip(struct bonding *bond, struct arp_pkt *arp); |
| 86 | static void rlb_src_unlink(struct bonding *bond, u32 index); |
| 87 | static void rlb_src_link(struct bonding *bond, u32 ip_src_hash, |
| 88 | u32 ip_dst_hash); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 90 | static inline u8 _simple_hash(const u8 *hash_start, int hash_size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | { |
| 92 | int i; |
| 93 | u8 hash = 0; |
| 94 | |
Wang Yufen | fdb89d7 | 2014-02-14 17:15:14 +0800 | [diff] [blame] | 95 | for (i = 0; i < hash_size; i++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | hash ^= hash_start[i]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | |
| 98 | return hash; |
| 99 | } |
| 100 | |
| 101 | /*********************** tlb specific functions ***************************/ |
| 102 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | static inline void tlb_init_table_entry(struct tlb_client_info *entry, int save_load) |
| 104 | { |
| 105 | if (save_load) { |
| 106 | entry->load_history = 1 + entry->tx_bytes / |
| 107 | BOND_TLB_REBALANCE_INTERVAL; |
| 108 | entry->tx_bytes = 0; |
| 109 | } |
| 110 | |
| 111 | entry->tx_slave = NULL; |
| 112 | entry->next = TLB_NULL_INDEX; |
| 113 | entry->prev = TLB_NULL_INDEX; |
| 114 | } |
| 115 | |
| 116 | static inline void tlb_init_slave(struct slave *slave) |
| 117 | { |
| 118 | SLAVE_TLB_INFO(slave).load = 0; |
| 119 | SLAVE_TLB_INFO(slave).head = TLB_NULL_INDEX; |
| 120 | } |
| 121 | |
Maxim Uvarov | f515e6b | 2012-01-09 12:01:37 +0000 | [diff] [blame] | 122 | static void __tlb_clear_slave(struct bonding *bond, struct slave *slave, |
| 123 | int save_load) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | { |
| 125 | struct tlb_client_info *tx_hash_table; |
| 126 | u32 index; |
| 127 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | /* clear slave from tx_hashtbl */ |
| 129 | tx_hash_table = BOND_ALB_INFO(bond).tx_hashtbl; |
| 130 | |
Andy Gospodarek | ce39a80 | 2008-10-30 17:41:16 -0700 | [diff] [blame] | 131 | /* skip this if we've already freed the tx hash table */ |
| 132 | if (tx_hash_table) { |
| 133 | index = SLAVE_TLB_INFO(slave).head; |
| 134 | while (index != TLB_NULL_INDEX) { |
| 135 | u32 next_index = tx_hash_table[index].next; |
| 136 | tlb_init_table_entry(&tx_hash_table[index], save_load); |
| 137 | index = next_index; |
| 138 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | } |
| 140 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | tlb_init_slave(slave); |
Maxim Uvarov | f515e6b | 2012-01-09 12:01:37 +0000 | [diff] [blame] | 142 | } |
Jay Vosburgh | 5af47b2 | 2006-01-09 12:14:00 -0800 | [diff] [blame] | 143 | |
Maxim Uvarov | f515e6b | 2012-01-09 12:01:37 +0000 | [diff] [blame] | 144 | static void tlb_clear_slave(struct bonding *bond, struct slave *slave, |
| 145 | int save_load) |
| 146 | { |
Nikolay Aleksandrov | 4bab16d | 2014-09-11 22:49:26 +0200 | [diff] [blame] | 147 | spin_lock_bh(&bond->mode_lock); |
Maxim Uvarov | f515e6b | 2012-01-09 12:01:37 +0000 | [diff] [blame] | 148 | __tlb_clear_slave(bond, slave, save_load); |
Nikolay Aleksandrov | 4bab16d | 2014-09-11 22:49:26 +0200 | [diff] [blame] | 149 | spin_unlock_bh(&bond->mode_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | } |
| 151 | |
| 152 | /* Must be called before starting the monitor timer */ |
| 153 | static int tlb_initialize(struct bonding *bond) |
| 154 | { |
| 155 | struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond)); |
| 156 | int size = TLB_HASH_TABLE_SIZE * sizeof(struct tlb_client_info); |
Mitch Williams | 0d206a3 | 2005-11-09 10:35:30 -0800 | [diff] [blame] | 157 | struct tlb_client_info *new_hashtbl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | int i; |
| 159 | |
Joe Jin | 243cb4e | 2007-02-06 14:16:40 -0800 | [diff] [blame] | 160 | new_hashtbl = kzalloc(size, GFP_KERNEL); |
Joe Perches | e404dec | 2012-01-29 12:56:23 +0000 | [diff] [blame] | 161 | if (!new_hashtbl) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | return -1; |
Joe Perches | e404dec | 2012-01-29 12:56:23 +0000 | [diff] [blame] | 163 | |
Nikolay Aleksandrov | 4bab16d | 2014-09-11 22:49:26 +0200 | [diff] [blame] | 164 | spin_lock_bh(&bond->mode_lock); |
Mitch Williams | 0d206a3 | 2005-11-09 10:35:30 -0800 | [diff] [blame] | 165 | |
| 166 | bond_info->tx_hashtbl = new_hashtbl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | |
Wang Yufen | fdb89d7 | 2014-02-14 17:15:14 +0800 | [diff] [blame] | 168 | for (i = 0; i < TLB_HASH_TABLE_SIZE; i++) |
Peter Pan(潘卫平) | 38dbaf0 | 2011-04-08 03:40:19 +0000 | [diff] [blame] | 169 | tlb_init_table_entry(&bond_info->tx_hashtbl[i], 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | |
Nikolay Aleksandrov | 4bab16d | 2014-09-11 22:49:26 +0200 | [diff] [blame] | 171 | spin_unlock_bh(&bond->mode_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | |
| 173 | return 0; |
| 174 | } |
| 175 | |
| 176 | /* Must be called only after all slaves have been released */ |
| 177 | static void tlb_deinitialize(struct bonding *bond) |
| 178 | { |
| 179 | struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond)); |
Mahesh Bandewar | 6b794c1 | 2014-07-16 11:10:36 -0700 | [diff] [blame] | 180 | struct tlb_up_slave *arr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | |
Nikolay Aleksandrov | 4bab16d | 2014-09-11 22:49:26 +0200 | [diff] [blame] | 182 | spin_lock_bh(&bond->mode_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | |
| 184 | kfree(bond_info->tx_hashtbl); |
| 185 | bond_info->tx_hashtbl = NULL; |
| 186 | |
Nikolay Aleksandrov | 4bab16d | 2014-09-11 22:49:26 +0200 | [diff] [blame] | 187 | spin_unlock_bh(&bond->mode_lock); |
Mahesh Bandewar | 6b794c1 | 2014-07-16 11:10:36 -0700 | [diff] [blame] | 188 | |
| 189 | arr = rtnl_dereference(bond_info->slave_arr); |
| 190 | if (arr) |
| 191 | kfree_rcu(arr, rcu); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | } |
| 193 | |
Jiri Pirko | 097811b | 2010-05-19 03:26:39 +0000 | [diff] [blame] | 194 | static long long compute_gap(struct slave *slave) |
| 195 | { |
| 196 | return (s64) (slave->speed << 20) - /* Convert to Megabit per sec */ |
| 197 | (s64) (SLAVE_TLB_INFO(slave).load << 3); /* Bytes to bits */ |
| 198 | } |
| 199 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | static struct slave *tlb_get_least_loaded_slave(struct bonding *bond) |
| 201 | { |
| 202 | struct slave *slave, *least_loaded; |
Veaceslav Falico | 9caff1e7 | 2013-09-25 09:20:14 +0200 | [diff] [blame] | 203 | struct list_head *iter; |
Jiri Pirko | 097811b | 2010-05-19 03:26:39 +0000 | [diff] [blame] | 204 | long long max_gap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | |
Jiri Pirko | 097811b | 2010-05-19 03:26:39 +0000 | [diff] [blame] | 206 | least_loaded = NULL; |
| 207 | max_gap = LLONG_MIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | |
| 209 | /* Find the slave with the largest gap */ |
dingtianhong | 28c7192 | 2013-10-15 16:28:39 +0800 | [diff] [blame] | 210 | bond_for_each_slave_rcu(bond, slave, iter) { |
Veaceslav Falico | 8557cd7 | 2014-05-15 21:39:59 +0200 | [diff] [blame] | 211 | if (bond_slave_can_tx(slave)) { |
Jiri Pirko | 097811b | 2010-05-19 03:26:39 +0000 | [diff] [blame] | 212 | long long gap = compute_gap(slave); |
| 213 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | if (max_gap < gap) { |
| 215 | least_loaded = slave; |
| 216 | max_gap = gap; |
| 217 | } |
| 218 | } |
| 219 | } |
| 220 | |
| 221 | return least_loaded; |
| 222 | } |
| 223 | |
Maxim Uvarov | f515e6b | 2012-01-09 12:01:37 +0000 | [diff] [blame] | 224 | static struct slave *__tlb_choose_channel(struct bonding *bond, u32 hash_index, |
| 225 | u32 skb_len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | { |
| 227 | struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond)); |
| 228 | struct tlb_client_info *hash_table; |
| 229 | struct slave *assigned_slave; |
| 230 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | hash_table = bond_info->tx_hashtbl; |
| 232 | assigned_slave = hash_table[hash_index].tx_slave; |
| 233 | if (!assigned_slave) { |
| 234 | assigned_slave = tlb_get_least_loaded_slave(bond); |
| 235 | |
| 236 | if (assigned_slave) { |
| 237 | struct tlb_slave_info *slave_info = |
| 238 | &(SLAVE_TLB_INFO(assigned_slave)); |
| 239 | u32 next_index = slave_info->head; |
| 240 | |
| 241 | hash_table[hash_index].tx_slave = assigned_slave; |
| 242 | hash_table[hash_index].next = next_index; |
| 243 | hash_table[hash_index].prev = TLB_NULL_INDEX; |
| 244 | |
Wang Yufen | fdb89d7 | 2014-02-14 17:15:14 +0800 | [diff] [blame] | 245 | if (next_index != TLB_NULL_INDEX) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | hash_table[next_index].prev = hash_index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | |
| 248 | slave_info->head = hash_index; |
| 249 | slave_info->load += |
| 250 | hash_table[hash_index].load_history; |
| 251 | } |
| 252 | } |
| 253 | |
Wang Yufen | fdb89d7 | 2014-02-14 17:15:14 +0800 | [diff] [blame] | 254 | if (assigned_slave) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | hash_table[hash_index].tx_bytes += skb_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | return assigned_slave; |
| 258 | } |
| 259 | |
Maxim Uvarov | f515e6b | 2012-01-09 12:01:37 +0000 | [diff] [blame] | 260 | static struct slave *tlb_choose_channel(struct bonding *bond, u32 hash_index, |
| 261 | u32 skb_len) |
| 262 | { |
| 263 | struct slave *tx_slave; |
Nikolay Aleksandrov | 547942c | 2014-09-15 17:19:34 +0200 | [diff] [blame^] | 264 | |
| 265 | /* We don't need to disable softirq here, becase |
Maxim Uvarov | f515e6b | 2012-01-09 12:01:37 +0000 | [diff] [blame] | 266 | * tlb_choose_channel() is only called by bond_alb_xmit() |
| 267 | * which already has softirq disabled. |
| 268 | */ |
Nikolay Aleksandrov | 4bab16d | 2014-09-11 22:49:26 +0200 | [diff] [blame] | 269 | spin_lock(&bond->mode_lock); |
Maxim Uvarov | f515e6b | 2012-01-09 12:01:37 +0000 | [diff] [blame] | 270 | tx_slave = __tlb_choose_channel(bond, hash_index, skb_len); |
Nikolay Aleksandrov | 4bab16d | 2014-09-11 22:49:26 +0200 | [diff] [blame] | 271 | spin_unlock(&bond->mode_lock); |
Nikolay Aleksandrov | 547942c | 2014-09-15 17:19:34 +0200 | [diff] [blame^] | 272 | |
Maxim Uvarov | f515e6b | 2012-01-09 12:01:37 +0000 | [diff] [blame] | 273 | return tx_slave; |
| 274 | } |
| 275 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | /*********************** rlb specific functions ***************************/ |
Maxim Uvarov | f515e6b | 2012-01-09 12:01:37 +0000 | [diff] [blame] | 277 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | /* when an ARP REPLY is received from a client update its info |
| 279 | * in the rx_hashtbl |
| 280 | */ |
| 281 | static void rlb_update_entry_from_arp(struct bonding *bond, struct arp_pkt *arp) |
| 282 | { |
| 283 | struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond)); |
| 284 | struct rlb_client_info *client_info; |
| 285 | u32 hash_index; |
| 286 | |
Nikolay Aleksandrov | 4bab16d | 2014-09-11 22:49:26 +0200 | [diff] [blame] | 287 | spin_lock_bh(&bond->mode_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | |
Wang Yufen | b85b6fb | 2014-02-14 17:15:12 +0800 | [diff] [blame] | 289 | hash_index = _simple_hash((u8 *)&(arp->ip_src), sizeof(arp->ip_src)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | client_info = &(bond_info->rx_hashtbl[hash_index]); |
| 291 | |
| 292 | if ((client_info->assigned) && |
| 293 | (client_info->ip_src == arp->ip_dst) && |
Flavio Leitner | 42d782a | 2010-06-29 08:24:39 +0000 | [diff] [blame] | 294 | (client_info->ip_dst == arp->ip_src) && |
Joe Perches | a6700db | 2012-05-09 17:04:04 +0000 | [diff] [blame] | 295 | (!ether_addr_equal_64bits(client_info->mac_dst, arp->mac_src))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | /* update the clients MAC address */ |
Joe Perches | ada0f86 | 2014-02-15 16:02:17 -0800 | [diff] [blame] | 297 | ether_addr_copy(client_info->mac_dst, arp->mac_src); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | client_info->ntt = 1; |
| 299 | bond_info->rx_ntt = 1; |
| 300 | } |
| 301 | |
Nikolay Aleksandrov | 4bab16d | 2014-09-11 22:49:26 +0200 | [diff] [blame] | 302 | spin_unlock_bh(&bond->mode_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | } |
| 304 | |
Eric Dumazet | de063b7 | 2012-06-11 19:23:07 +0000 | [diff] [blame] | 305 | static int rlb_arp_recv(const struct sk_buff *skb, struct bonding *bond, |
| 306 | struct slave *slave) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | { |
Eric Dumazet | de063b7 | 2012-06-11 19:23:07 +0000 | [diff] [blame] | 308 | struct arp_pkt *arp, _arp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | |
Jiri Pirko | 3aba891 | 2011-04-19 03:48:16 +0000 | [diff] [blame] | 310 | if (skb->protocol != cpu_to_be16(ETH_P_ARP)) |
David S. Miller | b99215c | 2012-05-13 15:45:13 -0400 | [diff] [blame] | 311 | goto out; |
Jay Vosburgh | 6146b1a | 2008-11-04 17:51:15 -0800 | [diff] [blame] | 312 | |
Eric Dumazet | de063b7 | 2012-06-11 19:23:07 +0000 | [diff] [blame] | 313 | arp = skb_header_pointer(skb, 0, sizeof(_arp), &_arp); |
| 314 | if (!arp) |
David S. Miller | b99215c | 2012-05-13 15:45:13 -0400 | [diff] [blame] | 315 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | |
Jiri Bohac | e53665c | 2012-11-28 04:42:14 +0000 | [diff] [blame] | 317 | /* We received an ARP from arp->ip_src. |
| 318 | * We might have used this IP address previously (on the bonding host |
| 319 | * itself or on a system that is bridged together with the bond). |
| 320 | * However, if arp->mac_src is different than what is stored in |
| 321 | * rx_hashtbl, some other host is now using the IP and we must prevent |
| 322 | * sending out client updates with this IP address and the old MAC |
| 323 | * address. |
| 324 | * Clean up all hash table entries that have this address as ip_src but |
| 325 | * have a different mac_src. |
| 326 | */ |
| 327 | rlb_purge_src_ip(bond, arp); |
| 328 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | if (arp->op_code == htons(ARPOP_REPLY)) { |
| 330 | /* update rx hash table for this ARP */ |
| 331 | rlb_update_entry_from_arp(bond, arp); |
Veaceslav Falico | 0a111a0 | 2014-07-15 19:36:02 +0200 | [diff] [blame] | 332 | netdev_dbg(bond->dev, "Server received an ARP Reply from client\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 | } |
David S. Miller | b99215c | 2012-05-13 15:45:13 -0400 | [diff] [blame] | 334 | out: |
| 335 | return RX_HANDLER_ANOTHER; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | } |
| 337 | |
Nikolay Aleksandrov | 8c0bc55 | 2014-09-11 22:49:28 +0200 | [diff] [blame] | 338 | /* Caller must hold rcu_read_lock() */ |
dingtianhong | 28c7192 | 2013-10-15 16:28:39 +0800 | [diff] [blame] | 339 | static struct slave *__rlb_next_rx_slave(struct bonding *bond) |
| 340 | { |
| 341 | struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond)); |
| 342 | struct slave *before = NULL, *rx_slave = NULL, *slave; |
| 343 | struct list_head *iter; |
| 344 | bool found = false; |
| 345 | |
| 346 | bond_for_each_slave_rcu(bond, slave, iter) { |
Veaceslav Falico | 8557cd7 | 2014-05-15 21:39:59 +0200 | [diff] [blame] | 347 | if (!bond_slave_can_tx(slave)) |
dingtianhong | 28c7192 | 2013-10-15 16:28:39 +0800 | [diff] [blame] | 348 | continue; |
| 349 | if (!found) { |
| 350 | if (!before || before->speed < slave->speed) |
| 351 | before = slave; |
| 352 | } else { |
| 353 | if (!rx_slave || rx_slave->speed < slave->speed) |
| 354 | rx_slave = slave; |
| 355 | } |
| 356 | if (slave == bond_info->rx_slave) |
| 357 | found = true; |
| 358 | } |
| 359 | /* we didn't find anything after the current or we have something |
| 360 | * better before and up to the current slave |
| 361 | */ |
| 362 | if (!rx_slave || (before && rx_slave->speed < before->speed)) |
| 363 | rx_slave = before; |
| 364 | |
| 365 | if (rx_slave) |
| 366 | bond_info->rx_slave = rx_slave; |
| 367 | |
| 368 | return rx_slave; |
| 369 | } |
| 370 | |
Nikolay Aleksandrov | 56924c3 | 2014-09-15 17:19:33 +0200 | [diff] [blame] | 371 | /* Caller must hold RTNL, rcu_read_lock is obtained only to silence checkers */ |
| 372 | static struct slave *rlb_next_rx_slave(struct bonding *bond) |
| 373 | { |
| 374 | struct slave *rx_slave; |
| 375 | |
| 376 | ASSERT_RTNL(); |
| 377 | |
| 378 | rcu_read_lock(); |
| 379 | rx_slave = __rlb_next_rx_slave(bond); |
| 380 | rcu_read_unlock(); |
| 381 | |
| 382 | return rx_slave; |
| 383 | } |
| 384 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | /* teach the switch the mac of a disabled slave |
| 386 | * on the primary for fault tolerance |
| 387 | * |
Nikolay Aleksandrov | 62c5f51 | 2014-09-11 22:49:23 +0200 | [diff] [blame] | 388 | * Caller must hold RTNL |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | */ |
| 390 | static void rlb_teach_disabled_mac_on_primary(struct bonding *bond, u8 addr[]) |
| 391 | { |
Nikolay Aleksandrov | 1c72cfdc9 | 2014-09-11 22:49:24 +0200 | [diff] [blame] | 392 | struct slave *curr_active = rtnl_dereference(bond->curr_active_slave); |
Eric Dumazet | 4740d63 | 2014-07-15 06:56:55 -0700 | [diff] [blame] | 393 | |
| 394 | if (!curr_active) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | |
| 397 | if (!bond->alb_info.primary_is_promisc) { |
Eric Dumazet | 4740d63 | 2014-07-15 06:56:55 -0700 | [diff] [blame] | 398 | if (!dev_set_promiscuity(curr_active->dev, 1)) |
Wang Chen | 7e1a1ac | 2008-07-14 20:51:36 -0700 | [diff] [blame] | 399 | bond->alb_info.primary_is_promisc = 1; |
| 400 | else |
| 401 | bond->alb_info.primary_is_promisc = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | } |
| 403 | |
| 404 | bond->alb_info.rlb_promisc_timeout_counter = 0; |
| 405 | |
Eric Dumazet | 4740d63 | 2014-07-15 06:56:55 -0700 | [diff] [blame] | 406 | alb_send_learning_packets(curr_active, addr, true); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | } |
| 408 | |
| 409 | /* slave being removed should not be active at this point |
| 410 | * |
dingtianhong | b2e7ace | 2013-12-13 10:19:32 +0800 | [diff] [blame] | 411 | * Caller must hold rtnl. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | */ |
| 413 | static void rlb_clear_slave(struct bonding *bond, struct slave *slave) |
| 414 | { |
| 415 | struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond)); |
| 416 | struct rlb_client_info *rx_hash_table; |
| 417 | u32 index, next_index; |
| 418 | |
| 419 | /* clear slave from rx_hashtbl */ |
Nikolay Aleksandrov | 4bab16d | 2014-09-11 22:49:26 +0200 | [diff] [blame] | 420 | spin_lock_bh(&bond->mode_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | |
| 422 | rx_hash_table = bond_info->rx_hashtbl; |
Jiri Bohac | e53665c | 2012-11-28 04:42:14 +0000 | [diff] [blame] | 423 | index = bond_info->rx_hashtbl_used_head; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 424 | for (; index != RLB_NULL_INDEX; index = next_index) { |
Jiri Bohac | e53665c | 2012-11-28 04:42:14 +0000 | [diff] [blame] | 425 | next_index = rx_hash_table[index].used_next; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | if (rx_hash_table[index].slave == slave) { |
| 427 | struct slave *assigned_slave = rlb_next_rx_slave(bond); |
| 428 | |
| 429 | if (assigned_slave) { |
| 430 | rx_hash_table[index].slave = assigned_slave; |
Joe Perches | a6700db | 2012-05-09 17:04:04 +0000 | [diff] [blame] | 431 | if (!ether_addr_equal_64bits(rx_hash_table[index].mac_dst, |
| 432 | mac_bcast)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | bond_info->rx_hashtbl[index].ntt = 1; |
| 434 | bond_info->rx_ntt = 1; |
| 435 | /* A slave has been removed from the |
| 436 | * table because it is either disabled |
| 437 | * or being released. We must retry the |
| 438 | * update to avoid clients from not |
| 439 | * being updated & disconnecting when |
| 440 | * there is stress |
| 441 | */ |
| 442 | bond_info->rlb_update_retry_counter = |
| 443 | RLB_UPDATE_RETRY; |
| 444 | } |
| 445 | } else { /* there is no active slave */ |
| 446 | rx_hash_table[index].slave = NULL; |
| 447 | } |
| 448 | } |
| 449 | } |
| 450 | |
Nikolay Aleksandrov | 4bab16d | 2014-09-11 22:49:26 +0200 | [diff] [blame] | 451 | spin_unlock_bh(&bond->mode_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 452 | |
Nikolay Aleksandrov | 1c72cfdc9 | 2014-09-11 22:49:24 +0200 | [diff] [blame] | 453 | if (slave != rtnl_dereference(bond->curr_active_slave)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 454 | rlb_teach_disabled_mac_on_primary(bond, slave->dev->dev_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | } |
| 456 | |
| 457 | static void rlb_update_client(struct rlb_client_info *client_info) |
| 458 | { |
| 459 | int i; |
| 460 | |
Wang Yufen | 35d75ee | 2014-02-14 17:15:15 +0800 | [diff] [blame] | 461 | if (!client_info->slave) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 462 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 463 | |
| 464 | for (i = 0; i < RLB_ARP_BURST_SIZE; i++) { |
| 465 | struct sk_buff *skb; |
| 466 | |
| 467 | skb = arp_create(ARPOP_REPLY, ETH_P_ARP, |
| 468 | client_info->ip_dst, |
| 469 | client_info->slave->dev, |
| 470 | client_info->ip_src, |
| 471 | client_info->mac_dst, |
| 472 | client_info->slave->dev->dev_addr, |
| 473 | client_info->mac_dst); |
| 474 | if (!skb) { |
Veaceslav Falico | 0a111a0 | 2014-07-15 19:36:02 +0200 | [diff] [blame] | 475 | netdev_err(client_info->slave->bond->dev, |
| 476 | "failed to create an ARP packet\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 477 | continue; |
| 478 | } |
| 479 | |
| 480 | skb->dev = client_info->slave->dev; |
| 481 | |
Veaceslav Falico | d3ab3ff | 2013-08-29 23:38:57 +0200 | [diff] [blame] | 482 | if (client_info->vlan_id) { |
Patrick McHardy | 86a9bad | 2013-04-19 02:04:30 +0000 | [diff] [blame] | 483 | skb = vlan_put_tag(skb, htons(ETH_P_8021Q), client_info->vlan_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | if (!skb) { |
Veaceslav Falico | 0a111a0 | 2014-07-15 19:36:02 +0200 | [diff] [blame] | 485 | netdev_err(client_info->slave->bond->dev, |
| 486 | "failed to insert VLAN tag\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 487 | continue; |
| 488 | } |
| 489 | } |
| 490 | |
| 491 | arp_xmit(skb); |
| 492 | } |
| 493 | } |
| 494 | |
| 495 | /* sends ARP REPLIES that update the clients that need updating */ |
| 496 | static void rlb_update_rx_clients(struct bonding *bond) |
| 497 | { |
| 498 | struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond)); |
| 499 | struct rlb_client_info *client_info; |
| 500 | u32 hash_index; |
| 501 | |
Nikolay Aleksandrov | 4bab16d | 2014-09-11 22:49:26 +0200 | [diff] [blame] | 502 | spin_lock_bh(&bond->mode_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | |
Jiri Bohac | e53665c | 2012-11-28 04:42:14 +0000 | [diff] [blame] | 504 | hash_index = bond_info->rx_hashtbl_used_head; |
| 505 | for (; hash_index != RLB_NULL_INDEX; |
| 506 | hash_index = client_info->used_next) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 507 | client_info = &(bond_info->rx_hashtbl[hash_index]); |
| 508 | if (client_info->ntt) { |
| 509 | rlb_update_client(client_info); |
Wang Yufen | 35d75ee | 2014-02-14 17:15:15 +0800 | [diff] [blame] | 510 | if (bond_info->rlb_update_retry_counter == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 511 | client_info->ntt = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 512 | } |
| 513 | } |
| 514 | |
Thadeu Lima de Souza Cascardo | 94e2bd6 | 2009-10-16 15:20:49 +0200 | [diff] [blame] | 515 | /* do not update the entries again until this counter is zero so that |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 | * not to confuse the clients. |
| 517 | */ |
| 518 | bond_info->rlb_update_delay_counter = RLB_UPDATE_DELAY; |
| 519 | |
Nikolay Aleksandrov | 4bab16d | 2014-09-11 22:49:26 +0200 | [diff] [blame] | 520 | spin_unlock_bh(&bond->mode_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 521 | } |
| 522 | |
| 523 | /* The slave was assigned a new mac address - update the clients */ |
| 524 | static void rlb_req_update_slave_clients(struct bonding *bond, struct slave *slave) |
| 525 | { |
| 526 | struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond)); |
| 527 | struct rlb_client_info *client_info; |
| 528 | int ntt = 0; |
| 529 | u32 hash_index; |
| 530 | |
Nikolay Aleksandrov | 4bab16d | 2014-09-11 22:49:26 +0200 | [diff] [blame] | 531 | spin_lock_bh(&bond->mode_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 532 | |
Jiri Bohac | e53665c | 2012-11-28 04:42:14 +0000 | [diff] [blame] | 533 | hash_index = bond_info->rx_hashtbl_used_head; |
| 534 | for (; hash_index != RLB_NULL_INDEX; |
| 535 | hash_index = client_info->used_next) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 536 | client_info = &(bond_info->rx_hashtbl[hash_index]); |
| 537 | |
| 538 | if ((client_info->slave == slave) && |
Joe Perches | a6700db | 2012-05-09 17:04:04 +0000 | [diff] [blame] | 539 | !ether_addr_equal_64bits(client_info->mac_dst, mac_bcast)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 540 | client_info->ntt = 1; |
| 541 | ntt = 1; |
| 542 | } |
| 543 | } |
| 544 | |
Wang Yufen | 4708a1b | 2014-02-14 17:15:13 +0800 | [diff] [blame] | 545 | /* update the team's flag only after the whole iteration */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 546 | if (ntt) { |
| 547 | bond_info->rx_ntt = 1; |
Wang Yufen | 4708a1b | 2014-02-14 17:15:13 +0800 | [diff] [blame] | 548 | /* fasten the change */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 549 | bond_info->rlb_update_retry_counter = RLB_UPDATE_RETRY; |
| 550 | } |
| 551 | |
Nikolay Aleksandrov | 4bab16d | 2014-09-11 22:49:26 +0200 | [diff] [blame] | 552 | spin_unlock_bh(&bond->mode_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 553 | } |
| 554 | |
| 555 | /* mark all clients using src_ip to be updated */ |
Al Viro | d3bb52b | 2007-08-22 20:06:58 -0400 | [diff] [blame] | 556 | static void rlb_req_update_subnet_clients(struct bonding *bond, __be32 src_ip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 557 | { |
| 558 | struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond)); |
| 559 | struct rlb_client_info *client_info; |
| 560 | u32 hash_index; |
| 561 | |
Nikolay Aleksandrov | 4bab16d | 2014-09-11 22:49:26 +0200 | [diff] [blame] | 562 | spin_lock(&bond->mode_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 563 | |
Jiri Bohac | e53665c | 2012-11-28 04:42:14 +0000 | [diff] [blame] | 564 | hash_index = bond_info->rx_hashtbl_used_head; |
| 565 | for (; hash_index != RLB_NULL_INDEX; |
| 566 | hash_index = client_info->used_next) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 567 | client_info = &(bond_info->rx_hashtbl[hash_index]); |
| 568 | |
| 569 | if (!client_info->slave) { |
Veaceslav Falico | 0a111a0 | 2014-07-15 19:36:02 +0200 | [diff] [blame] | 570 | netdev_err(bond->dev, "found a client with no channel in the client's hash table\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 571 | continue; |
| 572 | } |
Nikolay Aleksandrov | 547942c | 2014-09-15 17:19:34 +0200 | [diff] [blame^] | 573 | /* update all clients using this src_ip, that are not assigned |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 574 | * to the team's address (curr_active_slave) and have a known |
| 575 | * unicast mac address. |
| 576 | */ |
| 577 | if ((client_info->ip_src == src_ip) && |
Joe Perches | a6700db | 2012-05-09 17:04:04 +0000 | [diff] [blame] | 578 | !ether_addr_equal_64bits(client_info->slave->dev->dev_addr, |
| 579 | bond->dev->dev_addr) && |
| 580 | !ether_addr_equal_64bits(client_info->mac_dst, mac_bcast)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 581 | client_info->ntt = 1; |
| 582 | bond_info->rx_ntt = 1; |
| 583 | } |
| 584 | } |
| 585 | |
Nikolay Aleksandrov | 4bab16d | 2014-09-11 22:49:26 +0200 | [diff] [blame] | 586 | spin_unlock(&bond->mode_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 587 | } |
| 588 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 589 | static struct slave *rlb_choose_channel(struct sk_buff *skb, struct bonding *bond) |
| 590 | { |
| 591 | struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond)); |
Arnaldo Carvalho de Melo | a16aeb3 | 2007-03-10 16:07:19 -0300 | [diff] [blame] | 592 | struct arp_pkt *arp = arp_pkt(skb); |
dingtianhong | 28c7192 | 2013-10-15 16:28:39 +0800 | [diff] [blame] | 593 | struct slave *assigned_slave, *curr_active_slave; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 594 | struct rlb_client_info *client_info; |
| 595 | u32 hash_index = 0; |
| 596 | |
Nikolay Aleksandrov | 4bab16d | 2014-09-11 22:49:26 +0200 | [diff] [blame] | 597 | spin_lock(&bond->mode_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 598 | |
dingtianhong | 28c7192 | 2013-10-15 16:28:39 +0800 | [diff] [blame] | 599 | curr_active_slave = rcu_dereference(bond->curr_active_slave); |
| 600 | |
Amerigo Wang | e364a34 | 2011-02-27 23:34:28 +0000 | [diff] [blame] | 601 | hash_index = _simple_hash((u8 *)&arp->ip_dst, sizeof(arp->ip_dst)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 602 | client_info = &(bond_info->rx_hashtbl[hash_index]); |
| 603 | |
| 604 | if (client_info->assigned) { |
| 605 | if ((client_info->ip_src == arp->ip_src) && |
| 606 | (client_info->ip_dst == arp->ip_dst)) { |
| 607 | /* the entry is already assigned to this client */ |
Joe Perches | a6700db | 2012-05-09 17:04:04 +0000 | [diff] [blame] | 608 | if (!ether_addr_equal_64bits(arp->mac_dst, mac_bcast)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 609 | /* update mac address from arp */ |
Joe Perches | ada0f86 | 2014-02-15 16:02:17 -0800 | [diff] [blame] | 610 | ether_addr_copy(client_info->mac_dst, arp->mac_dst); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 611 | } |
Joe Perches | ada0f86 | 2014-02-15 16:02:17 -0800 | [diff] [blame] | 612 | ether_addr_copy(client_info->mac_src, arp->mac_src); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 613 | |
| 614 | assigned_slave = client_info->slave; |
| 615 | if (assigned_slave) { |
Nikolay Aleksandrov | 4bab16d | 2014-09-11 22:49:26 +0200 | [diff] [blame] | 616 | spin_unlock(&bond->mode_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 617 | return assigned_slave; |
| 618 | } |
| 619 | } else { |
| 620 | /* the entry is already assigned to some other client, |
| 621 | * move the old client to primary (curr_active_slave) so |
| 622 | * that the new client can be assigned to this entry. |
| 623 | */ |
Eric Dumazet | 4740d63 | 2014-07-15 06:56:55 -0700 | [diff] [blame] | 624 | if (curr_active_slave && |
dingtianhong | 28c7192 | 2013-10-15 16:28:39 +0800 | [diff] [blame] | 625 | client_info->slave != curr_active_slave) { |
| 626 | client_info->slave = curr_active_slave; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 627 | rlb_update_client(client_info); |
| 628 | } |
| 629 | } |
| 630 | } |
| 631 | /* assign a new slave */ |
dingtianhong | 28c7192 | 2013-10-15 16:28:39 +0800 | [diff] [blame] | 632 | assigned_slave = __rlb_next_rx_slave(bond); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 633 | |
| 634 | if (assigned_slave) { |
Jiri Bohac | e53665c | 2012-11-28 04:42:14 +0000 | [diff] [blame] | 635 | if (!(client_info->assigned && |
| 636 | client_info->ip_src == arp->ip_src)) { |
| 637 | /* ip_src is going to be updated, |
| 638 | * fix the src hash list |
| 639 | */ |
| 640 | u32 hash_src = _simple_hash((u8 *)&arp->ip_src, |
| 641 | sizeof(arp->ip_src)); |
| 642 | rlb_src_unlink(bond, hash_index); |
| 643 | rlb_src_link(bond, hash_src, hash_index); |
| 644 | } |
| 645 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 646 | client_info->ip_src = arp->ip_src; |
| 647 | client_info->ip_dst = arp->ip_dst; |
| 648 | /* arp->mac_dst is broadcast for arp reqeusts. |
| 649 | * will be updated with clients actual unicast mac address |
| 650 | * upon receiving an arp reply. |
| 651 | */ |
Joe Perches | ada0f86 | 2014-02-15 16:02:17 -0800 | [diff] [blame] | 652 | ether_addr_copy(client_info->mac_dst, arp->mac_dst); |
| 653 | ether_addr_copy(client_info->mac_src, arp->mac_src); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 654 | client_info->slave = assigned_slave; |
| 655 | |
Joe Perches | a6700db | 2012-05-09 17:04:04 +0000 | [diff] [blame] | 656 | if (!ether_addr_equal_64bits(client_info->mac_dst, mac_bcast)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 657 | client_info->ntt = 1; |
| 658 | bond->alb_info.rx_ntt = 1; |
| 659 | } else { |
| 660 | client_info->ntt = 0; |
| 661 | } |
| 662 | |
dingtianhong | fb00bc2 | 2014-03-12 17:31:59 +0800 | [diff] [blame] | 663 | if (vlan_get_tag(skb, &client_info->vlan_id)) |
Veaceslav Falico | d3ab3ff | 2013-08-29 23:38:57 +0200 | [diff] [blame] | 664 | client_info->vlan_id = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 665 | |
| 666 | if (!client_info->assigned) { |
Jiri Bohac | e53665c | 2012-11-28 04:42:14 +0000 | [diff] [blame] | 667 | u32 prev_tbl_head = bond_info->rx_hashtbl_used_head; |
| 668 | bond_info->rx_hashtbl_used_head = hash_index; |
| 669 | client_info->used_next = prev_tbl_head; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 670 | if (prev_tbl_head != RLB_NULL_INDEX) { |
Jiri Bohac | e53665c | 2012-11-28 04:42:14 +0000 | [diff] [blame] | 671 | bond_info->rx_hashtbl[prev_tbl_head].used_prev = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 672 | hash_index; |
| 673 | } |
| 674 | client_info->assigned = 1; |
| 675 | } |
| 676 | } |
| 677 | |
Nikolay Aleksandrov | 4bab16d | 2014-09-11 22:49:26 +0200 | [diff] [blame] | 678 | spin_unlock(&bond->mode_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 679 | |
| 680 | return assigned_slave; |
| 681 | } |
| 682 | |
| 683 | /* chooses (and returns) transmit channel for arp reply |
| 684 | * does not choose channel for other arp types since they are |
| 685 | * sent on the curr_active_slave |
| 686 | */ |
| 687 | static struct slave *rlb_arp_xmit(struct sk_buff *skb, struct bonding *bond) |
| 688 | { |
Arnaldo Carvalho de Melo | a16aeb3 | 2007-03-10 16:07:19 -0300 | [diff] [blame] | 689 | struct arp_pkt *arp = arp_pkt(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 690 | struct slave *tx_slave = NULL; |
| 691 | |
zheng.li | 567b871 | 2012-11-27 23:57:04 +0000 | [diff] [blame] | 692 | /* Don't modify or load balance ARPs that do not originate locally |
| 693 | * (e.g.,arrive via a bridge). |
| 694 | */ |
Vlad Yasevich | 14af996 | 2014-06-04 16:23:38 -0400 | [diff] [blame] | 695 | if (!bond_slave_has_mac_rx(bond, arp->mac_src)) |
zheng.li | 567b871 | 2012-11-27 23:57:04 +0000 | [diff] [blame] | 696 | return NULL; |
| 697 | |
Brian Haley | f14c4e4 | 2008-09-02 10:08:08 -0400 | [diff] [blame] | 698 | if (arp->op_code == htons(ARPOP_REPLY)) { |
Nikolay Aleksandrov | 547942c | 2014-09-15 17:19:34 +0200 | [diff] [blame^] | 699 | /* the arp must be sent on the selected rx channel */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 700 | tx_slave = rlb_choose_channel(skb, bond); |
Wang Yufen | 35d75ee | 2014-02-14 17:15:15 +0800 | [diff] [blame] | 701 | if (tx_slave) |
Joe Perches | ada0f86 | 2014-02-15 16:02:17 -0800 | [diff] [blame] | 702 | ether_addr_copy(arp->mac_src, tx_slave->dev->dev_addr); |
Veaceslav Falico | 0a111a0 | 2014-07-15 19:36:02 +0200 | [diff] [blame] | 703 | netdev_dbg(bond->dev, "Server sent ARP Reply packet\n"); |
Brian Haley | f14c4e4 | 2008-09-02 10:08:08 -0400 | [diff] [blame] | 704 | } else if (arp->op_code == htons(ARPOP_REQUEST)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 705 | /* Create an entry in the rx_hashtbl for this client as a |
| 706 | * place holder. |
| 707 | * When the arp reply is received the entry will be updated |
| 708 | * with the correct unicast address of the client. |
| 709 | */ |
| 710 | rlb_choose_channel(skb, bond); |
| 711 | |
Peter Pan(潘卫平) | 77c8e2c | 2011-04-11 00:16:32 +0000 | [diff] [blame] | 712 | /* The ARP reply packets must be delayed so that |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 713 | * they can cancel out the influence of the ARP request. |
| 714 | */ |
| 715 | bond->alb_info.rlb_update_delay_counter = RLB_UPDATE_DELAY; |
| 716 | |
| 717 | /* arp requests are broadcast and are sent on the primary |
| 718 | * the arp request will collapse all clients on the subnet to |
| 719 | * the primary slave. We must register these clients to be |
| 720 | * updated with their assigned mac. |
| 721 | */ |
| 722 | rlb_req_update_subnet_clients(bond, arp->ip_src); |
Veaceslav Falico | 0a111a0 | 2014-07-15 19:36:02 +0200 | [diff] [blame] | 723 | netdev_dbg(bond->dev, "Server sent ARP Request packet\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 724 | } |
| 725 | |
| 726 | return tx_slave; |
| 727 | } |
| 728 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 729 | static void rlb_rebalance(struct bonding *bond) |
| 730 | { |
| 731 | struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond)); |
| 732 | struct slave *assigned_slave; |
| 733 | struct rlb_client_info *client_info; |
| 734 | int ntt; |
| 735 | u32 hash_index; |
| 736 | |
Nikolay Aleksandrov | 4bab16d | 2014-09-11 22:49:26 +0200 | [diff] [blame] | 737 | spin_lock_bh(&bond->mode_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 738 | |
| 739 | ntt = 0; |
Jiri Bohac | e53665c | 2012-11-28 04:42:14 +0000 | [diff] [blame] | 740 | hash_index = bond_info->rx_hashtbl_used_head; |
| 741 | for (; hash_index != RLB_NULL_INDEX; |
| 742 | hash_index = client_info->used_next) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 743 | client_info = &(bond_info->rx_hashtbl[hash_index]); |
dingtianhong | 733ab63 | 2013-12-13 10:19:45 +0800 | [diff] [blame] | 744 | assigned_slave = __rlb_next_rx_slave(bond); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 745 | if (assigned_slave && (client_info->slave != assigned_slave)) { |
| 746 | client_info->slave = assigned_slave; |
| 747 | client_info->ntt = 1; |
| 748 | ntt = 1; |
| 749 | } |
| 750 | } |
| 751 | |
| 752 | /* update the team's flag only after the whole iteration */ |
Wang Yufen | 35d75ee | 2014-02-14 17:15:15 +0800 | [diff] [blame] | 753 | if (ntt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 754 | bond_info->rx_ntt = 1; |
Nikolay Aleksandrov | 4bab16d | 2014-09-11 22:49:26 +0200 | [diff] [blame] | 755 | spin_unlock_bh(&bond->mode_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 756 | } |
| 757 | |
Nikolay Aleksandrov | 547942c | 2014-09-15 17:19:34 +0200 | [diff] [blame^] | 758 | /* Caller must hold mode_lock */ |
Jiri Bohac | e53665c | 2012-11-28 04:42:14 +0000 | [diff] [blame] | 759 | static void rlb_init_table_entry_dst(struct rlb_client_info *entry) |
| 760 | { |
| 761 | entry->used_next = RLB_NULL_INDEX; |
| 762 | entry->used_prev = RLB_NULL_INDEX; |
| 763 | entry->assigned = 0; |
| 764 | entry->slave = NULL; |
Veaceslav Falico | d3ab3ff | 2013-08-29 23:38:57 +0200 | [diff] [blame] | 765 | entry->vlan_id = 0; |
Jiri Bohac | e53665c | 2012-11-28 04:42:14 +0000 | [diff] [blame] | 766 | } |
| 767 | static void rlb_init_table_entry_src(struct rlb_client_info *entry) |
| 768 | { |
| 769 | entry->src_first = RLB_NULL_INDEX; |
| 770 | entry->src_prev = RLB_NULL_INDEX; |
| 771 | entry->src_next = RLB_NULL_INDEX; |
| 772 | } |
| 773 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 774 | static void rlb_init_table_entry(struct rlb_client_info *entry) |
| 775 | { |
| 776 | memset(entry, 0, sizeof(struct rlb_client_info)); |
Jiri Bohac | e53665c | 2012-11-28 04:42:14 +0000 | [diff] [blame] | 777 | rlb_init_table_entry_dst(entry); |
| 778 | rlb_init_table_entry_src(entry); |
| 779 | } |
| 780 | |
| 781 | static void rlb_delete_table_entry_dst(struct bonding *bond, u32 index) |
| 782 | { |
| 783 | struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond)); |
| 784 | u32 next_index = bond_info->rx_hashtbl[index].used_next; |
| 785 | u32 prev_index = bond_info->rx_hashtbl[index].used_prev; |
| 786 | |
| 787 | if (index == bond_info->rx_hashtbl_used_head) |
| 788 | bond_info->rx_hashtbl_used_head = next_index; |
| 789 | if (prev_index != RLB_NULL_INDEX) |
| 790 | bond_info->rx_hashtbl[prev_index].used_next = next_index; |
| 791 | if (next_index != RLB_NULL_INDEX) |
| 792 | bond_info->rx_hashtbl[next_index].used_prev = prev_index; |
| 793 | } |
| 794 | |
| 795 | /* unlink a rlb hash table entry from the src list */ |
| 796 | static void rlb_src_unlink(struct bonding *bond, u32 index) |
| 797 | { |
| 798 | struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond)); |
| 799 | u32 next_index = bond_info->rx_hashtbl[index].src_next; |
| 800 | u32 prev_index = bond_info->rx_hashtbl[index].src_prev; |
| 801 | |
| 802 | bond_info->rx_hashtbl[index].src_next = RLB_NULL_INDEX; |
| 803 | bond_info->rx_hashtbl[index].src_prev = RLB_NULL_INDEX; |
| 804 | |
| 805 | if (next_index != RLB_NULL_INDEX) |
| 806 | bond_info->rx_hashtbl[next_index].src_prev = prev_index; |
| 807 | |
| 808 | if (prev_index == RLB_NULL_INDEX) |
| 809 | return; |
| 810 | |
| 811 | /* is prev_index pointing to the head of this list? */ |
| 812 | if (bond_info->rx_hashtbl[prev_index].src_first == index) |
| 813 | bond_info->rx_hashtbl[prev_index].src_first = next_index; |
| 814 | else |
| 815 | bond_info->rx_hashtbl[prev_index].src_next = next_index; |
| 816 | |
| 817 | } |
| 818 | |
| 819 | static void rlb_delete_table_entry(struct bonding *bond, u32 index) |
| 820 | { |
| 821 | struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond)); |
| 822 | struct rlb_client_info *entry = &(bond_info->rx_hashtbl[index]); |
| 823 | |
| 824 | rlb_delete_table_entry_dst(bond, index); |
| 825 | rlb_init_table_entry_dst(entry); |
| 826 | |
| 827 | rlb_src_unlink(bond, index); |
| 828 | } |
| 829 | |
| 830 | /* add the rx_hashtbl[ip_dst_hash] entry to the list |
| 831 | * of entries with identical ip_src_hash |
| 832 | */ |
| 833 | static void rlb_src_link(struct bonding *bond, u32 ip_src_hash, u32 ip_dst_hash) |
| 834 | { |
| 835 | struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond)); |
| 836 | u32 next; |
| 837 | |
| 838 | bond_info->rx_hashtbl[ip_dst_hash].src_prev = ip_src_hash; |
| 839 | next = bond_info->rx_hashtbl[ip_src_hash].src_first; |
| 840 | bond_info->rx_hashtbl[ip_dst_hash].src_next = next; |
| 841 | if (next != RLB_NULL_INDEX) |
| 842 | bond_info->rx_hashtbl[next].src_prev = ip_dst_hash; |
| 843 | bond_info->rx_hashtbl[ip_src_hash].src_first = ip_dst_hash; |
| 844 | } |
| 845 | |
Nikolay Aleksandrov | 547942c | 2014-09-15 17:19:34 +0200 | [diff] [blame^] | 846 | /* deletes all rx_hashtbl entries with arp->ip_src if their mac_src does |
| 847 | * not match arp->mac_src |
| 848 | */ |
Jiri Bohac | e53665c | 2012-11-28 04:42:14 +0000 | [diff] [blame] | 849 | static void rlb_purge_src_ip(struct bonding *bond, struct arp_pkt *arp) |
| 850 | { |
| 851 | struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond)); |
Wang Yufen | b85b6fb | 2014-02-14 17:15:12 +0800 | [diff] [blame] | 852 | u32 ip_src_hash = _simple_hash((u8 *)&(arp->ip_src), sizeof(arp->ip_src)); |
Jiri Bohac | e53665c | 2012-11-28 04:42:14 +0000 | [diff] [blame] | 853 | u32 index; |
| 854 | |
Nikolay Aleksandrov | 4bab16d | 2014-09-11 22:49:26 +0200 | [diff] [blame] | 855 | spin_lock_bh(&bond->mode_lock); |
Jiri Bohac | e53665c | 2012-11-28 04:42:14 +0000 | [diff] [blame] | 856 | |
| 857 | index = bond_info->rx_hashtbl[ip_src_hash].src_first; |
| 858 | while (index != RLB_NULL_INDEX) { |
| 859 | struct rlb_client_info *entry = &(bond_info->rx_hashtbl[index]); |
| 860 | u32 next_index = entry->src_next; |
| 861 | if (entry->ip_src == arp->ip_src && |
| 862 | !ether_addr_equal_64bits(arp->mac_src, entry->mac_src)) |
| 863 | rlb_delete_table_entry(bond, index); |
| 864 | index = next_index; |
| 865 | } |
Nikolay Aleksandrov | 4bab16d | 2014-09-11 22:49:26 +0200 | [diff] [blame] | 866 | spin_unlock_bh(&bond->mode_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 867 | } |
| 868 | |
| 869 | static int rlb_initialize(struct bonding *bond) |
| 870 | { |
| 871 | struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond)); |
Mitch Williams | 0d206a3 | 2005-11-09 10:35:30 -0800 | [diff] [blame] | 872 | struct rlb_client_info *new_hashtbl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 873 | int size = RLB_HASH_TABLE_SIZE * sizeof(struct rlb_client_info); |
| 874 | int i; |
| 875 | |
Mitch Williams | 0d206a3 | 2005-11-09 10:35:30 -0800 | [diff] [blame] | 876 | new_hashtbl = kmalloc(size, GFP_KERNEL); |
Joe Perches | e404dec | 2012-01-29 12:56:23 +0000 | [diff] [blame] | 877 | if (!new_hashtbl) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 878 | return -1; |
Joe Perches | e404dec | 2012-01-29 12:56:23 +0000 | [diff] [blame] | 879 | |
Nikolay Aleksandrov | 4bab16d | 2014-09-11 22:49:26 +0200 | [diff] [blame] | 880 | spin_lock_bh(&bond->mode_lock); |
Mitch Williams | 0d206a3 | 2005-11-09 10:35:30 -0800 | [diff] [blame] | 881 | |
| 882 | bond_info->rx_hashtbl = new_hashtbl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 883 | |
Jiri Bohac | e53665c | 2012-11-28 04:42:14 +0000 | [diff] [blame] | 884 | bond_info->rx_hashtbl_used_head = RLB_NULL_INDEX; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 885 | |
Wang Yufen | 35d75ee | 2014-02-14 17:15:15 +0800 | [diff] [blame] | 886 | for (i = 0; i < RLB_HASH_TABLE_SIZE; i++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 887 | rlb_init_table_entry(bond_info->rx_hashtbl + i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 888 | |
Nikolay Aleksandrov | 4bab16d | 2014-09-11 22:49:26 +0200 | [diff] [blame] | 889 | spin_unlock_bh(&bond->mode_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 890 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 891 | /* register to receive ARPs */ |
Jiri Pirko | 3aba891 | 2011-04-19 03:48:16 +0000 | [diff] [blame] | 892 | bond->recv_probe = rlb_arp_recv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 893 | |
| 894 | return 0; |
| 895 | } |
| 896 | |
| 897 | static void rlb_deinitialize(struct bonding *bond) |
| 898 | { |
| 899 | struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond)); |
| 900 | |
Nikolay Aleksandrov | 4bab16d | 2014-09-11 22:49:26 +0200 | [diff] [blame] | 901 | spin_lock_bh(&bond->mode_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 902 | |
| 903 | kfree(bond_info->rx_hashtbl); |
| 904 | bond_info->rx_hashtbl = NULL; |
Jiri Bohac | e53665c | 2012-11-28 04:42:14 +0000 | [diff] [blame] | 905 | bond_info->rx_hashtbl_used_head = RLB_NULL_INDEX; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 906 | |
Nikolay Aleksandrov | 4bab16d | 2014-09-11 22:49:26 +0200 | [diff] [blame] | 907 | spin_unlock_bh(&bond->mode_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 908 | } |
| 909 | |
| 910 | static void rlb_clear_vlan(struct bonding *bond, unsigned short vlan_id) |
| 911 | { |
| 912 | struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond)); |
| 913 | u32 curr_index; |
| 914 | |
Nikolay Aleksandrov | 4bab16d | 2014-09-11 22:49:26 +0200 | [diff] [blame] | 915 | spin_lock_bh(&bond->mode_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 916 | |
Jiri Bohac | e53665c | 2012-11-28 04:42:14 +0000 | [diff] [blame] | 917 | curr_index = bond_info->rx_hashtbl_used_head; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 918 | while (curr_index != RLB_NULL_INDEX) { |
| 919 | struct rlb_client_info *curr = &(bond_info->rx_hashtbl[curr_index]); |
Jiri Bohac | e53665c | 2012-11-28 04:42:14 +0000 | [diff] [blame] | 920 | u32 next_index = bond_info->rx_hashtbl[curr_index].used_next; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 921 | |
Veaceslav Falico | d3ab3ff | 2013-08-29 23:38:57 +0200 | [diff] [blame] | 922 | if (curr->vlan_id == vlan_id) |
Jiri Bohac | e53665c | 2012-11-28 04:42:14 +0000 | [diff] [blame] | 923 | rlb_delete_table_entry(bond, curr_index); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 924 | |
| 925 | curr_index = next_index; |
| 926 | } |
| 927 | |
Nikolay Aleksandrov | 4bab16d | 2014-09-11 22:49:26 +0200 | [diff] [blame] | 928 | spin_unlock_bh(&bond->mode_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 929 | } |
| 930 | |
| 931 | /*********************** tlb/rlb shared functions *********************/ |
| 932 | |
Veaceslav Falico | 7aa6498 | 2013-08-28 23:25:13 +0200 | [diff] [blame] | 933 | static void alb_send_lp_vid(struct slave *slave, u8 mac_addr[], |
Vlad Yasevich | d6b694c | 2014-05-21 11:24:39 -0400 | [diff] [blame] | 934 | __be16 vlan_proto, u16 vid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 935 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 936 | struct learning_pkt pkt; |
Veaceslav Falico | 7aa6498 | 2013-08-28 23:25:13 +0200 | [diff] [blame] | 937 | struct sk_buff *skb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 938 | int size = sizeof(struct learning_pkt); |
Veaceslav Falico | 7aa6498 | 2013-08-28 23:25:13 +0200 | [diff] [blame] | 939 | char *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 940 | |
| 941 | memset(&pkt, 0, size); |
Joe Perches | ada0f86 | 2014-02-15 16:02:17 -0800 | [diff] [blame] | 942 | ether_addr_copy(pkt.mac_dst, mac_addr); |
| 943 | ether_addr_copy(pkt.mac_src, mac_addr); |
Veaceslav Falico | 96a0922 | 2014-03-13 12:41:58 +0100 | [diff] [blame] | 944 | pkt.type = cpu_to_be16(ETH_P_LOOPBACK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 945 | |
Veaceslav Falico | 7aa6498 | 2013-08-28 23:25:13 +0200 | [diff] [blame] | 946 | skb = dev_alloc_skb(size); |
| 947 | if (!skb) |
| 948 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 949 | |
Veaceslav Falico | 7aa6498 | 2013-08-28 23:25:13 +0200 | [diff] [blame] | 950 | data = skb_put(skb, size); |
| 951 | memcpy(data, &pkt, size); |
| 952 | |
| 953 | skb_reset_mac_header(skb); |
| 954 | skb->network_header = skb->mac_header + ETH_HLEN; |
| 955 | skb->protocol = pkt.type; |
| 956 | skb->priority = TC_PRIO_CONTROL; |
| 957 | skb->dev = slave->dev; |
| 958 | |
| 959 | if (vid) { |
Vlad Yasevich | d6b694c | 2014-05-21 11:24:39 -0400 | [diff] [blame] | 960 | skb = vlan_put_tag(skb, vlan_proto, vid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 961 | if (!skb) { |
Veaceslav Falico | 0a111a0 | 2014-07-15 19:36:02 +0200 | [diff] [blame] | 962 | netdev_err(slave->bond->dev, "failed to insert VLAN tag\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 963 | return; |
| 964 | } |
Veaceslav Falico | 7aa6498 | 2013-08-28 23:25:13 +0200 | [diff] [blame] | 965 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 966 | |
Veaceslav Falico | 7aa6498 | 2013-08-28 23:25:13 +0200 | [diff] [blame] | 967 | dev_queue_xmit(skb); |
| 968 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 969 | |
Vlad Yasevich | d0c21d4 | 2014-05-21 13:19:48 -0400 | [diff] [blame] | 970 | static void alb_send_learning_packets(struct slave *slave, u8 mac_addr[], |
| 971 | bool strict_match) |
Veaceslav Falico | 7aa6498 | 2013-08-28 23:25:13 +0200 | [diff] [blame] | 972 | { |
| 973 | struct bonding *bond = bond_get_bond_by_slave(slave); |
Veaceslav Falico | 5bf94b8 | 2013-08-28 23:25:14 +0200 | [diff] [blame] | 974 | struct net_device *upper; |
| 975 | struct list_head *iter; |
Veaceslav Falico | 3e403a7 | 2014-07-17 17:02:23 +0200 | [diff] [blame] | 976 | struct bond_vlan_tag *tags; |
Veaceslav Falico | 7aa6498 | 2013-08-28 23:25:13 +0200 | [diff] [blame] | 977 | |
Veaceslav Falico | 5bf94b8 | 2013-08-28 23:25:14 +0200 | [diff] [blame] | 978 | /* send untagged */ |
Vlad Yasevich | d6b694c | 2014-05-21 11:24:39 -0400 | [diff] [blame] | 979 | alb_send_lp_vid(slave, mac_addr, 0, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 980 | |
Vlad Yasevich | 14af996 | 2014-06-04 16:23:38 -0400 | [diff] [blame] | 981 | /* loop through all devices and see if we need to send a packet |
| 982 | * for that device. |
| 983 | */ |
Veaceslav Falico | 5bf94b8 | 2013-08-28 23:25:14 +0200 | [diff] [blame] | 984 | rcu_read_lock(); |
Veaceslav Falico | 2f268f1 | 2013-09-25 09:20:07 +0200 | [diff] [blame] | 985 | netdev_for_each_all_upper_dev_rcu(bond->dev, upper, iter) { |
Vlad Yasevich | d0c21d4 | 2014-05-21 13:19:48 -0400 | [diff] [blame] | 986 | if (is_vlan_dev(upper) && vlan_get_encap_level(upper) == 0) { |
| 987 | if (strict_match && |
| 988 | ether_addr_equal_64bits(mac_addr, |
| 989 | upper->dev_addr)) { |
| 990 | alb_send_lp_vid(slave, mac_addr, |
| 991 | vlan_dev_vlan_proto(upper), |
| 992 | vlan_dev_vlan_id(upper)); |
| 993 | } else if (!strict_match) { |
| 994 | alb_send_lp_vid(slave, upper->dev_addr, |
| 995 | vlan_dev_vlan_proto(upper), |
| 996 | vlan_dev_vlan_id(upper)); |
| 997 | } |
| 998 | } |
Vlad Yasevich | 14af996 | 2014-06-04 16:23:38 -0400 | [diff] [blame] | 999 | |
| 1000 | /* If this is a macvlan device, then only send updates |
| 1001 | * when strict_match is turned off. |
| 1002 | */ |
| 1003 | if (netif_is_macvlan(upper) && !strict_match) { |
Veaceslav Falico | 3e403a7 | 2014-07-17 17:02:23 +0200 | [diff] [blame] | 1004 | tags = bond_verify_device_path(bond->dev, upper, 0); |
| 1005 | if (IS_ERR_OR_NULL(tags)) |
| 1006 | BUG(); |
Vlad Yasevich | 14af996 | 2014-06-04 16:23:38 -0400 | [diff] [blame] | 1007 | alb_send_lp_vid(slave, upper->dev_addr, |
| 1008 | tags[0].vlan_proto, tags[0].vlan_id); |
Veaceslav Falico | 3e403a7 | 2014-07-17 17:02:23 +0200 | [diff] [blame] | 1009 | kfree(tags); |
Vlad Yasevich | 14af996 | 2014-06-04 16:23:38 -0400 | [diff] [blame] | 1010 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1011 | } |
Veaceslav Falico | 5bf94b8 | 2013-08-28 23:25:14 +0200 | [diff] [blame] | 1012 | rcu_read_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1013 | } |
| 1014 | |
Jiri Bohac | b924551 | 2012-01-18 12:24:54 +0000 | [diff] [blame] | 1015 | static int alb_set_slave_mac_addr(struct slave *slave, u8 addr[]) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1016 | { |
| 1017 | struct net_device *dev = slave->dev; |
| 1018 | struct sockaddr s_addr; |
| 1019 | |
Veaceslav Falico | 0184409 | 2014-05-15 21:39:55 +0200 | [diff] [blame] | 1020 | if (BOND_MODE(slave->bond) == BOND_MODE_TLB) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1021 | memcpy(dev->dev_addr, addr, dev->addr_len); |
| 1022 | return 0; |
| 1023 | } |
| 1024 | |
Nikolay Aleksandrov | 547942c | 2014-09-15 17:19:34 +0200 | [diff] [blame^] | 1025 | /* for rlb each slave must have a unique hw mac addresses so that |
| 1026 | * each slave will receive packets destined to a different mac |
| 1027 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1028 | memcpy(s_addr.sa_data, addr, dev->addr_len); |
| 1029 | s_addr.sa_family = dev->type; |
| 1030 | if (dev_set_mac_address(dev, &s_addr)) { |
Veaceslav Falico | 0a111a0 | 2014-07-15 19:36:02 +0200 | [diff] [blame] | 1031 | netdev_err(slave->bond->dev, "dev_set_mac_address of dev %s failed! ALB mode requires that the base driver support setting the hw address also when the network device's interface is open\n", |
| 1032 | dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1033 | return -EOPNOTSUPP; |
| 1034 | } |
| 1035 | return 0; |
| 1036 | } |
| 1037 | |
Nikolay Aleksandrov | 547942c | 2014-09-15 17:19:34 +0200 | [diff] [blame^] | 1038 | /* Swap MAC addresses between two slaves. |
Jay Vosburgh | 059fe7a | 2007-10-17 17:37:49 -0700 | [diff] [blame] | 1039 | * |
| 1040 | * Called with RTNL held, and no other locks. |
Jay Vosburgh | 059fe7a | 2007-10-17 17:37:49 -0700 | [diff] [blame] | 1041 | */ |
Veaceslav Falico | 43547ea | 2013-05-27 23:14:51 +0000 | [diff] [blame] | 1042 | static void alb_swap_mac_addr(struct slave *slave1, struct slave *slave2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1043 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1044 | u8 tmp_mac_addr[ETH_ALEN]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1045 | |
Joe Perches | ada0f86 | 2014-02-15 16:02:17 -0800 | [diff] [blame] | 1046 | ether_addr_copy(tmp_mac_addr, slave1->dev->dev_addr); |
Jiri Bohac | b924551 | 2012-01-18 12:24:54 +0000 | [diff] [blame] | 1047 | alb_set_slave_mac_addr(slave1, slave2->dev->dev_addr); |
| 1048 | alb_set_slave_mac_addr(slave2, tmp_mac_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1049 | |
Jay Vosburgh | 059fe7a | 2007-10-17 17:37:49 -0700 | [diff] [blame] | 1050 | } |
| 1051 | |
Nikolay Aleksandrov | 547942c | 2014-09-15 17:19:34 +0200 | [diff] [blame^] | 1052 | /* Send learning packets after MAC address swap. |
Jay Vosburgh | 059fe7a | 2007-10-17 17:37:49 -0700 | [diff] [blame] | 1053 | * |
Jay Vosburgh | 2543331 | 2008-01-17 16:24:59 -0800 | [diff] [blame] | 1054 | * Called with RTNL and no other locks |
Jay Vosburgh | 059fe7a | 2007-10-17 17:37:49 -0700 | [diff] [blame] | 1055 | */ |
| 1056 | static void alb_fasten_mac_swap(struct bonding *bond, struct slave *slave1, |
| 1057 | struct slave *slave2) |
| 1058 | { |
Veaceslav Falico | 8557cd7 | 2014-05-15 21:39:59 +0200 | [diff] [blame] | 1059 | int slaves_state_differ = (bond_slave_can_tx(slave1) != bond_slave_can_tx(slave2)); |
Jay Vosburgh | 059fe7a | 2007-10-17 17:37:49 -0700 | [diff] [blame] | 1060 | struct slave *disabled_slave = NULL; |
| 1061 | |
Jay Vosburgh | 2543331 | 2008-01-17 16:24:59 -0800 | [diff] [blame] | 1062 | ASSERT_RTNL(); |
| 1063 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1064 | /* fasten the change in the switch */ |
Veaceslav Falico | 8557cd7 | 2014-05-15 21:39:59 +0200 | [diff] [blame] | 1065 | if (bond_slave_can_tx(slave1)) { |
Vlad Yasevich | d0c21d4 | 2014-05-21 13:19:48 -0400 | [diff] [blame] | 1066 | alb_send_learning_packets(slave1, slave1->dev->dev_addr, false); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1067 | if (bond->alb_info.rlb_enabled) { |
| 1068 | /* inform the clients that the mac address |
| 1069 | * has changed |
| 1070 | */ |
| 1071 | rlb_req_update_slave_clients(bond, slave1); |
| 1072 | } |
| 1073 | } else { |
| 1074 | disabled_slave = slave1; |
| 1075 | } |
| 1076 | |
Veaceslav Falico | 8557cd7 | 2014-05-15 21:39:59 +0200 | [diff] [blame] | 1077 | if (bond_slave_can_tx(slave2)) { |
Vlad Yasevich | d0c21d4 | 2014-05-21 13:19:48 -0400 | [diff] [blame] | 1078 | alb_send_learning_packets(slave2, slave2->dev->dev_addr, false); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1079 | if (bond->alb_info.rlb_enabled) { |
| 1080 | /* inform the clients that the mac address |
| 1081 | * has changed |
| 1082 | */ |
| 1083 | rlb_req_update_slave_clients(bond, slave2); |
| 1084 | } |
| 1085 | } else { |
| 1086 | disabled_slave = slave2; |
| 1087 | } |
| 1088 | |
| 1089 | if (bond->alb_info.rlb_enabled && slaves_state_differ) { |
| 1090 | /* A disabled slave was assigned an active mac addr */ |
| 1091 | rlb_teach_disabled_mac_on_primary(bond, |
| 1092 | disabled_slave->dev->dev_addr); |
| 1093 | } |
| 1094 | } |
| 1095 | |
| 1096 | /** |
| 1097 | * alb_change_hw_addr_on_detach |
| 1098 | * @bond: bonding we're working on |
| 1099 | * @slave: the slave that was just detached |
| 1100 | * |
| 1101 | * We assume that @slave was already detached from the slave list. |
| 1102 | * |
| 1103 | * If @slave's permanent hw address is different both from its current |
| 1104 | * address and from @bond's address, then somewhere in the bond there's |
| 1105 | * a slave that has @slave's permanet address as its current address. |
| 1106 | * We'll make sure that that slave no longer uses @slave's permanent address. |
| 1107 | * |
Jay Vosburgh | 2543331 | 2008-01-17 16:24:59 -0800 | [diff] [blame] | 1108 | * Caller must hold RTNL and no other locks |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1109 | */ |
| 1110 | static void alb_change_hw_addr_on_detach(struct bonding *bond, struct slave *slave) |
| 1111 | { |
| 1112 | int perm_curr_diff; |
| 1113 | int perm_bond_diff; |
Veaceslav Falico | b88ec38 | 2013-06-18 13:44:52 +0200 | [diff] [blame] | 1114 | struct slave *found_slave; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1115 | |
Joe Perches | a6700db | 2012-05-09 17:04:04 +0000 | [diff] [blame] | 1116 | perm_curr_diff = !ether_addr_equal_64bits(slave->perm_hwaddr, |
| 1117 | slave->dev->dev_addr); |
| 1118 | perm_bond_diff = !ether_addr_equal_64bits(slave->perm_hwaddr, |
| 1119 | bond->dev->dev_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1120 | |
| 1121 | if (perm_curr_diff && perm_bond_diff) { |
Veaceslav Falico | b88ec38 | 2013-06-18 13:44:52 +0200 | [diff] [blame] | 1122 | found_slave = bond_slave_has_mac(bond, slave->perm_hwaddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1123 | |
Veaceslav Falico | b88ec38 | 2013-06-18 13:44:52 +0200 | [diff] [blame] | 1124 | if (found_slave) { |
Veaceslav Falico | b88ec38 | 2013-06-18 13:44:52 +0200 | [diff] [blame] | 1125 | alb_swap_mac_addr(slave, found_slave); |
| 1126 | alb_fasten_mac_swap(bond, slave, found_slave); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1127 | } |
| 1128 | } |
| 1129 | } |
| 1130 | |
| 1131 | /** |
| 1132 | * alb_handle_addr_collision_on_attach |
| 1133 | * @bond: bonding we're working on |
| 1134 | * @slave: the slave that was just attached |
| 1135 | * |
| 1136 | * checks uniqueness of slave's mac address and handles the case the |
| 1137 | * new slave uses the bonds mac address. |
| 1138 | * |
| 1139 | * If the permanent hw address of @slave is @bond's hw address, we need to |
| 1140 | * find a different hw address to give @slave, that isn't in use by any other |
Peter Pan(潘卫平) | 77c8e2c | 2011-04-11 00:16:32 +0000 | [diff] [blame] | 1141 | * slave in the bond. This address must be, of course, one of the permanent |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1142 | * addresses of the other slaves. |
| 1143 | * |
| 1144 | * We go over the slave list, and for each slave there we compare its |
| 1145 | * permanent hw address with the current address of all the other slaves. |
| 1146 | * If no match was found, then we've found a slave with a permanent address |
| 1147 | * that isn't used by any other slave in the bond, so we can assign it to |
| 1148 | * @slave. |
| 1149 | * |
| 1150 | * assumption: this function is called before @slave is attached to the |
Veaceslav Falico | cedb743 | 2013-06-17 19:30:35 +0200 | [diff] [blame] | 1151 | * bond slave list. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1152 | */ |
| 1153 | static int alb_handle_addr_collision_on_attach(struct bonding *bond, struct slave *slave) |
| 1154 | { |
Eric Dumazet | 4740d63 | 2014-07-15 06:56:55 -0700 | [diff] [blame] | 1155 | struct slave *has_bond_addr = rcu_access_pointer(bond->curr_active_slave); |
Veaceslav Falico | 9caff1e7 | 2013-09-25 09:20:14 +0200 | [diff] [blame] | 1156 | struct slave *tmp_slave1, *free_mac_slave = NULL; |
| 1157 | struct list_head *iter; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1158 | |
Veaceslav Falico | 0965a1f | 2013-09-25 09:20:21 +0200 | [diff] [blame] | 1159 | if (!bond_has_slaves(bond)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1160 | /* this is the first slave */ |
| 1161 | return 0; |
| 1162 | } |
| 1163 | |
| 1164 | /* if slave's mac address differs from bond's mac address |
| 1165 | * check uniqueness of slave's mac address against the other |
| 1166 | * slaves in the bond. |
| 1167 | */ |
Joe Perches | a6700db | 2012-05-09 17:04:04 +0000 | [diff] [blame] | 1168 | if (!ether_addr_equal_64bits(slave->perm_hwaddr, bond->dev->dev_addr)) { |
Veaceslav Falico | cedb743 | 2013-06-17 19:30:35 +0200 | [diff] [blame] | 1169 | if (!bond_slave_has_mac(bond, slave->dev->dev_addr)) |
John W. Linville | 6b38aef | 2005-07-28 15:00:15 -0400 | [diff] [blame] | 1170 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1171 | |
John W. Linville | 6b38aef | 2005-07-28 15:00:15 -0400 | [diff] [blame] | 1172 | /* Try setting slave mac to bond address and fall-through |
Nikolay Aleksandrov | 547942c | 2014-09-15 17:19:34 +0200 | [diff] [blame^] | 1173 | * to code handling that situation below... |
| 1174 | */ |
Jiri Bohac | b924551 | 2012-01-18 12:24:54 +0000 | [diff] [blame] | 1175 | alb_set_slave_mac_addr(slave, bond->dev->dev_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1176 | } |
| 1177 | |
| 1178 | /* The slave's address is equal to the address of the bond. |
| 1179 | * Search for a spare address in the bond for this slave. |
| 1180 | */ |
Veaceslav Falico | 9caff1e7 | 2013-09-25 09:20:14 +0200 | [diff] [blame] | 1181 | bond_for_each_slave(bond, tmp_slave1, iter) { |
Veaceslav Falico | cedb743 | 2013-06-17 19:30:35 +0200 | [diff] [blame] | 1182 | if (!bond_slave_has_mac(bond, tmp_slave1->perm_hwaddr)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1183 | /* no slave has tmp_slave1's perm addr |
| 1184 | * as its curr addr |
| 1185 | */ |
| 1186 | free_mac_slave = tmp_slave1; |
| 1187 | break; |
| 1188 | } |
| 1189 | |
| 1190 | if (!has_bond_addr) { |
Joe Perches | a6700db | 2012-05-09 17:04:04 +0000 | [diff] [blame] | 1191 | if (ether_addr_equal_64bits(tmp_slave1->dev->dev_addr, |
| 1192 | bond->dev->dev_addr)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1193 | |
| 1194 | has_bond_addr = tmp_slave1; |
| 1195 | } |
| 1196 | } |
| 1197 | } |
| 1198 | |
| 1199 | if (free_mac_slave) { |
Jiri Bohac | b924551 | 2012-01-18 12:24:54 +0000 | [diff] [blame] | 1200 | alb_set_slave_mac_addr(slave, free_mac_slave->perm_hwaddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1201 | |
Veaceslav Falico | 0a111a0 | 2014-07-15 19:36:02 +0200 | [diff] [blame] | 1202 | netdev_warn(bond->dev, "the hw address of slave %s is in use by the bond; giving it the hw address of %s\n", |
| 1203 | slave->dev->name, free_mac_slave->dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1204 | |
| 1205 | } else if (has_bond_addr) { |
Veaceslav Falico | 0a111a0 | 2014-07-15 19:36:02 +0200 | [diff] [blame] | 1206 | netdev_err(bond->dev, "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", |
| 1207 | slave->dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1208 | return -EFAULT; |
| 1209 | } |
| 1210 | |
| 1211 | return 0; |
| 1212 | } |
| 1213 | |
| 1214 | /** |
| 1215 | * alb_set_mac_address |
| 1216 | * @bond: |
| 1217 | * @addr: |
| 1218 | * |
| 1219 | * In TLB mode all slaves are configured to the bond's hw address, but set |
| 1220 | * their dev_addr field to different addresses (based on their permanent hw |
| 1221 | * addresses). |
| 1222 | * |
| 1223 | * For each slave, this function sets the interface to the new address and then |
| 1224 | * changes its dev_addr field to its previous value. |
| 1225 | * |
| 1226 | * Unwinding assumes bond's mac address has not yet changed. |
| 1227 | */ |
| 1228 | static int alb_set_mac_address(struct bonding *bond, void *addr) |
| 1229 | { |
Veaceslav Falico | 81f23b1 | 2013-09-25 09:20:13 +0200 | [diff] [blame] | 1230 | struct slave *slave, *rollback_slave; |
Veaceslav Falico | 9caff1e7 | 2013-09-25 09:20:14 +0200 | [diff] [blame] | 1231 | struct list_head *iter; |
nikolay@redhat.com | dec1e90 | 2013-08-01 16:54:47 +0200 | [diff] [blame] | 1232 | struct sockaddr sa; |
Veaceslav Falico | 81f23b1 | 2013-09-25 09:20:13 +0200 | [diff] [blame] | 1233 | char tmp_addr[ETH_ALEN]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1234 | int res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1235 | |
nikolay@redhat.com | dec1e90 | 2013-08-01 16:54:47 +0200 | [diff] [blame] | 1236 | if (bond->alb_info.rlb_enabled) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1237 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1238 | |
Veaceslav Falico | 9caff1e7 | 2013-09-25 09:20:14 +0200 | [diff] [blame] | 1239 | bond_for_each_slave(bond, slave, iter) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1240 | /* save net_device's current hw address */ |
Joe Perches | ada0f86 | 2014-02-15 16:02:17 -0800 | [diff] [blame] | 1241 | ether_addr_copy(tmp_addr, slave->dev->dev_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1242 | |
| 1243 | res = dev_set_mac_address(slave->dev, addr); |
| 1244 | |
| 1245 | /* restore net_device's hw address */ |
Joe Perches | ada0f86 | 2014-02-15 16:02:17 -0800 | [diff] [blame] | 1246 | ether_addr_copy(slave->dev->dev_addr, tmp_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1247 | |
Stephen Hemminger | eb7cc59 | 2008-11-19 21:56:05 -0800 | [diff] [blame] | 1248 | if (res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1249 | goto unwind; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1250 | } |
| 1251 | |
| 1252 | return 0; |
| 1253 | |
| 1254 | unwind: |
| 1255 | memcpy(sa.sa_data, bond->dev->dev_addr, bond->dev->addr_len); |
| 1256 | sa.sa_family = bond->dev->type; |
| 1257 | |
| 1258 | /* unwind from head to the slave that failed */ |
Veaceslav Falico | 9caff1e7 | 2013-09-25 09:20:14 +0200 | [diff] [blame] | 1259 | bond_for_each_slave(bond, rollback_slave, iter) { |
Veaceslav Falico | 81f23b1 | 2013-09-25 09:20:13 +0200 | [diff] [blame] | 1260 | if (rollback_slave == slave) |
| 1261 | break; |
Joe Perches | ada0f86 | 2014-02-15 16:02:17 -0800 | [diff] [blame] | 1262 | ether_addr_copy(tmp_addr, rollback_slave->dev->dev_addr); |
Veaceslav Falico | 81f23b1 | 2013-09-25 09:20:13 +0200 | [diff] [blame] | 1263 | dev_set_mac_address(rollback_slave->dev, &sa); |
Joe Perches | ada0f86 | 2014-02-15 16:02:17 -0800 | [diff] [blame] | 1264 | ether_addr_copy(rollback_slave->dev->dev_addr, tmp_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1265 | } |
| 1266 | |
| 1267 | return res; |
| 1268 | } |
| 1269 | |
| 1270 | /************************ exported alb funcions ************************/ |
| 1271 | |
| 1272 | int bond_alb_initialize(struct bonding *bond, int rlb_enabled) |
| 1273 | { |
| 1274 | int res; |
| 1275 | |
| 1276 | res = tlb_initialize(bond); |
Wang Yufen | 35d75ee | 2014-02-14 17:15:15 +0800 | [diff] [blame] | 1277 | if (res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1278 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1279 | |
| 1280 | if (rlb_enabled) { |
| 1281 | bond->alb_info.rlb_enabled = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1282 | res = rlb_initialize(bond); |
| 1283 | if (res) { |
| 1284 | tlb_deinitialize(bond); |
| 1285 | return res; |
| 1286 | } |
Mitch Williams | b76850a | 2005-11-09 10:35:35 -0800 | [diff] [blame] | 1287 | } else { |
| 1288 | bond->alb_info.rlb_enabled = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1289 | } |
| 1290 | |
| 1291 | return 0; |
| 1292 | } |
| 1293 | |
| 1294 | void bond_alb_deinitialize(struct bonding *bond) |
| 1295 | { |
| 1296 | struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond)); |
| 1297 | |
| 1298 | tlb_deinitialize(bond); |
| 1299 | |
Wang Yufen | dda0fd5 | 2014-02-14 17:15:16 +0800 | [diff] [blame] | 1300 | if (bond_info->rlb_enabled) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1301 | rlb_deinitialize(bond); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1302 | } |
| 1303 | |
Mahesh Bandewar | 9a49aba | 2014-04-22 16:30:18 -0700 | [diff] [blame] | 1304 | static int bond_do_alb_xmit(struct sk_buff *skb, struct bonding *bond, |
Nikolay Aleksandrov | 547942c | 2014-09-15 17:19:34 +0200 | [diff] [blame^] | 1305 | struct slave *tx_slave) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1306 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1307 | struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond)); |
Mahesh Bandewar | 9a49aba | 2014-04-22 16:30:18 -0700 | [diff] [blame] | 1308 | struct ethhdr *eth_data = eth_hdr(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1309 | |
| 1310 | if (!tx_slave) { |
| 1311 | /* unbalanced or unassigned, send through primary */ |
dingtianhong | 28c7192 | 2013-10-15 16:28:39 +0800 | [diff] [blame] | 1312 | tx_slave = rcu_dereference(bond->curr_active_slave); |
Mahesh Bandewar | e9f0fb8 | 2014-04-22 16:30:22 -0700 | [diff] [blame] | 1313 | if (bond->params.tlb_dynamic_lb) |
| 1314 | bond_info->unbalanced_load += skb->len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1315 | } |
| 1316 | |
Veaceslav Falico | 8557cd7 | 2014-05-15 21:39:59 +0200 | [diff] [blame] | 1317 | if (tx_slave && bond_slave_can_tx(tx_slave)) { |
Andreea-Cristina Bernat | b5091b5 | 2014-08-17 13:21:45 +0300 | [diff] [blame] | 1318 | if (tx_slave != rcu_access_pointer(bond->curr_active_slave)) { |
Joe Perches | 2a7c183 | 2014-02-18 09:42:45 -0800 | [diff] [blame] | 1319 | ether_addr_copy(eth_data->h_source, |
| 1320 | tx_slave->dev->dev_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1321 | } |
| 1322 | |
dingtianhong | 4d4ac1b | 2014-01-02 09:13:02 +0800 | [diff] [blame] | 1323 | bond_dev_queue_xmit(bond, skb, tx_slave->dev); |
| 1324 | goto out; |
Joe Perches | 157550fb | 2014-02-18 09:42:46 -0800 | [diff] [blame] | 1325 | } |
| 1326 | |
Mahesh Bandewar | e9f0fb8 | 2014-04-22 16:30:22 -0700 | [diff] [blame] | 1327 | if (tx_slave && bond->params.tlb_dynamic_lb) { |
Nikolay Aleksandrov | 4bab16d | 2014-09-11 22:49:26 +0200 | [diff] [blame] | 1328 | spin_lock(&bond->mode_lock); |
Joe Perches | 157550fb | 2014-02-18 09:42:46 -0800 | [diff] [blame] | 1329 | __tlb_clear_slave(bond, tx_slave, 0); |
Nikolay Aleksandrov | 4bab16d | 2014-09-11 22:49:26 +0200 | [diff] [blame] | 1330 | spin_unlock(&bond->mode_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1331 | } |
| 1332 | |
dingtianhong | 4d4ac1b | 2014-01-02 09:13:02 +0800 | [diff] [blame] | 1333 | /* no suitable interface, frame not sent */ |
Eric W. Biederman | 2bb77ab | 2014-03-11 14:16:58 -0700 | [diff] [blame] | 1334 | dev_kfree_skb_any(skb); |
dingtianhong | 4d4ac1b | 2014-01-02 09:13:02 +0800 | [diff] [blame] | 1335 | out: |
Patrick McHardy | ec634fe | 2009-07-05 19:23:38 -0700 | [diff] [blame] | 1336 | return NETDEV_TX_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1337 | } |
| 1338 | |
Mahesh Bandewar | 6b794c1 | 2014-07-16 11:10:36 -0700 | [diff] [blame] | 1339 | static int bond_tlb_update_slave_arr(struct bonding *bond, |
| 1340 | struct slave *skipslave) |
| 1341 | { |
| 1342 | struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond)); |
| 1343 | struct slave *tx_slave; |
| 1344 | struct list_head *iter; |
| 1345 | struct tlb_up_slave *new_arr, *old_arr; |
| 1346 | |
| 1347 | new_arr = kzalloc(offsetof(struct tlb_up_slave, arr[bond->slave_cnt]), |
| 1348 | GFP_ATOMIC); |
| 1349 | if (!new_arr) |
| 1350 | return -ENOMEM; |
| 1351 | |
| 1352 | bond_for_each_slave(bond, tx_slave, iter) { |
| 1353 | if (!bond_slave_can_tx(tx_slave)) |
| 1354 | continue; |
| 1355 | if (skipslave == tx_slave) |
| 1356 | continue; |
| 1357 | new_arr->arr[new_arr->count++] = tx_slave; |
| 1358 | } |
| 1359 | |
| 1360 | old_arr = rtnl_dereference(bond_info->slave_arr); |
| 1361 | rcu_assign_pointer(bond_info->slave_arr, new_arr); |
| 1362 | if (old_arr) |
| 1363 | kfree_rcu(old_arr, rcu); |
| 1364 | |
| 1365 | return 0; |
| 1366 | } |
| 1367 | |
Mahesh Bandewar | f05b42e | 2014-04-22 16:30:20 -0700 | [diff] [blame] | 1368 | int bond_tlb_xmit(struct sk_buff *skb, struct net_device *bond_dev) |
| 1369 | { |
| 1370 | struct bonding *bond = netdev_priv(bond_dev); |
Mahesh Bandewar | 6b794c1 | 2014-07-16 11:10:36 -0700 | [diff] [blame] | 1371 | struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond)); |
Mahesh Bandewar | f05b42e | 2014-04-22 16:30:20 -0700 | [diff] [blame] | 1372 | struct ethhdr *eth_data; |
| 1373 | struct slave *tx_slave = NULL; |
| 1374 | u32 hash_index; |
| 1375 | |
| 1376 | skb_reset_mac_header(skb); |
| 1377 | eth_data = eth_hdr(skb); |
| 1378 | |
| 1379 | /* Do not TX balance any multicast or broadcast */ |
| 1380 | if (!is_multicast_ether_addr(eth_data->h_dest)) { |
| 1381 | switch (skb->protocol) { |
| 1382 | case htons(ETH_P_IP): |
| 1383 | case htons(ETH_P_IPX): |
| 1384 | /* In case of IPX, it will falback to L2 hash */ |
| 1385 | case htons(ETH_P_IPV6): |
| 1386 | hash_index = bond_xmit_hash(bond, skb); |
Mahesh Bandewar | e9f0fb8 | 2014-04-22 16:30:22 -0700 | [diff] [blame] | 1387 | if (bond->params.tlb_dynamic_lb) { |
| 1388 | tx_slave = tlb_choose_channel(bond, |
| 1389 | hash_index & 0xFF, |
| 1390 | skb->len); |
| 1391 | } else { |
Mahesh Bandewar | 6b794c1 | 2014-07-16 11:10:36 -0700 | [diff] [blame] | 1392 | struct tlb_up_slave *slaves; |
Mahesh Bandewar | e9f0fb8 | 2014-04-22 16:30:22 -0700 | [diff] [blame] | 1393 | |
Mahesh Bandewar | 6b794c1 | 2014-07-16 11:10:36 -0700 | [diff] [blame] | 1394 | slaves = rcu_dereference(bond_info->slave_arr); |
| 1395 | if (slaves && slaves->count) |
| 1396 | tx_slave = slaves->arr[hash_index % |
| 1397 | slaves->count]; |
Mahesh Bandewar | e9f0fb8 | 2014-04-22 16:30:22 -0700 | [diff] [blame] | 1398 | } |
Mahesh Bandewar | f05b42e | 2014-04-22 16:30:20 -0700 | [diff] [blame] | 1399 | break; |
| 1400 | } |
| 1401 | } |
Mahesh Bandewar | f05b42e | 2014-04-22 16:30:20 -0700 | [diff] [blame] | 1402 | return bond_do_alb_xmit(skb, bond, tx_slave); |
| 1403 | } |
| 1404 | |
Mahesh Bandewar | 9a49aba | 2014-04-22 16:30:18 -0700 | [diff] [blame] | 1405 | int bond_alb_xmit(struct sk_buff *skb, struct net_device *bond_dev) |
| 1406 | { |
| 1407 | struct bonding *bond = netdev_priv(bond_dev); |
| 1408 | struct ethhdr *eth_data; |
| 1409 | struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond)); |
| 1410 | struct slave *tx_slave = NULL; |
| 1411 | static const __be32 ip_bcast = htonl(0xffffffff); |
| 1412 | int hash_size = 0; |
| 1413 | bool do_tx_balance = true; |
| 1414 | u32 hash_index = 0; |
| 1415 | const u8 *hash_start = NULL; |
| 1416 | struct ipv6hdr *ip6hdr; |
| 1417 | |
| 1418 | skb_reset_mac_header(skb); |
| 1419 | eth_data = eth_hdr(skb); |
| 1420 | |
| 1421 | switch (ntohs(skb->protocol)) { |
| 1422 | case ETH_P_IP: { |
| 1423 | const struct iphdr *iph = ip_hdr(skb); |
| 1424 | |
| 1425 | if (ether_addr_equal_64bits(eth_data->h_dest, mac_bcast) || |
| 1426 | (iph->daddr == ip_bcast) || |
| 1427 | (iph->protocol == IPPROTO_IGMP)) { |
| 1428 | do_tx_balance = false; |
| 1429 | break; |
| 1430 | } |
| 1431 | hash_start = (char *)&(iph->daddr); |
| 1432 | hash_size = sizeof(iph->daddr); |
| 1433 | } |
| 1434 | break; |
| 1435 | case ETH_P_IPV6: |
| 1436 | /* IPv6 doesn't really use broadcast mac address, but leave |
| 1437 | * that here just in case. |
| 1438 | */ |
| 1439 | if (ether_addr_equal_64bits(eth_data->h_dest, mac_bcast)) { |
| 1440 | do_tx_balance = false; |
| 1441 | break; |
| 1442 | } |
| 1443 | |
| 1444 | /* IPv6 uses all-nodes multicast as an equivalent to |
| 1445 | * broadcasts in IPv4. |
| 1446 | */ |
| 1447 | if (ether_addr_equal_64bits(eth_data->h_dest, mac_v6_allmcast)) { |
| 1448 | do_tx_balance = false; |
| 1449 | break; |
| 1450 | } |
| 1451 | |
| 1452 | /* Additianally, DAD probes should not be tx-balanced as that |
| 1453 | * will lead to false positives for duplicate addresses and |
| 1454 | * prevent address configuration from working. |
| 1455 | */ |
| 1456 | ip6hdr = ipv6_hdr(skb); |
| 1457 | if (ipv6_addr_any(&ip6hdr->saddr)) { |
| 1458 | do_tx_balance = false; |
| 1459 | break; |
| 1460 | } |
| 1461 | |
| 1462 | hash_start = (char *)&(ipv6_hdr(skb)->daddr); |
| 1463 | hash_size = sizeof(ipv6_hdr(skb)->daddr); |
| 1464 | break; |
| 1465 | case ETH_P_IPX: |
| 1466 | if (ipx_hdr(skb)->ipx_checksum != IPX_NO_CHECKSUM) { |
| 1467 | /* something is wrong with this packet */ |
| 1468 | do_tx_balance = false; |
| 1469 | break; |
| 1470 | } |
| 1471 | |
| 1472 | if (ipx_hdr(skb)->ipx_type != IPX_TYPE_NCP) { |
| 1473 | /* The only protocol worth balancing in |
| 1474 | * this family since it has an "ARP" like |
| 1475 | * mechanism |
| 1476 | */ |
| 1477 | do_tx_balance = false; |
| 1478 | break; |
| 1479 | } |
| 1480 | |
| 1481 | hash_start = (char *)eth_data->h_dest; |
| 1482 | hash_size = ETH_ALEN; |
| 1483 | break; |
| 1484 | case ETH_P_ARP: |
| 1485 | do_tx_balance = false; |
| 1486 | if (bond_info->rlb_enabled) |
| 1487 | tx_slave = rlb_arp_xmit(skb, bond); |
| 1488 | break; |
| 1489 | default: |
| 1490 | do_tx_balance = false; |
| 1491 | break; |
| 1492 | } |
| 1493 | |
| 1494 | if (do_tx_balance) { |
| 1495 | hash_index = _simple_hash(hash_start, hash_size); |
| 1496 | tx_slave = tlb_choose_channel(bond, hash_index, skb->len); |
| 1497 | } |
| 1498 | |
| 1499 | return bond_do_alb_xmit(skb, bond, tx_slave); |
| 1500 | } |
| 1501 | |
Jay Vosburgh | 1b76b31 | 2007-10-17 17:37:45 -0700 | [diff] [blame] | 1502 | void bond_alb_monitor(struct work_struct *work) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1503 | { |
Jay Vosburgh | 1b76b31 | 2007-10-17 17:37:45 -0700 | [diff] [blame] | 1504 | struct bonding *bond = container_of(work, struct bonding, |
| 1505 | alb_work.work); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1506 | struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond)); |
Veaceslav Falico | 9caff1e7 | 2013-09-25 09:20:14 +0200 | [diff] [blame] | 1507 | struct list_head *iter; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1508 | struct slave *slave; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1509 | |
Veaceslav Falico | 0965a1f | 2013-09-25 09:20:21 +0200 | [diff] [blame] | 1510 | if (!bond_has_slaves(bond)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1511 | bond_info->tx_rebalance_counter = 0; |
| 1512 | bond_info->lp_counter = 0; |
| 1513 | goto re_arm; |
| 1514 | } |
| 1515 | |
dingtianhong | 733ab63 | 2013-12-13 10:19:45 +0800 | [diff] [blame] | 1516 | rcu_read_lock(); |
| 1517 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1518 | bond_info->tx_rebalance_counter++; |
| 1519 | bond_info->lp_counter++; |
| 1520 | |
| 1521 | /* send learning packets */ |
Neil Horman | 7eacd03 | 2013-09-13 11:05:33 -0400 | [diff] [blame] | 1522 | if (bond_info->lp_counter >= BOND_ALB_LP_TICKS(bond)) { |
Vlad Yasevich | d0c21d4 | 2014-05-21 13:19:48 -0400 | [diff] [blame] | 1523 | bool strict_match; |
| 1524 | |
Vlad Yasevich | d0c21d4 | 2014-05-21 13:19:48 -0400 | [diff] [blame] | 1525 | bond_for_each_slave_rcu(bond, slave, iter) { |
| 1526 | /* If updating current_active, use all currently |
| 1527 | * user mac addreses (!strict_match). Otherwise, only |
| 1528 | * use mac of the slave device. |
Vlad Yasevich | 14af996 | 2014-06-04 16:23:38 -0400 | [diff] [blame] | 1529 | * In RLB mode, we always use strict matches. |
Vlad Yasevich | d0c21d4 | 2014-05-21 13:19:48 -0400 | [diff] [blame] | 1530 | */ |
Eric Dumazet | 4740d63 | 2014-07-15 06:56:55 -0700 | [diff] [blame] | 1531 | strict_match = (slave != rcu_access_pointer(bond->curr_active_slave) || |
Vlad Yasevich | 14af996 | 2014-06-04 16:23:38 -0400 | [diff] [blame] | 1532 | bond_info->rlb_enabled); |
Vlad Yasevich | d0c21d4 | 2014-05-21 13:19:48 -0400 | [diff] [blame] | 1533 | alb_send_learning_packets(slave, slave->dev->dev_addr, |
| 1534 | strict_match); |
| 1535 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1536 | bond_info->lp_counter = 0; |
| 1537 | } |
| 1538 | |
| 1539 | /* rebalance tx traffic */ |
| 1540 | if (bond_info->tx_rebalance_counter >= BOND_TLB_REBALANCE_TICKS) { |
dingtianhong | 733ab63 | 2013-12-13 10:19:45 +0800 | [diff] [blame] | 1541 | bond_for_each_slave_rcu(bond, slave, iter) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1542 | tlb_clear_slave(bond, slave, 1); |
Eric Dumazet | 4740d63 | 2014-07-15 06:56:55 -0700 | [diff] [blame] | 1543 | if (slave == rcu_access_pointer(bond->curr_active_slave)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1544 | SLAVE_TLB_INFO(slave).load = |
| 1545 | bond_info->unbalanced_load / |
| 1546 | BOND_TLB_REBALANCE_INTERVAL; |
| 1547 | bond_info->unbalanced_load = 0; |
| 1548 | } |
| 1549 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1550 | bond_info->tx_rebalance_counter = 0; |
| 1551 | } |
| 1552 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1553 | if (bond_info->rlb_enabled) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1554 | if (bond_info->primary_is_promisc && |
| 1555 | (++bond_info->rlb_promisc_timeout_counter >= RLB_PROMISC_TIMEOUT)) { |
| 1556 | |
Nikolay Aleksandrov | 547942c | 2014-09-15 17:19:34 +0200 | [diff] [blame^] | 1557 | /* dev_set_promiscuity requires rtnl and |
David S. Miller | 1f2cd84 | 2013-10-28 00:11:22 -0400 | [diff] [blame] | 1558 | * nothing else. Avoid race with bond_close. |
| 1559 | */ |
dingtianhong | 733ab63 | 2013-12-13 10:19:45 +0800 | [diff] [blame] | 1560 | rcu_read_unlock(); |
| 1561 | if (!rtnl_trylock()) |
David S. Miller | 1f2cd84 | 2013-10-28 00:11:22 -0400 | [diff] [blame] | 1562 | goto re_arm; |
David S. Miller | 1f2cd84 | 2013-10-28 00:11:22 -0400 | [diff] [blame] | 1563 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1564 | bond_info->rlb_promisc_timeout_counter = 0; |
| 1565 | |
| 1566 | /* If the primary was set to promiscuous mode |
| 1567 | * because a slave was disabled then |
| 1568 | * it can now leave promiscuous mode. |
| 1569 | */ |
Eric Dumazet | 4740d63 | 2014-07-15 06:56:55 -0700 | [diff] [blame] | 1570 | dev_set_promiscuity(rtnl_dereference(bond->curr_active_slave)->dev, |
| 1571 | -1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1572 | bond_info->primary_is_promisc = 0; |
David S. Miller | 1f2cd84 | 2013-10-28 00:11:22 -0400 | [diff] [blame] | 1573 | |
| 1574 | rtnl_unlock(); |
dingtianhong | 733ab63 | 2013-12-13 10:19:45 +0800 | [diff] [blame] | 1575 | rcu_read_lock(); |
Jay Vosburgh | d0e81b7 | 2007-10-17 17:37:51 -0700 | [diff] [blame] | 1576 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1577 | |
| 1578 | if (bond_info->rlb_rebalance) { |
| 1579 | bond_info->rlb_rebalance = 0; |
| 1580 | rlb_rebalance(bond); |
| 1581 | } |
| 1582 | |
| 1583 | /* check if clients need updating */ |
| 1584 | if (bond_info->rx_ntt) { |
| 1585 | if (bond_info->rlb_update_delay_counter) { |
| 1586 | --bond_info->rlb_update_delay_counter; |
| 1587 | } else { |
| 1588 | rlb_update_rx_clients(bond); |
Wang Yufen | dda0fd5 | 2014-02-14 17:15:16 +0800 | [diff] [blame] | 1589 | if (bond_info->rlb_update_retry_counter) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1590 | --bond_info->rlb_update_retry_counter; |
Wang Yufen | dda0fd5 | 2014-02-14 17:15:16 +0800 | [diff] [blame] | 1591 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1592 | bond_info->rx_ntt = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1593 | } |
| 1594 | } |
| 1595 | } |
dingtianhong | 733ab63 | 2013-12-13 10:19:45 +0800 | [diff] [blame] | 1596 | rcu_read_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1597 | re_arm: |
Jay Vosburgh | e6d265e | 2011-10-28 15:42:50 +0000 | [diff] [blame] | 1598 | queue_delayed_work(bond->wq, &bond->alb_work, alb_delta_in_ticks); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1599 | } |
| 1600 | |
| 1601 | /* assumption: called before the slave is attached to the bond |
| 1602 | * and not locked by the bond lock |
| 1603 | */ |
| 1604 | int bond_alb_init_slave(struct bonding *bond, struct slave *slave) |
| 1605 | { |
| 1606 | int res; |
| 1607 | |
Jiri Bohac | b924551 | 2012-01-18 12:24:54 +0000 | [diff] [blame] | 1608 | res = alb_set_slave_mac_addr(slave, slave->perm_hwaddr); |
Wang Yufen | dda0fd5 | 2014-02-14 17:15:16 +0800 | [diff] [blame] | 1609 | if (res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1610 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1611 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1612 | res = alb_handle_addr_collision_on_attach(bond, slave); |
Wang Yufen | dda0fd5 | 2014-02-14 17:15:16 +0800 | [diff] [blame] | 1613 | if (res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1614 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1615 | |
| 1616 | tlb_init_slave(slave); |
| 1617 | |
| 1618 | /* order a rebalance ASAP */ |
| 1619 | bond->alb_info.tx_rebalance_counter = BOND_TLB_REBALANCE_TICKS; |
| 1620 | |
Wang Yufen | dda0fd5 | 2014-02-14 17:15:16 +0800 | [diff] [blame] | 1621 | if (bond->alb_info.rlb_enabled) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1622 | bond->alb_info.rlb_rebalance = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1623 | |
| 1624 | return 0; |
| 1625 | } |
| 1626 | |
Nikolay Aleksandrov | 547942c | 2014-09-15 17:19:34 +0200 | [diff] [blame^] | 1627 | /* Remove slave from tlb and rlb hash tables, and fix up MAC addresses |
Jay Vosburgh | 2543331 | 2008-01-17 16:24:59 -0800 | [diff] [blame] | 1628 | * if necessary. |
| 1629 | * |
| 1630 | * Caller must hold RTNL and no other locks |
| 1631 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1632 | void bond_alb_deinit_slave(struct bonding *bond, struct slave *slave) |
| 1633 | { |
Veaceslav Falico | 0965a1f | 2013-09-25 09:20:21 +0200 | [diff] [blame] | 1634 | if (bond_has_slaves(bond)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1635 | alb_change_hw_addr_on_detach(bond, slave); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1636 | |
| 1637 | tlb_clear_slave(bond, slave, 0); |
| 1638 | |
| 1639 | if (bond->alb_info.rlb_enabled) { |
Veaceslav Falico | 6475ae4 | 2013-09-25 09:20:17 +0200 | [diff] [blame] | 1640 | bond->alb_info.rx_slave = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1641 | rlb_clear_slave(bond, slave); |
| 1642 | } |
Mahesh Bandewar | 6b794c1 | 2014-07-16 11:10:36 -0700 | [diff] [blame] | 1643 | |
| 1644 | if (bond_is_nondyn_tlb(bond)) |
| 1645 | if (bond_tlb_update_slave_arr(bond, slave)) |
| 1646 | pr_err("Failed to build slave-array for TLB mode.\n"); |
| 1647 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1648 | } |
| 1649 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1650 | void bond_alb_handle_link_change(struct bonding *bond, struct slave *slave, char link) |
| 1651 | { |
| 1652 | struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond)); |
| 1653 | |
| 1654 | if (link == BOND_LINK_DOWN) { |
| 1655 | tlb_clear_slave(bond, slave, 0); |
Wang Yufen | 73ac0cd | 2014-02-14 17:15:17 +0800 | [diff] [blame] | 1656 | if (bond->alb_info.rlb_enabled) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1657 | rlb_clear_slave(bond, slave); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | } |
Mahesh Bandewar | 6b794c1 | 2014-07-16 11:10:36 -0700 | [diff] [blame] | 1670 | |
| 1671 | if (bond_is_nondyn_tlb(bond)) { |
| 1672 | if (bond_tlb_update_slave_arr(bond, NULL)) |
| 1673 | pr_err("Failed to build slave-array for TLB mode.\n"); |
| 1674 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1675 | } |
| 1676 | |
| 1677 | /** |
| 1678 | * bond_alb_handle_active_change - assign new curr_active_slave |
| 1679 | * @bond: our bonding struct |
| 1680 | * @new_slave: new slave to assign |
| 1681 | * |
| 1682 | * Set the bond->curr_active_slave to @new_slave and handle |
| 1683 | * mac address swapping and promiscuity changes as needed. |
| 1684 | * |
Nikolay Aleksandrov | 62c5f51 | 2014-09-11 22:49:23 +0200 | [diff] [blame] | 1685 | * Caller must hold RTNL |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1686 | */ |
| 1687 | void bond_alb_handle_active_change(struct bonding *bond, struct slave *new_slave) |
| 1688 | { |
| 1689 | struct slave *swap_slave; |
Eric Dumazet | 4740d63 | 2014-07-15 06:56:55 -0700 | [diff] [blame] | 1690 | struct slave *curr_active; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1691 | |
Nikolay Aleksandrov | 62c5f51 | 2014-09-11 22:49:23 +0200 | [diff] [blame] | 1692 | curr_active = rtnl_dereference(bond->curr_active_slave); |
Eric Dumazet | 4740d63 | 2014-07-15 06:56:55 -0700 | [diff] [blame] | 1693 | if (curr_active == new_slave) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1694 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1695 | |
Eric Dumazet | 4740d63 | 2014-07-15 06:56:55 -0700 | [diff] [blame] | 1696 | if (curr_active && bond->alb_info.primary_is_promisc) { |
| 1697 | dev_set_promiscuity(curr_active->dev, -1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1698 | bond->alb_info.primary_is_promisc = 0; |
| 1699 | bond->alb_info.rlb_promisc_timeout_counter = 0; |
| 1700 | } |
| 1701 | |
Eric Dumazet | 4740d63 | 2014-07-15 06:56:55 -0700 | [diff] [blame] | 1702 | swap_slave = curr_active; |
nikolay@redhat.com | 278b208 | 2013-08-01 16:54:51 +0200 | [diff] [blame] | 1703 | rcu_assign_pointer(bond->curr_active_slave, new_slave); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1704 | |
Veaceslav Falico | 0965a1f | 2013-09-25 09:20:21 +0200 | [diff] [blame] | 1705 | if (!new_slave || !bond_has_slaves(bond)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1706 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1707 | |
| 1708 | /* set the new curr_active_slave to the bonds mac address |
| 1709 | * i.e. swap mac addresses of old curr_active_slave and new curr_active_slave |
| 1710 | */ |
Veaceslav Falico | b88ec38 | 2013-06-18 13:44:52 +0200 | [diff] [blame] | 1711 | if (!swap_slave) |
| 1712 | swap_slave = bond_slave_has_mac(bond, bond->dev->dev_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1713 | |
Nikolay Aleksandrov | 547942c | 2014-09-15 17:19:34 +0200 | [diff] [blame^] | 1714 | /* Arrange for swap_slave and new_slave to temporarily be |
Jay Vosburgh | 059fe7a | 2007-10-17 17:37:49 -0700 | [diff] [blame] | 1715 | * ignored so we can mess with their MAC addresses without |
| 1716 | * fear of interference from transmit activity. |
| 1717 | */ |
nikolay@redhat.com | dec1e90 | 2013-08-01 16:54:47 +0200 | [diff] [blame] | 1718 | if (swap_slave) |
Jay Vosburgh | 059fe7a | 2007-10-17 17:37:49 -0700 | [diff] [blame] | 1719 | tlb_clear_slave(bond, swap_slave, 1); |
Jay Vosburgh | 059fe7a | 2007-10-17 17:37:49 -0700 | [diff] [blame] | 1720 | tlb_clear_slave(bond, new_slave, 1); |
| 1721 | |
Veaceslav Falico | 4996b90 | 2013-10-07 09:17:20 +0200 | [diff] [blame] | 1722 | /* in TLB mode, the slave might flip down/up with the old dev_addr, |
| 1723 | * and thus filter bond->dev_addr's packets, so force bond's mac |
| 1724 | */ |
Veaceslav Falico | 0184409 | 2014-05-15 21:39:55 +0200 | [diff] [blame] | 1725 | if (BOND_MODE(bond) == BOND_MODE_TLB) { |
Veaceslav Falico | 4996b90 | 2013-10-07 09:17:20 +0200 | [diff] [blame] | 1726 | struct sockaddr sa; |
| 1727 | u8 tmp_addr[ETH_ALEN]; |
| 1728 | |
Joe Perches | ada0f86 | 2014-02-15 16:02:17 -0800 | [diff] [blame] | 1729 | ether_addr_copy(tmp_addr, new_slave->dev->dev_addr); |
Veaceslav Falico | 4996b90 | 2013-10-07 09:17:20 +0200 | [diff] [blame] | 1730 | |
| 1731 | memcpy(sa.sa_data, bond->dev->dev_addr, bond->dev->addr_len); |
| 1732 | sa.sa_family = bond->dev->type; |
| 1733 | /* we don't care if it can't change its mac, best effort */ |
| 1734 | dev_set_mac_address(new_slave->dev, &sa); |
| 1735 | |
Joe Perches | ada0f86 | 2014-02-15 16:02:17 -0800 | [diff] [blame] | 1736 | ether_addr_copy(new_slave->dev->dev_addr, tmp_addr); |
Veaceslav Falico | 4996b90 | 2013-10-07 09:17:20 +0200 | [diff] [blame] | 1737 | } |
| 1738 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1739 | /* curr_active_slave must be set before calling alb_swap_mac_addr */ |
| 1740 | if (swap_slave) { |
| 1741 | /* swap mac address */ |
Veaceslav Falico | 43547ea | 2013-05-27 23:14:51 +0000 | [diff] [blame] | 1742 | alb_swap_mac_addr(swap_slave, new_slave); |
Jay Vosburgh | 059fe7a | 2007-10-17 17:37:49 -0700 | [diff] [blame] | 1743 | alb_fasten_mac_swap(bond, swap_slave, new_slave); |
| 1744 | } else { |
Veaceslav Falico | b88ec38 | 2013-06-18 13:44:52 +0200 | [diff] [blame] | 1745 | /* set the new_slave to the bond mac address */ |
| 1746 | alb_set_slave_mac_addr(new_slave, bond->dev->dev_addr); |
Vlad Yasevich | d0c21d4 | 2014-05-21 13:19:48 -0400 | [diff] [blame] | 1747 | alb_send_learning_packets(new_slave, bond->dev->dev_addr, |
| 1748 | false); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1749 | } |
| 1750 | } |
| 1751 | |
Nikolay Aleksandrov | ecfede4 | 2014-09-09 23:16:59 +0200 | [diff] [blame] | 1752 | /* Called with RTNL */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1753 | int bond_alb_set_mac_address(struct net_device *bond_dev, void *addr) |
| 1754 | { |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 1755 | struct bonding *bond = netdev_priv(bond_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1756 | struct sockaddr *sa = addr; |
Eric Dumazet | 4740d63 | 2014-07-15 06:56:55 -0700 | [diff] [blame] | 1757 | struct slave *curr_active; |
Veaceslav Falico | b88ec38 | 2013-06-18 13:44:52 +0200 | [diff] [blame] | 1758 | struct slave *swap_slave; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1759 | int res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1760 | |
Wang Yufen | 73ac0cd | 2014-02-14 17:15:17 +0800 | [diff] [blame] | 1761 | if (!is_valid_ether_addr(sa->sa_data)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1762 | return -EADDRNOTAVAIL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1763 | |
| 1764 | res = alb_set_mac_address(bond, addr); |
Wang Yufen | 73ac0cd | 2014-02-14 17:15:17 +0800 | [diff] [blame] | 1765 | if (res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1766 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1767 | |
| 1768 | memcpy(bond_dev->dev_addr, sa->sa_data, bond_dev->addr_len); |
| 1769 | |
| 1770 | /* If there is no curr_active_slave there is nothing else to do. |
| 1771 | * Otherwise we'll need to pass the new address to it and handle |
| 1772 | * duplications. |
| 1773 | */ |
Eric Dumazet | 4740d63 | 2014-07-15 06:56:55 -0700 | [diff] [blame] | 1774 | curr_active = rtnl_dereference(bond->curr_active_slave); |
| 1775 | if (!curr_active) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1776 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1777 | |
Veaceslav Falico | b88ec38 | 2013-06-18 13:44:52 +0200 | [diff] [blame] | 1778 | swap_slave = bond_slave_has_mac(bond, bond_dev->dev_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1779 | |
| 1780 | if (swap_slave) { |
Eric Dumazet | 4740d63 | 2014-07-15 06:56:55 -0700 | [diff] [blame] | 1781 | alb_swap_mac_addr(swap_slave, curr_active); |
| 1782 | alb_fasten_mac_swap(bond, swap_slave, curr_active); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1783 | } else { |
Eric Dumazet | 4740d63 | 2014-07-15 06:56:55 -0700 | [diff] [blame] | 1784 | alb_set_slave_mac_addr(curr_active, bond_dev->dev_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1785 | |
Eric Dumazet | 4740d63 | 2014-07-15 06:56:55 -0700 | [diff] [blame] | 1786 | alb_send_learning_packets(curr_active, |
Vlad Yasevich | d0c21d4 | 2014-05-21 13:19:48 -0400 | [diff] [blame] | 1787 | bond_dev->dev_addr, false); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1788 | if (bond->alb_info.rlb_enabled) { |
| 1789 | /* inform clients mac address has changed */ |
Eric Dumazet | 4740d63 | 2014-07-15 06:56:55 -0700 | [diff] [blame] | 1790 | rlb_req_update_slave_clients(bond, curr_active); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1791 | } |
| 1792 | } |
| 1793 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1794 | return 0; |
| 1795 | } |
| 1796 | |
| 1797 | void bond_alb_clear_vlan(struct bonding *bond, unsigned short vlan_id) |
| 1798 | { |
Wang Yufen | 73ac0cd | 2014-02-14 17:15:17 +0800 | [diff] [blame] | 1799 | if (bond->alb_info.rlb_enabled) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1800 | rlb_clear_vlan(bond, vlan_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1801 | } |
| 1802 | |