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-lspping.c,v 1.3 2004-06-09 05:14:42 hannes Exp $";
25 #include <tcpdump-stdinc.h>
31 #include "interface.h"
33 #include "addrtoname.h"
36 * LSPPING common header
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 Number | Must Be Zero |
42 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
43 * | Message Type | Reply mode | Return Code | Return Subcode|
44 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
46 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
48 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
49 * | TimeStamp Sent (seconds) |
50 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
51 * | TimeStamp Sent (microseconds) |
52 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
53 * | TimeStamp Received (seconds) |
54 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
55 * | TimeStamp Received (microseconds) |
56 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
63 struct lspping_common_header
{
69 u_int8_t return_subcode
;
70 u_int8_t sender_handle
[4];
71 u_int8_t seq_number
[4];
72 u_int8_t ts_sent_sec
[4];
73 u_int8_t ts_sent_usec
[4];
74 u_int8_t ts_rcvd_sec
[4];
75 u_int8_t ts_rcvd_usec
[4];
78 #define LSPPING_VERSION 1
82 static const struct tok lspping_msg_type_values
[] = {
83 { 1, "MPLS Echo Request"},
84 { 2, "MPLS Echo Reply"},
88 static const struct tok lspping_reply_mode_values
[] = {
90 { 2, "Reply via an IPv4/IPv6 UDP packet"},
91 { 3, "Reply via an IPv4/IPv6 UDP packet with Router Alert"},
92 { 4, "Reply via application level control channel"},
96 static const struct tok lspping_return_code_values
[] = {
97 { 0, "No return code or return code contained in the Error Code TLV"},
98 { 1, "Malformed echo request received"},
99 { 2, "One or more of the TLVs was not understood"},
100 { 3, "Replying router is an egress for the FEC at stack depth"},
101 { 4, "Replying router has no mapping for the FEC at stack depth"},
105 { 8, "Label switched at stack-depth"},
106 { 9, "Label switched but no MPLS forwarding at stack-depth"},
107 { 10, "Mapping for this FEC is not the given label at stack depth"},
108 { 11, "No label entry at stack-depth"},
109 { 12, "Protocol not associated with interface at FEC stack depth"},
116 * 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
117 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
119 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
125 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
128 struct lspping_tlv_header
{
133 #define LSPPING_TLV_TARGET_FEC_STACK 1
134 #define LSPPING_TLV_DOWNSTREAM_MAPPING 2
135 #define LSPPING_TLV_PAD 3
136 #define LSPPING_TLV_ERROR_CODE 4
137 #define LSPPING_TLV_VENDOR_PRIVATE 5
139 static const struct tok lspping_tlv_values
[] = {
140 { LSPPING_TLV_TARGET_FEC_STACK
, "Target FEC Stack" },
141 { LSPPING_TLV_DOWNSTREAM_MAPPING
, "Downstream Mapping" },
142 { LSPPING_TLV_PAD
, "Pad" },
143 { LSPPING_TLV_ERROR_CODE
, "Error Code" },
144 { LSPPING_TLV_VENDOR_PRIVATE
, "Vendor Enterprise Code" },
148 #define LSPPING_TLV_TARGETFEC_SUBTLV_LDP_IPV4 1
149 #define LSPPING_TLV_TARGETFEC_SUBTLV_LDP_IPV6 2
150 #define LSPPING_TLV_TARGETFEC_SUBTLV_RSVP_IPV4 3
151 #define LSPPING_TLV_TARGETFEC_SUBTLV_RSVP_IPV6 4
152 #define LSPPING_TLV_TARGETFEC_SUBTLV_L3VPN_IPV4 6
153 #define LSPPING_TLV_TARGETFEC_SUBTLV_L3VPN_IPV6 7
154 #define LSPPING_TLV_TARGETFEC_SUBTLV_L2VPN_ENDPT 8
155 #define LSPPING_TLV_TARGETFEC_SUBTLV_L2VPN_VCID 9
156 #define LSPPING_TLV_TARGETFEC_SUBTLV_BGP_IPV4 10
158 static const struct tok lspping_tlvtargetfec_subtlv_values
[] = {
159 { LSPPING_TLV_TARGETFEC_SUBTLV_LDP_IPV4
, "LDP IPv4 prefix"},
160 { LSPPING_TLV_TARGETFEC_SUBTLV_LDP_IPV6
, "LDP IPv6 prefix"},
161 { LSPPING_TLV_TARGETFEC_SUBTLV_RSVP_IPV4
, "RSVP IPv4 Session Query"},
162 { LSPPING_TLV_TARGETFEC_SUBTLV_RSVP_IPV6
, "RSVP IPv6 Session Query"},
164 { LSPPING_TLV_TARGETFEC_SUBTLV_L3VPN_IPV4
, "VPN IPv4 prefix"},
165 { LSPPING_TLV_TARGETFEC_SUBTLV_L3VPN_IPV6
, "VPN IPv6 prefix"},
166 { LSPPING_TLV_TARGETFEC_SUBTLV_L2VPN_ENDPT
, "L2 VPN endpoint"},
167 { LSPPING_TLV_TARGETFEC_SUBTLV_L2VPN_VCID
, "L2 circuit ID"},
168 { LSPPING_TLV_TARGETFEC_SUBTLV_BGP_IPV4
, "BGP labeled IPv4 prefix"},
173 lspping_print(register const u_char
*pptr
, register u_int len
) {
175 const struct lspping_common_header
*lspping_com_header
;
176 const struct lspping_tlv_header
*lspping_tlv_header
;
177 const struct lspping_tlv_header
*lspping_subtlv_header
;
178 const u_char
*tptr
,*tlv_tptr
,*subtlv_tptr
;
179 int tlen
,lspping_tlv_len
,lspping_tlv_type
,tlv_tlen
;
180 int tlv_hexdump
,subtlv_hexdump
;
181 int lspping_subtlv_len
,lspping_subtlv_type
;
184 lspping_com_header
= (const struct lspping_common_header
*)pptr
;
185 TCHECK(*lspping_com_header
);
188 * Sanity checking of the header.
190 if (EXTRACT_16BITS(&lspping_com_header
->version
[0]) != LSPPING_VERSION
) {
191 printf("LSP-PING version %u packet not supported",
192 EXTRACT_16BITS(&lspping_com_header
->version
[0]));
196 /* in non-verbose mode just lets print the basic Message Type*/
198 printf("LSP-PINGv%u, %s, seq %u, length: %u",
199 EXTRACT_16BITS(&lspping_com_header
->version
[0]),
200 tok2str(lspping_msg_type_values
, "unknown (%u)",lspping_com_header
->msg_type
),
201 EXTRACT_32BITS(lspping_com_header
->seq_number
),
206 /* ok they seem to want to know everything - lets fully decode it */
210 printf("\n\tLSP-PINGv%u, msg-type: %s (%u), reply-mode: %s (%u)",
211 EXTRACT_16BITS(&lspping_com_header
->version
[0]),
212 tok2str(lspping_msg_type_values
, "unknown",lspping_com_header
->msg_type
),
213 lspping_com_header
->msg_type
,
214 tok2str(lspping_reply_mode_values
, "unknown",lspping_com_header
->reply_mode
),
215 lspping_com_header
->reply_mode
);
218 * the following return codes require that the subcode is attached
219 * at the end of the translated token output
221 if (lspping_com_header
->return_code
== 3 ||
222 lspping_com_header
->return_code
== 4 ||
223 lspping_com_header
->return_code
== 8 ||
224 lspping_com_header
->return_code
== 10 ||
225 lspping_com_header
->return_code
== 11 ||
226 lspping_com_header
->return_code
== 12 )
227 printf("\n\t Return Code: %s %u (%u), Return Subcode: (%u)",
228 tok2str(lspping_return_code_values
, "unknown",lspping_com_header
->return_code
),
229 lspping_com_header
->return_subcode
,
230 lspping_com_header
->return_code
,
231 lspping_com_header
->return_subcode
);
233 printf("\n\t Return Code: %s (%u), Return Subcode: (%u)",
234 tok2str(lspping_return_code_values
, "unknown",lspping_com_header
->return_code
),
235 lspping_com_header
->return_code
,
236 lspping_com_header
->return_subcode
);
238 printf("\n\t Sender Handle: 0x%08x, Sequence: %u" \
239 "\n\t Sender Timestamp %u.%us, Receiver Timestamp %u.%us",
240 EXTRACT_32BITS(lspping_com_header
->sender_handle
),
241 EXTRACT_32BITS(lspping_com_header
->seq_number
),
242 EXTRACT_32BITS(lspping_com_header
->ts_sent_sec
), /* FIXME: replace with ts_print() */
243 EXTRACT_32BITS(lspping_com_header
->ts_sent_usec
),
244 EXTRACT_32BITS(lspping_com_header
->ts_rcvd_sec
), /* FIXME: replace with ts_print() */
245 EXTRACT_32BITS(lspping_com_header
->ts_rcvd_usec
));
247 tptr
+=sizeof(const struct lspping_common_header
);
248 tlen
-=sizeof(const struct lspping_common_header
);
251 /* did we capture enough for fully decoding the tlv header ? */
252 if (!TTEST2(*tptr
, sizeof(struct lspping_tlv_header
)))
255 lspping_tlv_header
= (const struct lspping_tlv_header
*)tptr
;
256 lspping_tlv_type
=EXTRACT_16BITS(lspping_tlv_header
->type
);
257 lspping_tlv_len
=EXTRACT_16BITS(lspping_tlv_header
->length
);
259 if (lspping_tlv_len
== 0)
262 if(lspping_tlv_len
% 4 || lspping_tlv_len
< 4) { /* aligned to four octet boundary */
263 printf("\n\t ERROR: TLV %u bogus size %u",lspping_tlv_type
,lspping_tlv_len
);
267 printf("\n\t %s TLV (%u), length: %u",
268 tok2str(lspping_tlv_values
,
274 tlv_tptr
=tptr
+sizeof(struct lspping_tlv_header
);
275 tlv_tlen
=lspping_tlv_len
; /* header not included -> no adjustment */
277 /* did we capture enough for fully decoding the tlv ? */
278 if (!TTEST2(*tptr
, lspping_tlv_len
))
282 switch(lspping_tlv_type
) {
283 case LSPPING_TLV_TARGET_FEC_STACK
:
284 while(tlv_tlen
>(int)sizeof(struct lspping_tlv_header
)) {
286 /* did we capture enough for fully decoding the subtlv header ? */
287 if (!TTEST2(*tptr
, sizeof(struct lspping_tlv_header
)))
289 subtlv_hexdump
=FALSE
;
291 lspping_subtlv_header
= (const struct lspping_tlv_header
*)tlv_tptr
;
292 lspping_subtlv_type
=EXTRACT_16BITS(lspping_subtlv_header
->type
);
293 lspping_subtlv_len
=EXTRACT_16BITS(lspping_subtlv_header
->length
);
294 subtlv_tptr
=tlv_tptr
+sizeof(struct lspping_tlv_header
);
296 if (lspping_subtlv_len
== 0)
299 printf("\n\t %s subTLV (%u), length: %u",
300 tok2str(lspping_tlvtargetfec_subtlv_values
,
302 lspping_subtlv_type
),
306 switch(lspping_subtlv_type
) {
308 case LSPPING_TLV_TARGETFEC_SUBTLV_LDP_IPV4
:
312 * 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
313 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
315 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
316 * | Prefix Length | Must Be Zero |
317 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
321 ipaddr_string(subtlv_tptr
),
326 case LSPPING_TLV_TARGETFEC_SUBTLV_LDP_IPV6
:
329 * 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
330 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
335 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
336 * | Prefix Length | Must Be Zero |
337 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
341 ip6addr_string(subtlv_tptr
),
346 case LSPPING_TLV_TARGETFEC_SUBTLV_BGP_IPV4
:
348 * 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
349 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
350 * | Sender identifier |
351 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
353 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
354 * | Prefix Length | Must Be Zero |
355 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
358 printf("\n\t %s/%u, sender-ID %s",
359 ipaddr_string(subtlv_tptr
+4),
361 ipaddr_string(subtlv_tptr
));
365 * FIXME those are the defined subTLVs that lack a decoder
366 * you are welcome to contribute code ;-)
369 case LSPPING_TLV_TARGETFEC_SUBTLV_RSVP_IPV4
:
370 case LSPPING_TLV_TARGETFEC_SUBTLV_RSVP_IPV6
:
371 case LSPPING_TLV_TARGETFEC_SUBTLV_L3VPN_IPV4
:
372 case LSPPING_TLV_TARGETFEC_SUBTLV_L3VPN_IPV6
:
373 case LSPPING_TLV_TARGETFEC_SUBTLV_L2VPN_ENDPT
:
374 case LSPPING_TLV_TARGETFEC_SUBTLV_L2VPN_VCID
:
377 subtlv_hexdump
=TRUE
; /* unknown subTLV just hexdump it */
380 /* do we want to see an additionally subtlv hexdump ? */
381 if (vflag
> 1 || subtlv_hexdump
==TRUE
)
382 print_unknown_data(tlv_tptr
+sizeof(struct lspping_tlv_header
), \
386 tlv_tptr
+=lspping_subtlv_len
;
387 tlv_tlen
-=lspping_subtlv_len
+sizeof(struct lspping_tlv_header
);
392 * FIXME those are the defined TLVs that lack a decoder
393 * you are welcome to contribute code ;-)
396 case LSPPING_TLV_DOWNSTREAM_MAPPING
:
397 case LSPPING_TLV_PAD
:
398 case LSPPING_TLV_ERROR_CODE
:
399 case LSPPING_TLV_VENDOR_PRIVATE
:
403 print_unknown_data(tlv_tptr
,"\n\t ",tlv_tlen
);
406 /* do we want to see an additionally tlv hexdump ? */
407 if (vflag
> 1 || tlv_hexdump
==TRUE
)
408 print_unknown_data(tptr
+sizeof(sizeof(struct lspping_tlv_header
)),"\n\t ",
411 tptr
+=lspping_tlv_len
;
412 tlen
-=lspping_tlv_len
;
416 printf("\n\t\t packet exceeded snapshot");