blob: a85eec09139ea45b1d2df9abfc5dd7af9ee7a2a8 [file] [log] [blame]
JP Abgrall53f17a92014-02-12 14:02:41 -08001/*
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 * Support for the IEEE Connectivity Fault Management Protocols as per 802.1ag.
16 *
17 * Original code by Hannes Gredler (hannes@juniper.net)
18 */
19
Elliott Hughes892a68b2015-10-19 14:43:53 -070020#define NETDISSECT_REWORKED
JP Abgrall53f17a92014-02-12 14:02:41 -080021#ifdef HAVE_CONFIG_H
22#include "config.h"
23#endif
24
25#include <tcpdump-stdinc.h>
26
27#include <stdio.h>
JP Abgrall53f17a92014-02-12 14:02:41 -080028
29#include "interface.h"
30#include "extract.h"
31#include "ether.h"
32#include "addrtoname.h"
33#include "oui.h"
34#include "af.h"
35
JP Abgrall53f17a92014-02-12 14:02:41 -080036struct cfm_common_header_t {
Elliott Hughes892a68b2015-10-19 14:43:53 -070037 uint8_t mdlevel_version;
38 uint8_t opcode;
39 uint8_t flags;
40 uint8_t first_tlv_offset;
JP Abgrall53f17a92014-02-12 14:02:41 -080041};
42
43#define CFM_VERSION 0
44#define CFM_EXTRACT_VERSION(x) (((x)&0x1f))
45#define CFM_EXTRACT_MD_LEVEL(x) (((x)&0xe0)>>5)
46
47#define CFM_OPCODE_CCM 1
48#define CFM_OPCODE_LBR 2
49#define CFM_OPCODE_LBM 3
50#define CFM_OPCODE_LTR 4
51#define CFM_OPCODE_LTM 5
52
53static const struct tok cfm_opcode_values[] = {
54 { CFM_OPCODE_CCM, "Continouity Check Message"},
55 { CFM_OPCODE_LBR, "Loopback Reply"},
56 { CFM_OPCODE_LBM, "Loopback Message"},
57 { CFM_OPCODE_LTR, "Linktrace Reply"},
58 { CFM_OPCODE_LTM, "Linktrace Message"},
59 { 0, NULL}
60};
61
62/*
63 * Message Formats.
64 */
65struct cfm_ccm_t {
Elliott Hughes892a68b2015-10-19 14:43:53 -070066 uint8_t sequence[4];
67 uint8_t ma_epi[2];
68 uint8_t md_nameformat;
69 uint8_t md_namelength;
70 uint8_t md_name[46]; /* md name and short ma name */
71 uint8_t reserved_itu[16];
72 uint8_t reserved[6];
JP Abgrall53f17a92014-02-12 14:02:41 -080073};
74
75/*
76 * Timer Bases for the CCM Interval field.
77 * Expressed in units of seconds.
78 */
79const float ccm_interval_base[8] = {0, 0.003333, 0.01, 0.1, 1, 10, 60, 600};
80#define CCM_INTERVAL_MIN_MULTIPLIER 3.25
81#define CCM_INTERVAL_MAX_MULTIPLIER 3.5
82
83#define CFM_CCM_RDI_FLAG 0x80
84#define CFM_EXTRACT_CCM_INTERVAL(x) (((x)&0x07))
85
86#define CFM_CCM_MD_FORMAT_8021 0
87#define CFM_CCM_MD_FORMAT_NONE 1
88#define CFM_CCM_MD_FORMAT_DNS 2
89#define CFM_CCM_MD_FORMAT_MAC 3
90#define CFM_CCM_MD_FORMAT_CHAR 4
91
92static const struct tok cfm_md_nameformat_values[] = {
93 { CFM_CCM_MD_FORMAT_8021, "IEEE 802.1"},
94 { CFM_CCM_MD_FORMAT_NONE, "No MD Name present"},
95 { CFM_CCM_MD_FORMAT_DNS, "DNS string"},
96 { CFM_CCM_MD_FORMAT_MAC, "MAC + 16Bit Integer"},
97 { CFM_CCM_MD_FORMAT_CHAR, "Character string"},
98 { 0, NULL}
99};
100
101#define CFM_CCM_MA_FORMAT_8021 0
102#define CFM_CCM_MA_FORMAT_VID 1
103#define CFM_CCM_MA_FORMAT_CHAR 2
104#define CFM_CCM_MA_FORMAT_INT 3
105#define CFM_CCM_MA_FORMAT_VPN 4
106
107static const struct tok cfm_ma_nameformat_values[] = {
108 { CFM_CCM_MA_FORMAT_8021, "IEEE 802.1"},
109 { CFM_CCM_MA_FORMAT_VID, "Primary VID"},
110 { CFM_CCM_MA_FORMAT_CHAR, "Character string"},
111 { CFM_CCM_MA_FORMAT_INT, "16Bit Integer"},
112 { CFM_CCM_MA_FORMAT_VPN, "RFC2685 VPN-ID"},
113 { 0, NULL}
114};
115
116struct cfm_lbm_t {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700117 uint8_t transaction_id[4];
118 uint8_t reserved[4];
JP Abgrall53f17a92014-02-12 14:02:41 -0800119};
120
121struct cfm_ltm_t {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700122 uint8_t transaction_id[4];
123 uint8_t egress_id[8];
124 uint8_t ttl;
125 uint8_t original_mac[ETHER_ADDR_LEN];
126 uint8_t target_mac[ETHER_ADDR_LEN];
127 uint8_t reserved[3];
JP Abgrall53f17a92014-02-12 14:02:41 -0800128};
129
130static const struct tok cfm_ltm_flag_values[] = {
131 { 0x80, "Use Forwarding-DB only"},
132 { 0, NULL}
133};
134
135struct cfm_ltr_t {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700136 uint8_t transaction_id[4];
137 uint8_t last_egress_id[8];
138 uint8_t next_egress_id[8];
139 uint8_t ttl;
140 uint8_t replay_action;
141 uint8_t reserved[6];
JP Abgrall53f17a92014-02-12 14:02:41 -0800142};
143
144static const struct tok cfm_ltr_flag_values[] = {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700145 { 0x80, "UseFDB Only"},
146 { 0x40, "FwdYes"},
147 { 0x20, "Terminal MEP"},
JP Abgrall53f17a92014-02-12 14:02:41 -0800148 { 0, NULL}
149};
150
151static const struct tok cfm_ltr_replay_action_values[] = {
152 { 1, "Exact Match"},
153 { 2, "Filtering DB"},
154 { 3, "MIP CCM DB"},
155 { 0, NULL}
156};
157
158
159#define CFM_TLV_END 0
160#define CFM_TLV_SENDER_ID 1
161#define CFM_TLV_PORT_STATUS 2
162#define CFM_TLV_INTERFACE_STATUS 3
163#define CFM_TLV_DATA 4
164#define CFM_TLV_REPLY_INGRESS 5
165#define CFM_TLV_REPLY_EGRESS 6
166#define CFM_TLV_PRIVATE 31
167
168static const struct tok cfm_tlv_values[] = {
169 { CFM_TLV_END, "End"},
170 { CFM_TLV_SENDER_ID, "Sender ID"},
171 { CFM_TLV_PORT_STATUS, "Port status"},
172 { CFM_TLV_INTERFACE_STATUS, "Interface status"},
173 { CFM_TLV_DATA, "Data"},
174 { CFM_TLV_REPLY_INGRESS, "Reply Ingress"},
175 { CFM_TLV_REPLY_EGRESS, "Reply Egress"},
176 { CFM_TLV_PRIVATE, "Organization Specific"},
177 { 0, NULL}
178};
179
180/*
181 * TLVs
182 */
183
184struct cfm_tlv_header_t {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700185 uint8_t type;
186 uint8_t length[2];
JP Abgrall53f17a92014-02-12 14:02:41 -0800187};
188
189/* FIXME define TLV formats */
190
191static const struct tok cfm_tlv_port_status_values[] = {
192 { 1, "Blocked"},
193 { 2, "Up"},
194 { 0, NULL}
195};
196
197static const struct tok cfm_tlv_interface_status_values[] = {
198 { 1, "Up"},
199 { 2, "Down"},
200 { 3, "Testing"},
201 { 5, "Dormant"},
202 { 6, "not present"},
203 { 7, "lower Layer down"},
204 { 0, NULL}
205};
206
207#define CFM_CHASSIS_ID_CHASSIS_COMPONENT 1
208#define CFM_CHASSIS_ID_INTERFACE_ALIAS 2
209#define CFM_CHASSIS_ID_PORT_COMPONENT 3
210#define CFM_CHASSIS_ID_MAC_ADDRESS 4
211#define CFM_CHASSIS_ID_NETWORK_ADDRESS 5
212#define CFM_CHASSIS_ID_INTERFACE_NAME 6
213#define CFM_CHASSIS_ID_LOCAL 7
214
215static const struct tok cfm_tlv_senderid_chassisid_values[] = {
216 { 0, "Reserved"},
217 { CFM_CHASSIS_ID_CHASSIS_COMPONENT, "Chassis component"},
218 { CFM_CHASSIS_ID_INTERFACE_ALIAS, "Interface alias"},
219 { CFM_CHASSIS_ID_PORT_COMPONENT, "Port component"},
220 { CFM_CHASSIS_ID_MAC_ADDRESS, "MAC address"},
221 { CFM_CHASSIS_ID_NETWORK_ADDRESS, "Network address"},
222 { CFM_CHASSIS_ID_INTERFACE_NAME, "Interface name"},
223 { CFM_CHASSIS_ID_LOCAL, "Locally assigned"},
224 { 0, NULL}
225};
226
227
Elliott Hughes892a68b2015-10-19 14:43:53 -0700228static int
229cfm_mgmt_addr_print(netdissect_options *ndo,
230 register const u_char *tptr)
231{
JP Abgrall53f17a92014-02-12 14:02:41 -0800232 u_int mgmt_addr_type;
233 u_int hexdump = FALSE;
234
235 /*
236 * Altough AFIs are tpically 2 octects wide,
237 * 802.1ab specifies that this field width
238 * is only once octet
239 */
240 mgmt_addr_type = *tptr;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700241 ND_PRINT((ndo, "\n\t Management Address Type %s (%u)",
JP Abgrall53f17a92014-02-12 14:02:41 -0800242 tok2str(af_values, "Unknown", mgmt_addr_type),
Elliott Hughes892a68b2015-10-19 14:43:53 -0700243 mgmt_addr_type));
JP Abgrall53f17a92014-02-12 14:02:41 -0800244
245 /*
246 * Resolve the passed in Address.
247 */
248 switch(mgmt_addr_type) {
249 case AFNUM_INET:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700250 ND_PRINT((ndo, ", %s", ipaddr_string(ndo, tptr + 1)));
JP Abgrall53f17a92014-02-12 14:02:41 -0800251 break;
252
253#ifdef INET6
254 case AFNUM_INET6:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700255 ND_PRINT((ndo, ", %s", ip6addr_string(ndo, tptr + 1)));
JP Abgrall53f17a92014-02-12 14:02:41 -0800256 break;
257#endif
258
259 default:
260 hexdump = TRUE;
261 break;
262 }
263
264 return hexdump;
265}
266
267/*
268 * The egress-ID string is a 16-Bit string plus a MAC address.
269 */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700270static const char *
271cfm_egress_id_string(netdissect_options *ndo, register const u_char *tptr)
272{
JP Abgrall53f17a92014-02-12 14:02:41 -0800273 static char egress_id_buffer[80];
Elliott Hughes892a68b2015-10-19 14:43:53 -0700274
JP Abgrall53f17a92014-02-12 14:02:41 -0800275 snprintf(egress_id_buffer, sizeof(egress_id_buffer),
276 "MAC 0x%4x-%s",
277 EXTRACT_16BITS(tptr),
Elliott Hughes892a68b2015-10-19 14:43:53 -0700278 etheraddr_string(ndo, tptr+2));
JP Abgrall53f17a92014-02-12 14:02:41 -0800279
280 return egress_id_buffer;
281}
282
283void
Elliott Hughes892a68b2015-10-19 14:43:53 -0700284cfm_print(netdissect_options *ndo,
285 register const u_char *pptr, register u_int length)
286{
JP Abgrall53f17a92014-02-12 14:02:41 -0800287 const struct cfm_common_header_t *cfm_common_header;
288 const struct cfm_tlv_header_t *cfm_tlv_header;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700289 const uint8_t *tptr, *tlv_ptr, *ma_name, *ma_nameformat, *ma_namelength;
JP Abgrall53f17a92014-02-12 14:02:41 -0800290 u_int hexdump, tlen, cfm_tlv_len, cfm_tlv_type, ccm_interval;
291
292
293 union {
294 const struct cfm_ccm_t *cfm_ccm;
295 const struct cfm_lbm_t *cfm_lbm;
296 const struct cfm_ltm_t *cfm_ltm;
297 const struct cfm_ltr_t *cfm_ltr;
298 } msg_ptr;
299
300 tptr=pptr;
301 cfm_common_header = (const struct cfm_common_header_t *)pptr;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700302 ND_TCHECK(*cfm_common_header);
JP Abgrall53f17a92014-02-12 14:02:41 -0800303
304 /*
305 * Sanity checking of the header.
306 */
307 if (CFM_EXTRACT_VERSION(cfm_common_header->mdlevel_version) != CFM_VERSION) {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700308 ND_PRINT((ndo, "CFMv%u not supported, length %u",
309 CFM_EXTRACT_VERSION(cfm_common_header->mdlevel_version), length));
JP Abgrall53f17a92014-02-12 14:02:41 -0800310 return;
311 }
312
Elliott Hughes892a68b2015-10-19 14:43:53 -0700313 ND_PRINT((ndo, "CFMv%u %s, MD Level %u, length %u",
JP Abgrall53f17a92014-02-12 14:02:41 -0800314 CFM_EXTRACT_VERSION(cfm_common_header->mdlevel_version),
315 tok2str(cfm_opcode_values, "unknown (%u)", cfm_common_header->opcode),
316 CFM_EXTRACT_MD_LEVEL(cfm_common_header->mdlevel_version),
Elliott Hughes892a68b2015-10-19 14:43:53 -0700317 length));
JP Abgrall53f17a92014-02-12 14:02:41 -0800318
319 /*
320 * In non-verbose mode just print the opcode and md-level.
321 */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700322 if (ndo->ndo_vflag < 1) {
JP Abgrall53f17a92014-02-12 14:02:41 -0800323 return;
324 }
325
Elliott Hughes892a68b2015-10-19 14:43:53 -0700326 ND_PRINT((ndo, "\n\tFirst TLV offset %u", cfm_common_header->first_tlv_offset));
JP Abgrall53f17a92014-02-12 14:02:41 -0800327
328 tptr += sizeof(const struct cfm_common_header_t);
329 tlen = length - sizeof(struct cfm_common_header_t);
330
331 switch (cfm_common_header->opcode) {
332 case CFM_OPCODE_CCM:
333 msg_ptr.cfm_ccm = (const struct cfm_ccm_t *)tptr;
334
335 ccm_interval = CFM_EXTRACT_CCM_INTERVAL(cfm_common_header->flags);
Elliott Hughes892a68b2015-10-19 14:43:53 -0700336 ND_PRINT((ndo, ", Flags [CCM Interval %u%s]",
JP Abgrall53f17a92014-02-12 14:02:41 -0800337 ccm_interval,
338 cfm_common_header->flags & CFM_CCM_RDI_FLAG ?
Elliott Hughes892a68b2015-10-19 14:43:53 -0700339 ", RDI" : ""));
JP Abgrall53f17a92014-02-12 14:02:41 -0800340
341 /*
342 * Resolve the CCM interval field.
343 */
344 if (ccm_interval) {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700345 ND_PRINT((ndo, "\n\t CCM Interval %.3fs"
JP Abgrall53f17a92014-02-12 14:02:41 -0800346 ", min CCM Lifetime %.3fs, max CCM Lifetime %.3fs",
347 ccm_interval_base[ccm_interval],
348 ccm_interval_base[ccm_interval] * CCM_INTERVAL_MIN_MULTIPLIER,
Elliott Hughes892a68b2015-10-19 14:43:53 -0700349 ccm_interval_base[ccm_interval] * CCM_INTERVAL_MAX_MULTIPLIER));
JP Abgrall53f17a92014-02-12 14:02:41 -0800350 }
351
Elliott Hughes892a68b2015-10-19 14:43:53 -0700352 ND_PRINT((ndo, "\n\t Sequence Number 0x%08x, MA-End-Point-ID 0x%04x",
JP Abgrall53f17a92014-02-12 14:02:41 -0800353 EXTRACT_32BITS(msg_ptr.cfm_ccm->sequence),
Elliott Hughes892a68b2015-10-19 14:43:53 -0700354 EXTRACT_16BITS(msg_ptr.cfm_ccm->ma_epi)));
JP Abgrall53f17a92014-02-12 14:02:41 -0800355
356
357 /*
358 * Resolve the MD fields.
359 */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700360 ND_PRINT((ndo, "\n\t MD Name Format %s (%u), MD Name length %u",
JP Abgrall53f17a92014-02-12 14:02:41 -0800361 tok2str(cfm_md_nameformat_values, "Unknown",
362 msg_ptr.cfm_ccm->md_nameformat),
363 msg_ptr.cfm_ccm->md_nameformat,
Elliott Hughes892a68b2015-10-19 14:43:53 -0700364 msg_ptr.cfm_ccm->md_namelength));
JP Abgrall53f17a92014-02-12 14:02:41 -0800365
366 if (msg_ptr.cfm_ccm->md_nameformat != CFM_CCM_MD_FORMAT_NONE) {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700367 ND_PRINT((ndo, "\n\t MD Name: "));
JP Abgrall53f17a92014-02-12 14:02:41 -0800368 switch (msg_ptr.cfm_ccm->md_nameformat) {
369 case CFM_CCM_MD_FORMAT_DNS:
370 case CFM_CCM_MD_FORMAT_CHAR:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700371 safeputs(ndo, msg_ptr.cfm_ccm->md_name, msg_ptr.cfm_ccm->md_namelength);
JP Abgrall53f17a92014-02-12 14:02:41 -0800372 break;
373
374 case CFM_CCM_MD_FORMAT_MAC:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700375 ND_PRINT((ndo, "\n\t MAC %s", etheraddr_string(ndo,
376 msg_ptr.cfm_ccm->md_name)));
JP Abgrall53f17a92014-02-12 14:02:41 -0800377 break;
378
379 /* FIXME add printers for those MD formats - hexdump for now */
380 case CFM_CCM_MA_FORMAT_8021:
381 default:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700382 print_unknown_data(ndo, msg_ptr.cfm_ccm->md_name, "\n\t ",
JP Abgrall53f17a92014-02-12 14:02:41 -0800383 msg_ptr.cfm_ccm->md_namelength);
384 }
385 }
386
387
388 /*
389 * Resolve the MA fields.
390 */
391 ma_nameformat = msg_ptr.cfm_ccm->md_name + msg_ptr.cfm_ccm->md_namelength;
392 ma_namelength = msg_ptr.cfm_ccm->md_name + msg_ptr.cfm_ccm->md_namelength + 1;
393 ma_name = msg_ptr.cfm_ccm->md_name + msg_ptr.cfm_ccm->md_namelength + 2;
394
Elliott Hughes892a68b2015-10-19 14:43:53 -0700395 ND_PRINT((ndo, "\n\t MA Name-Format %s (%u), MA name length %u",
JP Abgrall53f17a92014-02-12 14:02:41 -0800396 tok2str(cfm_ma_nameformat_values, "Unknown",
397 *ma_nameformat),
398 *ma_nameformat,
Elliott Hughes892a68b2015-10-19 14:43:53 -0700399 *ma_namelength));
JP Abgrall53f17a92014-02-12 14:02:41 -0800400
Elliott Hughes892a68b2015-10-19 14:43:53 -0700401 ND_PRINT((ndo, "\n\t MA Name: "));
JP Abgrall53f17a92014-02-12 14:02:41 -0800402 switch (*ma_nameformat) {
403 case CFM_CCM_MA_FORMAT_CHAR:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700404 safeputs(ndo, ma_name, *ma_namelength);
JP Abgrall53f17a92014-02-12 14:02:41 -0800405 break;
406
407 /* FIXME add printers for those MA formats - hexdump for now */
408 case CFM_CCM_MA_FORMAT_8021:
409 case CFM_CCM_MA_FORMAT_VID:
410 case CFM_CCM_MA_FORMAT_INT:
411 case CFM_CCM_MA_FORMAT_VPN:
412 default:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700413 print_unknown_data(ndo, ma_name, "\n\t ", *ma_namelength);
JP Abgrall53f17a92014-02-12 14:02:41 -0800414 }
415 break;
416
417 case CFM_OPCODE_LTM:
418 msg_ptr.cfm_ltm = (const struct cfm_ltm_t *)tptr;
419
Elliott Hughes892a68b2015-10-19 14:43:53 -0700420 ND_PRINT((ndo, ", Flags [%s]",
421 bittok2str(cfm_ltm_flag_values, "none", cfm_common_header->flags)));
JP Abgrall53f17a92014-02-12 14:02:41 -0800422
Elliott Hughes892a68b2015-10-19 14:43:53 -0700423 ND_PRINT((ndo, "\n\t Transaction-ID 0x%08x, Egress-ID %s, ttl %u",
JP Abgrall53f17a92014-02-12 14:02:41 -0800424 EXTRACT_32BITS(msg_ptr.cfm_ltm->transaction_id),
Elliott Hughes892a68b2015-10-19 14:43:53 -0700425 cfm_egress_id_string(ndo, msg_ptr.cfm_ltm->egress_id),
426 msg_ptr.cfm_ltm->ttl));
JP Abgrall53f17a92014-02-12 14:02:41 -0800427
Elliott Hughes892a68b2015-10-19 14:43:53 -0700428 ND_PRINT((ndo, "\n\t Original-MAC %s, Target-MAC %s",
429 etheraddr_string(ndo, msg_ptr.cfm_ltm->original_mac),
430 etheraddr_string(ndo, msg_ptr.cfm_ltm->target_mac)));
JP Abgrall53f17a92014-02-12 14:02:41 -0800431 break;
432
433 case CFM_OPCODE_LTR:
434 msg_ptr.cfm_ltr = (const struct cfm_ltr_t *)tptr;
435
Elliott Hughes892a68b2015-10-19 14:43:53 -0700436 ND_PRINT((ndo, ", Flags [%s]",
437 bittok2str(cfm_ltr_flag_values, "none", cfm_common_header->flags)));
JP Abgrall53f17a92014-02-12 14:02:41 -0800438
Elliott Hughes892a68b2015-10-19 14:43:53 -0700439 ND_PRINT((ndo, "\n\t Transaction-ID 0x%08x, Last-Egress-ID %s",
JP Abgrall53f17a92014-02-12 14:02:41 -0800440 EXTRACT_32BITS(msg_ptr.cfm_ltr->transaction_id),
Elliott Hughes892a68b2015-10-19 14:43:53 -0700441 cfm_egress_id_string(ndo, msg_ptr.cfm_ltr->last_egress_id)));
JP Abgrall53f17a92014-02-12 14:02:41 -0800442
Elliott Hughes892a68b2015-10-19 14:43:53 -0700443 ND_PRINT((ndo, "\n\t Next-Egress-ID %s, ttl %u",
444 cfm_egress_id_string(ndo, msg_ptr.cfm_ltr->next_egress_id),
445 msg_ptr.cfm_ltr->ttl));
JP Abgrall53f17a92014-02-12 14:02:41 -0800446
Elliott Hughes892a68b2015-10-19 14:43:53 -0700447 ND_PRINT((ndo, "\n\t Replay-Action %s (%u)",
JP Abgrall53f17a92014-02-12 14:02:41 -0800448 tok2str(cfm_ltr_replay_action_values,
449 "Unknown",
450 msg_ptr.cfm_ltr->replay_action),
Elliott Hughes892a68b2015-10-19 14:43:53 -0700451 msg_ptr.cfm_ltr->replay_action));
JP Abgrall53f17a92014-02-12 14:02:41 -0800452 break;
453
454 /*
455 * No message decoder yet.
456 * Hexdump everything up until the start of the TLVs
457 */
458 case CFM_OPCODE_LBR:
459 case CFM_OPCODE_LBM:
460 default:
461 if (tlen > cfm_common_header->first_tlv_offset) {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700462 print_unknown_data(ndo, tptr, "\n\t ",
JP Abgrall53f17a92014-02-12 14:02:41 -0800463 tlen - cfm_common_header->first_tlv_offset);
464 }
465 break;
466 }
467
468 /*
469 * Sanity check for not walking off.
470 */
471 if (tlen <= cfm_common_header->first_tlv_offset) {
472 return;
473 }
474
475 tptr += cfm_common_header->first_tlv_offset;
476 tlen -= cfm_common_header->first_tlv_offset;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700477
JP Abgrall53f17a92014-02-12 14:02:41 -0800478 while (tlen > 0) {
479 cfm_tlv_header = (const struct cfm_tlv_header_t *)tptr;
480
481 /* Enough to read the tlv type ? */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700482 ND_TCHECK2(*tptr, 1);
JP Abgrall53f17a92014-02-12 14:02:41 -0800483 cfm_tlv_type=cfm_tlv_header->type;
484
485 if (cfm_tlv_type != CFM_TLV_END) {
486 /* did we capture enough for fully decoding the object header ? */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700487 ND_TCHECK2(*tptr, sizeof(struct cfm_tlv_header_t));
JP Abgrall53f17a92014-02-12 14:02:41 -0800488 cfm_tlv_len=EXTRACT_16BITS(&cfm_tlv_header->length);
489 } else {
490 cfm_tlv_len = 0;
491 }
492
Elliott Hughes892a68b2015-10-19 14:43:53 -0700493 ND_PRINT((ndo, "\n\t%s TLV (0x%02x), length %u",
JP Abgrall53f17a92014-02-12 14:02:41 -0800494 tok2str(cfm_tlv_values, "Unknown", cfm_tlv_type),
495 cfm_tlv_type,
Elliott Hughes892a68b2015-10-19 14:43:53 -0700496 cfm_tlv_len));
JP Abgrall53f17a92014-02-12 14:02:41 -0800497
498 /* sanity check for not walking off and infinite loop check. */
499 if ((cfm_tlv_type != CFM_TLV_END) &&
500 ((cfm_tlv_len + sizeof(struct cfm_tlv_header_t) > tlen) ||
501 (!cfm_tlv_len))) {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700502 print_unknown_data(ndo, tptr, "\n\t ", tlen);
JP Abgrall53f17a92014-02-12 14:02:41 -0800503 return;
504 }
505
506 tptr += sizeof(struct cfm_tlv_header_t);
507 tlen -= sizeof(struct cfm_tlv_header_t);
508 tlv_ptr = tptr;
509
510 /* did we capture enough for fully decoding the object ? */
511 if (cfm_tlv_type != CFM_TLV_END) {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700512 ND_TCHECK2(*tptr, cfm_tlv_len);
JP Abgrall53f17a92014-02-12 14:02:41 -0800513 }
514 hexdump = FALSE;
515
516 switch(cfm_tlv_type) {
517 case CFM_TLV_END:
518 /* we are done - bail out */
519 return;
520
521 case CFM_TLV_PORT_STATUS:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700522 ND_PRINT((ndo, ", Status: %s (%u)",
JP Abgrall53f17a92014-02-12 14:02:41 -0800523 tok2str(cfm_tlv_port_status_values, "Unknown", *tptr),
Elliott Hughes892a68b2015-10-19 14:43:53 -0700524 *tptr));
JP Abgrall53f17a92014-02-12 14:02:41 -0800525 break;
526
527 case CFM_TLV_INTERFACE_STATUS:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700528 ND_PRINT((ndo, ", Status: %s (%u)",
JP Abgrall53f17a92014-02-12 14:02:41 -0800529 tok2str(cfm_tlv_interface_status_values, "Unknown", *tptr),
Elliott Hughes892a68b2015-10-19 14:43:53 -0700530 *tptr));
JP Abgrall53f17a92014-02-12 14:02:41 -0800531 break;
532
533 case CFM_TLV_PRIVATE:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700534 ND_PRINT((ndo, ", Vendor: %s (%u), Sub-Type %u",
JP Abgrall53f17a92014-02-12 14:02:41 -0800535 tok2str(oui_values,"Unknown", EXTRACT_24BITS(tptr)),
536 EXTRACT_24BITS(tptr),
Elliott Hughes892a68b2015-10-19 14:43:53 -0700537 *(tptr + 3)));
JP Abgrall53f17a92014-02-12 14:02:41 -0800538 hexdump = TRUE;
539 break;
540
541 case CFM_TLV_SENDER_ID:
542 {
543 u_int chassis_id_type, chassis_id_length;
544 u_int mgmt_addr_length;
545
546 /*
547 * Check if there is a Chassis-ID.
548 */
549 chassis_id_length = *tptr;
550 if (chassis_id_length > tlen) {
551 hexdump = TRUE;
552 break;
553 }
554
555 tptr++;
556 tlen--;
557
558 if (chassis_id_length) {
559 chassis_id_type = *tptr;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700560 ND_PRINT((ndo, "\n\t Chassis-ID Type %s (%u), Chassis-ID length %u",
JP Abgrall53f17a92014-02-12 14:02:41 -0800561 tok2str(cfm_tlv_senderid_chassisid_values,
562 "Unknown",
563 chassis_id_type),
564 chassis_id_type,
Elliott Hughes892a68b2015-10-19 14:43:53 -0700565 chassis_id_length));
JP Abgrall53f17a92014-02-12 14:02:41 -0800566
567 switch (chassis_id_type) {
568 case CFM_CHASSIS_ID_MAC_ADDRESS:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700569 ND_PRINT((ndo, "\n\t MAC %s", etheraddr_string(ndo, tptr + 1)));
JP Abgrall53f17a92014-02-12 14:02:41 -0800570 break;
571
572 case CFM_CHASSIS_ID_NETWORK_ADDRESS:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700573 hexdump |= cfm_mgmt_addr_print(ndo, tptr);
JP Abgrall53f17a92014-02-12 14:02:41 -0800574 break;
575
576 case CFM_CHASSIS_ID_INTERFACE_NAME: /* fall through */
577 case CFM_CHASSIS_ID_INTERFACE_ALIAS:
578 case CFM_CHASSIS_ID_LOCAL:
579 case CFM_CHASSIS_ID_CHASSIS_COMPONENT:
580 case CFM_CHASSIS_ID_PORT_COMPONENT:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700581 safeputs(ndo, tptr + 1, chassis_id_length);
JP Abgrall53f17a92014-02-12 14:02:41 -0800582 break;
583
584 default:
585 hexdump = TRUE;
586 break;
587 }
588 }
589
590 tptr += chassis_id_length;
591 tlen -= chassis_id_length;
592
593 /*
594 * Check if there is a Management Address.
595 */
596 mgmt_addr_length = *tptr;
597 if (mgmt_addr_length > tlen) {
598 hexdump = TRUE;
599 break;
600 }
601
602 tptr++;
603 tlen--;
604
605 if (mgmt_addr_length) {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700606 hexdump |= cfm_mgmt_addr_print(ndo, tptr);
JP Abgrall53f17a92014-02-12 14:02:41 -0800607 }
608
609 tptr += mgmt_addr_length;
610 tlen -= mgmt_addr_length;
611
612 }
613 break;
614
615 /*
616 * FIXME those are the defined TLVs that lack a decoder
617 * you are welcome to contribute code ;-)
618 */
619
620 case CFM_TLV_DATA:
621 case CFM_TLV_REPLY_INGRESS:
622 case CFM_TLV_REPLY_EGRESS:
623 default:
624 hexdump = TRUE;
625 break;
626 }
627 /* do we want to see an additional hexdump ? */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700628 if (hexdump || ndo->ndo_vflag > 1)
629 print_unknown_data(ndo, tlv_ptr, "\n\t ", cfm_tlv_len);
JP Abgrall53f17a92014-02-12 14:02:41 -0800630
631 tptr+=cfm_tlv_len;
632 tlen-=cfm_tlv_len;
633 }
634 return;
635trunc:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700636 ND_PRINT((ndo, "\n\t\t packet exceeded snapshot"));
JP Abgrall53f17a92014-02-12 14:02:41 -0800637}