2019-05-27 09:55:01 +03:00
// SPDX-License-Identifier: GPL-2.0-or-later
2005-08-10 07:14:34 +04:00
/*
* net / dccp / timer . c
2006-12-10 21:01:18 +03:00
*
2005-08-10 07:14:34 +04:00
* An implementation of the DCCP protocol
* Arnaldo Carvalho de Melo < acme @ conectiva . com . br >
*/
# include <linux/dccp.h>
# include <linux/skbuff.h>
2011-07-15 19:47:34 +04:00
# include <linux/export.h>
2005-08-10 07:14:34 +04:00
# include "dccp.h"
2006-11-13 18:23:52 +03:00
/* sysctl variables governing numbers of retransmission attempts */
int sysctl_dccp_request_retries __read_mostly = TCP_SYN_RETRIES ;
int sysctl_dccp_retries1 __read_mostly = TCP_RETR1 ;
int sysctl_dccp_retries2 __read_mostly = TCP_RETR2 ;
2005-08-10 07:14:34 +04:00
static void dccp_write_err ( struct sock * sk )
{
sk - > sk_err = sk - > sk_err_soft ? : ETIMEDOUT ;
2021-06-28 01:48:21 +03:00
sk_error_report ( sk ) ;
2005-08-10 07:14:34 +04:00
2006-03-21 06:25:24 +03:00
dccp_send_reset ( sk , DCCP_RESET_CODE_ABORTED ) ;
2005-08-10 07:14:34 +04:00
dccp_done ( sk ) ;
2016-04-28 02:44:28 +03:00
__DCCP_INC_STATS ( DCCP_MIB_ABORTONTIMEOUT ) ;
2005-08-10 07:14:34 +04:00
}
/* A write timeout has occurred. Process the after effects. */
static int dccp_write_timeout ( struct sock * sk )
{
const struct inet_connection_sock * icsk = inet_csk ( sk ) ;
int retry_until ;
if ( sk - > sk_state = = DCCP_REQUESTING | | sk - > sk_state = = DCCP_PARTOPEN ) {
if ( icsk - > icsk_retransmits ! = 0 )
2010-04-09 03:03:29 +04:00
dst_negative_advice ( sk ) ;
2006-11-13 18:23:52 +03:00
retry_until = icsk - > icsk_syn_retries ?
: sysctl_dccp_request_retries ;
2005-08-10 07:14:34 +04:00
} else {
2006-11-13 18:23:52 +03:00
if ( icsk - > icsk_retransmits > = sysctl_dccp_retries1 ) {
2005-08-14 03:34:54 +04:00
/* NOTE. draft-ietf-tcpimpl-pmtud-01.txt requires pmtu
black hole detection . : - (
2005-08-10 07:14:34 +04:00
It is place to make it . It is not made . I do not want
to make it . It is disguisting . It does not work in any
case . Let me to cite the same draft , which requires for
us to implement this :
" The one security concern raised by this memo is that ICMP black holes
are often caused by over - zealous security administrators who block
all ICMP messages . It is vitally important that those who design and
deploy security systems understand the impact of strict filtering on
upper - layer protocols . The safest web site in the world is worthless
if most TCP implementations cannot transfer data from it . It would
be far nicer to have all of the black holes fixed rather than fixing
all of the TCP implementations . "
2007-02-09 17:24:38 +03:00
Golden words : - ) .
2005-08-10 07:14:34 +04:00
*/
2010-04-09 03:03:29 +04:00
dst_negative_advice ( sk ) ;
2005-08-10 07:14:34 +04:00
}
2006-11-13 18:23:52 +03:00
retry_until = sysctl_dccp_retries2 ;
2005-08-10 07:14:34 +04:00
/*
* FIXME : see tcp_write_timout and tcp_out_of_resources
*/
}
if ( icsk - > icsk_retransmits > = retry_until ) {
/* Has it gone just too far? */
dccp_write_err ( sk ) ;
return 1 ;
}
return 0 ;
}
/*
* The DCCP retransmit timer .
*/
static void dccp_retransmit_timer ( struct sock * sk )
{
struct inet_connection_sock * icsk = inet_csk ( sk ) ;
2006-12-10 21:01:18 +03:00
/*
2020-08-23 04:07:13 +03:00
* More than 4 MSL ( 8 minutes ) has passed , a RESET ( aborted ) was
2005-08-10 07:14:34 +04:00
* sent , no need to retransmit , this sock is dead .
*/
if ( dccp_write_timeout ( sk ) )
2008-07-26 14:59:09 +04:00
return ;
2005-08-10 07:14:34 +04:00
/*
* We want to know the number of packets retransmitted , not the
* total number of retransmissions of clones of original packets .
*/
if ( icsk - > icsk_retransmits = = 0 )
2016-04-28 02:44:28 +03:00
__DCCP_INC_STATS ( DCCP_MIB_TIMEOUTS ) ;
2005-08-10 07:14:34 +04:00
2008-07-26 14:59:09 +04:00
if ( dccp_retransmit_skb ( sk ) ! = 0 ) {
2005-08-10 07:14:34 +04:00
/*
* Retransmission failed because of local congestion ,
* do not backoff .
*/
2008-07-26 14:59:09 +04:00
if ( - - icsk - > icsk_retransmits = = 0 )
2005-08-10 07:14:34 +04:00
icsk - > icsk_retransmits = 1 ;
inet_csk_reset_xmit_timer ( sk , ICSK_TIME_RETRANS ,
min ( icsk - > icsk_rto ,
TCP_RESOURCE_PROBE_INTERVAL ) ,
2005-08-14 03:34:54 +04:00
DCCP_RTO_MAX ) ;
2008-07-26 14:59:09 +04:00
return ;
2005-08-10 07:14:34 +04:00
}
icsk - > icsk_backoff + + ;
icsk - > icsk_rto = min ( icsk - > icsk_rto < < 1 , DCCP_RTO_MAX ) ;
2005-08-14 03:34:54 +04:00
inet_csk_reset_xmit_timer ( sk , ICSK_TIME_RETRANS , icsk - > icsk_rto ,
DCCP_RTO_MAX ) ;
2006-11-13 18:23:52 +03:00
if ( icsk - > icsk_retransmits > sysctl_dccp_retries1 )
2005-08-10 07:14:34 +04:00
__sk_dst_reset ( sk ) ;
}
2017-10-17 03:29:19 +03:00
static void dccp_write_timer ( struct timer_list * t )
2005-08-10 07:14:34 +04:00
{
2017-10-17 03:29:19 +03:00
struct inet_connection_sock * icsk =
from_timer ( icsk , t , icsk_retransmit_timer ) ;
struct sock * sk = & icsk - > icsk_inet . sk ;
2005-08-10 07:14:34 +04:00
int event = 0 ;
bh_lock_sock ( sk ) ;
if ( sock_owned_by_user ( sk ) ) {
/* Try again later */
2005-08-14 03:34:54 +04:00
sk_reset_timer ( sk , & icsk - > icsk_retransmit_timer ,
jiffies + ( HZ / 20 ) ) ;
2005-08-10 07:14:34 +04:00
goto out ;
}
if ( sk - > sk_state = = DCCP_CLOSED | | ! icsk - > icsk_pending )
goto out ;
if ( time_after ( icsk - > icsk_timeout , jiffies ) ) {
2005-08-14 03:34:54 +04:00
sk_reset_timer ( sk , & icsk - > icsk_retransmit_timer ,
icsk - > icsk_timeout ) ;
2005-08-10 07:14:34 +04:00
goto out ;
}
event = icsk - > icsk_pending ;
icsk - > icsk_pending = 0 ;
switch ( event ) {
case ICSK_TIME_RETRANS :
dccp_retransmit_timer ( sk ) ;
break ;
}
out :
bh_unlock_sock ( sk ) ;
sock_put ( sk ) ;
}
2017-10-17 03:29:19 +03:00
static void dccp_keepalive_timer ( struct timer_list * t )
2005-08-10 07:14:34 +04:00
{
2017-10-17 03:29:19 +03:00
struct sock * sk = from_timer ( sk , t , sk_timer ) ;
2005-08-10 07:14:34 +04: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 05:04:20 +03:00
pr_err ( " dccp should not use a keepalive timer ! \n " ) ;
2005-08-10 07:14:34 +04:00
sock_put ( sk ) ;
}
2006-11-13 18:26:51 +03:00
/* This is the same as tcp_delack_timer, sans prequeue & mem_reclaim stuff */
2017-10-17 03:29:19 +03:00
static void dccp_delack_timer ( struct timer_list * t )
2006-11-13 18:26:51 +03:00
{
2017-10-17 03:29:19 +03:00
struct inet_connection_sock * icsk =
from_timer ( icsk , t , icsk_delack_timer ) ;
struct sock * sk = & icsk - > icsk_inet . sk ;
2006-11-13 18:26:51 +03:00
bh_lock_sock ( sk ) ;
if ( sock_owned_by_user ( sk ) ) {
/* Try again later. */
2016-04-28 02:44:39 +03:00
__NET_INC_STATS ( sock_net ( sk ) , LINUX_MIB_DELAYEDACKLOCKED ) ;
2006-11-13 18:26:51 +03:00
sk_reset_timer ( sk , & icsk - > icsk_delack_timer ,
jiffies + TCP_DELACK_MIN ) ;
goto out ;
}
if ( sk - > sk_state = = DCCP_CLOSED | |
! ( icsk - > icsk_ack . pending & ICSK_ACK_TIMER ) )
goto out ;
if ( time_after ( icsk - > icsk_ack . timeout , jiffies ) ) {
sk_reset_timer ( sk , & icsk - > icsk_delack_timer ,
icsk - > icsk_ack . timeout ) ;
goto out ;
}
icsk - > icsk_ack . pending & = ~ ICSK_ACK_TIMER ;
if ( inet_csk_ack_scheduled ( sk ) ) {
2019-01-25 21:53:19 +03:00
if ( ! inet_csk_in_pingpong_mode ( sk ) ) {
2006-11-13 18:26:51 +03:00
/* Delayed ACK missed: inflate ATO. */
icsk - > icsk_ack . ato = min ( icsk - > icsk_ack . ato < < 1 ,
icsk - > icsk_rto ) ;
} else {
/* Delayed ACK missed: leave pingpong mode and
* deflate ATO .
*/
2019-01-25 21:53:19 +03:00
inet_csk_exit_pingpong_mode ( sk ) ;
2006-11-13 18:26:51 +03:00
icsk - > icsk_ack . ato = TCP_ATO_MIN ;
}
dccp_send_ack ( sk ) ;
2016-04-28 02:44:39 +03:00
__NET_INC_STATS ( sock_net ( sk ) , LINUX_MIB_DELAYEDACKS ) ;
2006-11-13 18:26:51 +03:00
}
out :
bh_unlock_sock ( sk ) ;
sock_put ( sk ) ;
}
dccp: Extend CCID packet dequeueing interface
This extends the packet dequeuing interface of dccp_write_xmit() to allow
1. CCIDs to take care of timing when the next packet may be sent;
2. delayed sending (as before, with an inter-packet gap up to 65.535 seconds).
The main purpose is to take CCID-2 out of its polling mode (when it is network-
limited, it tries every millisecond to send, without interruption).
The mode of operation for (2) is as follows:
* new packet is enqueued via dccp_sendmsg() => dccp_write_xmit(),
* ccid_hc_tx_send_packet() detects that it may not send (e.g. window full),
* it signals this condition via `CCID_PACKET_WILL_DEQUEUE_LATER',
* dccp_write_xmit() returns without further action;
* after some time the wait-condition for CCID becomes true,
* that CCID schedules the tasklet,
* tasklet function calls ccid_hc_tx_send_packet() via dccp_write_xmit(),
* since the wait-condition is now true, ccid_hc_tx_packet() returns "send now",
* packet is sent, and possibly more (since dccp_write_xmit() loops).
Code reuse: the taskled function calls dccp_write_xmit(), the timer function
reduces to a wrapper around the same code.
Signed-off-by: Gerrit Renker <gerrit@erg.abdn.ac.uk>
Signed-off-by: David S. Miller <davem@davemloft.net>
2010-10-27 23:16:26 +04:00
/**
* dccp_write_xmitlet - Workhorse for CCID packet dequeueing interface
2020-11-03 12:18:16 +03:00
* @ t : pointer to the tasklet associated with this handler
2020-07-13 02:15:00 +03:00
*
dccp: Extend CCID packet dequeueing interface
This extends the packet dequeuing interface of dccp_write_xmit() to allow
1. CCIDs to take care of timing when the next packet may be sent;
2. delayed sending (as before, with an inter-packet gap up to 65.535 seconds).
The main purpose is to take CCID-2 out of its polling mode (when it is network-
limited, it tries every millisecond to send, without interruption).
The mode of operation for (2) is as follows:
* new packet is enqueued via dccp_sendmsg() => dccp_write_xmit(),
* ccid_hc_tx_send_packet() detects that it may not send (e.g. window full),
* it signals this condition via `CCID_PACKET_WILL_DEQUEUE_LATER',
* dccp_write_xmit() returns without further action;
* after some time the wait-condition for CCID becomes true,
* that CCID schedules the tasklet,
* tasklet function calls ccid_hc_tx_send_packet() via dccp_write_xmit(),
* since the wait-condition is now true, ccid_hc_tx_packet() returns "send now",
* packet is sent, and possibly more (since dccp_write_xmit() loops).
Code reuse: the taskled function calls dccp_write_xmit(), the timer function
reduces to a wrapper around the same code.
Signed-off-by: Gerrit Renker <gerrit@erg.abdn.ac.uk>
Signed-off-by: David S. Miller <davem@davemloft.net>
2010-10-27 23:16:26 +04:00
* See the comments above % ccid_dequeueing_decision for supported modes .
*/
2020-11-03 12:18:16 +03:00
static void dccp_write_xmitlet ( struct tasklet_struct * t )
2007-03-10 00:47:58 +03:00
{
2020-11-03 12:18:16 +03:00
struct dccp_sock * dp = from_tasklet ( dp , t , dccps_xmitlet ) ;
struct sock * sk = & dp - > dccps_inet_connection . icsk_inet . sk ;
2007-03-10 00:47:58 +03:00
bh_lock_sock ( sk ) ;
if ( sock_owned_by_user ( sk ) )
dccp: Extend CCID packet dequeueing interface
This extends the packet dequeuing interface of dccp_write_xmit() to allow
1. CCIDs to take care of timing when the next packet may be sent;
2. delayed sending (as before, with an inter-packet gap up to 65.535 seconds).
The main purpose is to take CCID-2 out of its polling mode (when it is network-
limited, it tries every millisecond to send, without interruption).
The mode of operation for (2) is as follows:
* new packet is enqueued via dccp_sendmsg() => dccp_write_xmit(),
* ccid_hc_tx_send_packet() detects that it may not send (e.g. window full),
* it signals this condition via `CCID_PACKET_WILL_DEQUEUE_LATER',
* dccp_write_xmit() returns without further action;
* after some time the wait-condition for CCID becomes true,
* that CCID schedules the tasklet,
* tasklet function calls ccid_hc_tx_send_packet() via dccp_write_xmit(),
* since the wait-condition is now true, ccid_hc_tx_packet() returns "send now",
* packet is sent, and possibly more (since dccp_write_xmit() loops).
Code reuse: the taskled function calls dccp_write_xmit(), the timer function
reduces to a wrapper around the same code.
Signed-off-by: Gerrit Renker <gerrit@erg.abdn.ac.uk>
Signed-off-by: David S. Miller <davem@davemloft.net>
2010-10-27 23:16:26 +04:00
sk_reset_timer ( sk , & dccp_sk ( sk ) - > dccps_xmit_timer , jiffies + 1 ) ;
2007-03-10 00:47:58 +03:00
else
dccp: Refine the wait-for-ccid mechanism
This extends the existing wait-for-ccid routine so that it may be used with
different types of CCID, addressing the following problems:
1) The queue-drain mechanism only works with rate-based CCIDs. If CCID-2 for
example has a full TX queue and becomes network-limited just as the
application wants to close, then waiting for CCID-2 to become unblocked
could lead to an indefinite delay (i.e., application "hangs").
2) Since each TX CCID in turn uses a feedback mechanism, there may be changes
in its sending policy while the queue is being drained. This can lead to
further delays during which the application will not be able to terminate.
3) The minimum wait time for CCID-3/4 can be expected to be the queue length
times the current inter-packet delay. For example if tx_qlen=100 and a delay
of 15 ms is used for each packet, then the application would have to wait
for a minimum of 1.5 seconds before being allowed to exit.
4) There is no way for the user/application to control this behaviour. It would
be good to use the timeout argument of dccp_close() as an upper bound. Then
the maximum time that an application is willing to wait for its CCIDs to can
be set via the SO_LINGER option.
These problems are addressed by giving the CCID a grace period of up to the
`timeout' value.
The wait-for-ccid function is, as before, used when the application
(a) has read all the data in its receive buffer and
(b) if SO_LINGER was set with a non-zero linger time, or
(c) the socket is either in the OPEN (active close) or in the PASSIVE_CLOSEREQ
state (client application closes after receiving CloseReq).
In addition, there is a catch-all case of __skb_queue_purge() after waiting for
the CCID. This is necessary since the write queue may still have data when
(a) the host has been passively-closed,
(b) abnormal termination (unread data, zero linger time),
(c) wait-for-ccid could not finish within the given time limit.
Signed-off-by: Gerrit Renker <gerrit@erg.abdn.ac.uk>
Signed-off-by: David S. Miller <davem@davemloft.net>
2010-10-27 23:16:27 +04:00
dccp_write_xmit ( sk ) ;
2007-03-10 00:47:58 +03:00
bh_unlock_sock ( sk ) ;
2018-05-03 19:39:20 +03:00
sock_put ( sk ) ;
2007-03-10 00:47:58 +03:00
}
2017-10-24 11:46:09 +03:00
static void dccp_write_xmit_timer ( struct timer_list * t )
2007-03-10 00:47:58 +03:00
{
2017-10-24 11:46:09 +03:00
struct dccp_sock * dp = from_timer ( dp , t , dccps_xmit_timer ) ;
2020-11-03 12:18:16 +03:00
dccp_write_xmitlet ( & dp - > dccps_xmitlet ) ;
2007-03-10 00:47:58 +03:00
}
2006-11-13 18:26:51 +03:00
void dccp_init_xmit_timers ( struct sock * sk )
{
dccp: Extend CCID packet dequeueing interface
This extends the packet dequeuing interface of dccp_write_xmit() to allow
1. CCIDs to take care of timing when the next packet may be sent;
2. delayed sending (as before, with an inter-packet gap up to 65.535 seconds).
The main purpose is to take CCID-2 out of its polling mode (when it is network-
limited, it tries every millisecond to send, without interruption).
The mode of operation for (2) is as follows:
* new packet is enqueued via dccp_sendmsg() => dccp_write_xmit(),
* ccid_hc_tx_send_packet() detects that it may not send (e.g. window full),
* it signals this condition via `CCID_PACKET_WILL_DEQUEUE_LATER',
* dccp_write_xmit() returns without further action;
* after some time the wait-condition for CCID becomes true,
* that CCID schedules the tasklet,
* tasklet function calls ccid_hc_tx_send_packet() via dccp_write_xmit(),
* since the wait-condition is now true, ccid_hc_tx_packet() returns "send now",
* packet is sent, and possibly more (since dccp_write_xmit() loops).
Code reuse: the taskled function calls dccp_write_xmit(), the timer function
reduces to a wrapper around the same code.
Signed-off-by: Gerrit Renker <gerrit@erg.abdn.ac.uk>
Signed-off-by: David S. Miller <davem@davemloft.net>
2010-10-27 23:16:26 +04:00
struct dccp_sock * dp = dccp_sk ( sk ) ;
2020-11-03 12:18:16 +03:00
tasklet_setup ( & dp - > dccps_xmitlet , dccp_write_xmitlet ) ;
2017-10-24 11:46:09 +03:00
timer_setup ( & dp - > dccps_xmit_timer , dccp_write_xmit_timer , 0 ) ;
2006-11-13 18:26:51 +03:00
inet_csk_init_xmit_timers ( sk , & dccp_write_timer , & dccp_delack_timer ,
& dccp_keepalive_timer ) ;
}
2007-09-26 09:40:13 +04:00
static ktime_t dccp_timestamp_seed ;
/**
* dccp_timestamp - 10 s of microseconds time source
* Returns the number of 10 s of microseconds since loading DCCP . This is native
* DCCP time difference format ( RFC 4340 , sec . 13 ) .
* Please note : This will wrap around about circa every 11.9 hours .
*/
u32 dccp_timestamp ( void )
{
2014-05-21 04:19:34 +04:00
u64 delta = ( u64 ) ktime_us_delta ( ktime_get_real ( ) , dccp_timestamp_seed ) ;
2007-09-26 09:40:13 +04:00
do_div ( delta , 10 ) ;
return delta ;
}
EXPORT_SYMBOL_GPL ( dccp_timestamp ) ;
void __init dccp_timestamping_init ( void )
{
dccp_timestamp_seed = ktime_get_real ( ) ;
}