diff options
author | David S. Miller <davem@davemloft.net> | 2010-11-11 13:43:30 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2010-11-11 13:43:30 -0500 |
commit | ed1deb7021b4dfee1d544b91edff4ef92f5c3b54 (patch) | |
tree | d4bfb7f1ec0e74db6d4f05245f56ccbc3a1173bf /net | |
parent | 72cdd1d971c0deb1619c5c339270570c43647a78 (diff) | |
parent | b3d14bff12a38ad13a174eb0cc83d2ac7169eee4 (diff) |
Merge branch 'dccp' of git://eden-feed.erg.abdn.ac.uk/net-next-2.6
Diffstat (limited to 'net')
-rw-r--r-- | net/dccp/ackvec.c | 251 | ||||
-rw-r--r-- | net/dccp/ackvec.h | 115 | ||||
-rw-r--r-- | net/dccp/ccids/ccid2.c | 13 | ||||
-rw-r--r-- | net/dccp/dccp.h | 11 | ||||
-rw-r--r-- | net/dccp/input.c | 6 | ||||
-rw-r--r-- | net/dccp/options.c | 65 |
6 files changed, 225 insertions, 236 deletions
diff --git a/net/dccp/ackvec.c b/net/dccp/ackvec.c index 92a6fcb40d7d..abaf241c7353 100644 --- a/net/dccp/ackvec.c +++ b/net/dccp/ackvec.c | |||
@@ -1,7 +1,8 @@ | |||
1 | /* | 1 | /* |
2 | * net/dccp/ackvec.c | 2 | * net/dccp/ackvec.c |
3 | * | 3 | * |
4 | * An implementation of the DCCP protocol | 4 | * An implementation of Ack Vectors for the DCCP protocol |
5 | * Copyright (c) 2007 University of Aberdeen, Scotland, UK | ||
5 | * Copyright (c) 2005 Arnaldo Carvalho de Melo <acme@ghostprotocols.net> | 6 | * Copyright (c) 2005 Arnaldo Carvalho de Melo <acme@ghostprotocols.net> |
6 | * | 7 | * |
7 | * This program is free software; you can redistribute it and/or modify it | 8 | * This program is free software; you can redistribute it and/or modify it |
@@ -23,173 +24,93 @@ | |||
23 | static struct kmem_cache *dccp_ackvec_slab; | 24 | static struct kmem_cache *dccp_ackvec_slab; |
24 | static struct kmem_cache *dccp_ackvec_record_slab; | 25 | static struct kmem_cache *dccp_ackvec_record_slab; |
25 | 26 | ||
26 | static struct dccp_ackvec_record *dccp_ackvec_record_new(void) | 27 | struct dccp_ackvec *dccp_ackvec_alloc(const gfp_t priority) |
27 | { | 28 | { |
28 | struct dccp_ackvec_record *avr = | 29 | struct dccp_ackvec *av = kmem_cache_zalloc(dccp_ackvec_slab, priority); |
29 | kmem_cache_alloc(dccp_ackvec_record_slab, GFP_ATOMIC); | ||
30 | |||
31 | if (avr != NULL) | ||
32 | INIT_LIST_HEAD(&avr->avr_node); | ||
33 | 30 | ||
34 | return avr; | 31 | if (av != NULL) { |
32 | av->av_buf_head = av->av_buf_tail = DCCPAV_MAX_ACKVEC_LEN - 1; | ||
33 | INIT_LIST_HEAD(&av->av_records); | ||
34 | } | ||
35 | return av; | ||
35 | } | 36 | } |
36 | 37 | ||
37 | static void dccp_ackvec_record_delete(struct dccp_ackvec_record *avr) | 38 | static void dccp_ackvec_purge_records(struct dccp_ackvec *av) |
38 | { | 39 | { |
39 | if (unlikely(avr == NULL)) | 40 | struct dccp_ackvec_record *cur, *next; |
40 | return; | 41 | |
41 | /* Check if deleting a linked record */ | 42 | list_for_each_entry_safe(cur, next, &av->av_records, avr_node) |
42 | WARN_ON(!list_empty(&avr->avr_node)); | 43 | kmem_cache_free(dccp_ackvec_record_slab, cur); |
43 | kmem_cache_free(dccp_ackvec_record_slab, avr); | 44 | INIT_LIST_HEAD(&av->av_records); |
44 | } | 45 | } |
45 | 46 | ||
46 | static void dccp_ackvec_insert_avr(struct dccp_ackvec *av, | 47 | void dccp_ackvec_free(struct dccp_ackvec *av) |
47 | struct dccp_ackvec_record *avr) | ||
48 | { | 48 | { |
49 | /* | 49 | if (likely(av != NULL)) { |
50 | * AVRs are sorted by seqno. Since we are sending them in order, we | 50 | dccp_ackvec_purge_records(av); |
51 | * just add the AVR at the head of the list. | 51 | kmem_cache_free(dccp_ackvec_slab, av); |
52 | * -sorbo. | ||
53 | */ | ||
54 | if (!list_empty(&av->av_records)) { | ||
55 | const struct dccp_ackvec_record *head = | ||
56 | list_entry(av->av_records.next, | ||
57 | struct dccp_ackvec_record, | ||
58 | avr_node); | ||
59 | BUG_ON(before48(avr->avr_ack_seqno, head->avr_ack_seqno)); | ||
60 | } | 52 | } |
61 | |||
62 | list_add(&avr->avr_node, &av->av_records); | ||
63 | } | 53 | } |
64 | 54 | ||
65 | int dccp_insert_option_ackvec(struct sock *sk, struct sk_buff *skb) | 55 | /** |
56 | * dccp_ackvec_update_records - Record information about sent Ack Vectors | ||
57 | * @av: Ack Vector records to update | ||
58 | * @seqno: Sequence number of the packet carrying the Ack Vector just sent | ||
59 | * @nonce_sum: The sum of all buffer nonces contained in the Ack Vector | ||
60 | */ | ||
61 | int dccp_ackvec_update_records(struct dccp_ackvec *av, u64 seqno, u8 nonce_sum) | ||
66 | { | 62 | { |
67 | struct dccp_sock *dp = dccp_sk(sk); | ||
68 | struct dccp_ackvec *av = dp->dccps_hc_rx_ackvec; | ||
69 | /* Figure out how many options do we need to represent the ackvec */ | ||
70 | const u8 nr_opts = DIV_ROUND_UP(av->av_vec_len, DCCP_SINGLE_OPT_MAXLEN); | ||
71 | u16 len = av->av_vec_len + 2 * nr_opts, i; | ||
72 | u32 elapsed_time; | ||
73 | const unsigned char *tail, *from; | ||
74 | unsigned char *to; | ||
75 | struct dccp_ackvec_record *avr; | 63 | struct dccp_ackvec_record *avr; |
76 | suseconds_t delta; | ||
77 | |||
78 | if (DCCP_SKB_CB(skb)->dccpd_opt_len + len > DCCP_MAX_OPT_LEN) | ||
79 | return -1; | ||
80 | |||
81 | delta = ktime_us_delta(ktime_get_real(), av->av_time); | ||
82 | elapsed_time = delta / 10; | ||
83 | 64 | ||
84 | if (elapsed_time != 0 && | 65 | avr = kmem_cache_alloc(dccp_ackvec_record_slab, GFP_ATOMIC); |
85 | dccp_insert_option_elapsed_time(skb, elapsed_time)) | ||
86 | return -1; | ||
87 | |||
88 | avr = dccp_ackvec_record_new(); | ||
89 | if (avr == NULL) | 66 | if (avr == NULL) |
90 | return -1; | 67 | return -ENOBUFS; |
91 | |||
92 | DCCP_SKB_CB(skb)->dccpd_opt_len += len; | ||
93 | |||
94 | to = skb_push(skb, len); | ||
95 | len = av->av_vec_len; | ||
96 | from = av->av_buf + av->av_buf_head; | ||
97 | tail = av->av_buf + DCCP_MAX_ACKVEC_LEN; | ||
98 | |||
99 | for (i = 0; i < nr_opts; ++i) { | ||
100 | int copylen = len; | ||
101 | |||
102 | if (len > DCCP_SINGLE_OPT_MAXLEN) | ||
103 | copylen = DCCP_SINGLE_OPT_MAXLEN; | ||
104 | |||
105 | *to++ = DCCPO_ACK_VECTOR_0; | ||
106 | *to++ = copylen + 2; | ||
107 | |||
108 | /* Check if buf_head wraps */ | ||
109 | if (from + copylen > tail) { | ||
110 | const u16 tailsize = tail - from; | ||
111 | |||
112 | memcpy(to, from, tailsize); | ||
113 | to += tailsize; | ||
114 | len -= tailsize; | ||
115 | copylen -= tailsize; | ||
116 | from = av->av_buf; | ||
117 | } | ||
118 | |||
119 | memcpy(to, from, copylen); | ||
120 | from += copylen; | ||
121 | to += copylen; | ||
122 | len -= copylen; | ||
123 | } | ||
124 | 68 | ||
69 | avr->avr_ack_seqno = seqno; | ||
70 | avr->avr_ack_ptr = av->av_buf_head; | ||
71 | avr->avr_ack_ackno = av->av_buf_ackno; | ||
72 | avr->avr_ack_nonce = nonce_sum; | ||
73 | avr->avr_ack_runlen = dccp_ackvec_runlen(av->av_buf + av->av_buf_head); | ||
125 | /* | 74 | /* |
126 | * From RFC 4340, A.2: | 75 | * When the buffer overflows, we keep no more than one record. This is |
127 | * | 76 | * the simplest way of disambiguating sender-Acks dating from before the |
128 | * For each acknowledgement it sends, the HC-Receiver will add an | 77 | * overflow from sender-Acks which refer to after the overflow; a simple |
129 | * acknowledgement record. ack_seqno will equal the HC-Receiver | 78 | * solution is preferable here since we are handling an exception. |
130 | * sequence number it used for the ack packet; ack_ptr will equal | ||
131 | * buf_head; ack_ackno will equal buf_ackno; and ack_nonce will | ||
132 | * equal buf_nonce. | ||
133 | */ | 79 | */ |
134 | avr->avr_ack_seqno = DCCP_SKB_CB(skb)->dccpd_seq; | 80 | if (av->av_overflow) |
135 | avr->avr_ack_ptr = av->av_buf_head; | 81 | dccp_ackvec_purge_records(av); |
136 | avr->avr_ack_ackno = av->av_buf_ackno; | 82 | /* |
137 | avr->avr_ack_nonce = av->av_buf_nonce; | 83 | * Since GSS is incremented for each packet, the list is automatically |
138 | avr->avr_sent_len = av->av_vec_len; | 84 | * arranged in descending order of @ack_seqno. |
139 | 85 | */ | |
140 | dccp_ackvec_insert_avr(av, avr); | 86 | list_add(&avr->avr_node, &av->av_records); |
141 | 87 | ||
142 | dccp_pr_debug("%s ACK Vector 0, len=%d, ack_seqno=%llu, " | 88 | dccp_pr_debug("Added Vector, ack_seqno=%llu, ack_ackno=%llu (rl=%u)\n", |
143 | "ack_ackno=%llu\n", | ||
144 | dccp_role(sk), avr->avr_sent_len, | ||
145 | (unsigned long long)avr->avr_ack_seqno, | 89 | (unsigned long long)avr->avr_ack_seqno, |
146 | (unsigned long long)avr->avr_ack_ackno); | 90 | (unsigned long long)avr->avr_ack_ackno, |
91 | avr->avr_ack_runlen); | ||
147 | return 0; | 92 | return 0; |
148 | } | 93 | } |
149 | 94 | ||
150 | struct dccp_ackvec *dccp_ackvec_alloc(const gfp_t priority) | 95 | /* |
151 | { | 96 | * Buffer index and length computation using modulo-buffersize arithmetic. |
152 | struct dccp_ackvec *av = kmem_cache_alloc(dccp_ackvec_slab, priority); | 97 | * Note that, as pointers move from right to left, head is `before' tail. |
153 | 98 | */ | |
154 | if (av != NULL) { | 99 | static inline u16 __ackvec_idx_add(const u16 a, const u16 b) |
155 | av->av_buf_head = DCCP_MAX_ACKVEC_LEN - 1; | ||
156 | av->av_buf_ackno = UINT48_MAX + 1; | ||
157 | av->av_buf_nonce = 0; | ||
158 | av->av_time = ktime_set(0, 0); | ||
159 | av->av_vec_len = 0; | ||
160 | INIT_LIST_HEAD(&av->av_records); | ||
161 | } | ||
162 | |||
163 | return av; | ||
164 | } | ||
165 | |||
166 | void dccp_ackvec_free(struct dccp_ackvec *av) | ||
167 | { | 100 | { |
168 | if (unlikely(av == NULL)) | 101 | return (a + b) % DCCPAV_MAX_ACKVEC_LEN; |
169 | return; | ||
170 | |||
171 | if (!list_empty(&av->av_records)) { | ||
172 | struct dccp_ackvec_record *avr, *next; | ||
173 | |||
174 | list_for_each_entry_safe(avr, next, &av->av_records, avr_node) { | ||
175 | list_del_init(&avr->avr_node); | ||
176 | dccp_ackvec_record_delete(avr); | ||
177 | } | ||
178 | } | ||
179 | |||
180 | kmem_cache_free(dccp_ackvec_slab, av); | ||
181 | } | 102 | } |
182 | 103 | ||
183 | static inline u8 dccp_ackvec_state(const struct dccp_ackvec *av, | 104 | static inline u16 __ackvec_idx_sub(const u16 a, const u16 b) |
184 | const u32 index) | ||
185 | { | 105 | { |
186 | return av->av_buf[index] & DCCP_ACKVEC_STATE_MASK; | 106 | return __ackvec_idx_add(a, DCCPAV_MAX_ACKVEC_LEN - b); |
187 | } | 107 | } |
188 | 108 | ||
189 | static inline u8 dccp_ackvec_len(const struct dccp_ackvec *av, | 109 | u16 dccp_ackvec_buflen(const struct dccp_ackvec *av) |
190 | const u32 index) | ||
191 | { | 110 | { |
192 | return av->av_buf[index] & DCCP_ACKVEC_LEN_MASK; | 111 | if (unlikely(av->av_overflow)) |
112 | return DCCPAV_MAX_ACKVEC_LEN; | ||
113 | return __ackvec_idx_sub(av->av_buf_tail, av->av_buf_head); | ||
193 | } | 114 | } |
194 | 115 | ||
195 | /* | 116 | /* |
@@ -204,7 +125,7 @@ static inline int dccp_ackvec_set_buf_head_state(struct dccp_ackvec *av, | |||
204 | long gap; | 125 | long gap; |
205 | long new_head; | 126 | long new_head; |
206 | 127 | ||
207 | if (av->av_vec_len + packets > DCCP_MAX_ACKVEC_LEN) | 128 | if (av->av_vec_len + packets > DCCPAV_MAX_ACKVEC_LEN) |
208 | return -ENOBUFS; | 129 | return -ENOBUFS; |
209 | 130 | ||
210 | gap = packets - 1; | 131 | gap = packets - 1; |
@@ -212,18 +133,18 @@ static inline int dccp_ackvec_set_buf_head_state(struct dccp_ackvec *av, | |||
212 | 133 | ||
213 | if (new_head < 0) { | 134 | if (new_head < 0) { |
214 | if (gap > 0) { | 135 | if (gap > 0) { |
215 | memset(av->av_buf, DCCP_ACKVEC_STATE_NOT_RECEIVED, | 136 | memset(av->av_buf, DCCPAV_NOT_RECEIVED, |
216 | gap + new_head + 1); | 137 | gap + new_head + 1); |
217 | gap = -new_head; | 138 | gap = -new_head; |
218 | } | 139 | } |
219 | new_head += DCCP_MAX_ACKVEC_LEN; | 140 | new_head += DCCPAV_MAX_ACKVEC_LEN; |
220 | } | 141 | } |
221 | 142 | ||
222 | av->av_buf_head = new_head; | 143 | av->av_buf_head = new_head; |
223 | 144 | ||
224 | if (gap > 0) | 145 | if (gap > 0) |
225 | memset(av->av_buf + av->av_buf_head + 1, | 146 | memset(av->av_buf + av->av_buf_head + 1, |
226 | DCCP_ACKVEC_STATE_NOT_RECEIVED, gap); | 147 | DCCPAV_NOT_RECEIVED, gap); |
227 | 148 | ||
228 | av->av_buf[av->av_buf_head] = state; | 149 | av->av_buf[av->av_buf_head] = state; |
229 | av->av_vec_len += packets; | 150 | av->av_vec_len += packets; |
@@ -236,6 +157,8 @@ static inline int dccp_ackvec_set_buf_head_state(struct dccp_ackvec *av, | |||
236 | int dccp_ackvec_add(struct dccp_ackvec *av, const struct sock *sk, | 157 | int dccp_ackvec_add(struct dccp_ackvec *av, const struct sock *sk, |
237 | const u64 ackno, const u8 state) | 158 | const u64 ackno, const u8 state) |
238 | { | 159 | { |
160 | u8 *cur_head = av->av_buf + av->av_buf_head, | ||
161 | *buf_end = av->av_buf + DCCPAV_MAX_ACKVEC_LEN; | ||
239 | /* | 162 | /* |
240 | * Check at the right places if the buffer is full, if it is, tell the | 163 | * Check at the right places if the buffer is full, if it is, tell the |
241 | * caller to start dropping packets till the HC-Sender acks our ACK | 164 | * caller to start dropping packets till the HC-Sender acks our ACK |
@@ -260,7 +183,7 @@ int dccp_ackvec_add(struct dccp_ackvec *av, const struct sock *sk, | |||
260 | 183 | ||
261 | /* See if this is the first ackno being inserted */ | 184 | /* See if this is the first ackno being inserted */ |
262 | if (av->av_vec_len == 0) { | 185 | if (av->av_vec_len == 0) { |
263 | av->av_buf[av->av_buf_head] = state; | 186 | *cur_head = state; |
264 | av->av_vec_len = 1; | 187 | av->av_vec_len = 1; |
265 | } else if (after48(ackno, av->av_buf_ackno)) { | 188 | } else if (after48(ackno, av->av_buf_ackno)) { |
266 | const u64 delta = dccp_delta_seqno(av->av_buf_ackno, ackno); | 189 | const u64 delta = dccp_delta_seqno(av->av_buf_ackno, ackno); |
@@ -269,10 +192,9 @@ int dccp_ackvec_add(struct dccp_ackvec *av, const struct sock *sk, | |||
269 | * Look if the state of this packet is the same as the | 192 | * Look if the state of this packet is the same as the |
270 | * previous ackno and if so if we can bump the head len. | 193 | * previous ackno and if so if we can bump the head len. |
271 | */ | 194 | */ |
272 | if (delta == 1 && | 195 | if (delta == 1 && dccp_ackvec_state(cur_head) == state && |
273 | dccp_ackvec_state(av, av->av_buf_head) == state && | 196 | dccp_ackvec_runlen(cur_head) < DCCPAV_MAX_RUNLEN) |
274 | dccp_ackvec_len(av, av->av_buf_head) < DCCP_ACKVEC_LEN_MASK) | 197 | *cur_head += 1; |
275 | av->av_buf[av->av_buf_head]++; | ||
276 | else if (dccp_ackvec_set_buf_head_state(av, delta, state)) | 198 | else if (dccp_ackvec_set_buf_head_state(av, delta, state)) |
277 | return -ENOBUFS; | 199 | return -ENOBUFS; |
278 | } else { | 200 | } else { |
@@ -285,21 +207,17 @@ int dccp_ackvec_add(struct dccp_ackvec *av, const struct sock *sk, | |||
285 | * could reduce the complexity of this scan.) | 207 | * could reduce the complexity of this scan.) |
286 | */ | 208 | */ |
287 | u64 delta = dccp_delta_seqno(ackno, av->av_buf_ackno); | 209 | u64 delta = dccp_delta_seqno(ackno, av->av_buf_ackno); |
288 | u32 index = av->av_buf_head; | ||
289 | 210 | ||
290 | while (1) { | 211 | while (1) { |
291 | const u8 len = dccp_ackvec_len(av, index); | 212 | const u8 len = dccp_ackvec_runlen(cur_head); |
292 | const u8 av_state = dccp_ackvec_state(av, index); | ||
293 | /* | 213 | /* |
294 | * valid packets not yet in av_buf have a reserved | 214 | * valid packets not yet in av_buf have a reserved |
295 | * entry, with a len equal to 0. | 215 | * entry, with a len equal to 0. |
296 | */ | 216 | */ |
297 | if (av_state == DCCP_ACKVEC_STATE_NOT_RECEIVED && | 217 | if (*cur_head == DCCPAV_NOT_RECEIVED && delta == 0) { |
298 | len == 0 && delta == 0) { /* Found our | ||
299 | reserved seat! */ | ||
300 | dccp_pr_debug("Found %llu reserved seat!\n", | 218 | dccp_pr_debug("Found %llu reserved seat!\n", |
301 | (unsigned long long)ackno); | 219 | (unsigned long long)ackno); |
302 | av->av_buf[index] = state; | 220 | *cur_head = state; |
303 | goto out; | 221 | goto out; |
304 | } | 222 | } |
305 | /* len == 0 means one packet */ | 223 | /* len == 0 means one packet */ |
@@ -307,13 +225,12 @@ int dccp_ackvec_add(struct dccp_ackvec *av, const struct sock *sk, | |||
307 | goto out_duplicate; | 225 | goto out_duplicate; |
308 | 226 | ||
309 | delta -= len + 1; | 227 | delta -= len + 1; |
310 | if (++index == DCCP_MAX_ACKVEC_LEN) | 228 | if (++cur_head == buf_end) |
311 | index = 0; | 229 | cur_head = av->av_buf; |
312 | } | 230 | } |
313 | } | 231 | } |
314 | 232 | ||
315 | av->av_buf_ackno = ackno; | 233 | av->av_buf_ackno = ackno; |
316 | av->av_time = ktime_get_real(); | ||
317 | out: | 234 | out: |
318 | return 0; | 235 | return 0; |
319 | 236 | ||
@@ -333,13 +250,13 @@ static void dccp_ackvec_throw_record(struct dccp_ackvec *av, | |||
333 | if (av->av_buf_head <= avr->avr_ack_ptr) | 250 | if (av->av_buf_head <= avr->avr_ack_ptr) |
334 | av->av_vec_len = avr->avr_ack_ptr - av->av_buf_head; | 251 | av->av_vec_len = avr->avr_ack_ptr - av->av_buf_head; |
335 | else | 252 | else |
336 | av->av_vec_len = DCCP_MAX_ACKVEC_LEN - 1 - | 253 | av->av_vec_len = DCCPAV_MAX_ACKVEC_LEN - 1 - |
337 | av->av_buf_head + avr->avr_ack_ptr; | 254 | av->av_buf_head + avr->avr_ack_ptr; |
338 | 255 | ||
339 | /* free records */ | 256 | /* free records */ |
340 | list_for_each_entry_safe_from(avr, next, &av->av_records, avr_node) { | 257 | list_for_each_entry_safe_from(avr, next, &av->av_records, avr_node) { |
341 | list_del_init(&avr->avr_node); | 258 | list_del(&avr->avr_node); |
342 | dccp_ackvec_record_delete(avr); | 259 | kmem_cache_free(dccp_ackvec_record_slab, avr); |
343 | } | 260 | } |
344 | } | 261 | } |
345 | 262 | ||
@@ -357,7 +274,7 @@ void dccp_ackvec_check_rcv_ackno(struct dccp_ackvec *av, struct sock *sk, | |||
357 | if (ackno == avr->avr_ack_seqno) { | 274 | if (ackno == avr->avr_ack_seqno) { |
358 | dccp_pr_debug("%s ACK packet 0, len=%d, ack_seqno=%llu, " | 275 | dccp_pr_debug("%s ACK packet 0, len=%d, ack_seqno=%llu, " |
359 | "ack_ackno=%llu, ACKED!\n", | 276 | "ack_ackno=%llu, ACKED!\n", |
360 | dccp_role(sk), 1, | 277 | dccp_role(sk), avr->avr_ack_runlen, |
361 | (unsigned long long)avr->avr_ack_seqno, | 278 | (unsigned long long)avr->avr_ack_seqno, |
362 | (unsigned long long)avr->avr_ack_ackno); | 279 | (unsigned long long)avr->avr_ack_ackno); |
363 | dccp_ackvec_throw_record(av, avr); | 280 | dccp_ackvec_throw_record(av, avr); |
@@ -387,7 +304,7 @@ static void dccp_ackvec_check_rcv_ackvector(struct dccp_ackvec *av, | |||
387 | */ | 304 | */ |
388 | avr = list_entry(av->av_records.next, struct dccp_ackvec_record, avr_node); | 305 | avr = list_entry(av->av_records.next, struct dccp_ackvec_record, avr_node); |
389 | while (i--) { | 306 | while (i--) { |
390 | const u8 rl = *vector & DCCP_ACKVEC_LEN_MASK; | 307 | const u8 rl = dccp_ackvec_runlen(vector); |
391 | u64 ackno_end_rl; | 308 | u64 ackno_end_rl; |
392 | 309 | ||
393 | dccp_set_seqno(&ackno_end_rl, *ackno - rl); | 310 | dccp_set_seqno(&ackno_end_rl, *ackno - rl); |
@@ -404,8 +321,7 @@ static void dccp_ackvec_check_rcv_ackvector(struct dccp_ackvec *av, | |||
404 | break; | 321 | break; |
405 | found: | 322 | found: |
406 | if (between48(avr->avr_ack_seqno, ackno_end_rl, *ackno)) { | 323 | if (between48(avr->avr_ack_seqno, ackno_end_rl, *ackno)) { |
407 | const u8 state = *vector & DCCP_ACKVEC_STATE_MASK; | 324 | if (dccp_ackvec_state(vector) != DCCPAV_NOT_RECEIVED) { |
408 | if (state != DCCP_ACKVEC_STATE_NOT_RECEIVED) { | ||
409 | dccp_pr_debug("%s ACK vector 0, len=%d, " | 325 | dccp_pr_debug("%s ACK vector 0, len=%d, " |
410 | "ack_seqno=%llu, ack_ackno=%llu, " | 326 | "ack_seqno=%llu, ack_ackno=%llu, " |
411 | "ACKED!\n", | 327 | "ACKED!\n", |
@@ -448,10 +364,9 @@ int __init dccp_ackvec_init(void) | |||
448 | if (dccp_ackvec_slab == NULL) | 364 | if (dccp_ackvec_slab == NULL) |
449 | goto out_err; | 365 | goto out_err; |
450 | 366 | ||
451 | dccp_ackvec_record_slab = | 367 | dccp_ackvec_record_slab = kmem_cache_create("dccp_ackvec_record", |
452 | kmem_cache_create("dccp_ackvec_record", | 368 | sizeof(struct dccp_ackvec_record), |
453 | sizeof(struct dccp_ackvec_record), | 369 | 0, SLAB_HWCACHE_ALIGN, NULL); |
454 | 0, SLAB_HWCACHE_ALIGN, NULL); | ||
455 | if (dccp_ackvec_record_slab == NULL) | 370 | if (dccp_ackvec_record_slab == NULL) |
456 | goto out_destroy_slab; | 371 | goto out_destroy_slab; |
457 | 372 | ||
diff --git a/net/dccp/ackvec.h b/net/dccp/ackvec.h index 7ea557b7c6b1..23880be8fc29 100644 --- a/net/dccp/ackvec.h +++ b/net/dccp/ackvec.h | |||
@@ -3,9 +3,9 @@ | |||
3 | /* | 3 | /* |
4 | * net/dccp/ackvec.h | 4 | * net/dccp/ackvec.h |
5 | * | 5 | * |
6 | * An implementation of the DCCP protocol | 6 | * An implementation of Ack Vectors for the DCCP protocol |
7 | * Copyright (c) 2007 University of Aberdeen, Scotland, UK | ||
7 | * Copyright (c) 2005 Arnaldo Carvalho de Melo <acme@mandriva.com> | 8 | * 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 | 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 | 10 | * under the terms of the GNU General Public License version 2 as |
11 | * published by the Free Software Foundation. | 11 | * published by the Free Software Foundation. |
@@ -13,75 +13,89 @@ | |||
13 | 13 | ||
14 | #include <linux/dccp.h> | 14 | #include <linux/dccp.h> |
15 | #include <linux/compiler.h> | 15 | #include <linux/compiler.h> |
16 | #include <linux/ktime.h> | ||
17 | #include <linux/list.h> | 16 | #include <linux/list.h> |
18 | #include <linux/types.h> | 17 | #include <linux/types.h> |
19 | 18 | ||
20 | /* We can spread an ack vector across multiple options */ | 19 | /* |
21 | #define DCCP_MAX_ACKVEC_LEN (DCCP_SINGLE_OPT_MAXLEN * 2) | 20 | * Ack Vector buffer space is static, in multiples of %DCCP_SINGLE_OPT_MAXLEN, |
21 | * the maximum size of a single Ack Vector. Setting %DCCPAV_NUM_ACKVECS to 1 | ||
22 | * will be sufficient for most cases of low Ack Ratios, using a value of 2 gives | ||
23 | * more headroom if Ack Ratio is higher or when the sender acknowledges slowly. | ||
24 | * The maximum value is bounded by the u16 types for indices and functions. | ||
25 | */ | ||
26 | #define DCCPAV_NUM_ACKVECS 2 | ||
27 | #define DCCPAV_MAX_ACKVEC_LEN (DCCP_SINGLE_OPT_MAXLEN * DCCPAV_NUM_ACKVECS) | ||
22 | 28 | ||
23 | /* Estimated minimum average Ack Vector length - used for updating MPS */ | 29 | /* Estimated minimum average Ack Vector length - used for updating MPS */ |
24 | #define DCCPAV_MIN_OPTLEN 16 | 30 | #define DCCPAV_MIN_OPTLEN 16 |
25 | 31 | ||
26 | #define DCCP_ACKVEC_STATE_RECEIVED 0 | 32 | enum dccp_ackvec_states { |
27 | #define DCCP_ACKVEC_STATE_ECN_MARKED (1 << 6) | 33 | DCCPAV_RECEIVED = 0x00, |
28 | #define DCCP_ACKVEC_STATE_NOT_RECEIVED (3 << 6) | 34 | DCCPAV_ECN_MARKED = 0x40, |
35 | DCCPAV_RESERVED = 0x80, | ||
36 | DCCPAV_NOT_RECEIVED = 0xC0 | ||
37 | }; | ||
38 | #define DCCPAV_MAX_RUNLEN 0x3F | ||
29 | 39 | ||
30 | #define DCCP_ACKVEC_STATE_MASK 0xC0 /* 11000000 */ | 40 | static inline u8 dccp_ackvec_runlen(const u8 *cell) |
31 | #define DCCP_ACKVEC_LEN_MASK 0x3F /* 00111111 */ | 41 | { |
42 | return *cell & DCCPAV_MAX_RUNLEN; | ||
43 | } | ||
32 | 44 | ||
33 | /** struct dccp_ackvec - ack vector | 45 | static inline u8 dccp_ackvec_state(const u8 *cell) |
34 | * | 46 | { |
35 | * This data structure is the one defined in RFC 4340, Appendix A. | 47 | return *cell & ~DCCPAV_MAX_RUNLEN; |
36 | * | 48 | } |
37 | * @av_buf_head - circular buffer head | 49 | |
38 | * @av_buf_tail - circular buffer tail | 50 | /** struct dccp_ackvec - Ack Vector main data structure |
39 | * @av_buf_ackno - ack # of the most recent packet acknowledgeable in the | ||
40 | * buffer (i.e. %av_buf_head) | ||
41 | * @av_buf_nonce - the one-bit sum of the ECN Nonces on all packets acked | ||
42 | * by the buffer with State 0 | ||
43 | * | ||
44 | * Additionally, the HC-Receiver must keep some information about the | ||
45 | * Ack Vectors it has recently sent. For each packet sent carrying an | ||
46 | * Ack Vector, it remembers four variables: | ||
47 | * | 51 | * |
48 | * @av_records - list of dccp_ackvec_record | 52 | * This implements a fixed-size circular buffer within an array and is largely |
49 | * @av_ack_nonce - the one-bit sum of the ECN Nonces for all State 0. | 53 | * based on Appendix A of RFC 4340. |
50 | * | 54 | * |
51 | * @av_time - the time in usecs | 55 | * @av_buf: circular buffer storage area |
52 | * @av_buf - circular buffer of acknowledgeable packets | 56 | * @av_buf_head: head index; begin of live portion in @av_buf |
57 | * @av_buf_tail: tail index; first index _after_ the live portion in @av_buf | ||
58 | * @av_buf_ackno: highest seqno of acknowledgeable packet recorded in @av_buf | ||
59 | * @av_tail_ackno: lowest seqno of acknowledgeable packet recorded in @av_buf | ||
60 | * @av_buf_nonce: ECN nonce sums, each covering subsequent segments of up to | ||
61 | * %DCCP_SINGLE_OPT_MAXLEN cells in the live portion of @av_buf | ||
62 | * @av_overflow: if 1 then buf_head == buf_tail indicates buffer wraparound | ||
63 | * @av_records: list of %dccp_ackvec_record (Ack Vectors sent previously) | ||
64 | * @av_veclen: length of the live portion of @av_buf | ||
53 | */ | 65 | */ |
54 | struct dccp_ackvec { | 66 | struct dccp_ackvec { |
55 | u64 av_buf_ackno; | 67 | u8 av_buf[DCCPAV_MAX_ACKVEC_LEN]; |
56 | struct list_head av_records; | ||
57 | ktime_t av_time; | ||
58 | u16 av_buf_head; | 68 | u16 av_buf_head; |
69 | u16 av_buf_tail; | ||
70 | u64 av_buf_ackno:48; | ||
71 | u64 av_tail_ackno:48; | ||
72 | bool av_buf_nonce[DCCPAV_NUM_ACKVECS]; | ||
73 | u8 av_overflow:1; | ||
74 | struct list_head av_records; | ||
59 | u16 av_vec_len; | 75 | u16 av_vec_len; |
60 | u8 av_buf_nonce; | ||
61 | u8 av_ack_nonce; | ||
62 | u8 av_buf[DCCP_MAX_ACKVEC_LEN]; | ||
63 | }; | 76 | }; |
64 | 77 | ||
65 | /** struct dccp_ackvec_record - ack vector record | 78 | /** struct dccp_ackvec_record - Records information about sent Ack Vectors |
66 | * | 79 | * |
67 | * ACK vector record as defined in Appendix A of spec. | 80 | * These list entries define the additional information which the HC-Receiver |
81 | * keeps about recently-sent Ack Vectors; again refer to RFC 4340, Appendix A. | ||
68 | * | 82 | * |
69 | * The list is sorted by avr_ack_seqno | 83 | * @avr_node: the list node in @av_records |
84 | * @avr_ack_seqno: sequence number of the packet the Ack Vector was sent on | ||
85 | * @avr_ack_ackno: the Ack number that this record/Ack Vector refers to | ||
86 | * @avr_ack_ptr: pointer into @av_buf where this record starts | ||
87 | * @avr_ack_runlen: run length of @avr_ack_ptr at the time of sending | ||
88 | * @avr_ack_nonce: the sum of @av_buf_nonce's at the time this record was sent | ||
70 | * | 89 | * |
71 | * @avr_node - node in av_records | 90 | * The list as a whole is sorted in descending order by @avr_ack_seqno. |
72 | * @avr_ack_seqno - sequence number of the packet this record was sent on | ||
73 | * @avr_ack_ackno - sequence number being acknowledged | ||
74 | * @avr_ack_ptr - pointer into av_buf where this record starts | ||
75 | * @avr_ack_nonce - av_ack_nonce at the time this record was sent | ||
76 | * @avr_sent_len - lenght of the record in av_buf | ||
77 | */ | 91 | */ |
78 | struct dccp_ackvec_record { | 92 | struct dccp_ackvec_record { |
79 | struct list_head avr_node; | 93 | struct list_head avr_node; |
80 | u64 avr_ack_seqno; | 94 | u64 avr_ack_seqno:48; |
81 | u64 avr_ack_ackno; | 95 | u64 avr_ack_ackno:48; |
82 | u16 avr_ack_ptr; | 96 | u16 avr_ack_ptr; |
83 | u16 avr_sent_len; | 97 | u8 avr_ack_runlen; |
84 | u8 avr_ack_nonce; | 98 | u8 avr_ack_nonce:1; |
85 | }; | 99 | }; |
86 | 100 | ||
87 | struct sock; | 101 | struct sock; |
@@ -102,10 +116,11 @@ extern int dccp_ackvec_parse(struct sock *sk, const struct sk_buff *skb, | |||
102 | u64 *ackno, const u8 opt, | 116 | u64 *ackno, const u8 opt, |
103 | const u8 *value, const u8 len); | 117 | const u8 *value, const u8 len); |
104 | 118 | ||
105 | extern int dccp_insert_option_ackvec(struct sock *sk, struct sk_buff *skb); | 119 | extern int dccp_ackvec_update_records(struct dccp_ackvec *av, u64 seq, u8 sum); |
120 | extern u16 dccp_ackvec_buflen(const struct dccp_ackvec *av); | ||
106 | 121 | ||
107 | static inline int dccp_ackvec_pending(const struct dccp_ackvec *av) | 122 | static inline bool dccp_ackvec_is_empty(const struct dccp_ackvec *av) |
108 | { | 123 | { |
109 | return av->av_vec_len; | 124 | return av->av_overflow == 0 && av->av_buf_head == av->av_buf_tail; |
110 | } | 125 | } |
111 | #endif /* _ACKVEC_H */ | 126 | #endif /* _ACKVEC_H */ |
diff --git a/net/dccp/ccids/ccid2.c b/net/dccp/ccids/ccid2.c index 6576eae9e779..cb1b4a0d1877 100644 --- a/net/dccp/ccids/ccid2.c +++ b/net/dccp/ccids/ccid2.c | |||
@@ -513,8 +513,7 @@ static void ccid2_hc_tx_packet_recv(struct sock *sk, struct sk_buff *skb) | |||
513 | &vector, &veclen)) != -1) { | 513 | &vector, &veclen)) != -1) { |
514 | /* go through this ack vector */ | 514 | /* go through this ack vector */ |
515 | while (veclen--) { | 515 | while (veclen--) { |
516 | const u8 rl = *vector & DCCP_ACKVEC_LEN_MASK; | 516 | u64 ackno_end_rl = SUB48(ackno, dccp_ackvec_runlen(vector)); |
517 | u64 ackno_end_rl = SUB48(ackno, rl); | ||
518 | 517 | ||
519 | ccid2_pr_debug("ackvec start:%llu end:%llu\n", | 518 | ccid2_pr_debug("ackvec start:%llu end:%llu\n", |
520 | (unsigned long long)ackno, | 519 | (unsigned long long)ackno, |
@@ -537,17 +536,15 @@ static void ccid2_hc_tx_packet_recv(struct sock *sk, struct sk_buff *skb) | |||
537 | * run length | 536 | * run length |
538 | */ | 537 | */ |
539 | while (between48(seqp->ccid2s_seq,ackno_end_rl,ackno)) { | 538 | while (between48(seqp->ccid2s_seq,ackno_end_rl,ackno)) { |
540 | const u8 state = *vector & | 539 | const u8 state = dccp_ackvec_state(vector); |
541 | DCCP_ACKVEC_STATE_MASK; | ||
542 | 540 | ||
543 | /* new packet received or marked */ | 541 | /* new packet received or marked */ |
544 | if (state != DCCP_ACKVEC_STATE_NOT_RECEIVED && | 542 | if (state != DCCPAV_NOT_RECEIVED && |
545 | !seqp->ccid2s_acked) { | 543 | !seqp->ccid2s_acked) { |
546 | if (state == | 544 | if (state == DCCPAV_ECN_MARKED) |
547 | DCCP_ACKVEC_STATE_ECN_MARKED) { | ||
548 | ccid2_congestion_event(sk, | 545 | ccid2_congestion_event(sk, |
549 | seqp); | 546 | seqp); |
550 | } else | 547 | else |
551 | ccid2_new_ack(sk, seqp, | 548 | ccid2_new_ack(sk, seqp, |
552 | &maxincr); | 549 | &maxincr); |
553 | 550 | ||
diff --git a/net/dccp/dccp.h b/net/dccp/dccp.h index a8ed459508b2..19fafd597465 100644 --- a/net/dccp/dccp.h +++ b/net/dccp/dccp.h | |||
@@ -457,12 +457,15 @@ static inline void dccp_update_gss(struct sock *sk, u64 seq) | |||
457 | dp->dccps_awh = dp->dccps_gss; | 457 | dp->dccps_awh = dp->dccps_gss; |
458 | } | 458 | } |
459 | 459 | ||
460 | static inline int dccp_ackvec_pending(const struct sock *sk) | ||
461 | { | ||
462 | return dccp_sk(sk)->dccps_hc_rx_ackvec != NULL && | ||
463 | !dccp_ackvec_is_empty(dccp_sk(sk)->dccps_hc_rx_ackvec); | ||
464 | } | ||
465 | |||
460 | static inline int dccp_ack_pending(const struct sock *sk) | 466 | static inline int dccp_ack_pending(const struct sock *sk) |
461 | { | 467 | { |
462 | const struct dccp_sock *dp = dccp_sk(sk); | 468 | return dccp_ackvec_pending(sk) || inet_csk_ack_scheduled(sk); |
463 | return (dp->dccps_hc_rx_ackvec != NULL && | ||
464 | dccp_ackvec_pending(dp->dccps_hc_rx_ackvec)) || | ||
465 | inet_csk_ack_scheduled(sk); | ||
466 | } | 469 | } |
467 | 470 | ||
468 | extern int dccp_feat_finalise_settings(struct dccp_sock *dp); | 471 | extern int dccp_feat_finalise_settings(struct dccp_sock *dp); |
diff --git a/net/dccp/input.c b/net/dccp/input.c index 265985370fa1..c7aeeba859d4 100644 --- a/net/dccp/input.c +++ b/net/dccp/input.c | |||
@@ -378,8 +378,7 @@ int dccp_rcv_established(struct sock *sk, struct sk_buff *skb, | |||
378 | 378 | ||
379 | if (dp->dccps_hc_rx_ackvec != NULL && | 379 | if (dp->dccps_hc_rx_ackvec != NULL && |
380 | dccp_ackvec_add(dp->dccps_hc_rx_ackvec, sk, | 380 | dccp_ackvec_add(dp->dccps_hc_rx_ackvec, sk, |
381 | DCCP_SKB_CB(skb)->dccpd_seq, | 381 | DCCP_SKB_CB(skb)->dccpd_seq, DCCPAV_RECEIVED)) |
382 | DCCP_ACKVEC_STATE_RECEIVED)) | ||
383 | goto discard; | 382 | goto discard; |
384 | dccp_deliver_input_to_ccids(sk, skb); | 383 | dccp_deliver_input_to_ccids(sk, skb); |
385 | 384 | ||
@@ -637,8 +636,7 @@ int dccp_rcv_state_process(struct sock *sk, struct sk_buff *skb, | |||
637 | 636 | ||
638 | if (dp->dccps_hc_rx_ackvec != NULL && | 637 | if (dp->dccps_hc_rx_ackvec != NULL && |
639 | dccp_ackvec_add(dp->dccps_hc_rx_ackvec, sk, | 638 | dccp_ackvec_add(dp->dccps_hc_rx_ackvec, sk, |
640 | DCCP_SKB_CB(skb)->dccpd_seq, | 639 | DCCP_SKB_CB(skb)->dccpd_seq, DCCPAV_RECEIVED)) |
641 | DCCP_ACKVEC_STATE_RECEIVED)) | ||
642 | goto discard; | 640 | goto discard; |
643 | 641 | ||
644 | dccp_deliver_input_to_ccids(sk, skb); | 642 | dccp_deliver_input_to_ccids(sk, skb); |
diff --git a/net/dccp/options.c b/net/dccp/options.c index cd3061813009..5adeeed5e0d2 100644 --- a/net/dccp/options.c +++ b/net/dccp/options.c | |||
@@ -340,6 +340,7 @@ static inline int dccp_elapsed_time_len(const u32 elapsed_time) | |||
340 | return elapsed_time == 0 ? 0 : elapsed_time <= 0xFFFF ? 2 : 4; | 340 | return elapsed_time == 0 ? 0 : elapsed_time <= 0xFFFF ? 2 : 4; |
341 | } | 341 | } |
342 | 342 | ||
343 | /* FIXME: This function is currently not used anywhere */ | ||
343 | int dccp_insert_option_elapsed_time(struct sk_buff *skb, u32 elapsed_time) | 344 | int dccp_insert_option_elapsed_time(struct sk_buff *skb, u32 elapsed_time) |
344 | { | 345 | { |
345 | const int elapsed_time_len = dccp_elapsed_time_len(elapsed_time); | 346 | const int elapsed_time_len = dccp_elapsed_time_len(elapsed_time); |
@@ -424,6 +425,67 @@ static int dccp_insert_option_timestamp_echo(struct dccp_sock *dp, | |||
424 | return 0; | 425 | return 0; |
425 | } | 426 | } |
426 | 427 | ||
428 | static int dccp_insert_option_ackvec(struct sock *sk, struct sk_buff *skb) | ||
429 | { | ||
430 | struct dccp_sock *dp = dccp_sk(sk); | ||
431 | struct dccp_ackvec *av = dp->dccps_hc_rx_ackvec; | ||
432 | const u16 buflen = dccp_ackvec_buflen(av); | ||
433 | /* Figure out how many options do we need to represent the ackvec */ | ||
434 | const u8 nr_opts = DIV_ROUND_UP(buflen, DCCP_SINGLE_OPT_MAXLEN); | ||
435 | u16 len = buflen + 2 * nr_opts; | ||
436 | u8 i, nonce = 0; | ||
437 | const unsigned char *tail, *from; | ||
438 | unsigned char *to; | ||
439 | |||
440 | if (DCCP_SKB_CB(skb)->dccpd_opt_len + len > DCCP_MAX_OPT_LEN) | ||
441 | return -1; | ||
442 | |||
443 | DCCP_SKB_CB(skb)->dccpd_opt_len += len; | ||
444 | |||
445 | to = skb_push(skb, len); | ||
446 | len = buflen; | ||
447 | from = av->av_buf + av->av_buf_head; | ||
448 | tail = av->av_buf + DCCPAV_MAX_ACKVEC_LEN; | ||
449 | |||
450 | for (i = 0; i < nr_opts; ++i) { | ||
451 | int copylen = len; | ||
452 | |||
453 | if (len > DCCP_SINGLE_OPT_MAXLEN) | ||
454 | copylen = DCCP_SINGLE_OPT_MAXLEN; | ||
455 | |||
456 | /* | ||
457 | * RFC 4340, 12.2: Encode the Nonce Echo for this Ack Vector via | ||
458 | * its type; ack_nonce is the sum of all individual buf_nonce's. | ||
459 | */ | ||
460 | nonce ^= av->av_buf_nonce[i]; | ||
461 | |||
462 | *to++ = DCCPO_ACK_VECTOR_0 + av->av_buf_nonce[i]; | ||
463 | *to++ = copylen + 2; | ||
464 | |||
465 | /* Check if buf_head wraps */ | ||
466 | if (from + copylen > tail) { | ||
467 | const u16 tailsize = tail - from; | ||
468 | |||
469 | memcpy(to, from, tailsize); | ||
470 | to += tailsize; | ||
471 | len -= tailsize; | ||
472 | copylen -= tailsize; | ||
473 | from = av->av_buf; | ||
474 | } | ||
475 | |||
476 | memcpy(to, from, copylen); | ||
477 | from += copylen; | ||
478 | to += copylen; | ||
479 | len -= copylen; | ||
480 | } | ||
481 | /* | ||
482 | * Each sent Ack Vector is recorded in the list, as per A.2 of RFC 4340. | ||
483 | */ | ||
484 | if (dccp_ackvec_update_records(av, DCCP_SKB_CB(skb)->dccpd_seq, nonce)) | ||
485 | return -ENOBUFS; | ||
486 | return 0; | ||
487 | } | ||
488 | |||
427 | /** | 489 | /** |
428 | * dccp_insert_option_mandatory - Mandatory option (5.8.2) | 490 | * dccp_insert_option_mandatory - Mandatory option (5.8.2) |
429 | * Note that since we are using skb_push, this function needs to be called | 491 | * Note that since we are using skb_push, this function needs to be called |
@@ -519,8 +581,7 @@ int dccp_insert_options(struct sock *sk, struct sk_buff *skb) | |||
519 | if (dccp_insert_option_timestamp(skb)) | 581 | if (dccp_insert_option_timestamp(skb)) |
520 | return -1; | 582 | return -1; |
521 | 583 | ||
522 | } else if (dp->dccps_hc_rx_ackvec != NULL && | 584 | } else if (dccp_ackvec_pending(sk) && |
523 | dccp_ackvec_pending(dp->dccps_hc_rx_ackvec) && | ||
524 | dccp_insert_option_ackvec(sk, skb)) { | 585 | dccp_insert_option_ackvec(sk, skb)) { |
525 | return -1; | 586 | return -1; |
526 | } | 587 | } |