diff options
Diffstat (limited to 'net/dccp/ackvec.c')
-rw-r--r-- | net/dccp/ackvec.c | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/net/dccp/ackvec.c b/net/dccp/ackvec.c index 1184d5e5dc96..f1341a617f96 100644 --- a/net/dccp/ackvec.c +++ b/net/dccp/ackvec.c | |||
@@ -92,6 +92,24 @@ int dccp_ackvec_update_records(struct dccp_ackvec *av, u64 seqno, u8 nonce_sum) | |||
92 | return 0; | 92 | return 0; |
93 | } | 93 | } |
94 | 94 | ||
95 | static struct dccp_ackvec_record *dccp_ackvec_lookup(struct list_head *av_list, | ||
96 | const u64 ackno) | ||
97 | { | ||
98 | struct dccp_ackvec_record *avr; | ||
99 | /* | ||
100 | * Exploit that records are inserted in descending order of sequence | ||
101 | * number, start with the oldest record first. If @ackno is `before' | ||
102 | * the earliest ack_ackno, the packet is too old to be considered. | ||
103 | */ | ||
104 | list_for_each_entry_reverse(avr, av_list, avr_node) { | ||
105 | if (avr->avr_ack_seqno == ackno) | ||
106 | return avr; | ||
107 | if (before48(ackno, avr->avr_ack_seqno)) | ||
108 | break; | ||
109 | } | ||
110 | return NULL; | ||
111 | } | ||
112 | |||
95 | /* | 113 | /* |
96 | * Buffer index and length computation using modulo-buffersize arithmetic. | 114 | * Buffer index and length computation using modulo-buffersize arithmetic. |
97 | * Note that, as pointers move from right to left, head is `before' tail. | 115 | * Note that, as pointers move from right to left, head is `before' tail. |
@@ -356,6 +374,76 @@ int dccp_ackvec_parse(struct sock *sk, const struct sk_buff *skb, | |||
356 | return 0; | 374 | return 0; |
357 | } | 375 | } |
358 | 376 | ||
377 | /** | ||
378 | * dccp_ackvec_clear_state - Perform house-keeping / garbage-collection | ||
379 | * This routine is called when the peer acknowledges the receipt of Ack Vectors | ||
380 | * up to and including @ackno. While based on on section A.3 of RFC 4340, here | ||
381 | * are additional precautions to prevent corrupted buffer state. In particular, | ||
382 | * we use tail_ackno to identify outdated records; it always marks the earliest | ||
383 | * packet of group (2) in 11.4.2. | ||
384 | */ | ||
385 | void dccp_ackvec_clear_state(struct dccp_ackvec *av, const u64 ackno) | ||
386 | { | ||
387 | struct dccp_ackvec_record *avr, *next; | ||
388 | u8 runlen_now, eff_runlen; | ||
389 | s64 delta; | ||
390 | |||
391 | avr = dccp_ackvec_lookup(&av->av_records, ackno); | ||
392 | if (avr == NULL) | ||
393 | return; | ||
394 | /* | ||
395 | * Deal with outdated acknowledgments: this arises when e.g. there are | ||
396 | * several old records and the acks from the peer come in slowly. In | ||
397 | * that case we may still have records that pre-date tail_ackno. | ||
398 | */ | ||
399 | delta = dccp_delta_seqno(av->av_tail_ackno, avr->avr_ack_ackno); | ||
400 | if (delta < 0) | ||
401 | goto free_records; | ||
402 | /* | ||
403 | * Deal with overlapping Ack Vectors: don't subtract more than the | ||
404 | * number of packets between tail_ackno and ack_ackno. | ||
405 | */ | ||
406 | eff_runlen = delta < avr->avr_ack_runlen ? delta : avr->avr_ack_runlen; | ||
407 | |||
408 | runlen_now = dccp_ackvec_runlen(av->av_buf + avr->avr_ack_ptr); | ||
409 | /* | ||
410 | * The run length of Ack Vector cells does not decrease over time. If | ||
411 | * the run length is the same as at the time the Ack Vector was sent, we | ||
412 | * free the ack_ptr cell. That cell can however not be freed if the run | ||
413 | * length has increased: in this case we need to move the tail pointer | ||
414 | * backwards (towards higher indices), to its next-oldest neighbour. | ||
415 | */ | ||
416 | if (runlen_now > eff_runlen) { | ||
417 | |||
418 | av->av_buf[avr->avr_ack_ptr] -= eff_runlen + 1; | ||
419 | av->av_buf_tail = __ackvec_idx_add(avr->avr_ack_ptr, 1); | ||
420 | |||
421 | /* This move may not have cleared the overflow flag. */ | ||
422 | if (av->av_overflow) | ||
423 | av->av_overflow = (av->av_buf_head == av->av_buf_tail); | ||
424 | } else { | ||
425 | av->av_buf_tail = avr->avr_ack_ptr; | ||
426 | /* | ||
427 | * We have made sure that avr points to a valid cell within the | ||
428 | * buffer. This cell is either older than head, or equals head | ||
429 | * (empty buffer): in both cases we no longer have any overflow. | ||
430 | */ | ||
431 | av->av_overflow = 0; | ||
432 | } | ||
433 | |||
434 | /* | ||
435 | * The peer has acknowledged up to and including ack_ackno. Hence the | ||
436 | * first packet in group (2) of 11.4.2 is the successor of ack_ackno. | ||
437 | */ | ||
438 | av->av_tail_ackno = ADD48(avr->avr_ack_ackno, 1); | ||
439 | |||
440 | free_records: | ||
441 | list_for_each_entry_safe_from(avr, next, &av->av_records, avr_node) { | ||
442 | list_del(&avr->avr_node); | ||
443 | kmem_cache_free(dccp_ackvec_record_slab, avr); | ||
444 | } | ||
445 | } | ||
446 | |||
359 | int __init dccp_ackvec_init(void) | 447 | int __init dccp_ackvec_init(void) |
360 | { | 448 | { |
361 | dccp_ackvec_slab = kmem_cache_create("dccp_ackvec", | 449 | dccp_ackvec_slab = kmem_cache_create("dccp_ackvec", |