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
|
|
|
|
*
|
|
|
|
* 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 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>
|
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
|
|
|
#define INET_CSK_DEBUG 1
|
|
|
|
|
|
|
|
/* 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 {
|
2011-05-07 13:23:20 +08:00
|
|
|
int (*queue_xmit)(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);
|
|
|
|
struct sock *(*syn_recv_sock)(struct sock *sk, struct sk_buff *skb,
|
|
|
|
struct request_sock *req,
|
|
|
|
struct dst_entry *dst);
|
[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;
|
2005-12-14 15:15:52 +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);
|
2005-12-14 15:15:52 +08:00
|
|
|
int (*getsockopt)(struct sock *sk, int level, int optname,
|
|
|
|
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 *);
|
[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 20:06:04 +08: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 06:21:45 +08:00
|
|
|
const struct inet_bind_bucket *tb, bool relax);
|
2005-12-14 15:15:52 +08:00
|
|
|
};
|
|
|
|
|
2005-08-10 11:10:42 +08: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 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
|
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;
|
2005-12-14 15:26:10 +08:00
|
|
|
unsigned int (*icsk_sync_mss)(struct sock *sk, u32 pmtu);
|
2005-08-10 15:03:31 +08:00
|
|
|
__u8 icsk_ca_state;
|
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 */
|
|
|
|
__u16 rcv_mss; /* MSS used for delayed ACK decisions */
|
|
|
|
} 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;
|
|
|
|
} icsk_mtup;
|
2005-08-10 15:03:31 +08:00
|
|
|
u32 icsk_ca_priv[16];
|
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;
|
2005-08-10 15:03:31 +08:00
|
|
|
#define ICSK_CA_PRIV_SIZE (16 * sizeof(u32))
|
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 */
|
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,
|
|
|
|
ICSK_ACK_PUSHED2 = 8
|
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,
|
|
|
|
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 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
|
|
|
|
|
|
|
#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 13:51:28 +08:00
|
|
|
pr_debug("%s", inet_csk_timer_bug_msg);
|
2005-08-10 11:11:08 +08: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 18:00:43 +08:00
|
|
|
if (what == ICSK_TIME_RETRANS || what == ICSK_TIME_PROBE0 ||
|
|
|
|
what == ICSK_TIME_EARLY_RETRANS || what == ICSK_TIME_LOSS_PROBE) {
|
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);
|
|
|
|
}
|
|
|
|
#ifdef INET_CSK_DEBUG
|
|
|
|
else {
|
2005-08-30 13:51:28 +08:00
|
|
|
pr_debug("%s", inet_csk_timer_bug_msg);
|
2005-08-10 11:11:08 +08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2013-09-22 01:22:41 +08:00
|
|
|
struct sock *inet_csk_accept(struct sock *sk, int flags, int *err);
|
2005-08-10 11:11:08 +08:00
|
|
|
|
2013-09-22 01:22:41 +08:00
|
|
|
struct request_sock *inet_csk_search_req(const struct sock *sk,
|
|
|
|
struct request_sock ***prevp,
|
|
|
|
const __be16 rport,
|
|
|
|
const __be32 raddr,
|
|
|
|
const __be32 laddr);
|
|
|
|
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 11:10:42 +08:00
|
|
|
|
2013-09-22 01:22:41 +08:00
|
|
|
struct dst_entry *inet_csk_route_req(struct sock *sk, struct flowi4 *fl4,
|
|
|
|
const struct request_sock *req);
|
|
|
|
struct dst_entry *inet_csk_route_child_sock(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
|
|
|
|
2005-08-10 11:11:08 +08:00
|
|
|
static inline void inet_csk_reqsk_queue_add(struct sock *sk,
|
|
|
|
struct request_sock *req,
|
|
|
|
struct sock *child)
|
|
|
|
{
|
|
|
|
reqsk_queue_add(&inet_csk(sk)->icsk_accept_queue, req, sk, 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);
|
2005-08-10 11:11:08 +08:00
|
|
|
|
|
|
|
static inline void inet_csk_reqsk_queue_removed(struct sock *sk,
|
|
|
|
struct request_sock *req)
|
|
|
|
{
|
|
|
|
if (reqsk_queue_removed(&inet_csk(sk)->icsk_accept_queue, req) == 0)
|
|
|
|
inet_csk_delete_keepalive_timer(sk);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void inet_csk_reqsk_queue_added(struct sock *sk,
|
|
|
|
const unsigned long timeout)
|
|
|
|
{
|
|
|
|
if (reqsk_queue_added(&inet_csk(sk)->icsk_accept_queue) == 0)
|
|
|
|
inet_csk_reset_keepalive_timer(sk, timeout);
|
|
|
|
}
|
|
|
|
|
|
|
|
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_young(const struct sock *sk)
|
|
|
|
{
|
|
|
|
return reqsk_queue_len_young(&inet_csk(sk)->icsk_accept_queue);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int inet_csk_reqsk_queue_is_full(const struct sock *sk)
|
|
|
|
{
|
|
|
|
return reqsk_queue_is_full(&inet_csk(sk)->icsk_accept_queue);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void inet_csk_reqsk_queue_unlink(struct sock *sk,
|
|
|
|
struct request_sock *req,
|
|
|
|
struct request_sock **prev)
|
|
|
|
{
|
|
|
|
reqsk_queue_unlink(&inet_csk(sk)->icsk_accept_queue, req, prev);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void inet_csk_reqsk_queue_drop(struct sock *sk,
|
|
|
|
struct request_sock *req,
|
|
|
|
struct request_sock **prev)
|
|
|
|
{
|
|
|
|
inet_csk_reqsk_queue_unlink(sk, req, prev);
|
|
|
|
inet_csk_reqsk_queue_removed(sk, req);
|
|
|
|
reqsk_free(req);
|
|
|
|
}
|
|
|
|
|
2013-09-22 01:22:41 +08:00
|
|
|
void inet_csk_reqsk_queue_prune(struct sock *parent,
|
|
|
|
const unsigned long interval,
|
|
|
|
const unsigned long timeout,
|
|
|
|
const unsigned long max_rto);
|
2005-08-10 11:15:09 +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..
|
|
|
|
*/
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2013-09-22 01:22:41 +08:00
|
|
|
int inet_csk_listen_start(struct sock *sk, const int nr_table_entries);
|
|
|
|
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);
|
2005-08-10 11:10:42 +08:00
|
|
|
#endif /* _INET_CONNECTION_SOCK_H */
|