Blame view
include/net/tcp.h
71.8 KB
2874c5fd2
|
1 |
/* SPDX-License-Identifier: GPL-2.0-or-later */ |
1da177e4c
|
2 3 4 5 6 7 8 9 10 |
/* * INET An implementation of the TCP/IP protocol suite for the LINUX * operating system. INET is implemented using the BSD Socket * interface as the means of communication with the user level. * * Definitions for the TCP module. * * Version: @(#)tcp.h 1.0.5 05/23/93 * |
02c30a84e
|
11 |
* Authors: Ross Biro |
1da177e4c
|
12 |
* Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG> |
1da177e4c
|
13 14 15 |
*/ #ifndef _TCP_H #define _TCP_H |
1da177e4c
|
16 |
#define FASTRETRANS_DEBUG 1 |
1da177e4c
|
17 18 |
#include <linux/list.h> #include <linux/tcp.h> |
187f1882b
|
19 |
#include <linux/bug.h> |
1da177e4c
|
20 21 22 |
#include <linux/slab.h> #include <linux/cache.h> #include <linux/percpu.h> |
fb286bb29
|
23 |
#include <linux/skbuff.h> |
435cf559f
|
24 |
#include <linux/kref.h> |
740b0f184
|
25 |
#include <linux/ktime.h> |
05e22e839
|
26 |
#include <linux/indirect_call_wrapper.h> |
3f421baa4
|
27 28 |
#include <net/inet_connection_sock.h> |
295ff7edb
|
29 |
#include <net/inet_timewait_sock.h> |
77d8bf9c6
|
30 |
#include <net/inet_hashtables.h> |
1da177e4c
|
31 |
#include <net/checksum.h> |
2e6599cb8
|
32 |
#include <net/request_sock.h> |
40a1227ea
|
33 |
#include <net/sock_reuseport.h> |
1da177e4c
|
34 35 36 |
#include <net/sock.h> #include <net/snmp.h> #include <net/ip.h> |
c752f0739
|
37 |
#include <net/tcp_states.h> |
bdf1ee5d3
|
38 |
#include <net/inet_ecn.h> |
0c266898b
|
39 |
#include <net/dst.h> |
857124841
|
40 |
#include <net/mptcp.h> |
c752f0739
|
41 |
|
1da177e4c
|
42 |
#include <linux/seq_file.h> |
180d8cd94
|
43 |
#include <linux/memcontrol.h> |
40304b2a1
|
44 |
#include <linux/bpf-cgroup.h> |
438ac8800
|
45 |
#include <linux/siphash.h> |
40304b2a1
|
46 |
|
6e04e0216
|
47 |
extern struct inet_hashinfo tcp_hashinfo; |
1da177e4c
|
48 |
|
dd24c0019
|
49 |
extern struct percpu_counter tcp_orphan_count; |
5c9f30236
|
50 |
void tcp_time_wait(struct sock *sk, int state, int timeo); |
1da177e4c
|
51 |
|
9bacd256f
|
52 |
#define MAX_TCP_HEADER L1_CACHE_ALIGN(128 + MAX_HEADER) |
33ad798c9
|
53 |
#define MAX_TCP_OPTION_SPACE 40 |
3b4929f65
|
54 55 |
#define TCP_MIN_SND_MSS 48 #define TCP_MIN_GSO_SIZE (TCP_MIN_SND_MSS - MAX_TCP_OPTION_SPACE) |
1da177e4c
|
56 |
|
105970f60
|
57 |
/* |
1da177e4c
|
58 |
* Never offer a window over 32767 without using window scaling. Some |
105970f60
|
59 |
* poor stacks do signed 16bit maths! |
1da177e4c
|
60 61 62 63 64 |
*/ #define MAX_TCP_WINDOW 32767U /* Minimal accepted MSS. It is (60+60+8) - (20+20). */ #define TCP_MIN_MSS 88U |
1555e6fdf
|
65 |
/* The initial MTU to use for probing */ |
dcd8fb853
|
66 |
#define TCP_BASE_MSS 1024 |
5d424d5a6
|
67 |
|
05cbc0db0
|
68 69 |
/* probing interval, default to 10 minutes as per RFC4821 */ #define TCP_PROBE_INTERVAL 600 |
6b58e0a5f
|
70 71 |
/* Specify interval when tcp mtu probing will stop */ #define TCP_PROBE_THRESHOLD 8 |
1da177e4c
|
72 73 |
/* After receiving this amount of duplicate ACKs fast retransmit starts. */ #define TCP_FASTRETRANS_THRESH 3 |
1da177e4c
|
74 75 |
/* Maximal number of ACKs sent quickly to accelerate slow-start. */ #define TCP_MAX_QUICKACKS 16U |
589c49cbf
|
76 77 |
/* Maximal number of window scale according to RFC1323 */ #define TCP_MAX_WSCALE 14U |
1da177e4c
|
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
/* urg_data states */ #define TCP_URG_VALID 0x0100 #define TCP_URG_NOTYET 0x0200 #define TCP_URG_READ 0x0400 #define TCP_RETR1 3 /* * This is how many retries it does before it * tries to figure out if the gateway is * down. Minimal RFC value is 3; it corresponds * to ~3sec-8min depending on RTO. */ #define TCP_RETR2 15 /* * This should take at least * 90 minutes to time out. * RFC1122 says that the limit is 100 sec. * 15 is ~13-30min depending on RTO. */ |
6c9ff979d
|
96 97 98 99 100 101 102 103 |
#define TCP_SYN_RETRIES 6 /* This is how many retries are done * when active opening a connection. * RFC1122 says the minimum retry MUST * be at least 180secs. Nevertheless * this value is corresponding to * 63secs of retransmission with the * current initial RTO. */ |
1da177e4c
|
104 |
|
6c9ff979d
|
105 106 107 108 109 110 |
#define TCP_SYNACK_RETRIES 5 /* This is how may retries are done * when passive opening a connection. * This is corresponding to 31secs of * retransmission with the current * initial RTO. */ |
1da177e4c
|
111 |
|
1da177e4c
|
112 113 114 115 116 117 118 119 |
#define TCP_TIMEWAIT_LEN (60*HZ) /* how long to wait to destroy TIME-WAIT * state, about 60 seconds */ #define TCP_FIN_TIMEOUT TCP_TIMEWAIT_LEN /* BSD style FIN_WAIT2 deadlock breaker. * It used to be 3min, new value is 60sec, * to combine FIN-WAIT-2 timeout with * TIME-WAIT timer. */ |
f0628c524
|
120 |
#define TCP_FIN_TIMEOUT_MAX (120 * HZ) /* max TCP_LINGER2 value (two minutes) */ |
1da177e4c
|
121 122 123 124 125 126 127 128 129 130 131 |
#define TCP_DELACK_MAX ((unsigned)(HZ/5)) /* maximal time to delay before sending an ACK */ #if HZ >= 100 #define TCP_DELACK_MIN ((unsigned)(HZ/25)) /* minimal time to delay before sending an ACK */ #define TCP_ATO_MIN ((unsigned)(HZ/25)) #else #define TCP_DELACK_MIN 4U #define TCP_ATO_MIN 4U #endif #define TCP_RTO_MAX ((unsigned)(120*HZ)) #define TCP_RTO_MIN ((unsigned)(HZ/5)) |
bb4d991a2
|
132 |
#define TCP_TIMEOUT_MIN (2U) /* Min timeout for TCP timers in jiffies */ |
fd4f2cead
|
133 |
#define TCP_TIMEOUT_INIT ((unsigned)(1*HZ)) /* RFC6298 2.1 initial RTO value */ |
9ad7c049f
|
134 135 136 137 138 139 |
#define TCP_TIMEOUT_FALLBACK ((unsigned)(3*HZ)) /* RFC 1122 initial RTO value, now * used as a fallback RTO for the * initial data transmission if no * valid RTT sample has been acquired, * most likely due to retrans in 3WHS. */ |
1da177e4c
|
140 141 142 143 |
#define TCP_RESOURCE_PROBE_INTERVAL ((unsigned)(HZ/2U)) /* Maximal interval between probes * for local resources. */ |
1da177e4c
|
144 145 146 147 148 149 150 151 152 153 |
#define TCP_KEEPALIVE_TIME (120*60*HZ) /* two hours */ #define TCP_KEEPALIVE_PROBES 9 /* Max of 9 keepalive probes */ #define TCP_KEEPALIVE_INTVL (75*HZ) #define MAX_TCP_KEEPIDLE 32767 #define MAX_TCP_KEEPINTVL 32767 #define MAX_TCP_KEEPCNT 127 #define MAX_TCP_SYNCNT 127 #define TCP_SYNQ_INTERVAL (HZ/5) /* Period of SYNACK timer */ |
1da177e4c
|
154 155 156 157 158 159 160 161 162 163 164 165 |
#define TCP_PAWS_24DAYS (60 * 60 * 24 * 24) #define TCP_PAWS_MSL 60 /* Per-host timestamps are invalidated * after this time. It should be equal * (or greater than) TCP_TIMEWAIT_LEN * to provide reliability equal to one * provided by timewait state. */ #define TCP_PAWS_WINDOW 1 /* Replay window for per-host * timestamps. It must be less than * minimal timewait lifetime. */ |
1da177e4c
|
166 167 168 |
/* * TCP option */ |
105970f60
|
169 |
|
1da177e4c
|
170 171 172 173 174 175 176 |
#define TCPOPT_NOP 1 /* Padding */ #define TCPOPT_EOL 0 /* End of options */ #define TCPOPT_MSS 2 /* Segment size negotiating */ #define TCPOPT_WINDOW 3 /* Window scaling */ #define TCPOPT_SACK_PERM 4 /* SACK Permitted */ #define TCPOPT_SACK 5 /* SACK Block */ #define TCPOPT_TIMESTAMP 8 /* Better RTT estimations/PAWS */ |
cfb6eeb4c
|
177 |
#define TCPOPT_MD5SIG 19 /* MD5 Signature (RFC2385) */ |
c74a39c86
|
178 |
#define TCPOPT_MPTCP 30 /* Multipath TCP (RFC6824) */ |
7f9b838b7
|
179 |
#define TCPOPT_FASTOPEN 34 /* Fast open (RFC7413) */ |
2100c8d2d
|
180 181 182 183 184 |
#define TCPOPT_EXP 254 /* Experimental */ /* Magic number to be after the option value for sharing TCP * experimental options. See draft-ietf-tcpm-experimental-options-00.txt */ #define TCPOPT_FASTOPEN_MAGIC 0xF989 |
60e2a7780
|
185 |
#define TCPOPT_SMC_MAGIC 0xE2D4C3D9 |
1da177e4c
|
186 187 188 189 190 191 192 193 194 |
/* * TCP option lengths */ #define TCPOLEN_MSS 4 #define TCPOLEN_WINDOW 3 #define TCPOLEN_SACK_PERM 2 #define TCPOLEN_TIMESTAMP 10 |
cfb6eeb4c
|
195 |
#define TCPOLEN_MD5SIG 18 |
7f9b838b7
|
196 |
#define TCPOLEN_FASTOPEN_BASE 2 |
2100c8d2d
|
197 |
#define TCPOLEN_EXP_FASTOPEN_BASE 4 |
60e2a7780
|
198 |
#define TCPOLEN_EXP_SMC_BASE 6 |
1da177e4c
|
199 200 201 202 203 204 205 206 |
/* But this is what stacks really send out. */ #define TCPOLEN_TSTAMP_ALIGNED 12 #define TCPOLEN_WSCALE_ALIGNED 4 #define TCPOLEN_SACKPERM_ALIGNED 4 #define TCPOLEN_SACK_BASE 2 #define TCPOLEN_SACK_BASE_ALIGNED 4 #define TCPOLEN_SACK_PERBLOCK 8 |
cfb6eeb4c
|
207 |
#define TCPOLEN_MD5SIG_ALIGNED 20 |
33ad798c9
|
208 |
#define TCPOLEN_MSS_ALIGNED 4 |
60e2a7780
|
209 |
#define TCPOLEN_EXP_SMC_BASE_ALIGNED 8 |
1da177e4c
|
210 |
|
1da177e4c
|
211 212 213 |
/* Flags in tp->nonagle */ #define TCP_NAGLE_OFF 1 /* Nagle's algo is disabled */ #define TCP_NAGLE_CORK 2 /* Socket is corked */ |
caa20d9ab
|
214 |
#define TCP_NAGLE_PUSH 4 /* Cork is overridden for already queued data */ |
1da177e4c
|
215 |
|
36e31b0af
|
216 217 |
/* TCP thin-stream limits */ #define TCP_THIN_LINEAR_RETRIES 6 /* After 6 linear retries, do exp. backoff */ |
21603fc45
|
218 |
/* TCP initial congestion window as per rfc6928 */ |
442b9635c
|
219 |
#define TCP_INIT_CWND 10 |
cf60af03c
|
220 221 |
/* Bit Flags for sysctl_tcp_fastopen */ #define TFO_CLIENT_ENABLE 1 |
104671636
|
222 |
#define TFO_SERVER_ENABLE 2 |
67da22d23
|
223 |
#define TFO_CLIENT_NO_COOKIE 4 /* Data in SYN w/o cookie option */ |
cf60af03c
|
224 |
|
104671636
|
225 226 227 228 |
/* Accept SYN data w/o any cookie option */ #define TFO_SERVER_COOKIE_NOT_REQD 0x200 /* Force enable TFO on all listeners, i.e., not requiring the |
cebc5cbab
|
229 |
* TCP_FASTOPEN socket option. |
104671636
|
230 231 |
*/ #define TFO_SERVER_WO_SOCKOPT1 0x400 |
104671636
|
232 |
|
295ff7edb
|
233 |
|
1da177e4c
|
234 |
/* sysctl variables for tcp */ |
1da177e4c
|
235 |
extern int sysctl_tcp_max_orphans; |
a4fe34bf9
|
236 |
extern long sysctl_tcp_mem[3]; |
e20223f19
|
237 |
|
a0370b3f3
|
238 |
#define TCP_RACK_LOSS_DETECTION 0x1 /* Use RACK to detect losses */ |
1f2556916
|
239 |
#define TCP_RACK_STATIC_REO_WND 0x2 /* Use static RACK reo wnd */ |
20b654dfe
|
240 |
#define TCP_RACK_NO_DUPTHRESH 0x4 /* Do not use DUPACK threshold in RACK */ |
a0370b3f3
|
241 |
|
8d987e5c7
|
242 |
extern atomic_long_t tcp_memory_allocated; |
1748376b6
|
243 |
extern struct percpu_counter tcp_sockets_allocated; |
060447511
|
244 |
extern unsigned long tcp_memory_pressure; |
1da177e4c
|
245 |
|
b8da51ebb
|
246 247 248 |
/* optimized version of sk_under_memory_pressure() for TCP sockets */ static inline bool tcp_under_memory_pressure(const struct sock *sk) { |
baac50bbc
|
249 250 |
if (mem_cgroup_sockets_enabled && sk->sk_memcg && mem_cgroup_under_socket_pressure(sk->sk_memcg)) |
e805605c7
|
251 |
return true; |
b8da51ebb
|
252 |
|
1f142c17d
|
253 |
return READ_ONCE(tcp_memory_pressure); |
b8da51ebb
|
254 |
} |
1da177e4c
|
255 |
/* |
1da177e4c
|
256 257 258 |
* The next routines deal with comparing 32 bit unsigned ints * and worry about wraparound (automatic with unsigned arithmetic). */ |
a2a385d62
|
259 |
static inline bool before(__u32 seq1, __u32 seq2) |
1da177e4c
|
260 |
{ |
0d630cc0a
|
261 |
return (__s32)(seq1-seq2) < 0; |
1da177e4c
|
262 |
} |
9a036b9c3
|
263 |
#define after(seq2, seq1) before(seq1, seq2) |
1da177e4c
|
264 265 |
/* is s2<=s1<=s3 ? */ |
a2a385d62
|
266 |
static inline bool between(__u32 seq1, __u32 seq2, __u32 seq3) |
1da177e4c
|
267 268 269 |
{ return seq3 - seq2 >= seq1 - seq2; } |
efcdbf24f
|
270 271 272 273 274 275 276 |
static inline bool tcp_out_of_memory(struct sock *sk) { if (sk->sk_wmem_queued > SOCK_MIN_SNDBUF && sk_memory_allocated(sk) > sk_prot_mem_limits(sk, 2)) return true; return false; } |
a6c5ea4cc
|
277 |
void sk_forced_mem_schedule(struct sock *sk, int size); |
ad1af0fed
|
278 |
static inline bool tcp_too_many_orphans(struct sock *sk, int shift) |
e4fd5da39
|
279 |
{ |
ad1af0fed
|
280 281 282 283 284 285 286 287 |
struct percpu_counter *ocp = sk->sk_prot->orphan_count; int orphans = percpu_counter_read_positive(ocp); if (orphans << shift > sysctl_tcp_max_orphans) { orphans = percpu_counter_sum_positive(ocp); if (orphans << shift > sysctl_tcp_max_orphans) return true; } |
ad1af0fed
|
288 |
return false; |
e4fd5da39
|
289 |
} |
1da177e4c
|
290 |
|
5c9f30236
|
291 |
bool tcp_check_oom(struct sock *sk, int shift); |
efcdbf24f
|
292 |
|
a0f82f64e
|
293 |
|
1da177e4c
|
294 |
extern struct proto tcp_prot; |
57ef42d59
|
295 |
#define TCP_INC_STATS(net, field) SNMP_INC_STATS((net)->mib.tcp_statistics, field) |
13415e46c
|
296 |
#define __TCP_INC_STATS(net, field) __SNMP_INC_STATS((net)->mib.tcp_statistics, field) |
57ef42d59
|
297 |
#define TCP_DEC_STATS(net, field) SNMP_DEC_STATS((net)->mib.tcp_statistics, field) |
aa2ea0586
|
298 |
#define TCP_ADD_STATS(net, field, val) SNMP_ADD_STATS((net)->mib.tcp_statistics, field, val) |
1da177e4c
|
299 |
|
5c9f30236
|
300 |
void tcp_tasklet_init(void); |
32bbd8793
|
301 |
int tcp_v4_err(struct sk_buff *skb, u32); |
5c9f30236
|
302 303 |
void tcp_shutdown(struct sock *sk, int how); |
7487449c8
|
304 |
int tcp_v4_early_demux(struct sk_buff *skb); |
5c9f30236
|
305 306 307 |
int tcp_v4_rcv(struct sk_buff *skb); int tcp_v4_tw_remember_stamp(struct inet_timewait_sock *tw); |
1b7841404
|
308 |
int tcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t size); |
306b13eb3
|
309 |
int tcp_sendmsg_locked(struct sock *sk, struct msghdr *msg, size_t size); |
5c9f30236
|
310 311 |
int tcp_sendpage(struct sock *sk, struct page *page, int offset, size_t size, int flags); |
306b13eb3
|
312 313 |
int tcp_sendpage_locked(struct sock *sk, struct page *page, int offset, size_t size, int flags); |
e3b5616a3
|
314 315 |
ssize_t do_tcp_sendpages(struct sock *sk, struct page *page, int offset, size_t size, int flags); |
35b2c3211
|
316 317 318 |
int tcp_send_mss(struct sock *sk, int *size_goal, int flags); void tcp_push(struct sock *sk, int flags, int mss_now, int nonagle, int size_goal); |
5c9f30236
|
319 320 321 322 323 |
void tcp_release_cb(struct sock *sk); void tcp_wfree(struct sk_buff *skb); void tcp_write_timer_handler(struct sock *sk); void tcp_delack_timer_handler(struct sock *sk); int tcp_ioctl(struct sock *sk, int cmd, unsigned long arg); |
72ab4a86f
|
324 |
int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb); |
3d97d88e8
|
325 |
void tcp_rcv_established(struct sock *sk, struct sk_buff *skb); |
5c9f30236
|
326 |
void tcp_rcv_space_adjust(struct sock *sk); |
5c9f30236
|
327 328 329 330 331 |
int tcp_twsk_unique(struct sock *sk, struct sock *sktw, void *twp); void tcp_twsk_destructor(struct sock *sk); ssize_t tcp_splice_read(struct socket *sk, loff_t *ppos, struct pipe_inode_info *pipe, size_t len, unsigned int flags); |
9c55e01c0
|
332 |
|
a0496ef2c
|
333 |
void tcp_enter_quickack_mode(struct sock *sk, unsigned int max_quickacks); |
463c84b97
|
334 335 |
static inline void tcp_dec_quickack_mode(struct sock *sk, const unsigned int pkts) |
1da177e4c
|
336 |
{ |
463c84b97
|
337 |
struct inet_connection_sock *icsk = inet_csk(sk); |
fc6415bcb
|
338 |
|
463c84b97
|
339 340 341 |
if (icsk->icsk_ack.quick) { if (pkts >= icsk->icsk_ack.quick) { icsk->icsk_ack.quick = 0; |
fc6415bcb
|
342 |
/* Leaving quickack mode we deflate ATO. */ |
463c84b97
|
343 |
icsk->icsk_ack.ato = TCP_ATO_MIN; |
fc6415bcb
|
344 |
} else |
463c84b97
|
345 |
icsk->icsk_ack.quick -= pkts; |
1da177e4c
|
346 347 |
} } |
bdf1ee5d3
|
348 349 350 |
#define TCP_ECN_OK 1 #define TCP_ECN_QUEUE_CWR 2 #define TCP_ECN_DEMAND_CWR 4 |
7a269ffad
|
351 |
#define TCP_ECN_SEEN 8 |
bdf1ee5d3
|
352 |
|
fd2c3ef76
|
353 |
enum tcp_tw_status { |
1da177e4c
|
354 355 356 357 358 |
TCP_TW_SUCCESS = 0, TCP_TW_RST = 1, TCP_TW_ACK = 2, TCP_TW_SYN = 3 }; |
5c9f30236
|
359 360 361 362 |
enum tcp_tw_status tcp_timewait_state_process(struct inet_timewait_sock *tw, struct sk_buff *skb, const struct tcphdr *th); struct sock *tcp_check_req(struct sock *sk, struct sk_buff *skb, |
e0f9759f5
|
363 364 |
struct request_sock *req, bool fastopen, bool *lost_race); |
5c9f30236
|
365 366 |
int tcp_child_process(struct sock *parent, struct sock *child, struct sk_buff *skb); |
5ae344c94
|
367 |
void tcp_enter_loss(struct sock *sk); |
57dde7f70
|
368 |
void tcp_cwnd_reduction(struct sock *sk, int newly_acked_sacked, int flag); |
5c9f30236
|
369 370 371 372 |
void tcp_clear_retrans(struct tcp_sock *tp); void tcp_update_metrics(struct sock *sk); void tcp_init_metrics(struct sock *sk); void tcp_metrics_init(void); |
d82bae12d
|
373 |
bool tcp_peer_is_proven(struct request_sock *req, struct dst_entry *dst); |
5c9f30236
|
374 375 |
void tcp_close(struct sock *sk, long timeout); void tcp_init_sock(struct sock *sk); |
72be0fe6b
|
376 |
void tcp_init_transfer(struct sock *sk, int bpf_op, struct sk_buff *skb); |
a11e1d432
|
377 378 |
__poll_t tcp_poll(struct file *file, struct socket *sock, struct poll_table_struct *wait); |
5c9f30236
|
379 380 |
int tcp_getsockopt(struct sock *sk, int level, int optname, char __user *optval, int __user *optlen); |
a7b75c5a8
|
381 382 |
int tcp_setsockopt(struct sock *sk, int level, int optname, sockptr_t optval, unsigned int optlen); |
5c9f30236
|
383 |
void tcp_set_keepalive(struct sock *sk, int val); |
42cb80a23
|
384 |
void tcp_syn_ack_timeout(const struct request_sock *req); |
1b7841404
|
385 386 |
int tcp_recvmsg(struct sock *sk, struct msghdr *msg, size_t len, int nonblock, int flags, int *addr_len); |
d1361840f
|
387 |
int tcp_set_rcvlowat(struct sock *sk, int val); |
03f45c883
|
388 |
void tcp_data_ready(struct sock *sk); |
340a6f3d2
|
389 |
#ifdef CONFIG_MMU |
93ab6cc69
|
390 391 |
int tcp_mmap(struct file *file, struct socket *sock, struct vm_area_struct *vma); |
340a6f3d2
|
392 |
#endif |
eed29f17f
|
393 |
void tcp_parse_options(const struct net *net, const struct sk_buff *skb, |
5c9f30236
|
394 395 396 |
struct tcp_options_received *opt_rx, int estab, struct tcp_fastopen_cookie *foc); const u8 *tcp_parse_md5sig_option(const struct tcphdr *th); |
7d5d5525b
|
397 |
|
1da177e4c
|
398 |
/* |
9349d600f
|
399 400 401 402 403 404 405 406 407 408 |
* BPF SKB-less helpers */ u16 tcp_v4_get_syncookie(struct sock *sk, struct iphdr *iph, struct tcphdr *th, u32 *cookie); u16 tcp_v6_get_syncookie(struct sock *sk, struct ipv6hdr *iph, struct tcphdr *th, u32 *cookie); u16 tcp_get_syncookie_mss(struct request_sock_ops *rsk_ops, const struct tcp_request_sock_ops *af_ops, struct sock *sk, struct tcphdr *th); /* |
1da177e4c
|
409 410 |
* TCP v4 functions exported for the inet6 API */ |
5c9f30236
|
411 |
void tcp_v4_send_check(struct sock *sk, struct sk_buff *skb); |
4fab90719
|
412 |
void tcp_v4_mtu_reduced(struct sock *sk); |
9cf749036
|
413 |
void tcp_req_err(struct sock *sk, u32 seq, bool abort); |
d29245692
|
414 |
void tcp_ld_RTO_revert(struct sock *sk, u32 seq); |
5c9f30236
|
415 |
int tcp_v4_conn_request(struct sock *sk, struct sk_buff *skb); |
c28c6f045
|
416 |
struct sock *tcp_create_openreq_child(const struct sock *sk, |
5c9f30236
|
417 418 |
struct request_sock *req, struct sk_buff *skb); |
81164413a
|
419 |
void tcp_ca_openreq_child(struct sock *sk, const struct dst_entry *dst); |
0c27171e6
|
420 |
struct sock *tcp_v4_syn_recv_sock(const struct sock *sk, struct sk_buff *skb, |
5c9f30236
|
421 |
struct request_sock *req, |
5e0724d02
|
422 423 424 |
struct dst_entry *dst, struct request_sock *req_unhash, bool *own_req); |
5c9f30236
|
425 426 427 |
int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb); int tcp_v4_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len); int tcp_connect(struct sock *sk); |
b3d051477
|
428 429 430 431 432 |
enum tcp_synack_type { TCP_SYNACK_NORMAL, TCP_SYNACK_FASTOPEN, TCP_SYNACK_COOKIE, }; |
5d062de7f
|
433 |
struct sk_buff *tcp_make_synack(const struct sock *sk, struct dst_entry *dst, |
5c9f30236
|
434 |
struct request_sock *req, |
ca6fb0651
|
435 |
struct tcp_fastopen_cookie *foc, |
331fca431
|
436 437 |
enum tcp_synack_type synack_type, struct sk_buff *syn_skb); |
5c9f30236
|
438 |
int tcp_disconnect(struct sock *sk, int flags); |
1da177e4c
|
439 |
|
370816aef
|
440 |
void tcp_finish_connect(struct sock *sk, struct sk_buff *skb); |
292e8d8c8
|
441 |
int tcp_send_rcvq(struct sock *sk, struct msghdr *msg, size_t size); |
63d02d157
|
442 |
void inet_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb); |
1da177e4c
|
443 |
|
1da177e4c
|
444 |
/* From syncookies.c */ |
b80c0e785
|
445 446 |
struct sock *tcp_get_cookie_sock(struct sock *sk, struct sk_buff *skb, struct request_sock *req, |
84b114b98
|
447 |
struct dst_entry *dst, u32 tsoff); |
5c9f30236
|
448 449 |
int __cookie_v4_check(const struct iphdr *iph, const struct tcphdr *th, u32 cookie); |
461b74c39
|
450 |
struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb); |
6fc8c827d
|
451 452 |
struct request_sock *cookie_tcp_reqsk_alloc(const struct request_sock_ops *ops, struct sock *sk, struct sk_buff *skb); |
e05c82d36
|
453 |
#ifdef CONFIG_SYN_COOKIES |
8c27bd75f
|
454 |
|
632623153
|
455 |
/* Syncookies use a monotonic timer which increments every 60 seconds. |
8c27bd75f
|
456 457 458 |
* This counter is used both as a hash input and partially encoded into * the cookie value. A cookie is only validated further if the delta * between the current counter value and the encoded one is less than this, |
632623153
|
459 |
* i.e. a sent cookie is valid only at most for 2*60 seconds (or less if |
8c27bd75f
|
460 461 |
* the counter advances immediately after a cookie is generated). */ |
264ea103a
|
462 463 464 465 466 467 |
#define MAX_SYNCOOKIE_AGE 2 #define TCP_SYNCOOKIE_PERIOD (60 * HZ) #define TCP_SYNCOOKIE_VALID (MAX_SYNCOOKIE_AGE * TCP_SYNCOOKIE_PERIOD) /* syncookies: remember time of last synqueue overflow * But do not dirty this field too often (once per second is enough) |
3f684b4b1
|
468 |
* It is racy as we do not hold a lock, but race is very minor. |
264ea103a
|
469 |
*/ |
3f684b4b1
|
470 |
static inline void tcp_synq_overflow(const struct sock *sk) |
264ea103a
|
471 |
{ |
40a1227ea
|
472 |
unsigned int last_overflow; |
cca9bab1b
|
473 |
unsigned int now = jiffies; |
264ea103a
|
474 |
|
40a1227ea
|
475 476 477 478 479 480 |
if (sk->sk_reuseport) { struct sock_reuseport *reuse; reuse = rcu_dereference(sk->sk_reuseport_cb); if (likely(reuse)) { last_overflow = READ_ONCE(reuse->synq_overflow_ts); |
04d26e7b1
|
481 482 |
if (!time_between32(now, last_overflow, last_overflow + HZ)) |
40a1227ea
|
483 484 485 486 |
WRITE_ONCE(reuse->synq_overflow_ts, now); return; } } |
721c8dafa
|
487 |
last_overflow = READ_ONCE(tcp_sk(sk)->rx_opt.ts_recent_stamp); |
04d26e7b1
|
488 |
if (!time_between32(now, last_overflow, last_overflow + HZ)) |
721c8dafa
|
489 |
WRITE_ONCE(tcp_sk(sk)->rx_opt.ts_recent_stamp, now); |
264ea103a
|
490 491 492 493 494 |
} /* syncookies: no recent synqueue overflow on this listening socket? */ static inline bool tcp_synq_no_recent_overflow(const struct sock *sk) { |
40a1227ea
|
495 |
unsigned int last_overflow; |
cca9bab1b
|
496 |
unsigned int now = jiffies; |
264ea103a
|
497 |
|
40a1227ea
|
498 499 500 501 502 503 |
if (sk->sk_reuseport) { struct sock_reuseport *reuse; reuse = rcu_dereference(sk->sk_reuseport_cb); if (likely(reuse)) { last_overflow = READ_ONCE(reuse->synq_overflow_ts); |
cb44a08f8
|
504 505 506 |
return !time_between32(now, last_overflow - HZ, last_overflow + TCP_SYNCOOKIE_VALID); |
40a1227ea
|
507 508 |
} } |
721c8dafa
|
509 |
last_overflow = READ_ONCE(tcp_sk(sk)->rx_opt.ts_recent_stamp); |
cb44a08f8
|
510 511 512 513 514 515 516 517 518 519 |
/* If last_overflow <= jiffies <= last_overflow + TCP_SYNCOOKIE_VALID, * then we're under synflood. However, we have to use * 'last_overflow - HZ' as lower bound. That's because a concurrent * tcp_synq_overflow() could update .ts_recent_stamp after we read * jiffies but before we store .ts_recent_stamp into last_overflow, * which could lead to rejecting a valid syncookie. */ return !time_between32(now, last_overflow - HZ, last_overflow + TCP_SYNCOOKIE_VALID); |
264ea103a
|
520 |
} |
8c27bd75f
|
521 522 523 |
static inline u32 tcp_cookie_time(void) { |
632623153
|
524 |
u64 val = get_jiffies_64(); |
264ea103a
|
525 |
do_div(val, TCP_SYNCOOKIE_PERIOD); |
632623153
|
526 |
return val; |
8c27bd75f
|
527 |
} |
5c9f30236
|
528 529 |
u32 __cookie_v4_init_sequence(const struct iphdr *iph, const struct tcphdr *th, u16 *mssp); |
3f684b4b1
|
530 |
__u32 cookie_v4_init_sequence(const struct sk_buff *skb, __u16 *mss); |
200ecef67
|
531 |
u64 cookie_init_timestamp(struct request_sock *req, u64 now); |
f93010342
|
532 533 |
bool cookie_timestamp_decode(const struct net *net, struct tcp_options_received *opt); |
f1673381b
|
534 |
bool cookie_ecn_ok(const struct tcp_options_received *opt, |
f7b3bec6f
|
535 |
const struct net *net, const struct dst_entry *dst); |
4dfc28170
|
536 |
|
c6aefafb7
|
537 |
/* From net/ipv6/syncookies.c */ |
5c9f30236
|
538 539 540 |
int __cookie_v6_check(const struct ipv6hdr *iph, const struct tcphdr *th, u32 cookie); struct sock *cookie_v6_check(struct sock *sk, struct sk_buff *skb); |
f1673381b
|
541 |
|
5c9f30236
|
542 543 |
u32 __cookie_v6_init_sequence(const struct ipv6hdr *iph, const struct tcphdr *th, u16 *mssp); |
3f684b4b1
|
544 |
__u32 cookie_v6_init_sequence(const struct sk_buff *skb, __u16 *mss); |
e05c82d36
|
545 |
#endif |
1da177e4c
|
546 |
/* tcp_output.c */ |
5c9f30236
|
547 548 |
void __tcp_push_pending_frames(struct sock *sk, unsigned int cur_mss, int nonagle); |
10d3be569
|
549 550 |
int __tcp_retransmit_skb(struct sock *sk, struct sk_buff *skb, int segs); int tcp_retransmit_skb(struct sock *sk, struct sk_buff *skb, int segs); |
5c9f30236
|
551 552 553 |
void tcp_retransmit_timer(struct sock *sk); void tcp_xmit_retransmit_queue(struct sock *); void tcp_simple_retransmit(struct sock *); |
57dde7f70
|
554 |
void tcp_enter_recovery(struct sock *sk, bool ece_ack); |
5c9f30236
|
555 |
int tcp_trim_head(struct sock *, struct sk_buff *, u32); |
75c119afe
|
556 557 558 559 560 561 562 |
enum tcp_queue { TCP_FRAG_IN_WRITE_QUEUE, TCP_FRAG_IN_RTX_QUEUE, }; int tcp_fragment(struct sock *sk, enum tcp_queue tcp_queue, struct sk_buff *skb, u32 len, unsigned int mss_now, gfp_t gfp); |
5c9f30236
|
563 564 565 |
void tcp_send_probe0(struct sock *); void tcp_send_partial(struct sock *); |
e520af48c
|
566 |
int tcp_write_wakeup(struct sock *, int mib); |
5c9f30236
|
567 568 569 |
void tcp_send_fin(struct sock *sk); void tcp_send_active_reset(struct sock *sk, gfp_t priority); int tcp_send_synack(struct sock *); |
5c9f30236
|
570 |
void tcp_push_one(struct sock *, unsigned int mss_now); |
27cde44a2
|
571 |
void __tcp_send_ack(struct sock *sk, u32 rcv_nxt); |
5c9f30236
|
572 573 574 |
void tcp_send_ack(struct sock *sk); void tcp_send_delayed_ack(struct sock *sk); void tcp_send_loss_probe(struct sock *sk); |
ed66dfaf2
|
575 |
bool tcp_schedule_loss_probe(struct sock *sk, bool advancing_rto); |
cfea5a688
|
576 577 |
void tcp_skb_collapse_tstamp(struct sk_buff *skb, const struct sk_buff *next_skb); |
1da177e4c
|
578 |
|
a762a9800
|
579 |
/* tcp_input.c */ |
5c9f30236
|
580 |
void tcp_rearm_rto(struct sock *sk); |
0f1c28ae7
|
581 |
void tcp_synack_rtt_meas(struct sock *sk, struct request_sock *req); |
5c9f30236
|
582 |
void tcp_reset(struct sock *sk); |
4f41b1c58
|
583 |
void tcp_skb_mark_lost_uncond_verify(struct tcp_sock *tp, struct sk_buff *skb); |
e3e17b773
|
584 |
void tcp_fin(struct sock *sk); |
a762a9800
|
585 |
|
1da177e4c
|
586 |
/* tcp_timer.c */ |
5c9f30236
|
587 |
void tcp_init_xmit_timers(struct sock *); |
463c84b97
|
588 589 |
static inline void tcp_clear_xmit_timers(struct sock *sk) { |
73a6bab5a
|
590 |
if (hrtimer_try_to_cancel(&tcp_sk(sk)->pacing_timer) == 1) |
cf0dd2037
|
591 |
__sock_put(sk); |
73a6bab5a
|
592 |
|
5d9f4262b
|
593 594 |
if (hrtimer_try_to_cancel(&tcp_sk(sk)->compressed_ack_timer) == 1) __sock_put(sk); |
463c84b97
|
595 596 |
inet_csk_clear_xmit_timers(sk); } |
1da177e4c
|
597 |
|
5c9f30236
|
598 599 |
unsigned int tcp_sync_mss(struct sock *sk, u32 pmtu); unsigned int tcp_current_mss(struct sock *sk); |
0c54b85f2
|
600 601 602 603 |
/* Bound MSS / TSO packet size with the half of the window */ static inline int tcp_bound_to_half_wnd(struct tcp_sock *tp, int pktsize) { |
01f83d698
|
604 605 606 607 608 609 610 611 612 |
int cutoff; /* When peer uses tiny windows, there is no use in packetizing * to sub-MSS pieces for the sake of SWS or making sure there * are enough packets in the pipe for fast recovery. * * On the other hand, for extremely large MSS devices, handling * smaller than MSS windows in this way does make sense. */ |
2631b79f6
|
613 |
if (tp->max_window > TCP_MSS_DEFAULT) |
01f83d698
|
614 615 616 617 618 619 |
cutoff = (tp->max_window >> 1); else cutoff = tp->max_window; if (cutoff && pktsize > cutoff) return max_t(int, cutoff, 68U - tp->tcp_header_len); |
0c54b85f2
|
620 621 622 |
else return pktsize; } |
1da177e4c
|
623 |
|
17b085eac
|
624 |
/* tcp.c */ |
0df48c26d
|
625 |
void tcp_get_info(struct sock *, struct tcp_info *); |
1da177e4c
|
626 627 |
/* Read 'sendfile()'-style from a TCP socket */ |
5c9f30236
|
628 629 |
int tcp_read_sock(struct sock *sk, read_descriptor_t *desc, sk_read_actor_t recv_actor); |
1da177e4c
|
630 |
|
5c9f30236
|
631 |
void tcp_initialize_rcv_mss(struct sock *sk); |
1da177e4c
|
632 |
|
5c9f30236
|
633 634 635 |
int tcp_mtu_to_mss(struct sock *sk, int pmtu); int tcp_mss_to_mtu(struct sock *sk, int mss); void tcp_mtup_init(struct sock *sk); |
5d424d5a6
|
636 |
|
f1ecd5d9e
|
637 638 639 640 641 642 643 644 |
static inline void tcp_bound_rto(const struct sock *sk) { if (inet_csk(sk)->icsk_rto > TCP_RTO_MAX) inet_csk(sk)->icsk_rto = TCP_RTO_MAX; } static inline u32 __tcp_set_rto(const struct tcp_sock *tp) { |
740b0f184
|
645 |
return usecs_to_jiffies((tp->srtt_us >> 3) + tp->rttvar_us); |
f1ecd5d9e
|
646 |
} |
31770e34e
|
647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 |
static inline void __tcp_fast_path_on(struct tcp_sock *tp, u32 snd_wnd) { tp->pred_flags = htonl((tp->tcp_header_len << 26) | ntohl(TCP_FLAG_ACK) | snd_wnd); } static inline void tcp_fast_path_on(struct tcp_sock *tp) { __tcp_fast_path_on(tp, tp->snd_wnd >> tp->rx_opt.snd_wscale); } static inline void tcp_fast_path_check(struct sock *sk) { struct tcp_sock *tp = tcp_sk(sk); if (RB_EMPTY_ROOT(&tp->out_of_order_queue) && tp->rcv_wnd && atomic_read(&sk->sk_rmem_alloc) < sk->sk_rcvbuf && !tp->urg_data) tcp_fast_path_on(tp); } |
0c266898b
|
669 670 671 |
/* Compute the actual rto_min value */ static inline u32 tcp_rto_min(struct sock *sk) { |
cf533ea53
|
672 |
const struct dst_entry *dst = __sk_dst_get(sk); |
ca584ba07
|
673 |
u32 rto_min = inet_csk(sk)->icsk_rto_min; |
0c266898b
|
674 675 676 677 678 |
if (dst && dst_metric_locked(dst, RTAX_RTO_MIN)) rto_min = dst_metric_rtt(dst, RTAX_RTO_MIN); return rto_min; } |
740b0f184
|
679 680 681 682 |
static inline u32 tcp_rto_min_us(struct sock *sk) { return jiffies_to_usecs(tcp_rto_min(sk)); } |
81164413a
|
683 684 685 686 |
static inline bool tcp_ca_dst_locked(const struct dst_entry *dst) { return dst_metric_locked(dst, RTAX_CC_ALGO); } |
f67225839
|
687 688 689 |
/* Minimum RTT in usec. ~0 means not available. */ static inline u32 tcp_min_rtt(const struct tcp_sock *tp) { |
640338921
|
690 |
return minmax_get(&tp->rtt_min); |
f67225839
|
691 |
} |
1da177e4c
|
692 693 694 695 |
/* Compute the actual receive window we are currently advertising. * Rcv_nxt can be after the window if our peer push more data * than the offered window. */ |
40efc6fa1
|
696 |
static inline u32 tcp_receive_window(const struct tcp_sock *tp) |
1da177e4c
|
697 698 699 700 701 702 703 704 705 706 707 708 |
{ s32 win = tp->rcv_wup + tp->rcv_wnd - tp->rcv_nxt; if (win < 0) win = 0; return (u32) win; } /* Choose a new window, without checks for shrinking, and without * scaling applied to the result. The caller does these things * if necessary. This is a "raw" window selection. */ |
5c9f30236
|
709 |
u32 __tcp_select_window(struct sock *sk); |
1da177e4c
|
710 |
|
ee9952831
|
711 |
void tcp_send_window_probe(struct sock *sk); |
ec66eda82
|
712 713 714 715 716 |
/* TCP uses 32bit jiffies to save some space. * Note that this is different from tcp_time_stamp, which * historically has been the same until linux-4.13. */ #define tcp_jiffies32 ((u32)jiffies) |
9a568de48
|
717 718 719 720 721 722 723 724 725 |
/* * Deliver a 32bit value for TCP timestamp option (RFC 7323) * It is no longer tied to jiffies, but to 1 ms clock. * Note: double check if you want to use tcp_jiffies32 instead of this. */ #define TCP_TS_HZ 1000 static inline u64 tcp_clock_ns(void) { |
fb420d5d9
|
726 |
return ktime_get_ns(); |
9a568de48
|
727 728 729 730 731 732 733 734 735 736 737 738 |
} static inline u64 tcp_clock_us(void) { return div_u64(tcp_clock_ns(), NSEC_PER_USEC); } /* This should only be used in contexts where tp->tcp_mstamp is up to date */ static inline u32 tcp_time_stamp(const struct tcp_sock *tp) { return div_u64(tp->tcp_mstamp, USEC_PER_SEC / TCP_TS_HZ); } |
200ecef67
|
739 740 741 742 743 |
/* Convert a nsec timestamp into TCP TSval timestamp (ms based currently) */ static inline u32 tcp_ns_to_ts(u64 ns) { return div_u64(ns, NSEC_PER_SEC / TCP_TS_HZ); } |
9a568de48
|
744 745 746 |
/* Could use tcp_clock_us() / 1000, but this version uses a single divide */ static inline u32 tcp_time_stamp_raw(void) { |
200ecef67
|
747 |
return tcp_ns_to_ts(tcp_clock_ns()); |
9a568de48
|
748 |
} |
9799ccb0e
|
749 |
void tcp_mstamp_refresh(struct tcp_sock *tp); |
9a568de48
|
750 751 752 753 754 |
static inline u32 tcp_stamp_us_delta(u64 t1, u64 t0) { return max_t(s64, t1 - t0, 0); } |
1da177e4c
|
755 |
|
7faee5c0d
|
756 757 |
static inline u32 tcp_skb_timestamp(const struct sk_buff *skb) { |
200ecef67
|
758 |
return tcp_ns_to_ts(skb->skb_mstamp_ns); |
7faee5c0d
|
759 |
} |
2fd66ffba
|
760 761 762 |
/* provide the departure time in us unit */ static inline u64 tcp_skb_timestamp_us(const struct sk_buff *skb) { |
d3edd06ea
|
763 |
return div_u64(skb->skb_mstamp_ns, NSEC_PER_USEC); |
2fd66ffba
|
764 |
} |
7faee5c0d
|
765 |
|
a3433f35a
|
766 767 768 769 770 771 772 773 774 775 |
#define tcp_flag_byte(th) (((u_int8_t *)th)[13]) #define TCPHDR_FIN 0x01 #define TCPHDR_SYN 0x02 #define TCPHDR_RST 0x04 #define TCPHDR_PSH 0x08 #define TCPHDR_ACK 0x10 #define TCPHDR_URG 0x20 #define TCPHDR_ECE 0x40 #define TCPHDR_CWR 0x80 |
492135557
|
776 |
#define TCPHDR_SYN_ECN (TCPHDR_SYN | TCPHDR_ECE | TCPHDR_CWR) |
caa20d9ab
|
777 |
/* This is what the send packet queuing engine uses to pass |
f86586fa4
|
778 779 780 781 |
* TCP per-packet control information to the transmission code. * We also store the host-order sequence numbers in here too. * This is 44 bytes if IPV6 is enabled. * If this grows please adjust skbuff.h:skbuff->cb[xxx] size appropriately. |
1da177e4c
|
782 783 |
*/ struct tcp_skb_cb { |
1da177e4c
|
784 785 |
__u32 seq; /* Starting sequence number */ __u32 end_seq; /* SEQ + FIN + SYN + datalen */ |
cd7d8498c
|
786 787 788 789 |
union { /* Note : tcp_tw_isn is used in input path only * (isn chosen by tcp_timewait_state_process()) * |
f69ad292c
|
790 791 |
* tcp_gso_segs/size are used in write queue only, * cf tcp_skb_pcount()/tcp_skb_mss() |
cd7d8498c
|
792 793 |
*/ __u32 tcp_tw_isn; |
f69ad292c
|
794 795 796 797 |
struct { u16 tcp_gso_segs; u16 tcp_gso_size; }; |
cd7d8498c
|
798 |
}; |
4de075e04
|
799 |
__u8 tcp_flags; /* TCP header flags. (tcp[13]) */ |
f4f9f6e75
|
800 |
|
713bafea9
|
801 |
__u8 sacked; /* State flags for SACK. */ |
1da177e4c
|
802 803 804 805 |
#define TCPCB_SACKED_ACKED 0x01 /* SKB ACK'd by a SACK block */ #define TCPCB_SACKED_RETRANS 0x02 /* SKB retransmitted */ #define TCPCB_LOST 0x04 /* SKB is lost */ #define TCPCB_TAGBITS 0x07 /* All tag bits */ |
d3edd06ea
|
806 |
#define TCPCB_REPAIRED 0x10 /* SKB repaired (no skb_mstamp_ns) */ |
1da177e4c
|
807 |
#define TCPCB_EVER_RETRANS 0x80 /* Ever retransmitted frame */ |
9d186cac7
|
808 809 |
#define TCPCB_RETRANS (TCPCB_SACKED_RETRANS|TCPCB_EVER_RETRANS| \ TCPCB_REPAIRED) |
1da177e4c
|
810 |
|
f4f9f6e75
|
811 |
__u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */ |
6b084928b
|
812 |
__u8 txstamp_ack:1, /* Record TX timestamp for ack? */ |
c134ecb87
|
813 |
eor:1, /* Is skb MSG_EOR marked? */ |
98aaa913b
|
814 815 |
has_rxtstamp:1, /* SKB has a RX timestamp */ unused:5; |
1da177e4c
|
816 |
__u32 ack_seq; /* Sequence number ACK'd */ |
971f10eca
|
817 |
union { |
b75803d52
|
818 |
struct { |
b9f64820f
|
819 |
/* There is space for up to 24 bytes */ |
d7722e857
|
820 821 822 |
__u32 in_flight:30,/* Bytes in flight at transmit */ is_app_limited:1, /* cwnd not fully used? */ unused:1; |
b9f64820f
|
823 824 825 |
/* pkts S/ACKed so far upon tx of skb, incl retrans: */ __u32 delivered; /* start of send pipeline phase */ |
9a568de48
|
826 |
u64 first_tx_mstamp; |
b9f64820f
|
827 |
/* when we reached the "delivered" count */ |
9a568de48
|
828 |
u64 delivered_mstamp; |
b75803d52
|
829 830 831 |
} tx; /* only used for outgoing skbs */ union { struct inet_skb_parm h4; |
971f10eca
|
832 |
#if IS_ENABLED(CONFIG_IPV6) |
b75803d52
|
833 |
struct inet6_skb_parm h6; |
971f10eca
|
834 |
#endif |
b75803d52
|
835 |
} header; /* For incoming skbs */ |
34f79502b
|
836 |
struct { |
34f79502b
|
837 |
__u32 flags; |
e5cd3abcb
|
838 |
struct sock *sk_redir; |
8108a7751
|
839 |
void *data_end; |
34f79502b
|
840 |
} bpf; |
b75803d52
|
841 |
}; |
1da177e4c
|
842 843 844 |
}; #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0])) |
0ea488ff8
|
845 846 847 848 |
static inline void bpf_compute_data_end_sk_skb(struct sk_buff *skb) { TCP_SKB_CB(skb)->bpf.data_end = skb->data + skb_headlen(skb); } |
870c31513
|
849 |
|
604326b41
|
850 851 852 853 854 855 856 857 858 859 860 861 862 863 |
static inline bool tcp_skb_bpf_ingress(const struct sk_buff *skb) { return TCP_SKB_CB(skb)->bpf.flags & BPF_F_INGRESS; } static inline struct sock *tcp_skb_bpf_redirect_fetch(struct sk_buff *skb) { return TCP_SKB_CB(skb)->bpf.sk_redir; } static inline void tcp_skb_bpf_redirect_clear(struct sk_buff *skb) { TCP_SKB_CB(skb)->bpf.sk_redir = NULL; } |
9b9e2f250
|
864 |
extern const struct inet_connection_sock_af_ops ipv4_specific; |
815afe178
|
865 |
#if IS_ENABLED(CONFIG_IPV6) |
870c31513
|
866 867 868 869 870 |
/* This is the variant of inet6_iif() that must be used by TCP, * as TCP moves IP6CB into a different location in skb->cb[] */ static inline int tcp_v6_iif(const struct sk_buff *skb) { |
24b711edf
|
871 872 873 874 875 |
return TCP_SKB_CB(skb)->header.h6.iif; } static inline int tcp_v6_iif_l3_slave(const struct sk_buff *skb) { |
a04a480d4
|
876 |
bool l3_slave = ipv6_l3mdev_skb(TCP_SKB_CB(skb)->header.h6.flags); |
74b20582a
|
877 878 |
return l3_slave ? skb->skb_iif : TCP_SKB_CB(skb)->header.h6.iif; |
870c31513
|
879 |
} |
4297a0ef0
|
880 881 882 883 884 885 886 887 888 889 |
/* TCP_SKB_CB reference means this can not be used from early demux */ static inline int tcp_v6_sdif(const struct sk_buff *skb) { #if IS_ENABLED(CONFIG_NET_L3_MASTER_DEV) if (skb && ipv6_l3mdev_skb(TCP_SKB_CB(skb)->header.h6.flags)) return TCP_SKB_CB(skb)->header.h6.iif; #endif return 0; } |
dd2e0b86f
|
890 |
|
b03d2142b
|
891 |
extern const struct inet_connection_sock_af_ops ipv6_specific; |
dd2e0b86f
|
892 |
INDIRECT_CALLABLE_DECLARE(void tcp_v6_send_check(struct sock *sk, struct sk_buff *skb)); |
243600ee6
|
893 894 |
INDIRECT_CALLABLE_DECLARE(int tcp_v6_rcv(struct sk_buff *skb)); INDIRECT_CALLABLE_DECLARE(void tcp_v6_early_demux(struct sk_buff *skb)); |
dd2e0b86f
|
895 |
|
815afe178
|
896 |
#endif |
870c31513
|
897 |
|
3fa6f616a
|
898 899 900 901 902 903 904 905 906 |
/* TCP_SKB_CB reference means this can not be used from early demux */ static inline int tcp_v4_sdif(struct sk_buff *skb) { #if IS_ENABLED(CONFIG_NET_L3_MASTER_DEV) if (skb && ipv4_l3mdev_skb(TCP_SKB_CB(skb)->header.h4.flags)) return TCP_SKB_CB(skb)->header.h4.iif; #endif return 0; } |
1da177e4c
|
907 908 |
/* Due to TSO, an SKB can be composed of multiple actual * packets. To keep these tracked properly, we use this. |
bd14b1b2e
|
909 |
*/ |
1da177e4c
|
910 |
static inline int tcp_skb_pcount(const struct sk_buff *skb) |
bd14b1b2e
|
911 |
{ |
cd7d8498c
|
912 913 |
return TCP_SKB_CB(skb)->tcp_gso_segs; } |
bd14b1b2e
|
914 |
|
cd7d8498c
|
915 916 917 |
static inline void tcp_skb_pcount_set(struct sk_buff *skb, int segs) { TCP_SKB_CB(skb)->tcp_gso_segs = segs; |
bd14b1b2e
|
918 |
} |
cd7d8498c
|
919 |
static inline void tcp_skb_pcount_add(struct sk_buff *skb, int segs) |
1da177e4c
|
920 |
{ |
cd7d8498c
|
921 |
TCP_SKB_CB(skb)->tcp_gso_segs += segs; |
1da177e4c
|
922 |
} |
f69ad292c
|
923 |
/* This is valid iff skb is in write queue and tcp_skb_pcount() > 1. */ |
1da177e4c
|
924 925 |
static inline int tcp_skb_mss(const struct sk_buff *skb) { |
f69ad292c
|
926 |
return TCP_SKB_CB(skb)->tcp_gso_size; |
1da177e4c
|
927 |
} |
c134ecb87
|
928 929 930 931 |
static inline bool tcp_skb_can_collapse_to(const struct sk_buff *skb) { return likely(!TCP_SKB_CB(skb)->eor); } |
857124841
|
932 933 934 935 936 937 |
static inline bool tcp_skb_can_collapse(const struct sk_buff *to, const struct sk_buff *from) { return likely(tcp_skb_can_collapse_to(to) && mptcp_skb_can_collapse(to, from)); } |
317a76f9a
|
938 939 940 941 942 |
/* Events passed to congestion control interface */ enum tcp_ca_event { CA_EVENT_TX_START, /* first transmit when no packets in flight */ CA_EVENT_CWND_RESTART, /* congestion window restart */ CA_EVENT_COMPLETE_CWR, /* end of congestion recovery */ |
317a76f9a
|
943 |
CA_EVENT_LOSS, /* loss timeout */ |
9890092e4
|
944 945 |
CA_EVENT_ECN_NO_CE, /* ECT set, but not CE marked */ CA_EVENT_ECN_IS_CE, /* received CE marked IP packet */ |
7354c8c38
|
946 |
}; |
9890092e4
|
947 |
/* Information about inbound ACK, passed to cong_ops->in_ack_event() */ |
7354c8c38
|
948 |
enum tcp_ca_ack_event_flags { |
c1d2b4c3e
|
949 950 951 |
CA_ACK_SLOWPATH = (1 << 0), /* In slow path processing */ CA_ACK_WIN_UPDATE = (1 << 1), /* ACK updated window */ CA_ACK_ECE = (1 << 2), /* ECE bit is set on ack */ |
317a76f9a
|
952 953 954 955 956 957 |
}; /* * Interface for adding new TCP congestion control handlers */ #define TCP_CA_NAME_MAX 16 |
3ff825b28
|
958 959 |
#define TCP_CA_MAX 128 #define TCP_CA_BUF_MAX (TCP_CA_NAME_MAX*TCP_CA_MAX) |
c5c6a8ab4
|
960 |
#define TCP_CA_UNSPEC 0 |
30e502a34
|
961 |
/* Algorithm can be set on socket without CAP_NET_ADMIN privileges */ |
164891aad
|
962 |
#define TCP_CONG_NON_RESTRICTED 0x1 |
30e502a34
|
963 964 |
/* Requires ECN/ECT set on all packets */ #define TCP_CONG_NEEDS_ECN 0x2 |
0baf26b0f
|
965 |
#define TCP_CONG_MASK (TCP_CONG_NON_RESTRICTED | TCP_CONG_NEEDS_ECN) |
164891aad
|
966 |
|
64f40ff5b
|
967 |
union tcp_cc_info; |
756ee1729
|
968 969 970 |
struct ack_sample { u32 pkts_acked; s32 rtt_us; |
6f094b9ec
|
971 |
u32 in_flight; |
756ee1729
|
972 |
}; |
b9f64820f
|
973 974 975 976 977 978 979 980 981 |
/* A rate sample measures the number of (original/retransmitted) data * packets delivered "delivered" over an interval of time "interval_us". * The tcp_rate.c code fills in the rate sample, and congestion * control modules that define a cong_control function to run at the end * of ACK processing can optionally chose to consult this sample when * setting cwnd and pacing rate. * A sample is invalid if "delivered" or "interval_us" is negative. */ struct rate_sample { |
9a568de48
|
982 |
u64 prior_mstamp; /* starting timestamp for interval */ |
b9f64820f
|
983 984 985 |
u32 prior_delivered; /* tp->delivered at "prior_mstamp" */ s32 delivered; /* number of packets delivered over interval */ long interval_us; /* time for tp->delivered to incr "delivered" */ |
4929c9428
|
986 987 |
u32 snd_interval_us; /* snd interval for delivered packets */ u32 rcv_interval_us; /* rcv interval for delivered packets */ |
b9f64820f
|
988 989 990 991 |
long rtt_us; /* RTT of last (S)ACKed packet (or -1) */ int losses; /* number of packets marked lost upon ACK */ u32 acked_sacked; /* number of packets newly (S)ACKed upon ACK */ u32 prior_in_flight; /* in flight before this ACK */ |
d7722e857
|
992 |
bool is_app_limited; /* is sample from packet with bubble in pipe? */ |
b9f64820f
|
993 |
bool is_retrans; /* is sample from retransmission? */ |
e42866031
|
994 |
bool is_ack_delayed; /* is this (likely) a delayed ACK? */ |
b9f64820f
|
995 |
}; |
317a76f9a
|
996 997 |
struct tcp_congestion_ops { struct list_head list; |
c5c6a8ab4
|
998 999 |
u32 key; u32 flags; |
317a76f9a
|
1000 1001 |
/* initialize private data (optional) */ |
6687e988d
|
1002 |
void (*init)(struct sock *sk); |
317a76f9a
|
1003 |
/* cleanup private data (optional) */ |
6687e988d
|
1004 |
void (*release)(struct sock *sk); |
317a76f9a
|
1005 1006 |
/* return slow start threshold (required) */ |
6687e988d
|
1007 |
u32 (*ssthresh)(struct sock *sk); |
317a76f9a
|
1008 |
/* do new cwnd calculation (required) */ |
249015515
|
1009 |
void (*cong_avoid)(struct sock *sk, u32 ack, u32 acked); |
317a76f9a
|
1010 |
/* call before changing ca_state (optional) */ |
6687e988d
|
1011 |
void (*set_state)(struct sock *sk, u8 new_state); |
317a76f9a
|
1012 |
/* call when cwnd event occurs (optional) */ |
6687e988d
|
1013 |
void (*cwnd_event)(struct sock *sk, enum tcp_ca_event ev); |
7354c8c38
|
1014 1015 |
/* call when ack arrives (optional) */ void (*in_ack_event)(struct sock *sk, u32 flags); |
1e0ce2a1e
|
1016 |
/* new value of cwnd after loss (required) */ |
6687e988d
|
1017 |
u32 (*undo_cwnd)(struct sock *sk); |
317a76f9a
|
1018 |
/* hook for packet ack accounting (optional) */ |
756ee1729
|
1019 |
void (*pkts_acked)(struct sock *sk, const struct ack_sample *sample); |
dcb8c9b43
|
1020 1021 |
/* override sysctl_tcp_min_tso_segs */ u32 (*min_tso_segs)(struct sock *sk); |
77bfc174c
|
1022 1023 |
/* returns the multiplier used in tcp_sndbuf_expand (optional) */ u32 (*sndbuf_expand)(struct sock *sk); |
c0402760f
|
1024 1025 1026 1027 |
/* call when packets are delivered to update cwnd and pacing rate, * after all the ca_state processing. (optional) */ void (*cong_control)(struct sock *sk, const struct rate_sample *rs); |
73c1f4a03
|
1028 |
/* get info for inet_diag (optional) */ |
64f40ff5b
|
1029 1030 |
size_t (*get_info)(struct sock *sk, u32 ext, int *attr, union tcp_cc_info *info); |
317a76f9a
|
1031 1032 1033 1034 |
char name[TCP_CA_NAME_MAX]; struct module *owner; }; |
5c9f30236
|
1035 1036 |
int tcp_register_congestion_control(struct tcp_congestion_ops *type); void tcp_unregister_congestion_control(struct tcp_congestion_ops *type); |
317a76f9a
|
1037 |
|
55d8694fa
|
1038 |
void tcp_assign_congestion_control(struct sock *sk); |
5c9f30236
|
1039 1040 |
void tcp_init_congestion_control(struct sock *sk); void tcp_cleanup_congestion_control(struct sock *sk); |
6670e1524
|
1041 1042 |
int tcp_set_default_congestion_control(struct net *net, const char *name); void tcp_get_default_congestion_control(struct net *net, char *name); |
5c9f30236
|
1043 1044 1045 |
void tcp_get_available_congestion_control(char *buf, size_t len); void tcp_get_allowed_congestion_control(char *buf, size_t len); int tcp_set_allowed_congestion_control(char *allowed); |
8d650cded
|
1046 |
int tcp_set_congestion_control(struct sock *sk, const char *name, bool load, |
29a949325
|
1047 |
bool cap_net_admin); |
e73ebb088
|
1048 1049 |
u32 tcp_slow_start(struct tcp_sock *tp, u32 acked); void tcp_cong_avoid_ai(struct tcp_sock *tp, u32 w, u32 acked); |
317a76f9a
|
1050 |
|
5c9f30236
|
1051 |
u32 tcp_reno_ssthresh(struct sock *sk); |
e97991832
|
1052 |
u32 tcp_reno_undo_cwnd(struct sock *sk); |
249015515
|
1053 |
void tcp_reno_cong_avoid(struct sock *sk, u32 ack, u32 acked); |
a8acfbac7
|
1054 |
extern struct tcp_congestion_ops tcp_reno; |
317a76f9a
|
1055 |
|
0baf26b0f
|
1056 |
struct tcp_congestion_ops *tcp_ca_find(const char *name); |
c5c6a8ab4
|
1057 |
struct tcp_congestion_ops *tcp_ca_find_key(u32 key); |
6670e1524
|
1058 |
u32 tcp_ca_get_key_by_name(struct net *net, const char *name, bool *ecn_ca); |
ea6976399
|
1059 |
#ifdef CONFIG_INET |
c5c6a8ab4
|
1060 |
char *tcp_ca_get_name_by_key(u32 key, char *buffer); |
ea6976399
|
1061 1062 1063 1064 1065 1066 |
#else static inline char *tcp_ca_get_name_by_key(u32 key, char *buffer) { return NULL; } #endif |
c5c6a8ab4
|
1067 |
|
30e502a34
|
1068 1069 1070 1071 1072 1073 |
static inline bool tcp_ca_needs_ecn(const struct sock *sk) { const struct inet_connection_sock *icsk = inet_csk(sk); return icsk->icsk_ca_ops->flags & TCP_CONG_NEEDS_ECN; } |
6687e988d
|
1074 |
static inline void tcp_set_ca_state(struct sock *sk, const u8 ca_state) |
317a76f9a
|
1075 |
{ |
6687e988d
|
1076 1077 1078 1079 1080 |
struct inet_connection_sock *icsk = inet_csk(sk); if (icsk->icsk_ca_ops->set_state) icsk->icsk_ca_ops->set_state(sk, ca_state); icsk->icsk_ca_state = ca_state; |
317a76f9a
|
1081 |
} |
6687e988d
|
1082 |
static inline void tcp_ca_event(struct sock *sk, const enum tcp_ca_event event) |
317a76f9a
|
1083 |
{ |
6687e988d
|
1084 1085 1086 1087 |
const struct inet_connection_sock *icsk = inet_csk(sk); if (icsk->icsk_ca_ops->cwnd_event) icsk->icsk_ca_ops->cwnd_event(sk, event); |
317a76f9a
|
1088 |
} |
b9f64820f
|
1089 1090 1091 1092 1093 |
/* From tcp_rate.c */ void tcp_rate_skb_sent(struct sock *sk, struct sk_buff *skb); void tcp_rate_skb_delivered(struct sock *sk, struct sk_buff *skb, struct rate_sample *rs); void tcp_rate_gen(struct sock *sk, u32 delivered, u32 lost, |
d4761754b
|
1094 |
bool is_sack_reneg, struct rate_sample *rs); |
d7722e857
|
1095 |
void tcp_rate_check_app_limited(struct sock *sk); |
b9f64820f
|
1096 |
|
e60402d0a
|
1097 1098 1099 1100 1101 1102 |
/* These functions determine how the current flow behaves in respect of SACK * handling. SACK is negotiated with the peer, and therefore it can vary * between different flows. * * tcp_is_sack - SACK enabled * tcp_is_reno - No SACK |
e60402d0a
|
1103 1104 1105 |
*/ static inline int tcp_is_sack(const struct tcp_sock *tp) { |
ebeef4bcc
|
1106 |
return likely(tp->rx_opt.sack_ok); |
e60402d0a
|
1107 |
} |
a2a385d62
|
1108 |
static inline bool tcp_is_reno(const struct tcp_sock *tp) |
e60402d0a
|
1109 1110 1111 |
{ return !tcp_is_sack(tp); } |
83ae40885
|
1112 1113 1114 1115 |
static inline unsigned int tcp_left_out(const struct tcp_sock *tp) { return tp->sacked_out + tp->lost_out; } |
1da177e4c
|
1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 |
/* This determines how many packets are "in the network" to the best * of our knowledge. In many cases it is conservative, but where * detailed information is available from the receiver (via SACK * blocks etc.) we can make more aggressive calculations. * * Use this for decisions involving congestion control, use just * tp->packets_out to determine if the send queue is empty or not. * * Read this equation as: * * "Packets sent once on transmission queue" MINUS * "Packets left network, but not honestly ACKed yet" PLUS * "Packets fast retransmitted" */ |
40efc6fa1
|
1130 |
static inline unsigned int tcp_packets_in_flight(const struct tcp_sock *tp) |
1da177e4c
|
1131 |
{ |
83ae40885
|
1132 |
return tp->packets_out - tcp_left_out(tp) + tp->retrans_out; |
1da177e4c
|
1133 |
} |
0b6a05c1d
|
1134 |
#define TCP_INFINITE_SSTHRESH 0x7fffffff |
071d5080e
|
1135 1136 |
static inline bool tcp_in_slow_start(const struct tcp_sock *tp) { |
76174004a
|
1137 |
return tp->snd_cwnd < tp->snd_ssthresh; |
071d5080e
|
1138 |
} |
0b6a05c1d
|
1139 1140 1141 1142 |
static inline bool tcp_in_initial_slowstart(const struct tcp_sock *tp) { return tp->snd_ssthresh >= TCP_INFINITE_SSTHRESH; } |
684bad110
|
1143 1144 1145 1146 1147 |
static inline bool tcp_in_cwnd_reduction(const struct sock *sk) { return (TCPF_CA_CWR | TCPF_CA_Recovery) & (1 << inet_csk(sk)->icsk_ca_state); } |
1da177e4c
|
1148 |
/* If cwnd > ssthresh, we may raise ssthresh to be half-way to cwnd. |
684bad110
|
1149 |
* The exception is cwnd reduction phase, when cwnd is decreasing towards |
1da177e4c
|
1150 1151 |
* ssthresh. */ |
6687e988d
|
1152 |
static inline __u32 tcp_current_ssthresh(const struct sock *sk) |
1da177e4c
|
1153 |
{ |
6687e988d
|
1154 |
const struct tcp_sock *tp = tcp_sk(sk); |
cf533ea53
|
1155 |
|
684bad110
|
1156 |
if (tcp_in_cwnd_reduction(sk)) |
1da177e4c
|
1157 1158 1159 1160 1161 1162 |
return tp->snd_ssthresh; else return max(tp->snd_ssthresh, ((tp->snd_cwnd >> 1) + (tp->snd_cwnd >> 2))); } |
b9c4595bc
|
1163 1164 |
/* Use define here intentionally to get WARN_ON location shown at the caller */ #define tcp_verify_left_out(tp) WARN_ON(tcp_left_out(tp) > tp->packets_out) |
1da177e4c
|
1165 |
|
5ee2c941b
|
1166 |
void tcp_enter_cwr(struct sock *sk); |
5c9f30236
|
1167 |
__u32 tcp_init_cwnd(const struct tcp_sock *tp, const struct dst_entry *dst); |
1da177e4c
|
1168 |
|
6b5a5c0db
|
1169 1170 1171 1172 1173 1174 1175 |
/* The maximum number of MSS of available cwnd for which TSO defers * sending if not using sysctl_tcp_tso_win_divisor. */ static inline __u32 tcp_max_tso_deferred_mss(const struct tcp_sock *tp) { return 3; } |
90840defa
|
1176 1177 1178 1179 1180 |
/* Returns end sequence number of the receiver's advertised window */ static inline u32 tcp_wnd_end(const struct tcp_sock *tp) { return tp->snd_una + tp->snd_wnd; } |
e114a710a
|
1181 1182 1183 |
/* We follow the spirit of RFC2861 to validate cwnd but implement a more * flexible approach. The RFC suggests cwnd should not be raised unless |
ca8a22634
|
1184 1185 1186 |
* it was fully used previously. And that's exactly what we do in * congestion avoidance mode. But in slow start we allow cwnd to grow * as long as the application has used half the cwnd. |
e114a710a
|
1187 1188 1189 1190 1191 1192 1193 |
* Example : * cwnd is 10 (IW10), but application sends 9 frames. * We allow cwnd to reach 18 when all frames are ACKed. * This check is safe because it's as aggressive as slow start which already * risks 100% overshoot. The advantage is that we discourage application to * either send more filler packets or data to artificially blow up the cwnd * usage, and allow application-limited process to probe bw more aggressively. |
e114a710a
|
1194 |
*/ |
249015515
|
1195 |
static inline bool tcp_is_cwnd_limited(const struct sock *sk) |
e114a710a
|
1196 1197 |
{ const struct tcp_sock *tp = tcp_sk(sk); |
ca8a22634
|
1198 |
/* If in slow start, ensure cwnd grows to twice what was ACKed. */ |
071d5080e
|
1199 |
if (tcp_in_slow_start(tp)) |
ca8a22634
|
1200 1201 1202 |
return tp->snd_cwnd < 2 * tp->max_packets_out; return tp->is_cwnd_limited; |
e114a710a
|
1203 |
} |
f4805eded
|
1204 |
|
cadefe5f5
|
1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 |
/* BBR congestion control needs pacing. * Same remark for SO_MAX_PACING_RATE. * sch_fq packet scheduler is efficiently handling pacing, * but is not always installed/used. * Return true if TCP stack should pace packets itself. */ static inline bool tcp_needs_internal_pacing(const struct sock *sk) { return smp_load_acquire(&sk->sk_pacing_status) == SK_PACING_NEEDED; } |
8dc242ad6
|
1215 1216 |
/* Estimates in how many jiffies next packet for this flow can be sent. * Scheduling a retransmit timer too early would be silly. |
3f80e08f4
|
1217 |
*/ |
8dc242ad6
|
1218 |
static inline unsigned long tcp_pacing_delay(const struct sock *sk) |
3f80e08f4
|
1219 |
{ |
8dc242ad6
|
1220 |
s64 delay = tcp_sk(sk)->tcp_wstamp_ns - tcp_sk(sk)->tcp_clock_cache; |
3f80e08f4
|
1221 |
|
8dc242ad6
|
1222 |
return delay > 0 ? nsecs_to_jiffies(delay) : 0; |
3f80e08f4
|
1223 1224 1225 1226 1227 |
} static inline void tcp_reset_xmit_timer(struct sock *sk, const int what, unsigned long when, |
8dc242ad6
|
1228 |
const unsigned long max_when) |
3f80e08f4
|
1229 |
{ |
8dc242ad6
|
1230 |
inet_csk_reset_xmit_timer(sk, what, when + tcp_pacing_delay(sk), |
3f80e08f4
|
1231 1232 |
max_when); } |
21c8fe991
|
1233 |
/* Something is really bad, we could not queue an additional packet, |
3f80e08f4
|
1234 |
* because qdisc is full or receiver sent a 0 window, or we are paced. |
21c8fe991
|
1235 1236 1237 1238 1239 |
* We do not want to add fuel to the fire, or abort too early, * so make sure the timer we arm now is at least 200ms in the future, * regardless of current icsk_rto value (as it could be ~2ms) */ static inline unsigned long tcp_probe0_base(const struct sock *sk) |
1da177e4c
|
1240 |
{ |
21c8fe991
|
1241 1242 |
return max_t(unsigned long, inet_csk(sk)->icsk_rto, TCP_RTO_MIN); } |
9e412ba76
|
1243 |
|
21c8fe991
|
1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 |
/* Variant of inet_csk_rto_backoff() used for zero window probes */ static inline unsigned long tcp_probe0_when(const struct sock *sk, unsigned long max_when) { u64 when = (u64)tcp_probe0_base(sk) << inet_csk(sk)->icsk_backoff; return (unsigned long)min_t(u64, when, max_when); } static inline void tcp_check_probe_timer(struct sock *sk) { if (!tcp_sk(sk)->packets_out && !inet_csk(sk)->icsk_pending) |
3f80e08f4
|
1256 |
tcp_reset_xmit_timer(sk, ICSK_TIME_PROBE0, |
8dc242ad6
|
1257 |
tcp_probe0_base(sk), TCP_RTO_MAX); |
1da177e4c
|
1258 |
} |
ee7537b63
|
1259 |
static inline void tcp_init_wl(struct tcp_sock *tp, u32 seq) |
1da177e4c
|
1260 1261 1262 |
{ tp->snd_wl1 = seq; } |
ee7537b63
|
1263 |
static inline void tcp_update_wl(struct tcp_sock *tp, u32 seq) |
1da177e4c
|
1264 1265 1266 |
{ tp->snd_wl1 = seq; } |
1da177e4c
|
1267 1268 1269 |
/* * Calculate(/check) TCP checksum */ |
ba7808eac
|
1270 1271 |
static inline __sum16 tcp_v4_check(int len, __be32 saddr, __be32 daddr, __wsum base) |
1da177e4c
|
1272 |
{ |
0b13c9bb9
|
1273 |
return csum_tcpudp_magic(saddr, daddr, len, IPPROTO_TCP, base); |
1da177e4c
|
1274 |
} |
a2a385d62
|
1275 |
static inline bool tcp_checksum_complete(struct sk_buff *skb) |
1da177e4c
|
1276 |
{ |
604763722
|
1277 |
return !skb_csum_unnecessary(skb) && |
6ab6dfa6b
|
1278 |
__skb_checksum_complete(skb); |
1da177e4c
|
1279 |
} |
c9c332125
|
1280 |
bool tcp_add_backlog(struct sock *sk, struct sk_buff *skb); |
ac6e78007
|
1281 |
int tcp_filter(struct sock *sk, struct sk_buff *skb); |
5c9f30236
|
1282 |
void tcp_set_state(struct sock *sk, int state); |
5c9f30236
|
1283 |
void tcp_done(struct sock *sk); |
c1e64e298
|
1284 |
int tcp_abort(struct sock *sk, int err); |
40efc6fa1
|
1285 |
static inline void tcp_sack_reset(struct tcp_options_received *rx_opt) |
1da177e4c
|
1286 1287 |
{ rx_opt->dsack = 0; |
1da177e4c
|
1288 1289 |
rx_opt->num_sacks = 0; } |
6f021c62d
|
1290 1291 1292 1293 |
void tcp_cwnd_restart(struct sock *sk, s32 delta); static inline void tcp_slow_start_after_idle_check(struct sock *sk) { |
1b1fc3fdd
|
1294 |
const struct tcp_congestion_ops *ca_ops = inet_csk(sk)->icsk_ca_ops; |
6f021c62d
|
1295 1296 |
struct tcp_sock *tp = tcp_sk(sk); s32 delta; |
b510f0d23
|
1297 |
if (!sock_net(sk)->ipv4.sysctl_tcp_slow_start_after_idle || tp->packets_out || |
1b1fc3fdd
|
1298 |
ca_ops->cong_control) |
6f021c62d
|
1299 |
return; |
d635fbe27
|
1300 |
delta = tcp_jiffies32 - tp->lsndtime; |
6f021c62d
|
1301 1302 1303 |
if (delta > inet_csk(sk)->icsk_rto) tcp_cwnd_restart(sk, delta); } |
85f16525a
|
1304 |
|
1da177e4c
|
1305 |
/* Determine a window scaling and initial window to offer. */ |
ceef9ab6b
|
1306 1307 |
void tcp_select_initial_window(const struct sock *sk, int __space, __u32 mss, __u32 *rcv_wnd, |
5c9f30236
|
1308 1309 |
__u32 *window_clamp, int wscale_ok, __u8 *rcv_wscale, __u32 init_rcv_wnd); |
1da177e4c
|
1310 |
|
94f0893e0
|
1311 |
static inline int tcp_win_from_space(const struct sock *sk, int space) |
1da177e4c
|
1312 |
{ |
94f0893e0
|
1313 |
int tcp_adv_win_scale = sock_net(sk)->ipv4.sysctl_tcp_adv_win_scale; |
c48367427
|
1314 1315 1316 1317 |
return tcp_adv_win_scale <= 0 ? (space>>(-tcp_adv_win_scale)) : space - (space>>tcp_adv_win_scale); |
1da177e4c
|
1318 |
} |
105970f60
|
1319 |
/* Note: caller must be prepared to deal with negative returns */ |
1da177e4c
|
1320 1321 |
static inline int tcp_space(const struct sock *sk) { |
ebb3b78db
|
1322 |
return tcp_win_from_space(sk, READ_ONCE(sk->sk_rcvbuf) - |
70c265584
|
1323 |
READ_ONCE(sk->sk_backlog.len) - |
1da177e4c
|
1324 |
atomic_read(&sk->sk_rmem_alloc)); |
105970f60
|
1325 |
} |
1da177e4c
|
1326 1327 1328 |
static inline int tcp_full_space(const struct sock *sk) { |
ebb3b78db
|
1329 |
return tcp_win_from_space(sk, READ_ONCE(sk->sk_rcvbuf)); |
1da177e4c
|
1330 |
} |
c76c69565
|
1331 |
void tcp_cleanup_rbuf(struct sock *sk, int copied); |
24adbc167
|
1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 |
/* We provision sk_rcvbuf around 200% of sk_rcvlowat. * If 87.5 % (7/8) of the space has been consumed, we want to override * SO_RCVLOWAT constraint, since we are receiving skbs with too small * len/truesize ratio. */ static inline bool tcp_rmem_pressure(const struct sock *sk) { int rcvbuf = READ_ONCE(sk->sk_rcvbuf); int threshold = rcvbuf - (rcvbuf >> 3); return atomic_read(&sk->sk_rmem_alloc) > threshold; } |
843f4a55e
|
1344 |
extern void tcp_openreq_init_rwin(struct request_sock *req, |
b1964b5fc
|
1345 1346 |
const struct sock *sk_listener, const struct dst_entry *dst); |
843f4a55e
|
1347 |
|
5c9f30236
|
1348 |
void tcp_enter_memory_pressure(struct sock *sk); |
060447511
|
1349 |
void tcp_leave_memory_pressure(struct sock *sk); |
1da177e4c
|
1350 |
|
1da177e4c
|
1351 1352 |
static inline int keepalive_intvl_when(const struct tcp_sock *tp) { |
b840d15d3
|
1353 1354 1355 |
struct net *net = sock_net((struct sock *)tp); return tp->keepalive_intvl ? : net->ipv4.sysctl_tcp_keepalive_intvl; |
1da177e4c
|
1356 1357 1358 1359 |
} static inline int keepalive_time_when(const struct tcp_sock *tp) { |
13b287e8d
|
1360 1361 1362 |
struct net *net = sock_net((struct sock *)tp); return tp->keepalive_time ? : net->ipv4.sysctl_tcp_keepalive_time; |
1da177e4c
|
1363 |
} |
df19a6267
|
1364 1365 |
static inline int keepalive_probes(const struct tcp_sock *tp) { |
9bd6861bd
|
1366 1367 1368 |
struct net *net = sock_net((struct sock *)tp); return tp->keepalive_probes ? : net->ipv4.sysctl_tcp_keepalive_probes; |
df19a6267
|
1369 |
} |
6c37e5de4
|
1370 1371 1372 |
static inline u32 keepalive_time_elapsed(const struct tcp_sock *tp) { const struct inet_connection_sock *icsk = &tp->inet_conn; |
70eabf0e1
|
1373 1374 |
return min_t(u32, tcp_jiffies32 - icsk->icsk_ack.lrcvtime, tcp_jiffies32 - tp->rcv_tstamp); |
6c37e5de4
|
1375 |
} |
463c84b97
|
1376 |
static inline int tcp_fin_time(const struct sock *sk) |
1da177e4c
|
1377 |
{ |
1e579caa1
|
1378 |
int fin_timeout = tcp_sk(sk)->linger2 ? : sock_net(sk)->ipv4.sysctl_tcp_fin_timeout; |
463c84b97
|
1379 |
const int rto = inet_csk(sk)->icsk_rto; |
1da177e4c
|
1380 |
|
463c84b97
|
1381 1382 |
if (fin_timeout < (rto << 2) - (rto >> 1)) fin_timeout = (rto << 2) - (rto >> 1); |
1da177e4c
|
1383 1384 1385 |
return fin_timeout; } |
a2a385d62
|
1386 1387 |
static inline bool tcp_paws_check(const struct tcp_options_received *rx_opt, int paws_win) |
1da177e4c
|
1388 |
{ |
c887e6d2d
|
1389 |
if ((s32)(rx_opt->ts_recent - rx_opt->rcv_tsval) <= paws_win) |
a2a385d62
|
1390 |
return true; |
cca9bab1b
|
1391 1392 |
if (unlikely(!time_before32(ktime_get_seconds(), rx_opt->ts_recent_stamp + TCP_PAWS_24DAYS))) |
a2a385d62
|
1393 |
return true; |
bc2ce894e
|
1394 1395 1396 1397 1398 1399 |
/* * Some OSes send SYN and SYNACK messages with tsval=0 tsecr=0, * then following tcp messages have valid values. Ignore 0 value, * or else 'negative' tsval might forbid us to accept their packets. */ if (!rx_opt->ts_recent) |
a2a385d62
|
1400 1401 |
return true; return false; |
c887e6d2d
|
1402 |
} |
a2a385d62
|
1403 1404 |
static inline bool tcp_paws_reject(const struct tcp_options_received *rx_opt, int rst) |
c887e6d2d
|
1405 1406 |
{ if (tcp_paws_check(rx_opt, 0)) |
a2a385d62
|
1407 |
return false; |
1da177e4c
|
1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 |
/* RST segments are not recommended to carry timestamp, and, if they do, it is recommended to ignore PAWS because "their cleanup function should take precedence over timestamps." Certainly, it is mistake. It is necessary to understand the reasons of this constraint to relax it: if peer reboots, clock may go out-of-sync and half-open connections will not be reset. Actually, the problem would be not existing if all the implementations followed draft about maintaining clock via reboots. Linux-2.2 DOES NOT! However, we can relax time bounds for RST segments to MSL. */ |
cca9bab1b
|
1421 1422 |
if (rst && !time_before32(ktime_get_seconds(), rx_opt->ts_recent_stamp + TCP_PAWS_MSL)) |
a2a385d62
|
1423 1424 |
return false; return true; |
1da177e4c
|
1425 |
} |
7970ddc8f
|
1426 1427 |
bool tcp_oow_rate_limited(struct net *net, const struct sk_buff *skb, int mib_idx, u32 *last_oow_ack_time); |
032ee4236
|
1428 |
|
a9c19329e
|
1429 |
static inline void tcp_mib_init(struct net *net) |
1da177e4c
|
1430 1431 |
{ /* See RFC 2012 */ |
6aef70a85
|
1432 1433 1434 1435 |
TCP_ADD_STATS(net, TCP_MIB_RTOALGORITHM, 1); TCP_ADD_STATS(net, TCP_MIB_RTOMIN, TCP_RTO_MIN*1000/HZ); TCP_ADD_STATS(net, TCP_MIB_RTOMAX, TCP_RTO_MAX*1000/HZ); TCP_ADD_STATS(net, TCP_MIB_MAXCONN, -1); |
1da177e4c
|
1436 |
} |
5af4ec236
|
1437 |
/* from STCP */ |
ef9da47c7
|
1438 |
static inline void tcp_clear_retrans_hints_partial(struct tcp_sock *tp) |
0800f1702
|
1439 |
{ |
6a438bbe6
|
1440 |
tp->lost_skb_hint = NULL; |
ef9da47c7
|
1441 1442 1443 1444 1445 |
} static inline void tcp_clear_all_retrans_hints(struct tcp_sock *tp) { tcp_clear_retrans_hints_partial(tp); |
6a438bbe6
|
1446 |
tp->retransmit_skb_hint = NULL; |
b76892051
|
1447 |
} |
a915da9b6
|
1448 1449 1450 1451 1452 1453 |
union tcp_md5_addr { struct in_addr a4; #if IS_ENABLED(CONFIG_IPV6) struct in6_addr a6; #endif }; |
cfb6eeb4c
|
1454 1455 |
/* - key database */ struct tcp_md5sig_key { |
a915da9b6
|
1456 |
struct hlist_node node; |
cfb6eeb4c
|
1457 |
u8 keylen; |
a915da9b6
|
1458 |
u8 family; /* AF_INET or AF_INET6 */ |
6797318e6
|
1459 |
u8 prefixlen; |
dea53bb80
|
1460 1461 |
union tcp_md5_addr addr; int l3index; /* set if key added with L3 scope */ |
a915da9b6
|
1462 1463 |
u8 key[TCP_MD5SIG_MAXKEYLEN]; struct rcu_head rcu; |
cfb6eeb4c
|
1464 1465 1466 1467 |
}; /* - sock block */ struct tcp_md5sig_info { |
a915da9b6
|
1468 |
struct hlist_head head; |
a8afca032
|
1469 |
struct rcu_head rcu; |
cfb6eeb4c
|
1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 |
}; /* - pseudo header */ struct tcp4_pseudohdr { __be32 saddr; __be32 daddr; __u8 pad; __u8 protocol; __be16 len; }; struct tcp6_pseudohdr { struct in6_addr saddr; struct in6_addr daddr; __be32 len; __be32 protocol; /* including padding */ }; union tcp_md5sum_block { struct tcp4_pseudohdr ip4; |
dfd56b8b3
|
1490 |
#if IS_ENABLED(CONFIG_IPV6) |
cfb6eeb4c
|
1491 1492 1493 1494 1495 1496 |
struct tcp6_pseudohdr ip6; #endif }; /* - pool: digest algorithm, hash description and scratch buffer */ struct tcp_md5sig_pool { |
cf80e0e47
|
1497 |
struct ahash_request *md5_req; |
19689e38e
|
1498 |
void *scratch; |
cfb6eeb4c
|
1499 |
}; |
cfb6eeb4c
|
1500 |
/* - functions */ |
39f8e58e5
|
1501 1502 |
int tcp_v4_md5_hash_skb(char *md5_hash, const struct tcp_md5sig_key *key, const struct sock *sk, const struct sk_buff *skb); |
5c9f30236
|
1503 |
int tcp_md5_do_add(struct sock *sk, const union tcp_md5_addr *addr, |
dea53bb80
|
1504 1505 |
int family, u8 prefixlen, int l3index, const u8 *newkey, u8 newkeylen, gfp_t gfp); |
5c9f30236
|
1506 |
int tcp_md5_do_del(struct sock *sk, const union tcp_md5_addr *addr, |
dea53bb80
|
1507 |
int family, u8 prefixlen, int l3index); |
b83e3deb9
|
1508 |
struct tcp_md5sig_key *tcp_v4_md5_lookup(const struct sock *sk, |
fd3a154a0
|
1509 |
const struct sock *addr_sk); |
cfb6eeb4c
|
1510 |
|
9501f9722
|
1511 |
#ifdef CONFIG_TCP_MD5SIG |
6015c71e6
|
1512 |
#include <linux/jump_label.h> |
921f9a0f2
|
1513 |
extern struct static_key_false tcp_md5_needed; |
dea53bb80
|
1514 |
struct tcp_md5sig_key *__tcp_md5_do_lookup(const struct sock *sk, int l3index, |
6015c71e6
|
1515 1516 1517 |
const union tcp_md5_addr *addr, int family); static inline struct tcp_md5sig_key * |
dea53bb80
|
1518 1519 |
tcp_md5_do_lookup(const struct sock *sk, int l3index, const union tcp_md5_addr *addr, int family) |
6015c71e6
|
1520 |
{ |
921f9a0f2
|
1521 |
if (!static_branch_unlikely(&tcp_md5_needed)) |
6015c71e6
|
1522 |
return NULL; |
dea53bb80
|
1523 |
return __tcp_md5_do_lookup(sk, l3index, addr, family); |
6015c71e6
|
1524 |
} |
a915da9b6
|
1525 |
#define tcp_twsk_md5_key(twsk) ((twsk)->tw_md5_key) |
9501f9722
|
1526 |
#else |
dea53bb80
|
1527 1528 1529 |
static inline struct tcp_md5sig_key * tcp_md5_do_lookup(const struct sock *sk, int l3index, const union tcp_md5_addr *addr, int family) |
a915da9b6
|
1530 1531 1532 |
{ return NULL; } |
9501f9722
|
1533 1534 |
#define tcp_twsk_md5_key(twsk) NULL #endif |
5c9f30236
|
1535 |
bool tcp_alloc_md5sig_pool(void); |
cfb6eeb4c
|
1536 |
|
5c9f30236
|
1537 |
struct tcp_md5sig_pool *tcp_get_md5sig_pool(void); |
71cea17ed
|
1538 1539 1540 1541 |
static inline void tcp_put_md5sig_pool(void) { local_bh_enable(); } |
35790c042
|
1542 |
|
5c9f30236
|
1543 1544 1545 1546 |
int tcp_md5_hash_skb_data(struct tcp_md5sig_pool *, const struct sk_buff *, unsigned int header_len); int tcp_md5_hash_key(struct tcp_md5sig_pool *hp, const struct tcp_md5sig_key *key); |
cfb6eeb4c
|
1547 |
|
104671636
|
1548 |
/* From tcp_fastopen.c */ |
5c9f30236
|
1549 |
void tcp_fastopen_cache_get(struct sock *sk, u16 *mss, |
7268586ba
|
1550 |
struct tcp_fastopen_cookie *cookie); |
5c9f30236
|
1551 |
void tcp_fastopen_cache_set(struct sock *sk, u16 mss, |
2646c831c
|
1552 1553 |
struct tcp_fastopen_cookie *cookie, bool syn_lost, u16 try_exp); |
783237e8d
|
1554 1555 1556 1557 |
struct tcp_fastopen_request { /* Fast Open cookie. Size 0 means a cookie request */ struct tcp_fastopen_cookie cookie; struct msghdr *data; /* data in MSG_FASTOPEN */ |
f5ddcbbb4
|
1558 1559 |
size_t size; int copied; /* queued in tcp_connect() */ |
f859a4484
|
1560 |
struct ubuf_info *uarg; |
783237e8d
|
1561 |
}; |
783237e8d
|
1562 |
void tcp_free_fastopen_req(struct tcp_sock *tp); |
1fba70e5b
|
1563 |
void tcp_fastopen_destroy_cipher(struct sock *sk); |
437138485
|
1564 |
void tcp_fastopen_ctx_destroy(struct net *net); |
1fba70e5b
|
1565 |
int tcp_fastopen_reset_cipher(struct net *net, struct sock *sk, |
438ac8800
|
1566 |
void *primary_key, void *backup_key); |
f19008e67
|
1567 1568 |
int tcp_fastopen_get_cipher(struct net *net, struct inet_connection_sock *icsk, u64 *key); |
61d2bcae9
|
1569 |
void tcp_fastopen_add_skb(struct sock *sk, struct sk_buff *skb); |
7c85af881
|
1570 1571 |
struct sock *tcp_try_fastopen(struct sock *sk, struct sk_buff *skb, struct request_sock *req, |
71c02379c
|
1572 1573 |
struct tcp_fastopen_cookie *foc, const struct dst_entry *dst); |
437138485
|
1574 |
void tcp_fastopen_init_key_once(struct net *net); |
065263f40
|
1575 1576 |
bool tcp_fastopen_cookie_check(struct sock *sk, u16 *mss, struct tcp_fastopen_cookie *cookie); |
19f6d3f3c
|
1577 |
bool tcp_fastopen_defer_connect(struct sock *sk, int *err); |
438ac8800
|
1578 |
#define TCP_FASTOPEN_KEY_LENGTH sizeof(siphash_key_t) |
9092a76d3
|
1579 1580 1581 |
#define TCP_FASTOPEN_KEY_MAX 2 #define TCP_FASTOPEN_KEY_BUF_LENGTH \ (TCP_FASTOPEN_KEY_LENGTH * TCP_FASTOPEN_KEY_MAX) |
104671636
|
1582 1583 1584 |
/* Fastopen key context */ struct tcp_fastopen_context { |
438ac8800
|
1585 |
siphash_key_t key[TCP_FASTOPEN_KEY_MAX]; |
c681edae3
|
1586 1587 |
int num; struct rcu_head rcu; |
104671636
|
1588 |
}; |
cf1ef3f07
|
1589 |
extern unsigned int sysctl_tcp_fastopen_blackhole_timeout; |
46c2fa398
|
1590 |
void tcp_fastopen_active_disable(struct sock *sk); |
cf1ef3f07
|
1591 1592 |
bool tcp_fastopen_active_should_disable(struct sock *sk); void tcp_fastopen_active_disable_ofo_check(struct sock *sk); |
7268586ba
|
1593 |
void tcp_fastopen_active_detect_blackhole(struct sock *sk, bool expired); |
cf1ef3f07
|
1594 |
|
9092a76d3
|
1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 |
/* Caller needs to wrap with rcu_read_(un)lock() */ static inline struct tcp_fastopen_context *tcp_fastopen_get_ctx(const struct sock *sk) { struct tcp_fastopen_context *ctx; ctx = rcu_dereference(inet_csk(sk)->icsk_accept_queue.fastopenq.ctx); if (!ctx) ctx = rcu_dereference(sock_net(sk)->ipv4.tcp_fastopen_ctx); return ctx; } static inline bool tcp_fastopen_cookie_match(const struct tcp_fastopen_cookie *foc, const struct tcp_fastopen_cookie *orig) { if (orig->len == TCP_FASTOPEN_COOKIE_SIZE && orig->len == foc->len && !memcmp(orig->val, foc->val, foc->len)) return true; return false; } static inline int tcp_fastopen_context_len(const struct tcp_fastopen_context *ctx) { |
c681edae3
|
1621 |
return ctx->num; |
9092a76d3
|
1622 |
} |
05b055e89
|
1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 |
/* Latencies incurred by various limits for a sender. They are * chronograph-like stats that are mutually exclusive. */ enum tcp_chrono { TCP_CHRONO_UNSPEC, TCP_CHRONO_BUSY, /* Actively sending data (non-empty write queue) */ TCP_CHRONO_RWND_LIMITED, /* Stalled by insufficient receive window */ TCP_CHRONO_SNDBUF_LIMITED, /* Stalled by insufficient send buffer */ __TCP_CHRONO_MAX, }; void tcp_chrono_start(struct sock *sk, const enum tcp_chrono type); void tcp_chrono_stop(struct sock *sk, const enum tcp_chrono type); |
e2080072e
|
1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 |
/* This helper is needed, because skb->tcp_tsorted_anchor uses * the same memory storage than skb->destructor/_skb_refdst */ static inline void tcp_skb_tsorted_anchor_cleanup(struct sk_buff *skb) { skb->destructor = NULL; skb->_skb_refdst = 0UL; } #define tcp_skb_tsorted_save(skb) { \ unsigned long _save = skb->_skb_refdst; \ skb->_skb_refdst = 0UL; #define tcp_skb_tsorted_restore(skb) \ skb->_skb_refdst = _save; \ } |
ac3f09ba3
|
1652 |
void tcp_write_queue_purge(struct sock *sk); |
fe067e8ab
|
1653 |
|
75c119afe
|
1654 1655 1656 1657 |
static inline struct sk_buff *tcp_rtx_queue_head(const struct sock *sk) { return skb_rb_first(&sk->tcp_rtx_queue); } |
b617158dc
|
1658 1659 1660 1661 |
static inline struct sk_buff *tcp_rtx_queue_tail(const struct sock *sk) { return skb_rb_last(&sk->tcp_rtx_queue); } |
cf533ea53
|
1662 |
static inline struct sk_buff *tcp_write_queue_head(const struct sock *sk) |
fe067e8ab
|
1663 |
{ |
cd07a8ea0
|
1664 |
return skb_peek(&sk->sk_write_queue); |
fe067e8ab
|
1665 |
} |
cf533ea53
|
1666 |
static inline struct sk_buff *tcp_write_queue_tail(const struct sock *sk) |
fe067e8ab
|
1667 |
{ |
cd07a8ea0
|
1668 |
return skb_peek_tail(&sk->sk_write_queue); |
fe067e8ab
|
1669 |
} |
234b68607
|
1670 |
#define tcp_for_write_queue_from_safe(skb, tmp, sk) \ |
cd07a8ea0
|
1671 |
skb_queue_walk_from_safe(&(sk)->sk_write_queue, skb, tmp) |
234b68607
|
1672 |
|
cf533ea53
|
1673 |
static inline struct sk_buff *tcp_send_head(const struct sock *sk) |
fe067e8ab
|
1674 |
{ |
75c119afe
|
1675 |
return skb_peek(&sk->sk_write_queue); |
fe067e8ab
|
1676 |
} |
cd07a8ea0
|
1677 1678 1679 1680 1681 |
static inline bool tcp_skb_is_last(const struct sock *sk, const struct sk_buff *skb) { return skb_queue_is_last(&sk->sk_write_queue, skb); } |
ee2aabd3f
|
1682 1683 1684 1685 1686 1687 1688 |
/** * tcp_write_queue_empty - test if any payload (or FIN) is available in write queue * @sk: socket * * Since the write queue can have a temporary empty skb in it, * we must not use "return skb_queue_empty(&sk->sk_write_queue)" */ |
75c119afe
|
1689 |
static inline bool tcp_write_queue_empty(const struct sock *sk) |
fe067e8ab
|
1690 |
{ |
ee2aabd3f
|
1691 1692 1693 |
const struct tcp_sock *tp = tcp_sk(sk); return tp->write_seq == tp->snd_nxt; |
75c119afe
|
1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 |
} static inline bool tcp_rtx_queue_empty(const struct sock *sk) { return RB_EMPTY_ROOT(&sk->tcp_rtx_queue); } static inline bool tcp_rtx_and_write_queues_empty(const struct sock *sk) { return tcp_rtx_queue_empty(sk) && tcp_write_queue_empty(sk); |
fe067e8ab
|
1704 |
} |
fe067e8ab
|
1705 1706 |
static inline void tcp_add_write_queue_tail(struct sock *sk, struct sk_buff *skb) { |
a43e052be
|
1707 |
__skb_queue_tail(&sk->sk_write_queue, skb); |
fe067e8ab
|
1708 1709 |
/* Queue it, remembering where we must start sending. */ |
50895b9de
|
1710 |
if (sk->sk_write_queue.next == skb) |
0f87230d1
|
1711 |
tcp_chrono_start(sk, TCP_CHRONO_BUSY); |
fe067e8ab
|
1712 |
} |
43f59c893
|
1713 |
/* Insert new before skb on the write queue of sk. */ |
fe067e8ab
|
1714 1715 1716 1717 |
static inline void tcp_insert_write_queue_before(struct sk_buff *new, struct sk_buff *skb, struct sock *sk) { |
43f59c893
|
1718 |
__skb_queue_before(&sk->sk_write_queue, skb, new); |
fe067e8ab
|
1719 1720 1721 1722 |
} static inline void tcp_unlink_write_queue(struct sk_buff *skb, struct sock *sk) { |
4a269818a
|
1723 |
tcp_skb_tsorted_anchor_cleanup(skb); |
fe067e8ab
|
1724 1725 |
__skb_unlink(skb, &sk->sk_write_queue); } |
75c119afe
|
1726 1727 1728 |
void tcp_rbtree_insert(struct rb_root *root, struct sk_buff *skb); static inline void tcp_rtx_queue_unlink(struct sk_buff *skb, struct sock *sk) |
fe067e8ab
|
1729 |
{ |
75c119afe
|
1730 1731 1732 1733 1734 1735 1736 1737 1738 |
tcp_skb_tsorted_anchor_cleanup(skb); rb_erase(&skb->rbnode, &sk->tcp_rtx_queue); } static inline void tcp_rtx_queue_unlink_and_free(struct sk_buff *skb, struct sock *sk) { list_del(&skb->tcp_tsorted_anchor); tcp_rtx_queue_unlink(skb, sk); sk_wmem_free_skb(sk, skb); |
fe067e8ab
|
1739 |
} |
12d50c46d
|
1740 1741 1742 1743 1744 1745 1746 1747 |
static inline void tcp_push_pending_frames(struct sock *sk) { if (tcp_send_head(sk)) { struct tcp_sock *tp = tcp_sk(sk); __tcp_push_pending_frames(sk, tcp_current_mss(sk), tp->nonagle); } } |
ecb971923
|
1748 1749 1750 |
/* Start sequence of the skb just after the highest skb with SACKed * bit, valid only if sacked_out > 0 or when the caller has ensured * validity by itself. |
a47e5a988
|
1751 1752 1753 1754 1755 |
*/ static inline u32 tcp_highest_sack_seq(struct tcp_sock *tp) { if (!tp->sacked_out) return tp->snd_una; |
6859d4947
|
1756 1757 1758 |
if (tp->highest_sack == NULL) return tp->snd_nxt; |
a47e5a988
|
1759 1760 |
return TCP_SKB_CB(tp->highest_sack)->seq; } |
6859d4947
|
1761 1762 |
static inline void tcp_advance_highest_sack(struct sock *sk, struct sk_buff *skb) { |
50895b9de
|
1763 |
tcp_sk(sk)->highest_sack = skb_rb_next(skb); |
6859d4947
|
1764 1765 1766 1767 1768 1769 1770 1771 1772 |
} static inline struct sk_buff *tcp_highest_sack(struct sock *sk) { return tcp_sk(sk)->highest_sack; } static inline void tcp_highest_sack_reset(struct sock *sk) { |
50895b9de
|
1773 |
tcp_sk(sk)->highest_sack = tcp_rtx_queue_head(sk); |
6859d4947
|
1774 |
} |
2b7cda9c3
|
1775 1776 |
/* Called when old skb is about to be deleted and replaced by new skb */ static inline void tcp_highest_sack_replace(struct sock *sk, |
6859d4947
|
1777 1778 1779 |
struct sk_buff *old, struct sk_buff *new) { |
2b7cda9c3
|
1780 |
if (old == tcp_highest_sack(sk)) |
6859d4947
|
1781 1782 |
tcp_sk(sk)->highest_sack = new; } |
b1f0a0e99
|
1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 |
/* This helper checks if socket has IP_TRANSPARENT set */ static inline bool inet_sk_transparent(const struct sock *sk) { switch (sk->sk_state) { case TCP_TIME_WAIT: return inet_twsk(sk)->tw_transparent; case TCP_NEW_SYN_RECV: return inet_rsk(inet_reqsk(sk))->no_srccheck; } return inet_sk(sk)->transparent; } |
5aa4b32fc
|
1794 1795 1796 |
/* Determines whether this is a thin stream (which may suffer from * increased latency). Used to trigger latency-reducing mechanisms. */ |
a2a385d62
|
1797 |
static inline bool tcp_stream_is_thin(struct tcp_sock *tp) |
5aa4b32fc
|
1798 1799 1800 |
{ return tp->packets_out < 4 && !tcp_in_initial_slowstart(tp); } |
1da177e4c
|
1801 1802 1803 |
/* /proc */ enum tcp_seq_states { TCP_SEQ_STATE_LISTENING, |
1da177e4c
|
1804 |
TCP_SEQ_STATE_ESTABLISHED, |
1da177e4c
|
1805 |
}; |
37d849bb4
|
1806 1807 1808 |
void *tcp_seq_start(struct seq_file *seq, loff_t *pos); void *tcp_seq_next(struct seq_file *seq, void *v, loff_t *pos); void tcp_seq_stop(struct seq_file *seq, void *v); |
73cb88ecb
|
1809 |
|
1da177e4c
|
1810 |
struct tcp_seq_afinfo { |
73cb88ecb
|
1811 |
sa_family_t family; |
1da177e4c
|
1812 1813 1814 |
}; struct tcp_iter_state { |
a4146b1b2
|
1815 |
struct seq_net_private p; |
1da177e4c
|
1816 1817 |
enum tcp_seq_states state; struct sock *syn_wait_sk; |
b08d4d3b6
|
1818 |
struct tcp_seq_afinfo *bpf_seq_afinfo; |
a7cb5a49b
|
1819 |
int bucket, offset, sbucket, num; |
a8b690f98
|
1820 |
loff_t last_pos; |
1da177e4c
|
1821 |
}; |
20380731b
|
1822 |
extern struct request_sock_ops tcp_request_sock_ops; |
c6aefafb7
|
1823 |
extern struct request_sock_ops tcp6_request_sock_ops; |
20380731b
|
1824 |
|
5c9f30236
|
1825 |
void tcp_v4_destroy_sock(struct sock *sk); |
20380731b
|
1826 |
|
28be6e07e
|
1827 |
struct sk_buff *tcp_gso_segment(struct sk_buff *skb, |
5c9f30236
|
1828 |
netdev_features_t features); |
d4546c250
|
1829 |
struct sk_buff *tcp_gro_receive(struct list_head *head, struct sk_buff *skb); |
5521d95e0
|
1830 1831 1832 1833 |
INDIRECT_CALLABLE_DECLARE(int tcp4_gro_complete(struct sk_buff *skb, int thoff)); INDIRECT_CALLABLE_DECLARE(struct sk_buff *tcp4_gro_receive(struct list_head *head, struct sk_buff *skb)); INDIRECT_CALLABLE_DECLARE(int tcp6_gro_complete(struct sk_buff *skb, int thoff)); INDIRECT_CALLABLE_DECLARE(struct sk_buff *tcp6_gro_receive(struct list_head *head, struct sk_buff *skb)); |
5c9f30236
|
1834 |
int tcp_gro_complete(struct sk_buff *skb); |
28850dc7c
|
1835 |
|
5c9f30236
|
1836 |
void __tcp_v4_send_check(struct sk_buff *skb, __be32 saddr, __be32 daddr); |
f4c50d990
|
1837 |
|
c9bee3b7f
|
1838 1839 |
static inline u32 tcp_notsent_lowat(const struct tcp_sock *tp) { |
4979f2d9f
|
1840 1841 |
struct net *net = sock_net((struct sock *)tp); return tp->notsent_lowat ?: net->ipv4.sysctl_tcp_notsent_lowat; |
c9bee3b7f
|
1842 |
} |
a74f0fa08
|
1843 1844 1845 1846 1847 |
/* @wake is one when sk_stream_write_space() calls us. * This sends EPOLLOUT only if notsent_bytes is half the limit. * This mimics the strategy used in sock_def_write_space(). */ static inline bool tcp_stream_memory_free(const struct sock *sk, int wake) |
c9bee3b7f
|
1848 1849 |
{ const struct tcp_sock *tp = tcp_sk(sk); |
e0d694d63
|
1850 1851 |
u32 notsent_bytes = READ_ONCE(tp->write_seq) - READ_ONCE(tp->snd_nxt); |
c9bee3b7f
|
1852 |
|
a74f0fa08
|
1853 |
return (notsent_bytes << wake) < tcp_notsent_lowat(tp); |
c9bee3b7f
|
1854 |
} |
20380731b
|
1855 |
#ifdef CONFIG_PROC_FS |
5c9f30236
|
1856 1857 |
int tcp4_proc_init(void); void tcp4_proc_exit(void); |
20380731b
|
1858 |
#endif |
ea3bea3a1
|
1859 |
int tcp_rtx_synack(const struct sock *sk, struct request_sock *req); |
1fb6f159f
|
1860 1861 1862 |
int tcp_conn_request(struct request_sock_ops *rsk_ops, const struct tcp_request_sock_ops *af_ops, struct sock *sk, struct sk_buff *skb); |
5db92c994
|
1863 |
|
cfb6eeb4c
|
1864 1865 1866 |
/* TCP af-specific functions */ struct tcp_sock_af_ops { #ifdef CONFIG_TCP_MD5SIG |
b83e3deb9
|
1867 |
struct tcp_md5sig_key *(*md5_lookup) (const struct sock *sk, |
fd3a154a0
|
1868 |
const struct sock *addr_sk); |
39f8e58e5
|
1869 1870 1871 1872 1873 |
int (*calc_md5_hash)(char *location, const struct tcp_md5sig_key *md5, const struct sock *sk, const struct sk_buff *skb); int (*md5_parse)(struct sock *sk, |
8917a777b
|
1874 |
int optname, |
d4c19c491
|
1875 |
sockptr_t optval, |
39f8e58e5
|
1876 |
int optlen); |
cfb6eeb4c
|
1877 1878 1879 1880 |
#endif }; struct tcp_request_sock_ops { |
2aec4a297
|
1881 |
u16 mss_clamp; |
cfb6eeb4c
|
1882 |
#ifdef CONFIG_TCP_MD5SIG |
b83e3deb9
|
1883 |
struct tcp_md5sig_key *(*req_md5_lookup)(const struct sock *sk, |
fd3a154a0
|
1884 |
const struct sock *addr_sk); |
39f8e58e5
|
1885 1886 1887 1888 |
int (*calc_md5_hash) (char *location, const struct tcp_md5sig_key *md5, const struct sock *sk, const struct sk_buff *skb); |
cfb6eeb4c
|
1889 |
#endif |
b40cf18ef
|
1890 1891 |
void (*init_req)(struct request_sock *req, const struct sock *sk_listener, |
16bea70aa
|
1892 |
struct sk_buff *skb); |
fb7b37a7f
|
1893 |
#ifdef CONFIG_SYN_COOKIES |
3f684b4b1
|
1894 |
__u32 (*cookie_init_seq)(const struct sk_buff *skb, |
fb7b37a7f
|
1895 1896 |
__u16 *mss); #endif |
f964629e3
|
1897 |
struct dst_entry *(*route_req)(const struct sock *sk, struct flowi *fl, |
4396e4618
|
1898 |
const struct request_sock *req); |
84b114b98
|
1899 |
u32 (*init_seq)(const struct sk_buff *skb); |
5d2ed0521
|
1900 |
u32 (*init_ts_off)(const struct net *net, const struct sk_buff *skb); |
0f935dbed
|
1901 |
int (*send_synack)(const struct sock *sk, struct dst_entry *dst, |
d6274bd8d
|
1902 |
struct flowi *fl, struct request_sock *req, |
dc6ef6be5
|
1903 |
struct tcp_fastopen_cookie *foc, |
331fca431
|
1904 1905 |
enum tcp_synack_type synack_type, struct sk_buff *syn_skb); |
cfb6eeb4c
|
1906 |
}; |
35b2c3211
|
1907 1908 1909 1910 |
extern const struct tcp_request_sock_ops tcp_request_sock_ipv4_ops; #if IS_ENABLED(CONFIG_IPV6) extern const struct tcp_request_sock_ops tcp_request_sock_ipv6_ops; #endif |
fb7b37a7f
|
1911 1912 |
#ifdef CONFIG_SYN_COOKIES static inline __u32 cookie_init_sequence(const struct tcp_request_sock_ops *ops, |
3f684b4b1
|
1913 |
const struct sock *sk, struct sk_buff *skb, |
fb7b37a7f
|
1914 1915 |
__u16 *mss) { |
3f684b4b1
|
1916 |
tcp_synq_overflow(sk); |
02a1d6e7a
|
1917 |
__NET_INC_STATS(sock_net(sk), LINUX_MIB_SYNCOOKIESSENT); |
3f684b4b1
|
1918 |
return ops->cookie_init_seq(skb, mss); |
fb7b37a7f
|
1919 1920 1921 |
} #else static inline __u32 cookie_init_sequence(const struct tcp_request_sock_ops *ops, |
3f684b4b1
|
1922 |
const struct sock *sk, struct sk_buff *skb, |
fb7b37a7f
|
1923 1924 1925 1926 1927 |
__u16 *mss) { return 0; } #endif |
5c9f30236
|
1928 |
int tcpv4_offload_init(void); |
28850dc7c
|
1929 |
|
5c9f30236
|
1930 1931 |
void tcp_v4_init(void); void tcp_init(void); |
20380731b
|
1932 |
|
659a8ad56
|
1933 |
/* tcp_recovery.c */ |
d716bfdb1
|
1934 |
void tcp_mark_skb_lost(struct sock *sk, struct sk_buff *skb); |
6ac06ecd3
|
1935 |
void tcp_newreno_mark_lost(struct sock *sk, bool snd_una_advanced); |
b8fef65a8
|
1936 1937 |
extern s32 tcp_rack_skb_timeout(struct tcp_sock *tp, struct sk_buff *skb, u32 reo_wnd); |
128eda86b
|
1938 |
extern void tcp_rack_mark_lost(struct sock *sk); |
1d0833df5
|
1939 |
extern void tcp_rack_advance(struct tcp_sock *tp, u8 sacked, u32 end_seq, |
9a568de48
|
1940 |
u64 xmit_time); |
57dde7f70
|
1941 |
extern void tcp_rack_reo_timeout(struct sock *sk); |
1f2556916
|
1942 |
extern void tcp_rack_update_reo_wnd(struct sock *sk, struct rate_sample *rs); |
659a8ad56
|
1943 |
|
e1a10ef7f
|
1944 1945 1946 |
/* At how many usecs into the future should the RTO fire? */ static inline s64 tcp_rto_delta_us(const struct sock *sk) { |
75c119afe
|
1947 |
const struct sk_buff *skb = tcp_rtx_queue_head(sk); |
e1a10ef7f
|
1948 |
u32 rto = inet_csk(sk)->icsk_rto; |
2fd66ffba
|
1949 |
u64 rto_time_stamp_us = tcp_skb_timestamp_us(skb) + jiffies_to_usecs(rto); |
e1a10ef7f
|
1950 1951 1952 |
return rto_time_stamp_us - tcp_sk(sk)->tcp_mstamp; } |
e25f866fb
|
1953 1954 1955 |
/* * Save and compile IPv4 options, return a pointer to it */ |
91ed1e666
|
1956 1957 |
static inline struct ip_options_rcu *tcp_v4_save_options(struct net *net, struct sk_buff *skb) |
e25f866fb
|
1958 1959 1960 |
{ const struct ip_options *opt = &TCP_SKB_CB(skb)->header.h4.opt; struct ip_options_rcu *dopt = NULL; |
461b74c39
|
1961 |
if (opt->optlen) { |
e25f866fb
|
1962 1963 1964 |
int opt_size = sizeof(*dopt) + opt->optlen; dopt = kmalloc(opt_size, GFP_ATOMIC); |
91ed1e666
|
1965 |
if (dopt && __ip_options_echo(net, &dopt->opt, skb, opt)) { |
e25f866fb
|
1966 1967 1968 1969 1970 1971 |
kfree(dopt); dopt = NULL; } } return dopt; } |
987819657
|
1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 |
/* locally generated TCP pure ACKs have skb->truesize == 2 * (check tcp_send_ack() in net/ipv4/tcp_output.c ) * This is much faster than dissecting the packet to find out. * (Think of GRE encapsulations, IPv4, IPv6, ...) */ static inline bool skb_is_tcp_pure_ack(const struct sk_buff *skb) { return skb->truesize == 2; } static inline void skb_set_tcp_pure_ack(struct sk_buff *skb) { skb->truesize = 2; } |
473bd239b
|
1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 |
static inline int tcp_inq(struct sock *sk) { struct tcp_sock *tp = tcp_sk(sk); int answ; if ((1 << sk->sk_state) & (TCPF_SYN_SENT | TCPF_SYN_RECV)) { answ = 0; } else if (sock_flag(sk, SOCK_URGINLINE) || !tp->urg_data || before(tp->urg_seq, tp->copied_seq) || !before(tp->urg_seq, tp->rcv_nxt)) { answ = tp->rcv_nxt - tp->copied_seq; /* Subtract 1, if FIN was received */ if (answ && sock_flag(sk, SOCK_DONE)) answ--; } else { answ = tp->urg_seq - tp->copied_seq; } return answ; } |
320355858
|
2009 |
int tcp_peek_len(struct socket *sock); |
a44d6eacd
|
2010 2011 2012 2013 2014 2015 2016 2017 2018 |
static inline void tcp_segs_in(struct tcp_sock *tp, const struct sk_buff *skb) { u16 segs_in; segs_in = max_t(u16, 1, skb_shinfo(skb)->gso_segs); tp->segs_in += segs_in; if (skb->len > tcp_hdrlen(skb)) tp->data_segs_in += segs_in; } |
9caad8641
|
2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 |
/* * TCP listen path runs lockless. * We forced "struct sock" to be const qualified to make sure * we don't modify one of its field by mistake. * Here, we increment sk_drops which is an atomic_t, so we can safely * make sock writable again. */ static inline void tcp_listendrop(const struct sock *sk) { atomic_inc(&((struct sock *)sk)->sk_drops); |
02a1d6e7a
|
2029 |
__NET_INC_STATS(sock_net(sk), LINUX_MIB_LISTENDROPS); |
9caad8641
|
2030 |
} |
218af599f
|
2031 |
enum hrtimer_restart tcp_pace_kick(struct hrtimer *timer); |
734942cc4
|
2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 |
/* * Interface for adding Upper Level Protocols over TCP */ #define TCP_ULP_NAME_MAX 16 #define TCP_ULP_MAX 128 #define TCP_ULP_BUF_MAX (TCP_ULP_NAME_MAX*TCP_ULP_MAX) struct tcp_ulp_ops { struct list_head list; /* initialize ulp */ int (*init)(struct sock *sk); |
95fa14547
|
2045 |
/* update ulp */ |
33bfe20dd
|
2046 2047 |
void (*update)(struct sock *sk, struct proto *p, void (*write_space)(struct sock *sk)); |
734942cc4
|
2048 2049 |
/* cleanup ulp */ void (*release)(struct sock *sk); |
61723b393
|
2050 2051 2052 |
/* diagnostic */ int (*get_info)(const struct sock *sk, struct sk_buff *skb); size_t (*get_info_size)(const struct sock *sk); |
132305930
|
2053 2054 2055 |
/* clone ulp */ void (*clone)(const struct request_sock *req, struct sock *newsk, const gfp_t priority); |
734942cc4
|
2056 2057 2058 2059 2060 2061 2062 2063 2064 |
char name[TCP_ULP_NAME_MAX]; struct module *owner; }; int tcp_register_ulp(struct tcp_ulp_ops *type); void tcp_unregister_ulp(struct tcp_ulp_ops *type); int tcp_set_ulp(struct sock *sk, const char *name); void tcp_get_available_ulp(char *buf, size_t len); void tcp_cleanup_ulp(struct sock *sk); |
33bfe20dd
|
2065 2066 |
void tcp_update_ulp(struct sock *sk, struct proto *p, void (*write_space)(struct sock *sk)); |
734942cc4
|
2067 |
|
037b0b86e
|
2068 2069 2070 |
#define MODULE_ALIAS_TCP_ULP(name) \ __MODULE_INFO(alias, alias_userspace, name); \ __MODULE_INFO(alias, alias_tcp_ulp, "tcp-ulp-" name) |
604326b41
|
2071 2072 |
struct sk_msg; struct sk_psock; |
f747632b6
|
2073 2074 2075 2076 2077 2078 2079 2080 |
#ifdef CONFIG_BPF_STREAM_PARSER struct proto *tcp_bpf_get_proto(struct sock *sk, struct sk_psock *psock); void tcp_bpf_clone(const struct sock *sk, struct sock *newsk); #else static inline void tcp_bpf_clone(const struct sock *sk, struct sock *newsk) { } #endif /* CONFIG_BPF_STREAM_PARSER */ |
5da004044
|
2081 |
#ifdef CONFIG_NET_SOCK_MSG |
604326b41
|
2082 2083 |
int tcp_bpf_sendmsg_redir(struct sock *sk, struct sk_msg *msg, u32 bytes, int flags); |
604326b41
|
2084 |
int __tcp_bpf_recvmsg(struct sock *sk, struct sk_psock *psock, |
02c558b2d
|
2085 |
struct msghdr *msg, int len, int flags); |
5da004044
|
2086 |
#endif /* CONFIG_NET_SOCK_MSG */ |
604326b41
|
2087 |
|
0813a8415
|
2088 |
#ifdef CONFIG_CGROUP_BPF |
0813a8415
|
2089 2090 2091 2092 2093 2094 2095 2096 |
static inline void bpf_skops_init_skb(struct bpf_sock_ops_kern *skops, struct sk_buff *skb, unsigned int end_offset) { skops->skb = skb; skops->skb_data_end = skb->data + end_offset; } #else |
0813a8415
|
2097 2098 2099 2100 2101 2102 |
static inline void bpf_skops_init_skb(struct bpf_sock_ops_kern *skops, struct sk_buff *skb, unsigned int end_offset) { } #endif |
40304b2a1
|
2103 2104 2105 2106 2107 2108 |
/* Call BPF_SOCK_OPS program that returns an int. If the return value * is < 0, then the BPF op failed (for example if the loaded BPF * program does not support the chosen operation or there is no BPF * program loaded). */ #ifdef CONFIG_BPF |
de525be2c
|
2109 |
static inline int tcp_call_bpf(struct sock *sk, int op, u32 nargs, u32 *args) |
40304b2a1
|
2110 2111 2112 |
{ struct bpf_sock_ops_kern sock_ops; int ret; |
b73042b8a
|
2113 |
memset(&sock_ops, 0, offsetof(struct bpf_sock_ops_kern, temp)); |
f19397a5c
|
2114 2115 |
if (sk_fullsock(sk)) { sock_ops.is_fullsock = 1; |
40304b2a1
|
2116 |
sock_owned_by_me(sk); |
f19397a5c
|
2117 |
} |
40304b2a1
|
2118 |
|
40304b2a1
|
2119 2120 |
sock_ops.sk = sk; sock_ops.op = op; |
de525be2c
|
2121 2122 |
if (nargs > 0) memcpy(sock_ops.args, args, nargs * sizeof(*args)); |
40304b2a1
|
2123 2124 2125 2126 2127 2128 2129 2130 |
ret = BPF_CGROUP_RUN_PROG_SOCK_OPS(&sock_ops); if (ret == 0) ret = sock_ops.reply; else ret = -1; return ret; } |
de525be2c
|
2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 |
static inline int tcp_call_bpf_2arg(struct sock *sk, int op, u32 arg1, u32 arg2) { u32 args[2] = {arg1, arg2}; return tcp_call_bpf(sk, op, 2, args); } static inline int tcp_call_bpf_3arg(struct sock *sk, int op, u32 arg1, u32 arg2, u32 arg3) { u32 args[3] = {arg1, arg2, arg3}; return tcp_call_bpf(sk, op, 3, args); } |
40304b2a1
|
2146 |
#else |
de525be2c
|
2147 |
static inline int tcp_call_bpf(struct sock *sk, int op, u32 nargs, u32 *args) |
40304b2a1
|
2148 2149 2150 |
{ return -EPERM; } |
de525be2c
|
2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 |
static inline int tcp_call_bpf_2arg(struct sock *sk, int op, u32 arg1, u32 arg2) { return -EPERM; } static inline int tcp_call_bpf_3arg(struct sock *sk, int op, u32 arg1, u32 arg2, u32 arg3) { return -EPERM; } |
40304b2a1
|
2162 |
#endif |
8550f328f
|
2163 2164 2165 |
static inline u32 tcp_timeout_init(struct sock *sk) { int timeout; |
de525be2c
|
2166 |
timeout = tcp_call_bpf(sk, BPF_SOCK_OPS_TIMEOUT_INIT, 0, NULL); |
8550f328f
|
2167 2168 2169 2170 2171 |
if (timeout <= 0) timeout = TCP_TIMEOUT_INIT; return timeout; } |
13d3b1ebe
|
2172 2173 2174 |
static inline u32 tcp_rwnd_init_bpf(struct sock *sk) { int rwnd; |
de525be2c
|
2175 |
rwnd = tcp_call_bpf(sk, BPF_SOCK_OPS_RWND_INIT, 0, NULL); |
13d3b1ebe
|
2176 2177 2178 2179 2180 |
if (rwnd < 0) rwnd = 0; return rwnd; } |
91b5b21c7
|
2181 2182 2183 |
static inline bool tcp_bpf_ca_needs_ecn(struct sock *sk) { |
de525be2c
|
2184 |
return (tcp_call_bpf(sk, BPF_SOCK_OPS_NEEDS_ECN, 0, NULL) == 1); |
91b5b21c7
|
2185 |
} |
60e2a7780
|
2186 |
|
23729ff23
|
2187 2188 |
static inline void tcp_bpf_rtt(struct sock *sk) { |
bef8e2639
|
2189 |
if (BPF_SOCK_OPS_TEST_FLAG(tcp_sk(sk), BPF_SOCK_OPS_RTT_CB_FLAG)) |
23729ff23
|
2190 2191 |
tcp_call_bpf(sk, BPF_SOCK_OPS_RTT_CB, 0, NULL); } |
60e2a7780
|
2192 2193 2194 |
#if IS_ENABLED(CONFIG_SMC) extern struct static_key_false tcp_have_smc; #endif |
6dac15235
|
2195 2196 2197 2198 2199 |
#if IS_ENABLED(CONFIG_TLS_DEVICE) void clean_acked_data_enable(struct inet_connection_sock *icsk, void (*cad)(struct sock *sk, u32 ack_seq)); void clean_acked_data_disable(struct inet_connection_sock *icsk); |
494bc1d28
|
2200 |
void clean_acked_data_flush(void); |
6dac15235
|
2201 |
#endif |
a842fe142
|
2202 2203 2204 2205 2206 2207 2208 |
DECLARE_STATIC_KEY_FALSE(tcp_tx_delay_enabled); static inline void tcp_add_tx_delay(struct sk_buff *skb, const struct tcp_sock *tp) { if (static_branch_unlikely(&tcp_tx_delay_enabled)) skb->skb_mstamp_ns += (u64)tp->tcp_tx_delay * NSEC_PER_USEC; } |
d6fb396cf
|
2209 2210 2211 2212 |
/* Compute Earliest Departure Time for some control packets * like ACK or RST for TIME_WAIT or non ESTABLISHED sockets. */ static inline u64 tcp_transmit_time(const struct sock *sk) |
a842fe142
|
2213 2214 2215 2216 |
{ if (static_branch_unlikely(&tcp_tx_delay_enabled)) { u32 delay = (sk->sk_state == TCP_TIME_WAIT) ? tcp_twsk(sk)->tw_tx_delay : tcp_sk(sk)->tcp_tx_delay; |
d6fb396cf
|
2217 |
return tcp_clock_ns() + (u64)delay * NSEC_PER_USEC; |
a842fe142
|
2218 |
} |
d6fb396cf
|
2219 |
return 0; |
a842fe142
|
2220 |
} |
1da177e4c
|
2221 |
#endif /* _TCP_H */ |