inet_connection_sock.h 9.7 KB

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