blob: f8208874ac7d79bc3f4c3516e54d7e7e87514c90 [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);
Arnaldo Carvalho de Melo7400d782006-03-20 17:15:42 -080070#ifdef CONFIG_IP_DCCP_DEBUG
71 const char *debug_prefix = dp->dccps_role == DCCP_ROLE_CLIENT ?
72 "CLIENT tx: " : "server tx: ";
73#endif
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -070074 struct dccp_ackvec *av = dp->dccps_hc_rx_ackvec;
75 int len = av->dccpav_vec_len + 2;
76 struct timeval now;
77 u32 elapsed_time;
78 unsigned char *to, *from;
Andrea Bittau02bcf282006-03-20 17:19:55 -080079 struct dccp_ackvec_record *avr;
80
81 if (DCCP_SKB_CB(skb)->dccpd_opt_len + len > DCCP_MAX_OPT_LEN)
82 return -1;
83
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -070084 dccp_timestamp(sk, &now);
85 elapsed_time = timeval_delta(&now, &av->dccpav_time) / 10;
86
Arnaldo Carvalho de Melo2d0817d2006-03-20 22:32:06 -080087 if (elapsed_time != 0 &&
88 dccp_insert_option_elapsed_time(sk, skb, elapsed_time))
89 return -1;
90
91 avr = dccp_ackvec_record_new();
92 if (avr == NULL)
93 return -1;
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -070094
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -070095 DCCP_SKB_CB(skb)->dccpd_opt_len += len;
96
97 to = skb_push(skb, len);
98 *to++ = DCCPO_ACK_VECTOR_0;
99 *to++ = len;
100
101 len = av->dccpav_vec_len;
102 from = av->dccpav_buf + av->dccpav_buf_head;
103
104 /* Check if buf_head wraps */
Andrea Bittau02bcf282006-03-20 17:19:55 -0800105 if ((int)av->dccpav_buf_head + len > DCCP_MAX_ACKVEC_LEN) {
106 const u32 tailsize = DCCP_MAX_ACKVEC_LEN - av->dccpav_buf_head;
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700107
108 memcpy(to, from, tailsize);
109 to += tailsize;
110 len -= tailsize;
111 from = av->dccpav_buf;
112 }
113
114 memcpy(to, from, len);
115 /*
Gerrit Renker0e64e942006-10-24 16:17:51 -0700116 * From RFC 4340, A.2:
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700117 *
118 * For each acknowledgement it sends, the HC-Receiver will add an
119 * acknowledgement record. ack_seqno will equal the HC-Receiver
120 * sequence number it used for the ack packet; ack_ptr will equal
121 * buf_head; ack_ackno will equal buf_ackno; and ack_nonce will
122 * equal buf_nonce.
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700123 */
Andrea Bittau02bcf282006-03-20 17:19:55 -0800124 avr->dccpavr_ack_seqno = DCCP_SKB_CB(skb)->dccpd_seq;
125 avr->dccpavr_ack_ptr = av->dccpav_buf_head;
126 avr->dccpavr_ack_ackno = av->dccpav_buf_ackno;
127 avr->dccpavr_ack_nonce = av->dccpav_buf_nonce;
128 avr->dccpavr_sent_len = av->dccpav_vec_len;
129
130 dccp_ackvec_insert_avr(av, avr);
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700131
132 dccp_pr_debug("%sACK Vector 0, len=%d, ack_seqno=%llu, "
133 "ack_ackno=%llu\n",
Andrea Bittau02bcf282006-03-20 17:19:55 -0800134 debug_prefix, avr->dccpavr_sent_len,
135 (unsigned long long)avr->dccpavr_ack_seqno,
136 (unsigned long long)avr->dccpavr_ack_ackno);
137 return 0;
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700138}
139
Arnaldo Carvalho de Melo7400d782006-03-20 17:15:42 -0800140struct dccp_ackvec *dccp_ackvec_alloc(const gfp_t priority)
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700141{
Arnaldo Carvalho de Melo9b07ef52006-03-20 17:16:17 -0800142 struct dccp_ackvec *av = kmem_cache_alloc(dccp_ackvec_slab, priority);
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700143
144 if (av != NULL) {
Andrea Bittau4a0a50fb42006-09-19 13:06:16 -0700145 av->dccpav_buf_head = DCCP_MAX_ACKVEC_LEN - 1;
Andrea Bittau02bcf282006-03-20 17:19:55 -0800146 av->dccpav_buf_ackno = DCCP_MAX_SEQNO + 1;
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700147 av->dccpav_buf_nonce = av->dccpav_buf_nonce = 0;
148 av->dccpav_ack_ptr = 0;
149 av->dccpav_time.tv_sec = 0;
150 av->dccpav_time.tv_usec = 0;
Andrea Bittau4a0a50fb42006-09-19 13:06:16 -0700151 av->dccpav_vec_len = 0;
Andrea Bittau02bcf282006-03-20 17:19:55 -0800152 INIT_LIST_HEAD(&av->dccpav_records);
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700153 }
154
155 return av;
156}
157
158void dccp_ackvec_free(struct dccp_ackvec *av)
159{
Andrea Bittau02bcf282006-03-20 17:19:55 -0800160 if (unlikely(av == NULL))
161 return;
Arnaldo Carvalho de Melod5e9b2c2006-03-20 17:20:46 -0800162
163 if (!list_empty(&av->dccpav_records)) {
164 struct dccp_ackvec_record *avr, *next;
165
166 list_for_each_entry_safe(avr, next, &av->dccpav_records,
167 dccpavr_node) {
168 list_del_init(&avr->dccpavr_node);
169 dccp_ackvec_record_delete(avr);
170 }
171 }
172
Arnaldo Carvalho de Melo9b07ef52006-03-20 17:16:17 -0800173 kmem_cache_free(dccp_ackvec_slab, av);
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700174}
175
176static inline u8 dccp_ackvec_state(const struct dccp_ackvec *av,
Arnaldo Carvalho de Meloe4dfd442006-01-04 01:46:34 -0200177 const u8 index)
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700178{
179 return av->dccpav_buf[index] & DCCP_ACKVEC_STATE_MASK;
180}
181
182static inline u8 dccp_ackvec_len(const struct dccp_ackvec *av,
Arnaldo Carvalho de Meloe4dfd442006-01-04 01:46:34 -0200183 const u8 index)
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700184{
185 return av->dccpav_buf[index] & DCCP_ACKVEC_LEN_MASK;
186}
187
188/*
189 * If several packets are missing, the HC-Receiver may prefer to enter multiple
190 * bytes with run length 0, rather than a single byte with a larger run length;
191 * this simplifies table updates if one of the missing packets arrives.
192 */
193static inline int dccp_ackvec_set_buf_head_state(struct dccp_ackvec *av,
194 const unsigned int packets,
Arnaldo Carvalho de Meloe4dfd442006-01-04 01:46:34 -0200195 const unsigned char state)
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700196{
197 unsigned int gap;
Kris Katterjohna8fc3d82006-01-17 13:03:54 -0800198 long new_head;
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700199
Arnaldo Carvalho de Melo7400d782006-03-20 17:15:42 -0800200 if (av->dccpav_vec_len + packets > DCCP_MAX_ACKVEC_LEN)
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700201 return -ENOBUFS;
202
203 gap = packets - 1;
204 new_head = av->dccpav_buf_head - packets;
205
206 if (new_head < 0) {
207 if (gap > 0) {
208 memset(av->dccpav_buf, DCCP_ACKVEC_STATE_NOT_RECEIVED,
209 gap + new_head + 1);
210 gap = -new_head;
211 }
Arnaldo Carvalho de Melo7400d782006-03-20 17:15:42 -0800212 new_head += DCCP_MAX_ACKVEC_LEN;
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700213 }
214
215 av->dccpav_buf_head = new_head;
216
217 if (gap > 0)
218 memset(av->dccpav_buf + av->dccpav_buf_head + 1,
219 DCCP_ACKVEC_STATE_NOT_RECEIVED, gap);
220
221 av->dccpav_buf[av->dccpav_buf_head] = state;
222 av->dccpav_vec_len += packets;
223 return 0;
224}
225
226/*
Gerrit Renker0e64e942006-10-24 16:17:51 -0700227 * Implements the RFC 4340, Appendix A
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700228 */
229int dccp_ackvec_add(struct dccp_ackvec *av, const struct sock *sk,
230 const u64 ackno, const u8 state)
231{
232 /*
233 * Check at the right places if the buffer is full, if it is, tell the
234 * caller to start dropping packets till the HC-Sender acks our ACK
235 * vectors, when we will free up space in dccpav_buf.
236 *
237 * We may well decide to do buffer compression, etc, but for now lets
238 * just drop.
239 *
Gerrit Renker0e64e942006-10-24 16:17:51 -0700240 * From Appendix A.1.1 (`New Packets'):
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700241 *
242 * Of course, the circular buffer may overflow, either when the
243 * HC-Sender is sending data at a very high rate, when the
244 * HC-Receiver's acknowledgements are not reaching the HC-Sender,
245 * or when the HC-Sender is forgetting to acknowledge those acks
246 * (so the HC-Receiver is unable to clean up old state). In this
247 * case, the HC-Receiver should either compress the buffer (by
248 * increasing run lengths when possible), transfer its state to
249 * a larger buffer, or, as a last resort, drop all received
250 * packets, without processing them whatsoever, until its buffer
251 * shrinks again.
252 */
253
254 /* See if this is the first ackno being inserted */
255 if (av->dccpav_vec_len == 0) {
256 av->dccpav_buf[av->dccpav_buf_head] = state;
257 av->dccpav_vec_len = 1;
258 } else if (after48(ackno, av->dccpav_buf_ackno)) {
259 const u64 delta = dccp_delta_seqno(av->dccpav_buf_ackno,
260 ackno);
261
262 /*
263 * Look if the state of this packet is the same as the
264 * previous ackno and if so if we can bump the head len.
265 */
266 if (delta == 1 &&
267 dccp_ackvec_state(av, av->dccpav_buf_head) == state &&
268 (dccp_ackvec_len(av, av->dccpav_buf_head) <
269 DCCP_ACKVEC_LEN_MASK))
270 av->dccpav_buf[av->dccpav_buf_head]++;
271 else if (dccp_ackvec_set_buf_head_state(av, delta, state))
272 return -ENOBUFS;
273 } else {
274 /*
275 * A.1.2. Old Packets
276 *
Gerrit Renker0e64e942006-10-24 16:17:51 -0700277 * When a packet with Sequence Number S <= buf_ackno
278 * arrives, the HC-Receiver will scan the table for
279 * the byte corresponding to S. (Indexing structures
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700280 * could reduce the complexity of this scan.)
281 */
282 u64 delta = dccp_delta_seqno(ackno, av->dccpav_buf_ackno);
Arnaldo Carvalho de Meloe4dfd442006-01-04 01:46:34 -0200283 u8 index = av->dccpav_buf_head;
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700284
285 while (1) {
286 const u8 len = dccp_ackvec_len(av, index);
287 const u8 state = dccp_ackvec_state(av, index);
288 /*
289 * valid packets not yet in dccpav_buf have a reserved
290 * entry, with a len equal to 0.
291 */
292 if (state == DCCP_ACKVEC_STATE_NOT_RECEIVED &&
293 len == 0 && delta == 0) { /* Found our
294 reserved seat! */
295 dccp_pr_debug("Found %llu reserved seat!\n",
296 (unsigned long long)ackno);
297 av->dccpav_buf[index] = state;
298 goto out;
299 }
300 /* len == 0 means one packet */
301 if (delta < len + 1)
302 goto out_duplicate;
303
304 delta -= len + 1;
Arnaldo Carvalho de Melo7400d782006-03-20 17:15:42 -0800305 if (++index == DCCP_MAX_ACKVEC_LEN)
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700306 index = 0;
307 }
308 }
309
310 av->dccpav_buf_ackno = ackno;
311 dccp_timestamp(sk, &av->dccpav_time);
312out:
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700313 return 0;
314
315out_duplicate:
316 /* Duplicate packet */
317 dccp_pr_debug("Received a dup or already considered lost "
318 "packet: %llu\n", (unsigned long long)ackno);
319 return -EILSEQ;
320}
321
322#ifdef CONFIG_IP_DCCP_DEBUG
323void dccp_ackvector_print(const u64 ackno, const unsigned char *vector, int len)
324{
325 if (!dccp_debug)
326 return;
327
328 printk("ACK vector len=%d, ackno=%llu |", len,
329 (unsigned long long)ackno);
330
331 while (len--) {
332 const u8 state = (*vector & DCCP_ACKVEC_STATE_MASK) >> 6;
333 const u8 rl = *vector & DCCP_ACKVEC_LEN_MASK;
334
335 printk("%d,%d|", state, rl);
336 ++vector;
337 }
338
339 printk("\n");
340}
341
342void dccp_ackvec_print(const struct dccp_ackvec *av)
343{
344 dccp_ackvector_print(av->dccpav_buf_ackno,
345 av->dccpav_buf + av->dccpav_buf_head,
346 av->dccpav_vec_len);
347}
348#endif
349
Andrea Bittau02bcf282006-03-20 17:19:55 -0800350static void dccp_ackvec_throw_record(struct dccp_ackvec *av,
351 struct dccp_ackvec_record *avr)
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700352{
Andrea Bittau02bcf282006-03-20 17:19:55 -0800353 struct dccp_ackvec_record *next;
354
Andrea Bittau23d06e32006-09-19 13:04:54 -0700355 /* sort out vector length */
356 if (av->dccpav_buf_head <= avr->dccpavr_ack_ptr)
357 av->dccpav_vec_len = avr->dccpavr_ack_ptr - av->dccpav_buf_head;
358 else
359 av->dccpav_vec_len = DCCP_MAX_ACKVEC_LEN - 1
360 - av->dccpav_buf_head
361 + avr->dccpavr_ack_ptr;
Andrea Bittau02bcf282006-03-20 17:19:55 -0800362
363 /* free records */
364 list_for_each_entry_safe_from(avr, next, &av->dccpav_records,
365 dccpavr_node) {
366 list_del_init(&avr->dccpavr_node);
367 dccp_ackvec_record_delete(avr);
368 }
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700369}
370
371void dccp_ackvec_check_rcv_ackno(struct dccp_ackvec *av, struct sock *sk,
372 const u64 ackno)
373{
Andrea Bittau02bcf282006-03-20 17:19:55 -0800374 struct dccp_ackvec_record *avr;
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700375
Andrea Bittau02bcf282006-03-20 17:19:55 -0800376 /*
377 * If we traverse backwards, it should be faster when we have large
378 * windows. We will be receiving ACKs for stuff we sent a while back
379 * -sorbo.
380 */
381 list_for_each_entry_reverse(avr, &av->dccpav_records, dccpavr_node) {
382 if (ackno == avr->dccpavr_ack_seqno) {
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700383#ifdef CONFIG_IP_DCCP_DEBUG
Andrea Bittau02bcf282006-03-20 17:19:55 -0800384 struct dccp_sock *dp = dccp_sk(sk);
385 const char *debug_prefix = dp->dccps_role == DCCP_ROLE_CLIENT ?
386 "CLIENT rx ack: " : "server rx ack: ";
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700387#endif
Andrea Bittau02bcf282006-03-20 17:19:55 -0800388 dccp_pr_debug("%sACK packet 0, len=%d, ack_seqno=%llu, "
389 "ack_ackno=%llu, ACKED!\n",
390 debug_prefix, 1,
391 (unsigned long long)avr->dccpavr_ack_seqno,
392 (unsigned long long)avr->dccpavr_ack_ackno);
393 dccp_ackvec_throw_record(av, avr);
394 break;
395 }
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700396 }
397}
398
399static void dccp_ackvec_check_rcv_ackvector(struct dccp_ackvec *av,
400 struct sock *sk, u64 ackno,
401 const unsigned char len,
402 const unsigned char *vector)
403{
404 unsigned char i;
Andrea Bittau02bcf282006-03-20 17:19:55 -0800405 struct dccp_ackvec_record *avr;
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700406
407 /* Check if we actually sent an ACK vector */
Andrea Bittau02bcf282006-03-20 17:19:55 -0800408 if (list_empty(&av->dccpav_records))
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700409 return;
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700410
411 i = len;
Andrea Bittau02bcf282006-03-20 17:19:55 -0800412 /*
413 * XXX
414 * I think it might be more efficient to work backwards. See comment on
415 * rcv_ackno. -sorbo.
416 */
417 avr = list_entry(av->dccpav_records.next, struct dccp_ackvec_record,
418 dccpavr_node);
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700419 while (i--) {
420 const u8 rl = *vector & DCCP_ACKVEC_LEN_MASK;
421 u64 ackno_end_rl;
422
423 dccp_set_seqno(&ackno_end_rl, ackno - rl);
424
425 /*
Andrea Bittau02bcf282006-03-20 17:19:55 -0800426 * If our AVR sequence number is greater than the ack, go
427 * forward in the AVR list until it is not so.
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700428 */
Andrea Bittau02bcf282006-03-20 17:19:55 -0800429 list_for_each_entry_from(avr, &av->dccpav_records,
430 dccpavr_node) {
431 if (!after48(avr->dccpavr_ack_seqno, ackno))
432 goto found;
433 }
434 /* End of the dccpav_records list, not found, exit */
435 break;
436found:
437 if (between48(avr->dccpavr_ack_seqno, ackno_end_rl, ackno)) {
Andrea Bittau8e27e462006-09-19 13:05:35 -0700438 const u8 state = *vector & DCCP_ACKVEC_STATE_MASK;
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700439 if (state != DCCP_ACKVEC_STATE_NOT_RECEIVED) {
440#ifdef CONFIG_IP_DCCP_DEBUG
441 struct dccp_sock *dp = dccp_sk(sk);
442 const char *debug_prefix =
443 dp->dccps_role == DCCP_ROLE_CLIENT ?
444 "CLIENT rx ack: " : "server rx ack: ";
445#endif
446 dccp_pr_debug("%sACK vector 0, len=%d, "
447 "ack_seqno=%llu, ack_ackno=%llu, "
448 "ACKED!\n",
449 debug_prefix, len,
450 (unsigned long long)
Andrea Bittau02bcf282006-03-20 17:19:55 -0800451 avr->dccpavr_ack_seqno,
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700452 (unsigned long long)
Andrea Bittau02bcf282006-03-20 17:19:55 -0800453 avr->dccpavr_ack_ackno);
454 dccp_ackvec_throw_record(av, avr);
Andrea Bittauafec35e2006-06-11 20:58:33 -0700455 break;
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700456 }
457 /*
Andrea Bittau02bcf282006-03-20 17:19:55 -0800458 * If it wasn't received, continue scanning... we might
459 * find another one.
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700460 */
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700461 }
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700462
463 dccp_set_seqno(&ackno, ackno_end_rl - 1);
464 ++vector;
465 }
466}
467
468int dccp_ackvec_parse(struct sock *sk, const struct sk_buff *skb,
469 const u8 opt, const u8 *value, const u8 len)
470{
471 if (len > DCCP_MAX_ACKVEC_LEN)
472 return -1;
473
474 /* dccp_ackvector_print(DCCP_SKB_CB(skb)->dccpd_ack_seq, value, len); */
475 dccp_ackvec_check_rcv_ackvector(dccp_sk(sk)->dccps_hc_rx_ackvec, sk,
476 DCCP_SKB_CB(skb)->dccpd_ack_seq,
477 len, value);
478 return 0;
479}
Arnaldo Carvalho de Melo9b07ef52006-03-20 17:16:17 -0800480
481static char dccp_ackvec_slab_msg[] __initdata =
Andrea Bittau02bcf282006-03-20 17:19:55 -0800482 KERN_CRIT "DCCP: Unable to create ack vectors slab caches\n";
Arnaldo Carvalho de Melo9b07ef52006-03-20 17:16:17 -0800483
484int __init dccp_ackvec_init(void)
485{
486 dccp_ackvec_slab = kmem_cache_create("dccp_ackvec",
487 sizeof(struct dccp_ackvec), 0,
488 SLAB_HWCACHE_ALIGN, NULL, NULL);
Andrea Bittau02bcf282006-03-20 17:19:55 -0800489 if (dccp_ackvec_slab == NULL)
490 goto out_err;
491
492 dccp_ackvec_record_slab =
493 kmem_cache_create("dccp_ackvec_record",
494 sizeof(struct dccp_ackvec_record),
495 0, SLAB_HWCACHE_ALIGN, NULL, NULL);
496 if (dccp_ackvec_record_slab == NULL)
497 goto out_destroy_slab;
Arnaldo Carvalho de Melo9b07ef52006-03-20 17:16:17 -0800498
499 return 0;
Andrea Bittau02bcf282006-03-20 17:19:55 -0800500
501out_destroy_slab:
502 kmem_cache_destroy(dccp_ackvec_slab);
503 dccp_ackvec_slab = NULL;
504out_err:
505 printk(dccp_ackvec_slab_msg);
506 return -ENOBUFS;
Arnaldo Carvalho de Melo9b07ef52006-03-20 17:16:17 -0800507}
508
509void dccp_ackvec_exit(void)
510{
511 if (dccp_ackvec_slab != NULL) {
512 kmem_cache_destroy(dccp_ackvec_slab);
513 dccp_ackvec_slab = NULL;
514 }
Andrea Bittau02bcf282006-03-20 17:19:55 -0800515 if (dccp_ackvec_record_slab != NULL) {
516 kmem_cache_destroy(dccp_ackvec_record_slab);
517 dccp_ackvec_record_slab = NULL;
518 }
Arnaldo Carvalho de Melo9b07ef52006-03-20 17:16:17 -0800519}