]> The Tcpdump Group git mirrors - tcpdump/blob - print-ldp.c
Avoid -E and -M options inconsistencies with no libcrypto
[tcpdump] / print-ldp.c
1 /*
2 * Redistribution and use in source and binary forms, with or without
3 * modification, are permitted provided that: (1) source code
4 * distributions retain the above copyright notice and this paragraph
5 * in its entirety, and (2) distributions including binary code include
6 * the above copyright notice and this paragraph in its entirety in
7 * the documentation or other materials provided with the distribution.
8 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND
9 * WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT
10 * LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
11 * FOR A PARTICULAR PURPOSE.
12 *
13 * Original code by Hannes Gredler (hannes@gredler.at)
14 * and Steinar Haug (sthaug@nethelp.no)
15 */
16
17 /* \summary: Label Distribution Protocol (LDP) printer */
18
19 #include <config.h>
20
21 #include "netdissect-stdinc.h"
22
23 #include "netdissect.h"
24 #include "extract.h"
25 #include "addrtoname.h"
26
27 #include "l2vpn.h"
28 #include "af.h"
29
30 /*
31 * ldp common header
32 *
33 * 0 1 2 3
34 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
35 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
36 * | Version | PDU Length |
37 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
38 * | LDP Identifier |
39 * + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
40 * | |
41 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
42 *
43 */
44
45 struct ldp_common_header {
46 nd_uint16_t version;
47 nd_uint16_t pdu_length;
48 nd_ipv4 lsr_id;
49 nd_uint16_t label_space;
50 };
51
52 #define LDP_VERSION 1
53
54 /*
55 * ldp message header
56 *
57 * 0 1 2 3
58 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
59 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
60 * |U| Message Type | Message Length |
61 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
62 * | Message ID |
63 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
64 * | |
65 * + +
66 * | Mandatory Parameters |
67 * + +
68 * | |
69 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
70 * | |
71 * + +
72 * | Optional Parameters |
73 * + +
74 * | |
75 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
76 */
77
78 struct ldp_msg_header {
79 nd_uint16_t type;
80 nd_uint16_t length;
81 nd_uint32_t id;
82 };
83
84 #define LDP_MASK_MSG_TYPE(x) ((x)&0x7fff)
85 #define LDP_MASK_U_BIT(x) ((x)&0x8000)
86
87 #define LDP_MSG_NOTIF 0x0001
88 #define LDP_MSG_HELLO 0x0100
89 #define LDP_MSG_INIT 0x0200
90 #define LDP_MSG_KEEPALIVE 0x0201
91 #define LDP_MSG_ADDRESS 0x0300
92 #define LDP_MSG_ADDRESS_WITHDRAW 0x0301
93 #define LDP_MSG_LABEL_MAPPING 0x0400
94 #define LDP_MSG_LABEL_REQUEST 0x0401
95 #define LDP_MSG_LABEL_WITHDRAW 0x0402
96 #define LDP_MSG_LABEL_RELEASE 0x0403
97 #define LDP_MSG_LABEL_ABORT_REQUEST 0x0404
98
99 #define LDP_VENDOR_PRIVATE_MIN 0x3e00
100 #define LDP_VENDOR_PRIVATE_MAX 0x3eff
101 #define LDP_EXPERIMENTAL_MIN 0x3f00
102 #define LDP_EXPERIMENTAL_MAX 0x3fff
103
104 static const struct tok ldp_msg_values[] = {
105 { LDP_MSG_NOTIF, "Notification" },
106 { LDP_MSG_HELLO, "Hello" },
107 { LDP_MSG_INIT, "Initialization" },
108 { LDP_MSG_KEEPALIVE, "Keepalive" },
109 { LDP_MSG_ADDRESS, "Address" },
110 { LDP_MSG_ADDRESS_WITHDRAW, "Address Withdraw" },
111 { LDP_MSG_LABEL_MAPPING, "Label Mapping" },
112 { LDP_MSG_LABEL_REQUEST, "Label Request" },
113 { LDP_MSG_LABEL_WITHDRAW, "Label Withdraw" },
114 { LDP_MSG_LABEL_RELEASE, "Label Release" },
115 { LDP_MSG_LABEL_ABORT_REQUEST, "Label Abort Request" },
116 { 0, NULL}
117 };
118
119 #define LDP_MASK_TLV_TYPE(x) ((x)&0x3fff)
120 #define LDP_MASK_F_BIT(x) ((x)&0x4000)
121
122 #define LDP_TLV_FEC 0x0100
123 #define LDP_TLV_ADDRESS_LIST 0x0101
124 #define LDP_TLV_ADDRESS_LIST_AFNUM_LEN 2
125 #define LDP_TLV_HOP_COUNT 0x0103
126 #define LDP_TLV_PATH_VECTOR 0x0104
127 #define LDP_TLV_GENERIC_LABEL 0x0200
128 #define LDP_TLV_ATM_LABEL 0x0201
129 #define LDP_TLV_FR_LABEL 0x0202
130 #define LDP_TLV_STATUS 0x0300
131 #define LDP_TLV_EXTD_STATUS 0x0301
132 #define LDP_TLV_RETURNED_PDU 0x0302
133 #define LDP_TLV_RETURNED_MSG 0x0303
134 #define LDP_TLV_COMMON_HELLO 0x0400
135 #define LDP_TLV_IPV4_TRANSPORT_ADDR 0x0401
136 #define LDP_TLV_CONFIG_SEQ_NUMBER 0x0402
137 #define LDP_TLV_IPV6_TRANSPORT_ADDR 0x0403
138 #define LDP_TLV_COMMON_SESSION 0x0500
139 #define LDP_TLV_ATM_SESSION_PARM 0x0501
140 #define LDP_TLV_FR_SESSION_PARM 0x0502
141 #define LDP_TLV_FT_SESSION 0x0503
142 #define LDP_TLV_TYPED_WC_FEC_CAP 0x050b /* rfc 5918 */
143 #define LDP_TLV_LABEL_REQUEST_MSG_ID 0x0600
144 #define LDP_TLV_MTU 0x0601 /* rfc 3988 */
145 #define LDP_TLV_DUAL_STACK_CAP 0x0701 /* rfc 7552 */
146
147 static const struct tok ldp_tlv_values[] = {
148 { LDP_TLV_FEC, "FEC" },
149 { LDP_TLV_ADDRESS_LIST, "Address List" },
150 { LDP_TLV_HOP_COUNT, "Hop Count" },
151 { LDP_TLV_PATH_VECTOR, "Path Vector" },
152 { LDP_TLV_GENERIC_LABEL, "Generic Label" },
153 { LDP_TLV_ATM_LABEL, "ATM Label" },
154 { LDP_TLV_FR_LABEL, "Frame-Relay Label" },
155 { LDP_TLV_STATUS, "Status" },
156 { LDP_TLV_EXTD_STATUS, "Extended Status" },
157 { LDP_TLV_RETURNED_PDU, "Returned PDU" },
158 { LDP_TLV_RETURNED_MSG, "Returned Message" },
159 { LDP_TLV_COMMON_HELLO, "Common Hello Parameters" },
160 { LDP_TLV_IPV4_TRANSPORT_ADDR, "IPv4 Transport Address" },
161 { LDP_TLV_CONFIG_SEQ_NUMBER, "Configuration Sequence Number" },
162 { LDP_TLV_IPV6_TRANSPORT_ADDR, "IPv6 Transport Address" },
163 { LDP_TLV_COMMON_SESSION, "Common Session Parameters" },
164 { LDP_TLV_ATM_SESSION_PARM, "ATM Session Parameters" },
165 { LDP_TLV_FR_SESSION_PARM, "Frame-Relay Session Parameters" },
166 { LDP_TLV_FT_SESSION, "Fault-Tolerant Session Parameters" },
167 { LDP_TLV_TYPED_WC_FEC_CAP, "Typed Wildcard FEC Capability" },
168 { LDP_TLV_LABEL_REQUEST_MSG_ID, "Label Request Message ID" },
169 { LDP_TLV_MTU, "MTU" },
170 { LDP_TLV_DUAL_STACK_CAP, "Dual-Stack Capability" },
171 { 0, NULL}
172 };
173
174 static const struct tok ldp_status_code_values[] = {
175 /* rfc 5036 */
176 { 0x00000000, "Success" },
177 { 0x00000001, "Bad LDP Identifier" },
178 { 0x00000002, "Bad Protocol Version" },
179 { 0x00000003, "Bad PDU Length" },
180 { 0x00000004, "Unknown Message Type" },
181 { 0x00000005, "Bad Message Length" },
182 { 0x00000006, "Unknown TLV" },
183 { 0x00000007, "Bad TLV Length" },
184 { 0x00000008, "Malformted TLV Value" },
185 { 0x00000009, "Hold Timer Expired" },
186 { 0x0000000A, "Shutdown" },
187 { 0x0000000B, "Loop Detected" },
188 { 0x0000000C, "Unknown FEC" },
189 { 0x0000000D, "No Route" },
190 { 0x0000000E, "No Label Resources" },
191 { 0x0000000F, "Label Resources/Available" },
192 { 0x00000010, "Session Rejected/No Hello" },
193 { 0x00000011, "Session Rejected/Parameters Advertisement Mode" },
194 { 0x00000012, "Session Rejected/Parameters Max PDU Length" },
195 { 0x00000013, "Session Rejected/Parameters Label Range" },
196 { 0x00000014, "KeepAlive Timer Expired" },
197 { 0x00000015, "Label Request Aborted" },
198 { 0x00000016, "Missing Message Parameters" },
199 { 0x00000017, "Unsupported Address Family" },
200 { 0x00000018, "Session Rejected/Bad KeepAlive Time" },
201 { 0x00000019, "Internal Error" },
202 { 0, NULL}
203 };
204
205 #define LDP_FEC_WILDCARD 0x01
206 #define LDP_FEC_PREFIX 0x02
207 #define LDP_FEC_HOSTADDRESS 0x03
208 /* From RFC 4906; should probably be updated to RFC 4447 (e.g., VC -> PW) */
209 #define LDP_FEC_MARTINI_VC 0x80
210
211 static const struct tok ldp_fec_values[] = {
212 { LDP_FEC_WILDCARD, "Wildcard" },
213 { LDP_FEC_PREFIX, "Prefix" },
214 { LDP_FEC_HOSTADDRESS, "Host address" },
215 { LDP_FEC_MARTINI_VC, "Martini VC" },
216 { 0, NULL}
217 };
218
219 #define LDP_FEC_MARTINI_IFPARM_MTU 0x01
220 #define LDP_FEC_MARTINI_IFPARM_DESC 0x03
221 #define LDP_FEC_MARTINI_IFPARM_VCCV 0x0c
222
223 static const struct tok ldp_fec_martini_ifparm_values[] = {
224 { LDP_FEC_MARTINI_IFPARM_MTU, "MTU" },
225 { LDP_FEC_MARTINI_IFPARM_DESC, "Description" },
226 { LDP_FEC_MARTINI_IFPARM_VCCV, "VCCV" },
227 { 0, NULL}
228 };
229
230 /* draft-ietf-pwe3-vccv-04.txt */
231 static const struct tok ldp_fec_martini_ifparm_vccv_cc_values[] = {
232 { 0x01, "PWE3 control word" },
233 { 0x02, "MPLS Router Alert Label" },
234 { 0x04, "MPLS inner label TTL = 1" },
235 { 0, NULL}
236 };
237
238 /* draft-ietf-pwe3-vccv-04.txt */
239 static const struct tok ldp_fec_martini_ifparm_vccv_cv_values[] = {
240 { 0x01, "ICMP Ping" },
241 { 0x02, "LSP Ping" },
242 { 0x04, "BFD" },
243 { 0, NULL}
244 };
245
246 /* rfc 7552 */
247 #define LDP_DUAL_STACK_TRANSPORT_PREF_IPV4 0x40
248 #define LDP_DUAL_STACK_TRANSPORT_PREF_IPV6 0x60
249
250 static const struct tok ldp_dual_stack_transport_pref_values[] = {
251 { LDP_DUAL_STACK_TRANSPORT_PREF_IPV4, "IPv4" },
252 { LDP_DUAL_STACK_TRANSPORT_PREF_IPV6, "IPv6" },
253 { 0, NULL}
254 };
255
256 static u_int ldp_pdu_print(netdissect_options *, const u_char *);
257
258 /*
259 * ldp tlv header
260 *
261 * 0 1 2 3
262 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
263 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
264 * |U|F| Type | Length |
265 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
266 * | |
267 * | Value |
268 * ~ ~
269 * | |
270 * | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
271 * | |
272 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
273 */
274
275 static u_int
276 ldp_tlv_print(netdissect_options *ndo,
277 const u_char *tptr,
278 u_int msg_tlen)
279 {
280 struct ldp_tlv_header {
281 nd_uint16_t type;
282 nd_uint16_t length;
283 };
284
285 const struct ldp_tlv_header *ldp_tlv_header;
286 u_short tlv_type,tlv_len,tlv_tlen,af,ft_flags;
287 u_char fec_type, transport_pref;
288 u_int ui,vc_info_len, vc_info_tlv_type, vc_info_tlv_len;
289 char buf[100];
290 int i;
291
292 ldp_tlv_header = (const struct ldp_tlv_header *)tptr;
293 ND_TCHECK_SIZE(ldp_tlv_header);
294 tlv_len=GET_BE_U_2(ldp_tlv_header->length);
295 if (tlv_len + 4U > msg_tlen) {
296 ND_PRINT("\n\t\t TLV contents go past end of message");
297 return 0;
298 }
299 tlv_tlen=tlv_len;
300 tlv_type=LDP_MASK_TLV_TYPE(GET_BE_U_2(ldp_tlv_header->type));
301
302 /* FIXME vendor private / experimental check */
303 ND_PRINT("\n\t %s TLV (0x%04x), length: %u, Flags: [%s and %s forward if unknown]",
304 tok2str(ldp_tlv_values,
305 "Unknown",
306 tlv_type),
307 tlv_type,
308 tlv_len,
309 LDP_MASK_U_BIT(GET_BE_U_2(ldp_tlv_header->type)) ? "continue processing" : "ignore",
310 LDP_MASK_F_BIT(GET_BE_U_2(ldp_tlv_header->type)) ? "do" : "don't");
311
312 tptr+=sizeof(struct ldp_tlv_header);
313
314 switch(tlv_type) {
315
316 case LDP_TLV_COMMON_HELLO:
317 ND_ICHECKMSG_U("tlv length", tlv_tlen, <, 4);
318 ND_PRINT("\n\t Hold Time: %us, Flags: [%s Hello%s]",
319 GET_BE_U_2(tptr),
320 (GET_BE_U_2(tptr + 2)&0x8000) ? "Targeted" : "Link",
321 (GET_BE_U_2(tptr + 2)&0x4000) ? ", Request for targeted Hellos" : "");
322 break;
323
324 case LDP_TLV_IPV4_TRANSPORT_ADDR:
325 ND_ICHECKMSG_U("tlv length", tlv_tlen, <, 4);
326 ND_PRINT("\n\t IPv4 Transport Address: %s", GET_IPADDR_STRING(tptr));
327 break;
328 case LDP_TLV_IPV6_TRANSPORT_ADDR:
329 ND_ICHECKMSG_U("tlv length", tlv_tlen, <, 16);
330 ND_PRINT("\n\t IPv6 Transport Address: %s", GET_IP6ADDR_STRING(tptr));
331 break;
332 case LDP_TLV_CONFIG_SEQ_NUMBER:
333 ND_ICHECKMSG_U("tlv length", tlv_tlen, <, 4);
334 ND_PRINT("\n\t Sequence Number: %u", GET_BE_U_4(tptr));
335 break;
336
337 case LDP_TLV_ADDRESS_LIST:
338 ND_ICHECKMSG_U("tlv length", tlv_tlen, <,
339 LDP_TLV_ADDRESS_LIST_AFNUM_LEN);
340 af = GET_BE_U_2(tptr);
341 tptr+=LDP_TLV_ADDRESS_LIST_AFNUM_LEN;
342 tlv_tlen -= LDP_TLV_ADDRESS_LIST_AFNUM_LEN;
343 ND_PRINT("\n\t Address Family: %s, addresses",
344 tok2str(af_values, "Unknown (%u)", af));
345 switch (af) {
346 case AFNUM_IP:
347 while(tlv_tlen >= sizeof(nd_ipv4)) {
348 ND_PRINT(" %s", GET_IPADDR_STRING(tptr));
349 tlv_tlen-=sizeof(nd_ipv4);
350 tptr+=sizeof(nd_ipv4);
351 }
352 break;
353 case AFNUM_IP6:
354 while(tlv_tlen >= sizeof(nd_ipv6)) {
355 ND_PRINT(" %s", GET_IP6ADDR_STRING(tptr));
356 tlv_tlen-=sizeof(nd_ipv6);
357 tptr+=sizeof(nd_ipv6);
358 }
359 break;
360 default:
361 /* unknown AF */
362 break;
363 }
364 break;
365
366 case LDP_TLV_HOP_COUNT:
367 ND_ICHECKMSG_U("tlv length", tlv_tlen, <, 1);
368 ND_PRINT("\n\t Hop Count: %u", GET_U_1(tptr));
369 break;
370
371 case LDP_TLV_PATH_VECTOR:
372 ND_ICHECKMSG_U("tlv length", tlv_tlen, <, 4);
373 ND_PRINT("\n\t Path Vector: %s", GET_IPADDR_STRING(tptr));
374 tptr += 4;
375 tlv_tlen -= 4;
376 while (tlv_tlen >= 4) {
377 ND_PRINT(", %s", GET_IPADDR_STRING(tptr));
378 tptr += 4;
379 tlv_tlen -= 4;
380 }
381 break;
382
383 case LDP_TLV_COMMON_SESSION:
384 ND_ICHECKMSG_U("tlv length", tlv_tlen, <, 14);
385 ND_PRINT("\n\t Version: %u, Keepalive: %us, Flags: [Downstream %s, Loop Detection %s]",
386 GET_BE_U_2(tptr), GET_BE_U_2(tptr + 2),
387 (GET_BE_U_2(tptr + 4)&0x8000) ? "On Demand" : "Unsolicited",
388 (GET_BE_U_2(tptr + 4)&0x4000) ? "Enabled" : "Disabled"
389 );
390 ND_PRINT("\n\t Path Vector Limit %u, Max-PDU length: %u, Receiver Label-Space-ID %s:%u",
391 GET_U_1(tptr+5),
392 GET_BE_U_2(tptr+6),
393 GET_IPADDR_STRING(tptr+8),
394 GET_BE_U_2(tptr+12)
395 );
396 break;
397
398 case LDP_TLV_FEC:
399 ND_ICHECKMSG_U("tlv length", tlv_tlen, <, 1);
400 fec_type = GET_U_1(tptr);
401 ND_PRINT("\n\t %s FEC (0x%02x)",
402 tok2str(ldp_fec_values, "Unknown", fec_type),
403 fec_type);
404
405 tptr+=1;
406 tlv_tlen-=1;
407 switch(fec_type) {
408
409 case LDP_FEC_WILDCARD:
410 break;
411 case LDP_FEC_PREFIX:
412 ND_ICHECKMSG_U("tlv length", tlv_tlen, <, 2);
413 af = GET_BE_U_2(tptr);
414 tptr+=2;
415 tlv_tlen-=2;
416 if (af == AFNUM_IP) {
417 i=decode_prefix4(ndo, tptr, tlv_tlen, buf, sizeof(buf));
418 if (i == -2)
419 goto trunc;
420 if (i == -3)
421 ND_PRINT(": IPv4 prefix (goes past end of TLV)");
422 else if (i == -1)
423 ND_PRINT(": IPv4 prefix (invalid length)");
424 else
425 ND_PRINT(": IPv4 prefix %s", buf);
426 } else if (af == AFNUM_IP6) {
427 i=decode_prefix6(ndo, tptr, tlv_tlen, buf, sizeof(buf));
428 if (i == -2)
429 goto trunc;
430 if (i == -3)
431 ND_PRINT(": IPv4 prefix (goes past end of TLV)");
432 else if (i == -1)
433 ND_PRINT(": IPv6 prefix (invalid length)");
434 else
435 ND_PRINT(": IPv6 prefix %s", buf);
436 } else
437 ND_PRINT(": Address family %u prefix", af);
438 break;
439 case LDP_FEC_HOSTADDRESS:
440 break;
441 case LDP_FEC_MARTINI_VC:
442 /*
443 * We assume the type was supposed to be one of the MPLS
444 * Pseudowire Types.
445 */
446 ND_ICHECKMSG_U("tlv length", tlv_tlen, <, 7);
447 vc_info_len = GET_U_1(tptr + 2);
448
449 /*
450 * According to RFC 4908, the VC info Length field can be zero,
451 * in which case not only are there no interface parameters,
452 * there's no VC ID.
453 */
454 if (vc_info_len == 0) {
455 ND_PRINT(": %s, %scontrol word, group-ID %u, VC-info-length: %u",
456 tok2str(mpls_pw_types_values, "Unknown", GET_BE_U_2(tptr)&0x7fff),
457 GET_BE_U_2(tptr)&0x8000 ? "" : "no ",
458 GET_BE_U_4(tptr + 3),
459 vc_info_len);
460 break;
461 }
462
463 /* Make sure we have the VC ID as well */
464 ND_ICHECKMSG_U("tlv length", tlv_tlen, <, 11);
465 ND_PRINT(": %s, %scontrol word, group-ID %u, VC-ID %u, VC-info-length: %u",
466 tok2str(mpls_pw_types_values, "Unknown", GET_BE_U_2(tptr)&0x7fff),
467 GET_BE_U_2(tptr)&0x8000 ? "" : "no ",
468 GET_BE_U_4(tptr + 3),
469 GET_BE_U_4(tptr + 7),
470 vc_info_len);
471 if (vc_info_len < 4) {
472 /* minimum 4, for the VC ID */
473 ND_PRINT(" (invalid, < 4");
474 return(tlv_len+4); /* Type & Length fields not included */
475 }
476 vc_info_len -= 4; /* subtract out the VC ID, giving the length of the interface parameters */
477
478 /* Skip past the fixed information and the VC ID */
479 tptr+=11;
480 tlv_tlen-=11;
481 ND_ICHECKMSG_U("tlv length", tlv_tlen, <, vc_info_len);
482
483 while (vc_info_len > 2) {
484 vc_info_tlv_type = GET_U_1(tptr);
485 vc_info_tlv_len = GET_U_1(tptr + 1);
486 if (vc_info_tlv_len < 2)
487 break;
488 if (vc_info_len < vc_info_tlv_len)
489 break;
490
491 ND_PRINT("\n\t\tInterface Parameter: %s (0x%02x), len %u",
492 tok2str(ldp_fec_martini_ifparm_values,"Unknown",vc_info_tlv_type),
493 vc_info_tlv_type,
494 vc_info_tlv_len);
495
496 switch(vc_info_tlv_type) {
497 case LDP_FEC_MARTINI_IFPARM_MTU:
498 ND_PRINT(": %u", GET_BE_U_2(tptr + 2));
499 break;
500
501 case LDP_FEC_MARTINI_IFPARM_DESC:
502 ND_PRINT(": ");
503 nd_printjn(ndo, tptr + 2, vc_info_tlv_len - 2);
504 break;
505
506 case LDP_FEC_MARTINI_IFPARM_VCCV:
507 ND_PRINT("\n\t\t Control Channels (0x%02x) = [%s]",
508 GET_U_1((tptr + 2)),
509 bittok2str(ldp_fec_martini_ifparm_vccv_cc_values, "none", GET_U_1((tptr + 2))));
510 ND_PRINT("\n\t\t CV Types (0x%02x) = [%s]",
511 GET_U_1((tptr + 3)),
512 bittok2str(ldp_fec_martini_ifparm_vccv_cv_values, "none", GET_U_1((tptr + 3))));
513 break;
514
515 default:
516 print_unknown_data(ndo, tptr+2, "\n\t\t ", vc_info_tlv_len-2);
517 break;
518 }
519
520 vc_info_len -= vc_info_tlv_len;
521 tptr += vc_info_tlv_len;
522 }
523 break;
524 }
525
526 break;
527
528 case LDP_TLV_GENERIC_LABEL:
529 ND_ICHECKMSG_U("tlv length", tlv_tlen, <, 4);
530 ND_PRINT("\n\t Label: %u", GET_BE_U_4(tptr) & 0xfffff);
531 break;
532
533 case LDP_TLV_STATUS:
534 ND_ICHECKMSG_U("tlv length", tlv_tlen, <, 10);
535 ui = GET_BE_U_4(tptr);
536 tptr+=4;
537 ND_PRINT("\n\t Status Code: %s, Flags: [%s and %s forward]",
538 tok2str(ldp_status_code_values, "Unknown", ui&0x3fffffff),
539 ui&0x80000000 ? "Fatal error" : "Advisory Notification",
540 ui&0x40000000 ? "do" : "don't");
541 ui = GET_BE_U_4(tptr);
542 tptr+=4;
543 if (ui)
544 ND_PRINT(", causing Message ID: 0x%08x", ui);
545 ui = GET_BE_U_2(tptr);
546 if (ui)
547 ND_PRINT(", Message Type: %s", tok2str(ldp_msg_values, "Unknown", ui));
548 break;
549
550 case LDP_TLV_FT_SESSION:
551 ND_ICHECKMSG_U("tlv length", tlv_tlen, <, 12);
552 ft_flags = GET_BE_U_2(tptr);
553 ND_PRINT("\n\t Flags: [%sReconnect, %sSave State, %sAll-Label Protection, %s Checkpoint, %sRe-Learn State]",
554 ft_flags&0x8000 ? "" : "No ",
555 ft_flags&0x8 ? "" : "Don't ",
556 ft_flags&0x4 ? "" : "No ",
557 ft_flags&0x2 ? "Sequence Numbered Label" : "All Labels",
558 ft_flags&0x1 ? "" : "Don't ");
559 /* 16 bits (FT Flags) + 16 bits (Reserved) */
560 tptr+=4;
561 ui = GET_BE_U_4(tptr);
562 if (ui)
563 ND_PRINT(", Reconnect Timeout: %ums", ui);
564 tptr+=4;
565 ui = GET_BE_U_4(tptr);
566 if (ui)
567 ND_PRINT(", Recovery Time: %ums", ui);
568 break;
569
570 case LDP_TLV_TYPED_WC_FEC_CAP:
571 ND_ICHECKMSG_U("tlv length", tlv_tlen, <, 1);
572 ND_PRINT("\n\t %s", GET_U_1(tptr)&0x80 ? "Support" : "No Support");
573 break;
574
575 case LDP_TLV_MTU:
576 ND_ICHECKMSG_U("tlv length", tlv_tlen, <, 2);
577 ND_PRINT("\n\t MTU: %u", GET_BE_U_2(tptr));
578 break;
579
580 case LDP_TLV_DUAL_STACK_CAP:
581 ND_ICHECKMSG_U("tlv length", tlv_tlen, <, 4);
582 transport_pref = GET_U_1(tptr);
583 ND_PRINT("\n\t Transport Connection Preference: %s",
584 tok2str(ldp_dual_stack_transport_pref_values,
585 "Unknown",
586 transport_pref));
587 break;
588
589 /*
590 * FIXME those are the defined TLVs that lack a decoder
591 * you are welcome to contribute code ;-)
592 */
593
594 case LDP_TLV_ATM_LABEL:
595 case LDP_TLV_FR_LABEL:
596 case LDP_TLV_EXTD_STATUS:
597 case LDP_TLV_RETURNED_PDU:
598 case LDP_TLV_RETURNED_MSG:
599 case LDP_TLV_ATM_SESSION_PARM:
600 case LDP_TLV_FR_SESSION_PARM:
601 case LDP_TLV_LABEL_REQUEST_MSG_ID:
602
603 default:
604 if (ndo->ndo_vflag <= 1)
605 print_unknown_data(ndo, tptr, "\n\t ", tlv_tlen);
606 break;
607 }
608 return(tlv_len+4); /* Type & Length fields not included */
609
610 trunc:
611 nd_trunc_longjmp(ndo);
612
613 invalid:
614 nd_print_invalid(ndo);
615 return(tlv_len+4); /* Type & Length fields not included */
616 }
617
618 void
619 ldp_print(netdissect_options *ndo,
620 const u_char *pptr, u_int len)
621 {
622 u_int processed;
623
624 ndo->ndo_protocol = "ldp";
625 while (len > (sizeof(struct ldp_common_header) + sizeof(struct ldp_msg_header))) {
626 processed = ldp_pdu_print(ndo, pptr);
627 if (processed == 0)
628 return;
629 if (len < processed) {
630 ND_PRINT(" [remaining length %u < %u]", len, processed);
631 nd_print_invalid(ndo);
632 break;
633 }
634 len -= processed;
635 pptr += processed;
636 }
637 }
638
639 static u_int
640 ldp_pdu_print(netdissect_options *ndo,
641 const u_char *pptr)
642 {
643 const struct ldp_common_header *ldp_com_header;
644 const struct ldp_msg_header *ldp_msg_header;
645 const u_char *tptr,*msg_tptr;
646 u_short tlen;
647 u_short pdu_len,msg_len,msg_type;
648 u_int msg_tlen;
649 int hexdump,processed;
650
651 ldp_com_header = (const struct ldp_common_header *)pptr;
652 ND_TCHECK_SIZE(ldp_com_header);
653
654 /*
655 * Sanity checking of the header.
656 */
657 if (GET_BE_U_2(ldp_com_header->version) != LDP_VERSION) {
658 ND_PRINT("%sLDP version %u packet not supported",
659 (ndo->ndo_vflag < 1) ? "" : "\n\t",
660 GET_BE_U_2(ldp_com_header->version));
661 return 0;
662 }
663
664 pdu_len = GET_BE_U_2(ldp_com_header->pdu_length);
665 if (pdu_len < sizeof(struct ldp_common_header)-4) {
666 /* length too short */
667 ND_PRINT("%sLDP, pdu-length: %u (too short, < %zu)",
668 (ndo->ndo_vflag < 1) ? "" : "\n\t",
669 pdu_len,
670 sizeof(struct ldp_common_header)-4);
671 return 0;
672 }
673
674 /* print the LSR-ID, label-space & length */
675 ND_PRINT("%sLDP, Label-Space-ID: %s:%u, pdu-length: %u",
676 (ndo->ndo_vflag < 1) ? "" : "\n\t",
677 GET_IPADDR_STRING(ldp_com_header->lsr_id),
678 GET_BE_U_2(ldp_com_header->label_space),
679 pdu_len);
680
681 /* bail out if non-verbose */
682 if (ndo->ndo_vflag < 1)
683 return 0;
684
685 /* ok they seem to want to know everything - lets fully decode it */
686 tptr = pptr + sizeof(struct ldp_common_header);
687 tlen = pdu_len - (sizeof(struct ldp_common_header)-4); /* Type & Length fields not included */
688
689 while(tlen != 0) {
690 /* did we capture enough for fully decoding the msg header ? */
691 ND_TCHECK_LEN(tptr, sizeof(struct ldp_msg_header));
692
693 ldp_msg_header = (const struct ldp_msg_header *)tptr;
694 msg_len=GET_BE_U_2(ldp_msg_header->length);
695 msg_type=LDP_MASK_MSG_TYPE(GET_BE_U_2(ldp_msg_header->type));
696
697 if (msg_len < sizeof(struct ldp_msg_header)-4) {
698 /* length too short */
699 /* FIXME vendor private / experimental check */
700 ND_PRINT("\n\t %s Message (0x%04x), length: %u (too short, < %zu)",
701 tok2str(ldp_msg_values,
702 "Unknown",
703 msg_type),
704 msg_type,
705 msg_len,
706 sizeof(struct ldp_msg_header)-4);
707 return 0;
708 }
709
710 /* FIXME vendor private / experimental check */
711 ND_PRINT("\n\t %s Message (0x%04x), length: %u, Message ID: 0x%08x, Flags: [%s if unknown]",
712 tok2str(ldp_msg_values,
713 "Unknown",
714 msg_type),
715 msg_type,
716 msg_len,
717 GET_BE_U_4(ldp_msg_header->id),
718 LDP_MASK_U_BIT(GET_BE_U_2(ldp_msg_header->type)) ? "continue processing" : "ignore");
719
720 msg_tptr=tptr+sizeof(struct ldp_msg_header);
721 msg_tlen=msg_len-(sizeof(struct ldp_msg_header)-4); /* Type & Length fields not included */
722
723 /* did we capture enough for fully decoding the message ? */
724 ND_TCHECK_LEN(tptr, msg_len);
725 hexdump=FALSE;
726
727 switch(msg_type) {
728
729 case LDP_MSG_NOTIF:
730 case LDP_MSG_HELLO:
731 case LDP_MSG_INIT:
732 case LDP_MSG_KEEPALIVE:
733 case LDP_MSG_ADDRESS:
734 case LDP_MSG_LABEL_MAPPING:
735 case LDP_MSG_ADDRESS_WITHDRAW:
736 case LDP_MSG_LABEL_WITHDRAW:
737 case LDP_MSG_LABEL_REQUEST:
738 case LDP_MSG_LABEL_RELEASE:
739 case LDP_MSG_LABEL_ABORT_REQUEST:
740 while(msg_tlen >= 4) {
741 processed = ldp_tlv_print(ndo, msg_tptr, msg_tlen);
742 if (processed == 0)
743 break;
744 msg_tlen-=processed;
745 msg_tptr+=processed;
746 }
747 break;
748
749 default:
750 if (ndo->ndo_vflag <= 1)
751 print_unknown_data(ndo, msg_tptr, "\n\t ", msg_tlen);
752 break;
753 }
754 /* do we want to see an additionally hexdump ? */
755 if (ndo->ndo_vflag > 1 || hexdump==TRUE)
756 print_unknown_data(ndo, tptr+sizeof(struct ldp_msg_header), "\n\t ",
757 msg_len);
758
759 tptr += msg_len+4;
760 tlen -= msg_len+4;
761 }
762 return pdu_len+4;
763 trunc:
764 nd_trunc_longjmp(ndo);
765 }