Blame view
include/linux/tcp.h
13 KB
1da177e4c
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
/* * 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 protocol. * * Version: @(#)tcp.h 1.0.2 04/28/93 * * Author: Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG> * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version * 2 of the License, or (at your option) any later version. */ #ifndef _LINUX_TCP_H #define _LINUX_TCP_H |
1da177e4c
|
19 |
|
1da177e4c
|
20 |
#include <linux/skbuff.h> |
1da177e4c
|
21 |
#include <net/sock.h> |
463c84b97
|
22 |
#include <net/inet_connection_sock.h> |
8feaf0c0a
|
23 |
#include <net/inet_timewait_sock.h> |
607ca46e9
|
24 |
#include <uapi/linux/tcp.h> |
1da177e4c
|
25 |
|
aa8223c7b
|
26 27 |
static inline struct tcphdr *tcp_hdr(const struct sk_buff *skb) { |
9c70220b7
|
28 |
return (struct tcphdr *)skb_transport_header(skb); |
aa8223c7b
|
29 |
} |
ab6a5bb6b
|
30 31 |
static inline unsigned int tcp_hdrlen(const struct sk_buff *skb) { |
aa8223c7b
|
32 |
return tcp_hdr(skb)->doff * 4; |
ab6a5bb6b
|
33 |
} |
6a674e9c7
|
34 35 36 37 38 39 40 41 42 |
static inline struct tcphdr *inner_tcp_hdr(const struct sk_buff *skb) { return (struct tcphdr *)skb_inner_transport_header(skb); } static inline unsigned int inner_tcp_hdrlen(const struct sk_buff *skb) { return inner_tcp_hdr(skb)->doff * 4; } |
ab6a5bb6b
|
43 44 |
static inline unsigned int tcp_optlen(const struct sk_buff *skb) { |
aa8223c7b
|
45 |
return (tcp_hdr(skb)->doff - 5) * 4; |
ab6a5bb6b
|
46 |
} |
2100c8d2d
|
47 48 49 |
/* TCP Fast Open */ #define TCP_FASTOPEN_COOKIE_MIN 4 /* Min Fast Open Cookie size in bytes */ #define TCP_FASTOPEN_COOKIE_MAX 16 /* Max Fast Open Cookie size in bytes */ |
104671636
|
50 |
#define TCP_FASTOPEN_COOKIE_SIZE 8 /* the size employed by this impl. */ |
2100c8d2d
|
51 52 53 54 55 |
/* TCP Fast Open Cookie as stored in memory */ struct tcp_fastopen_cookie { s8 len; u8 val[TCP_FASTOPEN_COOKIE_MAX]; |
7f9b838b7
|
56 |
bool exp; /* In RFC6994 experimental option format */ |
2100c8d2d
|
57 |
}; |
1da177e4c
|
58 |
/* This defines a selective acknowledgement block. */ |
269bd27e6
|
59 60 61 62 |
struct tcp_sack_block_wire { __be32 start_seq; __be32 end_seq; }; |
1da177e4c
|
63 |
struct tcp_sack_block { |
3a137d206
|
64 65 |
u32 start_seq; u32 end_seq; |
1da177e4c
|
66 |
}; |
ab56222a3
|
67 68 69 70 |
/*These are used to set the sack_ok field in struct tcp_options_received */ #define TCP_SACK_SEEN (1 << 0) /*1 = peer is SACK capable, */ #define TCP_FACK_ENABLED (1 << 1) /*1 = FACK is enabled locally*/ #define TCP_DSACK_SEEN (1 << 2) /*1 = DSACK was received from peer*/ |
1da177e4c
|
71 72 73 |
struct tcp_options_received { /* PAWS/RTTM data */ long ts_recent_stamp;/* Time we stored ts_recent (for aging) */ |
3a137d206
|
74 75 76 77 |
u32 ts_recent; /* Time stamp to echo next */ u32 rcv_tsval; /* Time stamp value */ u32 rcv_tsecr; /* Time stamp echo reply */ u16 saw_tstamp : 1, /* Saw TIMESTAMP on last packet */ |
1da177e4c
|
78 79 80 81 82 83 |
tstamp_ok : 1, /* TIMESTAMP seen on SYN packet */ dsack : 1, /* D-SACK is scheduled */ wscale_ok : 1, /* Wscale seen on SYN packet */ sack_ok : 4, /* SACK seen on SYN packet */ snd_wscale : 4, /* Window scaling received from sender */ rcv_wscale : 4; /* Window scaling to send to receiver */ |
3a137d206
|
84 |
u8 num_sacks; /* Number of SACK blocks */ |
435cf559f
|
85 |
u16 user_mss; /* mss requested by user in ioctl */ |
3a137d206
|
86 |
u16 mss_clamp; /* Maximal mss, negotiated at connection setup */ |
1da177e4c
|
87 |
}; |
519855c50
|
88 89 |
static inline void tcp_clear_options(struct tcp_options_received *rx_opt) { |
435cf559f
|
90 91 |
rx_opt->tstamp_ok = rx_opt->sack_ok = 0; rx_opt->wscale_ok = rx_opt->snd_wscale = 0; |
519855c50
|
92 |
} |
4389dded7
|
93 |
/* This is the max number of SACKS that we'll generate and process. It's safe |
435cf559f
|
94 |
* to increase this, although since: |
4389dded7
|
95 96 97 |
* size = TCPOLEN_SACK_BASE_ALIGNED (4) + n * TCPOLEN_SACK_PERBLOCK (8) * only four options will fit in a standard TCP header */ #define TCP_NUM_SACKS 4 |
435cf559f
|
98 |
struct tcp_request_sock_ops; |
2e6599cb8
|
99 |
struct tcp_request_sock { |
cfb6eeb4c
|
100 |
struct inet_request_sock req; |
b2e4b3deb
|
101 |
const struct tcp_request_sock_ops *af_specific; |
0f1c28ae7
|
102 |
struct skb_mstamp snt_synack; /* first SYNACK sent time */ |
9439ce00f
|
103 |
bool tfo_listener; |
58d607d3e
|
104 |
u32 txhash; |
435cf559f
|
105 106 |
u32 rcv_isn; u32 snt_isn; |
a9b2c06db
|
107 |
u32 last_oow_ack_time; /* last SYNACK */ |
104671636
|
108 109 110 111 |
u32 rcv_nxt; /* the ack # by SYNACK. For * FastOpen it's the seq# * after data-in-SYN. */ |
2e6599cb8
|
112 |
}; |
60236fdd0
|
113 |
static inline struct tcp_request_sock *tcp_rsk(const struct request_sock *req) |
2e6599cb8
|
114 115 116 |
{ return (struct tcp_request_sock *)req; } |
1da177e4c
|
117 |
struct tcp_sock { |
463c84b97
|
118 119 |
/* inet_connection_sock has to be the first member of tcp_sock */ struct inet_connection_sock inet_conn; |
2ff52f282
|
120 |
u16 tcp_header_len; /* Bytes of tcp header to send */ |
605ad7f18
|
121 |
u16 gso_segs; /* Max number of segs per GSO packet */ |
1da177e4c
|
122 123 124 125 126 |
/* * Header prediction flags * 0x5?10 << 16 + snd_wnd in net byte order */ |
dddc93c05
|
127 |
__be32 pred_flags; |
1da177e4c
|
128 129 130 131 132 133 |
/* * RFC793 variables by their proper names. This means you can * read the code and the spec side by side (and laugh ...) * See RFC793 and RFC1122. The RFC writes these in capitals. */ |
bdd1f9eda
|
134 135 136 137 |
u64 bytes_received; /* RFC4898 tcpEStatsAppHCThruOctetsReceived * sum(delta(rcv_nxt)), or how many bytes * were acked. */ |
2efd055c5
|
138 139 140 |
u32 segs_in; /* RFC4898 tcpEStatsPerfSegsIn * total number of segments in. */ |
3a137d206
|
141 |
u32 rcv_nxt; /* What we want to receive next */ |
54287cc17
|
142 143 |
u32 copied_seq; /* Head of yet unread data */ u32 rcv_wup; /* rcv_nxt on last window update sent */ |
3a137d206
|
144 |
u32 snd_nxt; /* Next sequence we send */ |
2efd055c5
|
145 146 147 |
u32 segs_out; /* RFC4898 tcpEStatsPerfSegsOut * The total number of segments sent. */ |
0df48c26d
|
148 149 150 151 |
u64 bytes_acked; /* RFC4898 tcpEStatsAppHCThruOctetsAcked * sum(delta(snd_una)), or how many bytes * were acked. */ |
d654976cb
|
152 |
struct u64_stats_sync syncp; /* protects 64bit vars (cf tcp_get_info()) */ |
3a137d206
|
153 154 155 156 |
u32 snd_una; /* First byte we want an ack for */ u32 snd_sml; /* Last byte of the most recently transmitted small packet */ u32 rcv_tstamp; /* timestamp of last received ACK (for keepalives) */ u32 lsndtime; /* timestamp of last sent data packet (for restart window) */ |
f2b2c582e
|
157 |
u32 last_oow_ack_time; /* timestamp of last out-of-window ACK */ |
1da177e4c
|
158 |
|
ceaa1fef6
|
159 |
u32 tsoffset; /* timestamp offset */ |
46d3ceabd
|
160 161 |
struct list_head tsq_node; /* anchor in tsq_tasklet.head list */ unsigned long tsq_flags; |
1da177e4c
|
162 163 164 165 |
/* Data for direct copy to user */ struct { struct sk_buff_head prequeue; struct task_struct *task; |
f4362a2c9
|
166 |
struct msghdr *msg; |
1da177e4c
|
167 168 169 |
int memory; int len; } ucopy; |
3a137d206
|
170 171 172 173 |
u32 snd_wl1; /* Sequence for window update */ u32 snd_wnd; /* The window we expect to receive */ u32 max_window; /* Maximal window ever seen from peer */ u32 mss_cache; /* Cached effective mss, not including SACKS */ |
1da177e4c
|
174 |
|
3a137d206
|
175 176 |
u32 window_clamp; /* Maximal window to advertise */ u32 rcv_ssthresh; /* Current window clamp */ |
1da177e4c
|
177 |
|
659a8ad56
|
178 179 180 181 182 183 |
/* Information of the most recently (s)acked skb */ struct tcp_rack { struct skb_mstamp mstamp; /* (Re)sent time of the skb */ u8 advanced; /* mstamp advanced since last lost marking */ u8 reord; /* reordering detected */ } rack; |
b79eeeb9e
|
184 |
u16 advmss; /* Advertised MSS */ |
9b44190dc
|
185 |
u8 unused; |
36e31b0af
|
186 187 |
u8 nonagle : 4,/* Disable Nagle algorithm? */ thin_lto : 1,/* Use linear timeouts for thin streams */ |
7e3801755
|
188 |
thin_dupack : 1,/* Fast retransmit on first dupack */ |
e33099f96
|
189 190 |
repair : 1, frto : 1;/* F-RTO (RFC5682) activated in CA_Loss */ |
ee9952831
|
191 |
u8 repair_queue; |
750ea2baf
|
192 |
u8 do_early_retrans:1,/* Enable RFC5827 early-retransmit */ |
67da22d23
|
193 |
syn_data:1, /* SYN includes data */ |
6f73601ef
|
194 |
syn_fastopen:1, /* SYN includes Fast Open option */ |
2646c831c
|
195 |
syn_fastopen_exp:1,/* SYN includes Fast Open exp. option */ |
ca8a22634
|
196 |
syn_data_acked:1,/* data in SYN is acked by SYN-ACK */ |
cd8ae8529
|
197 |
save_syn:1, /* Save headers of SYN packet */ |
ca8a22634
|
198 |
is_cwnd_limited:1;/* forward progress limited by snd_cwnd? */ |
9b717a8d2
|
199 |
u32 tlp_high_seq; /* snd_nxt at the time of TLP retransmit. */ |
1da177e4c
|
200 201 |
/* RTT measurement */ |
740b0f184
|
202 203 204 205 |
u32 srtt_us; /* smoothed round trip time << 3 in usecs */ u32 mdev_us; /* medium deviation */ u32 mdev_max_us; /* maximal mdev for the last rtt period */ u32 rttvar_us; /* smoothed mdev_max */ |
3a137d206
|
206 |
u32 rtt_seq; /* sequence number to update rttvar */ |
f67225839
|
207 208 209 |
struct rtt_meas { u32 rtt, ts; /* RTT in usec and sampling time in jiffies. */ } rtt_min[3]; |
3a137d206
|
210 211 |
u32 packets_out; /* Packets which are "in flight" */ |
3a137d206
|
212 |
u32 retrans_out; /* Retransmitted packets out */ |
ca8a22634
|
213 214 |
u32 max_packets_out; /* max packets_out in last window */ u32 max_packets_seq; /* right edge of max_packets_out flight */ |
b79eeeb9e
|
215 216 |
u16 urg_data; /* Saved octet of OOB data and control flags */ |
b79eeeb9e
|
217 |
u8 ecn_flags; /* ECN status bits. */ |
dca145ffa
|
218 219 |
u8 keepalive_probes; /* num of allowed keep alive probes */ u32 reordering; /* Packet reordering metric. */ |
33f5f57ee
|
220 |
u32 snd_up; /* Urgent pointer */ |
1da177e4c
|
221 222 223 |
/* * Options received (usually on last packet, some only on SYN packets). */ |
1da177e4c
|
224 225 226 227 228 |
struct tcp_options_received rx_opt; /* * Slow start and congestion control (see also Nagle, and Karn & Partridge) */ |
3a137d206
|
229 230 |
u32 snd_ssthresh; /* Slow start size threshold */ u32 snd_cwnd; /* Sending congestion window */ |
f78a1b389
|
231 |
u32 snd_cwnd_cnt; /* Linear increase counter */ |
e0ef57cc5
|
232 |
u32 snd_cwnd_clamp; /* Do not allow snd_cwnd to grow above this */ |
3a137d206
|
233 234 |
u32 snd_cwnd_used; u32 snd_cwnd_stamp; |
a262f0cdf
|
235 236 237 238 |
u32 prior_cwnd; /* Congestion window at start of Recovery. */ u32 prr_delivered; /* Number of newly delivered packets to * receiver in Recovery. */ u32 prr_out; /* Total number of pkts sent during Recovery. */ |
1da177e4c
|
239 |
|
3a137d206
|
240 |
u32 rcv_wnd; /* Current receiver window */ |
3a137d206
|
241 |
u32 write_seq; /* Tail(+1) of data held in tcp send buffer */ |
c9bee3b7f
|
242 |
u32 notsent_lowat; /* TCP_NOTSENT_LOWAT */ |
3a137d206
|
243 |
u32 pushed_seq; /* Last pushed seq, required to talk to windows */ |
b79eeeb9e
|
244 245 246 |
u32 lost_out; /* Lost packets */ u32 sacked_out; /* SACK'd packets */ u32 fackets_out; /* FACK'd packets */ |
1da177e4c
|
247 |
|
b79eeeb9e
|
248 249 |
/* from STCP, retrans queue hinting */ struct sk_buff* lost_skb_hint; |
b79eeeb9e
|
250 |
struct sk_buff *retransmit_skb_hint; |
b79eeeb9e
|
251 |
|
996b175e3
|
252 253 254 255 |
/* OOO segments go in this list. Note that socket lock must be held, * as we do not use sk_buff_head lock. */ struct sk_buff_head out_of_order_queue; |
b79eeeb9e
|
256 |
|
c0a788c45
|
257 |
/* SACKs data, these 2 need to be together (see tcp_options_write) */ |
1da177e4c
|
258 259 |
struct tcp_sack_block duplicate_sack[1]; /* D-SACK block */ struct tcp_sack_block selective_acks[4]; /* The SACKS themselves*/ |
fd6dad616
|
260 |
struct tcp_sack_block recv_sack_cache[4]; |
6a438bbe6
|
261 |
|
ecb971923
|
262 263 |
struct sk_buff *highest_sack; /* skb just after the highest * skb with SACKed bit set |
a47e5a988
|
264 265 266 |
* (validity guaranteed only if * sacked_out > 0) */ |
d738cd8fc
|
267 |
|
6a438bbe6
|
268 |
int lost_cnt_hint; |
006f582c7
|
269 |
u32 retransmit_high; /* L-bits may be on up to this seqno */ |
6a438bbe6
|
270 |
|
4b7494404
|
271 |
u32 prior_ssthresh; /* ssthresh saved at recovery start */ |
3a137d206
|
272 |
u32 high_seq; /* snd_nxt at onset of congestion */ |
1da177e4c
|
273 |
|
3a137d206
|
274 |
u32 retrans_stamp; /* Timestamp of the last retransmit, |
1da177e4c
|
275 276 |
* also used in SYN-SENT to remember stamp of * the first SYN. */ |
989e04c5b
|
277 |
u32 undo_marker; /* snd_una upon a new recovery episode. */ |
1da177e4c
|
278 |
int undo_retrans; /* number of undoable retransmissions. */ |
b79eeeb9e
|
279 |
u32 total_retrans; /* Total retransmits for entire connection */ |
3a137d206
|
280 |
u32 urg_seq; /* Seq of received urgent pointer */ |
1da177e4c
|
281 282 |
unsigned int keepalive_time; /* time before keep alive takes place */ unsigned int keepalive_intvl; /* time interval between keep alive probes */ |
1da177e4c
|
283 |
|
a0f82f64e
|
284 |
int linger2; |
1da177e4c
|
285 286 287 |
/* Receiver side RTT estimation */ struct { |
3a137d206
|
288 289 290 |
u32 rtt; u32 seq; u32 time; |
1da177e4c
|
291 292 293 294 295 |
} rcv_rtt_est; /* Receiver queue space */ struct { int space; |
3a137d206
|
296 297 |
u32 seq; u32 time; |
1da177e4c
|
298 |
} rcvq_space; |
0e7b13685
|
299 300 301 |
/* TCP-specific MTU probe information. */ struct { |
3a137d206
|
302 303 |
u32 probe_seq_start; u32 probe_seq_end; |
0e7b13685
|
304 |
} mtu_probe; |
563d34d05
|
305 306 307 |
u32 mtu_info; /* We received an ICMP_FRAG_NEEDED / ICMPV6_PKT_TOOBIG * while socket was owned by user. */ |
cfb6eeb4c
|
308 309 310 |
#ifdef CONFIG_TCP_MD5SIG /* TCP AF-Specific parts; only used by MD5 Signature support so far */ |
b2e4b3deb
|
311 |
const struct tcp_sock_af_ops *af_specific; |
cfb6eeb4c
|
312 |
|
b2e4b3deb
|
313 |
/* TCP MD5 Signature Option information */ |
a8afca032
|
314 |
struct tcp_md5sig_info __rcu *md5sig_info; |
cfb6eeb4c
|
315 |
#endif |
435cf559f
|
316 |
|
104671636
|
317 318 319 320 321 322 |
/* TCP fastopen related information */ struct tcp_fastopen_request *fastopen_req; /* fastopen_rsk points to request_sock that resulted in this big * socket. Used to retransmit SYNACKs etc. */ struct request_sock *fastopen_rsk; |
cd8ae8529
|
323 |
u32 *saved_syn; |
1da177e4c
|
324 |
}; |
46d3ceabd
|
325 326 327 |
enum tsq_flags { TSQ_THROTTLED, TSQ_QUEUED, |
6f458dfb4
|
328 329 330 |
TCP_TSQ_DEFERRED, /* tcp_tasklet_func() found socket was owned */ TCP_WRITE_TIMER_DEFERRED, /* tcp_write_timer() found socket was owned */ TCP_DELACK_TIMER_DEFERRED, /* tcp_delack_timer() found socket was owned */ |
563d34d05
|
331 332 333 |
TCP_MTU_REDUCED_DEFERRED, /* tcp_v{4|6}_err() could not call * tcp_v{4|6}_mtu_reduced() */ |
46d3ceabd
|
334 |
}; |
1da177e4c
|
335 336 337 338 |
static inline struct tcp_sock *tcp_sk(const struct sock *sk) { return (struct tcp_sock *)sk; } |
8feaf0c0a
|
339 340 |
struct tcp_timewait_sock { struct inet_timewait_sock tw_sk; |
d475f090b
|
341 342 |
#define tw_rcv_nxt tw_sk.__tw_common.skc_tw_rcv_nxt #define tw_snd_nxt tw_sk.__tw_common.skc_tw_snd_nxt |
3a137d206
|
343 |
u32 tw_rcv_wnd; |
ceaa1fef6
|
344 |
u32 tw_ts_offset; |
3a137d206
|
345 |
u32 tw_ts_recent; |
4fb17a609
|
346 347 348 |
/* The time we sent the last out-of-window ACK: */ u32 tw_last_oow_ack_time; |
8feaf0c0a
|
349 |
long tw_ts_recent_stamp; |
cfb6eeb4c
|
350 |
#ifdef CONFIG_TCP_MD5SIG |
2397849ba
|
351 |
struct tcp_md5sig_key *tw_md5_key; |
cfb6eeb4c
|
352 |
#endif |
8feaf0c0a
|
353 354 355 356 357 358 |
}; static inline struct tcp_timewait_sock *tcp_twsk(const struct sock *sk) { return (struct tcp_timewait_sock *)sk; } |
104671636
|
359 360 361 362 363 |
static inline bool tcp_passive_fastopen(const struct sock *sk) { return (sk->sk_state == TCP_SYN_RECV && tcp_sk(sk)->fastopen_rsk != NULL); } |
0536fcc03
|
364 |
static inline void fastopen_queue_tune(struct sock *sk, int backlog) |
104671636
|
365 |
{ |
0536fcc03
|
366 |
struct request_sock_queue *queue = &inet_csk(sk)->icsk_accept_queue; |
dbf650b67
|
367 |
int somaxconn = READ_ONCE(sock_net(sk)->core.sysctl_somaxconn); |
0536fcc03
|
368 |
|
dbf650b67
|
369 |
queue->fastopenq.max_qlen = min_t(unsigned int, backlog, somaxconn); |
104671636
|
370 |
} |
805c4bc05
|
371 372 373 374 375 376 |
static inline void tcp_move_syn(struct tcp_sock *tp, struct request_sock *req) { tp->saved_syn = req->saved_syn; req->saved_syn = NULL; } |
cd8ae8529
|
377 378 379 380 381 |
static inline void tcp_saved_syn_free(struct tcp_sock *tp) { kfree(tp->saved_syn); tp->saved_syn = NULL; } |
1da177e4c
|
382 |
#endif /* _LINUX_TCP_H */ |