]> The Tcpdump Group git mirrors - tcpdump/blob - print-lspping.c
50e28f2b8ca0468d1391cad76f8ffb0a71db3bce
[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.7 2004-06-15 08:17:19 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 #include "bgp.h"
35
36 /*
37 * LSPPING common header
38 *
39 * 0 1 2 3
40 * 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
41 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
42 * | Version Number | Must Be Zero |
43 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
44 * | Message Type | Reply mode | Return Code | Return Subcode|
45 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
46 * | Sender's Handle |
47 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
48 * | Sequence Number |
49 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
50 * | TimeStamp Sent (seconds) |
51 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
52 * | TimeStamp Sent (microseconds) |
53 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
54 * | TimeStamp Received (seconds) |
55 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
56 * | TimeStamp Received (microseconds) |
57 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
58 * | TLVs ... |
59 * . .
60 * . .
61 * . .
62 */
63
64 struct lspping_common_header {
65 u_int8_t version[2];
66 u_int8_t reserved[2];
67 u_int8_t msg_type;
68 u_int8_t reply_mode;
69 u_int8_t return_code;
70 u_int8_t return_subcode;
71 u_int8_t sender_handle[4];
72 u_int8_t seq_number[4];
73 u_int8_t ts_sent_sec[4];
74 u_int8_t ts_sent_usec[4];
75 u_int8_t ts_rcvd_sec[4];
76 u_int8_t ts_rcvd_usec[4];
77 };
78
79 #define LSPPING_VERSION 1
80 #define FALSE 0
81 #define TRUE 1
82
83 static const struct tok lspping_msg_type_values[] = {
84 { 1, "MPLS Echo Request"},
85 { 2, "MPLS Echo Reply"},
86 { 0, NULL}
87 };
88
89 static const struct tok lspping_reply_mode_values[] = {
90 { 1, "Do not reply"},
91 { 2, "Reply via an IPv4/IPv6 UDP packet"},
92 { 3, "Reply via an IPv4/IPv6 UDP packet with Router Alert"},
93 { 4, "Reply via application level control channel"},
94 { 0, NULL}
95 };
96
97 static const struct tok lspping_return_code_values[] = {
98 { 0, "No return code or return code contained in the Error Code TLV"},
99 { 1, "Malformed echo request received"},
100 { 2, "One or more of the TLVs was not understood"},
101 { 3, "Replying router is an egress for the FEC at stack depth"},
102 { 4, "Replying router has no mapping for the FEC at stack depth"},
103 { 5, "Reserved"},
104 { 6, "Reserved"},
105 { 7, "Reserved"},
106 { 8, "Label switched at stack-depth"},
107 { 9, "Label switched but no MPLS forwarding at stack-depth"},
108 { 10, "Mapping for this FEC is not the given label at stack depth"},
109 { 11, "No label entry at stack-depth"},
110 { 12, "Protocol not associated with interface at FEC stack depth"},
111 };
112
113
114 /*
115 * LSPPING TLV header
116 * 0 1 2 3
117 * 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
118 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
119 * | Type | Length |
120 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
121 * | Value |
122 * . .
123 * . .
124 * . .
125 * | |
126 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
127 */
128
129 struct lspping_tlv_header {
130 u_int8_t type[2];
131 u_int8_t length[2];
132 };
133
134 #define LSPPING_TLV_TARGET_FEC_STACK 1
135 #define LSPPING_TLV_DOWNSTREAM_MAPPING 2
136 #define LSPPING_TLV_PAD 3
137 #define LSPPING_TLV_ERROR_CODE 4
138 #define LSPPING_TLV_VENDOR_PRIVATE 5
139
140 static const struct tok lspping_tlv_values[] = {
141 { LSPPING_TLV_TARGET_FEC_STACK, "Target FEC Stack" },
142 { LSPPING_TLV_DOWNSTREAM_MAPPING, "Downstream Mapping" },
143 { LSPPING_TLV_PAD, "Pad" },
144 { LSPPING_TLV_ERROR_CODE, "Error Code" },
145 { LSPPING_TLV_VENDOR_PRIVATE, "Vendor Enterprise Code" },
146 { 0, NULL}
147 };
148
149 #define LSPPING_TLV_TARGETFEC_SUBTLV_LDP_IPV4 1
150 #define LSPPING_TLV_TARGETFEC_SUBTLV_LDP_IPV6 2
151 #define LSPPING_TLV_TARGETFEC_SUBTLV_RSVP_IPV4 3
152 #define LSPPING_TLV_TARGETFEC_SUBTLV_RSVP_IPV6 4
153 #define LSPPING_TLV_TARGETFEC_SUBTLV_L3VPN_IPV4 6
154 #define LSPPING_TLV_TARGETFEC_SUBTLV_L3VPN_IPV6 7
155 #define LSPPING_TLV_TARGETFEC_SUBTLV_L2VPN_ENDPT 8
156 #define LSPPING_TLV_TARGETFEC_SUBTLV_L2VPN_VCID 9
157 #define LSPPING_TLV_TARGETFEC_SUBTLV_BGP_IPV4 10
158 #define LSPPING_TLV_TARGETFEC_SUBTLV_BGP_IPV6 11
159
160 static const struct tok lspping_tlvtargetfec_subtlv_values[] = {
161 { LSPPING_TLV_TARGETFEC_SUBTLV_LDP_IPV4, "LDP IPv4 prefix"},
162 { LSPPING_TLV_TARGETFEC_SUBTLV_LDP_IPV6, "LDP IPv6 prefix"},
163 { LSPPING_TLV_TARGETFEC_SUBTLV_RSVP_IPV4, "RSVP IPv4 Session Query"},
164 { LSPPING_TLV_TARGETFEC_SUBTLV_RSVP_IPV6, "RSVP IPv6 Session Query"},
165 { 5, "Reserved"},
166 { LSPPING_TLV_TARGETFEC_SUBTLV_L3VPN_IPV4, "VPN IPv4 prefix"},
167 { LSPPING_TLV_TARGETFEC_SUBTLV_L3VPN_IPV6, "VPN IPv6 prefix"},
168 { LSPPING_TLV_TARGETFEC_SUBTLV_L2VPN_ENDPT, "L2 VPN endpoint"},
169 { LSPPING_TLV_TARGETFEC_SUBTLV_L2VPN_VCID, "L2 circuit ID"},
170 { LSPPING_TLV_TARGETFEC_SUBTLV_BGP_IPV4, "BGP labeled IPv4 prefix"},
171 { LSPPING_TLV_TARGETFEC_SUBTLV_BGP_IPV6, "BGP labeled IPv6 prefix"},
172 { 0, NULL}
173 };
174
175 /*
176 * 0 1 2 3
177 * 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
178 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
179 * | IPv4 prefix |
180 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
181 * | Prefix Length | Must Be Zero |
182 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
183 */
184 struct lspping_tlv_targetfec_subtlv_ldp_ipv4_t {
185 u_int8_t prefix [4];
186 u_int8_t prefix_len;
187 };
188
189 /*
190 * 0 1 2 3
191 * 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
192 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
193 * | IPv6 prefix |
194 * | (16 octets) |
195 * | |
196 * | |
197 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
198 * | Prefix Length | Must Be Zero |
199 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
200 */
201 struct lspping_tlv_targetfec_subtlv_ldp_ipv6_t {
202 u_int8_t prefix [16];
203 u_int8_t prefix_len;
204 };
205
206 /*
207 * 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
208 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
209 * | Sender identifier |
210 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
211 * | IPv4 prefix |
212 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
213 * | Prefix Length | Must Be Zero |
214 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
215 */
216 struct lspping_tlv_targetfec_subtlv_bgp_ipv4_t {
217 u_int8_t sender_id [4];
218 u_int8_t prefix [4];
219 u_int8_t prefix_len;
220 };
221
222 /*
223 * 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
224 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
225 * | Sender identifier |
226 * | (16 octets) |
227 * | |
228 * | |
229 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
230 * | IPv6 prefix |
231 * | (16 octets) |
232 * | |
233 * | |
234 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
235 * | Prefix Length | Must Be Zero |
236 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
237 */
238 struct lspping_tlv_targetfec_subtlv_bgp_ipv6_t {
239 u_int8_t sender_id [16];
240 u_int8_t prefix [16];
241 u_int8_t prefix_len;
242 };
243
244 /*
245 * 0 1 2 3
246 * 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
247 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
248 * | IPv4 tunnel end point address |
249 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
250 * | Must Be Zero | Tunnel ID |
251 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
252 * | Extended Tunnel ID |
253 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
254 * | IPv4 tunnel sender address |
255 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
256 * | Must Be Zero | LSP ID |
257 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
258 */
259 struct lspping_tlv_targetfec_subtlv_rsvp_ipv4_t {
260 u_int8_t tunnel_endpoint [4];
261 u_int8_t res[2];
262 u_int8_t tunnel_id[2];
263 u_int8_t extended_tunnel_id[4];
264 u_int8_t tunnel_sender [4];
265 u_int8_t res2[2];
266 u_int8_t lsp_id [2];
267 };
268
269 /*
270 * 0 1 2 3
271 * 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
272 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
273 * | IPv6 tunnel end point address |
274 * | |
275 * | |
276 * | |
277 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
278 * | Must Be Zero | Tunnel ID |
279 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
280 * | Extended Tunnel ID |
281 * | |
282 * | |
283 * | |
284 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
285 * | IPv6 tunnel sender address |
286 * | |
287 * | |
288 * | |
289 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
290 * | Must Be Zero | LSP ID |
291 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
292 */
293 struct lspping_tlv_targetfec_subtlv_rsvp_ipv6_t {
294 u_int8_t tunnel_endpoint [16];
295 u_int8_t res[2];
296 u_int8_t tunnel_id[2];
297 u_int8_t extended_tunnel_id[16];
298 u_int8_t tunnel_sender [16];
299 u_int8_t res2[2];
300 u_int8_t lsp_id [2];
301 };
302
303 /*
304 * 0 1 2 3
305 * 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
306 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
307 * | Route Distinguisher |
308 * | (8 octets) |
309 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
310 * | IPv4 prefix |
311 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
312 * | Prefix Length | Must Be Zero |
313 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
314 */
315 struct lspping_tlv_targetfec_subtlv_l3vpn_ipv4_t {
316 u_int8_t rd [8];
317 u_int8_t prefix [4];
318 u_int8_t prefix_len;
319 };
320
321 /*
322 * 0 1 2 3
323 * 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
324 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
325 * | Route Distinguisher |
326 * | (8 octets) |
327 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
328 * | IPv6 prefix |
329 * | (16 octets) |
330 * | |
331 * | |
332 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
333 * | Prefix Length | Must Be Zero |
334 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
335 */
336 struct lspping_tlv_targetfec_subtlv_l3vpn_ipv6_t {
337 u_int8_t rd [8];
338 u_int8_t prefix [16];
339 u_int8_t prefix_len;
340 };
341
342 /*
343 * 0 1 2 3
344 * 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
345 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
346 * | Route Distinguisher |
347 * | (8 octets) |
348 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
349 * | Sender's CE ID | Receiver's CE ID |
350 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
351 * | Encapsulation Type | Must Be Zero |
352 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
353 * 0 1 2 3
354 */
355 struct lspping_tlv_targetfec_subtlv_l2vpn_endpt_t {
356 u_int8_t rd [8];
357 u_int8_t sender_ce_id [2];
358 u_int8_t receiver_ce_id [2];
359 u_int8_t encapsulation[2];
360 };
361
362 /*
363 * 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
364 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
365 * | Sender's PE Address |
366 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
367 * | Remote PE Address |
368 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
369 * | VC ID |
370 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
371 * | Encapsulation Type | Must Be Zero |
372 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
373 */
374 struct lspping_tlv_targetfec_subtlv_l2vpn_vcid_t {
375 u_int8_t sender_pe_address [4];
376 u_int8_t remote_pe_address [4];
377 u_int8_t vc_id [4];
378 u_int8_t encapsulation[2];
379 };
380
381 void
382 lspping_print(register const u_char *pptr, register u_int len) {
383
384 const struct lspping_common_header *lspping_com_header;
385 const struct lspping_tlv_header *lspping_tlv_header;
386 const struct lspping_tlv_header *lspping_subtlv_header;
387 const u_char *tptr,*tlv_tptr,*subtlv_tptr;
388 int tlen,lspping_tlv_len,lspping_tlv_type,tlv_tlen;
389 int tlv_hexdump,subtlv_hexdump;
390 int lspping_subtlv_len,lspping_subtlv_type;
391
392 union {
393 const struct lspping_tlv_targetfec_subtlv_ldp_ipv4_t *lspping_tlv_targetfec_subtlv_ldp_ipv4;
394 const struct lspping_tlv_targetfec_subtlv_ldp_ipv6_t *lspping_tlv_targetfec_subtlv_ldp_ipv6;
395 const struct lspping_tlv_targetfec_subtlv_rsvp_ipv4_t *lspping_tlv_targetfec_subtlv_rsvp_ipv4;
396 const struct lspping_tlv_targetfec_subtlv_rsvp_ipv6_t *lspping_tlv_targetfec_subtlv_rsvp_ipv6;
397 const struct lspping_tlv_targetfec_subtlv_l3vpn_ipv4_t *lspping_tlv_targetfec_subtlv_l3vpn_ipv4;
398 const struct lspping_tlv_targetfec_subtlv_l3vpn_ipv6_t *lspping_tlv_targetfec_subtlv_l3vpn_ipv6;
399 const struct lspping_tlv_targetfec_subtlv_l2vpn_endpt_t *lspping_tlv_targetfec_subtlv_l2vpn_endpt;
400 const struct lspping_tlv_targetfec_subtlv_l2vpn_vcid_t *lspping_tlv_targetfec_subtlv_l2vpn_vcid;
401 const struct lspping_tlv_targetfec_subtlv_bgp_ipv4_t *lspping_tlv_targetfec_subtlv_bgp_ipv4;
402 const struct lspping_tlv_targetfec_subtlv_bgp_ipv6_t *lspping_tlv_targetfec_subtlv_bgp_ipv6;
403 } subtlv_ptr;
404
405 tptr=pptr;
406 lspping_com_header = (const struct lspping_common_header *)pptr;
407 TCHECK(*lspping_com_header);
408
409 /*
410 * Sanity checking of the header.
411 */
412 if (EXTRACT_16BITS(&lspping_com_header->version[0]) != LSPPING_VERSION) {
413 printf("LSP-PING version %u packet not supported",
414 EXTRACT_16BITS(&lspping_com_header->version[0]));
415 return;
416 }
417
418 /* in non-verbose mode just lets print the basic Message Type*/
419 if (vflag < 1) {
420 printf("LSP-PINGv%u, %s, seq %u, length: %u",
421 EXTRACT_16BITS(&lspping_com_header->version[0]),
422 tok2str(lspping_msg_type_values, "unknown (%u)",lspping_com_header->msg_type),
423 EXTRACT_32BITS(lspping_com_header->seq_number),
424 len);
425 return;
426 }
427
428 /* ok they seem to want to know everything - lets fully decode it */
429
430 tlen=len;
431
432 printf("\n\tLSP-PINGv%u, msg-type: %s (%u), reply-mode: %s (%u)",
433 EXTRACT_16BITS(&lspping_com_header->version[0]),
434 tok2str(lspping_msg_type_values, "unknown",lspping_com_header->msg_type),
435 lspping_com_header->msg_type,
436 tok2str(lspping_reply_mode_values, "unknown",lspping_com_header->reply_mode),
437 lspping_com_header->reply_mode);
438
439 /*
440 * the following return codes require that the subcode is attached
441 * at the end of the translated token output
442 */
443 if (lspping_com_header->return_code == 3 ||
444 lspping_com_header->return_code == 4 ||
445 lspping_com_header->return_code == 8 ||
446 lspping_com_header->return_code == 10 ||
447 lspping_com_header->return_code == 11 ||
448 lspping_com_header->return_code == 12 )
449 printf("\n\t Return Code: %s %u (%u), Return Subcode: (%u)",
450 tok2str(lspping_return_code_values, "unknown",lspping_com_header->return_code),
451 lspping_com_header->return_subcode,
452 lspping_com_header->return_code,
453 lspping_com_header->return_subcode);
454 else
455 printf("\n\t Return Code: %s (%u), Return Subcode: (%u)",
456 tok2str(lspping_return_code_values, "unknown",lspping_com_header->return_code),
457 lspping_com_header->return_code,
458 lspping_com_header->return_subcode);
459
460 printf("\n\t Sender Handle: 0x%08x, Sequence: %u" \
461 "\n\t Sender Timestamp %u.%us, Receiver Timestamp %u.%us",
462 EXTRACT_32BITS(lspping_com_header->sender_handle),
463 EXTRACT_32BITS(lspping_com_header->seq_number),
464 EXTRACT_32BITS(lspping_com_header->ts_sent_sec), /* FIXME: replace with ts_print() */
465 EXTRACT_32BITS(lspping_com_header->ts_sent_usec),
466 EXTRACT_32BITS(lspping_com_header->ts_rcvd_sec), /* FIXME: replace with ts_print() */
467 EXTRACT_32BITS(lspping_com_header->ts_rcvd_usec));
468
469 tptr+=sizeof(const struct lspping_common_header);
470 tlen-=sizeof(const struct lspping_common_header);
471
472 while(tlen>(int)sizeof(struct lspping_tlv_header)) {
473 /* did we capture enough for fully decoding the tlv header ? */
474 if (!TTEST2(*tptr, sizeof(struct lspping_tlv_header)))
475 goto trunc;
476
477 lspping_tlv_header = (const struct lspping_tlv_header *)tptr;
478 lspping_tlv_type=EXTRACT_16BITS(lspping_tlv_header->type);
479 lspping_tlv_len=EXTRACT_16BITS(lspping_tlv_header->length);
480
481 if (lspping_tlv_len == 0)
482 return;
483
484 if(lspping_tlv_len % 4 || lspping_tlv_len < 4) { /* aligned to four octet boundary */
485 printf("\n\t ERROR: TLV %u bogus size %u",lspping_tlv_type,lspping_tlv_len);
486 return;
487 }
488
489 printf("\n\t %s TLV (%u), length: %u",
490 tok2str(lspping_tlv_values,
491 "Unknown",
492 lspping_tlv_type),
493 lspping_tlv_type,
494 lspping_tlv_len);
495
496 tlv_tptr=tptr+sizeof(struct lspping_tlv_header);
497 tlv_tlen=lspping_tlv_len; /* header not included -> no adjustment */
498
499 /* did we capture enough for fully decoding the tlv ? */
500 if (!TTEST2(*tptr, lspping_tlv_len))
501 goto trunc;
502 tlv_hexdump=FALSE;
503
504 switch(lspping_tlv_type) {
505 case LSPPING_TLV_TARGET_FEC_STACK:
506 while(tlv_tlen>(int)sizeof(struct lspping_tlv_header)) {
507
508 /* did we capture enough for fully decoding the subtlv header ? */
509 if (!TTEST2(*tptr, sizeof(struct lspping_tlv_header)))
510 goto trunc;
511 subtlv_hexdump=FALSE;
512
513 lspping_subtlv_header = (const struct lspping_tlv_header *)tlv_tptr;
514 lspping_subtlv_type=EXTRACT_16BITS(lspping_subtlv_header->type);
515 lspping_subtlv_len=EXTRACT_16BITS(lspping_subtlv_header->length);
516 subtlv_tptr=tlv_tptr+sizeof(struct lspping_tlv_header);
517
518 if (lspping_subtlv_len == 0)
519 break;
520
521 printf("\n\t %s subTLV (%u), length: %u",
522 tok2str(lspping_tlvtargetfec_subtlv_values,
523 "Unknown",
524 lspping_subtlv_type),
525 lspping_subtlv_type,
526 lspping_subtlv_len);
527
528 switch(lspping_subtlv_type) {
529
530 case LSPPING_TLV_TARGETFEC_SUBTLV_LDP_IPV4:
531 subtlv_ptr.lspping_tlv_targetfec_subtlv_ldp_ipv4 = \
532 (const struct lspping_tlv_targetfec_subtlv_ldp_ipv4_t *)subtlv_tptr;
533 printf("\n\t %s/%u",
534 ipaddr_string(subtlv_ptr.lspping_tlv_targetfec_subtlv_ldp_ipv4->prefix),
535 subtlv_ptr.lspping_tlv_targetfec_subtlv_ldp_ipv4->prefix_len);
536 break;
537
538 #ifdef INET6
539 case LSPPING_TLV_TARGETFEC_SUBTLV_LDP_IPV6:
540 subtlv_ptr.lspping_tlv_targetfec_subtlv_ldp_ipv6 = \
541 (const struct lspping_tlv_targetfec_subtlv_ldp_ipv6_t *)subtlv_tptr;
542 printf("\n\t %s/%u",
543 ip6addr_string(subtlv_ptr.lspping_tlv_targetfec_subtlv_ldp_ipv6->prefix),
544 subtlv_ptr.lspping_tlv_targetfec_subtlv_ldp_ipv6->prefix_len);
545 break;
546 #endif
547
548 case LSPPING_TLV_TARGETFEC_SUBTLV_BGP_IPV4:
549 subtlv_ptr.lspping_tlv_targetfec_subtlv_bgp_ipv4 = \
550 (const struct lspping_tlv_targetfec_subtlv_bgp_ipv4_t *)subtlv_tptr;
551 printf("\n\t %s/%u, sender-id %s",
552 ipaddr_string(subtlv_ptr.lspping_tlv_targetfec_subtlv_bgp_ipv4->prefix),
553 subtlv_ptr.lspping_tlv_targetfec_subtlv_bgp_ipv4->prefix_len,
554 ipaddr_string(subtlv_ptr.lspping_tlv_targetfec_subtlv_bgp_ipv4->sender_id));
555 break;
556
557 #ifdef INET6
558 case LSPPING_TLV_TARGETFEC_SUBTLV_BGP_IPV6:
559 subtlv_ptr.lspping_tlv_targetfec_subtlv_bgp_ipv6 = \
560 (const struct lspping_tlv_targetfec_subtlv_bgp_ipv6_t *)subtlv_tptr;
561 printf("\n\t %s/%u, sender-id %s",
562 ip6addr_string(subtlv_ptr.lspping_tlv_targetfec_subtlv_bgp_ipv6->prefix),
563 subtlv_ptr.lspping_tlv_targetfec_subtlv_bgp_ipv6->prefix_len,
564 ip6addr_string(subtlv_ptr.lspping_tlv_targetfec_subtlv_bgp_ipv6->sender_id));
565 break;
566 #endif
567
568 case LSPPING_TLV_TARGETFEC_SUBTLV_RSVP_IPV4:
569 subtlv_ptr.lspping_tlv_targetfec_subtlv_rsvp_ipv4 = \
570 (const struct lspping_tlv_targetfec_subtlv_rsvp_ipv4_t *)subtlv_tptr;
571 printf("\n\t tunnel end-point %s, tunnel sender %s, lsp-id 0x%04x" \
572 "\n\t tunnel-id 0x%04x, extended tunnel-id %s",
573 ipaddr_string(subtlv_ptr.lspping_tlv_targetfec_subtlv_rsvp_ipv4->tunnel_endpoint),
574 ipaddr_string(subtlv_ptr.lspping_tlv_targetfec_subtlv_rsvp_ipv4->tunnel_sender),
575 EXTRACT_16BITS(subtlv_ptr.lspping_tlv_targetfec_subtlv_rsvp_ipv4->lsp_id),
576 EXTRACT_16BITS(subtlv_ptr.lspping_tlv_targetfec_subtlv_rsvp_ipv4->tunnel_id),
577 ipaddr_string(subtlv_ptr.lspping_tlv_targetfec_subtlv_rsvp_ipv4->extended_tunnel_id));
578 break;
579
580 #ifdef INET6
581 case LSPPING_TLV_TARGETFEC_SUBTLV_RSVP_IPV6:
582 subtlv_ptr.lspping_tlv_targetfec_subtlv_rsvp_ipv6 = \
583 (const struct lspping_tlv_targetfec_subtlv_rsvp_ipv6_t *)subtlv_tptr;
584 printf("\n\t tunnel end-point %s, tunnel sender %s, lsp-id 0x%04x" \
585 "\n\t tunnel-id 0x%04x, extended tunnel-id %s",
586 ip6addr_string(subtlv_ptr.lspping_tlv_targetfec_subtlv_rsvp_ipv6->tunnel_endpoint),
587 ip6addr_string(subtlv_ptr.lspping_tlv_targetfec_subtlv_rsvp_ipv6->tunnel_sender),
588 EXTRACT_16BITS(subtlv_ptr.lspping_tlv_targetfec_subtlv_rsvp_ipv6->lsp_id),
589 EXTRACT_16BITS(subtlv_ptr.lspping_tlv_targetfec_subtlv_rsvp_ipv6->tunnel_id),
590 ip6addr_string(subtlv_ptr.lspping_tlv_targetfec_subtlv_rsvp_ipv6->extended_tunnel_id));
591 break;
592 #endif
593
594 case LSPPING_TLV_TARGETFEC_SUBTLV_L3VPN_IPV4:
595 subtlv_ptr.lspping_tlv_targetfec_subtlv_l3vpn_ipv4 = \
596 (const struct lspping_tlv_targetfec_subtlv_l3vpn_ipv4_t *)subtlv_tptr;
597 printf("\n\t RD: %s, %s/%u",
598 bgp_vpn_rd_print(subtlv_ptr.lspping_tlv_targetfec_subtlv_l3vpn_ipv4->rd),
599 ipaddr_string(subtlv_ptr.lspping_tlv_targetfec_subtlv_l3vpn_ipv4->prefix),
600 subtlv_ptr.lspping_tlv_targetfec_subtlv_l3vpn_ipv4->prefix_len);
601 break;
602
603 #ifdef INET6
604 case LSPPING_TLV_TARGETFEC_SUBTLV_L3VPN_IPV6:
605 subtlv_ptr.lspping_tlv_targetfec_subtlv_l3vpn_ipv6 = \
606 (const struct lspping_tlv_targetfec_subtlv_l3vpn_ipv6_t *)subtlv_tptr;
607 printf("\n\t RD: %s, %s/%u",
608 bgp_vpn_rd_print(subtlv_ptr.lspping_tlv_targetfec_subtlv_l3vpn_ipv6->rd),
609 ip6addr_string(subtlv_ptr.lspping_tlv_targetfec_subtlv_l3vpn_ipv6->prefix),
610 subtlv_ptr.lspping_tlv_targetfec_subtlv_l3vpn_ipv6->prefix_len);
611 break;
612 #endif
613
614 case LSPPING_TLV_TARGETFEC_SUBTLV_L2VPN_ENDPT:
615 subtlv_ptr.lspping_tlv_targetfec_subtlv_l2vpn_endpt = \
616 (const struct lspping_tlv_targetfec_subtlv_l2vpn_endpt_t *)subtlv_tptr;
617 printf("\n\t RD: %s, Sender CE-ID: %u, Receiver CE-ID: %u" \
618 "\n\t Encapsulation Type: %s (%u)",
619 bgp_vpn_rd_print(subtlv_ptr.lspping_tlv_targetfec_subtlv_l2vpn_endpt->rd),
620 EXTRACT_16BITS(subtlv_ptr.lspping_tlv_targetfec_subtlv_l2vpn_endpt->sender_ce_id),
621 EXTRACT_16BITS(subtlv_ptr.lspping_tlv_targetfec_subtlv_l2vpn_endpt->receiver_ce_id),
622 tok2str(bgp_l2vpn_encaps_values,
623 "unknown",
624 EXTRACT_16BITS(subtlv_ptr.lspping_tlv_targetfec_subtlv_l2vpn_endpt->encapsulation)),
625 EXTRACT_16BITS(subtlv_ptr.lspping_tlv_targetfec_subtlv_l2vpn_endpt->encapsulation));
626
627 break;
628
629 case LSPPING_TLV_TARGETFEC_SUBTLV_L2VPN_VCID:
630 subtlv_ptr.lspping_tlv_targetfec_subtlv_l2vpn_vcid = \
631 (const struct lspping_tlv_targetfec_subtlv_l2vpn_vcid_t *)subtlv_tptr;
632 printf("\n\t Sender PE: %s, Remote PE: %s" \
633 "\n\t VC-ID: 0x%08x, Encapsulation Type: %s (%u)",
634 ipaddr_string(subtlv_ptr.lspping_tlv_targetfec_subtlv_l2vpn_vcid->sender_pe_address),
635 ipaddr_string(subtlv_ptr.lspping_tlv_targetfec_subtlv_l2vpn_vcid->remote_pe_address),
636 EXTRACT_32BITS(subtlv_ptr.lspping_tlv_targetfec_subtlv_l2vpn_vcid->vc_id),
637 tok2str(bgp_l2vpn_encaps_values, /* FIXME are the L2 encaps codepoints of BGP == LDP ??? */
638 "unknown",
639 EXTRACT_16BITS(subtlv_ptr.lspping_tlv_targetfec_subtlv_l2vpn_endpt->encapsulation)),
640 EXTRACT_16BITS(subtlv_ptr.lspping_tlv_targetfec_subtlv_l2vpn_endpt->encapsulation));
641
642 break;
643
644 default:
645 subtlv_hexdump=TRUE; /* unknown subTLV just hexdump it */
646 break;
647 }
648 /* do we want to see an additionally subtlv hexdump ? */
649 if (vflag > 1 || subtlv_hexdump==TRUE)
650 print_unknown_data(tlv_tptr+sizeof(struct lspping_tlv_header), \
651 "\n\t ",
652 lspping_subtlv_len);
653
654 tlv_tptr+=lspping_subtlv_len;
655 tlv_tlen-=lspping_subtlv_len+sizeof(struct lspping_tlv_header);
656 }
657 break;
658
659 /*
660 * FIXME those are the defined TLVs that lack a decoder
661 * you are welcome to contribute code ;-)
662 */
663
664 case LSPPING_TLV_DOWNSTREAM_MAPPING:
665 case LSPPING_TLV_PAD:
666 case LSPPING_TLV_ERROR_CODE:
667 case LSPPING_TLV_VENDOR_PRIVATE:
668
669 default:
670 if (vflag <= 1)
671 print_unknown_data(tlv_tptr,"\n\t ",tlv_tlen);
672 break;
673 }
674 /* do we want to see an additionally tlv hexdump ? */
675 if (vflag > 1 || tlv_hexdump==TRUE)
676 print_unknown_data(tptr+sizeof(sizeof(struct lspping_tlv_header)),"\n\t ",
677 lspping_tlv_len);
678
679 tptr+=lspping_tlv_len;
680 tlen-=lspping_tlv_len+sizeof(struct lspping_tlv_header);
681 }
682 return;
683 trunc:
684 printf("\n\t\t packet exceeded snapshot");
685 }