inet_connection_sock.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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/ip.h>
  18. #include <linux/string.h>
  19. #include <linux/timer.h>
  20. #include <net/request_sock.h>
  21. #define INET_CSK_DEBUG 1
  22. /* Cancel timers, when they are not required. */
  23. #undef INET_CSK_CLEAR_TIMERS
  24. struct inet_bind_bucket;
  25. struct inet_hashinfo;
  26. /** inet_connection_sock - INET connection oriented sock
  27. *
  28. * @icsk_accept_queue: FIFO of established children
  29. * @icsk_bind_hash: Bind node
  30. * @icsk_timeout: Timeout
  31. * @icsk_retransmit_timer: Resend (no ack)
  32. * @icsk_rto: Retransmit timeout
  33. * @icsk_retransmits: Number of unrecovered [RTO] timeouts
  34. * @icsk_pending: Scheduled timer event
  35. * @icsk_backoff: Backoff
  36. * @icsk_syn_retries: Number of allowed SYN (or equivalent) retries
  37. * @icsk_ack: Delayed ACK control data
  38. */
  39. struct inet_connection_sock {
  40. /* inet_sock has to be the first member! */
  41. struct inet_sock icsk_inet;
  42. struct request_sock_queue icsk_accept_queue;
  43. struct inet_bind_bucket *icsk_bind_hash;
  44. unsigned long icsk_timeout;
  45. struct timer_list icsk_retransmit_timer;
  46. struct timer_list icsk_delack_timer;
  47. __u32 icsk_rto;
  48. __u8 icsk_retransmits;
  49. __u8 icsk_pending;
  50. __u8 icsk_backoff;
  51. __u8 icsk_syn_retries;
  52. struct {
  53. __u8 pending; /* ACK is pending */
  54. __u8 quick; /* Scheduled number of quick acks */
  55. __u8 pingpong; /* The session is interactive */
  56. __u8 blocked; /* Delayed ACK was blocked by socket lock */
  57. __u32 ato; /* Predicted tick of soft clock */
  58. unsigned long timeout; /* Currently scheduled timeout */
  59. __u32 lrcvtime; /* timestamp of last received data packet */
  60. __u16 last_seg_size; /* Size of last incoming segment */
  61. __u16 rcv_mss; /* MSS used for delayed ACK decisions */
  62. } icsk_ack;
  63. };
  64. #define ICSK_TIME_RETRANS 1 /* Retransmit timer */
  65. #define ICSK_TIME_DACK 2 /* Delayed ack timer */
  66. #define ICSK_TIME_PROBE0 3 /* Zero window probe timer */
  67. #define ICSK_TIME_KEEPOPEN 4 /* Keepalive timer */
  68. static inline struct inet_connection_sock *inet_csk(const struct sock *sk)
  69. {
  70. return (struct inet_connection_sock *)sk;
  71. }
  72. extern struct sock *inet_csk_clone(struct sock *sk,
  73. const struct request_sock *req,
  74. const unsigned int __nocast priority);
  75. enum inet_csk_ack_state_t {
  76. ICSK_ACK_SCHED = 1,
  77. ICSK_ACK_TIMER = 2,
  78. ICSK_ACK_PUSHED = 4
  79. };
  80. extern void inet_csk_init_xmit_timers(struct sock *sk,
  81. void (*retransmit_handler)(unsigned long),
  82. void (*delack_handler)(unsigned long),
  83. void (*keepalive_handler)(unsigned long));
  84. extern void inet_csk_clear_xmit_timers(struct sock *sk);
  85. static inline void inet_csk_schedule_ack(struct sock *sk)
  86. {
  87. inet_csk(sk)->icsk_ack.pending |= ICSK_ACK_SCHED;
  88. }
  89. static inline int inet_csk_ack_scheduled(const struct sock *sk)
  90. {
  91. return inet_csk(sk)->icsk_ack.pending & ICSK_ACK_SCHED;
  92. }
  93. static inline void inet_csk_delack_init(struct sock *sk)
  94. {
  95. memset(&inet_csk(sk)->icsk_ack, 0, sizeof(inet_csk(sk)->icsk_ack));
  96. }
  97. extern void inet_csk_delete_keepalive_timer(struct sock *sk);
  98. extern void inet_csk_reset_keepalive_timer(struct sock *sk, unsigned long timeout);
  99. #ifdef INET_CSK_DEBUG
  100. extern const char inet_csk_timer_bug_msg[];
  101. #endif
  102. static inline void inet_csk_clear_xmit_timer(struct sock *sk, const int what)
  103. {
  104. struct inet_connection_sock *icsk = inet_csk(sk);
  105. if (what == ICSK_TIME_RETRANS || what == ICSK_TIME_PROBE0) {
  106. icsk->icsk_pending = 0;
  107. #ifdef INET_CSK_CLEAR_TIMERS
  108. sk_stop_timer(sk, &icsk->icsk_retransmit_timer);
  109. #endif
  110. } else if (what == ICSK_TIME_DACK) {
  111. icsk->icsk_ack.blocked = icsk->icsk_ack.pending = 0;
  112. #ifdef INET_CSK_CLEAR_TIMERS
  113. sk_stop_timer(sk, &icsk->icsk_delack_timer);
  114. #endif
  115. }
  116. #ifdef INET_CSK_DEBUG
  117. else {
  118. pr_debug(inet_csk_timer_bug_msg);
  119. }
  120. #endif
  121. }
  122. /*
  123. * Reset the retransmission timer
  124. */
  125. static inline void inet_csk_reset_xmit_timer(struct sock *sk, const int what,
  126. unsigned long when,
  127. const unsigned long max_when)
  128. {
  129. struct inet_connection_sock *icsk = inet_csk(sk);
  130. if (when > max_when) {
  131. #ifdef INET_CSK_DEBUG
  132. pr_debug("reset_xmit_timer: sk=%p %d when=0x%lx, caller=%p\n",
  133. sk, what, when, current_text_addr());
  134. #endif
  135. when = max_when;
  136. }
  137. if (what == ICSK_TIME_RETRANS || what == ICSK_TIME_PROBE0) {
  138. icsk->icsk_pending = what;
  139. icsk->icsk_timeout = jiffies + when;
  140. sk_reset_timer(sk, &icsk->icsk_retransmit_timer, icsk->icsk_timeout);
  141. } else if (what == ICSK_TIME_DACK) {
  142. icsk->icsk_ack.pending |= ICSK_ACK_TIMER;
  143. icsk->icsk_ack.timeout = jiffies + when;
  144. sk_reset_timer(sk, &icsk->icsk_delack_timer, icsk->icsk_ack.timeout);
  145. }
  146. #ifdef INET_CSK_DEBUG
  147. else {
  148. pr_debug(inet_csk_timer_bug_msg);
  149. }
  150. #endif
  151. }
  152. extern struct sock *inet_csk_accept(struct sock *sk, int flags, int *err);
  153. extern struct request_sock *inet_csk_search_req(const struct sock *sk,
  154. struct request_sock ***prevp,
  155. const __u16 rport,
  156. const __u32 raddr,
  157. const __u32 laddr);
  158. extern int inet_csk_get_port(struct inet_hashinfo *hashinfo,
  159. struct sock *sk, unsigned short snum);
  160. extern struct dst_entry* inet_csk_route_req(struct sock *sk,
  161. const struct request_sock *req);
  162. static inline void inet_csk_reqsk_queue_add(struct sock *sk,
  163. struct request_sock *req,
  164. struct sock *child)
  165. {
  166. reqsk_queue_add(&inet_csk(sk)->icsk_accept_queue, req, sk, child);
  167. }
  168. extern void inet_csk_reqsk_queue_hash_add(struct sock *sk,
  169. struct request_sock *req,
  170. const unsigned timeout);
  171. static inline void inet_csk_reqsk_queue_removed(struct sock *sk,
  172. struct request_sock *req)
  173. {
  174. if (reqsk_queue_removed(&inet_csk(sk)->icsk_accept_queue, req) == 0)
  175. inet_csk_delete_keepalive_timer(sk);
  176. }
  177. static inline void inet_csk_reqsk_queue_added(struct sock *sk,
  178. const unsigned long timeout)
  179. {
  180. if (reqsk_queue_added(&inet_csk(sk)->icsk_accept_queue) == 0)
  181. inet_csk_reset_keepalive_timer(sk, timeout);
  182. }
  183. static inline int inet_csk_reqsk_queue_len(const struct sock *sk)
  184. {
  185. return reqsk_queue_len(&inet_csk(sk)->icsk_accept_queue);
  186. }
  187. static inline int inet_csk_reqsk_queue_young(const struct sock *sk)
  188. {
  189. return reqsk_queue_len_young(&inet_csk(sk)->icsk_accept_queue);
  190. }
  191. static inline int inet_csk_reqsk_queue_is_full(const struct sock *sk)
  192. {
  193. return reqsk_queue_is_full(&inet_csk(sk)->icsk_accept_queue);
  194. }
  195. static inline void inet_csk_reqsk_queue_unlink(struct sock *sk,
  196. struct request_sock *req,
  197. struct request_sock **prev)
  198. {
  199. reqsk_queue_unlink(&inet_csk(sk)->icsk_accept_queue, req, prev);
  200. }
  201. static inline void inet_csk_reqsk_queue_drop(struct sock *sk,
  202. struct request_sock *req,
  203. struct request_sock **prev)
  204. {
  205. inet_csk_reqsk_queue_unlink(sk, req, prev);
  206. inet_csk_reqsk_queue_removed(sk, req);
  207. reqsk_free(req);
  208. }
  209. extern void inet_csk_reqsk_queue_prune(struct sock *parent,
  210. const unsigned long interval,
  211. const unsigned long timeout,
  212. const unsigned long max_rto);
  213. extern void inet_csk_destroy_sock(struct sock *sk);
  214. extern int inet_csk_listen_start(struct sock *sk, const int nr_table_entries);
  215. extern void inet_csk_listen_stop(struct sock *sk);
  216. #endif /* _INET_CONNECTION_SOCK_H */