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.
13 * Original code by Hannes Gredler (hannes@juniper.net)
14 * and Steinar Haug (sthaug@nethelp.no)
18 static const char rcsid
[] _U_
=
19 "@(#) $Header: /tcpdump/master/tcpdump/print-ldp.c,v 1.7 2004-05-27 21:20:50 guy Exp $";
26 #include <tcpdump-stdinc.h>
32 #include "interface.h"
33 #include "decode_prefix.h"
35 #include "addrtoname.h"
41 * 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
42 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
43 * | Version | PDU Length |
44 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
46 * + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
48 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
52 struct ldp_common_header
{
54 u_int8_t pdu_length
[2];
56 u_int8_t label_space
[2];
65 * 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
66 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
67 * |U| Message Type | Message Length |
68 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
70 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
73 * | Mandatory Parameters |
76 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
79 * | Optional Parameters |
82 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
85 struct ldp_msg_header
{
91 #define LDP_MASK_MSG_TYPE(x) ((x)&0x7fff)
92 #define LDP_MASK_U_BIT(x) ((x)&0x8000)
94 #define LDP_MSG_NOTIF 0x0001
95 #define LDP_MSG_HELLO 0x0100
96 #define LDP_MSG_INIT 0x0200
97 #define LDP_MSG_KEEPALIVE 0x0201
98 #define LDP_MSG_ADDRESS 0x0300
99 #define LDP_MSG_ADDRESS_WITHDRAW 0x0301
100 #define LDP_MSG_LABEL_MAPPING 0x0400
101 #define LDP_MSG_LABEL_REQUEST 0x0401
102 #define LDP_MSG_LABEL_WITHDRAW 0x0402
103 #define LDP_MSG_LABEL_RELEASE 0x0403
104 #define LDP_MSG_LABEL_ABORT_REQUEST 0x0404
106 #define LDP_VENDOR_PRIVATE_MIN 0x3e00
107 #define LDP_VENDOR_PRIVATE_MAX 0x3eff
108 #define LDP_EXPERIMENTAL_MIN 0x3f00
109 #define LDP_EXPERIMENTAL_MAX 0x3fff
111 static const struct tok ldp_msg_values
[] = {
112 { LDP_MSG_NOTIF
, "Notification" },
113 { LDP_MSG_HELLO
, "Hello" },
114 { LDP_MSG_INIT
, "Initialization" },
115 { LDP_MSG_KEEPALIVE
, "Keepalive" },
116 { LDP_MSG_ADDRESS
, "Address" },
117 { LDP_MSG_ADDRESS_WITHDRAW
, "Address Widthdraw" },
118 { LDP_MSG_LABEL_MAPPING
, "Label Mapping" },
119 { LDP_MSG_LABEL_REQUEST
, "Label Request" },
120 { LDP_MSG_LABEL_WITHDRAW
, "Label Withdraw" },
121 { LDP_MSG_LABEL_RELEASE
, "Label Release" },
122 { LDP_MSG_LABEL_ABORT_REQUEST
, "Label Abort Request" },
126 #define LDP_MASK_TLV_TYPE(x) ((x)&0x3fff)
127 #define LDP_MASK_F_BIT(x) ((x)&0x4000)
129 #define LDP_TLV_FEC 0x0100
130 #define LDP_TLV_ADDRESS_LIST 0x0101
131 #define LDP_TLV_HOP_COUNT 0x0103
132 #define LDP_TLV_PATH_VECTOR 0x0104
133 #define LDP_TLV_GENERIC_LABEL 0x0200
134 #define LDP_TLV_ATM_LABEL 0x0201
135 #define LDP_TLV_FR_LABEL 0x0202
136 #define LDP_TLV_STATUS 0x0300
137 #define LDP_TLV_EXTD_STATUS 0x0301
138 #define LDP_TLV_RETURNED_PDU 0x0302
139 #define LDP_TLV_RETURNED_MSG 0x0303
140 #define LDP_TLV_COMMON_HELLO 0x0400
141 #define LDP_TLV_IPV4_TRANSPORT_ADDR 0x0401
142 #define LDP_TLV_CONFIG_SEQ_NUMBER 0x0402
143 #define LDP_TLV_IPV6_TRANSPORT_ADDR 0x0403
144 #define LDP_TLV_COMMON_SESSION 0x0500
145 #define LDP_TLV_ATM_SESSION_PARM 0x0501
146 #define LDP_TLV_FR_SESSION_PARM 0x0502
147 #define LDP_TLV_FT_SESSION 0x0503
148 #define LDP_TLV_LABEL_REQUEST_MSG_ID 0x0600
150 static const struct tok ldp_tlv_values
[] = {
151 { LDP_TLV_FEC
, "FEC" },
152 { LDP_TLV_ADDRESS_LIST
, "Address List" },
153 { LDP_TLV_HOP_COUNT
, "Hop Count" },
154 { LDP_TLV_PATH_VECTOR
, "Path Vector" },
155 { LDP_TLV_GENERIC_LABEL
, "Generic Label" },
156 { LDP_TLV_ATM_LABEL
, "ATM Label" },
157 { LDP_TLV_FR_LABEL
, "Frame-Relay Label" },
158 { LDP_TLV_STATUS
, "Status" },
159 { LDP_TLV_EXTD_STATUS
, "Extended Status" },
160 { LDP_TLV_RETURNED_PDU
, "Returned PDU" },
161 { LDP_TLV_RETURNED_MSG
, "Returned Message" },
162 { LDP_TLV_COMMON_HELLO
, "Common Hello Parameters" },
163 { LDP_TLV_IPV4_TRANSPORT_ADDR
, "IPv4 Transport Address" },
164 { LDP_TLV_CONFIG_SEQ_NUMBER
, "Configuration Sequence Number" },
165 { LDP_TLV_IPV6_TRANSPORT_ADDR
, "IPv6 Transport Address" },
166 { LDP_TLV_COMMON_SESSION
, "Common Session Parameters" },
167 { LDP_TLV_ATM_SESSION_PARM
, "ATM Session Parameters" },
168 { LDP_TLV_FR_SESSION_PARM
, "Frame-Relay Session Parameters" },
169 { LDP_TLV_FT_SESSION
, "Fault-Tolerant Session Parameters" },
170 { LDP_TLV_LABEL_REQUEST_MSG_ID
, "Label Request Message ID" },
174 #define LDP_FEC_WILDCARD 0x01
175 #define LDP_FEC_PREFIX 0x02
176 #define LDP_FEC_HOSTADDRESS 0x03
177 /* From draft-martini-l2circuit-trans-mpls-13.txt */
178 #define LDP_FEC_MARTINI_VC 0x80
180 static const struct tok ldp_fec_values
[] = {
181 { LDP_FEC_WILDCARD
, "Wildcard" },
182 { LDP_FEC_PREFIX
, "Prefix" },
183 { LDP_FEC_HOSTADDRESS
, "Host address" },
184 { LDP_FEC_MARTINI_VC
, "Martini VC" },
188 /* From draft-martini-l2circuit-trans-mpls-13.txt */
189 #define LDP_MARTINI_VCTYPE_FR_DLCI 0x0001
190 #define LDP_MARTINI_VCTYPE_ATM_AAL5 0x0002
191 #define LDP_MARTINI_VCTYPE_ATM_CELL 0x0003
192 #define LDP_MARTINI_VCTYPE_ETH_VLAN 0x0004
193 #define LDP_MARTINI_VCTYPE_ETHERNET 0x0005
194 #define LDP_MARTINI_VCTYPE_HDLC 0x0006
195 #define LDP_MARTINI_VCTYPE_PPP 0x0007
196 #define LDP_MARTINI_VCTYPE_CEM 0x0008
197 #define LDP_MARTINI_VCTYPE_ATM_VCC 0x0009
198 #define LDP_MARTINI_VCTYPE_ATM_VPC 0x000A
200 /* Overlaps print-bgp.c bgp_l2vpn_encaps_values */
201 static const struct tok ldp_vctype_values
[] = {
202 { LDP_MARTINI_VCTYPE_FR_DLCI
, "Frame Relay DLCI" },
203 { LDP_MARTINI_VCTYPE_ATM_AAL5
, "ATM AAL5 VCC transport" },
204 { LDP_MARTINI_VCTYPE_ATM_CELL
, "ATM transparent cell transport" },
205 { LDP_MARTINI_VCTYPE_ETH_VLAN
, "Ethernet VLAN" },
206 { LDP_MARTINI_VCTYPE_ETHERNET
, "Ethernet" },
207 { LDP_MARTINI_VCTYPE_HDLC
, "HDLC" },
208 { LDP_MARTINI_VCTYPE_PPP
, "PPP" },
209 { LDP_MARTINI_VCTYPE_CEM
, "SONET/SDH Circuit Emulation Service" },
210 { LDP_MARTINI_VCTYPE_ATM_VCC
, "ATM VCC cell transport" },
211 { LDP_MARTINI_VCTYPE_ATM_VPC
, "ATM VPC cell transport" },
215 /* RFC1700 address family numbers, same definition in print-bgp.c */
217 #define AFNUM_INET6 2
222 int ldp_tlv_print(register const u_char
*);
228 * 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
229 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
230 * |U|F| Type | Length |
231 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
236 * | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
238 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
242 ldp_tlv_print(register const u_char
*tptr
) {
244 struct ldp_tlv_header
{
249 const struct ldp_tlv_header
*ldp_tlv_header
;
250 u_short tlv_type
,tlv_len
,tlv_tlen
,af
,ft_flags
;
256 ldp_tlv_header
= (const struct ldp_tlv_header
*)tptr
;
257 tlv_len
=EXTRACT_16BITS(ldp_tlv_header
->length
);
259 tlv_type
=LDP_MASK_TLV_TYPE(EXTRACT_16BITS(ldp_tlv_header
->type
));
261 /* FIXME vendor private / experimental check */
262 printf("\n\t %s TLV (0x%04x), length: %u, Flags: [%s and %s forward if unknown]",
263 tok2str(ldp_tlv_values
,
268 LDP_MASK_U_BIT(EXTRACT_16BITS(&ldp_tlv_header
->type
)) ? "continue processing" : "ignore",
269 LDP_MASK_F_BIT(EXTRACT_16BITS(&ldp_tlv_header
->type
)) ? "do" : "don't");
271 tptr
+=sizeof(struct ldp_tlv_header
);
275 case LDP_TLV_COMMON_HELLO
:
276 printf("\n\t Hold Time: %us, Flags: [%s Hello%s]",
277 EXTRACT_16BITS(tptr
),
278 (EXTRACT_16BITS(tptr
+2)&0x8000) ? "Targeted" : "Link",
279 (EXTRACT_16BITS(tptr
+2)&0x4000) ? ", Request for targeted Hellos" : "");
282 case LDP_TLV_IPV4_TRANSPORT_ADDR
:
283 printf("\n\t IPv4 Transport Address: %s", ipaddr_string(tptr
));
286 case LDP_TLV_IPV6_TRANSPORT_ADDR
:
287 printf("\n\t IPv6 Transport Address: %s", ip6addr_string(tptr
));
290 case LDP_TLV_CONFIG_SEQ_NUMBER
:
291 printf("\n\t Sequence Number: %u", EXTRACT_32BITS(tptr
));
294 case LDP_TLV_ADDRESS_LIST
:
295 af
= EXTRACT_16BITS(tptr
);
297 printf("\n\t Adress Family: ");
298 if (af
== AFNUM_INET
) {
299 printf("IPv4, addresses:");
300 for (i
=0; i
<(tlv_tlen
-2)/4; i
++) {
301 printf(" %s",ipaddr_string(tptr
));
306 else if (af
== AFNUM_INET6
) {
307 printf("IPv6, addresses:");
308 for (i
=0; i
<(tlv_tlen
-2)/16; i
++) {
309 printf(" %s",ip6addr_string(tptr
));
316 case LDP_TLV_COMMON_SESSION
:
317 printf("\n\t Version: %u, Keepalive: %us, Flags: [Downstream %s, Loop Detection %s]",
318 EXTRACT_16BITS(tptr
), EXTRACT_16BITS(tptr
+2),
319 (EXTRACT_16BITS(tptr
+6)&0x8000) ? "On Demand" : "Unsolicited",
320 (EXTRACT_16BITS(tptr
+6)&0x4000) ? "Enabled" : "Disabled"
326 printf("\n\t %s FEC (0x%02x)",
327 tok2str(ldp_fec_values
, "Unknown", fec_type
),
333 case LDP_FEC_WILDCARD
:
336 af
= EXTRACT_16BITS(tptr
);
338 if (af
== AFNUM_INET
) {
339 i
=decode_prefix4(tptr
,buf
,sizeof(buf
));
340 printf(": IPv4 prefix %s",buf
);
343 else if (af
== AFNUM_INET6
) {
344 i
=decode_prefix6(tptr
,buf
,sizeof(buf
));
345 printf(": IPv6 prefix %s",buf
);
349 case LDP_FEC_HOSTADDRESS
:
351 case LDP_FEC_MARTINI_VC
:
352 printf(": %s, %scontrol word, VC %u",
353 tok2str(ldp_vctype_values
, "Unknown", EXTRACT_16BITS(tptr
)&0x7fff),
354 EXTRACT_16BITS(tptr
)&0x8000 ? "" : "no ",
355 EXTRACT_32BITS(tptr
+7));
361 case LDP_TLV_GENERIC_LABEL
:
362 printf("\n\t Label: %u", EXTRACT_32BITS(tptr
) & 0xfffff);
366 ui
= EXTRACT_32BITS(tptr
);
368 printf("\n\t Status: 0x%02x, Flags: [%s and %s forward]",
370 ui
&0x80000000 ? "Fatal error" : "Advisory Notification",
371 ui
&0x40000000 ? "do" : "don't");
372 ui
= EXTRACT_32BITS(tptr
);
375 printf(", causing Message ID: 0x%08x", ui
);
378 case LDP_TLV_FT_SESSION
:
379 ft_flags
= EXTRACT_16BITS(tptr
);
380 printf("\n\t Flags: [%sReconnect, %sSave State, %sAll-Label Protection, %s Checkpoint, %sRe-Learn State]",
381 ft_flags
&0x8000 ? "" : "No ",
382 ft_flags
&0x8 ? "" : "Don't ",
383 ft_flags
&0x4 ? "" : "No ",
384 ft_flags
&0x2 ? "Sequence Numbered Label" : "All Labels",
385 ft_flags
&0x1 ? "" : "Don't ");
387 ui
= EXTRACT_32BITS(tptr
);
389 printf(", Reconnect Timeout: %ums", ui
);
391 ui
= EXTRACT_32BITS(tptr
);
393 printf(", Recovery Time: %ums", ui
);
398 * FIXME those are the defined TLVs that lack a decoder
399 * you are welcome to contribute code ;-)
402 case LDP_TLV_HOP_COUNT
:
403 case LDP_TLV_PATH_VECTOR
:
404 case LDP_TLV_ATM_LABEL
:
405 case LDP_TLV_FR_LABEL
:
406 case LDP_TLV_EXTD_STATUS
:
407 case LDP_TLV_RETURNED_PDU
:
408 case LDP_TLV_RETURNED_MSG
:
409 case LDP_TLV_ATM_SESSION_PARM
:
410 case LDP_TLV_FR_SESSION_PARM
:
411 case LDP_TLV_LABEL_REQUEST_MSG_ID
:
415 print_unknown_data(tptr
,"\n\t ",tlv_tlen
);
418 return(tlv_len
+4); /* Type & Length fields not included */
422 ldp_print(register const u_char
*pptr
, register u_int len
) {
424 const struct ldp_common_header
*ldp_com_header
;
425 const struct ldp_msg_header
*ldp_msg_header
;
426 const u_char
*tptr
,*msg_tptr
;
428 u_short msg_len
,msg_type
,msg_tlen
;
429 int hexdump
,processed
;
432 ldp_com_header
= (const struct ldp_common_header
*)pptr
;
433 TCHECK(*ldp_com_header
);
436 * Sanity checking of the header.
438 if (EXTRACT_16BITS(&ldp_com_header
->version
) != LDP_VERSION
) {
439 printf("LDP version %u packet not supported",
440 EXTRACT_16BITS(&ldp_com_header
->version
));
444 /* print the LSR-ID, label-space & length */
445 printf("%sLDP, Label-Space-ID: %s:%u, length: %u",
446 (vflag
< 1) ? "" : "\n\t",
447 ipaddr_string(&ldp_com_header
->lsr_id
),
448 EXTRACT_16BITS(&ldp_com_header
->label_space
),
451 /* bail out if non-verbose */
455 /* ok they seem to want to know everything - lets fully decode it */
456 tlen
=EXTRACT_16BITS(ldp_com_header
->pdu_length
);
458 tptr
+= sizeof(const struct ldp_common_header
);
459 tlen
-= sizeof(const struct ldp_common_header
)-4; /* Type & Length fields not included */
462 /* did we capture enough for fully decoding the msg header ? */
463 if (!TTEST2(*tptr
, sizeof(struct ldp_msg_header
)))
466 ldp_msg_header
= (const struct ldp_msg_header
*)tptr
;
467 msg_len
=EXTRACT_16BITS(ldp_msg_header
->length
);
468 msg_type
=LDP_MASK_MSG_TYPE(EXTRACT_16BITS(ldp_msg_header
->type
));
470 /* FIXME vendor private / experimental check */
471 printf("\n\t %s Message (0x%04x), length: %u, Message ID: 0x%08x, Flags: [%s if unknown]",
472 tok2str(ldp_msg_values
,
477 EXTRACT_32BITS(&ldp_msg_header
->id
),
478 LDP_MASK_U_BIT(EXTRACT_16BITS(&ldp_msg_header
->type
)) ? "continue processing" : "ignore");
480 msg_tptr
=tptr
+sizeof(struct ldp_msg_header
);
481 msg_tlen
=msg_len
-sizeof(struct ldp_msg_header
)+4; /* Type & Length fields not included */
483 /* did we capture enough for fully decoding the message ? */
484 if (!TTEST2(*tptr
, msg_len
))
493 case LDP_MSG_KEEPALIVE
:
494 case LDP_MSG_ADDRESS
:
495 case LDP_MSG_LABEL_MAPPING
:
496 while(msg_tlen
>= 4) {
497 processed
= ldp_tlv_print(msg_tptr
);
506 * FIXME those are the defined messages that lack a decoder
507 * you are welcome to contribute code ;-)
510 case LDP_MSG_ADDRESS_WITHDRAW
:
511 case LDP_MSG_LABEL_REQUEST
:
512 case LDP_MSG_LABEL_WITHDRAW
:
513 case LDP_MSG_LABEL_RELEASE
:
514 case LDP_MSG_LABEL_ABORT_REQUEST
:
518 print_unknown_data(msg_tptr
,"\n\t ",msg_tlen
);
521 /* do we want to see an additionally hexdump ? */
522 if (vflag
> 1 || hexdump
==TRUE
)
523 print_unknown_data(tptr
+sizeof(sizeof(struct ldp_msg_header
)),"\n\t ",
531 printf("\n\t\t packet exceeded snapshot");