hc
2024-09-20 a36159eec6ca17402b0e146b86efaf76568dc353
kernel/drivers/net/bonding/bond_main.c
....@@ -41,6 +41,8 @@
4141 #include <linux/in.h>
4242 #include <net/ip.h>
4343 #include <linux/ip.h>
44
+#include <linux/icmp.h>
45
+#include <linux/icmpv6.h>
4446 #include <linux/tcp.h>
4547 #include <linux/udp.h>
4648 #include <linux/slab.h>
....@@ -77,7 +79,7 @@
7779 #include <net/pkt_sched.h>
7880 #include <linux/rculist.h>
7981 #include <net/flow_dissector.h>
80
-#include <net/switchdev.h>
82
+#include <net/xfrm.h>
8183 #include <net/bonding.h>
8284 #include <net/bond_3ad.h>
8385 #include <net/bond_alb.h>
....@@ -201,6 +203,51 @@
201203
202204 unsigned int bond_net_id __read_mostly;
203205
206
+static const struct flow_dissector_key flow_keys_bonding_keys[] = {
207
+ {
208
+ .key_id = FLOW_DISSECTOR_KEY_CONTROL,
209
+ .offset = offsetof(struct flow_keys, control),
210
+ },
211
+ {
212
+ .key_id = FLOW_DISSECTOR_KEY_BASIC,
213
+ .offset = offsetof(struct flow_keys, basic),
214
+ },
215
+ {
216
+ .key_id = FLOW_DISSECTOR_KEY_IPV4_ADDRS,
217
+ .offset = offsetof(struct flow_keys, addrs.v4addrs),
218
+ },
219
+ {
220
+ .key_id = FLOW_DISSECTOR_KEY_IPV6_ADDRS,
221
+ .offset = offsetof(struct flow_keys, addrs.v6addrs),
222
+ },
223
+ {
224
+ .key_id = FLOW_DISSECTOR_KEY_TIPC,
225
+ .offset = offsetof(struct flow_keys, addrs.tipckey),
226
+ },
227
+ {
228
+ .key_id = FLOW_DISSECTOR_KEY_PORTS,
229
+ .offset = offsetof(struct flow_keys, ports),
230
+ },
231
+ {
232
+ .key_id = FLOW_DISSECTOR_KEY_ICMP,
233
+ .offset = offsetof(struct flow_keys, icmp),
234
+ },
235
+ {
236
+ .key_id = FLOW_DISSECTOR_KEY_VLAN,
237
+ .offset = offsetof(struct flow_keys, vlan),
238
+ },
239
+ {
240
+ .key_id = FLOW_DISSECTOR_KEY_FLOW_LABEL,
241
+ .offset = offsetof(struct flow_keys, tags),
242
+ },
243
+ {
244
+ .key_id = FLOW_DISSECTOR_KEY_GRE_KEYID,
245
+ .offset = offsetof(struct flow_keys, keyid),
246
+ },
247
+};
248
+
249
+static struct flow_dissector flow_keys_bonding __read_mostly;
250
+
204251 /*-------------------------- Forward declarations ---------------------------*/
205252
206253 static int bond_init(struct net_device *bond_dev);
....@@ -232,8 +279,6 @@
232279 return names[mode];
233280 }
234281
235
-/*---------------------------------- VLAN -----------------------------------*/
236
-
237282 /**
238283 * bond_dev_queue_xmit - Prepare skb for xmit.
239284 *
....@@ -241,7 +286,7 @@
241286 * @skb: hw accel VLAN tagged skb to transmit
242287 * @slave_dev: slave that is supposed to xmit this skbuff
243288 */
244
-void bond_dev_queue_xmit(struct bonding *bond, struct sk_buff *skb,
289
+netdev_tx_t bond_dev_queue_xmit(struct bonding *bond, struct sk_buff *skb,
245290 struct net_device *slave_dev)
246291 {
247292 skb->dev = slave_dev;
....@@ -251,10 +296,12 @@
251296 skb_set_queue_mapping(skb, qdisc_skb_cb(skb)->slave_dev_queue_mapping);
252297
253298 if (unlikely(netpoll_tx_running(bond->dev)))
254
- bond_netpoll_send_skb(bond_get_slave_by_dev(bond, slave_dev), skb);
255
- else
256
- dev_queue_xmit(skb);
299
+ return bond_netpoll_send_skb(bond_get_slave_by_dev(bond, slave_dev), skb);
300
+
301
+ return dev_queue_xmit(skb);
257302 }
303
+
304
+/*---------------------------------- VLAN -----------------------------------*/
258305
259306 /* In the following 2 functions, bond_vlan_rx_add_vid and bond_vlan_rx_kill_vid,
260307 * We don't protect the slave list iteration with a lock because:
....@@ -275,6 +322,7 @@
275322 /**
276323 * bond_vlan_rx_add_vid - Propagates adding an id to slaves
277324 * @bond_dev: bonding net device that got called
325
+ * @proto: network protocol ID
278326 * @vid: vlan id being added
279327 */
280328 static int bond_vlan_rx_add_vid(struct net_device *bond_dev,
....@@ -308,6 +356,7 @@
308356 /**
309357 * bond_vlan_rx_kill_vid - Propagates deleting an id to slaves
310358 * @bond_dev: bonding net device that got called
359
+ * @proto: network protocol ID
311360 * @vid: vlan id being removed
312361 */
313362 static int bond_vlan_rx_kill_vid(struct net_device *bond_dev,
....@@ -325,6 +374,225 @@
325374
326375 return 0;
327376 }
377
+
378
+/*---------------------------------- XFRM -----------------------------------*/
379
+
380
+#ifdef CONFIG_XFRM_OFFLOAD
381
+/**
382
+ * bond_ipsec_add_sa - program device with a security association
383
+ * @xs: pointer to transformer state struct
384
+ **/
385
+static int bond_ipsec_add_sa(struct xfrm_state *xs)
386
+{
387
+ struct net_device *bond_dev = xs->xso.dev;
388
+ struct bond_ipsec *ipsec;
389
+ struct bonding *bond;
390
+ struct slave *slave;
391
+ int err;
392
+
393
+ if (!bond_dev)
394
+ return -EINVAL;
395
+
396
+ rcu_read_lock();
397
+ bond = netdev_priv(bond_dev);
398
+ slave = rcu_dereference(bond->curr_active_slave);
399
+ if (!slave) {
400
+ rcu_read_unlock();
401
+ return -ENODEV;
402
+ }
403
+
404
+ if (!slave->dev->xfrmdev_ops ||
405
+ !slave->dev->xfrmdev_ops->xdo_dev_state_add ||
406
+ netif_is_bond_master(slave->dev)) {
407
+ slave_warn(bond_dev, slave->dev, "Slave does not support ipsec offload\n");
408
+ rcu_read_unlock();
409
+ return -EINVAL;
410
+ }
411
+
412
+ ipsec = kmalloc(sizeof(*ipsec), GFP_ATOMIC);
413
+ if (!ipsec) {
414
+ rcu_read_unlock();
415
+ return -ENOMEM;
416
+ }
417
+ xs->xso.real_dev = slave->dev;
418
+
419
+ err = slave->dev->xfrmdev_ops->xdo_dev_state_add(xs);
420
+ if (!err) {
421
+ ipsec->xs = xs;
422
+ INIT_LIST_HEAD(&ipsec->list);
423
+ spin_lock_bh(&bond->ipsec_lock);
424
+ list_add(&ipsec->list, &bond->ipsec_list);
425
+ spin_unlock_bh(&bond->ipsec_lock);
426
+ } else {
427
+ kfree(ipsec);
428
+ }
429
+ rcu_read_unlock();
430
+ return err;
431
+}
432
+
433
+static void bond_ipsec_add_sa_all(struct bonding *bond)
434
+{
435
+ struct net_device *bond_dev = bond->dev;
436
+ struct bond_ipsec *ipsec;
437
+ struct slave *slave;
438
+
439
+ rcu_read_lock();
440
+ slave = rcu_dereference(bond->curr_active_slave);
441
+ if (!slave)
442
+ goto out;
443
+
444
+ if (!slave->dev->xfrmdev_ops ||
445
+ !slave->dev->xfrmdev_ops->xdo_dev_state_add ||
446
+ netif_is_bond_master(slave->dev)) {
447
+ spin_lock_bh(&bond->ipsec_lock);
448
+ if (!list_empty(&bond->ipsec_list))
449
+ slave_warn(bond_dev, slave->dev,
450
+ "%s: no slave xdo_dev_state_add\n",
451
+ __func__);
452
+ spin_unlock_bh(&bond->ipsec_lock);
453
+ goto out;
454
+ }
455
+
456
+ spin_lock_bh(&bond->ipsec_lock);
457
+ list_for_each_entry(ipsec, &bond->ipsec_list, list) {
458
+ ipsec->xs->xso.real_dev = slave->dev;
459
+ if (slave->dev->xfrmdev_ops->xdo_dev_state_add(ipsec->xs)) {
460
+ slave_warn(bond_dev, slave->dev, "%s: failed to add SA\n", __func__);
461
+ ipsec->xs->xso.real_dev = NULL;
462
+ }
463
+ }
464
+ spin_unlock_bh(&bond->ipsec_lock);
465
+out:
466
+ rcu_read_unlock();
467
+}
468
+
469
+/**
470
+ * bond_ipsec_del_sa - clear out this specific SA
471
+ * @xs: pointer to transformer state struct
472
+ **/
473
+static void bond_ipsec_del_sa(struct xfrm_state *xs)
474
+{
475
+ struct net_device *bond_dev = xs->xso.dev;
476
+ struct bond_ipsec *ipsec;
477
+ struct bonding *bond;
478
+ struct slave *slave;
479
+
480
+ if (!bond_dev)
481
+ return;
482
+
483
+ rcu_read_lock();
484
+ bond = netdev_priv(bond_dev);
485
+ slave = rcu_dereference(bond->curr_active_slave);
486
+
487
+ if (!slave)
488
+ goto out;
489
+
490
+ if (!xs->xso.real_dev)
491
+ goto out;
492
+
493
+ WARN_ON(xs->xso.real_dev != slave->dev);
494
+
495
+ if (!slave->dev->xfrmdev_ops ||
496
+ !slave->dev->xfrmdev_ops->xdo_dev_state_delete ||
497
+ netif_is_bond_master(slave->dev)) {
498
+ slave_warn(bond_dev, slave->dev, "%s: no slave xdo_dev_state_delete\n", __func__);
499
+ goto out;
500
+ }
501
+
502
+ slave->dev->xfrmdev_ops->xdo_dev_state_delete(xs);
503
+out:
504
+ spin_lock_bh(&bond->ipsec_lock);
505
+ list_for_each_entry(ipsec, &bond->ipsec_list, list) {
506
+ if (ipsec->xs == xs) {
507
+ list_del(&ipsec->list);
508
+ kfree(ipsec);
509
+ break;
510
+ }
511
+ }
512
+ spin_unlock_bh(&bond->ipsec_lock);
513
+ rcu_read_unlock();
514
+}
515
+
516
+static void bond_ipsec_del_sa_all(struct bonding *bond)
517
+{
518
+ struct net_device *bond_dev = bond->dev;
519
+ struct bond_ipsec *ipsec;
520
+ struct slave *slave;
521
+
522
+ rcu_read_lock();
523
+ slave = rcu_dereference(bond->curr_active_slave);
524
+ if (!slave) {
525
+ rcu_read_unlock();
526
+ return;
527
+ }
528
+
529
+ spin_lock_bh(&bond->ipsec_lock);
530
+ list_for_each_entry(ipsec, &bond->ipsec_list, list) {
531
+ if (!ipsec->xs->xso.real_dev)
532
+ continue;
533
+
534
+ if (!slave->dev->xfrmdev_ops ||
535
+ !slave->dev->xfrmdev_ops->xdo_dev_state_delete ||
536
+ netif_is_bond_master(slave->dev)) {
537
+ slave_warn(bond_dev, slave->dev,
538
+ "%s: no slave xdo_dev_state_delete\n",
539
+ __func__);
540
+ } else {
541
+ slave->dev->xfrmdev_ops->xdo_dev_state_delete(ipsec->xs);
542
+ }
543
+ ipsec->xs->xso.real_dev = NULL;
544
+ }
545
+ spin_unlock_bh(&bond->ipsec_lock);
546
+ rcu_read_unlock();
547
+}
548
+
549
+/**
550
+ * bond_ipsec_offload_ok - can this packet use the xfrm hw offload
551
+ * @skb: current data packet
552
+ * @xs: pointer to transformer state struct
553
+ **/
554
+static bool bond_ipsec_offload_ok(struct sk_buff *skb, struct xfrm_state *xs)
555
+{
556
+ struct net_device *bond_dev = xs->xso.dev;
557
+ struct net_device *real_dev;
558
+ struct slave *curr_active;
559
+ struct bonding *bond;
560
+ int err;
561
+
562
+ bond = netdev_priv(bond_dev);
563
+ rcu_read_lock();
564
+ curr_active = rcu_dereference(bond->curr_active_slave);
565
+ real_dev = curr_active->dev;
566
+
567
+ if (BOND_MODE(bond) != BOND_MODE_ACTIVEBACKUP) {
568
+ err = false;
569
+ goto out;
570
+ }
571
+
572
+ if (!xs->xso.real_dev) {
573
+ err = false;
574
+ goto out;
575
+ }
576
+
577
+ if (!real_dev->xfrmdev_ops ||
578
+ !real_dev->xfrmdev_ops->xdo_dev_offload_ok ||
579
+ netif_is_bond_master(real_dev)) {
580
+ err = false;
581
+ goto out;
582
+ }
583
+
584
+ err = real_dev->xfrmdev_ops->xdo_dev_offload_ok(skb, xs);
585
+out:
586
+ rcu_read_unlock();
587
+ return err;
588
+}
589
+
590
+static const struct xfrmdev_ops bond_xfrmdev_ops = {
591
+ .xdo_dev_state_add = bond_ipsec_add_sa,
592
+ .xdo_dev_state_delete = bond_ipsec_del_sa,
593
+ .xdo_dev_offload_ok = bond_ipsec_offload_ok,
594
+};
595
+#endif /* CONFIG_XFRM_OFFLOAD */
328596
329597 /*------------------------------- Link status -------------------------------*/
330598
....@@ -559,12 +827,8 @@
559827 dev_uc_unsync(slave_dev, bond_dev);
560828 dev_mc_unsync(slave_dev, bond_dev);
561829
562
- if (BOND_MODE(bond) == BOND_MODE_8023AD) {
563
- /* del lacpdu mc addr from mc list */
564
- u8 lacpdu_multicast[ETH_ALEN] = MULTICAST_LACPDU_ADDR;
565
-
566
- dev_mc_del(slave_dev, lacpdu_multicast);
567
- }
830
+ if (BOND_MODE(bond) == BOND_MODE_8023AD)
831
+ dev_mc_del(slave_dev, lacpdu_mcast_addr);
568832 }
569833
570834 /*--------------------------- Active slave change ---------------------------*/
....@@ -584,7 +848,8 @@
584848 if (bond->dev->flags & IFF_ALLMULTI)
585849 dev_set_allmulti(old_active->dev, -1);
586850
587
- bond_hw_addr_flush(bond->dev, old_active->dev);
851
+ if (bond->dev->flags & IFF_UP)
852
+ bond_hw_addr_flush(bond->dev, old_active->dev);
588853 }
589854
590855 if (new_active) {
....@@ -595,10 +860,12 @@
595860 if (bond->dev->flags & IFF_ALLMULTI)
596861 dev_set_allmulti(new_active->dev, 1);
597862
598
- netif_addr_lock_bh(bond->dev);
599
- dev_uc_sync(new_active->dev, bond->dev);
600
- dev_mc_sync(new_active->dev, bond->dev);
601
- netif_addr_unlock_bh(bond->dev);
863
+ if (bond->dev->flags & IFF_UP) {
864
+ netif_addr_lock_bh(bond->dev);
865
+ dev_uc_sync(new_active->dev, bond->dev);
866
+ dev_mc_sync(new_active->dev, bond->dev);
867
+ netif_addr_unlock_bh(bond->dev);
868
+ }
602869 }
603870 }
604871
....@@ -609,14 +876,21 @@
609876 *
610877 * Should be called with RTNL held.
611878 */
612
-static void bond_set_dev_addr(struct net_device *bond_dev,
613
- struct net_device *slave_dev)
879
+static int bond_set_dev_addr(struct net_device *bond_dev,
880
+ struct net_device *slave_dev)
614881 {
615
- netdev_dbg(bond_dev, "bond_dev=%p slave_dev=%p slave_dev->name=%s slave_dev->addr_len=%d\n",
616
- bond_dev, slave_dev, slave_dev->name, slave_dev->addr_len);
882
+ int err;
883
+
884
+ slave_dbg(bond_dev, slave_dev, "bond_dev=%p slave_dev=%p slave_dev->addr_len=%d\n",
885
+ bond_dev, slave_dev, slave_dev->addr_len);
886
+ err = dev_pre_changeaddr_notify(bond_dev, slave_dev->dev_addr, NULL);
887
+ if (err)
888
+ return err;
889
+
617890 memcpy(bond_dev->dev_addr, slave_dev->dev_addr, slave_dev->addr_len);
618891 bond_dev->addr_assign_type = NET_ADDR_STOLEN;
619892 call_netdevice_notifiers(NETDEV_CHANGEADDR, bond_dev);
893
+ return 0;
620894 }
621895
622896 static struct slave *bond_get_old_active(struct bonding *bond,
....@@ -652,8 +926,12 @@
652926
653927 switch (bond->params.fail_over_mac) {
654928 case BOND_FOM_ACTIVE:
655
- if (new_active)
656
- bond_set_dev_addr(bond->dev, new_active->dev);
929
+ if (new_active) {
930
+ rv = bond_set_dev_addr(bond->dev, new_active->dev);
931
+ if (rv)
932
+ slave_err(bond->dev, new_active->dev, "Error %d setting bond MAC from slave\n",
933
+ -rv);
934
+ }
657935 break;
658936 case BOND_FOM_FOLLOW:
659937 /* if new_active && old_active, swap them
....@@ -680,10 +958,10 @@
680958 }
681959
682960 rv = dev_set_mac_address(new_active->dev,
683
- (struct sockaddr *)&ss);
961
+ (struct sockaddr *)&ss, NULL);
684962 if (rv) {
685
- netdev_err(bond->dev, "Error %d setting MAC of slave %s\n",
686
- -rv, new_active->dev->name);
963
+ slave_err(bond->dev, new_active->dev, "Error %d setting MAC of new active slave\n",
964
+ -rv);
687965 goto out;
688966 }
689967
....@@ -695,10 +973,10 @@
695973 ss.ss_family = old_active->dev->type;
696974
697975 rv = dev_set_mac_address(old_active->dev,
698
- (struct sockaddr *)&ss);
976
+ (struct sockaddr *)&ss, NULL);
699977 if (rv)
700
- netdev_err(bond->dev, "Error %d setting MAC of slave %s\n",
701
- -rv, new_active->dev->name);
978
+ slave_err(bond->dev, old_active->dev, "Error %d setting MAC of old active slave\n",
979
+ -rv);
702980 out:
703981 break;
704982 default:
....@@ -783,6 +1061,8 @@
7831061 rcu_read_unlock();
7841062
7851063 if (!slave || !bond->send_peer_notif ||
1064
+ bond->send_peer_notif %
1065
+ max(1, bond->params.peer_notif_delay) != 0 ||
7861066 !netif_carrier_ok(bond->dev) ||
7871067 test_bit(__LINK_STATE_LINKWATCH_PENDING, &slave->dev->state))
7881068 return false;
....@@ -796,7 +1076,7 @@
7961076 /**
7971077 * change_active_interface - change the active slave into the specified one
7981078 * @bond: our bonding struct
799
- * @new: the new slave to make the active one
1079
+ * @new_active: the new slave to make the active one
8001080 *
8011081 * Set the new slave to the bond's settings and unset them on the old
8021082 * curr_active_slave.
....@@ -819,14 +1099,17 @@
8191099 if (old_active == new_active)
8201100 return;
8211101
1102
+#ifdef CONFIG_XFRM_OFFLOAD
1103
+ bond_ipsec_del_sa_all(bond);
1104
+#endif /* CONFIG_XFRM_OFFLOAD */
1105
+
8221106 if (new_active) {
8231107 new_active->last_link_up = jiffies;
8241108
8251109 if (new_active->link == BOND_LINK_BACK) {
8261110 if (bond_uses_primary(bond)) {
827
- netdev_info(bond->dev, "making interface %s the new active one %d ms earlier\n",
828
- new_active->dev->name,
829
- (bond->params.updelay - new_active->delay) * bond->params.miimon);
1111
+ slave_info(bond->dev, new_active->dev, "making interface the new active one %d ms earlier\n",
1112
+ (bond->params.updelay - new_active->delay) * bond->params.miimon);
8301113 }
8311114
8321115 new_active->delay = 0;
....@@ -840,8 +1123,7 @@
8401123 bond_alb_handle_link_change(bond, new_active, BOND_LINK_UP);
8411124 } else {
8421125 if (bond_uses_primary(bond)) {
843
- netdev_info(bond->dev, "making interface %s the new active one\n",
844
- new_active->dev->name);
1126
+ slave_info(bond->dev, new_active->dev, "making interface the new active one\n");
8451127 }
8461128 }
8471129 }
....@@ -878,17 +1160,24 @@
8781160
8791161 if (netif_running(bond->dev)) {
8801162 bond->send_peer_notif =
881
- bond->params.num_peer_notif;
1163
+ bond->params.num_peer_notif *
1164
+ max(1, bond->params.peer_notif_delay);
8821165 should_notify_peers =
8831166 bond_should_notify_peers(bond);
8841167 }
8851168
8861169 call_netdevice_notifiers(NETDEV_BONDING_FAILOVER, bond->dev);
887
- if (should_notify_peers)
1170
+ if (should_notify_peers) {
1171
+ bond->send_peer_notif--;
8881172 call_netdevice_notifiers(NETDEV_NOTIFY_PEERS,
8891173 bond->dev);
1174
+ }
8901175 }
8911176 }
1177
+
1178
+#ifdef CONFIG_XFRM_OFFLOAD
1179
+ bond_ipsec_add_sa_all(bond);
1180
+#endif /* CONFIG_XFRM_OFFLOAD */
8921181
8931182 /* resend IGMP joins since active slave has changed or
8941183 * all were sent on curr_active_slave.
....@@ -929,7 +1218,7 @@
9291218 return;
9301219
9311220 if (netif_carrier_ok(bond->dev))
932
- netdev_info(bond->dev, "first active interface up!\n");
1221
+ netdev_info(bond->dev, "active interface up!\n");
9331222 else
9341223 netdev_info(bond->dev, "now running without any active interface!\n");
9351224 }
....@@ -963,7 +1252,8 @@
9631252 return;
9641253
9651254 slave->np = NULL;
966
- __netpoll_free_async(np);
1255
+
1256
+ __netpoll_free(np);
9671257 }
9681258
9691259 static void bond_poll_controller(struct net_device *bond_dev)
....@@ -1066,12 +1356,20 @@
10661356 #define BOND_ENC_FEATURES (NETIF_F_HW_CSUM | NETIF_F_SG | \
10671357 NETIF_F_RXCSUM | NETIF_F_ALL_TSO)
10681358
1359
+#define BOND_MPLS_FEATURES (NETIF_F_HW_CSUM | NETIF_F_SG | \
1360
+ NETIF_F_ALL_TSO)
1361
+
1362
+
10691363 static void bond_compute_features(struct bonding *bond)
10701364 {
10711365 unsigned int dst_release_flag = IFF_XMIT_DST_RELEASE |
10721366 IFF_XMIT_DST_RELEASE_PERM;
10731367 netdev_features_t vlan_features = BOND_VLAN_FEATURES;
10741368 netdev_features_t enc_features = BOND_ENC_FEATURES;
1369
+#ifdef CONFIG_XFRM_OFFLOAD
1370
+ netdev_features_t xfrm_features = BOND_XFRM_FEATURES;
1371
+#endif /* CONFIG_XFRM_OFFLOAD */
1372
+ netdev_features_t mpls_features = BOND_MPLS_FEATURES;
10751373 struct net_device *bond_dev = bond->dev;
10761374 struct list_head *iter;
10771375 struct slave *slave;
....@@ -1082,6 +1380,7 @@
10821380 if (!bond_has_slaves(bond))
10831381 goto done;
10841382 vlan_features &= NETIF_F_ALL_FOR_ALL;
1383
+ mpls_features &= NETIF_F_ALL_FOR_ALL;
10851384
10861385 bond_for_each_slave(bond, slave, iter) {
10871386 vlan_features = netdev_increment_features(vlan_features,
....@@ -1090,6 +1389,17 @@
10901389 enc_features = netdev_increment_features(enc_features,
10911390 slave->dev->hw_enc_features,
10921391 BOND_ENC_FEATURES);
1392
+
1393
+#ifdef CONFIG_XFRM_OFFLOAD
1394
+ xfrm_features = netdev_increment_features(xfrm_features,
1395
+ slave->dev->hw_enc_features,
1396
+ BOND_XFRM_FEATURES);
1397
+#endif /* CONFIG_XFRM_OFFLOAD */
1398
+
1399
+ mpls_features = netdev_increment_features(mpls_features,
1400
+ slave->dev->mpls_features,
1401
+ BOND_MPLS_FEATURES);
1402
+
10931403 dst_release_flag &= slave->dev->priv_flags;
10941404 if (slave->dev->hard_header_len > max_hard_header_len)
10951405 max_hard_header_len = slave->dev->hard_header_len;
....@@ -1105,6 +1415,10 @@
11051415 NETIF_F_HW_VLAN_CTAG_TX |
11061416 NETIF_F_HW_VLAN_STAG_TX |
11071417 NETIF_F_GSO_UDP_L4;
1418
+#ifdef CONFIG_XFRM_OFFLOAD
1419
+ bond_dev->hw_enc_features |= xfrm_features;
1420
+#endif /* CONFIG_XFRM_OFFLOAD */
1421
+ bond_dev->mpls_features = mpls_features;
11081422 bond_dev->gso_max_segs = gso_max_segs;
11091423 netif_set_gso_max_size(bond_dev, gso_max_size);
11101424
....@@ -1128,6 +1442,11 @@
11281442
11291443 memcpy(bond_dev->broadcast, slave_dev->broadcast,
11301444 slave_dev->addr_len);
1445
+
1446
+ if (slave_dev->flags & IFF_POINTOPOINT) {
1447
+ bond_dev->flags &= ~(IFF_BROADCAST | IFF_MULTICAST);
1448
+ bond_dev->flags |= (IFF_POINTOPOINT | IFF_NOARP);
1449
+ }
11311450 }
11321451
11331452 /* On bonding slaves other than the currently active slave, suppress
....@@ -1194,7 +1513,7 @@
11941513 skb->dev = bond->dev;
11951514
11961515 if (BOND_MODE(bond) == BOND_MODE_ALB &&
1197
- bond->dev->priv_flags & IFF_BRIDGE_PORT &&
1516
+ netif_is_bridge_port(bond->dev) &&
11981517 skb->pkt_type == PACKET_HOST) {
11991518
12001519 if (unlikely(skb_cow_head(skb,
....@@ -1388,15 +1707,14 @@
13881707 if (!bond->params.use_carrier &&
13891708 slave_dev->ethtool_ops->get_link == NULL &&
13901709 slave_ops->ndo_do_ioctl == NULL) {
1391
- netdev_warn(bond_dev, "no link monitoring support for %s\n",
1392
- slave_dev->name);
1710
+ slave_warn(bond_dev, slave_dev, "no link monitoring support\n");
13931711 }
13941712
13951713 /* already in-use? */
13961714 if (netdev_is_rx_handler_busy(slave_dev)) {
13971715 NL_SET_ERR_MSG(extack, "Device is in use and cannot be enslaved");
1398
- netdev_err(bond_dev,
1399
- "Error: Device is in use and cannot be enslaved\n");
1716
+ slave_err(bond_dev, slave_dev,
1717
+ "Error: Device is in use and cannot be enslaved\n");
14001718 return -EBUSY;
14011719 }
14021720
....@@ -1409,22 +1727,20 @@
14091727 /* vlan challenged mutual exclusion */
14101728 /* no need to lock since we're protected by rtnl_lock */
14111729 if (slave_dev->features & NETIF_F_VLAN_CHALLENGED) {
1412
- netdev_dbg(bond_dev, "%s is NETIF_F_VLAN_CHALLENGED\n",
1413
- slave_dev->name);
1730
+ slave_dbg(bond_dev, slave_dev, "is NETIF_F_VLAN_CHALLENGED\n");
14141731 if (vlan_uses_dev(bond_dev)) {
14151732 NL_SET_ERR_MSG(extack, "Can not enslave VLAN challenged device to VLAN enabled bond");
1416
- netdev_err(bond_dev, "Error: cannot enslave VLAN challenged slave %s on VLAN enabled bond %s\n",
1417
- slave_dev->name, bond_dev->name);
1733
+ slave_err(bond_dev, slave_dev, "Error: cannot enslave VLAN challenged slave on VLAN enabled bond\n");
14181734 return -EPERM;
14191735 } else {
1420
- netdev_warn(bond_dev, "enslaved VLAN challenged slave %s. Adding VLANs will be blocked as long as %s is part of bond %s\n",
1421
- slave_dev->name, slave_dev->name,
1422
- bond_dev->name);
1736
+ slave_warn(bond_dev, slave_dev, "enslaved VLAN challenged slave. Adding VLANs will be blocked as long as it is part of bond.\n");
14231737 }
14241738 } else {
1425
- netdev_dbg(bond_dev, "%s is !NETIF_F_VLAN_CHALLENGED\n",
1426
- slave_dev->name);
1739
+ slave_dbg(bond_dev, slave_dev, "is !NETIF_F_VLAN_CHALLENGED\n");
14271740 }
1741
+
1742
+ if (slave_dev->features & NETIF_F_HW_ESP)
1743
+ slave_dbg(bond_dev, slave_dev, "is esp-hw-offload capable\n");
14281744
14291745 /* Old ifenslave binaries are no longer supported. These can
14301746 * be identified with moderate accuracy by the state of the slave:
....@@ -1433,8 +1749,7 @@
14331749 */
14341750 if (slave_dev->flags & IFF_UP) {
14351751 NL_SET_ERR_MSG(extack, "Device can not be enslaved while up");
1436
- netdev_err(bond_dev, "%s is up - this may be due to an out of date ifenslave\n",
1437
- slave_dev->name);
1752
+ slave_err(bond_dev, slave_dev, "slave is up - this may be due to an out of date ifenslave\n");
14381753 return -EPERM;
14391754 }
14401755
....@@ -1447,14 +1762,14 @@
14471762 */
14481763 if (!bond_has_slaves(bond)) {
14491764 if (bond_dev->type != slave_dev->type) {
1450
- netdev_dbg(bond_dev, "change device type from %d to %d\n",
1451
- bond_dev->type, slave_dev->type);
1765
+ slave_dbg(bond_dev, slave_dev, "change device type from %d to %d\n",
1766
+ bond_dev->type, slave_dev->type);
14521767
14531768 res = call_netdevice_notifiers(NETDEV_PRE_TYPE_CHANGE,
14541769 bond_dev);
14551770 res = notifier_to_errno(res);
14561771 if (res) {
1457
- netdev_err(bond_dev, "refused to change device type\n");
1772
+ slave_err(bond_dev, slave_dev, "refused to change device type\n");
14581773 return -EBUSY;
14591774 }
14601775
....@@ -1474,31 +1789,31 @@
14741789 }
14751790 } else if (bond_dev->type != slave_dev->type) {
14761791 NL_SET_ERR_MSG(extack, "Device type is different from other slaves");
1477
- netdev_err(bond_dev, "%s ether type (%d) is different from other slaves (%d), can not enslave it\n",
1478
- slave_dev->name, slave_dev->type, bond_dev->type);
1792
+ slave_err(bond_dev, slave_dev, "ether type (%d) is different from other slaves (%d), can not enslave it\n",
1793
+ slave_dev->type, bond_dev->type);
14791794 return -EINVAL;
14801795 }
14811796
14821797 if (slave_dev->type == ARPHRD_INFINIBAND &&
14831798 BOND_MODE(bond) != BOND_MODE_ACTIVEBACKUP) {
14841799 NL_SET_ERR_MSG(extack, "Only active-backup mode is supported for infiniband slaves");
1485
- netdev_warn(bond_dev, "Type (%d) supports only active-backup mode\n",
1486
- slave_dev->type);
1800
+ slave_warn(bond_dev, slave_dev, "Type (%d) supports only active-backup mode\n",
1801
+ slave_dev->type);
14871802 res = -EOPNOTSUPP;
14881803 goto err_undo_flags;
14891804 }
14901805
14911806 if (!slave_ops->ndo_set_mac_address ||
14921807 slave_dev->type == ARPHRD_INFINIBAND) {
1493
- netdev_warn(bond_dev, "The slave device specified does not support setting the MAC address\n");
1808
+ slave_warn(bond_dev, slave_dev, "The slave device specified does not support setting the MAC address\n");
14941809 if (BOND_MODE(bond) == BOND_MODE_ACTIVEBACKUP &&
14951810 bond->params.fail_over_mac != BOND_FOM_ACTIVE) {
14961811 if (!bond_has_slaves(bond)) {
14971812 bond->params.fail_over_mac = BOND_FOM_ACTIVE;
1498
- netdev_warn(bond_dev, "Setting fail_over_mac to active for active-backup mode\n");
1813
+ slave_warn(bond_dev, slave_dev, "Setting fail_over_mac to active for active-backup mode\n");
14991814 } else {
15001815 NL_SET_ERR_MSG(extack, "Slave device does not support setting the MAC address, but fail_over_mac is not set to active");
1501
- netdev_err(bond_dev, "The slave device specified does not support setting the MAC address, but fail_over_mac is not set to active\n");
1816
+ slave_err(bond_dev, slave_dev, "The slave device specified does not support setting the MAC address, but fail_over_mac is not set to active\n");
15021817 res = -EOPNOTSUPP;
15031818 goto err_undo_flags;
15041819 }
....@@ -1511,8 +1826,11 @@
15111826 * address to be the same as the slave's.
15121827 */
15131828 if (!bond_has_slaves(bond) &&
1514
- bond->dev->addr_assign_type == NET_ADDR_RANDOM)
1515
- bond_set_dev_addr(bond->dev, slave_dev);
1829
+ bond->dev->addr_assign_type == NET_ADDR_RANDOM) {
1830
+ res = bond_set_dev_addr(bond->dev, slave_dev);
1831
+ if (res)
1832
+ goto err_undo_flags;
1833
+ }
15161834
15171835 new_slave = bond_alloc_slave(bond, slave_dev);
15181836 if (!new_slave) {
....@@ -1529,7 +1847,7 @@
15291847 new_slave->original_mtu = slave_dev->mtu;
15301848 res = dev_set_mtu(slave_dev, bond->dev->mtu);
15311849 if (res) {
1532
- netdev_dbg(bond_dev, "Error %d calling dev_set_mtu\n", res);
1850
+ slave_err(bond_dev, slave_dev, "Error %d calling dev_set_mtu\n", res);
15331851 goto err_free;
15341852 }
15351853
....@@ -1547,9 +1865,10 @@
15471865 */
15481866 memcpy(ss.__data, bond_dev->dev_addr, bond_dev->addr_len);
15491867 ss.ss_family = slave_dev->type;
1550
- res = dev_set_mac_address(slave_dev, (struct sockaddr *)&ss);
1868
+ res = dev_set_mac_address(slave_dev, (struct sockaddr *)&ss,
1869
+ extack);
15511870 if (res) {
1552
- netdev_dbg(bond_dev, "Error %d calling set_mac_address\n", res);
1871
+ slave_err(bond_dev, slave_dev, "Error %d calling set_mac_address\n", res);
15531872 goto err_restore_mtu;
15541873 }
15551874 }
....@@ -1558,9 +1877,9 @@
15581877 slave_dev->flags |= IFF_SLAVE;
15591878
15601879 /* open the slave since the application closed it */
1561
- res = dev_open(slave_dev);
1880
+ res = dev_open(slave_dev, extack);
15621881 if (res) {
1563
- netdev_dbg(bond_dev, "Opening slave %s failed\n", slave_dev->name);
1882
+ slave_err(bond_dev, slave_dev, "Opening slave failed\n");
15641883 goto err_restore_mac;
15651884 }
15661885
....@@ -1579,8 +1898,7 @@
15791898
15801899 res = vlan_vids_add_by_dev(slave_dev, bond_dev);
15811900 if (res) {
1582
- netdev_err(bond_dev, "Couldn't add bond vlan ids to %s\n",
1583
- slave_dev->name);
1901
+ slave_err(bond_dev, slave_dev, "Couldn't add bond vlan ids\n");
15841902 goto err_close;
15851903 }
15861904
....@@ -1610,12 +1928,10 @@
16101928 * supported); thus, we don't need to change
16111929 * the messages for netif_carrier.
16121930 */
1613
- netdev_warn(bond_dev, "MII and ETHTOOL support not available for interface %s, and arp_interval/arp_ip_target module parameters not specified, thus bonding will not detect link failures! see bonding.txt for details\n",
1614
- slave_dev->name);
1931
+ slave_warn(bond_dev, slave_dev, "MII and ETHTOOL support not available for slave, and arp_interval/arp_ip_target module parameters not specified, thus bonding will not detect link failures! see bonding.txt for details\n");
16151932 } else if (link_reporting == -1) {
16161933 /* unable get link status using mii/ethtool */
1617
- netdev_warn(bond_dev, "can't get link status from interface %s; the network driver associated with this interface does not support MII or ETHTOOL link status reporting, thus miimon has no effect on this interface\n",
1618
- slave_dev->name);
1934
+ slave_warn(bond_dev, slave_dev, "can't get link status from slave; the network driver associated with this interface does not support MII or ETHTOOL link status reporting, thus miimon has no effect on this interface\n");
16191935 }
16201936 }
16211937
....@@ -1649,9 +1965,9 @@
16491965
16501966 if (new_slave->link != BOND_LINK_DOWN)
16511967 new_slave->last_link_up = jiffies;
1652
- netdev_dbg(bond_dev, "Initial state of slave_dev is BOND_LINK_%s\n",
1653
- new_slave->link == BOND_LINK_DOWN ? "DOWN" :
1654
- (new_slave->link == BOND_LINK_UP ? "UP" : "BACK"));
1968
+ slave_dbg(bond_dev, slave_dev, "Initial state of slave is BOND_LINK_%s\n",
1969
+ new_slave->link == BOND_LINK_DOWN ? "DOWN" :
1970
+ (new_slave->link == BOND_LINK_UP ? "UP" : "BACK"));
16551971
16561972 if (bond_uses_primary(bond) && bond->params.primary[0]) {
16571973 /* if there is a primary slave, remember it */
....@@ -1692,7 +2008,7 @@
16922008 bond_set_slave_inactive_flags(new_slave, BOND_SLAVE_NOTIFY_NOW);
16932009 break;
16942010 default:
1695
- netdev_dbg(bond_dev, "This slave is always active in trunk mode\n");
2011
+ slave_dbg(bond_dev, slave_dev, "This slave is always active in trunk mode\n");
16962012
16972013 /* always active in trunk mode */
16982014 bond_set_active_slave(new_slave);
....@@ -1711,7 +2027,7 @@
17112027 #ifdef CONFIG_NET_POLL_CONTROLLER
17122028 if (bond->dev->npinfo) {
17132029 if (slave_enable_netpoll(new_slave)) {
1714
- netdev_info(bond_dev, "master_dev is using netpoll, but new slave device does not support netpoll\n");
2030
+ slave_info(bond_dev, slave_dev, "master_dev is using netpoll, but new slave device does not support netpoll\n");
17152031 res = -EBUSY;
17162032 goto err_detach;
17172033 }
....@@ -1724,23 +2040,21 @@
17242040 res = netdev_rx_handler_register(slave_dev, bond_handle_frame,
17252041 new_slave);
17262042 if (res) {
1727
- netdev_dbg(bond_dev, "Error %d calling netdev_rx_handler_register\n", res);
2043
+ slave_dbg(bond_dev, slave_dev, "Error %d calling netdev_rx_handler_register\n", res);
17282044 goto err_detach;
17292045 }
17302046
17312047 res = bond_master_upper_dev_link(bond, new_slave, extack);
17322048 if (res) {
1733
- netdev_dbg(bond_dev, "Error %d calling bond_master_upper_dev_link\n", res);
2049
+ slave_dbg(bond_dev, slave_dev, "Error %d calling bond_master_upper_dev_link\n", res);
17342050 goto err_unregister;
17352051 }
17362052
17372053 res = bond_sysfs_slave_add(new_slave);
17382054 if (res) {
1739
- netdev_dbg(bond_dev, "Error %d calling bond_sysfs_slave_add\n", res);
2055
+ slave_dbg(bond_dev, slave_dev, "Error %d calling bond_sysfs_slave_add\n", res);
17402056 goto err_upper_unlink;
17412057 }
1742
-
1743
- bond->nest_level = dev_get_nest_level(bond_dev) + 1;
17442058
17452059 /* If the mode uses primary, then the following is handled by
17462060 * bond_change_active_slave().
....@@ -1763,16 +2077,14 @@
17632077 }
17642078 }
17652079
1766
- netif_addr_lock_bh(bond_dev);
1767
- dev_mc_sync_multiple(slave_dev, bond_dev);
1768
- dev_uc_sync_multiple(slave_dev, bond_dev);
1769
- netif_addr_unlock_bh(bond_dev);
2080
+ if (bond_dev->flags & IFF_UP) {
2081
+ netif_addr_lock_bh(bond_dev);
2082
+ dev_mc_sync_multiple(slave_dev, bond_dev);
2083
+ dev_uc_sync_multiple(slave_dev, bond_dev);
2084
+ netif_addr_unlock_bh(bond_dev);
17702085
1771
- if (BOND_MODE(bond) == BOND_MODE_8023AD) {
1772
- /* add lacpdu mc addr to mc list */
1773
- u8 lacpdu_multicast[ETH_ALEN] = MULTICAST_LACPDU_ADDR;
1774
-
1775
- dev_mc_add(slave_dev, lacpdu_multicast);
2086
+ if (BOND_MODE(bond) == BOND_MODE_8023AD)
2087
+ dev_mc_add(slave_dev, lacpdu_mcast_addr);
17762088 }
17772089 }
17782090
....@@ -1790,10 +2102,9 @@
17902102 bond_update_slave_arr(bond, NULL);
17912103
17922104
1793
- netdev_info(bond_dev, "Enslaving %s as %s interface with %s link\n",
1794
- slave_dev->name,
1795
- bond_is_active_slave(new_slave) ? "an active" : "a backup",
1796
- new_slave->link != BOND_LINK_DOWN ? "an up" : "a down");
2105
+ slave_info(bond_dev, slave_dev, "Enslaving as %s interface with %s link\n",
2106
+ bond_is_active_slave(new_slave) ? "an active" : "a backup",
2107
+ new_slave->link != BOND_LINK_DOWN ? "an up" : "a down");
17972108
17982109 /* enslave is successful */
17992110 bond_queue_slave_event(new_slave);
....@@ -1839,7 +2150,7 @@
18392150 bond_hw_addr_copy(ss.__data, new_slave->perm_hwaddr,
18402151 new_slave->dev->addr_len);
18412152 ss.ss_family = slave_dev->type;
1842
- dev_set_mac_address(slave_dev, (struct sockaddr *)&ss);
2153
+ dev_set_mac_address(slave_dev, (struct sockaddr *)&ss, NULL);
18432154 }
18442155
18452156 err_restore_mtu:
....@@ -1889,8 +2200,7 @@
18892200 /* slave is not a slave or master is not master of this slave */
18902201 if (!(slave_dev->flags & IFF_SLAVE) ||
18912202 !netdev_has_upper_dev(slave_dev, bond_dev)) {
1892
- netdev_dbg(bond_dev, "cannot release %s\n",
1893
- slave_dev->name);
2203
+ slave_dbg(bond_dev, slave_dev, "cannot release slave\n");
18942204 return -EINVAL;
18952205 }
18962206
....@@ -1899,8 +2209,7 @@
18992209 slave = bond_get_slave_by_dev(bond, slave_dev);
19002210 if (!slave) {
19012211 /* not a slave of this bond */
1902
- netdev_info(bond_dev, "%s not enslaved\n",
1903
- slave_dev->name);
2212
+ slave_info(bond_dev, slave_dev, "interface not enslaved\n");
19042213 unblock_netpoll_tx();
19052214 return -EINVAL;
19062215 }
....@@ -1925,9 +2234,8 @@
19252234 if (bond_mode_can_use_xmit_hash(bond))
19262235 bond_update_slave_arr(bond, slave);
19272236
1928
- netdev_info(bond_dev, "Releasing %s interface %s\n",
1929
- bond_is_active_slave(slave) ? "active" : "backup",
1930
- slave_dev->name);
2237
+ slave_info(bond_dev, slave_dev, "Releasing %s interface\n",
2238
+ bond_is_active_slave(slave) ? "active" : "backup");
19312239
19322240 oldcurrent = rcu_access_pointer(bond->curr_active_slave);
19332241
....@@ -1937,9 +2245,8 @@
19372245 BOND_MODE(bond) != BOND_MODE_ACTIVEBACKUP)) {
19382246 if (ether_addr_equal_64bits(bond_dev->dev_addr, slave->perm_hwaddr) &&
19392247 bond_has_slaves(bond))
1940
- netdev_warn(bond_dev, "the permanent HWaddr of %s - %pM - is still in use by %s - set the HWaddr of %s to a different address to avoid conflicts\n",
1941
- slave_dev->name, slave->perm_hwaddr,
1942
- bond_dev->name, slave_dev->name);
2248
+ slave_warn(bond_dev, slave_dev, "the permanent HWaddr of slave - %pM - is still in use by bond - set the HWaddr of slave to a different address to avoid conflicts\n",
2249
+ slave->perm_hwaddr);
19432250 }
19442251
19452252 if (rtnl_dereference(bond->primary_slave) == slave)
....@@ -1967,13 +2274,9 @@
19672274 bond_select_active_slave(bond);
19682275 }
19692276
1970
- if (!bond_has_slaves(bond)) {
1971
- bond_set_carrier(bond);
2277
+ bond_set_carrier(bond);
2278
+ if (!bond_has_slaves(bond))
19722279 eth_hw_addr_random(bond_dev);
1973
- bond->nest_level = SINGLE_DEPTH_NESTING;
1974
- } else {
1975
- bond->nest_level = dev_get_nest_level(bond_dev) + 1;
1976
- }
19772280
19782281 unblock_netpoll_tx();
19792282 synchronize_rcu();
....@@ -1987,8 +2290,7 @@
19872290 bond_compute_features(bond);
19882291 if (!(bond_dev->features & NETIF_F_VLAN_CHALLENGED) &&
19892292 (old_features & NETIF_F_VLAN_CHALLENGED))
1990
- netdev_info(bond_dev, "last VLAN challenged slave %s left bond %s - VLAN blocking is removed\n",
1991
- slave_dev->name, bond_dev->name);
2293
+ slave_info(bond_dev, slave_dev, "last VLAN challenged slave left bond - VLAN blocking is removed\n");
19922294
19932295 vlan_vids_del_by_dev(slave_dev, bond_dev);
19942296
....@@ -2010,7 +2312,8 @@
20102312 if (old_flags & IFF_ALLMULTI)
20112313 dev_set_allmulti(slave_dev, -1);
20122314
2013
- bond_hw_addr_flush(bond_dev, slave_dev);
2315
+ if (old_flags & IFF_UP)
2316
+ bond_hw_addr_flush(bond_dev, slave_dev);
20142317 }
20152318
20162319 slave_disable_netpoll(slave);
....@@ -2024,7 +2327,7 @@
20242327 bond_hw_addr_copy(ss.__data, slave->perm_hwaddr,
20252328 slave->dev->addr_len);
20262329 ss.ss_family = slave_dev->type;
2027
- dev_set_mac_address(slave_dev, (struct sockaddr *)&ss);
2330
+ dev_set_mac_address(slave_dev, (struct sockaddr *)&ss, NULL);
20282331 }
20292332
20302333 if (unregister)
....@@ -2049,8 +2352,8 @@
20492352 /* First release a slave and then destroy the bond if no more slaves are left.
20502353 * Must be under rtnl_lock when this function is called.
20512354 */
2052
-static int bond_release_and_destroy(struct net_device *bond_dev,
2053
- struct net_device *slave_dev)
2355
+static int bond_release_and_destroy(struct net_device *bond_dev,
2356
+ struct net_device *slave_dev)
20542357 {
20552358 struct bonding *bond = netdev_priv(bond_dev);
20562359 int ret;
....@@ -2059,8 +2362,7 @@
20592362 if (ret == 0 && !bond_has_slaves(bond) &&
20602363 bond_dev->reg_state != NETREG_UNREGISTERING) {
20612364 bond_dev->priv_flags |= IFF_DISABLE_NETPOLL;
2062
- netdev_info(bond_dev, "Destroying bond %s\n",
2063
- bond_dev->name);
2365
+ netdev_info(bond_dev, "Destroying bond\n");
20642366 bond_remove_proc_entry(bond);
20652367 unregister_netdevice(bond_dev);
20662368 }
....@@ -2096,12 +2398,21 @@
20962398 /* called with rcu_read_lock() */
20972399 static int bond_miimon_inspect(struct bonding *bond)
20982400 {
2401
+ bool ignore_updelay = false;
20992402 int link_state, commit = 0;
21002403 struct list_head *iter;
21012404 struct slave *slave;
2102
- bool ignore_updelay;
21032405
2104
- ignore_updelay = !rcu_dereference(bond->curr_active_slave);
2406
+ if (BOND_MODE(bond) == BOND_MODE_ACTIVEBACKUP) {
2407
+ ignore_updelay = !rcu_dereference(bond->curr_active_slave);
2408
+ } else {
2409
+ struct bond_up_slave *usable_slaves;
2410
+
2411
+ usable_slaves = rcu_dereference(bond->usable_slaves);
2412
+
2413
+ if (usable_slaves && usable_slaves->count == 0)
2414
+ ignore_updelay = true;
2415
+ }
21052416
21062417 bond_for_each_slave_rcu(bond, slave, iter) {
21072418 bond_propose_link_state(slave, BOND_LINK_NOCHANGE);
....@@ -2117,24 +2428,22 @@
21172428 commit++;
21182429 slave->delay = bond->params.downdelay;
21192430 if (slave->delay) {
2120
- netdev_info(bond->dev, "link status down for %sinterface %s, disabling it in %d ms\n",
2121
- (BOND_MODE(bond) ==
2122
- BOND_MODE_ACTIVEBACKUP) ?
2123
- (bond_is_active_slave(slave) ?
2124
- "active " : "backup ") : "",
2125
- slave->dev->name,
2126
- bond->params.downdelay * bond->params.miimon);
2431
+ slave_info(bond->dev, slave->dev, "link status down for %sinterface, disabling it in %d ms\n",
2432
+ (BOND_MODE(bond) ==
2433
+ BOND_MODE_ACTIVEBACKUP) ?
2434
+ (bond_is_active_slave(slave) ?
2435
+ "active " : "backup ") : "",
2436
+ bond->params.downdelay * bond->params.miimon);
21272437 }
2128
- /*FALLTHRU*/
2438
+ fallthrough;
21292439 case BOND_LINK_FAIL:
21302440 if (link_state) {
21312441 /* recovered before downdelay expired */
21322442 bond_propose_link_state(slave, BOND_LINK_UP);
21332443 slave->last_link_up = jiffies;
2134
- netdev_info(bond->dev, "link status up again after %d ms for interface %s\n",
2135
- (bond->params.downdelay - slave->delay) *
2136
- bond->params.miimon,
2137
- slave->dev->name);
2444
+ slave_info(bond->dev, slave->dev, "link status up again after %d ms\n",
2445
+ (bond->params.downdelay - slave->delay) *
2446
+ bond->params.miimon);
21382447 commit++;
21392448 continue;
21402449 }
....@@ -2157,20 +2466,18 @@
21572466 slave->delay = bond->params.updelay;
21582467
21592468 if (slave->delay) {
2160
- netdev_info(bond->dev, "link status up for interface %s, enabling it in %d ms\n",
2161
- slave->dev->name,
2162
- ignore_updelay ? 0 :
2163
- bond->params.updelay *
2164
- bond->params.miimon);
2469
+ slave_info(bond->dev, slave->dev, "link status up, enabling it in %d ms\n",
2470
+ ignore_updelay ? 0 :
2471
+ bond->params.updelay *
2472
+ bond->params.miimon);
21652473 }
2166
- /*FALLTHRU*/
2474
+ fallthrough;
21672475 case BOND_LINK_BACK:
21682476 if (!link_state) {
21692477 bond_propose_link_state(slave, BOND_LINK_DOWN);
2170
- netdev_info(bond->dev, "link status down again after %d ms for interface %s\n",
2171
- (bond->params.updelay - slave->delay) *
2172
- bond->params.miimon,
2173
- slave->dev->name);
2478
+ slave_info(bond->dev, slave->dev, "link status down again after %d ms\n",
2479
+ (bond->params.updelay - slave->delay) *
2480
+ bond->params.miimon);
21742481 commit++;
21752482 continue;
21762483 }
....@@ -2235,9 +2542,8 @@
22352542 bond_needs_speed_duplex(bond)) {
22362543 slave->link = BOND_LINK_DOWN;
22372544 if (net_ratelimit())
2238
- netdev_warn(bond->dev,
2239
- "failed to get link speed/duplex for %s\n",
2240
- slave->dev->name);
2545
+ slave_warn(bond->dev, slave->dev,
2546
+ "failed to get link speed/duplex\n");
22412547 continue;
22422548 }
22432549 bond_set_slave_link_state(slave, BOND_LINK_UP,
....@@ -2253,10 +2559,9 @@
22532559 bond_set_active_slave(slave);
22542560 }
22552561
2256
- netdev_info(bond->dev, "link status definitely up for interface %s, %u Mbps %s duplex\n",
2257
- slave->dev->name,
2258
- slave->speed == SPEED_UNKNOWN ? 0 : slave->speed,
2259
- slave->duplex ? "full" : "half");
2562
+ slave_info(bond->dev, slave->dev, "link status definitely up, %u Mbps %s duplex\n",
2563
+ slave->speed == SPEED_UNKNOWN ? 0 : slave->speed,
2564
+ slave->duplex ? "full" : "half");
22602565
22612566 bond_miimon_link_change(bond, slave, BOND_LINK_UP);
22622567
....@@ -2277,8 +2582,7 @@
22772582 bond_set_slave_inactive_flags(slave,
22782583 BOND_SLAVE_NOTIFY_NOW);
22792584
2280
- netdev_info(bond->dev, "link status definitely down for interface %s, disabling it\n",
2281
- slave->dev->name);
2585
+ slave_info(bond->dev, slave->dev, "link status definitely down, disabling slave\n");
22822586
22832587 bond_miimon_link_change(bond, slave, BOND_LINK_DOWN);
22842588
....@@ -2288,8 +2592,8 @@
22882592 continue;
22892593
22902594 default:
2291
- netdev_err(bond->dev, "invalid new link %d on slave %s\n",
2292
- slave->link_new_state, slave->dev->name);
2595
+ slave_err(bond->dev, slave->dev, "invalid new link %d on slave\n",
2596
+ slave->link_new_state);
22932597 bond_propose_link_state(slave, BOND_LINK_NOCHANGE);
22942598
22952599 continue;
....@@ -2316,6 +2620,7 @@
23162620 struct bonding *bond = container_of(work, struct bonding,
23172621 mii_work.work);
23182622 bool should_notify_peers = false;
2623
+ bool commit;
23192624 unsigned long delay;
23202625 struct slave *slave;
23212626 struct list_head *iter;
....@@ -2326,12 +2631,19 @@
23262631 goto re_arm;
23272632
23282633 rcu_read_lock();
2329
-
23302634 should_notify_peers = bond_should_notify_peers(bond);
2331
-
2332
- if (bond_miimon_inspect(bond)) {
2635
+ commit = !!bond_miimon_inspect(bond);
2636
+ if (bond->send_peer_notif) {
23332637 rcu_read_unlock();
2638
+ if (rtnl_trylock()) {
2639
+ bond->send_peer_notif--;
2640
+ rtnl_unlock();
2641
+ }
2642
+ } else {
2643
+ rcu_read_unlock();
2644
+ }
23342645
2646
+ if (commit) {
23352647 /* Race avoidance with bond_close cancel of workqueue */
23362648 if (!rtnl_trylock()) {
23372649 delay = 1;
....@@ -2345,8 +2657,7 @@
23452657 bond_miimon_commit(bond);
23462658
23472659 rtnl_unlock(); /* might sleep, hold no other locks */
2348
- } else
2349
- rcu_read_unlock();
2660
+ }
23502661
23512662 re_arm:
23522663 if (bond->params.miimon)
....@@ -2360,22 +2671,26 @@
23602671 }
23612672 }
23622673
2363
-static int bond_upper_dev_walk(struct net_device *upper, void *data)
2674
+static int bond_upper_dev_walk(struct net_device *upper,
2675
+ struct netdev_nested_priv *priv)
23642676 {
2365
- __be32 ip = *((__be32 *)data);
2677
+ __be32 ip = *(__be32 *)priv->data;
23662678
23672679 return ip == bond_confirm_addr(upper, 0, ip);
23682680 }
23692681
23702682 static bool bond_has_this_ip(struct bonding *bond, __be32 ip)
23712683 {
2684
+ struct netdev_nested_priv priv = {
2685
+ .data = (void *)&ip,
2686
+ };
23722687 bool ret = false;
23732688
23742689 if (ip == bond_confirm_addr(bond->dev, 0, ip))
23752690 return true;
23762691
23772692 rcu_read_lock();
2378
- if (netdev_walk_all_upper_dev_rcu(bond->dev, bond_upper_dev_walk, &ip))
2693
+ if (netdev_walk_all_upper_dev_rcu(bond->dev, bond_upper_dev_walk, &priv))
23792694 ret = true;
23802695 rcu_read_unlock();
23812696
....@@ -2386,15 +2701,16 @@
23862701 * switches in VLAN mode (especially if ports are configured as
23872702 * "native" to a VLAN) might not pass non-tagged frames.
23882703 */
2389
-static void bond_arp_send(struct net_device *slave_dev, int arp_op,
2390
- __be32 dest_ip, __be32 src_ip,
2391
- struct bond_vlan_tag *tags)
2704
+static void bond_arp_send(struct slave *slave, int arp_op, __be32 dest_ip,
2705
+ __be32 src_ip, struct bond_vlan_tag *tags)
23922706 {
23932707 struct sk_buff *skb;
23942708 struct bond_vlan_tag *outer_tag = tags;
2709
+ struct net_device *slave_dev = slave->dev;
2710
+ struct net_device *bond_dev = slave->bond->dev;
23952711
2396
- netdev_dbg(slave_dev, "arp %d on slave %s: dst %pI4 src %pI4\n",
2397
- arp_op, slave_dev->name, &dest_ip, &src_ip);
2712
+ slave_dbg(bond_dev, slave_dev, "arp %d on slave: dst %pI4 src %pI4\n",
2713
+ arp_op, &dest_ip, &src_ip);
23982714
23992715 skb = arp_create(arp_op, ETH_P_ARP, dest_ip, slave_dev, src_ip,
24002716 NULL, slave_dev->dev_addr, NULL);
....@@ -2416,8 +2732,8 @@
24162732 continue;
24172733 }
24182734
2419
- netdev_dbg(slave_dev, "inner tag: proto %X vid %X\n",
2420
- ntohs(outer_tag->vlan_proto), tags->vlan_id);
2735
+ slave_dbg(bond_dev, slave_dev, "inner tag: proto %X vid %X\n",
2736
+ ntohs(outer_tag->vlan_proto), tags->vlan_id);
24212737 skb = vlan_insert_tag_set_proto(skb, tags->vlan_proto,
24222738 tags->vlan_id);
24232739 if (!skb) {
....@@ -2429,8 +2745,8 @@
24292745 }
24302746 /* Set the outer tag */
24312747 if (outer_tag->vlan_id) {
2432
- netdev_dbg(slave_dev, "outer tag: proto %X vid %X\n",
2433
- ntohs(outer_tag->vlan_proto), outer_tag->vlan_id);
2748
+ slave_dbg(bond_dev, slave_dev, "outer tag: proto %X vid %X\n",
2749
+ ntohs(outer_tag->vlan_proto), outer_tag->vlan_id);
24342750 __vlan_hwaccel_put_tag(skb, outer_tag->vlan_proto,
24352751 outer_tag->vlan_id);
24362752 }
....@@ -2487,7 +2803,8 @@
24872803 int i;
24882804
24892805 for (i = 0; i < BOND_MAX_ARP_TARGETS && targets[i]; i++) {
2490
- netdev_dbg(bond->dev, "basa: target %pI4\n", &targets[i]);
2806
+ slave_dbg(bond->dev, slave->dev, "%s: target %pI4\n",
2807
+ __func__, &targets[i]);
24912808 tags = NULL;
24922809
24932810 /* Find out through which dev should the packet go */
....@@ -2501,7 +2818,7 @@
25012818 net_warn_ratelimited("%s: no route to arp_ip_target %pI4 and arp_validate is set\n",
25022819 bond->dev->name,
25032820 &targets[i]);
2504
- bond_arp_send(slave->dev, ARPOP_REQUEST, targets[i],
2821
+ bond_arp_send(slave, ARPOP_REQUEST, targets[i],
25052822 0, tags);
25062823 continue;
25072824 }
....@@ -2518,7 +2835,7 @@
25182835 goto found;
25192836
25202837 /* Not our device - skip */
2521
- netdev_dbg(bond->dev, "no path to arp_ip_target %pI4 via rt.dev %s\n",
2838
+ slave_dbg(bond->dev, slave->dev, "no path to arp_ip_target %pI4 via rt.dev %s\n",
25222839 &targets[i], rt->dst.dev ? rt->dst.dev->name : "NULL");
25232840
25242841 ip_rt_put(rt);
....@@ -2527,8 +2844,7 @@
25272844 found:
25282845 addr = bond_confirm_addr(rt->dst.dev, targets[i], 0);
25292846 ip_rt_put(rt);
2530
- bond_arp_send(slave->dev, ARPOP_REQUEST, targets[i],
2531
- addr, tags);
2847
+ bond_arp_send(slave, ARPOP_REQUEST, targets[i], addr, tags);
25322848 kfree(tags);
25332849 }
25342850 }
....@@ -2538,15 +2854,15 @@
25382854 int i;
25392855
25402856 if (!sip || !bond_has_this_ip(bond, tip)) {
2541
- netdev_dbg(bond->dev, "bva: sip %pI4 tip %pI4 not found\n",
2542
- &sip, &tip);
2857
+ slave_dbg(bond->dev, slave->dev, "%s: sip %pI4 tip %pI4 not found\n",
2858
+ __func__, &sip, &tip);
25432859 return;
25442860 }
25452861
25462862 i = bond_get_targets_ip(bond->params.arp_targets, sip);
25472863 if (i == -1) {
2548
- netdev_dbg(bond->dev, "bva: sip %pI4 not found in targets\n",
2549
- &sip);
2864
+ slave_dbg(bond->dev, slave->dev, "%s: sip %pI4 not found in targets\n",
2865
+ __func__, &sip);
25502866 return;
25512867 }
25522868 slave->last_rx = jiffies;
....@@ -2574,8 +2890,8 @@
25742890
25752891 alen = arp_hdr_len(bond->dev);
25762892
2577
- netdev_dbg(bond->dev, "bond_arp_rcv: skb->dev %s\n",
2578
- skb->dev->name);
2893
+ slave_dbg(bond->dev, slave->dev, "%s: skb->dev %s\n",
2894
+ __func__, skb->dev->name);
25792895
25802896 if (alen > skb_headlen(skb)) {
25812897 arp = kmalloc(alen, GFP_ATOMIC);
....@@ -2599,10 +2915,10 @@
25992915 arp_ptr += 4 + bond->dev->addr_len;
26002916 memcpy(&tip, arp_ptr, 4);
26012917
2602
- netdev_dbg(bond->dev, "bond_arp_rcv: %s/%d av %d sv %d sip %pI4 tip %pI4\n",
2603
- slave->dev->name, bond_slave_state(slave),
2604
- bond->params.arp_validate, slave_do_arp_validate(bond, slave),
2605
- &sip, &tip);
2918
+ slave_dbg(bond->dev, slave->dev, "%s: %s/%d av %d sv %d sip %pI4 tip %pI4\n",
2919
+ __func__, slave->dev->name, bond_slave_state(slave),
2920
+ bond->params.arp_validate, slave_do_arp_validate(bond, slave),
2921
+ &sip, &tip);
26062922
26072923 curr_active_slave = rcu_dereference(bond->curr_active_slave);
26082924 curr_arp_slave = rcu_dereference(bond->current_arp_slave);
....@@ -2705,12 +3021,10 @@
27053021 * is closed.
27063022 */
27073023 if (!oldcurrent) {
2708
- netdev_info(bond->dev, "link status definitely up for interface %s\n",
2709
- slave->dev->name);
3024
+ slave_info(bond->dev, slave->dev, "link status definitely up\n");
27103025 do_failover = 1;
27113026 } else {
2712
- netdev_info(bond->dev, "interface %s is now up\n",
2713
- slave->dev->name);
3027
+ slave_info(bond->dev, slave->dev, "interface is now up\n");
27143028 }
27153029 }
27163030 } else {
....@@ -2729,8 +3043,7 @@
27293043 if (slave->link_failure_count < UINT_MAX)
27303044 slave->link_failure_count++;
27313045
2732
- netdev_info(bond->dev, "interface %s is now down\n",
2733
- slave->dev->name);
3046
+ slave_info(bond->dev, slave->dev, "interface is now down\n");
27343047
27353048 if (slave == oldcurrent)
27363049 do_failover = 1;
....@@ -2883,8 +3196,7 @@
28833196 RCU_INIT_POINTER(bond->current_arp_slave, NULL);
28843197 }
28853198
2886
- netdev_info(bond->dev, "link status definitely up for interface %s\n",
2887
- slave->dev->name);
3199
+ slave_info(bond->dev, slave->dev, "link status definitely up\n");
28883200
28893201 if (!rtnl_dereference(bond->curr_active_slave) ||
28903202 slave == rtnl_dereference(bond->primary_slave))
....@@ -2903,8 +3215,7 @@
29033215 bond_set_slave_inactive_flags(slave,
29043216 BOND_SLAVE_NOTIFY_NOW);
29053217
2906
- netdev_info(bond->dev, "link status definitely down for interface %s, disabling it\n",
2907
- slave->dev->name);
3218
+ slave_info(bond->dev, slave->dev, "link status definitely down, disabling slave\n");
29083219
29093220 if (slave == rtnl_dereference(bond->curr_active_slave)) {
29103221 RCU_INIT_POINTER(bond->current_arp_slave, NULL);
....@@ -2927,8 +3238,9 @@
29273238 continue;
29283239
29293240 default:
2930
- netdev_err(bond->dev, "impossible: new_link %d on slave %s\n",
2931
- slave->link_new_state, slave->dev->name);
3241
+ slave_err(bond->dev, slave->dev,
3242
+ "impossible: link_new_state %d on slave\n",
3243
+ slave->link_new_state);
29323244 continue;
29333245 }
29343246
....@@ -2997,8 +3309,7 @@
29973309 bond_set_slave_inactive_flags(slave,
29983310 BOND_SLAVE_NOTIFY_LATER);
29993311
3000
- netdev_info(bond->dev, "backup interface %s is now down\n",
3001
- slave->dev->name);
3312
+ slave_info(bond->dev, slave->dev, "backup interface is now down\n");
30023313 }
30033314 if (slave == curr_arp_slave)
30043315 found = true;
....@@ -3069,9 +3380,11 @@
30693380 if (!rtnl_trylock())
30703381 return;
30713382
3072
- if (should_notify_peers)
3383
+ if (should_notify_peers) {
3384
+ bond->send_peer_notif--;
30733385 call_netdevice_notifiers(NETDEV_NOTIFY_PEERS,
30743386 bond->dev);
3387
+ }
30753388 if (should_notify_rtnl) {
30763389 bond_slave_state_notify(bond);
30773390 bond_slave_link_notify(bond);
....@@ -3110,18 +3423,19 @@
31103423 {
31113424 struct bonding *event_bond = netdev_priv(bond_dev);
31123425
3426
+ netdev_dbg(bond_dev, "%s called\n", __func__);
3427
+
31133428 switch (event) {
31143429 case NETDEV_CHANGENAME:
31153430 return bond_event_changename(event_bond);
31163431 case NETDEV_UNREGISTER:
31173432 bond_remove_proc_entry(event_bond);
3433
+#ifdef CONFIG_XFRM_OFFLOAD
3434
+ xfrm_dev_state_flush(dev_net(bond_dev), bond_dev, true);
3435
+#endif /* CONFIG_XFRM_OFFLOAD */
31183436 break;
31193437 case NETDEV_REGISTER:
31203438 bond_create_proc_entry(event_bond);
3121
- break;
3122
- case NETDEV_NOTIFY_PEERS:
3123
- if (event_bond->send_peer_notif)
3124
- event_bond->send_peer_notif--;
31253439 break;
31263440 default:
31273441 break;
....@@ -3141,11 +3455,16 @@
31413455 * before netdev_rx_handler_register is called in which case
31423456 * slave will be NULL
31433457 */
3144
- if (!slave)
3458
+ if (!slave) {
3459
+ netdev_dbg(slave_dev, "%s called on NULL slave\n", __func__);
31453460 return NOTIFY_DONE;
3461
+ }
3462
+
31463463 bond_dev = slave->bond->dev;
31473464 bond = slave->bond;
31483465 primary = rtnl_dereference(bond->primary_slave);
3466
+
3467
+ slave_dbg(bond_dev, slave_dev, "%s called\n", __func__);
31493468
31503469 switch (event) {
31513470 case NETDEV_UNREGISTER:
....@@ -3173,7 +3492,7 @@
31733492
31743493 if (BOND_MODE(bond) == BOND_MODE_8023AD)
31753494 bond_3ad_adapter_speed_duplex_changed(slave);
3176
- /* Fallthrough */
3495
+ fallthrough;
31773496 case NETDEV_DOWN:
31783497 /* Refresh slave-array if applicable!
31793498 * If the setup does not use miimon or arpmon (mode-specific!),
....@@ -3223,7 +3542,11 @@
32233542 unblock_netpoll_tx();
32243543 break;
32253544 case NETDEV_FEAT_CHANGE:
3226
- bond_compute_features(bond);
3545
+ if (!bond->notifier_ctx) {
3546
+ bond->notifier_ctx = true;
3547
+ bond_compute_features(bond);
3548
+ bond->notifier_ctx = false;
3549
+ }
32273550 break;
32283551 case NETDEV_RESEND_IGMP:
32293552 /* Propagate to master device */
....@@ -3248,7 +3571,8 @@
32483571 {
32493572 struct net_device *event_dev = netdev_notifier_info_to_dev(ptr);
32503573
3251
- netdev_dbg(event_dev, "event: %lx\n", event);
3574
+ netdev_dbg(event_dev, "%s received %s\n",
3575
+ __func__, netdev_cmd_to_name(event));
32523576
32533577 if (!(event_dev->priv_flags & IFF_BONDING))
32543578 return NOTIFY_DONE;
....@@ -3256,16 +3580,13 @@
32563580 if (event_dev->flags & IFF_MASTER) {
32573581 int ret;
32583582
3259
- netdev_dbg(event_dev, "IFF_MASTER\n");
32603583 ret = bond_master_netdev_event(event, event_dev);
32613584 if (ret != NOTIFY_DONE)
32623585 return ret;
32633586 }
32643587
3265
- if (event_dev->flags & IFF_SLAVE) {
3266
- netdev_dbg(event_dev, "IFF_SLAVE\n");
3588
+ if (event_dev->flags & IFF_SLAVE)
32673589 return bond_slave_netdev_event(event, event_dev);
3268
- }
32693590
32703591 return NOTIFY_DONE;
32713592 }
....@@ -3287,39 +3608,78 @@
32873608 return 0;
32883609 }
32893610
3611
+static bool bond_flow_ip(struct sk_buff *skb, struct flow_keys *fk,
3612
+ int *noff, int *proto, bool l34)
3613
+{
3614
+ const struct ipv6hdr *iph6;
3615
+ const struct iphdr *iph;
3616
+
3617
+ if (skb->protocol == htons(ETH_P_IP)) {
3618
+ if (unlikely(!pskb_may_pull(skb, *noff + sizeof(*iph))))
3619
+ return false;
3620
+ iph = (const struct iphdr *)(skb->data + *noff);
3621
+ iph_to_flow_copy_v4addrs(fk, iph);
3622
+ *noff += iph->ihl << 2;
3623
+ if (!ip_is_fragment(iph))
3624
+ *proto = iph->protocol;
3625
+ } else if (skb->protocol == htons(ETH_P_IPV6)) {
3626
+ if (unlikely(!pskb_may_pull(skb, *noff + sizeof(*iph6))))
3627
+ return false;
3628
+ iph6 = (const struct ipv6hdr *)(skb->data + *noff);
3629
+ iph_to_flow_copy_v6addrs(fk, iph6);
3630
+ *noff += sizeof(*iph6);
3631
+ *proto = iph6->nexthdr;
3632
+ } else {
3633
+ return false;
3634
+ }
3635
+
3636
+ if (l34 && *proto >= 0)
3637
+ fk->ports.ports = skb_flow_get_ports(skb, *noff, *proto);
3638
+
3639
+ return true;
3640
+}
3641
+
32903642 /* Extract the appropriate headers based on bond's xmit policy */
32913643 static bool bond_flow_dissect(struct bonding *bond, struct sk_buff *skb,
32923644 struct flow_keys *fk)
32933645 {
3294
- const struct ipv6hdr *iph6;
3295
- const struct iphdr *iph;
3646
+ bool l34 = bond->params.xmit_policy == BOND_XMIT_POLICY_LAYER34;
32963647 int noff, proto = -1;
32973648
3298
- if (bond->params.xmit_policy > BOND_XMIT_POLICY_LAYER23)
3299
- return skb_flow_dissect_flow_keys(skb, fk, 0);
3649
+ if (bond->params.xmit_policy > BOND_XMIT_POLICY_LAYER23) {
3650
+ memset(fk, 0, sizeof(*fk));
3651
+ return __skb_flow_dissect(NULL, skb, &flow_keys_bonding,
3652
+ fk, NULL, 0, 0, 0, 0);
3653
+ }
33003654
33013655 fk->ports.ports = 0;
3656
+ memset(&fk->icmp, 0, sizeof(fk->icmp));
33023657 noff = skb_network_offset(skb);
3303
- if (skb->protocol == htons(ETH_P_IP)) {
3304
- if (unlikely(!pskb_may_pull(skb, noff + sizeof(*iph))))
3305
- return false;
3306
- iph = ip_hdr(skb);
3307
- iph_to_flow_copy_v4addrs(fk, iph);
3308
- noff += iph->ihl << 2;
3309
- if (!ip_is_fragment(iph))
3310
- proto = iph->protocol;
3311
- } else if (skb->protocol == htons(ETH_P_IPV6)) {
3312
- if (unlikely(!pskb_may_pull(skb, noff + sizeof(*iph6))))
3313
- return false;
3314
- iph6 = ipv6_hdr(skb);
3315
- iph_to_flow_copy_v6addrs(fk, iph6);
3316
- noff += sizeof(*iph6);
3317
- proto = iph6->nexthdr;
3318
- } else {
3658
+ if (!bond_flow_ip(skb, fk, &noff, &proto, l34))
33193659 return false;
3660
+
3661
+ /* ICMP error packets contains at least 8 bytes of the header
3662
+ * of the packet which generated the error. Use this information
3663
+ * to correlate ICMP error packets within the same flow which
3664
+ * generated the error.
3665
+ */
3666
+ if (proto == IPPROTO_ICMP || proto == IPPROTO_ICMPV6) {
3667
+ skb_flow_get_icmp_tci(skb, &fk->icmp, skb->data,
3668
+ skb_transport_offset(skb),
3669
+ skb_headlen(skb));
3670
+ if (proto == IPPROTO_ICMP) {
3671
+ if (!icmp_is_err(fk->icmp.type))
3672
+ return true;
3673
+
3674
+ noff += sizeof(struct icmphdr);
3675
+ } else if (proto == IPPROTO_ICMPV6) {
3676
+ if (!icmpv6_is_err(fk->icmp.type))
3677
+ return true;
3678
+
3679
+ noff += sizeof(struct icmp6hdr);
3680
+ }
3681
+ return bond_flow_ip(skb, fk, &noff, &proto, l34);
33203682 }
3321
- if (bond->params.xmit_policy == BOND_XMIT_POLICY_LAYER34 && proto >= 0)
3322
- fk->ports.ports = skb_flow_get_ports(skb, noff, proto);
33233683
33243684 return true;
33253685 }
....@@ -3346,10 +3706,14 @@
33463706 return bond_eth_hash(skb);
33473707
33483708 if (bond->params.xmit_policy == BOND_XMIT_POLICY_LAYER23 ||
3349
- bond->params.xmit_policy == BOND_XMIT_POLICY_ENCAP23)
3709
+ bond->params.xmit_policy == BOND_XMIT_POLICY_ENCAP23) {
33503710 hash = bond_eth_hash(skb);
3351
- else
3352
- hash = (__force u32)flow.ports.ports;
3711
+ } else {
3712
+ if (flow.icmp.id)
3713
+ memcpy(&hash, &flow.icmp, sizeof(hash));
3714
+ else
3715
+ memcpy(&hash, &flow.ports.ports, sizeof(hash));
3716
+ }
33533717 hash ^= (__force u32)flow_get_u32_dst(&flow) ^
33543718 (__force u32)flow_get_u32_src(&flow);
33553719 hash ^= (hash >> 16);
....@@ -3424,6 +3788,9 @@
34243788 /* register to receive LACPDUs */
34253789 bond->recv_probe = bond_3ad_lacpdu_recv;
34263790 bond_3ad_initiate_agg_selection(bond, 1);
3791
+
3792
+ bond_for_each_slave(bond, slave, iter)
3793
+ dev_mc_add(slave->dev, lacpdu_mcast_addr);
34273794 }
34283795
34293796 if (bond_mode_can_use_xmit_hash(bond))
....@@ -3435,12 +3802,26 @@
34353802 static int bond_close(struct net_device *bond_dev)
34363803 {
34373804 struct bonding *bond = netdev_priv(bond_dev);
3805
+ struct slave *slave;
34383806
34393807 bond_work_cancel_all(bond);
34403808 bond->send_peer_notif = 0;
34413809 if (bond_is_lb(bond))
34423810 bond_alb_deinitialize(bond);
34433811 bond->recv_probe = NULL;
3812
+
3813
+ if (bond_uses_primary(bond)) {
3814
+ rcu_read_lock();
3815
+ slave = rcu_dereference(bond->curr_active_slave);
3816
+ if (slave)
3817
+ bond_hw_addr_flush(bond_dev, slave->dev);
3818
+ rcu_read_unlock();
3819
+ } else {
3820
+ struct list_head *iter;
3821
+
3822
+ bond_for_each_slave(bond, slave, iter)
3823
+ bond_hw_addr_flush(bond_dev, slave->dev);
3824
+ }
34443825
34453826 return 0;
34463827 }
....@@ -3474,12 +3855,46 @@
34743855 }
34753856 }
34763857
3477
-static int bond_get_nest_level(struct net_device *bond_dev)
3858
+#ifdef CONFIG_LOCKDEP
3859
+static int bond_get_lowest_level_rcu(struct net_device *dev)
34783860 {
3479
- struct bonding *bond = netdev_priv(bond_dev);
3861
+ struct net_device *ldev, *next, *now, *dev_stack[MAX_NEST_DEV + 1];
3862
+ struct list_head *niter, *iter, *iter_stack[MAX_NEST_DEV + 1];
3863
+ int cur = 0, max = 0;
34803864
3481
- return bond->nest_level;
3865
+ now = dev;
3866
+ iter = &dev->adj_list.lower;
3867
+
3868
+ while (1) {
3869
+ next = NULL;
3870
+ while (1) {
3871
+ ldev = netdev_next_lower_dev_rcu(now, &iter);
3872
+ if (!ldev)
3873
+ break;
3874
+
3875
+ next = ldev;
3876
+ niter = &ldev->adj_list.lower;
3877
+ dev_stack[cur] = now;
3878
+ iter_stack[cur++] = iter;
3879
+ if (max <= cur)
3880
+ max = cur;
3881
+ break;
3882
+ }
3883
+
3884
+ if (!next) {
3885
+ if (!cur)
3886
+ return max;
3887
+ next = dev_stack[--cur];
3888
+ niter = iter_stack[cur];
3889
+ }
3890
+
3891
+ now = next;
3892
+ iter = niter;
3893
+ }
3894
+
3895
+ return max;
34823896 }
3897
+#endif
34833898
34843899 static void bond_get_stats(struct net_device *bond_dev,
34853900 struct rtnl_link_stats64 *stats)
....@@ -3488,11 +3903,17 @@
34883903 struct rtnl_link_stats64 temp;
34893904 struct list_head *iter;
34903905 struct slave *slave;
3906
+ int nest_level = 0;
34913907
3492
- spin_lock_nested(&bond->stats_lock, bond_get_nest_level(bond_dev));
3493
- memcpy(stats, &bond->bond_stats, sizeof(*stats));
34943908
34953909 rcu_read_lock();
3910
+#ifdef CONFIG_LOCKDEP
3911
+ nest_level = bond_get_lowest_level_rcu(bond_dev);
3912
+#endif
3913
+
3914
+ spin_lock_nested(&bond->stats_lock, nest_level);
3915
+ memcpy(stats, &bond->bond_stats, sizeof(*stats));
3916
+
34963917 bond_for_each_slave_rcu(bond, slave, iter) {
34973918 const struct rtnl_link_stats64 *new =
34983919 dev_get_stats(slave->dev, &temp);
....@@ -3502,10 +3923,10 @@
35023923 /* save off the slave stats for the next run */
35033924 memcpy(&slave->slave_stats, new, sizeof(*new));
35043925 }
3505
- rcu_read_unlock();
35063926
35073927 memcpy(&bond->bond_stats, stats, sizeof(*stats));
35083928 spin_unlock(&bond->stats_lock);
3929
+ rcu_read_unlock();
35093930 }
35103931
35113932 static int bond_do_ioctl(struct net_device *bond_dev, struct ifreq *ifr, int cmd)
....@@ -3530,7 +3951,7 @@
35303951 return -EINVAL;
35313952
35323953 mii->phy_id = 0;
3533
- /* Fall Through */
3954
+ fallthrough;
35343955 case SIOCGMIIREG:
35353956 /* We do this again just in case we were called by SIOCGMIIREG
35363957 * instead of SIOCGMIIPHY.
....@@ -3582,12 +4003,11 @@
35824003
35834004 slave_dev = __dev_get_by_name(net, ifr->ifr_slave);
35844005
3585
- netdev_dbg(bond_dev, "slave_dev=%p:\n", slave_dev);
4006
+ slave_dbg(bond_dev, slave_dev, "slave_dev=%p:\n", slave_dev);
35864007
35874008 if (!slave_dev)
35884009 return -ENODEV;
35894010
3590
- netdev_dbg(bond_dev, "slave_dev->name=%s:\n", slave_dev->name);
35914011 switch (cmd) {
35924012 case BOND_ENSLAVE_OLD:
35934013 case SIOCBONDENSLAVE:
....@@ -3599,8 +4019,7 @@
35994019 break;
36004020 case BOND_SETHWADDR_OLD:
36014021 case SIOCBONDSETHWADDR:
3602
- bond_set_dev_addr(bond_dev, slave_dev);
3603
- res = 0;
4022
+ res = bond_set_dev_addr(bond_dev, slave_dev);
36044023 break;
36054024 case BOND_CHANGE_ACTIVE_OLD:
36064025 case SIOCBONDCHANGEACTIVE:
....@@ -3656,32 +4075,35 @@
36564075 const struct net_device_ops *slave_ops;
36574076 struct neigh_parms parms;
36584077 struct slave *slave;
3659
- int ret;
4078
+ int ret = 0;
36604079
3661
- slave = bond_first_slave(bond);
4080
+ rcu_read_lock();
4081
+ slave = bond_first_slave_rcu(bond);
36624082 if (!slave)
3663
- return 0;
4083
+ goto out;
36644084 slave_ops = slave->dev->netdev_ops;
36654085 if (!slave_ops->ndo_neigh_setup)
3666
- return 0;
4086
+ goto out;
36674087
3668
- parms.neigh_setup = NULL;
3669
- parms.neigh_cleanup = NULL;
3670
- ret = slave_ops->ndo_neigh_setup(slave->dev, &parms);
3671
- if (ret)
3672
- return ret;
3673
-
3674
- /* Assign slave's neigh_cleanup to neighbour in case cleanup is called
3675
- * after the last slave has been detached. Assumes that all slaves
3676
- * utilize the same neigh_cleanup (true at this writing as only user
3677
- * is ipoib).
4088
+ /* TODO: find another way [1] to implement this.
4089
+ * Passing a zeroed structure is fragile,
4090
+ * but at least we do not pass garbage.
4091
+ *
4092
+ * [1] One way would be that ndo_neigh_setup() never touch
4093
+ * struct neigh_parms, but propagate the new neigh_setup()
4094
+ * back to ___neigh_create() / neigh_parms_alloc()
36784095 */
3679
- n->parms->neigh_cleanup = parms.neigh_cleanup;
4096
+ memset(&parms, 0, sizeof(parms));
4097
+ ret = slave_ops->ndo_neigh_setup(slave->dev, &parms);
36804098
3681
- if (!parms.neigh_setup)
3682
- return 0;
4099
+ if (ret)
4100
+ goto out;
36834101
3684
- return parms.neigh_setup(n);
4102
+ if (parms.neigh_setup)
4103
+ ret = parms.neigh_setup(n);
4104
+out:
4105
+ rcu_read_unlock();
4106
+ return ret;
36854107 }
36864108
36874109 /* The bonding ndo_neigh_setup is called at init time beofre any
....@@ -3713,7 +4135,7 @@
37134135 netdev_dbg(bond_dev, "bond=%p, new_mtu=%d\n", bond, new_mtu);
37144136
37154137 bond_for_each_slave(bond, slave, iter) {
3716
- netdev_dbg(bond_dev, "s %p c_m %p\n",
4138
+ slave_dbg(bond_dev, slave->dev, "s %p c_m %p\n",
37174139 slave, slave->dev->netdev_ops->ndo_change_mtu);
37184140
37194141 res = dev_set_mtu(slave->dev, new_mtu);
....@@ -3727,8 +4149,8 @@
37274149 * means changing their mtu from timer context, which
37284150 * is probably not a good idea.
37294151 */
3730
- netdev_dbg(bond_dev, "err %d %s\n", res,
3731
- slave->dev->name);
4152
+ slave_dbg(bond_dev, slave->dev, "err %d setting mtu to %d\n",
4153
+ res, new_mtu);
37324154 goto unwind;
37334155 }
37344156 }
....@@ -3746,10 +4168,9 @@
37464168 break;
37474169
37484170 tmp_res = dev_set_mtu(rollback_slave->dev, bond_dev->mtu);
3749
- if (tmp_res) {
3750
- netdev_dbg(bond_dev, "unwind err %d dev %s\n",
3751
- tmp_res, rollback_slave->dev->name);
3752
- }
4171
+ if (tmp_res)
4172
+ slave_dbg(bond_dev, rollback_slave->dev, "unwind err %d\n",
4173
+ tmp_res);
37534174 }
37544175
37554176 return res;
....@@ -3773,7 +4194,7 @@
37734194 return bond_alb_set_mac_address(bond_dev, addr);
37744195
37754196
3776
- netdev_dbg(bond_dev, "bond=%p\n", bond);
4197
+ netdev_dbg(bond_dev, "%s: bond=%p\n", __func__, bond);
37774198
37784199 /* If fail_over_mac is enabled, do nothing and return success.
37794200 * Returning an error causes ifenslave to fail.
....@@ -3786,8 +4207,9 @@
37864207 return -EADDRNOTAVAIL;
37874208
37884209 bond_for_each_slave(bond, slave, iter) {
3789
- netdev_dbg(bond_dev, "slave %p %s\n", slave, slave->dev->name);
3790
- res = dev_set_mac_address(slave->dev, addr);
4210
+ slave_dbg(bond_dev, slave->dev, "%s: slave=%p\n",
4211
+ __func__, slave);
4212
+ res = dev_set_mac_address(slave->dev, addr, NULL);
37914213 if (res) {
37924214 /* TODO: consider downing the slave
37934215 * and retry ?
....@@ -3795,7 +4217,8 @@
37954217 * breakage anyway until ARP finish
37964218 * updating, so...
37974219 */
3798
- netdev_dbg(bond_dev, "err %d %s\n", res, slave->dev->name);
4220
+ slave_dbg(bond_dev, slave->dev, "%s: err %d\n",
4221
+ __func__, res);
37994222 goto unwind;
38004223 }
38014224 }
....@@ -3816,10 +4239,10 @@
38164239 break;
38174240
38184241 tmp_res = dev_set_mac_address(rollback_slave->dev,
3819
- (struct sockaddr *)&tmp_ss);
4242
+ (struct sockaddr *)&tmp_ss, NULL);
38204243 if (tmp_res) {
3821
- netdev_dbg(bond_dev, "unwind err %d dev %s\n",
3822
- tmp_res, rollback_slave->dev->name);
4244
+ slave_dbg(bond_dev, rollback_slave->dev, "%s: unwind err %d\n",
4245
+ __func__, tmp_res);
38234246 }
38244247 }
38254248
....@@ -3827,16 +4250,15 @@
38274250 }
38284251
38294252 /**
3830
- * bond_xmit_slave_id - transmit skb through slave with slave_id
4253
+ * bond_get_slave_by_id - get xmit slave with slave_id
38314254 * @bond: bonding device that is transmitting
3832
- * @skb: buffer to transmit
38334255 * @slave_id: slave id up to slave_cnt-1 through which to transmit
38344256 *
3835
- * This function tries to transmit through slave with slave_id but in case
4257
+ * This function tries to get slave with slave_id but in case
38364258 * it fails, it tries to find the first available slave for transmission.
3837
- * The skb is consumed in all cases, thus the function is void.
38384259 */
3839
-static void bond_xmit_slave_id(struct bonding *bond, struct sk_buff *skb, int slave_id)
4260
+static struct slave *bond_get_slave_by_id(struct bonding *bond,
4261
+ int slave_id)
38404262 {
38414263 struct list_head *iter;
38424264 struct slave *slave;
....@@ -3845,10 +4267,8 @@
38454267 /* Here we start from the slave with slave_id */
38464268 bond_for_each_slave_rcu(bond, slave, iter) {
38474269 if (--i < 0) {
3848
- if (bond_slave_can_tx(slave)) {
3849
- bond_dev_queue_xmit(bond, skb, slave->dev);
3850
- return;
3851
- }
4270
+ if (bond_slave_can_tx(slave))
4271
+ return slave;
38524272 }
38534273 }
38544274
....@@ -3857,13 +4277,11 @@
38574277 bond_for_each_slave_rcu(bond, slave, iter) {
38584278 if (--i < 0)
38594279 break;
3860
- if (bond_slave_can_tx(slave)) {
3861
- bond_dev_queue_xmit(bond, skb, slave->dev);
3862
- return;
3863
- }
4280
+ if (bond_slave_can_tx(slave))
4281
+ return slave;
38644282 }
38654283 /* no slave that can tx has been found */
3866
- bond_tx_drop(bond->dev, skb);
4284
+ return NULL;
38674285 }
38684286
38694287 /**
....@@ -3899,10 +4317,9 @@
38994317 return slave_id;
39004318 }
39014319
3902
-static netdev_tx_t bond_xmit_roundrobin(struct sk_buff *skb,
3903
- struct net_device *bond_dev)
4320
+static struct slave *bond_xmit_roundrobin_slave_get(struct bonding *bond,
4321
+ struct sk_buff *skb)
39044322 {
3905
- struct bonding *bond = netdev_priv(bond_dev);
39064323 struct slave *slave;
39074324 int slave_cnt;
39084325 u32 slave_id;
....@@ -3924,22 +4341,37 @@
39244341 if (iph->protocol == IPPROTO_IGMP) {
39254342 slave = rcu_dereference(bond->curr_active_slave);
39264343 if (slave)
3927
- bond_dev_queue_xmit(bond, skb, slave->dev);
3928
- else
3929
- bond_xmit_slave_id(bond, skb, 0);
3930
- return NETDEV_TX_OK;
4344
+ return slave;
4345
+ return bond_get_slave_by_id(bond, 0);
39314346 }
39324347 }
39334348
39344349 non_igmp:
39354350 slave_cnt = READ_ONCE(bond->slave_cnt);
39364351 if (likely(slave_cnt)) {
3937
- slave_id = bond_rr_gen_slave_id(bond);
3938
- bond_xmit_slave_id(bond, skb, slave_id % slave_cnt);
3939
- } else {
3940
- bond_tx_drop(bond_dev, skb);
4352
+ slave_id = bond_rr_gen_slave_id(bond) % slave_cnt;
4353
+ return bond_get_slave_by_id(bond, slave_id);
39414354 }
3942
- return NETDEV_TX_OK;
4355
+ return NULL;
4356
+}
4357
+
4358
+static netdev_tx_t bond_xmit_roundrobin(struct sk_buff *skb,
4359
+ struct net_device *bond_dev)
4360
+{
4361
+ struct bonding *bond = netdev_priv(bond_dev);
4362
+ struct slave *slave;
4363
+
4364
+ slave = bond_xmit_roundrobin_slave_get(bond, skb);
4365
+ if (likely(slave))
4366
+ return bond_dev_queue_xmit(bond, skb, slave->dev);
4367
+
4368
+ return bond_tx_drop(bond_dev, skb);
4369
+}
4370
+
4371
+static struct slave *bond_xmit_activebackup_slave_get(struct bonding *bond,
4372
+ struct sk_buff *skb)
4373
+{
4374
+ return rcu_dereference(bond->curr_active_slave);
39434375 }
39444376
39454377 /* In active-backup mode, we know that bond->curr_active_slave is always valid if
....@@ -3951,13 +4383,11 @@
39514383 struct bonding *bond = netdev_priv(bond_dev);
39524384 struct slave *slave;
39534385
3954
- slave = rcu_dereference(bond->curr_active_slave);
4386
+ slave = bond_xmit_activebackup_slave_get(bond, skb);
39554387 if (slave)
3956
- bond_dev_queue_xmit(bond, skb, slave->dev);
3957
- else
3958
- bond_tx_drop(bond_dev, skb);
4388
+ return bond_dev_queue_xmit(bond, skb, slave->dev);
39594389
3960
- return NETDEV_TX_OK;
4390
+ return bond_tx_drop(bond_dev, skb);
39614391 }
39624392
39634393 /* Use this to update slave_array when (a) it's not appropriate to update
....@@ -3991,6 +4421,61 @@
39914421 bond_slave_arr_work_rearm(bond, 1);
39924422 }
39934423
4424
+static void bond_skip_slave(struct bond_up_slave *slaves,
4425
+ struct slave *skipslave)
4426
+{
4427
+ int idx;
4428
+
4429
+ /* Rare situation where caller has asked to skip a specific
4430
+ * slave but allocation failed (most likely!). BTW this is
4431
+ * only possible when the call is initiated from
4432
+ * __bond_release_one(). In this situation; overwrite the
4433
+ * skipslave entry in the array with the last entry from the
4434
+ * array to avoid a situation where the xmit path may choose
4435
+ * this to-be-skipped slave to send a packet out.
4436
+ */
4437
+ for (idx = 0; slaves && idx < slaves->count; idx++) {
4438
+ if (skipslave == slaves->arr[idx]) {
4439
+ slaves->arr[idx] =
4440
+ slaves->arr[slaves->count - 1];
4441
+ slaves->count--;
4442
+ break;
4443
+ }
4444
+ }
4445
+}
4446
+
4447
+static void bond_set_slave_arr(struct bonding *bond,
4448
+ struct bond_up_slave *usable_slaves,
4449
+ struct bond_up_slave *all_slaves)
4450
+{
4451
+ struct bond_up_slave *usable, *all;
4452
+
4453
+ usable = rtnl_dereference(bond->usable_slaves);
4454
+ rcu_assign_pointer(bond->usable_slaves, usable_slaves);
4455
+ kfree_rcu(usable, rcu);
4456
+
4457
+ all = rtnl_dereference(bond->all_slaves);
4458
+ rcu_assign_pointer(bond->all_slaves, all_slaves);
4459
+ kfree_rcu(all, rcu);
4460
+}
4461
+
4462
+static void bond_reset_slave_arr(struct bonding *bond)
4463
+{
4464
+ struct bond_up_slave *usable, *all;
4465
+
4466
+ usable = rtnl_dereference(bond->usable_slaves);
4467
+ if (usable) {
4468
+ RCU_INIT_POINTER(bond->usable_slaves, NULL);
4469
+ kfree_rcu(usable, rcu);
4470
+ }
4471
+
4472
+ all = rtnl_dereference(bond->all_slaves);
4473
+ if (all) {
4474
+ RCU_INIT_POINTER(bond->all_slaves, NULL);
4475
+ kfree_rcu(all, rcu);
4476
+ }
4477
+}
4478
+
39944479 /* Build the usable slaves array in control path for modes that use xmit-hash
39954480 * to determine the slave interface -
39964481 * (a) BOND_MODE_8023AD
....@@ -4001,9 +4486,9 @@
40014486 */
40024487 int bond_update_slave_arr(struct bonding *bond, struct slave *skipslave)
40034488 {
4489
+ struct bond_up_slave *usable_slaves = NULL, *all_slaves = NULL;
40044490 struct slave *slave;
40054491 struct list_head *iter;
4006
- struct bond_up_slave *new_arr, *old_arr;
40074492 int agg_id = 0;
40084493 int ret = 0;
40094494
....@@ -4011,11 +4496,12 @@
40114496 WARN_ON(lockdep_is_held(&bond->mode_lock));
40124497 #endif
40134498
4014
- new_arr = kzalloc(offsetof(struct bond_up_slave, arr[bond->slave_cnt]),
4015
- GFP_KERNEL);
4016
- if (!new_arr) {
4499
+ usable_slaves = kzalloc(struct_size(usable_slaves, arr,
4500
+ bond->slave_cnt), GFP_KERNEL);
4501
+ all_slaves = kzalloc(struct_size(all_slaves, arr,
4502
+ bond->slave_cnt), GFP_KERNEL);
4503
+ if (!usable_slaves || !all_slaves) {
40174504 ret = -ENOMEM;
4018
- pr_err("Failed to build slave-array.\n");
40194505 goto out;
40204506 }
40214507 if (BOND_MODE(bond) == BOND_MODE_8023AD) {
....@@ -4023,20 +4509,19 @@
40234509
40244510 if (bond_3ad_get_active_agg_info(bond, &ad_info)) {
40254511 pr_debug("bond_3ad_get_active_agg_info failed\n");
4026
- kfree_rcu(new_arr, rcu);
40274512 /* No active aggragator means it's not safe to use
40284513 * the previous array.
40294514 */
4030
- old_arr = rtnl_dereference(bond->slave_arr);
4031
- if (old_arr) {
4032
- RCU_INIT_POINTER(bond->slave_arr, NULL);
4033
- kfree_rcu(old_arr, rcu);
4034
- }
4515
+ bond_reset_slave_arr(bond);
40354516 goto out;
40364517 }
40374518 agg_id = ad_info.aggregator_id;
40384519 }
40394520 bond_for_each_slave(bond, slave, iter) {
4521
+ if (skipslave == slave)
4522
+ continue;
4523
+
4524
+ all_slaves->arr[all_slaves->count++] = slave;
40404525 if (BOND_MODE(bond) == BOND_MODE_8023AD) {
40414526 struct aggregator *agg;
40424527
....@@ -4046,43 +4531,43 @@
40464531 }
40474532 if (!bond_slave_can_tx(slave))
40484533 continue;
4049
- if (skipslave == slave)
4050
- continue;
40514534
4052
- netdev_dbg(bond->dev,
4053
- "Adding slave dev %s to tx hash array[%d]\n",
4054
- slave->dev->name, new_arr->count);
4535
+ slave_dbg(bond->dev, slave->dev, "Adding slave to tx hash array[%d]\n",
4536
+ usable_slaves->count);
40554537
4056
- new_arr->arr[new_arr->count++] = slave;
4538
+ usable_slaves->arr[usable_slaves->count++] = slave;
40574539 }
40584540
4059
- old_arr = rtnl_dereference(bond->slave_arr);
4060
- rcu_assign_pointer(bond->slave_arr, new_arr);
4061
- if (old_arr)
4062
- kfree_rcu(old_arr, rcu);
4541
+ bond_set_slave_arr(bond, usable_slaves, all_slaves);
4542
+ return ret;
40634543 out:
40644544 if (ret != 0 && skipslave) {
4065
- int idx;
4066
-
4067
- /* Rare situation where caller has asked to skip a specific
4068
- * slave but allocation failed (most likely!). BTW this is
4069
- * only possible when the call is initiated from
4070
- * __bond_release_one(). In this situation; overwrite the
4071
- * skipslave entry in the array with the last entry from the
4072
- * array to avoid a situation where the xmit path may choose
4073
- * this to-be-skipped slave to send a packet out.
4074
- */
4075
- old_arr = rtnl_dereference(bond->slave_arr);
4076
- for (idx = 0; old_arr != NULL && idx < old_arr->count; idx++) {
4077
- if (skipslave == old_arr->arr[idx]) {
4078
- old_arr->arr[idx] =
4079
- old_arr->arr[old_arr->count-1];
4080
- old_arr->count--;
4081
- break;
4082
- }
4083
- }
4545
+ bond_skip_slave(rtnl_dereference(bond->all_slaves),
4546
+ skipslave);
4547
+ bond_skip_slave(rtnl_dereference(bond->usable_slaves),
4548
+ skipslave);
40844549 }
4550
+ kfree_rcu(all_slaves, rcu);
4551
+ kfree_rcu(usable_slaves, rcu);
4552
+
40854553 return ret;
4554
+}
4555
+
4556
+static struct slave *bond_xmit_3ad_xor_slave_get(struct bonding *bond,
4557
+ struct sk_buff *skb,
4558
+ struct bond_up_slave *slaves)
4559
+{
4560
+ struct slave *slave;
4561
+ unsigned int count;
4562
+ u32 hash;
4563
+
4564
+ hash = bond_xmit_hash(bond, skb);
4565
+ count = slaves ? READ_ONCE(slaves->count) : 0;
4566
+ if (unlikely(!count))
4567
+ return NULL;
4568
+
4569
+ slave = slaves->arr[hash % count];
4570
+ return slave;
40864571 }
40874572
40884573 /* Use this Xmit function for 3AD as well as XOR modes. The current
....@@ -4093,20 +4578,15 @@
40934578 struct net_device *dev)
40944579 {
40954580 struct bonding *bond = netdev_priv(dev);
4096
- struct slave *slave;
40974581 struct bond_up_slave *slaves;
4098
- unsigned int count;
4582
+ struct slave *slave;
40994583
4100
- slaves = rcu_dereference(bond->slave_arr);
4101
- count = slaves ? READ_ONCE(slaves->count) : 0;
4102
- if (likely(count)) {
4103
- slave = slaves->arr[bond_xmit_hash(bond, skb) % count];
4104
- bond_dev_queue_xmit(bond, skb, slave->dev);
4105
- } else {
4106
- bond_tx_drop(dev, skb);
4107
- }
4584
+ slaves = rcu_dereference(bond->usable_slaves);
4585
+ slave = bond_xmit_3ad_xor_slave_get(bond, skb, slaves);
4586
+ if (likely(slave))
4587
+ return bond_dev_queue_xmit(bond, skb, slave->dev);
41084588
4109
- return NETDEV_TX_OK;
4589
+ return bond_tx_drop(dev, skb);
41104590 }
41114591
41124592 /* in broadcast mode, we send everything to all usable interfaces. */
....@@ -4116,27 +4596,39 @@
41164596 struct bonding *bond = netdev_priv(bond_dev);
41174597 struct slave *slave = NULL;
41184598 struct list_head *iter;
4599
+ bool xmit_suc = false;
4600
+ bool skb_used = false;
41194601
41204602 bond_for_each_slave_rcu(bond, slave, iter) {
4121
- if (bond_is_last_slave(bond, slave))
4122
- break;
4123
- if (bond_slave_is_up(slave) && slave->link == BOND_LINK_UP) {
4124
- struct sk_buff *skb2 = skb_clone(skb, GFP_ATOMIC);
4603
+ struct sk_buff *skb2;
41254604
4605
+ if (!(bond_slave_is_up(slave) && slave->link == BOND_LINK_UP))
4606
+ continue;
4607
+
4608
+ if (bond_is_last_slave(bond, slave)) {
4609
+ skb2 = skb;
4610
+ skb_used = true;
4611
+ } else {
4612
+ skb2 = skb_clone(skb, GFP_ATOMIC);
41264613 if (!skb2) {
41274614 net_err_ratelimited("%s: Error: %s: skb_clone() failed\n",
41284615 bond_dev->name, __func__);
41294616 continue;
41304617 }
4131
- bond_dev_queue_xmit(bond, skb2, slave->dev);
41324618 }
4133
- }
4134
- if (slave && bond_slave_is_up(slave) && slave->link == BOND_LINK_UP)
4135
- bond_dev_queue_xmit(bond, skb, slave->dev);
4136
- else
4137
- bond_tx_drop(bond_dev, skb);
41384619
4139
- return NETDEV_TX_OK;
4620
+ if (bond_dev_queue_xmit(bond, skb2, slave->dev) == NETDEV_TX_OK)
4621
+ xmit_suc = true;
4622
+ }
4623
+
4624
+ if (!skb_used)
4625
+ dev_kfree_skb_any(skb);
4626
+
4627
+ if (xmit_suc)
4628
+ return NETDEV_TX_OK;
4629
+
4630
+ atomic_long_inc(&bond_dev->tx_dropped);
4631
+ return NET_XMIT_DROP;
41404632 }
41414633
41424634 /*------------------------- Device initialization ---------------------------*/
....@@ -4169,8 +4661,7 @@
41694661
41704662
41714663 static u16 bond_select_queue(struct net_device *dev, struct sk_buff *skb,
4172
- struct net_device *sb_dev,
4173
- select_queue_fallback_t fallback)
4664
+ struct net_device *sb_dev)
41744665 {
41754666 /* This helper function exists to help dev_pick_tx get the correct
41764667 * destination queue. Using a helper function skips a call to
....@@ -4188,6 +4679,48 @@
41884679 } while (txq >= dev->real_num_tx_queues);
41894680 }
41904681 return txq;
4682
+}
4683
+
4684
+static struct net_device *bond_xmit_get_slave(struct net_device *master_dev,
4685
+ struct sk_buff *skb,
4686
+ bool all_slaves)
4687
+{
4688
+ struct bonding *bond = netdev_priv(master_dev);
4689
+ struct bond_up_slave *slaves;
4690
+ struct slave *slave = NULL;
4691
+
4692
+ switch (BOND_MODE(bond)) {
4693
+ case BOND_MODE_ROUNDROBIN:
4694
+ slave = bond_xmit_roundrobin_slave_get(bond, skb);
4695
+ break;
4696
+ case BOND_MODE_ACTIVEBACKUP:
4697
+ slave = bond_xmit_activebackup_slave_get(bond, skb);
4698
+ break;
4699
+ case BOND_MODE_8023AD:
4700
+ case BOND_MODE_XOR:
4701
+ if (all_slaves)
4702
+ slaves = rcu_dereference(bond->all_slaves);
4703
+ else
4704
+ slaves = rcu_dereference(bond->usable_slaves);
4705
+ slave = bond_xmit_3ad_xor_slave_get(bond, skb, slaves);
4706
+ break;
4707
+ case BOND_MODE_BROADCAST:
4708
+ break;
4709
+ case BOND_MODE_ALB:
4710
+ slave = bond_xmit_alb_slave_get(bond, skb);
4711
+ break;
4712
+ case BOND_MODE_TLB:
4713
+ slave = bond_xmit_tlb_slave_get(bond, skb);
4714
+ break;
4715
+ default:
4716
+ /* Should never happen, mode already checked */
4717
+ WARN_ONCE(true, "Unknown bonding mode");
4718
+ break;
4719
+ }
4720
+
4721
+ if (slave)
4722
+ return slave->dev;
4723
+ return NULL;
41914724 }
41924725
41934726 static netdev_tx_t __bond_start_xmit(struct sk_buff *skb, struct net_device *dev)
....@@ -4216,8 +4749,7 @@
42164749 /* Should never happen, mode already checked */
42174750 netdev_err(dev, "Unknown bonding mode %d\n", BOND_MODE(bond));
42184751 WARN_ON_ONCE(1);
4219
- bond_tx_drop(dev, skb);
4220
- return NETDEV_TX_OK;
4752
+ return bond_tx_drop(dev, skb);
42214753 }
42224754 }
42234755
....@@ -4236,7 +4768,7 @@
42364768 if (bond_has_slaves(bond))
42374769 ret = __bond_start_xmit(skb, dev);
42384770 else
4239
- bond_tx_drop(dev, skb);
4771
+ ret = bond_tx_drop(dev, skb);
42404772 rcu_read_unlock();
42414773
42424774 return ret;
....@@ -4291,7 +4823,6 @@
42914823 struct ethtool_drvinfo *drvinfo)
42924824 {
42934825 strlcpy(drvinfo->driver, DRV_NAME, sizeof(drvinfo->driver));
4294
- strlcpy(drvinfo->version, DRV_VERSION, sizeof(drvinfo->version));
42954826 snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version), "%d",
42964827 BOND_ABI_VERSION);
42974828 }
....@@ -4318,7 +4849,6 @@
43184849 .ndo_neigh_setup = bond_neigh_setup,
43194850 .ndo_vlan_rx_add_vid = bond_vlan_rx_add_vid,
43204851 .ndo_vlan_rx_kill_vid = bond_vlan_rx_kill_vid,
4321
- .ndo_get_lock_subclass = bond_get_nest_level,
43224852 #ifdef CONFIG_NET_POLL_CONTROLLER
43234853 .ndo_netpoll_setup = bond_netpoll_setup,
43244854 .ndo_netpoll_cleanup = bond_netpoll_cleanup,
....@@ -4328,6 +4858,7 @@
43284858 .ndo_del_slave = bond_release,
43294859 .ndo_fix_features = bond_fix_features,
43304860 .ndo_features_check = passthru_features_check,
4861
+ .ndo_get_xmit_slave = bond_xmit_get_slave,
43314862 };
43324863
43334864 static const struct device_type bond_type = {
....@@ -4346,7 +4877,6 @@
43464877 struct bonding *bond = netdev_priv(bond_dev);
43474878
43484879 spin_lock_init(&bond->mode_lock);
4349
- spin_lock_init(&bond->stats_lock);
43504880 bond->params = bonding_defaults;
43514881
43524882 /* Initialize pointers */
....@@ -4368,6 +4898,13 @@
43684898 bond_dev->priv_flags |= IFF_BONDING | IFF_UNICAST_FLT | IFF_NO_QUEUE;
43694899 bond_dev->priv_flags &= ~(IFF_XMIT_DST_RELEASE | IFF_TX_SKB_SHARING);
43704900
4901
+#ifdef CONFIG_XFRM_OFFLOAD
4902
+ /* set up xfrm device ops (only supported in active-backup right now) */
4903
+ bond_dev->xfrmdev_ops = &bond_xfrmdev_ops;
4904
+ INIT_LIST_HEAD(&bond->ipsec_list);
4905
+ spin_lock_init(&bond->ipsec_lock);
4906
+#endif /* CONFIG_XFRM_OFFLOAD */
4907
+
43714908 /* don't acquire bond device's netif_tx_lock when transmitting */
43724909 bond_dev->features |= NETIF_F_LLTX;
43734910
....@@ -4383,11 +4920,21 @@
43834920
43844921 bond_dev->hw_features = BOND_VLAN_FEATURES |
43854922 NETIF_F_HW_VLAN_CTAG_RX |
4386
- NETIF_F_HW_VLAN_CTAG_FILTER;
4923
+ NETIF_F_HW_VLAN_CTAG_FILTER |
4924
+ NETIF_F_HW_VLAN_STAG_RX |
4925
+ NETIF_F_HW_VLAN_STAG_FILTER;
43874926
43884927 bond_dev->hw_features |= NETIF_F_GSO_ENCAP_ALL | NETIF_F_GSO_UDP_L4;
4928
+#ifdef CONFIG_XFRM_OFFLOAD
4929
+ bond_dev->hw_features |= BOND_XFRM_FEATURES;
4930
+#endif /* CONFIG_XFRM_OFFLOAD */
43894931 bond_dev->features |= bond_dev->hw_features;
43904932 bond_dev->features |= NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_HW_VLAN_STAG_TX;
4933
+#ifdef CONFIG_XFRM_OFFLOAD
4934
+ /* Disable XFRM features if this isn't an active-backup config */
4935
+ if (BOND_MODE(bond) != BOND_MODE_ACTIVEBACKUP)
4936
+ bond_dev->features &= ~BOND_XFRM_FEATURES;
4937
+#endif /* CONFIG_XFRM_OFFLOAD */
43914938 }
43924939
43934940 /* Destroy a bonding device.
....@@ -4396,9 +4943,9 @@
43964943 static void bond_uninit(struct net_device *bond_dev)
43974944 {
43984945 struct bonding *bond = netdev_priv(bond_dev);
4946
+ struct bond_up_slave *usable, *all;
43994947 struct list_head *iter;
44004948 struct slave *slave;
4401
- struct bond_up_slave *arr;
44024949
44034950 bond_netpoll_cleanup(bond_dev);
44044951
....@@ -4407,10 +4954,16 @@
44074954 __bond_release_one(bond_dev, slave->dev, true, true);
44084955 netdev_info(bond_dev, "Released all slaves\n");
44094956
4410
- arr = rtnl_dereference(bond->slave_arr);
4411
- if (arr) {
4412
- RCU_INIT_POINTER(bond->slave_arr, NULL);
4413
- kfree_rcu(arr, rcu);
4957
+ usable = rtnl_dereference(bond->usable_slaves);
4958
+ if (usable) {
4959
+ RCU_INIT_POINTER(bond->usable_slaves, NULL);
4960
+ kfree_rcu(usable, rcu);
4961
+ }
4962
+
4963
+ all = rtnl_dereference(bond->all_slaves);
4964
+ if (all) {
4965
+ RCU_INIT_POINTER(bond->all_slaves, NULL);
4966
+ kfree_rcu(all, rcu);
44144967 }
44154968
44164969 list_del(&bond->bond_list);
....@@ -4769,6 +5322,7 @@
47695322 params->arp_all_targets = arp_all_targets_value;
47705323 params->updelay = updelay;
47715324 params->downdelay = downdelay;
5325
+ params->peer_notif_delay = 0;
47725326 params->use_carrier = use_carrier;
47735327 params->lacp_fast = lacp_fast;
47745328 params->primary[0] = 0;
....@@ -4817,7 +5371,9 @@
48175371 if (!bond->wq)
48185372 return -ENOMEM;
48195373
4820
- bond->nest_level = SINGLE_DEPTH_NESTING;
5374
+ bond->notifier_ctx = false;
5375
+
5376
+ spin_lock_init(&bond->stats_lock);
48215377 netdev_lockdep_set_classes(bond_dev);
48225378
48235379 list_add_tail(&bond->bond_list, &bn->dev_list);
....@@ -4932,8 +5488,6 @@
49325488 int i;
49335489 int res;
49345490
4935
- pr_info("%s", bond_version);
4936
-
49375491 res = bond_check_params(&bonding_defaults);
49385492 if (res)
49395493 goto out;
....@@ -4953,6 +5507,10 @@
49535507 if (res)
49545508 goto err;
49555509 }
5510
+
5511
+ skb_flow_dissector_init(&flow_keys_bonding,
5512
+ flow_keys_bonding_keys,
5513
+ ARRAY_SIZE(flow_keys_bonding_keys));
49565514
49575515 register_netdevice_notifier(&bond_netdev_notifier);
49585516 out:
....@@ -4984,6 +5542,5 @@
49845542 module_init(bonding_init);
49855543 module_exit(bonding_exit);
49865544 MODULE_LICENSE("GPL");
4987
-MODULE_VERSION(DRV_VERSION);
4988
-MODULE_DESCRIPTION(DRV_DESCRIPTION ", v" DRV_VERSION);
5545
+MODULE_DESCRIPTION(DRV_DESCRIPTION);
49895546 MODULE_AUTHOR("Thomas Davis, tadavis@lbl.gov and many others");