blob: 204d8218893a2ae7681daf41df61397ce18e9fd0 [file] [log] [blame]
developer7e32f7e2022-05-18 21:10:08 +08001From c0e4eadfb8daf2e9557c7450f9b237c08b404419 Mon Sep 17 00:00:00 2001
2From: Antoine Tenart <antoine.tenart@bootlin.com>
3Date: Mon, 13 Jan 2020 23:31:39 +0100
4Subject: net: macsec: move some definitions in a dedicated header
5
6This patch moves some structure, type and identifier definitions into a
7MACsec specific header. This patch does not modify how the MACsec code
8is running and only move things around. This is a preparation for the
9future MACsec hardware offloading support, which will re-use those
10definitions outside macsec.c.
11
12Signed-off-by: Antoine Tenart <antoine.tenart@bootlin.com>
13Signed-off-by: David S. Miller <davem@davemloft.net>
14---
15 drivers/net/macsec.c | 164 +----------------------------------------------
16 include/net/macsec.h | 177 +++++++++++++++++++++++++++++++++++++++++++++++++++
17 2 files changed, 178 insertions(+), 163 deletions(-)
18 create mode 100644 include/net/macsec.h
19
20diff --git a/drivers/net/macsec.c b/drivers/net/macsec.c
21index afd8b2a082454..a336eee018f0b 100644
22--- a/drivers/net/macsec.c
23+++ b/drivers/net/macsec.c
24@@ -16,11 +16,10 @@
25 #include <net/genetlink.h>
26 #include <net/sock.h>
27 #include <net/gro_cells.h>
28+#include <net/macsec.h>
29
30 #include <uapi/linux/if_macsec.h>
31
32-typedef u64 __bitwise sci_t;
33-
34 #define MACSEC_SCI_LEN 8
35
36 /* SecTAG length = macsec_eth_header without the optional SCI */
37@@ -58,8 +57,6 @@ struct macsec_eth_header {
38 #define GCM_AES_IV_LEN 12
39 #define DEFAULT_ICV_LEN 16
40
41-#define MACSEC_NUM_AN 4 /* 2 bits for the association number */
42-
43 #define for_each_rxsc(secy, sc) \
44 for (sc = rcu_dereference_bh(secy->rx_sc); \
45 sc; \
46@@ -77,49 +74,6 @@ struct gcm_iv {
47 __be32 pn;
48 };
49
50-/**
51- * struct macsec_key - SA key
52- * @id: user-provided key identifier
53- * @tfm: crypto struct, key storage
54- */
55-struct macsec_key {
56- u8 id[MACSEC_KEYID_LEN];
57- struct crypto_aead *tfm;
58-};
59-
60-struct macsec_rx_sc_stats {
61- __u64 InOctetsValidated;
62- __u64 InOctetsDecrypted;
63- __u64 InPktsUnchecked;
64- __u64 InPktsDelayed;
65- __u64 InPktsOK;
66- __u64 InPktsInvalid;
67- __u64 InPktsLate;
68- __u64 InPktsNotValid;
69- __u64 InPktsNotUsingSA;
70- __u64 InPktsUnusedSA;
71-};
72-
73-struct macsec_rx_sa_stats {
74- __u32 InPktsOK;
75- __u32 InPktsInvalid;
76- __u32 InPktsNotValid;
77- __u32 InPktsNotUsingSA;
78- __u32 InPktsUnusedSA;
79-};
80-
81-struct macsec_tx_sa_stats {
82- __u32 OutPktsProtected;
83- __u32 OutPktsEncrypted;
84-};
85-
86-struct macsec_tx_sc_stats {
87- __u64 OutPktsProtected;
88- __u64 OutPktsEncrypted;
89- __u64 OutOctetsProtected;
90- __u64 OutOctetsEncrypted;
91-};
92-
93 struct macsec_dev_stats {
94 __u64 OutPktsUntagged;
95 __u64 InPktsUntagged;
96@@ -131,124 +85,8 @@ struct macsec_dev_stats {
97 __u64 InPktsOverrun;
98 };
99
100-/**
101- * struct macsec_rx_sa - receive secure association
102- * @active:
103- * @next_pn: packet number expected for the next packet
104- * @lock: protects next_pn manipulations
105- * @key: key structure
106- * @stats: per-SA stats
107- */
108-struct macsec_rx_sa {
109- struct macsec_key key;
110- spinlock_t lock;
111- u32 next_pn;
112- refcount_t refcnt;
113- bool active;
114- struct macsec_rx_sa_stats __percpu *stats;
115- struct macsec_rx_sc *sc;
116- struct rcu_head rcu;
117-};
118-
119-struct pcpu_rx_sc_stats {
120- struct macsec_rx_sc_stats stats;
121- struct u64_stats_sync syncp;
122-};
123-
124-/**
125- * struct macsec_rx_sc - receive secure channel
126- * @sci: secure channel identifier for this SC
127- * @active: channel is active
128- * @sa: array of secure associations
129- * @stats: per-SC stats
130- */
131-struct macsec_rx_sc {
132- struct macsec_rx_sc __rcu *next;
133- sci_t sci;
134- bool active;
135- struct macsec_rx_sa __rcu *sa[MACSEC_NUM_AN];
136- struct pcpu_rx_sc_stats __percpu *stats;
137- refcount_t refcnt;
138- struct rcu_head rcu_head;
139-};
140-
141-/**
142- * struct macsec_tx_sa - transmit secure association
143- * @active:
144- * @next_pn: packet number to use for the next packet
145- * @lock: protects next_pn manipulations
146- * @key: key structure
147- * @stats: per-SA stats
148- */
149-struct macsec_tx_sa {
150- struct macsec_key key;
151- spinlock_t lock;
152- u32 next_pn;
153- refcount_t refcnt;
154- bool active;
155- struct macsec_tx_sa_stats __percpu *stats;
156- struct rcu_head rcu;
157-};
158-
159-struct pcpu_tx_sc_stats {
160- struct macsec_tx_sc_stats stats;
161- struct u64_stats_sync syncp;
162-};
163-
164-/**
165- * struct macsec_tx_sc - transmit secure channel
166- * @active:
167- * @encoding_sa: association number of the SA currently in use
168- * @encrypt: encrypt packets on transmit, or authenticate only
169- * @send_sci: always include the SCI in the SecTAG
170- * @end_station:
171- * @scb: single copy broadcast flag
172- * @sa: array of secure associations
173- * @stats: stats for this TXSC
174- */
175-struct macsec_tx_sc {
176- bool active;
177- u8 encoding_sa;
178- bool encrypt;
179- bool send_sci;
180- bool end_station;
181- bool scb;
182- struct macsec_tx_sa __rcu *sa[MACSEC_NUM_AN];
183- struct pcpu_tx_sc_stats __percpu *stats;
184-};
185-
186 #define MACSEC_VALIDATE_DEFAULT MACSEC_VALIDATE_STRICT
187
188-/**
189- * struct macsec_secy - MACsec Security Entity
190- * @netdev: netdevice for this SecY
191- * @n_rx_sc: number of receive secure channels configured on this SecY
192- * @sci: secure channel identifier used for tx
193- * @key_len: length of keys used by the cipher suite
194- * @icv_len: length of ICV used by the cipher suite
195- * @validate_frames: validation mode
196- * @operational: MAC_Operational flag
197- * @protect_frames: enable protection for this SecY
198- * @replay_protect: enable packet number checks on receive
199- * @replay_window: size of the replay window
200- * @tx_sc: transmit secure channel
201- * @rx_sc: linked list of receive secure channels
202- */
203-struct macsec_secy {
204- struct net_device *netdev;
205- unsigned int n_rx_sc;
206- sci_t sci;
207- u16 key_len;
208- u16 icv_len;
209- enum macsec_validation_type validate_frames;
210- bool operational;
211- bool protect_frames;
212- bool replay_protect;
213- u32 replay_window;
214- struct macsec_tx_sc tx_sc;
215- struct macsec_rx_sc __rcu *rx_sc;
216-};
217-
218 struct pcpu_secy_stats {
219 struct macsec_dev_stats stats;
220 struct u64_stats_sync syncp;
221diff --git a/include/net/macsec.h b/include/net/macsec.h
222new file mode 100644
223index 0000000000000..e7b41c1043f6f
224--- /dev/null
225+++ b/include/net/macsec.h
226@@ -0,0 +1,177 @@
227+/* SPDX-License-Identifier: GPL-2.0+ */
228+/*
229+ * MACsec netdev header, used for h/w accelerated implementations.
230+ *
231+ * Copyright (c) 2015 Sabrina Dubroca <sd@queasysnail.net>
232+ */
233+#ifndef _NET_MACSEC_H_
234+#define _NET_MACSEC_H_
235+
236+#include <linux/u64_stats_sync.h>
237+#include <uapi/linux/if_link.h>
238+#include <uapi/linux/if_macsec.h>
239+
240+typedef u64 __bitwise sci_t;
241+
242+#define MACSEC_NUM_AN 4 /* 2 bits for the association number */
243+
244+/**
245+ * struct macsec_key - SA key
246+ * @id: user-provided key identifier
247+ * @tfm: crypto struct, key storage
248+ */
249+struct macsec_key {
250+ u8 id[MACSEC_KEYID_LEN];
251+ struct crypto_aead *tfm;
252+};
253+
254+struct macsec_rx_sc_stats {
255+ __u64 InOctetsValidated;
256+ __u64 InOctetsDecrypted;
257+ __u64 InPktsUnchecked;
258+ __u64 InPktsDelayed;
259+ __u64 InPktsOK;
260+ __u64 InPktsInvalid;
261+ __u64 InPktsLate;
262+ __u64 InPktsNotValid;
263+ __u64 InPktsNotUsingSA;
264+ __u64 InPktsUnusedSA;
265+};
266+
267+struct macsec_rx_sa_stats {
268+ __u32 InPktsOK;
269+ __u32 InPktsInvalid;
270+ __u32 InPktsNotValid;
271+ __u32 InPktsNotUsingSA;
272+ __u32 InPktsUnusedSA;
273+};
274+
275+struct macsec_tx_sa_stats {
276+ __u32 OutPktsProtected;
277+ __u32 OutPktsEncrypted;
278+};
279+
280+struct macsec_tx_sc_stats {
281+ __u64 OutPktsProtected;
282+ __u64 OutPktsEncrypted;
283+ __u64 OutOctetsProtected;
284+ __u64 OutOctetsEncrypted;
285+};
286+
287+/**
288+ * struct macsec_rx_sa - receive secure association
289+ * @active:
290+ * @next_pn: packet number expected for the next packet
291+ * @lock: protects next_pn manipulations
292+ * @key: key structure
293+ * @stats: per-SA stats
294+ */
295+struct macsec_rx_sa {
296+ struct macsec_key key;
297+ spinlock_t lock;
298+ u32 next_pn;
299+ refcount_t refcnt;
300+ bool active;
301+ struct macsec_rx_sa_stats __percpu *stats;
302+ struct macsec_rx_sc *sc;
303+ struct rcu_head rcu;
304+};
305+
306+struct pcpu_rx_sc_stats {
307+ struct macsec_rx_sc_stats stats;
308+ struct u64_stats_sync syncp;
309+};
310+
311+struct pcpu_tx_sc_stats {
312+ struct macsec_tx_sc_stats stats;
313+ struct u64_stats_sync syncp;
314+};
315+
316+/**
317+ * struct macsec_rx_sc - receive secure channel
318+ * @sci: secure channel identifier for this SC
319+ * @active: channel is active
320+ * @sa: array of secure associations
321+ * @stats: per-SC stats
322+ */
323+struct macsec_rx_sc {
324+ struct macsec_rx_sc __rcu *next;
325+ sci_t sci;
326+ bool active;
327+ struct macsec_rx_sa __rcu *sa[MACSEC_NUM_AN];
328+ struct pcpu_rx_sc_stats __percpu *stats;
329+ refcount_t refcnt;
330+ struct rcu_head rcu_head;
331+};
332+
333+/**
334+ * struct macsec_tx_sa - transmit secure association
335+ * @active:
336+ * @next_pn: packet number to use for the next packet
337+ * @lock: protects next_pn manipulations
338+ * @key: key structure
339+ * @stats: per-SA stats
340+ */
341+struct macsec_tx_sa {
342+ struct macsec_key key;
343+ spinlock_t lock;
344+ u32 next_pn;
345+ refcount_t refcnt;
346+ bool active;
347+ struct macsec_tx_sa_stats __percpu *stats;
348+ struct rcu_head rcu;
349+};
350+
351+/**
352+ * struct macsec_tx_sc - transmit secure channel
353+ * @active:
354+ * @encoding_sa: association number of the SA currently in use
355+ * @encrypt: encrypt packets on transmit, or authenticate only
356+ * @send_sci: always include the SCI in the SecTAG
357+ * @end_station:
358+ * @scb: single copy broadcast flag
359+ * @sa: array of secure associations
360+ * @stats: stats for this TXSC
361+ */
362+struct macsec_tx_sc {
363+ bool active;
364+ u8 encoding_sa;
365+ bool encrypt;
366+ bool send_sci;
367+ bool end_station;
368+ bool scb;
369+ struct macsec_tx_sa __rcu *sa[MACSEC_NUM_AN];
370+ struct pcpu_tx_sc_stats __percpu *stats;
371+};
372+
373+/**
374+ * struct macsec_secy - MACsec Security Entity
375+ * @netdev: netdevice for this SecY
376+ * @n_rx_sc: number of receive secure channels configured on this SecY
377+ * @sci: secure channel identifier used for tx
378+ * @key_len: length of keys used by the cipher suite
379+ * @icv_len: length of ICV used by the cipher suite
380+ * @validate_frames: validation mode
381+ * @operational: MAC_Operational flag
382+ * @protect_frames: enable protection for this SecY
383+ * @replay_protect: enable packet number checks on receive
384+ * @replay_window: size of the replay window
385+ * @tx_sc: transmit secure channel
386+ * @rx_sc: linked list of receive secure channels
387+ */
388+struct macsec_secy {
389+ struct net_device *netdev;
390+ unsigned int n_rx_sc;
391+ sci_t sci;
392+ u16 key_len;
393+ u16 icv_len;
394+ enum macsec_validation_type validate_frames;
395+ bool operational;
396+ bool protect_frames;
397+ bool replay_protect;
398+ u32 replay_window;
399+ struct macsec_tx_sc tx_sc;
400+ struct macsec_rx_sc __rcu *rx_sc;
401+};
402+
403+#endif /* _NET_MACSEC_H_ */
404--
405cgit 1.2.3-1.el7
406