]> The Tcpdump Group git mirrors - tcpdump/blob - print-icmp.c
598f3db9776b70e9ac35ac2cfaa0085f02553c58
[tcpdump] / print-icmp.c
1 /*
2 * Copyright (c) 1988, 1989, 1990, 1991, 1993, 1994, 1995, 1996
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that: (1) source code distributions
7 * retain the above copyright notice and this paragraph in its entirety, (2)
8 * distributions including binary code include the above copyright notice and
9 * this paragraph in its entirety in the documentation or other materials
10 * provided with the distribution, and (3) all advertising materials mentioning
11 * features or use of this software display the following acknowledgement:
12 * ``This product includes software developed by the University of California,
13 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
14 * the University nor the names of its contributors may be used to endorse
15 * or promote products derived from this software without specific prior
16 * written permission.
17 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20 */
21
22 #ifndef lint
23 static const char rcsid[] _U_ =
24 "@(#) $Header: /tcpdump/master/tcpdump/print-icmp.c,v 1.81.2.1 2005-06-22 13:44:24 hannes Exp $ (LBL)";
25 #endif
26
27 #ifdef HAVE_CONFIG_H
28 #include "config.h"
29 #endif
30
31 #include <tcpdump-stdinc.h>
32
33 #include <stdio.h>
34 #include <string.h>
35
36 #include "interface.h"
37 #include "addrtoname.h"
38 #include "extract.h" /* must come after interface.h */
39
40 #include "ip.h"
41 #include "udp.h"
42 #include "ipproto.h"
43 #include "mpls.h"
44
45 /*
46 * Interface Control Message Protocol Definitions.
47 * Per RFC 792, September 1981.
48 */
49
50 /*
51 * Structure of an icmp header.
52 */
53 struct icmp {
54 u_int8_t icmp_type; /* type of message, see below */
55 u_int8_t icmp_code; /* type sub code */
56 u_int16_t icmp_cksum; /* ones complement cksum of struct */
57 union {
58 u_int8_t ih_pptr; /* ICMP_PARAMPROB */
59 struct in_addr ih_gwaddr; /* ICMP_REDIRECT */
60 struct ih_idseq {
61 u_int16_t icd_id;
62 u_int16_t icd_seq;
63 } ih_idseq;
64 u_int32_t ih_void;
65
66 /* ICMP_UNREACH_NEEDFRAG -- Path MTU Discovery (RFC1191) */
67 struct ih_pmtu {
68 u_int16_t ipm_void;
69 u_int16_t ipm_nextmtu;
70 } ih_pmtu;
71 } icmp_hun;
72 #define icmp_pptr icmp_hun.ih_pptr
73 #define icmp_gwaddr icmp_hun.ih_gwaddr
74 #define icmp_id icmp_hun.ih_idseq.icd_id
75 #define icmp_seq icmp_hun.ih_idseq.icd_seq
76 #define icmp_void icmp_hun.ih_void
77 #define icmp_pmvoid icmp_hun.ih_pmtu.ipm_void
78 #define icmp_nextmtu icmp_hun.ih_pmtu.ipm_nextmtu
79 union {
80 struct id_ts {
81 u_int32_t its_otime;
82 u_int32_t its_rtime;
83 u_int32_t its_ttime;
84 } id_ts;
85 struct id_ip {
86 struct ip idi_ip;
87 /* options and then 64 bits of data */
88 } id_ip;
89 struct mpls_ext {
90 u_int8_t legacy_header[128]; /* extension header starts 128 bytes after ICMP header */
91 u_int8_t version_res[2];
92 u_int8_t checksum[2];
93 u_int8_t data[1];
94 } mpls_ext;
95 u_int32_t id_mask;
96 u_int8_t id_data[1];
97 } icmp_dun;
98 #define icmp_otime icmp_dun.id_ts.its_otime
99 #define icmp_rtime icmp_dun.id_ts.its_rtime
100 #define icmp_ttime icmp_dun.id_ts.its_ttime
101 #define icmp_ip icmp_dun.id_ip.idi_ip
102 #define icmp_mask icmp_dun.id_mask
103 #define icmp_data icmp_dun.id_data
104 #define icmp_mpls_ext_version icmp_dun.mpls_ext.version_res
105 #define icmp_mpls_ext_checksum icmp_dun.mpls_ext.checksum
106 #define icmp_mpls_ext_data icmp_dun.mpls_ext.data
107 };
108
109 #define ICMP_MPLS_EXT_EXTRACT_VERSION(x) (((x)&0xf0)>>4)
110 #define ICMP_MPLS_EXT_VERSION 2
111
112 /*
113 * Lower bounds on packet lengths for various types.
114 * For the error advice packets must first insure that the
115 * packet is large enought to contain the returned ip header.
116 * Only then can we do the check to see if 64 bits of packet
117 * data have been returned, since we need to check the returned
118 * ip header length.
119 */
120 #define ICMP_MINLEN 8 /* abs minimum */
121 #define ICMP_EXTD_MINLEN (156 - sizeof (struct ip)) /* draft-bonica-icmp-mpls-02 */
122 #define ICMP_TSLEN (8 + 3 * sizeof (u_int32_t)) /* timestamp */
123 #define ICMP_MASKLEN 12 /* address mask */
124 #define ICMP_ADVLENMIN (8 + sizeof (struct ip) + 8) /* min */
125 #define ICMP_ADVLEN(p) (8 + (IP_HL(&(p)->icmp_ip) << 2) + 8)
126 /* N.B.: must separately check that ip_hl >= 5 */
127
128 /*
129 * Definition of type and code field values.
130 */
131 #define ICMP_ECHOREPLY 0 /* echo reply */
132 #define ICMP_UNREACH 3 /* dest unreachable, codes: */
133 #define ICMP_UNREACH_NET 0 /* bad net */
134 #define ICMP_UNREACH_HOST 1 /* bad host */
135 #define ICMP_UNREACH_PROTOCOL 2 /* bad protocol */
136 #define ICMP_UNREACH_PORT 3 /* bad port */
137 #define ICMP_UNREACH_NEEDFRAG 4 /* IP_DF caused drop */
138 #define ICMP_UNREACH_SRCFAIL 5 /* src route failed */
139 #define ICMP_UNREACH_NET_UNKNOWN 6 /* unknown net */
140 #define ICMP_UNREACH_HOST_UNKNOWN 7 /* unknown host */
141 #define ICMP_UNREACH_ISOLATED 8 /* src host isolated */
142 #define ICMP_UNREACH_NET_PROHIB 9 /* prohibited access */
143 #define ICMP_UNREACH_HOST_PROHIB 10 /* ditto */
144 #define ICMP_UNREACH_TOSNET 11 /* bad tos for net */
145 #define ICMP_UNREACH_TOSHOST 12 /* bad tos for host */
146 #define ICMP_SOURCEQUENCH 4 /* packet lost, slow down */
147 #define ICMP_REDIRECT 5 /* shorter route, codes: */
148 #define ICMP_REDIRECT_NET 0 /* for network */
149 #define ICMP_REDIRECT_HOST 1 /* for host */
150 #define ICMP_REDIRECT_TOSNET 2 /* for tos and net */
151 #define ICMP_REDIRECT_TOSHOST 3 /* for tos and host */
152 #define ICMP_ECHO 8 /* echo service */
153 #define ICMP_ROUTERADVERT 9 /* router advertisement */
154 #define ICMP_ROUTERSOLICIT 10 /* router solicitation */
155 #define ICMP_TIMXCEED 11 /* time exceeded, code: */
156 #define ICMP_TIMXCEED_INTRANS 0 /* ttl==0 in transit */
157 #define ICMP_TIMXCEED_REASS 1 /* ttl==0 in reass */
158 #define ICMP_PARAMPROB 12 /* ip header bad */
159 #define ICMP_PARAMPROB_OPTABSENT 1 /* req. opt. absent */
160 #define ICMP_TSTAMP 13 /* timestamp request */
161 #define ICMP_TSTAMPREPLY 14 /* timestamp reply */
162 #define ICMP_IREQ 15 /* information request */
163 #define ICMP_IREQREPLY 16 /* information reply */
164 #define ICMP_MASKREQ 17 /* address mask request */
165 #define ICMP_MASKREPLY 18 /* address mask reply */
166
167 #define ICMP_MAXTYPE 18
168
169 #define ICMP_INFOTYPE(type) \
170 ((type) == ICMP_ECHOREPLY || (type) == ICMP_ECHO || \
171 (type) == ICMP_ROUTERADVERT || (type) == ICMP_ROUTERSOLICIT || \
172 (type) == ICMP_TSTAMP || (type) == ICMP_TSTAMPREPLY || \
173 (type) == ICMP_IREQ || (type) == ICMP_IREQREPLY || \
174 (type) == ICMP_MASKREQ || (type) == ICMP_MASKREPLY)
175 #define ICMP_MPLS_EXT_TYPE(type) \
176 ((type) == ICMP_UNREACH || (type) == ICMP_TIMXCEED)
177 /* rfc1700 */
178 #ifndef ICMP_UNREACH_NET_UNKNOWN
179 #define ICMP_UNREACH_NET_UNKNOWN 6 /* destination net unknown */
180 #endif
181 #ifndef ICMP_UNREACH_HOST_UNKNOWN
182 #define ICMP_UNREACH_HOST_UNKNOWN 7 /* destination host unknown */
183 #endif
184 #ifndef ICMP_UNREACH_ISOLATED
185 #define ICMP_UNREACH_ISOLATED 8 /* source host isolated */
186 #endif
187 #ifndef ICMP_UNREACH_NET_PROHIB
188 #define ICMP_UNREACH_NET_PROHIB 9 /* admin prohibited net */
189 #endif
190 #ifndef ICMP_UNREACH_HOST_PROHIB
191 #define ICMP_UNREACH_HOST_PROHIB 10 /* admin prohibited host */
192 #endif
193 #ifndef ICMP_UNREACH_TOSNET
194 #define ICMP_UNREACH_TOSNET 11 /* tos prohibited net */
195 #endif
196 #ifndef ICMP_UNREACH_TOSHOST
197 #define ICMP_UNREACH_TOSHOST 12 /* tos prohibited host */
198 #endif
199
200 /* rfc1716 */
201 #ifndef ICMP_UNREACH_FILTER_PROHIB
202 #define ICMP_UNREACH_FILTER_PROHIB 13 /* admin prohibited filter */
203 #endif
204 #ifndef ICMP_UNREACH_HOST_PRECEDENCE
205 #define ICMP_UNREACH_HOST_PRECEDENCE 14 /* host precedence violation */
206 #endif
207 #ifndef ICMP_UNREACH_PRECEDENCE_CUTOFF
208 #define ICMP_UNREACH_PRECEDENCE_CUTOFF 15 /* precedence cutoff */
209 #endif
210
211 /* Most of the icmp types */
212 static struct tok icmp2str[] = {
213 { ICMP_ECHOREPLY, "echo reply" },
214 { ICMP_SOURCEQUENCH, "source quench" },
215 { ICMP_ECHO, "echo request" },
216 { ICMP_ROUTERSOLICIT, "router solicitation" },
217 { ICMP_TSTAMP, "time stamp request" },
218 { ICMP_TSTAMPREPLY, "time stamp reply" },
219 { ICMP_IREQ, "information request" },
220 { ICMP_IREQREPLY, "information reply" },
221 { ICMP_MASKREQ, "address mask request" },
222 { 0, NULL }
223 };
224
225 /* Formats for most of the ICMP_UNREACH codes */
226 static struct tok unreach2str[] = {
227 { ICMP_UNREACH_NET, "net %s unreachable" },
228 { ICMP_UNREACH_HOST, "host %s unreachable" },
229 { ICMP_UNREACH_SRCFAIL,
230 "%s unreachable - source route failed" },
231 { ICMP_UNREACH_NET_UNKNOWN, "net %s unreachable - unknown" },
232 { ICMP_UNREACH_HOST_UNKNOWN, "host %s unreachable - unknown" },
233 { ICMP_UNREACH_ISOLATED,
234 "%s unreachable - source host isolated" },
235 { ICMP_UNREACH_NET_PROHIB,
236 "net %s unreachable - admin prohibited" },
237 { ICMP_UNREACH_HOST_PROHIB,
238 "host %s unreachable - admin prohibited" },
239 { ICMP_UNREACH_TOSNET,
240 "net %s unreachable - tos prohibited" },
241 { ICMP_UNREACH_TOSHOST,
242 "host %s unreachable - tos prohibited" },
243 { ICMP_UNREACH_FILTER_PROHIB,
244 "host %s unreachable - admin prohibited filter" },
245 { ICMP_UNREACH_HOST_PRECEDENCE,
246 "host %s unreachable - host precedence violation" },
247 { ICMP_UNREACH_PRECEDENCE_CUTOFF,
248 "host %s unreachable - precedence cutoff" },
249 { 0, NULL }
250 };
251
252 /* Formats for the ICMP_REDIRECT codes */
253 static struct tok type2str[] = {
254 { ICMP_REDIRECT_NET, "redirect %s to net %s" },
255 { ICMP_REDIRECT_HOST, "redirect %s to host %s" },
256 { ICMP_REDIRECT_TOSNET, "redirect-tos %s to net %s" },
257 { ICMP_REDIRECT_TOSHOST, "redirect-tos %s to host %s" },
258 { 0, NULL }
259 };
260
261 /* rfc1191 */
262 struct mtu_discovery {
263 u_int16_t unused;
264 u_int16_t nexthopmtu;
265 };
266
267 /* rfc1256 */
268 struct ih_rdiscovery {
269 u_int8_t ird_addrnum;
270 u_int8_t ird_addrsiz;
271 u_int16_t ird_lifetime;
272 };
273
274 struct id_rdiscovery {
275 u_int32_t ird_addr;
276 u_int32_t ird_pref;
277 };
278
279 /* draft-bonica-icmp-mpls-02 */
280 struct icmp_mpls_ext_object_header_t {
281 u_int8_t length[2];
282 u_int8_t class_num;
283 u_int8_t ctype;
284 };
285
286 static const struct tok icmp_mpls_ext_obj_values[] = {
287 { 1, "MPLS Stack Entry" },
288 { 2, "Extended Payload" },
289 { 0, NULL}
290 };
291
292 /* prototypes */
293 const char *icmp_tstamp_print(u_int);
294
295 /* print the milliseconds since midnight UTC */
296 const char *
297 icmp_tstamp_print(u_int tstamp) {
298 u_int msec,sec,min,hrs;
299
300 static char buf[64];
301
302 msec = tstamp % 1000;
303 sec = tstamp / 1000;
304 min = sec / 60; sec -= min * 60;
305 hrs = min / 60; min -= hrs * 60;
306 snprintf(buf, sizeof(buf), "%02u:%02u:%02u.%03u",hrs,min,sec,msec);
307 return buf;
308 }
309
310 void
311 icmp_print(const u_char *bp, u_int plen, const u_char *bp2, int fragmented)
312 {
313 char *cp;
314 const struct icmp *dp;
315 const struct ip *ip;
316 const char *str, *fmt;
317 const struct ip *oip;
318 const struct udphdr *ouh;
319 const u_int8_t *obj_tptr;
320 u_int32_t raw_label;
321 const struct icmp_mpls_ext_object_header_t *icmp_mpls_ext_object_header;
322 u_int hlen, dport, mtu, obj_tlen, obj_class_num, obj_ctype;
323 char buf[MAXHOSTNAMELEN + 100];
324
325 dp = (struct icmp *)bp;
326 ip = (struct ip *)bp2;
327 str = buf;
328
329 TCHECK(dp->icmp_code);
330 switch (dp->icmp_type) {
331
332 case ICMP_ECHO:
333 case ICMP_ECHOREPLY:
334 TCHECK(dp->icmp_seq);
335 (void)snprintf(buf, sizeof(buf), "echo %s seq %u",
336 dp->icmp_type == ICMP_ECHO ?
337 "request" : "reply",
338 EXTRACT_16BITS(&dp->icmp_seq));
339 break;
340
341 case ICMP_UNREACH:
342 TCHECK(dp->icmp_ip.ip_dst);
343 switch (dp->icmp_code) {
344
345 case ICMP_UNREACH_PROTOCOL:
346 TCHECK(dp->icmp_ip.ip_p);
347 (void)snprintf(buf, sizeof(buf),
348 "%s protocol %d unreachable",
349 ipaddr_string(&dp->icmp_ip.ip_dst),
350 dp->icmp_ip.ip_p);
351 break;
352
353 case ICMP_UNREACH_PORT:
354 TCHECK(dp->icmp_ip.ip_p);
355 oip = &dp->icmp_ip;
356 hlen = IP_HL(oip) * 4;
357 ouh = (struct udphdr *)(((u_char *)oip) + hlen);
358 TCHECK(ouh->uh_dport);
359 dport = EXTRACT_16BITS(&ouh->uh_dport);
360 switch (oip->ip_p) {
361
362 case IPPROTO_TCP:
363 (void)snprintf(buf, sizeof(buf),
364 "%s tcp port %s unreachable",
365 ipaddr_string(&oip->ip_dst),
366 tcpport_string(dport));
367 break;
368
369 case IPPROTO_UDP:
370 (void)snprintf(buf, sizeof(buf),
371 "%s udp port %s unreachable",
372 ipaddr_string(&oip->ip_dst),
373 udpport_string(dport));
374 break;
375
376 default:
377 (void)snprintf(buf, sizeof(buf),
378 "%s protocol %d port %d unreachable",
379 ipaddr_string(&oip->ip_dst),
380 oip->ip_p, dport);
381 break;
382 }
383 break;
384
385 case ICMP_UNREACH_NEEDFRAG:
386 {
387 register const struct mtu_discovery *mp;
388 mp = (struct mtu_discovery *)&dp->icmp_void;
389 mtu = EXTRACT_16BITS(&mp->nexthopmtu);
390 if (mtu) {
391 (void)snprintf(buf, sizeof(buf),
392 "%s unreachable - need to frag (mtu %d)",
393 ipaddr_string(&dp->icmp_ip.ip_dst), mtu);
394 } else {
395 (void)snprintf(buf, sizeof(buf),
396 "%s unreachable - need to frag",
397 ipaddr_string(&dp->icmp_ip.ip_dst));
398 }
399 }
400 break;
401
402 default:
403 fmt = tok2str(unreach2str, "#%d %%s unreachable",
404 dp->icmp_code);
405 (void)snprintf(buf, sizeof(buf), fmt,
406 ipaddr_string(&dp->icmp_ip.ip_dst));
407 break;
408 }
409 break;
410
411 case ICMP_REDIRECT:
412 TCHECK(dp->icmp_ip.ip_dst);
413 fmt = tok2str(type2str, "redirect-#%d %%s to net %%s",
414 dp->icmp_code);
415 (void)snprintf(buf, sizeof(buf), fmt,
416 ipaddr_string(&dp->icmp_ip.ip_dst),
417 ipaddr_string(&dp->icmp_gwaddr));
418 break;
419
420 case ICMP_ROUTERADVERT:
421 {
422 register const struct ih_rdiscovery *ihp;
423 register const struct id_rdiscovery *idp;
424 u_int lifetime, num, size;
425
426 (void)snprintf(buf, sizeof(buf), "router advertisement");
427 cp = buf + strlen(buf);
428
429 ihp = (struct ih_rdiscovery *)&dp->icmp_void;
430 TCHECK(*ihp);
431 (void)strncpy(cp, " lifetime ", sizeof(buf) - (cp - buf));
432 cp = buf + strlen(buf);
433 lifetime = EXTRACT_16BITS(&ihp->ird_lifetime);
434 if (lifetime < 60) {
435 (void)snprintf(cp, sizeof(buf) - (cp - buf), "%u",
436 lifetime);
437 } else if (lifetime < 60 * 60) {
438 (void)snprintf(cp, sizeof(buf) - (cp - buf), "%u:%02u",
439 lifetime / 60, lifetime % 60);
440 } else {
441 (void)snprintf(cp, sizeof(buf) - (cp - buf),
442 "%u:%02u:%02u",
443 lifetime / 3600,
444 (lifetime % 3600) / 60,
445 lifetime % 60);
446 }
447 cp = buf + strlen(buf);
448
449 num = ihp->ird_addrnum;
450 (void)snprintf(cp, sizeof(buf) - (cp - buf), " %d:", num);
451 cp = buf + strlen(buf);
452
453 size = ihp->ird_addrsiz;
454 if (size != 2) {
455 (void)snprintf(cp, sizeof(buf) - (cp - buf),
456 " [size %d]", size);
457 break;
458 }
459 idp = (struct id_rdiscovery *)&dp->icmp_data;
460 while (num-- > 0) {
461 TCHECK(*idp);
462 (void)snprintf(cp, sizeof(buf) - (cp - buf), " {%s %u}",
463 ipaddr_string(&idp->ird_addr),
464 EXTRACT_32BITS(&idp->ird_pref));
465 cp = buf + strlen(buf);
466 ++idp;
467 }
468 }
469 break;
470
471 case ICMP_TIMXCEED:
472 TCHECK(dp->icmp_ip.ip_dst);
473 switch (dp->icmp_code) {
474
475 case ICMP_TIMXCEED_INTRANS:
476 str = "time exceeded in-transit";
477 break;
478
479 case ICMP_TIMXCEED_REASS:
480 str = "ip reassembly time exceeded";
481 break;
482
483 default:
484 (void)snprintf(buf, sizeof(buf), "time exceeded-#%d",
485 dp->icmp_code);
486 break;
487 }
488 break;
489
490 case ICMP_PARAMPROB:
491 if (dp->icmp_code)
492 (void)snprintf(buf, sizeof(buf),
493 "parameter problem - code %d", dp->icmp_code);
494 else {
495 TCHECK(dp->icmp_pptr);
496 (void)snprintf(buf, sizeof(buf),
497 "parameter problem - octet %d", dp->icmp_pptr);
498 }
499 break;
500
501 case ICMP_MASKREPLY:
502 TCHECK(dp->icmp_mask);
503 (void)snprintf(buf, sizeof(buf), "address mask is 0x%08x",
504 EXTRACT_32BITS(&dp->icmp_mask));
505 break;
506
507 case ICMP_TSTAMP:
508 TCHECK(dp->icmp_seq);
509 (void)snprintf(buf, sizeof(buf),
510 "time stamp query id %u seq %u",
511 EXTRACT_16BITS(&dp->icmp_id),
512 EXTRACT_16BITS(&dp->icmp_seq));
513 break;
514
515 case ICMP_TSTAMPREPLY:
516 TCHECK(dp->icmp_ttime);
517 (void)snprintf(buf, sizeof(buf),
518 "time stamp reply id %u seq %u: org %s",
519 EXTRACT_16BITS(&dp->icmp_id),
520 EXTRACT_16BITS(&dp->icmp_seq),
521 icmp_tstamp_print(EXTRACT_32BITS(&dp->icmp_otime)));
522
523 (void)snprintf(buf+strlen(buf),sizeof(buf)-strlen(buf),", recv %s",
524 icmp_tstamp_print(EXTRACT_32BITS(&dp->icmp_rtime)));
525 (void)snprintf(buf+strlen(buf),sizeof(buf)-strlen(buf),", xmit %s",
526 icmp_tstamp_print(EXTRACT_32BITS(&dp->icmp_ttime)));
527 break;
528
529 default:
530 str = tok2str(icmp2str, "type-#%d", dp->icmp_type);
531 break;
532 }
533 (void)printf("ICMP %s, length %u", str, plen);
534 if (vflag && !fragmented) { /* don't attempt checksumming if this is a frag */
535 u_int16_t sum, icmp_sum;
536 if (TTEST2(*bp, plen)) {
537 sum = in_cksum((u_short*)dp, plen, 0);
538 if (sum != 0) {
539 icmp_sum = EXTRACT_16BITS(&dp->icmp_cksum);
540 (void)printf(" (wrong icmp cksum %x (->%x)!)",
541 icmp_sum,
542 in_cksum_shouldbe(icmp_sum, sum));
543 }
544 }
545 }
546 if (vflag >= 1 && !ICMP_INFOTYPE(dp->icmp_type)) {
547 bp += 8;
548 (void)printf("\n\t");
549 ip = (struct ip *)bp;
550 snaplen = snapend - bp;
551 ip_print(gndo, bp, EXTRACT_16BITS(&ip->ip_len));
552 }
553
554 if (vflag >= 1 && plen > ICMP_EXTD_MINLEN && ICMP_MPLS_EXT_TYPE(dp->icmp_type)) {
555
556 TCHECK(*(dp->icmp_mpls_ext_version));
557 printf("\n\tMPLS extension v%u",ICMP_MPLS_EXT_EXTRACT_VERSION(*(dp->icmp_mpls_ext_version)));
558
559 /*
560 * Sanity checking of the header.
561 */
562 if (ICMP_MPLS_EXT_EXTRACT_VERSION(*(dp->icmp_mpls_ext_version)) != ICMP_MPLS_EXT_VERSION) {
563 printf(" packet not supported");
564 return;
565 }
566
567 hlen = plen - ICMP_EXTD_MINLEN;
568 TCHECK2(*(dp->icmp_mpls_ext_checksum), 2);
569 printf(", checksum 0x%04x (unverified), length %u", /* FIXME */
570 EXTRACT_16BITS(dp->icmp_mpls_ext_checksum),
571 hlen);
572
573 hlen -= 4; /* subtract common header size */
574 obj_tptr = (u_int8_t *)dp->icmp_mpls_ext_data;
575
576 while (hlen > sizeof(struct icmp_mpls_ext_object_header_t)) {
577
578 icmp_mpls_ext_object_header = (struct icmp_mpls_ext_object_header_t *)obj_tptr;
579 TCHECK(*icmp_mpls_ext_object_header);
580 obj_tlen = EXTRACT_16BITS(icmp_mpls_ext_object_header->length);
581 obj_class_num = icmp_mpls_ext_object_header->class_num;
582 obj_ctype = icmp_mpls_ext_object_header->ctype;
583 obj_tptr += sizeof(struct icmp_mpls_ext_object_header_t);
584
585 printf("\n\t %s Object (%u), Class-Type: %u, length %u",
586 tok2str(icmp_mpls_ext_obj_values,"unknown",obj_class_num),
587 obj_class_num,
588 obj_ctype,
589 obj_tlen);
590
591 hlen-=sizeof(struct icmp_mpls_ext_object_header_t); /* length field includes tlv header */
592 if (obj_tlen < sizeof(struct icmp_mpls_ext_object_header_t))
593 break;
594 obj_tlen-=sizeof(struct icmp_mpls_ext_object_header_t);
595
596 switch (obj_class_num) {
597 case 1:
598 switch(obj_ctype) {
599 case 1:
600 TCHECK2(*obj_tptr, 4);
601 raw_label = EXTRACT_32BITS(obj_tptr);
602 printf("\n\t label %u, exp %u", MPLS_LABEL(raw_label), MPLS_EXP(raw_label));
603 if (MPLS_STACK(raw_label))
604 printf(", [S]");
605 printf(", ttl %u", MPLS_TTL(raw_label));
606 break;
607 default:
608 print_unknown_data(obj_tptr, "\n\t ", obj_tlen);
609 }
610 break;
611
612 /*
613 * FIXME those are the defined objects that lack a decoder
614 * you are welcome to contribute code ;-)
615 */
616 case 2:
617 default:
618 print_unknown_data(obj_tptr, "\n\t ", obj_tlen);
619 break;
620 }
621 if (hlen < obj_tlen)
622 break;
623 hlen -= obj_tlen;
624 obj_tptr += obj_tlen;
625 }
626 }
627
628 return;
629 trunc:
630 fputs("[|icmp]", stdout);
631 }