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