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