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