]> git.ipfire.org Git - thirdparty/glibc.git/blame - sysdeps/gnu/netinet/ip_icmp.h
Update copyright dates with scripts/update-copyrights.
[thirdparty/glibc.git] / sysdeps / gnu / netinet / ip_icmp.h
CommitLineData
bfff8b1b 1/* Copyright (C) 1991-2017 Free Software Foundation, Inc.
1fb05e3d
UD
2 This file is part of the GNU C Library.
3
4 The GNU C Library is free software; you can redistribute it and/or
41bdb6e2
AJ
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
1fb05e3d
UD
8
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
41bdb6e2 12 Lesser General Public License for more details.
1fb05e3d 13
41bdb6e2 14 You should have received a copy of the GNU Lesser General Public
59ba27a6
PE
15 License along with the GNU C Library; if not, see
16 <http://www.gnu.org/licenses/>. */
1fb05e3d
UD
17
18#ifndef __NETINET_IP_ICMP_H
19#define __NETINET_IP_ICMP_H 1
20
1fb05e3d 21#include <sys/types.h>
11160cb7 22#include <stdint.h>
1fb05e3d
UD
23
24__BEGIN_DECLS
25
5929563f
UD
26struct icmphdr
27{
11160cb7
ZW
28 uint8_t type; /* message type */
29 uint8_t code; /* type sub-code */
30 uint16_t checksum;
5929563f
UD
31 union
32 {
33 struct
34 {
11160cb7
ZW
35 uint16_t id;
36 uint16_t sequence;
5929563f 37 } echo; /* echo datagram */
11160cb7 38 uint32_t gateway; /* gateway address */
5929563f
UD
39 struct
40 {
11160cb7
ZW
41 uint16_t __glibc_reserved;
42 uint16_t mtu;
5929563f
UD
43 } frag; /* path mtu discovery */
44 } un;
45};
46
47#define ICMP_ECHOREPLY 0 /* Echo Reply */
48#define ICMP_DEST_UNREACH 3 /* Destination Unreachable */
49#define ICMP_SOURCE_QUENCH 4 /* Source Quench */
50#define ICMP_REDIRECT 5 /* Redirect (change route) */
51#define ICMP_ECHO 8 /* Echo Request */
52#define ICMP_TIME_EXCEEDED 11 /* Time Exceeded */
53#define ICMP_PARAMETERPROB 12 /* Parameter Problem */
54#define ICMP_TIMESTAMP 13 /* Timestamp Request */
55#define ICMP_TIMESTAMPREPLY 14 /* Timestamp Reply */
56#define ICMP_INFO_REQUEST 15 /* Information Request */
57#define ICMP_INFO_REPLY 16 /* Information Reply */
58#define ICMP_ADDRESS 17 /* Address Mask Request */
59#define ICMP_ADDRESSREPLY 18 /* Address Mask Reply */
60#define NR_ICMP_TYPES 18
61
62
63/* Codes for UNREACH. */
64#define ICMP_NET_UNREACH 0 /* Network Unreachable */
65#define ICMP_HOST_UNREACH 1 /* Host Unreachable */
66#define ICMP_PROT_UNREACH 2 /* Protocol Unreachable */
67#define ICMP_PORT_UNREACH 3 /* Port Unreachable */
68#define ICMP_FRAG_NEEDED 4 /* Fragmentation Needed/DF set */
69#define ICMP_SR_FAILED 5 /* Source Route failed */
70#define ICMP_NET_UNKNOWN 6
71#define ICMP_HOST_UNKNOWN 7
72#define ICMP_HOST_ISOLATED 8
73#define ICMP_NET_ANO 9
74#define ICMP_HOST_ANO 10
75#define ICMP_NET_UNR_TOS 11
76#define ICMP_HOST_UNR_TOS 12
77#define ICMP_PKT_FILTERED 13 /* Packet filtered */
78#define ICMP_PREC_VIOLATION 14 /* Precedence violation */
79#define ICMP_PREC_CUTOFF 15 /* Precedence cut off */
80#define NR_ICMP_UNREACH 15 /* instead of hardcoding immediate value */
81
82/* Codes for REDIRECT. */
83#define ICMP_REDIR_NET 0 /* Redirect Net */
84#define ICMP_REDIR_HOST 1 /* Redirect Host */
85#define ICMP_REDIR_NETTOS 2 /* Redirect Net for TOS */
86#define ICMP_REDIR_HOSTTOS 3 /* Redirect Host for TOS */
87
88/* Codes for TIME_EXCEEDED. */
89#define ICMP_EXC_TTL 0 /* TTL count exceeded */
90#define ICMP_EXC_FRAGTIME 1 /* Fragment Reass time exceeded */
91
92
498afc54 93#ifdef __USE_MISC
1fb05e3d
UD
94/*
95 * Copyright (c) 1982, 1986, 1993
96 * The Regents of the University of California. All rights reserved.
97 *
98 * Redistribution and use in source and binary forms, with or without
99 * modification, are permitted provided that the following conditions
100 * are met:
101 * 1. Redistributions of source code must retain the above copyright
102 * notice, this list of conditions and the following disclaimer.
103 * 2. Redistributions in binary form must reproduce the above copyright
104 * notice, this list of conditions and the following disclaimer in the
105 * documentation and/or other materials provided with the distribution.
1fb05e3d
UD
106 * 4. Neither the name of the University nor the names of its contributors
107 * may be used to endorse or promote products derived from this software
108 * without specific prior written permission.
109 *
110 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
111 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
112 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
113 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
114 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
115 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
116 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
117 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
118 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
119 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
120 * SUCH DAMAGE.
121 *
122 * @(#)ip_icmp.h 8.1 (Berkeley) 6/10/93
123 */
124
125#include <netinet/in.h>
126#include <netinet/ip.h>
127
128/*
129 * Internal of an ICMP Router Advertisement
130 */
5929563f
UD
131struct icmp_ra_addr
132{
11160cb7
ZW
133 uint32_t ira_addr;
134 uint32_t ira_preference;
1fb05e3d
UD
135};
136
5929563f
UD
137struct icmp
138{
11160cb7
ZW
139 uint8_t icmp_type; /* type of message, see below */
140 uint8_t icmp_code; /* type sub code */
141 uint16_t icmp_cksum; /* ones complement checksum of struct */
5929563f
UD
142 union
143 {
11160cb7 144 unsigned char ih_pptr; /* ICMP_PARAMPROB */
1fb05e3d 145 struct in_addr ih_gwaddr; /* gateway address */
5929563f
UD
146 struct ih_idseq /* echo datagram */
147 {
11160cb7
ZW
148 uint16_t icd_id;
149 uint16_t icd_seq;
1fb05e3d 150 } ih_idseq;
11160cb7 151 uint32_t ih_void;
1fb05e3d
UD
152
153 /* ICMP_UNREACH_NEEDFRAG -- Path MTU Discovery (RFC1191) */
5929563f
UD
154 struct ih_pmtu
155 {
11160cb7
ZW
156 uint16_t ipm_void;
157 uint16_t ipm_nextmtu;
1fb05e3d
UD
158 } ih_pmtu;
159
5929563f
UD
160 struct ih_rtradv
161 {
11160cb7
ZW
162 uint8_t irt_num_addrs;
163 uint8_t irt_wpa;
164 uint16_t irt_lifetime;
1fb05e3d
UD
165 } ih_rtradv;
166 } icmp_hun;
167#define icmp_pptr icmp_hun.ih_pptr
168#define icmp_gwaddr icmp_hun.ih_gwaddr
169#define icmp_id icmp_hun.ih_idseq.icd_id
170#define icmp_seq icmp_hun.ih_idseq.icd_seq
171#define icmp_void icmp_hun.ih_void
172#define icmp_pmvoid icmp_hun.ih_pmtu.ipm_void
173#define icmp_nextmtu icmp_hun.ih_pmtu.ipm_nextmtu
174#define icmp_num_addrs icmp_hun.ih_rtradv.irt_num_addrs
175#define icmp_wpa icmp_hun.ih_rtradv.irt_wpa
176#define icmp_lifetime icmp_hun.ih_rtradv.irt_lifetime
5929563f
UD
177 union
178 {
179 struct
180 {
11160cb7
ZW
181 uint32_t its_otime;
182 uint32_t its_rtime;
183 uint32_t its_ttime;
1fb05e3d 184 } id_ts;
5929563f
UD
185 struct
186 {
1fb05e3d
UD
187 struct ip idi_ip;
188 /* options and then 64 bits of data */
189 } id_ip;
190 struct icmp_ra_addr id_radv;
11160cb7
ZW
191 uint32_t id_mask;
192 uint8_t id_data[1];
1fb05e3d
UD
193 } icmp_dun;
194#define icmp_otime icmp_dun.id_ts.its_otime
195#define icmp_rtime icmp_dun.id_ts.its_rtime
196#define icmp_ttime icmp_dun.id_ts.its_ttime
197#define icmp_ip icmp_dun.id_ip.idi_ip
198#define icmp_radv icmp_dun.id_radv
199#define icmp_mask icmp_dun.id_mask
200#define icmp_data icmp_dun.id_data
201};
202
203/*
204 * Lower bounds on packet lengths for various types.
205 * For the error advice packets must first insure that the
206 * packet is large enough to contain the returned ip header.
207 * Only then can we do the check to see if 64 bits of packet
208 * data have been returned, since we need to check the returned
209 * ip header length.
210 */
211#define ICMP_MINLEN 8 /* abs minimum */
212#define ICMP_TSLEN (8 + 3 * sizeof (n_time)) /* timestamp */
213#define ICMP_MASKLEN 12 /* address mask */
214#define ICMP_ADVLENMIN (8 + sizeof (struct ip) + 8) /* min */
215#ifndef _IP_VHL
216#define ICMP_ADVLEN(p) (8 + ((p)->icmp_ip.ip_hl << 2) + 8)
217 /* N.B.: must separately check that ip_hl >= 5 */
218#else
219#define ICMP_ADVLEN(p) (8 + (IP_VHL_HL((p)->icmp_ip.ip_vhl) << 2) + 8)
220 /* N.B.: must separately check that header length >= 5 */
221#endif
222
223/* Definition of type and code fields. */
5929563f 224/* defined above: ICMP_ECHOREPLY, ICMP_REDIRECT, ICMP_ECHO */
1fb05e3d
UD
225#define ICMP_UNREACH 3 /* dest unreachable, codes: */
226#define ICMP_SOURCEQUENCH 4 /* packet lost, slow down */
1fb05e3d
UD
227#define ICMP_ROUTERADVERT 9 /* router advertisement */
228#define ICMP_ROUTERSOLICIT 10 /* router solicitation */
229#define ICMP_TIMXCEED 11 /* time exceeded, code: */
230#define ICMP_PARAMPROB 12 /* ip header bad */
231#define ICMP_TSTAMP 13 /* timestamp request */
232#define ICMP_TSTAMPREPLY 14 /* timestamp reply */
233#define ICMP_IREQ 15 /* information request */
234#define ICMP_IREQREPLY 16 /* information reply */
235#define ICMP_MASKREQ 17 /* address mask request */
236#define ICMP_MASKREPLY 18 /* address mask reply */
237
238#define ICMP_MAXTYPE 18
239
240/* UNREACH codes */
241#define ICMP_UNREACH_NET 0 /* bad net */
242#define ICMP_UNREACH_HOST 1 /* bad host */
243#define ICMP_UNREACH_PROTOCOL 2 /* bad protocol */
244#define ICMP_UNREACH_PORT 3 /* bad port */
245#define ICMP_UNREACH_NEEDFRAG 4 /* IP_DF caused drop */
246#define ICMP_UNREACH_SRCFAIL 5 /* src route failed */
247#define ICMP_UNREACH_NET_UNKNOWN 6 /* unknown net */
248#define ICMP_UNREACH_HOST_UNKNOWN 7 /* unknown host */
249#define ICMP_UNREACH_ISOLATED 8 /* src host isolated */
250#define ICMP_UNREACH_NET_PROHIB 9 /* net denied */
251#define ICMP_UNREACH_HOST_PROHIB 10 /* host denied */
252#define ICMP_UNREACH_TOSNET 11 /* bad tos for net */
253#define ICMP_UNREACH_TOSHOST 12 /* bad tos for host */
254#define ICMP_UNREACH_FILTER_PROHIB 13 /* admin prohib */
255#define ICMP_UNREACH_HOST_PRECEDENCE 14 /* host prec vio. */
256#define ICMP_UNREACH_PRECEDENCE_CUTOFF 15 /* prec cutoff */
257
258/* REDIRECT codes */
259#define ICMP_REDIRECT_NET 0 /* for network */
260#define ICMP_REDIRECT_HOST 1 /* for host */
261#define ICMP_REDIRECT_TOSNET 2 /* for tos and net */
262#define ICMP_REDIRECT_TOSHOST 3 /* for tos and host */
263
264/* TIMEXCEED codes */
265#define ICMP_TIMXCEED_INTRANS 0 /* ttl==0 in transit */
266#define ICMP_TIMXCEED_REASS 1 /* ttl==0 in reass */
267
268/* PARAMPROB code */
269#define ICMP_PARAMPROB_OPTABSENT 1 /* req. opt. absent */
270
271#define ICMP_INFOTYPE(type) \
272 ((type) == ICMP_ECHOREPLY || (type) == ICMP_ECHO || \
273 (type) == ICMP_ROUTERADVERT || (type) == ICMP_ROUTERSOLICIT || \
274 (type) == ICMP_TSTAMP || (type) == ICMP_TSTAMPREPLY || \
275 (type) == ICMP_IREQ || (type) == ICMP_IREQREPLY || \
276 (type) == ICMP_MASKREQ || (type) == ICMP_MASKREPLY)
277
498afc54 278#endif /* __USE_MISC */
5929563f 279
1fb05e3d
UD
280__END_DECLS
281
282#endif /* netinet/ip_icmp.h */