2005-08-10 05:10:42 +02: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
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version
|
|
|
|
* 2 of the License, or (at your option) any later version.
|
|
|
|
*/
|
|
|
|
#ifndef _INET_CONNECTION_SOCK_H
|
|
|
|
#define _INET_CONNECTION_SOCK_H
|
|
|
|
|
2005-12-14 08:15:52 +01:00
|
|
|
#include <linux/compiler.h>
|
2005-08-10 05:11:08 +02:00
|
|
|
#include <linux/string.h>
|
2005-08-10 05:10:42 +02:00
|
|
|
#include <linux/timer.h>
|
2006-10-19 23:23:57 +02:00
|
|
|
#include <linux/poll.h>
|
2005-12-27 05:43:12 +01:00
|
|
|
|
|
|
|
#include <net/inet_sock.h>
|
2005-08-10 05:10:42 +02:00
|
|
|
#include <net/request_sock.h>
|
|
|
|
|
2005-08-10 05:11:08 +02:00
|
|
|
#define INET_CSK_DEBUG 1
|
|
|
|
|
|
|
|
/* Cancel timers, when they are not required. */
|
|
|
|
#undef INET_CSK_CLEAR_TIMERS
|
|
|
|
|
2005-08-10 05:10:42 +02:00
|
|
|
struct inet_bind_bucket;
|
2005-08-10 09:03:31 +02:00
|
|
|
struct tcp_congestion_ops;
|
2005-08-10 05:10:42 +02:00
|
|
|
|
2005-12-14 08:15:52 +01:00
|
|
|
/*
|
|
|
|
* Pointers to address related TCP functions
|
|
|
|
* (i.e. things that depend on the address family)
|
|
|
|
*/
|
|
|
|
struct inet_connection_sock_af_ops {
|
2014-04-15 18:58:34 +02:00
|
|
|
int (*queue_xmit)(struct sock *sk, struct sk_buff *skb, struct flowi *fl);
|
2010-04-11 04:15:55 +02:00
|
|
|
void (*send_check)(struct sock *sk, struct sk_buff *skb);
|
2005-12-14 08:15:52 +01:00
|
|
|
int (*rebuild_header)(struct sock *sk);
|
2012-08-06 07:09:33 +02:00
|
|
|
void (*sk_rx_dst_set)(struct sock *sk, const struct sk_buff *skb);
|
2005-12-14 08:15:52 +01:00
|
|
|
int (*conn_request)(struct sock *sk, struct sk_buff *skb);
|
2015-09-29 16:42:48 +02:00
|
|
|
struct sock *(*syn_recv_sock)(const struct sock *sk, struct sk_buff *skb,
|
2005-12-14 08:15:52 +01:00
|
|
|
struct request_sock *req,
|
2015-10-22 17:20:46 +02: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-27 20:56:43 +01: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 09:37:38 +02: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-27 20:56:43 +01:00
|
|
|
u16 sockaddr_len;
|
2005-12-14 08:15:52 +01:00
|
|
|
int (*setsockopt)(struct sock *sk, int level, int optname,
|
2009-10-01 01:12:20 +02:00
|
|
|
char __user *optval, unsigned int optlen);
|
2005-12-14 08:15:52 +01:00
|
|
|
int (*getsockopt)(struct sock *sk, int level, int optname,
|
|
|
|
char __user *optval, int __user *optlen);
|
2008-08-28 11:53:51 +02:00
|
|
|
#ifdef CONFIG_COMPAT
|
2006-03-21 07:45:21 +01:00
|
|
|
int (*compat_setsockopt)(struct sock *sk,
|
|
|
|
int level, int optname,
|
2009-10-01 01:12:20 +02:00
|
|
|
char __user *optval, unsigned int optlen);
|
2006-03-21 07:45:21 +01:00
|
|
|
int (*compat_getsockopt)(struct sock *sk,
|
|
|
|
int level, int optname,
|
|
|
|
char __user *optval, int __user *optlen);
|
2008-08-28 11:53:51 +02:00
|
|
|
#endif
|
2005-12-14 08:15:52 +01:00
|
|
|
void (*addr2sockaddr)(struct sock *sk, struct sockaddr *);
|
[SOCK] proto: Add hashinfo member to struct proto
This way we can remove TCP and DCCP specific versions of
sk->sk_prot->get_port: both v4 and v6 use inet_csk_get_port
sk->sk_prot->hash: inet_hash is directly used, only v6 need
a specific version to deal with mapped sockets
sk->sk_prot->unhash: both v4 and v6 use inet_hash directly
struct inet_connection_sock_af_ops also gets a new member, bind_conflict, so
that inet_csk_get_port can find the per family routine.
Now only the lookup routines receive as a parameter a struct inet_hashtable.
With this we further reuse code, reducing the difference among INET transport
protocols.
Eventually work has to be done on UDP and SCTP to make them share this
infrastructure and get as a bonus inet_diag interfaces so that iproute can be
used with these protocols.
net-2.6/net/ipv4/inet_hashtables.c:
struct proto | +8
struct inet_connection_sock_af_ops | +8
2 structs changed
__inet_hash_nolisten | +18
__inet_hash | -210
inet_put_port | +8
inet_bind_bucket_create | +1
__inet_hash_connect | -8
5 functions changed, 27 bytes added, 218 bytes removed, diff: -191
net-2.6/net/core/sock.c:
proto_seq_show | +3
1 function changed, 3 bytes added, diff: +3
net-2.6/net/ipv4/inet_connection_sock.c:
inet_csk_get_port | +15
1 function changed, 15 bytes added, diff: +15
net-2.6/net/ipv4/tcp.c:
tcp_set_state | -7
1 function changed, 7 bytes removed, diff: -7
net-2.6/net/ipv4/tcp_ipv4.c:
tcp_v4_get_port | -31
tcp_v4_hash | -48
tcp_v4_destroy_sock | -7
tcp_v4_syn_recv_sock | -2
tcp_unhash | -179
5 functions changed, 267 bytes removed, diff: -267
net-2.6/net/ipv6/inet6_hashtables.c:
__inet6_hash | +8
1 function changed, 8 bytes added, diff: +8
net-2.6/net/ipv4/inet_hashtables.c:
inet_unhash | +190
inet_hash | +242
2 functions changed, 432 bytes added, diff: +432
vmlinux:
16 functions changed, 485 bytes added, 492 bytes removed, diff: -7
/home/acme/git/net-2.6/net/ipv6/tcp_ipv6.c:
tcp_v6_get_port | -31
tcp_v6_hash | -7
tcp_v6_syn_recv_sock | -9
3 functions changed, 47 bytes removed, diff: -47
/home/acme/git/net-2.6/net/dccp/proto.c:
dccp_destroy_sock | -7
dccp_unhash | -179
dccp_hash | -49
dccp_set_state | -7
dccp_done | +1
5 functions changed, 1 bytes added, 242 bytes removed, diff: -241
/home/acme/git/net-2.6/net/dccp/ipv4.c:
dccp_v4_get_port | -31
dccp_v4_request_recv_sock | -2
2 functions changed, 33 bytes removed, diff: -33
/home/acme/git/net-2.6/net/dccp/ipv6.c:
dccp_v6_get_port | -31
dccp_v6_hash | -7
dccp_v6_request_recv_sock | +5
3 functions changed, 5 bytes added, 38 bytes removed, diff: -33
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2008-02-03 13:06:04 +01:00
|
|
|
int (*bind_conflict)(const struct sock *sk,
|
tcp: bind() use stronger condition for bind_conflict
We must try harder to get unique (addr, port) pairs when
doing port autoselection for sockets with SO_REUSEADDR
option set.
We achieve this by adding a relaxation parameter to
inet_csk_bind_conflict. When 'relax' parameter is off
we return a conflict whenever the current searched
pair (addr, port) is not unique.
This tries to address the problems reported in patch:
8d238b25b1ec22a73b1c2206f111df2faaff8285
Revert "tcp: bind() fix when many ports are bound"
Tests where ran for creating and binding(0) many sockets
on 100 IPs. The results are, on average:
* 60000 sockets, 600 ports / IP:
* 0.210 s, 620 (IP, port) duplicates without patch
* 0.219 s, no duplicates with patch
* 100000 sockets, 1000 ports / IP:
* 0.371 s, 1720 duplicates without patch
* 0.373 s, no duplicates with patch
* 200000 sockets, 2000 ports / IP:
* 0.766 s, 6900 duplicates without patch
* 0.768 s, no duplicates with patch
* 500000 sockets, 5000 ports / IP:
* 2.227 s, 41500 duplicates without patch
* 2.284 s, no duplicates with patch
Signed-off-by: Alex Copot <alex.mihai.c@gmail.com>
Signed-off-by: Daniel Baluta <dbaluta@ixiacom.com>
Signed-off-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2012-04-13 00:21:45 +02:00
|
|
|
const struct inet_bind_bucket *tb, bool relax);
|
2014-08-14 18:40:05 +02:00
|
|
|
void (*mtu_reduced)(struct sock *sk);
|
2005-12-14 08:15:52 +01:00
|
|
|
};
|
|
|
|
|
2005-08-10 05:10:42 +02:00
|
|
|
/** inet_connection_sock - INET connection oriented sock
|
|
|
|
*
|
|
|
|
* @icsk_accept_queue: FIFO of established children
|
|
|
|
* @icsk_bind_hash: Bind node
|
|
|
|
* @icsk_timeout: Timeout
|
|
|
|
* @icsk_retransmit_timer: Resend (no ack)
|
|
|
|
* @icsk_rto: Retransmit timeout
|
2005-12-14 08:26:10 +01:00
|
|
|
* @icsk_pmtu_cookie Last pmtu seen by socket
|
2005-08-10 09:03:31 +02:00
|
|
|
* @icsk_ca_ops Pluggable congestion control hook
|
2005-12-14 08:15:52 +01:00
|
|
|
* @icsk_af_ops Operations which are AF_INET{4,6} specific
|
2005-08-10 09:03:31 +02:00
|
|
|
* @icsk_ca_state: Congestion control state
|
2005-08-10 05:10:42 +02: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 09:03:31 +02:00
|
|
|
* @icsk_probes_out: unanswered 0 window probes
|
2005-12-14 08:26:10 +01:00
|
|
|
* @icsk_ext_hdr_len: Network protocol overhead (IP/IPv6 options)
|
2005-08-10 05:10:42 +02:00
|
|
|
* @icsk_ack: Delayed ACK control data
|
2006-03-21 02:53:41 +01:00
|
|
|
* @icsk_mtup; MTU probing control data
|
2005-08-10 05:10:42 +02: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 08:26:10 +01:00
|
|
|
__u32 icsk_pmtu_cookie;
|
2006-01-10 00:56:09 +01:00
|
|
|
const struct tcp_congestion_ops *icsk_ca_ops;
|
|
|
|
const struct inet_connection_sock_af_ops *icsk_af_ops;
|
2005-12-14 08:26:10 +01:00
|
|
|
unsigned int (*icsk_sync_mss)(struct sock *sk, u32 pmtu);
|
2015-05-29 19:47:07 +02: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-05 23:57:46 +01:00
|
|
|
icsk_ca_dst_locked:1;
|
2005-08-10 05:10:42 +02:00
|
|
|
__u8 icsk_retransmits;
|
|
|
|
__u8 icsk_pending;
|
|
|
|
__u8 icsk_backoff;
|
|
|
|
__u8 icsk_syn_retries;
|
2005-08-10 09:03:31 +02:00
|
|
|
__u8 icsk_probes_out;
|
2005-12-14 08:26:10 +01:00
|
|
|
__u16 icsk_ext_hdr_len;
|
2005-08-10 05:10:42 +02: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 */
|
|
|
|
__u16 rcv_mss; /* MSS used for delayed ACK decisions */
|
|
|
|
} icsk_ack;
|
2006-03-21 02:53:41 +01: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 04:18:24 +01:00
|
|
|
|
|
|
|
u32 probe_timestamp;
|
2006-03-21 02:53:41 +01: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-27 21:13:28 +02:00
|
|
|
u32 icsk_user_timeout;
|
2015-05-19 02:06:14 +02:00
|
|
|
|
2016-09-20 05:39:22 +02:00
|
|
|
u64 icsk_ca_priv[88 / sizeof(u64)];
|
|
|
|
#define ICSK_CA_PRIV_SIZE (11 * sizeof(u64))
|
2005-08-10 05:10:42 +02:00
|
|
|
};
|
|
|
|
|
2005-08-10 05:11:08 +02: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 11:00:43 +01:00
|
|
|
#define ICSK_TIME_EARLY_RETRANS 4 /* Early retransmit timer */
|
|
|
|
#define ICSK_TIME_LOSS_PROBE 5 /* Tail loss probe timer */
|
2005-08-10 05:11:08 +02:00
|
|
|
|
2005-08-10 05:10:42 +02:00
|
|
|
static inline struct inet_connection_sock *inet_csk(const struct sock *sk)
|
|
|
|
{
|
|
|
|
return (struct inet_connection_sock *)sk;
|
|
|
|
}
|
|
|
|
|
2005-08-10 09:03:31 +02:00
|
|
|
static inline void *inet_csk_ca(const struct sock *sk)
|
|
|
|
{
|
|
|
|
return (void *)inet_csk(sk)->icsk_ca_priv;
|
|
|
|
}
|
|
|
|
|
2013-09-21 19:22:41 +02:00
|
|
|
struct sock *inet_csk_clone_lock(const struct sock *sk,
|
|
|
|
const struct request_sock *req,
|
|
|
|
const gfp_t priority);
|
2005-08-10 05:11:24 +02:00
|
|
|
|
2005-08-10 05:11:08 +02:00
|
|
|
enum inet_csk_ack_state_t {
|
|
|
|
ICSK_ACK_SCHED = 1,
|
|
|
|
ICSK_ACK_TIMER = 2,
|
2006-09-19 21:52:50 +02:00
|
|
|
ICSK_ACK_PUSHED = 4,
|
|
|
|
ICSK_ACK_PUSHED2 = 8
|
2005-08-10 05:11:08 +02:00
|
|
|
};
|
|
|
|
|
2013-09-21 19:22:41 +02:00
|
|
|
void inet_csk_init_xmit_timers(struct sock *sk,
|
|
|
|
void (*retransmit_handler)(unsigned long),
|
|
|
|
void (*delack_handler)(unsigned long),
|
|
|
|
void (*keepalive_handler)(unsigned long));
|
|
|
|
void inet_csk_clear_xmit_timers(struct sock *sk);
|
2005-08-10 05:10:42 +02:00
|
|
|
|
2005-08-10 05:11:08 +02: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-21 19:22:41 +02: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 05:11:08 +02:00
|
|
|
|
|
|
|
#ifdef INET_CSK_DEBUG
|
|
|
|
extern const char inet_csk_timer_bug_msg[];
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static inline void inet_csk_clear_xmit_timer(struct sock *sk, const int what)
|
|
|
|
{
|
|
|
|
struct inet_connection_sock *icsk = inet_csk(sk);
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
#ifdef INET_CSK_DEBUG
|
|
|
|
else {
|
2005-08-30 07:51:28 +02:00
|
|
|
pr_debug("%s", inet_csk_timer_bug_msg);
|
2005-08-10 05:11:08 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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) {
|
|
|
|
#ifdef INET_CSK_DEBUG
|
|
|
|
pr_debug("reset_xmit_timer: sk=%p %d when=0x%lx, caller=%p\n",
|
|
|
|
sk, what, when, current_text_addr());
|
|
|
|
#endif
|
|
|
|
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 11:00:43 +01:00
|
|
|
if (what == ICSK_TIME_RETRANS || what == ICSK_TIME_PROBE0 ||
|
|
|
|
what == ICSK_TIME_EARLY_RETRANS || what == ICSK_TIME_LOSS_PROBE) {
|
2005-08-10 05:11:08 +02: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);
|
|
|
|
}
|
|
|
|
#ifdef INET_CSK_DEBUG
|
|
|
|
else {
|
2005-08-30 07:51:28 +02:00
|
|
|
pr_debug("%s", inet_csk_timer_bug_msg);
|
2005-08-10 05:11:08 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2014-09-22 22:19:44 +02: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);
|
|
|
|
}
|
|
|
|
|
2013-09-21 19:22:41 +02:00
|
|
|
struct sock *inet_csk_accept(struct sock *sk, int flags, int *err);
|
2005-08-10 05:11:08 +02:00
|
|
|
|
2013-09-21 19:22:41 +02:00
|
|
|
int inet_csk_bind_conflict(const struct sock *sk,
|
|
|
|
const struct inet_bind_bucket *tb, bool relax);
|
|
|
|
int inet_csk_get_port(struct sock *sk, unsigned short snum);
|
2005-08-10 05:10:42 +02:00
|
|
|
|
2015-09-25 16:39:11 +02:00
|
|
|
struct dst_entry *inet_csk_route_req(const struct sock *sk, struct flowi4 *fl4,
|
2013-09-21 19:22:41 +02:00
|
|
|
const struct request_sock *req);
|
2015-09-29 16:42:43 +02:00
|
|
|
struct dst_entry *inet_csk_route_child_sock(const struct sock *sk,
|
|
|
|
struct sock *newsk,
|
2012-07-17 23:02:46 +02:00
|
|
|
const struct request_sock *req);
|
2005-08-10 05:10:42 +02:00
|
|
|
|
2016-02-18 14:39:18 +01:00
|
|
|
struct sock *inet_csk_reqsk_queue_add(struct sock *sk,
|
|
|
|
struct request_sock *req,
|
|
|
|
struct sock *child);
|
2013-09-21 19:22:41 +02:00
|
|
|
void inet_csk_reqsk_queue_hash_add(struct sock *sk, struct request_sock *req,
|
|
|
|
unsigned long timeout);
|
2015-10-22 17:20:46 +02:00
|
|
|
struct sock *inet_csk_complete_hashdance(struct sock *sk, struct sock *child,
|
|
|
|
struct request_sock *req,
|
|
|
|
bool own_req);
|
2005-08-10 05:11:08 +02:00
|
|
|
|
2015-10-02 20:43:31 +02:00
|
|
|
static inline void inet_csk_reqsk_queue_added(struct sock *sk)
|
2005-08-10 05:11:08 +02: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 03:04:20 +01:00
|
|
|
reqsk_queue_added(&inet_csk(sk)->icsk_accept_queue);
|
2005-08-10 05:11:08 +02: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-02 20:43:37 +02:00
|
|
|
return inet_csk_reqsk_queue_len(sk) >= sk->sk_max_ack_backlog;
|
2005-08-10 05:11:08 +02:00
|
|
|
}
|
|
|
|
|
2015-04-24 03:03:44 +02:00
|
|
|
void inet_csk_reqsk_queue_drop(struct sock *sk, struct request_sock *req);
|
2015-10-14 20:16:27 +02:00
|
|
|
void inet_csk_reqsk_queue_drop_and_put(struct sock *sk, struct request_sock *req);
|
2005-08-10 05:11:08 +02:00
|
|
|
|
2013-09-21 19:22:41 +02:00
|
|
|
void inet_csk_destroy_sock(struct sock *sk);
|
|
|
|
void inet_csk_prepare_forced_close(struct sock *sk);
|
2005-08-24 06:52:58 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* LISTEN is a special case for poll..
|
|
|
|
*/
|
|
|
|
static inline unsigned int inet_csk_listen_poll(const struct sock *sk)
|
|
|
|
{
|
|
|
|
return !reqsk_queue_empty(&inet_csk(sk)->icsk_accept_queue) ?
|
|
|
|
(POLLIN | POLLRDNORM) : 0;
|
|
|
|
}
|
|
|
|
|
2015-10-14 15:16:49 +02:00
|
|
|
int inet_csk_listen_start(struct sock *sk, int backlog);
|
2013-09-21 19:22:41 +02:00
|
|
|
void inet_csk_listen_stop(struct sock *sk);
|
2005-08-10 05:11:56 +02:00
|
|
|
|
2013-09-21 19:22:41 +02:00
|
|
|
void inet_csk_addr2sockaddr(struct sock *sk, struct sockaddr *uaddr);
|
2005-12-14 08:16:04 +01:00
|
|
|
|
2013-09-21 19:22:41 +02: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 12:28:06 +02:00
|
|
|
|
2013-09-21 19:22:41 +02:00
|
|
|
struct dst_entry *inet_csk_update_pmtu(struct sock *sk, u32 mtu);
|
2005-08-10 05:10:42 +02:00
|
|
|
#endif /* _INET_CONNECTION_SOCK_H */
|