0001
0002
0003
0004
0005
0006
0007 #ifndef _NET_MACSEC_H_
0008 #define _NET_MACSEC_H_
0009
0010 #include <linux/u64_stats_sync.h>
0011 #include <uapi/linux/if_link.h>
0012 #include <uapi/linux/if_macsec.h>
0013
0014 #define MACSEC_DEFAULT_PN_LEN 4
0015 #define MACSEC_XPN_PN_LEN 8
0016
0017 #define MACSEC_SALT_LEN 12
0018 #define MACSEC_NUM_AN 4
0019
0020 typedef u64 __bitwise sci_t;
0021 typedef u32 __bitwise ssci_t;
0022
0023 typedef union salt {
0024 struct {
0025 u32 ssci;
0026 u64 pn;
0027 } __packed;
0028 u8 bytes[MACSEC_SALT_LEN];
0029 } __packed salt_t;
0030
0031 typedef union pn {
0032 struct {
0033 #if defined(__LITTLE_ENDIAN_BITFIELD)
0034 u32 lower;
0035 u32 upper;
0036 #elif defined(__BIG_ENDIAN_BITFIELD)
0037 u32 upper;
0038 u32 lower;
0039 #else
0040 #error "Please fix <asm/byteorder.h>"
0041 #endif
0042 };
0043 u64 full64;
0044 } pn_t;
0045
0046
0047
0048
0049
0050
0051
0052 struct macsec_key {
0053 u8 id[MACSEC_KEYID_LEN];
0054 struct crypto_aead *tfm;
0055 salt_t salt;
0056 };
0057
0058 struct macsec_rx_sc_stats {
0059 __u64 InOctetsValidated;
0060 __u64 InOctetsDecrypted;
0061 __u64 InPktsUnchecked;
0062 __u64 InPktsDelayed;
0063 __u64 InPktsOK;
0064 __u64 InPktsInvalid;
0065 __u64 InPktsLate;
0066 __u64 InPktsNotValid;
0067 __u64 InPktsNotUsingSA;
0068 __u64 InPktsUnusedSA;
0069 };
0070
0071 struct macsec_rx_sa_stats {
0072 __u32 InPktsOK;
0073 __u32 InPktsInvalid;
0074 __u32 InPktsNotValid;
0075 __u32 InPktsNotUsingSA;
0076 __u32 InPktsUnusedSA;
0077 };
0078
0079 struct macsec_tx_sa_stats {
0080 __u32 OutPktsProtected;
0081 __u32 OutPktsEncrypted;
0082 };
0083
0084 struct macsec_tx_sc_stats {
0085 __u64 OutPktsProtected;
0086 __u64 OutPktsEncrypted;
0087 __u64 OutOctetsProtected;
0088 __u64 OutOctetsEncrypted;
0089 };
0090
0091 struct macsec_dev_stats {
0092 __u64 OutPktsUntagged;
0093 __u64 InPktsUntagged;
0094 __u64 OutPktsTooLong;
0095 __u64 InPktsNoTag;
0096 __u64 InPktsBadTag;
0097 __u64 InPktsUnknownSCI;
0098 __u64 InPktsNoSCI;
0099 __u64 InPktsOverrun;
0100 };
0101
0102
0103
0104
0105
0106
0107
0108
0109
0110
0111 struct macsec_rx_sa {
0112 struct macsec_key key;
0113 ssci_t ssci;
0114 spinlock_t lock;
0115 union {
0116 pn_t next_pn_halves;
0117 u64 next_pn;
0118 };
0119 refcount_t refcnt;
0120 bool active;
0121 struct macsec_rx_sa_stats __percpu *stats;
0122 struct macsec_rx_sc *sc;
0123 struct rcu_head rcu;
0124 };
0125
0126 struct pcpu_rx_sc_stats {
0127 struct macsec_rx_sc_stats stats;
0128 struct u64_stats_sync syncp;
0129 };
0130
0131 struct pcpu_tx_sc_stats {
0132 struct macsec_tx_sc_stats stats;
0133 struct u64_stats_sync syncp;
0134 };
0135
0136
0137
0138
0139
0140
0141
0142
0143 struct macsec_rx_sc {
0144 struct macsec_rx_sc __rcu *next;
0145 sci_t sci;
0146 bool active;
0147 struct macsec_rx_sa __rcu *sa[MACSEC_NUM_AN];
0148 struct pcpu_rx_sc_stats __percpu *stats;
0149 refcount_t refcnt;
0150 struct rcu_head rcu_head;
0151 };
0152
0153
0154
0155
0156
0157
0158
0159
0160
0161
0162 struct macsec_tx_sa {
0163 struct macsec_key key;
0164 ssci_t ssci;
0165 spinlock_t lock;
0166 union {
0167 pn_t next_pn_halves;
0168 u64 next_pn;
0169 };
0170 refcount_t refcnt;
0171 bool active;
0172 struct macsec_tx_sa_stats __percpu *stats;
0173 struct rcu_head rcu;
0174 };
0175
0176
0177
0178
0179
0180
0181
0182
0183
0184
0185
0186
0187 struct macsec_tx_sc {
0188 bool active;
0189 u8 encoding_sa;
0190 bool encrypt;
0191 bool send_sci;
0192 bool end_station;
0193 bool scb;
0194 struct macsec_tx_sa __rcu *sa[MACSEC_NUM_AN];
0195 struct pcpu_tx_sc_stats __percpu *stats;
0196 };
0197
0198
0199
0200
0201
0202
0203
0204
0205
0206
0207
0208
0209
0210
0211
0212
0213
0214 struct macsec_secy {
0215 struct net_device *netdev;
0216 unsigned int n_rx_sc;
0217 sci_t sci;
0218 u16 key_len;
0219 u16 icv_len;
0220 enum macsec_validation_type validate_frames;
0221 bool xpn;
0222 bool operational;
0223 bool protect_frames;
0224 bool replay_protect;
0225 u32 replay_window;
0226 struct macsec_tx_sc tx_sc;
0227 struct macsec_rx_sc __rcu *rx_sc;
0228 };
0229
0230
0231
0232
0233 struct macsec_context {
0234 union {
0235 struct net_device *netdev;
0236 struct phy_device *phydev;
0237 };
0238 enum macsec_offload offload;
0239
0240 struct macsec_secy *secy;
0241 struct macsec_rx_sc *rx_sc;
0242 struct {
0243 unsigned char assoc_num;
0244 u8 key[MACSEC_MAX_KEY_LEN];
0245 union {
0246 struct macsec_rx_sa *rx_sa;
0247 struct macsec_tx_sa *tx_sa;
0248 };
0249 } sa;
0250 union {
0251 struct macsec_tx_sc_stats *tx_sc_stats;
0252 struct macsec_tx_sa_stats *tx_sa_stats;
0253 struct macsec_rx_sc_stats *rx_sc_stats;
0254 struct macsec_rx_sa_stats *rx_sa_stats;
0255 struct macsec_dev_stats *dev_stats;
0256 } stats;
0257
0258 u8 prepare:1;
0259 };
0260
0261
0262
0263
0264 struct macsec_ops {
0265
0266 int (*mdo_dev_open)(struct macsec_context *ctx);
0267 int (*mdo_dev_stop)(struct macsec_context *ctx);
0268
0269 int (*mdo_add_secy)(struct macsec_context *ctx);
0270 int (*mdo_upd_secy)(struct macsec_context *ctx);
0271 int (*mdo_del_secy)(struct macsec_context *ctx);
0272
0273 int (*mdo_add_rxsc)(struct macsec_context *ctx);
0274 int (*mdo_upd_rxsc)(struct macsec_context *ctx);
0275 int (*mdo_del_rxsc)(struct macsec_context *ctx);
0276
0277 int (*mdo_add_rxsa)(struct macsec_context *ctx);
0278 int (*mdo_upd_rxsa)(struct macsec_context *ctx);
0279 int (*mdo_del_rxsa)(struct macsec_context *ctx);
0280 int (*mdo_add_txsa)(struct macsec_context *ctx);
0281 int (*mdo_upd_txsa)(struct macsec_context *ctx);
0282 int (*mdo_del_txsa)(struct macsec_context *ctx);
0283
0284 int (*mdo_get_dev_stats)(struct macsec_context *ctx);
0285 int (*mdo_get_tx_sc_stats)(struct macsec_context *ctx);
0286 int (*mdo_get_tx_sa_stats)(struct macsec_context *ctx);
0287 int (*mdo_get_rx_sc_stats)(struct macsec_context *ctx);
0288 int (*mdo_get_rx_sa_stats)(struct macsec_context *ctx);
0289 };
0290
0291 void macsec_pn_wrapped(struct macsec_secy *secy, struct macsec_tx_sa *tx_sa);
0292
0293 #endif