Skip to content

Commit 63c2616

Browse files
authored
Use nd_ types and GET_ macros.
1 parent 7885cfa commit 63c2616

File tree

1 file changed

+22
-27
lines changed

1 file changed

+22
-27
lines changed

print-macsec.c

+22-27
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,11 @@ static const char tstr[] = "[|MACsec]";
6060
* composed of a MAC address + 16-bit port number
6161
*/
6262
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+
};
7468

7569
/* IEEE 802.1AE-2006 9.5 */
7670
#define MACSEC_TCI_VERSION 0x80
@@ -82,32 +76,33 @@ struct macsec_sectag {
8276
#define MACSEC_AN_MASK 0x03 /* association number */
8377
#define MACSEC_TCI_FLAGS (MACSEC_TCI_ES | MACSEC_TCI_SC | MACSEC_TCI_SCB | MACSEC_TCI_E | MACSEC_TCI_C)
8478
#define MACSEC_TCI_CONFID (MACSEC_TCI_E | MACSEC_TCI_C)
79+
#define MACSEC_SL_MASK 0x3F /* short length */
8580

8681
#define MACSEC_SECTAG_LEN_NOSCI 6
8782
#define MACSEC_SECTAG_LEN_SCI 14
8883
static int
89-
ieee8021ae_sectag_len(const struct macsec_sectag *sectag)
84+
ieee8021ae_sectag_len(netdissect_options *ndo, const struct macsec_sectag *sectag)
9085
{
91-
return (sectag->tci_an & MACSEC_TCI_SC) ?
86+
return (GET_U_1(sectag->tci_an) & MACSEC_TCI_SC) ?
9287
MACSEC_SECTAG_LEN_SCI :
9388
MACSEC_SECTAG_LEN_NOSCI;
9489
}
9590

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)
9792
{
9893
u_int len;
9994

10095
/* we need the full MACsec header in the capture */
10196
if (caplen < (MACSEC_SECTAG_LEN_NOSCI + 2))
10297
return 0;
10398

104-
len = ieee8021ae_sectag_len(sectag);
99+
len = ieee8021ae_sectag_len(ndo, sectag);
105100
if (caplen < (len + 2))
106101
return 0;
107102

108-
if (sectag->short_length != 0) {
103+
if ((GET_U_1(sectag->short_length) & MACSEC_SL_MASK) != 0) {
109104
/* 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);
111106
return exact == length;
112107
} else {
113108
/* original packet must not be short */
@@ -153,18 +148,18 @@ int macsec_print(netdissect_options *ndo, const u_char **bp,
153148

154149
if (ndo->ndo_eflag) {
155150
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),
159154
bittok2str_nosep(macsec_flag_values, "none",
160-
sectag->tci_an & MACSEC_TCI_FLAGS));
155+
GET_U_1(sectag->tci_an) & MACSEC_TCI_FLAGS));
161156
if (n < 0)
162157
return hdrlen + caplen;
163158

164159

165160
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);
168163
if (r < 0)
169164
return hdrlen + caplen;
170165
n += r;
@@ -173,7 +168,7 @@ int macsec_print(netdissect_options *ndo, const u_char **bp,
173168
if (sectag->tci_an & MACSEC_TCI_SC) {
174169
uint64_t sci;
175170
int r;
176-
sci = EXTRACT_64BITS(sectag->secure_channel_id);
171+
sci = GET_BE_U_8(sectag->secure_channel_id);
177172
r = snprintf(buf + n, sizeof(buf) - n, ", sci " SCI_FMT, sci);
178173
if (r < 0)
179174
return hdrlen + caplen;
@@ -183,12 +178,12 @@ int macsec_print(netdissect_options *ndo, const u_char **bp,
183178
ND_PRINT((ndo, "%s, ", buf));
184179
}
185180

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);
188183
if (ndo->ndo_eflag && *length_type > ETHERMTU && !(sectag->tci_an & MACSEC_TCI_E))
189184
ND_PRINT((ndo, "ethertype %s, ", tok2str(ethertype_values,"0x%04x", *length_type)));
190185

191-
if ((sectag->tci_an & MACSEC_TCI_CONFID)) {
186+
if ((GET_U_1(sectag->tci_an) & MACSEC_TCI_CONFID)) {
192187
*bp += len;
193188
*hdrlenp += len;
194189

0 commit comments

Comments
 (0)