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)
17 static const char rcsid
[] _U_
=
18 "@(#) $Header: /tcpdump/master/tcpdump/print-ldp.c,v 1.4.2.3 2005-04-27 18:42:29 hannes Exp $";
25 #include <tcpdump-stdinc.h>
31 #include "interface.h"
33 #include "addrtoname.h"
39 * 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
40 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
41 * | Version | PDU Length |
42 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
44 * + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
46 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
50 struct ldp_common_header
{
52 u_int8_t pdu_length
[2];
54 u_int8_t label_space
[2];
63 * 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
64 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
65 * |U| Message Type | Message Length |
66 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
68 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
71 * | Mandatory Parameters |
74 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
77 * | Optional Parameters |
80 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
83 struct ldp_msg_header
{
89 #define LDP_MASK_MSG_TYPE(x) ((x)&0x7fff)
90 #define LDP_MASK_U_BIT(x) ((x)&0x8000)
92 #define LDP_MSG_NOTIF 0x0001
93 #define LDP_MSG_HELLO 0x0100
94 #define LDP_MSG_INIT 0x0200
95 #define LDP_MSG_KEEPALIVE 0x0201
96 #define LDP_MSG_ADDRESS 0x0300
97 #define LDP_MSG_ADDRESS_WITHDRAW 0x0301
98 #define LDP_MSG_LABEL_MAPPING 0x0400
99 #define LDP_MSG_LABEL_REQUEST 0x0401
100 #define LDP_MSG_LABEL_WITHDRAW 0x0402
101 #define LDP_MSG_LABEL_RELEASE 0x0403
102 #define LDP_MSG_LABEL_ABORT_REQUEST 0x0404
104 #define LDP_VENDOR_PRIVATE_MIN 0x3e00
105 #define LDP_VENDOR_PRIVATE_MAX 0x3eff
106 #define LDP_EXPERIMENTAL_MIN 0x3f00
107 #define LDP_EXPERIMENTAL_MAX 0x3fff
109 static const struct tok ldp_msg_values
[] = {
110 { LDP_MSG_NOTIF
, "Notification" },
111 { LDP_MSG_HELLO
, "Hello" },
112 { LDP_MSG_INIT
, "Initialization" },
113 { LDP_MSG_KEEPALIVE
, "Keepalive" },
114 { LDP_MSG_ADDRESS
, "Address" },
115 { LDP_MSG_ADDRESS_WITHDRAW
, "Address Widthdraw" },
116 { LDP_MSG_LABEL_MAPPING
, "Label Mapping" },
117 { LDP_MSG_LABEL_REQUEST
, "Label Request" },
118 { LDP_MSG_LABEL_WITHDRAW
, "Label Withdraw" },
119 { LDP_MSG_LABEL_RELEASE
, "Label Release" },
120 { LDP_MSG_LABEL_ABORT_REQUEST
, "Label Abort Request" },
124 #define LDP_MASK_TLV_TYPE(x) ((x)&0x3fff)
125 #define LDP_MASK_F_BIT(x) ((x)&0x4000)
127 #define LDP_TLV_FEC 0x0100
128 #define LDP_TLV_ADDRESS_LIST 0x0101
129 #define LDP_TLV_HOP_COUNT 0x0103
130 #define LDP_TLV_PATH_VECTOR 0x0104
131 #define LDP_TLV_GENERIC_LABEL 0x0200
132 #define LDP_TLV_ATM_LABEL 0x0201
133 #define LDP_TLV_FR_LABEL 0x0202
134 #define LDP_TLV_STATUS 0x0300
135 #define LDP_TLV_EXTD_STATUS 0x0301
136 #define LDP_TLV_RETURNED_PDU 0x0302
137 #define LDP_TLV_RETURNED_MSG 0x0303
138 #define LDP_TLV_COMMON_HELLO 0x0400
139 #define LDP_TLV_IPV4_TRANSPORT_ADDR 0x0401
140 #define LDP_TLV_CONFIG_SEQ_NUMBER 0x0402
141 #define LDP_TLV_IPV6_TRANSPORT_ADDR 0x0403
142 #define LDP_TLV_COMMON_SESSION 0x0500
143 #define LDP_TLV_ATM_SESSION_PARM 0x0501
144 #define LDP_TLV_FR_SESSION_PARM 0x0502
145 #define LDP_TLV_LABEL_REQUEST_MSG_ID 0x0600
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_LABEL_REQUEST_MSG_ID
, "Label Request Message ID" },
173 int ldp_tlv_print(register const u_char
*);
179 * 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
180 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
181 * |U|F| Type | Length |
182 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
187 * | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
189 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
193 ldp_tlv_print(register const u_char
*tptr
) {
195 struct ldp_tlv_header
{
200 const struct ldp_tlv_header
*ldp_tlv_header
;
201 u_short tlv_type
,tlv_len
,tlv_tlen
;
203 ldp_tlv_header
= (const struct ldp_tlv_header
*)tptr
;
204 tlv_len
=EXTRACT_16BITS(ldp_tlv_header
->length
);
206 tlv_type
=LDP_MASK_TLV_TYPE(EXTRACT_16BITS(ldp_tlv_header
->type
));
208 /* FIXME vendor private / experimental check */
209 printf("\n\t %s TLV (0x%04x), length: %u, Flags: [%s and %s forward if unknown]",
210 tok2str(ldp_tlv_values
,
215 LDP_MASK_U_BIT(EXTRACT_16BITS(&ldp_tlv_header
->type
)) ? "continue processing" : "ignore",
216 LDP_MASK_F_BIT(EXTRACT_16BITS(&ldp_tlv_header
->type
)) ? "do" : "don't");
218 tptr
+=sizeof(struct ldp_tlv_header
);
222 case LDP_TLV_COMMON_HELLO
:
223 printf("\n\t Hold Time: %us, Flags: [%s Hello%s]",
224 EXTRACT_16BITS(tptr
),
225 (EXTRACT_16BITS(tptr
+2)&0x8000) ? "Targeted" : "Link",
226 (EXTRACT_16BITS(tptr
+2)&0x4000) ? ", Request for targeted Hellos" : "");
229 case LDP_TLV_IPV4_TRANSPORT_ADDR
:
230 printf("\n\t IPv4 Transport Address: %s", ipaddr_string(tptr
));
233 case LDP_TLV_IPV6_TRANSPORT_ADDR
:
234 printf("\n\t IPv6 Transport Address: %s", ip6addr_string(tptr
));
237 case LDP_TLV_CONFIG_SEQ_NUMBER
:
238 printf("\n\t Sequence Number: %u", EXTRACT_32BITS(tptr
));
242 * FIXME those are the defined TLVs that lack a decoder
243 * you are welcome to contribute code ;-)
247 case LDP_TLV_ADDRESS_LIST
:
248 case LDP_TLV_HOP_COUNT
:
249 case LDP_TLV_PATH_VECTOR
:
250 case LDP_TLV_GENERIC_LABEL
:
251 case LDP_TLV_ATM_LABEL
:
252 case LDP_TLV_FR_LABEL
:
254 case LDP_TLV_EXTD_STATUS
:
255 case LDP_TLV_RETURNED_PDU
:
256 case LDP_TLV_RETURNED_MSG
:
257 case LDP_TLV_COMMON_SESSION
:
258 case LDP_TLV_ATM_SESSION_PARM
:
259 case LDP_TLV_FR_SESSION_PARM
:
260 case LDP_TLV_LABEL_REQUEST_MSG_ID
:
264 print_unknown_data(tptr
,"\n\t ",tlv_tlen
);
267 return(tlv_len
+4); /* Type & Length fields not included */
271 ldp_print(register const u_char
*pptr
, register u_int len
) {
273 const struct ldp_common_header
*ldp_com_header
;
274 const struct ldp_msg_header
*ldp_msg_header
;
275 const u_char
*tptr
,*msg_tptr
;
277 u_short msg_len
,msg_type
,msg_tlen
;
278 int hexdump
,processed
;
281 ldp_com_header
= (const struct ldp_common_header
*)pptr
;
282 TCHECK(*ldp_com_header
);
285 * Sanity checking of the header.
287 if (EXTRACT_16BITS(&ldp_com_header
->version
) != LDP_VERSION
) {
288 printf("LDP version %u packet not supported",
289 EXTRACT_16BITS(&ldp_com_header
->version
));
293 /* print the LSR-ID, label-space & length */
294 printf("%sLDP, Label-Space-ID: %s:%u, length: %u",
295 (vflag
< 1) ? "" : "\n\t",
296 ipaddr_string(&ldp_com_header
->lsr_id
),
297 EXTRACT_16BITS(&ldp_com_header
->label_space
),
300 /* bail out if non-verbose */
304 /* ok they seem to want to know everything - lets fully decode it */
305 tlen
=EXTRACT_16BITS(ldp_com_header
->pdu_length
);
307 tptr
+=sizeof(const struct ldp_common_header
);
308 tlen
-=sizeof(const struct ldp_common_header
);
311 /* did we capture enough for fully decoding the msg header ? */
312 if (!TTEST2(*tptr
, sizeof(struct ldp_msg_header
)))
315 ldp_msg_header
= (const struct ldp_msg_header
*)tptr
;
316 msg_len
=EXTRACT_16BITS(ldp_msg_header
->length
);
317 msg_type
=LDP_MASK_MSG_TYPE(EXTRACT_16BITS(ldp_msg_header
->type
));
319 /* FIXME vendor private / experimental check */
320 printf("\n\t %s Message (0x%04x), length: %u, Message ID: 0x%08x, Flags: [%s if unknown]",
321 tok2str(ldp_msg_values
,
326 EXTRACT_32BITS(&ldp_msg_header
->id
),
327 LDP_MASK_U_BIT(EXTRACT_16BITS(&ldp_msg_header
->type
)) ? "continue processing" : "ignore");
329 if (msg_len
== 0) /* infinite loop protection */
332 msg_tptr
=tptr
+sizeof(struct ldp_msg_header
);
333 msg_tlen
=msg_len
-sizeof(struct ldp_msg_header
)+4; /* Type & Length fields not included */
335 /* did we capture enough for fully decoding the message ? */
336 if (!TTEST2(*tptr
, msg_len
))
343 while(msg_tlen
>= 4) {
344 processed
= ldp_tlv_print(msg_tptr
);
353 * FIXME those are the defined messages that lack a decoder
354 * you are welcome to contribute code ;-)
359 case LDP_MSG_KEEPALIVE
:
360 case LDP_MSG_ADDRESS
:
361 case LDP_MSG_ADDRESS_WITHDRAW
:
362 case LDP_MSG_LABEL_MAPPING
:
363 case LDP_MSG_LABEL_REQUEST
:
364 case LDP_MSG_LABEL_WITHDRAW
:
365 case LDP_MSG_LABEL_RELEASE
:
366 case LDP_MSG_LABEL_ABORT_REQUEST
:
370 print_unknown_data(msg_tptr
,"\n\t ",msg_tlen
);
373 /* do we want to see an additionally hexdump ? */
374 if (vflag
> 1 || hexdump
==TRUE
)
375 print_unknown_data(tptr
+sizeof(sizeof(struct ldp_msg_header
)),"\n\t ",
383 printf("\n\t\t packet exceeded snapshot");