xref: /netbsd-src/external/bsd/tcpdump/dist/print-lspping.c (revision 3117ece4fc4a4ca4489ba793710b60b0d26bab6c)
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@gredler.at)
14  */
15 
16 #include <sys/cdefs.h>
17 #ifndef lint
18 __RCSID("$NetBSD: print-lspping.c,v 1.11 2024/09/02 16:15:32 christos Exp $");
19 #endif
20 
21 /* \summary: MPLS LSP PING printer */
22 
23 /* specification: RFC 4379 */
24 
25 #include <config.h>
26 
27 #include "netdissect-stdinc.h"
28 
29 #define ND_LONGJMP_FROM_TCHECK
30 #include "netdissect.h"
31 #include "extract.h"
32 #include "addrtoname.h"
33 #include "ntp.h"
34 
35 #include "l2vpn.h"
36 #include "oui.h"
37 
38 
39 /*
40  * LSPPING common header
41  *
42  *  0                   1                   2                   3
43  *  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
44  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
45  * |         Version Number        |         Must Be Zero          |
46  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
47  * |  Message Type |   Reply mode  |  Return Code  | Return Subcode|
48  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
49  * |                        Sender's Handle                        |
50  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
51  * |                        Sequence Number                        |
52  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
53  * |                    TimeStamp Sent (seconds)                   |
54  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
55  * |                  TimeStamp Sent (microseconds)                |
56  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
57  * |                  TimeStamp Received (seconds)                 |
58  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
59  * |                TimeStamp Received (microseconds)              |
60  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
61  * |                            TLVs ...                           |
62  * .                                                               .
63  * .                                                               .
64  * .                                                               .
65  */
66 
67 struct lspping_common_header {
68     nd_uint16_t version;
69     nd_uint16_t global_flags;
70     nd_uint8_t  msg_type;
71     nd_uint8_t  reply_mode;
72     nd_uint8_t  return_code;
73     nd_uint8_t  return_subcode;
74     nd_uint32_t sender_handle;
75     nd_uint32_t seq_number;
76     struct l_fixedpt ts_sent;
77     struct l_fixedpt ts_rcvd;
78 };
79 
80 #define LSPPING_VERSION            1
81 
82 static const struct tok lspping_msg_type_values[] = {
83     { 1, "MPLS Echo Request"},
84     { 2, "MPLS Echo Reply"},
85     { 0, NULL}
86 };
87 
88 static const struct tok lspping_reply_mode_values[] = {
89     { 1, "Do not reply"},
90     { 2, "Reply via an IPv4/IPv6 UDP packet"},
91     { 3, "Reply via an IPv4/IPv6 UDP packet with Router Alert"},
92     { 4, "Reply via application level control channel"},
93     { 0, NULL}
94 };
95 
96 static const struct tok lspping_return_code_values[] = {
97     {  0, "No return code or return code contained in the Error Code TLV"},
98     {  1, "Malformed echo request received"},
99     {  2, "One or more of the TLVs was not understood"},
100     {  3, "Replying router is an egress for the FEC at stack depth"},
101     {  4, "Replying router has no mapping for the FEC at stack depth"},
102     {  5, "Reserved"},
103     {  6, "Reserved"},
104     {  7, "Reserved"},
105     {  8, "Label switched at stack-depth"},
106     {  9, "Label switched but no MPLS forwarding at stack-depth"},
107     { 10, "Mapping for this FEC is not the given label at stack depth"},
108     { 11, "No label entry at stack-depth"},
109     { 12, "Protocol not associated with interface at FEC stack depth"},
110     { 13, "Premature termination of ping due to label stack shrinking to a single label"},
111     { 0,  NULL},
112 };
113 
114 
115 /*
116  * LSPPING TLV header
117  *  0                   1                   2                   3
118  *  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
119  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
120  * |             Type              |            Length             |
121  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
122  * |                             Value                             |
123  * .                                                               .
124  * .                                                               .
125  * .                                                               .
126  * |                                                               |
127  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
128  */
129 
130 struct lspping_tlv_header {
131     nd_uint16_t type;
132     nd_uint16_t length;
133 };
134 
135 #define	LSPPING_TLV_TARGET_FEC_STACK      1
136 #define	LSPPING_TLV_DOWNSTREAM_MAPPING    2
137 #define	LSPPING_TLV_PAD                   3
138 /* not assigned                           4 */
139 #define LSPPING_TLV_VENDOR_ENTERPRISE     5
140 #define LSPPING_TLV_VENDOR_ENTERPRISE_LEN 4
141 /* not assigned                           6 */
142 #define LSPPING_TLV_INTERFACE_LABEL_STACK 7
143 /* not assigned                           8 */
144 #define	LSPPING_TLV_ERROR_CODE            9
145 #define LSPPING_TLV_REPLY_TOS_BYTE        10
146 #define	LSPPING_TLV_BFD_DISCRIMINATOR     15 /* draft-ietf-bfd-mpls-02 */
147 #define LSPPING_TLV_BFD_DISCRIMINATOR_LEN 4
148 #define	LSPPING_TLV_VENDOR_PRIVATE        0xfc00
149 
150 static const struct tok lspping_tlv_values[] = {
151     { LSPPING_TLV_TARGET_FEC_STACK, "Target FEC Stack" },
152     { LSPPING_TLV_DOWNSTREAM_MAPPING, "Downstream Mapping" },
153     { LSPPING_TLV_PAD, "Pad" },
154     { LSPPING_TLV_ERROR_CODE, "Error Code" },
155     { LSPPING_TLV_VENDOR_ENTERPRISE, "Vendor Enterprise Code" },
156     { LSPPING_TLV_INTERFACE_LABEL_STACK, "Interface Label Stack" },
157     { LSPPING_TLV_REPLY_TOS_BYTE, "Reply TOS Byte" },
158     { LSPPING_TLV_BFD_DISCRIMINATOR, "BFD Discriminator" },
159     { LSPPING_TLV_VENDOR_PRIVATE, "Vendor Private Code" },
160     { 0, NULL}
161 };
162 
163 #define	LSPPING_TLV_TARGETFEC_SUBTLV_LDP_IPV4       1
164 #define	LSPPING_TLV_TARGETFEC_SUBTLV_LDP_IPV6       2
165 #define	LSPPING_TLV_TARGETFEC_SUBTLV_RSVP_IPV4      3
166 #define	LSPPING_TLV_TARGETFEC_SUBTLV_RSVP_IPV6      4
167 /* not assigned                                     5 */
168 #define	LSPPING_TLV_TARGETFEC_SUBTLV_L3VPN_IPV4     6
169 #define	LSPPING_TLV_TARGETFEC_SUBTLV_L3VPN_IPV6     7
170 #define	LSPPING_TLV_TARGETFEC_SUBTLV_L2VPN_ENDPT    8
171 #define	LSPPING_TLV_TARGETFEC_SUBTLV_FEC_128_PW_OLD 9
172 #define	LSPPING_TLV_TARGETFEC_SUBTLV_FEC_128_PW     10
173 #define	LSPPING_TLV_TARGETFEC_SUBTLV_FEC_129_PW     11
174 #define	LSPPING_TLV_TARGETFEC_SUBTLV_BGP_IPV4       12
175 #define	LSPPING_TLV_TARGETFEC_SUBTLV_BGP_IPV6       13
176 #define	LSPPING_TLV_TARGETFEC_SUBTLV_GENERIC_IPV4   14
177 #define	LSPPING_TLV_TARGETFEC_SUBTLV_GENERIC_IPV6   15
178 #define	LSPPING_TLV_TARGETFEC_SUBTLV_NIL_FEC        16
179 
180 static const struct tok lspping_tlvtargetfec_subtlv_values[] = {
181     { LSPPING_TLV_TARGETFEC_SUBTLV_LDP_IPV4, "LDP IPv4 prefix"},
182     { LSPPING_TLV_TARGETFEC_SUBTLV_LDP_IPV6, "LDP IPv6 prefix"},
183     { LSPPING_TLV_TARGETFEC_SUBTLV_RSVP_IPV4, "RSVP IPv4 Session Query"},
184     { LSPPING_TLV_TARGETFEC_SUBTLV_RSVP_IPV6, "RSVP IPv6 Session Query"},
185     { 5, "Reserved"},
186     { LSPPING_TLV_TARGETFEC_SUBTLV_L3VPN_IPV4, "VPN IPv4 prefix"},
187     { LSPPING_TLV_TARGETFEC_SUBTLV_L3VPN_IPV6, "VPN IPv6 prefix"},
188     { LSPPING_TLV_TARGETFEC_SUBTLV_L2VPN_ENDPT, "L2 VPN endpoint"},
189     { LSPPING_TLV_TARGETFEC_SUBTLV_FEC_128_PW_OLD, "FEC 128 pseudowire (old)"},
190     { LSPPING_TLV_TARGETFEC_SUBTLV_FEC_128_PW, "FEC 128 pseudowire"},
191     { LSPPING_TLV_TARGETFEC_SUBTLV_BGP_IPV4, "BGP labeled IPv4 prefix"},
192     { LSPPING_TLV_TARGETFEC_SUBTLV_BGP_IPV6, "BGP labeled IPv6 prefix"},
193     { 0, NULL}
194 };
195 
196 /*
197  *  0                   1                   2                   3
198  *  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
199  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
200  * |                          IPv4 prefix                          |
201  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
202  * | Prefix Length |         Must Be Zero                          |
203  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
204  */
205 struct lspping_tlv_targetfec_subtlv_ldp_ipv4_t {
206     nd_ipv4    prefix;
207     nd_uint8_t prefix_len;
208 };
209 
210 /*
211  *  0                   1                   2                   3
212  *  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
213  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
214  * |                          IPv6 prefix                          |
215  * |                          (16 octets)                          |
216  * |                                                               |
217  * |                                                               |
218  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
219  * | Prefix Length |         Must Be Zero                          |
220  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
221  */
222 struct lspping_tlv_targetfec_subtlv_ldp_ipv6_t {
223     nd_ipv6    prefix;
224     nd_uint8_t prefix_len;
225 };
226 
227 /*
228  *  0                   1                   2                   3
229  *  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
230  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
231  * |                 IPv4 tunnel end point address                 |
232  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
233  * |          Must Be Zero         |     Tunnel ID                 |
234  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
235  * |                       Extended Tunnel ID                      |
236  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
237  * |                   IPv4 tunnel sender address                  |
238  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
239  * |          Must Be Zero         |            LSP ID             |
240  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
241  */
242 struct lspping_tlv_targetfec_subtlv_rsvp_ipv4_t {
243     nd_ipv4     tunnel_endpoint;
244     nd_byte     res[2];
245     nd_uint16_t tunnel_id;
246     nd_ipv4     extended_tunnel_id;
247     nd_ipv4     tunnel_sender;
248     nd_byte     res2[2];
249     nd_uint16_t lsp_id;
250 };
251 
252 /*
253  *  0                   1                   2                   3
254  *  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
255  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
256  * |                 IPv6 tunnel end point address                 |
257  * |                                                               |
258  * |                                                               |
259  * |                                                               |
260  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
261  * |          Must Be Zero         |          Tunnel ID            |
262  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
263  * |                       Extended Tunnel ID                      |
264  * |                                                               |
265  * |                                                               |
266  * |                                                               |
267  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
268  * |                   IPv6 tunnel sender address                  |
269  * |                                                               |
270  * |                                                               |
271  * |                                                               |
272  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
273  * |          Must Be Zero         |            LSP ID             |
274  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
275  */
276 struct lspping_tlv_targetfec_subtlv_rsvp_ipv6_t {
277     nd_ipv6     tunnel_endpoint;
278     nd_byte     res[2];
279     nd_uint16_t tunnel_id;
280     nd_ipv6     extended_tunnel_id;
281     nd_ipv6     tunnel_sender;
282     nd_byte     res2[2];
283     nd_uint16_t lsp_id;
284 };
285 
286 /*
287  *  0                   1                   2                   3
288  *  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
289  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
290  * |                      Route Distinguisher                      |
291  * |                          (8 octets)                           |
292  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
293  * |                         IPv4 prefix                           |
294  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
295  * | Prefix Length |                 Must Be Zero                  |
296  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
297  */
298 struct lspping_tlv_targetfec_subtlv_l3vpn_ipv4_t {
299     nd_byte    rd[8];
300     nd_ipv4    prefix;
301     nd_uint8_t prefix_len;
302 };
303 
304 /*
305  *  0                   1                   2                   3
306  *  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
307  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
308  * |                      Route Distinguisher                      |
309  * |                          (8 octets)                           |
310  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
311  * |                          IPv6 prefix                          |
312  * |                          (16 octets)                          |
313  * |                                                               |
314  * |                                                               |
315  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
316  * | Prefix Length |                 Must Be Zero                  |
317  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
318  */
319 struct lspping_tlv_targetfec_subtlv_l3vpn_ipv6_t {
320     nd_byte    rd[8];
321     nd_ipv6    prefix;
322     nd_uint8_t prefix_len;
323 };
324 
325 /*
326  *  0                   1                   2                   3
327  *  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
328  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
329  * |                      Route Distinguisher                      |
330  * |                          (8 octets)                           |
331  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
332  * |         Sender's VE ID        |       Receiver's VE ID        |
333  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
334  * |      Encapsulation Type       |         Must Be Zero          |
335  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
336  *  0                   1                   2                   3
337  */
338 struct lspping_tlv_targetfec_subtlv_l2vpn_endpt_t {
339     nd_byte     rd[8];
340     nd_uint16_t sender_ve_id;
341     nd_uint16_t receiver_ve_id;
342     nd_uint16_t encapsulation;
343 };
344 
345 /*
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  * |                      Remote PE Address                        |
349  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
350  * |                             PW ID                             |
351  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
352  * |            PW Type            |          Must Be Zero         |
353  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
354  */
355 struct lspping_tlv_targetfec_subtlv_fec_128_pw_old {
356     nd_ipv4     remote_pe_address;
357     nd_uint32_t pw_id;
358     nd_uint16_t pw_type;
359 };
360 
361 /*
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  * |                     Sender's PE Address                       |
365  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
366  * |                      Remote PE Address                        |
367  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
368  * |                             PW ID                             |
369  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
370  * |            PW Type            |          Must Be Zero         |
371  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
372  */
373 struct lspping_tlv_targetfec_subtlv_fec_128_pw {
374     nd_ipv4     sender_pe_address;
375     nd_ipv4     remote_pe_address;
376     nd_uint32_t pw_id;
377     nd_uint16_t pw_type;
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  * |                         IPv4 prefix                           |
384  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
385  * | Prefix Length |                 Must Be Zero                  |
386  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
387  */
388 struct lspping_tlv_targetfec_subtlv_bgp_ipv4_t {
389     nd_ipv4    prefix;
390     nd_uint8_t prefix_len;
391 };
392 
393 /*
394  * 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
395  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
396  * |                          IPv6 prefix                          |
397  * |                          (16 octets)                          |
398  * |                                                               |
399  * |                                                               |
400  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
401  * | Prefix Length |                 Must Be Zero                  |
402  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
403  */
404 struct lspping_tlv_targetfec_subtlv_bgp_ipv6_t {
405     nd_ipv6    prefix;
406     nd_uint8_t prefix_len;
407 };
408 
409 /*
410  *  0                   1                   2                   3
411  *  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
412  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
413  * |               MTU             | Address Type  |  Resvd (SBZ)  |
414  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
415  * |             Downstream IP Address (4 or 16 octets)            |
416  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
417  * |         Downstream Interface Address (4 or 16 octets)         |
418  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
419  * | Multipath Type| Depth Limit   |        Multipath Length       |
420  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
421  * .                                                               .
422  * .                     (Multipath Information)                   .
423  * .                                                               .
424  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
425  * |               Downstream Label                |    Protocol   |
426  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
427  * .                                                               .
428  * .                                                               .
429  * .                                                               .
430  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
431  * |               Downstream Label                |    Protocol   |
432  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
433  */
434 /* Enough to get the address type */
435 struct lspping_tlv_downstream_map_t {
436     nd_uint16_t mtu;
437     nd_uint8_t  address_type;
438     nd_uint8_t  ds_flags;
439 };
440 
441 struct lspping_tlv_downstream_map_ipv4_t {
442     nd_uint16_t mtu;
443     nd_uint8_t  address_type;
444     nd_uint8_t  ds_flags;
445     nd_ipv4     downstream_ip;
446     nd_ipv4     downstream_interface;
447 };
448 
449 struct lspping_tlv_downstream_map_ipv4_unmb_t {
450     nd_uint16_t mtu;
451     nd_uint8_t  address_type;
452     nd_uint8_t  ds_flags;
453     nd_ipv4     downstream_ip;
454     nd_uint32_t downstream_interface;
455 };
456 
457 struct lspping_tlv_downstream_map_ipv6_t {
458     nd_uint16_t mtu;
459     nd_uint8_t  address_type;
460     nd_uint8_t  ds_flags;
461     nd_ipv6     downstream_ip;
462     nd_ipv6     downstream_interface;
463 };
464 
465 struct lspping_tlv_downstream_map_ipv6_unmb_t {
466     nd_uint16_t mtu;
467     nd_uint8_t  address_type;
468     nd_uint8_t  ds_flags;
469     nd_ipv6     downstream_ip;
470     nd_uint32_t downstream_interface;
471 };
472 
473 struct lspping_tlv_downstream_map_info_t {
474     nd_uint8_t  multipath_type;
475     nd_uint8_t  depth_limit;
476     nd_uint16_t multipath_length;
477 };
478 
479 #define LSPPING_AFI_IPV4      1
480 #define LSPPING_AFI_IPV4_UNMB 2
481 #define LSPPING_AFI_IPV6      3
482 #define LSPPING_AFI_IPV6_UNMB 4
483 
484 static const struct tok lspping_tlv_downstream_addr_values[] = {
485     { LSPPING_AFI_IPV4,      "IPv4"},
486     { LSPPING_AFI_IPV4_UNMB, "Unnumbered IPv4"},
487     { LSPPING_AFI_IPV6,      "IPv6"},
488     { LSPPING_AFI_IPV6_UNMB, "IPv6"},
489     { 0, NULL}
490 };
491 
492 void
493 lspping_print(netdissect_options *ndo,
494               const u_char *pptr, u_int len)
495 {
496     const struct lspping_common_header *lspping_com_header;
497     const struct lspping_tlv_header *lspping_tlv_header;
498     const struct lspping_tlv_header *lspping_subtlv_header;
499     const u_char *tptr,*tlv_tptr,*subtlv_tptr;
500     u_int return_code, return_subcode;
501     u_int tlen,lspping_tlv_len,lspping_tlv_type,tlv_tlen;
502     int tlv_hexdump,subtlv_hexdump;
503     u_int lspping_subtlv_len,lspping_subtlv_type;
504     uint32_t int_part, fraction;
505     u_int address_type;
506 
507     union {
508         const struct lspping_tlv_downstream_map_t *lspping_tlv_downstream_map;
509         const struct lspping_tlv_downstream_map_ipv4_t *lspping_tlv_downstream_map_ipv4;
510         const struct lspping_tlv_downstream_map_ipv4_unmb_t *lspping_tlv_downstream_map_ipv4_unmb;
511         const struct lspping_tlv_downstream_map_ipv6_t *lspping_tlv_downstream_map_ipv6;
512         const struct lspping_tlv_downstream_map_ipv6_unmb_t *lspping_tlv_downstream_map_ipv6_unmb;
513         const struct lspping_tlv_downstream_map_info_t  *lspping_tlv_downstream_map_info;
514     } tlv_ptr;
515 
516     union {
517         const struct lspping_tlv_targetfec_subtlv_ldp_ipv4_t *lspping_tlv_targetfec_subtlv_ldp_ipv4;
518         const struct lspping_tlv_targetfec_subtlv_ldp_ipv6_t *lspping_tlv_targetfec_subtlv_ldp_ipv6;
519         const struct lspping_tlv_targetfec_subtlv_rsvp_ipv4_t *lspping_tlv_targetfec_subtlv_rsvp_ipv4;
520         const struct lspping_tlv_targetfec_subtlv_rsvp_ipv6_t *lspping_tlv_targetfec_subtlv_rsvp_ipv6;
521         const struct lspping_tlv_targetfec_subtlv_l3vpn_ipv4_t *lspping_tlv_targetfec_subtlv_l3vpn_ipv4;
522         const struct lspping_tlv_targetfec_subtlv_l3vpn_ipv6_t *lspping_tlv_targetfec_subtlv_l3vpn_ipv6;
523         const struct lspping_tlv_targetfec_subtlv_l2vpn_endpt_t *lspping_tlv_targetfec_subtlv_l2vpn_endpt;
524         const struct lspping_tlv_targetfec_subtlv_fec_128_pw_old *lspping_tlv_targetfec_subtlv_l2vpn_vcid_old;
525         const struct lspping_tlv_targetfec_subtlv_fec_128_pw *lspping_tlv_targetfec_subtlv_l2vpn_vcid;
526         const struct lspping_tlv_targetfec_subtlv_bgp_ipv4_t *lspping_tlv_targetfec_subtlv_bgp_ipv4;
527         const struct lspping_tlv_targetfec_subtlv_bgp_ipv6_t *lspping_tlv_targetfec_subtlv_bgp_ipv6;
528     } subtlv_ptr;
529 
530     ndo->ndo_protocol = "lspping";
531     tptr=pptr;
532     lspping_com_header = (const struct lspping_common_header *)pptr;
533     if (len < sizeof(struct lspping_common_header))
534         goto tooshort;
535     ND_TCHECK_SIZE(lspping_com_header);
536 
537     /*
538      * Sanity checking of the header.
539      */
540     if (GET_BE_U_2(lspping_com_header->version) != LSPPING_VERSION) {
541 	ND_PRINT("LSP-PING version %u packet not supported",
542                GET_BE_U_2(lspping_com_header->version));
543 	return;
544     }
545 
546     /* in non-verbose mode just lets print the basic Message Type*/
547     if (ndo->ndo_vflag < 1) {
548         ND_PRINT("LSP-PINGv%u, %s, seq %u, length: %u",
549                GET_BE_U_2(lspping_com_header->version),
550                tok2str(lspping_msg_type_values, "unknown (%u)",GET_U_1(lspping_com_header->msg_type)),
551                GET_BE_U_4(lspping_com_header->seq_number),
552                len);
553         return;
554     }
555 
556     /* ok they seem to want to know everything - lets fully decode it */
557 
558     tlen=len;
559 
560     ND_PRINT("\n\tLSP-PINGv%u, msg-type: %s (%u), length: %u\n\t  reply-mode: %s (%u)",
561            GET_BE_U_2(lspping_com_header->version),
562            tok2str(lspping_msg_type_values, "unknown",GET_U_1(lspping_com_header->msg_type)),
563            GET_U_1(lspping_com_header->msg_type),
564            len,
565            tok2str(lspping_reply_mode_values, "unknown",GET_U_1(lspping_com_header->reply_mode)),
566            GET_U_1(lspping_com_header->reply_mode));
567 
568     /*
569      *  the following return codes require that the subcode is attached
570      *  at the end of the translated token output
571      */
572     return_code = GET_U_1(lspping_com_header->return_code);
573     return_subcode = GET_U_1(lspping_com_header->return_subcode);
574     if (return_code == 3 ||
575         return_code == 4 ||
576         return_code == 8 ||
577         return_code == 10 ||
578         return_code == 11 ||
579         return_code == 12 )
580         ND_PRINT("\n\t  Return Code: %s %u (%u)\n\t  Return Subcode: (%u)",
581                tok2str(lspping_return_code_values, "unknown",return_code),
582                return_subcode,
583                return_code,
584                return_subcode);
585     else
586         ND_PRINT("\n\t  Return Code: %s (%u)\n\t  Return Subcode: (%u)",
587                tok2str(lspping_return_code_values, "unknown",return_code),
588                return_code,
589                return_subcode);
590 
591     ND_PRINT("\n\t  Sender Handle: 0x%08x, Sequence: %u",
592            GET_BE_U_4(lspping_com_header->sender_handle),
593            GET_BE_U_4(lspping_com_header->seq_number));
594 
595     ND_PRINT("\n\t  Sender Timestamp: ");
596     p_ntp_time(ndo, &lspping_com_header->ts_sent);
597     ND_PRINT(" ");
598 
599     int_part=GET_BE_U_4(lspping_com_header->ts_rcvd.int_part);
600     fraction=GET_BE_U_4(lspping_com_header->ts_rcvd.fraction);
601     ND_PRINT("Receiver Timestamp: ");
602     if (! (int_part == 0 && fraction == 0))
603         p_ntp_time(ndo, &lspping_com_header->ts_rcvd);
604     else
605         ND_PRINT("no timestamp");
606 
607     tptr+=sizeof(struct lspping_common_header);
608     tlen-=sizeof(struct lspping_common_header);
609 
610     while (tlen != 0) {
611         /* Does the TLV go past the end of the packet? */
612         if (tlen < sizeof(struct lspping_tlv_header))
613             goto tooshort;
614 
615         lspping_tlv_header = (const struct lspping_tlv_header *)tptr;
616         lspping_tlv_type=GET_BE_U_2(lspping_tlv_header->type);
617         lspping_tlv_len=GET_BE_U_2(lspping_tlv_header->length);
618 
619         ND_PRINT("\n\t  %s TLV (%u), length: %u",
620                tok2str(lspping_tlv_values,
621                        "Unknown",
622                        lspping_tlv_type),
623                lspping_tlv_type,
624                lspping_tlv_len);
625 
626         /* some little sanity checking */
627         if (lspping_tlv_len == 0) {
628             tptr+=sizeof(struct lspping_tlv_header);
629             tlen-=sizeof(struct lspping_tlv_header);
630             continue;    /* no value to dissect */
631         }
632 
633         tlv_tptr=tptr+sizeof(struct lspping_tlv_header);
634         tlv_tlen=lspping_tlv_len; /* header not included -> no adjustment */
635 
636         /* Does the TLV go past the end of the packet? */
637         if (tlen < lspping_tlv_len+sizeof(struct lspping_tlv_header))
638             goto tooshort;
639         /* did we capture enough for fully decoding the tlv ? */
640         ND_TCHECK_LEN(tlv_tptr, lspping_tlv_len);
641         tlv_hexdump=FALSE;
642 
643         switch(lspping_tlv_type) {
644         case LSPPING_TLV_TARGET_FEC_STACK:
645             while (tlv_tlen != 0) {
646                 /* Does the subTLV header go past the end of the TLV? */
647                 if (tlv_tlen < sizeof(struct lspping_tlv_header)) {
648                     ND_PRINT("\n\t      TLV is too short");
649                     tlv_hexdump = TRUE;
650                     goto tlv_tooshort;
651                 }
652                 subtlv_hexdump=FALSE;
653 
654                 lspping_subtlv_header = (const struct lspping_tlv_header *)tlv_tptr;
655                 lspping_subtlv_type=GET_BE_U_2(lspping_subtlv_header->type);
656                 lspping_subtlv_len=GET_BE_U_2(lspping_subtlv_header->length);
657                 subtlv_tptr=tlv_tptr+sizeof(struct lspping_tlv_header);
658 
659                 /* Does the subTLV go past the end of the TLV? */
660                 if (tlv_tlen < lspping_subtlv_len+sizeof(struct lspping_tlv_header)) {
661                     ND_PRINT("\n\t      TLV is too short");
662                     tlv_hexdump = TRUE;
663                     goto tlv_tooshort;
664                 }
665 
666                 /* Did we capture enough for fully decoding the subTLV? */
667                 ND_TCHECK_LEN(subtlv_tptr, lspping_subtlv_len);
668 
669                 ND_PRINT("\n\t    %s subTLV (%u), length: %u",
670                        tok2str(lspping_tlvtargetfec_subtlv_values,
671                                "Unknown",
672                                lspping_subtlv_type),
673                        lspping_subtlv_type,
674                        lspping_subtlv_len);
675 
676                 switch(lspping_subtlv_type) {
677 
678                 case LSPPING_TLV_TARGETFEC_SUBTLV_LDP_IPV4:
679                     /* Is the subTLV length correct? */
680                     if (lspping_subtlv_len != 5) {
681                         ND_PRINT("\n\t      invalid subTLV length, should be 5");
682                         subtlv_hexdump=TRUE; /* unknown subTLV just hexdump it */
683                     } else {
684                         subtlv_ptr.lspping_tlv_targetfec_subtlv_ldp_ipv4 =
685                             (const struct lspping_tlv_targetfec_subtlv_ldp_ipv4_t *)subtlv_tptr;
686                         ND_PRINT("\n\t      %s/%u",
687                                GET_IPADDR_STRING(subtlv_ptr.lspping_tlv_targetfec_subtlv_ldp_ipv4->prefix),
688                                GET_U_1(subtlv_ptr.lspping_tlv_targetfec_subtlv_ldp_ipv4->prefix_len));
689                     }
690                     break;
691 
692                 case LSPPING_TLV_TARGETFEC_SUBTLV_LDP_IPV6:
693                     /* Is the subTLV length correct? */
694                     if (lspping_subtlv_len != 17) {
695                         ND_PRINT("\n\t      invalid subTLV length, should be 17");
696                         subtlv_hexdump=TRUE; /* unknown subTLV just hexdump it */
697                     } else {
698                         subtlv_ptr.lspping_tlv_targetfec_subtlv_ldp_ipv6 =
699                             (const struct lspping_tlv_targetfec_subtlv_ldp_ipv6_t *)subtlv_tptr;
700                         ND_PRINT("\n\t      %s/%u",
701                                GET_IP6ADDR_STRING(subtlv_ptr.lspping_tlv_targetfec_subtlv_ldp_ipv6->prefix),
702                                GET_U_1(subtlv_ptr.lspping_tlv_targetfec_subtlv_ldp_ipv6->prefix_len));
703                     }
704                     break;
705 
706                 case LSPPING_TLV_TARGETFEC_SUBTLV_BGP_IPV4:
707                     /* Is the subTLV length correct? */
708                     if (lspping_subtlv_len != 5) {
709                         ND_PRINT("\n\t      invalid subTLV length, should be 5");
710                         subtlv_hexdump=TRUE; /* unknown subTLV just hexdump it */
711                     } else {
712                         subtlv_ptr.lspping_tlv_targetfec_subtlv_bgp_ipv4 =
713                             (const struct lspping_tlv_targetfec_subtlv_bgp_ipv4_t *)subtlv_tptr;
714                         ND_PRINT("\n\t      %s/%u",
715                                GET_IPADDR_STRING(subtlv_ptr.lspping_tlv_targetfec_subtlv_bgp_ipv4->prefix),
716                                GET_U_1(subtlv_ptr.lspping_tlv_targetfec_subtlv_bgp_ipv4->prefix_len));
717                     }
718                     break;
719 
720                 case LSPPING_TLV_TARGETFEC_SUBTLV_BGP_IPV6:
721                     /* Is the subTLV length correct? */
722                     if (lspping_subtlv_len != 17) {
723                         ND_PRINT("\n\t      invalid subTLV length, should be 17");
724                         subtlv_hexdump=TRUE; /* unknown subTLV just hexdump it */
725                     } else {
726                         subtlv_ptr.lspping_tlv_targetfec_subtlv_bgp_ipv6 =
727                             (const struct lspping_tlv_targetfec_subtlv_bgp_ipv6_t *)subtlv_tptr;
728                         ND_PRINT("\n\t      %s/%u",
729                                GET_IP6ADDR_STRING(subtlv_ptr.lspping_tlv_targetfec_subtlv_bgp_ipv6->prefix),
730                                GET_U_1(subtlv_ptr.lspping_tlv_targetfec_subtlv_bgp_ipv6->prefix_len));
731                     }
732                     break;
733 
734                 case LSPPING_TLV_TARGETFEC_SUBTLV_RSVP_IPV4:
735                     /* Is the subTLV length correct? */
736                     if (lspping_subtlv_len != 20) {
737                         ND_PRINT("\n\t      invalid subTLV length, should be 20");
738                         subtlv_hexdump=TRUE; /* unknown subTLV just hexdump it */
739                     } else {
740                         subtlv_ptr.lspping_tlv_targetfec_subtlv_rsvp_ipv4 =
741                             (const struct lspping_tlv_targetfec_subtlv_rsvp_ipv4_t *)subtlv_tptr;
742                         ND_PRINT("\n\t      tunnel end-point %s, tunnel sender %s, lsp-id 0x%04x"
743                                "\n\t      tunnel-id 0x%04x, extended tunnel-id %s",
744                                GET_IPADDR_STRING(subtlv_ptr.lspping_tlv_targetfec_subtlv_rsvp_ipv4->tunnel_endpoint),
745                                GET_IPADDR_STRING(subtlv_ptr.lspping_tlv_targetfec_subtlv_rsvp_ipv4->tunnel_sender),
746                                GET_BE_U_2(subtlv_ptr.lspping_tlv_targetfec_subtlv_rsvp_ipv4->lsp_id),
747                                GET_BE_U_2(subtlv_ptr.lspping_tlv_targetfec_subtlv_rsvp_ipv4->tunnel_id),
748                                GET_IPADDR_STRING(subtlv_ptr.lspping_tlv_targetfec_subtlv_rsvp_ipv4->extended_tunnel_id));
749                     }
750                     break;
751 
752                 case LSPPING_TLV_TARGETFEC_SUBTLV_RSVP_IPV6:
753                     /* Is the subTLV length correct? */
754                     if (lspping_subtlv_len != 56) {
755                         ND_PRINT("\n\t      invalid subTLV length, should be 56");
756                         subtlv_hexdump=TRUE; /* unknown subTLV just hexdump it */
757                     } else {
758                         subtlv_ptr.lspping_tlv_targetfec_subtlv_rsvp_ipv6 =
759                             (const struct lspping_tlv_targetfec_subtlv_rsvp_ipv6_t *)subtlv_tptr;
760                         ND_PRINT("\n\t      tunnel end-point %s, tunnel sender %s, lsp-id 0x%04x"
761                                "\n\t      tunnel-id 0x%04x, extended tunnel-id %s",
762                                GET_IP6ADDR_STRING(subtlv_ptr.lspping_tlv_targetfec_subtlv_rsvp_ipv6->tunnel_endpoint),
763                                GET_IP6ADDR_STRING(subtlv_ptr.lspping_tlv_targetfec_subtlv_rsvp_ipv6->tunnel_sender),
764                                GET_BE_U_2(subtlv_ptr.lspping_tlv_targetfec_subtlv_rsvp_ipv6->lsp_id),
765                                GET_BE_U_2(subtlv_ptr.lspping_tlv_targetfec_subtlv_rsvp_ipv6->tunnel_id),
766                                GET_IP6ADDR_STRING(subtlv_ptr.lspping_tlv_targetfec_subtlv_rsvp_ipv6->extended_tunnel_id));
767                     }
768                     break;
769 
770                 case LSPPING_TLV_TARGETFEC_SUBTLV_L3VPN_IPV4:
771                     /* Is the subTLV length correct? */
772                     if (lspping_subtlv_len != 13) {
773                         ND_PRINT("\n\t      invalid subTLV length, should be 13");
774                         subtlv_hexdump=TRUE; /* unknown subTLV just hexdump it */
775                     } else {
776                         subtlv_ptr.lspping_tlv_targetfec_subtlv_l3vpn_ipv4 =
777                             (const struct lspping_tlv_targetfec_subtlv_l3vpn_ipv4_t *)subtlv_tptr;
778                         ND_PRINT("\n\t      RD: %s, %s/%u",
779                                bgp_vpn_rd_print(ndo, subtlv_ptr.lspping_tlv_targetfec_subtlv_l3vpn_ipv4->rd),
780                                GET_IPADDR_STRING(subtlv_ptr.lspping_tlv_targetfec_subtlv_l3vpn_ipv4->prefix),
781                                GET_U_1(subtlv_ptr.lspping_tlv_targetfec_subtlv_l3vpn_ipv4->prefix_len));
782                     }
783                     break;
784 
785                 case LSPPING_TLV_TARGETFEC_SUBTLV_L3VPN_IPV6:
786                     /* Is the subTLV length correct? */
787                     if (lspping_subtlv_len != 25) {
788                         ND_PRINT("\n\t      invalid subTLV length, should be 25");
789                         subtlv_hexdump=TRUE; /* unknown subTLV just hexdump it */
790                     } else {
791                         subtlv_ptr.lspping_tlv_targetfec_subtlv_l3vpn_ipv6 =
792                             (const struct lspping_tlv_targetfec_subtlv_l3vpn_ipv6_t *)subtlv_tptr;
793                         ND_PRINT("\n\t      RD: %s, %s/%u",
794                                bgp_vpn_rd_print(ndo, subtlv_ptr.lspping_tlv_targetfec_subtlv_l3vpn_ipv6->rd),
795                                GET_IP6ADDR_STRING(subtlv_ptr.lspping_tlv_targetfec_subtlv_l3vpn_ipv6->prefix),
796                                GET_U_1(subtlv_ptr.lspping_tlv_targetfec_subtlv_l3vpn_ipv6->prefix_len));
797                     }
798                     break;
799 
800                 case LSPPING_TLV_TARGETFEC_SUBTLV_L2VPN_ENDPT:
801                     /* Is the subTLV length correct? */
802                     if (lspping_subtlv_len != 14) {
803                         ND_PRINT("\n\t      invalid subTLV length, should be 14");
804                         subtlv_hexdump=TRUE; /* unknown subTLV just hexdump it */
805                     } else {
806                         subtlv_ptr.lspping_tlv_targetfec_subtlv_l2vpn_endpt =
807                             (const struct lspping_tlv_targetfec_subtlv_l2vpn_endpt_t *)subtlv_tptr;
808                         ND_PRINT("\n\t      RD: %s, Sender VE ID: %u, Receiver VE ID: %u"
809                                "\n\t      Encapsulation Type: %s (%u)",
810                                bgp_vpn_rd_print(ndo, subtlv_ptr.lspping_tlv_targetfec_subtlv_l2vpn_endpt->rd),
811                                GET_BE_U_2(subtlv_ptr.lspping_tlv_targetfec_subtlv_l2vpn_endpt->sender_ve_id),
812                                GET_BE_U_2(subtlv_ptr.lspping_tlv_targetfec_subtlv_l2vpn_endpt->receiver_ve_id),
813                                tok2str(mpls_pw_types_values,
814                                        "unknown",
815                                        GET_BE_U_2(subtlv_ptr.lspping_tlv_targetfec_subtlv_l2vpn_endpt->encapsulation)),
816                                GET_BE_U_2(subtlv_ptr.lspping_tlv_targetfec_subtlv_l2vpn_endpt->encapsulation));
817                     }
818                     break;
819 
820                     /* the old L2VPN VCID subTLV does not have support for the sender field */
821                 case LSPPING_TLV_TARGETFEC_SUBTLV_FEC_128_PW_OLD:
822                     /* Is the subTLV length correct? */
823                     if (lspping_subtlv_len != 10) {
824                         ND_PRINT("\n\t      invalid subTLV length, should be 10");
825                         subtlv_hexdump=TRUE; /* unknown subTLV just hexdump it */
826                     } else {
827                         subtlv_ptr.lspping_tlv_targetfec_subtlv_l2vpn_vcid_old =
828                             (const struct lspping_tlv_targetfec_subtlv_fec_128_pw_old *)subtlv_tptr;
829                         ND_PRINT("\n\t      Remote PE: %s"
830                                "\n\t      PW ID: 0x%08x, PW Type: %s (%u)",
831                                GET_IPADDR_STRING(subtlv_ptr.lspping_tlv_targetfec_subtlv_l2vpn_vcid_old->remote_pe_address),
832                                GET_BE_U_4(subtlv_ptr.lspping_tlv_targetfec_subtlv_l2vpn_vcid_old->pw_id),
833                                tok2str(mpls_pw_types_values,
834                                        "unknown",
835                                        GET_BE_U_2(subtlv_ptr.lspping_tlv_targetfec_subtlv_l2vpn_vcid_old->pw_type)),
836                                GET_BE_U_2(subtlv_ptr.lspping_tlv_targetfec_subtlv_l2vpn_vcid_old->pw_type));
837                     }
838                     break;
839 
840                 case LSPPING_TLV_TARGETFEC_SUBTLV_FEC_128_PW:
841                     /* Is the subTLV length correct? */
842                     if (lspping_subtlv_len != 14) {
843                         ND_PRINT("\n\t      invalid subTLV length, should be 14");
844                         subtlv_hexdump=TRUE; /* unknown subTLV just hexdump it */
845                     } else {
846                         subtlv_ptr.lspping_tlv_targetfec_subtlv_l2vpn_vcid =
847                             (const struct lspping_tlv_targetfec_subtlv_fec_128_pw *)subtlv_tptr;
848                         ND_PRINT("\n\t      Sender PE: %s, Remote PE: %s"
849                                "\n\t      PW ID: 0x%08x, PW Type: %s (%u)",
850                                GET_IPADDR_STRING(subtlv_ptr.lspping_tlv_targetfec_subtlv_l2vpn_vcid->sender_pe_address),
851                                GET_IPADDR_STRING(subtlv_ptr.lspping_tlv_targetfec_subtlv_l2vpn_vcid->remote_pe_address),
852                                GET_BE_U_4(subtlv_ptr.lspping_tlv_targetfec_subtlv_l2vpn_vcid->pw_id),
853                                tok2str(mpls_pw_types_values,
854                                        "unknown",
855                                        GET_BE_U_2(subtlv_ptr.lspping_tlv_targetfec_subtlv_l2vpn_vcid->pw_type)),
856                                GET_BE_U_2(subtlv_ptr.lspping_tlv_targetfec_subtlv_l2vpn_vcid->pw_type));
857                     }
858                     break;
859 
860                 default:
861                     subtlv_hexdump=TRUE; /* unknown subTLV just hexdump it */
862                     break;
863                 }
864                 /* do we want to see an additionally subtlv hexdump ? */
865                 if (ndo->ndo_vflag > 1 || subtlv_hexdump==TRUE)
866                     print_unknown_data(ndo, tlv_tptr+sizeof(struct lspping_tlv_header),
867                                        "\n\t      ",
868                                        lspping_subtlv_len);
869 
870                 /* All subTLVs are aligned to four octet boundary */
871                 if (lspping_subtlv_len % 4) {
872                     lspping_subtlv_len += 4 - (lspping_subtlv_len % 4);
873                     /* Does the subTLV, including padding, go past the end of the TLV? */
874                     if (tlv_tlen < lspping_subtlv_len+sizeof(struct lspping_tlv_header)) {
875                         ND_PRINT("\n\t\t TLV is too short");
876                         return;
877                     }
878                 }
879                 tlv_tptr+=lspping_subtlv_len;
880                 tlv_tlen-=lspping_subtlv_len+sizeof(struct lspping_tlv_header);
881             }
882             break;
883 
884         case LSPPING_TLV_DOWNSTREAM_MAPPING:
885             /* Does the header go past the end of the TLV? */
886             if (tlv_tlen < sizeof(struct lspping_tlv_downstream_map_t)) {
887                 ND_PRINT("\n\t      TLV is too short");
888                 tlv_hexdump = TRUE;
889                 goto tlv_tooshort;
890             }
891             /* Did we capture enough to get the address family? */
892             ND_TCHECK_LEN(tlv_tptr,
893                           sizeof(struct lspping_tlv_downstream_map_t));
894 
895             tlv_ptr.lspping_tlv_downstream_map=
896                 (const struct lspping_tlv_downstream_map_t *)tlv_tptr;
897 
898             /* that strange thing with the downstream map TLV is that until now
899              * we do not know if its IPv4 or IPv6 or is unnumbered; after
900              * we find the address-type, we recast the tlv_tptr and move on. */
901 
902             address_type = GET_U_1(tlv_ptr.lspping_tlv_downstream_map->address_type);
903             ND_PRINT("\n\t    MTU: %u, Address-Type: %s (%u)",
904                    GET_BE_U_2(tlv_ptr.lspping_tlv_downstream_map->mtu),
905                    tok2str(lspping_tlv_downstream_addr_values,
906                            "unknown",
907                            address_type),
908                    address_type);
909 
910             switch(address_type) {
911 
912             case LSPPING_AFI_IPV4:
913                 /* Does the data go past the end of the TLV? */
914                 if (tlv_tlen < sizeof(struct lspping_tlv_downstream_map_ipv4_t)) {
915                     ND_PRINT("\n\t      TLV is too short");
916                     tlv_hexdump = TRUE;
917                     goto tlv_tooshort;
918                 }
919                 /* Did we capture enough for this part of the TLV? */
920                 ND_TCHECK_LEN(tlv_tptr,
921                               sizeof(struct lspping_tlv_downstream_map_ipv4_t));
922 
923                 tlv_ptr.lspping_tlv_downstream_map_ipv4=
924                     (const struct lspping_tlv_downstream_map_ipv4_t *)tlv_tptr;
925                 ND_PRINT("\n\t    Downstream IP: %s"
926                        "\n\t    Downstream Interface IP: %s",
927                        GET_IPADDR_STRING(tlv_ptr.lspping_tlv_downstream_map_ipv4->downstream_ip),
928                        GET_IPADDR_STRING(tlv_ptr.lspping_tlv_downstream_map_ipv4->downstream_interface));
929                 tlv_tptr+=sizeof(struct lspping_tlv_downstream_map_ipv4_t);
930                 tlv_tlen-=sizeof(struct lspping_tlv_downstream_map_ipv4_t);
931                 break;
932             case LSPPING_AFI_IPV4_UNMB:
933                 /* Does the data go past the end of the TLV? */
934                 if (tlv_tlen < sizeof(struct lspping_tlv_downstream_map_ipv4_unmb_t)) {
935                     ND_PRINT("\n\t      TLV is too short");
936                     tlv_hexdump = TRUE;
937                     goto tlv_tooshort;
938                 }
939                 /* Did we capture enough for this part of the TLV? */
940                 ND_TCHECK_LEN(tlv_tptr,
941                               sizeof(struct lspping_tlv_downstream_map_ipv4_unmb_t));
942 
943                 tlv_ptr.lspping_tlv_downstream_map_ipv4_unmb=
944                     (const struct lspping_tlv_downstream_map_ipv4_unmb_t *)tlv_tptr;
945                 ND_PRINT("\n\t    Downstream IP: %s"
946                        "\n\t    Downstream Interface Index: 0x%08x",
947                        GET_IPADDR_STRING(tlv_ptr.lspping_tlv_downstream_map_ipv4_unmb->downstream_ip),
948                        GET_BE_U_4(tlv_ptr.lspping_tlv_downstream_map_ipv4_unmb->downstream_interface));
949                 tlv_tptr+=sizeof(struct lspping_tlv_downstream_map_ipv4_unmb_t);
950                 tlv_tlen-=sizeof(struct lspping_tlv_downstream_map_ipv4_unmb_t);
951                 break;
952             case LSPPING_AFI_IPV6:
953                 /* Does the data go past the end of the TLV? */
954                 if (tlv_tlen < sizeof(struct lspping_tlv_downstream_map_ipv6_t)) {
955                     ND_PRINT("\n\t      TLV is too short");
956                     tlv_hexdump = TRUE;
957                     goto tlv_tooshort;
958                 }
959                 /* Did we capture enough for this part of the TLV? */
960                 ND_TCHECK_LEN(tlv_tptr,
961                               sizeof(struct lspping_tlv_downstream_map_ipv6_t));
962 
963                 tlv_ptr.lspping_tlv_downstream_map_ipv6=
964                     (const struct lspping_tlv_downstream_map_ipv6_t *)tlv_tptr;
965                 ND_PRINT("\n\t    Downstream IP: %s"
966                        "\n\t    Downstream Interface IP: %s",
967                        GET_IP6ADDR_STRING(tlv_ptr.lspping_tlv_downstream_map_ipv6->downstream_ip),
968                        GET_IP6ADDR_STRING(tlv_ptr.lspping_tlv_downstream_map_ipv6->downstream_interface));
969                 tlv_tptr+=sizeof(struct lspping_tlv_downstream_map_ipv6_t);
970                 tlv_tlen-=sizeof(struct lspping_tlv_downstream_map_ipv6_t);
971                 break;
972              case LSPPING_AFI_IPV6_UNMB:
973                 /* Does the data go past the end of the TLV? */
974                 if (tlv_tlen < sizeof(struct lspping_tlv_downstream_map_ipv6_unmb_t)) {
975                     ND_PRINT("\n\t      TLV is too short");
976                     tlv_hexdump = TRUE;
977                     goto tlv_tooshort;
978                 }
979                 /* Did we capture enough for this part of the TLV? */
980                 ND_TCHECK_LEN(tlv_tptr,
981                               sizeof(struct lspping_tlv_downstream_map_ipv6_unmb_t));
982 
983                 tlv_ptr.lspping_tlv_downstream_map_ipv6_unmb=
984                    (const struct lspping_tlv_downstream_map_ipv6_unmb_t *)tlv_tptr;
985                 ND_PRINT("\n\t    Downstream IP: %s"
986                        "\n\t    Downstream Interface Index: 0x%08x",
987                        GET_IP6ADDR_STRING(tlv_ptr.lspping_tlv_downstream_map_ipv6_unmb->downstream_ip),
988                        GET_BE_U_4(tlv_ptr.lspping_tlv_downstream_map_ipv6_unmb->downstream_interface));
989                 tlv_tptr+=sizeof(struct lspping_tlv_downstream_map_ipv6_unmb_t);
990                 tlv_tlen-=sizeof(struct lspping_tlv_downstream_map_ipv6_unmb_t);
991                 break;
992 
993             default:
994                 /* should not happen ! - no error message - tok2str() has barked already */
995                 break;
996             }
997 
998             /* Does the data go past the end of the TLV? */
999             if (tlv_tlen < sizeof(struct lspping_tlv_downstream_map_info_t)) {
1000                 ND_PRINT("\n\t      TLV is too short");
1001                 tlv_hexdump = TRUE;
1002                 goto tlv_tooshort;
1003             }
1004             /* Did we capture enough for this part of the TLV? */
1005             ND_TCHECK_LEN(tlv_tptr,
1006                           sizeof(struct lspping_tlv_downstream_map_info_t));
1007 
1008             tlv_ptr.lspping_tlv_downstream_map_info=
1009                 (const struct lspping_tlv_downstream_map_info_t *)tlv_tptr;
1010 
1011             /* FIXME add hash-key type, depth limit, multipath processing */
1012 
1013             /* FIXME print downstream labels */
1014 
1015             tlv_hexdump=TRUE; /* dump the TLV until code complete */
1016 
1017             break;
1018 
1019         case LSPPING_TLV_BFD_DISCRIMINATOR:
1020             if (tlv_tlen < LSPPING_TLV_BFD_DISCRIMINATOR_LEN) {
1021                 ND_PRINT("\n\t      TLV is too short");
1022                 tlv_hexdump = TRUE;
1023                 goto tlv_tooshort;
1024             } else {
1025                 ND_PRINT("\n\t    BFD Discriminator 0x%08x", GET_BE_U_4(tlv_tptr));
1026             }
1027             break;
1028 
1029         case  LSPPING_TLV_VENDOR_ENTERPRISE:
1030         {
1031             uint32_t vendor_id;
1032 
1033             if (tlv_tlen < LSPPING_TLV_VENDOR_ENTERPRISE_LEN) {
1034                 ND_PRINT("\n\t      TLV is too short");
1035                 tlv_hexdump = TRUE;
1036                 goto tlv_tooshort;
1037             } else {
1038                 vendor_id = GET_BE_U_4(tlv_tptr);
1039                 ND_PRINT("\n\t    Vendor: %s (0x%04x)",
1040                        tok2str(smi_values, "Unknown", vendor_id),
1041                        vendor_id);
1042             }
1043         }
1044             break;
1045 
1046             /*
1047              *  FIXME those are the defined TLVs that lack a decoder
1048              *  you are welcome to contribute code ;-)
1049              */
1050         case LSPPING_TLV_PAD:
1051         case LSPPING_TLV_ERROR_CODE:
1052         case LSPPING_TLV_VENDOR_PRIVATE:
1053 
1054         default:
1055             if (ndo->ndo_vflag <= 1)
1056                 print_unknown_data(ndo, tlv_tptr, "\n\t    ", tlv_tlen);
1057             break;
1058         }
1059         /* do we want to see an additionally tlv hexdump ? */
1060     tlv_tooshort:
1061         if (ndo->ndo_vflag > 1 || tlv_hexdump==TRUE)
1062             print_unknown_data(ndo, tptr+sizeof(struct lspping_tlv_header), "\n\t    ",
1063                                lspping_tlv_len);
1064 
1065 
1066         /* All TLVs are aligned to four octet boundary */
1067         if (lspping_tlv_len % 4) {
1068             lspping_tlv_len += (4 - lspping_tlv_len % 4);
1069             /* Does the TLV, including padding, go past the end of the packet? */
1070             if (tlen < lspping_tlv_len+sizeof(struct lspping_tlv_header))
1071                 goto tooshort;
1072         }
1073 
1074         tptr+=lspping_tlv_len+sizeof(struct lspping_tlv_header);
1075         tlen-=lspping_tlv_len+sizeof(struct lspping_tlv_header);
1076     }
1077     return;
1078 tooshort:
1079     ND_PRINT("\n\t\t packet is too short");
1080 }
1081