1
2
3
4
5
6
7
8
9
10
11
12
13
14
15#ifndef _INET_CONNECTION_SOCK_H
16#define _INET_CONNECTION_SOCK_H
17
18#include <linux/compiler.h>
19#include <linux/string.h>
20#include <linux/timer.h>
21#include <linux/poll.h>
22
23#include <net/inet_sock.h>
24#include <net/request_sock.h>
25
26
27#undef INET_CSK_CLEAR_TIMERS
28
29struct inet_bind_bucket;
30struct tcp_congestion_ops;
31
32
33
34
35
36struct inet_connection_sock_af_ops {
37 int (*queue_xmit)(struct sock *sk, struct sk_buff *skb, struct flowi *fl);
38 void (*send_check)(struct sock *sk, struct sk_buff *skb);
39 int (*rebuild_header)(struct sock *sk);
40 void (*sk_rx_dst_set)(struct sock *sk, const struct sk_buff *skb);
41 int (*conn_request)(struct sock *sk, struct sk_buff *skb);
42 struct sock *(*syn_recv_sock)(const struct sock *sk, struct sk_buff *skb,
43 struct request_sock *req,
44 struct dst_entry *dst,
45 struct request_sock *req_unhash,
46 bool *own_req);
47 u16 net_header_len;
48 u16 net_frag_header_len;
49 u16 sockaddr_len;
50 int (*setsockopt)(struct sock *sk, int level, int optname,
51 char __user *optval, unsigned int optlen);
52 int (*getsockopt)(struct sock *sk, int level, int optname,
53 char __user *optval, int __user *optlen);
54#ifdef CONFIG_COMPAT
55 int (*compat_setsockopt)(struct sock *sk,
56 int level, int optname,
57 char __user *optval, unsigned int optlen);
58 int (*compat_getsockopt)(struct sock *sk,
59 int level, int optname,
60 char __user *optval, int __user *optlen);
61#endif
62 void (*addr2sockaddr)(struct sock *sk, struct sockaddr *);
63 void (*mtu_reduced)(struct sock *sk);
64};
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90struct inet_connection_sock {
91
92 struct inet_sock icsk_inet;
93 struct request_sock_queue icsk_accept_queue;
94 struct inet_bind_bucket *icsk_bind_hash;
95 unsigned long icsk_timeout;
96 struct timer_list icsk_retransmit_timer;
97 struct timer_list icsk_delack_timer;
98 __u32 icsk_rto;
99 __u32 icsk_rto_min;
100 __u32 icsk_delack_max;
101 __u32 icsk_pmtu_cookie;
102 const struct tcp_congestion_ops *icsk_ca_ops;
103 const struct inet_connection_sock_af_ops *icsk_af_ops;
104 const struct tcp_ulp_ops *icsk_ulp_ops;
105 void __rcu *icsk_ulp_data;
106 void (*icsk_clean_acked)(struct sock *sk, u32 acked_seq);
107 struct hlist_node icsk_listen_portaddr_node;
108 unsigned int (*icsk_sync_mss)(struct sock *sk, u32 pmtu);
109 __u8 icsk_ca_state:5,
110 icsk_ca_initialized:1,
111 icsk_ca_setsockopt:1,
112 icsk_ca_dst_locked:1;
113 __u8 icsk_retransmits;
114 __u8 icsk_pending;
115 __u8 icsk_backoff;
116 __u8 icsk_syn_retries;
117 __u8 icsk_probes_out;
118 __u16 icsk_ext_hdr_len;
119 struct {
120 __u8 pending;
121 __u8 quick;
122 __u8 pingpong;
123 __u8 blocked;
124 __u32 ato;
125 unsigned long timeout;
126 __u32 lrcvtime;
127 __u16 last_seg_size;
128 __u16 rcv_mss;
129 } icsk_ack;
130 struct {
131 int enabled;
132
133
134 int search_high;
135 int search_low;
136
137
138 int probe_size;
139
140 u32 probe_timestamp;
141 } icsk_mtup;
142 u32 icsk_user_timeout;
143
144 u64 icsk_ca_priv[104 / sizeof(u64)];
145#define ICSK_CA_PRIV_SIZE (13 * sizeof(u64))
146};
147
148#define ICSK_TIME_RETRANS 1
149#define ICSK_TIME_DACK 2
150#define ICSK_TIME_PROBE0 3
151#define ICSK_TIME_EARLY_RETRANS 4
152#define ICSK_TIME_LOSS_PROBE 5
153#define ICSK_TIME_REO_TIMEOUT 6
154
155static inline struct inet_connection_sock *inet_csk(const struct sock *sk)
156{
157 return (struct inet_connection_sock *)sk;
158}
159
160static inline void *inet_csk_ca(const struct sock *sk)
161{
162 return (void *)inet_csk(sk)->icsk_ca_priv;
163}
164
165struct sock *inet_csk_clone_lock(const struct sock *sk,
166 const struct request_sock *req,
167 const gfp_t priority);
168
169enum inet_csk_ack_state_t {
170 ICSK_ACK_SCHED = 1,
171 ICSK_ACK_TIMER = 2,
172 ICSK_ACK_PUSHED = 4,
173 ICSK_ACK_PUSHED2 = 8,
174 ICSK_ACK_NOW = 16
175};
176
177void inet_csk_init_xmit_timers(struct sock *sk,
178 void (*retransmit_handler)(struct timer_list *),
179 void (*delack_handler)(struct timer_list *),
180 void (*keepalive_handler)(struct timer_list *));
181void inet_csk_clear_xmit_timers(struct sock *sk);
182
183static inline void inet_csk_schedule_ack(struct sock *sk)
184{
185 inet_csk(sk)->icsk_ack.pending |= ICSK_ACK_SCHED;
186}
187
188static inline int inet_csk_ack_scheduled(const struct sock *sk)
189{
190 return inet_csk(sk)->icsk_ack.pending & ICSK_ACK_SCHED;
191}
192
193static inline void inet_csk_delack_init(struct sock *sk)
194{
195 memset(&inet_csk(sk)->icsk_ack, 0, sizeof(inet_csk(sk)->icsk_ack));
196}
197
198void inet_csk_delete_keepalive_timer(struct sock *sk);
199void inet_csk_reset_keepalive_timer(struct sock *sk, unsigned long timeout);
200
201static inline void inet_csk_clear_xmit_timer(struct sock *sk, const int what)
202{
203 struct inet_connection_sock *icsk = inet_csk(sk);
204
205 if (what == ICSK_TIME_RETRANS || what == ICSK_TIME_PROBE0) {
206 icsk->icsk_pending = 0;
207#ifdef INET_CSK_CLEAR_TIMERS
208 sk_stop_timer(sk, &icsk->icsk_retransmit_timer);
209#endif
210 } else if (what == ICSK_TIME_DACK) {
211 icsk->icsk_ack.blocked = icsk->icsk_ack.pending = 0;
212#ifdef INET_CSK_CLEAR_TIMERS
213 sk_stop_timer(sk, &icsk->icsk_delack_timer);
214#endif
215 } else {
216 pr_debug("inet_csk BUG: unknown timer value\n");
217 }
218}
219
220
221
222
223static inline void inet_csk_reset_xmit_timer(struct sock *sk, const int what,
224 unsigned long when,
225 const unsigned long max_when)
226{
227 struct inet_connection_sock *icsk = inet_csk(sk);
228
229 if (when > max_when) {
230 pr_debug("reset_xmit_timer: sk=%p %d when=0x%lx, caller=%p\n",
231 sk, what, when, current_text_addr());
232 when = max_when;
233 }
234
235 if (what == ICSK_TIME_RETRANS || what == ICSK_TIME_PROBE0 ||
236 what == ICSK_TIME_EARLY_RETRANS || what == ICSK_TIME_LOSS_PROBE ||
237 what == ICSK_TIME_REO_TIMEOUT) {
238 icsk->icsk_pending = what;
239 icsk->icsk_timeout = jiffies + when;
240 sk_reset_timer(sk, &icsk->icsk_retransmit_timer, icsk->icsk_timeout);
241 } else if (what == ICSK_TIME_DACK) {
242 icsk->icsk_ack.pending |= ICSK_ACK_TIMER;
243 icsk->icsk_ack.timeout = jiffies + when;
244 sk_reset_timer(sk, &icsk->icsk_delack_timer, icsk->icsk_ack.timeout);
245 } else {
246 pr_debug("inet_csk BUG: unknown timer value\n");
247 }
248}
249
250static inline unsigned long
251inet_csk_rto_backoff(const struct inet_connection_sock *icsk,
252 unsigned long max_when)
253{
254 u64 when = (u64)icsk->icsk_rto << icsk->icsk_backoff;
255
256 return (unsigned long)min_t(u64, when, max_when);
257}
258
259struct sock *inet_csk_accept(struct sock *sk, int flags, int *err, bool kern);
260
261int inet_csk_get_port(struct sock *sk, unsigned short snum);
262
263struct dst_entry *inet_csk_route_req(const struct sock *sk, struct flowi4 *fl4,
264 const struct request_sock *req);
265struct dst_entry *inet_csk_route_child_sock(const struct sock *sk,
266 struct sock *newsk,
267 const struct request_sock *req);
268
269struct sock *inet_csk_reqsk_queue_add(struct sock *sk,
270 struct request_sock *req,
271 struct sock *child);
272void inet_csk_reqsk_queue_hash_add(struct sock *sk, struct request_sock *req,
273 unsigned long timeout);
274struct sock *inet_csk_complete_hashdance(struct sock *sk, struct sock *child,
275 struct request_sock *req,
276 bool own_req);
277
278static inline void inet_csk_reqsk_queue_added(struct sock *sk)
279{
280 reqsk_queue_added(&inet_csk(sk)->icsk_accept_queue);
281}
282
283static inline int inet_csk_reqsk_queue_len(const struct sock *sk)
284{
285 return reqsk_queue_len(&inet_csk(sk)->icsk_accept_queue);
286}
287
288static inline int inet_csk_reqsk_queue_is_full(const struct sock *sk)
289{
290 return inet_csk_reqsk_queue_len(sk) >= sk->sk_max_ack_backlog;
291}
292
293bool inet_csk_reqsk_queue_drop(struct sock *sk, struct request_sock *req);
294void inet_csk_reqsk_queue_drop_and_put(struct sock *sk, struct request_sock *req);
295
296static inline void inet_csk_prepare_for_destroy_sock(struct sock *sk)
297{
298
299 sock_set_flag(sk, SOCK_DEAD);
300 percpu_counter_inc(sk->sk_prot->orphan_count);
301}
302
303void inet_csk_destroy_sock(struct sock *sk);
304void inet_csk_prepare_forced_close(struct sock *sk);
305
306
307
308
309static inline __poll_t inet_csk_listen_poll(const struct sock *sk)
310{
311 return !reqsk_queue_empty(&inet_csk(sk)->icsk_accept_queue) ?
312 (EPOLLIN | EPOLLRDNORM) : 0;
313}
314
315int inet_csk_listen_start(struct sock *sk, int backlog);
316void inet_csk_listen_stop(struct sock *sk);
317
318void inet_csk_addr2sockaddr(struct sock *sk, struct sockaddr *uaddr);
319
320
321void inet_csk_update_fastreuse(struct inet_bind_bucket *tb,
322 struct sock *sk);
323
324int inet_csk_compat_getsockopt(struct sock *sk, int level, int optname,
325 char __user *optval, int __user *optlen);
326int inet_csk_compat_setsockopt(struct sock *sk, int level, int optname,
327 char __user *optval, unsigned int optlen);
328
329struct dst_entry *inet_csk_update_pmtu(struct sock *sk, u32 mtu);
330
331#define TCP_PINGPONG_THRESH 1
332
333static inline void inet_csk_enter_pingpong_mode(struct sock *sk)
334{
335 inet_csk(sk)->icsk_ack.pingpong = TCP_PINGPONG_THRESH;
336}
337
338static inline void inet_csk_exit_pingpong_mode(struct sock *sk)
339{
340 inet_csk(sk)->icsk_ack.pingpong = 0;
341}
342
343static inline bool inet_csk_in_pingpong_mode(struct sock *sk)
344{
345 return inet_csk(sk)->icsk_ack.pingpong >= TCP_PINGPONG_THRESH;
346}
347
348static inline bool inet_csk_has_ulp(struct sock *sk)
349{
350 return inet_sk(sk)->is_icsk && !!inet_csk(sk)->icsk_ulp_ops;
351}
352
353#endif
354