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