Skip to content

Commit b3d14bf

Browse files
author
Gerrit Renker
committed
dccp ccid-2: Implementation of circular Ack Vector buffer with overflow handling
This completes the implementation of a circular buffer for Ack Vectors, by extending the current (linear array-based) implementation. The changes are: (a) An `overflow' flag to deal with the case of overflow. As before, dynamic growth of the buffer will not be supported; but code will be added to deal robustly with overflowing Ack Vector buffers. (b) A `tail_seqno' field. When naively implementing the algorithm of Appendix A in RFC 4340, problems arise whenever subsequent Ack Vector records overlap, which can bring the entire run length calculation completely out of synch. (This is documented on http://www.erg.abdn.ac.uk/users/gerrit/dccp/notes/\ ack_vectors/tracking_tail_ackno/ .) (c) The buffer length is now computed dynamically (i.e. current fill level), as the span between head to tail. As a result, dccp_ackvec_pending() is now simpler - the #ifdef is no longer necessary since buf_empty is always true when IP_DCCP_ACKVEC is not configured. Signed-off-by: Gerrit Renker <gerrit@erg.abdn.ac.uk>
1 parent 7d87093 commit b3d14bf

4 files changed

Lines changed: 50 additions & 12 deletions

File tree

‎net/dccp/ackvec.c‎

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ struct dccp_ackvec *dccp_ackvec_alloc(const gfp_t priority)
2929
struct dccp_ackvec *av = kmem_cache_zalloc(dccp_ackvec_slab, priority);
3030

3131
if (av != NULL) {
32-
av->av_buf_head = DCCPAV_MAX_ACKVEC_LEN - 1;
32+
av->av_buf_head = av->av_buf_tail = DCCPAV_MAX_ACKVEC_LEN - 1;
3333
INIT_LIST_HEAD(&av->av_records);
3434
}
3535
return av;
@@ -71,6 +71,14 @@ int dccp_ackvec_update_records(struct dccp_ackvec *av, u64 seqno, u8 nonce_sum)
7171
avr->avr_ack_ackno = av->av_buf_ackno;
7272
avr->avr_ack_nonce = nonce_sum;
7373
avr->avr_ack_runlen = dccp_ackvec_runlen(av->av_buf + av->av_buf_head);
74+
/*
75+
* When the buffer overflows, we keep no more than one record. This is
76+
* the simplest way of disambiguating sender-Acks dating from before the
77+
* overflow from sender-Acks which refer to after the overflow; a simple
78+
* solution is preferable here since we are handling an exception.
79+
*/
80+
if (av->av_overflow)
81+
dccp_ackvec_purge_records(av);
7482
/*
7583
* Since GSS is incremented for each packet, the list is automatically
7684
* arranged in descending order of @ack_seqno.
@@ -84,6 +92,27 @@ int dccp_ackvec_update_records(struct dccp_ackvec *av, u64 seqno, u8 nonce_sum)
8492
return 0;
8593
}
8694

95+
/*
96+
* Buffer index and length computation using modulo-buffersize arithmetic.
97+
* Note that, as pointers move from right to left, head is `before' tail.
98+
*/
99+
static inline u16 __ackvec_idx_add(const u16 a, const u16 b)
100+
{
101+
return (a + b) % DCCPAV_MAX_ACKVEC_LEN;
102+
}
103+
104+
static inline u16 __ackvec_idx_sub(const u16 a, const u16 b)
105+
{
106+
return __ackvec_idx_add(a, DCCPAV_MAX_ACKVEC_LEN - b);
107+
}
108+
109+
u16 dccp_ackvec_buflen(const struct dccp_ackvec *av)
110+
{
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);
114+
}
115+
87116
/*
88117
* If several packets are missing, the HC-Receiver may prefer to enter multiple
89118
* bytes with run length 0, rather than a single byte with a larger run length;

‎net/dccp/ackvec.h‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
* the maximum size of a single Ack Vector. Setting %DCCPAV_NUM_ACKVECS to 1
2222
* will be sufficient for most cases of low Ack Ratios, using a value of 2 gives
2323
* 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.
2425
*/
2526
#define DCCPAV_NUM_ACKVECS 2
2627
#define DCCPAV_MAX_ACKVEC_LEN (DCCP_SINGLE_OPT_MAXLEN * DCCPAV_NUM_ACKVECS)
@@ -55,8 +56,10 @@ static inline u8 dccp_ackvec_state(const u8 *cell)
5556
* @av_buf_head: head index; begin of live portion in @av_buf
5657
* @av_buf_tail: tail index; first index _after_ the live portion in @av_buf
5758
* @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
5860
* @av_buf_nonce: ECN nonce sums, each covering subsequent segments of up to
5961
* %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
6063
* @av_records: list of %dccp_ackvec_record (Ack Vectors sent previously)
6164
* @av_veclen: length of the live portion of @av_buf
6265
*/
@@ -65,7 +68,9 @@ struct dccp_ackvec {
6568
u16 av_buf_head;
6669
u16 av_buf_tail;
6770
u64 av_buf_ackno:48;
71+
u64 av_tail_ackno:48;
6872
bool av_buf_nonce[DCCPAV_NUM_ACKVECS];
73+
u8 av_overflow:1;
6974
struct list_head av_records;
7075
u16 av_vec_len;
7176
};
@@ -112,9 +117,10 @@ extern int dccp_ackvec_parse(struct sock *sk, const struct sk_buff *skb,
112117
const u8 *value, const u8 len);
113118

114119
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);
115121

116-
static inline int dccp_ackvec_pending(const struct dccp_ackvec *av)
122+
static inline bool dccp_ackvec_is_empty(const struct dccp_ackvec *av)
117123
{
118-
return av->av_vec_len;
124+
return av->av_overflow == 0 && av->av_buf_head == av->av_buf_tail;
119125
}
120126
#endif /* _ACKVEC_H */

‎net/dccp/dccp.h‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -457,12 +457,15 @@ static inline void dccp_update_gss(struct sock *sk, u64 seq)
457457
dp->dccps_awh = dp->dccps_gss;
458458
}
459459

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+
460466
static inline int dccp_ack_pending(const struct sock *sk)
461467
{
462-
const struct dccp_sock *dp = dccp_sk(sk);
463-
return (dp->dccps_hc_rx_ackvec != NULL &&
464-
dccp_ackvec_pending(dp->dccps_hc_rx_ackvec)) ||
465-
inet_csk_ack_scheduled(sk);
468+
return dccp_ackvec_pending(sk) || inet_csk_ack_scheduled(sk);
466469
}
467470

468471
extern int dccp_feat_finalise_settings(struct dccp_sock *dp);

‎net/dccp/options.c‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -429,9 +429,10 @@ static int dccp_insert_option_ackvec(struct sock *sk, struct sk_buff *skb)
429429
{
430430
struct dccp_sock *dp = dccp_sk(sk);
431431
struct dccp_ackvec *av = dp->dccps_hc_rx_ackvec;
432+
const u16 buflen = dccp_ackvec_buflen(av);
432433
/* Figure out how many options do we need to represent the ackvec */
433-
const u8 nr_opts = DIV_ROUND_UP(av->av_vec_len, DCCP_SINGLE_OPT_MAXLEN);
434-
u16 len = av->av_vec_len + 2 * nr_opts;
434+
const u8 nr_opts = DIV_ROUND_UP(buflen, DCCP_SINGLE_OPT_MAXLEN);
435+
u16 len = buflen + 2 * nr_opts;
435436
u8 i, nonce = 0;
436437
const unsigned char *tail, *from;
437438
unsigned char *to;
@@ -442,7 +443,7 @@ static int dccp_insert_option_ackvec(struct sock *sk, struct sk_buff *skb)
442443
DCCP_SKB_CB(skb)->dccpd_opt_len += len;
443444

444445
to = skb_push(skb, len);
445-
len = av->av_vec_len;
446+
len = buflen;
446447
from = av->av_buf + av->av_buf_head;
447448
tail = av->av_buf + DCCPAV_MAX_ACKVEC_LEN;
448449

@@ -580,8 +581,7 @@ int dccp_insert_options(struct sock *sk, struct sk_buff *skb)
580581
if (dccp_insert_option_timestamp(skb))
581582
return -1;
582583

583-
} else if (dp->dccps_hc_rx_ackvec != NULL &&
584-
dccp_ackvec_pending(dp->dccps_hc_rx_ackvec) &&
584+
} else if (dccp_ackvec_pending(sk) &&
585585
dccp_insert_option_ackvec(sk, skb)) {
586586
return -1;
587587
}

0 commit comments

Comments
 (0)