hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
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
....@@ -1194,7 +1508,7 @@
11941508 skb->dev = bond->dev;
11951509
11961510 if (BOND_MODE(bond) == BOND_MODE_ALB &&
1197
- bond->dev->priv_flags & IFF_BRIDGE_PORT &&
1511
+ netif_is_bridge_port(bond->dev) &&
11981512 skb->pkt_type == PACKET_HOST) {
11991513
12001514 if (unlikely(skb_cow_head(skb,
....@@ -1388,15 +1702,14 @@
13881702 if (!bond->params.use_carrier &&
13891703 slave_dev->ethtool_ops->get_link == NULL &&
13901704 slave_ops->ndo_do_ioctl == NULL) {
1391
- netdev_warn(bond_dev, "no link monitoring support for %s\n",
1392
- slave_dev->name);
1705
+ slave_warn(bond_dev, slave_dev, "no link monitoring support\n");
13931706 }
13941707
13951708 /* already in-use? */
13961709 if (netdev_is_rx_handler_busy(slave_dev)) {
13971710 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");
1711
+ slave_err(bond_dev, slave_dev,
1712
+ "Error: Device is in use and cannot be enslaved\n");
14001713 return -EBUSY;
14011714 }
14021715
....@@ -1409,22 +1722,20 @@
14091722 /* vlan challenged mutual exclusion */
14101723 /* no need to lock since we're protected by rtnl_lock */
14111724 if (slave_dev->features & NETIF_F_VLAN_CHALLENGED) {
1412
- netdev_dbg(bond_dev, "%s is NETIF_F_VLAN_CHALLENGED\n",
1413
- slave_dev->name);
1725
+ slave_dbg(bond_dev, slave_dev, "is NETIF_F_VLAN_CHALLENGED\n");
14141726 if (vlan_uses_dev(bond_dev)) {
14151727 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);
1728
+ slave_err(bond_dev, slave_dev, "Error: cannot enslave VLAN challenged slave on VLAN enabled bond\n");
14181729 return -EPERM;
14191730 } 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);
1731
+ slave_warn(bond_dev, slave_dev, "enslaved VLAN challenged slave. Adding VLANs will be blocked as long as it is part of bond.\n");
14231732 }
14241733 } else {
1425
- netdev_dbg(bond_dev, "%s is !NETIF_F_VLAN_CHALLENGED\n",
1426
- slave_dev->name);
1734
+ slave_dbg(bond_dev, slave_dev, "is !NETIF_F_VLAN_CHALLENGED\n");
14271735 }
1736
+
1737
+ if (slave_dev->features & NETIF_F_HW_ESP)
1738
+ slave_dbg(bond_dev, slave_dev, "is esp-hw-offload capable\n");
14281739
14291740 /* Old ifenslave binaries are no longer supported. These can
14301741 * be identified with moderate accuracy by the state of the slave:
....@@ -1433,8 +1744,7 @@
14331744 */
14341745 if (slave_dev->flags & IFF_UP) {
14351746 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);
1747
+ slave_err(bond_dev, slave_dev, "slave is up - this may be due to an out of date ifenslave\n");
14381748 return -EPERM;
14391749 }
14401750
....@@ -1447,14 +1757,14 @@
14471757 */
14481758 if (!bond_has_slaves(bond)) {
14491759 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);
1760
+ slave_dbg(bond_dev, slave_dev, "change device type from %d to %d\n",
1761
+ bond_dev->type, slave_dev->type);
14521762
14531763 res = call_netdevice_notifiers(NETDEV_PRE_TYPE_CHANGE,
14541764 bond_dev);
14551765 res = notifier_to_errno(res);
14561766 if (res) {
1457
- netdev_err(bond_dev, "refused to change device type\n");
1767
+ slave_err(bond_dev, slave_dev, "refused to change device type\n");
14581768 return -EBUSY;
14591769 }
14601770
....@@ -1474,31 +1784,31 @@
14741784 }
14751785 } else if (bond_dev->type != slave_dev->type) {
14761786 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);
1787
+ slave_err(bond_dev, slave_dev, "ether type (%d) is different from other slaves (%d), can not enslave it\n",
1788
+ slave_dev->type, bond_dev->type);
14791789 return -EINVAL;
14801790 }
14811791
14821792 if (slave_dev->type == ARPHRD_INFINIBAND &&
14831793 BOND_MODE(bond) != BOND_MODE_ACTIVEBACKUP) {
14841794 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);
1795
+ slave_warn(bond_dev, slave_dev, "Type (%d) supports only active-backup mode\n",
1796
+ slave_dev->type);
14871797 res = -EOPNOTSUPP;
14881798 goto err_undo_flags;
14891799 }
14901800
14911801 if (!slave_ops->ndo_set_mac_address ||
14921802 slave_dev->type == ARPHRD_INFINIBAND) {
1493
- netdev_warn(bond_dev, "The slave device specified does not support setting the MAC address\n");
1803
+ slave_warn(bond_dev, slave_dev, "The slave device specified does not support setting the MAC address\n");
14941804 if (BOND_MODE(bond) == BOND_MODE_ACTIVEBACKUP &&
14951805 bond->params.fail_over_mac != BOND_FOM_ACTIVE) {
14961806 if (!bond_has_slaves(bond)) {
14971807 bond->params.fail_over_mac = BOND_FOM_ACTIVE;
1498
- netdev_warn(bond_dev, "Setting fail_over_mac to active for active-backup mode\n");
1808
+ slave_warn(bond_dev, slave_dev, "Setting fail_over_mac to active for active-backup mode\n");
14991809 } else {
15001810 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");
1811
+ 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");
15021812 res = -EOPNOTSUPP;
15031813 goto err_undo_flags;
15041814 }
....@@ -1511,8 +1821,11 @@
15111821 * address to be the same as the slave's.
15121822 */
15131823 if (!bond_has_slaves(bond) &&
1514
- bond->dev->addr_assign_type == NET_ADDR_RANDOM)
1515
- bond_set_dev_addr(bond->dev, slave_dev);
1824
+ bond->dev->addr_assign_type == NET_ADDR_RANDOM) {
1825
+ res = bond_set_dev_addr(bond->dev, slave_dev);
1826
+ if (res)
1827
+ goto err_undo_flags;
1828
+ }
15161829
15171830 new_slave = bond_alloc_slave(bond, slave_dev);
15181831 if (!new_slave) {
....@@ -1529,7 +1842,7 @@
15291842 new_slave->original_mtu = slave_dev->mtu;
15301843 res = dev_set_mtu(slave_dev, bond->dev->mtu);
15311844 if (res) {
1532
- netdev_dbg(bond_dev, "Error %d calling dev_set_mtu\n", res);
1845
+ slave_err(bond_dev, slave_dev, "Error %d calling dev_set_mtu\n", res);
15331846 goto err_free;
15341847 }
15351848
....@@ -1547,9 +1860,10 @@
15471860 */
15481861 memcpy(ss.__data, bond_dev->dev_addr, bond_dev->addr_len);
15491862 ss.ss_family = slave_dev->type;
1550
- res = dev_set_mac_address(slave_dev, (struct sockaddr *)&ss);
1863
+ res = dev_set_mac_address(slave_dev, (struct sockaddr *)&ss,
1864
+ extack);
15511865 if (res) {
1552
- netdev_dbg(bond_dev, "Error %d calling set_mac_address\n", res);
1866
+ slave_err(bond_dev, slave_dev, "Error %d calling set_mac_address\n", res);
15531867 goto err_restore_mtu;
15541868 }
15551869 }
....@@ -1558,9 +1872,9 @@
15581872 slave_dev->flags |= IFF_SLAVE;
15591873
15601874 /* open the slave since the application closed it */
1561
- res = dev_open(slave_dev);
1875
+ res = dev_open(slave_dev, extack);
15621876 if (res) {
1563
- netdev_dbg(bond_dev, "Opening slave %s failed\n", slave_dev->name);
1877
+ slave_err(bond_dev, slave_dev, "Opening slave failed\n");
15641878 goto err_restore_mac;
15651879 }
15661880
....@@ -1579,8 +1893,7 @@
15791893
15801894 res = vlan_vids_add_by_dev(slave_dev, bond_dev);
15811895 if (res) {
1582
- netdev_err(bond_dev, "Couldn't add bond vlan ids to %s\n",
1583
- slave_dev->name);
1896
+ slave_err(bond_dev, slave_dev, "Couldn't add bond vlan ids\n");
15841897 goto err_close;
15851898 }
15861899
....@@ -1610,12 +1923,10 @@
16101923 * supported); thus, we don't need to change
16111924 * the messages for netif_carrier.
16121925 */
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);
1926
+ 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");
16151927 } else if (link_reporting == -1) {
16161928 /* 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);
1929
+ 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");
16191930 }
16201931 }
16211932
....@@ -1649,9 +1960,9 @@
16491960
16501961 if (new_slave->link != BOND_LINK_DOWN)
16511962 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"));
1963
+ slave_dbg(bond_dev, slave_dev, "Initial state of slave is BOND_LINK_%s\n",
1964
+ new_slave->link == BOND_LINK_DOWN ? "DOWN" :
1965
+ (new_slave->link == BOND_LINK_UP ? "UP" : "BACK"));
16551966
16561967 if (bond_uses_primary(bond) && bond->params.primary[0]) {
16571968 /* if there is a primary slave, remember it */
....@@ -1692,7 +2003,7 @@
16922003 bond_set_slave_inactive_flags(new_slave, BOND_SLAVE_NOTIFY_NOW);
16932004 break;
16942005 default:
1695
- netdev_dbg(bond_dev, "This slave is always active in trunk mode\n");
2006
+ slave_dbg(bond_dev, slave_dev, "This slave is always active in trunk mode\n");
16962007
16972008 /* always active in trunk mode */
16982009 bond_set_active_slave(new_slave);
....@@ -1711,7 +2022,7 @@
17112022 #ifdef CONFIG_NET_POLL_CONTROLLER
17122023 if (bond->dev->npinfo) {
17132024 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");
2025
+ slave_info(bond_dev, slave_dev, "master_dev is using netpoll, but new slave device does not support netpoll\n");
17152026 res = -EBUSY;
17162027 goto err_detach;
17172028 }
....@@ -1724,23 +2035,21 @@
17242035 res = netdev_rx_handler_register(slave_dev, bond_handle_frame,
17252036 new_slave);
17262037 if (res) {
1727
- netdev_dbg(bond_dev, "Error %d calling netdev_rx_handler_register\n", res);
2038
+ slave_dbg(bond_dev, slave_dev, "Error %d calling netdev_rx_handler_register\n", res);
17282039 goto err_detach;
17292040 }
17302041
17312042 res = bond_master_upper_dev_link(bond, new_slave, extack);
17322043 if (res) {
1733
- netdev_dbg(bond_dev, "Error %d calling bond_master_upper_dev_link\n", res);
2044
+ slave_dbg(bond_dev, slave_dev, "Error %d calling bond_master_upper_dev_link\n", res);
17342045 goto err_unregister;
17352046 }
17362047
17372048 res = bond_sysfs_slave_add(new_slave);
17382049 if (res) {
1739
- netdev_dbg(bond_dev, "Error %d calling bond_sysfs_slave_add\n", res);
2050
+ slave_dbg(bond_dev, slave_dev, "Error %d calling bond_sysfs_slave_add\n", res);
17402051 goto err_upper_unlink;
17412052 }
1742
-
1743
- bond->nest_level = dev_get_nest_level(bond_dev) + 1;
17442053
17452054 /* If the mode uses primary, then the following is handled by
17462055 * bond_change_active_slave().
....@@ -1763,16 +2072,14 @@
17632072 }
17642073 }
17652074
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);
2075
+ if (bond_dev->flags & IFF_UP) {
2076
+ netif_addr_lock_bh(bond_dev);
2077
+ dev_mc_sync_multiple(slave_dev, bond_dev);
2078
+ dev_uc_sync_multiple(slave_dev, bond_dev);
2079
+ netif_addr_unlock_bh(bond_dev);
17702080
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);
2081
+ if (BOND_MODE(bond) == BOND_MODE_8023AD)
2082
+ dev_mc_add(slave_dev, lacpdu_mcast_addr);
17762083 }
17772084 }
17782085
....@@ -1790,10 +2097,9 @@
17902097 bond_update_slave_arr(bond, NULL);
17912098
17922099
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");
2100
+ slave_info(bond_dev, slave_dev, "Enslaving as %s interface with %s link\n",
2101
+ bond_is_active_slave(new_slave) ? "an active" : "a backup",
2102
+ new_slave->link != BOND_LINK_DOWN ? "an up" : "a down");
17972103
17982104 /* enslave is successful */
17992105 bond_queue_slave_event(new_slave);
....@@ -1839,7 +2145,7 @@
18392145 bond_hw_addr_copy(ss.__data, new_slave->perm_hwaddr,
18402146 new_slave->dev->addr_len);
18412147 ss.ss_family = slave_dev->type;
1842
- dev_set_mac_address(slave_dev, (struct sockaddr *)&ss);
2148
+ dev_set_mac_address(slave_dev, (struct sockaddr *)&ss, NULL);
18432149 }
18442150
18452151 err_restore_mtu:
....@@ -1889,8 +2195,7 @@
18892195 /* slave is not a slave or master is not master of this slave */
18902196 if (!(slave_dev->flags & IFF_SLAVE) ||
18912197 !netdev_has_upper_dev(slave_dev, bond_dev)) {
1892
- netdev_dbg(bond_dev, "cannot release %s\n",
1893
- slave_dev->name);
2198
+ slave_dbg(bond_dev, slave_dev, "cannot release slave\n");
18942199 return -EINVAL;
18952200 }
18962201
....@@ -1899,8 +2204,7 @@
18992204 slave = bond_get_slave_by_dev(bond, slave_dev);
19002205 if (!slave) {
19012206 /* not a slave of this bond */
1902
- netdev_info(bond_dev, "%s not enslaved\n",
1903
- slave_dev->name);
2207
+ slave_info(bond_dev, slave_dev, "interface not enslaved\n");
19042208 unblock_netpoll_tx();
19052209 return -EINVAL;
19062210 }
....@@ -1925,9 +2229,8 @@
19252229 if (bond_mode_can_use_xmit_hash(bond))
19262230 bond_update_slave_arr(bond, slave);
19272231
1928
- netdev_info(bond_dev, "Releasing %s interface %s\n",
1929
- bond_is_active_slave(slave) ? "active" : "backup",
1930
- slave_dev->name);
2232
+ slave_info(bond_dev, slave_dev, "Releasing %s interface\n",
2233
+ bond_is_active_slave(slave) ? "active" : "backup");
19312234
19322235 oldcurrent = rcu_access_pointer(bond->curr_active_slave);
19332236
....@@ -1937,9 +2240,8 @@
19372240 BOND_MODE(bond) != BOND_MODE_ACTIVEBACKUP)) {
19382241 if (ether_addr_equal_64bits(bond_dev->dev_addr, slave->perm_hwaddr) &&
19392242 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);
2243
+ 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",
2244
+ slave->perm_hwaddr);
19432245 }
19442246
19452247 if (rtnl_dereference(bond->primary_slave) == slave)
....@@ -1967,13 +2269,9 @@
19672269 bond_select_active_slave(bond);
19682270 }
19692271
1970
- if (!bond_has_slaves(bond)) {
1971
- bond_set_carrier(bond);
2272
+ bond_set_carrier(bond);
2273
+ if (!bond_has_slaves(bond))
19722274 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
- }
19772275
19782276 unblock_netpoll_tx();
19792277 synchronize_rcu();
....@@ -1987,8 +2285,7 @@
19872285 bond_compute_features(bond);
19882286 if (!(bond_dev->features & NETIF_F_VLAN_CHALLENGED) &&
19892287 (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);
2288
+ slave_info(bond_dev, slave_dev, "last VLAN challenged slave left bond - VLAN blocking is removed\n");
19922289
19932290 vlan_vids_del_by_dev(slave_dev, bond_dev);
19942291
....@@ -2010,7 +2307,8 @@
20102307 if (old_flags & IFF_ALLMULTI)
20112308 dev_set_allmulti(slave_dev, -1);
20122309
2013
- bond_hw_addr_flush(bond_dev, slave_dev);
2310
+ if (old_flags & IFF_UP)
2311
+ bond_hw_addr_flush(bond_dev, slave_dev);
20142312 }
20152313
20162314 slave_disable_netpoll(slave);
....@@ -2024,7 +2322,7 @@
20242322 bond_hw_addr_copy(ss.__data, slave->perm_hwaddr,
20252323 slave->dev->addr_len);
20262324 ss.ss_family = slave_dev->type;
2027
- dev_set_mac_address(slave_dev, (struct sockaddr *)&ss);
2325
+ dev_set_mac_address(slave_dev, (struct sockaddr *)&ss, NULL);
20282326 }
20292327
20302328 if (unregister)
....@@ -2049,8 +2347,8 @@
20492347 /* First release a slave and then destroy the bond if no more slaves are left.
20502348 * Must be under rtnl_lock when this function is called.
20512349 */
2052
-static int bond_release_and_destroy(struct net_device *bond_dev,
2053
- struct net_device *slave_dev)
2350
+static int bond_release_and_destroy(struct net_device *bond_dev,
2351
+ struct net_device *slave_dev)
20542352 {
20552353 struct bonding *bond = netdev_priv(bond_dev);
20562354 int ret;
....@@ -2059,8 +2357,7 @@
20592357 if (ret == 0 && !bond_has_slaves(bond) &&
20602358 bond_dev->reg_state != NETREG_UNREGISTERING) {
20612359 bond_dev->priv_flags |= IFF_DISABLE_NETPOLL;
2062
- netdev_info(bond_dev, "Destroying bond %s\n",
2063
- bond_dev->name);
2360
+ netdev_info(bond_dev, "Destroying bond\n");
20642361 bond_remove_proc_entry(bond);
20652362 unregister_netdevice(bond_dev);
20662363 }
....@@ -2117,24 +2414,22 @@
21172414 commit++;
21182415 slave->delay = bond->params.downdelay;
21192416 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);
2417
+ slave_info(bond->dev, slave->dev, "link status down for %sinterface, disabling it in %d ms\n",
2418
+ (BOND_MODE(bond) ==
2419
+ BOND_MODE_ACTIVEBACKUP) ?
2420
+ (bond_is_active_slave(slave) ?
2421
+ "active " : "backup ") : "",
2422
+ bond->params.downdelay * bond->params.miimon);
21272423 }
2128
- /*FALLTHRU*/
2424
+ fallthrough;
21292425 case BOND_LINK_FAIL:
21302426 if (link_state) {
21312427 /* recovered before downdelay expired */
21322428 bond_propose_link_state(slave, BOND_LINK_UP);
21332429 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);
2430
+ slave_info(bond->dev, slave->dev, "link status up again after %d ms\n",
2431
+ (bond->params.downdelay - slave->delay) *
2432
+ bond->params.miimon);
21382433 commit++;
21392434 continue;
21402435 }
....@@ -2157,20 +2452,18 @@
21572452 slave->delay = bond->params.updelay;
21582453
21592454 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);
2455
+ slave_info(bond->dev, slave->dev, "link status up, enabling it in %d ms\n",
2456
+ ignore_updelay ? 0 :
2457
+ bond->params.updelay *
2458
+ bond->params.miimon);
21652459 }
2166
- /*FALLTHRU*/
2460
+ fallthrough;
21672461 case BOND_LINK_BACK:
21682462 if (!link_state) {
21692463 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);
2464
+ slave_info(bond->dev, slave->dev, "link status down again after %d ms\n",
2465
+ (bond->params.updelay - slave->delay) *
2466
+ bond->params.miimon);
21742467 commit++;
21752468 continue;
21762469 }
....@@ -2235,9 +2528,8 @@
22352528 bond_needs_speed_duplex(bond)) {
22362529 slave->link = BOND_LINK_DOWN;
22372530 if (net_ratelimit())
2238
- netdev_warn(bond->dev,
2239
- "failed to get link speed/duplex for %s\n",
2240
- slave->dev->name);
2531
+ slave_warn(bond->dev, slave->dev,
2532
+ "failed to get link speed/duplex\n");
22412533 continue;
22422534 }
22432535 bond_set_slave_link_state(slave, BOND_LINK_UP,
....@@ -2253,10 +2545,9 @@
22532545 bond_set_active_slave(slave);
22542546 }
22552547
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");
2548
+ slave_info(bond->dev, slave->dev, "link status definitely up, %u Mbps %s duplex\n",
2549
+ slave->speed == SPEED_UNKNOWN ? 0 : slave->speed,
2550
+ slave->duplex ? "full" : "half");
22602551
22612552 bond_miimon_link_change(bond, slave, BOND_LINK_UP);
22622553
....@@ -2277,8 +2568,7 @@
22772568 bond_set_slave_inactive_flags(slave,
22782569 BOND_SLAVE_NOTIFY_NOW);
22792570
2280
- netdev_info(bond->dev, "link status definitely down for interface %s, disabling it\n",
2281
- slave->dev->name);
2571
+ slave_info(bond->dev, slave->dev, "link status definitely down, disabling slave\n");
22822572
22832573 bond_miimon_link_change(bond, slave, BOND_LINK_DOWN);
22842574
....@@ -2288,8 +2578,8 @@
22882578 continue;
22892579
22902580 default:
2291
- netdev_err(bond->dev, "invalid new link %d on slave %s\n",
2292
- slave->link_new_state, slave->dev->name);
2581
+ slave_err(bond->dev, slave->dev, "invalid new link %d on slave\n",
2582
+ slave->link_new_state);
22932583 bond_propose_link_state(slave, BOND_LINK_NOCHANGE);
22942584
22952585 continue;
....@@ -2316,6 +2606,7 @@
23162606 struct bonding *bond = container_of(work, struct bonding,
23172607 mii_work.work);
23182608 bool should_notify_peers = false;
2609
+ bool commit;
23192610 unsigned long delay;
23202611 struct slave *slave;
23212612 struct list_head *iter;
....@@ -2326,12 +2617,19 @@
23262617 goto re_arm;
23272618
23282619 rcu_read_lock();
2329
-
23302620 should_notify_peers = bond_should_notify_peers(bond);
2331
-
2332
- if (bond_miimon_inspect(bond)) {
2621
+ commit = !!bond_miimon_inspect(bond);
2622
+ if (bond->send_peer_notif) {
23332623 rcu_read_unlock();
2624
+ if (rtnl_trylock()) {
2625
+ bond->send_peer_notif--;
2626
+ rtnl_unlock();
2627
+ }
2628
+ } else {
2629
+ rcu_read_unlock();
2630
+ }
23342631
2632
+ if (commit) {
23352633 /* Race avoidance with bond_close cancel of workqueue */
23362634 if (!rtnl_trylock()) {
23372635 delay = 1;
....@@ -2345,8 +2643,7 @@
23452643 bond_miimon_commit(bond);
23462644
23472645 rtnl_unlock(); /* might sleep, hold no other locks */
2348
- } else
2349
- rcu_read_unlock();
2646
+ }
23502647
23512648 re_arm:
23522649 if (bond->params.miimon)
....@@ -2360,22 +2657,26 @@
23602657 }
23612658 }
23622659
2363
-static int bond_upper_dev_walk(struct net_device *upper, void *data)
2660
+static int bond_upper_dev_walk(struct net_device *upper,
2661
+ struct netdev_nested_priv *priv)
23642662 {
2365
- __be32 ip = *((__be32 *)data);
2663
+ __be32 ip = *(__be32 *)priv->data;
23662664
23672665 return ip == bond_confirm_addr(upper, 0, ip);
23682666 }
23692667
23702668 static bool bond_has_this_ip(struct bonding *bond, __be32 ip)
23712669 {
2670
+ struct netdev_nested_priv priv = {
2671
+ .data = (void *)&ip,
2672
+ };
23722673 bool ret = false;
23732674
23742675 if (ip == bond_confirm_addr(bond->dev, 0, ip))
23752676 return true;
23762677
23772678 rcu_read_lock();
2378
- if (netdev_walk_all_upper_dev_rcu(bond->dev, bond_upper_dev_walk, &ip))
2679
+ if (netdev_walk_all_upper_dev_rcu(bond->dev, bond_upper_dev_walk, &priv))
23792680 ret = true;
23802681 rcu_read_unlock();
23812682
....@@ -2386,15 +2687,16 @@
23862687 * switches in VLAN mode (especially if ports are configured as
23872688 * "native" to a VLAN) might not pass non-tagged frames.
23882689 */
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)
2690
+static void bond_arp_send(struct slave *slave, int arp_op, __be32 dest_ip,
2691
+ __be32 src_ip, struct bond_vlan_tag *tags)
23922692 {
23932693 struct sk_buff *skb;
23942694 struct bond_vlan_tag *outer_tag = tags;
2695
+ struct net_device *slave_dev = slave->dev;
2696
+ struct net_device *bond_dev = slave->bond->dev;
23952697
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);
2698
+ slave_dbg(bond_dev, slave_dev, "arp %d on slave: dst %pI4 src %pI4\n",
2699
+ arp_op, &dest_ip, &src_ip);
23982700
23992701 skb = arp_create(arp_op, ETH_P_ARP, dest_ip, slave_dev, src_ip,
24002702 NULL, slave_dev->dev_addr, NULL);
....@@ -2416,8 +2718,8 @@
24162718 continue;
24172719 }
24182720
2419
- netdev_dbg(slave_dev, "inner tag: proto %X vid %X\n",
2420
- ntohs(outer_tag->vlan_proto), tags->vlan_id);
2721
+ slave_dbg(bond_dev, slave_dev, "inner tag: proto %X vid %X\n",
2722
+ ntohs(outer_tag->vlan_proto), tags->vlan_id);
24212723 skb = vlan_insert_tag_set_proto(skb, tags->vlan_proto,
24222724 tags->vlan_id);
24232725 if (!skb) {
....@@ -2429,8 +2731,8 @@
24292731 }
24302732 /* Set the outer tag */
24312733 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);
2734
+ slave_dbg(bond_dev, slave_dev, "outer tag: proto %X vid %X\n",
2735
+ ntohs(outer_tag->vlan_proto), outer_tag->vlan_id);
24342736 __vlan_hwaccel_put_tag(skb, outer_tag->vlan_proto,
24352737 outer_tag->vlan_id);
24362738 }
....@@ -2487,7 +2789,8 @@
24872789 int i;
24882790
24892791 for (i = 0; i < BOND_MAX_ARP_TARGETS && targets[i]; i++) {
2490
- netdev_dbg(bond->dev, "basa: target %pI4\n", &targets[i]);
2792
+ slave_dbg(bond->dev, slave->dev, "%s: target %pI4\n",
2793
+ __func__, &targets[i]);
24912794 tags = NULL;
24922795
24932796 /* Find out through which dev should the packet go */
....@@ -2501,7 +2804,7 @@
25012804 net_warn_ratelimited("%s: no route to arp_ip_target %pI4 and arp_validate is set\n",
25022805 bond->dev->name,
25032806 &targets[i]);
2504
- bond_arp_send(slave->dev, ARPOP_REQUEST, targets[i],
2807
+ bond_arp_send(slave, ARPOP_REQUEST, targets[i],
25052808 0, tags);
25062809 continue;
25072810 }
....@@ -2518,7 +2821,7 @@
25182821 goto found;
25192822
25202823 /* Not our device - skip */
2521
- netdev_dbg(bond->dev, "no path to arp_ip_target %pI4 via rt.dev %s\n",
2824
+ slave_dbg(bond->dev, slave->dev, "no path to arp_ip_target %pI4 via rt.dev %s\n",
25222825 &targets[i], rt->dst.dev ? rt->dst.dev->name : "NULL");
25232826
25242827 ip_rt_put(rt);
....@@ -2527,8 +2830,7 @@
25272830 found:
25282831 addr = bond_confirm_addr(rt->dst.dev, targets[i], 0);
25292832 ip_rt_put(rt);
2530
- bond_arp_send(slave->dev, ARPOP_REQUEST, targets[i],
2531
- addr, tags);
2833
+ bond_arp_send(slave, ARPOP_REQUEST, targets[i], addr, tags);
25322834 kfree(tags);
25332835 }
25342836 }
....@@ -2538,15 +2840,15 @@
25382840 int i;
25392841
25402842 if (!sip || !bond_has_this_ip(bond, tip)) {
2541
- netdev_dbg(bond->dev, "bva: sip %pI4 tip %pI4 not found\n",
2542
- &sip, &tip);
2843
+ slave_dbg(bond->dev, slave->dev, "%s: sip %pI4 tip %pI4 not found\n",
2844
+ __func__, &sip, &tip);
25432845 return;
25442846 }
25452847
25462848 i = bond_get_targets_ip(bond->params.arp_targets, sip);
25472849 if (i == -1) {
2548
- netdev_dbg(bond->dev, "bva: sip %pI4 not found in targets\n",
2549
- &sip);
2850
+ slave_dbg(bond->dev, slave->dev, "%s: sip %pI4 not found in targets\n",
2851
+ __func__, &sip);
25502852 return;
25512853 }
25522854 slave->last_rx = jiffies;
....@@ -2574,8 +2876,8 @@
25742876
25752877 alen = arp_hdr_len(bond->dev);
25762878
2577
- netdev_dbg(bond->dev, "bond_arp_rcv: skb->dev %s\n",
2578
- skb->dev->name);
2879
+ slave_dbg(bond->dev, slave->dev, "%s: skb->dev %s\n",
2880
+ __func__, skb->dev->name);
25792881
25802882 if (alen > skb_headlen(skb)) {
25812883 arp = kmalloc(alen, GFP_ATOMIC);
....@@ -2599,10 +2901,10 @@
25992901 arp_ptr += 4 + bond->dev->addr_len;
26002902 memcpy(&tip, arp_ptr, 4);
26012903
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);
2904
+ slave_dbg(bond->dev, slave->dev, "%s: %s/%d av %d sv %d sip %pI4 tip %pI4\n",
2905
+ __func__, slave->dev->name, bond_slave_state(slave),
2906
+ bond->params.arp_validate, slave_do_arp_validate(bond, slave),
2907
+ &sip, &tip);
26062908
26072909 curr_active_slave = rcu_dereference(bond->curr_active_slave);
26082910 curr_arp_slave = rcu_dereference(bond->current_arp_slave);
....@@ -2705,12 +3007,10 @@
27053007 * is closed.
27063008 */
27073009 if (!oldcurrent) {
2708
- netdev_info(bond->dev, "link status definitely up for interface %s\n",
2709
- slave->dev->name);
3010
+ slave_info(bond->dev, slave->dev, "link status definitely up\n");
27103011 do_failover = 1;
27113012 } else {
2712
- netdev_info(bond->dev, "interface %s is now up\n",
2713
- slave->dev->name);
3013
+ slave_info(bond->dev, slave->dev, "interface is now up\n");
27143014 }
27153015 }
27163016 } else {
....@@ -2729,8 +3029,7 @@
27293029 if (slave->link_failure_count < UINT_MAX)
27303030 slave->link_failure_count++;
27313031
2732
- netdev_info(bond->dev, "interface %s is now down\n",
2733
- slave->dev->name);
3032
+ slave_info(bond->dev, slave->dev, "interface is now down\n");
27343033
27353034 if (slave == oldcurrent)
27363035 do_failover = 1;
....@@ -2883,8 +3182,7 @@
28833182 RCU_INIT_POINTER(bond->current_arp_slave, NULL);
28843183 }
28853184
2886
- netdev_info(bond->dev, "link status definitely up for interface %s\n",
2887
- slave->dev->name);
3185
+ slave_info(bond->dev, slave->dev, "link status definitely up\n");
28883186
28893187 if (!rtnl_dereference(bond->curr_active_slave) ||
28903188 slave == rtnl_dereference(bond->primary_slave))
....@@ -2903,8 +3201,7 @@
29033201 bond_set_slave_inactive_flags(slave,
29043202 BOND_SLAVE_NOTIFY_NOW);
29053203
2906
- netdev_info(bond->dev, "link status definitely down for interface %s, disabling it\n",
2907
- slave->dev->name);
3204
+ slave_info(bond->dev, slave->dev, "link status definitely down, disabling slave\n");
29083205
29093206 if (slave == rtnl_dereference(bond->curr_active_slave)) {
29103207 RCU_INIT_POINTER(bond->current_arp_slave, NULL);
....@@ -2927,8 +3224,9 @@
29273224 continue;
29283225
29293226 default:
2930
- netdev_err(bond->dev, "impossible: new_link %d on slave %s\n",
2931
- slave->link_new_state, slave->dev->name);
3227
+ slave_err(bond->dev, slave->dev,
3228
+ "impossible: link_new_state %d on slave\n",
3229
+ slave->link_new_state);
29323230 continue;
29333231 }
29343232
....@@ -2997,8 +3295,7 @@
29973295 bond_set_slave_inactive_flags(slave,
29983296 BOND_SLAVE_NOTIFY_LATER);
29993297
3000
- netdev_info(bond->dev, "backup interface %s is now down\n",
3001
- slave->dev->name);
3298
+ slave_info(bond->dev, slave->dev, "backup interface is now down\n");
30023299 }
30033300 if (slave == curr_arp_slave)
30043301 found = true;
....@@ -3069,9 +3366,11 @@
30693366 if (!rtnl_trylock())
30703367 return;
30713368
3072
- if (should_notify_peers)
3369
+ if (should_notify_peers) {
3370
+ bond->send_peer_notif--;
30733371 call_netdevice_notifiers(NETDEV_NOTIFY_PEERS,
30743372 bond->dev);
3373
+ }
30753374 if (should_notify_rtnl) {
30763375 bond_slave_state_notify(bond);
30773376 bond_slave_link_notify(bond);
....@@ -3110,18 +3409,19 @@
31103409 {
31113410 struct bonding *event_bond = netdev_priv(bond_dev);
31123411
3412
+ netdev_dbg(bond_dev, "%s called\n", __func__);
3413
+
31133414 switch (event) {
31143415 case NETDEV_CHANGENAME:
31153416 return bond_event_changename(event_bond);
31163417 case NETDEV_UNREGISTER:
31173418 bond_remove_proc_entry(event_bond);
3419
+#ifdef CONFIG_XFRM_OFFLOAD
3420
+ xfrm_dev_state_flush(dev_net(bond_dev), bond_dev, true);
3421
+#endif /* CONFIG_XFRM_OFFLOAD */
31183422 break;
31193423 case NETDEV_REGISTER:
31203424 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--;
31253425 break;
31263426 default:
31273427 break;
....@@ -3141,11 +3441,16 @@
31413441 * before netdev_rx_handler_register is called in which case
31423442 * slave will be NULL
31433443 */
3144
- if (!slave)
3444
+ if (!slave) {
3445
+ netdev_dbg(slave_dev, "%s called on NULL slave\n", __func__);
31453446 return NOTIFY_DONE;
3447
+ }
3448
+
31463449 bond_dev = slave->bond->dev;
31473450 bond = slave->bond;
31483451 primary = rtnl_dereference(bond->primary_slave);
3452
+
3453
+ slave_dbg(bond_dev, slave_dev, "%s called\n", __func__);
31493454
31503455 switch (event) {
31513456 case NETDEV_UNREGISTER:
....@@ -3173,7 +3478,7 @@
31733478
31743479 if (BOND_MODE(bond) == BOND_MODE_8023AD)
31753480 bond_3ad_adapter_speed_duplex_changed(slave);
3176
- /* Fallthrough */
3481
+ fallthrough;
31773482 case NETDEV_DOWN:
31783483 /* Refresh slave-array if applicable!
31793484 * If the setup does not use miimon or arpmon (mode-specific!),
....@@ -3248,7 +3553,8 @@
32483553 {
32493554 struct net_device *event_dev = netdev_notifier_info_to_dev(ptr);
32503555
3251
- netdev_dbg(event_dev, "event: %lx\n", event);
3556
+ netdev_dbg(event_dev, "%s received %s\n",
3557
+ __func__, netdev_cmd_to_name(event));
32523558
32533559 if (!(event_dev->priv_flags & IFF_BONDING))
32543560 return NOTIFY_DONE;
....@@ -3256,16 +3562,13 @@
32563562 if (event_dev->flags & IFF_MASTER) {
32573563 int ret;
32583564
3259
- netdev_dbg(event_dev, "IFF_MASTER\n");
32603565 ret = bond_master_netdev_event(event, event_dev);
32613566 if (ret != NOTIFY_DONE)
32623567 return ret;
32633568 }
32643569
3265
- if (event_dev->flags & IFF_SLAVE) {
3266
- netdev_dbg(event_dev, "IFF_SLAVE\n");
3570
+ if (event_dev->flags & IFF_SLAVE)
32673571 return bond_slave_netdev_event(event, event_dev);
3268
- }
32693572
32703573 return NOTIFY_DONE;
32713574 }
....@@ -3287,39 +3590,78 @@
32873590 return 0;
32883591 }
32893592
3593
+static bool bond_flow_ip(struct sk_buff *skb, struct flow_keys *fk,
3594
+ int *noff, int *proto, bool l34)
3595
+{
3596
+ const struct ipv6hdr *iph6;
3597
+ const struct iphdr *iph;
3598
+
3599
+ if (skb->protocol == htons(ETH_P_IP)) {
3600
+ if (unlikely(!pskb_may_pull(skb, *noff + sizeof(*iph))))
3601
+ return false;
3602
+ iph = (const struct iphdr *)(skb->data + *noff);
3603
+ iph_to_flow_copy_v4addrs(fk, iph);
3604
+ *noff += iph->ihl << 2;
3605
+ if (!ip_is_fragment(iph))
3606
+ *proto = iph->protocol;
3607
+ } else if (skb->protocol == htons(ETH_P_IPV6)) {
3608
+ if (unlikely(!pskb_may_pull(skb, *noff + sizeof(*iph6))))
3609
+ return false;
3610
+ iph6 = (const struct ipv6hdr *)(skb->data + *noff);
3611
+ iph_to_flow_copy_v6addrs(fk, iph6);
3612
+ *noff += sizeof(*iph6);
3613
+ *proto = iph6->nexthdr;
3614
+ } else {
3615
+ return false;
3616
+ }
3617
+
3618
+ if (l34 && *proto >= 0)
3619
+ fk->ports.ports = skb_flow_get_ports(skb, *noff, *proto);
3620
+
3621
+ return true;
3622
+}
3623
+
32903624 /* Extract the appropriate headers based on bond's xmit policy */
32913625 static bool bond_flow_dissect(struct bonding *bond, struct sk_buff *skb,
32923626 struct flow_keys *fk)
32933627 {
3294
- const struct ipv6hdr *iph6;
3295
- const struct iphdr *iph;
3628
+ bool l34 = bond->params.xmit_policy == BOND_XMIT_POLICY_LAYER34;
32963629 int noff, proto = -1;
32973630
3298
- if (bond->params.xmit_policy > BOND_XMIT_POLICY_LAYER23)
3299
- return skb_flow_dissect_flow_keys(skb, fk, 0);
3631
+ if (bond->params.xmit_policy > BOND_XMIT_POLICY_LAYER23) {
3632
+ memset(fk, 0, sizeof(*fk));
3633
+ return __skb_flow_dissect(NULL, skb, &flow_keys_bonding,
3634
+ fk, NULL, 0, 0, 0, 0);
3635
+ }
33003636
33013637 fk->ports.ports = 0;
3638
+ memset(&fk->icmp, 0, sizeof(fk->icmp));
33023639 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 {
3640
+ if (!bond_flow_ip(skb, fk, &noff, &proto, l34))
33193641 return false;
3642
+
3643
+ /* ICMP error packets contains at least 8 bytes of the header
3644
+ * of the packet which generated the error. Use this information
3645
+ * to correlate ICMP error packets within the same flow which
3646
+ * generated the error.
3647
+ */
3648
+ if (proto == IPPROTO_ICMP || proto == IPPROTO_ICMPV6) {
3649
+ skb_flow_get_icmp_tci(skb, &fk->icmp, skb->data,
3650
+ skb_transport_offset(skb),
3651
+ skb_headlen(skb));
3652
+ if (proto == IPPROTO_ICMP) {
3653
+ if (!icmp_is_err(fk->icmp.type))
3654
+ return true;
3655
+
3656
+ noff += sizeof(struct icmphdr);
3657
+ } else if (proto == IPPROTO_ICMPV6) {
3658
+ if (!icmpv6_is_err(fk->icmp.type))
3659
+ return true;
3660
+
3661
+ noff += sizeof(struct icmp6hdr);
3662
+ }
3663
+ return bond_flow_ip(skb, fk, &noff, &proto, l34);
33203664 }
3321
- if (bond->params.xmit_policy == BOND_XMIT_POLICY_LAYER34 && proto >= 0)
3322
- fk->ports.ports = skb_flow_get_ports(skb, noff, proto);
33233665
33243666 return true;
33253667 }
....@@ -3346,10 +3688,14 @@
33463688 return bond_eth_hash(skb);
33473689
33483690 if (bond->params.xmit_policy == BOND_XMIT_POLICY_LAYER23 ||
3349
- bond->params.xmit_policy == BOND_XMIT_POLICY_ENCAP23)
3691
+ bond->params.xmit_policy == BOND_XMIT_POLICY_ENCAP23) {
33503692 hash = bond_eth_hash(skb);
3351
- else
3352
- hash = (__force u32)flow.ports.ports;
3693
+ } else {
3694
+ if (flow.icmp.id)
3695
+ memcpy(&hash, &flow.icmp, sizeof(hash));
3696
+ else
3697
+ memcpy(&hash, &flow.ports.ports, sizeof(hash));
3698
+ }
33533699 hash ^= (__force u32)flow_get_u32_dst(&flow) ^
33543700 (__force u32)flow_get_u32_src(&flow);
33553701 hash ^= (hash >> 16);
....@@ -3424,6 +3770,9 @@
34243770 /* register to receive LACPDUs */
34253771 bond->recv_probe = bond_3ad_lacpdu_recv;
34263772 bond_3ad_initiate_agg_selection(bond, 1);
3773
+
3774
+ bond_for_each_slave(bond, slave, iter)
3775
+ dev_mc_add(slave->dev, lacpdu_mcast_addr);
34273776 }
34283777
34293778 if (bond_mode_can_use_xmit_hash(bond))
....@@ -3435,12 +3784,26 @@
34353784 static int bond_close(struct net_device *bond_dev)
34363785 {
34373786 struct bonding *bond = netdev_priv(bond_dev);
3787
+ struct slave *slave;
34383788
34393789 bond_work_cancel_all(bond);
34403790 bond->send_peer_notif = 0;
34413791 if (bond_is_lb(bond))
34423792 bond_alb_deinitialize(bond);
34433793 bond->recv_probe = NULL;
3794
+
3795
+ if (bond_uses_primary(bond)) {
3796
+ rcu_read_lock();
3797
+ slave = rcu_dereference(bond->curr_active_slave);
3798
+ if (slave)
3799
+ bond_hw_addr_flush(bond_dev, slave->dev);
3800
+ rcu_read_unlock();
3801
+ } else {
3802
+ struct list_head *iter;
3803
+
3804
+ bond_for_each_slave(bond, slave, iter)
3805
+ bond_hw_addr_flush(bond_dev, slave->dev);
3806
+ }
34443807
34453808 return 0;
34463809 }
....@@ -3474,12 +3837,46 @@
34743837 }
34753838 }
34763839
3477
-static int bond_get_nest_level(struct net_device *bond_dev)
3840
+#ifdef CONFIG_LOCKDEP
3841
+static int bond_get_lowest_level_rcu(struct net_device *dev)
34783842 {
3479
- struct bonding *bond = netdev_priv(bond_dev);
3843
+ struct net_device *ldev, *next, *now, *dev_stack[MAX_NEST_DEV + 1];
3844
+ struct list_head *niter, *iter, *iter_stack[MAX_NEST_DEV + 1];
3845
+ int cur = 0, max = 0;
34803846
3481
- return bond->nest_level;
3847
+ now = dev;
3848
+ iter = &dev->adj_list.lower;
3849
+
3850
+ while (1) {
3851
+ next = NULL;
3852
+ while (1) {
3853
+ ldev = netdev_next_lower_dev_rcu(now, &iter);
3854
+ if (!ldev)
3855
+ break;
3856
+
3857
+ next = ldev;
3858
+ niter = &ldev->adj_list.lower;
3859
+ dev_stack[cur] = now;
3860
+ iter_stack[cur++] = iter;
3861
+ if (max <= cur)
3862
+ max = cur;
3863
+ break;
3864
+ }
3865
+
3866
+ if (!next) {
3867
+ if (!cur)
3868
+ return max;
3869
+ next = dev_stack[--cur];
3870
+ niter = iter_stack[cur];
3871
+ }
3872
+
3873
+ now = next;
3874
+ iter = niter;
3875
+ }
3876
+
3877
+ return max;
34823878 }
3879
+#endif
34833880
34843881 static void bond_get_stats(struct net_device *bond_dev,
34853882 struct rtnl_link_stats64 *stats)
....@@ -3488,11 +3885,17 @@
34883885 struct rtnl_link_stats64 temp;
34893886 struct list_head *iter;
34903887 struct slave *slave;
3888
+ int nest_level = 0;
34913889
3492
- spin_lock_nested(&bond->stats_lock, bond_get_nest_level(bond_dev));
3493
- memcpy(stats, &bond->bond_stats, sizeof(*stats));
34943890
34953891 rcu_read_lock();
3892
+#ifdef CONFIG_LOCKDEP
3893
+ nest_level = bond_get_lowest_level_rcu(bond_dev);
3894
+#endif
3895
+
3896
+ spin_lock_nested(&bond->stats_lock, nest_level);
3897
+ memcpy(stats, &bond->bond_stats, sizeof(*stats));
3898
+
34963899 bond_for_each_slave_rcu(bond, slave, iter) {
34973900 const struct rtnl_link_stats64 *new =
34983901 dev_get_stats(slave->dev, &temp);
....@@ -3502,10 +3905,10 @@
35023905 /* save off the slave stats for the next run */
35033906 memcpy(&slave->slave_stats, new, sizeof(*new));
35043907 }
3505
- rcu_read_unlock();
35063908
35073909 memcpy(&bond->bond_stats, stats, sizeof(*stats));
35083910 spin_unlock(&bond->stats_lock);
3911
+ rcu_read_unlock();
35093912 }
35103913
35113914 static int bond_do_ioctl(struct net_device *bond_dev, struct ifreq *ifr, int cmd)
....@@ -3530,7 +3933,7 @@
35303933 return -EINVAL;
35313934
35323935 mii->phy_id = 0;
3533
- /* Fall Through */
3936
+ fallthrough;
35343937 case SIOCGMIIREG:
35353938 /* We do this again just in case we were called by SIOCGMIIREG
35363939 * instead of SIOCGMIIPHY.
....@@ -3582,12 +3985,11 @@
35823985
35833986 slave_dev = __dev_get_by_name(net, ifr->ifr_slave);
35843987
3585
- netdev_dbg(bond_dev, "slave_dev=%p:\n", slave_dev);
3988
+ slave_dbg(bond_dev, slave_dev, "slave_dev=%p:\n", slave_dev);
35863989
35873990 if (!slave_dev)
35883991 return -ENODEV;
35893992
3590
- netdev_dbg(bond_dev, "slave_dev->name=%s:\n", slave_dev->name);
35913993 switch (cmd) {
35923994 case BOND_ENSLAVE_OLD:
35933995 case SIOCBONDENSLAVE:
....@@ -3599,8 +4001,7 @@
35994001 break;
36004002 case BOND_SETHWADDR_OLD:
36014003 case SIOCBONDSETHWADDR:
3602
- bond_set_dev_addr(bond_dev, slave_dev);
3603
- res = 0;
4004
+ res = bond_set_dev_addr(bond_dev, slave_dev);
36044005 break;
36054006 case BOND_CHANGE_ACTIVE_OLD:
36064007 case SIOCBONDCHANGEACTIVE:
....@@ -3656,32 +4057,35 @@
36564057 const struct net_device_ops *slave_ops;
36574058 struct neigh_parms parms;
36584059 struct slave *slave;
3659
- int ret;
4060
+ int ret = 0;
36604061
3661
- slave = bond_first_slave(bond);
4062
+ rcu_read_lock();
4063
+ slave = bond_first_slave_rcu(bond);
36624064 if (!slave)
3663
- return 0;
4065
+ goto out;
36644066 slave_ops = slave->dev->netdev_ops;
36654067 if (!slave_ops->ndo_neigh_setup)
3666
- return 0;
4068
+ goto out;
36674069
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).
4070
+ /* TODO: find another way [1] to implement this.
4071
+ * Passing a zeroed structure is fragile,
4072
+ * but at least we do not pass garbage.
4073
+ *
4074
+ * [1] One way would be that ndo_neigh_setup() never touch
4075
+ * struct neigh_parms, but propagate the new neigh_setup()
4076
+ * back to ___neigh_create() / neigh_parms_alloc()
36784077 */
3679
- n->parms->neigh_cleanup = parms.neigh_cleanup;
4078
+ memset(&parms, 0, sizeof(parms));
4079
+ ret = slave_ops->ndo_neigh_setup(slave->dev, &parms);
36804080
3681
- if (!parms.neigh_setup)
3682
- return 0;
4081
+ if (ret)
4082
+ goto out;
36834083
3684
- return parms.neigh_setup(n);
4084
+ if (parms.neigh_setup)
4085
+ ret = parms.neigh_setup(n);
4086
+out:
4087
+ rcu_read_unlock();
4088
+ return ret;
36854089 }
36864090
36874091 /* The bonding ndo_neigh_setup is called at init time beofre any
....@@ -3713,7 +4117,7 @@
37134117 netdev_dbg(bond_dev, "bond=%p, new_mtu=%d\n", bond, new_mtu);
37144118
37154119 bond_for_each_slave(bond, slave, iter) {
3716
- netdev_dbg(bond_dev, "s %p c_m %p\n",
4120
+ slave_dbg(bond_dev, slave->dev, "s %p c_m %p\n",
37174121 slave, slave->dev->netdev_ops->ndo_change_mtu);
37184122
37194123 res = dev_set_mtu(slave->dev, new_mtu);
....@@ -3727,8 +4131,8 @@
37274131 * means changing their mtu from timer context, which
37284132 * is probably not a good idea.
37294133 */
3730
- netdev_dbg(bond_dev, "err %d %s\n", res,
3731
- slave->dev->name);
4134
+ slave_dbg(bond_dev, slave->dev, "err %d setting mtu to %d\n",
4135
+ res, new_mtu);
37324136 goto unwind;
37334137 }
37344138 }
....@@ -3746,10 +4150,9 @@
37464150 break;
37474151
37484152 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
- }
4153
+ if (tmp_res)
4154
+ slave_dbg(bond_dev, rollback_slave->dev, "unwind err %d\n",
4155
+ tmp_res);
37534156 }
37544157
37554158 return res;
....@@ -3773,7 +4176,7 @@
37734176 return bond_alb_set_mac_address(bond_dev, addr);
37744177
37754178
3776
- netdev_dbg(bond_dev, "bond=%p\n", bond);
4179
+ netdev_dbg(bond_dev, "%s: bond=%p\n", __func__, bond);
37774180
37784181 /* If fail_over_mac is enabled, do nothing and return success.
37794182 * Returning an error causes ifenslave to fail.
....@@ -3786,8 +4189,9 @@
37864189 return -EADDRNOTAVAIL;
37874190
37884191 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);
4192
+ slave_dbg(bond_dev, slave->dev, "%s: slave=%p\n",
4193
+ __func__, slave);
4194
+ res = dev_set_mac_address(slave->dev, addr, NULL);
37914195 if (res) {
37924196 /* TODO: consider downing the slave
37934197 * and retry ?
....@@ -3795,7 +4199,8 @@
37954199 * breakage anyway until ARP finish
37964200 * updating, so...
37974201 */
3798
- netdev_dbg(bond_dev, "err %d %s\n", res, slave->dev->name);
4202
+ slave_dbg(bond_dev, slave->dev, "%s: err %d\n",
4203
+ __func__, res);
37994204 goto unwind;
38004205 }
38014206 }
....@@ -3816,10 +4221,10 @@
38164221 break;
38174222
38184223 tmp_res = dev_set_mac_address(rollback_slave->dev,
3819
- (struct sockaddr *)&tmp_ss);
4224
+ (struct sockaddr *)&tmp_ss, NULL);
38204225 if (tmp_res) {
3821
- netdev_dbg(bond_dev, "unwind err %d dev %s\n",
3822
- tmp_res, rollback_slave->dev->name);
4226
+ slave_dbg(bond_dev, rollback_slave->dev, "%s: unwind err %d\n",
4227
+ __func__, tmp_res);
38234228 }
38244229 }
38254230
....@@ -3827,16 +4232,15 @@
38274232 }
38284233
38294234 /**
3830
- * bond_xmit_slave_id - transmit skb through slave with slave_id
4235
+ * bond_get_slave_by_id - get xmit slave with slave_id
38314236 * @bond: bonding device that is transmitting
3832
- * @skb: buffer to transmit
38334237 * @slave_id: slave id up to slave_cnt-1 through which to transmit
38344238 *
3835
- * This function tries to transmit through slave with slave_id but in case
4239
+ * This function tries to get slave with slave_id but in case
38364240 * 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.
38384241 */
3839
-static void bond_xmit_slave_id(struct bonding *bond, struct sk_buff *skb, int slave_id)
4242
+static struct slave *bond_get_slave_by_id(struct bonding *bond,
4243
+ int slave_id)
38404244 {
38414245 struct list_head *iter;
38424246 struct slave *slave;
....@@ -3845,10 +4249,8 @@
38454249 /* Here we start from the slave with slave_id */
38464250 bond_for_each_slave_rcu(bond, slave, iter) {
38474251 if (--i < 0) {
3848
- if (bond_slave_can_tx(slave)) {
3849
- bond_dev_queue_xmit(bond, skb, slave->dev);
3850
- return;
3851
- }
4252
+ if (bond_slave_can_tx(slave))
4253
+ return slave;
38524254 }
38534255 }
38544256
....@@ -3857,13 +4259,11 @@
38574259 bond_for_each_slave_rcu(bond, slave, iter) {
38584260 if (--i < 0)
38594261 break;
3860
- if (bond_slave_can_tx(slave)) {
3861
- bond_dev_queue_xmit(bond, skb, slave->dev);
3862
- return;
3863
- }
4262
+ if (bond_slave_can_tx(slave))
4263
+ return slave;
38644264 }
38654265 /* no slave that can tx has been found */
3866
- bond_tx_drop(bond->dev, skb);
4266
+ return NULL;
38674267 }
38684268
38694269 /**
....@@ -3899,10 +4299,9 @@
38994299 return slave_id;
39004300 }
39014301
3902
-static netdev_tx_t bond_xmit_roundrobin(struct sk_buff *skb,
3903
- struct net_device *bond_dev)
4302
+static struct slave *bond_xmit_roundrobin_slave_get(struct bonding *bond,
4303
+ struct sk_buff *skb)
39044304 {
3905
- struct bonding *bond = netdev_priv(bond_dev);
39064305 struct slave *slave;
39074306 int slave_cnt;
39084307 u32 slave_id;
....@@ -3924,22 +4323,37 @@
39244323 if (iph->protocol == IPPROTO_IGMP) {
39254324 slave = rcu_dereference(bond->curr_active_slave);
39264325 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;
4326
+ return slave;
4327
+ return bond_get_slave_by_id(bond, 0);
39314328 }
39324329 }
39334330
39344331 non_igmp:
39354332 slave_cnt = READ_ONCE(bond->slave_cnt);
39364333 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);
4334
+ slave_id = bond_rr_gen_slave_id(bond) % slave_cnt;
4335
+ return bond_get_slave_by_id(bond, slave_id);
39414336 }
3942
- return NETDEV_TX_OK;
4337
+ return NULL;
4338
+}
4339
+
4340
+static netdev_tx_t bond_xmit_roundrobin(struct sk_buff *skb,
4341
+ struct net_device *bond_dev)
4342
+{
4343
+ struct bonding *bond = netdev_priv(bond_dev);
4344
+ struct slave *slave;
4345
+
4346
+ slave = bond_xmit_roundrobin_slave_get(bond, skb);
4347
+ if (likely(slave))
4348
+ return bond_dev_queue_xmit(bond, skb, slave->dev);
4349
+
4350
+ return bond_tx_drop(bond_dev, skb);
4351
+}
4352
+
4353
+static struct slave *bond_xmit_activebackup_slave_get(struct bonding *bond,
4354
+ struct sk_buff *skb)
4355
+{
4356
+ return rcu_dereference(bond->curr_active_slave);
39434357 }
39444358
39454359 /* In active-backup mode, we know that bond->curr_active_slave is always valid if
....@@ -3951,13 +4365,11 @@
39514365 struct bonding *bond = netdev_priv(bond_dev);
39524366 struct slave *slave;
39534367
3954
- slave = rcu_dereference(bond->curr_active_slave);
4368
+ slave = bond_xmit_activebackup_slave_get(bond, skb);
39554369 if (slave)
3956
- bond_dev_queue_xmit(bond, skb, slave->dev);
3957
- else
3958
- bond_tx_drop(bond_dev, skb);
4370
+ return bond_dev_queue_xmit(bond, skb, slave->dev);
39594371
3960
- return NETDEV_TX_OK;
4372
+ return bond_tx_drop(bond_dev, skb);
39614373 }
39624374
39634375 /* Use this to update slave_array when (a) it's not appropriate to update
....@@ -3991,6 +4403,61 @@
39914403 bond_slave_arr_work_rearm(bond, 1);
39924404 }
39934405
4406
+static void bond_skip_slave(struct bond_up_slave *slaves,
4407
+ struct slave *skipslave)
4408
+{
4409
+ int idx;
4410
+
4411
+ /* Rare situation where caller has asked to skip a specific
4412
+ * slave but allocation failed (most likely!). BTW this is
4413
+ * only possible when the call is initiated from
4414
+ * __bond_release_one(). In this situation; overwrite the
4415
+ * skipslave entry in the array with the last entry from the
4416
+ * array to avoid a situation where the xmit path may choose
4417
+ * this to-be-skipped slave to send a packet out.
4418
+ */
4419
+ for (idx = 0; slaves && idx < slaves->count; idx++) {
4420
+ if (skipslave == slaves->arr[idx]) {
4421
+ slaves->arr[idx] =
4422
+ slaves->arr[slaves->count - 1];
4423
+ slaves->count--;
4424
+ break;
4425
+ }
4426
+ }
4427
+}
4428
+
4429
+static void bond_set_slave_arr(struct bonding *bond,
4430
+ struct bond_up_slave *usable_slaves,
4431
+ struct bond_up_slave *all_slaves)
4432
+{
4433
+ struct bond_up_slave *usable, *all;
4434
+
4435
+ usable = rtnl_dereference(bond->usable_slaves);
4436
+ rcu_assign_pointer(bond->usable_slaves, usable_slaves);
4437
+ kfree_rcu(usable, rcu);
4438
+
4439
+ all = rtnl_dereference(bond->all_slaves);
4440
+ rcu_assign_pointer(bond->all_slaves, all_slaves);
4441
+ kfree_rcu(all, rcu);
4442
+}
4443
+
4444
+static void bond_reset_slave_arr(struct bonding *bond)
4445
+{
4446
+ struct bond_up_slave *usable, *all;
4447
+
4448
+ usable = rtnl_dereference(bond->usable_slaves);
4449
+ if (usable) {
4450
+ RCU_INIT_POINTER(bond->usable_slaves, NULL);
4451
+ kfree_rcu(usable, rcu);
4452
+ }
4453
+
4454
+ all = rtnl_dereference(bond->all_slaves);
4455
+ if (all) {
4456
+ RCU_INIT_POINTER(bond->all_slaves, NULL);
4457
+ kfree_rcu(all, rcu);
4458
+ }
4459
+}
4460
+
39944461 /* Build the usable slaves array in control path for modes that use xmit-hash
39954462 * to determine the slave interface -
39964463 * (a) BOND_MODE_8023AD
....@@ -4001,9 +4468,9 @@
40014468 */
40024469 int bond_update_slave_arr(struct bonding *bond, struct slave *skipslave)
40034470 {
4471
+ struct bond_up_slave *usable_slaves = NULL, *all_slaves = NULL;
40044472 struct slave *slave;
40054473 struct list_head *iter;
4006
- struct bond_up_slave *new_arr, *old_arr;
40074474 int agg_id = 0;
40084475 int ret = 0;
40094476
....@@ -4011,11 +4478,12 @@
40114478 WARN_ON(lockdep_is_held(&bond->mode_lock));
40124479 #endif
40134480
4014
- new_arr = kzalloc(offsetof(struct bond_up_slave, arr[bond->slave_cnt]),
4015
- GFP_KERNEL);
4016
- if (!new_arr) {
4481
+ usable_slaves = kzalloc(struct_size(usable_slaves, arr,
4482
+ bond->slave_cnt), GFP_KERNEL);
4483
+ all_slaves = kzalloc(struct_size(all_slaves, arr,
4484
+ bond->slave_cnt), GFP_KERNEL);
4485
+ if (!usable_slaves || !all_slaves) {
40174486 ret = -ENOMEM;
4018
- pr_err("Failed to build slave-array.\n");
40194487 goto out;
40204488 }
40214489 if (BOND_MODE(bond) == BOND_MODE_8023AD) {
....@@ -4023,20 +4491,19 @@
40234491
40244492 if (bond_3ad_get_active_agg_info(bond, &ad_info)) {
40254493 pr_debug("bond_3ad_get_active_agg_info failed\n");
4026
- kfree_rcu(new_arr, rcu);
40274494 /* No active aggragator means it's not safe to use
40284495 * the previous array.
40294496 */
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
- }
4497
+ bond_reset_slave_arr(bond);
40354498 goto out;
40364499 }
40374500 agg_id = ad_info.aggregator_id;
40384501 }
40394502 bond_for_each_slave(bond, slave, iter) {
4503
+ if (skipslave == slave)
4504
+ continue;
4505
+
4506
+ all_slaves->arr[all_slaves->count++] = slave;
40404507 if (BOND_MODE(bond) == BOND_MODE_8023AD) {
40414508 struct aggregator *agg;
40424509
....@@ -4046,43 +4513,43 @@
40464513 }
40474514 if (!bond_slave_can_tx(slave))
40484515 continue;
4049
- if (skipslave == slave)
4050
- continue;
40514516
4052
- netdev_dbg(bond->dev,
4053
- "Adding slave dev %s to tx hash array[%d]\n",
4054
- slave->dev->name, new_arr->count);
4517
+ slave_dbg(bond->dev, slave->dev, "Adding slave to tx hash array[%d]\n",
4518
+ usable_slaves->count);
40554519
4056
- new_arr->arr[new_arr->count++] = slave;
4520
+ usable_slaves->arr[usable_slaves->count++] = slave;
40574521 }
40584522
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);
4523
+ bond_set_slave_arr(bond, usable_slaves, all_slaves);
4524
+ return ret;
40634525 out:
40644526 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
- }
4527
+ bond_skip_slave(rtnl_dereference(bond->all_slaves),
4528
+ skipslave);
4529
+ bond_skip_slave(rtnl_dereference(bond->usable_slaves),
4530
+ skipslave);
40844531 }
4532
+ kfree_rcu(all_slaves, rcu);
4533
+ kfree_rcu(usable_slaves, rcu);
4534
+
40854535 return ret;
4536
+}
4537
+
4538
+static struct slave *bond_xmit_3ad_xor_slave_get(struct bonding *bond,
4539
+ struct sk_buff *skb,
4540
+ struct bond_up_slave *slaves)
4541
+{
4542
+ struct slave *slave;
4543
+ unsigned int count;
4544
+ u32 hash;
4545
+
4546
+ hash = bond_xmit_hash(bond, skb);
4547
+ count = slaves ? READ_ONCE(slaves->count) : 0;
4548
+ if (unlikely(!count))
4549
+ return NULL;
4550
+
4551
+ slave = slaves->arr[hash % count];
4552
+ return slave;
40864553 }
40874554
40884555 /* Use this Xmit function for 3AD as well as XOR modes. The current
....@@ -4093,20 +4560,15 @@
40934560 struct net_device *dev)
40944561 {
40954562 struct bonding *bond = netdev_priv(dev);
4096
- struct slave *slave;
40974563 struct bond_up_slave *slaves;
4098
- unsigned int count;
4564
+ struct slave *slave;
40994565
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
- }
4566
+ slaves = rcu_dereference(bond->usable_slaves);
4567
+ slave = bond_xmit_3ad_xor_slave_get(bond, skb, slaves);
4568
+ if (likely(slave))
4569
+ return bond_dev_queue_xmit(bond, skb, slave->dev);
41084570
4109
- return NETDEV_TX_OK;
4571
+ return bond_tx_drop(dev, skb);
41104572 }
41114573
41124574 /* in broadcast mode, we send everything to all usable interfaces. */
....@@ -4116,27 +4578,39 @@
41164578 struct bonding *bond = netdev_priv(bond_dev);
41174579 struct slave *slave = NULL;
41184580 struct list_head *iter;
4581
+ bool xmit_suc = false;
4582
+ bool skb_used = false;
41194583
41204584 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);
4585
+ struct sk_buff *skb2;
41254586
4587
+ if (!(bond_slave_is_up(slave) && slave->link == BOND_LINK_UP))
4588
+ continue;
4589
+
4590
+ if (bond_is_last_slave(bond, slave)) {
4591
+ skb2 = skb;
4592
+ skb_used = true;
4593
+ } else {
4594
+ skb2 = skb_clone(skb, GFP_ATOMIC);
41264595 if (!skb2) {
41274596 net_err_ratelimited("%s: Error: %s: skb_clone() failed\n",
41284597 bond_dev->name, __func__);
41294598 continue;
41304599 }
4131
- bond_dev_queue_xmit(bond, skb2, slave->dev);
41324600 }
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);
41384601
4139
- return NETDEV_TX_OK;
4602
+ if (bond_dev_queue_xmit(bond, skb2, slave->dev) == NETDEV_TX_OK)
4603
+ xmit_suc = true;
4604
+ }
4605
+
4606
+ if (!skb_used)
4607
+ dev_kfree_skb_any(skb);
4608
+
4609
+ if (xmit_suc)
4610
+ return NETDEV_TX_OK;
4611
+
4612
+ atomic_long_inc(&bond_dev->tx_dropped);
4613
+ return NET_XMIT_DROP;
41404614 }
41414615
41424616 /*------------------------- Device initialization ---------------------------*/
....@@ -4169,8 +4643,7 @@
41694643
41704644
41714645 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)
4646
+ struct net_device *sb_dev)
41744647 {
41754648 /* This helper function exists to help dev_pick_tx get the correct
41764649 * destination queue. Using a helper function skips a call to
....@@ -4188,6 +4661,48 @@
41884661 } while (txq >= dev->real_num_tx_queues);
41894662 }
41904663 return txq;
4664
+}
4665
+
4666
+static struct net_device *bond_xmit_get_slave(struct net_device *master_dev,
4667
+ struct sk_buff *skb,
4668
+ bool all_slaves)
4669
+{
4670
+ struct bonding *bond = netdev_priv(master_dev);
4671
+ struct bond_up_slave *slaves;
4672
+ struct slave *slave = NULL;
4673
+
4674
+ switch (BOND_MODE(bond)) {
4675
+ case BOND_MODE_ROUNDROBIN:
4676
+ slave = bond_xmit_roundrobin_slave_get(bond, skb);
4677
+ break;
4678
+ case BOND_MODE_ACTIVEBACKUP:
4679
+ slave = bond_xmit_activebackup_slave_get(bond, skb);
4680
+ break;
4681
+ case BOND_MODE_8023AD:
4682
+ case BOND_MODE_XOR:
4683
+ if (all_slaves)
4684
+ slaves = rcu_dereference(bond->all_slaves);
4685
+ else
4686
+ slaves = rcu_dereference(bond->usable_slaves);
4687
+ slave = bond_xmit_3ad_xor_slave_get(bond, skb, slaves);
4688
+ break;
4689
+ case BOND_MODE_BROADCAST:
4690
+ break;
4691
+ case BOND_MODE_ALB:
4692
+ slave = bond_xmit_alb_slave_get(bond, skb);
4693
+ break;
4694
+ case BOND_MODE_TLB:
4695
+ slave = bond_xmit_tlb_slave_get(bond, skb);
4696
+ break;
4697
+ default:
4698
+ /* Should never happen, mode already checked */
4699
+ WARN_ONCE(true, "Unknown bonding mode");
4700
+ break;
4701
+ }
4702
+
4703
+ if (slave)
4704
+ return slave->dev;
4705
+ return NULL;
41914706 }
41924707
41934708 static netdev_tx_t __bond_start_xmit(struct sk_buff *skb, struct net_device *dev)
....@@ -4216,8 +4731,7 @@
42164731 /* Should never happen, mode already checked */
42174732 netdev_err(dev, "Unknown bonding mode %d\n", BOND_MODE(bond));
42184733 WARN_ON_ONCE(1);
4219
- bond_tx_drop(dev, skb);
4220
- return NETDEV_TX_OK;
4734
+ return bond_tx_drop(dev, skb);
42214735 }
42224736 }
42234737
....@@ -4236,7 +4750,7 @@
42364750 if (bond_has_slaves(bond))
42374751 ret = __bond_start_xmit(skb, dev);
42384752 else
4239
- bond_tx_drop(dev, skb);
4753
+ ret = bond_tx_drop(dev, skb);
42404754 rcu_read_unlock();
42414755
42424756 return ret;
....@@ -4291,7 +4805,6 @@
42914805 struct ethtool_drvinfo *drvinfo)
42924806 {
42934807 strlcpy(drvinfo->driver, DRV_NAME, sizeof(drvinfo->driver));
4294
- strlcpy(drvinfo->version, DRV_VERSION, sizeof(drvinfo->version));
42954808 snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version), "%d",
42964809 BOND_ABI_VERSION);
42974810 }
....@@ -4318,7 +4831,6 @@
43184831 .ndo_neigh_setup = bond_neigh_setup,
43194832 .ndo_vlan_rx_add_vid = bond_vlan_rx_add_vid,
43204833 .ndo_vlan_rx_kill_vid = bond_vlan_rx_kill_vid,
4321
- .ndo_get_lock_subclass = bond_get_nest_level,
43224834 #ifdef CONFIG_NET_POLL_CONTROLLER
43234835 .ndo_netpoll_setup = bond_netpoll_setup,
43244836 .ndo_netpoll_cleanup = bond_netpoll_cleanup,
....@@ -4328,6 +4840,7 @@
43284840 .ndo_del_slave = bond_release,
43294841 .ndo_fix_features = bond_fix_features,
43304842 .ndo_features_check = passthru_features_check,
4843
+ .ndo_get_xmit_slave = bond_xmit_get_slave,
43314844 };
43324845
43334846 static const struct device_type bond_type = {
....@@ -4346,7 +4859,6 @@
43464859 struct bonding *bond = netdev_priv(bond_dev);
43474860
43484861 spin_lock_init(&bond->mode_lock);
4349
- spin_lock_init(&bond->stats_lock);
43504862 bond->params = bonding_defaults;
43514863
43524864 /* Initialize pointers */
....@@ -4368,6 +4880,13 @@
43684880 bond_dev->priv_flags |= IFF_BONDING | IFF_UNICAST_FLT | IFF_NO_QUEUE;
43694881 bond_dev->priv_flags &= ~(IFF_XMIT_DST_RELEASE | IFF_TX_SKB_SHARING);
43704882
4883
+#ifdef CONFIG_XFRM_OFFLOAD
4884
+ /* set up xfrm device ops (only supported in active-backup right now) */
4885
+ bond_dev->xfrmdev_ops = &bond_xfrmdev_ops;
4886
+ INIT_LIST_HEAD(&bond->ipsec_list);
4887
+ spin_lock_init(&bond->ipsec_lock);
4888
+#endif /* CONFIG_XFRM_OFFLOAD */
4889
+
43714890 /* don't acquire bond device's netif_tx_lock when transmitting */
43724891 bond_dev->features |= NETIF_F_LLTX;
43734892
....@@ -4386,8 +4905,16 @@
43864905 NETIF_F_HW_VLAN_CTAG_FILTER;
43874906
43884907 bond_dev->hw_features |= NETIF_F_GSO_ENCAP_ALL | NETIF_F_GSO_UDP_L4;
4908
+#ifdef CONFIG_XFRM_OFFLOAD
4909
+ bond_dev->hw_features |= BOND_XFRM_FEATURES;
4910
+#endif /* CONFIG_XFRM_OFFLOAD */
43894911 bond_dev->features |= bond_dev->hw_features;
43904912 bond_dev->features |= NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_HW_VLAN_STAG_TX;
4913
+#ifdef CONFIG_XFRM_OFFLOAD
4914
+ /* Disable XFRM features if this isn't an active-backup config */
4915
+ if (BOND_MODE(bond) != BOND_MODE_ACTIVEBACKUP)
4916
+ bond_dev->features &= ~BOND_XFRM_FEATURES;
4917
+#endif /* CONFIG_XFRM_OFFLOAD */
43914918 }
43924919
43934920 /* Destroy a bonding device.
....@@ -4396,9 +4923,9 @@
43964923 static void bond_uninit(struct net_device *bond_dev)
43974924 {
43984925 struct bonding *bond = netdev_priv(bond_dev);
4926
+ struct bond_up_slave *usable, *all;
43994927 struct list_head *iter;
44004928 struct slave *slave;
4401
- struct bond_up_slave *arr;
44024929
44034930 bond_netpoll_cleanup(bond_dev);
44044931
....@@ -4407,10 +4934,16 @@
44074934 __bond_release_one(bond_dev, slave->dev, true, true);
44084935 netdev_info(bond_dev, "Released all slaves\n");
44094936
4410
- arr = rtnl_dereference(bond->slave_arr);
4411
- if (arr) {
4412
- RCU_INIT_POINTER(bond->slave_arr, NULL);
4413
- kfree_rcu(arr, rcu);
4937
+ usable = rtnl_dereference(bond->usable_slaves);
4938
+ if (usable) {
4939
+ RCU_INIT_POINTER(bond->usable_slaves, NULL);
4940
+ kfree_rcu(usable, rcu);
4941
+ }
4942
+
4943
+ all = rtnl_dereference(bond->all_slaves);
4944
+ if (all) {
4945
+ RCU_INIT_POINTER(bond->all_slaves, NULL);
4946
+ kfree_rcu(all, rcu);
44144947 }
44154948
44164949 list_del(&bond->bond_list);
....@@ -4769,6 +5302,7 @@
47695302 params->arp_all_targets = arp_all_targets_value;
47705303 params->updelay = updelay;
47715304 params->downdelay = downdelay;
5305
+ params->peer_notif_delay = 0;
47725306 params->use_carrier = use_carrier;
47735307 params->lacp_fast = lacp_fast;
47745308 params->primary[0] = 0;
....@@ -4817,7 +5351,7 @@
48175351 if (!bond->wq)
48185352 return -ENOMEM;
48195353
4820
- bond->nest_level = SINGLE_DEPTH_NESTING;
5354
+ spin_lock_init(&bond->stats_lock);
48215355 netdev_lockdep_set_classes(bond_dev);
48225356
48235357 list_add_tail(&bond->bond_list, &bn->dev_list);
....@@ -4932,8 +5466,6 @@
49325466 int i;
49335467 int res;
49345468
4935
- pr_info("%s", bond_version);
4936
-
49375469 res = bond_check_params(&bonding_defaults);
49385470 if (res)
49395471 goto out;
....@@ -4953,6 +5485,10 @@
49535485 if (res)
49545486 goto err;
49555487 }
5488
+
5489
+ skb_flow_dissector_init(&flow_keys_bonding,
5490
+ flow_keys_bonding_keys,
5491
+ ARRAY_SIZE(flow_keys_bonding_keys));
49565492
49575493 register_netdevice_notifier(&bond_netdev_notifier);
49585494 out:
....@@ -4984,6 +5520,5 @@
49845520 module_init(bonding_init);
49855521 module_exit(bonding_exit);
49865522 MODULE_LICENSE("GPL");
4987
-MODULE_VERSION(DRV_VERSION);
4988
-MODULE_DESCRIPTION(DRV_DESCRIPTION ", v" DRV_VERSION);
5523
+MODULE_DESCRIPTION(DRV_DESCRIPTION);
49895524 MODULE_AUTHOR("Thomas Davis, tadavis@lbl.gov and many others");