2 * Copyright (c) 1998-2006 The TCPDUMP project
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.
15 * Support for the IEEE Connectivity Fault Management Protocols as per 802.1ag.
17 * Original code by Hannes Gredler (hannes@juniper.net)
24 #include <netdissect-stdinc.h>
28 #include "netdissect.h"
31 #include "addrtoname.h"
35 struct cfm_common_header_t
{
36 uint8_t mdlevel_version
;
39 uint8_t first_tlv_offset
;
43 #define CFM_EXTRACT_VERSION(x) (((x)&0x1f))
44 #define CFM_EXTRACT_MD_LEVEL(x) (((x)&0xe0)>>5)
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
52 static const struct tok cfm_opcode_values
[] = {
53 { CFM_OPCODE_CCM
, "Continouity 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"},
67 uint8_t md_nameformat
;
68 uint8_t md_namelength
;
69 uint8_t md_name
[46]; /* md name and short ma name */
70 uint8_t reserved_itu
[16];
75 * Timer Bases for the CCM Interval field.
76 * Expressed in units of seconds.
78 const float ccm_interval_base
[8] = {0, 0.003333, 0.01, 0.1, 1, 10, 60, 600};
79 #define CCM_INTERVAL_MIN_MULTIPLIER 3.25
80 #define CCM_INTERVAL_MAX_MULTIPLIER 3.5
82 #define CFM_CCM_RDI_FLAG 0x80
83 #define CFM_EXTRACT_CCM_INTERVAL(x) (((x)&0x07))
85 #define CFM_CCM_MD_FORMAT_8021 0
86 #define CFM_CCM_MD_FORMAT_NONE 1
87 #define CFM_CCM_MD_FORMAT_DNS 2
88 #define CFM_CCM_MD_FORMAT_MAC 3
89 #define CFM_CCM_MD_FORMAT_CHAR 4
91 static const struct tok cfm_md_nameformat_values
[] = {
92 { CFM_CCM_MD_FORMAT_8021
, "IEEE 802.1"},
93 { CFM_CCM_MD_FORMAT_NONE
, "No MD Name present"},
94 { CFM_CCM_MD_FORMAT_DNS
, "DNS string"},
95 { CFM_CCM_MD_FORMAT_MAC
, "MAC + 16Bit Integer"},
96 { CFM_CCM_MD_FORMAT_CHAR
, "Character string"},
100 #define CFM_CCM_MA_FORMAT_8021 0
101 #define CFM_CCM_MA_FORMAT_VID 1
102 #define CFM_CCM_MA_FORMAT_CHAR 2
103 #define CFM_CCM_MA_FORMAT_INT 3
104 #define CFM_CCM_MA_FORMAT_VPN 4
106 static const struct tok cfm_ma_nameformat_values
[] = {
107 { CFM_CCM_MA_FORMAT_8021
, "IEEE 802.1"},
108 { CFM_CCM_MA_FORMAT_VID
, "Primary VID"},
109 { CFM_CCM_MA_FORMAT_CHAR
, "Character string"},
110 { CFM_CCM_MA_FORMAT_INT
, "16Bit Integer"},
111 { CFM_CCM_MA_FORMAT_VPN
, "RFC2685 VPN-ID"},
116 uint8_t transaction_id
[4];
121 uint8_t transaction_id
[4];
122 uint8_t egress_id
[8];
124 uint8_t original_mac
[ETHER_ADDR_LEN
];
125 uint8_t target_mac
[ETHER_ADDR_LEN
];
129 static const struct tok cfm_ltm_flag_values
[] = {
130 { 0x80, "Use Forwarding-DB only"},
135 uint8_t transaction_id
[4];
136 uint8_t last_egress_id
[8];
137 uint8_t next_egress_id
[8];
139 uint8_t replay_action
;
143 static const struct tok cfm_ltr_flag_values
[] = {
144 { 0x80, "UseFDB Only"},
146 { 0x20, "Terminal MEP"},
150 static const struct tok cfm_ltr_replay_action_values
[] = {
152 { 2, "Filtering DB"},
158 #define CFM_TLV_END 0
159 #define CFM_TLV_SENDER_ID 1
160 #define CFM_TLV_PORT_STATUS 2
161 #define CFM_TLV_INTERFACE_STATUS 3
162 #define CFM_TLV_DATA 4
163 #define CFM_TLV_REPLY_INGRESS 5
164 #define CFM_TLV_REPLY_EGRESS 6
165 #define CFM_TLV_PRIVATE 31
167 static const struct tok cfm_tlv_values
[] = {
168 { CFM_TLV_END
, "End"},
169 { CFM_TLV_SENDER_ID
, "Sender ID"},
170 { CFM_TLV_PORT_STATUS
, "Port status"},
171 { CFM_TLV_INTERFACE_STATUS
, "Interface status"},
172 { CFM_TLV_DATA
, "Data"},
173 { CFM_TLV_REPLY_INGRESS
, "Reply Ingress"},
174 { CFM_TLV_REPLY_EGRESS
, "Reply Egress"},
175 { CFM_TLV_PRIVATE
, "Organization Specific"},
183 struct cfm_tlv_header_t
{
188 /* FIXME define TLV formats */
190 static const struct tok cfm_tlv_port_status_values
[] = {
196 static const struct tok cfm_tlv_interface_status_values
[] = {
202 { 7, "lower Layer down"},
206 #define CFM_CHASSIS_ID_CHASSIS_COMPONENT 1
207 #define CFM_CHASSIS_ID_INTERFACE_ALIAS 2
208 #define CFM_CHASSIS_ID_PORT_COMPONENT 3
209 #define CFM_CHASSIS_ID_MAC_ADDRESS 4
210 #define CFM_CHASSIS_ID_NETWORK_ADDRESS 5
211 #define CFM_CHASSIS_ID_INTERFACE_NAME 6
212 #define CFM_CHASSIS_ID_LOCAL 7
214 static const struct tok cfm_tlv_senderid_chassisid_values
[] = {
216 { CFM_CHASSIS_ID_CHASSIS_COMPONENT
, "Chassis component"},
217 { CFM_CHASSIS_ID_INTERFACE_ALIAS
, "Interface alias"},
218 { CFM_CHASSIS_ID_PORT_COMPONENT
, "Port component"},
219 { CFM_CHASSIS_ID_MAC_ADDRESS
, "MAC address"},
220 { CFM_CHASSIS_ID_NETWORK_ADDRESS
, "Network address"},
221 { CFM_CHASSIS_ID_INTERFACE_NAME
, "Interface name"},
222 { CFM_CHASSIS_ID_LOCAL
, "Locally assigned"},
228 cfm_mgmt_addr_print(netdissect_options
*ndo
,
229 register const u_char
*tptr
)
231 u_int mgmt_addr_type
;
232 u_int hexdump
= FALSE
;
235 * Altough AFIs are tpically 2 octects wide,
236 * 802.1ab specifies that this field width
239 mgmt_addr_type
= *tptr
;
240 ND_PRINT((ndo
, "\n\t Management Address Type %s (%u)",
241 tok2str(af_values
, "Unknown", mgmt_addr_type
),
245 * Resolve the passed in Address.
247 switch(mgmt_addr_type
) {
249 ND_PRINT((ndo
, ", %s", ipaddr_string(ndo
, tptr
+ 1)));
253 ND_PRINT((ndo
, ", %s", ip6addr_string(ndo
, tptr
+ 1)));
265 * The egress-ID string is a 16-Bit string plus a MAC address.
268 cfm_egress_id_string(netdissect_options
*ndo
, register const u_char
*tptr
)
270 static char egress_id_buffer
[80];
272 snprintf(egress_id_buffer
, sizeof(egress_id_buffer
),
274 EXTRACT_16BITS(tptr
),
275 etheraddr_string(ndo
, tptr
+2));
277 return egress_id_buffer
;
281 cfm_print(netdissect_options
*ndo
,
282 register const u_char
*pptr
, register u_int length
)
284 const struct cfm_common_header_t
*cfm_common_header
;
285 const struct cfm_tlv_header_t
*cfm_tlv_header
;
286 const uint8_t *tptr
, *tlv_ptr
, *ma_name
, *ma_nameformat
, *ma_namelength
;
287 u_int hexdump
, tlen
, cfm_tlv_len
, cfm_tlv_type
, ccm_interval
;
291 const struct cfm_ccm_t
*cfm_ccm
;
292 const struct cfm_lbm_t
*cfm_lbm
;
293 const struct cfm_ltm_t
*cfm_ltm
;
294 const struct cfm_ltr_t
*cfm_ltr
;
298 cfm_common_header
= (const struct cfm_common_header_t
*)pptr
;
299 ND_TCHECK(*cfm_common_header
);
302 * Sanity checking of the header.
304 if (CFM_EXTRACT_VERSION(cfm_common_header
->mdlevel_version
) != CFM_VERSION
) {
305 ND_PRINT((ndo
, "CFMv%u not supported, length %u",
306 CFM_EXTRACT_VERSION(cfm_common_header
->mdlevel_version
), length
));
310 ND_PRINT((ndo
, "CFMv%u %s, MD Level %u, length %u",
311 CFM_EXTRACT_VERSION(cfm_common_header
->mdlevel_version
),
312 tok2str(cfm_opcode_values
, "unknown (%u)", cfm_common_header
->opcode
),
313 CFM_EXTRACT_MD_LEVEL(cfm_common_header
->mdlevel_version
),
317 * In non-verbose mode just print the opcode and md-level.
319 if (ndo
->ndo_vflag
< 1) {
323 ND_PRINT((ndo
, "\n\tFirst TLV offset %u", cfm_common_header
->first_tlv_offset
));
325 tptr
+= sizeof(const struct cfm_common_header_t
);
326 tlen
= length
- sizeof(struct cfm_common_header_t
);
328 switch (cfm_common_header
->opcode
) {
330 msg_ptr
.cfm_ccm
= (const struct cfm_ccm_t
*)tptr
;
332 ccm_interval
= CFM_EXTRACT_CCM_INTERVAL(cfm_common_header
->flags
);
333 ND_PRINT((ndo
, ", Flags [CCM Interval %u%s]",
335 cfm_common_header
->flags
& CFM_CCM_RDI_FLAG
?
339 * Resolve the CCM interval field.
342 ND_PRINT((ndo
, "\n\t CCM Interval %.3fs"
343 ", min CCM Lifetime %.3fs, max CCM Lifetime %.3fs",
344 ccm_interval_base
[ccm_interval
],
345 ccm_interval_base
[ccm_interval
] * CCM_INTERVAL_MIN_MULTIPLIER
,
346 ccm_interval_base
[ccm_interval
] * CCM_INTERVAL_MAX_MULTIPLIER
));
349 ND_PRINT((ndo
, "\n\t Sequence Number 0x%08x, MA-End-Point-ID 0x%04x",
350 EXTRACT_32BITS(msg_ptr
.cfm_ccm
->sequence
),
351 EXTRACT_16BITS(msg_ptr
.cfm_ccm
->ma_epi
)));
355 * Resolve the MD fields.
357 ND_PRINT((ndo
, "\n\t MD Name Format %s (%u), MD Name length %u",
358 tok2str(cfm_md_nameformat_values
, "Unknown",
359 msg_ptr
.cfm_ccm
->md_nameformat
),
360 msg_ptr
.cfm_ccm
->md_nameformat
,
361 msg_ptr
.cfm_ccm
->md_namelength
));
363 if (msg_ptr
.cfm_ccm
->md_nameformat
!= CFM_CCM_MD_FORMAT_NONE
) {
364 ND_PRINT((ndo
, "\n\t MD Name: "));
365 switch (msg_ptr
.cfm_ccm
->md_nameformat
) {
366 case CFM_CCM_MD_FORMAT_DNS
:
367 case CFM_CCM_MD_FORMAT_CHAR
:
368 safeputs(ndo
, msg_ptr
.cfm_ccm
->md_name
, msg_ptr
.cfm_ccm
->md_namelength
);
371 case CFM_CCM_MD_FORMAT_MAC
:
372 ND_PRINT((ndo
, "\n\t MAC %s", etheraddr_string(ndo
,
373 msg_ptr
.cfm_ccm
->md_name
)));
376 /* FIXME add printers for those MD formats - hexdump for now */
377 case CFM_CCM_MA_FORMAT_8021
:
379 print_unknown_data(ndo
, msg_ptr
.cfm_ccm
->md_name
, "\n\t ",
380 msg_ptr
.cfm_ccm
->md_namelength
);
386 * Resolve the MA fields.
388 ma_nameformat
= msg_ptr
.cfm_ccm
->md_name
+ msg_ptr
.cfm_ccm
->md_namelength
;
389 ma_namelength
= msg_ptr
.cfm_ccm
->md_name
+ msg_ptr
.cfm_ccm
->md_namelength
+ 1;
390 ma_name
= msg_ptr
.cfm_ccm
->md_name
+ msg_ptr
.cfm_ccm
->md_namelength
+ 2;
392 ND_PRINT((ndo
, "\n\t MA Name-Format %s (%u), MA name length %u",
393 tok2str(cfm_ma_nameformat_values
, "Unknown",
398 ND_PRINT((ndo
, "\n\t MA Name: "));
399 switch (*ma_nameformat
) {
400 case CFM_CCM_MA_FORMAT_CHAR
:
401 safeputs(ndo
, ma_name
, *ma_namelength
);
404 /* FIXME add printers for those MA formats - hexdump for now */
405 case CFM_CCM_MA_FORMAT_8021
:
406 case CFM_CCM_MA_FORMAT_VID
:
407 case CFM_CCM_MA_FORMAT_INT
:
408 case CFM_CCM_MA_FORMAT_VPN
:
410 print_unknown_data(ndo
, ma_name
, "\n\t ", *ma_namelength
);
415 msg_ptr
.cfm_ltm
= (const struct cfm_ltm_t
*)tptr
;
417 ND_PRINT((ndo
, ", Flags [%s]",
418 bittok2str(cfm_ltm_flag_values
, "none", cfm_common_header
->flags
)));
420 ND_PRINT((ndo
, "\n\t Transaction-ID 0x%08x, Egress-ID %s, ttl %u",
421 EXTRACT_32BITS(msg_ptr
.cfm_ltm
->transaction_id
),
422 cfm_egress_id_string(ndo
, msg_ptr
.cfm_ltm
->egress_id
),
423 msg_ptr
.cfm_ltm
->ttl
));
425 ND_PRINT((ndo
, "\n\t Original-MAC %s, Target-MAC %s",
426 etheraddr_string(ndo
, msg_ptr
.cfm_ltm
->original_mac
),
427 etheraddr_string(ndo
, msg_ptr
.cfm_ltm
->target_mac
)));
431 msg_ptr
.cfm_ltr
= (const struct cfm_ltr_t
*)tptr
;
433 ND_PRINT((ndo
, ", Flags [%s]",
434 bittok2str(cfm_ltr_flag_values
, "none", cfm_common_header
->flags
)));
436 ND_PRINT((ndo
, "\n\t Transaction-ID 0x%08x, Last-Egress-ID %s",
437 EXTRACT_32BITS(msg_ptr
.cfm_ltr
->transaction_id
),
438 cfm_egress_id_string(ndo
, msg_ptr
.cfm_ltr
->last_egress_id
)));
440 ND_PRINT((ndo
, "\n\t Next-Egress-ID %s, ttl %u",
441 cfm_egress_id_string(ndo
, msg_ptr
.cfm_ltr
->next_egress_id
),
442 msg_ptr
.cfm_ltr
->ttl
));
444 ND_PRINT((ndo
, "\n\t Replay-Action %s (%u)",
445 tok2str(cfm_ltr_replay_action_values
,
447 msg_ptr
.cfm_ltr
->replay_action
),
448 msg_ptr
.cfm_ltr
->replay_action
));
452 * No message decoder yet.
453 * Hexdump everything up until the start of the TLVs
458 if (tlen
> cfm_common_header
->first_tlv_offset
) {
459 print_unknown_data(ndo
, tptr
, "\n\t ",
460 tlen
- cfm_common_header
->first_tlv_offset
);
466 * Sanity check for not walking off.
468 if (tlen
<= cfm_common_header
->first_tlv_offset
) {
472 tptr
+= cfm_common_header
->first_tlv_offset
;
473 tlen
-= cfm_common_header
->first_tlv_offset
;
476 cfm_tlv_header
= (const struct cfm_tlv_header_t
*)tptr
;
478 /* Enough to read the tlv type ? */
479 ND_TCHECK2(*tptr
, 1);
480 cfm_tlv_type
=cfm_tlv_header
->type
;
482 if (cfm_tlv_type
!= CFM_TLV_END
) {
483 /* did we capture enough for fully decoding the object header ? */
484 ND_TCHECK2(*tptr
, sizeof(struct cfm_tlv_header_t
));
485 cfm_tlv_len
=EXTRACT_16BITS(&cfm_tlv_header
->length
);
490 ND_PRINT((ndo
, "\n\t%s TLV (0x%02x), length %u",
491 tok2str(cfm_tlv_values
, "Unknown", cfm_tlv_type
),
495 /* sanity check for not walking off and infinite loop check. */
496 if ((cfm_tlv_type
!= CFM_TLV_END
) &&
497 ((cfm_tlv_len
+ sizeof(struct cfm_tlv_header_t
) > tlen
) ||
499 print_unknown_data(ndo
, tptr
, "\n\t ", tlen
);
503 tptr
+= sizeof(struct cfm_tlv_header_t
);
504 tlen
-= sizeof(struct cfm_tlv_header_t
);
507 /* did we capture enough for fully decoding the object ? */
508 if (cfm_tlv_type
!= CFM_TLV_END
) {
509 ND_TCHECK2(*tptr
, cfm_tlv_len
);
513 switch(cfm_tlv_type
) {
515 /* we are done - bail out */
518 case CFM_TLV_PORT_STATUS
:
519 ND_PRINT((ndo
, ", Status: %s (%u)",
520 tok2str(cfm_tlv_port_status_values
, "Unknown", *tptr
),
524 case CFM_TLV_INTERFACE_STATUS
:
525 ND_PRINT((ndo
, ", Status: %s (%u)",
526 tok2str(cfm_tlv_interface_status_values
, "Unknown", *tptr
),
530 case CFM_TLV_PRIVATE
:
531 ND_PRINT((ndo
, ", Vendor: %s (%u), Sub-Type %u",
532 tok2str(oui_values
,"Unknown", EXTRACT_24BITS(tptr
)),
533 EXTRACT_24BITS(tptr
),
538 case CFM_TLV_SENDER_ID
:
540 u_int chassis_id_type
, chassis_id_length
;
541 u_int mgmt_addr_length
;
544 * Check if there is a Chassis-ID.
546 chassis_id_length
= *tptr
;
547 if (chassis_id_length
> tlen
) {
555 if (chassis_id_length
) {
556 chassis_id_type
= *tptr
;
557 ND_PRINT((ndo
, "\n\t Chassis-ID Type %s (%u), Chassis-ID length %u",
558 tok2str(cfm_tlv_senderid_chassisid_values
,
564 switch (chassis_id_type
) {
565 case CFM_CHASSIS_ID_MAC_ADDRESS
:
566 ND_PRINT((ndo
, "\n\t MAC %s", etheraddr_string(ndo
, tptr
+ 1)));
569 case CFM_CHASSIS_ID_NETWORK_ADDRESS
:
570 hexdump
|= cfm_mgmt_addr_print(ndo
, tptr
);
573 case CFM_CHASSIS_ID_INTERFACE_NAME
: /* fall through */
574 case CFM_CHASSIS_ID_INTERFACE_ALIAS
:
575 case CFM_CHASSIS_ID_LOCAL
:
576 case CFM_CHASSIS_ID_CHASSIS_COMPONENT
:
577 case CFM_CHASSIS_ID_PORT_COMPONENT
:
578 safeputs(ndo
, tptr
+ 1, chassis_id_length
);
587 tptr
+= chassis_id_length
;
588 tlen
-= chassis_id_length
;
591 * Check if there is a Management Address.
593 mgmt_addr_length
= *tptr
;
594 if (mgmt_addr_length
> tlen
) {
602 if (mgmt_addr_length
) {
603 hexdump
|= cfm_mgmt_addr_print(ndo
, tptr
);
606 tptr
+= mgmt_addr_length
;
607 tlen
-= mgmt_addr_length
;
613 * FIXME those are the defined TLVs that lack a decoder
614 * you are welcome to contribute code ;-)
618 case CFM_TLV_REPLY_INGRESS
:
619 case CFM_TLV_REPLY_EGRESS
:
624 /* do we want to see an additional hexdump ? */
625 if (hexdump
|| ndo
->ndo_vflag
> 1)
626 print_unknown_data(ndo
, tlv_ptr
, "\n\t ", cfm_tlv_len
);
633 ND_PRINT((ndo
, "\n\t\t packet exceeded snapshot"));