]> The Tcpdump Group git mirrors - tcpdump/blob - print-cfm.c
Use the new GET_ macros instead of the EXTRACT_ ones
[tcpdump] / print-cfm.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 * Original code by Hannes Gredler (hannes@gredler.at)
16 */
17
18 /* \summary: IEEE 802.1ag Connectivity Fault Management (CFM) protocols printer */
19
20 #ifdef HAVE_CONFIG_H
21 #include <config.h>
22 #endif
23
24 #include "netdissect-stdinc.h"
25
26 #include <stdio.h>
27
28 #include "netdissect.h"
29 #include "extract.h"
30 #include "addrtoname.h"
31 #include "oui.h"
32 #include "af.h"
33
34
35 struct cfm_common_header_t {
36 nd_uint8_t mdlevel_version;
37 nd_uint8_t opcode;
38 nd_uint8_t flags;
39 nd_uint8_t first_tlv_offset;
40 };
41
42 #define CFM_VERSION 0
43 #define CFM_EXTRACT_VERSION(x) ((x)&0x1f)
44 #define CFM_EXTRACT_MD_LEVEL(x) (((x)&0xe0)>>5)
45
46 #define CFM_OPCODE_CCM 1
47 #define CFM_OPCODE_LBR 2
48 #define CFM_OPCODE_LBM 3
49 #define CFM_OPCODE_LTR 4
50 #define CFM_OPCODE_LTM 5
51
52 static const struct tok cfm_opcode_values[] = {
53 { CFM_OPCODE_CCM, "Continuity Check Message"},
54 { CFM_OPCODE_LBR, "Loopback Reply"},
55 { CFM_OPCODE_LBM, "Loopback Message"},
56 { CFM_OPCODE_LTR, "Linktrace Reply"},
57 { CFM_OPCODE_LTM, "Linktrace Message"},
58 { 0, NULL}
59 };
60
61 /*
62 * Message Formats.
63 */
64 struct cfm_ccm_t {
65 nd_uint32_t sequence;
66 nd_uint16_t ma_epi;
67 nd_byte names[48];
68 nd_byte itu_t_y_1731[16];
69 };
70
71 /*
72 * Timer Bases for the CCM Interval field.
73 * Expressed in units of seconds.
74 */
75 static const float ccm_interval_base[8] = {0.0f, 0.003333f, 0.01f, 0.1f, 1.0f, 10.0f, 60.0f, 600.0f};
76 #define CCM_INTERVAL_MIN_MULTIPLIER 3.25
77 #define CCM_INTERVAL_MAX_MULTIPLIER 3.5
78
79 #define CFM_CCM_RDI_FLAG 0x80
80 #define CFM_EXTRACT_CCM_INTERVAL(x) ((x)&0x07)
81
82 #define CFM_CCM_MD_FORMAT_8021 0
83 #define CFM_CCM_MD_FORMAT_NONE 1
84 #define CFM_CCM_MD_FORMAT_DNS 2
85 #define CFM_CCM_MD_FORMAT_MAC 3
86 #define CFM_CCM_MD_FORMAT_CHAR 4
87
88 static const struct tok cfm_md_nameformat_values[] = {
89 { CFM_CCM_MD_FORMAT_8021, "IEEE 802.1"},
90 { CFM_CCM_MD_FORMAT_NONE, "No MD Name present"},
91 { CFM_CCM_MD_FORMAT_DNS, "DNS string"},
92 { CFM_CCM_MD_FORMAT_MAC, "MAC + 16Bit Integer"},
93 { CFM_CCM_MD_FORMAT_CHAR, "Character string"},
94 { 0, NULL}
95 };
96
97 #define CFM_CCM_MA_FORMAT_8021 0
98 #define CFM_CCM_MA_FORMAT_VID 1
99 #define CFM_CCM_MA_FORMAT_CHAR 2
100 #define CFM_CCM_MA_FORMAT_INT 3
101 #define CFM_CCM_MA_FORMAT_VPN 4
102
103 static const struct tok cfm_ma_nameformat_values[] = {
104 { CFM_CCM_MA_FORMAT_8021, "IEEE 802.1"},
105 { CFM_CCM_MA_FORMAT_VID, "Primary VID"},
106 { CFM_CCM_MA_FORMAT_CHAR, "Character string"},
107 { CFM_CCM_MA_FORMAT_INT, "16Bit Integer"},
108 { CFM_CCM_MA_FORMAT_VPN, "RFC2685 VPN-ID"},
109 { 0, NULL}
110 };
111
112 struct cfm_lbm_t {
113 nd_uint32_t transaction_id;
114 };
115
116 struct cfm_ltm_t {
117 nd_uint32_t transaction_id;
118 nd_uint8_t ttl;
119 nd_mac_addr original_mac;
120 nd_mac_addr target_mac;
121 };
122
123 static const struct tok cfm_ltm_flag_values[] = {
124 { 0x80, "Use Forwarding-DB only"},
125 { 0, NULL}
126 };
127
128 struct cfm_ltr_t {
129 nd_uint32_t transaction_id;
130 nd_uint8_t ttl;
131 nd_uint8_t replay_action;
132 };
133
134 static const struct tok cfm_ltr_flag_values[] = {
135 { 0x80, "UseFDB Only"},
136 { 0x40, "FwdYes"},
137 { 0x20, "Terminal MEP"},
138 { 0, NULL}
139 };
140
141 static const struct tok cfm_ltr_replay_action_values[] = {
142 { 1, "Exact Match"},
143 { 2, "Filtering DB"},
144 { 3, "MIP CCM DB"},
145 { 0, NULL}
146 };
147
148
149 #define CFM_TLV_END 0
150 #define CFM_TLV_SENDER_ID 1
151 #define CFM_TLV_PORT_STATUS 2
152 #define CFM_TLV_INTERFACE_STATUS 3
153 #define CFM_TLV_DATA 4
154 #define CFM_TLV_REPLY_INGRESS 5
155 #define CFM_TLV_REPLY_EGRESS 6
156 #define CFM_TLV_PRIVATE 31
157
158 static const struct tok cfm_tlv_values[] = {
159 { CFM_TLV_END, "End"},
160 { CFM_TLV_SENDER_ID, "Sender ID"},
161 { CFM_TLV_PORT_STATUS, "Port status"},
162 { CFM_TLV_INTERFACE_STATUS, "Interface status"},
163 { CFM_TLV_DATA, "Data"},
164 { CFM_TLV_REPLY_INGRESS, "Reply Ingress"},
165 { CFM_TLV_REPLY_EGRESS, "Reply Egress"},
166 { CFM_TLV_PRIVATE, "Organization Specific"},
167 { 0, NULL}
168 };
169
170 /*
171 * TLVs
172 */
173
174 struct cfm_tlv_header_t {
175 nd_uint8_t type;
176 nd_uint16_t length;
177 };
178
179 /* FIXME define TLV formats */
180
181 static const struct tok cfm_tlv_port_status_values[] = {
182 { 1, "Blocked"},
183 { 2, "Up"},
184 { 0, NULL}
185 };
186
187 static const struct tok cfm_tlv_interface_status_values[] = {
188 { 1, "Up"},
189 { 2, "Down"},
190 { 3, "Testing"},
191 { 5, "Dormant"},
192 { 6, "not present"},
193 { 7, "lower Layer down"},
194 { 0, NULL}
195 };
196
197 #define CFM_CHASSIS_ID_CHASSIS_COMPONENT 1
198 #define CFM_CHASSIS_ID_INTERFACE_ALIAS 2
199 #define CFM_CHASSIS_ID_PORT_COMPONENT 3
200 #define CFM_CHASSIS_ID_MAC_ADDRESS 4
201 #define CFM_CHASSIS_ID_NETWORK_ADDRESS 5
202 #define CFM_CHASSIS_ID_INTERFACE_NAME 6
203 #define CFM_CHASSIS_ID_LOCAL 7
204
205 static const struct tok cfm_tlv_senderid_chassisid_values[] = {
206 { 0, "Reserved"},
207 { CFM_CHASSIS_ID_CHASSIS_COMPONENT, "Chassis component"},
208 { CFM_CHASSIS_ID_INTERFACE_ALIAS, "Interface alias"},
209 { CFM_CHASSIS_ID_PORT_COMPONENT, "Port component"},
210 { CFM_CHASSIS_ID_MAC_ADDRESS, "MAC address"},
211 { CFM_CHASSIS_ID_NETWORK_ADDRESS, "Network address"},
212 { CFM_CHASSIS_ID_INTERFACE_NAME, "Interface name"},
213 { CFM_CHASSIS_ID_LOCAL, "Locally assigned"},
214 { 0, NULL}
215 };
216
217
218 static int
219 cfm_network_addr_print(netdissect_options *ndo,
220 const u_char *tptr, const u_int length)
221 {
222 u_int network_addr_type;
223 u_int hexdump = FALSE;
224
225 /*
226 * Although AFIs are typically 2 octects wide,
227 * 802.1ab specifies that this field width
228 * is only one octet.
229 */
230 if (length < 1) {
231 ND_PRINT("\n\t Network Address Type (invalid, no data");
232 return hexdump;
233 }
234 /* The calling function must make any due ND_TCHECK calls. */
235 network_addr_type = GET_U_1(tptr);
236 ND_PRINT("\n\t Network Address Type %s (%u)",
237 tok2str(af_values, "Unknown", network_addr_type),
238 network_addr_type);
239
240 /*
241 * Resolve the passed in Address.
242 */
243 switch(network_addr_type) {
244 case AFNUM_INET:
245 if (length != 1 + 4) {
246 ND_PRINT("(invalid IPv4 address length %u)", length - 1);
247 hexdump = TRUE;
248 break;
249 }
250 ND_PRINT(", %s", ipaddr_string(ndo, tptr + 1));
251 break;
252
253 case AFNUM_INET6:
254 if (length != 1 + 16) {
255 ND_PRINT("(invalid IPv6 address length %u)", length - 1);
256 hexdump = TRUE;
257 break;
258 }
259 ND_PRINT(", %s", ip6addr_string(ndo, tptr + 1));
260 break;
261
262 default:
263 hexdump = TRUE;
264 break;
265 }
266
267 return hexdump;
268 }
269
270 void
271 cfm_print(netdissect_options *ndo,
272 const u_char *pptr, u_int length)
273 {
274 const struct cfm_common_header_t *cfm_common_header;
275 uint8_t mdlevel_version, opcode, flags, first_tlv_offset;
276 const struct cfm_tlv_header_t *cfm_tlv_header;
277 const uint8_t *tptr, *tlv_ptr;
278 const uint8_t *namesp;
279 u_int names_data_remaining;
280 uint8_t md_nameformat, md_namelength;
281 const uint8_t *md_name;
282 uint8_t ma_nameformat, ma_namelength;
283 const uint8_t *ma_name;
284 u_int hexdump, tlen, cfm_tlv_len, cfm_tlv_type, ccm_interval;
285
286
287 union {
288 const struct cfm_ccm_t *cfm_ccm;
289 const struct cfm_lbm_t *cfm_lbm;
290 const struct cfm_ltm_t *cfm_ltm;
291 const struct cfm_ltr_t *cfm_ltr;
292 } msg_ptr;
293
294 ndo->ndo_protocol = "cfm";
295 tptr=pptr;
296 cfm_common_header = (const struct cfm_common_header_t *)pptr;
297 if (length < sizeof(*cfm_common_header))
298 goto tooshort;
299 ND_TCHECK_SIZE(cfm_common_header);
300
301 /*
302 * Sanity checking of the header.
303 */
304 mdlevel_version = GET_U_1(cfm_common_header->mdlevel_version);
305 if (CFM_EXTRACT_VERSION(mdlevel_version) != CFM_VERSION) {
306 ND_PRINT("CFMv%u not supported, length %u",
307 CFM_EXTRACT_VERSION(mdlevel_version), length);
308 return;
309 }
310
311 opcode = GET_U_1(cfm_common_header->opcode);
312 ND_PRINT("CFMv%u %s, MD Level %u, length %u",
313 CFM_EXTRACT_VERSION(mdlevel_version),
314 tok2str(cfm_opcode_values, "unknown (%u)", opcode),
315 CFM_EXTRACT_MD_LEVEL(mdlevel_version),
316 length);
317
318 /*
319 * In non-verbose mode just print the opcode and md-level.
320 */
321 if (ndo->ndo_vflag < 1) {
322 return;
323 }
324
325 flags = GET_U_1(cfm_common_header->flags);
326 first_tlv_offset = GET_U_1(cfm_common_header->first_tlv_offset);
327 ND_PRINT("\n\tFirst TLV offset %u", first_tlv_offset);
328
329 tptr += sizeof(struct cfm_common_header_t);
330 tlen = length - sizeof(struct cfm_common_header_t);
331
332 /*
333 * Sanity check the first TLV offset.
334 */
335 if (first_tlv_offset > tlen) {
336 ND_PRINT(" (too large, must be <= %u)", tlen);
337 return;
338 }
339
340 switch (opcode) {
341 case CFM_OPCODE_CCM:
342 msg_ptr.cfm_ccm = (const struct cfm_ccm_t *)tptr;
343 if (first_tlv_offset < sizeof(*msg_ptr.cfm_ccm)) {
344 ND_PRINT(" (too small 1, must be >= %lu)",
345 (unsigned long) sizeof(*msg_ptr.cfm_ccm));
346 return;
347 }
348 if (tlen < sizeof(*msg_ptr.cfm_ccm))
349 goto tooshort;
350 ND_TCHECK_SIZE(msg_ptr.cfm_ccm);
351
352 ccm_interval = CFM_EXTRACT_CCM_INTERVAL(flags);
353 ND_PRINT(", Flags [CCM Interval %u%s]",
354 ccm_interval,
355 flags & CFM_CCM_RDI_FLAG ?
356 ", RDI" : "");
357
358 /*
359 * Resolve the CCM interval field.
360 */
361 if (ccm_interval) {
362 ND_PRINT("\n\t CCM Interval %.3fs"
363 ", min CCM Lifetime %.3fs, max CCM Lifetime %.3fs",
364 ccm_interval_base[ccm_interval],
365 ccm_interval_base[ccm_interval] * CCM_INTERVAL_MIN_MULTIPLIER,
366 ccm_interval_base[ccm_interval] * CCM_INTERVAL_MAX_MULTIPLIER);
367 }
368
369 ND_PRINT("\n\t Sequence Number 0x%08x, MA-End-Point-ID 0x%04x",
370 GET_BE_U_4(msg_ptr.cfm_ccm->sequence),
371 GET_BE_U_2(msg_ptr.cfm_ccm->ma_epi));
372
373 namesp = msg_ptr.cfm_ccm->names;
374 names_data_remaining = sizeof(msg_ptr.cfm_ccm->names);
375
376 /*
377 * Resolve the MD fields.
378 */
379 md_nameformat = GET_U_1(namesp);
380 namesp++;
381 names_data_remaining--; /* We know this is != 0 */
382 if (md_nameformat != CFM_CCM_MD_FORMAT_NONE) {
383 md_namelength = GET_U_1(namesp);
384 namesp++;
385 names_data_remaining--; /* We know this is !=0 */
386 ND_PRINT("\n\t MD Name Format %s (%u), MD Name length %u",
387 tok2str(cfm_md_nameformat_values, "Unknown",
388 md_nameformat),
389 md_nameformat,
390 md_namelength);
391
392 /*
393 * -3 for the MA short name format and length and one byte
394 * of MA short name.
395 */
396 if (md_namelength > names_data_remaining - 3) {
397 ND_PRINT(" (too large, must be <= %u)", names_data_remaining - 2);
398 return;
399 }
400
401 md_name = namesp;
402 ND_PRINT("\n\t MD Name: ");
403 switch (md_nameformat) {
404 case CFM_CCM_MD_FORMAT_DNS:
405 case CFM_CCM_MD_FORMAT_CHAR:
406 (void)nd_printzp(ndo, md_name, md_namelength, NULL);
407 break;
408
409 case CFM_CCM_MD_FORMAT_MAC:
410 if (md_namelength == 6) {
411 ND_PRINT("\n\t MAC %s", etheraddr_string(ndo,
412 md_name));
413 } else {
414 ND_PRINT("\n\t MAC (length invalid)");
415 }
416 break;
417
418 /* FIXME add printers for those MD formats - hexdump for now */
419 case CFM_CCM_MA_FORMAT_8021:
420 default:
421 print_unknown_data(ndo, md_name, "\n\t ",
422 md_namelength);
423 }
424 namesp += md_namelength;
425 names_data_remaining -= md_namelength;
426 } else {
427 ND_PRINT("\n\t MD Name Format %s (%u)",
428 tok2str(cfm_md_nameformat_values, "Unknown",
429 md_nameformat),
430 md_nameformat);
431 }
432
433
434 /*
435 * Resolve the MA fields.
436 */
437 ma_nameformat = GET_U_1(namesp);
438 namesp++;
439 names_data_remaining--; /* We know this is != 0 */
440 ma_namelength = GET_U_1(namesp);
441 namesp++;
442 names_data_remaining--; /* We know this is != 0 */
443 ND_PRINT("\n\t MA Name-Format %s (%u), MA name length %u",
444 tok2str(cfm_ma_nameformat_values, "Unknown",
445 ma_nameformat),
446 ma_nameformat,
447 ma_namelength);
448
449 if (ma_namelength > names_data_remaining) {
450 ND_PRINT(" (too large, must be <= %u)", names_data_remaining);
451 return;
452 }
453
454 ma_name = namesp;
455 ND_PRINT("\n\t MA Name: ");
456 switch (ma_nameformat) {
457 case CFM_CCM_MA_FORMAT_CHAR:
458 (void)nd_printzp(ndo, ma_name, ma_namelength, NULL);
459 break;
460
461 /* FIXME add printers for those MA formats - hexdump for now */
462 case CFM_CCM_MA_FORMAT_8021:
463 case CFM_CCM_MA_FORMAT_VID:
464 case CFM_CCM_MA_FORMAT_INT:
465 case CFM_CCM_MA_FORMAT_VPN:
466 default:
467 print_unknown_data(ndo, ma_name, "\n\t ", ma_namelength);
468 }
469 break;
470
471 case CFM_OPCODE_LTM:
472 msg_ptr.cfm_ltm = (const struct cfm_ltm_t *)tptr;
473 if (first_tlv_offset < sizeof(*msg_ptr.cfm_ltm)) {
474 ND_PRINT(" (too small 4, must be >= %lu)",
475 (unsigned long) sizeof(*msg_ptr.cfm_ltm));
476 return;
477 }
478 if (tlen < sizeof(*msg_ptr.cfm_ltm))
479 goto tooshort;
480 ND_TCHECK_SIZE(msg_ptr.cfm_ltm);
481
482 ND_PRINT(", Flags [%s]",
483 bittok2str(cfm_ltm_flag_values, "none", flags));
484
485 ND_PRINT("\n\t Transaction-ID 0x%08x, ttl %u",
486 GET_BE_U_4(msg_ptr.cfm_ltm->transaction_id),
487 GET_U_1(msg_ptr.cfm_ltm->ttl));
488
489 ND_PRINT("\n\t Original-MAC %s, Target-MAC %s",
490 etheraddr_string(ndo, msg_ptr.cfm_ltm->original_mac),
491 etheraddr_string(ndo, msg_ptr.cfm_ltm->target_mac));
492 break;
493
494 case CFM_OPCODE_LTR:
495 msg_ptr.cfm_ltr = (const struct cfm_ltr_t *)tptr;
496 if (first_tlv_offset < sizeof(*msg_ptr.cfm_ltr)) {
497 ND_PRINT(" (too small 5, must be >= %lu)",
498 (unsigned long) sizeof(*msg_ptr.cfm_ltr));
499 return;
500 }
501 if (tlen < sizeof(*msg_ptr.cfm_ltr))
502 goto tooshort;
503 ND_TCHECK_SIZE(msg_ptr.cfm_ltr);
504
505 ND_PRINT(", Flags [%s]",
506 bittok2str(cfm_ltr_flag_values, "none", flags));
507
508 ND_PRINT("\n\t Transaction-ID 0x%08x, ttl %u",
509 GET_BE_U_4(msg_ptr.cfm_ltr->transaction_id),
510 GET_U_1(msg_ptr.cfm_ltr->ttl));
511
512 ND_PRINT("\n\t Replay-Action %s (%u)",
513 tok2str(cfm_ltr_replay_action_values,
514 "Unknown",
515 GET_U_1(msg_ptr.cfm_ltr->replay_action)),
516 GET_U_1(msg_ptr.cfm_ltr->replay_action));
517 break;
518
519 /*
520 * No message decoder yet.
521 * Hexdump everything up until the start of the TLVs
522 */
523 case CFM_OPCODE_LBR:
524 case CFM_OPCODE_LBM:
525 default:
526 print_unknown_data(ndo, tptr, "\n\t ",
527 tlen - first_tlv_offset);
528 break;
529 }
530
531 tptr += first_tlv_offset;
532 tlen -= first_tlv_offset;
533
534 while (tlen > 0) {
535 cfm_tlv_header = (const struct cfm_tlv_header_t *)tptr;
536
537 /* Enough to read the tlv type ? */
538 ND_TCHECK_1(cfm_tlv_header->type);
539 cfm_tlv_type = GET_U_1(cfm_tlv_header->type);
540
541 ND_PRINT("\n\t%s TLV (0x%02x)",
542 tok2str(cfm_tlv_values, "Unknown", cfm_tlv_type),
543 cfm_tlv_type);
544
545 if (cfm_tlv_type == CFM_TLV_END) {
546 /* Length is "Not present if the Type field is 0." */
547 return;
548 }
549
550 /* do we have the full tlv header ? */
551 if (tlen < sizeof(struct cfm_tlv_header_t))
552 goto tooshort;
553 ND_TCHECK_LEN(tptr, sizeof(struct cfm_tlv_header_t));
554 cfm_tlv_len=GET_BE_U_2(cfm_tlv_header->length);
555
556 ND_PRINT(", length %u", cfm_tlv_len);
557
558 tptr += sizeof(struct cfm_tlv_header_t);
559 tlen -= sizeof(struct cfm_tlv_header_t);
560 tlv_ptr = tptr;
561
562 /* do we have the full tlv ? */
563 if (tlen < cfm_tlv_len)
564 goto tooshort;
565 ND_TCHECK_LEN(tptr, cfm_tlv_len);
566 hexdump = FALSE;
567
568 switch(cfm_tlv_type) {
569 case CFM_TLV_PORT_STATUS:
570 if (cfm_tlv_len < 1) {
571 ND_PRINT(" (too short, must be >= 1)");
572 return;
573 }
574 ND_PRINT(", Status: %s (%u)",
575 tok2str(cfm_tlv_port_status_values, "Unknown", GET_U_1(tptr)),
576 GET_U_1(tptr));
577 break;
578
579 case CFM_TLV_INTERFACE_STATUS:
580 if (cfm_tlv_len < 1) {
581 ND_PRINT(" (too short, must be >= 1)");
582 return;
583 }
584 ND_PRINT(", Status: %s (%u)",
585 tok2str(cfm_tlv_interface_status_values, "Unknown", GET_U_1(tptr)),
586 GET_U_1(tptr));
587 break;
588
589 case CFM_TLV_PRIVATE:
590 if (cfm_tlv_len < 4) {
591 ND_PRINT(" (too short, must be >= 4)");
592 return;
593 }
594 ND_PRINT(", Vendor: %s (%u), Sub-Type %u",
595 tok2str(oui_values,"Unknown", GET_BE_U_3(tptr)),
596 GET_BE_U_3(tptr),
597 GET_U_1(tptr + 3));
598 hexdump = TRUE;
599 break;
600
601 case CFM_TLV_SENDER_ID:
602 {
603 u_int chassis_id_type, chassis_id_length;
604 u_int mgmt_addr_length;
605
606 if (cfm_tlv_len < 1) {
607 ND_PRINT(" (too short, must be >= 1)");
608 goto next_tlv;
609 }
610
611 /*
612 * Get the Chassis ID length and check it.
613 * IEEE 802.1Q-2014 Section 21.5.3.1
614 */
615 chassis_id_length = GET_U_1(tptr);
616 tptr++;
617 tlen--;
618 cfm_tlv_len--;
619
620 if (chassis_id_length) {
621 /*
622 * IEEE 802.1Q-2014 Section 21.5.3.2: Chassis ID Subtype, references
623 * IEEE 802.1AB-2005 Section 9.5.2.2, subsequently
624 * IEEE 802.1AB-2016 Section 8.5.2.2: chassis ID subtype
625 */
626 if (cfm_tlv_len < 1) {
627 ND_PRINT("\n\t (TLV too short)");
628 goto next_tlv;
629 }
630 chassis_id_type = GET_U_1(tptr);
631 cfm_tlv_len--;
632 ND_PRINT("\n\t Chassis-ID Type %s (%u), Chassis-ID length %u",
633 tok2str(cfm_tlv_senderid_chassisid_values,
634 "Unknown",
635 chassis_id_type),
636 chassis_id_type,
637 chassis_id_length);
638
639 if (cfm_tlv_len < chassis_id_length) {
640 ND_PRINT("\n\t (TLV too short)");
641 goto next_tlv;
642 }
643
644 /* IEEE 802.1Q-2014 Section 21.5.3.3: Chassis ID */
645 switch (chassis_id_type) {
646 case CFM_CHASSIS_ID_MAC_ADDRESS:
647 if (chassis_id_length != MAC_ADDR_LEN) {
648 ND_PRINT(" (invalid MAC address length)");
649 hexdump = TRUE;
650 break;
651 }
652 ND_PRINT("\n\t MAC %s", etheraddr_string(ndo, tptr + 1));
653 break;
654
655 case CFM_CHASSIS_ID_NETWORK_ADDRESS:
656 hexdump |= cfm_network_addr_print(ndo, tptr + 1, chassis_id_length);
657 break;
658
659 case CFM_CHASSIS_ID_INTERFACE_NAME: /* fall through */
660 case CFM_CHASSIS_ID_INTERFACE_ALIAS:
661 case CFM_CHASSIS_ID_LOCAL:
662 case CFM_CHASSIS_ID_CHASSIS_COMPONENT:
663 case CFM_CHASSIS_ID_PORT_COMPONENT:
664 (void)nd_printzp(ndo, tptr + 1, chassis_id_length, NULL);
665 break;
666
667 default:
668 hexdump = TRUE;
669 break;
670 }
671 cfm_tlv_len -= chassis_id_length;
672
673 tptr += 1 + chassis_id_length;
674 tlen -= 1 + chassis_id_length;
675 }
676
677 /*
678 * Check if there is a Management Address.
679 * IEEE 802.1Q-2014 Section 21.5.3.4: Management Address Domain Length
680 * This and all subsequent fields are not present if the TLV length
681 * allows only the above fields.
682 */
683 if (cfm_tlv_len == 0) {
684 /* No, there isn't; we're done. */
685 break;
686 }
687
688 /* Here mgmt_addr_length stands for the management domain length. */
689 mgmt_addr_length = GET_U_1(tptr);
690 tptr++;
691 tlen--;
692 cfm_tlv_len--;
693 ND_PRINT("\n\t Management Address Domain Length %u", mgmt_addr_length);
694 if (mgmt_addr_length) {
695 /* IEEE 802.1Q-2014 Section 21.5.3.5: Management Address Domain */
696 if (cfm_tlv_len < mgmt_addr_length) {
697 ND_PRINT("\n\t (TLV too short)");
698 goto next_tlv;
699 }
700 cfm_tlv_len -= mgmt_addr_length;
701 /*
702 * XXX - this is an OID; print it as such.
703 */
704 hex_print(ndo, "\n\t Management Address Domain: ", tptr, mgmt_addr_length);
705 tptr += mgmt_addr_length;
706 tlen -= mgmt_addr_length;
707
708 /*
709 * IEEE 802.1Q-2014 Section 21.5.3.6: Management Address Length
710 * This field is present if Management Address Domain Length is not 0.
711 */
712 if (cfm_tlv_len < 1) {
713 ND_PRINT(" (Management Address Length is missing)");
714 hexdump = TRUE;
715 break;
716 }
717
718 /* Here mgmt_addr_length stands for the management address length. */
719 mgmt_addr_length = GET_U_1(tptr);
720 tptr++;
721 tlen--;
722 cfm_tlv_len--;
723 ND_PRINT("\n\t Management Address Length %u", mgmt_addr_length);
724 if (mgmt_addr_length) {
725 /* IEEE 802.1Q-2014 Section 21.5.3.7: Management Address */
726 if (cfm_tlv_len < mgmt_addr_length) {
727 ND_PRINT("\n\t (TLV too short)");
728 return;
729 }
730 cfm_tlv_len -= mgmt_addr_length;
731 /*
732 * XXX - this is a TransportDomain; print it as such.
733 */
734 hex_print(ndo, "\n\t Management Address: ", tptr, mgmt_addr_length);
735 tptr += mgmt_addr_length;
736 tlen -= mgmt_addr_length;
737 }
738 }
739 break;
740 }
741
742 /*
743 * FIXME those are the defined TLVs that lack a decoder
744 * you are welcome to contribute code ;-)
745 */
746
747 case CFM_TLV_DATA:
748 case CFM_TLV_REPLY_INGRESS:
749 case CFM_TLV_REPLY_EGRESS:
750 default:
751 hexdump = TRUE;
752 break;
753 }
754 /* do we want to see an additional hexdump ? */
755 if (hexdump || ndo->ndo_vflag > 1)
756 print_unknown_data(ndo, tlv_ptr, "\n\t ", cfm_tlv_len);
757
758 next_tlv:
759 tptr+=cfm_tlv_len;
760 tlen-=cfm_tlv_len;
761 }
762 return;
763
764 tooshort:
765 ND_PRINT("\n\t\t packet is too short");
766 return;
767
768 trunc:
769 nd_print_trunc(ndo);
770 }