blob: 17bf10f9605793bdf50528f735c86548d493b7d9 [file] [log] [blame]
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -07001/*
2 * net/dccp/ackvec.c
3 *
Gerrit Renkerf17a37c2010-11-10 21:20:07 +01004 * An implementation of Ack Vectors for the DCCP protocol
5 * Copyright (c) 2007 University of Aberdeen, Scotland, UK
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -07006 * Copyright (c) 2005 Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; version 2 of the License;
11 */
12
13#include "ackvec.h"
14#include "dccp.h"
15
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
Christoph Lametere18b8902006-12-06 20:33:20 -080024static struct kmem_cache *dccp_ackvec_slab;
25static struct kmem_cache *dccp_ackvec_record_slab;
Andrea Bittau02bcf282006-03-20 17:19:55 -080026
Gerrit Renkerf17a37c2010-11-10 21:20:07 +010027struct dccp_ackvec *dccp_ackvec_alloc(const gfp_t priority)
Andrea Bittau02bcf282006-03-20 17:19:55 -080028{
Gerrit Renkerf17a37c2010-11-10 21:20:07 +010029 struct dccp_ackvec *av = kmem_cache_zalloc(dccp_ackvec_slab, priority);
Andrea Bittau02bcf282006-03-20 17:19:55 -080030
Gerrit Renkerf17a37c2010-11-10 21:20:07 +010031 if (av != NULL) {
32 av->av_buf_head = DCCPAV_MAX_ACKVEC_LEN - 1;
33 INIT_LIST_HEAD(&av->av_records);
34 }
35 return av;
Andrea Bittau02bcf282006-03-20 17:19:55 -080036}
37
Gerrit Renkerf17a37c2010-11-10 21:20:07 +010038static void dccp_ackvec_purge_records(struct dccp_ackvec *av)
Andrea Bittau02bcf282006-03-20 17:19:55 -080039{
Gerrit Renkerf17a37c2010-11-10 21:20:07 +010040 struct dccp_ackvec_record *cur, *next;
41
42 list_for_each_entry_safe(cur, next, &av->av_records, avr_node)
43 kmem_cache_free(dccp_ackvec_record_slab, cur);
44 INIT_LIST_HEAD(&av->av_records);
45}
46
47void dccp_ackvec_free(struct dccp_ackvec *av)
48{
49 if (likely(av != NULL)) {
50 dccp_ackvec_purge_records(av);
51 kmem_cache_free(dccp_ackvec_slab, av);
52 }
Andrea Bittau02bcf282006-03-20 17:19:55 -080053}
54
55static void dccp_ackvec_insert_avr(struct dccp_ackvec *av,
56 struct dccp_ackvec_record *avr)
57{
58 /*
59 * AVRs are sorted by seqno. Since we are sending them in order, we
60 * just add the AVR at the head of the list.
61 * -sorbo.
62 */
Gerrit Renkera47c5102007-12-30 04:19:31 -080063 if (!list_empty(&av->av_records)) {
Andrea Bittau02bcf282006-03-20 17:19:55 -080064 const struct dccp_ackvec_record *head =
Gerrit Renkera47c5102007-12-30 04:19:31 -080065 list_entry(av->av_records.next,
Andrea Bittau02bcf282006-03-20 17:19:55 -080066 struct dccp_ackvec_record,
Gerrit Renkera47c5102007-12-30 04:19:31 -080067 avr_node);
68 BUG_ON(before48(avr->avr_ack_seqno, head->avr_ack_seqno));
Andrea Bittau02bcf282006-03-20 17:19:55 -080069 }
70
Gerrit Renkera47c5102007-12-30 04:19:31 -080071 list_add(&avr->avr_node, &av->av_records);
Andrea Bittau02bcf282006-03-20 17:19:55 -080072}
Arnaldo Carvalho de Melo9b07ef52006-03-20 17:16:17 -080073
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -070074int dccp_insert_option_ackvec(struct sock *sk, struct sk_buff *skb)
75{
76 struct dccp_sock *dp = dccp_sk(sk);
77 struct dccp_ackvec *av = dp->dccps_hc_rx_ackvec;
Andrea Bittau522f1d02006-11-26 01:04:40 -020078 /* Figure out how many options do we need to represent the ackvec */
Gerrit Renkerb20a9c22008-11-23 16:02:31 -080079 const u8 nr_opts = DIV_ROUND_UP(av->av_vec_len, DCCP_SINGLE_OPT_MAXLEN);
Gerrit Renkerf17a37c2010-11-10 21:20:07 +010080 u16 len = av->av_vec_len + 2 * nr_opts;
81 u8 i, nonce = 0;
Andrea Bittau522f1d02006-11-26 01:04:40 -020082 const unsigned char *tail, *from;
83 unsigned char *to;
Andrea Bittau02bcf282006-03-20 17:19:55 -080084 struct dccp_ackvec_record *avr;
85
86 if (DCCP_SKB_CB(skb)->dccpd_opt_len + len > DCCP_MAX_OPT_LEN)
87 return -1;
88
Gerrit Renkerf17a37c2010-11-10 21:20:07 +010089 avr = kmem_cache_alloc(dccp_ackvec_record_slab, GFP_ATOMIC);
Arnaldo Carvalho de Melo2d0817d2006-03-20 22:32:06 -080090 if (avr == NULL)
91 return -1;
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -070092
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -070093 DCCP_SKB_CB(skb)->dccpd_opt_len += len;
94
Andrea Bittau522f1d02006-11-26 01:04:40 -020095 to = skb_push(skb, len);
Gerrit Renkera47c5102007-12-30 04:19:31 -080096 len = av->av_vec_len;
97 from = av->av_buf + av->av_buf_head;
Gerrit Renkerf17a37c2010-11-10 21:20:07 +010098 tail = av->av_buf + DCCPAV_MAX_ACKVEC_LEN;
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -070099
Andrea Bittau522f1d02006-11-26 01:04:40 -0200100 for (i = 0; i < nr_opts; ++i) {
101 int copylen = len;
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700102
Gerrit Renkerb20a9c22008-11-23 16:02:31 -0800103 if (len > DCCP_SINGLE_OPT_MAXLEN)
104 copylen = DCCP_SINGLE_OPT_MAXLEN;
Andrea Bittau522f1d02006-11-26 01:04:40 -0200105
Gerrit Renkerf17a37c2010-11-10 21:20:07 +0100106 /*
107 * RFC 4340, 12.2: Encode the Nonce Echo for this Ack Vector via
108 * its type; ack_nonce is the sum of all individual buf_nonce's.
109 */
110 nonce ^= av->av_buf_nonce[i];
111
112 *to++ = DCCPO_ACK_VECTOR_0 + av->av_buf_nonce[i];
Andrea Bittau522f1d02006-11-26 01:04:40 -0200113 *to++ = copylen + 2;
114
115 /* Check if buf_head wraps */
116 if (from + copylen > tail) {
117 const u16 tailsize = tail - from;
118
119 memcpy(to, from, tailsize);
120 to += tailsize;
121 len -= tailsize;
122 copylen -= tailsize;
Gerrit Renkera47c5102007-12-30 04:19:31 -0800123 from = av->av_buf;
Andrea Bittau522f1d02006-11-26 01:04:40 -0200124 }
125
126 memcpy(to, from, copylen);
127 from += copylen;
128 to += copylen;
129 len -= copylen;
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700130 }
131
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700132 /*
Gerrit Renkerf17a37c2010-11-10 21:20:07 +0100133 * Each sent Ack Vector is recorded in the list, as per A.2 of RFC 4340.
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700134 */
Gerrit Renkerf17a37c2010-11-10 21:20:07 +0100135 avr->avr_ack_seqno = DCCP_SKB_CB(skb)->dccpd_seq;
136 avr->avr_ack_ptr = av->av_buf_head;
137 avr->avr_ack_ackno = av->av_buf_ackno;
138 avr->avr_ack_nonce = nonce;
139 avr->avr_ack_runlen = dccp_ackvec_runlen(av->av_buf + av->av_buf_head);
Andrea Bittau02bcf282006-03-20 17:19:55 -0800140
141 dccp_ackvec_insert_avr(av, avr);
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700142
Gerrit Renker09dbc382006-11-14 12:57:34 -0200143 dccp_pr_debug("%s ACK Vector 0, len=%d, ack_seqno=%llu, "
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700144 "ack_ackno=%llu\n",
Gerrit Renkerf17a37c2010-11-10 21:20:07 +0100145 dccp_role(sk), avr->avr_ack_runlen,
Gerrit Renkera47c5102007-12-30 04:19:31 -0800146 (unsigned long long)avr->avr_ack_seqno,
147 (unsigned long long)avr->avr_ack_ackno);
Andrea Bittau02bcf282006-03-20 17:19:55 -0800148 return 0;
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700149}
150
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700151/*
152 * If several packets are missing, the HC-Receiver may prefer to enter multiple
153 * bytes with run length 0, rather than a single byte with a larger run length;
154 * this simplifies table updates if one of the missing packets arrives.
155 */
156static inline int dccp_ackvec_set_buf_head_state(struct dccp_ackvec *av,
157 const unsigned int packets,
Arnaldo Carvalho de Meloe4dfd4492006-01-04 01:46:34 -0200158 const unsigned char state)
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700159{
Kulikov Vasiliy8e641592010-07-17 05:21:00 +0000160 long gap;
Kris Katterjohna8fc3d82006-01-17 13:03:54 -0800161 long new_head;
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700162
Gerrit Renkerf17a37c2010-11-10 21:20:07 +0100163 if (av->av_vec_len + packets > DCCPAV_MAX_ACKVEC_LEN)
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700164 return -ENOBUFS;
165
166 gap = packets - 1;
Gerrit Renkera47c5102007-12-30 04:19:31 -0800167 new_head = av->av_buf_head - packets;
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700168
169 if (new_head < 0) {
170 if (gap > 0) {
Gerrit Renkerf17a37c2010-11-10 21:20:07 +0100171 memset(av->av_buf, DCCPAV_NOT_RECEIVED,
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700172 gap + new_head + 1);
173 gap = -new_head;
174 }
Gerrit Renkerf17a37c2010-11-10 21:20:07 +0100175 new_head += DCCPAV_MAX_ACKVEC_LEN;
Arnaldo Carvalho de Melo8109b022006-12-10 16:01:18 -0200176 }
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700177
Gerrit Renkera47c5102007-12-30 04:19:31 -0800178 av->av_buf_head = new_head;
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700179
180 if (gap > 0)
Gerrit Renkera47c5102007-12-30 04:19:31 -0800181 memset(av->av_buf + av->av_buf_head + 1,
Gerrit Renkerf17a37c2010-11-10 21:20:07 +0100182 DCCPAV_NOT_RECEIVED, gap);
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700183
Gerrit Renkera47c5102007-12-30 04:19:31 -0800184 av->av_buf[av->av_buf_head] = state;
185 av->av_vec_len += packets;
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700186 return 0;
187}
188
189/*
Gerrit Renker0e64e942006-10-24 16:17:51 -0700190 * Implements the RFC 4340, Appendix A
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700191 */
192int dccp_ackvec_add(struct dccp_ackvec *av, const struct sock *sk,
193 const u64 ackno, const u8 state)
194{
Gerrit Renkerf17a37c2010-11-10 21:20:07 +0100195 u8 *cur_head = av->av_buf + av->av_buf_head,
196 *buf_end = av->av_buf + DCCPAV_MAX_ACKVEC_LEN;
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700197 /*
198 * Check at the right places if the buffer is full, if it is, tell the
199 * caller to start dropping packets till the HC-Sender acks our ACK
Gerrit Renkera47c5102007-12-30 04:19:31 -0800200 * vectors, when we will free up space in av_buf.
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700201 *
202 * We may well decide to do buffer compression, etc, but for now lets
203 * just drop.
204 *
Gerrit Renker0e64e942006-10-24 16:17:51 -0700205 * From Appendix A.1.1 (`New Packets'):
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700206 *
207 * Of course, the circular buffer may overflow, either when the
208 * HC-Sender is sending data at a very high rate, when the
209 * HC-Receiver's acknowledgements are not reaching the HC-Sender,
210 * or when the HC-Sender is forgetting to acknowledge those acks
211 * (so the HC-Receiver is unable to clean up old state). In this
212 * case, the HC-Receiver should either compress the buffer (by
213 * increasing run lengths when possible), transfer its state to
214 * a larger buffer, or, as a last resort, drop all received
215 * packets, without processing them whatsoever, until its buffer
216 * shrinks again.
217 */
218
219 /* See if this is the first ackno being inserted */
Gerrit Renkera47c5102007-12-30 04:19:31 -0800220 if (av->av_vec_len == 0) {
Gerrit Renkerf17a37c2010-11-10 21:20:07 +0100221 *cur_head = state;
Gerrit Renkera47c5102007-12-30 04:19:31 -0800222 av->av_vec_len = 1;
223 } else if (after48(ackno, av->av_buf_ackno)) {
224 const u64 delta = dccp_delta_seqno(av->av_buf_ackno, ackno);
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700225
226 /*
227 * Look if the state of this packet is the same as the
228 * previous ackno and if so if we can bump the head len.
229 */
Gerrit Renkerf17a37c2010-11-10 21:20:07 +0100230 if (delta == 1 && dccp_ackvec_state(cur_head) == state &&
231 dccp_ackvec_runlen(cur_head) < DCCPAV_MAX_RUNLEN)
232 *cur_head += 1;
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700233 else if (dccp_ackvec_set_buf_head_state(av, delta, state))
234 return -ENOBUFS;
235 } else {
236 /*
237 * A.1.2. Old Packets
238 *
Gerrit Renker0e64e942006-10-24 16:17:51 -0700239 * When a packet with Sequence Number S <= buf_ackno
240 * arrives, the HC-Receiver will scan the table for
241 * the byte corresponding to S. (Indexing structures
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700242 * could reduce the complexity of this scan.)
243 */
Gerrit Renkera47c5102007-12-30 04:19:31 -0800244 u64 delta = dccp_delta_seqno(ackno, av->av_buf_ackno);
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700245
246 while (1) {
Gerrit Renkerf17a37c2010-11-10 21:20:07 +0100247 const u8 len = dccp_ackvec_runlen(cur_head);
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700248 /*
Gerrit Renkera47c5102007-12-30 04:19:31 -0800249 * valid packets not yet in av_buf have a reserved
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700250 * entry, with a len equal to 0.
251 */
Gerrit Renkerf17a37c2010-11-10 21:20:07 +0100252 if (*cur_head == DCCPAV_NOT_RECEIVED && delta == 0) {
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700253 dccp_pr_debug("Found %llu reserved seat!\n",
254 (unsigned long long)ackno);
Gerrit Renkerf17a37c2010-11-10 21:20:07 +0100255 *cur_head = state;
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700256 goto out;
257 }
258 /* len == 0 means one packet */
259 if (delta < len + 1)
260 goto out_duplicate;
261
262 delta -= len + 1;
Gerrit Renkerf17a37c2010-11-10 21:20:07 +0100263 if (++cur_head == buf_end)
264 cur_head = av->av_buf;
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700265 }
266 }
267
Gerrit Renkera47c5102007-12-30 04:19:31 -0800268 av->av_buf_ackno = ackno;
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700269out:
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700270 return 0;
271
272out_duplicate:
273 /* Duplicate packet */
274 dccp_pr_debug("Received a dup or already considered lost "
275 "packet: %llu\n", (unsigned long long)ackno);
276 return -EILSEQ;
277}
278
Andrea Bittau02bcf282006-03-20 17:19:55 -0800279static void dccp_ackvec_throw_record(struct dccp_ackvec *av,
280 struct dccp_ackvec_record *avr)
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700281{
Andrea Bittau02bcf282006-03-20 17:19:55 -0800282 struct dccp_ackvec_record *next;
283
Andrea Bittau23d06e32006-09-19 13:04:54 -0700284 /* sort out vector length */
Gerrit Renkera47c5102007-12-30 04:19:31 -0800285 if (av->av_buf_head <= avr->avr_ack_ptr)
286 av->av_vec_len = avr->avr_ack_ptr - av->av_buf_head;
Andrea Bittau23d06e32006-09-19 13:04:54 -0700287 else
Gerrit Renkerf17a37c2010-11-10 21:20:07 +0100288 av->av_vec_len = DCCPAV_MAX_ACKVEC_LEN - 1 -
Gerrit Renkera47c5102007-12-30 04:19:31 -0800289 av->av_buf_head + avr->avr_ack_ptr;
Andrea Bittau02bcf282006-03-20 17:19:55 -0800290
291 /* free records */
Gerrit Renkera47c5102007-12-30 04:19:31 -0800292 list_for_each_entry_safe_from(avr, next, &av->av_records, avr_node) {
Gerrit Renkerf17a37c2010-11-10 21:20:07 +0100293 list_del(&avr->avr_node);
294 kmem_cache_free(dccp_ackvec_record_slab, avr);
Andrea Bittau02bcf282006-03-20 17:19:55 -0800295 }
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700296}
297
298void dccp_ackvec_check_rcv_ackno(struct dccp_ackvec *av, struct sock *sk,
299 const u64 ackno)
300{
Andrea Bittau02bcf282006-03-20 17:19:55 -0800301 struct dccp_ackvec_record *avr;
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700302
Andrea Bittau02bcf282006-03-20 17:19:55 -0800303 /*
304 * If we traverse backwards, it should be faster when we have large
305 * windows. We will be receiving ACKs for stuff we sent a while back
306 * -sorbo.
307 */
Gerrit Renkera47c5102007-12-30 04:19:31 -0800308 list_for_each_entry_reverse(avr, &av->av_records, avr_node) {
309 if (ackno == avr->avr_ack_seqno) {
Gerrit Renker09dbc382006-11-14 12:57:34 -0200310 dccp_pr_debug("%s ACK packet 0, len=%d, ack_seqno=%llu, "
Andrea Bittau02bcf282006-03-20 17:19:55 -0800311 "ack_ackno=%llu, ACKED!\n",
Gerrit Renkerf17a37c2010-11-10 21:20:07 +0100312 dccp_role(sk), avr->avr_ack_runlen,
Gerrit Renkera47c5102007-12-30 04:19:31 -0800313 (unsigned long long)avr->avr_ack_seqno,
314 (unsigned long long)avr->avr_ack_ackno);
Andrea Bittau02bcf282006-03-20 17:19:55 -0800315 dccp_ackvec_throw_record(av, avr);
316 break;
Gerrit Renkera47c5102007-12-30 04:19:31 -0800317 } else if (avr->avr_ack_seqno > ackno)
Andrea Bittaud23ca152006-11-14 13:19:45 -0200318 break; /* old news */
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700319 }
320}
321
322static void dccp_ackvec_check_rcv_ackvector(struct dccp_ackvec *av,
Andrea Bittaubdf13d22006-11-24 13:02:42 -0200323 struct sock *sk, u64 *ackno,
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700324 const unsigned char len,
325 const unsigned char *vector)
326{
327 unsigned char i;
Andrea Bittau02bcf282006-03-20 17:19:55 -0800328 struct dccp_ackvec_record *avr;
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700329
330 /* Check if we actually sent an ACK vector */
Gerrit Renkera47c5102007-12-30 04:19:31 -0800331 if (list_empty(&av->av_records))
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700332 return;
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700333
334 i = len;
Andrea Bittau02bcf282006-03-20 17:19:55 -0800335 /*
336 * XXX
337 * I think it might be more efficient to work backwards. See comment on
338 * rcv_ackno. -sorbo.
339 */
Gerrit Renkera47c5102007-12-30 04:19:31 -0800340 avr = list_entry(av->av_records.next, struct dccp_ackvec_record, avr_node);
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700341 while (i--) {
Gerrit Renkerf17a37c2010-11-10 21:20:07 +0100342 const u8 rl = dccp_ackvec_runlen(vector);
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700343 u64 ackno_end_rl;
344
Andrea Bittaubdf13d22006-11-24 13:02:42 -0200345 dccp_set_seqno(&ackno_end_rl, *ackno - rl);
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700346
347 /*
Andrea Bittau02bcf282006-03-20 17:19:55 -0800348 * If our AVR sequence number is greater than the ack, go
349 * forward in the AVR list until it is not so.
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700350 */
Gerrit Renkera47c5102007-12-30 04:19:31 -0800351 list_for_each_entry_from(avr, &av->av_records, avr_node) {
352 if (!after48(avr->avr_ack_seqno, *ackno))
Andrea Bittau02bcf282006-03-20 17:19:55 -0800353 goto found;
354 }
Gerrit Renkera47c5102007-12-30 04:19:31 -0800355 /* End of the av_records list, not found, exit */
Andrea Bittau02bcf282006-03-20 17:19:55 -0800356 break;
357found:
Gerrit Renkera47c5102007-12-30 04:19:31 -0800358 if (between48(avr->avr_ack_seqno, ackno_end_rl, *ackno)) {
Gerrit Renkerf17a37c2010-11-10 21:20:07 +0100359 if (dccp_ackvec_state(vector) != DCCPAV_NOT_RECEIVED) {
Gerrit Renker09dbc382006-11-14 12:57:34 -0200360 dccp_pr_debug("%s ACK vector 0, len=%d, "
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700361 "ack_seqno=%llu, ack_ackno=%llu, "
362 "ACKED!\n",
Gerrit Renker09dbc382006-11-14 12:57:34 -0200363 dccp_role(sk), len,
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700364 (unsigned long long)
Gerrit Renkera47c5102007-12-30 04:19:31 -0800365 avr->avr_ack_seqno,
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700366 (unsigned long long)
Gerrit Renkera47c5102007-12-30 04:19:31 -0800367 avr->avr_ack_ackno);
Andrea Bittau02bcf282006-03-20 17:19:55 -0800368 dccp_ackvec_throw_record(av, avr);
Andrea Bittauafec35e2006-06-11 20:58:33 -0700369 break;
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700370 }
371 /*
Andrea Bittau02bcf282006-03-20 17:19:55 -0800372 * If it wasn't received, continue scanning... we might
373 * find another one.
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700374 */
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700375 }
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700376
Andrea Bittaubdf13d22006-11-24 13:02:42 -0200377 dccp_set_seqno(ackno, ackno_end_rl - 1);
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700378 ++vector;
379 }
380}
381
382int dccp_ackvec_parse(struct sock *sk, const struct sk_buff *skb,
Andrea Bittaubdf13d22006-11-24 13:02:42 -0200383 u64 *ackno, const u8 opt, const u8 *value, const u8 len)
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700384{
Gerrit Renkerb20a9c22008-11-23 16:02:31 -0800385 if (len > DCCP_SINGLE_OPT_MAXLEN)
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700386 return -1;
387
388 /* dccp_ackvector_print(DCCP_SKB_CB(skb)->dccpd_ack_seq, value, len); */
389 dccp_ackvec_check_rcv_ackvector(dccp_sk(sk)->dccps_hc_rx_ackvec, sk,
Andrea Bittaubdf13d22006-11-24 13:02:42 -0200390 ackno, len, value);
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700391 return 0;
392}
Arnaldo Carvalho de Melo9b07ef52006-03-20 17:16:17 -0800393
Arnaldo Carvalho de Melo9b07ef52006-03-20 17:16:17 -0800394int __init dccp_ackvec_init(void)
395{
396 dccp_ackvec_slab = kmem_cache_create("dccp_ackvec",
397 sizeof(struct dccp_ackvec), 0,
Paul Mundt20c2df82007-07-20 10:11:58 +0900398 SLAB_HWCACHE_ALIGN, NULL);
Andrea Bittau02bcf282006-03-20 17:19:55 -0800399 if (dccp_ackvec_slab == NULL)
400 goto out_err;
401
Gerrit Renkerf17a37c2010-11-10 21:20:07 +0100402 dccp_ackvec_record_slab = kmem_cache_create("dccp_ackvec_record",
403 sizeof(struct dccp_ackvec_record),
404 0, SLAB_HWCACHE_ALIGN, NULL);
Andrea Bittau02bcf282006-03-20 17:19:55 -0800405 if (dccp_ackvec_record_slab == NULL)
406 goto out_destroy_slab;
Arnaldo Carvalho de Melo9b07ef52006-03-20 17:16:17 -0800407
408 return 0;
Andrea Bittau02bcf282006-03-20 17:19:55 -0800409
410out_destroy_slab:
411 kmem_cache_destroy(dccp_ackvec_slab);
412 dccp_ackvec_slab = NULL;
413out_err:
Gerrit Renker59348b12006-11-20 18:39:23 -0200414 DCCP_CRIT("Unable to create Ack Vector slab cache");
Andrea Bittau02bcf282006-03-20 17:19:55 -0800415 return -ENOBUFS;
Arnaldo Carvalho de Melo9b07ef52006-03-20 17:16:17 -0800416}
417
418void dccp_ackvec_exit(void)
419{
420 if (dccp_ackvec_slab != NULL) {
421 kmem_cache_destroy(dccp_ackvec_slab);
422 dccp_ackvec_slab = NULL;
423 }
Andrea Bittau02bcf282006-03-20 17:19:55 -0800424 if (dccp_ackvec_record_slab != NULL) {
425 kmem_cache_destroy(dccp_ackvec_record_slab);
426 dccp_ackvec_record_slab = NULL;
427 }
Arnaldo Carvalho de Melo9b07ef52006-03-20 17:16:17 -0800428}