4 * An implementation of the DCCP protocol
5 * Arnaldo Carvalho de Melo <acme@conectiva.com.br>
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version
10 * 2 of the License, or (at your option) any later version.
13 #include <linux/dccp.h>
14 #include <linux/skbuff.h>
18 /* sysctl variables governing numbers of retransmission attempts */
19 int sysctl_dccp_request_retries __read_mostly
= TCP_SYN_RETRIES
;
20 int sysctl_dccp_retries1 __read_mostly
= TCP_RETR1
;
21 int sysctl_dccp_retries2 __read_mostly
= TCP_RETR2
;
23 static void dccp_write_err(struct sock
*sk
)
25 sk
->sk_err
= sk
->sk_err_soft
? : ETIMEDOUT
;
26 sk
->sk_error_report(sk
);
28 dccp_send_reset(sk
, DCCP_RESET_CODE_ABORTED
);
30 DCCP_INC_STATS_BH(DCCP_MIB_ABORTONTIMEOUT
);
33 /* A write timeout has occurred. Process the after effects. */
34 static int dccp_write_timeout(struct sock
*sk
)
36 const struct inet_connection_sock
*icsk
= inet_csk(sk
);
39 if (sk
->sk_state
== DCCP_REQUESTING
|| sk
->sk_state
== DCCP_PARTOPEN
) {
40 if (icsk
->icsk_retransmits
!= 0)
41 dst_negative_advice(&sk
->sk_dst_cache
);
42 retry_until
= icsk
->icsk_syn_retries
?
43 : sysctl_dccp_request_retries
;
45 if (icsk
->icsk_retransmits
>= sysctl_dccp_retries1
) {
46 /* NOTE. draft-ietf-tcpimpl-pmtud-01.txt requires pmtu
47 black hole detection. :-(
49 It is place to make it. It is not made. I do not want
50 to make it. It is disguisting. It does not work in any
51 case. Let me to cite the same draft, which requires for
54 "The one security concern raised by this memo is that ICMP black holes
55 are often caused by over-zealous security administrators who block
56 all ICMP messages. It is vitally important that those who design and
57 deploy security systems understand the impact of strict filtering on
58 upper-layer protocols. The safest web site in the world is worthless
59 if most TCP implementations cannot transfer data from it. It would
60 be far nicer to have all of the black holes fixed rather than fixing
61 all of the TCP implementations."
66 dst_negative_advice(&sk
->sk_dst_cache
);
69 retry_until
= sysctl_dccp_retries2
;
71 * FIXME: see tcp_write_timout and tcp_out_of_resources
75 if (icsk
->icsk_retransmits
>= retry_until
) {
76 /* Has it gone just too far? */
84 * The DCCP retransmit timer.
86 static void dccp_retransmit_timer(struct sock
*sk
)
88 struct inet_connection_sock
*icsk
= inet_csk(sk
);
91 * More than than 4MSL (8 minutes) has passed, a RESET(aborted) was
92 * sent, no need to retransmit, this sock is dead.
94 if (dccp_write_timeout(sk
))
98 * We want to know the number of packets retransmitted, not the
99 * total number of retransmissions of clones of original packets.
101 if (icsk
->icsk_retransmits
== 0)
102 DCCP_INC_STATS_BH(DCCP_MIB_TIMEOUTS
);
104 if (dccp_retransmit_skb(sk
) != 0) {
106 * Retransmission failed because of local congestion,
109 if (--icsk
->icsk_retransmits
== 0)
110 icsk
->icsk_retransmits
= 1;
111 inet_csk_reset_xmit_timer(sk
, ICSK_TIME_RETRANS
,
113 TCP_RESOURCE_PROBE_INTERVAL
),
118 icsk
->icsk_backoff
++;
120 icsk
->icsk_rto
= min(icsk
->icsk_rto
<< 1, DCCP_RTO_MAX
);
121 inet_csk_reset_xmit_timer(sk
, ICSK_TIME_RETRANS
, icsk
->icsk_rto
,
123 if (icsk
->icsk_retransmits
> sysctl_dccp_retries1
)
127 static void dccp_write_timer(unsigned long data
)
129 struct sock
*sk
= (struct sock
*)data
;
130 struct inet_connection_sock
*icsk
= inet_csk(sk
);
134 if (sock_owned_by_user(sk
)) {
135 /* Try again later */
136 sk_reset_timer(sk
, &icsk
->icsk_retransmit_timer
,
137 jiffies
+ (HZ
/ 20));
141 if (sk
->sk_state
== DCCP_CLOSED
|| !icsk
->icsk_pending
)
144 if (time_after(icsk
->icsk_timeout
, jiffies
)) {
145 sk_reset_timer(sk
, &icsk
->icsk_retransmit_timer
,
150 event
= icsk
->icsk_pending
;
151 icsk
->icsk_pending
= 0;
154 case ICSK_TIME_RETRANS
:
155 dccp_retransmit_timer(sk
);
164 * Timer for listening sockets
166 static void dccp_response_timer(struct sock
*sk
)
168 inet_csk_reqsk_queue_prune(sk
, TCP_SYNQ_INTERVAL
, DCCP_TIMEOUT_INIT
,
172 static void dccp_keepalive_timer(unsigned long data
)
174 struct sock
*sk
= (struct sock
*)data
;
176 /* Only process if socket is not in use. */
178 if (sock_owned_by_user(sk
)) {
179 /* Try again later. */
180 inet_csk_reset_keepalive_timer(sk
, HZ
/ 20);
184 if (sk
->sk_state
== DCCP_LISTEN
) {
185 dccp_response_timer(sk
);
193 /* This is the same as tcp_delack_timer, sans prequeue & mem_reclaim stuff */
194 static void dccp_delack_timer(unsigned long data
)
196 struct sock
*sk
= (struct sock
*)data
;
197 struct inet_connection_sock
*icsk
= inet_csk(sk
);
200 if (sock_owned_by_user(sk
)) {
201 /* Try again later. */
202 icsk
->icsk_ack
.blocked
= 1;
203 NET_INC_STATS_BH(sock_net(sk
), LINUX_MIB_DELAYEDACKLOCKED
);
204 sk_reset_timer(sk
, &icsk
->icsk_delack_timer
,
205 jiffies
+ TCP_DELACK_MIN
);
209 if (sk
->sk_state
== DCCP_CLOSED
||
210 !(icsk
->icsk_ack
.pending
& ICSK_ACK_TIMER
))
212 if (time_after(icsk
->icsk_ack
.timeout
, jiffies
)) {
213 sk_reset_timer(sk
, &icsk
->icsk_delack_timer
,
214 icsk
->icsk_ack
.timeout
);
218 icsk
->icsk_ack
.pending
&= ~ICSK_ACK_TIMER
;
220 if (inet_csk_ack_scheduled(sk
)) {
221 if (!icsk
->icsk_ack
.pingpong
) {
222 /* Delayed ACK missed: inflate ATO. */
223 icsk
->icsk_ack
.ato
= min(icsk
->icsk_ack
.ato
<< 1,
226 /* Delayed ACK missed: leave pingpong mode and
229 icsk
->icsk_ack
.pingpong
= 0;
230 icsk
->icsk_ack
.ato
= TCP_ATO_MIN
;
233 NET_INC_STATS_BH(sock_net(sk
), LINUX_MIB_DELAYEDACKS
);
240 /* Transmit-delay timer: used by the CCIDs to delay actual send time */
241 static void dccp_write_xmit_timer(unsigned long data
)
243 struct sock
*sk
= (struct sock
*)data
;
244 struct dccp_sock
*dp
= dccp_sk(sk
);
247 if (sock_owned_by_user(sk
))
248 sk_reset_timer(sk
, &dp
->dccps_xmit_timer
, jiffies
+1);
250 dccp_write_xmit(sk
, 0);
255 static void dccp_init_write_xmit_timer(struct sock
*sk
)
257 struct dccp_sock
*dp
= dccp_sk(sk
);
259 setup_timer(&dp
->dccps_xmit_timer
, dccp_write_xmit_timer
,
263 void dccp_init_xmit_timers(struct sock
*sk
)
265 dccp_init_write_xmit_timer(sk
);
266 inet_csk_init_xmit_timers(sk
, &dccp_write_timer
, &dccp_delack_timer
,
267 &dccp_keepalive_timer
);
270 static ktime_t dccp_timestamp_seed
;
272 * dccp_timestamp - 10s of microseconds time source
273 * Returns the number of 10s of microseconds since loading DCCP. This is native
274 * DCCP time difference format (RFC 4340, sec. 13).
275 * Please note: This will wrap around about circa every 11.9 hours.
277 u32
dccp_timestamp(void)
279 s64 delta
= ktime_us_delta(ktime_get_real(), dccp_timestamp_seed
);
284 EXPORT_SYMBOL_GPL(dccp_timestamp
);
286 void __init
dccp_timestamping_init(void)
288 dccp_timestamp_seed
= ktime_get_real();