ip.h 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. /* Copyright (C) 1991, 92, 93, 95, 96, 97, 98 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 Library General Public License as
  5. published by the Free Software Foundation; either version 2 of the
  6. 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. Library General Public License for more details.
  11. You should have received a copy of the GNU Library General Public
  12. License along with the GNU C Library; see the file COPYING.LIB. If not,
  13. write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  14. Boston, MA 02111-1307, USA. */
  15. #ifndef __NETINET_IP_H
  16. #define __NETINET_IP_H 1
  17. #include <features.h>
  18. #include <sys/types.h>
  19. #include <netinet/in.h>
  20. __BEGIN_DECLS
  21. struct timestamp
  22. {
  23. u_int8_t len;
  24. u_int8_t ptr;
  25. #if __BYTE_ORDER == __LITTLE_ENDIAN
  26. unsigned int flags:4;
  27. unsigned int overflow:4;
  28. #elif __BYTE_ORDER == __BIG_ENDIAN
  29. unsigned int overflow:4;
  30. unsigned int flags:4;
  31. #else
  32. # error "Please fix <bits/endian.h>"
  33. #endif
  34. u_int32_t data[9];
  35. };
  36. struct ip_options
  37. {
  38. u_int32_t faddr; /* Saved first hop address */
  39. u_int8_t optlen;
  40. u_int8_t srr;
  41. u_int8_t rr;
  42. u_int8_t ts;
  43. unsigned int is_setbyuser:1; /* Set by setsockopt? */
  44. unsigned int is_data:1; /* Options in __data, rather than skb */
  45. unsigned int is_strictroute:1; /* Strict source route */
  46. unsigned int srr_is_hit:1; /* Packet destination addr was our one */
  47. unsigned int is_changed:1; /* IP checksum more not valid */
  48. unsigned int rr_needaddr:1; /* Need to record addr of outgoing dev */
  49. unsigned int ts_needtime:1; /* Need to record timestamp */
  50. unsigned int ts_needaddr:1; /* Need to record addr of outgoing dev */
  51. u_int8_t router_alert;
  52. u_int8_t __pad1;
  53. u_int8_t __pad2;
  54. #ifdef __GNUC__
  55. u_int8_t __data[0];
  56. #endif
  57. };
  58. struct iphdr
  59. {
  60. #if __BYTE_ORDER == __LITTLE_ENDIAN
  61. unsigned int ihl:4;
  62. unsigned int version:4;
  63. #elif __BYTE_ORDER == __BIG_ENDIAN
  64. unsigned int version:4;
  65. unsigned int ihl:4;
  66. #else
  67. # error "Please fix <bits/endian.h>"
  68. #endif
  69. u_int8_t tos;
  70. u_int16_t tot_len;
  71. u_int16_t id;
  72. u_int16_t frag_off;
  73. u_int8_t ttl;
  74. u_int8_t protocol;
  75. u_int16_t check;
  76. u_int32_t saddr;
  77. u_int32_t daddr;
  78. /*The options start here. */
  79. };
  80. #ifdef __USE_BSD
  81. /*
  82. * Copyright (c) 1982, 1986, 1993
  83. * The Regents of the University of California. All rights reserved.
  84. *
  85. * Redistribution and use in source and binary forms, with or without
  86. * modification, are permitted provided that the following conditions
  87. * are met:
  88. * 1. Redistributions of source code must retain the above copyright
  89. * notice, this list of conditions and the following disclaimer.
  90. * 2. Redistributions in binary form must reproduce the above copyright
  91. * notice, this list of conditions and the following disclaimer in the
  92. * documentation and/or other materials provided with the distribution.
  93. * 3. All advertising materials mentioning features or use of this software
  94. * must display the following acknowledgement:
  95. * This product includes software developed by the University of
  96. * California, Berkeley and its contributors.
  97. * 4. Neither the name of the University nor the names of its contributors
  98. * may be used to endorse or promote products derived from this software
  99. * without specific prior written permission.
  100. *
  101. * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  102. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  103. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  104. * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  105. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  106. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  107. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  108. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  109. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  110. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  111. * SUCH DAMAGE.
  112. *
  113. * @(#)ip.h 8.1 (Berkeley) 6/10/93
  114. */
  115. /*
  116. * Definitions for internet protocol version 4.
  117. * Per RFC 791, September 1981.
  118. */
  119. /*
  120. * Structure of an internet header, naked of options.
  121. */
  122. struct ip
  123. {
  124. #if __BYTE_ORDER == __LITTLE_ENDIAN
  125. unsigned int ip_hl:4; /* header length */
  126. unsigned int ip_v:4; /* version */
  127. #endif
  128. #if __BYTE_ORDER == __BIG_ENDIAN
  129. unsigned int ip_v:4; /* version */
  130. unsigned int ip_hl:4; /* header length */
  131. #endif
  132. u_int8_t ip_tos; /* type of service */
  133. u_short ip_len; /* total length */
  134. u_short ip_id; /* identification */
  135. u_short ip_off; /* fragment offset field */
  136. #define IP_RF 0x8000 /* reserved fragment flag */
  137. #define IP_DF 0x4000 /* dont fragment flag */
  138. #define IP_MF 0x2000 /* more fragments flag */
  139. #define IP_OFFMASK 0x1fff /* mask for fragmenting bits */
  140. u_int8_t ip_ttl; /* time to live */
  141. u_int8_t ip_p; /* protocol */
  142. u_short ip_sum; /* checksum */
  143. struct in_addr ip_src, ip_dst; /* source and dest address */
  144. };
  145. /*
  146. * Time stamp option structure.
  147. */
  148. struct ip_timestamp
  149. {
  150. u_int8_t ipt_code; /* IPOPT_TS */
  151. u_int8_t ipt_len; /* size of structure (variable) */
  152. u_int8_t ipt_ptr; /* index of current entry */
  153. #if __BYTE_ORDER == __LITTLE_ENDIAN
  154. unsigned int ipt_flg:4; /* flags, see below */
  155. unsigned int ipt_oflw:4; /* overflow counter */
  156. #endif
  157. #if __BYTE_ORDER == __BIG_ENDIAN
  158. unsigned int ipt_oflw:4; /* overflow counter */
  159. unsigned int ipt_flg:4; /* flags, see below */
  160. #endif
  161. u_int32_t data[9];
  162. };
  163. #endif /* __USE_BSD */
  164. #define IPVERSION 4 /* IP version number */
  165. #define IP_MAXPACKET 65535 /* maximum packet size */
  166. /*
  167. * Definitions for IP type of service (ip_tos)
  168. */
  169. #define IPTOS_TOS_MASK 0x1E
  170. #define IPTOS_TOS(tos) ((tos) & IPTOS_TOS_MASK)
  171. #define IPTOS_LOWDELAY 0x10
  172. #define IPTOS_THROUGHPUT 0x08
  173. #define IPTOS_RELIABILITY 0x04
  174. #define IPTOS_LOWCOST 0x02
  175. #define IPTOS_MINCOST IPTOS_LOWCOST
  176. /*
  177. * Definitions for IP precedence (also in ip_tos) (hopefully unused)
  178. */
  179. #define IPTOS_PREC_MASK 0xe0
  180. #define IPTOS_PREC(tos) ((tos) & IPTOS_PREC_MASK)
  181. #define IPTOS_PREC_NETCONTROL 0xe0
  182. #define IPTOS_PREC_INTERNETCONTROL 0xc0
  183. #define IPTOS_PREC_CRITIC_ECP 0xa0
  184. #define IPTOS_PREC_FLASHOVERRIDE 0x80
  185. #define IPTOS_PREC_FLASH 0x60
  186. #define IPTOS_PREC_IMMEDIATE 0x40
  187. #define IPTOS_PREC_PRIORITY 0x20
  188. #define IPTOS_PREC_ROUTINE 0x00
  189. /*
  190. * Definitions for options.
  191. */
  192. #define IPOPT_COPY 0x80
  193. #define IPOPT_CLASS_MASK 0x60
  194. #define IPOPT_NUMBER_MASK 0x1f
  195. #define IPOPT_COPIED(o) ((o) & IPOPT_COPY)
  196. #define IPOPT_CLASS(o) ((o) & IPOPT_CLASS_MASK)
  197. #define IPOPT_NUMBER(o) ((o) & IPOPT_NUMBER_MASK)
  198. #define IPOPT_CONTROL 0x00
  199. #define IPOPT_RESERVED1 0x20
  200. #define IPOPT_DEBMEAS 0x40
  201. #define IPOPT_MEASUREMENT IPOPT_DEBMEAS
  202. #define IPOPT_RESERVED2 0x60
  203. #define IPOPT_EOL 0 /* end of option list */
  204. #define IPOPT_END IPOPT_EOL
  205. #define IPOPT_NOP 1 /* no operation */
  206. #define IPOPT_NOOP IPOPT_NOP
  207. #define IPOPT_RR 7 /* record packet route */
  208. #define IPOPT_TS 68 /* timestamp */
  209. #define IPOPT_TIMESTAMP IPOPT_TS
  210. #define IPOPT_SECURITY 130 /* provide s,c,h,tcc */
  211. #define IPOPT_SEC IPOPT_SECURITY
  212. #define IPOPT_LSRR 131 /* loose source route */
  213. #define IPOPT_SATID 136 /* satnet id */
  214. #define IPOPT_SID IPOPT_SATID
  215. #define IPOPT_SSRR 137 /* strict source route */
  216. #define IPOPT_RA 148 /* router alert */
  217. /*
  218. * Offsets to fields in options other than EOL and NOP.
  219. */
  220. #define IPOPT_OPTVAL 0 /* option ID */
  221. #define IPOPT_OLEN 1 /* option length */
  222. #define IPOPT_OFFSET 2 /* offset within option */
  223. #define IPOPT_MINOFF 4 /* min value of above */
  224. #define MAX_IPOPTLEN 40
  225. /* flag bits for ipt_flg */
  226. #define IPOPT_TS_TSONLY 0 /* timestamps only */
  227. #define IPOPT_TS_TSANDADDR 1 /* timestamps and addresses */
  228. #define IPOPT_TS_PRESPEC 3 /* specified modules only */
  229. /* bits for security (not byte swapped) */
  230. #define IPOPT_SECUR_UNCLASS 0x0000
  231. #define IPOPT_SECUR_CONFID 0xf135
  232. #define IPOPT_SECUR_EFTO 0x789a
  233. #define IPOPT_SECUR_MMMM 0xbc4d
  234. #define IPOPT_SECUR_RESTR 0xaf13
  235. #define IPOPT_SECUR_SECRET 0xd788
  236. #define IPOPT_SECUR_TOPSECRET 0x6bc5
  237. /*
  238. * Internet implementation parameters.
  239. */
  240. #define MAXTTL 255 /* maximum time to live (seconds) */
  241. #define IPDEFTTL 64 /* default ttl, from RFC 1340 */
  242. #define IPFRAGTTL 60 /* time to live for frags, slowhz */
  243. #define IPTTLDEC 1 /* subtracted when forwarding */
  244. #define IP_MSS 576 /* default maximum segment size */
  245. __END_DECLS
  246. #endif /* netinet/ip.h */