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.1 2004-06-06 19:20:03 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"},
99 * 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
100 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
102 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
108 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
111 struct lspping_tlv_header
{
116 #define LSPPING_TLV_TARGET_FEC_STACK 1
117 #define LSPPING_TLV_DOWNSTREAM_MAPPING 2
118 #define LSPPING_TLV_PAD 3
119 #define LSPPING_TLV_ERROR_CODE 4
120 #define LSPPING_TLV_VENDOR_PRIVATE 5
122 static const struct tok lspping_tlv_values
[] = {
123 { LSPPING_TLV_TARGET_FEC_STACK
, "Target FEC Stack" },
124 { LSPPING_TLV_DOWNSTREAM_MAPPING
, "Downstream Mapping" },
125 { LSPPING_TLV_PAD
, "Pad" },
126 { LSPPING_TLV_ERROR_CODE
, "Error Code" },
127 { LSPPING_TLV_VENDOR_PRIVATE
, "Vendor Enterprise Code" },
132 lspping_print(register const u_char
*pptr
, register u_int len
) {
134 const struct lspping_common_header
*lspping_com_header
;
135 const struct lspping_tlv_header
*lspping_tlv_header
;
136 const u_char
*tptr
,*tlv_tptr
;
137 int tlen
,lspping_tlv_len
,lspping_tlv_type
,tlv_tlen
;
141 lspping_com_header
= (const struct lspping_common_header
*)pptr
;
142 TCHECK(*lspping_com_header
);
145 * Sanity checking of the header.
147 if (EXTRACT_16BITS(&lspping_com_header
->version
[0]) != LSPPING_VERSION
) {
148 printf("LSP-PING version %u packet not supported",
149 EXTRACT_16BITS(&lspping_com_header
->version
[0]));
153 /* in non-verbose mode just lets print the basic Message Type*/
155 printf("LSP-PINGv%u, %s, seq %u, length: %u",
156 EXTRACT_16BITS(&lspping_com_header
->version
[0]),
157 tok2str(lspping_msg_type_values
, "unknown (%u)",lspping_com_header
->msg_type
),
158 EXTRACT_32BITS(lspping_com_header
->seq_number
),
163 /* ok they seem to want to know everything - lets fully decode it */
167 printf("\n\tLSP-PINGv%u, msg-type: %s (%u), reply-mode: %s (%u)" \
168 "\n\t Return Code: (%u), Return Subcode: (%u)" \
169 "\n\t Sender Handle: 0x%08x, Sequence: %u" \
170 "\n\t Sender Timestamp %u.%us, Receiver Timestamp %u.%us",
171 EXTRACT_16BITS(&lspping_com_header
->version
[0]),
172 tok2str(lspping_msg_type_values
, "unknown",lspping_com_header
->msg_type
),
173 lspping_com_header
->msg_type
,
174 tok2str(lspping_reply_mode_values
, "unknown",lspping_com_header
->reply_mode
),
175 lspping_com_header
->reply_mode
,
176 lspping_com_header
->return_code
,
177 lspping_com_header
->return_subcode
,
178 EXTRACT_32BITS(lspping_com_header
->sender_handle
),
179 EXTRACT_32BITS(lspping_com_header
->seq_number
),
180 EXTRACT_32BITS(lspping_com_header
->ts_sent_sec
),
181 EXTRACT_32BITS(lspping_com_header
->ts_sent_usec
),
182 EXTRACT_32BITS(lspping_com_header
->ts_rcvd_sec
),
183 EXTRACT_32BITS(lspping_com_header
->ts_rcvd_usec
));
185 tptr
+=sizeof(const struct lspping_common_header
);
186 tlen
-=sizeof(const struct lspping_common_header
);
189 /* did we capture enough for fully decoding the tlv header ? */
190 if (!TTEST2(*tptr
, sizeof(struct lspping_tlv_header
)))
193 lspping_tlv_header
= (const struct lspping_tlv_header
*)tptr
;
194 lspping_tlv_type
=EXTRACT_16BITS(lspping_tlv_header
->type
);
195 lspping_tlv_len
=EXTRACT_16BITS(lspping_tlv_header
->length
);
197 if(lspping_tlv_len
% 4 || lspping_tlv_len
< 4)
200 printf("\n\t %s TLV (%u), length: %u",
201 tok2str(lspping_tlv_values
,
207 tlv_tptr
=tptr
+sizeof(struct lspping_tlv_header
);
208 tlv_tlen
=lspping_tlv_len
-sizeof(struct lspping_tlv_header
);
210 /* did we capture enough for fully decoding the tlv ? */
211 if (!TTEST2(*tptr
, lspping_tlv_len
))
215 switch(lspping_tlv_type
) {
218 * FIXME those are the defined messages that lack a decoder
219 * you are welcome to contribute code ;-)
222 case LSPPING_TLV_TARGET_FEC_STACK
:
223 case LSPPING_TLV_DOWNSTREAM_MAPPING
:
224 case LSPPING_TLV_PAD
:
225 case LSPPING_TLV_ERROR_CODE
:
226 case LSPPING_TLV_VENDOR_PRIVATE
:
230 print_unknown_data(tlv_tptr
,"\n\t ",tlv_tlen
);
233 /* do we want to see an additionally hexdump ? */
234 if (vflag
> 1 || hexdump
==TRUE
)
235 print_unknown_data(tptr
+sizeof(sizeof(struct lspping_tlv_header
)),"\n\t ",
236 lspping_tlv_len
-sizeof(struct lspping_tlv_header
));
238 tptr
+=lspping_tlv_len
;
239 tlen
-=lspping_tlv_len
;
243 printf("\n\t\t packet exceeded snapshot");