hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
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:
....@@ -1315,8 +1308,7 @@
13151308 struct crypto_aead *tfm;
13161309 int ret;
13171310
1318
- /* Pick a sync gcm(aes) cipher to ensure order is preserved. */
1319
- tfm = crypto_alloc_aead("gcm(aes)", 0, CRYPTO_ALG_ASYNC);
1311
+ tfm = crypto_alloc_aead("gcm(aes)", 0, 0);
13201312
13211313 if (IS_ERR(tfm))
13221314 return tfm;
....@@ -1348,6 +1340,7 @@
13481340 return PTR_ERR(rx_sa->key.tfm);
13491341 }
13501342
1343
+ rx_sa->ssci = MACSEC_UNDEF_SSCI;
13511344 rx_sa->active = false;
13521345 rx_sa->next_pn = 1;
13531346 refcount_set(&rx_sa->refcnt, 1);
....@@ -1396,7 +1389,8 @@
13961389 return NULL;
13971390 }
13981391
1399
-static struct macsec_rx_sc *create_rx_sc(struct net_device *dev, sci_t sci)
1392
+static struct macsec_rx_sc *create_rx_sc(struct net_device *dev, sci_t sci,
1393
+ bool active)
14001394 {
14011395 struct macsec_rx_sc *rx_sc;
14021396 struct macsec_dev *macsec;
....@@ -1420,7 +1414,7 @@
14201414 }
14211415
14221416 rx_sc->sci = sci;
1423
- rx_sc->active = true;
1417
+ rx_sc->active = active;
14241418 refcount_set(&rx_sc->refcnt, 1);
14251419
14261420 secy = &macsec_priv(dev)->secy;
....@@ -1446,6 +1440,7 @@
14461440 return PTR_ERR(tx_sa->key.tfm);
14471441 }
14481442
1443
+ tx_sa->ssci = MACSEC_UNDEF_SSCI;
14491444 tx_sa->active = false;
14501445 refcount_set(&tx_sa->refcnt, 1);
14511446 spin_lock_init(&tx_sa->lock);
....@@ -1478,6 +1473,11 @@
14781473 return dev;
14791474 }
14801475
1476
+static enum macsec_offload nla_get_offload(const struct nlattr *nla)
1477
+{
1478
+ return (__force enum macsec_offload)nla_get_u8(nla);
1479
+}
1480
+
14811481 static sci_t nla_get_sci(const struct nlattr *nla)
14821482 {
14831483 return (__force sci_t)nla_get_u64(nla);
....@@ -1487,6 +1487,16 @@
14871487 int padattr)
14881488 {
14891489 return nla_put_u64_64bit(skb, attrtype, (__force u64)value, padattr);
1490
+}
1491
+
1492
+static ssci_t nla_get_ssci(const struct nlattr *nla)
1493
+{
1494
+ return (__force ssci_t)nla_get_u32(nla);
1495
+}
1496
+
1497
+static int nla_put_ssci(struct sk_buff *skb, int attrtype, ssci_t value)
1498
+{
1499
+ return nla_put_u32(skb, attrtype, (__force u64)value);
14901500 }
14911501
14921502 static struct macsec_tx_sa *get_txsa_from_nl(struct net *net,
....@@ -1589,11 +1599,11 @@
15891599 return rx_sa;
15901600 }
15911601
1592
-
15931602 static const struct nla_policy macsec_genl_policy[NUM_MACSEC_ATTR] = {
15941603 [MACSEC_ATTR_IFINDEX] = { .type = NLA_U32 },
15951604 [MACSEC_ATTR_RXSC_CONFIG] = { .type = NLA_NESTED },
15961605 [MACSEC_ATTR_SA_CONFIG] = { .type = NLA_NESTED },
1606
+ [MACSEC_ATTR_OFFLOAD] = { .type = NLA_NESTED },
15971607 };
15981608
15991609 static const struct nla_policy macsec_genl_rxsc_policy[NUM_MACSEC_RXSC_ATTR] = {
....@@ -1604,21 +1614,60 @@
16041614 static const struct nla_policy macsec_genl_sa_policy[NUM_MACSEC_SA_ATTR] = {
16051615 [MACSEC_SA_ATTR_AN] = { .type = NLA_U8 },
16061616 [MACSEC_SA_ATTR_ACTIVE] = { .type = NLA_U8 },
1607
- [MACSEC_SA_ATTR_PN] = { .type = NLA_U32 },
1617
+ [MACSEC_SA_ATTR_PN] = NLA_POLICY_MIN_LEN(4),
16081618 [MACSEC_SA_ATTR_KEYID] = { .type = NLA_BINARY,
16091619 .len = MACSEC_KEYID_LEN, },
16101620 [MACSEC_SA_ATTR_KEY] = { .type = NLA_BINARY,
16111621 .len = MACSEC_MAX_KEY_LEN, },
1622
+ [MACSEC_SA_ATTR_SSCI] = { .type = NLA_U32 },
1623
+ [MACSEC_SA_ATTR_SALT] = { .type = NLA_BINARY,
1624
+ .len = MACSEC_SALT_LEN, },
16121625 };
1626
+
1627
+static const struct nla_policy macsec_genl_offload_policy[NUM_MACSEC_OFFLOAD_ATTR] = {
1628
+ [MACSEC_OFFLOAD_ATTR_TYPE] = { .type = NLA_U8 },
1629
+};
1630
+
1631
+/* Offloads an operation to a device driver */
1632
+static int macsec_offload(int (* const func)(struct macsec_context *),
1633
+ struct macsec_context *ctx)
1634
+{
1635
+ int ret;
1636
+
1637
+ if (unlikely(!func))
1638
+ return 0;
1639
+
1640
+ if (ctx->offload == MACSEC_OFFLOAD_PHY)
1641
+ mutex_lock(&ctx->phydev->lock);
1642
+
1643
+ /* Phase I: prepare. The drive should fail here if there are going to be
1644
+ * issues in the commit phase.
1645
+ */
1646
+ ctx->prepare = true;
1647
+ ret = (*func)(ctx);
1648
+ if (ret)
1649
+ goto phy_unlock;
1650
+
1651
+ /* Phase II: commit. This step cannot fail. */
1652
+ ctx->prepare = false;
1653
+ ret = (*func)(ctx);
1654
+ /* This should never happen: commit is not allowed to fail */
1655
+ if (unlikely(ret))
1656
+ WARN(1, "MACsec offloading commit failed (%d)\n", ret);
1657
+
1658
+phy_unlock:
1659
+ if (ctx->offload == MACSEC_OFFLOAD_PHY)
1660
+ mutex_unlock(&ctx->phydev->lock);
1661
+
1662
+ return ret;
1663
+}
16131664
16141665 static int parse_sa_config(struct nlattr **attrs, struct nlattr **tb_sa)
16151666 {
16161667 if (!attrs[MACSEC_ATTR_SA_CONFIG])
16171668 return -EINVAL;
16181669
1619
- if (nla_parse_nested(tb_sa, MACSEC_SA_ATTR_MAX,
1620
- attrs[MACSEC_ATTR_SA_CONFIG],
1621
- macsec_genl_sa_policy, NULL))
1670
+ if (nla_parse_nested_deprecated(tb_sa, MACSEC_SA_ATTR_MAX, attrs[MACSEC_ATTR_SA_CONFIG], macsec_genl_sa_policy, NULL))
16221671 return -EINVAL;
16231672
16241673 return 0;
....@@ -1629,9 +1678,7 @@
16291678 if (!attrs[MACSEC_ATTR_RXSC_CONFIG])
16301679 return -EINVAL;
16311680
1632
- if (nla_parse_nested(tb_rxsc, MACSEC_RXSC_ATTR_MAX,
1633
- attrs[MACSEC_ATTR_RXSC_CONFIG],
1634
- macsec_genl_rxsc_policy, NULL))
1681
+ if (nla_parse_nested_deprecated(tb_rxsc, MACSEC_RXSC_ATTR_MAX, attrs[MACSEC_ATTR_RXSC_CONFIG], macsec_genl_rxsc_policy, NULL))
16351682 return -EINVAL;
16361683
16371684 return 0;
....@@ -1647,7 +1694,8 @@
16471694 if (nla_get_u8(attrs[MACSEC_SA_ATTR_AN]) >= MACSEC_NUM_AN)
16481695 return false;
16491696
1650
- if (attrs[MACSEC_SA_ATTR_PN] && nla_get_u32(attrs[MACSEC_SA_ATTR_PN]) == 0)
1697
+ if (attrs[MACSEC_SA_ATTR_PN] &&
1698
+ nla_get_u64(attrs[MACSEC_SA_ATTR_PN]) == 0)
16511699 return false;
16521700
16531701 if (attrs[MACSEC_SA_ATTR_ACTIVE]) {
....@@ -1669,6 +1717,7 @@
16691717 struct macsec_rx_sc *rx_sc;
16701718 struct macsec_rx_sa *rx_sa;
16711719 unsigned char assoc_num;
1720
+ int pn_len;
16721721 struct nlattr *tb_rxsc[MACSEC_RXSC_ATTR_MAX + 1];
16731722 struct nlattr *tb_sa[MACSEC_SA_ATTR_MAX + 1];
16741723 int err;
....@@ -1701,6 +1750,30 @@
17011750 return -EINVAL;
17021751 }
17031752
1753
+ pn_len = secy->xpn ? MACSEC_XPN_PN_LEN : MACSEC_DEFAULT_PN_LEN;
1754
+ if (tb_sa[MACSEC_SA_ATTR_PN] &&
1755
+ nla_len(tb_sa[MACSEC_SA_ATTR_PN]) != pn_len) {
1756
+ pr_notice("macsec: nl: add_rxsa: bad pn length: %d != %d\n",
1757
+ nla_len(tb_sa[MACSEC_SA_ATTR_PN]), pn_len);
1758
+ rtnl_unlock();
1759
+ return -EINVAL;
1760
+ }
1761
+
1762
+ if (secy->xpn) {
1763
+ if (!tb_sa[MACSEC_SA_ATTR_SSCI] || !tb_sa[MACSEC_SA_ATTR_SALT]) {
1764
+ rtnl_unlock();
1765
+ return -EINVAL;
1766
+ }
1767
+
1768
+ if (nla_len(tb_sa[MACSEC_SA_ATTR_SALT]) != MACSEC_SALT_LEN) {
1769
+ pr_notice("macsec: nl: add_rxsa: bad salt length: %d != %d\n",
1770
+ nla_len(tb_sa[MACSEC_SA_ATTR_SALT]),
1771
+ MACSEC_SALT_LEN);
1772
+ rtnl_unlock();
1773
+ return -EINVAL;
1774
+ }
1775
+ }
1776
+
17041777 rx_sa = rtnl_dereference(rx_sc->sa[assoc_num]);
17051778 if (rx_sa) {
17061779 rtnl_unlock();
....@@ -1723,20 +1796,55 @@
17231796
17241797 if (tb_sa[MACSEC_SA_ATTR_PN]) {
17251798 spin_lock_bh(&rx_sa->lock);
1726
- rx_sa->next_pn = nla_get_u32(tb_sa[MACSEC_SA_ATTR_PN]);
1799
+ rx_sa->next_pn = nla_get_u64(tb_sa[MACSEC_SA_ATTR_PN]);
17271800 spin_unlock_bh(&rx_sa->lock);
17281801 }
17291802
17301803 if (tb_sa[MACSEC_SA_ATTR_ACTIVE])
17311804 rx_sa->active = !!nla_get_u8(tb_sa[MACSEC_SA_ATTR_ACTIVE]);
17321805
1733
- nla_memcpy(rx_sa->key.id, tb_sa[MACSEC_SA_ATTR_KEYID], MACSEC_KEYID_LEN);
17341806 rx_sa->sc = rx_sc;
1807
+
1808
+ /* If h/w offloading is available, propagate to the device */
1809
+ if (macsec_is_offloaded(netdev_priv(dev))) {
1810
+ const struct macsec_ops *ops;
1811
+ struct macsec_context ctx;
1812
+
1813
+ ops = macsec_get_ops(netdev_priv(dev), &ctx);
1814
+ if (!ops) {
1815
+ err = -EOPNOTSUPP;
1816
+ goto cleanup;
1817
+ }
1818
+
1819
+ ctx.sa.assoc_num = assoc_num;
1820
+ ctx.sa.rx_sa = rx_sa;
1821
+ ctx.secy = secy;
1822
+ memcpy(ctx.sa.key, nla_data(tb_sa[MACSEC_SA_ATTR_KEY]),
1823
+ secy->key_len);
1824
+
1825
+ err = macsec_offload(ops->mdo_add_rxsa, &ctx);
1826
+ memzero_explicit(ctx.sa.key, secy->key_len);
1827
+ if (err)
1828
+ goto cleanup;
1829
+ }
1830
+
1831
+ if (secy->xpn) {
1832
+ rx_sa->ssci = nla_get_ssci(tb_sa[MACSEC_SA_ATTR_SSCI]);
1833
+ nla_memcpy(rx_sa->key.salt.bytes, tb_sa[MACSEC_SA_ATTR_SALT],
1834
+ MACSEC_SALT_LEN);
1835
+ }
1836
+
1837
+ nla_memcpy(rx_sa->key.id, tb_sa[MACSEC_SA_ATTR_KEYID], MACSEC_KEYID_LEN);
17351838 rcu_assign_pointer(rx_sc->sa[assoc_num], rx_sa);
17361839
17371840 rtnl_unlock();
17381841
17391842 return 0;
1843
+
1844
+cleanup:
1845
+ macsec_rxsa_put(rx_sa);
1846
+ rtnl_unlock();
1847
+ return err;
17401848 }
17411849
17421850 static bool validate_add_rxsc(struct nlattr **attrs)
....@@ -1759,6 +1867,9 @@
17591867 struct nlattr **attrs = info->attrs;
17601868 struct macsec_rx_sc *rx_sc;
17611869 struct nlattr *tb_rxsc[MACSEC_RXSC_ATTR_MAX + 1];
1870
+ struct macsec_secy *secy;
1871
+ bool active = true;
1872
+ int ret;
17621873
17631874 if (!attrs[MACSEC_ATTR_IFINDEX])
17641875 return -EINVAL;
....@@ -1776,20 +1887,45 @@
17761887 return PTR_ERR(dev);
17771888 }
17781889
1890
+ secy = &macsec_priv(dev)->secy;
17791891 sci = nla_get_sci(tb_rxsc[MACSEC_RXSC_ATTR_SCI]);
17801892
1781
- rx_sc = create_rx_sc(dev, sci);
1893
+ if (tb_rxsc[MACSEC_RXSC_ATTR_ACTIVE])
1894
+ active = nla_get_u8(tb_rxsc[MACSEC_RXSC_ATTR_ACTIVE]);
1895
+
1896
+ rx_sc = create_rx_sc(dev, sci, active);
17821897 if (IS_ERR(rx_sc)) {
17831898 rtnl_unlock();
17841899 return PTR_ERR(rx_sc);
17851900 }
17861901
1787
- if (tb_rxsc[MACSEC_RXSC_ATTR_ACTIVE])
1788
- rx_sc->active = !!nla_get_u8(tb_rxsc[MACSEC_RXSC_ATTR_ACTIVE]);
1902
+ if (macsec_is_offloaded(netdev_priv(dev))) {
1903
+ const struct macsec_ops *ops;
1904
+ struct macsec_context ctx;
1905
+
1906
+ ops = macsec_get_ops(netdev_priv(dev), &ctx);
1907
+ if (!ops) {
1908
+ ret = -EOPNOTSUPP;
1909
+ goto cleanup;
1910
+ }
1911
+
1912
+ ctx.rx_sc = rx_sc;
1913
+ ctx.secy = secy;
1914
+
1915
+ ret = macsec_offload(ops->mdo_add_rxsc, &ctx);
1916
+ if (ret)
1917
+ goto cleanup;
1918
+ }
17891919
17901920 rtnl_unlock();
17911921
17921922 return 0;
1923
+
1924
+cleanup:
1925
+ del_rx_sc(secy, sci);
1926
+ free_rx_sc(rx_sc);
1927
+ rtnl_unlock();
1928
+ return ret;
17931929 }
17941930
17951931 static bool validate_add_txsa(struct nlattr **attrs)
....@@ -1803,7 +1939,7 @@
18031939 if (nla_get_u8(attrs[MACSEC_SA_ATTR_AN]) >= MACSEC_NUM_AN)
18041940 return false;
18051941
1806
- if (nla_get_u32(attrs[MACSEC_SA_ATTR_PN]) == 0)
1942
+ if (nla_get_u64(attrs[MACSEC_SA_ATTR_PN]) == 0)
18071943 return false;
18081944
18091945 if (attrs[MACSEC_SA_ATTR_ACTIVE]) {
....@@ -1825,7 +1961,9 @@
18251961 struct macsec_tx_sc *tx_sc;
18261962 struct macsec_tx_sa *tx_sa;
18271963 unsigned char assoc_num;
1964
+ int pn_len;
18281965 struct nlattr *tb_sa[MACSEC_SA_ATTR_MAX + 1];
1966
+ bool was_operational;
18291967 int err;
18301968
18311969 if (!attrs[MACSEC_ATTR_IFINDEX])
....@@ -1856,6 +1994,29 @@
18561994 return -EINVAL;
18571995 }
18581996
1997
+ pn_len = secy->xpn ? MACSEC_XPN_PN_LEN : MACSEC_DEFAULT_PN_LEN;
1998
+ if (nla_len(tb_sa[MACSEC_SA_ATTR_PN]) != pn_len) {
1999
+ pr_notice("macsec: nl: add_txsa: bad pn length: %d != %d\n",
2000
+ nla_len(tb_sa[MACSEC_SA_ATTR_PN]), pn_len);
2001
+ rtnl_unlock();
2002
+ return -EINVAL;
2003
+ }
2004
+
2005
+ if (secy->xpn) {
2006
+ if (!tb_sa[MACSEC_SA_ATTR_SSCI] || !tb_sa[MACSEC_SA_ATTR_SALT]) {
2007
+ rtnl_unlock();
2008
+ return -EINVAL;
2009
+ }
2010
+
2011
+ if (nla_len(tb_sa[MACSEC_SA_ATTR_SALT]) != MACSEC_SALT_LEN) {
2012
+ pr_notice("macsec: nl: add_txsa: bad salt length: %d != %d\n",
2013
+ nla_len(tb_sa[MACSEC_SA_ATTR_SALT]),
2014
+ MACSEC_SALT_LEN);
2015
+ rtnl_unlock();
2016
+ return -EINVAL;
2017
+ }
2018
+ }
2019
+
18592020 tx_sa = rtnl_dereference(tx_sc->sa[assoc_num]);
18602021 if (tx_sa) {
18612022 rtnl_unlock();
....@@ -1876,23 +2037,58 @@
18762037 return err;
18772038 }
18782039
1879
- nla_memcpy(tx_sa->key.id, tb_sa[MACSEC_SA_ATTR_KEYID], MACSEC_KEYID_LEN);
1880
-
18812040 spin_lock_bh(&tx_sa->lock);
1882
- tx_sa->next_pn = nla_get_u32(tb_sa[MACSEC_SA_ATTR_PN]);
2041
+ tx_sa->next_pn = nla_get_u64(tb_sa[MACSEC_SA_ATTR_PN]);
18832042 spin_unlock_bh(&tx_sa->lock);
18842043
18852044 if (tb_sa[MACSEC_SA_ATTR_ACTIVE])
18862045 tx_sa->active = !!nla_get_u8(tb_sa[MACSEC_SA_ATTR_ACTIVE]);
18872046
2047
+ was_operational = secy->operational;
18882048 if (assoc_num == tx_sc->encoding_sa && tx_sa->active)
18892049 secy->operational = true;
18902050
2051
+ /* If h/w offloading is available, propagate to the device */
2052
+ if (macsec_is_offloaded(netdev_priv(dev))) {
2053
+ const struct macsec_ops *ops;
2054
+ struct macsec_context ctx;
2055
+
2056
+ ops = macsec_get_ops(netdev_priv(dev), &ctx);
2057
+ if (!ops) {
2058
+ err = -EOPNOTSUPP;
2059
+ goto cleanup;
2060
+ }
2061
+
2062
+ ctx.sa.assoc_num = assoc_num;
2063
+ ctx.sa.tx_sa = tx_sa;
2064
+ ctx.secy = secy;
2065
+ memcpy(ctx.sa.key, nla_data(tb_sa[MACSEC_SA_ATTR_KEY]),
2066
+ secy->key_len);
2067
+
2068
+ err = macsec_offload(ops->mdo_add_txsa, &ctx);
2069
+ memzero_explicit(ctx.sa.key, secy->key_len);
2070
+ if (err)
2071
+ goto cleanup;
2072
+ }
2073
+
2074
+ if (secy->xpn) {
2075
+ tx_sa->ssci = nla_get_ssci(tb_sa[MACSEC_SA_ATTR_SSCI]);
2076
+ nla_memcpy(tx_sa->key.salt.bytes, tb_sa[MACSEC_SA_ATTR_SALT],
2077
+ MACSEC_SALT_LEN);
2078
+ }
2079
+
2080
+ nla_memcpy(tx_sa->key.id, tb_sa[MACSEC_SA_ATTR_KEYID], MACSEC_KEYID_LEN);
18912081 rcu_assign_pointer(tx_sc->sa[assoc_num], tx_sa);
18922082
18932083 rtnl_unlock();
18942084
18952085 return 0;
2086
+
2087
+cleanup:
2088
+ secy->operational = was_operational;
2089
+ macsec_txsa_put(tx_sa);
2090
+ rtnl_unlock();
2091
+ return err;
18962092 }
18972093
18982094 static int macsec_del_rxsa(struct sk_buff *skb, struct genl_info *info)
....@@ -1905,6 +2101,7 @@
19052101 u8 assoc_num;
19062102 struct nlattr *tb_rxsc[MACSEC_RXSC_ATTR_MAX + 1];
19072103 struct nlattr *tb_sa[MACSEC_SA_ATTR_MAX + 1];
2104
+ int ret;
19082105
19092106 if (!attrs[MACSEC_ATTR_IFINDEX])
19102107 return -EINVAL;
....@@ -1928,12 +2125,36 @@
19282125 return -EBUSY;
19292126 }
19302127
2128
+ /* If h/w offloading is available, propagate to the device */
2129
+ if (macsec_is_offloaded(netdev_priv(dev))) {
2130
+ const struct macsec_ops *ops;
2131
+ struct macsec_context ctx;
2132
+
2133
+ ops = macsec_get_ops(netdev_priv(dev), &ctx);
2134
+ if (!ops) {
2135
+ ret = -EOPNOTSUPP;
2136
+ goto cleanup;
2137
+ }
2138
+
2139
+ ctx.sa.assoc_num = assoc_num;
2140
+ ctx.sa.rx_sa = rx_sa;
2141
+ ctx.secy = secy;
2142
+
2143
+ ret = macsec_offload(ops->mdo_del_rxsa, &ctx);
2144
+ if (ret)
2145
+ goto cleanup;
2146
+ }
2147
+
19312148 RCU_INIT_POINTER(rx_sc->sa[assoc_num], NULL);
19322149 clear_rx_sa(rx_sa);
19332150
19342151 rtnl_unlock();
19352152
19362153 return 0;
2154
+
2155
+cleanup:
2156
+ rtnl_unlock();
2157
+ return ret;
19372158 }
19382159
19392160 static int macsec_del_rxsc(struct sk_buff *skb, struct genl_info *info)
....@@ -1944,6 +2165,7 @@
19442165 struct macsec_rx_sc *rx_sc;
19452166 sci_t sci;
19462167 struct nlattr *tb_rxsc[MACSEC_RXSC_ATTR_MAX + 1];
2168
+ int ret;
19472169
19482170 if (!attrs[MACSEC_ATTR_IFINDEX])
19492171 return -EINVAL;
....@@ -1970,10 +2192,32 @@
19702192 return -ENODEV;
19712193 }
19722194
2195
+ /* If h/w offloading is available, propagate to the device */
2196
+ if (macsec_is_offloaded(netdev_priv(dev))) {
2197
+ const struct macsec_ops *ops;
2198
+ struct macsec_context ctx;
2199
+
2200
+ ops = macsec_get_ops(netdev_priv(dev), &ctx);
2201
+ if (!ops) {
2202
+ ret = -EOPNOTSUPP;
2203
+ goto cleanup;
2204
+ }
2205
+
2206
+ ctx.rx_sc = rx_sc;
2207
+ ctx.secy = secy;
2208
+ ret = macsec_offload(ops->mdo_del_rxsc, &ctx);
2209
+ if (ret)
2210
+ goto cleanup;
2211
+ }
2212
+
19732213 free_rx_sc(rx_sc);
19742214 rtnl_unlock();
19752215
19762216 return 0;
2217
+
2218
+cleanup:
2219
+ rtnl_unlock();
2220
+ return ret;
19772221 }
19782222
19792223 static int macsec_del_txsa(struct sk_buff *skb, struct genl_info *info)
....@@ -1985,6 +2229,7 @@
19852229 struct macsec_tx_sa *tx_sa;
19862230 u8 assoc_num;
19872231 struct nlattr *tb_sa[MACSEC_SA_ATTR_MAX + 1];
2232
+ int ret;
19882233
19892234 if (!attrs[MACSEC_ATTR_IFINDEX])
19902235 return -EINVAL;
....@@ -2005,25 +2250,51 @@
20052250 return -EBUSY;
20062251 }
20072252
2253
+ /* If h/w offloading is available, propagate to the device */
2254
+ if (macsec_is_offloaded(netdev_priv(dev))) {
2255
+ const struct macsec_ops *ops;
2256
+ struct macsec_context ctx;
2257
+
2258
+ ops = macsec_get_ops(netdev_priv(dev), &ctx);
2259
+ if (!ops) {
2260
+ ret = -EOPNOTSUPP;
2261
+ goto cleanup;
2262
+ }
2263
+
2264
+ ctx.sa.assoc_num = assoc_num;
2265
+ ctx.sa.tx_sa = tx_sa;
2266
+ ctx.secy = secy;
2267
+
2268
+ ret = macsec_offload(ops->mdo_del_txsa, &ctx);
2269
+ if (ret)
2270
+ goto cleanup;
2271
+ }
2272
+
20082273 RCU_INIT_POINTER(tx_sc->sa[assoc_num], NULL);
20092274 clear_tx_sa(tx_sa);
20102275
20112276 rtnl_unlock();
20122277
20132278 return 0;
2279
+
2280
+cleanup:
2281
+ rtnl_unlock();
2282
+ return ret;
20142283 }
20152284
20162285 static bool validate_upd_sa(struct nlattr **attrs)
20172286 {
20182287 if (!attrs[MACSEC_SA_ATTR_AN] ||
20192288 attrs[MACSEC_SA_ATTR_KEY] ||
2020
- attrs[MACSEC_SA_ATTR_KEYID])
2289
+ attrs[MACSEC_SA_ATTR_KEYID] ||
2290
+ attrs[MACSEC_SA_ATTR_SSCI] ||
2291
+ attrs[MACSEC_SA_ATTR_SALT])
20212292 return false;
20222293
20232294 if (nla_get_u8(attrs[MACSEC_SA_ATTR_AN]) >= MACSEC_NUM_AN)
20242295 return false;
20252296
2026
- if (attrs[MACSEC_SA_ATTR_PN] && nla_get_u32(attrs[MACSEC_SA_ATTR_PN]) == 0)
2297
+ if (attrs[MACSEC_SA_ATTR_PN] && nla_get_u64(attrs[MACSEC_SA_ATTR_PN]) == 0)
20272298 return false;
20282299
20292300 if (attrs[MACSEC_SA_ATTR_ACTIVE]) {
....@@ -2043,6 +2314,11 @@
20432314 struct macsec_tx_sa *tx_sa;
20442315 u8 assoc_num;
20452316 struct nlattr *tb_sa[MACSEC_SA_ATTR_MAX + 1];
2317
+ bool was_operational, was_active;
2318
+ pn_t prev_pn;
2319
+ int ret = 0;
2320
+
2321
+ prev_pn.full64 = 0;
20462322
20472323 if (!attrs[MACSEC_ATTR_IFINDEX])
20482324 return -EINVAL;
....@@ -2062,20 +2338,64 @@
20622338 }
20632339
20642340 if (tb_sa[MACSEC_SA_ATTR_PN]) {
2341
+ int pn_len;
2342
+
2343
+ pn_len = secy->xpn ? MACSEC_XPN_PN_LEN : MACSEC_DEFAULT_PN_LEN;
2344
+ if (nla_len(tb_sa[MACSEC_SA_ATTR_PN]) != pn_len) {
2345
+ pr_notice("macsec: nl: upd_txsa: bad pn length: %d != %d\n",
2346
+ nla_len(tb_sa[MACSEC_SA_ATTR_PN]), pn_len);
2347
+ rtnl_unlock();
2348
+ return -EINVAL;
2349
+ }
2350
+
20652351 spin_lock_bh(&tx_sa->lock);
2066
- tx_sa->next_pn = nla_get_u32(tb_sa[MACSEC_SA_ATTR_PN]);
2352
+ prev_pn = tx_sa->next_pn_halves;
2353
+ tx_sa->next_pn = nla_get_u64(tb_sa[MACSEC_SA_ATTR_PN]);
20672354 spin_unlock_bh(&tx_sa->lock);
20682355 }
20692356
2357
+ was_active = tx_sa->active;
20702358 if (tb_sa[MACSEC_SA_ATTR_ACTIVE])
20712359 tx_sa->active = nla_get_u8(tb_sa[MACSEC_SA_ATTR_ACTIVE]);
20722360
2361
+ was_operational = secy->operational;
20732362 if (assoc_num == tx_sc->encoding_sa)
20742363 secy->operational = tx_sa->active;
2364
+
2365
+ /* If h/w offloading is available, propagate to the device */
2366
+ if (macsec_is_offloaded(netdev_priv(dev))) {
2367
+ const struct macsec_ops *ops;
2368
+ struct macsec_context ctx;
2369
+
2370
+ ops = macsec_get_ops(netdev_priv(dev), &ctx);
2371
+ if (!ops) {
2372
+ ret = -EOPNOTSUPP;
2373
+ goto cleanup;
2374
+ }
2375
+
2376
+ ctx.sa.assoc_num = assoc_num;
2377
+ ctx.sa.tx_sa = tx_sa;
2378
+ ctx.secy = secy;
2379
+
2380
+ ret = macsec_offload(ops->mdo_upd_txsa, &ctx);
2381
+ if (ret)
2382
+ goto cleanup;
2383
+ }
20752384
20762385 rtnl_unlock();
20772386
20782387 return 0;
2388
+
2389
+cleanup:
2390
+ if (tb_sa[MACSEC_SA_ATTR_PN]) {
2391
+ spin_lock_bh(&tx_sa->lock);
2392
+ tx_sa->next_pn_halves = prev_pn;
2393
+ spin_unlock_bh(&tx_sa->lock);
2394
+ }
2395
+ tx_sa->active = was_active;
2396
+ secy->operational = was_operational;
2397
+ rtnl_unlock();
2398
+ return ret;
20792399 }
20802400
20812401 static int macsec_upd_rxsa(struct sk_buff *skb, struct genl_info *info)
....@@ -2088,6 +2408,11 @@
20882408 u8 assoc_num;
20892409 struct nlattr *tb_rxsc[MACSEC_RXSC_ATTR_MAX + 1];
20902410 struct nlattr *tb_sa[MACSEC_SA_ATTR_MAX + 1];
2411
+ bool was_active;
2412
+ pn_t prev_pn;
2413
+ int ret = 0;
2414
+
2415
+ prev_pn.full64 = 0;
20912416
20922417 if (!attrs[MACSEC_ATTR_IFINDEX])
20932418 return -EINVAL;
....@@ -2110,16 +2435,58 @@
21102435 }
21112436
21122437 if (tb_sa[MACSEC_SA_ATTR_PN]) {
2438
+ int pn_len;
2439
+
2440
+ pn_len = secy->xpn ? MACSEC_XPN_PN_LEN : MACSEC_DEFAULT_PN_LEN;
2441
+ if (nla_len(tb_sa[MACSEC_SA_ATTR_PN]) != pn_len) {
2442
+ pr_notice("macsec: nl: upd_rxsa: bad pn length: %d != %d\n",
2443
+ nla_len(tb_sa[MACSEC_SA_ATTR_PN]), pn_len);
2444
+ rtnl_unlock();
2445
+ return -EINVAL;
2446
+ }
2447
+
21132448 spin_lock_bh(&rx_sa->lock);
2114
- rx_sa->next_pn = nla_get_u32(tb_sa[MACSEC_SA_ATTR_PN]);
2449
+ prev_pn = rx_sa->next_pn_halves;
2450
+ rx_sa->next_pn = nla_get_u64(tb_sa[MACSEC_SA_ATTR_PN]);
21152451 spin_unlock_bh(&rx_sa->lock);
21162452 }
21172453
2454
+ was_active = rx_sa->active;
21182455 if (tb_sa[MACSEC_SA_ATTR_ACTIVE])
21192456 rx_sa->active = nla_get_u8(tb_sa[MACSEC_SA_ATTR_ACTIVE]);
21202457
2458
+ /* If h/w offloading is available, propagate to the device */
2459
+ if (macsec_is_offloaded(netdev_priv(dev))) {
2460
+ const struct macsec_ops *ops;
2461
+ struct macsec_context ctx;
2462
+
2463
+ ops = macsec_get_ops(netdev_priv(dev), &ctx);
2464
+ if (!ops) {
2465
+ ret = -EOPNOTSUPP;
2466
+ goto cleanup;
2467
+ }
2468
+
2469
+ ctx.sa.assoc_num = assoc_num;
2470
+ ctx.sa.rx_sa = rx_sa;
2471
+ ctx.secy = secy;
2472
+
2473
+ ret = macsec_offload(ops->mdo_upd_rxsa, &ctx);
2474
+ if (ret)
2475
+ goto cleanup;
2476
+ }
2477
+
21212478 rtnl_unlock();
21222479 return 0;
2480
+
2481
+cleanup:
2482
+ if (tb_sa[MACSEC_SA_ATTR_PN]) {
2483
+ spin_lock_bh(&rx_sa->lock);
2484
+ rx_sa->next_pn_halves = prev_pn;
2485
+ spin_unlock_bh(&rx_sa->lock);
2486
+ }
2487
+ rx_sa->active = was_active;
2488
+ rtnl_unlock();
2489
+ return ret;
21232490 }
21242491
21252492 static int macsec_upd_rxsc(struct sk_buff *skb, struct genl_info *info)
....@@ -2129,6 +2496,9 @@
21292496 struct macsec_secy *secy;
21302497 struct macsec_rx_sc *rx_sc;
21312498 struct nlattr *tb_rxsc[MACSEC_RXSC_ATTR_MAX + 1];
2499
+ unsigned int prev_n_rx_sc;
2500
+ bool was_active;
2501
+ int ret;
21322502
21332503 if (!attrs[MACSEC_ATTR_IFINDEX])
21342504 return -EINVAL;
....@@ -2146,6 +2516,8 @@
21462516 return PTR_ERR(rx_sc);
21472517 }
21482518
2519
+ was_active = rx_sc->active;
2520
+ prev_n_rx_sc = secy->n_rx_sc;
21492521 if (tb_rxsc[MACSEC_RXSC_ATTR_ACTIVE]) {
21502522 bool new = !!nla_get_u8(tb_rxsc[MACSEC_RXSC_ATTR_ACTIVE]);
21512523
....@@ -2155,211 +2527,447 @@
21552527 rx_sc->active = new;
21562528 }
21572529
2530
+ /* If h/w offloading is available, propagate to the device */
2531
+ if (macsec_is_offloaded(netdev_priv(dev))) {
2532
+ const struct macsec_ops *ops;
2533
+ struct macsec_context ctx;
2534
+
2535
+ ops = macsec_get_ops(netdev_priv(dev), &ctx);
2536
+ if (!ops) {
2537
+ ret = -EOPNOTSUPP;
2538
+ goto cleanup;
2539
+ }
2540
+
2541
+ ctx.rx_sc = rx_sc;
2542
+ ctx.secy = secy;
2543
+
2544
+ ret = macsec_offload(ops->mdo_upd_rxsc, &ctx);
2545
+ if (ret)
2546
+ goto cleanup;
2547
+ }
2548
+
21582549 rtnl_unlock();
21592550
21602551 return 0;
2552
+
2553
+cleanup:
2554
+ secy->n_rx_sc = prev_n_rx_sc;
2555
+ rx_sc->active = was_active;
2556
+ rtnl_unlock();
2557
+ return ret;
21612558 }
21622559
2163
-static int copy_tx_sa_stats(struct sk_buff *skb,
2164
- struct macsec_tx_sa_stats __percpu *pstats)
2560
+static bool macsec_is_configured(struct macsec_dev *macsec)
21652561 {
2166
- struct macsec_tx_sa_stats sum = {0, };
2167
- int cpu;
2562
+ struct macsec_secy *secy = &macsec->secy;
2563
+ struct macsec_tx_sc *tx_sc = &secy->tx_sc;
2564
+ int i;
21682565
2169
- for_each_possible_cpu(cpu) {
2170
- const struct macsec_tx_sa_stats *stats = per_cpu_ptr(pstats, cpu);
2566
+ if (secy->rx_sc)
2567
+ return true;
21712568
2172
- sum.OutPktsProtected += stats->OutPktsProtected;
2173
- sum.OutPktsEncrypted += stats->OutPktsEncrypted;
2569
+ for (i = 0; i < MACSEC_NUM_AN; i++)
2570
+ if (tx_sc->sa[i])
2571
+ return true;
2572
+
2573
+ return false;
2574
+}
2575
+
2576
+static int macsec_upd_offload(struct sk_buff *skb, struct genl_info *info)
2577
+{
2578
+ struct nlattr *tb_offload[MACSEC_OFFLOAD_ATTR_MAX + 1];
2579
+ enum macsec_offload offload, prev_offload;
2580
+ int (*func)(struct macsec_context *ctx);
2581
+ struct nlattr **attrs = info->attrs;
2582
+ struct net_device *dev;
2583
+ const struct macsec_ops *ops;
2584
+ struct macsec_context ctx;
2585
+ struct macsec_dev *macsec;
2586
+ int ret = 0;
2587
+
2588
+ if (!attrs[MACSEC_ATTR_IFINDEX])
2589
+ return -EINVAL;
2590
+
2591
+ if (!attrs[MACSEC_ATTR_OFFLOAD])
2592
+ return -EINVAL;
2593
+
2594
+ if (nla_parse_nested_deprecated(tb_offload, MACSEC_OFFLOAD_ATTR_MAX,
2595
+ attrs[MACSEC_ATTR_OFFLOAD],
2596
+ macsec_genl_offload_policy, NULL))
2597
+ return -EINVAL;
2598
+
2599
+ rtnl_lock();
2600
+
2601
+ dev = get_dev_from_nl(genl_info_net(info), attrs);
2602
+ if (IS_ERR(dev)) {
2603
+ ret = PTR_ERR(dev);
2604
+ goto out;
2605
+ }
2606
+ macsec = macsec_priv(dev);
2607
+
2608
+ if (!tb_offload[MACSEC_OFFLOAD_ATTR_TYPE]) {
2609
+ ret = -EINVAL;
2610
+ goto out;
21742611 }
21752612
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))
2613
+ offload = nla_get_u8(tb_offload[MACSEC_OFFLOAD_ATTR_TYPE]);
2614
+ if (macsec->offload == offload)
2615
+ goto out;
2616
+
2617
+ /* Check if the offloading mode is supported by the underlying layers */
2618
+ if (offload != MACSEC_OFFLOAD_OFF &&
2619
+ !macsec_check_offload(offload, macsec)) {
2620
+ ret = -EOPNOTSUPP;
2621
+ goto out;
2622
+ }
2623
+
2624
+ /* Check if the net device is busy. */
2625
+ if (netif_running(dev)) {
2626
+ ret = -EBUSY;
2627
+ goto out;
2628
+ }
2629
+
2630
+ prev_offload = macsec->offload;
2631
+ macsec->offload = offload;
2632
+
2633
+ /* Check if the device already has rules configured: we do not support
2634
+ * rules migration.
2635
+ */
2636
+ if (macsec_is_configured(macsec)) {
2637
+ ret = -EBUSY;
2638
+ goto rollback;
2639
+ }
2640
+
2641
+ ops = __macsec_get_ops(offload == MACSEC_OFFLOAD_OFF ? prev_offload : offload,
2642
+ macsec, &ctx);
2643
+ if (!ops) {
2644
+ ret = -EOPNOTSUPP;
2645
+ goto rollback;
2646
+ }
2647
+
2648
+ if (prev_offload == MACSEC_OFFLOAD_OFF)
2649
+ func = ops->mdo_add_secy;
2650
+ else
2651
+ func = ops->mdo_del_secy;
2652
+
2653
+ ctx.secy = &macsec->secy;
2654
+ ret = macsec_offload(func, &ctx);
2655
+ if (ret)
2656
+ goto rollback;
2657
+
2658
+ rtnl_unlock();
2659
+ return 0;
2660
+
2661
+rollback:
2662
+ macsec->offload = prev_offload;
2663
+out:
2664
+ rtnl_unlock();
2665
+ return ret;
2666
+}
2667
+
2668
+static void get_tx_sa_stats(struct net_device *dev, int an,
2669
+ struct macsec_tx_sa *tx_sa,
2670
+ struct macsec_tx_sa_stats *sum)
2671
+{
2672
+ struct macsec_dev *macsec = macsec_priv(dev);
2673
+ int cpu;
2674
+
2675
+ /* If h/w offloading is available, propagate to the device */
2676
+ if (macsec_is_offloaded(macsec)) {
2677
+ const struct macsec_ops *ops;
2678
+ struct macsec_context ctx;
2679
+
2680
+ ops = macsec_get_ops(macsec, &ctx);
2681
+ if (ops) {
2682
+ ctx.sa.assoc_num = an;
2683
+ ctx.sa.tx_sa = tx_sa;
2684
+ ctx.stats.tx_sa_stats = sum;
2685
+ ctx.secy = &macsec_priv(dev)->secy;
2686
+ macsec_offload(ops->mdo_get_tx_sa_stats, &ctx);
2687
+ }
2688
+ return;
2689
+ }
2690
+
2691
+ for_each_possible_cpu(cpu) {
2692
+ const struct macsec_tx_sa_stats *stats =
2693
+ per_cpu_ptr(tx_sa->stats, cpu);
2694
+
2695
+ sum->OutPktsProtected += stats->OutPktsProtected;
2696
+ sum->OutPktsEncrypted += stats->OutPktsEncrypted;
2697
+ }
2698
+}
2699
+
2700
+static int copy_tx_sa_stats(struct sk_buff *skb, struct macsec_tx_sa_stats *sum)
2701
+{
2702
+ if (nla_put_u32(skb, MACSEC_SA_STATS_ATTR_OUT_PKTS_PROTECTED,
2703
+ sum->OutPktsProtected) ||
2704
+ nla_put_u32(skb, MACSEC_SA_STATS_ATTR_OUT_PKTS_ENCRYPTED,
2705
+ sum->OutPktsEncrypted))
21782706 return -EMSGSIZE;
21792707
21802708 return 0;
2709
+}
2710
+
2711
+static void get_rx_sa_stats(struct net_device *dev,
2712
+ struct macsec_rx_sc *rx_sc, int an,
2713
+ struct macsec_rx_sa *rx_sa,
2714
+ struct macsec_rx_sa_stats *sum)
2715
+{
2716
+ struct macsec_dev *macsec = macsec_priv(dev);
2717
+ int cpu;
2718
+
2719
+ /* If h/w offloading is available, propagate to the device */
2720
+ if (macsec_is_offloaded(macsec)) {
2721
+ const struct macsec_ops *ops;
2722
+ struct macsec_context ctx;
2723
+
2724
+ ops = macsec_get_ops(macsec, &ctx);
2725
+ if (ops) {
2726
+ ctx.sa.assoc_num = an;
2727
+ ctx.sa.rx_sa = rx_sa;
2728
+ ctx.stats.rx_sa_stats = sum;
2729
+ ctx.secy = &macsec_priv(dev)->secy;
2730
+ ctx.rx_sc = rx_sc;
2731
+ macsec_offload(ops->mdo_get_rx_sa_stats, &ctx);
2732
+ }
2733
+ return;
2734
+ }
2735
+
2736
+ for_each_possible_cpu(cpu) {
2737
+ const struct macsec_rx_sa_stats *stats =
2738
+ per_cpu_ptr(rx_sa->stats, cpu);
2739
+
2740
+ sum->InPktsOK += stats->InPktsOK;
2741
+ sum->InPktsInvalid += stats->InPktsInvalid;
2742
+ sum->InPktsNotValid += stats->InPktsNotValid;
2743
+ sum->InPktsNotUsingSA += stats->InPktsNotUsingSA;
2744
+ sum->InPktsUnusedSA += stats->InPktsUnusedSA;
2745
+ }
21812746 }
21822747
21832748 static int copy_rx_sa_stats(struct sk_buff *skb,
2184
- struct macsec_rx_sa_stats __percpu *pstats)
2749
+ struct macsec_rx_sa_stats *sum)
21852750 {
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))
2751
+ if (nla_put_u32(skb, MACSEC_SA_STATS_ATTR_IN_PKTS_OK, sum->InPktsOK) ||
2752
+ nla_put_u32(skb, MACSEC_SA_STATS_ATTR_IN_PKTS_INVALID,
2753
+ sum->InPktsInvalid) ||
2754
+ nla_put_u32(skb, MACSEC_SA_STATS_ATTR_IN_PKTS_NOT_VALID,
2755
+ sum->InPktsNotValid) ||
2756
+ nla_put_u32(skb, MACSEC_SA_STATS_ATTR_IN_PKTS_NOT_USING_SA,
2757
+ sum->InPktsNotUsingSA) ||
2758
+ nla_put_u32(skb, MACSEC_SA_STATS_ATTR_IN_PKTS_UNUSED_SA,
2759
+ sum->InPktsUnusedSA))
22042760 return -EMSGSIZE;
22052761
22062762 return 0;
22072763 }
22082764
2209
-static int copy_rx_sc_stats(struct sk_buff *skb,
2210
- struct pcpu_rx_sc_stats __percpu *pstats)
2765
+static void get_rx_sc_stats(struct net_device *dev,
2766
+ struct macsec_rx_sc *rx_sc,
2767
+ struct macsec_rx_sc_stats *sum)
22112768 {
2212
- struct macsec_rx_sc_stats sum = {0, };
2769
+ struct macsec_dev *macsec = macsec_priv(dev);
22132770 int cpu;
2771
+
2772
+ /* If h/w offloading is available, propagate to the device */
2773
+ if (macsec_is_offloaded(macsec)) {
2774
+ const struct macsec_ops *ops;
2775
+ struct macsec_context ctx;
2776
+
2777
+ ops = macsec_get_ops(macsec, &ctx);
2778
+ if (ops) {
2779
+ ctx.stats.rx_sc_stats = sum;
2780
+ ctx.secy = &macsec_priv(dev)->secy;
2781
+ ctx.rx_sc = rx_sc;
2782
+ macsec_offload(ops->mdo_get_rx_sc_stats, &ctx);
2783
+ }
2784
+ return;
2785
+ }
22142786
22152787 for_each_possible_cpu(cpu) {
22162788 const struct pcpu_rx_sc_stats *stats;
22172789 struct macsec_rx_sc_stats tmp;
22182790 unsigned int start;
22192791
2220
- stats = per_cpu_ptr(pstats, cpu);
2792
+ stats = per_cpu_ptr(rx_sc->stats, cpu);
22212793 do {
22222794 start = u64_stats_fetch_begin_irq(&stats->syncp);
22232795 memcpy(&tmp, &stats->stats, sizeof(tmp));
22242796 } while (u64_stats_fetch_retry_irq(&stats->syncp, start));
22252797
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;
2798
+ sum->InOctetsValidated += tmp.InOctetsValidated;
2799
+ sum->InOctetsDecrypted += tmp.InOctetsDecrypted;
2800
+ sum->InPktsUnchecked += tmp.InPktsUnchecked;
2801
+ sum->InPktsDelayed += tmp.InPktsDelayed;
2802
+ sum->InPktsOK += tmp.InPktsOK;
2803
+ sum->InPktsInvalid += tmp.InPktsInvalid;
2804
+ sum->InPktsLate += tmp.InPktsLate;
2805
+ sum->InPktsNotValid += tmp.InPktsNotValid;
2806
+ sum->InPktsNotUsingSA += tmp.InPktsNotUsingSA;
2807
+ sum->InPktsUnusedSA += tmp.InPktsUnusedSA;
22362808 }
2809
+}
22372810
2811
+static int copy_rx_sc_stats(struct sk_buff *skb, struct macsec_rx_sc_stats *sum)
2812
+{
22382813 if (nla_put_u64_64bit(skb, MACSEC_RXSC_STATS_ATTR_IN_OCTETS_VALIDATED,
2239
- sum.InOctetsValidated,
2814
+ sum->InOctetsValidated,
22402815 MACSEC_RXSC_STATS_ATTR_PAD) ||
22412816 nla_put_u64_64bit(skb, MACSEC_RXSC_STATS_ATTR_IN_OCTETS_DECRYPTED,
2242
- sum.InOctetsDecrypted,
2817
+ sum->InOctetsDecrypted,
22432818 MACSEC_RXSC_STATS_ATTR_PAD) ||
22442819 nla_put_u64_64bit(skb, MACSEC_RXSC_STATS_ATTR_IN_PKTS_UNCHECKED,
2245
- sum.InPktsUnchecked,
2820
+ sum->InPktsUnchecked,
22462821 MACSEC_RXSC_STATS_ATTR_PAD) ||
22472822 nla_put_u64_64bit(skb, MACSEC_RXSC_STATS_ATTR_IN_PKTS_DELAYED,
2248
- sum.InPktsDelayed,
2823
+ sum->InPktsDelayed,
22492824 MACSEC_RXSC_STATS_ATTR_PAD) ||
22502825 nla_put_u64_64bit(skb, MACSEC_RXSC_STATS_ATTR_IN_PKTS_OK,
2251
- sum.InPktsOK,
2826
+ sum->InPktsOK,
22522827 MACSEC_RXSC_STATS_ATTR_PAD) ||
22532828 nla_put_u64_64bit(skb, MACSEC_RXSC_STATS_ATTR_IN_PKTS_INVALID,
2254
- sum.InPktsInvalid,
2829
+ sum->InPktsInvalid,
22552830 MACSEC_RXSC_STATS_ATTR_PAD) ||
22562831 nla_put_u64_64bit(skb, MACSEC_RXSC_STATS_ATTR_IN_PKTS_LATE,
2257
- sum.InPktsLate,
2832
+ sum->InPktsLate,
22582833 MACSEC_RXSC_STATS_ATTR_PAD) ||
22592834 nla_put_u64_64bit(skb, MACSEC_RXSC_STATS_ATTR_IN_PKTS_NOT_VALID,
2260
- sum.InPktsNotValid,
2835
+ sum->InPktsNotValid,
22612836 MACSEC_RXSC_STATS_ATTR_PAD) ||
22622837 nla_put_u64_64bit(skb, MACSEC_RXSC_STATS_ATTR_IN_PKTS_NOT_USING_SA,
2263
- sum.InPktsNotUsingSA,
2838
+ sum->InPktsNotUsingSA,
22642839 MACSEC_RXSC_STATS_ATTR_PAD) ||
22652840 nla_put_u64_64bit(skb, MACSEC_RXSC_STATS_ATTR_IN_PKTS_UNUSED_SA,
2266
- sum.InPktsUnusedSA,
2841
+ sum->InPktsUnusedSA,
22672842 MACSEC_RXSC_STATS_ATTR_PAD))
22682843 return -EMSGSIZE;
22692844
22702845 return 0;
22712846 }
22722847
2273
-static int copy_tx_sc_stats(struct sk_buff *skb,
2274
- struct pcpu_tx_sc_stats __percpu *pstats)
2848
+static void get_tx_sc_stats(struct net_device *dev,
2849
+ struct macsec_tx_sc_stats *sum)
22752850 {
2276
- struct macsec_tx_sc_stats sum = {0, };
2851
+ struct macsec_dev *macsec = macsec_priv(dev);
22772852 int cpu;
2853
+
2854
+ /* If h/w offloading is available, propagate to the device */
2855
+ if (macsec_is_offloaded(macsec)) {
2856
+ const struct macsec_ops *ops;
2857
+ struct macsec_context ctx;
2858
+
2859
+ ops = macsec_get_ops(macsec, &ctx);
2860
+ if (ops) {
2861
+ ctx.stats.tx_sc_stats = sum;
2862
+ ctx.secy = &macsec_priv(dev)->secy;
2863
+ macsec_offload(ops->mdo_get_tx_sc_stats, &ctx);
2864
+ }
2865
+ return;
2866
+ }
22782867
22792868 for_each_possible_cpu(cpu) {
22802869 const struct pcpu_tx_sc_stats *stats;
22812870 struct macsec_tx_sc_stats tmp;
22822871 unsigned int start;
22832872
2284
- stats = per_cpu_ptr(pstats, cpu);
2873
+ stats = per_cpu_ptr(macsec_priv(dev)->secy.tx_sc.stats, cpu);
22852874 do {
22862875 start = u64_stats_fetch_begin_irq(&stats->syncp);
22872876 memcpy(&tmp, &stats->stats, sizeof(tmp));
22882877 } while (u64_stats_fetch_retry_irq(&stats->syncp, start));
22892878
2290
- sum.OutPktsProtected += tmp.OutPktsProtected;
2291
- sum.OutPktsEncrypted += tmp.OutPktsEncrypted;
2292
- sum.OutOctetsProtected += tmp.OutOctetsProtected;
2293
- sum.OutOctetsEncrypted += tmp.OutOctetsEncrypted;
2879
+ sum->OutPktsProtected += tmp.OutPktsProtected;
2880
+ sum->OutPktsEncrypted += tmp.OutPktsEncrypted;
2881
+ sum->OutOctetsProtected += tmp.OutOctetsProtected;
2882
+ sum->OutOctetsEncrypted += tmp.OutOctetsEncrypted;
22942883 }
2884
+}
22952885
2886
+static int copy_tx_sc_stats(struct sk_buff *skb, struct macsec_tx_sc_stats *sum)
2887
+{
22962888 if (nla_put_u64_64bit(skb, MACSEC_TXSC_STATS_ATTR_OUT_PKTS_PROTECTED,
2297
- sum.OutPktsProtected,
2889
+ sum->OutPktsProtected,
22982890 MACSEC_TXSC_STATS_ATTR_PAD) ||
22992891 nla_put_u64_64bit(skb, MACSEC_TXSC_STATS_ATTR_OUT_PKTS_ENCRYPTED,
2300
- sum.OutPktsEncrypted,
2892
+ sum->OutPktsEncrypted,
23012893 MACSEC_TXSC_STATS_ATTR_PAD) ||
23022894 nla_put_u64_64bit(skb, MACSEC_TXSC_STATS_ATTR_OUT_OCTETS_PROTECTED,
2303
- sum.OutOctetsProtected,
2895
+ sum->OutOctetsProtected,
23042896 MACSEC_TXSC_STATS_ATTR_PAD) ||
23052897 nla_put_u64_64bit(skb, MACSEC_TXSC_STATS_ATTR_OUT_OCTETS_ENCRYPTED,
2306
- sum.OutOctetsEncrypted,
2898
+ sum->OutOctetsEncrypted,
23072899 MACSEC_TXSC_STATS_ATTR_PAD))
23082900 return -EMSGSIZE;
23092901
23102902 return 0;
23112903 }
23122904
2313
-static int copy_secy_stats(struct sk_buff *skb,
2314
- struct pcpu_secy_stats __percpu *pstats)
2905
+static void get_secy_stats(struct net_device *dev, struct macsec_dev_stats *sum)
23152906 {
2316
- struct macsec_dev_stats sum = {0, };
2907
+ struct macsec_dev *macsec = macsec_priv(dev);
23172908 int cpu;
2909
+
2910
+ /* If h/w offloading is available, propagate to the device */
2911
+ if (macsec_is_offloaded(macsec)) {
2912
+ const struct macsec_ops *ops;
2913
+ struct macsec_context ctx;
2914
+
2915
+ ops = macsec_get_ops(macsec, &ctx);
2916
+ if (ops) {
2917
+ ctx.stats.dev_stats = sum;
2918
+ ctx.secy = &macsec_priv(dev)->secy;
2919
+ macsec_offload(ops->mdo_get_dev_stats, &ctx);
2920
+ }
2921
+ return;
2922
+ }
23182923
23192924 for_each_possible_cpu(cpu) {
23202925 const struct pcpu_secy_stats *stats;
23212926 struct macsec_dev_stats tmp;
23222927 unsigned int start;
23232928
2324
- stats = per_cpu_ptr(pstats, cpu);
2929
+ stats = per_cpu_ptr(macsec_priv(dev)->stats, cpu);
23252930 do {
23262931 start = u64_stats_fetch_begin_irq(&stats->syncp);
23272932 memcpy(&tmp, &stats->stats, sizeof(tmp));
23282933 } while (u64_stats_fetch_retry_irq(&stats->syncp, start));
23292934
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;
2935
+ sum->OutPktsUntagged += tmp.OutPktsUntagged;
2936
+ sum->InPktsUntagged += tmp.InPktsUntagged;
2937
+ sum->OutPktsTooLong += tmp.OutPktsTooLong;
2938
+ sum->InPktsNoTag += tmp.InPktsNoTag;
2939
+ sum->InPktsBadTag += tmp.InPktsBadTag;
2940
+ sum->InPktsUnknownSCI += tmp.InPktsUnknownSCI;
2941
+ sum->InPktsNoSCI += tmp.InPktsNoSCI;
2942
+ sum->InPktsOverrun += tmp.InPktsOverrun;
23382943 }
2944
+}
23392945
2946
+static int copy_secy_stats(struct sk_buff *skb, struct macsec_dev_stats *sum)
2947
+{
23402948 if (nla_put_u64_64bit(skb, MACSEC_SECY_STATS_ATTR_OUT_PKTS_UNTAGGED,
2341
- sum.OutPktsUntagged,
2949
+ sum->OutPktsUntagged,
23422950 MACSEC_SECY_STATS_ATTR_PAD) ||
23432951 nla_put_u64_64bit(skb, MACSEC_SECY_STATS_ATTR_IN_PKTS_UNTAGGED,
2344
- sum.InPktsUntagged,
2952
+ sum->InPktsUntagged,
23452953 MACSEC_SECY_STATS_ATTR_PAD) ||
23462954 nla_put_u64_64bit(skb, MACSEC_SECY_STATS_ATTR_OUT_PKTS_TOO_LONG,
2347
- sum.OutPktsTooLong,
2955
+ sum->OutPktsTooLong,
23482956 MACSEC_SECY_STATS_ATTR_PAD) ||
23492957 nla_put_u64_64bit(skb, MACSEC_SECY_STATS_ATTR_IN_PKTS_NO_TAG,
2350
- sum.InPktsNoTag,
2958
+ sum->InPktsNoTag,
23512959 MACSEC_SECY_STATS_ATTR_PAD) ||
23522960 nla_put_u64_64bit(skb, MACSEC_SECY_STATS_ATTR_IN_PKTS_BAD_TAG,
2353
- sum.InPktsBadTag,
2961
+ sum->InPktsBadTag,
23542962 MACSEC_SECY_STATS_ATTR_PAD) ||
23552963 nla_put_u64_64bit(skb, MACSEC_SECY_STATS_ATTR_IN_PKTS_UNKNOWN_SCI,
2356
- sum.InPktsUnknownSCI,
2964
+ sum->InPktsUnknownSCI,
23572965 MACSEC_SECY_STATS_ATTR_PAD) ||
23582966 nla_put_u64_64bit(skb, MACSEC_SECY_STATS_ATTR_IN_PKTS_NO_SCI,
2359
- sum.InPktsNoSCI,
2967
+ sum->InPktsNoSCI,
23602968 MACSEC_SECY_STATS_ATTR_PAD) ||
23612969 nla_put_u64_64bit(skb, MACSEC_SECY_STATS_ATTR_IN_PKTS_OVERRUN,
2362
- sum.InPktsOverrun,
2970
+ sum->InPktsOverrun,
23632971 MACSEC_SECY_STATS_ATTR_PAD))
23642972 return -EMSGSIZE;
23652973
....@@ -2369,7 +2977,8 @@
23692977 static int nla_put_secy(struct macsec_secy *secy, struct sk_buff *skb)
23702978 {
23712979 struct macsec_tx_sc *tx_sc = &secy->tx_sc;
2372
- struct nlattr *secy_nest = nla_nest_start(skb, MACSEC_ATTR_SECY);
2980
+ struct nlattr *secy_nest = nla_nest_start_noflag(skb,
2981
+ MACSEC_ATTR_SECY);
23732982 u64 csid;
23742983
23752984 if (!secy_nest)
....@@ -2377,10 +2986,10 @@
23772986
23782987 switch (secy->key_len) {
23792988 case MACSEC_GCM_AES_128_SAK_LEN:
2380
- csid = MACSEC_DEFAULT_CIPHER_ID;
2989
+ csid = secy->xpn ? MACSEC_CIPHER_ID_GCM_AES_XPN_128 : MACSEC_DEFAULT_CIPHER_ID;
23812990 break;
23822991 case MACSEC_GCM_AES_256_SAK_LEN:
2383
- csid = MACSEC_CIPHER_ID_GCM_AES_256;
2992
+ csid = secy->xpn ? MACSEC_CIPHER_ID_GCM_AES_XPN_256 : MACSEC_CIPHER_ID_GCM_AES_256;
23842993 break;
23852994 default:
23862995 goto cancel;
....@@ -2415,15 +3024,22 @@
24153024 return 1;
24163025 }
24173026
2418
-static int dump_secy(struct macsec_secy *secy, struct net_device *dev,
2419
- struct sk_buff *skb, struct netlink_callback *cb)
3027
+static noinline_for_stack int
3028
+dump_secy(struct macsec_secy *secy, struct net_device *dev,
3029
+ struct sk_buff *skb, struct netlink_callback *cb)
24203030 {
2421
- struct macsec_rx_sc *rx_sc;
3031
+ struct macsec_tx_sc_stats tx_sc_stats = {0, };
3032
+ struct macsec_tx_sa_stats tx_sa_stats = {0, };
3033
+ struct macsec_rx_sc_stats rx_sc_stats = {0, };
3034
+ struct macsec_rx_sa_stats rx_sa_stats = {0, };
3035
+ struct macsec_dev *macsec = netdev_priv(dev);
3036
+ struct macsec_dev_stats dev_stats = {0, };
24223037 struct macsec_tx_sc *tx_sc = &secy->tx_sc;
24233038 struct nlattr *txsa_list, *rxsc_list;
2424
- int i, j;
2425
- void *hdr;
3039
+ struct macsec_rx_sc *rx_sc;
24263040 struct nlattr *attr;
3041
+ void *hdr;
3042
+ int i, j;
24273043
24283044 hdr = genlmsg_put(skb, NETLINK_CB(cb->skb).portid, cb->nlh->nlmsg_seq,
24293045 &macsec_fam, NLM_F_MULTI, MACSEC_CMD_GET_TXSC);
....@@ -2435,59 +3051,64 @@
24353051 if (nla_put_u32(skb, MACSEC_ATTR_IFINDEX, dev->ifindex))
24363052 goto nla_put_failure;
24373053
3054
+ attr = nla_nest_start_noflag(skb, MACSEC_ATTR_OFFLOAD);
3055
+ if (!attr)
3056
+ goto nla_put_failure;
3057
+ if (nla_put_u8(skb, MACSEC_OFFLOAD_ATTR_TYPE, macsec->offload))
3058
+ goto nla_put_failure;
3059
+ nla_nest_end(skb, attr);
3060
+
24383061 if (nla_put_secy(secy, skb))
24393062 goto nla_put_failure;
24403063
2441
- attr = nla_nest_start(skb, MACSEC_ATTR_TXSC_STATS);
3064
+ attr = nla_nest_start_noflag(skb, MACSEC_ATTR_TXSC_STATS);
24423065 if (!attr)
24433066 goto nla_put_failure;
2444
- if (copy_tx_sc_stats(skb, tx_sc->stats)) {
3067
+
3068
+ get_tx_sc_stats(dev, &tx_sc_stats);
3069
+ if (copy_tx_sc_stats(skb, &tx_sc_stats)) {
24453070 nla_nest_cancel(skb, attr);
24463071 goto nla_put_failure;
24473072 }
24483073 nla_nest_end(skb, attr);
24493074
2450
- attr = nla_nest_start(skb, MACSEC_ATTR_SECY_STATS);
3075
+ attr = nla_nest_start_noflag(skb, MACSEC_ATTR_SECY_STATS);
24513076 if (!attr)
24523077 goto nla_put_failure;
2453
- if (copy_secy_stats(skb, macsec_priv(dev)->stats)) {
3078
+ get_secy_stats(dev, &dev_stats);
3079
+ if (copy_secy_stats(skb, &dev_stats)) {
24543080 nla_nest_cancel(skb, attr);
24553081 goto nla_put_failure;
24563082 }
24573083 nla_nest_end(skb, attr);
24583084
2459
- txsa_list = nla_nest_start(skb, MACSEC_ATTR_TXSA_LIST);
3085
+ txsa_list = nla_nest_start_noflag(skb, MACSEC_ATTR_TXSA_LIST);
24603086 if (!txsa_list)
24613087 goto nla_put_failure;
24623088 for (i = 0, j = 1; i < MACSEC_NUM_AN; i++) {
24633089 struct macsec_tx_sa *tx_sa = rtnl_dereference(tx_sc->sa[i]);
24643090 struct nlattr *txsa_nest;
3091
+ u64 pn;
3092
+ int pn_len;
24653093
24663094 if (!tx_sa)
24673095 continue;
24683096
2469
- txsa_nest = nla_nest_start(skb, j++);
3097
+ txsa_nest = nla_nest_start_noflag(skb, j++);
24703098 if (!txsa_nest) {
24713099 nla_nest_cancel(skb, txsa_list);
24723100 goto nla_put_failure;
24733101 }
24743102
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);
3103
+ attr = nla_nest_start_noflag(skb, MACSEC_SA_ATTR_STATS);
24853104 if (!attr) {
24863105 nla_nest_cancel(skb, txsa_nest);
24873106 nla_nest_cancel(skb, txsa_list);
24883107 goto nla_put_failure;
24893108 }
2490
- if (copy_tx_sa_stats(skb, tx_sa->stats)) {
3109
+ memset(&tx_sa_stats, 0, sizeof(tx_sa_stats));
3110
+ get_tx_sa_stats(dev, i, tx_sa, &tx_sa_stats);
3111
+ if (copy_tx_sa_stats(skb, &tx_sa_stats)) {
24913112 nla_nest_cancel(skb, attr);
24923113 nla_nest_cancel(skb, txsa_nest);
24933114 nla_nest_cancel(skb, txsa_list);
....@@ -2495,11 +3116,29 @@
24953116 }
24963117 nla_nest_end(skb, attr);
24973118
3119
+ if (secy->xpn) {
3120
+ pn = tx_sa->next_pn;
3121
+ pn_len = MACSEC_XPN_PN_LEN;
3122
+ } else {
3123
+ pn = tx_sa->next_pn_halves.lower;
3124
+ pn_len = MACSEC_DEFAULT_PN_LEN;
3125
+ }
3126
+
3127
+ if (nla_put_u8(skb, MACSEC_SA_ATTR_AN, i) ||
3128
+ nla_put(skb, MACSEC_SA_ATTR_PN, pn_len, &pn) ||
3129
+ nla_put(skb, MACSEC_SA_ATTR_KEYID, MACSEC_KEYID_LEN, tx_sa->key.id) ||
3130
+ (secy->xpn && nla_put_ssci(skb, MACSEC_SA_ATTR_SSCI, tx_sa->ssci)) ||
3131
+ nla_put_u8(skb, MACSEC_SA_ATTR_ACTIVE, tx_sa->active)) {
3132
+ nla_nest_cancel(skb, txsa_nest);
3133
+ nla_nest_cancel(skb, txsa_list);
3134
+ goto nla_put_failure;
3135
+ }
3136
+
24983137 nla_nest_end(skb, txsa_nest);
24993138 }
25003139 nla_nest_end(skb, txsa_list);
25013140
2502
- rxsc_list = nla_nest_start(skb, MACSEC_ATTR_RXSC_LIST);
3141
+ rxsc_list = nla_nest_start_noflag(skb, MACSEC_ATTR_RXSC_LIST);
25033142 if (!rxsc_list)
25043143 goto nla_put_failure;
25053144
....@@ -2507,7 +3146,7 @@
25073146 for_each_rxsc_rtnl(secy, rx_sc) {
25083147 int k;
25093148 struct nlattr *rxsa_list;
2510
- struct nlattr *rxsc_nest = nla_nest_start(skb, j++);
3149
+ struct nlattr *rxsc_nest = nla_nest_start_noflag(skb, j++);
25113150
25123151 if (!rxsc_nest) {
25133152 nla_nest_cancel(skb, rxsc_list);
....@@ -2522,13 +3161,15 @@
25223161 goto nla_put_failure;
25233162 }
25243163
2525
- attr = nla_nest_start(skb, MACSEC_RXSC_ATTR_STATS);
3164
+ attr = nla_nest_start_noflag(skb, MACSEC_RXSC_ATTR_STATS);
25263165 if (!attr) {
25273166 nla_nest_cancel(skb, rxsc_nest);
25283167 nla_nest_cancel(skb, rxsc_list);
25293168 goto nla_put_failure;
25303169 }
2531
- if (copy_rx_sc_stats(skb, rx_sc->stats)) {
3170
+ memset(&rx_sc_stats, 0, sizeof(rx_sc_stats));
3171
+ get_rx_sc_stats(dev, rx_sc, &rx_sc_stats);
3172
+ if (copy_rx_sc_stats(skb, &rx_sc_stats)) {
25323173 nla_nest_cancel(skb, attr);
25333174 nla_nest_cancel(skb, rxsc_nest);
25343175 nla_nest_cancel(skb, rxsc_list);
....@@ -2536,7 +3177,8 @@
25363177 }
25373178 nla_nest_end(skb, attr);
25383179
2539
- rxsa_list = nla_nest_start(skb, MACSEC_RXSC_ATTR_SA_LIST);
3180
+ rxsa_list = nla_nest_start_noflag(skb,
3181
+ MACSEC_RXSC_ATTR_SA_LIST);
25403182 if (!rxsa_list) {
25413183 nla_nest_cancel(skb, rxsc_nest);
25423184 nla_nest_cancel(skb, rxsc_list);
....@@ -2546,11 +3188,13 @@
25463188 for (i = 0, k = 1; i < MACSEC_NUM_AN; i++) {
25473189 struct macsec_rx_sa *rx_sa = rtnl_dereference(rx_sc->sa[i]);
25483190 struct nlattr *rxsa_nest;
3191
+ u64 pn;
3192
+ int pn_len;
25493193
25503194 if (!rx_sa)
25513195 continue;
25523196
2553
- rxsa_nest = nla_nest_start(skb, k++);
3197
+ rxsa_nest = nla_nest_start_noflag(skb, k++);
25543198 if (!rxsa_nest) {
25553199 nla_nest_cancel(skb, rxsa_list);
25563200 nla_nest_cancel(skb, rxsc_nest);
....@@ -2558,14 +3202,17 @@
25583202 goto nla_put_failure;
25593203 }
25603204
2561
- attr = nla_nest_start(skb, MACSEC_SA_ATTR_STATS);
3205
+ attr = nla_nest_start_noflag(skb,
3206
+ MACSEC_SA_ATTR_STATS);
25623207 if (!attr) {
25633208 nla_nest_cancel(skb, rxsa_list);
25643209 nla_nest_cancel(skb, rxsc_nest);
25653210 nla_nest_cancel(skb, rxsc_list);
25663211 goto nla_put_failure;
25673212 }
2568
- if (copy_rx_sa_stats(skb, rx_sa->stats)) {
3213
+ memset(&rx_sa_stats, 0, sizeof(rx_sa_stats));
3214
+ get_rx_sa_stats(dev, rx_sc, i, rx_sa, &rx_sa_stats);
3215
+ if (copy_rx_sa_stats(skb, &rx_sa_stats)) {
25693216 nla_nest_cancel(skb, attr);
25703217 nla_nest_cancel(skb, rxsa_list);
25713218 nla_nest_cancel(skb, rxsc_nest);
....@@ -2574,9 +3221,18 @@
25743221 }
25753222 nla_nest_end(skb, attr);
25763223
3224
+ if (secy->xpn) {
3225
+ pn = rx_sa->next_pn;
3226
+ pn_len = MACSEC_XPN_PN_LEN;
3227
+ } else {
3228
+ pn = rx_sa->next_pn_halves.lower;
3229
+ pn_len = MACSEC_DEFAULT_PN_LEN;
3230
+ }
3231
+
25773232 if (nla_put_u8(skb, MACSEC_SA_ATTR_AN, i) ||
2578
- nla_put_u32(skb, MACSEC_SA_ATTR_PN, rx_sa->next_pn) ||
3233
+ nla_put(skb, MACSEC_SA_ATTR_PN, pn_len, &pn) ||
25793234 nla_put(skb, MACSEC_SA_ATTR_KEYID, MACSEC_KEYID_LEN, rx_sa->key.id) ||
3235
+ (secy->xpn && nla_put_ssci(skb, MACSEC_SA_ATTR_SSCI, rx_sa->ssci)) ||
25803236 nla_put_u8(skb, MACSEC_SA_ATTR_ACTIVE, rx_sa->active)) {
25813237 nla_nest_cancel(skb, rxsa_nest);
25823238 nla_nest_cancel(skb, rxsc_nest);
....@@ -2638,64 +3294,70 @@
26383294 return skb->len;
26393295 }
26403296
2641
-static const struct genl_ops macsec_genl_ops[] = {
3297
+static const struct genl_small_ops macsec_genl_ops[] = {
26423298 {
26433299 .cmd = MACSEC_CMD_GET_TXSC,
3300
+ .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
26443301 .dumpit = macsec_dump_txsc,
2645
- .policy = macsec_genl_policy,
26463302 },
26473303 {
26483304 .cmd = MACSEC_CMD_ADD_RXSC,
3305
+ .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
26493306 .doit = macsec_add_rxsc,
2650
- .policy = macsec_genl_policy,
26513307 .flags = GENL_ADMIN_PERM,
26523308 },
26533309 {
26543310 .cmd = MACSEC_CMD_DEL_RXSC,
3311
+ .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
26553312 .doit = macsec_del_rxsc,
2656
- .policy = macsec_genl_policy,
26573313 .flags = GENL_ADMIN_PERM,
26583314 },
26593315 {
26603316 .cmd = MACSEC_CMD_UPD_RXSC,
3317
+ .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
26613318 .doit = macsec_upd_rxsc,
2662
- .policy = macsec_genl_policy,
26633319 .flags = GENL_ADMIN_PERM,
26643320 },
26653321 {
26663322 .cmd = MACSEC_CMD_ADD_TXSA,
3323
+ .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
26673324 .doit = macsec_add_txsa,
2668
- .policy = macsec_genl_policy,
26693325 .flags = GENL_ADMIN_PERM,
26703326 },
26713327 {
26723328 .cmd = MACSEC_CMD_DEL_TXSA,
3329
+ .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
26733330 .doit = macsec_del_txsa,
2674
- .policy = macsec_genl_policy,
26753331 .flags = GENL_ADMIN_PERM,
26763332 },
26773333 {
26783334 .cmd = MACSEC_CMD_UPD_TXSA,
3335
+ .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
26793336 .doit = macsec_upd_txsa,
2680
- .policy = macsec_genl_policy,
26813337 .flags = GENL_ADMIN_PERM,
26823338 },
26833339 {
26843340 .cmd = MACSEC_CMD_ADD_RXSA,
3341
+ .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
26853342 .doit = macsec_add_rxsa,
2686
- .policy = macsec_genl_policy,
26873343 .flags = GENL_ADMIN_PERM,
26883344 },
26893345 {
26903346 .cmd = MACSEC_CMD_DEL_RXSA,
3347
+ .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
26913348 .doit = macsec_del_rxsa,
2692
- .policy = macsec_genl_policy,
26933349 .flags = GENL_ADMIN_PERM,
26943350 },
26953351 {
26963352 .cmd = MACSEC_CMD_UPD_RXSA,
3353
+ .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
26973354 .doit = macsec_upd_rxsa,
2698
- .policy = macsec_genl_policy,
3355
+ .flags = GENL_ADMIN_PERM,
3356
+ },
3357
+ {
3358
+ .cmd = MACSEC_CMD_UPD_OFFLOAD,
3359
+ .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
3360
+ .doit = macsec_upd_offload,
26993361 .flags = GENL_ADMIN_PERM,
27003362 },
27013363 };
....@@ -2705,10 +3367,11 @@
27053367 .hdrsize = 0,
27063368 .version = MACSEC_GENL_VERSION,
27073369 .maxattr = MACSEC_ATTR_MAX,
3370
+ .policy = macsec_genl_policy,
27083371 .netnsok = true,
27093372 .module = THIS_MODULE,
2710
- .ops = macsec_genl_ops,
2711
- .n_ops = ARRAY_SIZE(macsec_genl_ops),
3373
+ .small_ops = macsec_genl_ops,
3374
+ .n_small_ops = ARRAY_SIZE(macsec_genl_ops),
27123375 };
27133376
27143377 static netdev_tx_t macsec_start_xmit(struct sk_buff *skb,
....@@ -2718,6 +3381,11 @@
27183381 struct macsec_secy *secy = &macsec->secy;
27193382 struct pcpu_secy_stats *secy_stats;
27203383 int ret, len;
3384
+
3385
+ if (macsec_is_offloaded(netdev_priv(dev))) {
3386
+ skb->dev = macsec->real_dev;
3387
+ return dev_queue_xmit(skb);
3388
+ }
27213389
27223390 /* 10.5 */
27233391 if (!secy->protect_frames) {
....@@ -2756,7 +3424,6 @@
27563424
27573425 #define MACSEC_FEATURES \
27583426 (NETIF_F_SG | NETIF_F_HIGHDMA | NETIF_F_FRAGLIST)
2759
-static struct lock_class_key macsec_netdev_addr_lock_key;
27603427
27613428 static int macsec_dev_init(struct net_device *dev)
27623429 {
....@@ -2833,6 +3500,23 @@
28333500 goto clear_allmulti;
28343501 }
28353502
3503
+ /* If h/w offloading is available, propagate to the device */
3504
+ if (macsec_is_offloaded(macsec)) {
3505
+ const struct macsec_ops *ops;
3506
+ struct macsec_context ctx;
3507
+
3508
+ ops = macsec_get_ops(netdev_priv(dev), &ctx);
3509
+ if (!ops) {
3510
+ err = -EOPNOTSUPP;
3511
+ goto clear_allmulti;
3512
+ }
3513
+
3514
+ ctx.secy = &macsec->secy;
3515
+ err = macsec_offload(ops->mdo_dev_open, &ctx);
3516
+ if (err)
3517
+ goto clear_allmulti;
3518
+ }
3519
+
28363520 if (netif_carrier_ok(real_dev))
28373521 netif_carrier_on(dev);
28383522
....@@ -2852,6 +3536,18 @@
28523536 struct net_device *real_dev = macsec->real_dev;
28533537
28543538 netif_carrier_off(dev);
3539
+
3540
+ /* If h/w offloading is available, propagate to the device */
3541
+ if (macsec_is_offloaded(macsec)) {
3542
+ const struct macsec_ops *ops;
3543
+ struct macsec_context ctx;
3544
+
3545
+ ops = macsec_get_ops(macsec, &ctx);
3546
+ if (ops) {
3547
+ ctx.secy = &macsec->secy;
3548
+ macsec_offload(ops->mdo_dev_stop, &ctx);
3549
+ }
3550
+ }
28553551
28563552 dev_mc_unsync(real_dev, dev);
28573553 dev_uc_unsync(real_dev, dev);
....@@ -2890,11 +3586,6 @@
28903586 dev_uc_sync(real_dev, dev);
28913587 }
28923588
2893
-static sci_t dev_to_sci(struct net_device *dev, __be16 port)
2894
-{
2895
- return make_sci(dev->dev_addr, port);
2896
-}
2897
-
28983589 static int macsec_set_mac_address(struct net_device *dev, void *p)
28993590 {
29003591 struct macsec_dev *macsec = macsec_priv(dev);
....@@ -2917,6 +3608,19 @@
29173608 out:
29183609 ether_addr_copy(dev->dev_addr, addr->sa_data);
29193610 macsec->secy.sci = dev_to_sci(dev, MACSEC_PORT_ES);
3611
+
3612
+ /* If h/w offloading is available, propagate to the device */
3613
+ if (macsec_is_offloaded(macsec)) {
3614
+ const struct macsec_ops *ops;
3615
+ struct macsec_context ctx;
3616
+
3617
+ ops = macsec_get_ops(macsec, &ctx);
3618
+ if (ops) {
3619
+ ctx.secy = &macsec->secy;
3620
+ macsec_offload(ops->mdo_upd_secy, &ctx);
3621
+ }
3622
+ }
3623
+
29203624 return 0;
29213625 }
29223626
....@@ -2936,30 +3640,10 @@
29363640 static void macsec_get_stats64(struct net_device *dev,
29373641 struct rtnl_link_stats64 *s)
29383642 {
2939
- int cpu;
2940
-
29413643 if (!dev->tstats)
29423644 return;
29433645
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
- }
3646
+ dev_fetch_sw_netstats(s, dev->tstats);
29633647
29643648 s->rx_dropped = dev->stats.rx_dropped;
29653649 s->tx_dropped = dev->stats.tx_dropped;
....@@ -2969,13 +3653,6 @@
29693653 {
29703654 return macsec_priv(dev)->real_dev->ifindex;
29713655 }
2972
-
2973
-
2974
-static int macsec_get_nest_level(struct net_device *dev)
2975
-{
2976
- return macsec_priv(dev)->nest_level;
2977
-}
2978
-
29793656
29803657 static const struct net_device_ops macsec_netdev_ops = {
29813658 .ndo_init = macsec_dev_init,
....@@ -2990,7 +3667,6 @@
29903667 .ndo_start_xmit = macsec_start_xmit,
29913668 .ndo_get_stats64 = macsec_get_stats64,
29923669 .ndo_get_iflink = macsec_get_iflink,
2993
- .ndo_get_lock_subclass = macsec_get_nest_level,
29943670 };
29953671
29963672 static const struct device_type macsec_type = {
....@@ -3011,6 +3687,7 @@
30113687 [IFLA_MACSEC_SCB] = { .type = NLA_U8 },
30123688 [IFLA_MACSEC_REPLAY_PROTECT] = { .type = NLA_U8 },
30133689 [IFLA_MACSEC_VALIDATION] = { .type = NLA_U8 },
3690
+ [IFLA_MACSEC_OFFLOAD] = { .type = NLA_U8 },
30143691 };
30153692
30163693 static void macsec_free_netdev(struct net_device *dev)
....@@ -3054,9 +3731,6 @@
30543731 secy->operational = tx_sa && tx_sa->active;
30553732 }
30563733
3057
- if (data[IFLA_MACSEC_WINDOW])
3058
- secy->replay_window = nla_get_u32(data[IFLA_MACSEC_WINDOW]);
3059
-
30603734 if (data[IFLA_MACSEC_ENCRYPT])
30613735 tx_sc->encrypt = !!nla_get_u8(data[IFLA_MACSEC_ENCRYPT]);
30623736
....@@ -3083,13 +3757,33 @@
30833757 case MACSEC_CIPHER_ID_GCM_AES_128:
30843758 case MACSEC_DEFAULT_CIPHER_ID:
30853759 secy->key_len = MACSEC_GCM_AES_128_SAK_LEN;
3760
+ secy->xpn = false;
30863761 break;
30873762 case MACSEC_CIPHER_ID_GCM_AES_256:
30883763 secy->key_len = MACSEC_GCM_AES_256_SAK_LEN;
3764
+ secy->xpn = false;
3765
+ break;
3766
+ case MACSEC_CIPHER_ID_GCM_AES_XPN_128:
3767
+ secy->key_len = MACSEC_GCM_AES_128_SAK_LEN;
3768
+ secy->xpn = true;
3769
+ break;
3770
+ case MACSEC_CIPHER_ID_GCM_AES_XPN_256:
3771
+ secy->key_len = MACSEC_GCM_AES_256_SAK_LEN;
3772
+ secy->xpn = true;
30893773 break;
30903774 default:
30913775 return -EINVAL;
30923776 }
3777
+ }
3778
+
3779
+ if (data[IFLA_MACSEC_WINDOW]) {
3780
+ secy->replay_window = nla_get_u32(data[IFLA_MACSEC_WINDOW]);
3781
+
3782
+ /* IEEE 802.1AEbw-2013 10.7.8 - maximum replay window
3783
+ * for XPN cipher suites */
3784
+ if (secy->xpn &&
3785
+ secy->replay_window > MACSEC_XPN_MAX_REPLAY_WINDOW)
3786
+ return -EINVAL;
30933787 }
30943788
30953789 return 0;
....@@ -3099,6 +3793,11 @@
30993793 struct nlattr *data[],
31003794 struct netlink_ext_ack *extack)
31013795 {
3796
+ struct macsec_dev *macsec = macsec_priv(dev);
3797
+ struct macsec_tx_sc tx_sc;
3798
+ struct macsec_secy secy;
3799
+ int ret;
3800
+
31023801 if (!data)
31033802 return 0;
31043803
....@@ -3108,7 +3807,40 @@
31083807 data[IFLA_MACSEC_PORT])
31093808 return -EINVAL;
31103809
3111
- return macsec_changelink_common(dev, data);
3810
+ /* Keep a copy of unmodified secy and tx_sc, in case the offload
3811
+ * propagation fails, to revert macsec_changelink_common.
3812
+ */
3813
+ memcpy(&secy, &macsec->secy, sizeof(secy));
3814
+ memcpy(&tx_sc, &macsec->secy.tx_sc, sizeof(tx_sc));
3815
+
3816
+ ret = macsec_changelink_common(dev, data);
3817
+ if (ret)
3818
+ goto cleanup;
3819
+
3820
+ /* If h/w offloading is available, propagate to the device */
3821
+ if (macsec_is_offloaded(macsec)) {
3822
+ const struct macsec_ops *ops;
3823
+ struct macsec_context ctx;
3824
+
3825
+ ops = macsec_get_ops(netdev_priv(dev), &ctx);
3826
+ if (!ops) {
3827
+ ret = -EOPNOTSUPP;
3828
+ goto cleanup;
3829
+ }
3830
+
3831
+ ctx.secy = &macsec->secy;
3832
+ ret = macsec_offload(ops->mdo_upd_secy, &ctx);
3833
+ if (ret)
3834
+ goto cleanup;
3835
+ }
3836
+
3837
+ return 0;
3838
+
3839
+cleanup:
3840
+ memcpy(&macsec->secy.tx_sc, &tx_sc, sizeof(tx_sc));
3841
+ memcpy(&macsec->secy, &secy, sizeof(secy));
3842
+
3843
+ return ret;
31123844 }
31133845
31143846 static void macsec_del_dev(struct macsec_dev *macsec)
....@@ -3136,6 +3868,18 @@
31363868 {
31373869 struct macsec_dev *macsec = macsec_priv(dev);
31383870 struct net_device *real_dev = macsec->real_dev;
3871
+
3872
+ /* If h/w offloading is available, propagate to the device */
3873
+ if (macsec_is_offloaded(macsec)) {
3874
+ const struct macsec_ops *ops;
3875
+ struct macsec_context ctx;
3876
+
3877
+ ops = macsec_get_ops(netdev_priv(dev), &ctx);
3878
+ if (ops) {
3879
+ ctx.secy = &macsec->secy;
3880
+ macsec_offload(ops->mdo_del_secy, &ctx);
3881
+ }
3882
+ }
31393883
31403884 unregister_netdevice_queue(dev, head);
31413885 list_del_rcu(&macsec->secys);
....@@ -3224,6 +3968,7 @@
32243968 secy->validate_frames = MACSEC_VALIDATE_DEFAULT;
32253969 secy->protect_frames = true;
32263970 secy->replay_protect = false;
3971
+ secy->xpn = DEFAULT_XPN;
32273972
32283973 secy->sci = sci;
32293974 secy->tx_sc.active = true;
....@@ -3235,6 +3980,8 @@
32353980
32363981 return 0;
32373982 }
3983
+
3984
+static struct lock_class_key macsec_netdev_addr_lock_key;
32383985
32393986 static int macsec_newlink(struct net *net, struct net_device *dev,
32403987 struct nlattr *tb[], struct nlattr *data[],
....@@ -3258,6 +4005,17 @@
32584005 dev->priv_flags |= IFF_MACSEC;
32594006
32604007 macsec->real_dev = real_dev;
4008
+
4009
+ if (data && data[IFLA_MACSEC_OFFLOAD])
4010
+ macsec->offload = nla_get_offload(data[IFLA_MACSEC_OFFLOAD]);
4011
+ else
4012
+ /* MACsec offloading is off by default */
4013
+ macsec->offload = MACSEC_OFFLOAD_OFF;
4014
+
4015
+ /* Check if the offloading mode is supported by the underlying layers */
4016
+ if (macsec->offload != MACSEC_OFFLOAD_OFF &&
4017
+ !macsec_check_offload(macsec->offload, macsec))
4018
+ return -EOPNOTSUPP;
32614019
32624020 /* send_sci must be set to true when transmit sci explicitly is set */
32634021 if ((data && data[IFLA_MACSEC_SCI]) &&
....@@ -3284,11 +4042,9 @@
32844042 if (err < 0)
32854043 return err;
32864044
3287
- macsec->nest_level = dev_get_nest_level(real_dev) + 1;
32884045 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));
4046
+ lockdep_set_class(&dev->addr_list_lock,
4047
+ &macsec_netdev_addr_lock_key);
32924048
32934049 err = netdev_upper_dev_link(real_dev, dev, extack);
32944050 if (err < 0)
....@@ -3317,6 +4073,20 @@
33174073 err = macsec_changelink_common(dev, data);
33184074 if (err)
33194075 goto del_dev;
4076
+ }
4077
+
4078
+ /* If h/w offloading is available, propagate to the device */
4079
+ if (macsec_is_offloaded(macsec)) {
4080
+ const struct macsec_ops *ops;
4081
+ struct macsec_context ctx;
4082
+
4083
+ ops = macsec_get_ops(macsec, &ctx);
4084
+ if (ops) {
4085
+ ctx.secy = &macsec->secy;
4086
+ err = macsec_offload(ops->mdo_add_secy, &ctx);
4087
+ if (err)
4088
+ goto del_dev;
4089
+ }
33204090 }
33214091
33224092 err = register_macsec_dev(real_dev, dev);
....@@ -3371,6 +4141,8 @@
33714141 switch (csid) {
33724142 case MACSEC_CIPHER_ID_GCM_AES_128:
33734143 case MACSEC_CIPHER_ID_GCM_AES_256:
4144
+ case MACSEC_CIPHER_ID_GCM_AES_XPN_128:
4145
+ case MACSEC_CIPHER_ID_GCM_AES_XPN_256:
33744146 case MACSEC_DEFAULT_CIPHER_ID:
33754147 if (icv_len < MACSEC_MIN_ICV_LEN ||
33764148 icv_len > MACSEC_STD_ICV_LEN)
....@@ -3444,10 +4216,10 @@
34444216
34454217 switch (secy->key_len) {
34464218 case MACSEC_GCM_AES_128_SAK_LEN:
3447
- csid = MACSEC_DEFAULT_CIPHER_ID;
4219
+ csid = secy->xpn ? MACSEC_CIPHER_ID_GCM_AES_XPN_128 : MACSEC_DEFAULT_CIPHER_ID;
34484220 break;
34494221 case MACSEC_GCM_AES_256_SAK_LEN:
3450
- csid = MACSEC_CIPHER_ID_GCM_AES_256;
4222
+ csid = secy->xpn ? MACSEC_CIPHER_ID_GCM_AES_XPN_256 : MACSEC_CIPHER_ID_GCM_AES_256;
34514223 break;
34524224 default:
34534225 goto nla_put_failure;