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