18b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project/*
28b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project * Copyright (c) 1982, 1986, 1993
38b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project *	The Regents of the University of California.  All rights reserved.
48b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project *
58b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project * Redistribution and use in source and binary forms, with or without
68b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project * modification, are permitted provided that the following conditions
78b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project * are met:
88b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project * 1. Redistributions of source code must retain the above copyright
98b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project *    notice, this list of conditions and the following disclaimer.
108b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project * 2. Redistributions in binary form must reproduce the above copyright
118b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project *    notice, this list of conditions and the following disclaimer in the
128b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project *    documentation and/or other materials provided with the distribution.
135d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner * 3. Neither the name of the University nor the names of its contributors
148b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project *    may be used to endorse or promote products derived from this software
158b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project *    without specific prior written permission.
168b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project *
178b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
188b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
198b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
208b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
218b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
228b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
238b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
248b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
258b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
268b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
278b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project * SUCH DAMAGE.
288b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project *
298b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project *	@(#)ip_icmp.h	8.1 (Berkeley) 6/10/93
308b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project * ip_icmp.h,v 1.4 1995/05/30 08:09:43 rgrimes Exp
318b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project */
328b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
338b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#ifndef _NETINET_IP_ICMP_H_
348b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define _NETINET_IP_ICMP_H_
358b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
368b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project/*
378b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project * Interface Control Message Protocol Definitions.
388b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project * Per RFC 792, September 1981.
398b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project */
408b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
418b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Projecttypedef u_int32_t n_time;
428b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
438b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project/*
448b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project * Structure of an icmp header.
458b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project */
468b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Projectstruct icmp {
478b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project	u_char	icmp_type;		/* type of message, see below */
488b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project	u_char	icmp_code;		/* type sub code */
498b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project	u_short	icmp_cksum;		/* ones complement cksum of struct */
508b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project	union {
515d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner		u_char ih_pptr;			/* ICMP_PARAMPROB */
525d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner		struct in_addr ih_gwaddr;	/* ICMP_REDIRECT */
538b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project		struct ih_idseq {
548b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project			u_short	icd_id;
558b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project			u_short	icd_seq;
568b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project		} ih_idseq;
578b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project		int ih_void;
588b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
598b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project		/* ICMP_UNREACH_NEEDFRAG -- Path MTU Discovery (RFC1191) */
608b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project		struct ih_pmtu {
618b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project			u_short ipm_void;
628b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project			u_short ipm_nextmtu;
638b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project		} ih_pmtu;
648b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project	} icmp_hun;
658b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define	icmp_pptr	icmp_hun.ih_pptr
668b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define	icmp_gwaddr	icmp_hun.ih_gwaddr
678b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define	icmp_id		icmp_hun.ih_idseq.icd_id
688b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define	icmp_seq	icmp_hun.ih_idseq.icd_seq
698b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define	icmp_void	icmp_hun.ih_void
708b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define	icmp_pmvoid	icmp_hun.ih_pmtu.ipm_void
718b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define	icmp_nextmtu	icmp_hun.ih_pmtu.ipm_nextmtu
728b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project	union {
738b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project		struct id_ts {
748b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project			n_time its_otime;
758b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project			n_time its_rtime;
768b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project			n_time its_ttime;
778b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project		} id_ts;
788b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project		struct id_ip  {
798b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project			struct ip idi_ip;
808b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project			/* options and then 64 bits of data */
818b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project		} id_ip;
828b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project		uint32_t	id_mask;
838b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project		char		id_data[1];
848b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project	} icmp_dun;
858b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define	icmp_otime	icmp_dun.id_ts.its_otime
868b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define	icmp_rtime	icmp_dun.id_ts.its_rtime
878b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define	icmp_ttime	icmp_dun.id_ts.its_ttime
888b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define	icmp_ip		icmp_dun.id_ip.idi_ip
898b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define	icmp_mask	icmp_dun.id_mask
908b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define	icmp_data	icmp_dun.id_data
918b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project};
928b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
938b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project/*
948b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project * Lower bounds on packet lengths for various types.
958b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project * For the error advice packets must first insure that the
968b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project * packet is large enought to contain the returned ip header.
978b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project * Only then can we do the check to see if 64 bits of packet
988b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project * data have been returned, since we need to check the returned
998b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project * ip header length.
1008b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project */
1018b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define	ICMP_MINLEN	8				/* abs minimum */
1028b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define	ICMP_TSLEN	(8 + 3 * sizeof (n_time))	/* timestamp */
1038b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define	ICMP_MASKLEN	12				/* address mask */
1048b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define	ICMP_ADVLENMIN	(8 + sizeof (struct ip) + 8)	/* min */
1058b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define	ICMP_ADVLEN(p)	(8 + ((p)->icmp_ip.ip_hl << 2) + 8)
1068b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project	/* N.B.: must separately check that ip_hl >= 5 */
1078b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
1088b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project/*
1098b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project * Definition of type and code field values.
1108b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project */
1118b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define	ICMP_ECHOREPLY		0		/* echo reply */
1128b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define	ICMP_UNREACH		3		/* dest unreachable, codes: */
1138b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define		ICMP_UNREACH_NET	0		/* bad net */
1148b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define		ICMP_UNREACH_HOST	1		/* bad host */
1158b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define		ICMP_UNREACH_PROTOCOL	2		/* bad protocol */
1168b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define		ICMP_UNREACH_PORT	3		/* bad port */
1178b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define		ICMP_UNREACH_NEEDFRAG	4		/* IP_DF caused drop */
1188b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define		ICMP_UNREACH_SRCFAIL	5		/* src route failed */
1198b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define		ICMP_UNREACH_NET_UNKNOWN 6		/* unknown net */
1208b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define		ICMP_UNREACH_HOST_UNKNOWN 7		/* unknown host */
1218b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define		ICMP_UNREACH_ISOLATED	8		/* src host isolated */
1228b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define		ICMP_UNREACH_NET_PROHIB	9		/* prohibited access */
1238b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define		ICMP_UNREACH_HOST_PROHIB 10		/* ditto */
1248b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define		ICMP_UNREACH_TOSNET	11		/* bad tos for net */
1258b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define		ICMP_UNREACH_TOSHOST	12		/* bad tos for host */
1268b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define	ICMP_SOURCEQUENCH	4		/* packet lost, slow down */
1278b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define	ICMP_REDIRECT		5		/* shorter route, codes: */
1288b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define		ICMP_REDIRECT_NET	0		/* for network */
1298b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define		ICMP_REDIRECT_HOST	1		/* for host */
1308b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define		ICMP_REDIRECT_TOSNET	2		/* for tos and net */
1318b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define		ICMP_REDIRECT_TOSHOST	3		/* for tos and host */
1328b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define	ICMP_ECHO		8		/* echo service */
1338b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define	ICMP_ROUTERADVERT	9		/* router advertisement */
1348b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define	ICMP_ROUTERSOLICIT	10		/* router solicitation */
1358b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define	ICMP_TIMXCEED		11		/* time exceeded, code: */
1368b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define		ICMP_TIMXCEED_INTRANS	0		/* ttl==0 in transit */
1378b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define		ICMP_TIMXCEED_REASS	1		/* ttl==0 in reass */
1388b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define	ICMP_PARAMPROB		12		/* ip header bad */
1398b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define		ICMP_PARAMPROB_OPTABSENT 1		/* req. opt. absent */
1408b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define	ICMP_TSTAMP		13		/* timestamp request */
1418b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define	ICMP_TSTAMPREPLY	14		/* timestamp reply */
1428b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define	ICMP_IREQ		15		/* information request */
1438b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define	ICMP_IREQREPLY		16		/* information reply */
1448b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define	ICMP_MASKREQ		17		/* address mask request */
1458b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define	ICMP_MASKREPLY		18		/* address mask reply */
1468b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
1478b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define	ICMP_MAXTYPE		18
1488b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
1498b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define	ICMP_INFOTYPE(type) \
1508b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project	((type) == ICMP_ECHOREPLY || (type) == ICMP_ECHO || \
1518b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project	(type) == ICMP_ROUTERADVERT || (type) == ICMP_ROUTERSOLICIT || \
1528b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project	(type) == ICMP_TSTAMP || (type) == ICMP_TSTAMPREPLY || \
1538b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project	(type) == ICMP_IREQ || (type) == ICMP_IREQREPLY || \
1548b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project	(type) == ICMP_MASKREQ || (type) == ICMP_MASKREPLY)
1558b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
1565d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turnervoid icmp_input _P((struct mbuf *, int));
1575d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turnervoid icmp_error(struct mbuf *msrc, u_char type, u_char code, int minsize,
1585d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner                const char *message);
1595d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turnervoid icmp_reflect _P((struct mbuf *));
1608b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
1618b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#endif
162