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