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 static void dccp_write_timer(unsigned long data
);
19 static void dccp_keepalive_timer(unsigned long data
);
20 static void dccp_delack_timer(unsigned long data
);
22 void dccp_init_xmit_timers(struct sock
*sk
)
24 inet_csk_init_xmit_timers(sk
, &dccp_write_timer
, &dccp_delack_timer
,
25 &dccp_keepalive_timer
);
28 static void dccp_write_err(struct sock
*sk
)
30 sk
->sk_err
= sk
->sk_err_soft
? : ETIMEDOUT
;
31 sk
->sk_error_report(sk
);
33 dccp_send_reset(sk
, DCCP_RESET_CODE_ABORTED
);
35 DCCP_INC_STATS_BH(DCCP_MIB_ABORTONTIMEOUT
);
38 /* A write timeout has occurred. Process the after effects. */
39 static int dccp_write_timeout(struct sock
*sk
)
41 const struct inet_connection_sock
*icsk
= inet_csk(sk
);
44 if (sk
->sk_state
== DCCP_REQUESTING
|| sk
->sk_state
== DCCP_PARTOPEN
) {
45 if (icsk
->icsk_retransmits
!= 0)
46 dst_negative_advice(&sk
->sk_dst_cache
);
47 retry_until
= icsk
->icsk_syn_retries
? :
48 /* FIXME! */ 3 /* FIXME! sysctl_tcp_syn_retries */;
50 if (icsk
->icsk_retransmits
>=
51 /* FIXME! sysctl_tcp_retries1 */ 5 /* FIXME! */) {
52 /* NOTE. draft-ietf-tcpimpl-pmtud-01.txt requires pmtu
53 black hole detection. :-(
55 It is place to make it. It is not made. I do not want
56 to make it. It is disguisting. It does not work in any
57 case. Let me to cite the same draft, which requires for
60 "The one security concern raised by this memo is that ICMP black holes
61 are often caused by over-zealous security administrators who block
62 all ICMP messages. It is vitally important that those who design and
63 deploy security systems understand the impact of strict filtering on
64 upper-layer protocols. The safest web site in the world is worthless
65 if most TCP implementations cannot transfer data from it. It would
66 be far nicer to have all of the black holes fixed rather than fixing
67 all of the TCP implementations."
72 dst_negative_advice(&sk
->sk_dst_cache
);
75 retry_until
= /* FIXME! */ 15 /* FIXME! sysctl_tcp_retries2 */;
77 * FIXME: see tcp_write_timout and tcp_out_of_resources
81 if (icsk
->icsk_retransmits
>= retry_until
) {
82 /* Has it gone just too far? */
89 /* This is the same as tcp_delack_timer, sans prequeue & mem_reclaim stuff */
90 static void dccp_delack_timer(unsigned long data
)
92 struct sock
*sk
= (struct sock
*)data
;
93 struct inet_connection_sock
*icsk
= inet_csk(sk
);
96 if (sock_owned_by_user(sk
)) {
97 /* Try again later. */
98 icsk
->icsk_ack
.blocked
= 1;
99 NET_INC_STATS_BH(LINUX_MIB_DELAYEDACKLOCKED
);
100 sk_reset_timer(sk
, &icsk
->icsk_delack_timer
,
101 jiffies
+ TCP_DELACK_MIN
);
105 if (sk
->sk_state
== DCCP_CLOSED
||
106 !(icsk
->icsk_ack
.pending
& ICSK_ACK_TIMER
))
108 if (time_after(icsk
->icsk_ack
.timeout
, jiffies
)) {
109 sk_reset_timer(sk
, &icsk
->icsk_delack_timer
,
110 icsk
->icsk_ack
.timeout
);
114 icsk
->icsk_ack
.pending
&= ~ICSK_ACK_TIMER
;
116 if (inet_csk_ack_scheduled(sk
)) {
117 if (!icsk
->icsk_ack
.pingpong
) {
118 /* Delayed ACK missed: inflate ATO. */
119 icsk
->icsk_ack
.ato
= min(icsk
->icsk_ack
.ato
<< 1,
122 /* Delayed ACK missed: leave pingpong mode and
125 icsk
->icsk_ack
.pingpong
= 0;
126 icsk
->icsk_ack
.ato
= TCP_ATO_MIN
;
129 NET_INC_STATS_BH(LINUX_MIB_DELAYEDACKS
);
137 * The DCCP retransmit timer.
139 static void dccp_retransmit_timer(struct sock
*sk
)
141 struct inet_connection_sock
*icsk
= inet_csk(sk
);
143 /* retransmit timer is used for feature negotiation throughout
144 * connection. In this case, no packet is re-transmitted, but rather an
145 * ack is generated and pending changes are placed into its options.
147 if (sk
->sk_send_head
== NULL
) {
148 dccp_pr_debug("feat negotiation retransmit timeout %p\n", sk
);
149 if (sk
->sk_state
== DCCP_OPEN
)
155 * sk->sk_send_head has to have one skb with
156 * DCCP_SKB_CB(skb)->dccpd_type set to one of the retransmittable DCCP
157 * packet types. The only packets eligible for retransmission are:
158 * -- Requests in client-REQUEST state (sec. 8.1.1)
159 * -- Acks in client-PARTOPEN state (sec. 8.1.5)
160 * -- CloseReq in server-CLOSEREQ state (sec. 8.3)
161 * -- Close in node-CLOSING state (sec. 8.3) */
162 BUG_TRAP(sk
->sk_send_head
!= NULL
);
165 * More than than 4MSL (8 minutes) has passed, a RESET(aborted) was
166 * sent, no need to retransmit, this sock is dead.
168 if (dccp_write_timeout(sk
))
172 * We want to know the number of packets retransmitted, not the
173 * total number of retransmissions of clones of original packets.
175 if (icsk
->icsk_retransmits
== 0)
176 DCCP_INC_STATS_BH(DCCP_MIB_TIMEOUTS
);
178 if (dccp_retransmit_skb(sk
, sk
->sk_send_head
) < 0) {
180 * Retransmission failed because of local congestion,
183 if (icsk
->icsk_retransmits
== 0)
184 icsk
->icsk_retransmits
= 1;
185 inet_csk_reset_xmit_timer(sk
, ICSK_TIME_RETRANS
,
187 TCP_RESOURCE_PROBE_INTERVAL
),
193 icsk
->icsk_backoff
++;
194 icsk
->icsk_retransmits
++;
196 icsk
->icsk_rto
= min(icsk
->icsk_rto
<< 1, DCCP_RTO_MAX
);
197 inet_csk_reset_xmit_timer(sk
, ICSK_TIME_RETRANS
, icsk
->icsk_rto
,
199 if (icsk
->icsk_retransmits
> 3 /* FIXME: sysctl_dccp_retries1 */)
204 static void dccp_write_timer(unsigned long data
)
206 struct sock
*sk
= (struct sock
*)data
;
207 struct inet_connection_sock
*icsk
= inet_csk(sk
);
211 if (sock_owned_by_user(sk
)) {
212 /* Try again later */
213 sk_reset_timer(sk
, &icsk
->icsk_retransmit_timer
,
214 jiffies
+ (HZ
/ 20));
218 if (sk
->sk_state
== DCCP_CLOSED
|| !icsk
->icsk_pending
)
221 if (time_after(icsk
->icsk_timeout
, jiffies
)) {
222 sk_reset_timer(sk
, &icsk
->icsk_retransmit_timer
,
227 event
= icsk
->icsk_pending
;
228 icsk
->icsk_pending
= 0;
231 case ICSK_TIME_RETRANS
:
232 dccp_retransmit_timer(sk
);
241 * Timer for listening sockets
243 static void dccp_response_timer(struct sock
*sk
)
245 inet_csk_reqsk_queue_prune(sk
, TCP_SYNQ_INTERVAL
, DCCP_TIMEOUT_INIT
,
249 static void dccp_keepalive_timer(unsigned long data
)
251 struct sock
*sk
= (struct sock
*)data
;
253 /* Only process if socket is not in use. */
255 if (sock_owned_by_user(sk
)) {
256 /* Try again later. */
257 inet_csk_reset_keepalive_timer(sk
, HZ
/ 20);
261 if (sk
->sk_state
== DCCP_LISTEN
) {
262 dccp_response_timer(sk
);