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