]> The Tcpdump Group git mirrors - tcpdump/blob - print-lspping.c
4bd27afc77f48940f0dc01a299aa82c04aaf0b39
[tcpdump] / print-lspping.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@juniper.net)
14 */
15
16 #ifndef lint
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 $";
19 #endif
20
21 #ifdef HAVE_CONFIG_H
22 #include "config.h"
23 #endif
24
25 #include <tcpdump-stdinc.h>
26
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <string.h>
30
31 #include "interface.h"
32 #include "extract.h"
33 #include "addrtoname.h"
34
35 /*
36 * LSPPING common header
37 *
38 * 0 1 2 3
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 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
45 * | Sender's Handle |
46 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
47 * | Sequence Number |
48 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
49 * | TimeStamp Sent (seconds) |
50 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
51 * | TimeStamp Sent (microseconds) |
52 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
53 * | TimeStamp Received (seconds) |
54 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
55 * | TimeStamp Received (microseconds) |
56 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
57 * | TLVs ... |
58 * . .
59 * . .
60 * . .
61 */
62
63 struct lspping_common_header {
64 u_int8_t version[2];
65 u_int8_t reserved[2];
66 u_int8_t msg_type;
67 u_int8_t reply_mode;
68 u_int8_t return_code;
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];
76 };
77
78 #define LSPPING_VERSION 1
79 #define FALSE 0
80 #define TRUE 1
81
82 static const struct tok lspping_msg_type_values[] = {
83 { 1, "MPLS Echo Request"},
84 { 2, "MPLS Echo Reply"},
85 { 0, NULL}
86 };
87
88 static const struct tok lspping_reply_mode_values[] = {
89 { 1, "Do not reply"},
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"},
93 { 0, NULL}
94 };
95
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"},
102 { 5, "Reserved"},
103 { 6, "Reserved"},
104 { 7, "Reserved"},
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"},
110 };
111
112
113 /*
114 * LSPPING TLV header
115 * 0 1 2 3
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 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
118 * | Type | Length |
119 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
120 * | Value |
121 * . .
122 * . .
123 * . .
124 * | |
125 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
126 */
127
128 struct lspping_tlv_header {
129 u_int8_t type[2];
130 u_int8_t length[2];
131 };
132
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
138
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" },
145 { 0, NULL}
146 };
147
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
157
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"},
163 { 5, "Reserved"},
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"},
169 { 0, NULL}
170 };
171
172 void
173 lspping_print(register const u_char *pptr, register u_int len) {
174
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;
182
183 tptr=pptr;
184 lspping_com_header = (const struct lspping_common_header *)pptr;
185 TCHECK(*lspping_com_header);
186
187 /*
188 * Sanity checking of the header.
189 */
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]));
193 return;
194 }
195
196 /* in non-verbose mode just lets print the basic Message Type*/
197 if (vflag < 1) {
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),
202 len);
203 return;
204 }
205
206 /* ok they seem to want to know everything - lets fully decode it */
207
208 tlen=len;
209
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);
216
217 /*
218 * the following return codes require that the subcode is attached
219 * at the end of the translated token output
220 */
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);
232 else
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);
237
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));
246
247 tptr+=sizeof(const struct lspping_common_header);
248 tlen-=sizeof(const struct lspping_common_header);
249
250 while(tlen>0) {
251 /* did we capture enough for fully decoding the tlv header ? */
252 if (!TTEST2(*tptr, sizeof(struct lspping_tlv_header)))
253 goto trunc;
254
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);
258
259 if (lspping_tlv_len == 0)
260 return;
261
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);
264 return;
265 }
266
267 printf("\n\t %s TLV (%u), length: %u",
268 tok2str(lspping_tlv_values,
269 "Unknown",
270 lspping_tlv_type),
271 lspping_tlv_type,
272 lspping_tlv_len);
273
274 tlv_tptr=tptr+sizeof(struct lspping_tlv_header);
275 tlv_tlen=lspping_tlv_len; /* header not included -> no adjustment */
276
277 /* did we capture enough for fully decoding the tlv ? */
278 if (!TTEST2(*tptr, lspping_tlv_len))
279 goto trunc;
280 tlv_hexdump=FALSE;
281
282 switch(lspping_tlv_type) {
283 case LSPPING_TLV_TARGET_FEC_STACK:
284 while(tlv_tlen>(int)sizeof(struct lspping_tlv_header)) {
285
286 /* did we capture enough for fully decoding the subtlv header ? */
287 if (!TTEST2(*tptr, sizeof(struct lspping_tlv_header)))
288 goto trunc;
289 subtlv_hexdump=FALSE;
290
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);
295
296 if (lspping_subtlv_len == 0)
297 break;
298
299 printf("\n\t %s subTLV (%u), length: %u",
300 tok2str(lspping_tlvtargetfec_subtlv_values,
301 "Unknown",
302 lspping_subtlv_type),
303 lspping_subtlv_type,
304 lspping_subtlv_len);
305
306 switch(lspping_subtlv_type) {
307
308 case LSPPING_TLV_TARGETFEC_SUBTLV_LDP_IPV4:
309
310 /*
311 * 0 1 2 3
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 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
314 * | IPv4 prefix |
315 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
316 * | Prefix Length | Must Be Zero |
317 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
318 */
319
320 printf("\n\t %s/%u",
321 ipaddr_string(subtlv_tptr),
322 *(subtlv_tptr+4));
323 break;
324
325 #ifdef INET6
326 case LSPPING_TLV_TARGETFEC_SUBTLV_LDP_IPV6:
327 /*
328 * 0 1 2 3
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 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
331 * | IPv6 prefix |
332 * | (16 octets) |
333 * | |
334 * | |
335 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
336 * | Prefix Length | Must Be Zero |
337 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
338 */
339
340 printf("\n\t %s/%u",
341 ip6addr_string(subtlv_tptr),
342 *(subtlv_tptr+16));
343 break;
344 #endif
345
346 case LSPPING_TLV_TARGETFEC_SUBTLV_BGP_IPV4:
347 /*
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 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
352 * | IPv4 prefix |
353 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
354 * | Prefix Length | Must Be Zero |
355 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
356 */
357
358 printf("\n\t %s/%u, sender-ID %s",
359 ipaddr_string(subtlv_tptr+4),
360 *(subtlv_tptr+8),
361 ipaddr_string(subtlv_tptr));
362 break;
363
364 /*
365 * FIXME those are the defined subTLVs that lack a decoder
366 * you are welcome to contribute code ;-)
367 */
368
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:
375
376 default:
377 subtlv_hexdump=TRUE; /* unknown subTLV just hexdump it */
378 break;
379 }
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), \
383 "\n\t ",
384 lspping_subtlv_len);
385
386 tlv_tptr+=lspping_subtlv_len;
387 tlv_tlen-=lspping_subtlv_len+sizeof(struct lspping_tlv_header);
388 }
389 break;
390
391 /*
392 * FIXME those are the defined TLVs that lack a decoder
393 * you are welcome to contribute code ;-)
394 */
395
396 case LSPPING_TLV_DOWNSTREAM_MAPPING:
397 case LSPPING_TLV_PAD:
398 case LSPPING_TLV_ERROR_CODE:
399 case LSPPING_TLV_VENDOR_PRIVATE:
400
401 default:
402 if (vflag <= 1)
403 print_unknown_data(tlv_tptr,"\n\t ",tlv_tlen);
404 break;
405 }
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 ",
409 lspping_tlv_len);
410
411 tptr+=lspping_tlv_len;
412 tlen-=lspping_tlv_len;
413 }
414 return;
415 trunc:
416 printf("\n\t\t packet exceeded snapshot");
417 }