Skip to content

Commit c8bf462

Browse files
author
Gerrit Renker
committed
dccp ccid-2: Separate option parsing from CCID processing
This patch replaces an almost identical replication of code: large parts of dccp_parse_options() re-appeared as ccid2_ackvector() in ccid2.c. Apart from the duplication, this caused two more problems: 1. CCIDs should not need to be concerned with parsing header options; 2. one can not assume that Ack Vectors appear as a contiguous area within an skb, it is legal to insert other options and/or padding in between. The current code would throw an error and stop reading in such a case. The patch provides a new data structure and associated list housekeeping. Only small changes were necessary to integrate with CCID-2: data structure initialisation, adapt list traversal routine, and add call to the provided cleanup routine. The latter also lead to fixing the following BUG: CCID-2 so far ignored Ack Vectors on all packets other than Ack/DataAck, which is incorrect, since Ack Vectors can be present on any packet that has an Ack field. Details: -------- * received Ack Vectors are parsed by dccp_parse_options() alone, which passes the result on to the CCID-specific routine ccid_hc_tx_parse_options(); * CCIDs interested in using/decoding Ack Vector information will add code to fetch parsed Ack Vectors via this interface; * a data structure, `struct dccp_ackvec_parsed' is provided as interface; * this structure arranges Ack Vectors of the same skb into a FIFO order; * a doubly-linked list is used to keep the required FIFO code small. Signed-off-by: Gerrit Renker <gerrit@erg.abdn.ac.uk>
1 parent 5a577b4 commit c8bf462

5 files changed

Lines changed: 101 additions & 100 deletions

File tree

‎net/dccp/ackvec.c‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,34 @@ void dccp_ackvec_clear_state(struct dccp_ackvec *av, const u64 ackno)
343343
}
344344
}
345345

346+
/*
347+
* Routines to keep track of Ack Vectors received in an skb
348+
*/
349+
int dccp_ackvec_parsed_add(struct list_head *head, u8 *vec, u8 len, u8 nonce)
350+
{
351+
struct dccp_ackvec_parsed *new = kmalloc(sizeof(*new), GFP_ATOMIC);
352+
353+
if (new == NULL)
354+
return -ENOBUFS;
355+
new->vec = vec;
356+
new->len = len;
357+
new->nonce = nonce;
358+
359+
list_add_tail(&new->node, head);
360+
return 0;
361+
}
362+
EXPORT_SYMBOL_GPL(dccp_ackvec_parsed_add);
363+
364+
void dccp_ackvec_parsed_cleanup(struct list_head *parsed_chunks)
365+
{
366+
struct dccp_ackvec_parsed *cur, *next;
367+
368+
list_for_each_entry_safe(cur, next, parsed_chunks, node)
369+
kfree(cur);
370+
INIT_LIST_HEAD(parsed_chunks);
371+
}
372+
EXPORT_SYMBOL_GPL(dccp_ackvec_parsed_cleanup);
373+
346374
int __init dccp_ackvec_init(void)
347375
{
348376
dccp_ackvec_slab = kmem_cache_create("dccp_ackvec",

‎net/dccp/ackvec.h‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,4 +114,23 @@ static inline bool dccp_ackvec_is_empty(const struct dccp_ackvec *av)
114114
{
115115
return av->av_overflow == 0 && av->av_buf_head == av->av_buf_tail;
116116
}
117+
118+
/**
119+
* struct dccp_ackvec_parsed - Record offsets of Ack Vectors in skb
120+
* @vec: start of vector (offset into skb)
121+
* @len: length of @vec
122+
* @nonce: whether @vec had an ECN nonce of 0 or 1
123+
* @node: FIFO - arranged in descending order of ack_ackno
124+
* This structure is used by CCIDs to access Ack Vectors in a received skb.
125+
*/
126+
struct dccp_ackvec_parsed {
127+
u8 *vec,
128+
len,
129+
nonce:1;
130+
struct list_head node;
131+
};
132+
133+
extern int dccp_ackvec_parsed_add(struct list_head *head,
134+
u8 *vec, u8 len, u8 nonce);
135+
extern void dccp_ackvec_parsed_cleanup(struct list_head *parsed_chunks);
117136
#endif /* _ACKVEC_H */

‎net/dccp/ccids/ccid2.c‎

Lines changed: 42 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -317,68 +317,6 @@ static void ccid2_hc_tx_packet_sent(struct sock *sk, unsigned int len)
317317
#endif
318318
}
319319

320-
/* XXX Lame code duplication!
321-
* returns -1 if none was found.
322-
* else returns the next offset to use in the function call.
323-
*/
324-
static int ccid2_ackvector(struct sock *sk, struct sk_buff *skb, int offset,
325-
unsigned char **vec, unsigned char *veclen)
326-
{
327-
const struct dccp_hdr *dh = dccp_hdr(skb);
328-
unsigned char *options = (unsigned char *)dh + dccp_hdr_len(skb);
329-
unsigned char *opt_ptr;
330-
const unsigned char *opt_end = (unsigned char *)dh +
331-
(dh->dccph_doff * 4);
332-
unsigned char opt, len;
333-
unsigned char *value;
334-
335-
BUG_ON(offset < 0);
336-
options += offset;
337-
opt_ptr = options;
338-
if (opt_ptr >= opt_end)
339-
return -1;
340-
341-
while (opt_ptr != opt_end) {
342-
opt = *opt_ptr++;
343-
len = 0;
344-
value = NULL;
345-
346-
/* Check if this isn't a single byte option */
347-
if (opt > DCCPO_MAX_RESERVED) {
348-
if (opt_ptr == opt_end)
349-
goto out_invalid_option;
350-
351-
len = *opt_ptr++;
352-
if (len < 3)
353-
goto out_invalid_option;
354-
/*
355-
* Remove the type and len fields, leaving
356-
* just the value size
357-
*/
358-
len -= 2;
359-
value = opt_ptr;
360-
opt_ptr += len;
361-
362-
if (opt_ptr > opt_end)
363-
goto out_invalid_option;
364-
}
365-
366-
switch (opt) {
367-
case DCCPO_ACK_VECTOR_0:
368-
case DCCPO_ACK_VECTOR_1:
369-
*vec = value;
370-
*veclen = len;
371-
return offset + (opt_ptr - options);
372-
}
373-
}
374-
375-
return -1;
376-
377-
out_invalid_option:
378-
DCCP_BUG("Invalid option - this should not happen (previous parsing)!");
379-
return -1;
380-
}
381-
382320
static void ccid2_hc_tx_kill_rto_timer(struct sock *sk)
383321
{
384322
struct ccid2_hc_tx_sock *hctx = ccid2_hc_tx_sk(sk);
@@ -499,15 +437,27 @@ static void ccid2_congestion_event(struct sock *sk, struct ccid2_seq *seqp)
499437
ccid2_change_l_ack_ratio(sk, hctx->cwnd);
500438
}
501439

440+
static int ccid2_hc_tx_parse_options(struct sock *sk, u8 packet_type,
441+
u8 option, u8 *optval, u8 optlen)
442+
{
443+
struct ccid2_hc_tx_sock *hctx = ccid2_hc_tx_sk(sk);
444+
445+
switch (option) {
446+
case DCCPO_ACK_VECTOR_0:
447+
case DCCPO_ACK_VECTOR_1:
448+
return dccp_ackvec_parsed_add(&hctx->av_chunks, optval, optlen,
449+
option - DCCPO_ACK_VECTOR_0);
450+
}
451+
return 0;
452+
}
453+
502454
static void ccid2_hc_tx_packet_recv(struct sock *sk, struct sk_buff *skb)
503455
{
504456
struct dccp_sock *dp = dccp_sk(sk);
505457
struct ccid2_hc_tx_sock *hctx = ccid2_hc_tx_sk(sk);
458+
struct dccp_ackvec_parsed *avp;
506459
u64 ackno, seqno;
507460
struct ccid2_seq *seqp;
508-
unsigned char *vector;
509-
unsigned char veclen;
510-
int offset = 0;
511461
int done = 0;
512462
unsigned int maxincr = 0;
513463

@@ -542,17 +492,12 @@ static void ccid2_hc_tx_packet_recv(struct sock *sk, struct sk_buff *skb)
542492
}
543493

544494
/* check forward path congestion */
545-
/* still didn't send out new data packets */
546-
if (hctx->seqh == hctx->seqt)
495+
if (dccp_packet_without_ack(skb))
547496
return;
548497

549-
switch (DCCP_SKB_CB(skb)->dccpd_type) {
550-
case DCCP_PKT_ACK:
551-
case DCCP_PKT_DATAACK:
552-
break;
553-
default:
554-
return;
555-
}
498+
/* still didn't send out new data packets */
499+
if (hctx->seqh == hctx->seqt)
500+
goto done;
556501

557502
ackno = DCCP_SKB_CB(skb)->dccpd_ack_seq;
558503
if (after48(ackno, hctx->high_ack))
@@ -576,15 +521,16 @@ static void ccid2_hc_tx_packet_recv(struct sock *sk, struct sk_buff *skb)
576521
maxincr = DIV_ROUND_UP(dp->dccps_l_ack_ratio, 2);
577522

578523
/* go through all ack vectors */
579-
while ((offset = ccid2_ackvector(sk, skb, offset,
580-
&vector, &veclen)) != -1) {
524+
list_for_each_entry(avp, &hctx->av_chunks, node) {
581525
/* go through this ack vector */
582-
while (veclen--) {
583-
u64 ackno_end_rl = SUB48(ackno, dccp_ackvec_runlen(vector));
526+
for (; avp->len--; avp->vec++) {
527+
u64 ackno_end_rl = SUB48(ackno,
528+
dccp_ackvec_runlen(avp->vec));
584529

585-
ccid2_pr_debug("ackvec start:%llu end:%llu\n",
530+
ccid2_pr_debug("ackvec %llu |%u,%u|\n",
586531
(unsigned long long)ackno,
587-
(unsigned long long)ackno_end_rl);
532+
dccp_ackvec_state(avp->vec) >> 6,
533+
dccp_ackvec_runlen(avp->vec));
588534
/* if the seqno we are analyzing is larger than the
589535
* current ackno, then move towards the tail of our
590536
* seqnos.
@@ -603,7 +549,7 @@ static void ccid2_hc_tx_packet_recv(struct sock *sk, struct sk_buff *skb)
603549
* run length
604550
*/
605551
while (between48(seqp->ccid2s_seq,ackno_end_rl,ackno)) {
606-
const u8 state = dccp_ackvec_state(vector);
552+
const u8 state = dccp_ackvec_state(avp->vec);
607553

608554
/* new packet received or marked */
609555
if (state != DCCPAV_NOT_RECEIVED &&
@@ -630,7 +576,6 @@ static void ccid2_hc_tx_packet_recv(struct sock *sk, struct sk_buff *skb)
630576
break;
631577

632578
ackno = SUB48(ackno_end_rl, 1);
633-
vector++;
634579
}
635580
if (done)
636581
break;
@@ -694,6 +639,8 @@ static void ccid2_hc_tx_packet_recv(struct sock *sk, struct sk_buff *skb)
694639
}
695640

696641
ccid2_hc_tx_check_sanity(hctx);
642+
done:
643+
dccp_ackvec_parsed_cleanup(&hctx->av_chunks);
697644
}
698645

699646
static int ccid2_hc_tx_init(struct ccid *ccid, struct sock *sk)
@@ -727,6 +674,7 @@ static int ccid2_hc_tx_init(struct ccid *ccid, struct sock *sk)
727674
hctx->rpdupack = -1;
728675
hctx->last_cong = jiffies;
729676
setup_timer(&hctx->rtotimer, ccid2_hc_tx_rto_expire, (unsigned long)sk);
677+
INIT_LIST_HEAD(&hctx->av_chunks);
730678

731679
ccid2_hc_tx_check_sanity(hctx);
732680
return 0;
@@ -762,17 +710,18 @@ static void ccid2_hc_rx_packet_recv(struct sock *sk, struct sk_buff *skb)
762710
}
763711

764712
static struct ccid_operations ccid2 = {
765-
.ccid_id = DCCPC_CCID2,
766-
.ccid_name = "TCP-like",
767-
.ccid_owner = THIS_MODULE,
768-
.ccid_hc_tx_obj_size = sizeof(struct ccid2_hc_tx_sock),
769-
.ccid_hc_tx_init = ccid2_hc_tx_init,
770-
.ccid_hc_tx_exit = ccid2_hc_tx_exit,
771-
.ccid_hc_tx_send_packet = ccid2_hc_tx_send_packet,
772-
.ccid_hc_tx_packet_sent = ccid2_hc_tx_packet_sent,
773-
.ccid_hc_tx_packet_recv = ccid2_hc_tx_packet_recv,
774-
.ccid_hc_rx_obj_size = sizeof(struct ccid2_hc_rx_sock),
775-
.ccid_hc_rx_packet_recv = ccid2_hc_rx_packet_recv,
713+
.ccid_id = DCCPC_CCID2,
714+
.ccid_name = "TCP-like",
715+
.ccid_owner = THIS_MODULE,
716+
.ccid_hc_tx_obj_size = sizeof(struct ccid2_hc_tx_sock),
717+
.ccid_hc_tx_init = ccid2_hc_tx_init,
718+
.ccid_hc_tx_exit = ccid2_hc_tx_exit,
719+
.ccid_hc_tx_send_packet = ccid2_hc_tx_send_packet,
720+
.ccid_hc_tx_packet_sent = ccid2_hc_tx_packet_sent,
721+
.ccid_hc_tx_parse_options = ccid2_hc_tx_parse_options,
722+
.ccid_hc_tx_packet_recv = ccid2_hc_tx_packet_recv,
723+
.ccid_hc_rx_obj_size = sizeof(struct ccid2_hc_rx_sock),
724+
.ccid_hc_rx_packet_recv = ccid2_hc_rx_packet_recv,
776725
};
777726

778727
#ifdef CONFIG_IP_DCCP_CCID2_DEBUG

‎net/dccp/ccids/ccid2.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ struct ccid2_seq {
4747
* @lastrtt: time RTT was last measured
4848
* @rpseq: last consecutive seqno
4949
* @rpdupack: dupacks since rpseq
50+
* @av_chunks: list of Ack Vectors received on current skb
5051
*/
5152
struct ccid2_hc_tx_sock {
5253
u32 cwnd;
@@ -66,6 +67,7 @@ struct ccid2_hc_tx_sock {
6667
int rpdupack;
6768
unsigned long last_cong;
6869
u64 high_ack;
70+
struct list_head av_chunks;
6971
};
7072

7173
struct ccid2_hc_rx_sock {

‎net/dccp/options.c‎

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,6 @@ int dccp_parse_options(struct sock *sk, struct dccp_request_sock *dreq,
128128
if (rc)
129129
goto out_featneg_failed;
130130
break;
131-
case DCCPO_ACK_VECTOR_0:
132-
case DCCPO_ACK_VECTOR_1:
133-
if (dccp_packet_without_ack(skb)) /* RFC 4340, 11.4 */
134-
break;
135-
dccp_pr_debug("%s Ack Vector (len=%u)\n", dccp_role(sk),
136-
len);
137-
break;
138131
case DCCPO_TIMESTAMP:
139132
if (len != 4)
140133
goto out_invalid_option;
@@ -224,6 +217,16 @@ int dccp_parse_options(struct sock *sk, struct dccp_request_sock *dreq,
224217
pkt_type, opt, value, len))
225218
goto out_invalid_option;
226219
break;
220+
case DCCPO_ACK_VECTOR_0:
221+
case DCCPO_ACK_VECTOR_1:
222+
if (dccp_packet_without_ack(skb)) /* RFC 4340, 11.4 */
223+
break;
224+
/*
225+
* Ack vectors are processed by the TX CCID if it is
226+
* interested. The RX CCID need not parse Ack Vectors,
227+
* since it is only interested in clearing old state.
228+
* Fall through.
229+
*/
227230
case DCCPO_MIN_TX_CCID_SPECIFIC ... DCCPO_MAX_TX_CCID_SPECIFIC:
228231
if (ccid_hc_tx_parse_options(dp->dccps_hc_tx_ccid, sk,
229232
pkt_type, opt, value, len))

0 commit comments

Comments
 (0)