2019-05-27 14:55:01 +08:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
2005-08-10 11:10:42 +08:00
|
|
|
/*
|
|
|
|
* NET Generic infrastructure for INET connection oriented protocols.
|
|
|
|
*
|
|
|
|
* Definitions for inet_connection_sock
|
|
|
|
*
|
|
|
|
* Authors: Many people, see the TCP sources
|
|
|
|
*
|
|
|
|
* From code originally in TCP
|
|
|
|
*/
|
|
|
|
#ifndef _INET_CONNECTION_SOCK_H
|
|
|
|
#define _INET_CONNECTION_SOCK_H
|
|
|
|
|
2005-12-14 15:15:52 +08:00
|
|
|
#include <linux/compiler.h>
|
2005-08-10 11:11:08 +08:00
|
|
|
#include <linux/string.h>
|
2005-08-10 11:10:42 +08:00
|
|
|
#include <linux/timer.h>
|
2006-10-20 05:23:57 +08:00
|
|
|
#include <linux/poll.h>
|
2018-08-02 05:57:59 +08:00
|
|
|
#include <linux/kernel.h>
|
2005-12-27 12:43:12 +08:00
|
|
|
|
|
|
|
#include <net/inet_sock.h>
|
2005-08-10 11:10:42 +08:00
|
|
|
#include <net/request_sock.h>
|
|
|
|
|
2005-08-10 11:11:08 +08:00
|
|
|
/* Cancel timers, when they are not required. */
|
|
|
|
#undef INET_CSK_CLEAR_TIMERS
|
|
|
|
|
2005-08-10 11:10:42 +08:00
|
|
|
struct inet_bind_bucket;
|
2005-08-10 15:03:31 +08:00
|
|
|
struct tcp_congestion_ops;
|
2005-08-10 11:10:42 +08:00
|
|
|
|
2005-12-14 15:15:52 +08:00
|
|
|
/*
|
|
|
|
* Pointers to address related TCP functions
|
|
|
|
* (i.e. things that depend on the address family)
|
|
|
|
*/
|
|
|
|
struct inet_connection_sock_af_ops {
|
2014-04-16 00:58:34 +08:00
|
|
|
int (*queue_xmit)(struct sock *sk, struct sk_buff *skb, struct flowi *fl);
|
2010-04-11 10:15:55 +08:00
|
|
|
void (*send_check)(struct sock *sk, struct sk_buff *skb);
|
2005-12-14 15:15:52 +08:00
|
|
|
int (*rebuild_header)(struct sock *sk);
|
2012-08-06 13:09:33 +08:00
|
|
|
void (*sk_rx_dst_set)(struct sock *sk, const struct sk_buff *skb);
|
2005-12-14 15:15:52 +08:00
|
|
|
int (*conn_request)(struct sock *sk, struct sk_buff *skb);
|
2015-09-29 22:42:48 +08:00
|
|
|
struct sock *(*syn_recv_sock)(const struct sock *sk, struct sk_buff *skb,
|
2005-12-14 15:15:52 +08:00
|
|
|
struct request_sock *req,
|
2015-10-22 23:20:46 +08:00
|
|
|
struct dst_entry *dst,
|
|
|
|
struct request_sock *req_unhash,
|
|
|
|
bool *own_req);
|
[INET_CONNECTION_SOCK]: Pack struct inet_connection_sock_af_ops
We have a hole in:
[acme@newtoy net-2.6.20]$ pahole net/ipv6/tcp_ipv6.o inet_connection_sock_af_ops
/* /pub/scm/linux/kernel/git/acme/net-2.6.20/include/net/inet_connection_sock.h:38 */
struct inet_connection_sock_af_ops {
int (*queue_xmit)(); /* 0 4 */
void (*send_check)(); /* 4 4 */
int (*rebuild_header)(); /* 8 4 */
int (*conn_request)(); /* 12 4 */
struct sock * (*syn_recv_sock)(); /* 16 4 */
int (*remember_stamp)(); /* 20 4 */
__u16 net_header_len; /* 24 2 */
/* XXX 2 bytes hole, try to pack */
int (*setsockopt)(); /* 28 4 */
int (*getsockopt)(); /* 32 4 */
int (*compat_setsockopt)(); /* 36 4 */
int (*compat_getsockopt)(); /* 40 4 */
void (*addr2sockaddr)(); /* 44 4 */
int sockaddr_len; /* 48 4 */
}; /* size: 52, sum members: 50, holes: 1, sum holes: 2 */
But we don't need sockaddr_len to be an int:
[acme@newtoy net-2.6.20]$ find net -name "*.[ch]" | xargs grep '\.sockaddr_len.\+=' | sort -u
net/dccp/ipv4.c: .sockaddr_len = sizeof(struct sockaddr_in),
net/dccp/ipv6.c: .sockaddr_len = sizeof(struct sockaddr_in6),
net/ipv4/tcp_ipv4.c: .sockaddr_len = sizeof(struct sockaddr_in),
net/ipv6/tcp_ipv6.c: .sockaddr_len = sizeof(struct sockaddr_in6),
net/sctp/ipv6.c: .sockaddr_len = sizeof(struct sockaddr_in6),
net/sctp/protocol.c: .sockaddr_len = sizeof(struct sockaddr_in),
[acme@newtoy net-2.6.20]$ pahole --sizes net/ipv6/tcp_ipv6.o | grep sockaddr_in
struct sockaddr_in: 16 0
struct sockaddr_in6: 28 0
[acme@newtoy net-2.6.20]$
So I turned sockaddr_len a 'u16', and now:
[acme@newtoy net-2.6.20]$ pahole net/ipv6/tcp_ipv6.o inet_connection_sock_af_ops
/* /pub/scm/linux/kernel/git/acme/net-2.6.20/include/net/inet_connection_sock.h:38 */
struct inet_connection_sock_af_ops {
int (*queue_xmit)(); /* 0 4 */
void (*send_check)(); /* 4 4 */
int (*rebuild_header)(); /* 8 4 */
int (*conn_request)(); /* 12 4 */
struct sock * (*syn_recv_sock)(); /* 16 4 */
int (*remember_stamp)(); /* 20 4 */
u16 net_header_len; /* 24 2 */
u16 sockaddr_len; /* 26 2 */
int (*setsockopt)(); /* 28 4 */
int (*getsockopt)(); /* 32 4 */
int (*compat_setsockopt)(); /* 36 4 */
int (*compat_getsockopt)(); /* 40 4 */
void (*addr2sockaddr)(); /* 44 4 */
}; /* size: 48 */
So we've saved 4 bytes:
[acme@newtoy net-2.6.20]$ codiff -sV /tmp/tcp_ipv6.o.before net/ipv6/tcp_ipv6.o
/pub/scm/linux/kernel/git/acme/net-2.6.20/net/ipv6/tcp_ipv6.c:
struct inet_connection_sock_af_ops | -4
net_header_len;
from: __u16 /* 24(0) 2(0) */
to: u16 /* 24(0) 2(0) */
sockaddr_len;
from: int /* 48(0) 4(0) */
to: u16 /* 26(0) 2(0) */
1 struct changed
[acme@newtoy net-2.6.20]$
Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-11-28 03:56:43 +08:00
|
|
|
u16 net_header_len;
|
ipv6: RTAX_FEATURE_ALLFRAG causes inefficient TCP segment sizing
Quoting Tore Anderson from :
https://bugzilla.kernel.org/show_bug.cgi?id=42572
When RTAX_FEATURE_ALLFRAG is set on a route, the effective TCP segment
size does not take into account the size of the IPv6 Fragmentation
header that needs to be included in outbound packets, causing every
transmitted TCP segment to be fragmented across two IPv6 packets, the
latter of which will only contain 8 bytes of actual payload.
RTAX_FEATURE_ALLFRAG is typically set on a route in response to
receving a ICMPv6 Packet Too Big message indicating a Path MTU of less
than 1280 bytes. 1280 bytes is the minimum IPv6 MTU, however ICMPv6
PTBs with MTU < 1280 are still valid, in particular when an IPv6
packet is sent to an IPv4 destination through a stateless translator.
Any ICMPv4 Need To Fragment packets originated from the IPv4 part of
the path will be translated to ICMPv6 PTB which may then indicate an
MTU of less than 1280.
The Linux kernel refuses to reduce the effective MTU to anything below
1280 bytes, instead it sets it to exactly 1280 bytes, and
RTAX_FEATURE_ALLFRAG is also set. However, the TCP segment size appears
to be set to 1240 bytes (1280 Path MTU - 40 bytes of IPv6 header),
instead of 1232 (additionally taking into account the 8 bytes required
by the IPv6 Fragmentation extension header).
This in turn results in rather inefficient transmission, as every
transmitted TCP segment now is split in two fragments containing
1232+8 bytes of payload.
After this patch, all the outgoing packets that includes a
Fragmentation header all are "atomic" or "non-fragmented" fragments,
i.e., they both have Offset=0 and More Fragments=0.
With help from David S. Miller
Reported-by: Tore Anderson <tore@fud.no>
Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Maciej Żenczykowski <maze@google.com>
Cc: Tom Herbert <therbert@google.com>
Tested-by: Tore Anderson <tore@fud.no>
Signed-off-by: David S. Miller <davem@davemloft.net>
2012-04-24 15:37:38 +08:00
|
|
|
u16 net_frag_header_len;
|
[INET_CONNECTION_SOCK]: Pack struct inet_connection_sock_af_ops
We have a hole in:
[acme@newtoy net-2.6.20]$ pahole net/ipv6/tcp_ipv6.o inet_connection_sock_af_ops
/* /pub/scm/linux/kernel/git/acme/net-2.6.20/include/net/inet_connection_sock.h:38 */
struct inet_connection_sock_af_ops {
int (*queue_xmit)(); /* 0 4 */
void (*send_check)(); /* 4 4 */
int (*rebuild_header)(); /* 8 4 */
int (*conn_request)(); /* 12 4 */
struct sock * (*syn_recv_sock)(); /* 16 4 */
int (*remember_stamp)(); /* 20 4 */
__u16 net_header_len; /* 24 2 */
/* XXX 2 bytes hole, try to pack */
int (*setsockopt)(); /* 28 4 */
int (*getsockopt)(); /* 32 4 */
int (*compat_setsockopt)(); /* 36 4 */
int (*compat_getsockopt)(); /* 40 4 */
void (*addr2sockaddr)(); /* 44 4 */
int sockaddr_len; /* 48 4 */
}; /* size: 52, sum members: 50, holes: 1, sum holes: 2 */
But we don't need sockaddr_len to be an int:
[acme@newtoy net-2.6.20]$ find net -name "*.[ch]" | xargs grep '\.sockaddr_len.\+=' | sort -u
net/dccp/ipv4.c: .sockaddr_len = sizeof(struct sockaddr_in),
net/dccp/ipv6.c: .sockaddr_len = sizeof(struct sockaddr_in6),
net/ipv4/tcp_ipv4.c: .sockaddr_len = sizeof(struct sockaddr_in),
net/ipv6/tcp_ipv6.c: .sockaddr_len = sizeof(struct sockaddr_in6),
net/sctp/ipv6.c: .sockaddr_len = sizeof(struct sockaddr_in6),
net/sctp/protocol.c: .sockaddr_len = sizeof(struct sockaddr_in),
[acme@newtoy net-2.6.20]$ pahole --sizes net/ipv6/tcp_ipv6.o | grep sockaddr_in
struct sockaddr_in: 16 0
struct sockaddr_in6: 28 0
[acme@newtoy net-2.6.20]$
So I turned sockaddr_len a 'u16', and now:
[acme@newtoy net-2.6.20]$ pahole net/ipv6/tcp_ipv6.o inet_connection_sock_af_ops
/* /pub/scm/linux/kernel/git/acme/net-2.6.20/include/net/inet_connection_sock.h:38 */
struct inet_connection_sock_af_ops {
int (*queue_xmit)(); /* 0 4 */
void (*send_check)(); /* 4 4 */
int (*rebuild_header)(); /* 8 4 */
int (*conn_request)(); /* 12 4 */
struct sock * (*syn_recv_sock)(); /* 16 4 */
int (*remember_stamp)(); /* 20 4 */
u16 net_header_len; /* 24 2 */
u16 sockaddr_len; /* 26 2 */
int (*setsockopt)(); /* 28 4 */
int (*getsockopt)(); /* 32 4 */
int (*compat_setsockopt)(); /* 36 4 */
int (*compat_getsockopt)(); /* 40 4 */
void (*addr2sockaddr)(); /* 44 4 */
}; /* size: 48 */
So we've saved 4 bytes:
[acme@newtoy net-2.6.20]$ codiff -sV /tmp/tcp_ipv6.o.before net/ipv6/tcp_ipv6.o
/pub/scm/linux/kernel/git/acme/net-2.6.20/net/ipv6/tcp_ipv6.c:
struct inet_connection_sock_af_ops | -4
net_header_len;
from: __u16 /* 24(0) 2(0) */
to: u16 /* 24(0) 2(0) */
sockaddr_len;
from: int /* 48(0) 4(0) */
to: u16 /* 26(0) 2(0) */
1 struct changed
[acme@newtoy net-2.6.20]$
Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-11-28 03:56:43 +08:00
|
|
|
u16 sockaddr_len;
|
2018-02-28 07:48:21 +08:00
|
|
|
int (*setsockopt)(struct sock *sk, int level, int optname,
|
2009-10-01 07:12:20 +08:00
|
|
|
char __user *optval, unsigned int optlen);
|
2018-02-28 07:48:21 +08:00
|
|
|
int (*getsockopt)(struct sock *sk, int level, int optname,
|
2005-12-14 15:15:52 +08:00
|
|
|
char __user *optval, int __user *optlen);
|
2008-08-28 17:53:51 +08:00
|
|
|
#ifdef CONFIG_COMPAT
|
2006-03-21 14:45:21 +08:00
|
|
|
int (*compat_setsockopt)(struct sock *sk,
|
|
|
|
int level, int optname,
|
2009-10-01 07:12:20 +08:00
|
|
|
char __user *optval, unsigned int optlen);
|
2006-03-21 14:45:21 +08:00
|
|
|
int (*compat_getsockopt)(struct sock *sk,
|
|
|
|
int level, int optname,
|
|
|
|
char __user *optval, int __user *optlen);
|
2008-08-28 17:53:51 +08:00
|
|
|
#endif
|
2005-12-14 15:15:52 +08:00
|
|
|
void (*addr2sockaddr)(struct sock *sk, struct sockaddr *);
|
2014-08-15 00:40:05 +08:00
|
|
|
void (*mtu_reduced)(struct sock *sk);
|
2005-12-14 15:15:52 +08:00
|
|
|
};
|
|
|
|
|
2005-08-10 11:10:42 +08:00
|
|
|
/** inet_connection_sock - INET connection oriented sock
|
|
|
|
*
|
2018-02-28 07:48:21 +08:00
|
|
|
* @icsk_accept_queue: FIFO of established children
|
2005-08-10 11:10:42 +08:00
|
|
|
* @icsk_bind_hash: Bind node
|
|
|
|
* @icsk_timeout: Timeout
|
|
|
|
* @icsk_retransmit_timer: Resend (no ack)
|
|
|
|
* @icsk_rto: Retransmit timeout
|
2005-12-14 15:26:10 +08:00
|
|
|
* @icsk_pmtu_cookie Last pmtu seen by socket
|
2005-08-10 15:03:31 +08:00
|
|
|
* @icsk_ca_ops Pluggable congestion control hook
|
2005-12-14 15:15:52 +08:00
|
|
|
* @icsk_af_ops Operations which are AF_INET{4,6} specific
|
2017-06-15 02:37:14 +08:00
|
|
|
* @icsk_ulp_ops Pluggable ULP control hook
|
|
|
|
* @icsk_ulp_data ULP private data
|
2018-04-30 15:16:10 +08:00
|
|
|
* @icsk_clean_acked Clean acked data hook
|
2017-12-02 04:52:31 +08:00
|
|
|
* @icsk_listen_portaddr_node hash to the portaddr listener hashtable
|
2005-08-10 15:03:31 +08:00
|
|
|
* @icsk_ca_state: Congestion control state
|
2005-08-10 11:10:42 +08:00
|
|
|
* @icsk_retransmits: Number of unrecovered [RTO] timeouts
|
|
|
|
* @icsk_pending: Scheduled timer event
|
|
|
|
* @icsk_backoff: Backoff
|
|
|
|
* @icsk_syn_retries: Number of allowed SYN (or equivalent) retries
|
2005-08-10 15:03:31 +08:00
|
|
|
* @icsk_probes_out: unanswered 0 window probes
|
2005-12-14 15:26:10 +08:00
|
|
|
* @icsk_ext_hdr_len: Network protocol overhead (IP/IPv6 options)
|
2005-08-10 11:10:42 +08:00
|
|
|
* @icsk_ack: Delayed ACK control data
|
2006-03-21 09:53:41 +08:00
|
|
|
* @icsk_mtup; MTU probing control data
|
2005-08-10 11:10:42 +08:00
|
|
|
*/
|
|
|
|
struct inet_connection_sock {
|
|
|
|
/* inet_sock has to be the first member! */
|
|
|
|
struct inet_sock icsk_inet;
|
|
|
|
struct request_sock_queue icsk_accept_queue;
|
|
|
|
struct inet_bind_bucket *icsk_bind_hash;
|
|
|
|
unsigned long icsk_timeout;
|
|
|
|
struct timer_list icsk_retransmit_timer;
|
|
|
|
struct timer_list icsk_delack_timer;
|
|
|
|
__u32 icsk_rto;
|
2005-12-14 15:26:10 +08:00
|
|
|
__u32 icsk_pmtu_cookie;
|
2006-01-10 07:56:09 +08:00
|
|
|
const struct tcp_congestion_ops *icsk_ca_ops;
|
|
|
|
const struct inet_connection_sock_af_ops *icsk_af_ops;
|
2017-06-15 02:37:14 +08:00
|
|
|
const struct tcp_ulp_ops *icsk_ulp_ops;
|
2019-08-30 18:25:47 +08:00
|
|
|
void __rcu *icsk_ulp_data;
|
2018-04-30 15:16:10 +08:00
|
|
|
void (*icsk_clean_acked)(struct sock *sk, u32 acked_seq);
|
2017-12-02 04:52:31 +08:00
|
|
|
struct hlist_node icsk_listen_portaddr_node;
|
2005-12-14 15:26:10 +08:00
|
|
|
unsigned int (*icsk_sync_mss)(struct sock *sk, u32 pmtu);
|
2015-05-30 01:47:07 +08:00
|
|
|
__u8 icsk_ca_state:6,
|
|
|
|
icsk_ca_setsockopt:1,
|
net: tcp: add key management to congestion control
This patch adds necessary infrastructure to the congestion control
framework for later per route congestion control support.
For a per route congestion control possibility, our aim is to store
a unique u32 key identifier into dst metrics, which can then be
mapped into a tcp_congestion_ops struct. We argue that having a
RTAX key entry is the most simple, generic and easy way to manage,
and also keeps the memory footprint of dst entries lower on 64 bit
than with storing a pointer directly, for example. Having a unique
key id also allows for decoupling actual TCP congestion control
module management from the FIB layer, i.e. we don't have to care
about expensive module refcounting inside the FIB at this point.
We first thought of using an IDR store for the realization, which
takes over dynamic assignment of unused key space and also performs
the key to pointer mapping in RCU. While doing so, we stumbled upon
the issue that due to the nature of dynamic key distribution, it
just so happens, arguably in very rare occasions, that excessive
module loads and unloads can lead to a possible reuse of previously
used key space. Thus, previously stale keys in the dst metric are
now being reassigned to a different congestion control algorithm,
which might lead to unexpected behaviour. One way to resolve this
would have been to walk FIBs on the actually rare occasion of a
module unload and reset the metric keys for each FIB in each netns,
but that's just very costly.
Therefore, we argue a better solution is to reuse the unique
congestion control algorithm name member and map that into u32 key
space through jhash. For that, we split the flags attribute (as it
currently uses 2 bits only anyway) into two u32 attributes, flags
and key, so that we can keep the cacheline boundary of 2 cachelines
on x86_64 and cache the precalculated key at registration time for
the fast path. On average we might expect 2 - 4 modules being loaded
worst case perhaps 15, so a key collision possibility is extremely
low, and guaranteed collision-free on LE/BE for all in-tree modules.
Overall this results in much simpler code, and all without the
overhead of an IDR. Due to the deterministic nature, modules can
now be unloaded, the congestion control algorithm for a specific
but unloaded key will fall back to the default one, and on module
reload time it will switch back to the expected algorithm
transparently.
Joint work with Florian Westphal.
Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Daniel Borkmann <dborkman@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2015-01-06 06:57:46 +08:00
|
|
|
icsk_ca_dst_locked:1;
|
2005-08-10 11:10:42 +08:00
|
|
|
__u8 icsk_retransmits;
|
|
|
|
__u8 icsk_pending;
|
|
|
|
__u8 icsk_backoff;
|
|
|
|
__u8 icsk_syn_retries;
|
2005-08-10 15:03:31 +08:00
|
|
|
__u8 icsk_probes_out;
|
2005-12-14 15:26:10 +08:00
|
|
|
__u16 icsk_ext_hdr_len;
|
2005-08-10 11:10:42 +08:00
|
|
|
struct {
|
|
|
|
__u8 pending; /* ACK is pending */
|
|
|
|
__u8 quick; /* Scheduled number of quick acks */
|
|
|
|
__u8 pingpong; /* The session is interactive */
|
|
|
|
__u8 blocked; /* Delayed ACK was blocked by socket lock */
|
|
|
|
__u32 ato; /* Predicted tick of soft clock */
|
|
|
|
unsigned long timeout; /* Currently scheduled timeout */
|
|
|
|
__u32 lrcvtime; /* timestamp of last received data packet */
|
|
|
|
__u16 last_seg_size; /* Size of last incoming segment */
|
2018-02-28 07:48:21 +08:00
|
|
|
__u16 rcv_mss; /* MSS used for delayed ACK decisions */
|
2005-08-10 11:10:42 +08:00
|
|
|
} icsk_ack;
|
2006-03-21 09:53:41 +08:00
|
|
|
struct {
|
|
|
|
int enabled;
|
|
|
|
|
|
|
|
/* Range of MTUs to search */
|
|
|
|
int search_high;
|
|
|
|
int search_low;
|
|
|
|
|
|
|
|
/* Information on the current probe. */
|
|
|
|
int probe_size;
|
2015-03-06 11:18:24 +08:00
|
|
|
|
|
|
|
u32 probe_timestamp;
|
2006-03-21 09:53:41 +08:00
|
|
|
} icsk_mtup;
|
tcp: Add TCP_USER_TIMEOUT socket option.
This patch provides a "user timeout" support as described in RFC793. The
socket option is also needed for the the local half of RFC5482 "TCP User
Timeout Option".
TCP_USER_TIMEOUT is a TCP level socket option that takes an unsigned int,
when > 0, to specify the maximum amount of time in ms that transmitted
data may remain unacknowledged before TCP will forcefully close the
corresponding connection and return ETIMEDOUT to the application. If
0 is given, TCP will continue to use the system default.
Increasing the user timeouts allows a TCP connection to survive extended
periods without end-to-end connectivity. Decreasing the user timeouts
allows applications to "fail fast" if so desired. Otherwise it may take
upto 20 minutes with the current system defaults in a normal WAN
environment.
The socket option can be made during any state of a TCP connection, but
is only effective during the synchronized states of a connection
(ESTABLISHED, FIN-WAIT-1, FIN-WAIT-2, CLOSE-WAIT, CLOSING, or LAST-ACK).
Moreover, when used with the TCP keepalive (SO_KEEPALIVE) option,
TCP_USER_TIMEOUT will overtake keepalive to determine when to close a
connection due to keepalive failure.
The option does not change in anyway when TCP retransmits a packet, nor
when a keepalive probe will be sent.
This option, like many others, will be inherited by an acceptor from its
listener.
Signed-off-by: H.K. Jerry Chu <hkchu@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2010-08-28 03:13:28 +08:00
|
|
|
u32 icsk_user_timeout;
|
2015-05-19 08:06:14 +08:00
|
|
|
|
tcp_bbr: adapt cwnd based on ack aggregation estimation
Aggregation effects are extremely common with wifi, cellular, and cable
modem link technologies, ACK decimation in middleboxes, and LRO and GRO
in receiving hosts. The aggregation can happen in either direction,
data or ACKs, but in either case the aggregation effect is visible
to the sender in the ACK stream.
Previously BBR's sending was often limited by cwnd under severe ACK
aggregation/decimation because BBR sized the cwnd at 2*BDP. If packets
were acked in bursts after long delays (e.g. one ACK acking 5*BDP after
5*RTT), BBR's sending was halted after sending 2*BDP over 2*RTT, leaving
the bottleneck idle for potentially long periods. Note that loss-based
congestion control does not have this issue because when facing
aggregation it continues increasing cwnd after bursts of ACKs, growing
cwnd until the buffer is full.
To achieve good throughput in the presence of aggregation effects, this
algorithm allows the BBR sender to put extra data in flight to keep the
bottleneck utilized during silences in the ACK stream that it has evidence
to suggest were caused by aggregation.
A summary of the algorithm: when a burst of packets are acked by a
stretched ACK or a burst of ACKs or both, BBR first estimates the expected
amount of data that should have been acked, based on its estimated
bandwidth. Then the surplus ("extra_acked") is recorded in a windowed-max
filter to estimate the recent level of observed ACK aggregation. Then cwnd
is increased by the ACK aggregation estimate. The larger cwnd avoids BBR
being cwnd-limited in the face of ACK silences that recent history suggests
were caused by aggregation. As a sanity check, the ACK aggregation degree
is upper-bounded by the cwnd (at the time of measurement) and a global max
of BW * 100ms. The algorithm is further described by the following
presentation:
https://datatracker.ietf.org/meeting/101/materials/slides-101-iccrg-an-update-on-bbr-work-at-google-00
In our internal testing, we observed a significant increase in BBR
throughput (measured using netperf), in a basic wifi setup.
- Host1 (sender on ethernet) -> AP -> Host2 (receiver on wifi)
- 2.4 GHz -> BBR before: ~73 Mbps; BBR after: ~102 Mbps; CUBIC: ~100 Mbps
- 5.0 GHz -> BBR before: ~362 Mbps; BBR after: ~593 Mbps; CUBIC: ~601 Mbps
Also, this code is running globally on YouTube TCP connections and produced
significant bandwidth increases for YouTube traffic.
This is based on Ian Swett's max_ack_height_ algorithm from the
QUIC BBR implementation.
Signed-off-by: Priyaranjan Jha <priyarjha@google.com>
Signed-off-by: Neal Cardwell <ncardwell@google.com>
Signed-off-by: Yuchung Cheng <ycheng@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2019-01-24 04:04:54 +08:00
|
|
|
u64 icsk_ca_priv[104 / sizeof(u64)];
|
|
|
|
#define ICSK_CA_PRIV_SIZE (13 * sizeof(u64))
|
2005-08-10 11:10:42 +08:00
|
|
|
};
|
|
|
|
|
2005-08-10 11:11:08 +08:00
|
|
|
#define ICSK_TIME_RETRANS 1 /* Retransmit timer */
|
|
|
|
#define ICSK_TIME_DACK 2 /* Delayed ack timer */
|
|
|
|
#define ICSK_TIME_PROBE0 3 /* Zero window probe timer */
|
tcp: Tail loss probe (TLP)
This patch series implement the Tail loss probe (TLP) algorithm described
in http://tools.ietf.org/html/draft-dukkipati-tcpm-tcp-loss-probe-01. The
first patch implements the basic algorithm.
TLP's goal is to reduce tail latency of short transactions. It achieves
this by converting retransmission timeouts (RTOs) occuring due
to tail losses (losses at end of transactions) into fast recovery.
TLP transmits one packet in two round-trips when a connection is in
Open state and isn't receiving any ACKs. The transmitted packet, aka
loss probe, can be either new or a retransmission. When there is tail
loss, the ACK from a loss probe triggers FACK/early-retransmit based
fast recovery, thus avoiding a costly RTO. In the absence of loss,
there is no change in the connection state.
PTO stands for probe timeout. It is a timer event indicating
that an ACK is overdue and triggers a loss probe packet. The PTO value
is set to max(2*SRTT, 10ms) and is adjusted to account for delayed
ACK timer when there is only one oustanding packet.
TLP Algorithm
On transmission of new data in Open state:
-> packets_out > 1: schedule PTO in max(2*SRTT, 10ms).
-> packets_out == 1: schedule PTO in max(2*RTT, 1.5*RTT + 200ms)
-> PTO = min(PTO, RTO)
Conditions for scheduling PTO:
-> Connection is in Open state.
-> Connection is either cwnd limited or no new data to send.
-> Number of probes per tail loss episode is limited to one.
-> Connection is SACK enabled.
When PTO fires:
new_segment_exists:
-> transmit new segment.
-> packets_out++. cwnd remains same.
no_new_packet:
-> retransmit the last segment.
Its ACK triggers FACK or early retransmit based recovery.
ACK path:
-> rearm RTO at start of ACK processing.
-> reschedule PTO if need be.
In addition, the patch includes a small variation to the Early Retransmit
(ER) algorithm, such that ER and TLP together can in principle recover any
N-degree of tail loss through fast recovery. TLP is controlled by the same
sysctl as ER, tcp_early_retrans sysctl.
tcp_early_retrans==0; disables TLP and ER.
==1; enables RFC5827 ER.
==2; delayed ER.
==3; TLP and delayed ER. [DEFAULT]
==4; TLP only.
The TLP patch series have been extensively tested on Google Web servers.
It is most effective for short Web trasactions, where it reduced RTOs by 15%
and improved HTTP response time (average by 6%, 99th percentile by 10%).
The transmitted probes account for <0.5% of the overall transmissions.
Signed-off-by: Nandita Dukkipati <nanditad@google.com>
Acked-by: Neal Cardwell <ncardwell@google.com>
Acked-by: Yuchung Cheng <ycheng@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2013-03-11 18:00:43 +08:00
|
|
|
#define ICSK_TIME_EARLY_RETRANS 4 /* Early retransmit timer */
|
|
|
|
#define ICSK_TIME_LOSS_PROBE 5 /* Tail loss probe timer */
|
2017-01-13 14:11:33 +08:00
|
|
|
#define ICSK_TIME_REO_TIMEOUT 6 /* Reordering timer */
|
2005-08-10 11:11:08 +08:00
|
|
|
|
2005-08-10 11:10:42 +08:00
|
|
|
static inline struct inet_connection_sock *inet_csk(const struct sock *sk)
|
|
|
|
{
|
|
|
|
return (struct inet_connection_sock *)sk;
|
|
|
|
}
|
|
|
|
|
2005-08-10 15:03:31 +08:00
|
|
|
static inline void *inet_csk_ca(const struct sock *sk)
|
|
|
|
{
|
|
|
|
return (void *)inet_csk(sk)->icsk_ca_priv;
|
|
|
|
}
|
|
|
|
|
2013-09-22 01:22:41 +08:00
|
|
|
struct sock *inet_csk_clone_lock(const struct sock *sk,
|
|
|
|
const struct request_sock *req,
|
|
|
|
const gfp_t priority);
|
2005-08-10 11:11:24 +08:00
|
|
|
|
2005-08-10 11:11:08 +08:00
|
|
|
enum inet_csk_ack_state_t {
|
|
|
|
ICSK_ACK_SCHED = 1,
|
|
|
|
ICSK_ACK_TIMER = 2,
|
2006-09-20 03:52:50 +08:00
|
|
|
ICSK_ACK_PUSHED = 4,
|
2018-08-10 00:38:09 +08:00
|
|
|
ICSK_ACK_PUSHED2 = 8,
|
|
|
|
ICSK_ACK_NOW = 16 /* Send the next ACK immediately (once) */
|
2005-08-10 11:11:08 +08:00
|
|
|
};
|
|
|
|
|
2013-09-22 01:22:41 +08:00
|
|
|
void inet_csk_init_xmit_timers(struct sock *sk,
|
2017-10-17 08:29:19 +08:00
|
|
|
void (*retransmit_handler)(struct timer_list *),
|
|
|
|
void (*delack_handler)(struct timer_list *),
|
|
|
|
void (*keepalive_handler)(struct timer_list *));
|
2013-09-22 01:22:41 +08:00
|
|
|
void inet_csk_clear_xmit_timers(struct sock *sk);
|
2005-08-10 11:10:42 +08:00
|
|
|
|
2005-08-10 11:11:08 +08:00
|
|
|
static inline void inet_csk_schedule_ack(struct sock *sk)
|
|
|
|
{
|
|
|
|
inet_csk(sk)->icsk_ack.pending |= ICSK_ACK_SCHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int inet_csk_ack_scheduled(const struct sock *sk)
|
|
|
|
{
|
|
|
|
return inet_csk(sk)->icsk_ack.pending & ICSK_ACK_SCHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void inet_csk_delack_init(struct sock *sk)
|
|
|
|
{
|
|
|
|
memset(&inet_csk(sk)->icsk_ack, 0, sizeof(inet_csk(sk)->icsk_ack));
|
|
|
|
}
|
|
|
|
|
2013-09-22 01:22:41 +08:00
|
|
|
void inet_csk_delete_keepalive_timer(struct sock *sk);
|
|
|
|
void inet_csk_reset_keepalive_timer(struct sock *sk, unsigned long timeout);
|
2005-08-10 11:11:08 +08:00
|
|
|
|
|
|
|
static inline void inet_csk_clear_xmit_timer(struct sock *sk, const int what)
|
|
|
|
{
|
|
|
|
struct inet_connection_sock *icsk = inet_csk(sk);
|
2018-02-28 07:48:21 +08:00
|
|
|
|
2005-08-10 11:11:08 +08:00
|
|
|
if (what == ICSK_TIME_RETRANS || what == ICSK_TIME_PROBE0) {
|
|
|
|
icsk->icsk_pending = 0;
|
|
|
|
#ifdef INET_CSK_CLEAR_TIMERS
|
|
|
|
sk_stop_timer(sk, &icsk->icsk_retransmit_timer);
|
|
|
|
#endif
|
|
|
|
} else if (what == ICSK_TIME_DACK) {
|
|
|
|
icsk->icsk_ack.blocked = icsk->icsk_ack.pending = 0;
|
|
|
|
#ifdef INET_CSK_CLEAR_TIMERS
|
|
|
|
sk_stop_timer(sk, &icsk->icsk_delack_timer);
|
|
|
|
#endif
|
2018-05-10 14:24:07 +08:00
|
|
|
} else {
|
|
|
|
pr_debug("inet_csk BUG: unknown timer value\n");
|
2005-08-10 11:11:08 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Reset the retransmission timer
|
|
|
|
*/
|
|
|
|
static inline void inet_csk_reset_xmit_timer(struct sock *sk, const int what,
|
|
|
|
unsigned long when,
|
|
|
|
const unsigned long max_when)
|
|
|
|
{
|
|
|
|
struct inet_connection_sock *icsk = inet_csk(sk);
|
|
|
|
|
|
|
|
if (when > max_when) {
|
|
|
|
pr_debug("reset_xmit_timer: sk=%p %d when=0x%lx, caller=%p\n",
|
2018-08-02 05:57:59 +08:00
|
|
|
sk, what, when, (void *)_THIS_IP_);
|
2005-08-10 11:11:08 +08:00
|
|
|
when = max_when;
|
|
|
|
}
|
|
|
|
|
tcp: Tail loss probe (TLP)
This patch series implement the Tail loss probe (TLP) algorithm described
in http://tools.ietf.org/html/draft-dukkipati-tcpm-tcp-loss-probe-01. The
first patch implements the basic algorithm.
TLP's goal is to reduce tail latency of short transactions. It achieves
this by converting retransmission timeouts (RTOs) occuring due
to tail losses (losses at end of transactions) into fast recovery.
TLP transmits one packet in two round-trips when a connection is in
Open state and isn't receiving any ACKs. The transmitted packet, aka
loss probe, can be either new or a retransmission. When there is tail
loss, the ACK from a loss probe triggers FACK/early-retransmit based
fast recovery, thus avoiding a costly RTO. In the absence of loss,
there is no change in the connection state.
PTO stands for probe timeout. It is a timer event indicating
that an ACK is overdue and triggers a loss probe packet. The PTO value
is set to max(2*SRTT, 10ms) and is adjusted to account for delayed
ACK timer when there is only one oustanding packet.
TLP Algorithm
On transmission of new data in Open state:
-> packets_out > 1: schedule PTO in max(2*SRTT, 10ms).
-> packets_out == 1: schedule PTO in max(2*RTT, 1.5*RTT + 200ms)
-> PTO = min(PTO, RTO)
Conditions for scheduling PTO:
-> Connection is in Open state.
-> Connection is either cwnd limited or no new data to send.
-> Number of probes per tail loss episode is limited to one.
-> Connection is SACK enabled.
When PTO fires:
new_segment_exists:
-> transmit new segment.
-> packets_out++. cwnd remains same.
no_new_packet:
-> retransmit the last segment.
Its ACK triggers FACK or early retransmit based recovery.
ACK path:
-> rearm RTO at start of ACK processing.
-> reschedule PTO if need be.
In addition, the patch includes a small variation to the Early Retransmit
(ER) algorithm, such that ER and TLP together can in principle recover any
N-degree of tail loss through fast recovery. TLP is controlled by the same
sysctl as ER, tcp_early_retrans sysctl.
tcp_early_retrans==0; disables TLP and ER.
==1; enables RFC5827 ER.
==2; delayed ER.
==3; TLP and delayed ER. [DEFAULT]
==4; TLP only.
The TLP patch series have been extensively tested on Google Web servers.
It is most effective for short Web trasactions, where it reduced RTOs by 15%
and improved HTTP response time (average by 6%, 99th percentile by 10%).
The transmitted probes account for <0.5% of the overall transmissions.
Signed-off-by: Nandita Dukkipati <nanditad@google.com>
Acked-by: Neal Cardwell <ncardwell@google.com>
Acked-by: Yuchung Cheng <ycheng@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2013-03-11 18:00:43 +08:00
|
|
|
if (what == ICSK_TIME_RETRANS || what == ICSK_TIME_PROBE0 ||
|
2017-01-13 14:11:33 +08:00
|
|
|
what == ICSK_TIME_EARLY_RETRANS || what == ICSK_TIME_LOSS_PROBE ||
|
|
|
|
what == ICSK_TIME_REO_TIMEOUT) {
|
2005-08-10 11:11:08 +08:00
|
|
|
icsk->icsk_pending = what;
|
|
|
|
icsk->icsk_timeout = jiffies + when;
|
|
|
|
sk_reset_timer(sk, &icsk->icsk_retransmit_timer, icsk->icsk_timeout);
|
|
|
|
} else if (what == ICSK_TIME_DACK) {
|
|
|
|
icsk->icsk_ack.pending |= ICSK_ACK_TIMER;
|
|
|
|
icsk->icsk_ack.timeout = jiffies + when;
|
|
|
|
sk_reset_timer(sk, &icsk->icsk_delack_timer, icsk->icsk_ack.timeout);
|
2018-05-10 14:24:07 +08:00
|
|
|
} else {
|
|
|
|
pr_debug("inet_csk BUG: unknown timer value\n");
|
2005-08-10 11:11:08 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-23 04:19:44 +08:00
|
|
|
static inline unsigned long
|
|
|
|
inet_csk_rto_backoff(const struct inet_connection_sock *icsk,
|
|
|
|
unsigned long max_when)
|
|
|
|
{
|
|
|
|
u64 when = (u64)icsk->icsk_rto << icsk->icsk_backoff;
|
|
|
|
|
|
|
|
return (unsigned long)min_t(u64, when, max_when);
|
|
|
|
}
|
|
|
|
|
2017-03-09 16:09:05 +08:00
|
|
|
struct sock *inet_csk_accept(struct sock *sk, int flags, int *err, bool kern);
|
2005-08-10 11:11:08 +08:00
|
|
|
|
2013-09-22 01:22:41 +08:00
|
|
|
int inet_csk_get_port(struct sock *sk, unsigned short snum);
|
2005-08-10 11:10:42 +08:00
|
|
|
|
2015-09-25 22:39:11 +08:00
|
|
|
struct dst_entry *inet_csk_route_req(const struct sock *sk, struct flowi4 *fl4,
|
2013-09-22 01:22:41 +08:00
|
|
|
const struct request_sock *req);
|
2015-09-29 22:42:43 +08:00
|
|
|
struct dst_entry *inet_csk_route_child_sock(const struct sock *sk,
|
|
|
|
struct sock *newsk,
|
2012-07-18 05:02:46 +08:00
|
|
|
const struct request_sock *req);
|
2005-08-10 11:10:42 +08:00
|
|
|
|
2016-02-18 21:39:18 +08:00
|
|
|
struct sock *inet_csk_reqsk_queue_add(struct sock *sk,
|
|
|
|
struct request_sock *req,
|
|
|
|
struct sock *child);
|
2013-09-22 01:22:41 +08:00
|
|
|
void inet_csk_reqsk_queue_hash_add(struct sock *sk, struct request_sock *req,
|
|
|
|
unsigned long timeout);
|
2015-10-22 23:20:46 +08:00
|
|
|
struct sock *inet_csk_complete_hashdance(struct sock *sk, struct sock *child,
|
|
|
|
struct request_sock *req,
|
|
|
|
bool own_req);
|
2005-08-10 11:11:08 +08:00
|
|
|
|
2015-10-03 02:43:31 +08:00
|
|
|
static inline void inet_csk_reqsk_queue_added(struct sock *sk)
|
2005-08-10 11:11:08 +08:00
|
|
|
{
|
inet: get rid of central tcp/dccp listener timer
One of the major issue for TCP is the SYNACK rtx handling,
done by inet_csk_reqsk_queue_prune(), fired by the keepalive
timer of a TCP_LISTEN socket.
This function runs for awful long times, with socket lock held,
meaning that other cpus needing this lock have to spin for hundred of ms.
SYNACK are sent in huge bursts, likely to cause severe drops anyway.
This model was OK 15 years ago when memory was very tight.
We now can afford to have a timer per request sock.
Timer invocations no longer need to lock the listener,
and can be run from all cpus in parallel.
With following patch increasing somaxconn width to 32 bits,
I tested a listener with more than 4 million active request sockets,
and a steady SYNFLOOD of ~200,000 SYN per second.
Host was sending ~830,000 SYNACK per second.
This is ~100 times more what we could achieve before this patch.
Later, we will get rid of the listener hash and use ehash instead.
Signed-off-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2015-03-20 10:04:20 +08:00
|
|
|
reqsk_queue_added(&inet_csk(sk)->icsk_accept_queue);
|
2005-08-10 11:11:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline int inet_csk_reqsk_queue_len(const struct sock *sk)
|
|
|
|
{
|
|
|
|
return reqsk_queue_len(&inet_csk(sk)->icsk_accept_queue);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int inet_csk_reqsk_queue_is_full(const struct sock *sk)
|
|
|
|
{
|
2015-10-03 02:43:37 +08:00
|
|
|
return inet_csk_reqsk_queue_len(sk) >= sk->sk_max_ack_backlog;
|
2005-08-10 11:11:08 +08:00
|
|
|
}
|
|
|
|
|
2015-04-24 09:03:44 +08:00
|
|
|
void inet_csk_reqsk_queue_drop(struct sock *sk, struct request_sock *req);
|
2015-10-15 02:16:27 +08:00
|
|
|
void inet_csk_reqsk_queue_drop_and_put(struct sock *sk, struct request_sock *req);
|
2005-08-10 11:11:08 +08:00
|
|
|
|
2013-09-22 01:22:41 +08:00
|
|
|
void inet_csk_destroy_sock(struct sock *sk);
|
|
|
|
void inet_csk_prepare_forced_close(struct sock *sk);
|
2005-08-24 12:52:58 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* LISTEN is a special case for poll..
|
|
|
|
*/
|
2017-07-03 12:01:49 +08:00
|
|
|
static inline __poll_t inet_csk_listen_poll(const struct sock *sk)
|
2005-08-24 12:52:58 +08:00
|
|
|
{
|
|
|
|
return !reqsk_queue_empty(&inet_csk(sk)->icsk_accept_queue) ?
|
2018-02-12 06:34:03 +08:00
|
|
|
(EPOLLIN | EPOLLRDNORM) : 0;
|
2005-08-24 12:52:58 +08:00
|
|
|
}
|
|
|
|
|
2015-10-14 21:16:49 +08:00
|
|
|
int inet_csk_listen_start(struct sock *sk, int backlog);
|
2013-09-22 01:22:41 +08:00
|
|
|
void inet_csk_listen_stop(struct sock *sk);
|
2005-08-10 11:11:56 +08:00
|
|
|
|
2013-09-22 01:22:41 +08:00
|
|
|
void inet_csk_addr2sockaddr(struct sock *sk, struct sockaddr *uaddr);
|
2005-12-14 15:16:04 +08:00
|
|
|
|
2013-09-22 01:22:41 +08:00
|
|
|
int inet_csk_compat_getsockopt(struct sock *sk, int level, int optname,
|
|
|
|
char __user *optval, int __user *optlen);
|
|
|
|
int inet_csk_compat_setsockopt(struct sock *sk, int level, int optname,
|
|
|
|
char __user *optval, unsigned int optlen);
|
2012-07-16 18:28:06 +08:00
|
|
|
|
2013-09-22 01:22:41 +08:00
|
|
|
struct dst_entry *inet_csk_update_pmtu(struct sock *sk, u32 mtu);
|
2019-01-26 02:53:19 +08:00
|
|
|
|
2019-01-26 02:53:20 +08:00
|
|
|
#define TCP_PINGPONG_THRESH 3
|
2019-01-26 02:53:19 +08:00
|
|
|
|
|
|
|
static inline void inet_csk_enter_pingpong_mode(struct sock *sk)
|
|
|
|
{
|
|
|
|
inet_csk(sk)->icsk_ack.pingpong = TCP_PINGPONG_THRESH;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void inet_csk_exit_pingpong_mode(struct sock *sk)
|
|
|
|
{
|
|
|
|
inet_csk(sk)->icsk_ack.pingpong = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool inet_csk_in_pingpong_mode(struct sock *sk)
|
|
|
|
{
|
|
|
|
return inet_csk(sk)->icsk_ack.pingpong >= TCP_PINGPONG_THRESH;
|
|
|
|
}
|
2019-01-26 02:53:20 +08:00
|
|
|
|
|
|
|
static inline void inet_csk_inc_pingpong_cnt(struct sock *sk)
|
|
|
|
{
|
|
|
|
struct inet_connection_sock *icsk = inet_csk(sk);
|
|
|
|
|
|
|
|
if (icsk->icsk_ack.pingpong < U8_MAX)
|
|
|
|
icsk->icsk_ack.pingpong++;
|
|
|
|
}
|
2020-03-09 19:12:32 +08:00
|
|
|
|
|
|
|
static inline bool inet_csk_has_ulp(struct sock *sk)
|
|
|
|
{
|
|
|
|
return inet_sk(sk)->is_icsk && !!inet_csk(sk)->icsk_ulp_ops;
|
|
|
|
}
|
|
|
|
|
2005-08-10 11:10:42 +08:00
|
|
|
#endif /* _INET_CONNECTION_SOCK_H */
|