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