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