aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid S. Miller <davem@davemloft.net>2013-08-29 16:19:50 -0400
committerDavid S. Miller <davem@davemloft.net>2013-08-29 16:19:50 -0400
commitd7ef9b04a219c1c8ad053e9b4321283b5af12938 (patch)
treeed95aed89dea6c836e57ad069737082693fee156
parent6d508cce9248acbd9f2713c71a28ef58ff5c4e27 (diff)
parent3e32582f7d5b6f364ddd31110bf7277d69fd4e91 (diff)
Merge branch 'bond_vlan'
Veaceslav Falico says: ==================== bonding: remove vlan special handling v1: Per Jiri's advice, remove the exported netdev_upper struct to keep it inside dev.c only, and instead implement a macro to iterate over the list and return only net_device *. v2: Jiri noted that we need to see every upper device, but not only the first level. Modify the netdev_upper logic to include a list of lower devices and for both upper/lower lists every device would see both its first-level devices and every other devices that is lower/upper of it. Also, convert some annoying spamming warnings to pr_debug in bond_arp_send_all. v3: move renaming part completely to patch 1 (did I forget to git add before commiting?) and address Jiri's input about comments/style of patch 2. v4: as Vlad found spotted, bond_arp_send_all() won't work in a config where we have a device with ip on top of our upper vlan. It fails to send packets because we don't tag the packet, while the device on top of vlan will emit tagged packets through this vlan. Fix this by first searching for all upper vlans, and for each vlan - for the devs on top of it. If we find the dev - then tag the packet with the underling's vlan_id, otherwise just search the old way - for all devices on top of bonding. Also, move the version changes under "---" so they won't get into the commit message, if/when applied. The aim of this patchset is to remove bondings' own vlan handling as much as possible and replace it with the netdev upper device functionality. The upper device functionality is extended to include also lower devices and to have, for each device, a full view of every lower and upper device, but not only the first-level ones. This might permit in the future to avoid, for any grouping/teaming/upper/lower devices, to maintain its own lists of slaves/vlans/etc. This is achieved by adding a helper function to upper dev list handling - netdev_upper_get_next_dev(dev, iter), which returns the next device after the list_head **iter, and sets *iter to the next list_head *. This patchset also adds netdev_for_each_upper_dev(dev, upper, iter), which iterates through the whole dev->upper_dev_list, setting upper to the net_device. The only special treatment of vlans remains in rlb code. This patchset solves several issues with bonding, simplifies it overall, RCUify further and exports upper list functions for any other users which might also want to get rid of its own vlan_lists or slaves. I'm testing it continuously currently, no issues found, will update on anything. ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--drivers/net/bonding/bond_alb.c75
-rw-r--r--drivers/net/bonding/bond_alb.h2
-rw-r--r--drivers/net/bonding/bond_main.c272
-rw-r--r--drivers/net/bonding/bonding.h21
-rw-r--r--include/linux/netdevice.h11
-rw-r--r--net/core/dev.c345
6 files changed, 416 insertions, 310 deletions
diff --git a/drivers/net/bonding/bond_alb.c b/drivers/net/bonding/bond_alb.c
index 3a5db7b1df68..018235263596 100644
--- a/drivers/net/bonding/bond_alb.c
+++ b/drivers/net/bonding/bond_alb.c
@@ -971,58 +971,62 @@ static void rlb_clear_vlan(struct bonding *bond, unsigned short vlan_id)
971 971
972/*********************** tlb/rlb shared functions *********************/ 972/*********************** tlb/rlb shared functions *********************/
973 973
974static void alb_send_learning_packets(struct slave *slave, u8 mac_addr[]) 974static void alb_send_lp_vid(struct slave *slave, u8 mac_addr[],
975 u16 vid)
975{ 976{
976 struct bonding *bond = bond_get_bond_by_slave(slave);
977 struct learning_pkt pkt; 977 struct learning_pkt pkt;
978 struct sk_buff *skb;
978 int size = sizeof(struct learning_pkt); 979 int size = sizeof(struct learning_pkt);
979 int i; 980 char *data;
980 981
981 memset(&pkt, 0, size); 982 memset(&pkt, 0, size);
982 memcpy(pkt.mac_dst, mac_addr, ETH_ALEN); 983 memcpy(pkt.mac_dst, mac_addr, ETH_ALEN);
983 memcpy(pkt.mac_src, mac_addr, ETH_ALEN); 984 memcpy(pkt.mac_src, mac_addr, ETH_ALEN);
984 pkt.type = cpu_to_be16(ETH_P_LOOP); 985 pkt.type = cpu_to_be16(ETH_P_LOOP);
985 986
986 for (i = 0; i < MAX_LP_BURST; i++) { 987 skb = dev_alloc_skb(size);
987 struct sk_buff *skb; 988 if (!skb)
988 char *data; 989 return;
990
991 data = skb_put(skb, size);
992 memcpy(data, &pkt, size);
989 993
990 skb = dev_alloc_skb(size); 994 skb_reset_mac_header(skb);
995 skb->network_header = skb->mac_header + ETH_HLEN;
996 skb->protocol = pkt.type;
997 skb->priority = TC_PRIO_CONTROL;
998 skb->dev = slave->dev;
999
1000 if (vid) {
1001 skb = vlan_put_tag(skb, htons(ETH_P_8021Q), vid);
991 if (!skb) { 1002 if (!skb) {
1003 pr_err("%s: Error: failed to insert VLAN tag\n",
1004 slave->bond->dev->name);
992 return; 1005 return;
993 } 1006 }
1007 }
994 1008
995 data = skb_put(skb, size); 1009 dev_queue_xmit(skb);
996 memcpy(data, &pkt, size); 1010}
997
998 skb_reset_mac_header(skb);
999 skb->network_header = skb->mac_header + ETH_HLEN;
1000 skb->protocol = pkt.type;
1001 skb->priority = TC_PRIO_CONTROL;
1002 skb->dev = slave->dev;
1003
1004 if (bond_vlan_used(bond)) {
1005 struct vlan_entry *vlan;
1006 1011
1007 vlan = bond_next_vlan(bond,
1008 bond->alb_info.current_alb_vlan);
1009 1012
1010 bond->alb_info.current_alb_vlan = vlan; 1013static void alb_send_learning_packets(struct slave *slave, u8 mac_addr[])
1011 if (!vlan) { 1014{
1012 kfree_skb(skb); 1015 struct bonding *bond = bond_get_bond_by_slave(slave);
1013 continue; 1016 struct net_device *upper;
1014 } 1017 struct list_head *iter;
1015 1018
1016 skb = vlan_put_tag(skb, htons(ETH_P_8021Q), vlan->vlan_id); 1019 /* send untagged */
1017 if (!skb) { 1020 alb_send_lp_vid(slave, mac_addr, 0);
1018 pr_err("%s: Error: failed to insert VLAN tag\n",
1019 bond->dev->name);
1020 continue;
1021 }
1022 }
1023 1021
1024 dev_queue_xmit(skb); 1022 /* loop through vlans and send one packet for each */
1023 rcu_read_lock();
1024 netdev_for_each_upper_dev_rcu(bond->dev, upper, iter) {
1025 if (upper->priv_flags & IFF_802_1Q_VLAN)
1026 alb_send_lp_vid(slave, mac_addr,
1027 vlan_dev_vlan_id(upper));
1025 } 1028 }
1029 rcu_read_unlock();
1026} 1030}
1027 1031
1028static int alb_set_slave_mac_addr(struct slave *slave, u8 addr[]) 1032static int alb_set_slave_mac_addr(struct slave *slave, u8 addr[])
@@ -1759,11 +1763,6 @@ int bond_alb_set_mac_address(struct net_device *bond_dev, void *addr)
1759 1763
1760void bond_alb_clear_vlan(struct bonding *bond, unsigned short vlan_id) 1764void bond_alb_clear_vlan(struct bonding *bond, unsigned short vlan_id)
1761{ 1765{
1762 if (bond->alb_info.current_alb_vlan &&
1763 (bond->alb_info.current_alb_vlan->vlan_id == vlan_id)) {
1764 bond->alb_info.current_alb_vlan = NULL;
1765 }
1766
1767 if (bond->alb_info.rlb_enabled) { 1766 if (bond->alb_info.rlb_enabled) {
1768 rlb_clear_vlan(bond, vlan_id); 1767 rlb_clear_vlan(bond, vlan_id);
1769 } 1768 }
diff --git a/drivers/net/bonding/bond_alb.h b/drivers/net/bonding/bond_alb.h
index e7a5b8b37ea3..e02c9c558c41 100644
--- a/drivers/net/bonding/bond_alb.h
+++ b/drivers/net/bonding/bond_alb.h
@@ -53,7 +53,6 @@ struct slave;
53 53
54 54
55#define TLB_NULL_INDEX 0xffffffff 55#define TLB_NULL_INDEX 0xffffffff
56#define MAX_LP_BURST 3
57 56
58/* rlb defs */ 57/* rlb defs */
59#define RLB_HASH_TABLE_SIZE 256 58#define RLB_HASH_TABLE_SIZE 256
@@ -170,7 +169,6 @@ struct alb_bond_info {
170 * rx traffic should be 169 * rx traffic should be
171 * rebalanced 170 * rebalanced
172 */ 171 */
173 struct vlan_entry *current_alb_vlan;
174}; 172};
175 173
176int bond_alb_initialize(struct bonding *bond, int rlb_enabled); 174int bond_alb_initialize(struct bonding *bond, int rlb_enabled);
diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index 7407e65f5d96..c50679f0a6b6 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -283,116 +283,6 @@ const char *bond_mode_name(int mode)
283/*---------------------------------- VLAN -----------------------------------*/ 283/*---------------------------------- VLAN -----------------------------------*/
284 284
285/** 285/**
286 * bond_add_vlan - add a new vlan id on bond
287 * @bond: bond that got the notification
288 * @vlan_id: the vlan id to add
289 *
290 * Returns -ENOMEM if allocation failed.
291 */
292static int bond_add_vlan(struct bonding *bond, unsigned short vlan_id)
293{
294 struct vlan_entry *vlan;
295
296 pr_debug("bond: %s, vlan id %d\n",
297 (bond ? bond->dev->name : "None"), vlan_id);
298
299 vlan = kzalloc(sizeof(struct vlan_entry), GFP_KERNEL);
300 if (!vlan)
301 return -ENOMEM;
302
303 INIT_LIST_HEAD(&vlan->vlan_list);
304 vlan->vlan_id = vlan_id;
305
306 write_lock_bh(&bond->lock);
307
308 list_add_tail(&vlan->vlan_list, &bond->vlan_list);
309
310 write_unlock_bh(&bond->lock);
311
312 pr_debug("added VLAN ID %d on bond %s\n", vlan_id, bond->dev->name);
313
314 return 0;
315}
316
317/**
318 * bond_del_vlan - delete a vlan id from bond
319 * @bond: bond that got the notification
320 * @vlan_id: the vlan id to delete
321 *
322 * returns -ENODEV if @vlan_id was not found in @bond.
323 */
324static int bond_del_vlan(struct bonding *bond, unsigned short vlan_id)
325{
326 struct vlan_entry *vlan;
327 int res = -ENODEV;
328
329 pr_debug("bond: %s, vlan id %d\n", bond->dev->name, vlan_id);
330
331 block_netpoll_tx();
332 write_lock_bh(&bond->lock);
333
334 list_for_each_entry(vlan, &bond->vlan_list, vlan_list) {
335 if (vlan->vlan_id == vlan_id) {
336 list_del(&vlan->vlan_list);
337
338 if (bond_is_lb(bond))
339 bond_alb_clear_vlan(bond, vlan_id);
340
341 pr_debug("removed VLAN ID %d from bond %s\n",
342 vlan_id, bond->dev->name);
343
344 kfree(vlan);
345
346 res = 0;
347 goto out;
348 }
349 }
350
351 pr_debug("couldn't find VLAN ID %d in bond %s\n",
352 vlan_id, bond->dev->name);
353
354out:
355 write_unlock_bh(&bond->lock);
356 unblock_netpoll_tx();
357 return res;
358}
359
360/**
361 * bond_next_vlan - safely skip to the next item in the vlans list.
362 * @bond: the bond we're working on
363 * @curr: item we're advancing from
364 *
365 * Returns %NULL if list is empty, bond->next_vlan if @curr is %NULL,
366 * or @curr->next otherwise (even if it is @curr itself again).
367 *
368 * Caller must hold bond->lock
369 */
370struct vlan_entry *bond_next_vlan(struct bonding *bond, struct vlan_entry *curr)
371{
372 struct vlan_entry *next, *last;
373
374 if (list_empty(&bond->vlan_list))
375 return NULL;
376
377 if (!curr) {
378 next = list_entry(bond->vlan_list.next,
379 struct vlan_entry, vlan_list);
380 } else {
381 last = list_entry(bond->vlan_list.prev,
382 struct vlan_entry, vlan_list);
383 if (last == curr) {
384 next = list_entry(bond->vlan_list.next,
385 struct vlan_entry, vlan_list);
386 } else {
387 next = list_entry(curr->vlan_list.next,
388 struct vlan_entry, vlan_list);
389 }
390 }
391
392 return next;
393}
394
395/**
396 * bond_dev_queue_xmit - Prepare skb for xmit. 286 * bond_dev_queue_xmit - Prepare skb for xmit.
397 * 287 *
398 * @bond: bond device that got this skb for tx. 288 * @bond: bond device that got this skb for tx.
@@ -451,13 +341,6 @@ static int bond_vlan_rx_add_vid(struct net_device *bond_dev,
451 goto unwind; 341 goto unwind;
452 } 342 }
453 343
454 res = bond_add_vlan(bond, vid);
455 if (res) {
456 pr_err("%s: Error: Failed to add vlan id %d\n",
457 bond_dev->name, vid);
458 goto unwind;
459 }
460
461 return 0; 344 return 0;
462 345
463unwind: 346unwind:
@@ -478,17 +361,12 @@ static int bond_vlan_rx_kill_vid(struct net_device *bond_dev,
478{ 361{
479 struct bonding *bond = netdev_priv(bond_dev); 362 struct bonding *bond = netdev_priv(bond_dev);
480 struct slave *slave; 363 struct slave *slave;
481 int res;
482 364
483 bond_for_each_slave(bond, slave) 365 bond_for_each_slave(bond, slave)
484 vlan_vid_del(slave->dev, proto, vid); 366 vlan_vid_del(slave->dev, proto, vid);
485 367
486 res = bond_del_vlan(bond, vid); 368 if (bond_is_lb(bond))
487 if (res) { 369 bond_alb_clear_vlan(bond, vid);
488 pr_err("%s: Error: Failed to remove vlan id %d\n",
489 bond_dev->name, vid);
490 return res;
491 }
492 370
493 return 0; 371 return 0;
494} 372}
@@ -1954,7 +1832,7 @@ static int __bond_release_one(struct net_device *bond_dev,
1954 bond_set_carrier(bond); 1832 bond_set_carrier(bond);
1955 eth_hw_addr_random(bond_dev); 1833 eth_hw_addr_random(bond_dev);
1956 1834
1957 if (bond_vlan_used(bond)) { 1835 if (vlan_uses_dev(bond_dev)) {
1958 pr_warning("%s: Warning: clearing HW address of %s while it still has VLANs.\n", 1836 pr_warning("%s: Warning: clearing HW address of %s while it still has VLANs.\n",
1959 bond_dev->name, bond_dev->name); 1837 bond_dev->name, bond_dev->name);
1960 pr_warning("%s: When re-adding slaves, make sure the bond's HW address matches its VLANs'.\n", 1838 pr_warning("%s: When re-adding slaves, make sure the bond's HW address matches its VLANs'.\n",
@@ -2392,24 +2270,25 @@ re_arm:
2392 } 2270 }
2393} 2271}
2394 2272
2395static int bond_has_this_ip(struct bonding *bond, __be32 ip) 2273static bool bond_has_this_ip(struct bonding *bond, __be32 ip)
2396{ 2274{
2397 struct vlan_entry *vlan; 2275 struct net_device *upper;
2398 struct net_device *vlan_dev; 2276 struct list_head *iter;
2277 bool ret = false;
2399 2278
2400 if (ip == bond_confirm_addr(bond->dev, 0, ip)) 2279 if (ip == bond_confirm_addr(bond->dev, 0, ip))
2401 return 1; 2280 return true;
2402 2281
2403 list_for_each_entry(vlan, &bond->vlan_list, vlan_list) { 2282 rcu_read_lock();
2404 rcu_read_lock(); 2283 netdev_for_each_upper_dev_rcu(bond->dev, upper, iter) {
2405 vlan_dev = __vlan_find_dev_deep(bond->dev, htons(ETH_P_8021Q), 2284 if (ip == bond_confirm_addr(upper, 0, ip)) {
2406 vlan->vlan_id); 2285 ret = true;
2407 rcu_read_unlock(); 2286 break;
2408 if (vlan_dev && ip == bond_confirm_addr(vlan_dev, 0, ip)) 2287 }
2409 return 1;
2410 } 2288 }
2289 rcu_read_unlock();
2411 2290
2412 return 0; 2291 return ret;
2413} 2292}
2414 2293
2415/* 2294/*
@@ -2444,81 +2323,79 @@ static void bond_arp_send(struct net_device *slave_dev, int arp_op, __be32 dest_
2444 2323
2445static void bond_arp_send_all(struct bonding *bond, struct slave *slave) 2324static void bond_arp_send_all(struct bonding *bond, struct slave *slave)
2446{ 2325{
2447 int i, vlan_id; 2326 struct net_device *upper, *vlan_upper;
2448 __be32 *targets = bond->params.arp_targets; 2327 struct list_head *iter, *vlan_iter;
2449 struct vlan_entry *vlan;
2450 struct net_device *vlan_dev = NULL;
2451 struct rtable *rt; 2328 struct rtable *rt;
2329 __be32 *targets = bond->params.arp_targets, addr;
2330 int i, vlan_id;
2452 2331
2453 for (i = 0; (i < BOND_MAX_ARP_TARGETS); i++) { 2332 for (i = 0; i < BOND_MAX_ARP_TARGETS && targets[i]; i++) {
2454 __be32 addr;
2455 if (!targets[i])
2456 break;
2457 pr_debug("basa: target %pI4\n", &targets[i]); 2333 pr_debug("basa: target %pI4\n", &targets[i]);
2458 if (!bond_vlan_used(bond)) {
2459 pr_debug("basa: empty vlan: arp_send\n");
2460 addr = bond_confirm_addr(bond->dev, targets[i], 0);
2461 bond_arp_send(slave->dev, ARPOP_REQUEST, targets[i],
2462 addr, 0);
2463 continue;
2464 }
2465 2334
2466 /* 2335 /* Find out through which dev should the packet go */
2467 * If VLANs are configured, we do a route lookup to
2468 * determine which VLAN interface would be used, so we
2469 * can tag the ARP with the proper VLAN tag.
2470 */
2471 rt = ip_route_output(dev_net(bond->dev), targets[i], 0, 2336 rt = ip_route_output(dev_net(bond->dev), targets[i], 0,
2472 RTO_ONLINK, 0); 2337 RTO_ONLINK, 0);
2473 if (IS_ERR(rt)) { 2338 if (IS_ERR(rt)) {
2474 if (net_ratelimit()) { 2339 pr_debug("%s: no route to arp_ip_target %pI4\n",
2475 pr_warning("%s: no route to arp_ip_target %pI4\n", 2340 bond->dev->name, &targets[i]);
2476 bond->dev->name, &targets[i]);
2477 }
2478 continue; 2341 continue;
2479 } 2342 }
2480 2343
2481 /* 2344 vlan_id = 0;
2482 * This target is not on a VLAN 2345
2346 /* bond device itself */
2347 if (rt->dst.dev == bond->dev)
2348 goto found;
2349
2350 rcu_read_lock();
2351 /* first we search only for vlan devices. for every vlan
2352 * found we verify its upper dev list, searching for the
2353 * rt->dst.dev. If found we save the tag of the vlan and
2354 * proceed to send the packet.
2355 *
2356 * TODO: QinQ?
2483 */ 2357 */
2484 if (rt->dst.dev == bond->dev) { 2358 netdev_for_each_upper_dev_rcu(bond->dev, vlan_upper, vlan_iter) {
2485 ip_rt_put(rt); 2359 if (!is_vlan_dev(vlan_upper))
2486 pr_debug("basa: rtdev == bond->dev: arp_send\n"); 2360 continue;
2487 addr = bond_confirm_addr(bond->dev, targets[i], 0); 2361 netdev_for_each_upper_dev_rcu(vlan_upper, upper, iter) {
2488 bond_arp_send(slave->dev, ARPOP_REQUEST, targets[i], 2362 if (upper == rt->dst.dev) {
2489 addr, 0); 2363 vlan_id = vlan_dev_vlan_id(vlan_upper);
2490 continue; 2364 rcu_read_unlock();
2365 goto found;
2366 }
2367 }
2491 } 2368 }
2492 2369
2493 vlan_id = 0; 2370 /* if the device we're looking for is not on top of any of
2494 list_for_each_entry(vlan, &bond->vlan_list, vlan_list) { 2371 * our upper vlans, then just search for any dev that
2495 rcu_read_lock(); 2372 * matches, and in case it's a vlan - save the id
2496 vlan_dev = __vlan_find_dev_deep(bond->dev, 2373 */
2497 htons(ETH_P_8021Q), 2374 netdev_for_each_upper_dev_rcu(bond->dev, upper, iter) {
2498 vlan->vlan_id); 2375 if (upper == rt->dst.dev) {
2499 rcu_read_unlock(); 2376 /* if it's a vlan - get its VID */
2500 if (vlan_dev == rt->dst.dev) { 2377 if (is_vlan_dev(upper))
2501 vlan_id = vlan->vlan_id; 2378 vlan_id = vlan_dev_vlan_id(upper);
2502 pr_debug("basa: vlan match on %s %d\n", 2379
2503 vlan_dev->name, vlan_id); 2380 rcu_read_unlock();
2504 break; 2381 goto found;
2505 } 2382 }
2506 } 2383 }
2384 rcu_read_unlock();
2507 2385
2508 if (vlan_id && vlan_dev) { 2386 /* Not our device - skip */
2509 ip_rt_put(rt); 2387 pr_debug("%s: no path to arp_ip_target %pI4 via rt.dev %s\n",
2510 addr = bond_confirm_addr(vlan_dev, targets[i], 0); 2388 bond->dev->name, &targets[i],
2511 bond_arp_send(slave->dev, ARPOP_REQUEST, targets[i], 2389 rt->dst.dev ? rt->dst.dev->name : "NULL");
2512 addr, vlan_id);
2513 continue;
2514 }
2515 2390
2516 if (net_ratelimit()) {
2517 pr_warning("%s: no path to arp_ip_target %pI4 via rt.dev %s\n",
2518 bond->dev->name, &targets[i],
2519 rt->dst.dev ? rt->dst.dev->name : "NULL");
2520 }
2521 ip_rt_put(rt); 2391 ip_rt_put(rt);
2392 continue;
2393
2394found:
2395 addr = bond_confirm_addr(rt->dst.dev, targets[i], 0);
2396 ip_rt_put(rt);
2397 bond_arp_send(slave->dev, ARPOP_REQUEST, targets[i],
2398 addr, vlan_id);
2522 } 2399 }
2523} 2400}
2524 2401
@@ -4142,7 +4019,6 @@ static void bond_setup(struct net_device *bond_dev)
4142 4019
4143 /* Initialize pointers */ 4020 /* Initialize pointers */
4144 bond->dev = bond_dev; 4021 bond->dev = bond_dev;
4145 INIT_LIST_HEAD(&bond->vlan_list);
4146 4022
4147 /* Initialize the device entry points */ 4023 /* Initialize the device entry points */
4148 ether_setup(bond_dev); 4024 ether_setup(bond_dev);
@@ -4195,7 +4071,6 @@ static void bond_uninit(struct net_device *bond_dev)
4195{ 4071{
4196 struct bonding *bond = netdev_priv(bond_dev); 4072 struct bonding *bond = netdev_priv(bond_dev);
4197 struct slave *slave, *tmp_slave; 4073 struct slave *slave, *tmp_slave;
4198 struct vlan_entry *vlan, *tmp;
4199 4074
4200 bond_netpoll_cleanup(bond_dev); 4075 bond_netpoll_cleanup(bond_dev);
4201 4076
@@ -4207,11 +4082,6 @@ static void bond_uninit(struct net_device *bond_dev)
4207 list_del(&bond->bond_list); 4082 list_del(&bond->bond_list);
4208 4083
4209 bond_debug_unregister(bond); 4084 bond_debug_unregister(bond);
4210
4211 list_for_each_entry_safe(vlan, tmp, &bond->vlan_list, vlan_list) {
4212 list_del(&vlan->vlan_list);
4213 kfree(vlan);
4214 }
4215} 4085}
4216 4086
4217/*------------------------- Module initialization ---------------------------*/ 4087/*------------------------- Module initialization ---------------------------*/
diff --git a/drivers/net/bonding/bonding.h b/drivers/net/bonding/bonding.h
index 4bf52d5f637e..4abc925823e1 100644
--- a/drivers/net/bonding/bonding.h
+++ b/drivers/net/bonding/bonding.h
@@ -185,11 +185,6 @@ struct bond_parm_tbl {
185 185
186#define BOND_MAX_MODENAME_LEN 20 186#define BOND_MAX_MODENAME_LEN 20
187 187
188struct vlan_entry {
189 struct list_head vlan_list;
190 unsigned short vlan_id;
191};
192
193struct slave { 188struct slave {
194 struct net_device *dev; /* first - useful for panic debug */ 189 struct net_device *dev; /* first - useful for panic debug */
195 struct list_head list; 190 struct list_head list;
@@ -254,7 +249,6 @@ struct bonding {
254 struct ad_bond_info ad_info; 249 struct ad_bond_info ad_info;
255 struct alb_bond_info alb_info; 250 struct alb_bond_info alb_info;
256 struct bond_params params; 251 struct bond_params params;
257 struct list_head vlan_list;
258 struct workqueue_struct *wq; 252 struct workqueue_struct *wq;
259 struct delayed_work mii_work; 253 struct delayed_work mii_work;
260 struct delayed_work arp_work; 254 struct delayed_work arp_work;
@@ -267,9 +261,22 @@ struct bonding {
267#endif /* CONFIG_DEBUG_FS */ 261#endif /* CONFIG_DEBUG_FS */
268}; 262};
269 263
264/* if we hold rtnl_lock() - call vlan_uses_dev() */
270static inline bool bond_vlan_used(struct bonding *bond) 265static inline bool bond_vlan_used(struct bonding *bond)
271{ 266{
272 return !list_empty(&bond->vlan_list); 267 struct net_device *upper;
268 struct list_head *iter;
269
270 rcu_read_lock();
271 netdev_for_each_upper_dev_rcu(bond->dev, upper, iter) {
272 if (upper->priv_flags & IFF_802_1Q_VLAN) {
273 rcu_read_unlock();
274 return true;
275 }
276 }
277 rcu_read_unlock();
278
279 return false;
273} 280}
274 281
275#define bond_slave_get_rcu(dev) \ 282#define bond_slave_get_rcu(dev) \
diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index 077363dcd860..3ad49b833eab 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -1125,6 +1125,7 @@ struct net_device {
1125 struct list_head napi_list; 1125 struct list_head napi_list;
1126 struct list_head unreg_list; 1126 struct list_head unreg_list;
1127 struct list_head upper_dev_list; /* List of upper devices */ 1127 struct list_head upper_dev_list; /* List of upper devices */
1128 struct list_head lower_dev_list;
1128 1129
1129 1130
1130 /* currently active device features */ 1131 /* currently active device features */
@@ -2767,6 +2768,16 @@ extern int bpf_jit_enable;
2767extern bool netdev_has_upper_dev(struct net_device *dev, 2768extern bool netdev_has_upper_dev(struct net_device *dev,
2768 struct net_device *upper_dev); 2769 struct net_device *upper_dev);
2769extern bool netdev_has_any_upper_dev(struct net_device *dev); 2770extern bool netdev_has_any_upper_dev(struct net_device *dev);
2771extern struct net_device *netdev_upper_get_next_dev_rcu(struct net_device *dev,
2772 struct list_head **iter);
2773
2774/* iterate through upper list, must be called under RCU read lock */
2775#define netdev_for_each_upper_dev_rcu(dev, upper, iter) \
2776 for (iter = &(dev)->upper_dev_list, \
2777 upper = netdev_upper_get_next_dev_rcu(dev, &(iter)); \
2778 upper; \
2779 upper = netdev_upper_get_next_dev_rcu(dev, &(iter)))
2780
2770extern struct net_device *netdev_master_upper_dev_get(struct net_device *dev); 2781extern struct net_device *netdev_master_upper_dev_get(struct net_device *dev);
2771extern struct net_device *netdev_master_upper_dev_get_rcu(struct net_device *dev); 2782extern struct net_device *netdev_master_upper_dev_get_rcu(struct net_device *dev);
2772extern int netdev_upper_dev_link(struct net_device *dev, 2783extern int netdev_upper_dev_link(struct net_device *dev,
diff --git a/net/core/dev.c b/net/core/dev.c
index 1ed2b66a10a6..6fbb0c90849b 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -4367,57 +4367,48 @@ softnet_break:
4367 goto out; 4367 goto out;
4368} 4368}
4369 4369
4370struct netdev_upper { 4370struct netdev_adjacent {
4371 struct net_device *dev; 4371 struct net_device *dev;
4372
4373 /* upper master flag, there can only be one master device per list */
4372 bool master; 4374 bool master;
4375
4376 /* indicates that this dev is our first-level lower/upper device */
4377 bool neighbour;
4378
4379 /* counter for the number of times this device was added to us */
4380 u16 ref_nr;
4381
4373 struct list_head list; 4382 struct list_head list;
4374 struct rcu_head rcu; 4383 struct rcu_head rcu;
4375 struct list_head search_list;
4376}; 4384};
4377 4385
4378static void __append_search_uppers(struct list_head *search_list, 4386static struct netdev_adjacent *__netdev_find_adj(struct net_device *dev,
4379 struct net_device *dev) 4387 struct net_device *adj_dev,
4388 bool upper)
4380{ 4389{
4381 struct netdev_upper *upper; 4390 struct netdev_adjacent *adj;
4391 struct list_head *dev_list;
4382 4392
4383 list_for_each_entry(upper, &dev->upper_dev_list, list) { 4393 dev_list = upper ? &dev->upper_dev_list : &dev->lower_dev_list;
4384 /* check if this upper is not already in search list */ 4394
4385 if (list_empty(&upper->search_list)) 4395 list_for_each_entry(adj, dev_list, list) {
4386 list_add_tail(&upper->search_list, search_list); 4396 if (adj->dev == adj_dev)
4397 return adj;
4387 } 4398 }
4399 return NULL;
4388} 4400}
4389 4401
4390static bool __netdev_search_upper_dev(struct net_device *dev, 4402static inline struct netdev_adjacent *__netdev_find_upper(struct net_device *dev,
4391 struct net_device *upper_dev) 4403 struct net_device *udev)
4392{ 4404{
4393 LIST_HEAD(search_list); 4405 return __netdev_find_adj(dev, udev, true);
4394 struct netdev_upper *upper;
4395 struct netdev_upper *tmp;
4396 bool ret = false;
4397
4398 __append_search_uppers(&search_list, dev);
4399 list_for_each_entry(upper, &search_list, search_list) {
4400 if (upper->dev == upper_dev) {
4401 ret = true;
4402 break;
4403 }
4404 __append_search_uppers(&search_list, upper->dev);
4405 }
4406 list_for_each_entry_safe(upper, tmp, &search_list, search_list)
4407 INIT_LIST_HEAD(&upper->search_list);
4408 return ret;
4409} 4406}
4410 4407
4411static struct netdev_upper *__netdev_find_upper(struct net_device *dev, 4408static inline struct netdev_adjacent *__netdev_find_lower(struct net_device *dev,
4412 struct net_device *upper_dev) 4409 struct net_device *ldev)
4413{ 4410{
4414 struct netdev_upper *upper; 4411 return __netdev_find_adj(dev, ldev, false);
4415
4416 list_for_each_entry(upper, &dev->upper_dev_list, list) {
4417 if (upper->dev == upper_dev)
4418 return upper;
4419 }
4420 return NULL;
4421} 4412}
4422 4413
4423/** 4414/**
@@ -4462,7 +4453,7 @@ EXPORT_SYMBOL(netdev_has_any_upper_dev);
4462 */ 4453 */
4463struct net_device *netdev_master_upper_dev_get(struct net_device *dev) 4454struct net_device *netdev_master_upper_dev_get(struct net_device *dev)
4464{ 4455{
4465 struct netdev_upper *upper; 4456 struct netdev_adjacent *upper;
4466 4457
4467 ASSERT_RTNL(); 4458 ASSERT_RTNL();
4468 4459
@@ -4470,13 +4461,38 @@ struct net_device *netdev_master_upper_dev_get(struct net_device *dev)
4470 return NULL; 4461 return NULL;
4471 4462
4472 upper = list_first_entry(&dev->upper_dev_list, 4463 upper = list_first_entry(&dev->upper_dev_list,
4473 struct netdev_upper, list); 4464 struct netdev_adjacent, list);
4474 if (likely(upper->master)) 4465 if (likely(upper->master))
4475 return upper->dev; 4466 return upper->dev;
4476 return NULL; 4467 return NULL;
4477} 4468}
4478EXPORT_SYMBOL(netdev_master_upper_dev_get); 4469EXPORT_SYMBOL(netdev_master_upper_dev_get);
4479 4470
4471/* netdev_upper_get_next_dev_rcu - Get the next dev from upper list
4472 * @dev: device
4473 * @iter: list_head ** of the current position
4474 *
4475 * Gets the next device from the dev's upper list, starting from iter
4476 * position. The caller must hold RCU read lock.
4477 */
4478struct net_device *netdev_upper_get_next_dev_rcu(struct net_device *dev,
4479 struct list_head **iter)
4480{
4481 struct netdev_adjacent *upper;
4482
4483 WARN_ON_ONCE(!rcu_read_lock_held());
4484
4485 upper = list_entry_rcu((*iter)->next, struct netdev_adjacent, list);
4486
4487 if (&upper->list == &dev->upper_dev_list)
4488 return NULL;
4489
4490 *iter = &upper->list;
4491
4492 return upper->dev;
4493}
4494EXPORT_SYMBOL(netdev_upper_get_next_dev_rcu);
4495
4480/** 4496/**
4481 * netdev_master_upper_dev_get_rcu - Get master upper device 4497 * netdev_master_upper_dev_get_rcu - Get master upper device
4482 * @dev: device 4498 * @dev: device
@@ -4486,20 +4502,158 @@ EXPORT_SYMBOL(netdev_master_upper_dev_get);
4486 */ 4502 */
4487struct net_device *netdev_master_upper_dev_get_rcu(struct net_device *dev) 4503struct net_device *netdev_master_upper_dev_get_rcu(struct net_device *dev)
4488{ 4504{
4489 struct netdev_upper *upper; 4505 struct netdev_adjacent *upper;
4490 4506
4491 upper = list_first_or_null_rcu(&dev->upper_dev_list, 4507 upper = list_first_or_null_rcu(&dev->upper_dev_list,
4492 struct netdev_upper, list); 4508 struct netdev_adjacent, list);
4493 if (upper && likely(upper->master)) 4509 if (upper && likely(upper->master))
4494 return upper->dev; 4510 return upper->dev;
4495 return NULL; 4511 return NULL;
4496} 4512}
4497EXPORT_SYMBOL(netdev_master_upper_dev_get_rcu); 4513EXPORT_SYMBOL(netdev_master_upper_dev_get_rcu);
4498 4514
4515static int __netdev_adjacent_dev_insert(struct net_device *dev,
4516 struct net_device *adj_dev,
4517 bool neighbour, bool master,
4518 bool upper)
4519{
4520 struct netdev_adjacent *adj;
4521
4522 adj = __netdev_find_adj(dev, adj_dev, upper);
4523
4524 if (adj) {
4525 BUG_ON(neighbour);
4526 adj->ref_nr++;
4527 return 0;
4528 }
4529
4530 adj = kmalloc(sizeof(*adj), GFP_KERNEL);
4531 if (!adj)
4532 return -ENOMEM;
4533
4534 adj->dev = adj_dev;
4535 adj->master = master;
4536 adj->neighbour = neighbour;
4537 adj->ref_nr = 1;
4538
4539 dev_hold(adj_dev);
4540 pr_debug("dev_hold for %s, because of %s link added from %s to %s\n",
4541 adj_dev->name, upper ? "upper" : "lower", dev->name,
4542 adj_dev->name);
4543
4544 if (!upper) {
4545 list_add_tail_rcu(&adj->list, &dev->lower_dev_list);
4546 return 0;
4547 }
4548
4549 /* Ensure that master upper link is always the first item in list. */
4550 if (master)
4551 list_add_rcu(&adj->list, &dev->upper_dev_list);
4552 else
4553 list_add_tail_rcu(&adj->list, &dev->upper_dev_list);
4554
4555 return 0;
4556}
4557
4558static inline int __netdev_upper_dev_insert(struct net_device *dev,
4559 struct net_device *udev,
4560 bool master, bool neighbour)
4561{
4562 return __netdev_adjacent_dev_insert(dev, udev, neighbour, master,
4563 true);
4564}
4565
4566static inline int __netdev_lower_dev_insert(struct net_device *dev,
4567 struct net_device *ldev,
4568 bool neighbour)
4569{
4570 return __netdev_adjacent_dev_insert(dev, ldev, neighbour, false,
4571 false);
4572}
4573
4574void __netdev_adjacent_dev_remove(struct net_device *dev,
4575 struct net_device *adj_dev, bool upper)
4576{
4577 struct netdev_adjacent *adj;
4578
4579 if (upper)
4580 adj = __netdev_find_upper(dev, adj_dev);
4581 else
4582 adj = __netdev_find_lower(dev, adj_dev);
4583
4584 if (!adj)
4585 BUG();
4586
4587 if (adj->ref_nr > 1) {
4588 adj->ref_nr--;
4589 return;
4590 }
4591
4592 list_del_rcu(&adj->list);
4593 pr_debug("dev_put for %s, because of %s link removed from %s to %s\n",
4594 adj_dev->name, upper ? "upper" : "lower", dev->name,
4595 adj_dev->name);
4596 dev_put(adj_dev);
4597 kfree_rcu(adj, rcu);
4598}
4599
4600static inline void __netdev_upper_dev_remove(struct net_device *dev,
4601 struct net_device *udev)
4602{
4603 return __netdev_adjacent_dev_remove(dev, udev, true);
4604}
4605
4606static inline void __netdev_lower_dev_remove(struct net_device *dev,
4607 struct net_device *ldev)
4608{
4609 return __netdev_adjacent_dev_remove(dev, ldev, false);
4610}
4611
4612int __netdev_adjacent_dev_insert_link(struct net_device *dev,
4613 struct net_device *upper_dev,
4614 bool master, bool neighbour)
4615{
4616 int ret;
4617
4618 ret = __netdev_upper_dev_insert(dev, upper_dev, master, neighbour);
4619 if (ret)
4620 return ret;
4621
4622 ret = __netdev_lower_dev_insert(upper_dev, dev, neighbour);
4623 if (ret) {
4624 __netdev_upper_dev_remove(dev, upper_dev);
4625 return ret;
4626 }
4627
4628 return 0;
4629}
4630
4631static inline int __netdev_adjacent_dev_link(struct net_device *dev,
4632 struct net_device *udev)
4633{
4634 return __netdev_adjacent_dev_insert_link(dev, udev, false, false);
4635}
4636
4637static inline int __netdev_adjacent_dev_link_neighbour(struct net_device *dev,
4638 struct net_device *udev,
4639 bool master)
4640{
4641 return __netdev_adjacent_dev_insert_link(dev, udev, master, true);
4642}
4643
4644void __netdev_adjacent_dev_unlink(struct net_device *dev,
4645 struct net_device *upper_dev)
4646{
4647 __netdev_upper_dev_remove(dev, upper_dev);
4648 __netdev_lower_dev_remove(upper_dev, dev);
4649}
4650
4651
4499static int __netdev_upper_dev_link(struct net_device *dev, 4652static int __netdev_upper_dev_link(struct net_device *dev,
4500 struct net_device *upper_dev, bool master) 4653 struct net_device *upper_dev, bool master)
4501{ 4654{
4502 struct netdev_upper *upper; 4655 struct netdev_adjacent *i, *j, *to_i, *to_j;
4656 int ret = 0;
4503 4657
4504 ASSERT_RTNL(); 4658 ASSERT_RTNL();
4505 4659
@@ -4507,7 +4661,7 @@ static int __netdev_upper_dev_link(struct net_device *dev,
4507 return -EBUSY; 4661 return -EBUSY;
4508 4662
4509 /* To prevent loops, check if dev is not upper device to upper_dev. */ 4663 /* To prevent loops, check if dev is not upper device to upper_dev. */
4510 if (__netdev_search_upper_dev(upper_dev, dev)) 4664 if (__netdev_find_upper(upper_dev, dev))
4511 return -EBUSY; 4665 return -EBUSY;
4512 4666
4513 if (__netdev_find_upper(dev, upper_dev)) 4667 if (__netdev_find_upper(dev, upper_dev))
@@ -4516,22 +4670,76 @@ static int __netdev_upper_dev_link(struct net_device *dev,
4516 if (master && netdev_master_upper_dev_get(dev)) 4670 if (master && netdev_master_upper_dev_get(dev))
4517 return -EBUSY; 4671 return -EBUSY;
4518 4672
4519 upper = kmalloc(sizeof(*upper), GFP_KERNEL); 4673 ret = __netdev_adjacent_dev_link_neighbour(dev, upper_dev, master);
4520 if (!upper) 4674 if (ret)
4521 return -ENOMEM; 4675 return ret;
4522 4676
4523 upper->dev = upper_dev; 4677 /* Now that we linked these devs, make all the upper_dev's
4524 upper->master = master; 4678 * upper_dev_list visible to every dev's lower_dev_list and vice
4525 INIT_LIST_HEAD(&upper->search_list); 4679 * versa, and don't forget the devices itself. All of these
4680 * links are non-neighbours.
4681 */
4682 list_for_each_entry(i, &upper_dev->upper_dev_list, list) {
4683 list_for_each_entry(j, &dev->lower_dev_list, list) {
4684 ret = __netdev_adjacent_dev_link(i->dev, j->dev);
4685 if (ret)
4686 goto rollback_mesh;
4687 }
4688 }
4689
4690 /* add dev to every upper_dev's upper device */
4691 list_for_each_entry(i, &upper_dev->upper_dev_list, list) {
4692 ret = __netdev_adjacent_dev_link(dev, i->dev);
4693 if (ret)
4694 goto rollback_upper_mesh;
4695 }
4696
4697 /* add upper_dev to every dev's lower device */
4698 list_for_each_entry(i, &dev->lower_dev_list, list) {
4699 ret = __netdev_adjacent_dev_link(i->dev, upper_dev);
4700 if (ret)
4701 goto rollback_lower_mesh;
4702 }
4526 4703
4527 /* Ensure that master upper link is always the first item in list. */
4528 if (master)
4529 list_add_rcu(&upper->list, &dev->upper_dev_list);
4530 else
4531 list_add_tail_rcu(&upper->list, &dev->upper_dev_list);
4532 dev_hold(upper_dev);
4533 call_netdevice_notifiers(NETDEV_CHANGEUPPER, dev); 4704 call_netdevice_notifiers(NETDEV_CHANGEUPPER, dev);
4534 return 0; 4705 return 0;
4706
4707rollback_lower_mesh:
4708 to_i = i;
4709 list_for_each_entry(i, &dev->lower_dev_list, list) {
4710 if (i == to_i)
4711 break;
4712 __netdev_adjacent_dev_unlink(i->dev, upper_dev);
4713 }
4714
4715 i = NULL;
4716
4717rollback_upper_mesh:
4718 to_i = i;
4719 list_for_each_entry(i, &upper_dev->upper_dev_list, list) {
4720 if (i == to_i)
4721 break;
4722 __netdev_adjacent_dev_unlink(dev, i->dev);
4723 }
4724
4725 i = j = NULL;
4726
4727rollback_mesh:
4728 to_i = i;
4729 to_j = j;
4730 list_for_each_entry(i, &dev->lower_dev_list, list) {
4731 list_for_each_entry(j, &upper_dev->upper_dev_list, list) {
4732 if (i == to_i && j == to_j)
4733 break;
4734 __netdev_adjacent_dev_unlink(i->dev, j->dev);
4735 }
4736 if (i == to_i)
4737 break;
4738 }
4739
4740 __netdev_adjacent_dev_unlink(dev, upper_dev);
4741
4742 return ret;
4535} 4743}
4536 4744
4537/** 4745/**
@@ -4580,16 +4788,28 @@ EXPORT_SYMBOL(netdev_master_upper_dev_link);
4580void netdev_upper_dev_unlink(struct net_device *dev, 4788void netdev_upper_dev_unlink(struct net_device *dev,
4581 struct net_device *upper_dev) 4789 struct net_device *upper_dev)
4582{ 4790{
4583 struct netdev_upper *upper; 4791 struct netdev_adjacent *i, *j;
4584
4585 ASSERT_RTNL(); 4792 ASSERT_RTNL();
4586 4793
4587 upper = __netdev_find_upper(dev, upper_dev); 4794 __netdev_adjacent_dev_unlink(dev, upper_dev);
4588 if (!upper) 4795
4589 return; 4796 /* Here is the tricky part. We must remove all dev's lower
4590 list_del_rcu(&upper->list); 4797 * devices from all upper_dev's upper devices and vice
4591 dev_put(upper_dev); 4798 * versa, to maintain the graph relationship.
4592 kfree_rcu(upper, rcu); 4799 */
4800 list_for_each_entry(i, &dev->lower_dev_list, list)
4801 list_for_each_entry(j, &upper_dev->upper_dev_list, list)
4802 __netdev_adjacent_dev_unlink(i->dev, j->dev);
4803
4804 /* remove also the devices itself from lower/upper device
4805 * list
4806 */
4807 list_for_each_entry(i, &dev->lower_dev_list, list)
4808 __netdev_adjacent_dev_unlink(i->dev, upper_dev);
4809
4810 list_for_each_entry(i, &upper_dev->upper_dev_list, list)
4811 __netdev_adjacent_dev_unlink(dev, i->dev);
4812
4593 call_netdevice_notifiers(NETDEV_CHANGEUPPER, dev); 4813 call_netdevice_notifiers(NETDEV_CHANGEUPPER, dev);
4594} 4814}
4595EXPORT_SYMBOL(netdev_upper_dev_unlink); 4815EXPORT_SYMBOL(netdev_upper_dev_unlink);
@@ -5850,6 +6070,7 @@ struct net_device *alloc_netdev_mqs(int sizeof_priv, const char *name,
5850 INIT_LIST_HEAD(&dev->unreg_list); 6070 INIT_LIST_HEAD(&dev->unreg_list);
5851 INIT_LIST_HEAD(&dev->link_watch_list); 6071 INIT_LIST_HEAD(&dev->link_watch_list);
5852 INIT_LIST_HEAD(&dev->upper_dev_list); 6072 INIT_LIST_HEAD(&dev->upper_dev_list);
6073 INIT_LIST_HEAD(&dev->lower_dev_list);
5853 dev->priv_flags = IFF_XMIT_DST_RELEASE; 6074 dev->priv_flags = IFF_XMIT_DST_RELEASE;
5854 setup(dev); 6075 setup(dev);
5855 6076