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 #include <sys/cdefs.h>
17 #ifndef lint
18 #if 0
19 static const char rcsid[] _U_ =
20     "@(#) Header: /tcpdump/master/tcpdump/print-lspping.c,v 1.20 2008-01-28 14:20:43 hannes Exp";
21 #else
22 __RCSID("$NetBSD: print-lspping.c,v 1.2 2010/12/05 05:11:30 christos Exp $");
23 #endif
24 #endif
25 
26 #ifdef HAVE_CONFIG_H
27 #include "config.h"
28 #endif
29 
30 #include <tcpdump-stdinc.h>
31 
32 #include <stdio.h>
33 #include <stdlib.h>
34 #include <string.h>
35 
36 #include "interface.h"
37 #include "extract.h"
38 #include "addrtoname.h"
39 
40 #include "bgp.h"
41 #include "l2vpn.h"
42 #include "oui.h"
43 
44 /*
45  * LSPPING common header
46  *
47  *  0                   1                   2                   3
48  *  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
49  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
50  * |         Version Number        |         Must Be Zero          |
51  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
52  * |  Message Type |   Reply mode  |  Return Code  | Return Subcode|
53  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
54  * |                        Sender's Handle                        |
55  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
56  * |                        Sequence Number                        |
57  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
58  * |                    TimeStamp Sent (seconds)                   |
59  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
60  * |                  TimeStamp Sent (microseconds)                |
61  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
62  * |                  TimeStamp Received (seconds)                 |
63  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
64  * |                TimeStamp Received (microseconds)              |
65  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
66  * |                            TLVs ...                           |
67  * .                                                               .
68  * .                                                               .
69  * .                                                               .
70  */
71 
72 struct lspping_common_header {
73     u_int8_t version[2];
74     u_int8_t reserved[2];
75     u_int8_t msg_type;
76     u_int8_t reply_mode;
77     u_int8_t return_code;
78     u_int8_t return_subcode;
79     u_int8_t sender_handle[4];
80     u_int8_t seq_number[4];
81     u_int8_t ts_sent_sec[4];
82     u_int8_t ts_sent_usec[4];
83     u_int8_t ts_rcvd_sec[4];
84     u_int8_t ts_rcvd_usec[4];
85 };
86 
87 #define LSPPING_VERSION            1
88 
89 static const struct tok lspping_msg_type_values[] = {
90     { 1, "MPLS Echo Request"},
91     { 2, "MPLS Echo Reply"},
92     { 0, NULL}
93 };
94 
95 static const struct tok lspping_reply_mode_values[] = {
96     { 1, "Do not reply"},
97     { 2, "Reply via an IPv4/IPv6 UDP packet"},
98     { 3, "Reply via an IPv4/IPv6 UDP packet with Router Alert"},
99     { 4, "Reply via application level control channel"},
100     { 0, NULL}
101 };
102 
103 static const struct tok lspping_return_code_values[] = {
104     {  0, "No return code or return code contained in the Error Code TLV"},
105     {  1, "Malformed echo request received"},
106     {  2, "One or more of the TLVs was not understood"},
107     {  3, "Replying router is an egress for the FEC at stack depth"},
108     {  4, "Replying router has no mapping for the FEC at stack depth"},
109     {  5, "Reserved"},
110     {  6, "Reserved"},
111     {  7, "Reserved"},
112     {  8, "Label switched at stack-depth"},
113     {  9, "Label switched but no MPLS forwarding at stack-depth"},
114     { 10, "Mapping for this FEC is not the given label at stack depth"},
115     { 11, "No label entry at stack-depth"},
116     { 12, "Protocol not associated with interface at FEC stack depth"},
117 };
118 
119 
120 /*
121  * LSPPING TLV header
122  *  0                   1                   2                   3
123  *  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
124  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
125  * |             Type              |            Length             |
126  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
127  * |                             Value                             |
128  * .                                                               .
129  * .                                                               .
130  * .                                                               .
131  * |                                                               |
132  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
133  */
134 
135 struct lspping_tlv_header {
136     u_int8_t type[2];
137     u_int8_t length[2];
138 };
139 
140 #define	LSPPING_TLV_TARGET_FEC_STACK      1
141 #define	LSPPING_TLV_DOWNSTREAM_MAPPING    2
142 #define	LSPPING_TLV_PAD                   3
143 #define LSPPING_TLV_VENDOR_ENTERPRISE     5
144 #define LSPPING_TLV_VENDOR_ENTERPRISE_LEN 4
145 #define LSPPING_TLV_INTERFACE_LABEL_STACK 7
146 #define	LSPPING_TLV_ERROR_CODE            9
147 #define LSPPING_TLV_REPLY_TOS_BYTE        10
148 #define	LSPPING_TLV_BFD_DISCRIMINATOR     15 /* draft-ietf-bfd-mpls-02 */
149 #define LSPPING_TLV_BFD_DISCRIMINATOR_LEN 4
150 #define	LSPPING_TLV_VENDOR_PRIVATE        0xfc00
151 
152 static const struct tok lspping_tlv_values[] = {
153     { LSPPING_TLV_TARGET_FEC_STACK, "Target FEC Stack" },
154     { LSPPING_TLV_DOWNSTREAM_MAPPING, "Downstream Mapping" },
155     { LSPPING_TLV_PAD, "Pad" },
156     { LSPPING_TLV_ERROR_CODE, "Error Code" },
157     { LSPPING_TLV_VENDOR_ENTERPRISE, "Vendor Enterprise Code" },
158     { LSPPING_TLV_INTERFACE_LABEL_STACK, "Interface Label Stack" },
159     { LSPPING_TLV_REPLY_TOS_BYTE, "Reply TOS Byte" },
160     { LSPPING_TLV_BFD_DISCRIMINATOR, "BFD Discriminator" },
161     { LSPPING_TLV_VENDOR_PRIVATE, "Vendor Private Code" },
162     { 0, NULL}
163 };
164 
165 #define	LSPPING_TLV_TARGETFEC_SUBTLV_LDP_IPV4      1
166 #define	LSPPING_TLV_TARGETFEC_SUBTLV_LDP_IPV6      2
167 #define	LSPPING_TLV_TARGETFEC_SUBTLV_RSVP_IPV4     3
168 #define	LSPPING_TLV_TARGETFEC_SUBTLV_RSVP_IPV6     4
169 #define	LSPPING_TLV_TARGETFEC_SUBTLV_L3VPN_IPV4    6
170 #define	LSPPING_TLV_TARGETFEC_SUBTLV_L3VPN_IPV6    7
171 #define	LSPPING_TLV_TARGETFEC_SUBTLV_L2VPN_ENDPT   8
172 #define	LSPPING_TLV_TARGETFEC_SUBTLV_L2VPN_VCID_OLD 9
173 #define	LSPPING_TLV_TARGETFEC_SUBTLV_L2VPN_VCID   10
174 #define	LSPPING_TLV_TARGETFEC_SUBTLV_BGP_IPV4     11
175 #define	LSPPING_TLV_TARGETFEC_SUBTLV_BGP_IPV6     12
176 
177 static const struct tok lspping_tlvtargetfec_subtlv_values[] = {
178     { LSPPING_TLV_TARGETFEC_SUBTLV_LDP_IPV4, "LDP IPv4 prefix"},
179     { LSPPING_TLV_TARGETFEC_SUBTLV_LDP_IPV6, "LDP IPv6 prefix"},
180     { LSPPING_TLV_TARGETFEC_SUBTLV_RSVP_IPV4, "RSVP IPv4 Session Query"},
181     { LSPPING_TLV_TARGETFEC_SUBTLV_RSVP_IPV6, "RSVP IPv6 Session Query"},
182     { 5, "Reserved"},
183     { LSPPING_TLV_TARGETFEC_SUBTLV_L3VPN_IPV4, "VPN IPv4 prefix"},
184     { LSPPING_TLV_TARGETFEC_SUBTLV_L3VPN_IPV6, "VPN IPv6 prefix"},
185     { LSPPING_TLV_TARGETFEC_SUBTLV_L2VPN_ENDPT, "L2 VPN endpoint"},
186     { LSPPING_TLV_TARGETFEC_SUBTLV_L2VPN_VCID_OLD, "L2 circuit ID (old)"},
187     { LSPPING_TLV_TARGETFEC_SUBTLV_L2VPN_VCID, "L2 circuit ID"},
188     { LSPPING_TLV_TARGETFEC_SUBTLV_BGP_IPV4, "BGP labeled IPv4 prefix"},
189     { LSPPING_TLV_TARGETFEC_SUBTLV_BGP_IPV6, "BGP labeled IPv6 prefix"},
190     { 0, NULL}
191 };
192 
193 /*
194  *  0                   1                   2                   3
195  *  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
196  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
197  * |                          IPv4 prefix                          |
198  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
199  * | Prefix Length |         Must Be Zero                          |
200  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
201  */
202 struct lspping_tlv_targetfec_subtlv_ldp_ipv4_t {
203     u_int8_t prefix [4];
204     u_int8_t prefix_len;
205 };
206 
207 /*
208  *  0                   1                   2                   3
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  * |                          IPv6 prefix                          |
212  * |                          (16 octets)                          |
213  * |                                                               |
214  * |                                                               |
215  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
216  * | Prefix Length |         Must Be Zero                          |
217  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
218  */
219 struct lspping_tlv_targetfec_subtlv_ldp_ipv6_t {
220     u_int8_t prefix [16];
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  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
229  * |                         IPv4 prefix                           |
230  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
231  * | Prefix Length |                 Must Be Zero                  |
232  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
233  */
234 struct lspping_tlv_targetfec_subtlv_bgp_ipv4_t {
235     u_int8_t sender_id [4];
236     u_int8_t prefix [4];
237     u_int8_t prefix_len;
238 };
239 
240 /*
241  * 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
242  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
243  * |                    Sender identifier                          |
244  * |                          (16 octets)                          |
245  * |                                                               |
246  * |                                                               |
247  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
248  * |                          IPv6 prefix                          |
249  * |                          (16 octets)                          |
250  * |                                                               |
251  * |                                                               |
252  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
253  * | Prefix Length |                 Must Be Zero                  |
254  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
255  */
256 struct lspping_tlv_targetfec_subtlv_bgp_ipv6_t {
257     u_int8_t sender_id [16];
258     u_int8_t prefix [16];
259     u_int8_t prefix_len;
260 };
261 
262 /*
263  *  0                   1                   2                   3
264  *  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
265  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
266  * |                 IPv4 tunnel end point address                 |
267  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
268  * |          Must Be Zero         |     Tunnel ID                 |
269  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
270  * |                       Extended Tunnel ID                      |
271  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
272  * |                   IPv4 tunnel sender address                  |
273  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
274  * |          Must Be Zero         |            LSP ID             |
275  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
276  */
277 struct lspping_tlv_targetfec_subtlv_rsvp_ipv4_t {
278     u_int8_t tunnel_endpoint [4];
279     u_int8_t res[2];
280     u_int8_t tunnel_id[2];
281     u_int8_t extended_tunnel_id[4];
282     u_int8_t tunnel_sender [4];
283     u_int8_t res2[2];
284     u_int8_t lsp_id [2];
285 };
286 
287 /*
288  *  0                   1                   2                   3
289  *  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
290  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
291  * |                 IPv6 tunnel end point address                 |
292  * |                                                               |
293  * |                                                               |
294  * |                                                               |
295  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
296  * |          Must Be Zero         |          Tunnel ID            |
297  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
298  * |                       Extended Tunnel ID                      |
299  * |                                                               |
300  * |                                                               |
301  * |                                                               |
302  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
303  * |                   IPv6 tunnel sender address                  |
304  * |                                                               |
305  * |                                                               |
306  * |                                                               |
307  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
308  * |          Must Be Zero         |            LSP ID             |
309  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
310  */
311 struct lspping_tlv_targetfec_subtlv_rsvp_ipv6_t {
312     u_int8_t tunnel_endpoint [16];
313     u_int8_t res[2];
314     u_int8_t tunnel_id[2];
315     u_int8_t extended_tunnel_id[16];
316     u_int8_t tunnel_sender [16];
317     u_int8_t res2[2];
318     u_int8_t lsp_id [2];
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  * |                         IPv4 prefix                           |
329  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
330  * | Prefix Length |                 Must Be Zero                  |
331  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
332  */
333 struct lspping_tlv_targetfec_subtlv_l3vpn_ipv4_t {
334     u_int8_t rd [8];
335     u_int8_t prefix [4];
336     u_int8_t prefix_len;
337 };
338 
339 /*
340  *  0                   1                   2                   3
341  *  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
342  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
343  * |                      Route Distinguisher                      |
344  * |                          (8 octets)                           |
345  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
346  * |                          IPv6 prefix                          |
347  * |                          (16 octets)                          |
348  * |                                                               |
349  * |                                                               |
350  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
351  * | Prefix Length |                 Must Be Zero                  |
352  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
353  */
354 struct lspping_tlv_targetfec_subtlv_l3vpn_ipv6_t {
355     u_int8_t rd [8];
356     u_int8_t prefix [16];
357     u_int8_t prefix_len;
358 };
359 
360 /*
361  *  0                   1                   2                   3
362  *  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
363  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
364  * |                      Route Distinguisher                      |
365  * |                          (8 octets)                           |
366  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
367  * |         Sender's CE ID        |       Receiver's CE ID        |
368  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
369  * |      Encapsulation Type       |         Must Be Zero          |
370  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
371  *  0                   1                   2                   3
372  */
373 struct lspping_tlv_targetfec_subtlv_l2vpn_endpt_t {
374     u_int8_t rd [8];
375     u_int8_t sender_ce_id [2];
376     u_int8_t receiver_ce_id [2];
377     u_int8_t encapsulation[2];
378 };
379 
380 /*
381  *  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
382  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
383  * |                      Remote PE Address                        |
384  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
385  * |                             VC ID                             |
386  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
387  * |      Encapsulation Type       |         Must Be Zero          |
388  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
389  */
390 struct lspping_tlv_targetfec_subtlv_l2vpn_vcid_old_t {
391     u_int8_t remote_pe_address [4];
392     u_int8_t vc_id [4];
393     u_int8_t encapsulation[2];
394 };
395 
396 /*
397  *  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
398  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
399  * |                     Sender's PE Address                       |
400  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
401  * |                      Remote PE Address                        |
402  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
403  * |                             VC ID                             |
404  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
405  * |      Encapsulation Type       |         Must Be Zero          |
406  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
407  */
408 struct lspping_tlv_targetfec_subtlv_l2vpn_vcid_t {
409     u_int8_t sender_pe_address [4];
410     u_int8_t remote_pe_address [4];
411     u_int8_t vc_id [4];
412     u_int8_t encapsulation[2];
413 };
414 
415 /*
416  *  0                   1                   2                   3
417  *  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
418  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
419  * |               MTU             | Address Type  |  Resvd (SBZ)  |
420  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
421  * |             Downstream IP Address (4 or 16 octets)            |
422  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
423  * |         Downstream Interface Address (4 or 16 octets)         |
424  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
425  * | Hash Key Type | Depth Limit   |        Multipath Length       |
426  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
427  * .                                                               .
428  * .                     (Multipath Information)                   .
429  * .                                                               .
430  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
431  * |               Downstream Label                |    Protocol   |
432  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
433  * .                                                               .
434  * .                                                               .
435  * .                                                               .
436  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
437  * |               Downstream Label                |    Protocol   |
438  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
439  */
440 struct lspping_tlv_downstream_map_ipv4_t {
441     u_int8_t mtu [2];
442     u_int8_t address_type;
443     u_int8_t res;
444     u_int8_t downstream_ip[4];
445     u_int8_t downstream_interface[4];
446 };
447 
448 struct lspping_tlv_downstream_map_ipv6_t {
449     u_int8_t mtu [2];
450     u_int8_t address_type;
451     u_int8_t res;
452     u_int8_t downstream_ip[16];
453     u_int8_t downstream_interface[16];
454 };
455 
456 struct lspping_tlv_downstream_map_info_t {
457     u_int8_t hash_key_type;
458     u_int8_t depth_limit;
459     u_int8_t multipath_length [2];
460 };
461 
462 #define LSPPING_AFI_IPV4 1
463 #define LSPPING_AFI_UNMB 2
464 #define LSPPING_AFI_IPV6 3
465 
466 static const struct tok lspping_tlv_downstream_addr_values[] = {
467     { LSPPING_AFI_IPV4, "IPv4"},
468     { LSPPING_AFI_IPV6, "IPv6"},
469     { LSPPING_AFI_UNMB, "Unnumbered"},
470     { 0, NULL}
471 };
472 
473 void
474 lspping_print(register const u_char *pptr, register u_int len) {
475 
476     const struct lspping_common_header *lspping_com_header;
477     const struct lspping_tlv_header *lspping_tlv_header;
478     const struct lspping_tlv_header *lspping_subtlv_header;
479     const u_char *tptr,*tlv_tptr,*subtlv_tptr;
480     int tlen,lspping_tlv_len,lspping_tlv_type,tlv_tlen;
481     int tlv_hexdump,subtlv_hexdump;
482     int lspping_subtlv_len,lspping_subtlv_type;
483     struct timeval timestamp;
484 
485     union {
486         const struct lspping_tlv_downstream_map_ipv4_t *lspping_tlv_downstream_map_ipv4;
487         const struct lspping_tlv_downstream_map_ipv6_t *lspping_tlv_downstream_map_ipv6;
488         const struct lspping_tlv_downstream_map_info_t  *lspping_tlv_downstream_map_info;
489     } tlv_ptr;
490 
491     union {
492         const struct lspping_tlv_targetfec_subtlv_ldp_ipv4_t *lspping_tlv_targetfec_subtlv_ldp_ipv4;
493         const struct lspping_tlv_targetfec_subtlv_ldp_ipv6_t *lspping_tlv_targetfec_subtlv_ldp_ipv6;
494         const struct lspping_tlv_targetfec_subtlv_rsvp_ipv4_t *lspping_tlv_targetfec_subtlv_rsvp_ipv4;
495         const struct lspping_tlv_targetfec_subtlv_rsvp_ipv6_t *lspping_tlv_targetfec_subtlv_rsvp_ipv6;
496         const struct lspping_tlv_targetfec_subtlv_l3vpn_ipv4_t *lspping_tlv_targetfec_subtlv_l3vpn_ipv4;
497         const struct lspping_tlv_targetfec_subtlv_l3vpn_ipv6_t *lspping_tlv_targetfec_subtlv_l3vpn_ipv6;
498         const struct lspping_tlv_targetfec_subtlv_l2vpn_endpt_t *lspping_tlv_targetfec_subtlv_l2vpn_endpt;
499         const struct lspping_tlv_targetfec_subtlv_l2vpn_vcid_old_t *lspping_tlv_targetfec_subtlv_l2vpn_vcid_old;
500         const struct lspping_tlv_targetfec_subtlv_l2vpn_vcid_t *lspping_tlv_targetfec_subtlv_l2vpn_vcid;
501         const struct lspping_tlv_targetfec_subtlv_bgp_ipv4_t *lspping_tlv_targetfec_subtlv_bgp_ipv4;
502         const struct lspping_tlv_targetfec_subtlv_bgp_ipv6_t *lspping_tlv_targetfec_subtlv_bgp_ipv6;
503     } subtlv_ptr;
504 
505     tptr=pptr;
506     lspping_com_header = (const struct lspping_common_header *)pptr;
507     TCHECK(*lspping_com_header);
508 
509     /*
510      * Sanity checking of the header.
511      */
512     if (EXTRACT_16BITS(&lspping_com_header->version[0]) != LSPPING_VERSION) {
513 	printf("LSP-PING version %u packet not supported",
514                EXTRACT_16BITS(&lspping_com_header->version[0]));
515 	return;
516     }
517 
518     /* in non-verbose mode just lets print the basic Message Type*/
519     if (vflag < 1) {
520         printf("LSP-PINGv%u, %s, seq %u, length: %u",
521                EXTRACT_16BITS(&lspping_com_header->version[0]),
522                tok2str(lspping_msg_type_values, "unknown (%u)",lspping_com_header->msg_type),
523                EXTRACT_32BITS(lspping_com_header->seq_number),
524                len);
525         return;
526     }
527 
528     /* ok they seem to want to know everything - lets fully decode it */
529 
530     tlen=len;
531 
532     printf("\n\tLSP-PINGv%u, msg-type: %s (%u), length: %u\n\t  reply-mode: %s (%u)",
533            EXTRACT_16BITS(&lspping_com_header->version[0]),
534            tok2str(lspping_msg_type_values, "unknown",lspping_com_header->msg_type),
535            lspping_com_header->msg_type,
536            len,
537            tok2str(lspping_reply_mode_values, "unknown",lspping_com_header->reply_mode),
538            lspping_com_header->reply_mode);
539 
540     /*
541      *  the following return codes require that the subcode is attached
542      *  at the end of the translated token output
543      */
544     if (lspping_com_header->return_code == 3 ||
545         lspping_com_header->return_code == 4 ||
546         lspping_com_header->return_code == 8 ||
547         lspping_com_header->return_code == 10 ||
548         lspping_com_header->return_code == 11 ||
549         lspping_com_header->return_code == 12 )
550         printf("\n\t  Return Code: %s %u (%u)\n\t  Return Subcode: (%u)",
551                tok2str(lspping_return_code_values, "unknown",lspping_com_header->return_code),
552                lspping_com_header->return_subcode,
553                lspping_com_header->return_code,
554                lspping_com_header->return_subcode);
555     else
556         printf("\n\t  Return Code: %s (%u)\n\t  Return Subcode: (%u)",
557                tok2str(lspping_return_code_values, "unknown",lspping_com_header->return_code),
558                lspping_com_header->return_code,
559                lspping_com_header->return_subcode);
560 
561     printf("\n\t  Sender Handle: 0x%08x, Sequence: %u",
562            EXTRACT_32BITS(lspping_com_header->sender_handle),
563            EXTRACT_32BITS(lspping_com_header->seq_number));
564 
565     timestamp.tv_sec=EXTRACT_32BITS(lspping_com_header->ts_sent_sec);
566     timestamp.tv_usec=EXTRACT_32BITS(lspping_com_header->ts_sent_usec);
567     printf("\n\t  Sender Timestamp: ");
568     ts_print(&timestamp);
569 
570     timestamp.tv_sec=EXTRACT_32BITS(lspping_com_header->ts_rcvd_sec);
571     timestamp.tv_usec=EXTRACT_32BITS(lspping_com_header->ts_rcvd_usec);
572     printf("Receiver Timestamp: ");
573     if ((timestamp.tv_sec != 0) && (timestamp.tv_usec != 0))
574         ts_print(&timestamp);
575     else
576         printf("no timestamp");
577 
578     tptr+=sizeof(const struct lspping_common_header);
579     tlen-=sizeof(const struct lspping_common_header);
580 
581     while(tlen>(int)sizeof(struct lspping_tlv_header)) {
582 
583         /* did we capture enough for fully decoding the tlv header ? */
584         if (!TTEST2(*tptr, sizeof(struct lspping_tlv_header)))
585             goto trunc;
586 
587         lspping_tlv_header = (const struct lspping_tlv_header *)tptr;
588         lspping_tlv_type=EXTRACT_16BITS(lspping_tlv_header->type);
589         lspping_tlv_len=EXTRACT_16BITS(lspping_tlv_header->length);
590 
591         /* some little sanity checking */
592         if (lspping_tlv_type == 0 || lspping_tlv_len == 0)
593             return;
594 
595         if(lspping_tlv_len < 4) {
596             printf("\n\t  ERROR: TLV %u bogus size %u",lspping_tlv_type,lspping_tlv_len);
597             return;
598         }
599 
600         printf("\n\t  %s TLV (%u), length: %u",
601                tok2str(lspping_tlv_values,
602                        "Unknown",
603                        lspping_tlv_type),
604                lspping_tlv_type,
605                lspping_tlv_len);
606 
607         tlv_tptr=tptr+sizeof(struct lspping_tlv_header);
608         tlv_tlen=lspping_tlv_len; /* header not included -> no adjustment */
609 
610         /* did we capture enough for fully decoding the tlv ? */
611         if (!TTEST2(*tptr, lspping_tlv_len))
612             goto trunc;
613         tlv_hexdump=FALSE;
614 
615         switch(lspping_tlv_type) {
616         case LSPPING_TLV_TARGET_FEC_STACK:
617             while(tlv_tlen>(int)sizeof(struct lspping_tlv_header)) {
618 
619                 /* did we capture enough for fully decoding the subtlv header ? */
620                 if (!TTEST2(*tptr, sizeof(struct lspping_tlv_header)))
621                     goto trunc;
622                 subtlv_hexdump=FALSE;
623 
624                 lspping_subtlv_header = (const struct lspping_tlv_header *)tlv_tptr;
625                 lspping_subtlv_type=EXTRACT_16BITS(lspping_subtlv_header->type);
626                 lspping_subtlv_len=EXTRACT_16BITS(lspping_subtlv_header->length);
627                 subtlv_tptr=tlv_tptr+sizeof(struct lspping_tlv_header);
628 
629                 if (lspping_subtlv_len == 0)
630                     break;
631 
632                 printf("\n\t    %s subTLV (%u), length: %u",
633                        tok2str(lspping_tlvtargetfec_subtlv_values,
634                                "Unknown",
635                                lspping_subtlv_type),
636                        lspping_subtlv_type,
637                        lspping_subtlv_len);
638 
639                 switch(lspping_subtlv_type) {
640 
641                 case LSPPING_TLV_TARGETFEC_SUBTLV_LDP_IPV4:
642                     subtlv_ptr.lspping_tlv_targetfec_subtlv_ldp_ipv4 = \
643                         (const struct lspping_tlv_targetfec_subtlv_ldp_ipv4_t *)subtlv_tptr;
644                     printf("\n\t      %s/%u",
645                            ipaddr_string(subtlv_ptr.lspping_tlv_targetfec_subtlv_ldp_ipv4->prefix),
646                            subtlv_ptr.lspping_tlv_targetfec_subtlv_ldp_ipv4->prefix_len);
647                     break;
648 
649 #ifdef INET6
650                 case LSPPING_TLV_TARGETFEC_SUBTLV_LDP_IPV6:
651                     subtlv_ptr.lspping_tlv_targetfec_subtlv_ldp_ipv6 = \
652                         (const struct lspping_tlv_targetfec_subtlv_ldp_ipv6_t *)subtlv_tptr;
653                     printf("\n\t      %s/%u",
654                            ip6addr_string(subtlv_ptr.lspping_tlv_targetfec_subtlv_ldp_ipv6->prefix),
655                            subtlv_ptr.lspping_tlv_targetfec_subtlv_ldp_ipv6->prefix_len);
656                     break;
657 #endif
658 
659                 case LSPPING_TLV_TARGETFEC_SUBTLV_BGP_IPV4:
660                     subtlv_ptr.lspping_tlv_targetfec_subtlv_bgp_ipv4 = \
661                         (const struct lspping_tlv_targetfec_subtlv_bgp_ipv4_t *)subtlv_tptr;
662                     printf("\n\t      %s/%u, sender-id %s",
663                            ipaddr_string(subtlv_ptr.lspping_tlv_targetfec_subtlv_bgp_ipv4->prefix),
664                            subtlv_ptr.lspping_tlv_targetfec_subtlv_bgp_ipv4->prefix_len,
665                            ipaddr_string(subtlv_ptr.lspping_tlv_targetfec_subtlv_bgp_ipv4->sender_id));
666                     break;
667 
668 #ifdef INET6
669                 case LSPPING_TLV_TARGETFEC_SUBTLV_BGP_IPV6:
670                     subtlv_ptr.lspping_tlv_targetfec_subtlv_bgp_ipv6 = \
671                         (const struct lspping_tlv_targetfec_subtlv_bgp_ipv6_t *)subtlv_tptr;
672                     printf("\n\t      %s/%u, sender-id %s",
673                            ip6addr_string(subtlv_ptr.lspping_tlv_targetfec_subtlv_bgp_ipv6->prefix),
674                            subtlv_ptr.lspping_tlv_targetfec_subtlv_bgp_ipv6->prefix_len,
675                            ip6addr_string(subtlv_ptr.lspping_tlv_targetfec_subtlv_bgp_ipv6->sender_id));
676                     break;
677 #endif
678 
679                 case LSPPING_TLV_TARGETFEC_SUBTLV_RSVP_IPV4:
680                     subtlv_ptr.lspping_tlv_targetfec_subtlv_rsvp_ipv4 = \
681                         (const struct lspping_tlv_targetfec_subtlv_rsvp_ipv4_t *)subtlv_tptr;
682                     printf("\n\t      tunnel end-point %s, tunnel sender %s, lsp-id 0x%04x" \
683                            "\n\t      tunnel-id 0x%04x, extended tunnel-id %s",
684                            ipaddr_string(subtlv_ptr.lspping_tlv_targetfec_subtlv_rsvp_ipv4->tunnel_endpoint),
685                            ipaddr_string(subtlv_ptr.lspping_tlv_targetfec_subtlv_rsvp_ipv4->tunnel_sender),
686                            EXTRACT_16BITS(subtlv_ptr.lspping_tlv_targetfec_subtlv_rsvp_ipv4->lsp_id),
687                            EXTRACT_16BITS(subtlv_ptr.lspping_tlv_targetfec_subtlv_rsvp_ipv4->tunnel_id),
688                            ipaddr_string(subtlv_ptr.lspping_tlv_targetfec_subtlv_rsvp_ipv4->extended_tunnel_id));
689                     break;
690 
691 #ifdef INET6
692                 case LSPPING_TLV_TARGETFEC_SUBTLV_RSVP_IPV6:
693                     subtlv_ptr.lspping_tlv_targetfec_subtlv_rsvp_ipv6 = \
694                         (const struct lspping_tlv_targetfec_subtlv_rsvp_ipv6_t *)subtlv_tptr;
695                     printf("\n\t      tunnel end-point %s, tunnel sender %s, lsp-id 0x%04x" \
696                            "\n\t      tunnel-id 0x%04x, extended tunnel-id %s",
697                            ip6addr_string(subtlv_ptr.lspping_tlv_targetfec_subtlv_rsvp_ipv6->tunnel_endpoint),
698                            ip6addr_string(subtlv_ptr.lspping_tlv_targetfec_subtlv_rsvp_ipv6->tunnel_sender),
699                            EXTRACT_16BITS(subtlv_ptr.lspping_tlv_targetfec_subtlv_rsvp_ipv6->lsp_id),
700                            EXTRACT_16BITS(subtlv_ptr.lspping_tlv_targetfec_subtlv_rsvp_ipv6->tunnel_id),
701                            ip6addr_string(subtlv_ptr.lspping_tlv_targetfec_subtlv_rsvp_ipv6->extended_tunnel_id));
702                     break;
703 #endif
704 
705                 case LSPPING_TLV_TARGETFEC_SUBTLV_L3VPN_IPV4:
706                     subtlv_ptr.lspping_tlv_targetfec_subtlv_l3vpn_ipv4 = \
707                         (const struct lspping_tlv_targetfec_subtlv_l3vpn_ipv4_t *)subtlv_tptr;
708                     printf("\n\t      RD: %s, %s/%u",
709                            bgp_vpn_rd_print(subtlv_ptr.lspping_tlv_targetfec_subtlv_l3vpn_ipv4->rd),
710                            ipaddr_string(subtlv_ptr.lspping_tlv_targetfec_subtlv_l3vpn_ipv4->prefix),
711                            subtlv_ptr.lspping_tlv_targetfec_subtlv_l3vpn_ipv4->prefix_len);
712                     break;
713 
714 #ifdef INET6
715                 case LSPPING_TLV_TARGETFEC_SUBTLV_L3VPN_IPV6:
716                     subtlv_ptr.lspping_tlv_targetfec_subtlv_l3vpn_ipv6 = \
717                         (const struct lspping_tlv_targetfec_subtlv_l3vpn_ipv6_t *)subtlv_tptr;
718                     printf("\n\t      RD: %s, %s/%u",
719                            bgp_vpn_rd_print(subtlv_ptr.lspping_tlv_targetfec_subtlv_l3vpn_ipv6->rd),
720                            ip6addr_string(subtlv_ptr.lspping_tlv_targetfec_subtlv_l3vpn_ipv6->prefix),
721                            subtlv_ptr.lspping_tlv_targetfec_subtlv_l3vpn_ipv6->prefix_len);
722                     break;
723 #endif
724 
725                 case LSPPING_TLV_TARGETFEC_SUBTLV_L2VPN_ENDPT:
726                     subtlv_ptr.lspping_tlv_targetfec_subtlv_l2vpn_endpt = \
727                         (const struct lspping_tlv_targetfec_subtlv_l2vpn_endpt_t *)subtlv_tptr;
728                     printf("\n\t      RD: %s, Sender CE-ID: %u, Receiver CE-ID: %u" \
729                            "\n\t      Encapsulation Type: %s (%u)",
730                            bgp_vpn_rd_print(subtlv_ptr.lspping_tlv_targetfec_subtlv_l2vpn_endpt->rd),
731                            EXTRACT_16BITS(subtlv_ptr.lspping_tlv_targetfec_subtlv_l2vpn_endpt->sender_ce_id),
732                            EXTRACT_16BITS(subtlv_ptr.lspping_tlv_targetfec_subtlv_l2vpn_endpt->receiver_ce_id),
733                            tok2str(l2vpn_encaps_values,
734                                    "unknown",
735                                    EXTRACT_16BITS(subtlv_ptr.lspping_tlv_targetfec_subtlv_l2vpn_endpt->encapsulation)),
736                            EXTRACT_16BITS(subtlv_ptr.lspping_tlv_targetfec_subtlv_l2vpn_endpt->encapsulation));
737 
738                     break;
739 
740                     /* the old L2VPN VCID subTLV does not have support for the sender field */
741                 case LSPPING_TLV_TARGETFEC_SUBTLV_L2VPN_VCID_OLD:
742                     subtlv_ptr.lspping_tlv_targetfec_subtlv_l2vpn_vcid_old = \
743                         (const struct lspping_tlv_targetfec_subtlv_l2vpn_vcid_old_t *)subtlv_tptr;
744                     printf("\n\t      Remote PE: %s" \
745                            "\n\t      VC-ID: 0x%08x, Encapsulation Type: %s (%u)",
746                            ipaddr_string(subtlv_ptr.lspping_tlv_targetfec_subtlv_l2vpn_vcid_old->remote_pe_address),
747                            EXTRACT_32BITS(subtlv_ptr.lspping_tlv_targetfec_subtlv_l2vpn_vcid_old->vc_id),
748                            tok2str(l2vpn_encaps_values,
749                                    "unknown",
750                                    EXTRACT_16BITS(subtlv_ptr.lspping_tlv_targetfec_subtlv_l2vpn_vcid_old->encapsulation)),
751                            EXTRACT_16BITS(subtlv_ptr.lspping_tlv_targetfec_subtlv_l2vpn_vcid_old->encapsulation));
752 
753                     break;
754 
755                 case LSPPING_TLV_TARGETFEC_SUBTLV_L2VPN_VCID:
756                     subtlv_ptr.lspping_tlv_targetfec_subtlv_l2vpn_vcid = \
757                         (const struct lspping_tlv_targetfec_subtlv_l2vpn_vcid_t *)subtlv_tptr;
758                     printf("\n\t      Sender PE: %s, Remote PE: %s" \
759                            "\n\t      VC-ID: 0x%08x, Encapsulation Type: %s (%u)",
760                            ipaddr_string(subtlv_ptr.lspping_tlv_targetfec_subtlv_l2vpn_vcid->sender_pe_address),
761                            ipaddr_string(subtlv_ptr.lspping_tlv_targetfec_subtlv_l2vpn_vcid->remote_pe_address),
762                            EXTRACT_32BITS(subtlv_ptr.lspping_tlv_targetfec_subtlv_l2vpn_vcid->vc_id),
763                            tok2str(l2vpn_encaps_values,
764                                    "unknown",
765                                    EXTRACT_16BITS(subtlv_ptr.lspping_tlv_targetfec_subtlv_l2vpn_vcid->encapsulation)),
766                            EXTRACT_16BITS(subtlv_ptr.lspping_tlv_targetfec_subtlv_l2vpn_vcid->encapsulation));
767 
768                     break;
769 
770                 default:
771                     subtlv_hexdump=TRUE; /* unknown subTLV just hexdump it */
772                     break;
773                 }
774                 /* do we want to see an additionally subtlv hexdump ? */
775                 if (vflag > 1 || subtlv_hexdump==TRUE)
776                     print_unknown_data(tlv_tptr+sizeof(struct lspping_tlv_header), \
777                                        "\n\t      ",
778                                        lspping_subtlv_len);
779 
780                 tlv_tptr+=lspping_subtlv_len;
781                 tlv_tlen-=lspping_subtlv_len+sizeof(struct lspping_tlv_header);
782             }
783             break;
784 
785         case LSPPING_TLV_DOWNSTREAM_MAPPING:
786             /* that strange thing with the downstream map TLV is that until now
787              * we do not know if its IPv4 or IPv6 , after we found the adress-type
788              * lets recast the tlv_tptr and move on */
789 
790             tlv_ptr.lspping_tlv_downstream_map_ipv4= \
791                 (const struct lspping_tlv_downstream_map_ipv4_t *)tlv_tptr;
792             tlv_ptr.lspping_tlv_downstream_map_ipv6= \
793                 (const struct lspping_tlv_downstream_map_ipv6_t *)tlv_tptr;
794             printf("\n\t    MTU: %u, Address-Type: %s (%u)",
795                    EXTRACT_16BITS(tlv_ptr.lspping_tlv_downstream_map_ipv4->mtu),
796                    tok2str(lspping_tlv_downstream_addr_values,
797                            "unknown",
798                            tlv_ptr.lspping_tlv_downstream_map_ipv4->address_type),
799                    tlv_ptr.lspping_tlv_downstream_map_ipv4->address_type);
800 
801             switch(tlv_ptr.lspping_tlv_downstream_map_ipv4->address_type) {
802 
803             case LSPPING_AFI_IPV4:
804                 printf("\n\t    Downstream IP: %s" \
805                        "\n\t    Downstream Interface IP: %s",
806                        ipaddr_string(tlv_ptr.lspping_tlv_downstream_map_ipv4->downstream_ip),
807                        ipaddr_string(tlv_ptr.lspping_tlv_downstream_map_ipv4->downstream_interface));
808                 tlv_tptr+=sizeof(struct lspping_tlv_downstream_map_ipv4_t);
809                 tlv_tlen-=sizeof(struct lspping_tlv_downstream_map_ipv4_t);
810                 break;
811 #ifdef INET6
812              case LSPPING_AFI_IPV6:
813                 printf("\n\t    Downstream IP: %s" \
814                        "\n\t    Downstream Interface IP: %s",
815                        ip6addr_string(tlv_ptr.lspping_tlv_downstream_map_ipv6->downstream_ip),
816                        ip6addr_string(tlv_ptr.lspping_tlv_downstream_map_ipv6->downstream_interface));
817                 tlv_tptr+=sizeof(struct lspping_tlv_downstream_map_ipv6_t);
818                 tlv_tlen-=sizeof(struct lspping_tlv_downstream_map_ipv6_t);
819                 break;
820 #endif
821             case LSPPING_AFI_UNMB:
822                 printf("\n\t    Downstream IP: %s" \
823                        "\n\t    Downstream Interface Index: 0x%08x",
824                        ipaddr_string(tlv_ptr.lspping_tlv_downstream_map_ipv4->downstream_ip),
825                        EXTRACT_32BITS(tlv_ptr.lspping_tlv_downstream_map_ipv4->downstream_interface));
826                 tlv_tptr+=sizeof(struct lspping_tlv_downstream_map_ipv4_t);
827                 tlv_tlen-=sizeof(struct lspping_tlv_downstream_map_ipv4_t);
828                 break;
829 
830             default:
831                 /* should not happen ! - no error message - tok2str() has barked already */
832                 break;
833             }
834 
835             tlv_ptr.lspping_tlv_downstream_map_info= \
836                 (const struct lspping_tlv_downstream_map_info_t *)tlv_tptr;
837 
838             /* FIXME add hash-key type, depth limit, multipath processing */
839 
840 
841             tlv_tptr+=sizeof(struct lspping_tlv_downstream_map_info_t);
842             tlv_tlen-=sizeof(struct lspping_tlv_downstream_map_info_t);
843 
844             /* FIXME print downstream labels */
845 
846 
847             tlv_hexdump=TRUE; /* dump the TLV until code complete */
848 
849             break;
850 
851         case LSPPING_TLV_BFD_DISCRIMINATOR:
852             tptr += sizeof(struct lspping_tlv_header);
853             if (!TTEST2(*tptr, LSPPING_TLV_BFD_DISCRIMINATOR_LEN))
854                 goto trunc;
855             printf("\n\t    BFD Discriminator 0x%08x", EXTRACT_32BITS(tptr));
856             break;
857 
858         case  LSPPING_TLV_VENDOR_ENTERPRISE:
859         {
860             u_int32_t vendor_id;
861 
862             if (!TTEST2(*tptr, LSPPING_TLV_VENDOR_ENTERPRISE_LEN))
863                 goto trunc;
864             vendor_id = EXTRACT_32BITS(tlv_tptr);
865             printf("\n\t    Vendor: %s (0x%04x)",
866                    tok2str(smi_values, "Unknown", vendor_id),
867                    vendor_id);
868         }
869             break;
870 
871             /*
872              *  FIXME those are the defined TLVs that lack a decoder
873              *  you are welcome to contribute code ;-)
874              */
875         case LSPPING_TLV_PAD:
876         case LSPPING_TLV_ERROR_CODE:
877         case LSPPING_TLV_VENDOR_PRIVATE:
878 
879         default:
880             if (vflag <= 1)
881                 print_unknown_data(tlv_tptr,"\n\t    ",tlv_tlen);
882             break;
883         }
884         /* do we want to see an additionally tlv hexdump ? */
885         if (vflag > 1 || tlv_hexdump==TRUE)
886             print_unknown_data(tptr+sizeof(sizeof(struct lspping_tlv_header)),"\n\t    ",
887                                lspping_tlv_len);
888 
889 
890         /* All TLVs are aligned to four octet boundary */
891         if (lspping_tlv_len % 4) {
892             lspping_tlv_len += (4 - lspping_tlv_len % 4);
893         }
894 
895         tptr+=lspping_tlv_len+sizeof(struct lspping_tlv_header);
896         tlen-=lspping_tlv_len+sizeof(struct lspping_tlv_header);
897     }
898     return;
899 trunc:
900     printf("\n\t\t packet exceeded snapshot");
901 }
902