ip.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. /*
  2. * INET An implementation of the TCP/IP protocol suite for the LINUX
  3. * operating system. INET is implemented using the BSD Socket
  4. * interface as the means of communication with the user level.
  5. *
  6. * Definitions for the IP protocol.
  7. *
  8. * Version: @(#)ip.h 1.0.2 04/28/93
  9. *
  10. * Authors: Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
  11. *
  12. * This program is free software; you can redistribute it and/or
  13. * modify it under the terms of the GNU General Public License
  14. * as published by the Free Software Foundation; either version
  15. * 2 of the License, or (at your option) any later version.
  16. */
  17. #ifndef _LINUX_IP_H
  18. #define _LINUX_IP_H
  19. #include <asm/byteorder.h>
  20. #define IPTOS_TOS_MASK 0x1E
  21. #define IPTOS_TOS(tos) ((tos)&IPTOS_TOS_MASK)
  22. #define IPTOS_LOWDELAY 0x10
  23. #define IPTOS_THROUGHPUT 0x08
  24. #define IPTOS_RELIABILITY 0x04
  25. #define IPTOS_MINCOST 0x02
  26. #define IPTOS_PREC_MASK 0xE0
  27. #define IPTOS_PREC(tos) ((tos)&IPTOS_PREC_MASK)
  28. #define IPTOS_PREC_NETCONTROL 0xe0
  29. #define IPTOS_PREC_INTERNETCONTROL 0xc0
  30. #define IPTOS_PREC_CRITIC_ECP 0xa0
  31. #define IPTOS_PREC_FLASHOVERRIDE 0x80
  32. #define IPTOS_PREC_FLASH 0x60
  33. #define IPTOS_PREC_IMMEDIATE 0x40
  34. #define IPTOS_PREC_PRIORITY 0x20
  35. #define IPTOS_PREC_ROUTINE 0x00
  36. /* IP options */
  37. #define IPOPT_COPY 0x80
  38. #define IPOPT_CLASS_MASK 0x60
  39. #define IPOPT_NUMBER_MASK 0x1f
  40. #define IPOPT_COPIED(o) ((o)&IPOPT_COPY)
  41. #define IPOPT_CLASS(o) ((o)&IPOPT_CLASS_MASK)
  42. #define IPOPT_NUMBER(o) ((o)&IPOPT_NUMBER_MASK)
  43. #define IPOPT_CONTROL 0x00
  44. #define IPOPT_RESERVED1 0x20
  45. #define IPOPT_MEASUREMENT 0x40
  46. #define IPOPT_RESERVED2 0x60
  47. #define IPOPT_END (0 |IPOPT_CONTROL)
  48. #define IPOPT_NOOP (1 |IPOPT_CONTROL)
  49. #define IPOPT_SEC (2 |IPOPT_CONTROL|IPOPT_COPY)
  50. #define IPOPT_LSRR (3 |IPOPT_CONTROL|IPOPT_COPY)
  51. #define IPOPT_TIMESTAMP (4 |IPOPT_MEASUREMENT)
  52. #define IPOPT_RR (7 |IPOPT_CONTROL)
  53. #define IPOPT_SID (8 |IPOPT_CONTROL|IPOPT_COPY)
  54. #define IPOPT_SSRR (9 |IPOPT_CONTROL|IPOPT_COPY)
  55. #define IPOPT_RA (20|IPOPT_CONTROL|IPOPT_COPY)
  56. #define IPVERSION 4
  57. #define MAXTTL 255
  58. #define IPDEFTTL 64
  59. #define IPOPT_OPTVAL 0
  60. #define IPOPT_OLEN 1
  61. #define IPOPT_OFFSET 2
  62. #define IPOPT_MINOFF 4
  63. #define MAX_IPOPTLEN 40
  64. #define IPOPT_NOP IPOPT_NOOP
  65. #define IPOPT_EOL IPOPT_END
  66. #define IPOPT_TS IPOPT_TIMESTAMP
  67. #define IPOPT_TS_TSONLY 0 /* timestamps only */
  68. #define IPOPT_TS_TSANDADDR 1 /* timestamps and addresses */
  69. #define IPOPT_TS_PRESPEC 3 /* specified modules only */
  70. #ifdef __KERNEL__
  71. #include <linux/config.h>
  72. #include <linux/types.h>
  73. #include <net/request_sock.h>
  74. #include <net/sock.h>
  75. #include <linux/igmp.h>
  76. #include <net/flow.h>
  77. struct ip_options {
  78. __u32 faddr; /* Saved first hop address */
  79. unsigned char optlen;
  80. unsigned char srr;
  81. unsigned char rr;
  82. unsigned char ts;
  83. unsigned char is_setbyuser:1, /* Set by setsockopt? */
  84. is_data:1, /* Options in __data, rather than skb */
  85. is_strictroute:1, /* Strict source route */
  86. srr_is_hit:1, /* Packet destination addr was our one */
  87. is_changed:1, /* IP checksum more not valid */
  88. rr_needaddr:1, /* Need to record addr of outgoing dev */
  89. ts_needtime:1, /* Need to record timestamp */
  90. ts_needaddr:1; /* Need to record addr of outgoing dev */
  91. unsigned char router_alert;
  92. unsigned char __pad1;
  93. unsigned char __pad2;
  94. unsigned char __data[0];
  95. };
  96. #define optlength(opt) (sizeof(struct ip_options) + opt->optlen)
  97. struct inet_request_sock {
  98. struct request_sock req;
  99. u32 loc_addr;
  100. u32 rmt_addr;
  101. u16 rmt_port;
  102. u16 snd_wscale : 4,
  103. rcv_wscale : 4,
  104. tstamp_ok : 1,
  105. sack_ok : 1,
  106. wscale_ok : 1,
  107. ecn_ok : 1,
  108. acked : 1;
  109. struct ip_options *opt;
  110. };
  111. static inline struct inet_request_sock *inet_rsk(const struct request_sock *sk)
  112. {
  113. return (struct inet_request_sock *)sk;
  114. }
  115. struct ipv6_pinfo;
  116. struct inet_sock {
  117. /* sk and pinet6 has to be the first two members of inet_sock */
  118. struct sock sk;
  119. #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
  120. struct ipv6_pinfo *pinet6;
  121. #endif
  122. /* Socket demultiplex comparisons on incoming packets. */
  123. __u32 daddr; /* Foreign IPv4 addr */
  124. __u32 rcv_saddr; /* Bound local IPv4 addr */
  125. __u16 dport; /* Destination port */
  126. __u16 num; /* Local port */
  127. __u32 saddr; /* Sending source */
  128. __s16 uc_ttl; /* Unicast TTL */
  129. __u16 cmsg_flags;
  130. struct ip_options *opt;
  131. __u16 sport; /* Source port */
  132. __u16 id; /* ID counter for DF pkts */
  133. __u8 tos; /* TOS */
  134. __u8 mc_ttl; /* Multicasting TTL */
  135. __u8 pmtudisc;
  136. unsigned recverr : 1,
  137. freebind : 1,
  138. hdrincl : 1,
  139. mc_loop : 1;
  140. int mc_index; /* Multicast device index */
  141. __u32 mc_addr;
  142. struct ip_mc_socklist *mc_list; /* Group array */
  143. /*
  144. * Following members are used to retain the infomation to build
  145. * an ip header on each ip fragmentation while the socket is corked.
  146. */
  147. struct {
  148. unsigned int flags;
  149. unsigned int fragsize;
  150. struct ip_options *opt;
  151. struct rtable *rt;
  152. int length; /* Total length of all frames */
  153. u32 addr;
  154. struct flowi fl;
  155. } cork;
  156. };
  157. #define IPCORK_OPT 1 /* ip-options has been held in ipcork.opt */
  158. #define IPCORK_ALLFRAG 2 /* always fragment (for ipv6 for now) */
  159. static inline struct inet_sock *inet_sk(const struct sock *sk)
  160. {
  161. return (struct inet_sock *)sk;
  162. }
  163. static inline void __inet_sk_copy_descendant(struct sock *sk_to,
  164. const struct sock *sk_from,
  165. const int ancestor_size)
  166. {
  167. memcpy(inet_sk(sk_to) + 1, inet_sk(sk_from) + 1,
  168. sk_from->sk_prot->obj_size - ancestor_size);
  169. }
  170. #if !(defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE))
  171. static inline void inet_sk_copy_descendant(struct sock *sk_to,
  172. const struct sock *sk_from)
  173. {
  174. __inet_sk_copy_descendant(sk_to, sk_from, sizeof(struct inet_sock));
  175. }
  176. #endif
  177. #endif
  178. struct iphdr {
  179. #if defined(__LITTLE_ENDIAN_BITFIELD)
  180. __u8 ihl:4,
  181. version:4;
  182. #elif defined (__BIG_ENDIAN_BITFIELD)
  183. __u8 version:4,
  184. ihl:4;
  185. #else
  186. #error "Please fix <asm/byteorder.h>"
  187. #endif
  188. __u8 tos;
  189. __u16 tot_len;
  190. __u16 id;
  191. __u16 frag_off;
  192. __u8 ttl;
  193. __u8 protocol;
  194. __u16 check;
  195. __u32 saddr;
  196. __u32 daddr;
  197. /*The options start here. */
  198. };
  199. struct ip_auth_hdr {
  200. __u8 nexthdr;
  201. __u8 hdrlen; /* This one is measured in 32 bit units! */
  202. __u16 reserved;
  203. __u32 spi;
  204. __u32 seq_no; /* Sequence number */
  205. __u8 auth_data[0]; /* Variable len but >=4. Mind the 64 bit alignment! */
  206. };
  207. struct ip_esp_hdr {
  208. __u32 spi;
  209. __u32 seq_no; /* Sequence number */
  210. __u8 enc_data[0]; /* Variable len but >=8. Mind the 64 bit alignment! */
  211. };
  212. struct ip_comp_hdr {
  213. __u8 nexthdr;
  214. __u8 flags;
  215. __u16 cpi;
  216. };
  217. #endif /* _LINUX_IP_H */