inet_connection_sock.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  1. /*
  2. * NET Generic infrastructure for INET connection oriented protocols.
  3. *
  4. * Definitions for inet_connection_sock
  5. *
  6. * Authors: Many people, see the TCP sources
  7. *
  8. * From code originally in TCP
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License
  12. * as published by the Free Software Foundation; either version
  13. * 2 of the License, or (at your option) any later version.
  14. */
  15. #ifndef _INET_CONNECTION_SOCK_H
  16. #define _INET_CONNECTION_SOCK_H
  17. #include <linux/compiler.h>
  18. #include <linux/string.h>
  19. #include <linux/timer.h>
  20. #include <linux/poll.h>
  21. #include <net/inet_sock.h>
  22. #include <net/request_sock.h>
  23. #define INET_CSK_DEBUG 1
  24. /* Cancel timers, when they are not required. */
  25. #undef INET_CSK_CLEAR_TIMERS
  26. struct inet_bind_bucket;
  27. struct inet_hashinfo;
  28. struct tcp_congestion_ops;
  29. /*
  30. * Pointers to address related TCP functions
  31. * (i.e. things that depend on the address family)
  32. */
  33. struct inet_connection_sock_af_ops {
  34. int (*queue_xmit)(struct sk_buff *skb, int ipfragok);
  35. void (*send_check)(struct sock *sk, int len,
  36. struct sk_buff *skb);
  37. int (*rebuild_header)(struct sock *sk);
  38. int (*conn_request)(struct sock *sk, struct sk_buff *skb);
  39. struct sock *(*syn_recv_sock)(struct sock *sk, struct sk_buff *skb,
  40. struct request_sock *req,
  41. struct dst_entry *dst);
  42. int (*remember_stamp)(struct sock *sk);
  43. u16 net_header_len;
  44. u16 sockaddr_len;
  45. int (*setsockopt)(struct sock *sk, int level, int optname,
  46. char __user *optval, int optlen);
  47. int (*getsockopt)(struct sock *sk, int level, int optname,
  48. char __user *optval, int __user *optlen);
  49. int (*compat_setsockopt)(struct sock *sk,
  50. int level, int optname,
  51. char __user *optval, int optlen);
  52. int (*compat_getsockopt)(struct sock *sk,
  53. int level, int optname,
  54. char __user *optval, int __user *optlen);
  55. void (*addr2sockaddr)(struct sock *sk, struct sockaddr *);
  56. };
  57. /** inet_connection_sock - INET connection oriented sock
  58. *
  59. * @icsk_accept_queue: FIFO of established children
  60. * @icsk_bind_hash: Bind node
  61. * @icsk_timeout: Timeout
  62. * @icsk_retransmit_timer: Resend (no ack)
  63. * @icsk_rto: Retransmit timeout
  64. * @icsk_pmtu_cookie Last pmtu seen by socket
  65. * @icsk_ca_ops Pluggable congestion control hook
  66. * @icsk_af_ops Operations which are AF_INET{4,6} specific
  67. * @icsk_ca_state: Congestion control state
  68. * @icsk_retransmits: Number of unrecovered [RTO] timeouts
  69. * @icsk_pending: Scheduled timer event
  70. * @icsk_backoff: Backoff
  71. * @icsk_syn_retries: Number of allowed SYN (or equivalent) retries
  72. * @icsk_probes_out: unanswered 0 window probes
  73. * @icsk_ext_hdr_len: Network protocol overhead (IP/IPv6 options)
  74. * @icsk_ack: Delayed ACK control data
  75. * @icsk_mtup; MTU probing control data
  76. */
  77. struct inet_connection_sock {
  78. /* inet_sock has to be the first member! */
  79. struct inet_sock icsk_inet;
  80. struct request_sock_queue icsk_accept_queue;
  81. struct inet_bind_bucket *icsk_bind_hash;
  82. unsigned long icsk_timeout;
  83. struct timer_list icsk_retransmit_timer;
  84. struct timer_list icsk_delack_timer;
  85. __u32 icsk_rto;
  86. __u32 icsk_pmtu_cookie;
  87. const struct tcp_congestion_ops *icsk_ca_ops;
  88. const struct inet_connection_sock_af_ops *icsk_af_ops;
  89. unsigned int (*icsk_sync_mss)(struct sock *sk, u32 pmtu);
  90. __u8 icsk_ca_state;
  91. __u8 icsk_retransmits;
  92. __u8 icsk_pending;
  93. __u8 icsk_backoff;
  94. __u8 icsk_syn_retries;
  95. __u8 icsk_probes_out;
  96. __u16 icsk_ext_hdr_len;
  97. struct {
  98. __u8 pending; /* ACK is pending */
  99. __u8 quick; /* Scheduled number of quick acks */
  100. __u8 pingpong; /* The session is interactive */
  101. __u8 blocked; /* Delayed ACK was blocked by socket lock */
  102. __u32 ato; /* Predicted tick of soft clock */
  103. unsigned long timeout; /* Currently scheduled timeout */
  104. __u32 lrcvtime; /* timestamp of last received data packet */
  105. __u16 last_seg_size; /* Size of last incoming segment */
  106. __u16 rcv_mss; /* MSS used for delayed ACK decisions */
  107. } icsk_ack;
  108. struct {
  109. int enabled;
  110. /* Range of MTUs to search */
  111. int search_high;
  112. int search_low;
  113. /* Information on the current probe. */
  114. int probe_size;
  115. } icsk_mtup;
  116. u32 icsk_ca_priv[16];
  117. #define ICSK_CA_PRIV_SIZE (16 * sizeof(u32))
  118. };
  119. #define ICSK_TIME_RETRANS 1 /* Retransmit timer */
  120. #define ICSK_TIME_DACK 2 /* Delayed ack timer */
  121. #define ICSK_TIME_PROBE0 3 /* Zero window probe timer */
  122. #define ICSK_TIME_KEEPOPEN 4 /* Keepalive timer */
  123. static inline struct inet_connection_sock *inet_csk(const struct sock *sk)
  124. {
  125. return (struct inet_connection_sock *)sk;
  126. }
  127. static inline void *inet_csk_ca(const struct sock *sk)
  128. {
  129. return (void *)inet_csk(sk)->icsk_ca_priv;
  130. }
  131. extern struct sock *inet_csk_clone(struct sock *sk,
  132. const struct request_sock *req,
  133. const gfp_t priority);
  134. enum inet_csk_ack_state_t {
  135. ICSK_ACK_SCHED = 1,
  136. ICSK_ACK_TIMER = 2,
  137. ICSK_ACK_PUSHED = 4,
  138. ICSK_ACK_PUSHED2 = 8
  139. };
  140. extern void inet_csk_init_xmit_timers(struct sock *sk,
  141. void (*retransmit_handler)(unsigned long),
  142. void (*delack_handler)(unsigned long),
  143. void (*keepalive_handler)(unsigned long));
  144. extern void inet_csk_clear_xmit_timers(struct sock *sk);
  145. static inline void inet_csk_schedule_ack(struct sock *sk)
  146. {
  147. inet_csk(sk)->icsk_ack.pending |= ICSK_ACK_SCHED;
  148. }
  149. static inline int inet_csk_ack_scheduled(const struct sock *sk)
  150. {
  151. return inet_csk(sk)->icsk_ack.pending & ICSK_ACK_SCHED;
  152. }
  153. static inline void inet_csk_delack_init(struct sock *sk)
  154. {
  155. memset(&inet_csk(sk)->icsk_ack, 0, sizeof(inet_csk(sk)->icsk_ack));
  156. }
  157. extern void inet_csk_delete_keepalive_timer(struct sock *sk);
  158. extern void inet_csk_reset_keepalive_timer(struct sock *sk, unsigned long timeout);
  159. #ifdef INET_CSK_DEBUG
  160. extern const char inet_csk_timer_bug_msg[];
  161. #endif
  162. static inline void inet_csk_clear_xmit_timer(struct sock *sk, const int what)
  163. {
  164. struct inet_connection_sock *icsk = inet_csk(sk);
  165. if (what == ICSK_TIME_RETRANS || what == ICSK_TIME_PROBE0) {
  166. icsk->icsk_pending = 0;
  167. #ifdef INET_CSK_CLEAR_TIMERS
  168. sk_stop_timer(sk, &icsk->icsk_retransmit_timer);
  169. #endif
  170. } else if (what == ICSK_TIME_DACK) {
  171. icsk->icsk_ack.blocked = icsk->icsk_ack.pending = 0;
  172. #ifdef INET_CSK_CLEAR_TIMERS
  173. sk_stop_timer(sk, &icsk->icsk_delack_timer);
  174. #endif
  175. }
  176. #ifdef INET_CSK_DEBUG
  177. else {
  178. pr_debug("%s", inet_csk_timer_bug_msg);
  179. }
  180. #endif
  181. }
  182. /*
  183. * Reset the retransmission timer
  184. */
  185. static inline void inet_csk_reset_xmit_timer(struct sock *sk, const int what,
  186. unsigned long when,
  187. const unsigned long max_when)
  188. {
  189. struct inet_connection_sock *icsk = inet_csk(sk);
  190. if (when > max_when) {
  191. #ifdef INET_CSK_DEBUG
  192. pr_debug("reset_xmit_timer: sk=%p %d when=0x%lx, caller=%p\n",
  193. sk, what, when, current_text_addr());
  194. #endif
  195. when = max_when;
  196. }
  197. if (what == ICSK_TIME_RETRANS || what == ICSK_TIME_PROBE0) {
  198. icsk->icsk_pending = what;
  199. icsk->icsk_timeout = jiffies + when;
  200. sk_reset_timer(sk, &icsk->icsk_retransmit_timer, icsk->icsk_timeout);
  201. } else if (what == ICSK_TIME_DACK) {
  202. icsk->icsk_ack.pending |= ICSK_ACK_TIMER;
  203. icsk->icsk_ack.timeout = jiffies + when;
  204. sk_reset_timer(sk, &icsk->icsk_delack_timer, icsk->icsk_ack.timeout);
  205. }
  206. #ifdef INET_CSK_DEBUG
  207. else {
  208. pr_debug("%s", inet_csk_timer_bug_msg);
  209. }
  210. #endif
  211. }
  212. extern struct sock *inet_csk_accept(struct sock *sk, int flags, int *err);
  213. extern struct request_sock *inet_csk_search_req(const struct sock *sk,
  214. struct request_sock ***prevp,
  215. const __be16 rport,
  216. const __be32 raddr,
  217. const __be32 laddr);
  218. extern int inet_csk_bind_conflict(const struct sock *sk,
  219. const struct inet_bind_bucket *tb);
  220. extern int inet_csk_get_port(struct inet_hashinfo *hashinfo,
  221. struct sock *sk, unsigned short snum,
  222. int (*bind_conflict)(const struct sock *sk,
  223. const struct inet_bind_bucket *tb));
  224. extern struct dst_entry* inet_csk_route_req(struct sock *sk,
  225. const struct request_sock *req);
  226. static inline void inet_csk_reqsk_queue_add(struct sock *sk,
  227. struct request_sock *req,
  228. struct sock *child)
  229. {
  230. reqsk_queue_add(&inet_csk(sk)->icsk_accept_queue, req, sk, child);
  231. }
  232. extern void inet_csk_reqsk_queue_hash_add(struct sock *sk,
  233. struct request_sock *req,
  234. unsigned long timeout);
  235. static inline void inet_csk_reqsk_queue_removed(struct sock *sk,
  236. struct request_sock *req)
  237. {
  238. if (reqsk_queue_removed(&inet_csk(sk)->icsk_accept_queue, req) == 0)
  239. inet_csk_delete_keepalive_timer(sk);
  240. }
  241. static inline void inet_csk_reqsk_queue_added(struct sock *sk,
  242. const unsigned long timeout)
  243. {
  244. if (reqsk_queue_added(&inet_csk(sk)->icsk_accept_queue) == 0)
  245. inet_csk_reset_keepalive_timer(sk, timeout);
  246. }
  247. static inline int inet_csk_reqsk_queue_len(const struct sock *sk)
  248. {
  249. return reqsk_queue_len(&inet_csk(sk)->icsk_accept_queue);
  250. }
  251. static inline int inet_csk_reqsk_queue_young(const struct sock *sk)
  252. {
  253. return reqsk_queue_len_young(&inet_csk(sk)->icsk_accept_queue);
  254. }
  255. static inline int inet_csk_reqsk_queue_is_full(const struct sock *sk)
  256. {
  257. return reqsk_queue_is_full(&inet_csk(sk)->icsk_accept_queue);
  258. }
  259. static inline void inet_csk_reqsk_queue_unlink(struct sock *sk,
  260. struct request_sock *req,
  261. struct request_sock **prev)
  262. {
  263. reqsk_queue_unlink(&inet_csk(sk)->icsk_accept_queue, req, prev);
  264. }
  265. static inline void inet_csk_reqsk_queue_drop(struct sock *sk,
  266. struct request_sock *req,
  267. struct request_sock **prev)
  268. {
  269. inet_csk_reqsk_queue_unlink(sk, req, prev);
  270. inet_csk_reqsk_queue_removed(sk, req);
  271. reqsk_free(req);
  272. }
  273. extern void inet_csk_reqsk_queue_prune(struct sock *parent,
  274. const unsigned long interval,
  275. const unsigned long timeout,
  276. const unsigned long max_rto);
  277. extern void inet_csk_destroy_sock(struct sock *sk);
  278. /*
  279. * LISTEN is a special case for poll..
  280. */
  281. static inline unsigned int inet_csk_listen_poll(const struct sock *sk)
  282. {
  283. return !reqsk_queue_empty(&inet_csk(sk)->icsk_accept_queue) ?
  284. (POLLIN | POLLRDNORM) : 0;
  285. }
  286. extern int inet_csk_listen_start(struct sock *sk, const int nr_table_entries);
  287. extern void inet_csk_listen_stop(struct sock *sk);
  288. extern void inet_csk_addr2sockaddr(struct sock *sk, struct sockaddr *uaddr);
  289. extern int inet_csk_ctl_sock_create(struct socket **sock,
  290. unsigned short family,
  291. unsigned short type,
  292. unsigned char protocol);
  293. extern int inet_csk_compat_getsockopt(struct sock *sk, int level, int optname,
  294. char __user *optval, int __user *optlen);
  295. extern int inet_csk_compat_setsockopt(struct sock *sk, int level, int optname,
  296. char __user *optval, int optlen);
  297. #endif /* _INET_CONNECTION_SOCK_H */