@@ -162,6 +162,19 @@ static struct macsec_rx_sa *macsec_rxsa_get(struct macsec_rx_sa __rcu *ptr)
162
162
return sa ;
163
163
}
164
164
165
+ static struct macsec_rx_sa * macsec_active_rxsa_get (struct macsec_rx_sc * rx_sc )
166
+ {
167
+ struct macsec_rx_sa * sa = NULL ;
168
+ int an ;
169
+
170
+ for (an = 0 ; an < MACSEC_NUM_AN ; an ++ ) {
171
+ sa = macsec_rxsa_get (rx_sc -> sa [an ]);
172
+ if (sa )
173
+ break ;
174
+ }
175
+ return sa ;
176
+ }
177
+
165
178
static void free_rx_sc_rcu (struct rcu_head * head )
166
179
{
167
180
struct macsec_rx_sc * rx_sc = container_of (head , struct macsec_rx_sc , rcu_head );
@@ -500,18 +513,28 @@ static void macsec_encrypt_finish(struct sk_buff *skb, struct net_device *dev)
500
513
skb -> protocol = eth_hdr (skb )-> h_proto ;
501
514
}
502
515
516
+ static unsigned int macsec_msdu_len (struct sk_buff * skb )
517
+ {
518
+ struct macsec_dev * macsec = macsec_priv (skb -> dev );
519
+ struct macsec_secy * secy = & macsec -> secy ;
520
+ bool sci_present = macsec_skb_cb (skb )-> has_sci ;
521
+
522
+ return skb -> len - macsec_hdr_len (sci_present ) - secy -> icv_len ;
523
+ }
524
+
503
525
static void macsec_count_tx (struct sk_buff * skb , struct macsec_tx_sc * tx_sc ,
504
526
struct macsec_tx_sa * tx_sa )
505
527
{
528
+ unsigned int msdu_len = macsec_msdu_len (skb );
506
529
struct pcpu_tx_sc_stats * txsc_stats = this_cpu_ptr (tx_sc -> stats );
507
530
508
531
u64_stats_update_begin (& txsc_stats -> syncp );
509
532
if (tx_sc -> encrypt ) {
510
- txsc_stats -> stats .OutOctetsEncrypted += skb -> len ;
533
+ txsc_stats -> stats .OutOctetsEncrypted += msdu_len ;
511
534
txsc_stats -> stats .OutPktsEncrypted ++ ;
512
535
this_cpu_inc (tx_sa -> stats -> OutPktsEncrypted );
513
536
} else {
514
- txsc_stats -> stats .OutOctetsProtected += skb -> len ;
537
+ txsc_stats -> stats .OutOctetsProtected += msdu_len ;
515
538
txsc_stats -> stats .OutPktsProtected ++ ;
516
539
this_cpu_inc (tx_sa -> stats -> OutPktsProtected );
517
540
}
@@ -541,9 +564,10 @@ static void macsec_encrypt_done(struct crypto_async_request *base, int err)
541
564
aead_request_free (macsec_skb_cb (skb )-> req );
542
565
543
566
rcu_read_lock_bh ();
544
- macsec_encrypt_finish (skb , dev );
545
567
macsec_count_tx (skb , & macsec -> secy .tx_sc , macsec_skb_cb (skb )-> tx_sa );
546
- len = skb -> len ;
568
+ /* packet is encrypted/protected so tx_bytes must be calculated */
569
+ len = macsec_msdu_len (skb ) + 2 * ETH_ALEN ;
570
+ macsec_encrypt_finish (skb , dev );
547
571
ret = dev_queue_xmit (skb );
548
572
count_tx (dev , ret , len );
549
573
rcu_read_unlock_bh ();
@@ -702,6 +726,7 @@ static struct sk_buff *macsec_encrypt(struct sk_buff *skb,
702
726
703
727
macsec_skb_cb (skb )-> req = req ;
704
728
macsec_skb_cb (skb )-> tx_sa = tx_sa ;
729
+ macsec_skb_cb (skb )-> has_sci = sci_present ;
705
730
aead_request_set_callback (req , 0 , macsec_encrypt_done , skb );
706
731
707
732
dev_hold (skb -> dev );
@@ -743,15 +768,17 @@ static bool macsec_post_decrypt(struct sk_buff *skb, struct macsec_secy *secy, u
743
768
u64_stats_update_begin (& rxsc_stats -> syncp );
744
769
rxsc_stats -> stats .InPktsLate ++ ;
745
770
u64_stats_update_end (& rxsc_stats -> syncp );
771
+ secy -> netdev -> stats .rx_dropped ++ ;
746
772
return false;
747
773
}
748
774
749
775
if (secy -> validate_frames != MACSEC_VALIDATE_DISABLED ) {
776
+ unsigned int msdu_len = macsec_msdu_len (skb );
750
777
u64_stats_update_begin (& rxsc_stats -> syncp );
751
778
if (hdr -> tci_an & MACSEC_TCI_E )
752
- rxsc_stats -> stats .InOctetsDecrypted += skb -> len ;
779
+ rxsc_stats -> stats .InOctetsDecrypted += msdu_len ;
753
780
else
754
- rxsc_stats -> stats .InOctetsValidated += skb -> len ;
781
+ rxsc_stats -> stats .InOctetsValidated += msdu_len ;
755
782
u64_stats_update_end (& rxsc_stats -> syncp );
756
783
}
757
784
@@ -764,6 +791,8 @@ static bool macsec_post_decrypt(struct sk_buff *skb, struct macsec_secy *secy, u
764
791
u64_stats_update_begin (& rxsc_stats -> syncp );
765
792
rxsc_stats -> stats .InPktsNotValid ++ ;
766
793
u64_stats_update_end (& rxsc_stats -> syncp );
794
+ this_cpu_inc (rx_sa -> stats -> InPktsNotValid );
795
+ secy -> netdev -> stats .rx_errors ++ ;
767
796
return false;
768
797
}
769
798
@@ -856,9 +885,9 @@ static void macsec_decrypt_done(struct crypto_async_request *base, int err)
856
885
857
886
macsec_finalize_skb (skb , macsec -> secy .icv_len ,
858
887
macsec_extra_len (macsec_skb_cb (skb )-> has_sci ));
888
+ len = skb -> len ;
859
889
macsec_reset_skb (skb , macsec -> secy .netdev );
860
890
861
- len = skb -> len ;
862
891
if (gro_cells_receive (& macsec -> gro_cells , skb ) == NET_RX_SUCCESS )
863
892
count_rx (dev , len );
864
893
@@ -1049,6 +1078,7 @@ static enum rx_handler_result handle_not_macsec(struct sk_buff *skb)
1049
1078
u64_stats_update_begin (& secy_stats -> syncp );
1050
1079
secy_stats -> stats .InPktsNoTag ++ ;
1051
1080
u64_stats_update_end (& secy_stats -> syncp );
1081
+ macsec -> secy .netdev -> stats .rx_dropped ++ ;
1052
1082
continue ;
1053
1083
}
1054
1084
@@ -1158,6 +1188,7 @@ static rx_handler_result_t macsec_handle_frame(struct sk_buff **pskb)
1158
1188
u64_stats_update_begin (& secy_stats -> syncp );
1159
1189
secy_stats -> stats .InPktsBadTag ++ ;
1160
1190
u64_stats_update_end (& secy_stats -> syncp );
1191
+ secy -> netdev -> stats .rx_errors ++ ;
1161
1192
goto drop_nosa ;
1162
1193
}
1163
1194
@@ -1168,11 +1199,15 @@ static rx_handler_result_t macsec_handle_frame(struct sk_buff **pskb)
1168
1199
/* If validateFrames is Strict or the C bit in the
1169
1200
* SecTAG is set, discard
1170
1201
*/
1202
+ struct macsec_rx_sa * active_rx_sa = macsec_active_rxsa_get (rx_sc );
1171
1203
if (hdr -> tci_an & MACSEC_TCI_C ||
1172
1204
secy -> validate_frames == MACSEC_VALIDATE_STRICT ) {
1173
1205
u64_stats_update_begin (& rxsc_stats -> syncp );
1174
1206
rxsc_stats -> stats .InPktsNotUsingSA ++ ;
1175
1207
u64_stats_update_end (& rxsc_stats -> syncp );
1208
+ secy -> netdev -> stats .rx_errors ++ ;
1209
+ if (active_rx_sa )
1210
+ this_cpu_inc (active_rx_sa -> stats -> InPktsNotUsingSA );
1176
1211
goto drop_nosa ;
1177
1212
}
1178
1213
@@ -1182,6 +1217,8 @@ static rx_handler_result_t macsec_handle_frame(struct sk_buff **pskb)
1182
1217
u64_stats_update_begin (& rxsc_stats -> syncp );
1183
1218
rxsc_stats -> stats .InPktsUnusedSA ++ ;
1184
1219
u64_stats_update_end (& rxsc_stats -> syncp );
1220
+ if (active_rx_sa )
1221
+ this_cpu_inc (active_rx_sa -> stats -> InPktsUnusedSA );
1185
1222
goto deliver ;
1186
1223
}
1187
1224
@@ -1202,6 +1239,7 @@ static rx_handler_result_t macsec_handle_frame(struct sk_buff **pskb)
1202
1239
u64_stats_update_begin (& rxsc_stats -> syncp );
1203
1240
rxsc_stats -> stats .InPktsLate ++ ;
1204
1241
u64_stats_update_end (& rxsc_stats -> syncp );
1242
+ macsec -> secy .netdev -> stats .rx_dropped ++ ;
1205
1243
goto drop ;
1206
1244
}
1207
1245
}
@@ -1230,14 +1268,14 @@ static rx_handler_result_t macsec_handle_frame(struct sk_buff **pskb)
1230
1268
deliver :
1231
1269
macsec_finalize_skb (skb , secy -> icv_len ,
1232
1270
macsec_extra_len (macsec_skb_cb (skb )-> has_sci ));
1271
+ len = skb -> len ;
1233
1272
macsec_reset_skb (skb , secy -> netdev );
1234
1273
1235
1274
if (rx_sa )
1236
1275
macsec_rxsa_put (rx_sa );
1237
1276
macsec_rxsc_put (rx_sc );
1238
1277
1239
1278
skb_orphan (skb );
1240
- len = skb -> len ;
1241
1279
ret = gro_cells_receive (& macsec -> gro_cells , skb );
1242
1280
if (ret == NET_RX_SUCCESS )
1243
1281
count_rx (dev , len );
@@ -1279,6 +1317,7 @@ static rx_handler_result_t macsec_handle_frame(struct sk_buff **pskb)
1279
1317
u64_stats_update_begin (& secy_stats -> syncp );
1280
1318
secy_stats -> stats .InPktsNoSCI ++ ;
1281
1319
u64_stats_update_end (& secy_stats -> syncp );
1320
+ macsec -> secy .netdev -> stats .rx_errors ++ ;
1282
1321
continue ;
1283
1322
}
1284
1323
@@ -3404,6 +3443,7 @@ static netdev_tx_t macsec_start_xmit(struct sk_buff *skb,
3404
3443
return NETDEV_TX_OK ;
3405
3444
}
3406
3445
3446
+ len = skb -> len ;
3407
3447
skb = macsec_encrypt (skb , dev );
3408
3448
if (IS_ERR (skb )) {
3409
3449
if (PTR_ERR (skb ) != - EINPROGRESS )
@@ -3414,7 +3454,6 @@ static netdev_tx_t macsec_start_xmit(struct sk_buff *skb,
3414
3454
macsec_count_tx (skb , & macsec -> secy .tx_sc , macsec_skb_cb (skb )-> tx_sa );
3415
3455
3416
3456
macsec_encrypt_finish (skb , dev );
3417
- len = skb -> len ;
3418
3457
ret = dev_queue_xmit (skb );
3419
3458
count_tx (dev , ret , len );
3420
3459
return ret ;
@@ -3662,6 +3701,7 @@ static void macsec_get_stats64(struct net_device *dev,
3662
3701
3663
3702
s -> rx_dropped = dev -> stats .rx_dropped ;
3664
3703
s -> tx_dropped = dev -> stats .tx_dropped ;
3704
+ s -> rx_errors = dev -> stats .rx_errors ;
3665
3705
}
3666
3706
3667
3707
static int macsec_get_iflink (const struct net_device * dev )
0 commit comments