xref: /csrg-svn/sys/netinet/ip_icmp.h (revision 44479)
123183Smckusick /*
229142Smckusick  * Copyright (c) 1982, 1986 Regents of the University of California.
332787Sbostic  * All rights reserved.
423183Smckusick  *
5*44479Sbostic  * %sccs.include.redist.c%
632787Sbostic  *
7*44479Sbostic  *	@(#)ip_icmp.h	7.5 (Berkeley) 06/28/90
823183Smckusick  */
94807Swnj 
104807Swnj /*
114807Swnj  * Interface Control Message Protocol Definitions.
124807Swnj  * Per RFC 792, September 1981.
134807Swnj  */
144807Swnj 
154807Swnj /*
164807Swnj  * Structure of an icmp header.
174807Swnj  */
184807Swnj struct icmp {
194807Swnj 	u_char	icmp_type;		/* type of message, see below */
204807Swnj 	u_char	icmp_code;		/* type sub code */
214807Swnj 	u_short	icmp_cksum;		/* ones complement cksum of struct */
224807Swnj 	union {
234807Swnj 		u_char ih_pptr;			/* ICMP_PARAMPROB */
244923Swnj 		struct in_addr ih_gwaddr;	/* ICMP_REDIRECT */
254807Swnj 		struct ih_idseq {
264807Swnj 			n_short	icd_id;
274807Swnj 			n_short	icd_seq;
284807Swnj 		} ih_idseq;
296583Ssam 		int ih_void;
304807Swnj 	} icmp_hun;
314807Swnj #define	icmp_pptr	icmp_hun.ih_pptr
324807Swnj #define	icmp_gwaddr	icmp_hun.ih_gwaddr
334807Swnj #define	icmp_id		icmp_hun.ih_idseq.icd_id
344807Swnj #define	icmp_seq	icmp_hun.ih_idseq.icd_seq
356583Ssam #define	icmp_void	icmp_hun.ih_void
364807Swnj 	union {
374807Swnj 		struct id_ts {
384807Swnj 			n_time its_otime;
394807Swnj 			n_time its_rtime;
404807Swnj 			n_time its_ttime;
414807Swnj 		} id_ts;
424807Swnj 		struct id_ip  {
434807Swnj 			struct ip idi_ip;
444807Swnj 			/* options and then 64 bits of data */
454807Swnj 		} id_ip;
4624812Skarels 		u_long	id_mask;
4727060Skarels 		char	id_data[1];
484807Swnj 	} icmp_dun;
494807Swnj #define	icmp_otime	icmp_dun.id_ts.its_otime
504807Swnj #define	icmp_rtime	icmp_dun.id_ts.its_rtime
514807Swnj #define	icmp_ttime	icmp_dun.id_ts.its_ttime
524807Swnj #define	icmp_ip		icmp_dun.id_ip.idi_ip
5324812Skarels #define	icmp_mask	icmp_dun.id_mask
5427060Skarels #define	icmp_data	icmp_dun.id_data
554807Swnj };
564807Swnj 
574807Swnj /*
584807Swnj  * Lower bounds on packet lengths for various types.
594807Swnj  * For the error advice packets must first insure that the
604807Swnj  * packet is large enought to contain the returned ip header.
614807Swnj  * Only then can we do the check to see if 64 bits of packet
624807Swnj  * data have been returned, since we need to check the returned
634807Swnj  * ip header length.
644807Swnj  */
654807Swnj #define	ICMP_MINLEN	8				/* abs minimum */
664807Swnj #define	ICMP_TSLEN	(8 + 3 * sizeof (n_time))	/* timestamp */
6724812Skarels #define	ICMP_MASKLEN	12				/* address mask */
684807Swnj #define	ICMP_ADVLENMIN	(8 + sizeof (struct ip) + 8)	/* min */
696590Ssam #define	ICMP_ADVLEN(p)	(8 + ((p)->icmp_ip.ip_hl << 2) + 8)
704807Swnj 	/* N.B.: must separately check that ip_hl >= 5 */
714807Swnj 
724807Swnj /*
734807Swnj  * Definition of type and code field values.
744807Swnj  */
754807Swnj #define	ICMP_ECHOREPLY		0		/* echo reply */
764807Swnj #define	ICMP_UNREACH		3		/* dest unreachable, codes: */
774807Swnj #define		ICMP_UNREACH_NET	0		/* bad net */
784807Swnj #define		ICMP_UNREACH_HOST	1		/* bad host */
794807Swnj #define		ICMP_UNREACH_PROTOCOL	2		/* bad protocol */
804807Swnj #define		ICMP_UNREACH_PORT	3		/* bad port */
814807Swnj #define		ICMP_UNREACH_NEEDFRAG	4		/* IP_DF caused drop */
824807Swnj #define		ICMP_UNREACH_SRCFAIL	5		/* src route failed */
834807Swnj #define	ICMP_SOURCEQUENCH	4		/* packet lost, slow down */
844807Swnj #define	ICMP_REDIRECT		5		/* shorter route, codes: */
854807Swnj #define		ICMP_REDIRECT_NET	0		/* for network */
864807Swnj #define		ICMP_REDIRECT_HOST	1		/* for host */
874807Swnj #define		ICMP_REDIRECT_TOSNET	2		/* for tos and net */
884807Swnj #define		ICMP_REDIRECT_TOSHOST	3		/* for tos and host */
894807Swnj #define	ICMP_ECHO		8		/* echo service */
904807Swnj #define	ICMP_TIMXCEED		11		/* time exceeded, code: */
914807Swnj #define		ICMP_TIMXCEED_INTRANS	0		/* ttl==0 in transit */
924807Swnj #define		ICMP_TIMXCEED_REASS	1		/* ttl==0 in reass */
935172Swnj #define	ICMP_PARAMPROB		12		/* ip header bad */
944807Swnj #define	ICMP_TSTAMP		13		/* timestamp request */
954807Swnj #define	ICMP_TSTAMPREPLY	14		/* timestamp reply */
964807Swnj #define	ICMP_IREQ		15		/* information request */
974807Swnj #define	ICMP_IREQREPLY		16		/* information reply */
9824812Skarels #define	ICMP_MASKREQ		17		/* address mask request */
9924812Skarels #define	ICMP_MASKREPLY		18		/* address mask reply */
10024812Skarels 
10124812Skarels #define	ICMP_MAXTYPE		18
10231394Skarels 
10331394Skarels #define	ICMP_INFOTYPE(type) \
10431394Skarels 	((type) == ICMP_ECHOREPLY || (type) == ICMP_ECHO || \
10531394Skarels 	(type) == ICMP_TSTAMP || (type) == ICMP_TSTAMPREPLY || \
10631394Skarels 	(type) == ICMP_IREQ || (type) == ICMP_IREQREPLY || \
10731394Skarels 	(type) == ICMP_MASKREQ || (type) == ICMP_MASKREPLY)
108