ip_icmp.h 9.9 KB

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