xref: /original-bsd/sys/netinet/ip_icmp.h (revision b4971bb3)
1 /*
2  * Copyright (c) 1982, 1986 Regents of the University of California.
3  * All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  *
7  *	@(#)ip_icmp.h	7.8 (Berkeley) 06/04/93
8  */
9 
10 /*
11  * Interface Control Message Protocol Definitions.
12  * Per RFC 792, September 1981.
13  */
14 
15 /*
16  * Structure of an icmp header.
17  */
18 struct icmp {
19 	u_char	icmp_type;		/* type of message, see below */
20 	u_char	icmp_code;		/* type sub code */
21 	u_short	icmp_cksum;		/* ones complement cksum of struct */
22 	union {
23 		u_char ih_pptr;			/* ICMP_PARAMPROB */
24 		struct in_addr ih_gwaddr;	/* ICMP_REDIRECT */
25 		struct ih_idseq {
26 			n_short	icd_id;
27 			n_short	icd_seq;
28 		} ih_idseq;
29 		int ih_void;
30 
31 		/* ICMP_UNREACH_NEEDFRAG -- Path MTU Discovery (RFC1191) */
32 		struct ih_pmtu {
33 			n_short ipm_void;
34 			n_short ipm_nextmtu;
35 		} ih_pmtu;
36 	} icmp_hun;
37 #define	icmp_pptr	icmp_hun.ih_pptr
38 #define	icmp_gwaddr	icmp_hun.ih_gwaddr
39 #define	icmp_id		icmp_hun.ih_idseq.icd_id
40 #define	icmp_seq	icmp_hun.ih_idseq.icd_seq
41 #define	icmp_void	icmp_hun.ih_void
42 #define	icmp_pmvoid	icmp_hun.ih_pmtu.ipm_void
43 #define	icmp_nextmtu	icmp_hun.ih_pmtu.ipm_nextmtu
44 	union {
45 		struct id_ts {
46 			n_time its_otime;
47 			n_time its_rtime;
48 			n_time its_ttime;
49 		} id_ts;
50 		struct id_ip  {
51 			struct ip idi_ip;
52 			/* options and then 64 bits of data */
53 		} id_ip;
54 		u_long	id_mask;
55 		char	id_data[1];
56 	} icmp_dun;
57 #define	icmp_otime	icmp_dun.id_ts.its_otime
58 #define	icmp_rtime	icmp_dun.id_ts.its_rtime
59 #define	icmp_ttime	icmp_dun.id_ts.its_ttime
60 #define	icmp_ip		icmp_dun.id_ip.idi_ip
61 #define	icmp_mask	icmp_dun.id_mask
62 #define	icmp_data	icmp_dun.id_data
63 };
64 
65 /*
66  * Lower bounds on packet lengths for various types.
67  * For the error advice packets must first insure that the
68  * packet is large enought to contain the returned ip header.
69  * Only then can we do the check to see if 64 bits of packet
70  * data have been returned, since we need to check the returned
71  * ip header length.
72  */
73 #define	ICMP_MINLEN	8				/* abs minimum */
74 #define	ICMP_TSLEN	(8 + 3 * sizeof (n_time))	/* timestamp */
75 #define	ICMP_MASKLEN	12				/* address mask */
76 #define	ICMP_ADVLENMIN	(8 + sizeof (struct ip) + 8)	/* min */
77 #define	ICMP_ADVLEN(p)	(8 + ((p)->icmp_ip.ip_hl << 2) + 8)
78 	/* N.B.: must separately check that ip_hl >= 5 */
79 
80 /*
81  * Definition of type and code field values.
82  */
83 #define	ICMP_ECHOREPLY		0		/* echo reply */
84 #define	ICMP_UNREACH		3		/* dest unreachable, codes: */
85 #define		ICMP_UNREACH_NET	0		/* bad net */
86 #define		ICMP_UNREACH_HOST	1		/* bad host */
87 #define		ICMP_UNREACH_PROTOCOL	2		/* bad protocol */
88 #define		ICMP_UNREACH_PORT	3		/* bad port */
89 #define		ICMP_UNREACH_NEEDFRAG	4		/* IP_DF caused drop */
90 #define		ICMP_UNREACH_SRCFAIL	5		/* src route failed */
91 #define		ICMP_UNREACH_NET_UNKNOWN 6		/* unknown net */
92 #define		ICMP_UNREACH_HOST_UNKNOWN 7		/* unknown host */
93 #define		ICMP_UNREACH_ISOLATED	8		/* src host isolated */
94 #define		ICMP_UNREACH_NET_PROHIB	9		/* prohibited access */
95 #define		ICMP_UNREACH_HOST_PROHIB 10		/* ditto */
96 #define		ICMP_UNREACH_TOSNET	11		/* bad tos for net */
97 #define		ICMP_UNREACH_TOSHOST	12		/* bad tos for host */
98 #define	ICMP_SOURCEQUENCH	4		/* packet lost, slow down */
99 #define	ICMP_REDIRECT		5		/* shorter route, codes: */
100 #define		ICMP_REDIRECT_NET	0		/* for network */
101 #define		ICMP_REDIRECT_HOST	1		/* for host */
102 #define		ICMP_REDIRECT_TOSNET	2		/* for tos and net */
103 #define		ICMP_REDIRECT_TOSHOST	3		/* for tos and host */
104 #define	ICMP_ECHO		8		/* echo service */
105 #define	ICMP_ROUTERADVERT	9		/* router advertisement */
106 #define	ICMP_ROUTERSOLICIT	10		/* router solicitation */
107 #define	ICMP_TIMXCEED		11		/* time exceeded, code: */
108 #define		ICMP_TIMXCEED_INTRANS	0		/* ttl==0 in transit */
109 #define		ICMP_TIMXCEED_REASS	1		/* ttl==0 in reass */
110 #define	ICMP_PARAMPROB		12		/* ip header bad */
111 #define		ICMP_PARAMPROB_OPTABSENT 1		/* req. opt. absent */
112 #define	ICMP_TSTAMP		13		/* timestamp request */
113 #define	ICMP_TSTAMPREPLY	14		/* timestamp reply */
114 #define	ICMP_IREQ		15		/* information request */
115 #define	ICMP_IREQREPLY		16		/* information reply */
116 #define	ICMP_MASKREQ		17		/* address mask request */
117 #define	ICMP_MASKREPLY		18		/* address mask reply */
118 
119 #define	ICMP_MAXTYPE		18
120 
121 #define	ICMP_INFOTYPE(type) \
122 	((type) == ICMP_ECHOREPLY || (type) == ICMP_ECHO || \
123 	(type) == ICMP_ROUTERADVERT || (type) == ICMP_ROUTERSOLICIT || \
124 	(type) == ICMP_TSTAMP || (type) == ICMP_TSTAMPREPLY || \
125 	(type) == ICMP_IREQ || (type) == ICMP_IREQREPLY || \
126 	(type) == ICMP_MASKREQ || (type) == ICMP_MASKREPLY)
127 
128 #ifdef KERNEL
129 void	icmp_error __P((struct mbuf *, int, int, n_long, struct ifnet *));
130 void	icmp_input __P((struct mbuf *, int));
131 void	icmp_reflect __P((struct mbuf *));
132 void	icmp_send __P((struct mbuf *, struct mbuf *));
133 int	icmp_sysctl __P((int *, u_int, void *, size_t *, void *, size_t));
134 #endif
135