| 1 |
/* SPDX-License-Identifier: LGPL-2.1-or-later */ |
| 2 |
#pragma once |
| 3 |
|
| 4 |
#include <linux/if_macsec.h> |
| 5 |
#include <net/ethernet.h> |
| 6 |
|
| 7 |
#include "shared-forward.h" |
| 8 |
#include "netdev.h" |
| 9 |
#include "sparse-endian.h" |
| 10 |
|
| 11 |
/* See the definition of MACSEC_NUM_AN in kernel's drivers/net/macsec.c */ |
| 12 |
#define MACSEC_MAX_ASSOCIATION_NUMBER 4 |
| 13 |
|
| 14 |
typedef struct MACsec MACsec; |
| 15 |
|
| 16 |
typedef union MACsecSCI { |
| 17 |
uint64_t as_uint64; |
| 18 |
|
| 19 |
struct { |
| 20 |
struct ether_addr mac; |
| 21 |
be16_t port; |
| 22 |
} _packed_; |
| 23 |
} MACsecSCI; |
| 24 |
|
| 25 |
assert_cc(sizeof(MACsecSCI) == sizeof(uint64_t)); |
| 26 |
|
| 27 |
typedef struct SecurityAssociation { |
| 28 |
uint8_t association_number; |
| 29 |
uint32_t packet_number; |
| 30 |
uint8_t key_id[MACSEC_KEYID_LEN]; |
| 31 |
uint8_t *key; |
| 32 |
uint32_t key_len; |
| 33 |
char *key_file; |
| 34 |
int activate; |
| 35 |
int use_for_encoding; |
| 36 |
} SecurityAssociation; |
| 37 |
|
| 38 |
typedef struct TransmitAssociation { |
| 39 |
MACsec *macsec; |
| 40 |
ConfigSection *section; |
| 41 |
|
| 42 |
SecurityAssociation sa; |
| 43 |
} TransmitAssociation; |
| 44 |
|
| 45 |
typedef struct ReceiveAssociation { |
| 46 |
MACsec *macsec; |
| 47 |
ConfigSection *section; |
| 48 |
|
| 49 |
MACsecSCI sci; |
| 50 |
SecurityAssociation sa; |
| 51 |
} ReceiveAssociation; |
| 52 |
|
| 53 |
typedef struct ReceiveChannel { |
| 54 |
MACsec *macsec; |
| 55 |
ConfigSection *section; |
| 56 |
|
| 57 |
MACsecSCI sci; |
| 58 |
ReceiveAssociation *rxsa[MACSEC_MAX_ASSOCIATION_NUMBER]; |
| 59 |
unsigned n_rxsa; |
| 60 |
} ReceiveChannel; |
| 61 |
|
| 62 |
typedef struct MACsec { |
| 63 |
NetDev meta; |
| 64 |
|
| 65 |
uint16_t port; |
| 66 |
int encrypt; |
| 67 |
uint8_t encoding_an; |
| 68 |
|
| 69 |
OrderedHashmap *receive_channels; |
| 70 |
OrderedHashmap *receive_channels_by_section; |
| 71 |
OrderedHashmap *transmit_associations_by_section; |
| 72 |
OrderedHashmap *receive_associations_by_section; |
| 73 |
} MACsec; |
| 74 |
|
| 75 |
DEFINE_NETDEV_CAST(MACSEC, MACsec); |
| 76 |
extern const NetDevVTable macsec_vtable; |
| 77 |
|
| 78 |
CONFIG_PARSER_PROTOTYPE(config_parse_macsec_port); |
| 79 |
CONFIG_PARSER_PROTOTYPE(config_parse_macsec_hw_address); |
| 80 |
CONFIG_PARSER_PROTOTYPE(config_parse_macsec_packet_number); |
| 81 |
CONFIG_PARSER_PROTOTYPE(config_parse_macsec_key_id); |
| 82 |
CONFIG_PARSER_PROTOTYPE(config_parse_macsec_key); |
| 83 |
CONFIG_PARSER_PROTOTYPE(config_parse_macsec_key_file); |
| 84 |
CONFIG_PARSER_PROTOTYPE(config_parse_macsec_sa_activate); |
| 85 |
CONFIG_PARSER_PROTOTYPE(config_parse_macsec_use_for_encoding); |