2019-05-27 06:55:01 +00:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
|
* 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>
|
|
|
|
|
*/
|
|
|
|
|
#ifndef _LINUX_TCP_H
|
|
|
|
|
#define _LINUX_TCP_H
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <linux/skbuff.h>
|
2016-09-20 03:39:10 +00:00
|
|
|
#include <linux/win_minmax.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
#include <net/sock.h>
|
2005-08-10 03:10:42 +00:00
|
|
|
#include <net/inet_connection_sock.h>
|
2005-08-10 03:09:30 +00:00
|
|
|
#include <net/inet_timewait_sock.h>
|
2012-10-13 09:46:48 +00:00
|
|
|
#include <uapi/linux/tcp.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2007-04-11 04:04:22 +00:00
|
|
|
static inline struct tcphdr *tcp_hdr(const struct sk_buff *skb)
|
|
|
|
|
{
|
2007-04-26 01:04:18 +00:00
|
|
|
return (struct tcphdr *)skb_transport_header(skb);
|
2007-04-11 04:04:22 +00:00
|
|
|
}
|
|
|
|
|
|
2016-02-10 16:50:37 +00:00
|
|
|
static inline unsigned int __tcp_hdrlen(const struct tcphdr *th)
|
|
|
|
|
{
|
|
|
|
|
return th->doff * 4;
|
|
|
|
|
}
|
|
|
|
|
|
2007-03-19 00:43:48 +00:00
|
|
|
static inline unsigned int tcp_hdrlen(const struct sk_buff *skb)
|
|
|
|
|
{
|
2016-02-10 16:50:37 +00:00
|
|
|
return __tcp_hdrlen(tcp_hdr(skb));
|
2007-03-19 00:43:48 +00:00
|
|
|
}
|
|
|
|
|
|
2012-12-07 14:14:14 +00:00
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-30 15:07:50 +00:00
|
|
|
/**
|
|
|
|
|
* skb_tcp_all_headers - Returns size of all headers for a TCP packet
|
|
|
|
|
* @skb: buffer
|
|
|
|
|
*
|
|
|
|
|
* Used in TX path, for a packet known to be a TCP one.
|
|
|
|
|
*
|
|
|
|
|
* if (skb_is_gso(skb)) {
|
|
|
|
|
* int hlen = skb_tcp_all_headers(skb);
|
|
|
|
|
* ...
|
|
|
|
|
*/
|
|
|
|
|
static inline int skb_tcp_all_headers(const struct sk_buff *skb)
|
|
|
|
|
{
|
|
|
|
|
return skb_transport_offset(skb) + tcp_hdrlen(skb);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* skb_inner_tcp_all_headers - Returns size of all headers for an encap TCP packet
|
|
|
|
|
* @skb: buffer
|
|
|
|
|
*
|
|
|
|
|
* Used in TX path, for a packet known to be a TCP one.
|
|
|
|
|
*
|
|
|
|
|
* if (skb_is_gso(skb) && skb->encapsulation) {
|
|
|
|
|
* int hlen = skb_inner_tcp_all_headers(skb);
|
|
|
|
|
* ...
|
|
|
|
|
*/
|
|
|
|
|
static inline int skb_inner_tcp_all_headers(const struct sk_buff *skb)
|
|
|
|
|
{
|
|
|
|
|
return skb_inner_transport_offset(skb) + inner_tcp_hdrlen(skb);
|
|
|
|
|
}
|
|
|
|
|
|
2007-03-19 00:43:48 +00:00
|
|
|
static inline unsigned int tcp_optlen(const struct sk_buff *skb)
|
|
|
|
|
{
|
2007-04-11 04:04:22 +00:00
|
|
|
return (tcp_hdr(skb)->doff - 5) * 4;
|
2007-03-19 00:43:48 +00:00
|
|
|
}
|
|
|
|
|
|
2012-07-19 06:43:05 +00:00
|
|
|
/* 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 */
|
2012-08-31 12:29:11 +00:00
|
|
|
#define TCP_FASTOPEN_COOKIE_SIZE 8 /* the size employed by this impl. */
|
2012-07-19 06:43:05 +00:00
|
|
|
|
|
|
|
|
/* TCP Fast Open Cookie as stored in memory */
|
|
|
|
|
struct tcp_fastopen_cookie {
|
2019-06-19 21:46:28 +00:00
|
|
|
__le64 val[DIV_ROUND_UP(TCP_FASTOPEN_COOKIE_MAX, sizeof(u64))];
|
2012-07-19 06:43:05 +00:00
|
|
|
s8 len;
|
2015-04-06 21:37:26 +00:00
|
|
|
bool exp; /* In RFC6994 experimental option format */
|
2012-07-19 06:43:05 +00:00
|
|
|
};
|
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/* This defines a selective acknowledgement block. */
|
2006-09-28 01:32:28 +00:00
|
|
|
struct tcp_sack_block_wire {
|
|
|
|
|
__be32 start_seq;
|
|
|
|
|
__be32 end_seq;
|
|
|
|
|
};
|
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
struct tcp_sack_block {
|
2006-11-28 03:12:38 +00:00
|
|
|
u32 start_seq;
|
|
|
|
|
u32 end_seq;
|
2005-04-16 22:20:36 +00:00
|
|
|
};
|
|
|
|
|
|
2011-12-20 13:23:24 +00:00
|
|
|
/*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_DSACK_SEEN (1 << 2) /*1 = DSACK was received from peer*/
|
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
struct tcp_options_received {
|
|
|
|
|
/* PAWS/RTTM data */
|
2018-07-11 10:16:12 +00:00
|
|
|
int ts_recent_stamp;/* Time we stored ts_recent (for aging) */
|
2006-11-28 03:12:38 +00:00
|
|
|
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 */
|
2005-04-16 22:20:36 +00:00
|
|
|
tstamp_ok : 1, /* TIMESTAMP seen on SYN packet */
|
|
|
|
|
dsack : 1, /* D-SACK is scheduled */
|
|
|
|
|
wscale_ok : 1, /* Wscale seen on SYN packet */
|
2017-10-25 09:01:45 +00:00
|
|
|
sack_ok : 3, /* SACK seen on SYN packet */
|
|
|
|
|
smc_ok : 1, /* SMC seen on SYN packet */
|
2005-04-16 22:20:36 +00:00
|
|
|
snd_wscale : 4, /* Window scaling received from sender */
|
|
|
|
|
rcv_wscale : 4; /* Window scaling to send to receiver */
|
2020-08-20 19:00:33 +00:00
|
|
|
u8 saw_unknown:1, /* Received unknown option */
|
|
|
|
|
unused:7;
|
2006-11-28 03:12:38 +00:00
|
|
|
u8 num_sacks; /* Number of SACK blocks */
|
TCPCT part 1d: define TCP cookie option, extend existing struct's
Data structures are carefully composed to require minimal additions.
For example, the struct tcp_options_received cookie_plus variable fits
between existing 16-bit and 8-bit variables, requiring no additional
space (taking alignment into consideration). There are no additions to
tcp_request_sock, and only 1 pointer in tcp_sock.
This is a significantly revised implementation of an earlier (year-old)
patch that no longer applies cleanly, with permission of the original
author (Adam Langley):
http://thread.gmane.org/gmane.linux.network/102586
The principle difference is using a TCP option to carry the cookie nonce,
instead of a user configured offset in the data. This is more flexible and
less subject to user configuration error. Such a cookie option has been
suggested for many years, and is also useful without SYN data, allowing
several related concepts to use the same extension option.
"Re: SYN floods (was: does history repeat itself?)", September 9, 1996.
http://www.merit.net/mail.archives/nanog/1996-09/msg00235.html
"Re: what a new TCP header might look like", May 12, 1998.
ftp://ftp.isi.edu/end2end/end2end-interest-1998.mail
These functions will also be used in subsequent patches that implement
additional features.
Requires:
TCPCT part 1a: add request_values parameter for sending SYNACK
TCPCT part 1b: generate Responder Cookie secret
TCPCT part 1c: sysctl_tcp_cookie_size, socket option TCP_COOKIE_TRANSACTIONS
Signed-off-by: William.Allen.Simpson@gmail.com
Signed-off-by: David S. Miller <davem@davemloft.net>
2009-12-02 18:17:05 +00:00
|
|
|
u16 user_mss; /* mss requested by user in ioctl */
|
2006-11-28 03:12:38 +00:00
|
|
|
u16 mss_clamp; /* Maximal mss, negotiated at connection setup */
|
2005-04-16 22:20:36 +00:00
|
|
|
};
|
|
|
|
|
|
2009-12-02 18:14:19 +00:00
|
|
|
static inline void tcp_clear_options(struct tcp_options_received *rx_opt)
|
|
|
|
|
{
|
TCPCT part 1d: define TCP cookie option, extend existing struct's
Data structures are carefully composed to require minimal additions.
For example, the struct tcp_options_received cookie_plus variable fits
between existing 16-bit and 8-bit variables, requiring no additional
space (taking alignment into consideration). There are no additions to
tcp_request_sock, and only 1 pointer in tcp_sock.
This is a significantly revised implementation of an earlier (year-old)
patch that no longer applies cleanly, with permission of the original
author (Adam Langley):
http://thread.gmane.org/gmane.linux.network/102586
The principle difference is using a TCP option to carry the cookie nonce,
instead of a user configured offset in the data. This is more flexible and
less subject to user configuration error. Such a cookie option has been
suggested for many years, and is also useful without SYN data, allowing
several related concepts to use the same extension option.
"Re: SYN floods (was: does history repeat itself?)", September 9, 1996.
http://www.merit.net/mail.archives/nanog/1996-09/msg00235.html
"Re: what a new TCP header might look like", May 12, 1998.
ftp://ftp.isi.edu/end2end/end2end-interest-1998.mail
These functions will also be used in subsequent patches that implement
additional features.
Requires:
TCPCT part 1a: add request_values parameter for sending SYNACK
TCPCT part 1b: generate Responder Cookie secret
TCPCT part 1c: sysctl_tcp_cookie_size, socket option TCP_COOKIE_TRANSACTIONS
Signed-off-by: William.Allen.Simpson@gmail.com
Signed-off-by: David S. Miller <davem@davemloft.net>
2009-12-02 18:17:05 +00:00
|
|
|
rx_opt->tstamp_ok = rx_opt->sack_ok = 0;
|
|
|
|
|
rx_opt->wscale_ok = rx_opt->snd_wscale = 0;
|
2017-10-25 09:01:45 +00:00
|
|
|
#if IS_ENABLED(CONFIG_SMC)
|
|
|
|
|
rx_opt->smc_ok = 0;
|
|
|
|
|
#endif
|
2009-12-02 18:14:19 +00:00
|
|
|
}
|
|
|
|
|
|
2008-07-19 07:07:02 +00:00
|
|
|
/* This is the max number of SACKS that we'll generate and process. It's safe
|
TCPCT part 1d: define TCP cookie option, extend existing struct's
Data structures are carefully composed to require minimal additions.
For example, the struct tcp_options_received cookie_plus variable fits
between existing 16-bit and 8-bit variables, requiring no additional
space (taking alignment into consideration). There are no additions to
tcp_request_sock, and only 1 pointer in tcp_sock.
This is a significantly revised implementation of an earlier (year-old)
patch that no longer applies cleanly, with permission of the original
author (Adam Langley):
http://thread.gmane.org/gmane.linux.network/102586
The principle difference is using a TCP option to carry the cookie nonce,
instead of a user configured offset in the data. This is more flexible and
less subject to user configuration error. Such a cookie option has been
suggested for many years, and is also useful without SYN data, allowing
several related concepts to use the same extension option.
"Re: SYN floods (was: does history repeat itself?)", September 9, 1996.
http://www.merit.net/mail.archives/nanog/1996-09/msg00235.html
"Re: what a new TCP header might look like", May 12, 1998.
ftp://ftp.isi.edu/end2end/end2end-interest-1998.mail
These functions will also be used in subsequent patches that implement
additional features.
Requires:
TCPCT part 1a: add request_values parameter for sending SYNACK
TCPCT part 1b: generate Responder Cookie secret
TCPCT part 1c: sysctl_tcp_cookie_size, socket option TCP_COOKIE_TRANSACTIONS
Signed-off-by: William.Allen.Simpson@gmail.com
Signed-off-by: David S. Miller <davem@davemloft.net>
2009-12-02 18:17:05 +00:00
|
|
|
* to increase this, although since:
|
2008-07-19 07:07:02 +00:00
|
|
|
* 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
|
|
|
|
|
|
TCPCT part 1d: define TCP cookie option, extend existing struct's
Data structures are carefully composed to require minimal additions.
For example, the struct tcp_options_received cookie_plus variable fits
between existing 16-bit and 8-bit variables, requiring no additional
space (taking alignment into consideration). There are no additions to
tcp_request_sock, and only 1 pointer in tcp_sock.
This is a significantly revised implementation of an earlier (year-old)
patch that no longer applies cleanly, with permission of the original
author (Adam Langley):
http://thread.gmane.org/gmane.linux.network/102586
The principle difference is using a TCP option to carry the cookie nonce,
instead of a user configured offset in the data. This is more flexible and
less subject to user configuration error. Such a cookie option has been
suggested for many years, and is also useful without SYN data, allowing
several related concepts to use the same extension option.
"Re: SYN floods (was: does history repeat itself?)", September 9, 1996.
http://www.merit.net/mail.archives/nanog/1996-09/msg00235.html
"Re: what a new TCP header might look like", May 12, 1998.
ftp://ftp.isi.edu/end2end/end2end-interest-1998.mail
These functions will also be used in subsequent patches that implement
additional features.
Requires:
TCPCT part 1a: add request_values parameter for sending SYNACK
TCPCT part 1b: generate Responder Cookie secret
TCPCT part 1c: sysctl_tcp_cookie_size, socket option TCP_COOKIE_TRANSACTIONS
Signed-off-by: William.Allen.Simpson@gmail.com
Signed-off-by: David S. Miller <davem@davemloft.net>
2009-12-02 18:17:05 +00:00
|
|
|
struct tcp_request_sock_ops;
|
|
|
|
|
|
[NET] Generalise TCP's struct open_request minisock infrastructure
Kept this first changeset minimal, without changing existing names to
ease peer review.
Basicaly tcp_openreq_alloc now receives the or_calltable, that in turn
has two new members:
->slab, that replaces tcp_openreq_cachep
->obj_size, to inform the size of the openreq descendant for
a specific protocol
The protocol specific fields in struct open_request were moved to a
class hierarchy, with the things that are common to all connection
oriented PF_INET protocols in struct inet_request_sock, the TCP ones
in tcp_request_sock, that is an inet_request_sock, that is an
open_request.
I.e. this uses the same approach used for the struct sock class
hierarchy, with sk_prot indicating if the protocol wants to use the
open_request infrastructure by filling in sk_prot->rsk_prot with an
or_calltable.
Results? Performance is improved and TCP v4 now uses only 64 bytes per
open request minisock, down from 96 without this patch :-)
Next changeset will rename some of the structs, fields and functions
mentioned above, struct or_calltable is way unclear, better name it
struct request_sock_ops, s/struct open_request/struct request_sock/g,
etc.
Signed-off-by: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
2005-06-19 05:46:52 +00:00
|
|
|
struct tcp_request_sock {
|
2006-11-15 03:07:45 +00:00
|
|
|
struct inet_request_sock req;
|
2009-09-01 19:25:03 +00:00
|
|
|
const struct tcp_request_sock_ops *af_specific;
|
2017-05-16 21:00:14 +00:00
|
|
|
u64 snt_synack; /* first SYNACK sent time */
|
2015-03-18 01:32:29 +00:00
|
|
|
bool tfo_listener;
|
2020-01-22 00:56:18 +00:00
|
|
|
bool is_mptcp;
|
2023-10-31 06:19:45 +00:00
|
|
|
bool req_usec_ts;
|
2020-05-15 17:22:15 +00:00
|
|
|
#if IS_ENABLED(CONFIG_MPTCP)
|
|
|
|
|
bool drop_req;
|
|
|
|
|
#endif
|
2015-09-15 22:24:20 +00:00
|
|
|
u32 txhash;
|
TCPCT part 1d: define TCP cookie option, extend existing struct's
Data structures are carefully composed to require minimal additions.
For example, the struct tcp_options_received cookie_plus variable fits
between existing 16-bit and 8-bit variables, requiring no additional
space (taking alignment into consideration). There are no additions to
tcp_request_sock, and only 1 pointer in tcp_sock.
This is a significantly revised implementation of an earlier (year-old)
patch that no longer applies cleanly, with permission of the original
author (Adam Langley):
http://thread.gmane.org/gmane.linux.network/102586
The principle difference is using a TCP option to carry the cookie nonce,
instead of a user configured offset in the data. This is more flexible and
less subject to user configuration error. Such a cookie option has been
suggested for many years, and is also useful without SYN data, allowing
several related concepts to use the same extension option.
"Re: SYN floods (was: does history repeat itself?)", September 9, 1996.
http://www.merit.net/mail.archives/nanog/1996-09/msg00235.html
"Re: what a new TCP header might look like", May 12, 1998.
ftp://ftp.isi.edu/end2end/end2end-interest-1998.mail
These functions will also be used in subsequent patches that implement
additional features.
Requires:
TCPCT part 1a: add request_values parameter for sending SYNACK
TCPCT part 1b: generate Responder Cookie secret
TCPCT part 1c: sysctl_tcp_cookie_size, socket option TCP_COOKIE_TRANSACTIONS
Signed-off-by: William.Allen.Simpson@gmail.com
Signed-off-by: David S. Miller <davem@davemloft.net>
2009-12-02 18:17:05 +00:00
|
|
|
u32 rcv_isn;
|
|
|
|
|
u32 snt_isn;
|
2016-12-01 10:32:06 +00:00
|
|
|
u32 ts_off;
|
2025-02-25 17:10:48 +00:00
|
|
|
u32 snt_tsval_first;
|
|
|
|
|
u32 snt_tsval_last;
|
tcp: mitigate ACK loops for connections as tcp_request_sock
In the SYN_RECV state, where the TCP connection is represented by
tcp_request_sock, we now rate-limit SYNACKs in response to a client's
retransmitted SYNs: we do not send a SYNACK in response to client SYN
if it has been less than sysctl_tcp_invalid_ratelimit (default 500ms)
since we last sent a SYNACK in response to a client's retransmitted
SYN.
This allows the vast majority of legitimate client connections to
proceed unimpeded, even for the most aggressive platforms, iOS and
MacOS, which actually retransmit SYNs 1-second intervals for several
times in a row. They use SYN RTO timeouts following the progression:
1,1,1,1,1,2,4,8,16,32.
Reported-by: Avery Fay <avery@mixpanel.com>
Signed-off-by: Neal Cardwell <ncardwell@google.com>
Signed-off-by: Yuchung Cheng <ycheng@google.com>
Signed-off-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2015-02-06 21:04:39 +00:00
|
|
|
u32 last_oow_ack_time; /* last SYNACK */
|
2012-08-31 12:29:11 +00:00
|
|
|
u32 rcv_nxt; /* the ack # by SYNACK. For
|
|
|
|
|
* FastOpen it's the seq#
|
|
|
|
|
* after data-in-SYN.
|
|
|
|
|
*/
|
2020-09-10 00:50:46 +00:00
|
|
|
u8 syn_tos;
|
2023-10-23 19:22:02 +00:00
|
|
|
#ifdef CONFIG_TCP_AO
|
|
|
|
|
u8 ao_keyid;
|
|
|
|
|
u8 ao_rcv_next;
|
2023-12-04 19:00:44 +00:00
|
|
|
bool used_tcp_ao;
|
2023-10-23 19:22:02 +00:00
|
|
|
#endif
|
[NET] Generalise TCP's struct open_request minisock infrastructure
Kept this first changeset minimal, without changing existing names to
ease peer review.
Basicaly tcp_openreq_alloc now receives the or_calltable, that in turn
has two new members:
->slab, that replaces tcp_openreq_cachep
->obj_size, to inform the size of the openreq descendant for
a specific protocol
The protocol specific fields in struct open_request were moved to a
class hierarchy, with the things that are common to all connection
oriented PF_INET protocols in struct inet_request_sock, the TCP ones
in tcp_request_sock, that is an inet_request_sock, that is an
open_request.
I.e. this uses the same approach used for the struct sock class
hierarchy, with sk_prot indicating if the protocol wants to use the
open_request infrastructure by filling in sk_prot->rsk_prot with an
or_calltable.
Results? Performance is improved and TCP v4 now uses only 64 bytes per
open request minisock, down from 96 without this patch :-)
Next changeset will rename some of the structs, fields and functions
mentioned above, struct or_calltable is way unclear, better name it
struct request_sock_ops, s/struct open_request/struct request_sock/g,
etc.
Signed-off-by: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
2005-06-19 05:46:52 +00:00
|
|
|
};
|
|
|
|
|
|
2005-06-19 05:47:21 +00:00
|
|
|
static inline struct tcp_request_sock *tcp_rsk(const struct request_sock *req)
|
[NET] Generalise TCP's struct open_request minisock infrastructure
Kept this first changeset minimal, without changing existing names to
ease peer review.
Basicaly tcp_openreq_alloc now receives the or_calltable, that in turn
has two new members:
->slab, that replaces tcp_openreq_cachep
->obj_size, to inform the size of the openreq descendant for
a specific protocol
The protocol specific fields in struct open_request were moved to a
class hierarchy, with the things that are common to all connection
oriented PF_INET protocols in struct inet_request_sock, the TCP ones
in tcp_request_sock, that is an inet_request_sock, that is an
open_request.
I.e. this uses the same approach used for the struct sock class
hierarchy, with sk_prot indicating if the protocol wants to use the
open_request infrastructure by filling in sk_prot->rsk_prot with an
or_calltable.
Results? Performance is improved and TCP v4 now uses only 64 bytes per
open request minisock, down from 96 without this patch :-)
Next changeset will rename some of the structs, fields and functions
mentioned above, struct or_calltable is way unclear, better name it
struct request_sock_ops, s/struct open_request/struct request_sock/g,
etc.
Signed-off-by: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
2005-06-19 05:46:52 +00:00
|
|
|
{
|
|
|
|
|
return (struct tcp_request_sock *)req;
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-23 19:22:02 +00:00
|
|
|
static inline bool tcp_rsk_used_ao(const struct request_sock *req)
|
|
|
|
|
{
|
|
|
|
|
#ifndef CONFIG_TCP_AO
|
|
|
|
|
return false;
|
|
|
|
|
#else
|
2023-12-04 19:00:44 +00:00
|
|
|
return tcp_rsk(req)->used_tcp_ao;
|
2023-10-23 19:22:02 +00:00
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
tcp: get rid of sysctl_tcp_adv_win_scale
With modern NIC drivers shifting to full page allocations per
received frame, we face the following issue:
TCP has one per-netns sysctl used to tweak how to translate
a memory use into an expected payload (RWIN), in RX path.
tcp_win_from_space() implementation is limited to few cases.
For hosts dealing with various MSS, we either under estimate
or over estimate the RWIN we send to the remote peers.
For instance with the default sysctl_tcp_adv_win_scale value,
we expect to store 50% of payload per allocated chunk of memory.
For the typical use of MTU=1500 traffic, and order-0 pages allocations
by NIC drivers, we are sending too big RWIN, leading to potential
tcp collapse operations, which are extremely expensive and source
of latency spikes.
This patch makes sysctl_tcp_adv_win_scale obsolete, and instead
uses a per socket scaling factor, so that we can precisely
adjust the RWIN based on effective skb->len/skb->truesize ratio.
This patch alone can double TCP receive performance when receivers
are too slow to drain their receive queue, or by allowing
a bigger RWIN when MSS is close to PAGE_SIZE.
Signed-off-by: Eric Dumazet <edumazet@google.com>
Acked-by: Soheil Hassas Yeganeh <soheil@google.com>
Link: https://lore.kernel.org/r/20230717152917.751987-1-edumazet@google.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2023-07-17 15:29:17 +00:00
|
|
|
#define TCP_RMEM_TO_WIN_SCALE 8
|
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
struct tcp_sock {
|
2023-12-04 20:12:31 +00:00
|
|
|
/* Cacheline organization can be found documented in
|
|
|
|
|
* Documentation/networking/net_cachelines/tcp_sock.rst.
|
|
|
|
|
* Please update the document when adding new fields.
|
|
|
|
|
*/
|
|
|
|
|
|
2005-08-10 03:10:42 +00:00
|
|
|
/* inet_connection_sock has to be the first member of tcp_sock */
|
|
|
|
|
struct inet_connection_sock inet_conn;
|
2023-12-04 20:12:31 +00:00
|
|
|
|
|
|
|
|
/* TX read-mostly hotpath cache lines */
|
|
|
|
|
__cacheline_group_begin(tcp_sock_read_tx);
|
|
|
|
|
u32 max_window; /* Maximal window ever seen from peer */
|
|
|
|
|
u32 rcv_ssthresh; /* Current window clamp */
|
|
|
|
|
u32 reordering; /* Packet reordering metric. */
|
|
|
|
|
u32 notsent_lowat; /* TCP_NOTSENT_LOWAT */
|
tcp: refine TSO autosizing
Commit 95bd09eb2750 ("tcp: TSO packets automatic sizing") tried to
control TSO size, but did this at the wrong place (sendmsg() time)
At sendmsg() time, we might have a pessimistic view of flow rate,
and we end up building very small skbs (with 2 MSS per skb).
This is bad because :
- It sends small TSO packets even in Slow Start where rate quickly
increases.
- It tends to make socket write queue very big, increasing tcp_ack()
processing time, but also increasing memory needs, not necessarily
accounted for, as fast clones overhead is currently ignored.
- Lower GRO efficiency and more ACK packets.
Servers with a lot of small lived connections suffer from this.
Lets instead fill skbs as much as possible (64KB of payload), but split
them at xmit time, when we have a precise idea of the flow rate.
skb split is actually quite efficient.
Patch looks bigger than necessary, because TCP Small Queue decision now
has to take place after the eventual split.
As Neal suggested, introduce a new tcp_tso_autosize() helper, so that
tcp_tso_should_defer() can be synchronized on same goal.
Rename tp->xmit_size_goal_segs to tp->gso_segs, as this variable
contains number of mss that we can put in GSO packet, and is not
related to the autosizing goal anymore.
Tested:
40 ms rtt link
nstat >/dev/null
netperf -H remote -l -2000000 -- -s 1000000
nstat | egrep "IpInReceives|IpOutRequests|TcpOutSegs|IpExtOutOctets"
Before patch :
Recv Send Send
Socket Socket Message Elapsed
Size Size Size Time Throughput
bytes bytes bytes secs. 10^6bits/s
87380 2000000 2000000 0.36 44.22
IpInReceives 600 0.0
IpOutRequests 599 0.0
TcpOutSegs 1397 0.0
IpExtOutOctets 2033249 0.0
After patch :
Recv Send Send
Socket Socket Message Elapsed
Size Size Size Time Throughput
bytes bytes bytes secs. 10^6bits/sec
87380 2000000 2000000 0.36 44.27
IpInReceives 221 0.0
IpOutRequests 232 0.0
TcpOutSegs 1397 0.0
IpExtOutOctets 2013953 0.0
Signed-off-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: Neal Cardwell <ncardwell@google.com>
Acked-by: Yuchung Cheng <ycheng@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2014-12-07 20:22:18 +00:00
|
|
|
u16 gso_segs; /* Max number of segs per GSO packet */
|
2023-12-04 20:12:31 +00:00
|
|
|
/* from STCP, retrans queue hinting */
|
|
|
|
|
struct sk_buff *lost_skb_hint;
|
|
|
|
|
struct sk_buff *retransmit_skb_hint;
|
|
|
|
|
__cacheline_group_end(tcp_sock_read_tx);
|
|
|
|
|
|
|
|
|
|
/* TXRX read-mostly hotpath cache lines */
|
|
|
|
|
__cacheline_group_begin(tcp_sock_read_txrx);
|
|
|
|
|
u32 tsoffset; /* timestamp offset */
|
|
|
|
|
u32 snd_wnd; /* The window we expect to receive */
|
|
|
|
|
u32 mss_cache; /* Cached effective mss, not including SACKS */
|
|
|
|
|
u32 snd_cwnd; /* Sending congestion window */
|
|
|
|
|
u32 prr_out; /* Total number of pkts sent during Recovery. */
|
|
|
|
|
u32 lost_out; /* Lost packets */
|
|
|
|
|
u32 sacked_out; /* SACK'd packets */
|
|
|
|
|
u16 tcp_header_len; /* Bytes of tcp header to send */
|
2024-02-08 14:43:21 +00:00
|
|
|
u8 scaling_ratio; /* see tcp_win_from_space() */
|
2023-12-04 20:12:31 +00:00
|
|
|
u8 chrono_type : 2, /* current chronograph type */
|
|
|
|
|
repair : 1,
|
2024-02-08 14:43:22 +00:00
|
|
|
tcp_usec_ts : 1, /* TSval values in usec */
|
2023-12-04 20:12:31 +00:00
|
|
|
is_sack_reneg:1, /* in recovery from loss with SACK reneg? */
|
|
|
|
|
is_cwnd_limited:1;/* forward progress limited by snd_cwnd? */
|
|
|
|
|
__cacheline_group_end(tcp_sock_read_txrx);
|
|
|
|
|
|
|
|
|
|
/* RX read-mostly hotpath cache lines */
|
|
|
|
|
__cacheline_group_begin(tcp_sock_read_rx);
|
|
|
|
|
u32 copied_seq; /* Head of yet unread data */
|
|
|
|
|
u32 rcv_tstamp; /* timestamp of last received ACK (for keepalives) */
|
|
|
|
|
u32 snd_wl1; /* Sequence for window update */
|
|
|
|
|
u32 tlp_high_seq; /* snd_nxt at the time of TLP */
|
|
|
|
|
u32 rttvar_us; /* smoothed mdev_max */
|
|
|
|
|
u32 retrans_out; /* Retransmitted packets out */
|
|
|
|
|
u16 advmss; /* Advertised MSS */
|
|
|
|
|
u16 urg_data; /* Saved octet of OOB data and control flags */
|
|
|
|
|
u32 lost; /* Total data packets lost incl. rexmits */
|
|
|
|
|
struct minmax rtt_min;
|
|
|
|
|
/* OOO segments go in this rbtree. Socket lock must be held. */
|
|
|
|
|
struct rb_root out_of_order_queue;
|
2025-03-17 08:53:13 +00:00
|
|
|
#if defined(CONFIG_TLS_DEVICE)
|
|
|
|
|
void (*tcp_clean_acked)(struct sock *sk, u32 acked_seq);
|
|
|
|
|
#endif
|
2023-12-04 20:12:31 +00:00
|
|
|
u32 snd_ssthresh; /* Slow start size threshold */
|
2024-04-05 10:29:26 +00:00
|
|
|
u8 recvmsg_inq : 1;/* Indicate # of bytes in queue upon recvmsg */
|
2023-12-04 20:12:31 +00:00
|
|
|
__cacheline_group_end(tcp_sock_read_rx);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2023-12-04 20:12:31 +00:00
|
|
|
/* TX read-write hotpath cache lines */
|
|
|
|
|
__cacheline_group_begin(tcp_sock_write_tx) ____cacheline_aligned;
|
|
|
|
|
u32 segs_out; /* RFC4898 tcpEStatsPerfSegsOut
|
|
|
|
|
* The total number of segments sent.
|
|
|
|
|
*/
|
|
|
|
|
u32 data_segs_out; /* RFC4898 tcpEStatsPerfDataSegsOut
|
|
|
|
|
* total number of data segments sent.
|
|
|
|
|
*/
|
|
|
|
|
u64 bytes_sent; /* RFC4898 tcpEStatsPerfHCDataOctetsOut
|
|
|
|
|
* total number of data bytes sent.
|
|
|
|
|
*/
|
|
|
|
|
u32 snd_sml; /* Last byte of the most recently transmitted small packet */
|
|
|
|
|
u32 chrono_start; /* Start time in jiffies of a TCP chrono */
|
|
|
|
|
u32 chrono_stat[3]; /* Time in jiffies for chrono_stat stats */
|
|
|
|
|
u32 write_seq; /* Tail(+1) of data held in tcp send buffer */
|
|
|
|
|
u32 pushed_seq; /* Last pushed seq, required to talk to windows */
|
2024-11-04 07:00:41 +00:00
|
|
|
u32 lsndtime; /* timestamp of last sent data packet (for restart window) */
|
2023-12-04 20:12:31 +00:00
|
|
|
u32 mdev_us; /* medium deviation */
|
tcp: remove some holes in struct tcp_sock
By moving some fields around, this patch shrinks
holes size from 56 to 32, saving 24 bytes on 64bit arches.
After the patch pahole gives the following for 'struct tcp_sock':
/* size: 2304, cachelines: 36, members: 162 */
/* sum members: 2234, holes: 6, sum holes: 32 */
/* sum bitfield members: 34 bits, bit holes: 5, sum bit holes: 14 bits */
/* padding: 32 */
/* paddings: 3, sum paddings: 10 */
/* forced alignments: 1, forced holes: 1, sum forced holes: 12 */
Signed-off-by: Eric Dumazet <edumazet@google.com>
Reviewed-by: Jiri Pirko <jiri@nvidia.com>
Link: https://lore.kernel.org/r/20240227192721.3558982-1-edumazet@google.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2024-02-27 19:27:21 +00:00
|
|
|
u32 rtt_seq; /* sequence number to update rttvar */
|
2023-12-04 20:12:31 +00:00
|
|
|
u64 tcp_wstamp_ns; /* departure time for next sent data packet */
|
|
|
|
|
struct list_head tsorted_sent_queue; /* time-sorted sent but un-SACKed skbs */
|
|
|
|
|
struct sk_buff *highest_sack; /* skb just after the highest
|
|
|
|
|
* skb with SACKed bit set
|
|
|
|
|
* (validity guaranteed only if
|
|
|
|
|
* sacked_out > 0)
|
|
|
|
|
*/
|
|
|
|
|
u8 ecn_flags; /* ECN status bits. */
|
|
|
|
|
__cacheline_group_end(tcp_sock_write_tx);
|
|
|
|
|
|
|
|
|
|
/* TXRX read-write hotpath cache lines */
|
|
|
|
|
__cacheline_group_begin(tcp_sock_write_txrx);
|
2017-08-30 17:24:58 +00:00
|
|
|
/*
|
|
|
|
|
* Header prediction flags
|
|
|
|
|
* 0x5?10 << 16 + snd_wnd in net byte order
|
|
|
|
|
*/
|
|
|
|
|
__be32 pred_flags;
|
2024-04-05 10:29:26 +00:00
|
|
|
u64 tcp_clock_cache; /* cache last tcp_clock_ns() (see tcp_mstamp_refresh()) */
|
|
|
|
|
u64 tcp_mstamp; /* most recent packet received/sent */
|
2023-12-04 20:12:31 +00:00
|
|
|
u32 rcv_nxt; /* What we want to receive next */
|
|
|
|
|
u32 snd_nxt; /* Next sequence we send */
|
|
|
|
|
u32 snd_una; /* First byte we want an ack for */
|
|
|
|
|
u32 window_clamp; /* Maximal window to advertise */
|
|
|
|
|
u32 srtt_us; /* smoothed round trip time << 3 in usecs */
|
|
|
|
|
u32 packets_out; /* Packets which are "in flight" */
|
|
|
|
|
u32 snd_up; /* Urgent pointer */
|
|
|
|
|
u32 delivered; /* Total data packets delivered incl. rexmits */
|
|
|
|
|
u32 delivered_ce; /* Like the above but only ECE marked packets */
|
|
|
|
|
u32 app_limited; /* limited until "delivered" reaches this val */
|
|
|
|
|
u32 rcv_wnd; /* Current receiver window */
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
2023-12-04 20:12:31 +00:00
|
|
|
* Options received (usually on last packet, some only on SYN packets).
|
2005-04-16 22:20:36 +00:00
|
|
|
*/
|
2023-12-04 20:12:31 +00:00
|
|
|
struct tcp_options_received rx_opt;
|
|
|
|
|
u8 nonagle : 4,/* Disable Nagle algorithm? */
|
|
|
|
|
rate_app_limited:1; /* rate_{delivered,interval_us} limited? */
|
|
|
|
|
__cacheline_group_end(tcp_sock_write_txrx);
|
|
|
|
|
|
|
|
|
|
/* RX read-write hotpath cache lines */
|
2024-03-01 17:19:45 +00:00
|
|
|
__cacheline_group_begin(tcp_sock_write_rx) __aligned(8);
|
2023-12-04 20:12:31 +00:00
|
|
|
u64 bytes_received;
|
|
|
|
|
/* RFC4898 tcpEStatsAppHCThruOctetsReceived
|
2015-04-28 22:28:18 +00:00
|
|
|
* sum(delta(rcv_nxt)), or how many bytes
|
|
|
|
|
* were acked.
|
|
|
|
|
*/
|
2015-05-20 23:35:41 +00:00
|
|
|
u32 segs_in; /* RFC4898 tcpEStatsPerfSegsIn
|
|
|
|
|
* total number of segments in.
|
|
|
|
|
*/
|
2016-03-14 17:52:15 +00:00
|
|
|
u32 data_segs_in; /* RFC4898 tcpEStatsPerfDataSegsIn
|
|
|
|
|
* total number of data segments in.
|
|
|
|
|
*/
|
2007-02-22 11:20:44 +00:00
|
|
|
u32 rcv_wup; /* rcv_nxt on last window update sent */
|
2023-12-04 20:12:31 +00:00
|
|
|
u32 max_packets_out; /* max packets_out in last window */
|
|
|
|
|
u32 cwnd_usage_seq; /* right edge of cwnd usage tracking flight */
|
|
|
|
|
u32 rate_delivered; /* saved rate sample: packets delivered */
|
|
|
|
|
u32 rate_interval_us; /* saved rate sample: time elapsed */
|
|
|
|
|
u32 rcv_rtt_last_tsecr;
|
|
|
|
|
u64 first_tx_mstamp; /* start of window send phase */
|
|
|
|
|
u64 delivered_mstamp; /* time we reached "delivered" */
|
2015-04-28 22:28:17 +00:00
|
|
|
u64 bytes_acked; /* RFC4898 tcpEStatsAppHCThruOctetsAcked
|
|
|
|
|
* sum(delta(snd_una)), or how many bytes
|
|
|
|
|
* were acked.
|
|
|
|
|
*/
|
2023-12-04 20:12:31 +00:00
|
|
|
struct {
|
|
|
|
|
u32 rtt_us;
|
|
|
|
|
u32 seq;
|
|
|
|
|
u64 time;
|
|
|
|
|
} rcv_rtt_est;
|
|
|
|
|
/* Receiver queue space */
|
|
|
|
|
struct {
|
2025-05-13 19:39:12 +00:00
|
|
|
int space;
|
2023-12-04 20:12:31 +00:00
|
|
|
u32 seq;
|
|
|
|
|
u64 time;
|
|
|
|
|
} rcvq_space;
|
|
|
|
|
__cacheline_group_end(tcp_sock_write_rx);
|
|
|
|
|
/* End of Hot Path */
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
2018-08-01 00:46:23 +00:00
|
|
|
u32 dsack_dups; /* RFC4898 tcpEStatsStackDSACKDups
|
|
|
|
|
* total number of DSACK blocks received
|
|
|
|
|
*/
|
2018-11-20 13:53:59 +00:00
|
|
|
u32 compressed_ack_rcv_nxt;
|
tcp: TCP Small Queues
This introduce TSQ (TCP Small Queues)
TSQ goal is to reduce number of TCP packets in xmit queues (qdisc &
device queues), to reduce RTT and cwnd bias, part of the bufferbloat
problem.
sk->sk_wmem_alloc not allowed to grow above a given limit,
allowing no more than ~128KB [1] per tcp socket in qdisc/dev layers at a
given time.
TSO packets are sized/capped to half the limit, so that we have two
TSO packets in flight, allowing better bandwidth use.
As a side effect, setting the limit to 40000 automatically reduces the
standard gso max limit (65536) to 40000/2 : It can help to reduce
latencies of high prio packets, having smaller TSO packets.
This means we divert sock_wfree() to a tcp_wfree() handler, to
queue/send following frames when skb_orphan() [2] is called for the
already queued skbs.
Results on my dev machines (tg3/ixgbe nics) are really impressive,
using standard pfifo_fast, and with or without TSO/GSO.
Without reduction of nominal bandwidth, we have reduction of buffering
per bulk sender :
< 1ms on Gbit (instead of 50ms with TSO)
< 8ms on 100Mbit (instead of 132 ms)
I no longer have 4 MBytes backlogged in qdisc by a single netperf
session, and both side socket autotuning no longer use 4 Mbytes.
As skb destructor cannot restart xmit itself ( as qdisc lock might be
taken at this point ), we delegate the work to a tasklet. We use one
tasklest per cpu for performance reasons.
If tasklet finds a socket owned by the user, it sets TSQ_OWNED flag.
This flag is tested in a new protocol method called from release_sock(),
to eventually send new segments.
[1] New /proc/sys/net/ipv4/tcp_limit_output_bytes tunable
[2] skb_orphan() is usually called at TX completion time,
but some drivers call it in their start_xmit() handler.
These drivers should at least use BQL, or else a single TCP
session can still fill the whole NIC TX ring, since TSQ will
have no effect.
Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Dave Taht <dave.taht@bufferbloat.net>
Cc: Tom Herbert <therbert@google.com>
Cc: Matt Mathis <mattmathis@google.com>
Cc: Yuchung Cheng <ycheng@google.com>
Cc: Nandita Dukkipati <nanditad@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2012-07-11 05:50:31 +00:00
|
|
|
struct list_head tsq_node; /* anchor in tsq_tasklet.head list */
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2015-10-17 04:57:46 +00:00
|
|
|
/* Information of the most recently (s)acked skb */
|
|
|
|
|
struct tcp_rack {
|
2017-05-16 21:00:14 +00:00
|
|
|
u64 mstamp; /* (Re)sent time of the skb */
|
2017-01-13 06:11:32 +00:00
|
|
|
u32 rtt_us; /* Associated RTT */
|
2017-01-13 06:11:34 +00:00
|
|
|
u32 end_seq; /* Ending TCP sequence of the skb */
|
2017-11-03 23:38:48 +00:00
|
|
|
u32 last_delivered; /* tp->delivered at last reo_wnd adj */
|
|
|
|
|
u8 reo_wnd_steps; /* Allowed reordering window */
|
|
|
|
|
#define TCP_RACK_RECOVERY_THRESH 16
|
|
|
|
|
u8 reo_wnd_persist:5, /* No. of recovery since last adj */
|
|
|
|
|
dsack_seen:1, /* Whether DSACK seen after last adj */
|
2018-08-01 00:46:24 +00:00
|
|
|
advanced:1; /* mstamp advanced since last lost marking */
|
2015-10-17 04:57:46 +00:00
|
|
|
} rack;
|
tcp: add SACK compression
When TCP receives an out-of-order packet, it immediately sends
a SACK packet, generating network load but also forcing the
receiver to send 1-MSS pathological packets, increasing its
RTX queue length/depth, and thus processing time.
Wifi networks suffer from this aggressive behavior, but generally
speaking, all these SACK packets add fuel to the fire when networks
are under congestion.
This patch adds a high resolution timer and tp->compressed_ack counter.
Instead of sending a SACK, we program this timer with a small delay,
based on RTT and capped to 1 ms :
delay = min ( 5 % of RTT, 1 ms)
If subsequent SACKs need to be sent while the timer has not yet
expired, we simply increment tp->compressed_ack.
When timer expires, a SACK is sent with the latest information.
Whenever an ACK is sent (if data is sent, or if in-order
data is received) timer is canceled.
Note that tcp_sack_new_ofo_skb() is able to force a SACK to be sent
if the sack blocks need to be shuffled, even if the timer has not
expired.
A new SNMP counter is added in the following patch.
Two other patches add sysctls to allow changing the 1,000,000 and 44
values that this commit hard-coded.
Signed-off-by: Eric Dumazet <edumazet@google.com>
Acked-by: Neal Cardwell <ncardwell@google.com>
Acked-by: Yuchung Cheng <ycheng@google.com>
Acked-by: Toke Høiland-Jørgensen <toke@toke.dk>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-05-17 21:47:26 +00:00
|
|
|
u8 compressed_ack;
|
2020-07-23 19:00:06 +00:00
|
|
|
u8 dup_ack_counter:2,
|
|
|
|
|
tlp_retrans:1, /* TLP is a retransmission */
|
2024-02-08 14:43:22 +00:00
|
|
|
unused:5;
|
2023-12-04 20:12:31 +00:00
|
|
|
u8 thin_lto : 1,/* Use linear timeouts for thin streams */
|
net/tcp-fastopen: Add new API support
This patch adds a new socket option, TCP_FASTOPEN_CONNECT, as an
alternative way to perform Fast Open on the active side (client). Prior
to this patch, a client needs to replace the connect() call with
sendto(MSG_FASTOPEN). This can be cumbersome for applications who want
to use Fast Open: these socket operations are often done in lower layer
libraries used by many other applications. Changing these libraries
and/or the socket call sequences are not trivial. A more convenient
approach is to perform Fast Open by simply enabling a socket option when
the socket is created w/o changing other socket calls sequence:
s = socket()
create a new socket
setsockopt(s, IPPROTO_TCP, TCP_FASTOPEN_CONNECT …);
newly introduced sockopt
If set, new functionality described below will be used.
Return ENOTSUPP if TFO is not supported or not enabled in the
kernel.
connect()
With cookie present, return 0 immediately.
With no cookie, initiate 3WHS with TFO cookie-request option and
return -1 with errno = EINPROGRESS.
write()/sendmsg()
With cookie present, send out SYN with data and return the number of
bytes buffered.
With no cookie, and 3WHS not yet completed, return -1 with errno =
EINPROGRESS.
No MSG_FASTOPEN flag is needed.
read()
Return -1 with errno = EWOULDBLOCK/EAGAIN if connect() is called but
write() is not called yet.
Return -1 with errno = EWOULDBLOCK/EAGAIN if connection is
established but no msg is received yet.
Return number of bytes read if socket is established and there is
msg received.
The new API simplifies life for applications that always perform a write()
immediately after a successful connect(). Such applications can now take
advantage of Fast Open by merely making one new setsockopt() call at the time
of creating the socket. Nothing else about the application's socket call
sequence needs to change.
Signed-off-by: Wei Wang <weiwan@google.com>
Acked-by: Eric Dumazet <edumazet@google.com>
Acked-by: Yuchung Cheng <ycheng@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2017-01-23 18:59:22 +00:00
|
|
|
fastopen_connect:1, /* FASTOPEN_CONNECT sockopt */
|
2017-10-23 20:22:23 +00:00
|
|
|
fastopen_no_cookie:1, /* Allow send/recv SYN+data without a cookie */
|
2023-12-04 20:12:31 +00:00
|
|
|
fastopen_client_fail:2, /* reason why fastopen failed */
|
2013-03-20 13:33:00 +00:00
|
|
|
frto : 1;/* F-RTO (RFC5682) activated in CA_Loss */
|
2012-04-19 03:40:39 +00:00
|
|
|
u8 repair_queue;
|
2020-08-20 19:01:23 +00:00
|
|
|
u8 save_syn:2, /* Save headers of SYN packet */
|
|
|
|
|
syn_data:1, /* SYN includes data */
|
2012-10-19 15:14:44 +00:00
|
|
|
syn_fastopen:1, /* SYN includes Fast Open option */
|
2015-04-06 21:37:27 +00:00
|
|
|
syn_fastopen_exp:1,/* SYN includes Fast Open exp. option */
|
net/tcp_fastopen: Disable active side TFO in certain scenarios
Middlebox firewall issues can potentially cause server's data being
blackholed after a successful 3WHS using TFO. Following are the related
reports from Apple:
https://www.nanog.org/sites/default/files/Paasch_Network_Support.pdf
Slide 31 identifies an issue where the client ACK to the server's data
sent during a TFO'd handshake is dropped.
C ---> syn-data ---> S
C <--- syn/ack ----- S
C (accept & write)
C <---- data ------- S
C ----- ACK -> X S
[retry and timeout]
https://www.ietf.org/proceedings/94/slides/slides-94-tcpm-13.pdf
Slide 5 shows a similar situation that the server's data gets dropped
after 3WHS.
C ---- syn-data ---> S
C <--- syn/ack ----- S
C ---- ack --------> S
S (accept & write)
C? X <- data ------ S
[retry and timeout]
This is the worst failure b/c the client can not detect such behavior to
mitigate the situation (such as disabling TFO). Failing to proceed, the
application (e.g., SSL library) may simply timeout and retry with TFO
again, and the process repeats indefinitely.
The proposed solution is to disable active TFO globally under the
following circumstances:
1. client side TFO socket detects out of order FIN
2. client side TFO socket receives out of order RST
We disable active side TFO globally for 1hr at first. Then if it
happens again, we disable it for 2h, then 4h, 8h, ...
And we reset the timeout to 1hr if a client side TFO sockets not opened
on loopback has successfully received data segs from server.
And we examine this condition during close().
The rational behind it is that when such firewall issue happens,
application running on the client should eventually close the socket as
it is not able to get the data it is expecting. Or application running
on the server should close the socket as it is not able to receive any
response from client.
In both cases, out of order FIN or RST will get received on the client
given that the firewall will not block them as no data are in those
frames.
And we want to disable active TFO globally as it helps if the middle box
is very close to the client and most of the connections are likely to
fail.
Also, add a debug sysctl:
tcp_fastopen_blackhole_detect_timeout_sec:
the initial timeout to use when firewall blackhole issue happens.
This can be set and read.
When setting it to 0, it means to disable the active disable logic.
Signed-off-by: Wei Wang <weiwan@google.com>
Acked-by: Yuchung Cheng <ycheng@google.com>
Acked-by: Neal Cardwell <ncardwell@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2017-04-20 21:45:46 +00:00
|
|
|
syn_fastopen_ch:1, /* Active TFO re-enabling probe */
|
2025-04-23 12:43:33 +00:00
|
|
|
syn_data_acked:1,/* data in SYN is acked by SYN-ACK */
|
|
|
|
|
syn_fastopen_child:1; /* created TFO passive child socket */
|
2005-04-16 22:20:36 +00:00
|
|
|
|
tcp: remove some holes in struct tcp_sock
By moving some fields around, this patch shrinks
holes size from 56 to 32, saving 24 bytes on 64bit arches.
After the patch pahole gives the following for 'struct tcp_sock':
/* size: 2304, cachelines: 36, members: 162 */
/* sum members: 2234, holes: 6, sum holes: 32 */
/* sum bitfield members: 34 bits, bit holes: 5, sum bit holes: 14 bits */
/* padding: 32 */
/* paddings: 3, sum paddings: 10 */
/* forced alignments: 1, forced holes: 1, sum forced holes: 12 */
Signed-off-by: Eric Dumazet <edumazet@google.com>
Reviewed-by: Jiri Pirko <jiri@nvidia.com>
Link: https://lore.kernel.org/r/20240227192721.3558982-1-edumazet@google.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2024-02-27 19:27:21 +00:00
|
|
|
u8 keepalive_probes; /* num of allowed keep alive probes */
|
tcp: add optional per socket transmit delay
Adding delays to TCP flows is crucial for studying behavior
of TCP stacks, including congestion control modules.
Linux offers netem module, but it has unpractical constraints :
- Need root access to change qdisc
- Hard to setup on egress if combined with non trivial qdisc like FQ
- Single delay for all flows.
EDT (Earliest Departure Time) adoption in TCP stack allows us
to enable a per socket delay at a very small cost.
Networking tools can now establish thousands of flows, each of them
with a different delay, simulating real world conditions.
This requires FQ packet scheduler or a EDT-enabled NIC.
This patchs adds TCP_TX_DELAY socket option, to set a delay in
usec units.
unsigned int tx_delay = 10000; /* 10 msec */
setsockopt(fd, SOL_TCP, TCP_TX_DELAY, &tx_delay, sizeof(tx_delay));
Note that FQ packet scheduler limits might need some tweaking :
man tc-fq
PARAMETERS
limit
Hard limit on the real queue size. When this limit is
reached, new packets are dropped. If the value is lowered,
packets are dropped so that the new limit is met. Default
is 10000 packets.
flow_limit
Hard limit on the maximum number of packets queued per
flow. Default value is 100.
Use of TCP_TX_DELAY option will increase number of skbs in FQ qdisc,
so packets would be dropped if any of the previous limit is hit.
Use of a jump label makes this support runtime-free, for hosts
never using the option.
Also note that TSQ (TCP Small Queues) limits are slightly changed
with this patch : we need to account that skbs artificially delayed
wont stop us providind more skbs to feed the pipe (netem uses
skb_orphan_partial() for this purpose, but FQ can not use this trick)
Because of that, using big delays might very well trigger
old bugs in TSO auto defer logic and/or sndbuf limited detection.
Signed-off-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2019-06-12 18:57:25 +00:00
|
|
|
u32 tcp_tx_delay; /* delay (in usec) added to TX packets */
|
2018-09-21 15:51:49 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/* RTT measurement */
|
2014-02-26 22:02:48 +00:00
|
|
|
u32 mdev_max_us; /* maximal mdev for the last rtt period */
|
2006-11-28 03:12:38 +00:00
|
|
|
|
2018-08-01 00:46:24 +00:00
|
|
|
u32 reord_seen; /* number of data packet reordering events */
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Slow start and congestion control (see also Nagle, and Karn & Partridge)
|
|
|
|
|
*/
|
2007-10-15 19:59:43 +00:00
|
|
|
u32 snd_cwnd_cnt; /* Linear increase counter */
|
2007-02-23 06:52:59 +00:00
|
|
|
u32 snd_cwnd_clamp; /* Do not allow snd_cwnd to grow above this */
|
2006-11-28 03:12:38 +00:00
|
|
|
u32 snd_cwnd_used;
|
|
|
|
|
u32 snd_cwnd_stamp;
|
2017-08-04 03:38:51 +00:00
|
|
|
u32 prior_cwnd; /* cwnd right before starting loss recovery */
|
2011-08-21 20:21:57 +00:00
|
|
|
u32 prr_delivered; /* Number of newly delivered packets to
|
|
|
|
|
* receiver in Recovery. */
|
tcp: remove some holes in struct tcp_sock
By moving some fields around, this patch shrinks
holes size from 56 to 32, saving 24 bytes on 64bit arches.
After the patch pahole gives the following for 'struct tcp_sock':
/* size: 2304, cachelines: 36, members: 162 */
/* sum members: 2234, holes: 6, sum holes: 32 */
/* sum bitfield members: 34 bits, bit holes: 5, sum bit holes: 14 bits */
/* padding: 32 */
/* paddings: 3, sum paddings: 10 */
/* forced alignments: 1, forced holes: 1, sum forced holes: 12 */
Signed-off-by: Eric Dumazet <edumazet@google.com>
Reviewed-by: Jiri Pirko <jiri@nvidia.com>
Link: https://lore.kernel.org/r/20240227192721.3558982-1-edumazet@google.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2024-02-27 19:27:21 +00:00
|
|
|
u32 last_oow_ack_time; /* timestamp of last out-of-window ACK */
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2017-05-16 11:24:36 +00:00
|
|
|
struct hrtimer pacing_timer;
|
tcp: add SACK compression
When TCP receives an out-of-order packet, it immediately sends
a SACK packet, generating network load but also forcing the
receiver to send 1-MSS pathological packets, increasing its
RTX queue length/depth, and thus processing time.
Wifi networks suffer from this aggressive behavior, but generally
speaking, all these SACK packets add fuel to the fire when networks
are under congestion.
This patch adds a high resolution timer and tp->compressed_ack counter.
Instead of sending a SACK, we program this timer with a small delay,
based on RTT and capped to 1 ms :
delay = min ( 5 % of RTT, 1 ms)
If subsequent SACKs need to be sent while the timer has not yet
expired, we simply increment tp->compressed_ack.
When timer expires, a SACK is sent with the latest information.
Whenever an ACK is sent (if data is sent, or if in-order
data is received) timer is canceled.
Note that tcp_sack_new_ofo_skb() is able to force a SACK to be sent
if the sack blocks need to be shuffled, even if the timer has not
expired.
A new SNMP counter is added in the following patch.
Two other patches add sysctls to allow changing the 1,000,000 and 44
values that this commit hard-coded.
Signed-off-by: Eric Dumazet <edumazet@google.com>
Acked-by: Neal Cardwell <ncardwell@google.com>
Acked-by: Yuchung Cheng <ycheng@google.com>
Acked-by: Toke Høiland-Jørgensen <toke@toke.dk>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-05-17 21:47:26 +00:00
|
|
|
struct hrtimer compressed_ack_timer;
|
2017-05-16 11:24:36 +00:00
|
|
|
|
tcp: use an RB tree for ooo receive queue
Over the years, TCP BDP has increased by several orders of magnitude,
and some people are considering to reach the 2 Gbytes limit.
Even with current window scale limit of 14, ~1 Gbytes maps to ~740,000
MSS.
In presence of packet losses (or reorders), TCP stores incoming packets
into an out of order queue, and number of skbs sitting there waiting for
the missing packets to be received can be in the 10^5 range.
Most packets are appended to the tail of this queue, and when
packets can finally be transferred to receive queue, we scan the queue
from its head.
However, in presence of heavy losses, we might have to find an arbitrary
point in this queue, involving a linear scan for every incoming packet,
throwing away cpu caches.
This patch converts it to a RB tree, to get bounded latencies.
Yaogong wrote a preliminary patch about 2 years ago.
Eric did the rebase, added ofo_last_skb cache, polishing and tests.
Tested with network dropping between 1 and 10 % packets, with good
success (about 30 % increase of throughput in stress tests)
Next step would be to also use an RB tree for the write queue at sender
side ;)
Signed-off-by: Yaogong Wang <wygivan@google.com>
Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Yuchung Cheng <ycheng@google.com>
Cc: Neal Cardwell <ncardwell@google.com>
Cc: Ilpo Järvinen <ilpo.jarvinen@helsinki.fi>
Acked-By: Ilpo Järvinen <ilpo.jarvinen@helsinki.fi>
Signed-off-by: David S. Miller <davem@davemloft.net>
2016-09-07 21:49:28 +00:00
|
|
|
struct sk_buff *ooo_last_skb; /* cache rb_last(out_of_order_queue) */
|
tcp: Reorganize tcp_sock to fill 64-bit holes & improve locality
I tried to group recovery related fields nearby (non-CA_Open related
variables, to be more accurate) so that one to three cachelines would
not be necessary in CA_Open. These are now contiguously deployed:
struct sk_buff_head out_of_order_queue; /* 1968 80 */
/* --- cacheline 32 boundary (2048 bytes) --- */
struct tcp_sack_block duplicate_sack[1]; /* 2048 8 */
struct tcp_sack_block selective_acks[4]; /* 2056 32 */
struct tcp_sack_block recv_sack_cache[4]; /* 2088 32 */
/* --- cacheline 33 boundary (2112 bytes) was 8 bytes ago --- */
struct sk_buff * highest_sack; /* 2120 8 */
int lost_cnt_hint; /* 2128 4 */
int retransmit_cnt_hint; /* 2132 4 */
u32 lost_retrans_low; /* 2136 4 */
u8 reordering; /* 2140 1 */
u8 keepalive_probes; /* 2141 1 */
/* XXX 2 bytes hole, try to pack */
u32 prior_ssthresh; /* 2144 4 */
u32 high_seq; /* 2148 4 */
u32 retrans_stamp; /* 2152 4 */
u32 undo_marker; /* 2156 4 */
int undo_retrans; /* 2160 4 */
u32 total_retrans; /* 2164 4 */
...and they're then followed by URG slowpath & keepalive related
variables.
Head of the out_of_order_queue always needed for empty checks, if
that's empty (and TCP is in CA_Open), following ~200 bytes (in 64-bit)
shouldn't be necessary for anything. If only OFO queue exists but TCP
is in CA_Open, selective_acks (and possibly duplicate_sack) are
necessary besides the out_of_order_queue but the rest of the block
again shouldn't be (ie., the other direction had losses).
As the cacheline boundaries depend on many factors in the preceeding
stuff, trying to align considering them doesn't make too much sense.
Commented one ordering hazard.
There are number of low utilized u8/16s that could be combined get 2
bytes less in total so that the hole could be made to vanish (includes
at least ecn_flags, urg_data, urg_mode, frto_counter, nonagle).
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@helsinki.fi>
Acked-by: Eric Dumazet <dada1@cosmosbay.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2008-05-29 10:25:23 +00:00
|
|
|
|
2012-05-07 19:33:04 +00:00
|
|
|
/* SACKs data, these 2 need to be together (see tcp_options_write) */
|
2005-04-16 22:20:36 +00:00
|
|
|
struct tcp_sack_block duplicate_sack[1]; /* D-SACK block */
|
|
|
|
|
struct tcp_sack_block selective_acks[4]; /* The SACKS themselves*/
|
|
|
|
|
|
2007-11-16 03:49:47 +00:00
|
|
|
struct tcp_sack_block recv_sack_cache[4];
|
2005-11-11 01:14:59 +00:00
|
|
|
|
|
|
|
|
int lost_cnt_hint;
|
|
|
|
|
|
2008-05-22 00:40:05 +00:00
|
|
|
u32 prior_ssthresh; /* ssthresh saved at recovery start */
|
2006-11-28 03:12:38 +00:00
|
|
|
u32 high_seq; /* snd_nxt at onset of congestion */
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2006-11-28 03:12:38 +00:00
|
|
|
u32 retrans_stamp; /* Timestamp of the last retransmit,
|
2005-04-16 22:20:36 +00:00
|
|
|
* also used in SYN-SENT to remember stamp of
|
|
|
|
|
* the first SYN. */
|
2014-08-22 21:15:22 +00:00
|
|
|
u32 undo_marker; /* snd_una upon a new recovery episode. */
|
2005-04-16 22:20:36 +00:00
|
|
|
int undo_retrans; /* number of undoable retransmissions. */
|
2018-08-01 00:46:22 +00:00
|
|
|
u64 bytes_retrans; /* RFC4898 tcpEStatsPerfOctetsRetrans
|
|
|
|
|
* Total data bytes retransmitted
|
|
|
|
|
*/
|
tcp: Reorganize tcp_sock to fill 64-bit holes & improve locality
I tried to group recovery related fields nearby (non-CA_Open related
variables, to be more accurate) so that one to three cachelines would
not be necessary in CA_Open. These are now contiguously deployed:
struct sk_buff_head out_of_order_queue; /* 1968 80 */
/* --- cacheline 32 boundary (2048 bytes) --- */
struct tcp_sack_block duplicate_sack[1]; /* 2048 8 */
struct tcp_sack_block selective_acks[4]; /* 2056 32 */
struct tcp_sack_block recv_sack_cache[4]; /* 2088 32 */
/* --- cacheline 33 boundary (2112 bytes) was 8 bytes ago --- */
struct sk_buff * highest_sack; /* 2120 8 */
int lost_cnt_hint; /* 2128 4 */
int retransmit_cnt_hint; /* 2132 4 */
u32 lost_retrans_low; /* 2136 4 */
u8 reordering; /* 2140 1 */
u8 keepalive_probes; /* 2141 1 */
/* XXX 2 bytes hole, try to pack */
u32 prior_ssthresh; /* 2144 4 */
u32 high_seq; /* 2148 4 */
u32 retrans_stamp; /* 2152 4 */
u32 undo_marker; /* 2156 4 */
int undo_retrans; /* 2160 4 */
u32 total_retrans; /* 2164 4 */
...and they're then followed by URG slowpath & keepalive related
variables.
Head of the out_of_order_queue always needed for empty checks, if
that's empty (and TCP is in CA_Open), following ~200 bytes (in 64-bit)
shouldn't be necessary for anything. If only OFO queue exists but TCP
is in CA_Open, selective_acks (and possibly duplicate_sack) are
necessary besides the out_of_order_queue but the rest of the block
again shouldn't be (ie., the other direction had losses).
As the cacheline boundaries depend on many factors in the preceeding
stuff, trying to align considering them doesn't make too much sense.
Commented one ordering hazard.
There are number of low utilized u8/16s that could be combined get 2
bytes less in total so that the hole could be made to vanish (includes
at least ecn_flags, urg_data, urg_mode, frto_counter, nonagle).
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@helsinki.fi>
Acked-by: Eric Dumazet <dada1@cosmosbay.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2008-05-29 10:25:23 +00:00
|
|
|
u32 total_retrans; /* Total retransmits for entire connection */
|
2023-09-14 14:36:21 +00:00
|
|
|
u32 rto_stamp; /* Start time (ms) of last CA_Loss recovery */
|
|
|
|
|
u16 total_rto; /* Total number of RTO timeouts, including
|
|
|
|
|
* SYN/SYN-ACK and recurring timeouts.
|
|
|
|
|
*/
|
|
|
|
|
u16 total_rto_recoveries; /* Total number of RTO recoveries,
|
|
|
|
|
* including any unfinished recovery.
|
|
|
|
|
*/
|
|
|
|
|
u32 total_rto_time; /* ms spent in (completed) RTO recoveries. */
|
tcp: Reorganize tcp_sock to fill 64-bit holes & improve locality
I tried to group recovery related fields nearby (non-CA_Open related
variables, to be more accurate) so that one to three cachelines would
not be necessary in CA_Open. These are now contiguously deployed:
struct sk_buff_head out_of_order_queue; /* 1968 80 */
/* --- cacheline 32 boundary (2048 bytes) --- */
struct tcp_sack_block duplicate_sack[1]; /* 2048 8 */
struct tcp_sack_block selective_acks[4]; /* 2056 32 */
struct tcp_sack_block recv_sack_cache[4]; /* 2088 32 */
/* --- cacheline 33 boundary (2112 bytes) was 8 bytes ago --- */
struct sk_buff * highest_sack; /* 2120 8 */
int lost_cnt_hint; /* 2128 4 */
int retransmit_cnt_hint; /* 2132 4 */
u32 lost_retrans_low; /* 2136 4 */
u8 reordering; /* 2140 1 */
u8 keepalive_probes; /* 2141 1 */
/* XXX 2 bytes hole, try to pack */
u32 prior_ssthresh; /* 2144 4 */
u32 high_seq; /* 2148 4 */
u32 retrans_stamp; /* 2152 4 */
u32 undo_marker; /* 2156 4 */
int undo_retrans; /* 2160 4 */
u32 total_retrans; /* 2164 4 */
...and they're then followed by URG slowpath & keepalive related
variables.
Head of the out_of_order_queue always needed for empty checks, if
that's empty (and TCP is in CA_Open), following ~200 bytes (in 64-bit)
shouldn't be necessary for anything. If only OFO queue exists but TCP
is in CA_Open, selective_acks (and possibly duplicate_sack) are
necessary besides the out_of_order_queue but the rest of the block
again shouldn't be (ie., the other direction had losses).
As the cacheline boundaries depend on many factors in the preceeding
stuff, trying to align considering them doesn't make too much sense.
Commented one ordering hazard.
There are number of low utilized u8/16s that could be combined get 2
bytes less in total so that the hole could be made to vanish (includes
at least ecn_flags, urg_data, urg_mode, frto_counter, nonagle).
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@helsinki.fi>
Acked-by: Eric Dumazet <dada1@cosmosbay.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2008-05-29 10:25:23 +00:00
|
|
|
|
2006-11-28 03:12:38 +00:00
|
|
|
u32 urg_seq; /* Seq of received urgent pointer */
|
2005-04-16 22:20:36 +00:00
|
|
|
unsigned int keepalive_time; /* time before keep alive takes place */
|
|
|
|
|
unsigned int keepalive_intvl; /* time interval between keep alive probes */
|
|
|
|
|
|
2009-04-19 09:43:48 +00:00
|
|
|
int linger2;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2018-01-26 00:14:10 +00:00
|
|
|
|
|
|
|
|
/* Sock_ops bpf program related variables */
|
|
|
|
|
#ifdef CONFIG_BPF
|
|
|
|
|
u8 bpf_sock_ops_cb_flags; /* Control calling BPF programs
|
|
|
|
|
* values defined in uapi/linux/tcp.h
|
|
|
|
|
*/
|
2022-09-29 07:04:06 +00:00
|
|
|
u8 bpf_chg_cc_inprogress:1; /* In the middle of
|
|
|
|
|
* bpf_setsockopt(TCP_CONGESTION),
|
|
|
|
|
* it is to avoid the bpf_tcp_cc->init()
|
|
|
|
|
* to recur itself by calling
|
|
|
|
|
* bpf_setsockopt(TCP_CONGESTION, "itself").
|
|
|
|
|
*/
|
2018-01-26 00:14:10 +00:00
|
|
|
#define BPF_SOCK_OPS_TEST_FLAG(TP, ARG) (TP->bpf_sock_ops_cb_flags & ARG)
|
|
|
|
|
#else
|
|
|
|
|
#define BPF_SOCK_OPS_TEST_FLAG(TP, ARG) 0
|
|
|
|
|
#endif
|
|
|
|
|
|
2020-01-24 21:34:02 +00:00
|
|
|
u16 timeout_rehash; /* Timeout-triggered rehash attempts */
|
|
|
|
|
|
2019-09-13 23:23:34 +00:00
|
|
|
u32 rcv_ooopack; /* Received out-of-order packets, for tcpinfo */
|
|
|
|
|
|
2006-03-21 05:32:58 +00:00
|
|
|
/* TCP-specific MTU probe information. */
|
|
|
|
|
struct {
|
2006-11-28 03:12:38 +00:00
|
|
|
u32 probe_seq_start;
|
|
|
|
|
u32 probe_seq_end;
|
2006-03-21 05:32:58 +00:00
|
|
|
} mtu_probe;
|
2022-10-26 13:51:14 +00:00
|
|
|
u32 plb_rehash; /* PLB-triggered rehash attempts */
|
2012-07-23 07:48:52 +00:00
|
|
|
u32 mtu_info; /* We received an ICMP_FRAG_NEEDED / ICMPV6_PKT_TOOBIG
|
|
|
|
|
* while socket was owned by user.
|
|
|
|
|
*/
|
2020-01-22 00:56:17 +00:00
|
|
|
#if IS_ENABLED(CONFIG_MPTCP)
|
|
|
|
|
bool is_mptcp;
|
|
|
|
|
#endif
|
2020-08-20 19:01:23 +00:00
|
|
|
#if IS_ENABLED(CONFIG_SMC)
|
|
|
|
|
bool syn_smc; /* SYN includes SMC */
|
tcp: remove some holes in struct tcp_sock
By moving some fields around, this patch shrinks
holes size from 56 to 32, saving 24 bytes on 64bit arches.
After the patch pahole gives the following for 'struct tcp_sock':
/* size: 2304, cachelines: 36, members: 162 */
/* sum members: 2234, holes: 6, sum holes: 32 */
/* sum bitfield members: 34 bits, bit holes: 5, sum bit holes: 14 bits */
/* padding: 32 */
/* paddings: 3, sum paddings: 10 */
/* forced alignments: 1, forced holes: 1, sum forced holes: 12 */
Signed-off-by: Eric Dumazet <edumazet@google.com>
Reviewed-by: Jiri Pirko <jiri@nvidia.com>
Link: https://lore.kernel.org/r/20240227192721.3558982-1-edumazet@google.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2024-02-27 19:27:21 +00:00
|
|
|
bool (*smc_hs_congested)(const struct sock *sk);
|
2020-08-20 19:01:23 +00:00
|
|
|
#endif
|
2006-11-15 03:07:45 +00:00
|
|
|
|
2023-10-23 19:21:54 +00:00
|
|
|
#if defined(CONFIG_TCP_MD5SIG) || defined(CONFIG_TCP_AO)
|
|
|
|
|
/* TCP AF-Specific parts; only used by TCP-AO/MD5 Signature support so far */
|
2009-09-01 19:25:03 +00:00
|
|
|
const struct tcp_sock_af_ops *af_specific;
|
2006-11-15 03:07:45 +00:00
|
|
|
|
2023-10-23 19:21:54 +00:00
|
|
|
#ifdef CONFIG_TCP_MD5SIG
|
2009-09-01 19:25:03 +00:00
|
|
|
/* TCP MD5 Signature Option information */
|
2012-01-31 18:45:40 +00:00
|
|
|
struct tcp_md5sig_info __rcu *md5sig_info;
|
2006-11-15 03:07:45 +00:00
|
|
|
#endif
|
2023-10-23 19:21:54 +00:00
|
|
|
#ifdef CONFIG_TCP_AO
|
|
|
|
|
struct tcp_ao_info __rcu *ao_info;
|
|
|
|
|
#endif
|
|
|
|
|
#endif
|
TCPCT part 1d: define TCP cookie option, extend existing struct's
Data structures are carefully composed to require minimal additions.
For example, the struct tcp_options_received cookie_plus variable fits
between existing 16-bit and 8-bit variables, requiring no additional
space (taking alignment into consideration). There are no additions to
tcp_request_sock, and only 1 pointer in tcp_sock.
This is a significantly revised implementation of an earlier (year-old)
patch that no longer applies cleanly, with permission of the original
author (Adam Langley):
http://thread.gmane.org/gmane.linux.network/102586
The principle difference is using a TCP option to carry the cookie nonce,
instead of a user configured offset in the data. This is more flexible and
less subject to user configuration error. Such a cookie option has been
suggested for many years, and is also useful without SYN data, allowing
several related concepts to use the same extension option.
"Re: SYN floods (was: does history repeat itself?)", September 9, 1996.
http://www.merit.net/mail.archives/nanog/1996-09/msg00235.html
"Re: what a new TCP header might look like", May 12, 1998.
ftp://ftp.isi.edu/end2end/end2end-interest-1998.mail
These functions will also be used in subsequent patches that implement
additional features.
Requires:
TCPCT part 1a: add request_values parameter for sending SYNACK
TCPCT part 1b: generate Responder Cookie secret
TCPCT part 1c: sysctl_tcp_cookie_size, socket option TCP_COOKIE_TRANSACTIONS
Signed-off-by: William.Allen.Simpson@gmail.com
Signed-off-by: David S. Miller <davem@davemloft.net>
2009-12-02 18:17:05 +00:00
|
|
|
|
2012-08-31 12:29:11 +00:00
|
|
|
/* 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.
|
|
|
|
|
*/
|
2019-10-11 03:17:38 +00:00
|
|
|
struct request_sock __rcu *fastopen_rsk;
|
2020-08-20 19:00:14 +00:00
|
|
|
struct saved_syn *saved_syn;
|
2005-04-16 22:20:36 +00:00
|
|
|
};
|
|
|
|
|
|
2016-12-03 19:14:50 +00:00
|
|
|
enum tsq_enum {
|
tcp: TCP Small Queues
This introduce TSQ (TCP Small Queues)
TSQ goal is to reduce number of TCP packets in xmit queues (qdisc &
device queues), to reduce RTT and cwnd bias, part of the bufferbloat
problem.
sk->sk_wmem_alloc not allowed to grow above a given limit,
allowing no more than ~128KB [1] per tcp socket in qdisc/dev layers at a
given time.
TSO packets are sized/capped to half the limit, so that we have two
TSO packets in flight, allowing better bandwidth use.
As a side effect, setting the limit to 40000 automatically reduces the
standard gso max limit (65536) to 40000/2 : It can help to reduce
latencies of high prio packets, having smaller TSO packets.
This means we divert sock_wfree() to a tcp_wfree() handler, to
queue/send following frames when skb_orphan() [2] is called for the
already queued skbs.
Results on my dev machines (tg3/ixgbe nics) are really impressive,
using standard pfifo_fast, and with or without TSO/GSO.
Without reduction of nominal bandwidth, we have reduction of buffering
per bulk sender :
< 1ms on Gbit (instead of 50ms with TSO)
< 8ms on 100Mbit (instead of 132 ms)
I no longer have 4 MBytes backlogged in qdisc by a single netperf
session, and both side socket autotuning no longer use 4 Mbytes.
As skb destructor cannot restart xmit itself ( as qdisc lock might be
taken at this point ), we delegate the work to a tasklet. We use one
tasklest per cpu for performance reasons.
If tasklet finds a socket owned by the user, it sets TSQ_OWNED flag.
This flag is tested in a new protocol method called from release_sock(),
to eventually send new segments.
[1] New /proc/sys/net/ipv4/tcp_limit_output_bytes tunable
[2] skb_orphan() is usually called at TX completion time,
but some drivers call it in their start_xmit() handler.
These drivers should at least use BQL, or else a single TCP
session can still fill the whole NIC TX ring, since TSQ will
have no effect.
Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Dave Taht <dave.taht@bufferbloat.net>
Cc: Tom Herbert <therbert@google.com>
Cc: Matt Mathis <mattmathis@google.com>
Cc: Yuchung Cheng <ycheng@google.com>
Cc: Nandita Dukkipati <nanditad@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2012-07-11 05:50:31 +00:00
|
|
|
TSQ_THROTTLED,
|
|
|
|
|
TSQ_QUEUED,
|
2012-07-20 05:45:50 +00:00
|
|
|
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 */
|
2012-07-23 07:48:52 +00:00
|
|
|
TCP_MTU_REDUCED_DEFERRED, /* tcp_v{4|6}_err() could not call
|
|
|
|
|
* tcp_v{4|6}_mtu_reduced()
|
|
|
|
|
*/
|
tcp: defer regular ACK while processing socket backlog
This idea came after a particular workload requested
the quickack attribute set on routes, and a performance
drop was noticed for large bulk transfers.
For high throughput flows, it is best to use one cpu
running the user thread issuing socket system calls,
and a separate cpu to process incoming packets from BH context.
(With TSO/GRO, bottleneck is usually the 'user' cpu)
Problem is the user thread can spend a lot of time while holding
the socket lock, forcing BH handler to queue most of incoming
packets in the socket backlog.
Whenever the user thread releases the socket lock, it must first
process all accumulated packets in the backlog, potentially
adding latency spikes. Due to flood mitigation, having too many
packets in the backlog increases chance of unexpected drops.
Backlog processing unfortunately shifts a fair amount of cpu cycles
from the BH cpu to the 'user' cpu, thus reducing max throughput.
This patch takes advantage of the backlog processing,
and the fact that ACK are mostly cumulative.
The idea is to detect we are in the backlog processing
and defer all eligible ACK into a single one,
sent from tcp_release_cb().
This saves cpu cycles on both sides, and network resources.
Performance of a single TCP flow on a 200Gbit NIC:
- Throughput is increased by 20% (100Gbit -> 120Gbit).
- Number of generated ACK per second shrinks from 240,000 to 40,000.
- Number of backlog drops per second shrinks from 230 to 0.
Benchmark context:
- Regular netperf TCP_STREAM (no zerocopy)
- Intel(R) Xeon(R) Platinum 8481C (Saphire Rapids)
- MAX_SKB_FRAGS = 17 (~60KB per GRO packet)
This feature is guarded by a new sysctl, and enabled by default:
/proc/sys/net/ipv4/tcp_backlog_ack_defer
Signed-off-by: Eric Dumazet <edumazet@google.com>
Acked-by: Yuchung Cheng <ycheng@google.com>
Acked-by: Neal Cardwell <ncardwell@google.com>
Acked-by: Soheil Hassas Yeganeh <soheil@google.com>
Acked-by: Dave Taht <dave.taht@gmail.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
2023-09-11 17:05:31 +00:00
|
|
|
TCP_ACK_DEFERRED, /* TX pure ack is deferred */
|
tcp: TCP Small Queues
This introduce TSQ (TCP Small Queues)
TSQ goal is to reduce number of TCP packets in xmit queues (qdisc &
device queues), to reduce RTT and cwnd bias, part of the bufferbloat
problem.
sk->sk_wmem_alloc not allowed to grow above a given limit,
allowing no more than ~128KB [1] per tcp socket in qdisc/dev layers at a
given time.
TSO packets are sized/capped to half the limit, so that we have two
TSO packets in flight, allowing better bandwidth use.
As a side effect, setting the limit to 40000 automatically reduces the
standard gso max limit (65536) to 40000/2 : It can help to reduce
latencies of high prio packets, having smaller TSO packets.
This means we divert sock_wfree() to a tcp_wfree() handler, to
queue/send following frames when skb_orphan() [2] is called for the
already queued skbs.
Results on my dev machines (tg3/ixgbe nics) are really impressive,
using standard pfifo_fast, and with or without TSO/GSO.
Without reduction of nominal bandwidth, we have reduction of buffering
per bulk sender :
< 1ms on Gbit (instead of 50ms with TSO)
< 8ms on 100Mbit (instead of 132 ms)
I no longer have 4 MBytes backlogged in qdisc by a single netperf
session, and both side socket autotuning no longer use 4 Mbytes.
As skb destructor cannot restart xmit itself ( as qdisc lock might be
taken at this point ), we delegate the work to a tasklet. We use one
tasklest per cpu for performance reasons.
If tasklet finds a socket owned by the user, it sets TSQ_OWNED flag.
This flag is tested in a new protocol method called from release_sock(),
to eventually send new segments.
[1] New /proc/sys/net/ipv4/tcp_limit_output_bytes tunable
[2] skb_orphan() is usually called at TX completion time,
but some drivers call it in their start_xmit() handler.
These drivers should at least use BQL, or else a single TCP
session can still fill the whole NIC TX ring, since TSQ will
have no effect.
Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Dave Taht <dave.taht@bufferbloat.net>
Cc: Tom Herbert <therbert@google.com>
Cc: Matt Mathis <mattmathis@google.com>
Cc: Yuchung Cheng <ycheng@google.com>
Cc: Nandita Dukkipati <nanditad@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2012-07-11 05:50:31 +00:00
|
|
|
};
|
|
|
|
|
|
2016-12-03 19:14:50 +00:00
|
|
|
enum tsq_flags {
|
tcp: defer regular ACK while processing socket backlog
This idea came after a particular workload requested
the quickack attribute set on routes, and a performance
drop was noticed for large bulk transfers.
For high throughput flows, it is best to use one cpu
running the user thread issuing socket system calls,
and a separate cpu to process incoming packets from BH context.
(With TSO/GRO, bottleneck is usually the 'user' cpu)
Problem is the user thread can spend a lot of time while holding
the socket lock, forcing BH handler to queue most of incoming
packets in the socket backlog.
Whenever the user thread releases the socket lock, it must first
process all accumulated packets in the backlog, potentially
adding latency spikes. Due to flood mitigation, having too many
packets in the backlog increases chance of unexpected drops.
Backlog processing unfortunately shifts a fair amount of cpu cycles
from the BH cpu to the 'user' cpu, thus reducing max throughput.
This patch takes advantage of the backlog processing,
and the fact that ACK are mostly cumulative.
The idea is to detect we are in the backlog processing
and defer all eligible ACK into a single one,
sent from tcp_release_cb().
This saves cpu cycles on both sides, and network resources.
Performance of a single TCP flow on a 200Gbit NIC:
- Throughput is increased by 20% (100Gbit -> 120Gbit).
- Number of generated ACK per second shrinks from 240,000 to 40,000.
- Number of backlog drops per second shrinks from 230 to 0.
Benchmark context:
- Regular netperf TCP_STREAM (no zerocopy)
- Intel(R) Xeon(R) Platinum 8481C (Saphire Rapids)
- MAX_SKB_FRAGS = 17 (~60KB per GRO packet)
This feature is guarded by a new sysctl, and enabled by default:
/proc/sys/net/ipv4/tcp_backlog_ack_defer
Signed-off-by: Eric Dumazet <edumazet@google.com>
Acked-by: Yuchung Cheng <ycheng@google.com>
Acked-by: Neal Cardwell <ncardwell@google.com>
Acked-by: Soheil Hassas Yeganeh <soheil@google.com>
Acked-by: Dave Taht <dave.taht@gmail.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
2023-09-11 17:05:31 +00:00
|
|
|
TSQF_THROTTLED = BIT(TSQ_THROTTLED),
|
|
|
|
|
TSQF_QUEUED = BIT(TSQ_QUEUED),
|
|
|
|
|
TCPF_TSQ_DEFERRED = BIT(TCP_TSQ_DEFERRED),
|
|
|
|
|
TCPF_WRITE_TIMER_DEFERRED = BIT(TCP_WRITE_TIMER_DEFERRED),
|
|
|
|
|
TCPF_DELACK_TIMER_DEFERRED = BIT(TCP_DELACK_TIMER_DEFERRED),
|
|
|
|
|
TCPF_MTU_REDUCED_DEFERRED = BIT(TCP_MTU_REDUCED_DEFERRED),
|
|
|
|
|
TCPF_ACK_DEFERRED = BIT(TCP_ACK_DEFERRED),
|
2016-12-03 19:14:50 +00:00
|
|
|
};
|
|
|
|
|
|
2023-03-17 15:55:39 +00:00
|
|
|
#define tcp_sk(ptr) container_of_const(ptr, struct tcp_sock, inet_conn.icsk_inet.sk)
|
|
|
|
|
|
|
|
|
|
/* Variant of tcp_sk() upgrading a const sock to a read/write tcp socket.
|
|
|
|
|
* Used in context of (lockless) tcp listeners.
|
|
|
|
|
*/
|
|
|
|
|
#define tcp_sk_rw(ptr) container_of(ptr, struct tcp_sock, inet_conn.icsk_inet.sk)
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2005-08-10 03:09:30 +00:00
|
|
|
struct tcp_timewait_sock {
|
|
|
|
|
struct inet_timewait_sock tw_sk;
|
2015-10-09 02:33:24 +00:00
|
|
|
#define tw_rcv_nxt tw_sk.__tw_common.skc_tw_rcv_nxt
|
|
|
|
|
#define tw_snd_nxt tw_sk.__tw_common.skc_tw_snd_nxt
|
2006-11-28 03:12:38 +00:00
|
|
|
u32 tw_rcv_wnd;
|
2013-02-11 05:50:17 +00:00
|
|
|
u32 tw_ts_offset;
|
2006-11-28 03:12:38 +00:00
|
|
|
u32 tw_ts_recent;
|
2015-02-06 21:04:41 +00:00
|
|
|
|
|
|
|
|
/* The time we sent the last out-of-window ACK: */
|
|
|
|
|
u32 tw_last_oow_ack_time;
|
|
|
|
|
|
2018-07-11 10:16:12 +00:00
|
|
|
int tw_ts_recent_stamp;
|
tcp: add optional per socket transmit delay
Adding delays to TCP flows is crucial for studying behavior
of TCP stacks, including congestion control modules.
Linux offers netem module, but it has unpractical constraints :
- Need root access to change qdisc
- Hard to setup on egress if combined with non trivial qdisc like FQ
- Single delay for all flows.
EDT (Earliest Departure Time) adoption in TCP stack allows us
to enable a per socket delay at a very small cost.
Networking tools can now establish thousands of flows, each of them
with a different delay, simulating real world conditions.
This requires FQ packet scheduler or a EDT-enabled NIC.
This patchs adds TCP_TX_DELAY socket option, to set a delay in
usec units.
unsigned int tx_delay = 10000; /* 10 msec */
setsockopt(fd, SOL_TCP, TCP_TX_DELAY, &tx_delay, sizeof(tx_delay));
Note that FQ packet scheduler limits might need some tweaking :
man tc-fq
PARAMETERS
limit
Hard limit on the real queue size. When this limit is
reached, new packets are dropped. If the value is lowered,
packets are dropped so that the new limit is met. Default
is 10000 packets.
flow_limit
Hard limit on the maximum number of packets queued per
flow. Default value is 100.
Use of TCP_TX_DELAY option will increase number of skbs in FQ qdisc,
so packets would be dropped if any of the previous limit is hit.
Use of a jump label makes this support runtime-free, for hosts
never using the option.
Also note that TSQ (TCP Small Queues) limits are slightly changed
with this patch : we need to account that skbs artificially delayed
wont stop us providind more skbs to feed the pipe (netem uses
skb_orphan_partial() for this purpose, but FQ can not use this trick)
Because of that, using big delays might very well trigger
old bugs in TSO auto defer logic and/or sndbuf limited detection.
Signed-off-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2019-06-12 18:57:25 +00:00
|
|
|
u32 tw_tx_delay;
|
2006-11-15 03:07:45 +00:00
|
|
|
#ifdef CONFIG_TCP_MD5SIG
|
2012-06-09 21:56:12 +00:00
|
|
|
struct tcp_md5sig_key *tw_md5_key;
|
2006-11-15 03:07:45 +00:00
|
|
|
#endif
|
2023-10-23 19:22:01 +00:00
|
|
|
#ifdef CONFIG_TCP_AO
|
|
|
|
|
struct tcp_ao_info __rcu *ao_info;
|
|
|
|
|
#endif
|
2005-08-10 03:09:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static inline struct tcp_timewait_sock *tcp_twsk(const struct sock *sk)
|
|
|
|
|
{
|
|
|
|
|
return (struct tcp_timewait_sock *)sk;
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-31 12:29:11 +00:00
|
|
|
static inline bool tcp_passive_fastopen(const struct sock *sk)
|
|
|
|
|
{
|
2019-10-11 03:17:38 +00:00
|
|
|
return sk->sk_state == TCP_SYN_RECV &&
|
|
|
|
|
rcu_access_pointer(tcp_sk(sk)->fastopen_rsk) != NULL;
|
2012-08-31 12:29:11 +00:00
|
|
|
}
|
|
|
|
|
|
2015-09-29 14:42:52 +00:00
|
|
|
static inline void fastopen_queue_tune(struct sock *sk, int backlog)
|
2012-08-31 12:29:11 +00:00
|
|
|
{
|
2015-09-29 14:42:52 +00:00
|
|
|
struct request_sock_queue *queue = &inet_csk(sk)->icsk_accept_queue;
|
2015-10-20 20:17:40 +00:00
|
|
|
int somaxconn = READ_ONCE(sock_net(sk)->core.sysctl_somaxconn);
|
2015-09-29 14:42:52 +00:00
|
|
|
|
2023-07-19 21:28:57 +00:00
|
|
|
WRITE_ONCE(queue->fastopenq.max_qlen, min_t(unsigned int, backlog, somaxconn));
|
2012-08-31 12:29:11 +00:00
|
|
|
}
|
|
|
|
|
|
2015-11-05 19:07:13 +00:00
|
|
|
static inline void tcp_move_syn(struct tcp_sock *tp,
|
|
|
|
|
struct request_sock *req)
|
|
|
|
|
{
|
|
|
|
|
tp->saved_syn = req->saved_syn;
|
|
|
|
|
req->saved_syn = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-04 04:34:46 +00:00
|
|
|
static inline void tcp_saved_syn_free(struct tcp_sock *tp)
|
|
|
|
|
{
|
|
|
|
|
kfree(tp->saved_syn);
|
|
|
|
|
tp->saved_syn = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-20 19:00:14 +00:00
|
|
|
static inline u32 tcp_saved_syn_len(const struct saved_syn *saved_syn)
|
|
|
|
|
{
|
2020-08-20 19:01:23 +00:00
|
|
|
return saved_syn->mac_hdrlen + saved_syn->network_hdrlen +
|
|
|
|
|
saved_syn->tcp_hdrlen;
|
2020-08-20 19:00:14 +00:00
|
|
|
}
|
|
|
|
|
|
2020-07-30 22:44:40 +00:00
|
|
|
struct sk_buff *tcp_get_timestamping_opt_stats(const struct sock *sk,
|
2021-01-20 20:41:55 +00:00
|
|
|
const struct sk_buff *orig_skb,
|
|
|
|
|
const struct sk_buff *ack_skb);
|
2016-11-28 07:07:18 +00:00
|
|
|
|
2017-02-02 16:04:56 +00:00
|
|
|
static inline u16 tcp_mss_clamp(const struct tcp_sock *tp, u16 mss)
|
|
|
|
|
{
|
|
|
|
|
/* We use READ_ONCE() here because socket might not be locked.
|
|
|
|
|
* This happens for listeners.
|
|
|
|
|
*/
|
|
|
|
|
u16 user_mss = READ_ONCE(tp->rx_opt.user_mss);
|
|
|
|
|
|
|
|
|
|
return (user_mss && user_mss < mss) ? user_mss : mss;
|
|
|
|
|
}
|
2019-05-18 00:17:22 +00:00
|
|
|
|
|
|
|
|
int tcp_skb_shift(struct sk_buff *to, struct sk_buff *from, int pcount,
|
|
|
|
|
int shiftlen);
|
|
|
|
|
|
2021-12-03 22:35:39 +00:00
|
|
|
void __tcp_sock_set_cork(struct sock *sk, bool on);
|
2020-05-28 05:12:18 +00:00
|
|
|
void tcp_sock_set_cork(struct sock *sk, bool on);
|
2020-05-28 05:12:25 +00:00
|
|
|
int tcp_sock_set_keepcnt(struct sock *sk, int val);
|
2020-06-20 15:30:51 +00:00
|
|
|
int tcp_sock_set_keepidle_locked(struct sock *sk, int val);
|
2020-05-28 05:12:23 +00:00
|
|
|
int tcp_sock_set_keepidle(struct sock *sk, int val);
|
2020-05-28 05:12:24 +00:00
|
|
|
int tcp_sock_set_keepintvl(struct sock *sk, int val);
|
2021-12-03 22:35:39 +00:00
|
|
|
void __tcp_sock_set_nodelay(struct sock *sk, bool on);
|
2020-05-28 05:12:19 +00:00
|
|
|
void tcp_sock_set_nodelay(struct sock *sk);
|
2020-05-28 05:12:20 +00:00
|
|
|
void tcp_sock_set_quickack(struct sock *sk, int val);
|
2020-05-28 05:12:21 +00:00
|
|
|
int tcp_sock_set_syncnt(struct sock *sk, int val);
|
2023-08-04 14:46:12 +00:00
|
|
|
int tcp_sock_set_user_timeout(struct sock *sk, int val);
|
2020-05-28 05:12:18 +00:00
|
|
|
|
2023-10-20 12:57:45 +00:00
|
|
|
static inline bool dst_tcp_usec_ts(const struct dst_entry *dst)
|
|
|
|
|
{
|
|
|
|
|
return dst_feature(dst, RTAX_FEATURE_TCP_USEC_TS);
|
|
|
|
|
}
|
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
#endif /* _LINUX_TCP_H */
|