]> The Tcpdump Group git mirrors - tcpdump/blob - print-slow.c
Revert partially the commit 21b1273
[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 subtype = GET_U_1(pptr);
255
256 /*
257 * Sanity checking of the header.
258 */
259 switch (subtype) {
260 case SLOW_PROTO_LACP:
261 if (len < 2)
262 goto tooshort;
263 if (GET_U_1(pptr + 1) != LACP_VERSION) {
264 ND_PRINT("LACP version %u packet not supported",
265 GET_U_1(pptr + 1));
266 return;
267 }
268 print_version = 1;
269 break;
270
271 case SLOW_PROTO_MARKER:
272 if (len < 2)
273 goto tooshort;
274 if (GET_U_1(pptr + 1) != MARKER_VERSION) {
275 ND_PRINT("MARKER version %u packet not supported",
276 GET_U_1(pptr + 1));
277 return;
278 }
279 print_version = 1;
280 break;
281
282 case SLOW_PROTO_OAM: /* fall through */
283 print_version = 0;
284 break;
285
286 default:
287 /* print basic information and exit */
288 print_version = -1;
289 break;
290 }
291
292 if (print_version == 1) {
293 ND_PRINT("%sv%u, length %u",
294 tok2str(slow_proto_values, "unknown (%u)", subtype),
295 GET_U_1((pptr + 1)),
296 len);
297 } else {
298 /* some slow protos don't have a version number in the header */
299 ND_PRINT("%s, length %u",
300 tok2str(slow_proto_values, "unknown (%u)", subtype),
301 len);
302 }
303
304 /* unrecognized subtype */
305 if (print_version == -1) {
306 print_unknown_data(ndo, pptr, "\n\t", len);
307 return;
308 }
309
310 if (!ndo->ndo_vflag)
311 return;
312
313 switch (subtype) {
314 default: /* should not happen */
315 break;
316
317 case SLOW_PROTO_OAM:
318 /* skip subtype */
319 len -= 1;
320 pptr += 1;
321 slow_oam_print(ndo, pptr, len);
322 break;
323
324 case SLOW_PROTO_LACP: /* LACP and MARKER share the same semantics */
325 case SLOW_PROTO_MARKER:
326 /* skip subtype and version */
327 len -= 2;
328 pptr += 2;
329 slow_marker_lacp_print(ndo, pptr, len, subtype);
330 break;
331 }
332 return;
333
334 tooshort:
335 if (!ndo->ndo_vflag)
336 ND_PRINT(" (packet is too short)");
337 else
338 ND_PRINT("\n\t\t packet is too short");
339 }
340
341 static void
342 slow_marker_lacp_print(netdissect_options *ndo,
343 const u_char *tptr, u_int tlen,
344 u_int proto_subtype)
345 {
346 const struct tlv_header_t *tlv_header;
347 const u_char *tlv_tptr;
348 u_int tlv_type, tlv_len, tlv_tlen;
349
350 union {
351 const struct lacp_marker_tlv_terminator_t *lacp_marker_tlv_terminator;
352 const struct lacp_tlv_actor_partner_info_t *lacp_tlv_actor_partner_info;
353 const struct lacp_tlv_collector_info_t *lacp_tlv_collector_info;
354 const struct marker_tlv_marker_info_t *marker_tlv_marker_info;
355 } tlv_ptr;
356
357 while(tlen>0) {
358 /* is the packet big enough to include the tlv header ? */
359 if (tlen < sizeof(struct tlv_header_t))
360 goto tooshort;
361 /* did we capture enough for fully decoding the tlv header ? */
362 ND_TCHECK_LEN(tptr, sizeof(struct tlv_header_t));
363 tlv_header = (const struct tlv_header_t *)tptr;
364 tlv_type = GET_U_1(tlv_header->type);
365 tlv_len = GET_U_1(tlv_header->length);
366
367 ND_PRINT("\n\t%s TLV (0x%02x), length %u",
368 tok2str(slow_tlv_values,
369 "Unknown",
370 (proto_subtype << 8) + tlv_type),
371 tlv_type,
372 tlv_len);
373
374 if (tlv_type == LACP_MARKER_TLV_TERMINATOR) {
375 /*
376 * This TLV has a length of zero, and means there are no
377 * more TLVs to process.
378 */
379 return;
380 }
381
382 /* length includes the type and length fields */
383 if (tlv_len < sizeof(struct tlv_header_t)) {
384 ND_PRINT("\n\t ERROR: illegal length - should be >= %zu",
385 sizeof(struct tlv_header_t));
386 return;
387 }
388
389 /* is the packet big enough to include the tlv ? */
390 if (tlen < tlv_len)
391 goto tooshort;
392 /* did we capture enough for fully decoding the tlv ? */
393 ND_TCHECK_LEN(tptr, tlv_len);
394
395 tlv_tptr=tptr+sizeof(struct tlv_header_t);
396 tlv_tlen=tlv_len-sizeof(struct tlv_header_t);
397
398 switch((proto_subtype << 8) + tlv_type) {
399
400 /* those two TLVs have the same structure -> fall through */
401 case ((SLOW_PROTO_LACP << 8) + LACP_TLV_ACTOR_INFO):
402 case ((SLOW_PROTO_LACP << 8) + LACP_TLV_PARTNER_INFO):
403 if (tlv_tlen !=
404 sizeof(struct lacp_tlv_actor_partner_info_t)) {
405 ND_PRINT("\n\t ERROR: illegal length - should be %zu",
406 sizeof(struct tlv_header_t) + sizeof(struct lacp_tlv_actor_partner_info_t));
407 goto badlength;
408 }
409
410 tlv_ptr.lacp_tlv_actor_partner_info = (const struct lacp_tlv_actor_partner_info_t *)tlv_tptr;
411
412 ND_PRINT("\n\t System %s, System Priority %u, Key %u"
413 ", Port %u, Port Priority %u\n\t State Flags [%s]",
414 GET_ETHERADDR_STRING(tlv_ptr.lacp_tlv_actor_partner_info->sys),
415 GET_BE_U_2(tlv_ptr.lacp_tlv_actor_partner_info->sys_pri),
416 GET_BE_U_2(tlv_ptr.lacp_tlv_actor_partner_info->key),
417 GET_BE_U_2(tlv_ptr.lacp_tlv_actor_partner_info->port),
418 GET_BE_U_2(tlv_ptr.lacp_tlv_actor_partner_info->port_pri),
419 bittok2str(lacp_tlv_actor_partner_info_state_values,
420 "none",
421 GET_U_1(tlv_ptr.lacp_tlv_actor_partner_info->state)));
422
423 break;
424
425 case ((SLOW_PROTO_LACP << 8) + LACP_TLV_COLLECTOR_INFO):
426 if (tlv_tlen !=
427 sizeof(struct lacp_tlv_collector_info_t)) {
428 ND_PRINT("\n\t ERROR: illegal length - should be %zu",
429 sizeof(struct tlv_header_t) + sizeof(struct lacp_tlv_collector_info_t));
430 goto badlength;
431 }
432
433 tlv_ptr.lacp_tlv_collector_info = (const struct lacp_tlv_collector_info_t *)tlv_tptr;
434
435 ND_PRINT("\n\t Max Delay %u",
436 GET_BE_U_2(tlv_ptr.lacp_tlv_collector_info->max_delay));
437
438 break;
439
440 case ((SLOW_PROTO_MARKER << 8) + MARKER_TLV_MARKER_INFO):
441 if (tlv_tlen !=
442 sizeof(struct marker_tlv_marker_info_t)) {
443 ND_PRINT("\n\t ERROR: illegal length - should be %zu",
444 sizeof(struct tlv_header_t) + sizeof(struct marker_tlv_marker_info_t));
445 goto badlength;
446 }
447
448 tlv_ptr.marker_tlv_marker_info = (const struct marker_tlv_marker_info_t *)tlv_tptr;
449
450 ND_PRINT("\n\t Request System %s, Request Port %u, Request Transaction ID 0x%08x",
451 GET_ETHERADDR_STRING(tlv_ptr.marker_tlv_marker_info->req_sys),
452 GET_BE_U_2(tlv_ptr.marker_tlv_marker_info->req_port),
453 GET_BE_U_4(tlv_ptr.marker_tlv_marker_info->req_trans_id));
454
455 break;
456
457 default:
458 if (ndo->ndo_vflag <= 1)
459 print_unknown_data(ndo, tlv_tptr, "\n\t ", tlv_tlen);
460 break;
461 }
462
463 badlength:
464 /* do we want to see an additional hexdump ? */
465 if (ndo->ndo_vflag > 1) {
466 print_unknown_data(ndo, tptr+sizeof(struct tlv_header_t), "\n\t ",
467 tlv_len-sizeof(struct tlv_header_t));
468 }
469
470 tptr+=tlv_len;
471 tlen-=tlv_len;
472 }
473 return;
474
475 tooshort:
476 ND_PRINT("\n\t\t packet is too short");
477 return;
478
479 trunc:
480 nd_print_trunc(ndo);
481 }
482
483 static void
484 slow_oam_print(netdissect_options *ndo,
485 const u_char *tptr, u_int tlen)
486 {
487 uint8_t code;
488 uint8_t type, length;
489 uint8_t state;
490 uint8_t command;
491 u_int hexdump;
492
493 struct slow_oam_common_header_t {
494 nd_uint16_t flags;
495 nd_uint8_t code;
496 };
497
498 struct slow_oam_tlv_header_t {
499 nd_uint8_t type;
500 nd_uint8_t length;
501 };
502
503 union {
504 const struct slow_oam_common_header_t *slow_oam_common_header;
505 const struct slow_oam_tlv_header_t *slow_oam_tlv_header;
506 } ptr;
507
508 union {
509 const struct slow_oam_info_t *slow_oam_info;
510 const struct slow_oam_link_event_t *slow_oam_link_event;
511 const struct slow_oam_variablerequest_t *slow_oam_variablerequest;
512 const struct slow_oam_variableresponse_t *slow_oam_variableresponse;
513 const struct slow_oam_loopbackctrl_t *slow_oam_loopbackctrl;
514 } tlv;
515
516 ptr.slow_oam_common_header = (const struct slow_oam_common_header_t *)tptr;
517 if (tlen < sizeof(*ptr.slow_oam_common_header))
518 goto tooshort;
519 ND_TCHECK_SIZE(ptr.slow_oam_common_header);
520 tptr += sizeof(struct slow_oam_common_header_t);
521 tlen -= sizeof(struct slow_oam_common_header_t);
522
523 code = GET_U_1(ptr.slow_oam_common_header->code);
524 ND_PRINT("\n\tCode %s OAM PDU, Flags [%s]",
525 tok2str(slow_oam_code_values, "Unknown (%u)", code),
526 bittok2str(slow_oam_flag_values,
527 "none",
528 GET_BE_U_2(ptr.slow_oam_common_header->flags)));
529
530 switch (code) {
531 case SLOW_OAM_CODE_INFO:
532 while (tlen > 0) {
533 ptr.slow_oam_tlv_header = (const struct slow_oam_tlv_header_t *)tptr;
534 if (tlen < sizeof(*ptr.slow_oam_tlv_header))
535 goto tooshort;
536 ND_TCHECK_SIZE(ptr.slow_oam_tlv_header);
537 type = GET_U_1(ptr.slow_oam_tlv_header->type);
538 length = GET_U_1(ptr.slow_oam_tlv_header->length);
539 ND_PRINT("\n\t %s Information Type (%u), length %u",
540 tok2str(slow_oam_info_type_values, "Reserved", type),
541 type,
542 length);
543
544 if (type == SLOW_OAM_INFO_TYPE_END_OF_TLV) {
545 /*
546 * As IEEE Std 802.3-2015 says for the End of TLV Marker,
547 * "(the length and value of the Type 0x00 TLV can be ignored)".
548 */
549 return;
550 }
551
552 /* length includes the type and length fields */
553 if (length < sizeof(struct slow_oam_tlv_header_t)) {
554 ND_PRINT("\n\t ERROR: illegal length - should be >= %u",
555 (u_int)sizeof(struct slow_oam_tlv_header_t));
556 return;
557 }
558
559 if (tlen < length)
560 goto tooshort;
561 ND_TCHECK_LEN(tptr, length);
562
563 hexdump = FALSE;
564 switch (type) {
565 case SLOW_OAM_INFO_TYPE_LOCAL: /* identical format - fall through */
566 case SLOW_OAM_INFO_TYPE_REMOTE:
567 tlv.slow_oam_info = (const struct slow_oam_info_t *)tptr;
568
569 if (GET_U_1(tlv.slow_oam_info->info_length) !=
570 sizeof(struct slow_oam_info_t)) {
571 ND_PRINT("\n\t ERROR: illegal length - should be %zu",
572 sizeof(struct slow_oam_info_t));
573 hexdump = TRUE;
574 goto badlength_code_info;
575 }
576
577 ND_PRINT("\n\t OAM-Version %u, Revision %u",
578 GET_U_1(tlv.slow_oam_info->oam_version),
579 GET_BE_U_2(tlv.slow_oam_info->revision));
580
581 state = GET_U_1(tlv.slow_oam_info->state);
582 ND_PRINT("\n\t State-Parser-Action %s, State-MUX-Action %s",
583 tok2str(slow_oam_info_type_state_parser_values, "Reserved",
584 state & OAM_INFO_TYPE_PARSER_MASK),
585 tok2str(slow_oam_info_type_state_mux_values, "Reserved",
586 state & OAM_INFO_TYPE_MUX_MASK));
587 ND_PRINT("\n\t OAM-Config Flags [%s], OAM-PDU-Config max-PDU size %u",
588 bittok2str(slow_oam_info_type_oam_config_values, "none",
589 GET_U_1(tlv.slow_oam_info->oam_config)),
590 GET_BE_U_2(tlv.slow_oam_info->oam_pdu_config) &
591 OAM_INFO_TYPE_PDU_SIZE_MASK);
592 ND_PRINT("\n\t OUI %s (0x%06x), Vendor-Private 0x%08x",
593 tok2str(oui_values, "Unknown",
594 GET_BE_U_3(tlv.slow_oam_info->oui)),
595 GET_BE_U_3(tlv.slow_oam_info->oui),
596 GET_BE_U_4(tlv.slow_oam_info->vendor_private));
597 break;
598
599 case SLOW_OAM_INFO_TYPE_ORG_SPECIFIC:
600 hexdump = TRUE;
601 break;
602
603 default:
604 hexdump = TRUE;
605 break;
606 }
607
608 badlength_code_info:
609 /* do we also want to see a hex dump ? */
610 if (ndo->ndo_vflag > 1 || hexdump==TRUE) {
611 print_unknown_data(ndo, tptr, "\n\t ",
612 length);
613 }
614
615 tlen -= length;
616 tptr += length;
617 }
618 break;
619
620 case SLOW_OAM_CODE_EVENT_NOTIF:
621 /* Sequence number */
622 if (tlen < 2)
623 goto tooshort;
624 ND_PRINT("\n\t Sequence Number %u", GET_BE_U_2(tptr));
625 tlen -= 2;
626 tptr += 2;
627
628 /* TLVs */
629 while (tlen > 0) {
630 ptr.slow_oam_tlv_header = (const struct slow_oam_tlv_header_t *)tptr;
631 if (tlen < sizeof(*ptr.slow_oam_tlv_header))
632 goto tooshort;
633 ND_TCHECK_SIZE(ptr.slow_oam_tlv_header);
634 type = GET_U_1(ptr.slow_oam_tlv_header->type);
635 length = GET_U_1(ptr.slow_oam_tlv_header->length);
636 ND_PRINT("\n\t %s Link Event Type (%u), length %u",
637 tok2str(slow_oam_link_event_values, "Reserved",
638 type),
639 type,
640 length);
641
642 if (type == SLOW_OAM_INFO_TYPE_END_OF_TLV) {
643 /*
644 * As IEEE Std 802.3-2015 says for the End of TLV Marker,
645 * "(the length and value of the Type 0x00 TLV can be ignored)".
646 */
647 return;
648 }
649
650 /* length includes the type and length fields */
651 if (length < sizeof(struct slow_oam_tlv_header_t)) {
652 ND_PRINT("\n\t ERROR: illegal length - should be >= %u",
653 (u_int)sizeof(struct slow_oam_tlv_header_t));
654 return;
655 }
656
657 if (tlen < length)
658 goto tooshort;
659 ND_TCHECK_LEN(tptr, length);
660
661 hexdump = FALSE;
662 switch (type) {
663 case SLOW_OAM_LINK_EVENT_ERR_SYM_PER: /* identical format - fall through */
664 case SLOW_OAM_LINK_EVENT_ERR_FRM:
665 case SLOW_OAM_LINK_EVENT_ERR_FRM_PER:
666 case SLOW_OAM_LINK_EVENT_ERR_FRM_SUMM:
667 tlv.slow_oam_link_event = (const struct slow_oam_link_event_t *)tptr;
668
669 if (GET_U_1(tlv.slow_oam_link_event->event_length) !=
670 sizeof(struct slow_oam_link_event_t)) {
671 ND_PRINT("\n\t ERROR: illegal length - should be %zu",
672 sizeof(struct slow_oam_link_event_t));
673 hexdump = TRUE;
674 goto badlength_event_notif;
675 }
676
677 ND_PRINT("\n\t Timestamp %u ms, Errored Window %" PRIu64
678 "\n\t Errored Threshold %" PRIu64
679 "\n\t Errors %" PRIu64
680 "\n\t Error Running Total %" PRIu64
681 "\n\t Event Running Total %u",
682 GET_BE_U_2(tlv.slow_oam_link_event->time_stamp)*100,
683 GET_BE_U_8(tlv.slow_oam_link_event->window),
684 GET_BE_U_8(tlv.slow_oam_link_event->threshold),
685 GET_BE_U_8(tlv.slow_oam_link_event->errors),
686 GET_BE_U_8(tlv.slow_oam_link_event->errors_running_total),
687 GET_BE_U_4(tlv.slow_oam_link_event->event_running_total));
688 break;
689
690 case SLOW_OAM_LINK_EVENT_ORG_SPECIFIC:
691 hexdump = TRUE;
692 break;
693
694 default:
695 hexdump = TRUE;
696 break;
697 }
698
699 badlength_event_notif:
700 /* do we also want to see a hex dump ? */
701 if (ndo->ndo_vflag > 1 || hexdump==TRUE) {
702 print_unknown_data(ndo, tptr, "\n\t ",
703 length);
704 }
705
706 tlen -= length;
707 tptr += length;
708 }
709 break;
710
711 case SLOW_OAM_CODE_LOOPBACK_CTRL:
712 tlv.slow_oam_loopbackctrl = (const struct slow_oam_loopbackctrl_t *)tptr;
713 if (tlen < sizeof(*tlv.slow_oam_loopbackctrl))
714 goto tooshort;
715 ND_TCHECK_SIZE(tlv.slow_oam_loopbackctrl);
716 command = GET_U_1(tlv.slow_oam_loopbackctrl->command);
717 ND_PRINT("\n\t Command %s (%u)",
718 tok2str(slow_oam_loopbackctrl_cmd_values,
719 "Unknown",
720 command),
721 command);
722 tptr ++;
723 tlen --;
724 break;
725
726 /*
727 * FIXME those are the defined codes that lack a decoder
728 * you are welcome to contribute code ;-)
729 */
730 case SLOW_OAM_CODE_VAR_REQUEST:
731 case SLOW_OAM_CODE_VAR_RESPONSE:
732 case SLOW_OAM_CODE_PRIVATE:
733 default:
734 if (ndo->ndo_vflag <= 1) {
735 print_unknown_data(ndo, tptr, "\n\t ", tlen);
736 }
737 break;
738 }
739 return;
740
741 tooshort:
742 ND_PRINT("\n\t\t packet is too short");
743 return;
744
745 trunc:
746 nd_print_trunc(ndo);
747 }