79
79
#include <net/pkt_sched.h>
80
80
#include <linux/rculist.h>
81
81
#include <net/flow_dissector.h>
82
+ #include <net/xfrm.h>
82
83
#include <net/bonding.h>
83
84
#include <net/bond_3ad.h>
84
85
#include <net/bond_alb.h>
@@ -278,8 +279,6 @@ const char *bond_mode_name(int mode)
278
279
return names [mode ];
279
280
}
280
281
281
- /*---------------------------------- VLAN -----------------------------------*/
282
-
283
282
/**
284
283
* bond_dev_queue_xmit - Prepare skb for xmit.
285
284
*
@@ -302,6 +301,8 @@ netdev_tx_t bond_dev_queue_xmit(struct bonding *bond, struct sk_buff *skb,
302
301
return dev_queue_xmit (skb );
303
302
}
304
303
304
+ /*---------------------------------- VLAN -----------------------------------*/
305
+
305
306
/* In the following 2 functions, bond_vlan_rx_add_vid and bond_vlan_rx_kill_vid,
306
307
* We don't protect the slave list iteration with a lock because:
307
308
* a. This operation is performed in IOCTL context,
@@ -372,6 +373,84 @@ static int bond_vlan_rx_kill_vid(struct net_device *bond_dev,
372
373
return 0 ;
373
374
}
374
375
376
+ /*---------------------------------- XFRM -----------------------------------*/
377
+
378
+ #ifdef CONFIG_XFRM_OFFLOAD
379
+ /**
380
+ * bond_ipsec_add_sa - program device with a security association
381
+ * @xs: pointer to transformer state struct
382
+ **/
383
+ static int bond_ipsec_add_sa (struct xfrm_state * xs )
384
+ {
385
+ struct net_device * bond_dev = xs -> xso .dev ;
386
+ struct bonding * bond = netdev_priv (bond_dev );
387
+ struct slave * slave = rtnl_dereference (bond -> curr_active_slave );
388
+
389
+ xs -> xso .slave_dev = slave -> dev ;
390
+ bond -> xs = xs ;
391
+
392
+ if (!(slave -> dev -> xfrmdev_ops
393
+ && slave -> dev -> xfrmdev_ops -> xdo_dev_state_add )) {
394
+ slave_warn (bond_dev , slave -> dev , "Slave does not support ipsec offload\n" );
395
+ return - EINVAL ;
396
+ }
397
+
398
+ return slave -> dev -> xfrmdev_ops -> xdo_dev_state_add (xs );
399
+ }
400
+
401
+ /**
402
+ * bond_ipsec_del_sa - clear out this specific SA
403
+ * @xs: pointer to transformer state struct
404
+ **/
405
+ static void bond_ipsec_del_sa (struct xfrm_state * xs )
406
+ {
407
+ struct net_device * bond_dev = xs -> xso .dev ;
408
+ struct bonding * bond = netdev_priv (bond_dev );
409
+ struct slave * slave = rtnl_dereference (bond -> curr_active_slave );
410
+
411
+ if (!slave )
412
+ return ;
413
+
414
+ xs -> xso .slave_dev = slave -> dev ;
415
+
416
+ if (!(slave -> dev -> xfrmdev_ops
417
+ && slave -> dev -> xfrmdev_ops -> xdo_dev_state_delete )) {
418
+ slave_warn (bond_dev , slave -> dev , "%s: no slave xdo_dev_state_delete\n" , __func__ );
419
+ return ;
420
+ }
421
+
422
+ slave -> dev -> xfrmdev_ops -> xdo_dev_state_delete (xs );
423
+ }
424
+
425
+ /**
426
+ * bond_ipsec_offload_ok - can this packet use the xfrm hw offload
427
+ * @skb: current data packet
428
+ * @xs: pointer to transformer state struct
429
+ **/
430
+ static bool bond_ipsec_offload_ok (struct sk_buff * skb , struct xfrm_state * xs )
431
+ {
432
+ struct net_device * bond_dev = xs -> xso .dev ;
433
+ struct bonding * bond = netdev_priv (bond_dev );
434
+ struct slave * curr_active = rtnl_dereference (bond -> curr_active_slave );
435
+ struct net_device * slave_dev = curr_active -> dev ;
436
+
437
+ if (!(slave_dev -> xfrmdev_ops
438
+ && slave_dev -> xfrmdev_ops -> xdo_dev_offload_ok )) {
439
+ slave_warn (bond_dev , slave_dev , "%s: no slave xdo_dev_offload_ok\n" , __func__ );
440
+ return false;
441
+ }
442
+
443
+ xs -> xso .slave_dev = slave_dev ;
444
+ return slave_dev -> xfrmdev_ops -> xdo_dev_offload_ok (skb , xs );
445
+ }
446
+
447
+ static const struct xfrmdev_ops bond_xfrmdev_ops = {
448
+ .xdo_dev_state_add = bond_ipsec_add_sa ,
449
+ .xdo_dev_state_delete = bond_ipsec_del_sa ,
450
+ .xdo_dev_offload_ok = bond_ipsec_offload_ok ,
451
+ };
452
+ #endif /* CONFIG_XFRM_OFFLOAD */
453
+
375
454
/*------------------------------- Link status -------------------------------*/
376
455
377
456
/* Set the carrier state for the master according to the state of its
@@ -879,6 +958,11 @@ void bond_change_active_slave(struct bonding *bond, struct slave *new_active)
879
958
return ;
880
959
881
960
if (new_active ) {
961
+ #ifdef CONFIG_XFRM_OFFLOAD
962
+ if ((BOND_MODE (bond ) == BOND_MODE_ACTIVEBACKUP ) && bond -> xs )
963
+ bond_ipsec_del_sa (bond -> xs );
964
+ #endif /* CONFIG_XFRM_OFFLOAD */
965
+
882
966
new_active -> last_link_up = jiffies ;
883
967
884
968
if (new_active -> link == BOND_LINK_BACK ) {
@@ -941,6 +1025,13 @@ void bond_change_active_slave(struct bonding *bond, struct slave *new_active)
941
1025
bond_should_notify_peers (bond );
942
1026
}
943
1027
1028
+ #ifdef CONFIG_XFRM_OFFLOAD
1029
+ if (old_active && bond -> xs ) {
1030
+ xfrm_dev_state_flush (dev_net (bond -> dev ), bond -> dev , true);
1031
+ bond_ipsec_add_sa (bond -> xs );
1032
+ }
1033
+ #endif /* CONFIG_XFRM_OFFLOAD */
1034
+
944
1035
call_netdevice_notifiers (NETDEV_BONDING_FAILOVER , bond -> dev );
945
1036
if (should_notify_peers ) {
946
1037
bond -> send_peer_notif -- ;
@@ -1127,15 +1218,24 @@ static netdev_features_t bond_fix_features(struct net_device *dev,
1127
1218
#define BOND_ENC_FEATURES (NETIF_F_HW_CSUM | NETIF_F_SG | \
1128
1219
NETIF_F_RXCSUM | NETIF_F_ALL_TSO)
1129
1220
1221
+ #ifdef CONFIG_XFRM_OFFLOAD
1222
+ #define BOND_XFRM_FEATURES (NETIF_F_HW_ESP | NETIF_F_HW_ESP_TX_CSUM | \
1223
+ NETIF_F_GSO_ESP)
1224
+ #endif /* CONFIG_XFRM_OFFLOAD */
1225
+
1130
1226
#define BOND_MPLS_FEATURES (NETIF_F_HW_CSUM | NETIF_F_SG | \
1131
1227
NETIF_F_ALL_TSO)
1132
1228
1229
+
1133
1230
static void bond_compute_features (struct bonding * bond )
1134
1231
{
1135
1232
unsigned int dst_release_flag = IFF_XMIT_DST_RELEASE |
1136
1233
IFF_XMIT_DST_RELEASE_PERM ;
1137
1234
netdev_features_t vlan_features = BOND_VLAN_FEATURES ;
1138
1235
netdev_features_t enc_features = BOND_ENC_FEATURES ;
1236
+ #ifdef CONFIG_XFRM_OFFLOAD
1237
+ netdev_features_t xfrm_features = BOND_XFRM_FEATURES ;
1238
+ #endif /* CONFIG_XFRM_OFFLOAD */
1139
1239
netdev_features_t mpls_features = BOND_MPLS_FEATURES ;
1140
1240
struct net_device * bond_dev = bond -> dev ;
1141
1241
struct list_head * iter ;
@@ -1157,6 +1257,12 @@ static void bond_compute_features(struct bonding *bond)
1157
1257
slave -> dev -> hw_enc_features ,
1158
1258
BOND_ENC_FEATURES );
1159
1259
1260
+ #ifdef CONFIG_XFRM_OFFLOAD
1261
+ xfrm_features = netdev_increment_features (xfrm_features ,
1262
+ slave -> dev -> hw_enc_features ,
1263
+ BOND_XFRM_FEATURES );
1264
+ #endif /* CONFIG_XFRM_OFFLOAD */
1265
+
1160
1266
mpls_features = netdev_increment_features (mpls_features ,
1161
1267
slave -> dev -> mpls_features ,
1162
1268
BOND_MPLS_FEATURES );
@@ -1176,6 +1282,9 @@ static void bond_compute_features(struct bonding *bond)
1176
1282
NETIF_F_HW_VLAN_CTAG_TX |
1177
1283
NETIF_F_HW_VLAN_STAG_TX |
1178
1284
NETIF_F_GSO_UDP_L4 ;
1285
+ #ifdef CONFIG_XFRM_OFFLOAD
1286
+ bond_dev -> hw_enc_features |= xfrm_features ;
1287
+ #endif /* CONFIG_XFRM_OFFLOAD */
1179
1288
bond_dev -> mpls_features = mpls_features ;
1180
1289
bond_dev -> gso_max_segs = gso_max_segs ;
1181
1290
netif_set_gso_max_size (bond_dev , gso_max_size );
@@ -1464,6 +1573,9 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,
1464
1573
slave_dbg (bond_dev , slave_dev , "is !NETIF_F_VLAN_CHALLENGED\n" );
1465
1574
}
1466
1575
1576
+ if (slave_dev -> features & NETIF_F_HW_ESP )
1577
+ slave_dbg (bond_dev , slave_dev , "is esp-hw-offload capable\n" );
1578
+
1467
1579
/* Old ifenslave binaries are no longer supported. These can
1468
1580
* be identified with moderate accuracy by the state of the slave:
1469
1581
* the current ifenslave will set the interface down prior to
@@ -4540,6 +4652,13 @@ void bond_setup(struct net_device *bond_dev)
4540
4652
bond_dev -> priv_flags |= IFF_BONDING | IFF_UNICAST_FLT | IFF_NO_QUEUE ;
4541
4653
bond_dev -> priv_flags &= ~(IFF_XMIT_DST_RELEASE | IFF_TX_SKB_SHARING );
4542
4654
4655
+ #ifdef CONFIG_XFRM_OFFLOAD
4656
+ /* set up xfrm device ops (only supported in active-backup right now) */
4657
+ if ((BOND_MODE (bond ) == BOND_MODE_ACTIVEBACKUP ))
4658
+ bond_dev -> xfrmdev_ops = & bond_xfrmdev_ops ;
4659
+ bond -> xs = NULL ;
4660
+ #endif /* CONFIG_XFRM_OFFLOAD */
4661
+
4543
4662
/* don't acquire bond device's netif_tx_lock when transmitting */
4544
4663
bond_dev -> features |= NETIF_F_LLTX ;
4545
4664
@@ -4558,6 +4677,10 @@ void bond_setup(struct net_device *bond_dev)
4558
4677
NETIF_F_HW_VLAN_CTAG_FILTER ;
4559
4678
4560
4679
bond_dev -> hw_features |= NETIF_F_GSO_ENCAP_ALL | NETIF_F_GSO_UDP_L4 ;
4680
+ #ifdef CONFIG_XFRM_OFFLOAD
4681
+ if ((BOND_MODE (bond ) == BOND_MODE_ACTIVEBACKUP ))
4682
+ bond_dev -> hw_features |= BOND_XFRM_FEATURES ;
4683
+ #endif /* CONFIG_XFRM_OFFLOAD */
4561
4684
bond_dev -> features |= bond_dev -> hw_features ;
4562
4685
bond_dev -> features |= NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_HW_VLAN_STAG_TX ;
4563
4686
}
0 commit comments