aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/linux/dccp.h14
-rw-r--r--net/dccp/Makefile2
-rw-r--r--net/dccp/ackvec.c419
-rw-r--r--net/dccp/ackvec.h133
-rw-r--r--net/dccp/dccp.h82
-rw-r--r--net/dccp/input.c69
-rw-r--r--net/dccp/ipv4.c59
-rw-r--r--net/dccp/minisocks.c13
-rw-r--r--net/dccp/options.c440
-rw-r--r--net/dccp/output.c12
10 files changed, 612 insertions, 631 deletions
diff --git a/include/linux/dccp.h b/include/linux/dccp.h
index 0e72708677e4..8c8e029095a5 100644
--- a/include/linux/dccp.h
+++ b/include/linux/dccp.h
@@ -353,14 +353,8 @@ static inline struct dccp_request_sock *dccp_rsk(const struct request_sock *req)
353 353
354extern struct inet_timewait_death_row dccp_death_row; 354extern struct inet_timewait_death_row dccp_death_row;
355 355
356/* Read about the ECN nonce to see why it is 253 */
357#define DCCP_MAX_ACK_VECTOR_LEN 253
358
359struct dccp_options_received { 356struct dccp_options_received {
360 u32 dccpor_ndp:24, 357 u32 dccpor_ndp; /* only 24 bits */
361 dccpor_ack_vector_len:8;
362 u32 dccpor_ack_vector_idx:10;
363 /* 22 bits hole, try to pack */
364 u32 dccpor_timestamp; 358 u32 dccpor_timestamp;
365 u32 dccpor_timestamp_echo; 359 u32 dccpor_timestamp_echo;
366 u32 dccpor_elapsed_time; 360 u32 dccpor_elapsed_time;
@@ -394,6 +388,8 @@ static inline int dccp_list_has_service(const struct dccp_service_list *sl,
394 return 0; 388 return 0;
395} 389}
396 390
391struct dccp_ackvec;
392
397/** 393/**
398 * struct dccp_sock - DCCP socket state 394 * struct dccp_sock - DCCP socket state
399 * 395 *
@@ -414,7 +410,7 @@ static inline int dccp_list_has_service(const struct dccp_service_list *sl,
414 * @dccps_packet_size - Set thru setsockopt 410 * @dccps_packet_size - Set thru setsockopt
415 * @dccps_role - Role of this sock, one of %dccp_role 411 * @dccps_role - Role of this sock, one of %dccp_role
416 * @dccps_ndp_count - number of Non Data Packets since last data packet 412 * @dccps_ndp_count - number of Non Data Packets since last data packet
417 * @dccps_hc_rx_ackpkts - receiver half connection acked packets 413 * @dccps_hc_rx_ackvec - rx half connection ack vector
418 */ 414 */
419struct dccp_sock { 415struct dccp_sock {
420 /* inet_connection_sock has to be the first member of dccp_sock */ 416 /* inet_connection_sock has to be the first member of dccp_sock */
@@ -439,7 +435,7 @@ struct dccp_sock {
439 __u32 dccps_pmtu_cookie; 435 __u32 dccps_pmtu_cookie;
440 __u32 dccps_mss_cache; 436 __u32 dccps_mss_cache;
441 struct dccp_options dccps_options; 437 struct dccp_options dccps_options;
442 struct dccp_ackpkts *dccps_hc_rx_ackpkts; 438 struct dccp_ackvec *dccps_hc_rx_ackvec;
443 void *dccps_hc_rx_ccid_private; 439 void *dccps_hc_rx_ccid_private;
444 void *dccps_hc_tx_ccid_private; 440 void *dccps_hc_tx_ccid_private;
445 struct ccid *dccps_hc_rx_ccid; 441 struct ccid *dccps_hc_rx_ccid;
diff --git a/net/dccp/Makefile b/net/dccp/Makefile
index fb97bb042455..344a8da153fc 100644
--- a/net/dccp/Makefile
+++ b/net/dccp/Makefile
@@ -3,6 +3,8 @@ obj-$(CONFIG_IP_DCCP) += dccp.o
3dccp-y := ccid.o input.o ipv4.o minisocks.o options.o output.o proto.o \ 3dccp-y := ccid.o input.o ipv4.o minisocks.o options.o output.o proto.o \
4 timer.o 4 timer.o
5 5
6dccp-$(CONFIG_IP_DCCP_ACKVEC) += ackvec.o
7
6obj-$(CONFIG_INET_DCCP_DIAG) += dccp_diag.o 8obj-$(CONFIG_INET_DCCP_DIAG) += dccp_diag.o
7 9
8dccp_diag-y := diag.o 10dccp_diag-y := diag.o
diff --git a/net/dccp/ackvec.c b/net/dccp/ackvec.c
new file mode 100644
index 000000000000..6530283eafca
--- /dev/null
+++ b/net/dccp/ackvec.c
@@ -0,0 +1,419 @@
1/*
2 * net/dccp/ackvec.c
3 *
4 * An implementation of the DCCP protocol
5 * Copyright (c) 2005 Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; version 2 of the License;
10 */
11
12#include "ackvec.h"
13#include "dccp.h"
14
15#include <linux/dccp.h>
16#include <linux/skbuff.h>
17
18#include <net/sock.h>
19
20int dccp_insert_option_ackvec(struct sock *sk, struct sk_buff *skb)
21{
22 struct dccp_sock *dp = dccp_sk(sk);
23 struct dccp_ackvec *av = dp->dccps_hc_rx_ackvec;
24 int len = av->dccpav_vec_len + 2;
25 struct timeval now;
26 u32 elapsed_time;
27 unsigned char *to, *from;
28
29 dccp_timestamp(sk, &now);
30 elapsed_time = timeval_delta(&now, &av->dccpav_time) / 10;
31
32 if (elapsed_time != 0)
33 dccp_insert_option_elapsed_time(sk, skb, elapsed_time);
34
35 if (DCCP_SKB_CB(skb)->dccpd_opt_len + len > DCCP_MAX_OPT_LEN)
36 return -1;
37
38 /*
39 * XXX: now we have just one ack vector sent record, so
40 * we have to wait for it to be cleared.
41 *
42 * Of course this is not acceptable, but this is just for
43 * basic testing now.
44 */
45 if (av->dccpav_ack_seqno != DCCP_MAX_SEQNO + 1)
46 return -1;
47
48 DCCP_SKB_CB(skb)->dccpd_opt_len += len;
49
50 to = skb_push(skb, len);
51 *to++ = DCCPO_ACK_VECTOR_0;
52 *to++ = len;
53
54 len = av->dccpav_vec_len;
55 from = av->dccpav_buf + av->dccpav_buf_head;
56
57 /* Check if buf_head wraps */
58 if (av->dccpav_buf_head + len > av->dccpav_vec_len) {
59 const u32 tailsize = (av->dccpav_vec_len - av->dccpav_buf_head);
60
61 memcpy(to, from, tailsize);
62 to += tailsize;
63 len -= tailsize;
64 from = av->dccpav_buf;
65 }
66
67 memcpy(to, from, len);
68 /*
69 * From draft-ietf-dccp-spec-11.txt:
70 *
71 * For each acknowledgement it sends, the HC-Receiver will add an
72 * acknowledgement record. ack_seqno will equal the HC-Receiver
73 * sequence number it used for the ack packet; ack_ptr will equal
74 * buf_head; ack_ackno will equal buf_ackno; and ack_nonce will
75 * equal buf_nonce.
76 *
77 * This implemention uses just one ack record for now.
78 */
79 av->dccpav_ack_seqno = DCCP_SKB_CB(skb)->dccpd_seq;
80 av->dccpav_ack_ptr = av->dccpav_buf_head;
81 av->dccpav_ack_ackno = av->dccpav_buf_ackno;
82 av->dccpav_ack_nonce = av->dccpav_buf_nonce;
83 av->dccpav_sent_len = av->dccpav_vec_len;
84
85 dccp_pr_debug("%sACK Vector 0, len=%d, ack_seqno=%llu, "
86 "ack_ackno=%llu\n",
87 debug_prefix, av->dccpav_sent_len,
88 (unsigned long long)av->dccpav_ack_seqno,
89 (unsigned long long)av->dccpav_ack_ackno);
90 return -1;
91}
92
93struct dccp_ackvec *dccp_ackvec_alloc(const unsigned int len,
94 const unsigned int __nocast priority)
95{
96 struct dccp_ackvec *av = kmalloc(sizeof(*av) + len, priority);
97
98 if (av != NULL) {
99 av->dccpav_buf_len = len;
100 av->dccpav_buf_head =
101 av->dccpav_buf_tail = av->dccpav_buf_len - 1;
102 av->dccpav_buf_ackno =
103 av->dccpav_ack_ackno = av->dccpav_ack_seqno = ~0LLU;
104 av->dccpav_buf_nonce = av->dccpav_buf_nonce = 0;
105 av->dccpav_ack_ptr = 0;
106 av->dccpav_time.tv_sec = 0;
107 av->dccpav_time.tv_usec = 0;
108 av->dccpav_sent_len = av->dccpav_vec_len = 0;
109 }
110
111 return av;
112}
113
114void dccp_ackvec_free(struct dccp_ackvec *av)
115{
116 kfree(av);
117}
118
119static inline u8 dccp_ackvec_state(const struct dccp_ackvec *av,
120 const unsigned int index)
121{
122 return av->dccpav_buf[index] & DCCP_ACKVEC_STATE_MASK;
123}
124
125static inline u8 dccp_ackvec_len(const struct dccp_ackvec *av,
126 const unsigned int index)
127{
128 return av->dccpav_buf[index] & DCCP_ACKVEC_LEN_MASK;
129}
130
131/*
132 * If several packets are missing, the HC-Receiver may prefer to enter multiple
133 * bytes with run length 0, rather than a single byte with a larger run length;
134 * this simplifies table updates if one of the missing packets arrives.
135 */
136static inline int dccp_ackvec_set_buf_head_state(struct dccp_ackvec *av,
137 const unsigned int packets,
138 const unsigned char state)
139{
140 unsigned int gap;
141 signed long new_head;
142
143 if (av->dccpav_vec_len + packets > av->dccpav_buf_len)
144 return -ENOBUFS;
145
146 gap = packets - 1;
147 new_head = av->dccpav_buf_head - packets;
148
149 if (new_head < 0) {
150 if (gap > 0) {
151 memset(av->dccpav_buf, DCCP_ACKVEC_STATE_NOT_RECEIVED,
152 gap + new_head + 1);
153 gap = -new_head;
154 }
155 new_head += av->dccpav_buf_len;
156 }
157
158 av->dccpav_buf_head = new_head;
159
160 if (gap > 0)
161 memset(av->dccpav_buf + av->dccpav_buf_head + 1,
162 DCCP_ACKVEC_STATE_NOT_RECEIVED, gap);
163
164 av->dccpav_buf[av->dccpav_buf_head] = state;
165 av->dccpav_vec_len += packets;
166 return 0;
167}
168
169/*
170 * Implements the draft-ietf-dccp-spec-11.txt Appendix A
171 */
172int dccp_ackvec_add(struct dccp_ackvec *av, const struct sock *sk,
173 const u64 ackno, const u8 state)
174{
175 /*
176 * Check at the right places if the buffer is full, if it is, tell the
177 * caller to start dropping packets till the HC-Sender acks our ACK
178 * vectors, when we will free up space in dccpav_buf.
179 *
180 * We may well decide to do buffer compression, etc, but for now lets
181 * just drop.
182 *
183 * From Appendix A:
184 *
185 * Of course, the circular buffer may overflow, either when the
186 * HC-Sender is sending data at a very high rate, when the
187 * HC-Receiver's acknowledgements are not reaching the HC-Sender,
188 * or when the HC-Sender is forgetting to acknowledge those acks
189 * (so the HC-Receiver is unable to clean up old state). In this
190 * case, the HC-Receiver should either compress the buffer (by
191 * increasing run lengths when possible), transfer its state to
192 * a larger buffer, or, as a last resort, drop all received
193 * packets, without processing them whatsoever, until its buffer
194 * shrinks again.
195 */
196
197 /* See if this is the first ackno being inserted */
198 if (av->dccpav_vec_len == 0) {
199 av->dccpav_buf[av->dccpav_buf_head] = state;
200 av->dccpav_vec_len = 1;
201 } else if (after48(ackno, av->dccpav_buf_ackno)) {
202 const u64 delta = dccp_delta_seqno(av->dccpav_buf_ackno,
203 ackno);
204
205 /*
206 * Look if the state of this packet is the same as the
207 * previous ackno and if so if we can bump the head len.
208 */
209 if (delta == 1 &&
210 dccp_ackvec_state(av, av->dccpav_buf_head) == state &&
211 (dccp_ackvec_len(av, av->dccpav_buf_head) <
212 DCCP_ACKVEC_LEN_MASK))
213 av->dccpav_buf[av->dccpav_buf_head]++;
214 else if (dccp_ackvec_set_buf_head_state(av, delta, state))
215 return -ENOBUFS;
216 } else {
217 /*
218 * A.1.2. Old Packets
219 *
220 * When a packet with Sequence Number S arrives, and
221 * S <= buf_ackno, the HC-Receiver will scan the table
222 * for the byte corresponding to S. (Indexing structures
223 * could reduce the complexity of this scan.)
224 */
225 u64 delta = dccp_delta_seqno(ackno, av->dccpav_buf_ackno);
226 unsigned int index = av->dccpav_buf_head;
227
228 while (1) {
229 const u8 len = dccp_ackvec_len(av, index);
230 const u8 state = dccp_ackvec_state(av, index);
231 /*
232 * valid packets not yet in dccpav_buf have a reserved
233 * entry, with a len equal to 0.
234 */
235 if (state == DCCP_ACKVEC_STATE_NOT_RECEIVED &&
236 len == 0 && delta == 0) { /* Found our
237 reserved seat! */
238 dccp_pr_debug("Found %llu reserved seat!\n",
239 (unsigned long long)ackno);
240 av->dccpav_buf[index] = state;
241 goto out;
242 }
243 /* len == 0 means one packet */
244 if (delta < len + 1)
245 goto out_duplicate;
246
247 delta -= len + 1;
248 if (++index == av->dccpav_buf_len)
249 index = 0;
250 }
251 }
252
253 av->dccpav_buf_ackno = ackno;
254 dccp_timestamp(sk, &av->dccpav_time);
255out:
256 dccp_pr_debug("");
257 return 0;
258
259out_duplicate:
260 /* Duplicate packet */
261 dccp_pr_debug("Received a dup or already considered lost "
262 "packet: %llu\n", (unsigned long long)ackno);
263 return -EILSEQ;
264}
265
266#ifdef CONFIG_IP_DCCP_DEBUG
267void dccp_ackvector_print(const u64 ackno, const unsigned char *vector, int len)
268{
269 if (!dccp_debug)
270 return;
271
272 printk("ACK vector len=%d, ackno=%llu |", len,
273 (unsigned long long)ackno);
274
275 while (len--) {
276 const u8 state = (*vector & DCCP_ACKVEC_STATE_MASK) >> 6;
277 const u8 rl = *vector & DCCP_ACKVEC_LEN_MASK;
278
279 printk("%d,%d|", state, rl);
280 ++vector;
281 }
282
283 printk("\n");
284}
285
286void dccp_ackvec_print(const struct dccp_ackvec *av)
287{
288 dccp_ackvector_print(av->dccpav_buf_ackno,
289 av->dccpav_buf + av->dccpav_buf_head,
290 av->dccpav_vec_len);
291}
292#endif
293
294static void dccp_ackvec_trow_away_ack_record(struct dccp_ackvec *av)
295{
296 /*
297 * As we're keeping track of the ack vector size (dccpav_vec_len) and
298 * the sent ack vector size (dccpav_sent_len) we don't need
299 * dccpav_buf_tail at all, but keep this code here as in the future
300 * we'll implement a vector of ack records, as suggested in
301 * draft-ietf-dccp-spec-11.txt Appendix A. -acme
302 */
303#if 0
304 av->dccpav_buf_tail = av->dccpav_ack_ptr + 1;
305 if (av->dccpav_buf_tail >= av->dccpav_vec_len)
306 av->dccpav_buf_tail -= av->dccpav_vec_len;
307#endif
308 av->dccpav_vec_len -= av->dccpav_sent_len;
309}
310
311void dccp_ackvec_check_rcv_ackno(struct dccp_ackvec *av, struct sock *sk,
312 const u64 ackno)
313{
314 /* Check if we actually sent an ACK vector */
315 if (av->dccpav_ack_seqno == DCCP_MAX_SEQNO + 1)
316 return;
317
318 if (ackno == av->dccpav_ack_seqno) {
319#ifdef CONFIG_IP_DCCP_DEBUG
320 struct dccp_sock *dp = dccp_sk(sk);
321 const char *debug_prefix = dp->dccps_role == DCCP_ROLE_CLIENT ?
322 "CLIENT rx ack: " : "server rx ack: ";
323#endif
324 dccp_pr_debug("%sACK packet 0, len=%d, ack_seqno=%llu, "
325 "ack_ackno=%llu, ACKED!\n",
326 debug_prefix, 1,
327 (unsigned long long)av->dccpav_ack_seqno,
328 (unsigned long long)av->dccpav_ack_ackno);
329 dccp_ackvec_trow_away_ack_record(av);
330 av->dccpav_ack_seqno = DCCP_MAX_SEQNO + 1;
331 }
332}
333
334static void dccp_ackvec_check_rcv_ackvector(struct dccp_ackvec *av,
335 struct sock *sk, u64 ackno,
336 const unsigned char len,
337 const unsigned char *vector)
338{
339 unsigned char i;
340
341 /* Check if we actually sent an ACK vector */
342 if (av->dccpav_ack_seqno == DCCP_MAX_SEQNO + 1)
343 return;
344 /*
345 * We're in the receiver half connection, so if the received an ACK
346 * vector ackno (e.g. 50) before dccpav_ack_seqno (e.g. 52), we're
347 * not interested.
348 *
349 * Extra explanation with example:
350 *
351 * if we received an ACK vector with ackno 50, it can only be acking
352 * 50, 49, 48, etc, not 52 (the seqno for the ACK vector we sent).
353 */
354 /* dccp_pr_debug("is %llu < %llu? ", ackno, av->dccpav_ack_seqno); */
355 if (before48(ackno, av->dccpav_ack_seqno)) {
356 /* dccp_pr_debug_cat("yes\n"); */
357 return;
358 }
359 /* dccp_pr_debug_cat("no\n"); */
360
361 i = len;
362 while (i--) {
363 const u8 rl = *vector & DCCP_ACKVEC_LEN_MASK;
364 u64 ackno_end_rl;
365
366 dccp_set_seqno(&ackno_end_rl, ackno - rl);
367
368 /*
369 * dccp_pr_debug("is %llu <= %llu <= %llu? ", ackno_end_rl,
370 * av->dccpav_ack_seqno, ackno);
371 */
372 if (between48(av->dccpav_ack_seqno, ackno_end_rl, ackno)) {
373 const u8 state = (*vector &
374 DCCP_ACKVEC_STATE_MASK) >> 6;
375 /* dccp_pr_debug_cat("yes\n"); */
376
377 if (state != DCCP_ACKVEC_STATE_NOT_RECEIVED) {
378#ifdef CONFIG_IP_DCCP_DEBUG
379 struct dccp_sock *dp = dccp_sk(sk);
380 const char *debug_prefix =
381 dp->dccps_role == DCCP_ROLE_CLIENT ?
382 "CLIENT rx ack: " : "server rx ack: ";
383#endif
384 dccp_pr_debug("%sACK vector 0, len=%d, "
385 "ack_seqno=%llu, ack_ackno=%llu, "
386 "ACKED!\n",
387 debug_prefix, len,
388 (unsigned long long)
389 av->dccpav_ack_seqno,
390 (unsigned long long)
391 av->dccpav_ack_ackno);
392 dccp_ackvec_trow_away_ack_record(av);
393 }
394 /*
395 * If dccpav_ack_seqno was not received, no problem
396 * we'll send another ACK vector.
397 */
398 av->dccpav_ack_seqno = DCCP_MAX_SEQNO + 1;
399 break;
400 }
401 /* dccp_pr_debug_cat("no\n"); */
402
403 dccp_set_seqno(&ackno, ackno_end_rl - 1);
404 ++vector;
405 }
406}
407
408int dccp_ackvec_parse(struct sock *sk, const struct sk_buff *skb,
409 const u8 opt, const u8 *value, const u8 len)
410{
411 if (len > DCCP_MAX_ACKVEC_LEN)
412 return -1;
413
414 /* dccp_ackvector_print(DCCP_SKB_CB(skb)->dccpd_ack_seq, value, len); */
415 dccp_ackvec_check_rcv_ackvector(dccp_sk(sk)->dccps_hc_rx_ackvec, sk,
416 DCCP_SKB_CB(skb)->dccpd_ack_seq,
417 len, value);
418 return 0;
419}
diff --git a/net/dccp/ackvec.h b/net/dccp/ackvec.h
new file mode 100644
index 000000000000..8ca51c9191f7
--- /dev/null
+++ b/net/dccp/ackvec.h
@@ -0,0 +1,133 @@
1#ifndef _ACKVEC_H
2#define _ACKVEC_H
3/*
4 * net/dccp/ackvec.h
5 *
6 * An implementation of the DCCP protocol
7 * Copyright (c) 2005 Arnaldo Carvalho de Melo <acme@mandriva.com>
8 *
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12 */
13
14#include <linux/config.h>
15#include <linux/compiler.h>
16#include <linux/time.h>
17#include <linux/types.h>
18
19/* Read about the ECN nonce to see why it is 253 */
20#define DCCP_MAX_ACKVEC_LEN 253
21
22#define DCCP_ACKVEC_STATE_RECEIVED 0
23#define DCCP_ACKVEC_STATE_ECN_MARKED (1 << 6)
24#define DCCP_ACKVEC_STATE_NOT_RECEIVED (3 << 6)
25
26#define DCCP_ACKVEC_STATE_MASK 0xC0 /* 11000000 */
27#define DCCP_ACKVEC_LEN_MASK 0x3F /* 00111111 */
28
29/** struct dccp_ackvec - ack vector
30 *
31 * This data structure is the one defined in the DCCP draft
32 * Appendix A.
33 *
34 * @dccpav_buf_head - circular buffer head
35 * @dccpav_buf_tail - circular buffer tail
36 * @dccpav_buf_ackno - ack # of the most recent packet acknowledgeable in the
37 * buffer (i.e. %dccpav_buf_head)
38 * @dccpav_buf_nonce - the one-bit sum of the ECN Nonces on all packets acked
39 * by the buffer with State 0
40 *
41 * Additionally, the HC-Receiver must keep some information about the
42 * Ack Vectors it has recently sent. For each packet sent carrying an
43 * Ack Vector, it remembers four variables:
44 *
45 * @dccpav_ack_seqno - the Sequence Number used for the packet
46 * (HC-Receiver seqno)
47 * @dccpav_ack_ptr - the value of buf_head at the time of acknowledgement.
48 * @dccpav_ack_ackno - the Acknowledgement Number used for the packet
49 * (HC-Sender seqno)
50 * @dccpav_ack_nonce - the one-bit sum of the ECN Nonces for all State 0.
51 *
52 * @dccpav_buf_len - circular buffer length
53 * @dccpav_time - the time in usecs
54 * @dccpav_buf - circular buffer of acknowledgeable packets
55 */
56struct dccp_ackvec {
57 unsigned int dccpav_buf_head;
58 unsigned int dccpav_buf_tail;
59 u64 dccpav_buf_ackno;
60 u64 dccpav_ack_seqno;
61 u64 dccpav_ack_ackno;
62 unsigned int dccpav_ack_ptr;
63 unsigned int dccpav_sent_len;
64 unsigned int dccpav_vec_len;
65 unsigned int dccpav_buf_len;
66 struct timeval dccpav_time;
67 u8 dccpav_buf_nonce;
68 u8 dccpav_ack_nonce;
69 u8 dccpav_buf[0];
70};
71
72struct sock;
73struct sk_buff;
74
75#ifdef CONFIG_IP_DCCP_ACKVEC
76extern struct dccp_ackvec *dccp_ackvec_alloc(unsigned int len,
77 const unsigned int __nocast priority);
78extern void dccp_ackvec_free(struct dccp_ackvec *av);
79
80extern int dccp_ackvec_add(struct dccp_ackvec *av, const struct sock *sk,
81 const u64 ackno, const u8 state);
82
83extern void dccp_ackvec_check_rcv_ackno(struct dccp_ackvec *av,
84 struct sock *sk, const u64 ackno);
85extern int dccp_ackvec_parse(struct sock *sk, const struct sk_buff *skb,
86 const u8 opt, const u8 *value, const u8 len);
87
88extern int dccp_insert_option_ackvec(struct sock *sk, struct sk_buff *skb);
89
90static inline int dccp_ackvec_pending(const struct dccp_ackvec *av)
91{
92 return av->dccpav_sent_len != av->dccpav_vec_len;
93}
94#else /* CONFIG_IP_DCCP_ACKVEC */
95static inline struct dccp_ackvec *dccp_ackvec_alloc(unsigned int len,
96 const unsigned int __nocast priority)
97{
98 return NULL;
99}
100
101static inline void dccp_ackvec_free(struct dccp_ackvec *av)
102{
103}
104
105static inline int dccp_ackvec_add(struct dccp_ackvec *av, const struct sock *sk,
106 const u64 ackno, const u8 state)
107{
108 return -1;
109}
110
111static inline void dccp_ackvec_check_rcv_ackno(struct dccp_ackvec *av,
112 struct sock *sk, const u64 ackno)
113{
114}
115
116static inline int dccp_ackvec_parse(struct sock *sk, const struct sk_buff *skb,
117 const u8 opt, const u8 *value, const u8 len)
118{
119 return -1;
120}
121
122static inline int dccp_insert_option_ackvec(const struct sock *sk,
123 const struct sk_buff *skb)
124{
125 return -1;
126}
127
128static inline int dccp_ackvec_pending(const struct dccp_ackvec *av)
129{
130 return 0;
131}
132#endif /* CONFIG_IP_DCCP_ACKVEC */
133#endif /* _ACKVEC_H */
diff --git a/net/dccp/dccp.h b/net/dccp/dccp.h
index be7a660b6b24..5871c027f9dc 100644
--- a/net/dccp/dccp.h
+++ b/net/dccp/dccp.h
@@ -17,6 +17,7 @@
17#include <net/snmp.h> 17#include <net/snmp.h>
18#include <net/sock.h> 18#include <net/sock.h>
19#include <net/tcp.h> 19#include <net/tcp.h>
20#include "ackvec.h"
20 21
21#ifdef CONFIG_IP_DCCP_DEBUG 22#ifdef CONFIG_IP_DCCP_DEBUG
22extern int dccp_debug; 23extern int dccp_debug;
@@ -358,6 +359,17 @@ static inline void dccp_update_gss(struct sock *sk, u64 seq)
358 (dp->dccps_gss - 359 (dp->dccps_gss -
359 dp->dccps_options.dccpo_sequence_window + 1)); 360 dp->dccps_options.dccpo_sequence_window + 1));
360} 361}
362
363static inline int dccp_ack_pending(const struct sock *sk)
364{
365 const struct dccp_sock *dp = dccp_sk(sk);
366 return dp->dccps_timestamp_echo != 0 ||
367#ifdef CONFIG_IP_DCCP_ACKVEC
368 (dp->dccps_options.dccpo_send_ack_vector &&
369 dccp_ackvec_pending(dp->dccps_hc_rx_ackvec)) ||
370#endif
371 inet_csk_ack_scheduled(sk);
372}
361 373
362extern void dccp_insert_options(struct sock *sk, struct sk_buff *skb); 374extern void dccp_insert_options(struct sock *sk, struct sk_buff *skb);
363extern void dccp_insert_option_elapsed_time(struct sock *sk, 375extern void dccp_insert_option_elapsed_time(struct sock *sk,
@@ -371,65 +383,6 @@ extern void dccp_insert_option(struct sock *sk, struct sk_buff *skb,
371 383
372extern struct socket *dccp_ctl_socket; 384extern struct socket *dccp_ctl_socket;
373 385
374#define DCCP_ACKPKTS_STATE_RECEIVED 0
375#define DCCP_ACKPKTS_STATE_ECN_MARKED (1 << 6)
376#define DCCP_ACKPKTS_STATE_NOT_RECEIVED (3 << 6)
377
378#define DCCP_ACKPKTS_STATE_MASK 0xC0 /* 11000000 */
379#define DCCP_ACKPKTS_LEN_MASK 0x3F /* 00111111 */
380
381/** struct dccp_ackpkts - acknowledgeable packets
382 *
383 * This data structure is the one defined in the DCCP draft
384 * Appendix A.
385 *
386 * @dccpap_buf_head - circular buffer head
387 * @dccpap_buf_tail - circular buffer tail
388 * @dccpap_buf_ackno - ack # of the most recent packet acknowledgeable in the
389 * buffer (i.e. %dccpap_buf_head)
390 * @dccpap_buf_nonce - the one-bit sum of the ECN Nonces on all packets acked
391 * by the buffer with State 0
392 *
393 * Additionally, the HC-Receiver must keep some information about the
394 * Ack Vectors it has recently sent. For each packet sent carrying an
395 * Ack Vector, it remembers four variables:
396 *
397 * @dccpap_ack_seqno - the Sequence Number used for the packet
398 * (HC-Receiver seqno)
399 * @dccpap_ack_ptr - the value of buf_head at the time of acknowledgement.
400 * @dccpap_ack_ackno - the Acknowledgement Number used for the packet
401 * (HC-Sender seqno)
402 * @dccpap_ack_nonce - the one-bit sum of the ECN Nonces for all State 0.
403 *
404 * @dccpap_buf_len - circular buffer length
405 * @dccpap_time - the time in usecs
406 * @dccpap_buf - circular buffer of acknowledgeable packets
407 */
408struct dccp_ackpkts {
409 unsigned int dccpap_buf_head;
410 unsigned int dccpap_buf_tail;
411 u64 dccpap_buf_ackno;
412 u64 dccpap_ack_seqno;
413 u64 dccpap_ack_ackno;
414 unsigned int dccpap_ack_ptr;
415 unsigned int dccpap_buf_vector_len;
416 unsigned int dccpap_ack_vector_len;
417 unsigned int dccpap_buf_len;
418 struct timeval dccpap_time;
419 u8 dccpap_buf_nonce;
420 u8 dccpap_ack_nonce;
421 u8 dccpap_buf[0];
422};
423
424extern struct dccp_ackpkts *
425 dccp_ackpkts_alloc(unsigned int len,
426 const unsigned int __nocast priority);
427extern void dccp_ackpkts_free(struct dccp_ackpkts *ap);
428extern int dccp_ackpkts_add(struct dccp_ackpkts *ap, const struct sock *sk,
429 u64 ackno, u8 state);
430extern void dccp_ackpkts_check_rcv_ackno(struct dccp_ackpkts *ap,
431 struct sock *sk, u64 ackno);
432
433extern void dccp_timestamp(const struct sock *sk, struct timeval *tv); 386extern void dccp_timestamp(const struct sock *sk, struct timeval *tv);
434 387
435static inline suseconds_t timeval_usecs(const struct timeval *tv) 388static inline suseconds_t timeval_usecs(const struct timeval *tv)
@@ -470,15 +423,4 @@ static inline void timeval_sub_usecs(struct timeval *tv,
470 } 423 }
471} 424}
472 425
473#ifdef CONFIG_IP_DCCP_DEBUG
474extern void dccp_ackvector_print(const u64 ackno,
475 const unsigned char *vector, int len);
476extern void dccp_ackpkts_print(const struct dccp_ackpkts *ap);
477#else
478static inline void dccp_ackvector_print(const u64 ackno,
479 const unsigned char *vector,
480 int len) { }
481static inline void dccp_ackpkts_print(const struct dccp_ackpkts *ap) { }
482#endif
483
484#endif /* _DCCP_H */ 426#endif /* _DCCP_H */
diff --git a/net/dccp/input.c b/net/dccp/input.c
index 062e9f8359d0..1b6b2cb12376 100644
--- a/net/dccp/input.c
+++ b/net/dccp/input.c
@@ -16,6 +16,7 @@
16 16
17#include <net/sock.h> 17#include <net/sock.h>
18 18
19#include "ackvec.h"
19#include "ccid.h" 20#include "ccid.h"
20#include "dccp.h" 21#include "dccp.h"
21 22
@@ -60,8 +61,8 @@ static inline void dccp_event_ack_recv(struct sock *sk, struct sk_buff *skb)
60 struct dccp_sock *dp = dccp_sk(sk); 61 struct dccp_sock *dp = dccp_sk(sk);
61 62
62 if (dp->dccps_options.dccpo_send_ack_vector) 63 if (dp->dccps_options.dccpo_send_ack_vector)
63 dccp_ackpkts_check_rcv_ackno(dp->dccps_hc_rx_ackpkts, sk, 64 dccp_ackvec_check_rcv_ackno(dp->dccps_hc_rx_ackvec, sk,
64 DCCP_SKB_CB(skb)->dccpd_ack_seq); 65 DCCP_SKB_CB(skb)->dccpd_ack_seq);
65} 66}
66 67
67static int dccp_check_seqno(struct sock *sk, struct sk_buff *skb) 68static int dccp_check_seqno(struct sock *sk, struct sk_buff *skb)
@@ -164,37 +165,11 @@ int dccp_rcv_established(struct sock *sk, struct sk_buff *skb,
164 if (DCCP_SKB_CB(skb)->dccpd_ack_seq != DCCP_PKT_WITHOUT_ACK_SEQ) 165 if (DCCP_SKB_CB(skb)->dccpd_ack_seq != DCCP_PKT_WITHOUT_ACK_SEQ)
165 dccp_event_ack_recv(sk, skb); 166 dccp_event_ack_recv(sk, skb);
166 167
167 /* 168 if (dp->dccps_options.dccpo_send_ack_vector &&
168 * FIXME: check ECN to see if we should use 169 dccp_ackvec_add(dp->dccps_hc_rx_ackvec, sk,
169 * DCCP_ACKPKTS_STATE_ECN_MARKED 170 DCCP_SKB_CB(skb)->dccpd_seq,
170 */ 171 DCCP_ACKVEC_STATE_RECEIVED))
171 if (dp->dccps_options.dccpo_send_ack_vector) { 172 goto discard;
172 struct dccp_ackpkts *ap = dp->dccps_hc_rx_ackpkts;
173
174 if (dccp_ackpkts_add(dp->dccps_hc_rx_ackpkts, sk,
175 DCCP_SKB_CB(skb)->dccpd_seq,
176 DCCP_ACKPKTS_STATE_RECEIVED)) {
177 LIMIT_NETDEBUG(KERN_WARNING "DCCP: acknowledgeable "
178 "packets buffer full!\n");
179 ap->dccpap_ack_seqno = DCCP_MAX_SEQNO + 1;
180 inet_csk_schedule_ack(sk);
181 inet_csk_reset_xmit_timer(sk, ICSK_TIME_DACK,
182 TCP_DELACK_MIN,
183 DCCP_RTO_MAX);
184 goto discard;
185 }
186
187 /*
188 * FIXME: this activation is probably wrong, have to study more
189 * TCP delack machinery and how it fits into DCCP draft, but
190 * for now it kinda "works" 8)
191 */
192 if (!inet_csk_ack_scheduled(sk)) {
193 inet_csk_schedule_ack(sk);
194 inet_csk_reset_xmit_timer(sk, ICSK_TIME_DACK, 5 * HZ,
195 DCCP_RTO_MAX);
196 }
197 }
198 173
199 ccid_hc_rx_packet_recv(dp->dccps_hc_rx_ccid, sk, skb); 174 ccid_hc_rx_packet_recv(dp->dccps_hc_rx_ccid, sk, skb);
200 ccid_hc_tx_packet_recv(dp->dccps_hc_tx_ccid, sk, skb); 175 ccid_hc_tx_packet_recv(dp->dccps_hc_tx_ccid, sk, skb);
@@ -495,29 +470,11 @@ int dccp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
495 ccid_hc_rx_packet_recv(dp->dccps_hc_rx_ccid, sk, skb); 470 ccid_hc_rx_packet_recv(dp->dccps_hc_rx_ccid, sk, skb);
496 ccid_hc_tx_packet_recv(dp->dccps_hc_tx_ccid, sk, skb); 471 ccid_hc_tx_packet_recv(dp->dccps_hc_tx_ccid, sk, skb);
497 472
498 /* 473 if (dp->dccps_options.dccpo_send_ack_vector &&
499 * FIXME: check ECN to see if we should use 474 dccp_ackvec_add(dp->dccps_hc_rx_ackvec, sk,
500 * DCCP_ACKPKTS_STATE_ECN_MARKED 475 DCCP_SKB_CB(skb)->dccpd_seq,
501 */ 476 DCCP_ACKVEC_STATE_RECEIVED))
502 if (dp->dccps_options.dccpo_send_ack_vector) { 477 goto discard;
503 if (dccp_ackpkts_add(dp->dccps_hc_rx_ackpkts, sk,
504 dcb->dccpd_seq,
505 DCCP_ACKPKTS_STATE_RECEIVED))
506 goto discard;
507 /*
508 * FIXME: this activation is probably wrong, have to
509 * study more TCP delack machinery and how it fits into
510 * DCCP draft, but for now it kinda "works" 8)
511 */
512 if ((dp->dccps_hc_rx_ackpkts->dccpap_ack_seqno ==
513 DCCP_MAX_SEQNO + 1) &&
514 !inet_csk_ack_scheduled(sk)) {
515 inet_csk_schedule_ack(sk);
516 inet_csk_reset_xmit_timer(sk, ICSK_TIME_DACK,
517 TCP_DELACK_MIN,
518 DCCP_RTO_MAX);
519 }
520 }
521 } 478 }
522 479
523 /* 480 /*
diff --git a/net/dccp/ipv4.c b/net/dccp/ipv4.c
index 94a440b2685b..82434e4a42df 100644
--- a/net/dccp/ipv4.c
+++ b/net/dccp/ipv4.c
@@ -23,6 +23,7 @@
23#include <net/tcp_states.h> 23#include <net/tcp_states.h>
24#include <net/xfrm.h> 24#include <net/xfrm.h>
25 25
26#include "ackvec.h"
26#include "ccid.h" 27#include "ccid.h"
27#include "dccp.h" 28#include "dccp.h"
28 29
@@ -1112,45 +1113,7 @@ int dccp_v4_rcv(struct sk_buff *skb)
1112 goto discard_it; 1113 goto discard_it;
1113 1114
1114 dh = dccp_hdr(skb); 1115 dh = dccp_hdr(skb);
1115#if 0
1116 /*
1117 * Use something like this to simulate some DATA/DATAACK loss to test
1118 * dccp_ackpkts_add, you'll get something like this on a session that
1119 * sends 10 DATA/DATAACK packets:
1120 *
1121 * ackpkts_print: 281473596467422 |0,0|3,0|0,0|3,0|0,0|3,0|0,0|3,0|0,1|
1122 *
1123 * 0, 0 means: DCCP_ACKPKTS_STATE_RECEIVED, RLE == just this packet
1124 * 0, 1 means: DCCP_ACKPKTS_STATE_RECEIVED, RLE == two adjacent packets
1125 * with the same state
1126 * 3, 0 means: DCCP_ACKPKTS_STATE_NOT_RECEIVED, RLE == just this packet
1127 *
1128 * So...
1129 *
1130 * 281473596467422 was received
1131 * 281473596467421 was not received
1132 * 281473596467420 was received
1133 * 281473596467419 was not received
1134 * 281473596467418 was received
1135 * 281473596467417 was not received
1136 * 281473596467416 was received
1137 * 281473596467415 was not received
1138 * 281473596467414 was received
1139 * 281473596467413 was received (this one was the 3way handshake
1140 * RESPONSE)
1141 *
1142 */
1143 if (dh->dccph_type == DCCP_PKT_DATA ||
1144 dh->dccph_type == DCCP_PKT_DATAACK) {
1145 static int discard = 0;
1146 1116
1147 if (discard) {
1148 discard = 0;
1149 goto discard_it;
1150 }
1151 discard = 1;
1152 }
1153#endif
1154 DCCP_SKB_CB(skb)->dccpd_seq = dccp_hdr_seq(skb); 1117 DCCP_SKB_CB(skb)->dccpd_seq = dccp_hdr_seq(skb);
1155 DCCP_SKB_CB(skb)->dccpd_type = dh->dccph_type; 1118 DCCP_SKB_CB(skb)->dccpd_type = dh->dccph_type;
1156 1119
@@ -1264,11 +1227,9 @@ static int dccp_v4_init_sock(struct sock *sk)
1264 do_gettimeofday(&dp->dccps_epoch); 1227 do_gettimeofday(&dp->dccps_epoch);
1265 1228
1266 if (dp->dccps_options.dccpo_send_ack_vector) { 1229 if (dp->dccps_options.dccpo_send_ack_vector) {
1267 dp->dccps_hc_rx_ackpkts = 1230 dp->dccps_hc_rx_ackvec = dccp_ackvec_alloc(DCCP_MAX_ACKVEC_LEN,
1268 dccp_ackpkts_alloc(DCCP_MAX_ACK_VECTOR_LEN, 1231 GFP_KERNEL);
1269 GFP_KERNEL); 1232 if (dp->dccps_hc_rx_ackvec == NULL)
1270
1271 if (dp->dccps_hc_rx_ackpkts == NULL)
1272 return -ENOMEM; 1233 return -ENOMEM;
1273 } 1234 }
1274 1235
@@ -1288,8 +1249,10 @@ static int dccp_v4_init_sock(struct sock *sk)
1288 dp->dccps_hc_tx_ccid == NULL) { 1249 dp->dccps_hc_tx_ccid == NULL) {
1289 ccid_exit(dp->dccps_hc_rx_ccid, sk); 1250 ccid_exit(dp->dccps_hc_rx_ccid, sk);
1290 ccid_exit(dp->dccps_hc_tx_ccid, sk); 1251 ccid_exit(dp->dccps_hc_tx_ccid, sk);
1291 dccp_ackpkts_free(dp->dccps_hc_rx_ackpkts); 1252 if (dp->dccps_options.dccpo_send_ack_vector) {
1292 dp->dccps_hc_rx_ackpkts = NULL; 1253 dccp_ackvec_free(dp->dccps_hc_rx_ackvec);
1254 dp->dccps_hc_rx_ackvec = NULL;
1255 }
1293 dp->dccps_hc_rx_ccid = dp->dccps_hc_tx_ccid = NULL; 1256 dp->dccps_hc_rx_ccid = dp->dccps_hc_tx_ccid = NULL;
1294 return -ENOMEM; 1257 return -ENOMEM;
1295 } 1258 }
@@ -1331,8 +1294,10 @@ static int dccp_v4_destroy_sock(struct sock *sk)
1331 1294
1332 ccid_hc_rx_exit(dp->dccps_hc_rx_ccid, sk); 1295 ccid_hc_rx_exit(dp->dccps_hc_rx_ccid, sk);
1333 ccid_hc_tx_exit(dp->dccps_hc_tx_ccid, sk); 1296 ccid_hc_tx_exit(dp->dccps_hc_tx_ccid, sk);
1334 dccp_ackpkts_free(dp->dccps_hc_rx_ackpkts); 1297 if (dp->dccps_options.dccpo_send_ack_vector) {
1335 dp->dccps_hc_rx_ackpkts = NULL; 1298 dccp_ackvec_free(dp->dccps_hc_rx_ackvec);
1299 dp->dccps_hc_rx_ackvec = NULL;
1300 }
1336 ccid_exit(dp->dccps_hc_rx_ccid, sk); 1301 ccid_exit(dp->dccps_hc_rx_ccid, sk);
1337 ccid_exit(dp->dccps_hc_tx_ccid, sk); 1302 ccid_exit(dp->dccps_hc_tx_ccid, sk);
1338 dp->dccps_hc_rx_ccid = dp->dccps_hc_tx_ccid = NULL; 1303 dp->dccps_hc_rx_ccid = dp->dccps_hc_tx_ccid = NULL;
diff --git a/net/dccp/minisocks.c b/net/dccp/minisocks.c
index 933e10db1789..1393461898bb 100644
--- a/net/dccp/minisocks.c
+++ b/net/dccp/minisocks.c
@@ -19,6 +19,7 @@
19#include <net/xfrm.h> 19#include <net/xfrm.h>
20#include <net/inet_timewait_sock.h> 20#include <net/inet_timewait_sock.h>
21 21
22#include "ackvec.h"
22#include "ccid.h" 23#include "ccid.h"
23#include "dccp.h" 24#include "dccp.h"
24 25
@@ -94,23 +95,23 @@ struct sock *dccp_create_openreq_child(struct sock *sk,
94 struct dccp_sock *newdp = dccp_sk(newsk); 95 struct dccp_sock *newdp = dccp_sk(newsk);
95 96
96 newdp->dccps_role = DCCP_ROLE_SERVER; 97 newdp->dccps_role = DCCP_ROLE_SERVER;
97 newdp->dccps_hc_rx_ackpkts = NULL; 98 newdp->dccps_hc_rx_ackvec = NULL;
98 newdp->dccps_service_list = NULL; 99 newdp->dccps_service_list = NULL;
99 newdp->dccps_service = dreq->dreq_service; 100 newdp->dccps_service = dreq->dreq_service;
100 newicsk->icsk_rto = DCCP_TIMEOUT_INIT; 101 newicsk->icsk_rto = DCCP_TIMEOUT_INIT;
101 do_gettimeofday(&newdp->dccps_epoch); 102 do_gettimeofday(&newdp->dccps_epoch);
102 103
103 if (newdp->dccps_options.dccpo_send_ack_vector) { 104 if (newdp->dccps_options.dccpo_send_ack_vector) {
104 newdp->dccps_hc_rx_ackpkts = 105 newdp->dccps_hc_rx_ackvec =
105 dccp_ackpkts_alloc(DCCP_MAX_ACK_VECTOR_LEN, 106 dccp_ackvec_alloc(DCCP_MAX_ACKVEC_LEN,
106 GFP_ATOMIC); 107 GFP_ATOMIC);
107 /* 108 /*
108 * XXX: We're using the same CCIDs set on the parent, 109 * XXX: We're using the same CCIDs set on the parent,
109 * i.e. sk_clone copied the master sock and left the 110 * i.e. sk_clone copied the master sock and left the
110 * CCID pointers for this child, that is why we do the 111 * CCID pointers for this child, that is why we do the
111 * __ccid_get calls. 112 * __ccid_get calls.
112 */ 113 */
113 if (unlikely(newdp->dccps_hc_rx_ackpkts == NULL)) 114 if (unlikely(newdp->dccps_hc_rx_ackvec == NULL))
114 goto out_free; 115 goto out_free;
115 } 116 }
116 117
@@ -118,7 +119,7 @@ struct sock *dccp_create_openreq_child(struct sock *sk,
118 newsk) != 0 || 119 newsk) != 0 ||
119 ccid_hc_tx_init(newdp->dccps_hc_tx_ccid, 120 ccid_hc_tx_init(newdp->dccps_hc_tx_ccid,
120 newsk) != 0)) { 121 newsk) != 0)) {
121 dccp_ackpkts_free(newdp->dccps_hc_rx_ackpkts); 122 dccp_ackvec_free(newdp->dccps_hc_rx_ackvec);
122 ccid_hc_rx_exit(newdp->dccps_hc_rx_ccid, newsk); 123 ccid_hc_rx_exit(newdp->dccps_hc_rx_ccid, newsk);
123 ccid_hc_tx_exit(newdp->dccps_hc_tx_ccid, newsk); 124 ccid_hc_tx_exit(newdp->dccps_hc_tx_ccid, newsk);
124out_free: 125out_free:
diff --git a/net/dccp/options.c b/net/dccp/options.c
index d4c4242d8dd7..c480c506a4a4 100644
--- a/net/dccp/options.c
+++ b/net/dccp/options.c
@@ -18,15 +18,10 @@
18#include <linux/kernel.h> 18#include <linux/kernel.h>
19#include <linux/skbuff.h> 19#include <linux/skbuff.h>
20 20
21#include "ackvec.h"
21#include "ccid.h" 22#include "ccid.h"
22#include "dccp.h" 23#include "dccp.h"
23 24
24static void dccp_ackpkts_check_rcv_ackvector(struct dccp_ackpkts *ap,
25 struct sock *sk,
26 const u64 ackno,
27 const unsigned char len,
28 const unsigned char *vector);
29
30/* stores the default values for new connection. may be changed with sysctl */ 25/* stores the default values for new connection. may be changed with sysctl */
31static const struct dccp_options dccpo_default_values = { 26static const struct dccp_options dccpo_default_values = {
32 .dccpo_sequence_window = DCCPF_INITIAL_SEQUENCE_WINDOW, 27 .dccpo_sequence_window = DCCPF_INITIAL_SEQUENCE_WINDOW,
@@ -113,25 +108,13 @@ int dccp_parse_options(struct sock *sk, struct sk_buff *skb)
113 opt_recv->dccpor_ndp); 108 opt_recv->dccpor_ndp);
114 break; 109 break;
115 case DCCPO_ACK_VECTOR_0: 110 case DCCPO_ACK_VECTOR_0:
116 if (len > DCCP_MAX_ACK_VECTOR_LEN) 111 case DCCPO_ACK_VECTOR_1:
117 goto out_invalid_option;
118
119 if (pkt_type == DCCP_PKT_DATA) 112 if (pkt_type == DCCP_PKT_DATA)
120 continue; 113 continue;
121 114
122 opt_recv->dccpor_ack_vector_len = len; 115 if (dp->dccps_options.dccpo_send_ack_vector &&
123 opt_recv->dccpor_ack_vector_idx = value - options; 116 dccp_ackvec_parse(sk, skb, opt, value, len))
124 117 goto out_invalid_option;
125 dccp_pr_debug("%sACK vector 0, len=%d, ack_ackno=%llu\n",
126 debug_prefix, len,
127 (unsigned long long)
128 DCCP_SKB_CB(skb)->dccpd_ack_seq);
129 dccp_ackvector_print(DCCP_SKB_CB(skb)->dccpd_ack_seq,
130 value, len);
131 dccp_ackpkts_check_rcv_ackvector(dp->dccps_hc_rx_ackpkts,
132 sk,
133 DCCP_SKB_CB(skb)->dccpd_ack_seq,
134 len, value);
135 break; 118 break;
136 case DCCPO_TIMESTAMP: 119 case DCCPO_TIMESTAMP:
137 if (len != 4) 120 if (len != 4)
@@ -352,86 +335,6 @@ void dccp_insert_option_elapsed_time(struct sock *sk,
352 335
353EXPORT_SYMBOL_GPL(dccp_insert_option_elapsed_time); 336EXPORT_SYMBOL_GPL(dccp_insert_option_elapsed_time);
354 337
355static void dccp_insert_option_ack_vector(struct sock *sk, struct sk_buff *skb)
356{
357 struct dccp_sock *dp = dccp_sk(sk);
358#ifdef CONFIG_IP_DCCP_DEBUG
359 const char *debug_prefix = dp->dccps_role == DCCP_ROLE_CLIENT ?
360 "CLIENT TX opt: " : "server TX opt: ";
361#endif
362 struct dccp_ackpkts *ap = dp->dccps_hc_rx_ackpkts;
363 int len = ap->dccpap_buf_vector_len + 2;
364 struct timeval now;
365 u32 elapsed_time;
366 unsigned char *to, *from;
367
368 dccp_timestamp(sk, &now);
369 elapsed_time = timeval_delta(&now, &ap->dccpap_time) / 10;
370
371 if (elapsed_time != 0)
372 dccp_insert_option_elapsed_time(sk, skb, elapsed_time);
373
374 if (DCCP_SKB_CB(skb)->dccpd_opt_len + len > DCCP_MAX_OPT_LEN) {
375 LIMIT_NETDEBUG(KERN_INFO "DCCP: packet too small to "
376 "insert ACK Vector!\n");
377 return;
378 }
379
380 /*
381 * XXX: now we have just one ack vector sent record, so
382 * we have to wait for it to be cleared.
383 *
384 * Of course this is not acceptable, but this is just for
385 * basic testing now.
386 */
387 if (ap->dccpap_ack_seqno != DCCP_MAX_SEQNO + 1)
388 return;
389
390 DCCP_SKB_CB(skb)->dccpd_opt_len += len;
391
392 to = skb_push(skb, len);
393 *to++ = DCCPO_ACK_VECTOR_0;
394 *to++ = len;
395
396 len = ap->dccpap_buf_vector_len;
397 from = ap->dccpap_buf + ap->dccpap_buf_head;
398
399 /* Check if buf_head wraps */
400 if (ap->dccpap_buf_head + len > ap->dccpap_buf_len) {
401 const unsigned int tailsize = (ap->dccpap_buf_len -
402 ap->dccpap_buf_head);
403
404 memcpy(to, from, tailsize);
405 to += tailsize;
406 len -= tailsize;
407 from = ap->dccpap_buf;
408 }
409
410 memcpy(to, from, len);
411 /*
412 * From draft-ietf-dccp-spec-11.txt:
413 *
414 * For each acknowledgement it sends, the HC-Receiver will add an
415 * acknowledgement record. ack_seqno will equal the HC-Receiver
416 * sequence number it used for the ack packet; ack_ptr will equal
417 * buf_head; ack_ackno will equal buf_ackno; and ack_nonce will
418 * equal buf_nonce.
419 *
420 * This implemention uses just one ack record for now.
421 */
422 ap->dccpap_ack_seqno = DCCP_SKB_CB(skb)->dccpd_seq;
423 ap->dccpap_ack_ptr = ap->dccpap_buf_head;
424 ap->dccpap_ack_ackno = ap->dccpap_buf_ackno;
425 ap->dccpap_ack_nonce = ap->dccpap_buf_nonce;
426 ap->dccpap_ack_vector_len = ap->dccpap_buf_vector_len;
427
428 dccp_pr_debug("%sACK Vector 0, len=%d, ack_seqno=%llu, "
429 "ack_ackno=%llu\n",
430 debug_prefix, ap->dccpap_ack_vector_len,
431 (unsigned long long) ap->dccpap_ack_seqno,
432 (unsigned long long) ap->dccpap_ack_ackno);
433}
434
435void dccp_timestamp(const struct sock *sk, struct timeval *tv) 338void dccp_timestamp(const struct sock *sk, struct timeval *tv)
436{ 339{
437 const struct dccp_sock *dp = dccp_sk(sk); 340 const struct dccp_sock *dp = dccp_sk(sk);
@@ -528,9 +431,8 @@ void dccp_insert_options(struct sock *sk, struct sk_buff *skb)
528 431
529 if (!dccp_packet_without_ack(skb)) { 432 if (!dccp_packet_without_ack(skb)) {
530 if (dp->dccps_options.dccpo_send_ack_vector && 433 if (dp->dccps_options.dccpo_send_ack_vector &&
531 (dp->dccps_hc_rx_ackpkts->dccpap_buf_ackno != 434 dccp_ackvec_pending(dp->dccps_hc_rx_ackvec))
532 DCCP_MAX_SEQNO + 1)) 435 dccp_insert_option_ackvec(sk, skb);
533 dccp_insert_option_ack_vector(sk, skb);
534 if (dp->dccps_timestamp_echo != 0) 436 if (dp->dccps_timestamp_echo != 0)
535 dccp_insert_option_timestamp_echo(sk, skb); 437 dccp_insert_option_timestamp_echo(sk, skb);
536 } 438 }
@@ -557,331 +459,3 @@ void dccp_insert_options(struct sock *sk, struct sk_buff *skb)
557 } 459 }
558 } 460 }
559} 461}
560
561struct dccp_ackpkts *dccp_ackpkts_alloc(const unsigned int len,
562 const unsigned int __nocast priority)
563{
564 struct dccp_ackpkts *ap = kmalloc(sizeof(*ap) + len, priority);
565
566 if (ap != NULL) {
567#ifdef CONFIG_IP_DCCP_DEBUG
568 memset(ap->dccpap_buf, 0xFF, len);
569#endif
570 ap->dccpap_buf_len = len;
571 ap->dccpap_buf_head =
572 ap->dccpap_buf_tail =
573 ap->dccpap_buf_len - 1;
574 ap->dccpap_buf_ackno =
575 ap->dccpap_ack_ackno =
576 ap->dccpap_ack_seqno = DCCP_MAX_SEQNO + 1;
577 ap->dccpap_buf_nonce = ap->dccpap_buf_nonce = 0;
578 ap->dccpap_ack_ptr = 0;
579 ap->dccpap_time.tv_sec = 0;
580 ap->dccpap_time.tv_usec = 0;
581 ap->dccpap_buf_vector_len = ap->dccpap_ack_vector_len = 0;
582 }
583
584 return ap;
585}
586
587void dccp_ackpkts_free(struct dccp_ackpkts *ap)
588{
589 if (ap != NULL) {
590#ifdef CONFIG_IP_DCCP_DEBUG
591 memset(ap, 0xFF, sizeof(*ap) + ap->dccpap_buf_len);
592#endif
593 kfree(ap);
594 }
595}
596
597static inline u8 dccp_ackpkts_state(const struct dccp_ackpkts *ap,
598 const unsigned int index)
599{
600 return ap->dccpap_buf[index] & DCCP_ACKPKTS_STATE_MASK;
601}
602
603static inline u8 dccp_ackpkts_len(const struct dccp_ackpkts *ap,
604 const unsigned int index)
605{
606 return ap->dccpap_buf[index] & DCCP_ACKPKTS_LEN_MASK;
607}
608
609/*
610 * If several packets are missing, the HC-Receiver may prefer to enter multiple
611 * bytes with run length 0, rather than a single byte with a larger run length;
612 * this simplifies table updates if one of the missing packets arrives.
613 */
614static inline int dccp_ackpkts_set_buf_head_state(struct dccp_ackpkts *ap,
615 const unsigned int packets,
616 const unsigned char state)
617{
618 unsigned int gap;
619 signed long new_head;
620
621 if (ap->dccpap_buf_vector_len + packets > ap->dccpap_buf_len)
622 return -ENOBUFS;
623
624 gap = packets - 1;
625 new_head = ap->dccpap_buf_head - packets;
626
627 if (new_head < 0) {
628 if (gap > 0) {
629 memset(ap->dccpap_buf, DCCP_ACKPKTS_STATE_NOT_RECEIVED,
630 gap + new_head + 1);
631 gap = -new_head;
632 }
633 new_head += ap->dccpap_buf_len;
634 }
635
636 ap->dccpap_buf_head = new_head;
637
638 if (gap > 0)
639 memset(ap->dccpap_buf + ap->dccpap_buf_head + 1,
640 DCCP_ACKPKTS_STATE_NOT_RECEIVED, gap);
641
642 ap->dccpap_buf[ap->dccpap_buf_head] = state;
643 ap->dccpap_buf_vector_len += packets;
644 return 0;
645}
646
647/*
648 * Implements the draft-ietf-dccp-spec-11.txt Appendix A
649 */
650int dccp_ackpkts_add(struct dccp_ackpkts *ap, const struct sock *sk,
651 u64 ackno, u8 state)
652{
653 /*
654 * Check at the right places if the buffer is full, if it is, tell the
655 * caller to start dropping packets till the HC-Sender acks our ACK
656 * vectors, when we will free up space in dccpap_buf.
657 *
658 * We may well decide to do buffer compression, etc, but for now lets
659 * just drop.
660 *
661 * From Appendix A:
662 *
663 * Of course, the circular buffer may overflow, either when the
664 * HC-Sender is sending data at a very high rate, when the
665 * HC-Receiver's acknowledgements are not reaching the HC-Sender,
666 * or when the HC-Sender is forgetting to acknowledge those acks
667 * (so the HC-Receiver is unable to clean up old state). In this
668 * case, the HC-Receiver should either compress the buffer (by
669 * increasing run lengths when possible), transfer its state to
670 * a larger buffer, or, as a last resort, drop all received
671 * packets, without processing them whatsoever, until its buffer
672 * shrinks again.
673 */
674
675 /* See if this is the first ackno being inserted */
676 if (ap->dccpap_buf_vector_len == 0) {
677 ap->dccpap_buf[ap->dccpap_buf_head] = state;
678 ap->dccpap_buf_vector_len = 1;
679 } else if (after48(ackno, ap->dccpap_buf_ackno)) {
680 const u64 delta = dccp_delta_seqno(ap->dccpap_buf_ackno,
681 ackno);
682
683 /*
684 * Look if the state of this packet is the same as the
685 * previous ackno and if so if we can bump the head len.
686 */
687 if (delta == 1 &&
688 dccp_ackpkts_state(ap, ap->dccpap_buf_head) == state &&
689 (dccp_ackpkts_len(ap, ap->dccpap_buf_head) <
690 DCCP_ACKPKTS_LEN_MASK))
691 ap->dccpap_buf[ap->dccpap_buf_head]++;
692 else if (dccp_ackpkts_set_buf_head_state(ap, delta, state))
693 return -ENOBUFS;
694 } else {
695 /*
696 * A.1.2. Old Packets
697 *
698 * When a packet with Sequence Number S arrives, and
699 * S <= buf_ackno, the HC-Receiver will scan the table
700 * for the byte corresponding to S. (Indexing structures
701 * could reduce the complexity of this scan.)
702 */
703 u64 delta = dccp_delta_seqno(ackno, ap->dccpap_buf_ackno);
704 unsigned int index = ap->dccpap_buf_head;
705
706 while (1) {
707 const u8 len = dccp_ackpkts_len(ap, index);
708 const u8 state = dccp_ackpkts_state(ap, index);
709 /*
710 * valid packets not yet in dccpap_buf have a reserved
711 * entry, with a len equal to 0.
712 */
713 if (state == DCCP_ACKPKTS_STATE_NOT_RECEIVED &&
714 len == 0 && delta == 0) { /* Found our
715 reserved seat! */
716 dccp_pr_debug("Found %llu reserved seat!\n",
717 (unsigned long long) ackno);
718 ap->dccpap_buf[index] = state;
719 goto out;
720 }
721 /* len == 0 means one packet */
722 if (delta < len + 1)
723 goto out_duplicate;
724
725 delta -= len + 1;
726 if (++index == ap->dccpap_buf_len)
727 index = 0;
728 }
729 }
730
731 ap->dccpap_buf_ackno = ackno;
732 dccp_timestamp(sk, &ap->dccpap_time);
733out:
734 dccp_pr_debug("");
735 dccp_ackpkts_print(ap);
736 return 0;
737
738out_duplicate:
739 /* Duplicate packet */
740 dccp_pr_debug("Received a dup or already considered lost "
741 "packet: %llu\n", (unsigned long long) ackno);
742 return -EILSEQ;
743}
744
745#ifdef CONFIG_IP_DCCP_DEBUG
746void dccp_ackvector_print(const u64 ackno, const unsigned char *vector,
747 int len)
748{
749 if (!dccp_debug)
750 return;
751
752 printk("ACK vector len=%d, ackno=%llu |", len,
753 (unsigned long long) ackno);
754
755 while (len--) {
756 const u8 state = (*vector & DCCP_ACKPKTS_STATE_MASK) >> 6;
757 const u8 rl = (*vector & DCCP_ACKPKTS_LEN_MASK);
758
759 printk("%d,%d|", state, rl);
760 ++vector;
761 }
762
763 printk("\n");
764}
765
766void dccp_ackpkts_print(const struct dccp_ackpkts *ap)
767{
768 dccp_ackvector_print(ap->dccpap_buf_ackno,
769 ap->dccpap_buf + ap->dccpap_buf_head,
770 ap->dccpap_buf_vector_len);
771}
772#endif
773
774static void dccp_ackpkts_trow_away_ack_record(struct dccp_ackpkts *ap)
775{
776 /*
777 * As we're keeping track of the ack vector size
778 * (dccpap_buf_vector_len) and the sent ack vector size
779 * (dccpap_ack_vector_len) we don't need dccpap_buf_tail at all, but
780 * keep this code here as in the future we'll implement a vector of
781 * ack records, as suggested in draft-ietf-dccp-spec-11.txt
782 * Appendix A. -acme
783 */
784#if 0
785 ap->dccpap_buf_tail = ap->dccpap_ack_ptr + 1;
786 if (ap->dccpap_buf_tail >= ap->dccpap_buf_len)
787 ap->dccpap_buf_tail -= ap->dccpap_buf_len;
788#endif
789 ap->dccpap_buf_vector_len -= ap->dccpap_ack_vector_len;
790}
791
792void dccp_ackpkts_check_rcv_ackno(struct dccp_ackpkts *ap, struct sock *sk,
793 u64 ackno)
794{
795 /* Check if we actually sent an ACK vector */
796 if (ap->dccpap_ack_seqno == DCCP_MAX_SEQNO + 1)
797 return;
798
799 if (ackno == ap->dccpap_ack_seqno) {
800#ifdef CONFIG_IP_DCCP_DEBUG
801 struct dccp_sock *dp = dccp_sk(sk);
802 const char *debug_prefix = dp->dccps_role == DCCP_ROLE_CLIENT ?
803 "CLIENT rx ack: " : "server rx ack: ";
804#endif
805 dccp_pr_debug("%sACK packet 0, len=%d, ack_seqno=%llu, "
806 "ack_ackno=%llu, ACKED!\n",
807 debug_prefix, 1,
808 (unsigned long long) ap->dccpap_ack_seqno,
809 (unsigned long long) ap->dccpap_ack_ackno);
810 dccp_ackpkts_trow_away_ack_record(ap);
811 ap->dccpap_ack_seqno = DCCP_MAX_SEQNO + 1;
812 }
813}
814
815static void dccp_ackpkts_check_rcv_ackvector(struct dccp_ackpkts *ap,
816 struct sock *sk, u64 ackno,
817 const unsigned char len,
818 const unsigned char *vector)
819{
820 unsigned char i;
821
822 /* Check if we actually sent an ACK vector */
823 if (ap->dccpap_ack_seqno == DCCP_MAX_SEQNO + 1)
824 return;
825 /*
826 * We're in the receiver half connection, so if the received an ACK
827 * vector ackno (e.g. 50) before dccpap_ack_seqno (e.g. 52), we're
828 * not interested.
829 *
830 * Extra explanation with example:
831 *
832 * if we received an ACK vector with ackno 50, it can only be acking
833 * 50, 49, 48, etc, not 52 (the seqno for the ACK vector we sent).
834 */
835 /* dccp_pr_debug("is %llu < %llu? ", ackno, ap->dccpap_ack_seqno); */
836 if (before48(ackno, ap->dccpap_ack_seqno)) {
837 /* dccp_pr_debug_cat("yes\n"); */
838 return;
839 }
840 /* dccp_pr_debug_cat("no\n"); */
841
842 i = len;
843 while (i--) {
844 const u8 rl = (*vector & DCCP_ACKPKTS_LEN_MASK);
845 u64 ackno_end_rl;
846
847 dccp_set_seqno(&ackno_end_rl, ackno - rl);
848
849 /*
850 * dccp_pr_debug("is %llu <= %llu <= %llu? ", ackno_end_rl,
851 * ap->dccpap_ack_seqno, ackno);
852 */
853 if (between48(ap->dccpap_ack_seqno, ackno_end_rl, ackno)) {
854 const u8 state = (*vector &
855 DCCP_ACKPKTS_STATE_MASK) >> 6;
856 /* dccp_pr_debug_cat("yes\n"); */
857
858 if (state != DCCP_ACKPKTS_STATE_NOT_RECEIVED) {
859#ifdef CONFIG_IP_DCCP_DEBUG
860 struct dccp_sock *dp = dccp_sk(sk);
861 const char *debug_prefix =
862 dp->dccps_role == DCCP_ROLE_CLIENT ?
863 "CLIENT rx ack: " : "server rx ack: ";
864#endif
865 dccp_pr_debug("%sACK vector 0, len=%d, "
866 "ack_seqno=%llu, ack_ackno=%llu, "
867 "ACKED!\n",
868 debug_prefix, len,
869 (unsigned long long)
870 ap->dccpap_ack_seqno,
871 (unsigned long long)
872 ap->dccpap_ack_ackno);
873 dccp_ackpkts_trow_away_ack_record(ap);
874 }
875 /*
876 * If dccpap_ack_seqno was not received, no problem
877 * we'll send another ACK vector.
878 */
879 ap->dccpap_ack_seqno = DCCP_MAX_SEQNO + 1;
880 break;
881 }
882 /* dccp_pr_debug_cat("no\n"); */
883
884 dccp_set_seqno(&ackno, ackno_end_rl - 1);
885 ++vector;
886 }
887}
diff --git a/net/dccp/output.c b/net/dccp/output.c
index 156b1d29a156..4786bdcddcc9 100644
--- a/net/dccp/output.c
+++ b/net/dccp/output.c
@@ -16,6 +16,7 @@
16 16
17#include <net/sock.h> 17#include <net/sock.h>
18 18
19#include "ackvec.h"
19#include "ccid.h" 20#include "ccid.h"
20#include "dccp.h" 21#include "dccp.h"
21 22
@@ -225,7 +226,6 @@ int dccp_write_xmit(struct sock *sk, struct sk_buff *skb, long *timeo)
225 err = dccp_wait_for_ccid(sk, skb, timeo); 226 err = dccp_wait_for_ccid(sk, skb, timeo);
226 227
227 if (err == 0) { 228 if (err == 0) {
228 const struct dccp_ackpkts *ap = dp->dccps_hc_rx_ackpkts;
229 struct dccp_skb_cb *dcb = DCCP_SKB_CB(skb); 229 struct dccp_skb_cb *dcb = DCCP_SKB_CB(skb);
230 const int len = skb->len; 230 const int len = skb->len;
231 231
@@ -236,15 +236,7 @@ int dccp_write_xmit(struct sock *sk, struct sk_buff *skb, long *timeo)
236 inet_csk(sk)->icsk_rto, 236 inet_csk(sk)->icsk_rto,
237 DCCP_RTO_MAX); 237 DCCP_RTO_MAX);
238 dcb->dccpd_type = DCCP_PKT_DATAACK; 238 dcb->dccpd_type = DCCP_PKT_DATAACK;
239 /* 239 } else if (dccp_ack_pending(sk))
240 * FIXME: we really should have a
241 * dccps_ack_pending or use icsk.
242 */
243 } else if (inet_csk_ack_scheduled(sk) ||
244 dp->dccps_timestamp_echo != 0 ||
245 (dp->dccps_options.dccpo_send_ack_vector &&
246 ap->dccpap_buf_ackno != DCCP_MAX_SEQNO + 1 &&
247 ap->dccpap_ack_seqno == DCCP_MAX_SEQNO + 1))
248 dcb->dccpd_type = DCCP_PKT_DATAACK; 240 dcb->dccpd_type = DCCP_PKT_DATAACK;
249 else 241 else
250 dcb->dccpd_type = DCCP_PKT_DATA; 242 dcb->dccpd_type = DCCP_PKT_DATA;