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_timer(unsigned long data);
24 static void dccp_keepalive_timer(unsigned long data);
25 static void dccp_delack_timer(unsigned long data);
27 void dccp_init_xmit_timers(struct sock *sk)
29 inet_csk_init_xmit_timers(sk, &dccp_write_timer, &dccp_delack_timer,
30 &dccp_keepalive_timer);
33 static void dccp_write_err(struct sock *sk)
35 sk->sk_err = sk->sk_err_soft ? : ETIMEDOUT;
36 sk->sk_error_report(sk);
38 dccp_send_reset(sk, DCCP_RESET_CODE_ABORTED);
40 DCCP_INC_STATS_BH(DCCP_MIB_ABORTONTIMEOUT);
43 /* A write timeout has occurred. Process the after effects. */
44 static int dccp_write_timeout(struct sock *sk)
46 const struct inet_connection_sock *icsk = inet_csk(sk);
49 if (sk->sk_state == DCCP_REQUESTING || sk->sk_state == DCCP_PARTOPEN) {
50 if (icsk->icsk_retransmits != 0)
51 dst_negative_advice(&sk->sk_dst_cache);
52 retry_until = icsk->icsk_syn_retries ?
53 : sysctl_dccp_request_retries;
55 if (icsk->icsk_retransmits >= sysctl_dccp_retries1) {
56 /* NOTE. draft-ietf-tcpimpl-pmtud-01.txt requires pmtu
57 black hole detection. :-(
59 It is place to make it. It is not made. I do not want
60 to make it. It is disguisting. It does not work in any
61 case. Let me to cite the same draft, which requires for
64 "The one security concern raised by this memo is that ICMP black holes
65 are often caused by over-zealous security administrators who block
66 all ICMP messages. It is vitally important that those who design and
67 deploy security systems understand the impact of strict filtering on
68 upper-layer protocols. The safest web site in the world is worthless
69 if most TCP implementations cannot transfer data from it. It would
70 be far nicer to have all of the black holes fixed rather than fixing
71 all of the TCP implementations."
76 dst_negative_advice(&sk->sk_dst_cache);
79 retry_until = sysctl_dccp_retries2;
81 * FIXME: see tcp_write_timout and tcp_out_of_resources
85 if (icsk->icsk_retransmits >= retry_until) {
86 /* Has it gone just too far? */
93 /* This is the same as tcp_delack_timer, sans prequeue & mem_reclaim stuff */
94 static void dccp_delack_timer(unsigned long data)
96 struct sock *sk = (struct sock *)data;
97 struct inet_connection_sock *icsk = inet_csk(sk);
100 if (sock_owned_by_user(sk)) {
101 /* Try again later. */
102 icsk->icsk_ack.blocked = 1;
103 NET_INC_STATS_BH(LINUX_MIB_DELAYEDACKLOCKED);
104 sk_reset_timer(sk, &icsk->icsk_delack_timer,
105 jiffies + TCP_DELACK_MIN);
109 if (sk->sk_state == DCCP_CLOSED ||
110 !(icsk->icsk_ack.pending & ICSK_ACK_TIMER))
112 if (time_after(icsk->icsk_ack.timeout, jiffies)) {
113 sk_reset_timer(sk, &icsk->icsk_delack_timer,
114 icsk->icsk_ack.timeout);
118 icsk->icsk_ack.pending &= ~ICSK_ACK_TIMER;
120 if (inet_csk_ack_scheduled(sk)) {
121 if (!icsk->icsk_ack.pingpong) {
122 /* Delayed ACK missed: inflate ATO. */
123 icsk->icsk_ack.ato = min(icsk->icsk_ack.ato << 1,
126 /* Delayed ACK missed: leave pingpong mode and
129 icsk->icsk_ack.pingpong = 0;
130 icsk->icsk_ack.ato = TCP_ATO_MIN;
133 NET_INC_STATS_BH(LINUX_MIB_DELAYEDACKS);
141 * The DCCP retransmit timer.
143 static void dccp_retransmit_timer(struct sock *sk)
145 struct inet_connection_sock *icsk = inet_csk(sk);
147 /* retransmit timer is used for feature negotiation throughout
148 * connection. In this case, no packet is re-transmitted, but rather an
149 * ack is generated and pending changes are placed into its options.
151 if (sk->sk_send_head == NULL) {
152 dccp_pr_debug("feat negotiation retransmit timeout %p\n", sk);
153 if (sk->sk_state == DCCP_OPEN)
159 * sk->sk_send_head has to have one skb with
160 * DCCP_SKB_CB(skb)->dccpd_type set to one of the retransmittable DCCP
161 * packet types. The only packets eligible for retransmission are:
162 * -- Requests in client-REQUEST state (sec. 8.1.1)
163 * -- Acks in client-PARTOPEN state (sec. 8.1.5)
164 * -- CloseReq in server-CLOSEREQ state (sec. 8.3)
165 * -- Close in node-CLOSING state (sec. 8.3) */
166 BUG_TRAP(sk->sk_send_head != NULL);
169 * More than than 4MSL (8 minutes) has passed, a RESET(aborted) was
170 * sent, no need to retransmit, this sock is dead.
172 if (dccp_write_timeout(sk))
176 * We want to know the number of packets retransmitted, not the
177 * total number of retransmissions of clones of original packets.
179 if (icsk->icsk_retransmits == 0)
180 DCCP_INC_STATS_BH(DCCP_MIB_TIMEOUTS);
182 if (dccp_retransmit_skb(sk, sk->sk_send_head) < 0) {
184 * Retransmission failed because of local congestion,
187 if (icsk->icsk_retransmits == 0)
188 icsk->icsk_retransmits = 1;
189 inet_csk_reset_xmit_timer(sk, ICSK_TIME_RETRANS,
191 TCP_RESOURCE_PROBE_INTERVAL),
197 icsk->icsk_backoff++;
198 icsk->icsk_retransmits++;
200 icsk->icsk_rto = min(icsk->icsk_rto << 1, DCCP_RTO_MAX);
201 inet_csk_reset_xmit_timer(sk, ICSK_TIME_RETRANS, icsk->icsk_rto,
203 if (icsk->icsk_retransmits > sysctl_dccp_retries1)
208 static void dccp_write_timer(unsigned long data)
210 struct sock *sk = (struct sock *)data;
211 struct inet_connection_sock *icsk = inet_csk(sk);
215 if (sock_owned_by_user(sk)) {
216 /* Try again later */
217 sk_reset_timer(sk, &icsk->icsk_retransmit_timer,
218 jiffies + (HZ / 20));
222 if (sk->sk_state == DCCP_CLOSED || !icsk->icsk_pending)
225 if (time_after(icsk->icsk_timeout, jiffies)) {
226 sk_reset_timer(sk, &icsk->icsk_retransmit_timer,
231 event = icsk->icsk_pending;
232 icsk->icsk_pending = 0;
235 case ICSK_TIME_RETRANS:
236 dccp_retransmit_timer(sk);
245 * Timer for listening sockets
247 static void dccp_response_timer(struct sock *sk)
249 inet_csk_reqsk_queue_prune(sk, TCP_SYNQ_INTERVAL, DCCP_TIMEOUT_INIT,
253 static void dccp_keepalive_timer(unsigned long data)
255 struct sock *sk = (struct sock *)data;
257 /* Only process if socket is not in use. */
259 if (sock_owned_by_user(sk)) {
260 /* Try again later. */
261 inet_csk_reset_keepalive_timer(sk, HZ / 20);
265 if (sk->sk_state == DCCP_LISTEN) {
266 dccp_response_timer(sk);