PageRenderTime 37ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/include/net/inet_connection_sock.h

https://gitlab.com/zeroepoch/android_kernel_amazon_sloane
C Header | 348 lines | 256 code | 44 blank | 48 comment | 24 complexity | afe8cbb6756e3bad06d19a31e275252d MD5 | raw file
Possible License(s): GPL-2.0
  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 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, struct flowi *fl);
  34. void (*send_check)(struct sock *sk, struct sk_buff *skb);
  35. int (*rebuild_header)(struct sock *sk);
  36. void (*sk_rx_dst_set)(struct sock *sk, const struct sk_buff *skb);
  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. u16 net_header_len;
  42. u16 net_frag_header_len;
  43. u16 sockaddr_len;
  44. int (*setsockopt)(struct sock *sk, int level, int optname,
  45. char __user *optval, unsigned int optlen);
  46. int (*getsockopt)(struct sock *sk, int level, int optname,
  47. char __user *optval, int __user *optlen);
  48. #ifdef CONFIG_COMPAT
  49. int (*compat_setsockopt)(struct sock *sk,
  50. int level, int optname,
  51. char __user *optval, unsigned int optlen);
  52. int (*compat_getsockopt)(struct sock *sk,
  53. int level, int optname,
  54. char __user *optval, int __user *optlen);
  55. #endif
  56. void (*addr2sockaddr)(struct sock *sk, struct sockaddr *);
  57. int (*bind_conflict)(const struct sock *sk,
  58. const struct inet_bind_bucket *tb, bool relax);
  59. void (*mtu_reduced)(struct sock *sk);
  60. };
  61. /** inet_connection_sock - INET connection oriented sock
  62. *
  63. * @icsk_accept_queue: FIFO of established children
  64. * @icsk_bind_hash: Bind node
  65. * @icsk_timeout: Timeout
  66. * @icsk_retransmit_timer: Resend (no ack)
  67. * @icsk_rto: Retransmit timeout
  68. * @icsk_pmtu_cookie Last pmtu seen by socket
  69. * @icsk_ca_ops Pluggable congestion control hook
  70. * @icsk_af_ops Operations which are AF_INET{4,6} specific
  71. * @icsk_ca_state: Congestion control state
  72. * @icsk_retransmits: Number of unrecovered [RTO] timeouts
  73. * @icsk_pending: Scheduled timer event
  74. * @icsk_backoff: Backoff
  75. * @icsk_syn_retries: Number of allowed SYN (or equivalent) retries
  76. * @icsk_probes_out: unanswered 0 window probes
  77. * @icsk_ext_hdr_len: Network protocol overhead (IP/IPv6 options)
  78. * @icsk_ack: Delayed ACK control data
  79. * @icsk_mtup; MTU probing control data
  80. */
  81. struct inet_connection_sock {
  82. /* inet_sock has to be the first member! */
  83. struct inet_sock icsk_inet;
  84. struct request_sock_queue icsk_accept_queue;
  85. struct inet_bind_bucket *icsk_bind_hash;
  86. unsigned long icsk_timeout;
  87. struct timer_list icsk_retransmit_timer;
  88. struct timer_list icsk_delack_timer;
  89. __u32 icsk_rto;
  90. __u32 icsk_MMSRB;
  91. __u32 icsk_pmtu_cookie;
  92. const struct tcp_congestion_ops *icsk_ca_ops;
  93. const struct inet_connection_sock_af_ops *icsk_af_ops;
  94. unsigned int (*icsk_sync_mss)(struct sock *sk, u32 pmtu);
  95. __u8 icsk_ca_state;
  96. __u8 icsk_retransmits;
  97. __u8 icsk_pending;
  98. __u8 icsk_backoff;
  99. __u8 icsk_syn_retries;
  100. __u8 icsk_probes_out;
  101. __u16 icsk_ext_hdr_len;
  102. struct {
  103. __u8 pending; /* ACK is pending */
  104. __u8 quick; /* Scheduled number of quick acks */
  105. __u8 pingpong; /* The session is interactive */
  106. __u8 blocked; /* Delayed ACK was blocked by socket lock */
  107. __u32 ato; /* Predicted tick of soft clock */
  108. unsigned long timeout; /* Currently scheduled timeout */
  109. __u32 lrcvtime; /* timestamp of last received data packet */
  110. __u16 last_seg_size; /* Size of last incoming segment */
  111. __u16 rcv_mss; /* MSS used for delayed ACK decisions */
  112. } icsk_ack;
  113. struct {
  114. int enabled;
  115. /* Range of MTUs to search */
  116. int search_high;
  117. int search_low;
  118. /* Information on the current probe. */
  119. int probe_size;
  120. } icsk_mtup;
  121. u32 icsk_ca_priv[16];
  122. u32 icsk_user_timeout;
  123. #define ICSK_CA_PRIV_SIZE (16 * sizeof(u32))
  124. };
  125. #define ICSK_TIME_RETRANS 1 /* Retransmit timer */
  126. #define ICSK_TIME_DACK 2 /* Delayed ack timer */
  127. #define ICSK_TIME_PROBE0 3 /* Zero window probe timer */
  128. #define ICSK_TIME_EARLY_RETRANS 4 /* Early retransmit timer */
  129. #define ICSK_TIME_LOSS_PROBE 5 /* Tail loss probe timer */
  130. static inline struct inet_connection_sock *inet_csk(const struct sock *sk)
  131. {
  132. return (struct inet_connection_sock *)sk;
  133. }
  134. static inline void *inet_csk_ca(const struct sock *sk)
  135. {
  136. return (void *)inet_csk(sk)->icsk_ca_priv;
  137. }
  138. extern struct sock *inet_csk_clone_lock(const struct sock *sk,
  139. const struct request_sock *req,
  140. const gfp_t priority);
  141. enum inet_csk_ack_state_t {
  142. ICSK_ACK_SCHED = 1,
  143. ICSK_ACK_TIMER = 2,
  144. ICSK_ACK_PUSHED = 4,
  145. ICSK_ACK_PUSHED2 = 8
  146. };
  147. extern void inet_csk_init_xmit_timers(struct sock *sk,
  148. void (*retransmit_handler)(unsigned long),
  149. void (*delack_handler)(unsigned long),
  150. void (*keepalive_handler)(unsigned long));
  151. extern void inet_csk_clear_xmit_timers(struct sock *sk);
  152. static inline void inet_csk_schedule_ack(struct sock *sk)
  153. {
  154. inet_csk(sk)->icsk_ack.pending |= ICSK_ACK_SCHED;
  155. }
  156. static inline int inet_csk_ack_scheduled(const struct sock *sk)
  157. {
  158. return inet_csk(sk)->icsk_ack.pending & ICSK_ACK_SCHED;
  159. }
  160. static inline void inet_csk_delack_init(struct sock *sk)
  161. {
  162. memset(&inet_csk(sk)->icsk_ack, 0, sizeof(inet_csk(sk)->icsk_ack));
  163. }
  164. extern void inet_csk_delete_keepalive_timer(struct sock *sk);
  165. extern void inet_csk_reset_keepalive_timer(struct sock *sk, unsigned long timeout);
  166. #ifdef INET_CSK_DEBUG
  167. extern const char inet_csk_timer_bug_msg[];
  168. #endif
  169. static inline void inet_csk_clear_xmit_timer(struct sock *sk, const int what)
  170. {
  171. struct inet_connection_sock *icsk = inet_csk(sk);
  172. if (what == ICSK_TIME_RETRANS || what == ICSK_TIME_PROBE0) {
  173. icsk->icsk_pending = 0;
  174. #ifdef INET_CSK_CLEAR_TIMERS
  175. sk_stop_timer(sk, &icsk->icsk_retransmit_timer);
  176. #endif
  177. } else if (what == ICSK_TIME_DACK) {
  178. icsk->icsk_ack.blocked = icsk->icsk_ack.pending = 0;
  179. #ifdef INET_CSK_CLEAR_TIMERS
  180. sk_stop_timer(sk, &icsk->icsk_delack_timer);
  181. #endif
  182. }
  183. #ifdef INET_CSK_DEBUG
  184. else {
  185. pr_debug("%s", inet_csk_timer_bug_msg);
  186. }
  187. #endif
  188. }
  189. /*
  190. * Reset the retransmission timer
  191. */
  192. static inline void inet_csk_reset_xmit_timer(struct sock *sk, const int what,
  193. unsigned long when,
  194. const unsigned long max_when)
  195. {
  196. struct inet_connection_sock *icsk = inet_csk(sk);
  197. if (when > max_when) {
  198. #ifdef INET_CSK_DEBUG
  199. pr_debug("reset_xmit_timer: sk=%p %d when=0x%lx, caller=%p\n",
  200. sk, what, when, current_text_addr());
  201. #endif
  202. when = max_when;
  203. }
  204. if (what == ICSK_TIME_RETRANS || what == ICSK_TIME_PROBE0 ||
  205. what == ICSK_TIME_EARLY_RETRANS || what == ICSK_TIME_LOSS_PROBE) {
  206. icsk->icsk_pending = what;
  207. icsk->icsk_timeout = jiffies + when;
  208. sk_reset_timer(sk, &icsk->icsk_retransmit_timer, icsk->icsk_timeout);
  209. } else if (what == ICSK_TIME_DACK) {
  210. icsk->icsk_ack.pending |= ICSK_ACK_TIMER;
  211. icsk->icsk_ack.timeout = jiffies + when;
  212. sk_reset_timer(sk, &icsk->icsk_delack_timer, icsk->icsk_ack.timeout);
  213. }
  214. #ifdef INET_CSK_DEBUG
  215. else {
  216. pr_debug("%s", inet_csk_timer_bug_msg);
  217. }
  218. #endif
  219. }
  220. extern struct sock *inet_csk_accept(struct sock *sk, int flags, int *err);
  221. extern struct request_sock *inet_csk_search_req(const struct sock *sk,
  222. struct request_sock ***prevp,
  223. const __be16 rport,
  224. const __be32 raddr,
  225. const __be32 laddr);
  226. extern int inet_csk_bind_conflict(const struct sock *sk,
  227. const struct inet_bind_bucket *tb, bool relax);
  228. extern int inet_csk_get_port(struct sock *sk, unsigned short snum);
  229. extern struct dst_entry* inet_csk_route_req(struct sock *sk,
  230. struct flowi4 *fl4,
  231. const struct request_sock *req);
  232. extern struct dst_entry* inet_csk_route_child_sock(struct sock *sk,
  233. struct sock *newsk,
  234. const struct request_sock *req);
  235. static inline void inet_csk_reqsk_queue_add(struct sock *sk,
  236. struct request_sock *req,
  237. struct sock *child)
  238. {
  239. reqsk_queue_add(&inet_csk(sk)->icsk_accept_queue, req, sk, child);
  240. }
  241. extern void inet_csk_reqsk_queue_hash_add(struct sock *sk,
  242. struct request_sock *req,
  243. unsigned long timeout);
  244. static inline void inet_csk_reqsk_queue_removed(struct sock *sk,
  245. struct request_sock *req)
  246. {
  247. if (reqsk_queue_removed(&inet_csk(sk)->icsk_accept_queue, req) == 0)
  248. inet_csk_delete_keepalive_timer(sk);
  249. }
  250. static inline void inet_csk_reqsk_queue_added(struct sock *sk,
  251. const unsigned long timeout)
  252. {
  253. if (reqsk_queue_added(&inet_csk(sk)->icsk_accept_queue) == 0)
  254. inet_csk_reset_keepalive_timer(sk, timeout);
  255. }
  256. static inline int inet_csk_reqsk_queue_len(const struct sock *sk)
  257. {
  258. return reqsk_queue_len(&inet_csk(sk)->icsk_accept_queue);
  259. }
  260. static inline int inet_csk_reqsk_queue_young(const struct sock *sk)
  261. {
  262. return reqsk_queue_len_young(&inet_csk(sk)->icsk_accept_queue);
  263. }
  264. static inline int inet_csk_reqsk_queue_is_full(const struct sock *sk)
  265. {
  266. return reqsk_queue_is_full(&inet_csk(sk)->icsk_accept_queue);
  267. }
  268. static inline void inet_csk_reqsk_queue_unlink(struct sock *sk,
  269. struct request_sock *req,
  270. struct request_sock **prev)
  271. {
  272. reqsk_queue_unlink(&inet_csk(sk)->icsk_accept_queue, req, prev);
  273. }
  274. static inline void inet_csk_reqsk_queue_drop(struct sock *sk,
  275. struct request_sock *req,
  276. struct request_sock **prev)
  277. {
  278. inet_csk_reqsk_queue_unlink(sk, req, prev);
  279. inet_csk_reqsk_queue_removed(sk, req);
  280. reqsk_free(req);
  281. }
  282. extern void inet_csk_reqsk_queue_prune(struct sock *parent,
  283. const unsigned long interval,
  284. const unsigned long timeout,
  285. const unsigned long max_rto);
  286. extern void inet_csk_destroy_sock(struct sock *sk);
  287. extern void inet_csk_prepare_forced_close(struct sock *sk);
  288. /*
  289. * LISTEN is a special case for poll..
  290. */
  291. static inline unsigned int inet_csk_listen_poll(const struct sock *sk)
  292. {
  293. return !reqsk_queue_empty(&inet_csk(sk)->icsk_accept_queue) ?
  294. (POLLIN | POLLRDNORM) : 0;
  295. }
  296. extern int inet_csk_listen_start(struct sock *sk, const int nr_table_entries);
  297. extern void inet_csk_listen_stop(struct sock *sk);
  298. extern void inet_csk_addr2sockaddr(struct sock *sk, struct sockaddr *uaddr);
  299. extern int inet_csk_compat_getsockopt(struct sock *sk, int level, int optname,
  300. char __user *optval, int __user *optlen);
  301. extern int inet_csk_compat_setsockopt(struct sock *sk, int level, int optname,
  302. char __user *optval, unsigned int optlen);
  303. extern struct dst_entry *inet_csk_update_pmtu(struct sock *sk, u32 mtu);
  304. #endif /* _INET_CONNECTION_SOCK_H */