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#include "helper.h"
378b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
388b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project/*
398b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project * Interface Control Message Protocol Definitions.
408b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project * Per RFC 792, September 1981.
418b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project */
428b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
438b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Projecttypedef u_int32_t n_time;
448b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
458b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project/*
468b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project * Structure of an icmp header.
478b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project */
488b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Projectstruct icmp {
498b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project	u_char	icmp_type;		/* type of message, see below */
508b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project	u_char	icmp_code;		/* type sub code */
518b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project	u_short	icmp_cksum;		/* ones complement cksum of struct */
528b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project	union {
538b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project		u_char    ih_pptr;			/* ICMP_PARAMPROB */
548b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project		ipaddr_t  ih_gwaddr;	/* ICMP_REDIRECT */
558b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project		struct ih_idseq {
568b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project			u_short	icd_id;
578b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project			u_short	icd_seq;
588b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project		} ih_idseq;
598b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project		int ih_void;
608b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
618b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project		/* ICMP_UNREACH_NEEDFRAG -- Path MTU Discovery (RFC1191) */
628b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project		struct ih_pmtu {
638b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project			u_short ipm_void;
648b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project			u_short ipm_nextmtu;
658b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project		} ih_pmtu;
668b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project	} icmp_hun;
678b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define	icmp_pptr	icmp_hun.ih_pptr
688b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define	icmp_gwaddr	icmp_hun.ih_gwaddr
698b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define	icmp_id		icmp_hun.ih_idseq.icd_id
708b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define	icmp_seq	icmp_hun.ih_idseq.icd_seq
718b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define	icmp_void	icmp_hun.ih_void
728b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define	icmp_pmvoid	icmp_hun.ih_pmtu.ipm_void
738b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define	icmp_nextmtu	icmp_hun.ih_pmtu.ipm_nextmtu
748b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project	union {
758b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project		struct id_ts {
768b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project			n_time its_otime;
778b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project			n_time its_rtime;
788b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project			n_time its_ttime;
798b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project		} id_ts;
808b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project		struct id_ip  {
818b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project			struct ip idi_ip;
828b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project			/* options and then 64 bits of data */
838b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project		} id_ip;
848b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project		uint32_t	id_mask;
858b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project		char		id_data[1];
868b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project	} icmp_dun;
878b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define	icmp_otime	icmp_dun.id_ts.its_otime
888b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define	icmp_rtime	icmp_dun.id_ts.its_rtime
898b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define	icmp_ttime	icmp_dun.id_ts.its_ttime
908b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define	icmp_ip		icmp_dun.id_ip.idi_ip
918b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define	icmp_mask	icmp_dun.id_mask
928b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define	icmp_data	icmp_dun.id_data
938b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project};
948b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
958b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project/*
968b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project * Lower bounds on packet lengths for various types.
978b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project * For the error advice packets must first insure that the
988b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project * packet is large enought to contain the returned ip header.
998b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project * Only then can we do the check to see if 64 bits of packet
1008b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project * data have been returned, since we need to check the returned
1018b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project * ip header length.
1028b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project */
1038b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define	ICMP_MINLEN	8				/* abs minimum */
1048b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define	ICMP_TSLEN	(8 + 3 * sizeof (n_time))	/* timestamp */
1058b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define	ICMP_MASKLEN	12				/* address mask */
1068b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define	ICMP_ADVLENMIN	(8 + sizeof (struct ip) + 8)	/* min */
1078b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define	ICMP_ADVLEN(p)	(8 + ((p)->icmp_ip.ip_hl << 2) + 8)
1088b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project	/* N.B.: must separately check that ip_hl >= 5 */
1098b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
1108b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project/*
1118b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project * Definition of type and code field values.
1128b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project */
1138b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define	ICMP_ECHOREPLY		0		/* echo reply */
1148b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define	ICMP_UNREACH		3		/* dest unreachable, codes: */
1158b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define		ICMP_UNREACH_NET	0		/* bad net */
1168b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define		ICMP_UNREACH_HOST	1		/* bad host */
1178b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define		ICMP_UNREACH_PROTOCOL	2		/* bad protocol */
1188b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define		ICMP_UNREACH_PORT	3		/* bad port */
1198b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define		ICMP_UNREACH_NEEDFRAG	4		/* IP_DF caused drop */
1208b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define		ICMP_UNREACH_SRCFAIL	5		/* src route failed */
1218b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define		ICMP_UNREACH_NET_UNKNOWN 6		/* unknown net */
1228b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define		ICMP_UNREACH_HOST_UNKNOWN 7		/* unknown host */
1238b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define		ICMP_UNREACH_ISOLATED	8		/* src host isolated */
1248b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define		ICMP_UNREACH_NET_PROHIB	9		/* prohibited access */
1258b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define		ICMP_UNREACH_HOST_PROHIB 10		/* ditto */
1268b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define		ICMP_UNREACH_TOSNET	11		/* bad tos for net */
1278b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define		ICMP_UNREACH_TOSHOST	12		/* bad tos for host */
1288b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define	ICMP_SOURCEQUENCH	4		/* packet lost, slow down */
1298b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define	ICMP_REDIRECT		5		/* shorter route, codes: */
1308b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define		ICMP_REDIRECT_NET	0		/* for network */
1318b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define		ICMP_REDIRECT_HOST	1		/* for host */
1328b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define		ICMP_REDIRECT_TOSNET	2		/* for tos and net */
1338b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define		ICMP_REDIRECT_TOSHOST	3		/* for tos and host */
1348b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define	ICMP_ECHO		8		/* echo service */
1358b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define	ICMP_ROUTERADVERT	9		/* router advertisement */
1368b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define	ICMP_ROUTERSOLICIT	10		/* router solicitation */
1378b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define	ICMP_TIMXCEED		11		/* time exceeded, code: */
1388b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define		ICMP_TIMXCEED_INTRANS	0		/* ttl==0 in transit */
1398b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define		ICMP_TIMXCEED_REASS	1		/* ttl==0 in reass */
1408b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define	ICMP_PARAMPROB		12		/* ip header bad */
1418b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define		ICMP_PARAMPROB_OPTABSENT 1		/* req. opt. absent */
1428b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define	ICMP_TSTAMP		13		/* timestamp request */
1438b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define	ICMP_TSTAMPREPLY	14		/* timestamp reply */
1448b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define	ICMP_IREQ		15		/* information request */
1458b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define	ICMP_IREQREPLY		16		/* information reply */
1468b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define	ICMP_MASKREQ		17		/* address mask request */
1478b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define	ICMP_MASKREPLY		18		/* address mask reply */
1488b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
1498b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define	ICMP_MAXTYPE		18
1508b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
1518b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#define	ICMP_INFOTYPE(type) \
1528b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project	((type) == ICMP_ECHOREPLY || (type) == ICMP_ECHO || \
1538b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project	(type) == ICMP_ROUTERADVERT || (type) == ICMP_ROUTERSOLICIT || \
1548b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project	(type) == ICMP_TSTAMP || (type) == ICMP_TSTAMPREPLY || \
1558b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project	(type) == ICMP_IREQ || (type) == ICMP_IREQREPLY || \
1568b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project	(type) == ICMP_MASKREQ || (type) == ICMP_MASKREPLY)
1578b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
1585d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turnervoid icmp_input _P((struct mbuf *, int));
1595d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turnervoid icmp_error(struct mbuf *msrc, u_char type, u_char code, int minsize,
1605d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turner                const char *message);
1615d8f37ad78fc66901af50c762029a501561f3b23David 'Digit' Turnervoid icmp_reflect _P((struct mbuf *));
1628b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project
1638b23a6c7e1aee255004dd19098d4c2462b61b849The Android Open Source Project#endif
164