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