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