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 <tcpdump-stdinc.h>
28 #include "interface.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)));
254 ND_PRINT((ndo
, ", %s", ip6addr_string(ndo
, tptr
+ 1)));
267 * The egress-ID string is a 16-Bit string plus a MAC address.
270 cfm_egress_id_string(netdissect_options
*ndo
, register const u_char
*tptr
)
272 static char egress_id_buffer
[80];
274 snprintf(egress_id_buffer
, sizeof(egress_id_buffer
),
276 EXTRACT_16BITS(tptr
),
277 etheraddr_string(ndo
, tptr
+2));
279 return egress_id_buffer
;
283 cfm_print(netdissect_options
*ndo
,
284 register const u_char
*pptr
, register u_int length
)
286 const struct cfm_common_header_t
*cfm_common_header
;
287 const struct cfm_tlv_header_t
*cfm_tlv_header
;
288 const uint8_t *tptr
, *tlv_ptr
, *ma_name
, *ma_nameformat
, *ma_namelength
;
289 u_int hexdump
, tlen
, cfm_tlv_len
, cfm_tlv_type
, ccm_interval
;
293 const struct cfm_ccm_t
*cfm_ccm
;
294 const struct cfm_lbm_t
*cfm_lbm
;
295 const struct cfm_ltm_t
*cfm_ltm
;
296 const struct cfm_ltr_t
*cfm_ltr
;
300 cfm_common_header
= (const struct cfm_common_header_t
*)pptr
;
301 ND_TCHECK(*cfm_common_header
);
304 * Sanity checking of the header.
306 if (CFM_EXTRACT_VERSION(cfm_common_header
->mdlevel_version
) != CFM_VERSION
) {
307 ND_PRINT((ndo
, "CFMv%u not supported, length %u",
308 CFM_EXTRACT_VERSION(cfm_common_header
->mdlevel_version
), length
));
312 ND_PRINT((ndo
, "CFMv%u %s, MD Level %u, length %u",
313 CFM_EXTRACT_VERSION(cfm_common_header
->mdlevel_version
),
314 tok2str(cfm_opcode_values
, "unknown (%u)", cfm_common_header
->opcode
),
315 CFM_EXTRACT_MD_LEVEL(cfm_common_header
->mdlevel_version
),
319 * In non-verbose mode just print the opcode and md-level.
321 if (ndo
->ndo_vflag
< 1) {
325 ND_PRINT((ndo
, "\n\tFirst TLV offset %u", cfm_common_header
->first_tlv_offset
));
327 tptr
+= sizeof(const struct cfm_common_header_t
);
328 tlen
= length
- sizeof(struct cfm_common_header_t
);
330 switch (cfm_common_header
->opcode
) {
332 msg_ptr
.cfm_ccm
= (const struct cfm_ccm_t
*)tptr
;
334 ccm_interval
= CFM_EXTRACT_CCM_INTERVAL(cfm_common_header
->flags
);
335 ND_PRINT((ndo
, ", Flags [CCM Interval %u%s]",
337 cfm_common_header
->flags
& CFM_CCM_RDI_FLAG
?
341 * Resolve the CCM interval field.
344 ND_PRINT((ndo
, "\n\t CCM Interval %.3fs"
345 ", min CCM Lifetime %.3fs, max CCM Lifetime %.3fs",
346 ccm_interval_base
[ccm_interval
],
347 ccm_interval_base
[ccm_interval
] * CCM_INTERVAL_MIN_MULTIPLIER
,
348 ccm_interval_base
[ccm_interval
] * CCM_INTERVAL_MAX_MULTIPLIER
));
351 ND_PRINT((ndo
, "\n\t Sequence Number 0x%08x, MA-End-Point-ID 0x%04x",
352 EXTRACT_32BITS(msg_ptr
.cfm_ccm
->sequence
),
353 EXTRACT_16BITS(msg_ptr
.cfm_ccm
->ma_epi
)));
357 * Resolve the MD fields.
359 ND_PRINT((ndo
, "\n\t MD Name Format %s (%u), MD Name length %u",
360 tok2str(cfm_md_nameformat_values
, "Unknown",
361 msg_ptr
.cfm_ccm
->md_nameformat
),
362 msg_ptr
.cfm_ccm
->md_nameformat
,
363 msg_ptr
.cfm_ccm
->md_namelength
));
365 if (msg_ptr
.cfm_ccm
->md_nameformat
!= CFM_CCM_MD_FORMAT_NONE
) {
366 ND_PRINT((ndo
, "\n\t MD Name: "));
367 switch (msg_ptr
.cfm_ccm
->md_nameformat
) {
368 case CFM_CCM_MD_FORMAT_DNS
:
369 case CFM_CCM_MD_FORMAT_CHAR
:
370 safeputs(ndo
, msg_ptr
.cfm_ccm
->md_name
, msg_ptr
.cfm_ccm
->md_namelength
);
373 case CFM_CCM_MD_FORMAT_MAC
:
374 ND_PRINT((ndo
, "\n\t MAC %s", etheraddr_string(ndo
,
375 msg_ptr
.cfm_ccm
->md_name
)));
378 /* FIXME add printers for those MD formats - hexdump for now */
379 case CFM_CCM_MA_FORMAT_8021
:
381 print_unknown_data(ndo
, msg_ptr
.cfm_ccm
->md_name
, "\n\t ",
382 msg_ptr
.cfm_ccm
->md_namelength
);
388 * Resolve the MA fields.
390 ma_nameformat
= msg_ptr
.cfm_ccm
->md_name
+ msg_ptr
.cfm_ccm
->md_namelength
;
391 ma_namelength
= msg_ptr
.cfm_ccm
->md_name
+ msg_ptr
.cfm_ccm
->md_namelength
+ 1;
392 ma_name
= msg_ptr
.cfm_ccm
->md_name
+ msg_ptr
.cfm_ccm
->md_namelength
+ 2;
394 ND_PRINT((ndo
, "\n\t MA Name-Format %s (%u), MA name length %u",
395 tok2str(cfm_ma_nameformat_values
, "Unknown",
400 ND_PRINT((ndo
, "\n\t MA Name: "));
401 switch (*ma_nameformat
) {
402 case CFM_CCM_MA_FORMAT_CHAR
:
403 safeputs(ndo
, ma_name
, *ma_namelength
);
406 /* FIXME add printers for those MA formats - hexdump for now */
407 case CFM_CCM_MA_FORMAT_8021
:
408 case CFM_CCM_MA_FORMAT_VID
:
409 case CFM_CCM_MA_FORMAT_INT
:
410 case CFM_CCM_MA_FORMAT_VPN
:
412 print_unknown_data(ndo
, ma_name
, "\n\t ", *ma_namelength
);
417 msg_ptr
.cfm_ltm
= (const struct cfm_ltm_t
*)tptr
;
419 ND_PRINT((ndo
, ", Flags [%s]",
420 bittok2str(cfm_ltm_flag_values
, "none", cfm_common_header
->flags
)));
422 ND_PRINT((ndo
, "\n\t Transaction-ID 0x%08x, Egress-ID %s, ttl %u",
423 EXTRACT_32BITS(msg_ptr
.cfm_ltm
->transaction_id
),
424 cfm_egress_id_string(ndo
, msg_ptr
.cfm_ltm
->egress_id
),
425 msg_ptr
.cfm_ltm
->ttl
));
427 ND_PRINT((ndo
, "\n\t Original-MAC %s, Target-MAC %s",
428 etheraddr_string(ndo
, msg_ptr
.cfm_ltm
->original_mac
),
429 etheraddr_string(ndo
, msg_ptr
.cfm_ltm
->target_mac
)));
433 msg_ptr
.cfm_ltr
= (const struct cfm_ltr_t
*)tptr
;
435 ND_PRINT((ndo
, ", Flags [%s]",
436 bittok2str(cfm_ltr_flag_values
, "none", cfm_common_header
->flags
)));
438 ND_PRINT((ndo
, "\n\t Transaction-ID 0x%08x, Last-Egress-ID %s",
439 EXTRACT_32BITS(msg_ptr
.cfm_ltr
->transaction_id
),
440 cfm_egress_id_string(ndo
, msg_ptr
.cfm_ltr
->last_egress_id
)));
442 ND_PRINT((ndo
, "\n\t Next-Egress-ID %s, ttl %u",
443 cfm_egress_id_string(ndo
, msg_ptr
.cfm_ltr
->next_egress_id
),
444 msg_ptr
.cfm_ltr
->ttl
));
446 ND_PRINT((ndo
, "\n\t Replay-Action %s (%u)",
447 tok2str(cfm_ltr_replay_action_values
,
449 msg_ptr
.cfm_ltr
->replay_action
),
450 msg_ptr
.cfm_ltr
->replay_action
));
454 * No message decoder yet.
455 * Hexdump everything up until the start of the TLVs
460 if (tlen
> cfm_common_header
->first_tlv_offset
) {
461 print_unknown_data(ndo
, tptr
, "\n\t ",
462 tlen
- cfm_common_header
->first_tlv_offset
);
468 * Sanity check for not walking off.
470 if (tlen
<= cfm_common_header
->first_tlv_offset
) {
474 tptr
+= cfm_common_header
->first_tlv_offset
;
475 tlen
-= cfm_common_header
->first_tlv_offset
;
478 cfm_tlv_header
= (const struct cfm_tlv_header_t
*)tptr
;
480 /* Enough to read the tlv type ? */
481 ND_TCHECK2(*tptr
, 1);
482 cfm_tlv_type
=cfm_tlv_header
->type
;
484 if (cfm_tlv_type
!= CFM_TLV_END
) {
485 /* did we capture enough for fully decoding the object header ? */
486 ND_TCHECK2(*tptr
, sizeof(struct cfm_tlv_header_t
));
487 cfm_tlv_len
=EXTRACT_16BITS(&cfm_tlv_header
->length
);
492 ND_PRINT((ndo
, "\n\t%s TLV (0x%02x), length %u",
493 tok2str(cfm_tlv_values
, "Unknown", cfm_tlv_type
),
497 /* sanity check for not walking off and infinite loop check. */
498 if ((cfm_tlv_type
!= CFM_TLV_END
) &&
499 ((cfm_tlv_len
+ sizeof(struct cfm_tlv_header_t
) > tlen
) ||
501 print_unknown_data(ndo
, tptr
, "\n\t ", tlen
);
505 tptr
+= sizeof(struct cfm_tlv_header_t
);
506 tlen
-= sizeof(struct cfm_tlv_header_t
);
509 /* did we capture enough for fully decoding the object ? */
510 if (cfm_tlv_type
!= CFM_TLV_END
) {
511 ND_TCHECK2(*tptr
, cfm_tlv_len
);
515 switch(cfm_tlv_type
) {
517 /* we are done - bail out */
520 case CFM_TLV_PORT_STATUS
:
521 ND_PRINT((ndo
, ", Status: %s (%u)",
522 tok2str(cfm_tlv_port_status_values
, "Unknown", *tptr
),
526 case CFM_TLV_INTERFACE_STATUS
:
527 ND_PRINT((ndo
, ", Status: %s (%u)",
528 tok2str(cfm_tlv_interface_status_values
, "Unknown", *tptr
),
532 case CFM_TLV_PRIVATE
:
533 ND_PRINT((ndo
, ", Vendor: %s (%u), Sub-Type %u",
534 tok2str(oui_values
,"Unknown", EXTRACT_24BITS(tptr
)),
535 EXTRACT_24BITS(tptr
),
540 case CFM_TLV_SENDER_ID
:
542 u_int chassis_id_type
, chassis_id_length
;
543 u_int mgmt_addr_length
;
546 * Check if there is a Chassis-ID.
548 chassis_id_length
= *tptr
;
549 if (chassis_id_length
> tlen
) {
557 if (chassis_id_length
) {
558 chassis_id_type
= *tptr
;
559 ND_PRINT((ndo
, "\n\t Chassis-ID Type %s (%u), Chassis-ID length %u",
560 tok2str(cfm_tlv_senderid_chassisid_values
,
566 switch (chassis_id_type
) {
567 case CFM_CHASSIS_ID_MAC_ADDRESS
:
568 ND_PRINT((ndo
, "\n\t MAC %s", etheraddr_string(ndo
, tptr
+ 1)));
571 case CFM_CHASSIS_ID_NETWORK_ADDRESS
:
572 hexdump
|= cfm_mgmt_addr_print(ndo
, tptr
);
575 case CFM_CHASSIS_ID_INTERFACE_NAME
: /* fall through */
576 case CFM_CHASSIS_ID_INTERFACE_ALIAS
:
577 case CFM_CHASSIS_ID_LOCAL
:
578 case CFM_CHASSIS_ID_CHASSIS_COMPONENT
:
579 case CFM_CHASSIS_ID_PORT_COMPONENT
:
580 safeputs(ndo
, tptr
+ 1, chassis_id_length
);
589 tptr
+= chassis_id_length
;
590 tlen
-= chassis_id_length
;
593 * Check if there is a Management Address.
595 mgmt_addr_length
= *tptr
;
596 if (mgmt_addr_length
> tlen
) {
604 if (mgmt_addr_length
) {
605 hexdump
|= cfm_mgmt_addr_print(ndo
, tptr
);
608 tptr
+= mgmt_addr_length
;
609 tlen
-= mgmt_addr_length
;
615 * FIXME those are the defined TLVs that lack a decoder
616 * you are welcome to contribute code ;-)
620 case CFM_TLV_REPLY_INGRESS
:
621 case CFM_TLV_REPLY_EGRESS
:
626 /* do we want to see an additional hexdump ? */
627 if (hexdump
|| ndo
->ndo_vflag
> 1)
628 print_unknown_data(ndo
, tlv_ptr
, "\n\t ", cfm_tlv_len
);
635 ND_PRINT((ndo
, "\n\t\t packet exceeded snapshot"));