print-slow.c revision 1.10 1 1.1 christos /*
2 1.1 christos * Copyright (c) 1998-2006 The TCPDUMP project
3 1.1 christos *
4 1.1 christos * Redistribution and use in source and binary forms, with or without
5 1.1 christos * modification, are permitted provided that: (1) source code
6 1.1 christos * distributions retain the above copyright notice and this paragraph
7 1.1 christos * in its entirety, and (2) distributions including binary code include
8 1.1 christos * the above copyright notice and this paragraph in its entirety in
9 1.1 christos * the documentation or other materials provided with the distribution.
10 1.1 christos * THIS SOFTWARE IS PROVIDED ``AS IS'' AND
11 1.1 christos * WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT
12 1.1 christos * LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
13 1.1 christos * FOR A PARTICULAR PURPOSE.
14 1.1 christos *
15 1.1 christos * support for the IEEE "slow protocols" LACP, MARKER as per 802.3ad
16 1.1 christos * OAM as per 802.3ah
17 1.1 christos *
18 1.9 christos * Original code by Hannes Gredler (hannes (at) gredler.at)
19 1.1 christos */
20 1.1 christos
21 1.2 christos #include <sys/cdefs.h>
22 1.1 christos #ifndef lint
23 1.10 christos __RCSID("$NetBSD: print-slow.c,v 1.10 2023/08/17 20:19:40 christos Exp $");
24 1.1 christos #endif
25 1.1 christos
26 1.8 spz /* \summary: IEEE "slow protocols" (802.3ad/802.3ah) printer */
27 1.8 spz
28 1.1 christos #ifdef HAVE_CONFIG_H
29 1.10 christos #include <config.h>
30 1.1 christos #endif
31 1.1 christos
32 1.10 christos #include "netdissect-stdinc.h"
33 1.1 christos
34 1.10 christos #define ND_LONGJMP_FROM_TCHECK
35 1.7 christos #include "netdissect.h"
36 1.1 christos #include "extract.h"
37 1.1 christos #include "addrtoname.h"
38 1.1 christos #include "oui.h"
39 1.1 christos
40 1.10 christos
41 1.1 christos #define SLOW_PROTO_LACP 1
42 1.1 christos #define SLOW_PROTO_MARKER 2
43 1.1 christos #define SLOW_PROTO_OAM 3
44 1.1 christos
45 1.1 christos #define LACP_VERSION 1
46 1.1 christos #define MARKER_VERSION 1
47 1.1 christos
48 1.1 christos static const struct tok slow_proto_values[] = {
49 1.1 christos { SLOW_PROTO_LACP, "LACP" },
50 1.1 christos { SLOW_PROTO_MARKER, "MARKER" },
51 1.1 christos { SLOW_PROTO_OAM, "OAM" },
52 1.1 christos { 0, NULL}
53 1.1 christos };
54 1.1 christos
55 1.1 christos static const struct tok slow_oam_flag_values[] = {
56 1.1 christos { 0x0001, "Link Fault" },
57 1.1 christos { 0x0002, "Dying Gasp" },
58 1.1 christos { 0x0004, "Critical Event" },
59 1.1 christos { 0x0008, "Local Evaluating" },
60 1.1 christos { 0x0010, "Local Stable" },
61 1.1 christos { 0x0020, "Remote Evaluating" },
62 1.1 christos { 0x0040, "Remote Stable" },
63 1.1 christos { 0, NULL}
64 1.5 christos };
65 1.1 christos
66 1.1 christos #define SLOW_OAM_CODE_INFO 0x00
67 1.1 christos #define SLOW_OAM_CODE_EVENT_NOTIF 0x01
68 1.1 christos #define SLOW_OAM_CODE_VAR_REQUEST 0x02
69 1.1 christos #define SLOW_OAM_CODE_VAR_RESPONSE 0x03
70 1.1 christos #define SLOW_OAM_CODE_LOOPBACK_CTRL 0x04
71 1.1 christos #define SLOW_OAM_CODE_PRIVATE 0xfe
72 1.1 christos
73 1.1 christos static const struct tok slow_oam_code_values[] = {
74 1.1 christos { SLOW_OAM_CODE_INFO, "Information" },
75 1.1 christos { SLOW_OAM_CODE_EVENT_NOTIF, "Event Notification" },
76 1.1 christos { SLOW_OAM_CODE_VAR_REQUEST, "Variable Request" },
77 1.1 christos { SLOW_OAM_CODE_VAR_RESPONSE, "Variable Response" },
78 1.1 christos { SLOW_OAM_CODE_LOOPBACK_CTRL, "Loopback Control" },
79 1.1 christos { SLOW_OAM_CODE_PRIVATE, "Vendor Private" },
80 1.1 christos { 0, NULL}
81 1.1 christos };
82 1.1 christos
83 1.1 christos struct slow_oam_info_t {
84 1.10 christos nd_uint8_t info_type;
85 1.10 christos nd_uint8_t info_length;
86 1.10 christos nd_uint8_t oam_version;
87 1.10 christos nd_uint16_t revision;
88 1.10 christos nd_uint8_t state;
89 1.10 christos nd_uint8_t oam_config;
90 1.10 christos nd_uint16_t oam_pdu_config;
91 1.10 christos nd_uint24_t oui;
92 1.10 christos nd_uint32_t vendor_private;
93 1.1 christos };
94 1.1 christos
95 1.1 christos #define SLOW_OAM_INFO_TYPE_END_OF_TLV 0x00
96 1.1 christos #define SLOW_OAM_INFO_TYPE_LOCAL 0x01
97 1.1 christos #define SLOW_OAM_INFO_TYPE_REMOTE 0x02
98 1.1 christos #define SLOW_OAM_INFO_TYPE_ORG_SPECIFIC 0xfe
99 1.1 christos
100 1.1 christos static const struct tok slow_oam_info_type_values[] = {
101 1.1 christos { SLOW_OAM_INFO_TYPE_END_OF_TLV, "End of TLV marker" },
102 1.1 christos { SLOW_OAM_INFO_TYPE_LOCAL, "Local" },
103 1.1 christos { SLOW_OAM_INFO_TYPE_REMOTE, "Remote" },
104 1.1 christos { SLOW_OAM_INFO_TYPE_ORG_SPECIFIC, "Organization specific" },
105 1.1 christos { 0, NULL}
106 1.1 christos };
107 1.1 christos
108 1.1 christos #define OAM_INFO_TYPE_PARSER_MASK 0x3
109 1.1 christos static const struct tok slow_oam_info_type_state_parser_values[] = {
110 1.1 christos { 0x00, "forwarding" },
111 1.1 christos { 0x01, "looping back" },
112 1.1 christos { 0x02, "discarding" },
113 1.1 christos { 0x03, "reserved" },
114 1.1 christos { 0, NULL}
115 1.1 christos };
116 1.1 christos
117 1.1 christos #define OAM_INFO_TYPE_MUX_MASK 0x4
118 1.1 christos static const struct tok slow_oam_info_type_state_mux_values[] = {
119 1.1 christos { 0x00, "forwarding" },
120 1.1 christos { 0x04, "discarding" },
121 1.1 christos { 0, NULL}
122 1.1 christos };
123 1.1 christos
124 1.1 christos static const struct tok slow_oam_info_type_oam_config_values[] = {
125 1.1 christos { 0x01, "Active" },
126 1.1 christos { 0x02, "Unidirectional" },
127 1.1 christos { 0x04, "Remote-Loopback" },
128 1.1 christos { 0x08, "Link-Events" },
129 1.1 christos { 0x10, "Variable-Retrieval" },
130 1.1 christos { 0, NULL}
131 1.1 christos };
132 1.1 christos
133 1.1 christos /* 11 Bits */
134 1.1 christos #define OAM_INFO_TYPE_PDU_SIZE_MASK 0x7ff
135 1.1 christos
136 1.1 christos #define SLOW_OAM_LINK_EVENT_END_OF_TLV 0x00
137 1.1 christos #define SLOW_OAM_LINK_EVENT_ERR_SYM_PER 0x01
138 1.1 christos #define SLOW_OAM_LINK_EVENT_ERR_FRM 0x02
139 1.1 christos #define SLOW_OAM_LINK_EVENT_ERR_FRM_PER 0x03
140 1.1 christos #define SLOW_OAM_LINK_EVENT_ERR_FRM_SUMM 0x04
141 1.1 christos #define SLOW_OAM_LINK_EVENT_ORG_SPECIFIC 0xfe
142 1.1 christos
143 1.1 christos static const struct tok slow_oam_link_event_values[] = {
144 1.1 christos { SLOW_OAM_LINK_EVENT_END_OF_TLV, "End of TLV marker" },
145 1.1 christos { SLOW_OAM_LINK_EVENT_ERR_SYM_PER, "Errored Symbol Period Event" },
146 1.1 christos { SLOW_OAM_LINK_EVENT_ERR_FRM, "Errored Frame Event" },
147 1.1 christos { SLOW_OAM_LINK_EVENT_ERR_FRM_PER, "Errored Frame Period Event" },
148 1.1 christos { SLOW_OAM_LINK_EVENT_ERR_FRM_SUMM, "Errored Frame Seconds Summary Event" },
149 1.1 christos { SLOW_OAM_LINK_EVENT_ORG_SPECIFIC, "Organization specific" },
150 1.1 christos { 0, NULL}
151 1.1 christos };
152 1.1 christos
153 1.1 christos struct slow_oam_link_event_t {
154 1.10 christos nd_uint8_t event_type;
155 1.10 christos nd_uint8_t event_length;
156 1.10 christos nd_uint16_t time_stamp;
157 1.10 christos nd_uint64_t window;
158 1.10 christos nd_uint64_t threshold;
159 1.10 christos nd_uint64_t errors;
160 1.10 christos nd_uint64_t errors_running_total;
161 1.10 christos nd_uint32_t event_running_total;
162 1.1 christos };
163 1.1 christos
164 1.1 christos struct slow_oam_variablerequest_t {
165 1.10 christos nd_uint8_t branch;
166 1.10 christos nd_uint16_t leaf;
167 1.1 christos };
168 1.1 christos
169 1.1 christos struct slow_oam_variableresponse_t {
170 1.10 christos nd_uint8_t branch;
171 1.10 christos nd_uint16_t leaf;
172 1.10 christos nd_uint8_t length;
173 1.1 christos };
174 1.1 christos
175 1.1 christos struct slow_oam_loopbackctrl_t {
176 1.10 christos nd_uint8_t command;
177 1.1 christos };
178 1.1 christos
179 1.1 christos static const struct tok slow_oam_loopbackctrl_cmd_values[] = {
180 1.1 christos { 0x01, "Enable OAM Remote Loopback" },
181 1.1 christos { 0x02, "Disable OAM Remote Loopback" },
182 1.1 christos { 0, NULL}
183 1.1 christos };
184 1.1 christos
185 1.1 christos struct tlv_header_t {
186 1.10 christos nd_uint8_t type;
187 1.10 christos nd_uint8_t length;
188 1.1 christos };
189 1.1 christos
190 1.8 spz #define LACP_MARKER_TLV_TERMINATOR 0x00 /* same code for LACP and Marker */
191 1.8 spz
192 1.8 spz #define LACP_TLV_ACTOR_INFO 0x01
193 1.8 spz #define LACP_TLV_PARTNER_INFO 0x02
194 1.8 spz #define LACP_TLV_COLLECTOR_INFO 0x03
195 1.1 christos
196 1.8 spz #define MARKER_TLV_MARKER_INFO 0x01
197 1.1 christos
198 1.1 christos static const struct tok slow_tlv_values[] = {
199 1.8 spz { (SLOW_PROTO_LACP << 8) + LACP_MARKER_TLV_TERMINATOR, "Terminator"},
200 1.1 christos { (SLOW_PROTO_LACP << 8) + LACP_TLV_ACTOR_INFO, "Actor Information"},
201 1.1 christos { (SLOW_PROTO_LACP << 8) + LACP_TLV_PARTNER_INFO, "Partner Information"},
202 1.1 christos { (SLOW_PROTO_LACP << 8) + LACP_TLV_COLLECTOR_INFO, "Collector Information"},
203 1.1 christos
204 1.8 spz { (SLOW_PROTO_MARKER << 8) + LACP_MARKER_TLV_TERMINATOR, "Terminator"},
205 1.1 christos { (SLOW_PROTO_MARKER << 8) + MARKER_TLV_MARKER_INFO, "Marker Information"},
206 1.1 christos { 0, NULL}
207 1.1 christos };
208 1.1 christos
209 1.1 christos struct lacp_tlv_actor_partner_info_t {
210 1.10 christos nd_uint16_t sys_pri;
211 1.10 christos nd_mac_addr sys;
212 1.10 christos nd_uint16_t key;
213 1.10 christos nd_uint16_t port_pri;
214 1.10 christos nd_uint16_t port;
215 1.10 christos nd_uint8_t state;
216 1.10 christos nd_byte pad[3];
217 1.5 christos };
218 1.1 christos
219 1.1 christos static const struct tok lacp_tlv_actor_partner_info_state_values[] = {
220 1.1 christos { 0x01, "Activity"},
221 1.1 christos { 0x02, "Timeout"},
222 1.1 christos { 0x04, "Aggregation"},
223 1.1 christos { 0x08, "Synchronization"},
224 1.1 christos { 0x10, "Collecting"},
225 1.1 christos { 0x20, "Distributing"},
226 1.1 christos { 0x40, "Default"},
227 1.1 christos { 0x80, "Expired"},
228 1.1 christos { 0, NULL}
229 1.1 christos };
230 1.1 christos
231 1.1 christos struct lacp_tlv_collector_info_t {
232 1.10 christos nd_uint16_t max_delay;
233 1.10 christos nd_byte pad[12];
234 1.5 christos };
235 1.1 christos
236 1.1 christos struct marker_tlv_marker_info_t {
237 1.10 christos nd_uint16_t req_port;
238 1.10 christos nd_mac_addr req_sys;
239 1.10 christos nd_uint32_t req_trans_id;
240 1.10 christos nd_byte pad[2];
241 1.5 christos };
242 1.1 christos
243 1.1 christos struct lacp_marker_tlv_terminator_t {
244 1.10 christos nd_byte pad[50];
245 1.5 christos };
246 1.1 christos
247 1.10 christos static void slow_marker_lacp_print(netdissect_options *, const u_char *, u_int, u_int);
248 1.10 christos static void slow_oam_print(netdissect_options *, const u_char *, u_int);
249 1.1 christos
250 1.1 christos void
251 1.5 christos slow_print(netdissect_options *ndo,
252 1.10 christos const u_char *pptr, u_int len)
253 1.6 christos {
254 1.1 christos int print_version;
255 1.8 spz u_int subtype;
256 1.1 christos
257 1.10 christos ndo->ndo_protocol = "slow";
258 1.8 spz if (len < 1)
259 1.8 spz goto tooshort;
260 1.10 christos subtype = GET_U_1(pptr);
261 1.1 christos
262 1.1 christos /*
263 1.1 christos * Sanity checking of the header.
264 1.1 christos */
265 1.8 spz switch (subtype) {
266 1.1 christos case SLOW_PROTO_LACP:
267 1.8 spz if (len < 2)
268 1.8 spz goto tooshort;
269 1.10 christos if (GET_U_1(pptr + 1) != LACP_VERSION) {
270 1.10 christos ND_PRINT("LACP version %u packet not supported",
271 1.10 christos GET_U_1(pptr + 1));
272 1.1 christos return;
273 1.1 christos }
274 1.1 christos print_version = 1;
275 1.1 christos break;
276 1.1 christos
277 1.1 christos case SLOW_PROTO_MARKER:
278 1.8 spz if (len < 2)
279 1.8 spz goto tooshort;
280 1.10 christos if (GET_U_1(pptr + 1) != MARKER_VERSION) {
281 1.10 christos ND_PRINT("MARKER version %u packet not supported",
282 1.10 christos GET_U_1(pptr + 1));
283 1.1 christos return;
284 1.1 christos }
285 1.1 christos print_version = 1;
286 1.1 christos break;
287 1.1 christos
288 1.1 christos case SLOW_PROTO_OAM: /* fall through */
289 1.1 christos print_version = 0;
290 1.1 christos break;
291 1.1 christos
292 1.1 christos default:
293 1.1 christos /* print basic information and exit */
294 1.1 christos print_version = -1;
295 1.1 christos break;
296 1.1 christos }
297 1.1 christos
298 1.8 spz if (print_version == 1) {
299 1.10 christos ND_PRINT("%sv%u, length %u",
300 1.8 spz tok2str(slow_proto_values, "unknown (%u)", subtype),
301 1.10 christos GET_U_1((pptr + 1)),
302 1.10 christos len);
303 1.1 christos } else {
304 1.1 christos /* some slow protos don't have a version number in the header */
305 1.10 christos ND_PRINT("%s, length %u",
306 1.8 spz tok2str(slow_proto_values, "unknown (%u)", subtype),
307 1.10 christos len);
308 1.1 christos }
309 1.1 christos
310 1.1 christos /* unrecognized subtype */
311 1.1 christos if (print_version == -1) {
312 1.5 christos print_unknown_data(ndo, pptr, "\n\t", len);
313 1.1 christos return;
314 1.1 christos }
315 1.1 christos
316 1.5 christos if (!ndo->ndo_vflag)
317 1.1 christos return;
318 1.1 christos
319 1.8 spz switch (subtype) {
320 1.1 christos default: /* should not happen */
321 1.1 christos break;
322 1.1 christos
323 1.1 christos case SLOW_PROTO_OAM:
324 1.8 spz /* skip subtype */
325 1.8 spz len -= 1;
326 1.8 spz pptr += 1;
327 1.8 spz slow_oam_print(ndo, pptr, len);
328 1.1 christos break;
329 1.1 christos
330 1.1 christos case SLOW_PROTO_LACP: /* LACP and MARKER share the same semantics */
331 1.1 christos case SLOW_PROTO_MARKER:
332 1.8 spz /* skip subtype and version */
333 1.8 spz len -= 2;
334 1.8 spz pptr += 2;
335 1.8 spz slow_marker_lacp_print(ndo, pptr, len, subtype);
336 1.1 christos break;
337 1.1 christos }
338 1.1 christos return;
339 1.1 christos
340 1.8 spz tooshort:
341 1.8 spz if (!ndo->ndo_vflag)
342 1.10 christos ND_PRINT(" (packet is too short)");
343 1.8 spz else
344 1.10 christos ND_PRINT("\n\t\t packet is too short");
345 1.1 christos }
346 1.1 christos
347 1.5 christos static void
348 1.5 christos slow_marker_lacp_print(netdissect_options *ndo,
349 1.10 christos const u_char *tptr, u_int tlen,
350 1.8 spz u_int proto_subtype)
351 1.6 christos {
352 1.1 christos const struct tlv_header_t *tlv_header;
353 1.1 christos const u_char *tlv_tptr;
354 1.10 christos u_int tlv_type, tlv_len, tlv_tlen;
355 1.1 christos
356 1.1 christos union {
357 1.1 christos const struct lacp_marker_tlv_terminator_t *lacp_marker_tlv_terminator;
358 1.1 christos const struct lacp_tlv_actor_partner_info_t *lacp_tlv_actor_partner_info;
359 1.1 christos const struct lacp_tlv_collector_info_t *lacp_tlv_collector_info;
360 1.1 christos const struct marker_tlv_marker_info_t *marker_tlv_marker_info;
361 1.1 christos } tlv_ptr;
362 1.5 christos
363 1.1 christos while(tlen>0) {
364 1.8 spz /* is the packet big enough to include the tlv header ? */
365 1.8 spz if (tlen < sizeof(struct tlv_header_t))
366 1.8 spz goto tooshort;
367 1.1 christos /* did we capture enough for fully decoding the tlv header ? */
368 1.1 christos tlv_header = (const struct tlv_header_t *)tptr;
369 1.10 christos tlv_type = GET_U_1(tlv_header->type);
370 1.10 christos tlv_len = GET_U_1(tlv_header->length);
371 1.1 christos
372 1.10 christos ND_PRINT("\n\t%s TLV (0x%02x), length %u",
373 1.1 christos tok2str(slow_tlv_values,
374 1.1 christos "Unknown",
375 1.10 christos (proto_subtype << 8) + tlv_type),
376 1.10 christos tlv_type,
377 1.10 christos tlv_len);
378 1.1 christos
379 1.10 christos if (tlv_type == LACP_MARKER_TLV_TERMINATOR) {
380 1.8 spz /*
381 1.8 spz * This TLV has a length of zero, and means there are no
382 1.8 spz * more TLVs to process.
383 1.8 spz */
384 1.1 christos return;
385 1.1 christos }
386 1.1 christos
387 1.8 spz /* length includes the type and length fields */
388 1.8 spz if (tlv_len < sizeof(struct tlv_header_t)) {
389 1.10 christos ND_PRINT("\n\t ERROR: illegal length - should be >= %zu",
390 1.10 christos sizeof(struct tlv_header_t));
391 1.8 spz return;
392 1.8 spz }
393 1.1 christos
394 1.8 spz /* is the packet big enough to include the tlv ? */
395 1.8 spz if (tlen < tlv_len)
396 1.8 spz goto tooshort;
397 1.1 christos /* did we capture enough for fully decoding the tlv ? */
398 1.10 christos ND_TCHECK_LEN(tptr, tlv_len);
399 1.1 christos
400 1.8 spz tlv_tptr=tptr+sizeof(struct tlv_header_t);
401 1.8 spz tlv_tlen=tlv_len-sizeof(struct tlv_header_t);
402 1.8 spz
403 1.10 christos switch((proto_subtype << 8) + tlv_type) {
404 1.1 christos
405 1.1 christos /* those two TLVs have the same structure -> fall through */
406 1.1 christos case ((SLOW_PROTO_LACP << 8) + LACP_TLV_ACTOR_INFO):
407 1.1 christos case ((SLOW_PROTO_LACP << 8) + LACP_TLV_PARTNER_INFO):
408 1.8 spz if (tlv_tlen !=
409 1.8 spz sizeof(struct lacp_tlv_actor_partner_info_t)) {
410 1.10 christos ND_PRINT("\n\t ERROR: illegal length - should be %zu",
411 1.10 christos sizeof(struct tlv_header_t) + sizeof(struct lacp_tlv_actor_partner_info_t));
412 1.8 spz goto badlength;
413 1.8 spz }
414 1.8 spz
415 1.1 christos tlv_ptr.lacp_tlv_actor_partner_info = (const struct lacp_tlv_actor_partner_info_t *)tlv_tptr;
416 1.1 christos
417 1.10 christos ND_PRINT("\n\t System %s, System Priority %u, Key %u"
418 1.1 christos ", Port %u, Port Priority %u\n\t State Flags [%s]",
419 1.10 christos GET_ETHERADDR_STRING(tlv_ptr.lacp_tlv_actor_partner_info->sys),
420 1.10 christos GET_BE_U_2(tlv_ptr.lacp_tlv_actor_partner_info->sys_pri),
421 1.10 christos GET_BE_U_2(tlv_ptr.lacp_tlv_actor_partner_info->key),
422 1.10 christos GET_BE_U_2(tlv_ptr.lacp_tlv_actor_partner_info->port),
423 1.10 christos GET_BE_U_2(tlv_ptr.lacp_tlv_actor_partner_info->port_pri),
424 1.1 christos bittok2str(lacp_tlv_actor_partner_info_state_values,
425 1.1 christos "none",
426 1.10 christos GET_U_1(tlv_ptr.lacp_tlv_actor_partner_info->state)));
427 1.1 christos
428 1.1 christos break;
429 1.1 christos
430 1.1 christos case ((SLOW_PROTO_LACP << 8) + LACP_TLV_COLLECTOR_INFO):
431 1.8 spz if (tlv_tlen !=
432 1.8 spz sizeof(struct lacp_tlv_collector_info_t)) {
433 1.10 christos ND_PRINT("\n\t ERROR: illegal length - should be %zu",
434 1.10 christos sizeof(struct tlv_header_t) + sizeof(struct lacp_tlv_collector_info_t));
435 1.8 spz goto badlength;
436 1.8 spz }
437 1.8 spz
438 1.1 christos tlv_ptr.lacp_tlv_collector_info = (const struct lacp_tlv_collector_info_t *)tlv_tptr;
439 1.1 christos
440 1.10 christos ND_PRINT("\n\t Max Delay %u",
441 1.10 christos GET_BE_U_2(tlv_ptr.lacp_tlv_collector_info->max_delay));
442 1.1 christos
443 1.1 christos break;
444 1.1 christos
445 1.1 christos case ((SLOW_PROTO_MARKER << 8) + MARKER_TLV_MARKER_INFO):
446 1.8 spz if (tlv_tlen !=
447 1.8 spz sizeof(struct marker_tlv_marker_info_t)) {
448 1.10 christos ND_PRINT("\n\t ERROR: illegal length - should be %zu",
449 1.10 christos sizeof(struct tlv_header_t) + sizeof(struct marker_tlv_marker_info_t));
450 1.8 spz goto badlength;
451 1.8 spz }
452 1.8 spz
453 1.1 christos tlv_ptr.marker_tlv_marker_info = (const struct marker_tlv_marker_info_t *)tlv_tptr;
454 1.1 christos
455 1.10 christos ND_PRINT("\n\t Request System %s, Request Port %u, Request Transaction ID 0x%08x",
456 1.10 christos GET_ETHERADDR_STRING(tlv_ptr.marker_tlv_marker_info->req_sys),
457 1.10 christos GET_BE_U_2(tlv_ptr.marker_tlv_marker_info->req_port),
458 1.10 christos GET_BE_U_4(tlv_ptr.marker_tlv_marker_info->req_trans_id));
459 1.1 christos
460 1.1 christos break;
461 1.1 christos
462 1.1 christos default:
463 1.5 christos if (ndo->ndo_vflag <= 1)
464 1.5 christos print_unknown_data(ndo, tlv_tptr, "\n\t ", tlv_tlen);
465 1.1 christos break;
466 1.1 christos }
467 1.8 spz
468 1.8 spz badlength:
469 1.1 christos /* do we want to see an additional hexdump ? */
470 1.5 christos if (ndo->ndo_vflag > 1) {
471 1.5 christos print_unknown_data(ndo, tptr+sizeof(struct tlv_header_t), "\n\t ",
472 1.1 christos tlv_len-sizeof(struct tlv_header_t));
473 1.1 christos }
474 1.1 christos
475 1.1 christos tptr+=tlv_len;
476 1.1 christos tlen-=tlv_len;
477 1.1 christos }
478 1.1 christos return;
479 1.8 spz
480 1.8 spz tooshort:
481 1.10 christos ND_PRINT("\n\t\t packet is too short");
482 1.1 christos }
483 1.1 christos
484 1.5 christos static void
485 1.5 christos slow_oam_print(netdissect_options *ndo,
486 1.10 christos const u_char *tptr, u_int tlen)
487 1.6 christos {
488 1.10 christos uint8_t code;
489 1.10 christos uint8_t type, length;
490 1.10 christos uint8_t state;
491 1.10 christos uint8_t command;
492 1.1 christos u_int hexdump;
493 1.1 christos
494 1.1 christos struct slow_oam_common_header_t {
495 1.10 christos nd_uint16_t flags;
496 1.10 christos nd_uint8_t code;
497 1.1 christos };
498 1.1 christos
499 1.1 christos struct slow_oam_tlv_header_t {
500 1.10 christos nd_uint8_t type;
501 1.10 christos nd_uint8_t length;
502 1.1 christos };
503 1.1 christos
504 1.1 christos union {
505 1.1 christos const struct slow_oam_common_header_t *slow_oam_common_header;
506 1.1 christos const struct slow_oam_tlv_header_t *slow_oam_tlv_header;
507 1.1 christos } ptr;
508 1.1 christos
509 1.1 christos union {
510 1.10 christos const struct slow_oam_info_t *slow_oam_info;
511 1.1 christos const struct slow_oam_link_event_t *slow_oam_link_event;
512 1.1 christos const struct slow_oam_variablerequest_t *slow_oam_variablerequest;
513 1.1 christos const struct slow_oam_variableresponse_t *slow_oam_variableresponse;
514 1.1 christos const struct slow_oam_loopbackctrl_t *slow_oam_loopbackctrl;
515 1.1 christos } tlv;
516 1.5 christos
517 1.7 christos ptr.slow_oam_common_header = (const struct slow_oam_common_header_t *)tptr;
518 1.8 spz if (tlen < sizeof(*ptr.slow_oam_common_header))
519 1.8 spz goto tooshort;
520 1.10 christos ND_TCHECK_SIZE(ptr.slow_oam_common_header);
521 1.1 christos tptr += sizeof(struct slow_oam_common_header_t);
522 1.1 christos tlen -= sizeof(struct slow_oam_common_header_t);
523 1.1 christos
524 1.10 christos code = GET_U_1(ptr.slow_oam_common_header->code);
525 1.10 christos ND_PRINT("\n\tCode %s OAM PDU, Flags [%s]",
526 1.10 christos tok2str(slow_oam_code_values, "Unknown (%u)", code),
527 1.1 christos bittok2str(slow_oam_flag_values,
528 1.1 christos "none",
529 1.10 christos GET_BE_U_2(ptr.slow_oam_common_header->flags)));
530 1.1 christos
531 1.10 christos switch (code) {
532 1.1 christos case SLOW_OAM_CODE_INFO:
533 1.1 christos while (tlen > 0) {
534 1.1 christos ptr.slow_oam_tlv_header = (const struct slow_oam_tlv_header_t *)tptr;
535 1.8 spz if (tlen < sizeof(*ptr.slow_oam_tlv_header))
536 1.8 spz goto tooshort;
537 1.10 christos ND_TCHECK_SIZE(ptr.slow_oam_tlv_header);
538 1.10 christos type = GET_U_1(ptr.slow_oam_tlv_header->type);
539 1.10 christos length = GET_U_1(ptr.slow_oam_tlv_header->length);
540 1.10 christos ND_PRINT("\n\t %s Information Type (%u), length %u",
541 1.10 christos tok2str(slow_oam_info_type_values, "Reserved", type),
542 1.10 christos type,
543 1.10 christos length);
544 1.1 christos
545 1.10 christos if (type == SLOW_OAM_INFO_TYPE_END_OF_TLV) {
546 1.8 spz /*
547 1.8 spz * As IEEE Std 802.3-2015 says for the End of TLV Marker,
548 1.8 spz * "(the length and value of the Type 0x00 TLV can be ignored)".
549 1.8 spz */
550 1.8 spz return;
551 1.8 spz }
552 1.8 spz
553 1.8 spz /* length includes the type and length fields */
554 1.10 christos if (length < sizeof(struct slow_oam_tlv_header_t)) {
555 1.10 christos ND_PRINT("\n\t ERROR: illegal length - should be >= %zu",
556 1.10 christos sizeof(struct slow_oam_tlv_header_t));
557 1.8 spz return;
558 1.8 spz }
559 1.8 spz
560 1.10 christos if (tlen < length)
561 1.8 spz goto tooshort;
562 1.10 christos ND_TCHECK_LEN(tptr, length);
563 1.8 spz
564 1.1 christos hexdump = FALSE;
565 1.10 christos switch (type) {
566 1.1 christos case SLOW_OAM_INFO_TYPE_LOCAL: /* identical format - fall through */
567 1.1 christos case SLOW_OAM_INFO_TYPE_REMOTE:
568 1.1 christos tlv.slow_oam_info = (const struct slow_oam_info_t *)tptr;
569 1.5 christos
570 1.10 christos if (GET_U_1(tlv.slow_oam_info->info_length) !=
571 1.1 christos sizeof(struct slow_oam_info_t)) {
572 1.10 christos ND_PRINT("\n\t ERROR: illegal length - should be %zu",
573 1.10 christos sizeof(struct slow_oam_info_t));
574 1.8 spz hexdump = TRUE;
575 1.8 spz goto badlength_code_info;
576 1.1 christos }
577 1.1 christos
578 1.10 christos ND_PRINT("\n\t OAM-Version %u, Revision %u",
579 1.10 christos GET_U_1(tlv.slow_oam_info->oam_version),
580 1.10 christos GET_BE_U_2(tlv.slow_oam_info->revision));
581 1.1 christos
582 1.10 christos state = GET_U_1(tlv.slow_oam_info->state);
583 1.10 christos ND_PRINT("\n\t State-Parser-Action %s, State-MUX-Action %s",
584 1.1 christos tok2str(slow_oam_info_type_state_parser_values, "Reserved",
585 1.10 christos state & OAM_INFO_TYPE_PARSER_MASK),
586 1.1 christos tok2str(slow_oam_info_type_state_mux_values, "Reserved",
587 1.10 christos state & OAM_INFO_TYPE_MUX_MASK));
588 1.10 christos ND_PRINT("\n\t OAM-Config Flags [%s], OAM-PDU-Config max-PDU size %u",
589 1.1 christos bittok2str(slow_oam_info_type_oam_config_values, "none",
590 1.10 christos GET_U_1(tlv.slow_oam_info->oam_config)),
591 1.10 christos GET_BE_U_2(tlv.slow_oam_info->oam_pdu_config) &
592 1.10 christos OAM_INFO_TYPE_PDU_SIZE_MASK);
593 1.10 christos ND_PRINT("\n\t OUI %s (0x%06x), Vendor-Private 0x%08x",
594 1.1 christos tok2str(oui_values, "Unknown",
595 1.10 christos GET_BE_U_3(tlv.slow_oam_info->oui)),
596 1.10 christos GET_BE_U_3(tlv.slow_oam_info->oui),
597 1.10 christos GET_BE_U_4(tlv.slow_oam_info->vendor_private));
598 1.1 christos break;
599 1.5 christos
600 1.1 christos case SLOW_OAM_INFO_TYPE_ORG_SPECIFIC:
601 1.1 christos hexdump = TRUE;
602 1.1 christos break;
603 1.5 christos
604 1.1 christos default:
605 1.1 christos hexdump = TRUE;
606 1.1 christos break;
607 1.1 christos }
608 1.1 christos
609 1.8 spz badlength_code_info:
610 1.1 christos /* do we also want to see a hex dump ? */
611 1.5 christos if (ndo->ndo_vflag > 1 || hexdump==TRUE) {
612 1.5 christos print_unknown_data(ndo, tptr, "\n\t ",
613 1.10 christos length);
614 1.1 christos }
615 1.1 christos
616 1.10 christos tlen -= length;
617 1.10 christos tptr += length;
618 1.1 christos }
619 1.1 christos break;
620 1.1 christos
621 1.1 christos case SLOW_OAM_CODE_EVENT_NOTIF:
622 1.8 spz /* Sequence number */
623 1.8 spz if (tlen < 2)
624 1.8 spz goto tooshort;
625 1.10 christos ND_PRINT("\n\t Sequence Number %u", GET_BE_U_2(tptr));
626 1.8 spz tlen -= 2;
627 1.8 spz tptr += 2;
628 1.8 spz
629 1.8 spz /* TLVs */
630 1.1 christos while (tlen > 0) {
631 1.1 christos ptr.slow_oam_tlv_header = (const struct slow_oam_tlv_header_t *)tptr;
632 1.8 spz if (tlen < sizeof(*ptr.slow_oam_tlv_header))
633 1.8 spz goto tooshort;
634 1.10 christos type = GET_U_1(ptr.slow_oam_tlv_header->type);
635 1.10 christos length = GET_U_1(ptr.slow_oam_tlv_header->length);
636 1.10 christos ND_PRINT("\n\t %s Link Event Type (%u), length %u",
637 1.1 christos tok2str(slow_oam_link_event_values, "Reserved",
638 1.10 christos type),
639 1.10 christos type,
640 1.10 christos length);
641 1.1 christos
642 1.10 christos if (type == SLOW_OAM_INFO_TYPE_END_OF_TLV) {
643 1.8 spz /*
644 1.8 spz * As IEEE Std 802.3-2015 says for the End of TLV Marker,
645 1.8 spz * "(the length and value of the Type 0x00 TLV can be ignored)".
646 1.8 spz */
647 1.8 spz return;
648 1.8 spz }
649 1.8 spz
650 1.8 spz /* length includes the type and length fields */
651 1.10 christos if (length < sizeof(struct slow_oam_tlv_header_t)) {
652 1.10 christos ND_PRINT("\n\t ERROR: illegal length - should be >= %zu",
653 1.10 christos sizeof(struct slow_oam_tlv_header_t));
654 1.8 spz return;
655 1.8 spz }
656 1.8 spz
657 1.10 christos if (tlen < length)
658 1.8 spz goto tooshort;
659 1.10 christos ND_TCHECK_LEN(tptr, length);
660 1.8 spz
661 1.1 christos hexdump = FALSE;
662 1.10 christos switch (type) {
663 1.1 christos case SLOW_OAM_LINK_EVENT_ERR_SYM_PER: /* identical format - fall through */
664 1.1 christos case SLOW_OAM_LINK_EVENT_ERR_FRM:
665 1.1 christos case SLOW_OAM_LINK_EVENT_ERR_FRM_PER:
666 1.1 christos case SLOW_OAM_LINK_EVENT_ERR_FRM_SUMM:
667 1.1 christos tlv.slow_oam_link_event = (const struct slow_oam_link_event_t *)tptr;
668 1.5 christos
669 1.10 christos if (GET_U_1(tlv.slow_oam_link_event->event_length) !=
670 1.1 christos sizeof(struct slow_oam_link_event_t)) {
671 1.10 christos ND_PRINT("\n\t ERROR: illegal length - should be %zu",
672 1.10 christos sizeof(struct slow_oam_link_event_t));
673 1.8 spz hexdump = TRUE;
674 1.8 spz goto badlength_event_notif;
675 1.1 christos }
676 1.1 christos
677 1.10 christos ND_PRINT("\n\t Timestamp %u ms, Errored Window %" PRIu64
678 1.1 christos "\n\t Errored Threshold %" PRIu64
679 1.1 christos "\n\t Errors %" PRIu64
680 1.1 christos "\n\t Error Running Total %" PRIu64
681 1.1 christos "\n\t Event Running Total %u",
682 1.10 christos GET_BE_U_2(tlv.slow_oam_link_event->time_stamp)*100,
683 1.10 christos GET_BE_U_8(tlv.slow_oam_link_event->window),
684 1.10 christos GET_BE_U_8(tlv.slow_oam_link_event->threshold),
685 1.10 christos GET_BE_U_8(tlv.slow_oam_link_event->errors),
686 1.10 christos GET_BE_U_8(tlv.slow_oam_link_event->errors_running_total),
687 1.10 christos GET_BE_U_4(tlv.slow_oam_link_event->event_running_total));
688 1.1 christos break;
689 1.5 christos
690 1.1 christos case SLOW_OAM_LINK_EVENT_ORG_SPECIFIC:
691 1.1 christos hexdump = TRUE;
692 1.1 christos break;
693 1.5 christos
694 1.1 christos default:
695 1.1 christos hexdump = TRUE;
696 1.1 christos break;
697 1.1 christos }
698 1.1 christos
699 1.8 spz badlength_event_notif:
700 1.1 christos /* do we also want to see a hex dump ? */
701 1.5 christos if (ndo->ndo_vflag > 1 || hexdump==TRUE) {
702 1.5 christos print_unknown_data(ndo, tptr, "\n\t ",
703 1.10 christos length);
704 1.1 christos }
705 1.1 christos
706 1.10 christos tlen -= length;
707 1.10 christos tptr += length;
708 1.1 christos }
709 1.1 christos break;
710 1.5 christos
711 1.1 christos case SLOW_OAM_CODE_LOOPBACK_CTRL:
712 1.1 christos tlv.slow_oam_loopbackctrl = (const struct slow_oam_loopbackctrl_t *)tptr;
713 1.8 spz if (tlen < sizeof(*tlv.slow_oam_loopbackctrl))
714 1.8 spz goto tooshort;
715 1.10 christos command = GET_U_1(tlv.slow_oam_loopbackctrl->command);
716 1.10 christos ND_PRINT("\n\t Command %s (%u)",
717 1.1 christos tok2str(slow_oam_loopbackctrl_cmd_values,
718 1.1 christos "Unknown",
719 1.10 christos command),
720 1.10 christos command);
721 1.8 spz tptr ++;
722 1.8 spz tlen --;
723 1.1 christos break;
724 1.1 christos
725 1.1 christos /*
726 1.1 christos * FIXME those are the defined codes that lack a decoder
727 1.1 christos * you are welcome to contribute code ;-)
728 1.1 christos */
729 1.1 christos case SLOW_OAM_CODE_VAR_REQUEST:
730 1.1 christos case SLOW_OAM_CODE_VAR_RESPONSE:
731 1.1 christos case SLOW_OAM_CODE_PRIVATE:
732 1.1 christos default:
733 1.5 christos if (ndo->ndo_vflag <= 1) {
734 1.5 christos print_unknown_data(ndo, tptr, "\n\t ", tlen);
735 1.1 christos }
736 1.1 christos break;
737 1.1 christos }
738 1.1 christos return;
739 1.8 spz
740 1.8 spz tooshort:
741 1.10 christos ND_PRINT("\n\t\t packet is too short");
742 1.1 christos }
743