hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/drivers/net/macsec.c
....@@ -1,12 +1,8 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * drivers/net/macsec.c - MACsec device
34 *
45 * Copyright (c) 2015 Sabrina Dubroca <sd@queasysnail.net>
5
- *
6
- * This program is free software; you can redistribute it and/or modify
7
- * it under the terms of the GNU General Public License as published by
8
- * the Free Software Foundation; either version 2 of the License, or
9
- * (at your option) any later version.
106 */
117
128 #include <linux/types.h>
....@@ -15,16 +11,18 @@
1511 #include <linux/module.h>
1612 #include <crypto/aead.h>
1713 #include <linux/etherdevice.h>
14
+#include <linux/netdevice.h>
1815 #include <linux/rtnetlink.h>
1916 #include <linux/refcount.h>
2017 #include <net/genetlink.h>
2118 #include <net/sock.h>
2219 #include <net/gro_cells.h>
20
+#include <net/macsec.h>
21
+#include <linux/phy.h>
22
+#include <linux/byteorder/generic.h>
2323 #include <linux/if_arp.h>
2424
2525 #include <uapi/linux/if_macsec.h>
26
-
27
-typedef u64 __bitwise sci_t;
2826
2927 #define MACSEC_SCI_LEN 8
3028
....@@ -63,16 +61,24 @@
6361 #define GCM_AES_IV_LEN 12
6462 #define DEFAULT_ICV_LEN 16
6563
66
-#define MACSEC_NUM_AN 4 /* 2 bits for the association number */
67
-
68
-#define for_each_rxsc(secy, sc) \
64
+#define for_each_rxsc(secy, sc) \
6965 for (sc = rcu_dereference_bh(secy->rx_sc); \
70
- sc; \
66
+ sc; \
7167 sc = rcu_dereference_bh(sc->next))
7268 #define for_each_rxsc_rtnl(secy, sc) \
7369 for (sc = rtnl_dereference(secy->rx_sc); \
7470 sc; \
7571 sc = rtnl_dereference(sc->next))
72
+
73
+#define pn_same_half(pn1, pn2) (!(((pn1) >> 31) ^ ((pn2) >> 31)))
74
+
75
+struct gcm_iv_xpn {
76
+ union {
77
+ u8 short_secure_channel_id[4];
78
+ ssci_t ssci;
79
+ };
80
+ __be64 pn;
81
+} __packed;
7682
7783 struct gcm_iv {
7884 union {
....@@ -82,177 +88,7 @@
8288 __be32 pn;
8389 };
8490
85
-/**
86
- * struct macsec_key - SA key
87
- * @id: user-provided key identifier
88
- * @tfm: crypto struct, key storage
89
- */
90
-struct macsec_key {
91
- u8 id[MACSEC_KEYID_LEN];
92
- struct crypto_aead *tfm;
93
-};
94
-
95
-struct macsec_rx_sc_stats {
96
- __u64 InOctetsValidated;
97
- __u64 InOctetsDecrypted;
98
- __u64 InPktsUnchecked;
99
- __u64 InPktsDelayed;
100
- __u64 InPktsOK;
101
- __u64 InPktsInvalid;
102
- __u64 InPktsLate;
103
- __u64 InPktsNotValid;
104
- __u64 InPktsNotUsingSA;
105
- __u64 InPktsUnusedSA;
106
-};
107
-
108
-struct macsec_rx_sa_stats {
109
- __u32 InPktsOK;
110
- __u32 InPktsInvalid;
111
- __u32 InPktsNotValid;
112
- __u32 InPktsNotUsingSA;
113
- __u32 InPktsUnusedSA;
114
-};
115
-
116
-struct macsec_tx_sa_stats {
117
- __u32 OutPktsProtected;
118
- __u32 OutPktsEncrypted;
119
-};
120
-
121
-struct macsec_tx_sc_stats {
122
- __u64 OutPktsProtected;
123
- __u64 OutPktsEncrypted;
124
- __u64 OutOctetsProtected;
125
- __u64 OutOctetsEncrypted;
126
-};
127
-
128
-struct macsec_dev_stats {
129
- __u64 OutPktsUntagged;
130
- __u64 InPktsUntagged;
131
- __u64 OutPktsTooLong;
132
- __u64 InPktsNoTag;
133
- __u64 InPktsBadTag;
134
- __u64 InPktsUnknownSCI;
135
- __u64 InPktsNoSCI;
136
- __u64 InPktsOverrun;
137
-};
138
-
139
-/**
140
- * struct macsec_rx_sa - receive secure association
141
- * @active:
142
- * @next_pn: packet number expected for the next packet
143
- * @lock: protects next_pn manipulations
144
- * @key: key structure
145
- * @stats: per-SA stats
146
- */
147
-struct macsec_rx_sa {
148
- struct macsec_key key;
149
- spinlock_t lock;
150
- u32 next_pn;
151
- refcount_t refcnt;
152
- bool active;
153
- struct macsec_rx_sa_stats __percpu *stats;
154
- struct macsec_rx_sc *sc;
155
- struct rcu_head rcu;
156
-};
157
-
158
-struct pcpu_rx_sc_stats {
159
- struct macsec_rx_sc_stats stats;
160
- struct u64_stats_sync syncp;
161
-};
162
-
163
-/**
164
- * struct macsec_rx_sc - receive secure channel
165
- * @sci: secure channel identifier for this SC
166
- * @active: channel is active
167
- * @sa: array of secure associations
168
- * @stats: per-SC stats
169
- */
170
-struct macsec_rx_sc {
171
- struct macsec_rx_sc __rcu *next;
172
- sci_t sci;
173
- bool active;
174
- struct macsec_rx_sa __rcu *sa[MACSEC_NUM_AN];
175
- struct pcpu_rx_sc_stats __percpu *stats;
176
- refcount_t refcnt;
177
- struct rcu_head rcu_head;
178
-};
179
-
180
-/**
181
- * struct macsec_tx_sa - transmit secure association
182
- * @active:
183
- * @next_pn: packet number to use for the next packet
184
- * @lock: protects next_pn manipulations
185
- * @key: key structure
186
- * @stats: per-SA stats
187
- */
188
-struct macsec_tx_sa {
189
- struct macsec_key key;
190
- spinlock_t lock;
191
- u32 next_pn;
192
- refcount_t refcnt;
193
- bool active;
194
- struct macsec_tx_sa_stats __percpu *stats;
195
- struct rcu_head rcu;
196
-};
197
-
198
-struct pcpu_tx_sc_stats {
199
- struct macsec_tx_sc_stats stats;
200
- struct u64_stats_sync syncp;
201
-};
202
-
203
-/**
204
- * struct macsec_tx_sc - transmit secure channel
205
- * @active:
206
- * @encoding_sa: association number of the SA currently in use
207
- * @encrypt: encrypt packets on transmit, or authenticate only
208
- * @send_sci: always include the SCI in the SecTAG
209
- * @end_station:
210
- * @scb: single copy broadcast flag
211
- * @sa: array of secure associations
212
- * @stats: stats for this TXSC
213
- */
214
-struct macsec_tx_sc {
215
- bool active;
216
- u8 encoding_sa;
217
- bool encrypt;
218
- bool send_sci;
219
- bool end_station;
220
- bool scb;
221
- struct macsec_tx_sa __rcu *sa[MACSEC_NUM_AN];
222
- struct pcpu_tx_sc_stats __percpu *stats;
223
-};
224
-
22591 #define MACSEC_VALIDATE_DEFAULT MACSEC_VALIDATE_STRICT
226
-
227
-/**
228
- * struct macsec_secy - MACsec Security Entity
229
- * @netdev: netdevice for this SecY
230
- * @n_rx_sc: number of receive secure channels configured on this SecY
231
- * @sci: secure channel identifier used for tx
232
- * @key_len: length of keys used by the cipher suite
233
- * @icv_len: length of ICV used by the cipher suite
234
- * @validate_frames: validation mode
235
- * @operational: MAC_Operational flag
236
- * @protect_frames: enable protection for this SecY
237
- * @replay_protect: enable packet number checks on receive
238
- * @replay_window: size of the replay window
239
- * @tx_sc: transmit secure channel
240
- * @rx_sc: linked list of receive secure channels
241
- */
242
-struct macsec_secy {
243
- struct net_device *netdev;
244
- unsigned int n_rx_sc;
245
- sci_t sci;
246
- u16 key_len;
247
- u16 icv_len;
248
- enum macsec_validation_type validate_frames;
249
- bool operational;
250
- bool protect_frames;
251
- bool replay_protect;
252
- u32 replay_window;
253
- struct macsec_tx_sc tx_sc;
254
- struct macsec_rx_sc __rcu *rx_sc;
255
-};
25692
25793 struct pcpu_secy_stats {
25894 struct macsec_dev_stats stats;
....@@ -265,6 +101,7 @@
265101 * @real_dev: pointer to underlying netdevice
266102 * @stats: MACsec device stats
267103 * @secys: linked list of SecY's on the underlying device
104
+ * @offload: status of offloading on the MACsec device
268105 */
269106 struct macsec_dev {
270107 struct macsec_secy secy;
....@@ -272,7 +109,7 @@
272109 struct pcpu_secy_stats __percpu *stats;
273110 struct list_head secys;
274111 struct gro_cells gro_cells;
275
- unsigned int nest_level;
112
+ enum macsec_offload offload;
276113 };
277114
278115 /**
....@@ -393,14 +230,17 @@
393230 #define MACSEC_PORT_ES (htons(0x0001))
394231 #define MACSEC_PORT_SCB (0x0000)
395232 #define MACSEC_UNDEF_SCI ((__force sci_t)0xffffffffffffffffULL)
233
+#define MACSEC_UNDEF_SSCI ((__force ssci_t)0xffffffff)
396234
397235 #define MACSEC_GCM_AES_128_SAK_LEN 16
398236 #define MACSEC_GCM_AES_256_SAK_LEN 32
399237
400238 #define DEFAULT_SAK_LEN MACSEC_GCM_AES_128_SAK_LEN
239
+#define DEFAULT_XPN false
401240 #define DEFAULT_SEND_SCI true
402241 #define DEFAULT_ENCRYPT false
403242 #define DEFAULT_ENCODING_SA 0
243
+#define MACSEC_XPN_MAX_REPLAY_WINDOW (((1 << 30) - 1))
404244
405245 static bool send_sci(const struct macsec_secy *secy)
406246 {
....@@ -486,8 +326,67 @@
486326 h->short_length = data_len;
487327 }
488328
489
-/* validate MACsec packet according to IEEE 802.1AE-2006 9.12 */
490
-static bool macsec_validate_skb(struct sk_buff *skb, u16 icv_len)
329
+/* Checks if a MACsec interface is being offloaded to an hardware engine */
330
+static bool macsec_is_offloaded(struct macsec_dev *macsec)
331
+{
332
+ if (macsec->offload == MACSEC_OFFLOAD_MAC ||
333
+ macsec->offload == MACSEC_OFFLOAD_PHY)
334
+ return true;
335
+
336
+ return false;
337
+}
338
+
339
+/* Checks if underlying layers implement MACsec offloading functions. */
340
+static bool macsec_check_offload(enum macsec_offload offload,
341
+ struct macsec_dev *macsec)
342
+{
343
+ if (!macsec || !macsec->real_dev)
344
+ return false;
345
+
346
+ if (offload == MACSEC_OFFLOAD_PHY)
347
+ return macsec->real_dev->phydev &&
348
+ macsec->real_dev->phydev->macsec_ops;
349
+ else if (offload == MACSEC_OFFLOAD_MAC)
350
+ return macsec->real_dev->features & NETIF_F_HW_MACSEC &&
351
+ macsec->real_dev->macsec_ops;
352
+
353
+ return false;
354
+}
355
+
356
+static const struct macsec_ops *__macsec_get_ops(enum macsec_offload offload,
357
+ struct macsec_dev *macsec,
358
+ struct macsec_context *ctx)
359
+{
360
+ if (ctx) {
361
+ memset(ctx, 0, sizeof(*ctx));
362
+ ctx->offload = offload;
363
+
364
+ if (offload == MACSEC_OFFLOAD_PHY)
365
+ ctx->phydev = macsec->real_dev->phydev;
366
+ else if (offload == MACSEC_OFFLOAD_MAC)
367
+ ctx->netdev = macsec->real_dev;
368
+ }
369
+
370
+ if (offload == MACSEC_OFFLOAD_PHY)
371
+ return macsec->real_dev->phydev->macsec_ops;
372
+ else
373
+ return macsec->real_dev->macsec_ops;
374
+}
375
+
376
+/* Returns a pointer to the MACsec ops struct if any and updates the MACsec
377
+ * context device reference if provided.
378
+ */
379
+static const struct macsec_ops *macsec_get_ops(struct macsec_dev *macsec,
380
+ struct macsec_context *ctx)
381
+{
382
+ if (!macsec_check_offload(macsec->offload, macsec))
383
+ return NULL;
384
+
385
+ return __macsec_get_ops(macsec->offload, macsec, ctx);
386
+}
387
+
388
+/* validate MACsec packet according to IEEE 802.1AE-2018 9.12 */
389
+static bool macsec_validate_skb(struct sk_buff *skb, u16 icv_len, bool xpn)
491390 {
492391 struct macsec_eth_header *h = (struct macsec_eth_header *)skb->data;
493392 int len = skb->len - 2 * ETH_ALEN;
....@@ -512,8 +411,8 @@
512411 if (h->unused)
513412 return false;
514413
515
- /* rx.pn != 0 (figure 10-5) */
516
- if (!h->packet_number)
414
+ /* rx.pn != 0 if not XPN (figure 10-5 with 802.11AEbw-2013 amendment) */
415
+ if (!h->packet_number && !xpn)
517416 return false;
518417
519418 /* length check, f) g) h) i) */
....@@ -524,6 +423,15 @@
524423
525424 #define MACSEC_NEEDED_HEADROOM (macsec_extra_len(true))
526425 #define MACSEC_NEEDED_TAILROOM MACSEC_STD_ICV_LEN
426
+
427
+static void macsec_fill_iv_xpn(unsigned char *iv, ssci_t ssci, u64 pn,
428
+ salt_t salt)
429
+{
430
+ struct gcm_iv_xpn *gcm_iv = (struct gcm_iv_xpn *)iv;
431
+
432
+ gcm_iv->ssci = ssci ^ salt.ssci;
433
+ gcm_iv->pn = cpu_to_be64(pn) ^ salt.pn;
434
+}
527435
528436 static void macsec_fill_iv(unsigned char *iv, sci_t sci, u32 pn)
529437 {
....@@ -538,20 +446,43 @@
538446 return (struct macsec_eth_header *)skb_mac_header(skb);
539447 }
540448
541
-static u32 tx_sa_update_pn(struct macsec_tx_sa *tx_sa, struct macsec_secy *secy)
449
+static sci_t dev_to_sci(struct net_device *dev, __be16 port)
542450 {
543
- u32 pn;
451
+ return make_sci(dev->dev_addr, port);
452
+}
453
+
454
+static void __macsec_pn_wrapped(struct macsec_secy *secy,
455
+ struct macsec_tx_sa *tx_sa)
456
+{
457
+ pr_debug("PN wrapped, transitioning to !oper\n");
458
+ tx_sa->active = false;
459
+ if (secy->protect_frames)
460
+ secy->operational = false;
461
+}
462
+
463
+void macsec_pn_wrapped(struct macsec_secy *secy, struct macsec_tx_sa *tx_sa)
464
+{
465
+ spin_lock_bh(&tx_sa->lock);
466
+ __macsec_pn_wrapped(secy, tx_sa);
467
+ spin_unlock_bh(&tx_sa->lock);
468
+}
469
+EXPORT_SYMBOL_GPL(macsec_pn_wrapped);
470
+
471
+static pn_t tx_sa_update_pn(struct macsec_tx_sa *tx_sa,
472
+ struct macsec_secy *secy)
473
+{
474
+ pn_t pn;
544475
545476 spin_lock_bh(&tx_sa->lock);
546
- pn = tx_sa->next_pn;
547477
548
- tx_sa->next_pn++;
549
- if (tx_sa->next_pn == 0) {
550
- pr_debug("PN wrapped, transitioning to !oper\n");
551
- tx_sa->active = false;
552
- if (secy->protect_frames)
553
- secy->operational = false;
554
- }
478
+ pn = tx_sa->next_pn_halves;
479
+ if (secy->xpn)
480
+ tx_sa->next_pn++;
481
+ else
482
+ tx_sa->next_pn_halves.lower++;
483
+
484
+ if (tx_sa->next_pn == 0)
485
+ __macsec_pn_wrapped(secy, tx_sa);
555486 spin_unlock_bh(&tx_sa->lock);
556487
557488 return pn;
....@@ -664,7 +595,7 @@
664595 struct macsec_tx_sa *tx_sa;
665596 struct macsec_dev *macsec = macsec_priv(dev);
666597 bool sci_present;
667
- u32 pn;
598
+ pn_t pn;
668599
669600 secy = &macsec->secy;
670601 tx_sc = &secy->tx_sc;
....@@ -706,12 +637,12 @@
706637 memmove(hh, eth, 2 * ETH_ALEN);
707638
708639 pn = tx_sa_update_pn(tx_sa, secy);
709
- if (pn == 0) {
640
+ if (pn.full64 == 0) {
710641 macsec_txsa_put(tx_sa);
711642 kfree_skb(skb);
712643 return ERR_PTR(-ENOLINK);
713644 }
714
- macsec_fill_sectag(hh, secy, pn, sci_present);
645
+ macsec_fill_sectag(hh, secy, pn.lower, sci_present);
715646 macsec_set_shortlen(hh, unprotected_len - 2 * ETH_ALEN);
716647
717648 skb_put(skb, secy->icv_len);
....@@ -742,7 +673,10 @@
742673 return ERR_PTR(-ENOMEM);
743674 }
744675
745
- macsec_fill_iv(iv, secy->sci, pn);
676
+ if (secy->xpn)
677
+ macsec_fill_iv_xpn(iv, tx_sa->ssci, pn.full64, tx_sa->key.salt);
678
+ else
679
+ macsec_fill_iv(iv, secy->sci, pn.lower);
746680
747681 sg_init_table(sg, ret);
748682 ret = skb_to_sgvec(skb, sg, 0, skb->len);
....@@ -794,13 +728,14 @@
794728 u32 lowest_pn = 0;
795729
796730 spin_lock(&rx_sa->lock);
797
- if (rx_sa->next_pn >= secy->replay_window)
798
- lowest_pn = rx_sa->next_pn - secy->replay_window;
731
+ if (rx_sa->next_pn_halves.lower >= secy->replay_window)
732
+ lowest_pn = rx_sa->next_pn_halves.lower - secy->replay_window;
799733
800734 /* Now perform replay protection check again
801735 * (see IEEE 802.1AE-2006 figure 10-5)
802736 */
803
- if (secy->replay_protect && pn < lowest_pn) {
737
+ if (secy->replay_protect && pn < lowest_pn &&
738
+ (!secy->xpn || pn_same_half(pn, lowest_pn))) {
804739 spin_unlock(&rx_sa->lock);
805740 u64_stats_update_begin(&rxsc_stats->syncp);
806741 rxsc_stats->stats.InPktsLate++;
....@@ -849,8 +784,15 @@
849784 }
850785 u64_stats_update_end(&rxsc_stats->syncp);
851786
852
- if (pn >= rx_sa->next_pn)
853
- rx_sa->next_pn = pn + 1;
787
+ // Instead of "pn >=" - to support pn overflow in xpn
788
+ if (pn + 1 > rx_sa->next_pn_halves.lower) {
789
+ rx_sa->next_pn_halves.lower = pn + 1;
790
+ } else if (secy->xpn &&
791
+ !pn_same_half(pn, rx_sa->next_pn_halves.lower)) {
792
+ rx_sa->next_pn_halves.upper++;
793
+ rx_sa->next_pn_halves.lower = pn + 1;
794
+ }
795
+
854796 spin_unlock(&rx_sa->lock);
855797 }
856798
....@@ -937,6 +879,7 @@
937879 unsigned char *iv;
938880 struct aead_request *req;
939881 struct macsec_eth_header *hdr;
882
+ u32 hdr_pn;
940883 u16 icv_len = secy->icv_len;
941884
942885 macsec_skb_cb(skb)->valid = false;
....@@ -956,7 +899,21 @@
956899 }
957900
958901 hdr = (struct macsec_eth_header *)skb->data;
959
- macsec_fill_iv(iv, sci, ntohl(hdr->packet_number));
902
+ hdr_pn = ntohl(hdr->packet_number);
903
+
904
+ if (secy->xpn) {
905
+ pn_t recovered_pn = rx_sa->next_pn_halves;
906
+
907
+ recovered_pn.lower = hdr_pn;
908
+ if (hdr_pn < rx_sa->next_pn_halves.lower &&
909
+ !pn_same_half(hdr_pn, rx_sa->next_pn_halves.lower))
910
+ recovered_pn.upper++;
911
+
912
+ macsec_fill_iv_xpn(iv, rx_sa->ssci, recovered_pn.full64,
913
+ rx_sa->key.salt);
914
+ } else {
915
+ macsec_fill_iv(iv, sci, hdr_pn);
916
+ }
960917
961918 sg_init_table(sg, ret);
962919 ret = skb_to_sgvec(skb, sg, 0, skb->len);
....@@ -1035,22 +992,56 @@
1035992 return NULL;
1036993 }
1037994
1038
-static void handle_not_macsec(struct sk_buff *skb)
995
+static enum rx_handler_result handle_not_macsec(struct sk_buff *skb)
1039996 {
997
+ /* Deliver to the uncontrolled port by default */
998
+ enum rx_handler_result ret = RX_HANDLER_PASS;
999
+ struct ethhdr *hdr = eth_hdr(skb);
10401000 struct macsec_rxh_data *rxd;
10411001 struct macsec_dev *macsec;
10421002
10431003 rcu_read_lock();
10441004 rxd = macsec_data_rcu(skb->dev);
10451005
1046
- /* 10.6 If the management control validateFrames is not
1047
- * Strict, frames without a SecTAG are received, counted, and
1048
- * delivered to the Controlled Port
1049
- */
10501006 list_for_each_entry_rcu(macsec, &rxd->secys, secys) {
10511007 struct sk_buff *nskb;
10521008 struct pcpu_secy_stats *secy_stats = this_cpu_ptr(macsec->stats);
1009
+ struct net_device *ndev = macsec->secy.netdev;
10531010
1011
+ /* If h/w offloading is enabled, HW decodes frames and strips
1012
+ * the SecTAG, so we have to deduce which port to deliver to.
1013
+ */
1014
+ if (macsec_is_offloaded(macsec) && netif_running(ndev)) {
1015
+ if (ether_addr_equal_64bits(hdr->h_dest,
1016
+ ndev->dev_addr)) {
1017
+ /* exact match, divert skb to this port */
1018
+ skb->dev = ndev;
1019
+ skb->pkt_type = PACKET_HOST;
1020
+ ret = RX_HANDLER_ANOTHER;
1021
+ goto out;
1022
+ } else if (is_multicast_ether_addr_64bits(
1023
+ hdr->h_dest)) {
1024
+ /* multicast frame, deliver on this port too */
1025
+ nskb = skb_clone(skb, GFP_ATOMIC);
1026
+ if (!nskb)
1027
+ break;
1028
+
1029
+ nskb->dev = ndev;
1030
+ if (ether_addr_equal_64bits(hdr->h_dest,
1031
+ ndev->broadcast))
1032
+ nskb->pkt_type = PACKET_BROADCAST;
1033
+ else
1034
+ nskb->pkt_type = PACKET_MULTICAST;
1035
+
1036
+ netif_rx(nskb);
1037
+ }
1038
+ continue;
1039
+ }
1040
+
1041
+ /* 10.6 If the management control validateFrames is not
1042
+ * Strict, frames without a SecTAG are received, counted, and
1043
+ * delivered to the Controlled Port
1044
+ */
10541045 if (macsec->secy.validate_frames == MACSEC_VALIDATE_STRICT) {
10551046 u64_stats_update_begin(&secy_stats->syncp);
10561047 secy_stats->stats.InPktsNoTag++;
....@@ -1063,7 +1054,7 @@
10631054 if (!nskb)
10641055 break;
10651056
1066
- nskb->dev = macsec->secy.netdev;
1057
+ nskb->dev = ndev;
10671058
10681059 if (netif_rx(nskb) == NET_RX_SUCCESS) {
10691060 u64_stats_update_begin(&secy_stats->syncp);
....@@ -1072,7 +1063,9 @@
10721063 }
10731064 }
10741065
1066
+out:
10751067 rcu_read_unlock();
1068
+ return ret;
10761069 }
10771070
10781071 static rx_handler_result_t macsec_handle_frame(struct sk_buff **pskb)
....@@ -1087,7 +1080,7 @@
10871080 struct macsec_dev *macsec;
10881081 unsigned int len;
10891082 sci_t sci;
1090
- u32 pn;
1083
+ u32 hdr_pn;
10911084 bool cbit;
10921085 struct pcpu_rx_sc_stats *rxsc_stats;
10931086 struct pcpu_secy_stats *secy_stats;
....@@ -1098,12 +1091,8 @@
10981091 goto drop_direct;
10991092
11001093 hdr = macsec_ethhdr(skb);
1101
- if (hdr->eth.h_proto != htons(ETH_P_MACSEC)) {
1102
- handle_not_macsec(skb);
1103
-
1104
- /* and deliver to the uncontrolled port */
1105
- return RX_HANDLER_PASS;
1106
- }
1094
+ if (hdr->eth.h_proto != htons(ETH_P_MACSEC))
1095
+ return handle_not_macsec(skb);
11071096
11081097 skb = skb_unshare(skb, GFP_ATOMIC);
11091098 *pskb = skb;
....@@ -1144,6 +1133,7 @@
11441133
11451134 list_for_each_entry_rcu(macsec, &rxd->secys, secys) {
11461135 struct macsec_rx_sc *sc = find_rx_sc(&macsec->secy, sci);
1136
+
11471137 sc = sc ? macsec_rxsc_get(sc) : NULL;
11481138
11491139 if (sc) {
....@@ -1161,7 +1151,7 @@
11611151 secy_stats = this_cpu_ptr(macsec->stats);
11621152 rxsc_stats = this_cpu_ptr(rx_sc->stats);
11631153
1164
- if (!macsec_validate_skb(skb, secy->icv_len)) {
1154
+ if (!macsec_validate_skb(skb, secy->icv_len, secy->xpn)) {
11651155 u64_stats_update_begin(&secy_stats->syncp);
11661156 secy_stats->stats.InPktsBadTag++;
11671157 u64_stats_update_end(&secy_stats->syncp);
....@@ -1193,13 +1183,16 @@
11931183 }
11941184
11951185 /* First, PN check to avoid decrypting obviously wrong packets */
1196
- pn = ntohl(hdr->packet_number);
1186
+ hdr_pn = ntohl(hdr->packet_number);
11971187 if (secy->replay_protect) {
11981188 bool late;
11991189
12001190 spin_lock(&rx_sa->lock);
1201
- late = rx_sa->next_pn >= secy->replay_window &&
1202
- pn < (rx_sa->next_pn - secy->replay_window);
1191
+ late = rx_sa->next_pn_halves.lower >= secy->replay_window &&
1192
+ hdr_pn < (rx_sa->next_pn_halves.lower - secy->replay_window);
1193
+
1194
+ if (secy->xpn)
1195
+ late = late && pn_same_half(rx_sa->next_pn_halves.lower, hdr_pn);
12031196 spin_unlock(&rx_sa->lock);
12041197
12051198 if (late) {
....@@ -1228,7 +1221,7 @@
12281221 return RX_HANDLER_CONSUMED;
12291222 }
12301223
1231
- if (!macsec_post_decrypt(skb, secy, pn))
1224
+ if (!macsec_post_decrypt(skb, secy, hdr_pn))
12321225 goto drop;
12331226
12341227 deliver:
....@@ -1348,6 +1341,7 @@
13481341 return PTR_ERR(rx_sa->key.tfm);
13491342 }
13501343
1344
+ rx_sa->ssci = MACSEC_UNDEF_SSCI;
13511345 rx_sa->active = false;
13521346 rx_sa->next_pn = 1;
13531347 refcount_set(&rx_sa->refcnt, 1);
....@@ -1396,7 +1390,8 @@
13961390 return NULL;
13971391 }
13981392
1399
-static struct macsec_rx_sc *create_rx_sc(struct net_device *dev, sci_t sci)
1393
+static struct macsec_rx_sc *create_rx_sc(struct net_device *dev, sci_t sci,
1394
+ bool active)
14001395 {
14011396 struct macsec_rx_sc *rx_sc;
14021397 struct macsec_dev *macsec;
....@@ -1420,7 +1415,7 @@
14201415 }
14211416
14221417 rx_sc->sci = sci;
1423
- rx_sc->active = true;
1418
+ rx_sc->active = active;
14241419 refcount_set(&rx_sc->refcnt, 1);
14251420
14261421 secy = &macsec_priv(dev)->secy;
....@@ -1446,6 +1441,7 @@
14461441 return PTR_ERR(tx_sa->key.tfm);
14471442 }
14481443
1444
+ tx_sa->ssci = MACSEC_UNDEF_SSCI;
14491445 tx_sa->active = false;
14501446 refcount_set(&tx_sa->refcnt, 1);
14511447 spin_lock_init(&tx_sa->lock);
....@@ -1478,6 +1474,11 @@
14781474 return dev;
14791475 }
14801476
1477
+static enum macsec_offload nla_get_offload(const struct nlattr *nla)
1478
+{
1479
+ return (__force enum macsec_offload)nla_get_u8(nla);
1480
+}
1481
+
14811482 static sci_t nla_get_sci(const struct nlattr *nla)
14821483 {
14831484 return (__force sci_t)nla_get_u64(nla);
....@@ -1487,6 +1488,16 @@
14871488 int padattr)
14881489 {
14891490 return nla_put_u64_64bit(skb, attrtype, (__force u64)value, padattr);
1491
+}
1492
+
1493
+static ssci_t nla_get_ssci(const struct nlattr *nla)
1494
+{
1495
+ return (__force ssci_t)nla_get_u32(nla);
1496
+}
1497
+
1498
+static int nla_put_ssci(struct sk_buff *skb, int attrtype, ssci_t value)
1499
+{
1500
+ return nla_put_u32(skb, attrtype, (__force u64)value);
14901501 }
14911502
14921503 static struct macsec_tx_sa *get_txsa_from_nl(struct net *net,
....@@ -1589,11 +1600,11 @@
15891600 return rx_sa;
15901601 }
15911602
1592
-
15931603 static const struct nla_policy macsec_genl_policy[NUM_MACSEC_ATTR] = {
15941604 [MACSEC_ATTR_IFINDEX] = { .type = NLA_U32 },
15951605 [MACSEC_ATTR_RXSC_CONFIG] = { .type = NLA_NESTED },
15961606 [MACSEC_ATTR_SA_CONFIG] = { .type = NLA_NESTED },
1607
+ [MACSEC_ATTR_OFFLOAD] = { .type = NLA_NESTED },
15971608 };
15981609
15991610 static const struct nla_policy macsec_genl_rxsc_policy[NUM_MACSEC_RXSC_ATTR] = {
....@@ -1604,21 +1615,60 @@
16041615 static const struct nla_policy macsec_genl_sa_policy[NUM_MACSEC_SA_ATTR] = {
16051616 [MACSEC_SA_ATTR_AN] = { .type = NLA_U8 },
16061617 [MACSEC_SA_ATTR_ACTIVE] = { .type = NLA_U8 },
1607
- [MACSEC_SA_ATTR_PN] = { .type = NLA_U32 },
1618
+ [MACSEC_SA_ATTR_PN] = NLA_POLICY_MIN_LEN(4),
16081619 [MACSEC_SA_ATTR_KEYID] = { .type = NLA_BINARY,
16091620 .len = MACSEC_KEYID_LEN, },
16101621 [MACSEC_SA_ATTR_KEY] = { .type = NLA_BINARY,
16111622 .len = MACSEC_MAX_KEY_LEN, },
1623
+ [MACSEC_SA_ATTR_SSCI] = { .type = NLA_U32 },
1624
+ [MACSEC_SA_ATTR_SALT] = { .type = NLA_BINARY,
1625
+ .len = MACSEC_SALT_LEN, },
16121626 };
1627
+
1628
+static const struct nla_policy macsec_genl_offload_policy[NUM_MACSEC_OFFLOAD_ATTR] = {
1629
+ [MACSEC_OFFLOAD_ATTR_TYPE] = { .type = NLA_U8 },
1630
+};
1631
+
1632
+/* Offloads an operation to a device driver */
1633
+static int macsec_offload(int (* const func)(struct macsec_context *),
1634
+ struct macsec_context *ctx)
1635
+{
1636
+ int ret;
1637
+
1638
+ if (unlikely(!func))
1639
+ return 0;
1640
+
1641
+ if (ctx->offload == MACSEC_OFFLOAD_PHY)
1642
+ mutex_lock(&ctx->phydev->lock);
1643
+
1644
+ /* Phase I: prepare. The drive should fail here if there are going to be
1645
+ * issues in the commit phase.
1646
+ */
1647
+ ctx->prepare = true;
1648
+ ret = (*func)(ctx);
1649
+ if (ret)
1650
+ goto phy_unlock;
1651
+
1652
+ /* Phase II: commit. This step cannot fail. */
1653
+ ctx->prepare = false;
1654
+ ret = (*func)(ctx);
1655
+ /* This should never happen: commit is not allowed to fail */
1656
+ if (unlikely(ret))
1657
+ WARN(1, "MACsec offloading commit failed (%d)\n", ret);
1658
+
1659
+phy_unlock:
1660
+ if (ctx->offload == MACSEC_OFFLOAD_PHY)
1661
+ mutex_unlock(&ctx->phydev->lock);
1662
+
1663
+ return ret;
1664
+}
16131665
16141666 static int parse_sa_config(struct nlattr **attrs, struct nlattr **tb_sa)
16151667 {
16161668 if (!attrs[MACSEC_ATTR_SA_CONFIG])
16171669 return -EINVAL;
16181670
1619
- if (nla_parse_nested(tb_sa, MACSEC_SA_ATTR_MAX,
1620
- attrs[MACSEC_ATTR_SA_CONFIG],
1621
- macsec_genl_sa_policy, NULL))
1671
+ if (nla_parse_nested_deprecated(tb_sa, MACSEC_SA_ATTR_MAX, attrs[MACSEC_ATTR_SA_CONFIG], macsec_genl_sa_policy, NULL))
16221672 return -EINVAL;
16231673
16241674 return 0;
....@@ -1629,9 +1679,7 @@
16291679 if (!attrs[MACSEC_ATTR_RXSC_CONFIG])
16301680 return -EINVAL;
16311681
1632
- if (nla_parse_nested(tb_rxsc, MACSEC_RXSC_ATTR_MAX,
1633
- attrs[MACSEC_ATTR_RXSC_CONFIG],
1634
- macsec_genl_rxsc_policy, NULL))
1682
+ if (nla_parse_nested_deprecated(tb_rxsc, MACSEC_RXSC_ATTR_MAX, attrs[MACSEC_ATTR_RXSC_CONFIG], macsec_genl_rxsc_policy, NULL))
16351683 return -EINVAL;
16361684
16371685 return 0;
....@@ -1647,7 +1695,8 @@
16471695 if (nla_get_u8(attrs[MACSEC_SA_ATTR_AN]) >= MACSEC_NUM_AN)
16481696 return false;
16491697
1650
- if (attrs[MACSEC_SA_ATTR_PN] && nla_get_u32(attrs[MACSEC_SA_ATTR_PN]) == 0)
1698
+ if (attrs[MACSEC_SA_ATTR_PN] &&
1699
+ nla_get_u64(attrs[MACSEC_SA_ATTR_PN]) == 0)
16511700 return false;
16521701
16531702 if (attrs[MACSEC_SA_ATTR_ACTIVE]) {
....@@ -1669,6 +1718,7 @@
16691718 struct macsec_rx_sc *rx_sc;
16701719 struct macsec_rx_sa *rx_sa;
16711720 unsigned char assoc_num;
1721
+ int pn_len;
16721722 struct nlattr *tb_rxsc[MACSEC_RXSC_ATTR_MAX + 1];
16731723 struct nlattr *tb_sa[MACSEC_SA_ATTR_MAX + 1];
16741724 int err;
....@@ -1701,6 +1751,30 @@
17011751 return -EINVAL;
17021752 }
17031753
1754
+ pn_len = secy->xpn ? MACSEC_XPN_PN_LEN : MACSEC_DEFAULT_PN_LEN;
1755
+ if (tb_sa[MACSEC_SA_ATTR_PN] &&
1756
+ nla_len(tb_sa[MACSEC_SA_ATTR_PN]) != pn_len) {
1757
+ pr_notice("macsec: nl: add_rxsa: bad pn length: %d != %d\n",
1758
+ nla_len(tb_sa[MACSEC_SA_ATTR_PN]), pn_len);
1759
+ rtnl_unlock();
1760
+ return -EINVAL;
1761
+ }
1762
+
1763
+ if (secy->xpn) {
1764
+ if (!tb_sa[MACSEC_SA_ATTR_SSCI] || !tb_sa[MACSEC_SA_ATTR_SALT]) {
1765
+ rtnl_unlock();
1766
+ return -EINVAL;
1767
+ }
1768
+
1769
+ if (nla_len(tb_sa[MACSEC_SA_ATTR_SALT]) != MACSEC_SALT_LEN) {
1770
+ pr_notice("macsec: nl: add_rxsa: bad salt length: %d != %d\n",
1771
+ nla_len(tb_sa[MACSEC_SA_ATTR_SALT]),
1772
+ MACSEC_SALT_LEN);
1773
+ rtnl_unlock();
1774
+ return -EINVAL;
1775
+ }
1776
+ }
1777
+
17041778 rx_sa = rtnl_dereference(rx_sc->sa[assoc_num]);
17051779 if (rx_sa) {
17061780 rtnl_unlock();
....@@ -1723,20 +1797,55 @@
17231797
17241798 if (tb_sa[MACSEC_SA_ATTR_PN]) {
17251799 spin_lock_bh(&rx_sa->lock);
1726
- rx_sa->next_pn = nla_get_u32(tb_sa[MACSEC_SA_ATTR_PN]);
1800
+ rx_sa->next_pn = nla_get_u64(tb_sa[MACSEC_SA_ATTR_PN]);
17271801 spin_unlock_bh(&rx_sa->lock);
17281802 }
17291803
17301804 if (tb_sa[MACSEC_SA_ATTR_ACTIVE])
17311805 rx_sa->active = !!nla_get_u8(tb_sa[MACSEC_SA_ATTR_ACTIVE]);
17321806
1733
- nla_memcpy(rx_sa->key.id, tb_sa[MACSEC_SA_ATTR_KEYID], MACSEC_KEYID_LEN);
17341807 rx_sa->sc = rx_sc;
1808
+
1809
+ /* If h/w offloading is available, propagate to the device */
1810
+ if (macsec_is_offloaded(netdev_priv(dev))) {
1811
+ const struct macsec_ops *ops;
1812
+ struct macsec_context ctx;
1813
+
1814
+ ops = macsec_get_ops(netdev_priv(dev), &ctx);
1815
+ if (!ops) {
1816
+ err = -EOPNOTSUPP;
1817
+ goto cleanup;
1818
+ }
1819
+
1820
+ ctx.sa.assoc_num = assoc_num;
1821
+ ctx.sa.rx_sa = rx_sa;
1822
+ ctx.secy = secy;
1823
+ memcpy(ctx.sa.key, nla_data(tb_sa[MACSEC_SA_ATTR_KEY]),
1824
+ secy->key_len);
1825
+
1826
+ err = macsec_offload(ops->mdo_add_rxsa, &ctx);
1827
+ memzero_explicit(ctx.sa.key, secy->key_len);
1828
+ if (err)
1829
+ goto cleanup;
1830
+ }
1831
+
1832
+ if (secy->xpn) {
1833
+ rx_sa->ssci = nla_get_ssci(tb_sa[MACSEC_SA_ATTR_SSCI]);
1834
+ nla_memcpy(rx_sa->key.salt.bytes, tb_sa[MACSEC_SA_ATTR_SALT],
1835
+ MACSEC_SALT_LEN);
1836
+ }
1837
+
1838
+ nla_memcpy(rx_sa->key.id, tb_sa[MACSEC_SA_ATTR_KEYID], MACSEC_KEYID_LEN);
17351839 rcu_assign_pointer(rx_sc->sa[assoc_num], rx_sa);
17361840
17371841 rtnl_unlock();
17381842
17391843 return 0;
1844
+
1845
+cleanup:
1846
+ macsec_rxsa_put(rx_sa);
1847
+ rtnl_unlock();
1848
+ return err;
17401849 }
17411850
17421851 static bool validate_add_rxsc(struct nlattr **attrs)
....@@ -1759,6 +1868,9 @@
17591868 struct nlattr **attrs = info->attrs;
17601869 struct macsec_rx_sc *rx_sc;
17611870 struct nlattr *tb_rxsc[MACSEC_RXSC_ATTR_MAX + 1];
1871
+ struct macsec_secy *secy;
1872
+ bool active = true;
1873
+ int ret;
17621874
17631875 if (!attrs[MACSEC_ATTR_IFINDEX])
17641876 return -EINVAL;
....@@ -1776,20 +1888,45 @@
17761888 return PTR_ERR(dev);
17771889 }
17781890
1891
+ secy = &macsec_priv(dev)->secy;
17791892 sci = nla_get_sci(tb_rxsc[MACSEC_RXSC_ATTR_SCI]);
17801893
1781
- rx_sc = create_rx_sc(dev, sci);
1894
+ if (tb_rxsc[MACSEC_RXSC_ATTR_ACTIVE])
1895
+ active = nla_get_u8(tb_rxsc[MACSEC_RXSC_ATTR_ACTIVE]);
1896
+
1897
+ rx_sc = create_rx_sc(dev, sci, active);
17821898 if (IS_ERR(rx_sc)) {
17831899 rtnl_unlock();
17841900 return PTR_ERR(rx_sc);
17851901 }
17861902
1787
- if (tb_rxsc[MACSEC_RXSC_ATTR_ACTIVE])
1788
- rx_sc->active = !!nla_get_u8(tb_rxsc[MACSEC_RXSC_ATTR_ACTIVE]);
1903
+ if (macsec_is_offloaded(netdev_priv(dev))) {
1904
+ const struct macsec_ops *ops;
1905
+ struct macsec_context ctx;
1906
+
1907
+ ops = macsec_get_ops(netdev_priv(dev), &ctx);
1908
+ if (!ops) {
1909
+ ret = -EOPNOTSUPP;
1910
+ goto cleanup;
1911
+ }
1912
+
1913
+ ctx.rx_sc = rx_sc;
1914
+ ctx.secy = secy;
1915
+
1916
+ ret = macsec_offload(ops->mdo_add_rxsc, &ctx);
1917
+ if (ret)
1918
+ goto cleanup;
1919
+ }
17891920
17901921 rtnl_unlock();
17911922
17921923 return 0;
1924
+
1925
+cleanup:
1926
+ del_rx_sc(secy, sci);
1927
+ free_rx_sc(rx_sc);
1928
+ rtnl_unlock();
1929
+ return ret;
17931930 }
17941931
17951932 static bool validate_add_txsa(struct nlattr **attrs)
....@@ -1803,7 +1940,7 @@
18031940 if (nla_get_u8(attrs[MACSEC_SA_ATTR_AN]) >= MACSEC_NUM_AN)
18041941 return false;
18051942
1806
- if (nla_get_u32(attrs[MACSEC_SA_ATTR_PN]) == 0)
1943
+ if (nla_get_u64(attrs[MACSEC_SA_ATTR_PN]) == 0)
18071944 return false;
18081945
18091946 if (attrs[MACSEC_SA_ATTR_ACTIVE]) {
....@@ -1825,7 +1962,9 @@
18251962 struct macsec_tx_sc *tx_sc;
18261963 struct macsec_tx_sa *tx_sa;
18271964 unsigned char assoc_num;
1965
+ int pn_len;
18281966 struct nlattr *tb_sa[MACSEC_SA_ATTR_MAX + 1];
1967
+ bool was_operational;
18291968 int err;
18301969
18311970 if (!attrs[MACSEC_ATTR_IFINDEX])
....@@ -1856,6 +1995,29 @@
18561995 return -EINVAL;
18571996 }
18581997
1998
+ pn_len = secy->xpn ? MACSEC_XPN_PN_LEN : MACSEC_DEFAULT_PN_LEN;
1999
+ if (nla_len(tb_sa[MACSEC_SA_ATTR_PN]) != pn_len) {
2000
+ pr_notice("macsec: nl: add_txsa: bad pn length: %d != %d\n",
2001
+ nla_len(tb_sa[MACSEC_SA_ATTR_PN]), pn_len);
2002
+ rtnl_unlock();
2003
+ return -EINVAL;
2004
+ }
2005
+
2006
+ if (secy->xpn) {
2007
+ if (!tb_sa[MACSEC_SA_ATTR_SSCI] || !tb_sa[MACSEC_SA_ATTR_SALT]) {
2008
+ rtnl_unlock();
2009
+ return -EINVAL;
2010
+ }
2011
+
2012
+ if (nla_len(tb_sa[MACSEC_SA_ATTR_SALT]) != MACSEC_SALT_LEN) {
2013
+ pr_notice("macsec: nl: add_txsa: bad salt length: %d != %d\n",
2014
+ nla_len(tb_sa[MACSEC_SA_ATTR_SALT]),
2015
+ MACSEC_SALT_LEN);
2016
+ rtnl_unlock();
2017
+ return -EINVAL;
2018
+ }
2019
+ }
2020
+
18592021 tx_sa = rtnl_dereference(tx_sc->sa[assoc_num]);
18602022 if (tx_sa) {
18612023 rtnl_unlock();
....@@ -1876,23 +2038,58 @@
18762038 return err;
18772039 }
18782040
1879
- nla_memcpy(tx_sa->key.id, tb_sa[MACSEC_SA_ATTR_KEYID], MACSEC_KEYID_LEN);
1880
-
18812041 spin_lock_bh(&tx_sa->lock);
1882
- tx_sa->next_pn = nla_get_u32(tb_sa[MACSEC_SA_ATTR_PN]);
2042
+ tx_sa->next_pn = nla_get_u64(tb_sa[MACSEC_SA_ATTR_PN]);
18832043 spin_unlock_bh(&tx_sa->lock);
18842044
18852045 if (tb_sa[MACSEC_SA_ATTR_ACTIVE])
18862046 tx_sa->active = !!nla_get_u8(tb_sa[MACSEC_SA_ATTR_ACTIVE]);
18872047
2048
+ was_operational = secy->operational;
18882049 if (assoc_num == tx_sc->encoding_sa && tx_sa->active)
18892050 secy->operational = true;
18902051
2052
+ /* If h/w offloading is available, propagate to the device */
2053
+ if (macsec_is_offloaded(netdev_priv(dev))) {
2054
+ const struct macsec_ops *ops;
2055
+ struct macsec_context ctx;
2056
+
2057
+ ops = macsec_get_ops(netdev_priv(dev), &ctx);
2058
+ if (!ops) {
2059
+ err = -EOPNOTSUPP;
2060
+ goto cleanup;
2061
+ }
2062
+
2063
+ ctx.sa.assoc_num = assoc_num;
2064
+ ctx.sa.tx_sa = tx_sa;
2065
+ ctx.secy = secy;
2066
+ memcpy(ctx.sa.key, nla_data(tb_sa[MACSEC_SA_ATTR_KEY]),
2067
+ secy->key_len);
2068
+
2069
+ err = macsec_offload(ops->mdo_add_txsa, &ctx);
2070
+ memzero_explicit(ctx.sa.key, secy->key_len);
2071
+ if (err)
2072
+ goto cleanup;
2073
+ }
2074
+
2075
+ if (secy->xpn) {
2076
+ tx_sa->ssci = nla_get_ssci(tb_sa[MACSEC_SA_ATTR_SSCI]);
2077
+ nla_memcpy(tx_sa->key.salt.bytes, tb_sa[MACSEC_SA_ATTR_SALT],
2078
+ MACSEC_SALT_LEN);
2079
+ }
2080
+
2081
+ nla_memcpy(tx_sa->key.id, tb_sa[MACSEC_SA_ATTR_KEYID], MACSEC_KEYID_LEN);
18912082 rcu_assign_pointer(tx_sc->sa[assoc_num], tx_sa);
18922083
18932084 rtnl_unlock();
18942085
18952086 return 0;
2087
+
2088
+cleanup:
2089
+ secy->operational = was_operational;
2090
+ macsec_txsa_put(tx_sa);
2091
+ rtnl_unlock();
2092
+ return err;
18962093 }
18972094
18982095 static int macsec_del_rxsa(struct sk_buff *skb, struct genl_info *info)
....@@ -1905,6 +2102,7 @@
19052102 u8 assoc_num;
19062103 struct nlattr *tb_rxsc[MACSEC_RXSC_ATTR_MAX + 1];
19072104 struct nlattr *tb_sa[MACSEC_SA_ATTR_MAX + 1];
2105
+ int ret;
19082106
19092107 if (!attrs[MACSEC_ATTR_IFINDEX])
19102108 return -EINVAL;
....@@ -1928,12 +2126,36 @@
19282126 return -EBUSY;
19292127 }
19302128
2129
+ /* If h/w offloading is available, propagate to the device */
2130
+ if (macsec_is_offloaded(netdev_priv(dev))) {
2131
+ const struct macsec_ops *ops;
2132
+ struct macsec_context ctx;
2133
+
2134
+ ops = macsec_get_ops(netdev_priv(dev), &ctx);
2135
+ if (!ops) {
2136
+ ret = -EOPNOTSUPP;
2137
+ goto cleanup;
2138
+ }
2139
+
2140
+ ctx.sa.assoc_num = assoc_num;
2141
+ ctx.sa.rx_sa = rx_sa;
2142
+ ctx.secy = secy;
2143
+
2144
+ ret = macsec_offload(ops->mdo_del_rxsa, &ctx);
2145
+ if (ret)
2146
+ goto cleanup;
2147
+ }
2148
+
19312149 RCU_INIT_POINTER(rx_sc->sa[assoc_num], NULL);
19322150 clear_rx_sa(rx_sa);
19332151
19342152 rtnl_unlock();
19352153
19362154 return 0;
2155
+
2156
+cleanup:
2157
+ rtnl_unlock();
2158
+ return ret;
19372159 }
19382160
19392161 static int macsec_del_rxsc(struct sk_buff *skb, struct genl_info *info)
....@@ -1944,6 +2166,7 @@
19442166 struct macsec_rx_sc *rx_sc;
19452167 sci_t sci;
19462168 struct nlattr *tb_rxsc[MACSEC_RXSC_ATTR_MAX + 1];
2169
+ int ret;
19472170
19482171 if (!attrs[MACSEC_ATTR_IFINDEX])
19492172 return -EINVAL;
....@@ -1970,10 +2193,32 @@
19702193 return -ENODEV;
19712194 }
19722195
2196
+ /* If h/w offloading is available, propagate to the device */
2197
+ if (macsec_is_offloaded(netdev_priv(dev))) {
2198
+ const struct macsec_ops *ops;
2199
+ struct macsec_context ctx;
2200
+
2201
+ ops = macsec_get_ops(netdev_priv(dev), &ctx);
2202
+ if (!ops) {
2203
+ ret = -EOPNOTSUPP;
2204
+ goto cleanup;
2205
+ }
2206
+
2207
+ ctx.rx_sc = rx_sc;
2208
+ ctx.secy = secy;
2209
+ ret = macsec_offload(ops->mdo_del_rxsc, &ctx);
2210
+ if (ret)
2211
+ goto cleanup;
2212
+ }
2213
+
19732214 free_rx_sc(rx_sc);
19742215 rtnl_unlock();
19752216
19762217 return 0;
2218
+
2219
+cleanup:
2220
+ rtnl_unlock();
2221
+ return ret;
19772222 }
19782223
19792224 static int macsec_del_txsa(struct sk_buff *skb, struct genl_info *info)
....@@ -1985,6 +2230,7 @@
19852230 struct macsec_tx_sa *tx_sa;
19862231 u8 assoc_num;
19872232 struct nlattr *tb_sa[MACSEC_SA_ATTR_MAX + 1];
2233
+ int ret;
19882234
19892235 if (!attrs[MACSEC_ATTR_IFINDEX])
19902236 return -EINVAL;
....@@ -2005,25 +2251,51 @@
20052251 return -EBUSY;
20062252 }
20072253
2254
+ /* If h/w offloading is available, propagate to the device */
2255
+ if (macsec_is_offloaded(netdev_priv(dev))) {
2256
+ const struct macsec_ops *ops;
2257
+ struct macsec_context ctx;
2258
+
2259
+ ops = macsec_get_ops(netdev_priv(dev), &ctx);
2260
+ if (!ops) {
2261
+ ret = -EOPNOTSUPP;
2262
+ goto cleanup;
2263
+ }
2264
+
2265
+ ctx.sa.assoc_num = assoc_num;
2266
+ ctx.sa.tx_sa = tx_sa;
2267
+ ctx.secy = secy;
2268
+
2269
+ ret = macsec_offload(ops->mdo_del_txsa, &ctx);
2270
+ if (ret)
2271
+ goto cleanup;
2272
+ }
2273
+
20082274 RCU_INIT_POINTER(tx_sc->sa[assoc_num], NULL);
20092275 clear_tx_sa(tx_sa);
20102276
20112277 rtnl_unlock();
20122278
20132279 return 0;
2280
+
2281
+cleanup:
2282
+ rtnl_unlock();
2283
+ return ret;
20142284 }
20152285
20162286 static bool validate_upd_sa(struct nlattr **attrs)
20172287 {
20182288 if (!attrs[MACSEC_SA_ATTR_AN] ||
20192289 attrs[MACSEC_SA_ATTR_KEY] ||
2020
- attrs[MACSEC_SA_ATTR_KEYID])
2290
+ attrs[MACSEC_SA_ATTR_KEYID] ||
2291
+ attrs[MACSEC_SA_ATTR_SSCI] ||
2292
+ attrs[MACSEC_SA_ATTR_SALT])
20212293 return false;
20222294
20232295 if (nla_get_u8(attrs[MACSEC_SA_ATTR_AN]) >= MACSEC_NUM_AN)
20242296 return false;
20252297
2026
- if (attrs[MACSEC_SA_ATTR_PN] && nla_get_u32(attrs[MACSEC_SA_ATTR_PN]) == 0)
2298
+ if (attrs[MACSEC_SA_ATTR_PN] && nla_get_u64(attrs[MACSEC_SA_ATTR_PN]) == 0)
20272299 return false;
20282300
20292301 if (attrs[MACSEC_SA_ATTR_ACTIVE]) {
....@@ -2043,6 +2315,11 @@
20432315 struct macsec_tx_sa *tx_sa;
20442316 u8 assoc_num;
20452317 struct nlattr *tb_sa[MACSEC_SA_ATTR_MAX + 1];
2318
+ bool was_operational, was_active;
2319
+ pn_t prev_pn;
2320
+ int ret = 0;
2321
+
2322
+ prev_pn.full64 = 0;
20462323
20472324 if (!attrs[MACSEC_ATTR_IFINDEX])
20482325 return -EINVAL;
....@@ -2062,20 +2339,64 @@
20622339 }
20632340
20642341 if (tb_sa[MACSEC_SA_ATTR_PN]) {
2342
+ int pn_len;
2343
+
2344
+ pn_len = secy->xpn ? MACSEC_XPN_PN_LEN : MACSEC_DEFAULT_PN_LEN;
2345
+ if (nla_len(tb_sa[MACSEC_SA_ATTR_PN]) != pn_len) {
2346
+ pr_notice("macsec: nl: upd_txsa: bad pn length: %d != %d\n",
2347
+ nla_len(tb_sa[MACSEC_SA_ATTR_PN]), pn_len);
2348
+ rtnl_unlock();
2349
+ return -EINVAL;
2350
+ }
2351
+
20652352 spin_lock_bh(&tx_sa->lock);
2066
- tx_sa->next_pn = nla_get_u32(tb_sa[MACSEC_SA_ATTR_PN]);
2353
+ prev_pn = tx_sa->next_pn_halves;
2354
+ tx_sa->next_pn = nla_get_u64(tb_sa[MACSEC_SA_ATTR_PN]);
20672355 spin_unlock_bh(&tx_sa->lock);
20682356 }
20692357
2358
+ was_active = tx_sa->active;
20702359 if (tb_sa[MACSEC_SA_ATTR_ACTIVE])
20712360 tx_sa->active = nla_get_u8(tb_sa[MACSEC_SA_ATTR_ACTIVE]);
20722361
2362
+ was_operational = secy->operational;
20732363 if (assoc_num == tx_sc->encoding_sa)
20742364 secy->operational = tx_sa->active;
2365
+
2366
+ /* If h/w offloading is available, propagate to the device */
2367
+ if (macsec_is_offloaded(netdev_priv(dev))) {
2368
+ const struct macsec_ops *ops;
2369
+ struct macsec_context ctx;
2370
+
2371
+ ops = macsec_get_ops(netdev_priv(dev), &ctx);
2372
+ if (!ops) {
2373
+ ret = -EOPNOTSUPP;
2374
+ goto cleanup;
2375
+ }
2376
+
2377
+ ctx.sa.assoc_num = assoc_num;
2378
+ ctx.sa.tx_sa = tx_sa;
2379
+ ctx.secy = secy;
2380
+
2381
+ ret = macsec_offload(ops->mdo_upd_txsa, &ctx);
2382
+ if (ret)
2383
+ goto cleanup;
2384
+ }
20752385
20762386 rtnl_unlock();
20772387
20782388 return 0;
2389
+
2390
+cleanup:
2391
+ if (tb_sa[MACSEC_SA_ATTR_PN]) {
2392
+ spin_lock_bh(&tx_sa->lock);
2393
+ tx_sa->next_pn_halves = prev_pn;
2394
+ spin_unlock_bh(&tx_sa->lock);
2395
+ }
2396
+ tx_sa->active = was_active;
2397
+ secy->operational = was_operational;
2398
+ rtnl_unlock();
2399
+ return ret;
20792400 }
20802401
20812402 static int macsec_upd_rxsa(struct sk_buff *skb, struct genl_info *info)
....@@ -2088,6 +2409,11 @@
20882409 u8 assoc_num;
20892410 struct nlattr *tb_rxsc[MACSEC_RXSC_ATTR_MAX + 1];
20902411 struct nlattr *tb_sa[MACSEC_SA_ATTR_MAX + 1];
2412
+ bool was_active;
2413
+ pn_t prev_pn;
2414
+ int ret = 0;
2415
+
2416
+ prev_pn.full64 = 0;
20912417
20922418 if (!attrs[MACSEC_ATTR_IFINDEX])
20932419 return -EINVAL;
....@@ -2110,16 +2436,58 @@
21102436 }
21112437
21122438 if (tb_sa[MACSEC_SA_ATTR_PN]) {
2439
+ int pn_len;
2440
+
2441
+ pn_len = secy->xpn ? MACSEC_XPN_PN_LEN : MACSEC_DEFAULT_PN_LEN;
2442
+ if (nla_len(tb_sa[MACSEC_SA_ATTR_PN]) != pn_len) {
2443
+ pr_notice("macsec: nl: upd_rxsa: bad pn length: %d != %d\n",
2444
+ nla_len(tb_sa[MACSEC_SA_ATTR_PN]), pn_len);
2445
+ rtnl_unlock();
2446
+ return -EINVAL;
2447
+ }
2448
+
21132449 spin_lock_bh(&rx_sa->lock);
2114
- rx_sa->next_pn = nla_get_u32(tb_sa[MACSEC_SA_ATTR_PN]);
2450
+ prev_pn = rx_sa->next_pn_halves;
2451
+ rx_sa->next_pn = nla_get_u64(tb_sa[MACSEC_SA_ATTR_PN]);
21152452 spin_unlock_bh(&rx_sa->lock);
21162453 }
21172454
2455
+ was_active = rx_sa->active;
21182456 if (tb_sa[MACSEC_SA_ATTR_ACTIVE])
21192457 rx_sa->active = nla_get_u8(tb_sa[MACSEC_SA_ATTR_ACTIVE]);
21202458
2459
+ /* If h/w offloading is available, propagate to the device */
2460
+ if (macsec_is_offloaded(netdev_priv(dev))) {
2461
+ const struct macsec_ops *ops;
2462
+ struct macsec_context ctx;
2463
+
2464
+ ops = macsec_get_ops(netdev_priv(dev), &ctx);
2465
+ if (!ops) {
2466
+ ret = -EOPNOTSUPP;
2467
+ goto cleanup;
2468
+ }
2469
+
2470
+ ctx.sa.assoc_num = assoc_num;
2471
+ ctx.sa.rx_sa = rx_sa;
2472
+ ctx.secy = secy;
2473
+
2474
+ ret = macsec_offload(ops->mdo_upd_rxsa, &ctx);
2475
+ if (ret)
2476
+ goto cleanup;
2477
+ }
2478
+
21212479 rtnl_unlock();
21222480 return 0;
2481
+
2482
+cleanup:
2483
+ if (tb_sa[MACSEC_SA_ATTR_PN]) {
2484
+ spin_lock_bh(&rx_sa->lock);
2485
+ rx_sa->next_pn_halves = prev_pn;
2486
+ spin_unlock_bh(&rx_sa->lock);
2487
+ }
2488
+ rx_sa->active = was_active;
2489
+ rtnl_unlock();
2490
+ return ret;
21232491 }
21242492
21252493 static int macsec_upd_rxsc(struct sk_buff *skb, struct genl_info *info)
....@@ -2129,6 +2497,9 @@
21292497 struct macsec_secy *secy;
21302498 struct macsec_rx_sc *rx_sc;
21312499 struct nlattr *tb_rxsc[MACSEC_RXSC_ATTR_MAX + 1];
2500
+ unsigned int prev_n_rx_sc;
2501
+ bool was_active;
2502
+ int ret;
21322503
21332504 if (!attrs[MACSEC_ATTR_IFINDEX])
21342505 return -EINVAL;
....@@ -2146,6 +2517,8 @@
21462517 return PTR_ERR(rx_sc);
21472518 }
21482519
2520
+ was_active = rx_sc->active;
2521
+ prev_n_rx_sc = secy->n_rx_sc;
21492522 if (tb_rxsc[MACSEC_RXSC_ATTR_ACTIVE]) {
21502523 bool new = !!nla_get_u8(tb_rxsc[MACSEC_RXSC_ATTR_ACTIVE]);
21512524
....@@ -2155,211 +2528,439 @@
21552528 rx_sc->active = new;
21562529 }
21572530
2531
+ /* If h/w offloading is available, propagate to the device */
2532
+ if (macsec_is_offloaded(netdev_priv(dev))) {
2533
+ const struct macsec_ops *ops;
2534
+ struct macsec_context ctx;
2535
+
2536
+ ops = macsec_get_ops(netdev_priv(dev), &ctx);
2537
+ if (!ops) {
2538
+ ret = -EOPNOTSUPP;
2539
+ goto cleanup;
2540
+ }
2541
+
2542
+ ctx.rx_sc = rx_sc;
2543
+ ctx.secy = secy;
2544
+
2545
+ ret = macsec_offload(ops->mdo_upd_rxsc, &ctx);
2546
+ if (ret)
2547
+ goto cleanup;
2548
+ }
2549
+
21582550 rtnl_unlock();
21592551
21602552 return 0;
2553
+
2554
+cleanup:
2555
+ secy->n_rx_sc = prev_n_rx_sc;
2556
+ rx_sc->active = was_active;
2557
+ rtnl_unlock();
2558
+ return ret;
21612559 }
21622560
2163
-static int copy_tx_sa_stats(struct sk_buff *skb,
2164
- struct macsec_tx_sa_stats __percpu *pstats)
2561
+static bool macsec_is_configured(struct macsec_dev *macsec)
21652562 {
2166
- struct macsec_tx_sa_stats sum = {0, };
2167
- int cpu;
2563
+ struct macsec_secy *secy = &macsec->secy;
2564
+ struct macsec_tx_sc *tx_sc = &secy->tx_sc;
2565
+ int i;
21682566
2169
- for_each_possible_cpu(cpu) {
2170
- const struct macsec_tx_sa_stats *stats = per_cpu_ptr(pstats, cpu);
2567
+ if (secy->rx_sc)
2568
+ return true;
21712569
2172
- sum.OutPktsProtected += stats->OutPktsProtected;
2173
- sum.OutPktsEncrypted += stats->OutPktsEncrypted;
2570
+ for (i = 0; i < MACSEC_NUM_AN; i++)
2571
+ if (tx_sc->sa[i])
2572
+ return true;
2573
+
2574
+ return false;
2575
+}
2576
+
2577
+static int macsec_upd_offload(struct sk_buff *skb, struct genl_info *info)
2578
+{
2579
+ struct nlattr *tb_offload[MACSEC_OFFLOAD_ATTR_MAX + 1];
2580
+ enum macsec_offload offload, prev_offload;
2581
+ int (*func)(struct macsec_context *ctx);
2582
+ struct nlattr **attrs = info->attrs;
2583
+ struct net_device *dev;
2584
+ const struct macsec_ops *ops;
2585
+ struct macsec_context ctx;
2586
+ struct macsec_dev *macsec;
2587
+ int ret;
2588
+
2589
+ if (!attrs[MACSEC_ATTR_IFINDEX])
2590
+ return -EINVAL;
2591
+
2592
+ if (!attrs[MACSEC_ATTR_OFFLOAD])
2593
+ return -EINVAL;
2594
+
2595
+ if (nla_parse_nested_deprecated(tb_offload, MACSEC_OFFLOAD_ATTR_MAX,
2596
+ attrs[MACSEC_ATTR_OFFLOAD],
2597
+ macsec_genl_offload_policy, NULL))
2598
+ return -EINVAL;
2599
+
2600
+ dev = get_dev_from_nl(genl_info_net(info), attrs);
2601
+ if (IS_ERR(dev))
2602
+ return PTR_ERR(dev);
2603
+ macsec = macsec_priv(dev);
2604
+
2605
+ if (!tb_offload[MACSEC_OFFLOAD_ATTR_TYPE])
2606
+ return -EINVAL;
2607
+
2608
+ offload = nla_get_u8(tb_offload[MACSEC_OFFLOAD_ATTR_TYPE]);
2609
+ if (macsec->offload == offload)
2610
+ return 0;
2611
+
2612
+ /* Check if the offloading mode is supported by the underlying layers */
2613
+ if (offload != MACSEC_OFFLOAD_OFF &&
2614
+ !macsec_check_offload(offload, macsec))
2615
+ return -EOPNOTSUPP;
2616
+
2617
+ /* Check if the net device is busy. */
2618
+ if (netif_running(dev))
2619
+ return -EBUSY;
2620
+
2621
+ rtnl_lock();
2622
+
2623
+ prev_offload = macsec->offload;
2624
+ macsec->offload = offload;
2625
+
2626
+ /* Check if the device already has rules configured: we do not support
2627
+ * rules migration.
2628
+ */
2629
+ if (macsec_is_configured(macsec)) {
2630
+ ret = -EBUSY;
2631
+ goto rollback;
21742632 }
21752633
2176
- if (nla_put_u32(skb, MACSEC_SA_STATS_ATTR_OUT_PKTS_PROTECTED, sum.OutPktsProtected) ||
2177
- nla_put_u32(skb, MACSEC_SA_STATS_ATTR_OUT_PKTS_ENCRYPTED, sum.OutPktsEncrypted))
2634
+ ops = __macsec_get_ops(offload == MACSEC_OFFLOAD_OFF ? prev_offload : offload,
2635
+ macsec, &ctx);
2636
+ if (!ops) {
2637
+ ret = -EOPNOTSUPP;
2638
+ goto rollback;
2639
+ }
2640
+
2641
+ if (prev_offload == MACSEC_OFFLOAD_OFF)
2642
+ func = ops->mdo_add_secy;
2643
+ else
2644
+ func = ops->mdo_del_secy;
2645
+
2646
+ ctx.secy = &macsec->secy;
2647
+ ret = macsec_offload(func, &ctx);
2648
+ if (ret)
2649
+ goto rollback;
2650
+
2651
+ rtnl_unlock();
2652
+ return 0;
2653
+
2654
+rollback:
2655
+ macsec->offload = prev_offload;
2656
+
2657
+ rtnl_unlock();
2658
+ return ret;
2659
+}
2660
+
2661
+static void get_tx_sa_stats(struct net_device *dev, int an,
2662
+ struct macsec_tx_sa *tx_sa,
2663
+ struct macsec_tx_sa_stats *sum)
2664
+{
2665
+ struct macsec_dev *macsec = macsec_priv(dev);
2666
+ int cpu;
2667
+
2668
+ /* If h/w offloading is available, propagate to the device */
2669
+ if (macsec_is_offloaded(macsec)) {
2670
+ const struct macsec_ops *ops;
2671
+ struct macsec_context ctx;
2672
+
2673
+ ops = macsec_get_ops(macsec, &ctx);
2674
+ if (ops) {
2675
+ ctx.sa.assoc_num = an;
2676
+ ctx.sa.tx_sa = tx_sa;
2677
+ ctx.stats.tx_sa_stats = sum;
2678
+ ctx.secy = &macsec_priv(dev)->secy;
2679
+ macsec_offload(ops->mdo_get_tx_sa_stats, &ctx);
2680
+ }
2681
+ return;
2682
+ }
2683
+
2684
+ for_each_possible_cpu(cpu) {
2685
+ const struct macsec_tx_sa_stats *stats =
2686
+ per_cpu_ptr(tx_sa->stats, cpu);
2687
+
2688
+ sum->OutPktsProtected += stats->OutPktsProtected;
2689
+ sum->OutPktsEncrypted += stats->OutPktsEncrypted;
2690
+ }
2691
+}
2692
+
2693
+static int copy_tx_sa_stats(struct sk_buff *skb, struct macsec_tx_sa_stats *sum)
2694
+{
2695
+ if (nla_put_u32(skb, MACSEC_SA_STATS_ATTR_OUT_PKTS_PROTECTED,
2696
+ sum->OutPktsProtected) ||
2697
+ nla_put_u32(skb, MACSEC_SA_STATS_ATTR_OUT_PKTS_ENCRYPTED,
2698
+ sum->OutPktsEncrypted))
21782699 return -EMSGSIZE;
21792700
21802701 return 0;
2702
+}
2703
+
2704
+static void get_rx_sa_stats(struct net_device *dev,
2705
+ struct macsec_rx_sc *rx_sc, int an,
2706
+ struct macsec_rx_sa *rx_sa,
2707
+ struct macsec_rx_sa_stats *sum)
2708
+{
2709
+ struct macsec_dev *macsec = macsec_priv(dev);
2710
+ int cpu;
2711
+
2712
+ /* If h/w offloading is available, propagate to the device */
2713
+ if (macsec_is_offloaded(macsec)) {
2714
+ const struct macsec_ops *ops;
2715
+ struct macsec_context ctx;
2716
+
2717
+ ops = macsec_get_ops(macsec, &ctx);
2718
+ if (ops) {
2719
+ ctx.sa.assoc_num = an;
2720
+ ctx.sa.rx_sa = rx_sa;
2721
+ ctx.stats.rx_sa_stats = sum;
2722
+ ctx.secy = &macsec_priv(dev)->secy;
2723
+ ctx.rx_sc = rx_sc;
2724
+ macsec_offload(ops->mdo_get_rx_sa_stats, &ctx);
2725
+ }
2726
+ return;
2727
+ }
2728
+
2729
+ for_each_possible_cpu(cpu) {
2730
+ const struct macsec_rx_sa_stats *stats =
2731
+ per_cpu_ptr(rx_sa->stats, cpu);
2732
+
2733
+ sum->InPktsOK += stats->InPktsOK;
2734
+ sum->InPktsInvalid += stats->InPktsInvalid;
2735
+ sum->InPktsNotValid += stats->InPktsNotValid;
2736
+ sum->InPktsNotUsingSA += stats->InPktsNotUsingSA;
2737
+ sum->InPktsUnusedSA += stats->InPktsUnusedSA;
2738
+ }
21812739 }
21822740
21832741 static int copy_rx_sa_stats(struct sk_buff *skb,
2184
- struct macsec_rx_sa_stats __percpu *pstats)
2742
+ struct macsec_rx_sa_stats *sum)
21852743 {
2186
- struct macsec_rx_sa_stats sum = {0, };
2187
- int cpu;
2188
-
2189
- for_each_possible_cpu(cpu) {
2190
- const struct macsec_rx_sa_stats *stats = per_cpu_ptr(pstats, cpu);
2191
-
2192
- sum.InPktsOK += stats->InPktsOK;
2193
- sum.InPktsInvalid += stats->InPktsInvalid;
2194
- sum.InPktsNotValid += stats->InPktsNotValid;
2195
- sum.InPktsNotUsingSA += stats->InPktsNotUsingSA;
2196
- sum.InPktsUnusedSA += stats->InPktsUnusedSA;
2197
- }
2198
-
2199
- if (nla_put_u32(skb, MACSEC_SA_STATS_ATTR_IN_PKTS_OK, sum.InPktsOK) ||
2200
- nla_put_u32(skb, MACSEC_SA_STATS_ATTR_IN_PKTS_INVALID, sum.InPktsInvalid) ||
2201
- nla_put_u32(skb, MACSEC_SA_STATS_ATTR_IN_PKTS_NOT_VALID, sum.InPktsNotValid) ||
2202
- nla_put_u32(skb, MACSEC_SA_STATS_ATTR_IN_PKTS_NOT_USING_SA, sum.InPktsNotUsingSA) ||
2203
- nla_put_u32(skb, MACSEC_SA_STATS_ATTR_IN_PKTS_UNUSED_SA, sum.InPktsUnusedSA))
2744
+ if (nla_put_u32(skb, MACSEC_SA_STATS_ATTR_IN_PKTS_OK, sum->InPktsOK) ||
2745
+ nla_put_u32(skb, MACSEC_SA_STATS_ATTR_IN_PKTS_INVALID,
2746
+ sum->InPktsInvalid) ||
2747
+ nla_put_u32(skb, MACSEC_SA_STATS_ATTR_IN_PKTS_NOT_VALID,
2748
+ sum->InPktsNotValid) ||
2749
+ nla_put_u32(skb, MACSEC_SA_STATS_ATTR_IN_PKTS_NOT_USING_SA,
2750
+ sum->InPktsNotUsingSA) ||
2751
+ nla_put_u32(skb, MACSEC_SA_STATS_ATTR_IN_PKTS_UNUSED_SA,
2752
+ sum->InPktsUnusedSA))
22042753 return -EMSGSIZE;
22052754
22062755 return 0;
22072756 }
22082757
2209
-static int copy_rx_sc_stats(struct sk_buff *skb,
2210
- struct pcpu_rx_sc_stats __percpu *pstats)
2758
+static void get_rx_sc_stats(struct net_device *dev,
2759
+ struct macsec_rx_sc *rx_sc,
2760
+ struct macsec_rx_sc_stats *sum)
22112761 {
2212
- struct macsec_rx_sc_stats sum = {0, };
2762
+ struct macsec_dev *macsec = macsec_priv(dev);
22132763 int cpu;
2764
+
2765
+ /* If h/w offloading is available, propagate to the device */
2766
+ if (macsec_is_offloaded(macsec)) {
2767
+ const struct macsec_ops *ops;
2768
+ struct macsec_context ctx;
2769
+
2770
+ ops = macsec_get_ops(macsec, &ctx);
2771
+ if (ops) {
2772
+ ctx.stats.rx_sc_stats = sum;
2773
+ ctx.secy = &macsec_priv(dev)->secy;
2774
+ ctx.rx_sc = rx_sc;
2775
+ macsec_offload(ops->mdo_get_rx_sc_stats, &ctx);
2776
+ }
2777
+ return;
2778
+ }
22142779
22152780 for_each_possible_cpu(cpu) {
22162781 const struct pcpu_rx_sc_stats *stats;
22172782 struct macsec_rx_sc_stats tmp;
22182783 unsigned int start;
22192784
2220
- stats = per_cpu_ptr(pstats, cpu);
2785
+ stats = per_cpu_ptr(rx_sc->stats, cpu);
22212786 do {
22222787 start = u64_stats_fetch_begin_irq(&stats->syncp);
22232788 memcpy(&tmp, &stats->stats, sizeof(tmp));
22242789 } while (u64_stats_fetch_retry_irq(&stats->syncp, start));
22252790
2226
- sum.InOctetsValidated += tmp.InOctetsValidated;
2227
- sum.InOctetsDecrypted += tmp.InOctetsDecrypted;
2228
- sum.InPktsUnchecked += tmp.InPktsUnchecked;
2229
- sum.InPktsDelayed += tmp.InPktsDelayed;
2230
- sum.InPktsOK += tmp.InPktsOK;
2231
- sum.InPktsInvalid += tmp.InPktsInvalid;
2232
- sum.InPktsLate += tmp.InPktsLate;
2233
- sum.InPktsNotValid += tmp.InPktsNotValid;
2234
- sum.InPktsNotUsingSA += tmp.InPktsNotUsingSA;
2235
- sum.InPktsUnusedSA += tmp.InPktsUnusedSA;
2791
+ sum->InOctetsValidated += tmp.InOctetsValidated;
2792
+ sum->InOctetsDecrypted += tmp.InOctetsDecrypted;
2793
+ sum->InPktsUnchecked += tmp.InPktsUnchecked;
2794
+ sum->InPktsDelayed += tmp.InPktsDelayed;
2795
+ sum->InPktsOK += tmp.InPktsOK;
2796
+ sum->InPktsInvalid += tmp.InPktsInvalid;
2797
+ sum->InPktsLate += tmp.InPktsLate;
2798
+ sum->InPktsNotValid += tmp.InPktsNotValid;
2799
+ sum->InPktsNotUsingSA += tmp.InPktsNotUsingSA;
2800
+ sum->InPktsUnusedSA += tmp.InPktsUnusedSA;
22362801 }
2802
+}
22372803
2804
+static int copy_rx_sc_stats(struct sk_buff *skb, struct macsec_rx_sc_stats *sum)
2805
+{
22382806 if (nla_put_u64_64bit(skb, MACSEC_RXSC_STATS_ATTR_IN_OCTETS_VALIDATED,
2239
- sum.InOctetsValidated,
2807
+ sum->InOctetsValidated,
22402808 MACSEC_RXSC_STATS_ATTR_PAD) ||
22412809 nla_put_u64_64bit(skb, MACSEC_RXSC_STATS_ATTR_IN_OCTETS_DECRYPTED,
2242
- sum.InOctetsDecrypted,
2810
+ sum->InOctetsDecrypted,
22432811 MACSEC_RXSC_STATS_ATTR_PAD) ||
22442812 nla_put_u64_64bit(skb, MACSEC_RXSC_STATS_ATTR_IN_PKTS_UNCHECKED,
2245
- sum.InPktsUnchecked,
2813
+ sum->InPktsUnchecked,
22462814 MACSEC_RXSC_STATS_ATTR_PAD) ||
22472815 nla_put_u64_64bit(skb, MACSEC_RXSC_STATS_ATTR_IN_PKTS_DELAYED,
2248
- sum.InPktsDelayed,
2816
+ sum->InPktsDelayed,
22492817 MACSEC_RXSC_STATS_ATTR_PAD) ||
22502818 nla_put_u64_64bit(skb, MACSEC_RXSC_STATS_ATTR_IN_PKTS_OK,
2251
- sum.InPktsOK,
2819
+ sum->InPktsOK,
22522820 MACSEC_RXSC_STATS_ATTR_PAD) ||
22532821 nla_put_u64_64bit(skb, MACSEC_RXSC_STATS_ATTR_IN_PKTS_INVALID,
2254
- sum.InPktsInvalid,
2822
+ sum->InPktsInvalid,
22552823 MACSEC_RXSC_STATS_ATTR_PAD) ||
22562824 nla_put_u64_64bit(skb, MACSEC_RXSC_STATS_ATTR_IN_PKTS_LATE,
2257
- sum.InPktsLate,
2825
+ sum->InPktsLate,
22582826 MACSEC_RXSC_STATS_ATTR_PAD) ||
22592827 nla_put_u64_64bit(skb, MACSEC_RXSC_STATS_ATTR_IN_PKTS_NOT_VALID,
2260
- sum.InPktsNotValid,
2828
+ sum->InPktsNotValid,
22612829 MACSEC_RXSC_STATS_ATTR_PAD) ||
22622830 nla_put_u64_64bit(skb, MACSEC_RXSC_STATS_ATTR_IN_PKTS_NOT_USING_SA,
2263
- sum.InPktsNotUsingSA,
2831
+ sum->InPktsNotUsingSA,
22642832 MACSEC_RXSC_STATS_ATTR_PAD) ||
22652833 nla_put_u64_64bit(skb, MACSEC_RXSC_STATS_ATTR_IN_PKTS_UNUSED_SA,
2266
- sum.InPktsUnusedSA,
2834
+ sum->InPktsUnusedSA,
22672835 MACSEC_RXSC_STATS_ATTR_PAD))
22682836 return -EMSGSIZE;
22692837
22702838 return 0;
22712839 }
22722840
2273
-static int copy_tx_sc_stats(struct sk_buff *skb,
2274
- struct pcpu_tx_sc_stats __percpu *pstats)
2841
+static void get_tx_sc_stats(struct net_device *dev,
2842
+ struct macsec_tx_sc_stats *sum)
22752843 {
2276
- struct macsec_tx_sc_stats sum = {0, };
2844
+ struct macsec_dev *macsec = macsec_priv(dev);
22772845 int cpu;
2846
+
2847
+ /* If h/w offloading is available, propagate to the device */
2848
+ if (macsec_is_offloaded(macsec)) {
2849
+ const struct macsec_ops *ops;
2850
+ struct macsec_context ctx;
2851
+
2852
+ ops = macsec_get_ops(macsec, &ctx);
2853
+ if (ops) {
2854
+ ctx.stats.tx_sc_stats = sum;
2855
+ ctx.secy = &macsec_priv(dev)->secy;
2856
+ macsec_offload(ops->mdo_get_tx_sc_stats, &ctx);
2857
+ }
2858
+ return;
2859
+ }
22782860
22792861 for_each_possible_cpu(cpu) {
22802862 const struct pcpu_tx_sc_stats *stats;
22812863 struct macsec_tx_sc_stats tmp;
22822864 unsigned int start;
22832865
2284
- stats = per_cpu_ptr(pstats, cpu);
2866
+ stats = per_cpu_ptr(macsec_priv(dev)->secy.tx_sc.stats, cpu);
22852867 do {
22862868 start = u64_stats_fetch_begin_irq(&stats->syncp);
22872869 memcpy(&tmp, &stats->stats, sizeof(tmp));
22882870 } while (u64_stats_fetch_retry_irq(&stats->syncp, start));
22892871
2290
- sum.OutPktsProtected += tmp.OutPktsProtected;
2291
- sum.OutPktsEncrypted += tmp.OutPktsEncrypted;
2292
- sum.OutOctetsProtected += tmp.OutOctetsProtected;
2293
- sum.OutOctetsEncrypted += tmp.OutOctetsEncrypted;
2872
+ sum->OutPktsProtected += tmp.OutPktsProtected;
2873
+ sum->OutPktsEncrypted += tmp.OutPktsEncrypted;
2874
+ sum->OutOctetsProtected += tmp.OutOctetsProtected;
2875
+ sum->OutOctetsEncrypted += tmp.OutOctetsEncrypted;
22942876 }
2877
+}
22952878
2879
+static int copy_tx_sc_stats(struct sk_buff *skb, struct macsec_tx_sc_stats *sum)
2880
+{
22962881 if (nla_put_u64_64bit(skb, MACSEC_TXSC_STATS_ATTR_OUT_PKTS_PROTECTED,
2297
- sum.OutPktsProtected,
2882
+ sum->OutPktsProtected,
22982883 MACSEC_TXSC_STATS_ATTR_PAD) ||
22992884 nla_put_u64_64bit(skb, MACSEC_TXSC_STATS_ATTR_OUT_PKTS_ENCRYPTED,
2300
- sum.OutPktsEncrypted,
2885
+ sum->OutPktsEncrypted,
23012886 MACSEC_TXSC_STATS_ATTR_PAD) ||
23022887 nla_put_u64_64bit(skb, MACSEC_TXSC_STATS_ATTR_OUT_OCTETS_PROTECTED,
2303
- sum.OutOctetsProtected,
2888
+ sum->OutOctetsProtected,
23042889 MACSEC_TXSC_STATS_ATTR_PAD) ||
23052890 nla_put_u64_64bit(skb, MACSEC_TXSC_STATS_ATTR_OUT_OCTETS_ENCRYPTED,
2306
- sum.OutOctetsEncrypted,
2891
+ sum->OutOctetsEncrypted,
23072892 MACSEC_TXSC_STATS_ATTR_PAD))
23082893 return -EMSGSIZE;
23092894
23102895 return 0;
23112896 }
23122897
2313
-static int copy_secy_stats(struct sk_buff *skb,
2314
- struct pcpu_secy_stats __percpu *pstats)
2898
+static void get_secy_stats(struct net_device *dev, struct macsec_dev_stats *sum)
23152899 {
2316
- struct macsec_dev_stats sum = {0, };
2900
+ struct macsec_dev *macsec = macsec_priv(dev);
23172901 int cpu;
2902
+
2903
+ /* If h/w offloading is available, propagate to the device */
2904
+ if (macsec_is_offloaded(macsec)) {
2905
+ const struct macsec_ops *ops;
2906
+ struct macsec_context ctx;
2907
+
2908
+ ops = macsec_get_ops(macsec, &ctx);
2909
+ if (ops) {
2910
+ ctx.stats.dev_stats = sum;
2911
+ ctx.secy = &macsec_priv(dev)->secy;
2912
+ macsec_offload(ops->mdo_get_dev_stats, &ctx);
2913
+ }
2914
+ return;
2915
+ }
23182916
23192917 for_each_possible_cpu(cpu) {
23202918 const struct pcpu_secy_stats *stats;
23212919 struct macsec_dev_stats tmp;
23222920 unsigned int start;
23232921
2324
- stats = per_cpu_ptr(pstats, cpu);
2922
+ stats = per_cpu_ptr(macsec_priv(dev)->stats, cpu);
23252923 do {
23262924 start = u64_stats_fetch_begin_irq(&stats->syncp);
23272925 memcpy(&tmp, &stats->stats, sizeof(tmp));
23282926 } while (u64_stats_fetch_retry_irq(&stats->syncp, start));
23292927
2330
- sum.OutPktsUntagged += tmp.OutPktsUntagged;
2331
- sum.InPktsUntagged += tmp.InPktsUntagged;
2332
- sum.OutPktsTooLong += tmp.OutPktsTooLong;
2333
- sum.InPktsNoTag += tmp.InPktsNoTag;
2334
- sum.InPktsBadTag += tmp.InPktsBadTag;
2335
- sum.InPktsUnknownSCI += tmp.InPktsUnknownSCI;
2336
- sum.InPktsNoSCI += tmp.InPktsNoSCI;
2337
- sum.InPktsOverrun += tmp.InPktsOverrun;
2928
+ sum->OutPktsUntagged += tmp.OutPktsUntagged;
2929
+ sum->InPktsUntagged += tmp.InPktsUntagged;
2930
+ sum->OutPktsTooLong += tmp.OutPktsTooLong;
2931
+ sum->InPktsNoTag += tmp.InPktsNoTag;
2932
+ sum->InPktsBadTag += tmp.InPktsBadTag;
2933
+ sum->InPktsUnknownSCI += tmp.InPktsUnknownSCI;
2934
+ sum->InPktsNoSCI += tmp.InPktsNoSCI;
2935
+ sum->InPktsOverrun += tmp.InPktsOverrun;
23382936 }
2937
+}
23392938
2939
+static int copy_secy_stats(struct sk_buff *skb, struct macsec_dev_stats *sum)
2940
+{
23402941 if (nla_put_u64_64bit(skb, MACSEC_SECY_STATS_ATTR_OUT_PKTS_UNTAGGED,
2341
- sum.OutPktsUntagged,
2942
+ sum->OutPktsUntagged,
23422943 MACSEC_SECY_STATS_ATTR_PAD) ||
23432944 nla_put_u64_64bit(skb, MACSEC_SECY_STATS_ATTR_IN_PKTS_UNTAGGED,
2344
- sum.InPktsUntagged,
2945
+ sum->InPktsUntagged,
23452946 MACSEC_SECY_STATS_ATTR_PAD) ||
23462947 nla_put_u64_64bit(skb, MACSEC_SECY_STATS_ATTR_OUT_PKTS_TOO_LONG,
2347
- sum.OutPktsTooLong,
2948
+ sum->OutPktsTooLong,
23482949 MACSEC_SECY_STATS_ATTR_PAD) ||
23492950 nla_put_u64_64bit(skb, MACSEC_SECY_STATS_ATTR_IN_PKTS_NO_TAG,
2350
- sum.InPktsNoTag,
2951
+ sum->InPktsNoTag,
23512952 MACSEC_SECY_STATS_ATTR_PAD) ||
23522953 nla_put_u64_64bit(skb, MACSEC_SECY_STATS_ATTR_IN_PKTS_BAD_TAG,
2353
- sum.InPktsBadTag,
2954
+ sum->InPktsBadTag,
23542955 MACSEC_SECY_STATS_ATTR_PAD) ||
23552956 nla_put_u64_64bit(skb, MACSEC_SECY_STATS_ATTR_IN_PKTS_UNKNOWN_SCI,
2356
- sum.InPktsUnknownSCI,
2957
+ sum->InPktsUnknownSCI,
23572958 MACSEC_SECY_STATS_ATTR_PAD) ||
23582959 nla_put_u64_64bit(skb, MACSEC_SECY_STATS_ATTR_IN_PKTS_NO_SCI,
2359
- sum.InPktsNoSCI,
2960
+ sum->InPktsNoSCI,
23602961 MACSEC_SECY_STATS_ATTR_PAD) ||
23612962 nla_put_u64_64bit(skb, MACSEC_SECY_STATS_ATTR_IN_PKTS_OVERRUN,
2362
- sum.InPktsOverrun,
2963
+ sum->InPktsOverrun,
23632964 MACSEC_SECY_STATS_ATTR_PAD))
23642965 return -EMSGSIZE;
23652966
....@@ -2369,7 +2970,8 @@
23692970 static int nla_put_secy(struct macsec_secy *secy, struct sk_buff *skb)
23702971 {
23712972 struct macsec_tx_sc *tx_sc = &secy->tx_sc;
2372
- struct nlattr *secy_nest = nla_nest_start(skb, MACSEC_ATTR_SECY);
2973
+ struct nlattr *secy_nest = nla_nest_start_noflag(skb,
2974
+ MACSEC_ATTR_SECY);
23732975 u64 csid;
23742976
23752977 if (!secy_nest)
....@@ -2377,10 +2979,10 @@
23772979
23782980 switch (secy->key_len) {
23792981 case MACSEC_GCM_AES_128_SAK_LEN:
2380
- csid = MACSEC_DEFAULT_CIPHER_ID;
2982
+ csid = secy->xpn ? MACSEC_CIPHER_ID_GCM_AES_XPN_128 : MACSEC_DEFAULT_CIPHER_ID;
23812983 break;
23822984 case MACSEC_GCM_AES_256_SAK_LEN:
2383
- csid = MACSEC_CIPHER_ID_GCM_AES_256;
2985
+ csid = secy->xpn ? MACSEC_CIPHER_ID_GCM_AES_XPN_256 : MACSEC_CIPHER_ID_GCM_AES_256;
23842986 break;
23852987 default:
23862988 goto cancel;
....@@ -2415,15 +3017,22 @@
24153017 return 1;
24163018 }
24173019
2418
-static int dump_secy(struct macsec_secy *secy, struct net_device *dev,
2419
- struct sk_buff *skb, struct netlink_callback *cb)
3020
+static noinline_for_stack int
3021
+dump_secy(struct macsec_secy *secy, struct net_device *dev,
3022
+ struct sk_buff *skb, struct netlink_callback *cb)
24203023 {
2421
- struct macsec_rx_sc *rx_sc;
3024
+ struct macsec_tx_sc_stats tx_sc_stats = {0, };
3025
+ struct macsec_tx_sa_stats tx_sa_stats = {0, };
3026
+ struct macsec_rx_sc_stats rx_sc_stats = {0, };
3027
+ struct macsec_rx_sa_stats rx_sa_stats = {0, };
3028
+ struct macsec_dev *macsec = netdev_priv(dev);
3029
+ struct macsec_dev_stats dev_stats = {0, };
24223030 struct macsec_tx_sc *tx_sc = &secy->tx_sc;
24233031 struct nlattr *txsa_list, *rxsc_list;
2424
- int i, j;
2425
- void *hdr;
3032
+ struct macsec_rx_sc *rx_sc;
24263033 struct nlattr *attr;
3034
+ void *hdr;
3035
+ int i, j;
24273036
24283037 hdr = genlmsg_put(skb, NETLINK_CB(cb->skb).portid, cb->nlh->nlmsg_seq,
24293038 &macsec_fam, NLM_F_MULTI, MACSEC_CMD_GET_TXSC);
....@@ -2435,59 +3044,64 @@
24353044 if (nla_put_u32(skb, MACSEC_ATTR_IFINDEX, dev->ifindex))
24363045 goto nla_put_failure;
24373046
3047
+ attr = nla_nest_start_noflag(skb, MACSEC_ATTR_OFFLOAD);
3048
+ if (!attr)
3049
+ goto nla_put_failure;
3050
+ if (nla_put_u8(skb, MACSEC_OFFLOAD_ATTR_TYPE, macsec->offload))
3051
+ goto nla_put_failure;
3052
+ nla_nest_end(skb, attr);
3053
+
24383054 if (nla_put_secy(secy, skb))
24393055 goto nla_put_failure;
24403056
2441
- attr = nla_nest_start(skb, MACSEC_ATTR_TXSC_STATS);
3057
+ attr = nla_nest_start_noflag(skb, MACSEC_ATTR_TXSC_STATS);
24423058 if (!attr)
24433059 goto nla_put_failure;
2444
- if (copy_tx_sc_stats(skb, tx_sc->stats)) {
3060
+
3061
+ get_tx_sc_stats(dev, &tx_sc_stats);
3062
+ if (copy_tx_sc_stats(skb, &tx_sc_stats)) {
24453063 nla_nest_cancel(skb, attr);
24463064 goto nla_put_failure;
24473065 }
24483066 nla_nest_end(skb, attr);
24493067
2450
- attr = nla_nest_start(skb, MACSEC_ATTR_SECY_STATS);
3068
+ attr = nla_nest_start_noflag(skb, MACSEC_ATTR_SECY_STATS);
24513069 if (!attr)
24523070 goto nla_put_failure;
2453
- if (copy_secy_stats(skb, macsec_priv(dev)->stats)) {
3071
+ get_secy_stats(dev, &dev_stats);
3072
+ if (copy_secy_stats(skb, &dev_stats)) {
24543073 nla_nest_cancel(skb, attr);
24553074 goto nla_put_failure;
24563075 }
24573076 nla_nest_end(skb, attr);
24583077
2459
- txsa_list = nla_nest_start(skb, MACSEC_ATTR_TXSA_LIST);
3078
+ txsa_list = nla_nest_start_noflag(skb, MACSEC_ATTR_TXSA_LIST);
24603079 if (!txsa_list)
24613080 goto nla_put_failure;
24623081 for (i = 0, j = 1; i < MACSEC_NUM_AN; i++) {
24633082 struct macsec_tx_sa *tx_sa = rtnl_dereference(tx_sc->sa[i]);
24643083 struct nlattr *txsa_nest;
3084
+ u64 pn;
3085
+ int pn_len;
24653086
24663087 if (!tx_sa)
24673088 continue;
24683089
2469
- txsa_nest = nla_nest_start(skb, j++);
3090
+ txsa_nest = nla_nest_start_noflag(skb, j++);
24703091 if (!txsa_nest) {
24713092 nla_nest_cancel(skb, txsa_list);
24723093 goto nla_put_failure;
24733094 }
24743095
2475
- if (nla_put_u8(skb, MACSEC_SA_ATTR_AN, i) ||
2476
- nla_put_u32(skb, MACSEC_SA_ATTR_PN, tx_sa->next_pn) ||
2477
- nla_put(skb, MACSEC_SA_ATTR_KEYID, MACSEC_KEYID_LEN, tx_sa->key.id) ||
2478
- nla_put_u8(skb, MACSEC_SA_ATTR_ACTIVE, tx_sa->active)) {
2479
- nla_nest_cancel(skb, txsa_nest);
2480
- nla_nest_cancel(skb, txsa_list);
2481
- goto nla_put_failure;
2482
- }
2483
-
2484
- attr = nla_nest_start(skb, MACSEC_SA_ATTR_STATS);
3096
+ attr = nla_nest_start_noflag(skb, MACSEC_SA_ATTR_STATS);
24853097 if (!attr) {
24863098 nla_nest_cancel(skb, txsa_nest);
24873099 nla_nest_cancel(skb, txsa_list);
24883100 goto nla_put_failure;
24893101 }
2490
- if (copy_tx_sa_stats(skb, tx_sa->stats)) {
3102
+ memset(&tx_sa_stats, 0, sizeof(tx_sa_stats));
3103
+ get_tx_sa_stats(dev, i, tx_sa, &tx_sa_stats);
3104
+ if (copy_tx_sa_stats(skb, &tx_sa_stats)) {
24913105 nla_nest_cancel(skb, attr);
24923106 nla_nest_cancel(skb, txsa_nest);
24933107 nla_nest_cancel(skb, txsa_list);
....@@ -2495,11 +3109,29 @@
24953109 }
24963110 nla_nest_end(skb, attr);
24973111
3112
+ if (secy->xpn) {
3113
+ pn = tx_sa->next_pn;
3114
+ pn_len = MACSEC_XPN_PN_LEN;
3115
+ } else {
3116
+ pn = tx_sa->next_pn_halves.lower;
3117
+ pn_len = MACSEC_DEFAULT_PN_LEN;
3118
+ }
3119
+
3120
+ if (nla_put_u8(skb, MACSEC_SA_ATTR_AN, i) ||
3121
+ nla_put(skb, MACSEC_SA_ATTR_PN, pn_len, &pn) ||
3122
+ nla_put(skb, MACSEC_SA_ATTR_KEYID, MACSEC_KEYID_LEN, tx_sa->key.id) ||
3123
+ (secy->xpn && nla_put_ssci(skb, MACSEC_SA_ATTR_SSCI, tx_sa->ssci)) ||
3124
+ nla_put_u8(skb, MACSEC_SA_ATTR_ACTIVE, tx_sa->active)) {
3125
+ nla_nest_cancel(skb, txsa_nest);
3126
+ nla_nest_cancel(skb, txsa_list);
3127
+ goto nla_put_failure;
3128
+ }
3129
+
24983130 nla_nest_end(skb, txsa_nest);
24993131 }
25003132 nla_nest_end(skb, txsa_list);
25013133
2502
- rxsc_list = nla_nest_start(skb, MACSEC_ATTR_RXSC_LIST);
3134
+ rxsc_list = nla_nest_start_noflag(skb, MACSEC_ATTR_RXSC_LIST);
25033135 if (!rxsc_list)
25043136 goto nla_put_failure;
25053137
....@@ -2507,7 +3139,7 @@
25073139 for_each_rxsc_rtnl(secy, rx_sc) {
25083140 int k;
25093141 struct nlattr *rxsa_list;
2510
- struct nlattr *rxsc_nest = nla_nest_start(skb, j++);
3142
+ struct nlattr *rxsc_nest = nla_nest_start_noflag(skb, j++);
25113143
25123144 if (!rxsc_nest) {
25133145 nla_nest_cancel(skb, rxsc_list);
....@@ -2522,13 +3154,15 @@
25223154 goto nla_put_failure;
25233155 }
25243156
2525
- attr = nla_nest_start(skb, MACSEC_RXSC_ATTR_STATS);
3157
+ attr = nla_nest_start_noflag(skb, MACSEC_RXSC_ATTR_STATS);
25263158 if (!attr) {
25273159 nla_nest_cancel(skb, rxsc_nest);
25283160 nla_nest_cancel(skb, rxsc_list);
25293161 goto nla_put_failure;
25303162 }
2531
- if (copy_rx_sc_stats(skb, rx_sc->stats)) {
3163
+ memset(&rx_sc_stats, 0, sizeof(rx_sc_stats));
3164
+ get_rx_sc_stats(dev, rx_sc, &rx_sc_stats);
3165
+ if (copy_rx_sc_stats(skb, &rx_sc_stats)) {
25323166 nla_nest_cancel(skb, attr);
25333167 nla_nest_cancel(skb, rxsc_nest);
25343168 nla_nest_cancel(skb, rxsc_list);
....@@ -2536,7 +3170,8 @@
25363170 }
25373171 nla_nest_end(skb, attr);
25383172
2539
- rxsa_list = nla_nest_start(skb, MACSEC_RXSC_ATTR_SA_LIST);
3173
+ rxsa_list = nla_nest_start_noflag(skb,
3174
+ MACSEC_RXSC_ATTR_SA_LIST);
25403175 if (!rxsa_list) {
25413176 nla_nest_cancel(skb, rxsc_nest);
25423177 nla_nest_cancel(skb, rxsc_list);
....@@ -2546,11 +3181,13 @@
25463181 for (i = 0, k = 1; i < MACSEC_NUM_AN; i++) {
25473182 struct macsec_rx_sa *rx_sa = rtnl_dereference(rx_sc->sa[i]);
25483183 struct nlattr *rxsa_nest;
3184
+ u64 pn;
3185
+ int pn_len;
25493186
25503187 if (!rx_sa)
25513188 continue;
25523189
2553
- rxsa_nest = nla_nest_start(skb, k++);
3190
+ rxsa_nest = nla_nest_start_noflag(skb, k++);
25543191 if (!rxsa_nest) {
25553192 nla_nest_cancel(skb, rxsa_list);
25563193 nla_nest_cancel(skb, rxsc_nest);
....@@ -2558,14 +3195,17 @@
25583195 goto nla_put_failure;
25593196 }
25603197
2561
- attr = nla_nest_start(skb, MACSEC_SA_ATTR_STATS);
3198
+ attr = nla_nest_start_noflag(skb,
3199
+ MACSEC_SA_ATTR_STATS);
25623200 if (!attr) {
25633201 nla_nest_cancel(skb, rxsa_list);
25643202 nla_nest_cancel(skb, rxsc_nest);
25653203 nla_nest_cancel(skb, rxsc_list);
25663204 goto nla_put_failure;
25673205 }
2568
- if (copy_rx_sa_stats(skb, rx_sa->stats)) {
3206
+ memset(&rx_sa_stats, 0, sizeof(rx_sa_stats));
3207
+ get_rx_sa_stats(dev, rx_sc, i, rx_sa, &rx_sa_stats);
3208
+ if (copy_rx_sa_stats(skb, &rx_sa_stats)) {
25693209 nla_nest_cancel(skb, attr);
25703210 nla_nest_cancel(skb, rxsa_list);
25713211 nla_nest_cancel(skb, rxsc_nest);
....@@ -2574,9 +3214,18 @@
25743214 }
25753215 nla_nest_end(skb, attr);
25763216
3217
+ if (secy->xpn) {
3218
+ pn = rx_sa->next_pn;
3219
+ pn_len = MACSEC_XPN_PN_LEN;
3220
+ } else {
3221
+ pn = rx_sa->next_pn_halves.lower;
3222
+ pn_len = MACSEC_DEFAULT_PN_LEN;
3223
+ }
3224
+
25773225 if (nla_put_u8(skb, MACSEC_SA_ATTR_AN, i) ||
2578
- nla_put_u32(skb, MACSEC_SA_ATTR_PN, rx_sa->next_pn) ||
3226
+ nla_put(skb, MACSEC_SA_ATTR_PN, pn_len, &pn) ||
25793227 nla_put(skb, MACSEC_SA_ATTR_KEYID, MACSEC_KEYID_LEN, rx_sa->key.id) ||
3228
+ (secy->xpn && nla_put_ssci(skb, MACSEC_SA_ATTR_SSCI, rx_sa->ssci)) ||
25803229 nla_put_u8(skb, MACSEC_SA_ATTR_ACTIVE, rx_sa->active)) {
25813230 nla_nest_cancel(skb, rxsa_nest);
25823231 nla_nest_cancel(skb, rxsc_nest);
....@@ -2638,64 +3287,70 @@
26383287 return skb->len;
26393288 }
26403289
2641
-static const struct genl_ops macsec_genl_ops[] = {
3290
+static const struct genl_small_ops macsec_genl_ops[] = {
26423291 {
26433292 .cmd = MACSEC_CMD_GET_TXSC,
3293
+ .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
26443294 .dumpit = macsec_dump_txsc,
2645
- .policy = macsec_genl_policy,
26463295 },
26473296 {
26483297 .cmd = MACSEC_CMD_ADD_RXSC,
3298
+ .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
26493299 .doit = macsec_add_rxsc,
2650
- .policy = macsec_genl_policy,
26513300 .flags = GENL_ADMIN_PERM,
26523301 },
26533302 {
26543303 .cmd = MACSEC_CMD_DEL_RXSC,
3304
+ .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
26553305 .doit = macsec_del_rxsc,
2656
- .policy = macsec_genl_policy,
26573306 .flags = GENL_ADMIN_PERM,
26583307 },
26593308 {
26603309 .cmd = MACSEC_CMD_UPD_RXSC,
3310
+ .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
26613311 .doit = macsec_upd_rxsc,
2662
- .policy = macsec_genl_policy,
26633312 .flags = GENL_ADMIN_PERM,
26643313 },
26653314 {
26663315 .cmd = MACSEC_CMD_ADD_TXSA,
3316
+ .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
26673317 .doit = macsec_add_txsa,
2668
- .policy = macsec_genl_policy,
26693318 .flags = GENL_ADMIN_PERM,
26703319 },
26713320 {
26723321 .cmd = MACSEC_CMD_DEL_TXSA,
3322
+ .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
26733323 .doit = macsec_del_txsa,
2674
- .policy = macsec_genl_policy,
26753324 .flags = GENL_ADMIN_PERM,
26763325 },
26773326 {
26783327 .cmd = MACSEC_CMD_UPD_TXSA,
3328
+ .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
26793329 .doit = macsec_upd_txsa,
2680
- .policy = macsec_genl_policy,
26813330 .flags = GENL_ADMIN_PERM,
26823331 },
26833332 {
26843333 .cmd = MACSEC_CMD_ADD_RXSA,
3334
+ .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
26853335 .doit = macsec_add_rxsa,
2686
- .policy = macsec_genl_policy,
26873336 .flags = GENL_ADMIN_PERM,
26883337 },
26893338 {
26903339 .cmd = MACSEC_CMD_DEL_RXSA,
3340
+ .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
26913341 .doit = macsec_del_rxsa,
2692
- .policy = macsec_genl_policy,
26933342 .flags = GENL_ADMIN_PERM,
26943343 },
26953344 {
26963345 .cmd = MACSEC_CMD_UPD_RXSA,
3346
+ .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
26973347 .doit = macsec_upd_rxsa,
2698
- .policy = macsec_genl_policy,
3348
+ .flags = GENL_ADMIN_PERM,
3349
+ },
3350
+ {
3351
+ .cmd = MACSEC_CMD_UPD_OFFLOAD,
3352
+ .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
3353
+ .doit = macsec_upd_offload,
26993354 .flags = GENL_ADMIN_PERM,
27003355 },
27013356 };
....@@ -2705,10 +3360,11 @@
27053360 .hdrsize = 0,
27063361 .version = MACSEC_GENL_VERSION,
27073362 .maxattr = MACSEC_ATTR_MAX,
3363
+ .policy = macsec_genl_policy,
27083364 .netnsok = true,
27093365 .module = THIS_MODULE,
2710
- .ops = macsec_genl_ops,
2711
- .n_ops = ARRAY_SIZE(macsec_genl_ops),
3366
+ .small_ops = macsec_genl_ops,
3367
+ .n_small_ops = ARRAY_SIZE(macsec_genl_ops),
27123368 };
27133369
27143370 static netdev_tx_t macsec_start_xmit(struct sk_buff *skb,
....@@ -2718,6 +3374,11 @@
27183374 struct macsec_secy *secy = &macsec->secy;
27193375 struct pcpu_secy_stats *secy_stats;
27203376 int ret, len;
3377
+
3378
+ if (macsec_is_offloaded(netdev_priv(dev))) {
3379
+ skb->dev = macsec->real_dev;
3380
+ return dev_queue_xmit(skb);
3381
+ }
27213382
27223383 /* 10.5 */
27233384 if (!secy->protect_frames) {
....@@ -2756,7 +3417,6 @@
27563417
27573418 #define MACSEC_FEATURES \
27583419 (NETIF_F_SG | NETIF_F_HIGHDMA | NETIF_F_FRAGLIST)
2759
-static struct lock_class_key macsec_netdev_addr_lock_key;
27603420
27613421 static int macsec_dev_init(struct net_device *dev)
27623422 {
....@@ -2833,6 +3493,23 @@
28333493 goto clear_allmulti;
28343494 }
28353495
3496
+ /* If h/w offloading is available, propagate to the device */
3497
+ if (macsec_is_offloaded(macsec)) {
3498
+ const struct macsec_ops *ops;
3499
+ struct macsec_context ctx;
3500
+
3501
+ ops = macsec_get_ops(netdev_priv(dev), &ctx);
3502
+ if (!ops) {
3503
+ err = -EOPNOTSUPP;
3504
+ goto clear_allmulti;
3505
+ }
3506
+
3507
+ ctx.secy = &macsec->secy;
3508
+ err = macsec_offload(ops->mdo_dev_open, &ctx);
3509
+ if (err)
3510
+ goto clear_allmulti;
3511
+ }
3512
+
28363513 if (netif_carrier_ok(real_dev))
28373514 netif_carrier_on(dev);
28383515
....@@ -2852,6 +3529,18 @@
28523529 struct net_device *real_dev = macsec->real_dev;
28533530
28543531 netif_carrier_off(dev);
3532
+
3533
+ /* If h/w offloading is available, propagate to the device */
3534
+ if (macsec_is_offloaded(macsec)) {
3535
+ const struct macsec_ops *ops;
3536
+ struct macsec_context ctx;
3537
+
3538
+ ops = macsec_get_ops(macsec, &ctx);
3539
+ if (ops) {
3540
+ ctx.secy = &macsec->secy;
3541
+ macsec_offload(ops->mdo_dev_stop, &ctx);
3542
+ }
3543
+ }
28553544
28563545 dev_mc_unsync(real_dev, dev);
28573546 dev_uc_unsync(real_dev, dev);
....@@ -2890,11 +3579,6 @@
28903579 dev_uc_sync(real_dev, dev);
28913580 }
28923581
2893
-static sci_t dev_to_sci(struct net_device *dev, __be16 port)
2894
-{
2895
- return make_sci(dev->dev_addr, port);
2896
-}
2897
-
28983582 static int macsec_set_mac_address(struct net_device *dev, void *p)
28993583 {
29003584 struct macsec_dev *macsec = macsec_priv(dev);
....@@ -2917,6 +3601,19 @@
29173601 out:
29183602 ether_addr_copy(dev->dev_addr, addr->sa_data);
29193603 macsec->secy.sci = dev_to_sci(dev, MACSEC_PORT_ES);
3604
+
3605
+ /* If h/w offloading is available, propagate to the device */
3606
+ if (macsec_is_offloaded(macsec)) {
3607
+ const struct macsec_ops *ops;
3608
+ struct macsec_context ctx;
3609
+
3610
+ ops = macsec_get_ops(macsec, &ctx);
3611
+ if (ops) {
3612
+ ctx.secy = &macsec->secy;
3613
+ macsec_offload(ops->mdo_upd_secy, &ctx);
3614
+ }
3615
+ }
3616
+
29203617 return 0;
29213618 }
29223619
....@@ -2936,30 +3633,10 @@
29363633 static void macsec_get_stats64(struct net_device *dev,
29373634 struct rtnl_link_stats64 *s)
29383635 {
2939
- int cpu;
2940
-
29413636 if (!dev->tstats)
29423637 return;
29433638
2944
- for_each_possible_cpu(cpu) {
2945
- struct pcpu_sw_netstats *stats;
2946
- struct pcpu_sw_netstats tmp;
2947
- int start;
2948
-
2949
- stats = per_cpu_ptr(dev->tstats, cpu);
2950
- do {
2951
- start = u64_stats_fetch_begin_irq(&stats->syncp);
2952
- tmp.rx_packets = stats->rx_packets;
2953
- tmp.rx_bytes = stats->rx_bytes;
2954
- tmp.tx_packets = stats->tx_packets;
2955
- tmp.tx_bytes = stats->tx_bytes;
2956
- } while (u64_stats_fetch_retry_irq(&stats->syncp, start));
2957
-
2958
- s->rx_packets += tmp.rx_packets;
2959
- s->rx_bytes += tmp.rx_bytes;
2960
- s->tx_packets += tmp.tx_packets;
2961
- s->tx_bytes += tmp.tx_bytes;
2962
- }
3639
+ dev_fetch_sw_netstats(s, dev->tstats);
29633640
29643641 s->rx_dropped = dev->stats.rx_dropped;
29653642 s->tx_dropped = dev->stats.tx_dropped;
....@@ -2969,13 +3646,6 @@
29693646 {
29703647 return macsec_priv(dev)->real_dev->ifindex;
29713648 }
2972
-
2973
-
2974
-static int macsec_get_nest_level(struct net_device *dev)
2975
-{
2976
- return macsec_priv(dev)->nest_level;
2977
-}
2978
-
29793649
29803650 static const struct net_device_ops macsec_netdev_ops = {
29813651 .ndo_init = macsec_dev_init,
....@@ -2990,7 +3660,6 @@
29903660 .ndo_start_xmit = macsec_start_xmit,
29913661 .ndo_get_stats64 = macsec_get_stats64,
29923662 .ndo_get_iflink = macsec_get_iflink,
2993
- .ndo_get_lock_subclass = macsec_get_nest_level,
29943663 };
29953664
29963665 static const struct device_type macsec_type = {
....@@ -3011,6 +3680,7 @@
30113680 [IFLA_MACSEC_SCB] = { .type = NLA_U8 },
30123681 [IFLA_MACSEC_REPLAY_PROTECT] = { .type = NLA_U8 },
30133682 [IFLA_MACSEC_VALIDATION] = { .type = NLA_U8 },
3683
+ [IFLA_MACSEC_OFFLOAD] = { .type = NLA_U8 },
30143684 };
30153685
30163686 static void macsec_free_netdev(struct net_device *dev)
....@@ -3054,9 +3724,6 @@
30543724 secy->operational = tx_sa && tx_sa->active;
30553725 }
30563726
3057
- if (data[IFLA_MACSEC_WINDOW])
3058
- secy->replay_window = nla_get_u32(data[IFLA_MACSEC_WINDOW]);
3059
-
30603727 if (data[IFLA_MACSEC_ENCRYPT])
30613728 tx_sc->encrypt = !!nla_get_u8(data[IFLA_MACSEC_ENCRYPT]);
30623729
....@@ -3083,13 +3750,33 @@
30833750 case MACSEC_CIPHER_ID_GCM_AES_128:
30843751 case MACSEC_DEFAULT_CIPHER_ID:
30853752 secy->key_len = MACSEC_GCM_AES_128_SAK_LEN;
3753
+ secy->xpn = false;
30863754 break;
30873755 case MACSEC_CIPHER_ID_GCM_AES_256:
30883756 secy->key_len = MACSEC_GCM_AES_256_SAK_LEN;
3757
+ secy->xpn = false;
3758
+ break;
3759
+ case MACSEC_CIPHER_ID_GCM_AES_XPN_128:
3760
+ secy->key_len = MACSEC_GCM_AES_128_SAK_LEN;
3761
+ secy->xpn = true;
3762
+ break;
3763
+ case MACSEC_CIPHER_ID_GCM_AES_XPN_256:
3764
+ secy->key_len = MACSEC_GCM_AES_256_SAK_LEN;
3765
+ secy->xpn = true;
30893766 break;
30903767 default:
30913768 return -EINVAL;
30923769 }
3770
+ }
3771
+
3772
+ if (data[IFLA_MACSEC_WINDOW]) {
3773
+ secy->replay_window = nla_get_u32(data[IFLA_MACSEC_WINDOW]);
3774
+
3775
+ /* IEEE 802.1AEbw-2013 10.7.8 - maximum replay window
3776
+ * for XPN cipher suites */
3777
+ if (secy->xpn &&
3778
+ secy->replay_window > MACSEC_XPN_MAX_REPLAY_WINDOW)
3779
+ return -EINVAL;
30933780 }
30943781
30953782 return 0;
....@@ -3099,6 +3786,11 @@
30993786 struct nlattr *data[],
31003787 struct netlink_ext_ack *extack)
31013788 {
3789
+ struct macsec_dev *macsec = macsec_priv(dev);
3790
+ struct macsec_tx_sc tx_sc;
3791
+ struct macsec_secy secy;
3792
+ int ret;
3793
+
31023794 if (!data)
31033795 return 0;
31043796
....@@ -3108,7 +3800,40 @@
31083800 data[IFLA_MACSEC_PORT])
31093801 return -EINVAL;
31103802
3111
- return macsec_changelink_common(dev, data);
3803
+ /* Keep a copy of unmodified secy and tx_sc, in case the offload
3804
+ * propagation fails, to revert macsec_changelink_common.
3805
+ */
3806
+ memcpy(&secy, &macsec->secy, sizeof(secy));
3807
+ memcpy(&tx_sc, &macsec->secy.tx_sc, sizeof(tx_sc));
3808
+
3809
+ ret = macsec_changelink_common(dev, data);
3810
+ if (ret)
3811
+ goto cleanup;
3812
+
3813
+ /* If h/w offloading is available, propagate to the device */
3814
+ if (macsec_is_offloaded(macsec)) {
3815
+ const struct macsec_ops *ops;
3816
+ struct macsec_context ctx;
3817
+
3818
+ ops = macsec_get_ops(netdev_priv(dev), &ctx);
3819
+ if (!ops) {
3820
+ ret = -EOPNOTSUPP;
3821
+ goto cleanup;
3822
+ }
3823
+
3824
+ ctx.secy = &macsec->secy;
3825
+ ret = macsec_offload(ops->mdo_upd_secy, &ctx);
3826
+ if (ret)
3827
+ goto cleanup;
3828
+ }
3829
+
3830
+ return 0;
3831
+
3832
+cleanup:
3833
+ memcpy(&macsec->secy.tx_sc, &tx_sc, sizeof(tx_sc));
3834
+ memcpy(&macsec->secy, &secy, sizeof(secy));
3835
+
3836
+ return ret;
31123837 }
31133838
31143839 static void macsec_del_dev(struct macsec_dev *macsec)
....@@ -3136,6 +3861,18 @@
31363861 {
31373862 struct macsec_dev *macsec = macsec_priv(dev);
31383863 struct net_device *real_dev = macsec->real_dev;
3864
+
3865
+ /* If h/w offloading is available, propagate to the device */
3866
+ if (macsec_is_offloaded(macsec)) {
3867
+ const struct macsec_ops *ops;
3868
+ struct macsec_context ctx;
3869
+
3870
+ ops = macsec_get_ops(netdev_priv(dev), &ctx);
3871
+ if (ops) {
3872
+ ctx.secy = &macsec->secy;
3873
+ macsec_offload(ops->mdo_del_secy, &ctx);
3874
+ }
3875
+ }
31393876
31403877 unregister_netdevice_queue(dev, head);
31413878 list_del_rcu(&macsec->secys);
....@@ -3224,6 +3961,7 @@
32243961 secy->validate_frames = MACSEC_VALIDATE_DEFAULT;
32253962 secy->protect_frames = true;
32263963 secy->replay_protect = false;
3964
+ secy->xpn = DEFAULT_XPN;
32273965
32283966 secy->sci = sci;
32293967 secy->tx_sc.active = true;
....@@ -3235,6 +3973,8 @@
32353973
32363974 return 0;
32373975 }
3976
+
3977
+static struct lock_class_key macsec_netdev_addr_lock_key;
32383978
32393979 static int macsec_newlink(struct net *net, struct net_device *dev,
32403980 struct nlattr *tb[], struct nlattr *data[],
....@@ -3258,6 +3998,17 @@
32583998 dev->priv_flags |= IFF_MACSEC;
32593999
32604000 macsec->real_dev = real_dev;
4001
+
4002
+ if (data && data[IFLA_MACSEC_OFFLOAD])
4003
+ macsec->offload = nla_get_offload(data[IFLA_MACSEC_OFFLOAD]);
4004
+ else
4005
+ /* MACsec offloading is off by default */
4006
+ macsec->offload = MACSEC_OFFLOAD_OFF;
4007
+
4008
+ /* Check if the offloading mode is supported by the underlying layers */
4009
+ if (macsec->offload != MACSEC_OFFLOAD_OFF &&
4010
+ !macsec_check_offload(macsec->offload, macsec))
4011
+ return -EOPNOTSUPP;
32614012
32624013 /* send_sci must be set to true when transmit sci explicitly is set */
32634014 if ((data && data[IFLA_MACSEC_SCI]) &&
....@@ -3284,11 +4035,9 @@
32844035 if (err < 0)
32854036 return err;
32864037
3287
- macsec->nest_level = dev_get_nest_level(real_dev) + 1;
32884038 netdev_lockdep_set_classes(dev);
3289
- lockdep_set_class_and_subclass(&dev->addr_list_lock,
3290
- &macsec_netdev_addr_lock_key,
3291
- macsec_get_nest_level(dev));
4039
+ lockdep_set_class(&dev->addr_list_lock,
4040
+ &macsec_netdev_addr_lock_key);
32924041
32934042 err = netdev_upper_dev_link(real_dev, dev, extack);
32944043 if (err < 0)
....@@ -3317,6 +4066,20 @@
33174066 err = macsec_changelink_common(dev, data);
33184067 if (err)
33194068 goto del_dev;
4069
+ }
4070
+
4071
+ /* If h/w offloading is available, propagate to the device */
4072
+ if (macsec_is_offloaded(macsec)) {
4073
+ const struct macsec_ops *ops;
4074
+ struct macsec_context ctx;
4075
+
4076
+ ops = macsec_get_ops(macsec, &ctx);
4077
+ if (ops) {
4078
+ ctx.secy = &macsec->secy;
4079
+ err = macsec_offload(ops->mdo_add_secy, &ctx);
4080
+ if (err)
4081
+ goto del_dev;
4082
+ }
33204083 }
33214084
33224085 err = register_macsec_dev(real_dev, dev);
....@@ -3371,6 +4134,8 @@
33714134 switch (csid) {
33724135 case MACSEC_CIPHER_ID_GCM_AES_128:
33734136 case MACSEC_CIPHER_ID_GCM_AES_256:
4137
+ case MACSEC_CIPHER_ID_GCM_AES_XPN_128:
4138
+ case MACSEC_CIPHER_ID_GCM_AES_XPN_256:
33744139 case MACSEC_DEFAULT_CIPHER_ID:
33754140 if (icv_len < MACSEC_MIN_ICV_LEN ||
33764141 icv_len > MACSEC_STD_ICV_LEN)
....@@ -3444,10 +4209,10 @@
34444209
34454210 switch (secy->key_len) {
34464211 case MACSEC_GCM_AES_128_SAK_LEN:
3447
- csid = MACSEC_DEFAULT_CIPHER_ID;
4212
+ csid = secy->xpn ? MACSEC_CIPHER_ID_GCM_AES_XPN_128 : MACSEC_DEFAULT_CIPHER_ID;
34484213 break;
34494214 case MACSEC_GCM_AES_256_SAK_LEN:
3450
- csid = MACSEC_CIPHER_ID_GCM_AES_256;
4215
+ csid = secy->xpn ? MACSEC_CIPHER_ID_GCM_AES_XPN_256 : MACSEC_CIPHER_ID_GCM_AES_256;
34514216 break;
34524217 default:
34534218 goto nla_put_failure;