blob: 41d34d1babc17da94d874a75878c66cc9fc5cb87 [file] [log] [blame]
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -07001/*
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>
Arnaldo Carvalho de Melo9b07ef52006-03-20 17:16:17 -080016#include <linux/init.h>
17#include <linux/errno.h>
18#include <linux/kernel.h>
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -070019#include <linux/skbuff.h>
Arnaldo Carvalho de Melo9b07ef52006-03-20 17:16:17 -080020#include <linux/slab.h>
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -070021
22#include <net/sock.h>
23
Arnaldo Carvalho de Melo9b07ef52006-03-20 17:16:17 -080024static kmem_cache_t *dccp_ackvec_slab;
Andrea Bittau02bcf282006-03-20 17:19:55 -080025static kmem_cache_t *dccp_ackvec_record_slab;
26
27static struct dccp_ackvec_record *dccp_ackvec_record_new(void)
28{
29 struct dccp_ackvec_record *avr =
30 kmem_cache_alloc(dccp_ackvec_record_slab, GFP_ATOMIC);
31
32 if (avr != NULL)
33 INIT_LIST_HEAD(&avr->dccpavr_node);
34
35 return avr;
36}
37
38static void dccp_ackvec_record_delete(struct dccp_ackvec_record *avr)
39{
40 if (unlikely(avr == NULL))
41 return;
42 /* Check if deleting a linked record */
43 WARN_ON(!list_empty(&avr->dccpavr_node));
44 kmem_cache_free(dccp_ackvec_record_slab, avr);
45}
46
47static void dccp_ackvec_insert_avr(struct dccp_ackvec *av,
48 struct dccp_ackvec_record *avr)
49{
50 /*
51 * AVRs are sorted by seqno. Since we are sending them in order, we
52 * just add the AVR at the head of the list.
53 * -sorbo.
54 */
55 if (!list_empty(&av->dccpav_records)) {
56 const struct dccp_ackvec_record *head =
57 list_entry(av->dccpav_records.next,
58 struct dccp_ackvec_record,
59 dccpavr_node);
60 BUG_ON(before48(avr->dccpavr_ack_seqno,
61 head->dccpavr_ack_seqno));
62 }
63
64 list_add(&avr->dccpavr_node, &av->dccpav_records);
65}
Arnaldo Carvalho de Melo9b07ef52006-03-20 17:16:17 -080066
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -070067int dccp_insert_option_ackvec(struct sock *sk, struct sk_buff *skb)
68{
69 struct dccp_sock *dp = dccp_sk(sk);
70 struct dccp_ackvec *av = dp->dccps_hc_rx_ackvec;
71 int len = av->dccpav_vec_len + 2;
72 struct timeval now;
73 u32 elapsed_time;
74 unsigned char *to, *from;
Andrea Bittau02bcf282006-03-20 17:19:55 -080075 struct dccp_ackvec_record *avr;
76
77 if (DCCP_SKB_CB(skb)->dccpd_opt_len + len > DCCP_MAX_OPT_LEN)
78 return -1;
79
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -070080 dccp_timestamp(sk, &now);
81 elapsed_time = timeval_delta(&now, &av->dccpav_time) / 10;
82
Arnaldo Carvalho de Melo2d0817d2006-03-20 22:32:06 -080083 if (elapsed_time != 0 &&
84 dccp_insert_option_elapsed_time(sk, skb, elapsed_time))
85 return -1;
86
87 avr = dccp_ackvec_record_new();
88 if (avr == NULL)
89 return -1;
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -070090
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -070091 DCCP_SKB_CB(skb)->dccpd_opt_len += len;
92
93 to = skb_push(skb, len);
94 *to++ = DCCPO_ACK_VECTOR_0;
95 *to++ = len;
96
97 len = av->dccpav_vec_len;
98 from = av->dccpav_buf + av->dccpav_buf_head;
99
100 /* Check if buf_head wraps */
Andrea Bittau02bcf282006-03-20 17:19:55 -0800101 if ((int)av->dccpav_buf_head + len > DCCP_MAX_ACKVEC_LEN) {
102 const u32 tailsize = DCCP_MAX_ACKVEC_LEN - av->dccpav_buf_head;
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700103
104 memcpy(to, from, tailsize);
105 to += tailsize;
106 len -= tailsize;
107 from = av->dccpav_buf;
108 }
109
110 memcpy(to, from, len);
111 /*
Gerrit Renker0e64e942006-10-24 16:17:51 -0700112 * From RFC 4340, A.2:
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700113 *
114 * For each acknowledgement it sends, the HC-Receiver will add an
115 * acknowledgement record. ack_seqno will equal the HC-Receiver
116 * sequence number it used for the ack packet; ack_ptr will equal
117 * buf_head; ack_ackno will equal buf_ackno; and ack_nonce will
118 * equal buf_nonce.
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700119 */
Andrea Bittau02bcf282006-03-20 17:19:55 -0800120 avr->dccpavr_ack_seqno = DCCP_SKB_CB(skb)->dccpd_seq;
121 avr->dccpavr_ack_ptr = av->dccpav_buf_head;
122 avr->dccpavr_ack_ackno = av->dccpav_buf_ackno;
123 avr->dccpavr_ack_nonce = av->dccpav_buf_nonce;
124 avr->dccpavr_sent_len = av->dccpav_vec_len;
125
126 dccp_ackvec_insert_avr(av, avr);
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700127
Gerrit Renker09dbc382006-11-14 12:57:34 -0200128 dccp_pr_debug("%s ACK Vector 0, len=%d, ack_seqno=%llu, "
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700129 "ack_ackno=%llu\n",
Gerrit Renker09dbc382006-11-14 12:57:34 -0200130 dccp_role(sk), avr->dccpavr_sent_len,
Andrea Bittau02bcf282006-03-20 17:19:55 -0800131 (unsigned long long)avr->dccpavr_ack_seqno,
132 (unsigned long long)avr->dccpavr_ack_ackno);
133 return 0;
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700134}
135
Arnaldo Carvalho de Melo7400d782006-03-20 17:15:42 -0800136struct dccp_ackvec *dccp_ackvec_alloc(const gfp_t priority)
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700137{
Arnaldo Carvalho de Melo9b07ef52006-03-20 17:16:17 -0800138 struct dccp_ackvec *av = kmem_cache_alloc(dccp_ackvec_slab, priority);
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700139
140 if (av != NULL) {
Andrea Bittau4a0a50fb42006-09-19 13:06:16 -0700141 av->dccpav_buf_head = DCCP_MAX_ACKVEC_LEN - 1;
Andrea Bittau02bcf282006-03-20 17:19:55 -0800142 av->dccpav_buf_ackno = DCCP_MAX_SEQNO + 1;
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700143 av->dccpav_buf_nonce = av->dccpav_buf_nonce = 0;
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700144 av->dccpav_time.tv_sec = 0;
145 av->dccpav_time.tv_usec = 0;
Andrea Bittau4a0a50fb42006-09-19 13:06:16 -0700146 av->dccpav_vec_len = 0;
Andrea Bittau02bcf282006-03-20 17:19:55 -0800147 INIT_LIST_HEAD(&av->dccpav_records);
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700148 }
149
150 return av;
151}
152
153void dccp_ackvec_free(struct dccp_ackvec *av)
154{
Andrea Bittau02bcf282006-03-20 17:19:55 -0800155 if (unlikely(av == NULL))
156 return;
Arnaldo Carvalho de Melod5e9b2c2006-03-20 17:20:46 -0800157
158 if (!list_empty(&av->dccpav_records)) {
159 struct dccp_ackvec_record *avr, *next;
160
161 list_for_each_entry_safe(avr, next, &av->dccpav_records,
162 dccpavr_node) {
163 list_del_init(&avr->dccpavr_node);
164 dccp_ackvec_record_delete(avr);
165 }
166 }
167
Arnaldo Carvalho de Melo9b07ef52006-03-20 17:16:17 -0800168 kmem_cache_free(dccp_ackvec_slab, av);
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700169}
170
171static inline u8 dccp_ackvec_state(const struct dccp_ackvec *av,
Andrea Bittaubdf13d22006-11-24 13:02:42 -0200172 const u32 index)
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700173{
174 return av->dccpav_buf[index] & DCCP_ACKVEC_STATE_MASK;
175}
176
177static inline u8 dccp_ackvec_len(const struct dccp_ackvec *av,
Andrea Bittaubdf13d22006-11-24 13:02:42 -0200178 const u32 index)
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700179{
180 return av->dccpav_buf[index] & DCCP_ACKVEC_LEN_MASK;
181}
182
183/*
184 * If several packets are missing, the HC-Receiver may prefer to enter multiple
185 * bytes with run length 0, rather than a single byte with a larger run length;
186 * this simplifies table updates if one of the missing packets arrives.
187 */
188static inline int dccp_ackvec_set_buf_head_state(struct dccp_ackvec *av,
189 const unsigned int packets,
Arnaldo Carvalho de Meloe4dfd442006-01-04 01:46:34 -0200190 const unsigned char state)
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700191{
192 unsigned int gap;
Kris Katterjohna8fc3d82006-01-17 13:03:54 -0800193 long new_head;
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700194
Arnaldo Carvalho de Melo7400d782006-03-20 17:15:42 -0800195 if (av->dccpav_vec_len + packets > DCCP_MAX_ACKVEC_LEN)
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700196 return -ENOBUFS;
197
198 gap = packets - 1;
199 new_head = av->dccpav_buf_head - packets;
200
201 if (new_head < 0) {
202 if (gap > 0) {
203 memset(av->dccpav_buf, DCCP_ACKVEC_STATE_NOT_RECEIVED,
204 gap + new_head + 1);
205 gap = -new_head;
206 }
Arnaldo Carvalho de Melo7400d782006-03-20 17:15:42 -0800207 new_head += DCCP_MAX_ACKVEC_LEN;
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700208 }
209
210 av->dccpav_buf_head = new_head;
211
212 if (gap > 0)
213 memset(av->dccpav_buf + av->dccpav_buf_head + 1,
214 DCCP_ACKVEC_STATE_NOT_RECEIVED, gap);
215
216 av->dccpav_buf[av->dccpav_buf_head] = state;
217 av->dccpav_vec_len += packets;
218 return 0;
219}
220
221/*
Gerrit Renker0e64e942006-10-24 16:17:51 -0700222 * Implements the RFC 4340, Appendix A
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700223 */
224int dccp_ackvec_add(struct dccp_ackvec *av, const struct sock *sk,
225 const u64 ackno, const u8 state)
226{
227 /*
228 * Check at the right places if the buffer is full, if it is, tell the
229 * caller to start dropping packets till the HC-Sender acks our ACK
230 * vectors, when we will free up space in dccpav_buf.
231 *
232 * We may well decide to do buffer compression, etc, but for now lets
233 * just drop.
234 *
Gerrit Renker0e64e942006-10-24 16:17:51 -0700235 * From Appendix A.1.1 (`New Packets'):
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700236 *
237 * Of course, the circular buffer may overflow, either when the
238 * HC-Sender is sending data at a very high rate, when the
239 * HC-Receiver's acknowledgements are not reaching the HC-Sender,
240 * or when the HC-Sender is forgetting to acknowledge those acks
241 * (so the HC-Receiver is unable to clean up old state). In this
242 * case, the HC-Receiver should either compress the buffer (by
243 * increasing run lengths when possible), transfer its state to
244 * a larger buffer, or, as a last resort, drop all received
245 * packets, without processing them whatsoever, until its buffer
246 * shrinks again.
247 */
248
249 /* See if this is the first ackno being inserted */
250 if (av->dccpav_vec_len == 0) {
251 av->dccpav_buf[av->dccpav_buf_head] = state;
252 av->dccpav_vec_len = 1;
253 } else if (after48(ackno, av->dccpav_buf_ackno)) {
254 const u64 delta = dccp_delta_seqno(av->dccpav_buf_ackno,
255 ackno);
256
257 /*
258 * Look if the state of this packet is the same as the
259 * previous ackno and if so if we can bump the head len.
260 */
261 if (delta == 1 &&
262 dccp_ackvec_state(av, av->dccpav_buf_head) == state &&
263 (dccp_ackvec_len(av, av->dccpav_buf_head) <
264 DCCP_ACKVEC_LEN_MASK))
265 av->dccpav_buf[av->dccpav_buf_head]++;
266 else if (dccp_ackvec_set_buf_head_state(av, delta, state))
267 return -ENOBUFS;
268 } else {
269 /*
270 * A.1.2. Old Packets
271 *
Gerrit Renker0e64e942006-10-24 16:17:51 -0700272 * When a packet with Sequence Number S <= buf_ackno
273 * arrives, the HC-Receiver will scan the table for
274 * the byte corresponding to S. (Indexing structures
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700275 * could reduce the complexity of this scan.)
276 */
277 u64 delta = dccp_delta_seqno(ackno, av->dccpav_buf_ackno);
Andrea Bittaubdf13d22006-11-24 13:02:42 -0200278 u32 index = av->dccpav_buf_head;
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700279
280 while (1) {
281 const u8 len = dccp_ackvec_len(av, index);
282 const u8 state = dccp_ackvec_state(av, index);
283 /*
284 * valid packets not yet in dccpav_buf have a reserved
285 * entry, with a len equal to 0.
286 */
287 if (state == DCCP_ACKVEC_STATE_NOT_RECEIVED &&
288 len == 0 && delta == 0) { /* Found our
289 reserved seat! */
290 dccp_pr_debug("Found %llu reserved seat!\n",
291 (unsigned long long)ackno);
292 av->dccpav_buf[index] = state;
293 goto out;
294 }
295 /* len == 0 means one packet */
296 if (delta < len + 1)
297 goto out_duplicate;
298
299 delta -= len + 1;
Arnaldo Carvalho de Melo7400d782006-03-20 17:15:42 -0800300 if (++index == DCCP_MAX_ACKVEC_LEN)
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700301 index = 0;
302 }
303 }
304
305 av->dccpav_buf_ackno = ackno;
306 dccp_timestamp(sk, &av->dccpav_time);
307out:
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700308 return 0;
309
310out_duplicate:
311 /* Duplicate packet */
312 dccp_pr_debug("Received a dup or already considered lost "
313 "packet: %llu\n", (unsigned long long)ackno);
314 return -EILSEQ;
315}
316
317#ifdef CONFIG_IP_DCCP_DEBUG
318void dccp_ackvector_print(const u64 ackno, const unsigned char *vector, int len)
319{
Gerrit Renker84116712006-11-20 18:26:03 -0200320 dccp_pr_debug_cat("ACK vector len=%d, ackno=%llu |", len,
321 (unsigned long long)ackno);
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700322
323 while (len--) {
324 const u8 state = (*vector & DCCP_ACKVEC_STATE_MASK) >> 6;
325 const u8 rl = *vector & DCCP_ACKVEC_LEN_MASK;
326
Gerrit Renker84116712006-11-20 18:26:03 -0200327 dccp_pr_debug_cat("%d,%d|", state, rl);
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700328 ++vector;
329 }
330
Gerrit Renker84116712006-11-20 18:26:03 -0200331 dccp_pr_debug_cat("\n");
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700332}
333
334void dccp_ackvec_print(const struct dccp_ackvec *av)
335{
336 dccp_ackvector_print(av->dccpav_buf_ackno,
337 av->dccpav_buf + av->dccpav_buf_head,
338 av->dccpav_vec_len);
339}
340#endif
341
Andrea Bittau02bcf282006-03-20 17:19:55 -0800342static void dccp_ackvec_throw_record(struct dccp_ackvec *av,
343 struct dccp_ackvec_record *avr)
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700344{
Andrea Bittau02bcf282006-03-20 17:19:55 -0800345 struct dccp_ackvec_record *next;
346
Andrea Bittau23d06e32006-09-19 13:04:54 -0700347 /* sort out vector length */
348 if (av->dccpav_buf_head <= avr->dccpavr_ack_ptr)
349 av->dccpav_vec_len = avr->dccpavr_ack_ptr - av->dccpav_buf_head;
350 else
351 av->dccpav_vec_len = DCCP_MAX_ACKVEC_LEN - 1
352 - av->dccpav_buf_head
353 + avr->dccpavr_ack_ptr;
Andrea Bittau02bcf282006-03-20 17:19:55 -0800354
355 /* free records */
356 list_for_each_entry_safe_from(avr, next, &av->dccpav_records,
357 dccpavr_node) {
358 list_del_init(&avr->dccpavr_node);
359 dccp_ackvec_record_delete(avr);
360 }
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700361}
362
363void dccp_ackvec_check_rcv_ackno(struct dccp_ackvec *av, struct sock *sk,
364 const u64 ackno)
365{
Andrea Bittau02bcf282006-03-20 17:19:55 -0800366 struct dccp_ackvec_record *avr;
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700367
Andrea Bittau02bcf282006-03-20 17:19:55 -0800368 /*
369 * If we traverse backwards, it should be faster when we have large
370 * windows. We will be receiving ACKs for stuff we sent a while back
371 * -sorbo.
372 */
373 list_for_each_entry_reverse(avr, &av->dccpav_records, dccpavr_node) {
374 if (ackno == avr->dccpavr_ack_seqno) {
Gerrit Renker09dbc382006-11-14 12:57:34 -0200375 dccp_pr_debug("%s ACK packet 0, len=%d, ack_seqno=%llu, "
Andrea Bittau02bcf282006-03-20 17:19:55 -0800376 "ack_ackno=%llu, ACKED!\n",
Gerrit Renker09dbc382006-11-14 12:57:34 -0200377 dccp_role(sk), 1,
Andrea Bittau02bcf282006-03-20 17:19:55 -0800378 (unsigned long long)avr->dccpavr_ack_seqno,
379 (unsigned long long)avr->dccpavr_ack_ackno);
380 dccp_ackvec_throw_record(av, avr);
381 break;
Andrea Bittaud23ca152006-11-14 13:19:45 -0200382 } else if (avr->dccpavr_ack_seqno > ackno)
383 break; /* old news */
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700384 }
385}
386
387static void dccp_ackvec_check_rcv_ackvector(struct dccp_ackvec *av,
Andrea Bittaubdf13d22006-11-24 13:02:42 -0200388 struct sock *sk, u64 *ackno,
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700389 const unsigned char len,
390 const unsigned char *vector)
391{
392 unsigned char i;
Andrea Bittau02bcf282006-03-20 17:19:55 -0800393 struct dccp_ackvec_record *avr;
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700394
395 /* Check if we actually sent an ACK vector */
Andrea Bittau02bcf282006-03-20 17:19:55 -0800396 if (list_empty(&av->dccpav_records))
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700397 return;
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700398
399 i = len;
Andrea Bittau02bcf282006-03-20 17:19:55 -0800400 /*
401 * XXX
402 * I think it might be more efficient to work backwards. See comment on
403 * rcv_ackno. -sorbo.
404 */
405 avr = list_entry(av->dccpav_records.next, struct dccp_ackvec_record,
406 dccpavr_node);
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700407 while (i--) {
408 const u8 rl = *vector & DCCP_ACKVEC_LEN_MASK;
409 u64 ackno_end_rl;
410
Andrea Bittaubdf13d22006-11-24 13:02:42 -0200411 dccp_set_seqno(&ackno_end_rl, *ackno - rl);
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700412
413 /*
Andrea Bittau02bcf282006-03-20 17:19:55 -0800414 * If our AVR sequence number is greater than the ack, go
415 * forward in the AVR list until it is not so.
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700416 */
Andrea Bittau02bcf282006-03-20 17:19:55 -0800417 list_for_each_entry_from(avr, &av->dccpav_records,
418 dccpavr_node) {
Andrea Bittaubdf13d22006-11-24 13:02:42 -0200419 if (!after48(avr->dccpavr_ack_seqno, *ackno))
Andrea Bittau02bcf282006-03-20 17:19:55 -0800420 goto found;
421 }
422 /* End of the dccpav_records list, not found, exit */
423 break;
424found:
Andrea Bittaubdf13d22006-11-24 13:02:42 -0200425 if (between48(avr->dccpavr_ack_seqno, ackno_end_rl, *ackno)) {
Andrea Bittau8e27e462006-09-19 13:05:35 -0700426 const u8 state = *vector & DCCP_ACKVEC_STATE_MASK;
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700427 if (state != DCCP_ACKVEC_STATE_NOT_RECEIVED) {
Gerrit Renker09dbc382006-11-14 12:57:34 -0200428 dccp_pr_debug("%s ACK vector 0, len=%d, "
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700429 "ack_seqno=%llu, ack_ackno=%llu, "
430 "ACKED!\n",
Gerrit Renker09dbc382006-11-14 12:57:34 -0200431 dccp_role(sk), len,
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700432 (unsigned long long)
Andrea Bittau02bcf282006-03-20 17:19:55 -0800433 avr->dccpavr_ack_seqno,
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700434 (unsigned long long)
Andrea Bittau02bcf282006-03-20 17:19:55 -0800435 avr->dccpavr_ack_ackno);
436 dccp_ackvec_throw_record(av, avr);
Andrea Bittauafec35e2006-06-11 20:58:33 -0700437 break;
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700438 }
439 /*
Andrea Bittau02bcf282006-03-20 17:19:55 -0800440 * If it wasn't received, continue scanning... we might
441 * find another one.
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700442 */
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700443 }
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700444
Andrea Bittaubdf13d22006-11-24 13:02:42 -0200445 dccp_set_seqno(ackno, ackno_end_rl - 1);
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700446 ++vector;
447 }
448}
449
450int dccp_ackvec_parse(struct sock *sk, const struct sk_buff *skb,
Andrea Bittaubdf13d22006-11-24 13:02:42 -0200451 u64 *ackno, const u8 opt, const u8 *value, const u8 len)
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700452{
Andrea Bittaubdf13d22006-11-24 13:02:42 -0200453 if (len > DCCP_MAX_ACKVEC_OPT_LEN)
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700454 return -1;
455
456 /* dccp_ackvector_print(DCCP_SKB_CB(skb)->dccpd_ack_seq, value, len); */
457 dccp_ackvec_check_rcv_ackvector(dccp_sk(sk)->dccps_hc_rx_ackvec, sk,
Andrea Bittaubdf13d22006-11-24 13:02:42 -0200458 ackno, len, value);
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700459 return 0;
460}
Arnaldo Carvalho de Melo9b07ef52006-03-20 17:16:17 -0800461
Arnaldo Carvalho de Melo9b07ef52006-03-20 17:16:17 -0800462int __init dccp_ackvec_init(void)
463{
464 dccp_ackvec_slab = kmem_cache_create("dccp_ackvec",
465 sizeof(struct dccp_ackvec), 0,
466 SLAB_HWCACHE_ALIGN, NULL, NULL);
Andrea Bittau02bcf282006-03-20 17:19:55 -0800467 if (dccp_ackvec_slab == NULL)
468 goto out_err;
469
470 dccp_ackvec_record_slab =
471 kmem_cache_create("dccp_ackvec_record",
472 sizeof(struct dccp_ackvec_record),
473 0, SLAB_HWCACHE_ALIGN, NULL, NULL);
474 if (dccp_ackvec_record_slab == NULL)
475 goto out_destroy_slab;
Arnaldo Carvalho de Melo9b07ef52006-03-20 17:16:17 -0800476
477 return 0;
Andrea Bittau02bcf282006-03-20 17:19:55 -0800478
479out_destroy_slab:
480 kmem_cache_destroy(dccp_ackvec_slab);
481 dccp_ackvec_slab = NULL;
482out_err:
Gerrit Renker59348b12006-11-20 18:39:23 -0200483 DCCP_CRIT("Unable to create Ack Vector slab cache");
Andrea Bittau02bcf282006-03-20 17:19:55 -0800484 return -ENOBUFS;
Arnaldo Carvalho de Melo9b07ef52006-03-20 17:16:17 -0800485}
486
487void dccp_ackvec_exit(void)
488{
489 if (dccp_ackvec_slab != NULL) {
490 kmem_cache_destroy(dccp_ackvec_slab);
491 dccp_ackvec_slab = NULL;
492 }
Andrea Bittau02bcf282006-03-20 17:19:55 -0800493 if (dccp_ackvec_record_slab != NULL) {
494 kmem_cache_destroy(dccp_ackvec_record_slab);
495 dccp_ackvec_record_slab = NULL;
496 }
Arnaldo Carvalho de Melo9b07ef52006-03-20 17:16:17 -0800497}