ip.h 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. /* Copyright (C) 1991-2020 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. <https://www.gnu.org/licenses/>. */
  14. #ifndef __NETINET_IP_H
  15. #define __NETINET_IP_H 1
  16. #include <features.h>
  17. #include <sys/types.h>
  18. #include <netinet/in.h>
  19. __BEGIN_DECLS
  20. struct timestamp
  21. {
  22. uint8_t len;
  23. uint8_t ptr;
  24. #if __BYTE_ORDER == __LITTLE_ENDIAN
  25. unsigned int flags:4;
  26. unsigned int overflow:4;
  27. #elif __BYTE_ORDER == __BIG_ENDIAN
  28. unsigned int overflow:4;
  29. unsigned int flags:4;
  30. #else
  31. # error "Please fix <bits/endian.h>"
  32. #endif
  33. uint32_t data[9];
  34. };
  35. struct iphdr
  36. {
  37. #if __BYTE_ORDER == __LITTLE_ENDIAN
  38. unsigned int ihl:4;
  39. unsigned int version:4;
  40. #elif __BYTE_ORDER == __BIG_ENDIAN
  41. unsigned int version:4;
  42. unsigned int ihl:4;
  43. #else
  44. # error "Please fix <bits/endian.h>"
  45. #endif
  46. uint8_t tos;
  47. uint16_t tot_len;
  48. uint16_t id;
  49. uint16_t frag_off;
  50. uint8_t ttl;
  51. uint8_t protocol;
  52. uint16_t check;
  53. uint32_t saddr;
  54. uint32_t daddr;
  55. /*The options start here. */
  56. };
  57. #ifdef __USE_MISC
  58. /*
  59. * Copyright (c) 1982, 1986, 1993
  60. * The Regents of the University of California. All rights reserved.
  61. *
  62. * Redistribution and use in source and binary forms, with or without
  63. * modification, are permitted provided that the following conditions
  64. * are met:
  65. * 1. Redistributions of source code must retain the above copyright
  66. * notice, this list of conditions and the following disclaimer.
  67. * 2. Redistributions in binary form must reproduce the above copyright
  68. * notice, this list of conditions and the following disclaimer in the
  69. * documentation and/or other materials provided with the distribution.
  70. * 4. Neither the name of the University nor the names of its contributors
  71. * may be used to endorse or promote products derived from this software
  72. * without specific prior written permission.
  73. *
  74. * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  75. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  76. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  77. * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  78. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  79. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  80. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  81. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  82. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  83. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  84. * SUCH DAMAGE.
  85. *
  86. * @(#)ip.h 8.1 (Berkeley) 6/10/93
  87. */
  88. /*
  89. * Definitions for internet protocol version 4.
  90. * Per RFC 791, September 1981.
  91. */
  92. /*
  93. * Structure of an internet header, naked of options.
  94. */
  95. struct ip
  96. {
  97. #if __BYTE_ORDER == __LITTLE_ENDIAN
  98. unsigned int ip_hl:4; /* header length */
  99. unsigned int ip_v:4; /* version */
  100. #endif
  101. #if __BYTE_ORDER == __BIG_ENDIAN
  102. unsigned int ip_v:4; /* version */
  103. unsigned int ip_hl:4; /* header length */
  104. #endif
  105. uint8_t ip_tos; /* type of service */
  106. unsigned short ip_len; /* total length */
  107. unsigned short ip_id; /* identification */
  108. unsigned short ip_off; /* fragment offset field */
  109. #define IP_RF 0x8000 /* reserved fragment flag */
  110. #define IP_DF 0x4000 /* dont fragment flag */
  111. #define IP_MF 0x2000 /* more fragments flag */
  112. #define IP_OFFMASK 0x1fff /* mask for fragmenting bits */
  113. uint8_t ip_ttl; /* time to live */
  114. uint8_t ip_p; /* protocol */
  115. unsigned short ip_sum; /* checksum */
  116. struct in_addr ip_src, ip_dst; /* source and dest address */
  117. };
  118. /*
  119. * Time stamp option structure.
  120. */
  121. struct ip_timestamp
  122. {
  123. uint8_t ipt_code; /* IPOPT_TS */
  124. uint8_t ipt_len; /* size of structure (variable) */
  125. uint8_t ipt_ptr; /* index of current entry */
  126. #if __BYTE_ORDER == __LITTLE_ENDIAN
  127. unsigned int ipt_flg:4; /* flags, see below */
  128. unsigned int ipt_oflw:4; /* overflow counter */
  129. #endif
  130. #if __BYTE_ORDER == __BIG_ENDIAN
  131. unsigned int ipt_oflw:4; /* overflow counter */
  132. unsigned int ipt_flg:4; /* flags, see below */
  133. #endif
  134. uint32_t data[9];
  135. };
  136. #endif /* __USE_MISC */
  137. #define IPVERSION 4 /* IP version number */
  138. #define IP_MAXPACKET 65535 /* maximum packet size */
  139. /*
  140. * Definitions for Explicit Congestion Notification (ECN)
  141. *
  142. * Taken from RFC-3168, Section 5.
  143. */
  144. #define IPTOS_ECN_MASK 0x03
  145. #define IPTOS_ECN(x) ((x) & IPTOS_ECN_MASK)
  146. #define IPTOS_ECN_NOT_ECT 0x00
  147. #define IPTOS_ECN_ECT1 0x01
  148. #define IPTOS_ECN_ECT0 0x02
  149. #define IPTOS_ECN_CE 0x03
  150. /*
  151. * Definitions for IP differentiated services code points (DSCP)
  152. *
  153. * Taken from RFC-2597, Section 6 and RFC-2598, Section 2.3.
  154. */
  155. #define IPTOS_DSCP_MASK 0xfc
  156. #define IPTOS_DSCP(x) ((x) & IPTOS_DSCP_MASK)
  157. #define IPTOS_DSCP_AF11 0x28
  158. #define IPTOS_DSCP_AF12 0x30
  159. #define IPTOS_DSCP_AF13 0x38
  160. #define IPTOS_DSCP_AF21 0x48
  161. #define IPTOS_DSCP_AF22 0x50
  162. #define IPTOS_DSCP_AF23 0x58
  163. #define IPTOS_DSCP_AF31 0x68
  164. #define IPTOS_DSCP_AF32 0x70
  165. #define IPTOS_DSCP_AF33 0x78
  166. #define IPTOS_DSCP_AF41 0x88
  167. #define IPTOS_DSCP_AF42 0x90
  168. #define IPTOS_DSCP_AF43 0x98
  169. #define IPTOS_DSCP_EF 0xb8
  170. /*
  171. * In RFC 2474, Section 4.2.2.1, the Class Selector Codepoints subsume
  172. * the old ToS Precedence values.
  173. */
  174. #define IPTOS_CLASS_MASK 0xe0
  175. #define IPTOS_CLASS(class) ((class) & IPTOS_CLASS_MASK)
  176. #define IPTOS_CLASS_CS0 0x00
  177. #define IPTOS_CLASS_CS1 0x20
  178. #define IPTOS_CLASS_CS2 0x40
  179. #define IPTOS_CLASS_CS3 0x60
  180. #define IPTOS_CLASS_CS4 0x80
  181. #define IPTOS_CLASS_CS5 0xa0
  182. #define IPTOS_CLASS_CS6 0xc0
  183. #define IPTOS_CLASS_CS7 0xe0
  184. #define IPTOS_CLASS_DEFAULT IPTOS_CLASS_CS0
  185. /*
  186. * Definitions for IP type of service (ip_tos) [deprecated; use DSCP
  187. * and CS definitions above instead.]
  188. */
  189. #define IPTOS_TOS_MASK 0x1E
  190. #define IPTOS_TOS(tos) ((tos) & IPTOS_TOS_MASK)
  191. #define IPTOS_LOWDELAY 0x10
  192. #define IPTOS_THROUGHPUT 0x08
  193. #define IPTOS_RELIABILITY 0x04
  194. #define IPTOS_LOWCOST 0x02
  195. #define IPTOS_MINCOST IPTOS_LOWCOST
  196. /*
  197. * Definitions for IP precedence (also in ip_tos) [also deprecated.]
  198. */
  199. #define IPTOS_PREC_MASK IPTOS_CLASS_MASK
  200. #define IPTOS_PREC(tos) IPTOS_CLASS(tos)
  201. #define IPTOS_PREC_NETCONTROL IPTOS_CLASS_CS7
  202. #define IPTOS_PREC_INTERNETCONTROL IPTOS_CLASS_CS6
  203. #define IPTOS_PREC_CRITIC_ECP IPTOS_CLASS_CS5
  204. #define IPTOS_PREC_FLASHOVERRIDE IPTOS_CLASS_CS4
  205. #define IPTOS_PREC_FLASH IPTOS_CLASS_CS3
  206. #define IPTOS_PREC_IMMEDIATE IPTOS_CLASS_CS2
  207. #define IPTOS_PREC_PRIORITY IPTOS_CLASS_CS1
  208. #define IPTOS_PREC_ROUTINE IPTOS_CLASS_CS0
  209. /*
  210. * Definitions for options.
  211. */
  212. #define IPOPT_COPY 0x80
  213. #define IPOPT_CLASS_MASK 0x60
  214. #define IPOPT_NUMBER_MASK 0x1f
  215. #define IPOPT_COPIED(o) ((o) & IPOPT_COPY)
  216. #define IPOPT_CLASS(o) ((o) & IPOPT_CLASS_MASK)
  217. #define IPOPT_NUMBER(o) ((o) & IPOPT_NUMBER_MASK)
  218. #define IPOPT_CONTROL 0x00
  219. #define IPOPT_RESERVED1 0x20
  220. #define IPOPT_DEBMEAS 0x40
  221. #define IPOPT_MEASUREMENT IPOPT_DEBMEAS
  222. #define IPOPT_RESERVED2 0x60
  223. #define IPOPT_EOL 0 /* end of option list */
  224. #define IPOPT_END IPOPT_EOL
  225. #define IPOPT_NOP 1 /* no operation */
  226. #define IPOPT_NOOP IPOPT_NOP
  227. #define IPOPT_RR 7 /* record packet route */
  228. #define IPOPT_TS 68 /* timestamp */
  229. #define IPOPT_TIMESTAMP IPOPT_TS
  230. #define IPOPT_SECURITY 130 /* provide s,c,h,tcc */
  231. #define IPOPT_SEC IPOPT_SECURITY
  232. #define IPOPT_LSRR 131 /* loose source route */
  233. #define IPOPT_SATID 136 /* satnet id */
  234. #define IPOPT_SID IPOPT_SATID
  235. #define IPOPT_SSRR 137 /* strict source route */
  236. #define IPOPT_RA 148 /* router alert */
  237. /*
  238. * Offsets to fields in options other than EOL and NOP.
  239. */
  240. #define IPOPT_OPTVAL 0 /* option ID */
  241. #define IPOPT_OLEN 1 /* option length */
  242. #define IPOPT_OFFSET 2 /* offset within option */
  243. #define IPOPT_MINOFF 4 /* min value of above */
  244. #define MAX_IPOPTLEN 40
  245. /* flag bits for ipt_flg */
  246. #define IPOPT_TS_TSONLY 0 /* timestamps only */
  247. #define IPOPT_TS_TSANDADDR 1 /* timestamps and addresses */
  248. #define IPOPT_TS_PRESPEC 3 /* specified modules only */
  249. /* bits for security (not byte swapped) */
  250. #define IPOPT_SECUR_UNCLASS 0x0000
  251. #define IPOPT_SECUR_CONFID 0xf135
  252. #define IPOPT_SECUR_EFTO 0x789a
  253. #define IPOPT_SECUR_MMMM 0xbc4d
  254. #define IPOPT_SECUR_RESTR 0xaf13
  255. #define IPOPT_SECUR_SECRET 0xd788
  256. #define IPOPT_SECUR_TOPSECRET 0x6bc5
  257. /*
  258. * Internet implementation parameters.
  259. */
  260. #define MAXTTL 255 /* maximum time to live (seconds) */
  261. #define IPDEFTTL 64 /* default ttl, from RFC 1340 */
  262. #define IPFRAGTTL 60 /* time to live for frags, slowhz */
  263. #define IPTTLDEC 1 /* subtracted when forwarding */
  264. #define IP_MSS 576 /* default maximum segment size */
  265. __END_DECLS
  266. #endif /* netinet/ip.h */