inet_sock.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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 inet_sock
  7. *
  8. * Authors: Many, reorganised here by
  9. * Arnaldo Carvalho de Melo <acme@mandriva.com>
  10. *
  11. * This program is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU General Public License
  13. * as published by the Free Software Foundation; either version
  14. * 2 of the License, or (at your option) any later version.
  15. */
  16. #ifndef _INET_SOCK_H
  17. #define _INET_SOCK_H
  18. #include <linux/string.h>
  19. #include <linux/types.h>
  20. #include <net/flow.h>
  21. #include <net/sock.h>
  22. #include <net/request_sock.h>
  23. /** struct ip_options - IP Options
  24. *
  25. * @faddr - Saved first hop address
  26. * @is_data - Options in __data, rather than skb
  27. * @is_strictroute - Strict source route
  28. * @srr_is_hit - Packet destination addr was our one
  29. * @is_changed - IP checksum more not valid
  30. * @rr_needaddr - Need to record addr of outgoing dev
  31. * @ts_needtime - Need to record timestamp
  32. * @ts_needaddr - Need to record addr of outgoing dev
  33. */
  34. struct ip_options {
  35. __be32 faddr;
  36. unsigned char optlen;
  37. unsigned char srr;
  38. unsigned char rr;
  39. unsigned char ts;
  40. unsigned char is_data:1,
  41. is_strictroute:1,
  42. srr_is_hit:1,
  43. is_changed:1,
  44. rr_needaddr:1,
  45. ts_needtime:1,
  46. ts_needaddr:1;
  47. unsigned char router_alert;
  48. unsigned char cipso;
  49. unsigned char __pad2;
  50. unsigned char __data[0];
  51. };
  52. #define optlength(opt) (sizeof(struct ip_options) + opt->optlen)
  53. struct inet_request_sock {
  54. struct request_sock req;
  55. #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
  56. u16 inet6_rsk_offset;
  57. /* 2 bytes hole, try to pack */
  58. #endif
  59. __be32 loc_addr;
  60. __be32 rmt_addr;
  61. __be16 rmt_port;
  62. u16 snd_wscale : 4,
  63. rcv_wscale : 4,
  64. tstamp_ok : 1,
  65. sack_ok : 1,
  66. wscale_ok : 1,
  67. ecn_ok : 1,
  68. acked : 1;
  69. struct ip_options *opt;
  70. };
  71. static inline struct inet_request_sock *inet_rsk(const struct request_sock *sk)
  72. {
  73. return (struct inet_request_sock *)sk;
  74. }
  75. struct ip_mc_socklist;
  76. struct ipv6_pinfo;
  77. struct rtable;
  78. /** struct inet_sock - representation of INET sockets
  79. *
  80. * @sk - ancestor class
  81. * @pinet6 - pointer to IPv6 control block
  82. * @daddr - Foreign IPv4 addr
  83. * @rcv_saddr - Bound local IPv4 addr
  84. * @dport - Destination port
  85. * @num - Local port
  86. * @saddr - Sending source
  87. * @uc_ttl - Unicast TTL
  88. * @sport - Source port
  89. * @id - ID counter for DF pkts
  90. * @tos - TOS
  91. * @mc_ttl - Multicasting TTL
  92. * @is_icsk - is this an inet_connection_sock?
  93. * @mc_index - Multicast device index
  94. * @mc_list - Group array
  95. * @cork - info to build ip hdr on each ip frag while socket is corked
  96. */
  97. struct inet_sock {
  98. /* sk and pinet6 has to be the first two members of inet_sock */
  99. struct sock sk;
  100. #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
  101. struct ipv6_pinfo *pinet6;
  102. #endif
  103. /* Socket demultiplex comparisons on incoming packets. */
  104. __be32 daddr;
  105. __be32 rcv_saddr;
  106. __be16 dport;
  107. __u16 num;
  108. __be32 saddr;
  109. __s16 uc_ttl;
  110. __u16 cmsg_flags;
  111. struct ip_options *opt;
  112. __be16 sport;
  113. __u16 id;
  114. __u8 tos;
  115. __u8 mc_ttl;
  116. __u8 pmtudisc;
  117. __u8 recverr:1,
  118. is_icsk:1,
  119. freebind:1,
  120. hdrincl:1,
  121. mc_loop:1;
  122. int mc_index;
  123. __be32 mc_addr;
  124. struct ip_mc_socklist *mc_list;
  125. struct {
  126. unsigned int flags;
  127. unsigned int fragsize;
  128. struct ip_options *opt;
  129. struct rtable *rt;
  130. int length; /* Total length of all frames */
  131. __be32 addr;
  132. struct flowi fl;
  133. } cork;
  134. };
  135. #define IPCORK_OPT 1 /* ip-options has been held in ipcork.opt */
  136. #define IPCORK_ALLFRAG 2 /* always fragment (for ipv6 for now) */
  137. static inline struct inet_sock *inet_sk(const struct sock *sk)
  138. {
  139. return (struct inet_sock *)sk;
  140. }
  141. static inline void __inet_sk_copy_descendant(struct sock *sk_to,
  142. const struct sock *sk_from,
  143. const int ancestor_size)
  144. {
  145. memcpy(inet_sk(sk_to) + 1, inet_sk(sk_from) + 1,
  146. sk_from->sk_prot->obj_size - ancestor_size);
  147. }
  148. #if !(defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE))
  149. static inline void inet_sk_copy_descendant(struct sock *sk_to,
  150. const struct sock *sk_from)
  151. {
  152. __inet_sk_copy_descendant(sk_to, sk_from, sizeof(struct inet_sock));
  153. }
  154. #endif
  155. extern int inet_sk_rebuild_header(struct sock *sk);
  156. static inline unsigned int inet_ehashfn(const __be32 laddr, const __u16 lport,
  157. const __be32 faddr, const __be16 fport)
  158. {
  159. unsigned int h = ((__force __u32)laddr ^ lport) ^ ((__force __u32)faddr ^ (__force __u32)fport);
  160. h ^= h >> 16;
  161. h ^= h >> 8;
  162. return h;
  163. }
  164. static inline int inet_sk_ehashfn(const struct sock *sk)
  165. {
  166. const struct inet_sock *inet = inet_sk(sk);
  167. const __be32 laddr = inet->rcv_saddr;
  168. const __u16 lport = inet->num;
  169. const __be32 faddr = inet->daddr;
  170. const __be16 fport = inet->dport;
  171. return inet_ehashfn(laddr, lport, faddr, fport);
  172. }
  173. #endif /* _INET_SOCK_H */