]> The Tcpdump Group git mirrors - tcpdump/blob - print-cfm.c
Use nd_ types in 802.x and FDDI headers.
[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 uint8_t mdlevel_version;
36 uint8_t opcode;
37 uint8_t flags;
38 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 uint8_t sequence[4];
65 uint8_t ma_epi[2];
66 uint8_t names[48];
67 uint8_t 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 uint8_t transaction_id[4];
113 };
114
115 struct cfm_ltm_t {
116 uint8_t transaction_id[4];
117 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 uint8_t transaction_id[4];
129 uint8_t ttl;
130 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 uint8_t type;
175 uint8_t length[2];
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 register 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((ndo, "\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((ndo, "\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((ndo, "(invalid IPv4 address length %u)", length - 1));
246 hexdump = TRUE;
247 break;
248 }
249 ND_PRINT((ndo, ", %s", ipaddr_string(ndo, tptr + 1)));
250 break;
251
252 case AFNUM_INET6:
253 if (length != 1 + 16) {
254 ND_PRINT((ndo, "(invalid IPv6 address length %u)", length - 1));
255 hexdump = TRUE;
256 break;
257 }
258 ND_PRINT((ndo, ", %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 register const u_char *pptr, register u_int length)
272 {
273 const struct cfm_common_header_t *cfm_common_header;
274 const struct cfm_tlv_header_t *cfm_tlv_header;
275 const uint8_t *tptr, *tlv_ptr;
276 const uint8_t *namesp;
277 u_int names_data_remaining;
278 uint8_t md_nameformat, md_namelength;
279 const uint8_t *md_name;
280 uint8_t ma_nameformat, ma_namelength;
281 const uint8_t *ma_name;
282 u_int hexdump, tlen, cfm_tlv_len, cfm_tlv_type, ccm_interval;
283
284
285 union {
286 const struct cfm_ccm_t *cfm_ccm;
287 const struct cfm_lbm_t *cfm_lbm;
288 const struct cfm_ltm_t *cfm_ltm;
289 const struct cfm_ltr_t *cfm_ltr;
290 } msg_ptr;
291
292 tptr=pptr;
293 cfm_common_header = (const struct cfm_common_header_t *)pptr;
294 if (length < sizeof(*cfm_common_header))
295 goto tooshort;
296 ND_TCHECK(*cfm_common_header);
297
298 /*
299 * Sanity checking of the header.
300 */
301 if (CFM_EXTRACT_VERSION(cfm_common_header->mdlevel_version) != CFM_VERSION) {
302 ND_PRINT((ndo, "CFMv%u not supported, length %u",
303 CFM_EXTRACT_VERSION(cfm_common_header->mdlevel_version), length));
304 return;
305 }
306
307 ND_PRINT((ndo, "CFMv%u %s, MD Level %u, length %u",
308 CFM_EXTRACT_VERSION(cfm_common_header->mdlevel_version),
309 tok2str(cfm_opcode_values, "unknown (%u)", cfm_common_header->opcode),
310 CFM_EXTRACT_MD_LEVEL(cfm_common_header->mdlevel_version),
311 length));
312
313 /*
314 * In non-verbose mode just print the opcode and md-level.
315 */
316 if (ndo->ndo_vflag < 1) {
317 return;
318 }
319
320 ND_PRINT((ndo, "\n\tFirst TLV offset %u", cfm_common_header->first_tlv_offset));
321
322 tptr += sizeof(struct cfm_common_header_t);
323 tlen = length - sizeof(struct cfm_common_header_t);
324
325 /*
326 * Sanity check the first TLV offset.
327 */
328 if (cfm_common_header->first_tlv_offset > tlen) {
329 ND_PRINT((ndo, " (too large, must be <= %u)", tlen));
330 return;
331 }
332
333 switch (cfm_common_header->opcode) {
334 case CFM_OPCODE_CCM:
335 msg_ptr.cfm_ccm = (const struct cfm_ccm_t *)tptr;
336 if (cfm_common_header->first_tlv_offset < sizeof(*msg_ptr.cfm_ccm)) {
337 ND_PRINT((ndo, " (too small 1, must be >= %lu)",
338 (unsigned long) sizeof(*msg_ptr.cfm_ccm)));
339 return;
340 }
341 if (tlen < sizeof(*msg_ptr.cfm_ccm))
342 goto tooshort;
343 ND_TCHECK(*msg_ptr.cfm_ccm);
344
345 ccm_interval = CFM_EXTRACT_CCM_INTERVAL(cfm_common_header->flags);
346 ND_PRINT((ndo, ", Flags [CCM Interval %u%s]",
347 ccm_interval,
348 cfm_common_header->flags & CFM_CCM_RDI_FLAG ?
349 ", RDI" : ""));
350
351 /*
352 * Resolve the CCM interval field.
353 */
354 if (ccm_interval) {
355 ND_PRINT((ndo, "\n\t CCM Interval %.3fs"
356 ", min CCM Lifetime %.3fs, max CCM Lifetime %.3fs",
357 ccm_interval_base[ccm_interval],
358 ccm_interval_base[ccm_interval] * CCM_INTERVAL_MIN_MULTIPLIER,
359 ccm_interval_base[ccm_interval] * CCM_INTERVAL_MAX_MULTIPLIER));
360 }
361
362 ND_PRINT((ndo, "\n\t Sequence Number 0x%08x, MA-End-Point-ID 0x%04x",
363 EXTRACT_BE_U_4(msg_ptr.cfm_ccm->sequence),
364 EXTRACT_BE_U_2(msg_ptr.cfm_ccm->ma_epi)));
365
366 namesp = msg_ptr.cfm_ccm->names;
367 names_data_remaining = sizeof(msg_ptr.cfm_ccm->names);
368
369 /*
370 * Resolve the MD fields.
371 */
372 md_nameformat = EXTRACT_U_1(namesp);
373 namesp++;
374 names_data_remaining--; /* We know this is != 0 */
375 if (md_nameformat != CFM_CCM_MD_FORMAT_NONE) {
376 md_namelength = EXTRACT_U_1(namesp);
377 namesp++;
378 names_data_remaining--; /* We know this is !=0 */
379 ND_PRINT((ndo, "\n\t MD Name Format %s (%u), MD Name length %u",
380 tok2str(cfm_md_nameformat_values, "Unknown",
381 md_nameformat),
382 md_nameformat,
383 md_namelength));
384
385 /*
386 * -3 for the MA short name format and length and one byte
387 * of MA short name.
388 */
389 if (md_namelength > names_data_remaining - 3) {
390 ND_PRINT((ndo, " (too large, must be <= %u)", names_data_remaining - 2));
391 return;
392 }
393
394 md_name = namesp;
395 ND_PRINT((ndo, "\n\t MD Name: "));
396 switch (md_nameformat) {
397 case CFM_CCM_MD_FORMAT_DNS:
398 case CFM_CCM_MD_FORMAT_CHAR:
399 safeputs(ndo, md_name, md_namelength);
400 break;
401
402 case CFM_CCM_MD_FORMAT_MAC:
403 if (md_namelength == 6) {
404 ND_PRINT((ndo, "\n\t MAC %s", etheraddr_string(ndo,
405 md_name)));
406 } else {
407 ND_PRINT((ndo, "\n\t MAC (length invalid)"));
408 }
409 break;
410
411 /* FIXME add printers for those MD formats - hexdump for now */
412 case CFM_CCM_MA_FORMAT_8021:
413 default:
414 print_unknown_data(ndo, md_name, "\n\t ",
415 md_namelength);
416 }
417 namesp += md_namelength;
418 names_data_remaining -= md_namelength;
419 } else {
420 ND_PRINT((ndo, "\n\t MD Name Format %s (%u)",
421 tok2str(cfm_md_nameformat_values, "Unknown",
422 md_nameformat),
423 md_nameformat));
424 }
425
426
427 /*
428 * Resolve the MA fields.
429 */
430 ma_nameformat = EXTRACT_U_1(namesp);
431 namesp++;
432 names_data_remaining--; /* We know this is != 0 */
433 ma_namelength = EXTRACT_U_1(namesp);
434 namesp++;
435 names_data_remaining--; /* We know this is != 0 */
436 ND_PRINT((ndo, "\n\t MA Name-Format %s (%u), MA name length %u",
437 tok2str(cfm_ma_nameformat_values, "Unknown",
438 ma_nameformat),
439 ma_nameformat,
440 ma_namelength));
441
442 if (ma_namelength > names_data_remaining) {
443 ND_PRINT((ndo, " (too large, must be <= %u)", names_data_remaining));
444 return;
445 }
446
447 ma_name = namesp;
448 ND_PRINT((ndo, "\n\t MA Name: "));
449 switch (ma_nameformat) {
450 case CFM_CCM_MA_FORMAT_CHAR:
451 safeputs(ndo, ma_name, ma_namelength);
452 break;
453
454 /* FIXME add printers for those MA formats - hexdump for now */
455 case CFM_CCM_MA_FORMAT_8021:
456 case CFM_CCM_MA_FORMAT_VID:
457 case CFM_CCM_MA_FORMAT_INT:
458 case CFM_CCM_MA_FORMAT_VPN:
459 default:
460 print_unknown_data(ndo, ma_name, "\n\t ", ma_namelength);
461 }
462 break;
463
464 case CFM_OPCODE_LTM:
465 msg_ptr.cfm_ltm = (const struct cfm_ltm_t *)tptr;
466 if (cfm_common_header->first_tlv_offset < sizeof(*msg_ptr.cfm_ltm)) {
467 ND_PRINT((ndo, " (too small 4, must be >= %lu)",
468 (unsigned long) sizeof(*msg_ptr.cfm_ltm)));
469 return;
470 }
471 if (tlen < sizeof(*msg_ptr.cfm_ltm))
472 goto tooshort;
473 ND_TCHECK(*msg_ptr.cfm_ltm);
474
475 ND_PRINT((ndo, ", Flags [%s]",
476 bittok2str(cfm_ltm_flag_values, "none", cfm_common_header->flags)));
477
478 ND_PRINT((ndo, "\n\t Transaction-ID 0x%08x, ttl %u",
479 EXTRACT_BE_U_4(msg_ptr.cfm_ltm->transaction_id),
480 msg_ptr.cfm_ltm->ttl));
481
482 ND_PRINT((ndo, "\n\t Original-MAC %s, Target-MAC %s",
483 etheraddr_string(ndo, msg_ptr.cfm_ltm->original_mac),
484 etheraddr_string(ndo, msg_ptr.cfm_ltm->target_mac)));
485 break;
486
487 case CFM_OPCODE_LTR:
488 msg_ptr.cfm_ltr = (const struct cfm_ltr_t *)tptr;
489 if (cfm_common_header->first_tlv_offset < sizeof(*msg_ptr.cfm_ltr)) {
490 ND_PRINT((ndo, " (too small 5, must be >= %lu)",
491 (unsigned long) sizeof(*msg_ptr.cfm_ltr)));
492 return;
493 }
494 if (tlen < sizeof(*msg_ptr.cfm_ltr))
495 goto tooshort;
496 ND_TCHECK(*msg_ptr.cfm_ltr);
497
498 ND_PRINT((ndo, ", Flags [%s]",
499 bittok2str(cfm_ltr_flag_values, "none", cfm_common_header->flags)));
500
501 ND_PRINT((ndo, "\n\t Transaction-ID 0x%08x, ttl %u",
502 EXTRACT_BE_U_4(msg_ptr.cfm_ltr->transaction_id),
503 msg_ptr.cfm_ltr->ttl));
504
505 ND_PRINT((ndo, "\n\t Replay-Action %s (%u)",
506 tok2str(cfm_ltr_replay_action_values,
507 "Unknown",
508 msg_ptr.cfm_ltr->replay_action),
509 msg_ptr.cfm_ltr->replay_action));
510 break;
511
512 /*
513 * No message decoder yet.
514 * Hexdump everything up until the start of the TLVs
515 */
516 case CFM_OPCODE_LBR:
517 case CFM_OPCODE_LBM:
518 default:
519 print_unknown_data(ndo, tptr, "\n\t ",
520 tlen - cfm_common_header->first_tlv_offset);
521 break;
522 }
523
524 tptr += cfm_common_header->first_tlv_offset;
525 tlen -= cfm_common_header->first_tlv_offset;
526
527 while (tlen > 0) {
528 cfm_tlv_header = (const struct cfm_tlv_header_t *)tptr;
529
530 /* Enough to read the tlv type ? */
531 ND_TCHECK_1(tptr);
532 cfm_tlv_type=cfm_tlv_header->type;
533
534 ND_PRINT((ndo, "\n\t%s TLV (0x%02x)",
535 tok2str(cfm_tlv_values, "Unknown", cfm_tlv_type),
536 cfm_tlv_type));
537
538 if (cfm_tlv_type == CFM_TLV_END) {
539 /* Length is "Not present if the Type field is 0." */
540 return;
541 }
542
543 /* do we have the full tlv header ? */
544 if (tlen < sizeof(struct cfm_tlv_header_t))
545 goto tooshort;
546 ND_TCHECK_LEN(tptr, sizeof(struct cfm_tlv_header_t));
547 cfm_tlv_len=EXTRACT_BE_U_2(&cfm_tlv_header->length);
548
549 ND_PRINT((ndo, ", length %u", cfm_tlv_len));
550
551 tptr += sizeof(struct cfm_tlv_header_t);
552 tlen -= sizeof(struct cfm_tlv_header_t);
553 tlv_ptr = tptr;
554
555 /* do we have the full tlv ? */
556 if (tlen < cfm_tlv_len)
557 goto tooshort;
558 ND_TCHECK_LEN(tptr, cfm_tlv_len);
559 hexdump = FALSE;
560
561 switch(cfm_tlv_type) {
562 case CFM_TLV_PORT_STATUS:
563 if (cfm_tlv_len < 1) {
564 ND_PRINT((ndo, " (too short, must be >= 1)"));
565 return;
566 }
567 ND_PRINT((ndo, ", Status: %s (%u)",
568 tok2str(cfm_tlv_port_status_values, "Unknown", EXTRACT_U_1(tptr)),
569 EXTRACT_U_1(tptr)));
570 break;
571
572 case CFM_TLV_INTERFACE_STATUS:
573 if (cfm_tlv_len < 1) {
574 ND_PRINT((ndo, " (too short, must be >= 1)"));
575 return;
576 }
577 ND_PRINT((ndo, ", Status: %s (%u)",
578 tok2str(cfm_tlv_interface_status_values, "Unknown", EXTRACT_U_1(tptr)),
579 EXTRACT_U_1(tptr)));
580 break;
581
582 case CFM_TLV_PRIVATE:
583 if (cfm_tlv_len < 4) {
584 ND_PRINT((ndo, " (too short, must be >= 4)"));
585 return;
586 }
587 ND_PRINT((ndo, ", Vendor: %s (%u), Sub-Type %u",
588 tok2str(oui_values,"Unknown", EXTRACT_BE_U_3(tptr)),
589 EXTRACT_BE_U_3(tptr),
590 EXTRACT_U_1(tptr + 3)));
591 hexdump = TRUE;
592 break;
593
594 case CFM_TLV_SENDER_ID:
595 {
596 u_int chassis_id_type, chassis_id_length;
597 u_int mgmt_addr_length;
598
599 if (cfm_tlv_len < 1) {
600 ND_PRINT((ndo, " (too short, must be >= 1)"));
601 goto next_tlv;
602 }
603
604 /*
605 * Get the Chassis ID length and check it.
606 * IEEE 802.1Q-2014 Section 21.5.3.1
607 */
608 chassis_id_length = EXTRACT_U_1(tptr);
609 tptr++;
610 tlen--;
611 cfm_tlv_len--;
612
613 if (chassis_id_length) {
614 /*
615 * IEEE 802.1Q-2014 Section 21.5.3.2: Chassis ID Subtype, references
616 * IEEE 802.1AB-2005 Section 9.5.2.2, subsequently
617 * IEEE 802.1AB-2016 Section 8.5.2.2: chassis ID subtype
618 */
619 if (cfm_tlv_len < 1) {
620 ND_PRINT((ndo, "\n\t (TLV too short)"));
621 goto next_tlv;
622 }
623 chassis_id_type = EXTRACT_U_1(tptr);
624 cfm_tlv_len--;
625 ND_PRINT((ndo, "\n\t Chassis-ID Type %s (%u), Chassis-ID length %u",
626 tok2str(cfm_tlv_senderid_chassisid_values,
627 "Unknown",
628 chassis_id_type),
629 chassis_id_type,
630 chassis_id_length));
631
632 if (cfm_tlv_len < chassis_id_length) {
633 ND_PRINT((ndo, "\n\t (TLV too short)"));
634 goto next_tlv;
635 }
636
637 /* IEEE 802.1Q-2014 Section 21.5.3.3: Chassis ID */
638 switch (chassis_id_type) {
639 case CFM_CHASSIS_ID_MAC_ADDRESS:
640 if (chassis_id_length != MAC_ADDR_LEN) {
641 ND_PRINT((ndo, " (invalid MAC address length)"));
642 hexdump = TRUE;
643 break;
644 }
645 ND_PRINT((ndo, "\n\t MAC %s", etheraddr_string(ndo, tptr + 1)));
646 break;
647
648 case CFM_CHASSIS_ID_NETWORK_ADDRESS:
649 hexdump |= cfm_network_addr_print(ndo, tptr + 1, chassis_id_length);
650 break;
651
652 case CFM_CHASSIS_ID_INTERFACE_NAME: /* fall through */
653 case CFM_CHASSIS_ID_INTERFACE_ALIAS:
654 case CFM_CHASSIS_ID_LOCAL:
655 case CFM_CHASSIS_ID_CHASSIS_COMPONENT:
656 case CFM_CHASSIS_ID_PORT_COMPONENT:
657 safeputs(ndo, tptr + 1, chassis_id_length);
658 break;
659
660 default:
661 hexdump = TRUE;
662 break;
663 }
664 cfm_tlv_len -= chassis_id_length;
665
666 tptr += 1 + chassis_id_length;
667 tlen -= 1 + chassis_id_length;
668 }
669
670 /*
671 * Check if there is a Management Address.
672 * IEEE 802.1Q-2014 Section 21.5.3.4: Management Address Domain Length
673 * This and all subsequent fields are not present if the TLV length
674 * allows only the above fields.
675 */
676 if (cfm_tlv_len == 0) {
677 /* No, there isn't; we're done. */
678 break;
679 }
680
681 /* Here mgmt_addr_length stands for the management domain length. */
682 mgmt_addr_length = EXTRACT_U_1(tptr);
683 tptr++;
684 tlen--;
685 cfm_tlv_len--;
686 ND_PRINT((ndo, "\n\t Management Address Domain Length %u", mgmt_addr_length));
687 if (mgmt_addr_length) {
688 /* IEEE 802.1Q-2014 Section 21.5.3.5: Management Address Domain */
689 if (cfm_tlv_len < mgmt_addr_length) {
690 ND_PRINT((ndo, "\n\t (TLV too short)"));
691 goto next_tlv;
692 }
693 cfm_tlv_len -= mgmt_addr_length;
694 /*
695 * XXX - this is an OID; print it as such.
696 */
697 hex_print(ndo, "\n\t Management Address Domain: ", tptr, mgmt_addr_length);
698 tptr += mgmt_addr_length;
699 tlen -= mgmt_addr_length;
700
701 /*
702 * IEEE 802.1Q-2014 Section 21.5.3.6: Management Address Length
703 * This field is present if Management Address Domain Length is not 0.
704 */
705 if (cfm_tlv_len < 1) {
706 ND_PRINT((ndo, " (Management Address Length is missing)"));
707 hexdump = TRUE;
708 break;
709 }
710
711 /* Here mgmt_addr_length stands for the management address length. */
712 mgmt_addr_length = EXTRACT_U_1(tptr);
713 tptr++;
714 tlen--;
715 cfm_tlv_len--;
716 ND_PRINT((ndo, "\n\t Management Address Length %u", mgmt_addr_length));
717 if (mgmt_addr_length) {
718 /* IEEE 802.1Q-2014 Section 21.5.3.7: Management Address */
719 if (cfm_tlv_len < mgmt_addr_length) {
720 ND_PRINT((ndo, "\n\t (TLV too short)"));
721 return;
722 }
723 cfm_tlv_len -= mgmt_addr_length;
724 /*
725 * XXX - this is a TransportDomain; print it as such.
726 */
727 hex_print(ndo, "\n\t Management Address: ", tptr, mgmt_addr_length);
728 tptr += mgmt_addr_length;
729 tlen -= mgmt_addr_length;
730 }
731 }
732 break;
733 }
734
735 /*
736 * FIXME those are the defined TLVs that lack a decoder
737 * you are welcome to contribute code ;-)
738 */
739
740 case CFM_TLV_DATA:
741 case CFM_TLV_REPLY_INGRESS:
742 case CFM_TLV_REPLY_EGRESS:
743 default:
744 hexdump = TRUE;
745 break;
746 }
747 /* do we want to see an additional hexdump ? */
748 if (hexdump || ndo->ndo_vflag > 1)
749 print_unknown_data(ndo, tlv_ptr, "\n\t ", cfm_tlv_len);
750
751 next_tlv:
752 tptr+=cfm_tlv_len;
753 tlen-=cfm_tlv_len;
754 }
755 return;
756
757 tooshort:
758 ND_PRINT((ndo, "\n\t\t packet is too short"));
759 return;
760
761 trunc:
762 ND_PRINT((ndo, "\n\t\t packet exceeded snapshot"));
763 }