Skip to content

Commit c0e4ead

Browse files
atenartdavem330
authored andcommitted
net: macsec: move some definitions in a dedicated header
This patch moves some structure, type and identifier definitions into a MACsec specific header. This patch does not modify how the MACsec code is running and only move things around. This is a preparation for the future MACsec hardware offloading support, which will re-use those definitions outside macsec.c. Signed-off-by: Antoine Tenart <antoine.tenart@bootlin.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 169af34 commit c0e4ead

File tree

2 files changed

+178
-163
lines changed

2 files changed

+178
-163
lines changed

drivers/net/macsec.c

Lines changed: 1 addition & 163 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,10 @@
1616
#include <net/genetlink.h>
1717
#include <net/sock.h>
1818
#include <net/gro_cells.h>
19+
#include <net/macsec.h>
1920

2021
#include <uapi/linux/if_macsec.h>
2122

22-
typedef u64 __bitwise sci_t;
23-
2423
#define MACSEC_SCI_LEN 8
2524

2625
/* SecTAG length = macsec_eth_header without the optional SCI */
@@ -58,8 +57,6 @@ struct macsec_eth_header {
5857
#define GCM_AES_IV_LEN 12
5958
#define DEFAULT_ICV_LEN 16
6059

61-
#define MACSEC_NUM_AN 4 /* 2 bits for the association number */
62-
6360
#define for_each_rxsc(secy, sc) \
6461
for (sc = rcu_dereference_bh(secy->rx_sc); \
6562
sc; \
@@ -77,49 +74,6 @@ struct gcm_iv {
7774
__be32 pn;
7875
};
7976

80-
/**
81-
* struct macsec_key - SA key
82-
* @id: user-provided key identifier
83-
* @tfm: crypto struct, key storage
84-
*/
85-
struct macsec_key {
86-
u8 id[MACSEC_KEYID_LEN];
87-
struct crypto_aead *tfm;
88-
};
89-
90-
struct macsec_rx_sc_stats {
91-
__u64 InOctetsValidated;
92-
__u64 InOctetsDecrypted;
93-
__u64 InPktsUnchecked;
94-
__u64 InPktsDelayed;
95-
__u64 InPktsOK;
96-
__u64 InPktsInvalid;
97-
__u64 InPktsLate;
98-
__u64 InPktsNotValid;
99-
__u64 InPktsNotUsingSA;
100-
__u64 InPktsUnusedSA;
101-
};
102-
103-
struct macsec_rx_sa_stats {
104-
__u32 InPktsOK;
105-
__u32 InPktsInvalid;
106-
__u32 InPktsNotValid;
107-
__u32 InPktsNotUsingSA;
108-
__u32 InPktsUnusedSA;
109-
};
110-
111-
struct macsec_tx_sa_stats {
112-
__u32 OutPktsProtected;
113-
__u32 OutPktsEncrypted;
114-
};
115-
116-
struct macsec_tx_sc_stats {
117-
__u64 OutPktsProtected;
118-
__u64 OutPktsEncrypted;
119-
__u64 OutOctetsProtected;
120-
__u64 OutOctetsEncrypted;
121-
};
122-
12377
struct macsec_dev_stats {
12478
__u64 OutPktsUntagged;
12579
__u64 InPktsUntagged;
@@ -131,124 +85,8 @@ struct macsec_dev_stats {
13185
__u64 InPktsOverrun;
13286
};
13387

134-
/**
135-
* struct macsec_rx_sa - receive secure association
136-
* @active:
137-
* @next_pn: packet number expected for the next packet
138-
* @lock: protects next_pn manipulations
139-
* @key: key structure
140-
* @stats: per-SA stats
141-
*/
142-
struct macsec_rx_sa {
143-
struct macsec_key key;
144-
spinlock_t lock;
145-
u32 next_pn;
146-
refcount_t refcnt;
147-
bool active;
148-
struct macsec_rx_sa_stats __percpu *stats;
149-
struct macsec_rx_sc *sc;
150-
struct rcu_head rcu;
151-
};
152-
153-
struct pcpu_rx_sc_stats {
154-
struct macsec_rx_sc_stats stats;
155-
struct u64_stats_sync syncp;
156-
};
157-
158-
/**
159-
* struct macsec_rx_sc - receive secure channel
160-
* @sci: secure channel identifier for this SC
161-
* @active: channel is active
162-
* @sa: array of secure associations
163-
* @stats: per-SC stats
164-
*/
165-
struct macsec_rx_sc {
166-
struct macsec_rx_sc __rcu *next;
167-
sci_t sci;
168-
bool active;
169-
struct macsec_rx_sa __rcu *sa[MACSEC_NUM_AN];
170-
struct pcpu_rx_sc_stats __percpu *stats;
171-
refcount_t refcnt;
172-
struct rcu_head rcu_head;
173-
};
174-
175-
/**
176-
* struct macsec_tx_sa - transmit secure association
177-
* @active:
178-
* @next_pn: packet number to use for the next packet
179-
* @lock: protects next_pn manipulations
180-
* @key: key structure
181-
* @stats: per-SA stats
182-
*/
183-
struct macsec_tx_sa {
184-
struct macsec_key key;
185-
spinlock_t lock;
186-
u32 next_pn;
187-
refcount_t refcnt;
188-
bool active;
189-
struct macsec_tx_sa_stats __percpu *stats;
190-
struct rcu_head rcu;
191-
};
192-
193-
struct pcpu_tx_sc_stats {
194-
struct macsec_tx_sc_stats stats;
195-
struct u64_stats_sync syncp;
196-
};
197-
198-
/**
199-
* struct macsec_tx_sc - transmit secure channel
200-
* @active:
201-
* @encoding_sa: association number of the SA currently in use
202-
* @encrypt: encrypt packets on transmit, or authenticate only
203-
* @send_sci: always include the SCI in the SecTAG
204-
* @end_station:
205-
* @scb: single copy broadcast flag
206-
* @sa: array of secure associations
207-
* @stats: stats for this TXSC
208-
*/
209-
struct macsec_tx_sc {
210-
bool active;
211-
u8 encoding_sa;
212-
bool encrypt;
213-
bool send_sci;
214-
bool end_station;
215-
bool scb;
216-
struct macsec_tx_sa __rcu *sa[MACSEC_NUM_AN];
217-
struct pcpu_tx_sc_stats __percpu *stats;
218-
};
219-
22088
#define MACSEC_VALIDATE_DEFAULT MACSEC_VALIDATE_STRICT
22189

222-
/**
223-
* struct macsec_secy - MACsec Security Entity
224-
* @netdev: netdevice for this SecY
225-
* @n_rx_sc: number of receive secure channels configured on this SecY
226-
* @sci: secure channel identifier used for tx
227-
* @key_len: length of keys used by the cipher suite
228-
* @icv_len: length of ICV used by the cipher suite
229-
* @validate_frames: validation mode
230-
* @operational: MAC_Operational flag
231-
* @protect_frames: enable protection for this SecY
232-
* @replay_protect: enable packet number checks on receive
233-
* @replay_window: size of the replay window
234-
* @tx_sc: transmit secure channel
235-
* @rx_sc: linked list of receive secure channels
236-
*/
237-
struct macsec_secy {
238-
struct net_device *netdev;
239-
unsigned int n_rx_sc;
240-
sci_t sci;
241-
u16 key_len;
242-
u16 icv_len;
243-
enum macsec_validation_type validate_frames;
244-
bool operational;
245-
bool protect_frames;
246-
bool replay_protect;
247-
u32 replay_window;
248-
struct macsec_tx_sc tx_sc;
249-
struct macsec_rx_sc __rcu *rx_sc;
250-
};
251-
25290
struct pcpu_secy_stats {
25391
struct macsec_dev_stats stats;
25492
struct u64_stats_sync syncp;

include/net/macsec.h

Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
/* SPDX-License-Identifier: GPL-2.0+ */
2+
/*
3+
* MACsec netdev header, used for h/w accelerated implementations.
4+
*
5+
* Copyright (c) 2015 Sabrina Dubroca <sd@queasysnail.net>
6+
*/
7+
#ifndef _NET_MACSEC_H_
8+
#define _NET_MACSEC_H_
9+
10+
#include <linux/u64_stats_sync.h>
11+
#include <uapi/linux/if_link.h>
12+
#include <uapi/linux/if_macsec.h>
13+
14+
typedef u64 __bitwise sci_t;
15+
16+
#define MACSEC_NUM_AN 4 /* 2 bits for the association number */
17+
18+
/**
19+
* struct macsec_key - SA key
20+
* @id: user-provided key identifier
21+
* @tfm: crypto struct, key storage
22+
*/
23+
struct macsec_key {
24+
u8 id[MACSEC_KEYID_LEN];
25+
struct crypto_aead *tfm;
26+
};
27+
28+
struct macsec_rx_sc_stats {
29+
__u64 InOctetsValidated;
30+
__u64 InOctetsDecrypted;
31+
__u64 InPktsUnchecked;
32+
__u64 InPktsDelayed;
33+
__u64 InPktsOK;
34+
__u64 InPktsInvalid;
35+
__u64 InPktsLate;
36+
__u64 InPktsNotValid;
37+
__u64 InPktsNotUsingSA;
38+
__u64 InPktsUnusedSA;
39+
};
40+
41+
struct macsec_rx_sa_stats {
42+
__u32 InPktsOK;
43+
__u32 InPktsInvalid;
44+
__u32 InPktsNotValid;
45+
__u32 InPktsNotUsingSA;
46+
__u32 InPktsUnusedSA;
47+
};
48+
49+
struct macsec_tx_sa_stats {
50+
__u32 OutPktsProtected;
51+
__u32 OutPktsEncrypted;
52+
};
53+
54+
struct macsec_tx_sc_stats {
55+
__u64 OutPktsProtected;
56+
__u64 OutPktsEncrypted;
57+
__u64 OutOctetsProtected;
58+
__u64 OutOctetsEncrypted;
59+
};
60+
61+
/**
62+
* struct macsec_rx_sa - receive secure association
63+
* @active:
64+
* @next_pn: packet number expected for the next packet
65+
* @lock: protects next_pn manipulations
66+
* @key: key structure
67+
* @stats: per-SA stats
68+
*/
69+
struct macsec_rx_sa {
70+
struct macsec_key key;
71+
spinlock_t lock;
72+
u32 next_pn;
73+
refcount_t refcnt;
74+
bool active;
75+
struct macsec_rx_sa_stats __percpu *stats;
76+
struct macsec_rx_sc *sc;
77+
struct rcu_head rcu;
78+
};
79+
80+
struct pcpu_rx_sc_stats {
81+
struct macsec_rx_sc_stats stats;
82+
struct u64_stats_sync syncp;
83+
};
84+
85+
struct pcpu_tx_sc_stats {
86+
struct macsec_tx_sc_stats stats;
87+
struct u64_stats_sync syncp;
88+
};
89+
90+
/**
91+
* struct macsec_rx_sc - receive secure channel
92+
* @sci: secure channel identifier for this SC
93+
* @active: channel is active
94+
* @sa: array of secure associations
95+
* @stats: per-SC stats
96+
*/
97+
struct macsec_rx_sc {
98+
struct macsec_rx_sc __rcu *next;
99+
sci_t sci;
100+
bool active;
101+
struct macsec_rx_sa __rcu *sa[MACSEC_NUM_AN];
102+
struct pcpu_rx_sc_stats __percpu *stats;
103+
refcount_t refcnt;
104+
struct rcu_head rcu_head;
105+
};
106+
107+
/**
108+
* struct macsec_tx_sa - transmit secure association
109+
* @active:
110+
* @next_pn: packet number to use for the next packet
111+
* @lock: protects next_pn manipulations
112+
* @key: key structure
113+
* @stats: per-SA stats
114+
*/
115+
struct macsec_tx_sa {
116+
struct macsec_key key;
117+
spinlock_t lock;
118+
u32 next_pn;
119+
refcount_t refcnt;
120+
bool active;
121+
struct macsec_tx_sa_stats __percpu *stats;
122+
struct rcu_head rcu;
123+
};
124+
125+
/**
126+
* struct macsec_tx_sc - transmit secure channel
127+
* @active:
128+
* @encoding_sa: association number of the SA currently in use
129+
* @encrypt: encrypt packets on transmit, or authenticate only
130+
* @send_sci: always include the SCI in the SecTAG
131+
* @end_station:
132+
* @scb: single copy broadcast flag
133+
* @sa: array of secure associations
134+
* @stats: stats for this TXSC
135+
*/
136+
struct macsec_tx_sc {
137+
bool active;
138+
u8 encoding_sa;
139+
bool encrypt;
140+
bool send_sci;
141+
bool end_station;
142+
bool scb;
143+
struct macsec_tx_sa __rcu *sa[MACSEC_NUM_AN];
144+
struct pcpu_tx_sc_stats __percpu *stats;
145+
};
146+
147+
/**
148+
* struct macsec_secy - MACsec Security Entity
149+
* @netdev: netdevice for this SecY
150+
* @n_rx_sc: number of receive secure channels configured on this SecY
151+
* @sci: secure channel identifier used for tx
152+
* @key_len: length of keys used by the cipher suite
153+
* @icv_len: length of ICV used by the cipher suite
154+
* @validate_frames: validation mode
155+
* @operational: MAC_Operational flag
156+
* @protect_frames: enable protection for this SecY
157+
* @replay_protect: enable packet number checks on receive
158+
* @replay_window: size of the replay window
159+
* @tx_sc: transmit secure channel
160+
* @rx_sc: linked list of receive secure channels
161+
*/
162+
struct macsec_secy {
163+
struct net_device *netdev;
164+
unsigned int n_rx_sc;
165+
sci_t sci;
166+
u16 key_len;
167+
u16 icv_len;
168+
enum macsec_validation_type validate_frames;
169+
bool operational;
170+
bool protect_frames;
171+
bool replay_protect;
172+
u32 replay_window;
173+
struct macsec_tx_sc tx_sc;
174+
struct macsec_rx_sc __rcu *rx_sc;
175+
};
176+
177+
#endif /* _NET_MACSEC_H_ */

0 commit comments

Comments
 (0)