@@ -60,17 +60,11 @@ static const char tstr[] = "[|MACsec]";
60
60
* composed of a MAC address + 16-bit port number
61
61
*/
62
62
struct macsec_sectag {
63
- u_char tci_an ;
64
- #if __BYTE_ORDER == __LITTLE_ENDIAN
65
- u_char short_length :6 ,
66
- unused :2 ;
67
- #else /* __BYTE_ORDER == __BIG_ENDIAN */
68
- u_char unused :2 ,
69
- short_length :6 ;
70
- #endif
71
- uint32_t packet_number ;
72
- u_char secure_channel_id [8 ]; /* optional */
73
- } __attribute__((packed ));
63
+ nd_uint8_t tci_an ;
64
+ nd_uint8_t short_length ;
65
+ nd_uint32_t packet_number ;
66
+ nd_uint8_t secure_channel_id [8 ]; /* optional */
67
+ };
74
68
75
69
/* IEEE 802.1AE-2006 9.5 */
76
70
#define MACSEC_TCI_VERSION 0x80
@@ -82,32 +76,33 @@ struct macsec_sectag {
82
76
#define MACSEC_AN_MASK 0x03 /* association number */
83
77
#define MACSEC_TCI_FLAGS (MACSEC_TCI_ES | MACSEC_TCI_SC | MACSEC_TCI_SCB | MACSEC_TCI_E | MACSEC_TCI_C)
84
78
#define MACSEC_TCI_CONFID (MACSEC_TCI_E | MACSEC_TCI_C)
79
+ #define MACSEC_SL_MASK 0x3F /* short length */
85
80
86
81
#define MACSEC_SECTAG_LEN_NOSCI 6
87
82
#define MACSEC_SECTAG_LEN_SCI 14
88
83
static int
89
- ieee8021ae_sectag_len (const struct macsec_sectag * sectag )
84
+ ieee8021ae_sectag_len (netdissect_options * ndo , const struct macsec_sectag * sectag )
90
85
{
91
- return (sectag -> tci_an & MACSEC_TCI_SC ) ?
86
+ return (GET_U_1 ( sectag -> tci_an ) & MACSEC_TCI_SC ) ?
92
87
MACSEC_SECTAG_LEN_SCI :
93
88
MACSEC_SECTAG_LEN_NOSCI ;
94
89
}
95
90
96
- static int macsec_check_length (const struct macsec_sectag * sectag , u_int length , u_int caplen )
91
+ static int macsec_check_length (netdissect_options * ndo , cconst struct macsec_sectag * sectag , u_int length , u_int caplen )
97
92
{
98
93
u_int len ;
99
94
100
95
/* we need the full MACsec header in the capture */
101
96
if (caplen < (MACSEC_SECTAG_LEN_NOSCI + 2 ))
102
97
return 0 ;
103
98
104
- len = ieee8021ae_sectag_len (sectag );
99
+ len = ieee8021ae_sectag_len (ndo , sectag );
105
100
if (caplen < (len + 2 ))
106
101
return 0 ;
107
102
108
- if (sectag -> short_length != 0 ) {
103
+ if (( GET_U_1 ( sectag -> short_length ) & MACSEC_SL_MASK ) != 0 ) {
109
104
/* original packet must have exact length */
110
- u_int exact = ETHER_HDRLEN + len + 2 + sectag -> short_length ;
105
+ u_int exact = ETHER_HDRLEN + len + 2 + ( GET_U_1 ( sectag -> short_length ) & MACSEC_SL_MASK ) ;
111
106
return exact == length ;
112
107
} else {
113
108
/* original packet must not be short */
@@ -153,18 +148,18 @@ int macsec_print(netdissect_options *ndo, const u_char **bp,
153
148
154
149
if (ndo -> ndo_eflag ) {
155
150
char buf [128 ];
156
- int n = snprintf (buf , sizeof (buf ), "an %d , pn %d , flags %s" ,
157
- sectag -> tci_an & MACSEC_AN_MASK ,
158
- EXTRACT_32BITS ( & sectag -> packet_number ),
151
+ int n = snprintf (buf , sizeof (buf ), "an %u , pn %u , flags %s" ,
152
+ GET_U_1 ( sectag -> tci_an ) & MACSEC_AN_MASK ,
153
+ GET_BE_U_4 ( sectag -> packet_number ),
159
154
bittok2str_nosep (macsec_flag_values , "none" ,
160
- sectag -> tci_an & MACSEC_TCI_FLAGS ));
155
+ GET_U_1 ( sectag -> tci_an ) & MACSEC_TCI_FLAGS ));
161
156
if (n < 0 )
162
157
return hdrlen + caplen ;
163
158
164
159
165
160
if (sectag -> short_length ) {
166
- int r = snprintf (buf + n , sizeof (buf ) - n , ", sl %d " ,
167
- sectag -> short_length );
161
+ int r = snprintf (buf + n , sizeof (buf ) - n , ", sl %u " ,
162
+ GET_U_1 ( sectag -> short_length ) & MACSEC_SL_MASK );
168
163
if (r < 0 )
169
164
return hdrlen + caplen ;
170
165
n += r ;
@@ -173,7 +168,7 @@ int macsec_print(netdissect_options *ndo, const u_char **bp,
173
168
if (sectag -> tci_an & MACSEC_TCI_SC ) {
174
169
uint64_t sci ;
175
170
int r ;
176
- sci = EXTRACT_64BITS (sectag -> secure_channel_id );
171
+ sci = GET_BE_U_8 (sectag -> secure_channel_id );
177
172
r = snprintf (buf + n , sizeof (buf ) - n , ", sci " SCI_FMT , sci );
178
173
if (r < 0 )
179
174
return hdrlen + caplen ;
@@ -183,12 +178,12 @@ int macsec_print(netdissect_options *ndo, const u_char **bp,
183
178
ND_PRINT ((ndo , "%s, " , buf ));
184
179
}
185
180
186
- len = ieee8021ae_sectag_len (sectag );
187
- * length_type = EXTRACT_16BITS (* bp + len );
181
+ len = ieee8021ae_sectag_len (ndo , sectag );
182
+ * length_type = GET_BE_U_2 (* bp + len );
188
183
if (ndo -> ndo_eflag && * length_type > ETHERMTU && !(sectag -> tci_an & MACSEC_TCI_E ))
189
184
ND_PRINT ((ndo , "ethertype %s, " , tok2str (ethertype_values ,"0x%04x" , * length_type )));
190
185
191
- if ((sectag -> tci_an & MACSEC_TCI_CONFID )) {
186
+ if ((GET_U_1 ( sectag -> tci_an ) & MACSEC_TCI_CONFID )) {
192
187
* bp += len ;
193
188
* hdrlenp += len ;
194
189
0 commit comments