Skip to content

Commit 7e87fe8

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. Since Ack Vectors provide CCID-specific information, they are now processed by the CCID directly, separating this functionality from the main DCCP code. Signed-off-by: Gerrit Renker <gerrit@erg.abdn.ac.uk>
1 parent 52394ee commit 7e87fe8

5 files changed

Lines changed: 100 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: 41 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -246,68 +246,6 @@ static void ccid2_hc_tx_packet_sent(struct sock *sk, unsigned int len)
246246
#endif
247247
}
248248

249-
/* XXX Lame code duplication!
250-
* returns -1 if none was found.
251-
* else returns the next offset to use in the function call.
252-
*/
253-
static int ccid2_ackvector(struct sock *sk, struct sk_buff *skb, int offset,
254-
unsigned char **vec, unsigned char *veclen)
255-
{
256-
const struct dccp_hdr *dh = dccp_hdr(skb);
257-
unsigned char *options = (unsigned char *)dh + dccp_hdr_len(skb);
258-
unsigned char *opt_ptr;
259-
const unsigned char *opt_end = (unsigned char *)dh +
260-
(dh->dccph_doff * 4);
261-
unsigned char opt, len;
262-
unsigned char *value;
263-
264-
BUG_ON(offset < 0);
265-
options += offset;
266-
opt_ptr = options;
267-
if (opt_ptr >= opt_end)
268-
return -1;
269-
270-
while (opt_ptr != opt_end) {
271-
opt = *opt_ptr++;
272-
len = 0;
273-
value = NULL;
274-
275-
/* Check if this isn't a single byte option */
276-
if (opt > DCCPO_MAX_RESERVED) {
277-
if (opt_ptr == opt_end)
278-
goto out_invalid_option;
279-
280-
len = *opt_ptr++;
281-
if (len < 3)
282-
goto out_invalid_option;
283-
/*
284-
* Remove the type and len fields, leaving
285-
* just the value size
286-
*/
287-
len -= 2;
288-
value = opt_ptr;
289-
opt_ptr += len;
290-
291-
if (opt_ptr > opt_end)
292-
goto out_invalid_option;
293-
}
294-
295-
switch (opt) {
296-
case DCCPO_ACK_VECTOR_0:
297-
case DCCPO_ACK_VECTOR_1:
298-
*vec = value;
299-
*veclen = len;
300-
return offset + (opt_ptr - options);
301-
}
302-
}
303-
304-
return -1;
305-
306-
out_invalid_option:
307-
DCCP_BUG("Invalid option - this should not happen (previous parsing)!");
308-
return -1;
309-
}
310-
311249
/**
312250
* ccid2_rtt_estimator - Sample RTT and compute RTO using RFC2988 algorithm
313251
* This code is almost identical with TCP's tcp_rtt_estimator(), since
@@ -432,16 +370,28 @@ static void ccid2_congestion_event(struct sock *sk, struct ccid2_seq *seqp)
432370
ccid2_change_l_ack_ratio(sk, hc->tx_cwnd);
433371
}
434372

373+
static int ccid2_hc_tx_parse_options(struct sock *sk, u8 packet_type,
374+
u8 option, u8 *optval, u8 optlen)
375+
{
376+
struct ccid2_hc_tx_sock *hc = ccid2_hc_tx_sk(sk);
377+
378+
switch (option) {
379+
case DCCPO_ACK_VECTOR_0:
380+
case DCCPO_ACK_VECTOR_1:
381+
return dccp_ackvec_parsed_add(&hc->tx_av_chunks, optval, optlen,
382+
option - DCCPO_ACK_VECTOR_0);
383+
}
384+
return 0;
385+
}
386+
435387
static void ccid2_hc_tx_packet_recv(struct sock *sk, struct sk_buff *skb)
436388
{
437389
struct dccp_sock *dp = dccp_sk(sk);
438390
struct ccid2_hc_tx_sock *hc = ccid2_hc_tx_sk(sk);
439391
const bool sender_was_blocked = ccid2_cwnd_network_limited(hc);
392+
struct dccp_ackvec_parsed *avp;
440393
u64 ackno, seqno;
441394
struct ccid2_seq *seqp;
442-
unsigned char *vector;
443-
unsigned char veclen;
444-
int offset = 0;
445395
int done = 0;
446396
unsigned int maxincr = 0;
447397

@@ -475,17 +425,12 @@ static void ccid2_hc_tx_packet_recv(struct sock *sk, struct sk_buff *skb)
475425
}
476426

477427
/* check forward path congestion */
478-
/* still didn't send out new data packets */
479-
if (hc->tx_seqh == hc->tx_seqt)
428+
if (dccp_packet_without_ack(skb))
480429
return;
481430

482-
switch (DCCP_SKB_CB(skb)->dccpd_type) {
483-
case DCCP_PKT_ACK:
484-
case DCCP_PKT_DATAACK:
485-
break;
486-
default:
487-
return;
488-
}
431+
/* still didn't send out new data packets */
432+
if (hc->tx_seqh == hc->tx_seqt)
433+
goto done;
489434

490435
ackno = DCCP_SKB_CB(skb)->dccpd_ack_seq;
491436
if (after48(ackno, hc->tx_high_ack))
@@ -509,15 +454,16 @@ static void ccid2_hc_tx_packet_recv(struct sock *sk, struct sk_buff *skb)
509454
maxincr = DIV_ROUND_UP(dp->dccps_l_ack_ratio, 2);
510455

511456
/* go through all ack vectors */
512-
while ((offset = ccid2_ackvector(sk, skb, offset,
513-
&vector, &veclen)) != -1) {
457+
list_for_each_entry(avp, &hc->tx_av_chunks, node) {
514458
/* go through this ack vector */
515-
while (veclen--) {
516-
u64 ackno_end_rl = SUB48(ackno, dccp_ackvec_runlen(vector));
459+
for (; avp->len--; avp->vec++) {
460+
u64 ackno_end_rl = SUB48(ackno,
461+
dccp_ackvec_runlen(avp->vec));
517462

518-
ccid2_pr_debug("ackvec start:%llu end:%llu\n",
463+
ccid2_pr_debug("ackvec %llu |%u,%u|\n",
519464
(unsigned long long)ackno,
520-
(unsigned long long)ackno_end_rl);
465+
dccp_ackvec_state(avp->vec) >> 6,
466+
dccp_ackvec_runlen(avp->vec));
521467
/* if the seqno we are analyzing is larger than the
522468
* current ackno, then move towards the tail of our
523469
* seqnos.
@@ -536,7 +482,7 @@ static void ccid2_hc_tx_packet_recv(struct sock *sk, struct sk_buff *skb)
536482
* run length
537483
*/
538484
while (between48(seqp->ccid2s_seq,ackno_end_rl,ackno)) {
539-
const u8 state = dccp_ackvec_state(vector);
485+
const u8 state = dccp_ackvec_state(avp->vec);
540486

541487
/* new packet received or marked */
542488
if (state != DCCPAV_NOT_RECEIVED &&
@@ -563,7 +509,6 @@ static void ccid2_hc_tx_packet_recv(struct sock *sk, struct sk_buff *skb)
563509
break;
564510

565511
ackno = SUB48(ackno_end_rl, 1);
566-
vector++;
567512
}
568513
if (done)
569514
break;
@@ -631,10 +576,11 @@ static void ccid2_hc_tx_packet_recv(struct sock *sk, struct sk_buff *skb)
631576
sk_stop_timer(sk, &hc->tx_rtotimer);
632577
else
633578
sk_reset_timer(sk, &hc->tx_rtotimer, jiffies + hc->tx_rto);
634-
579+
done:
635580
/* check if incoming Acks allow pending packets to be sent */
636581
if (sender_was_blocked && !ccid2_cwnd_network_limited(hc))
637582
tasklet_schedule(&dccp_sk(sk)->dccps_xmitlet);
583+
dccp_ackvec_parsed_cleanup(&hc->tx_av_chunks);
638584
}
639585

640586
static int ccid2_hc_tx_init(struct ccid *ccid, struct sock *sk)
@@ -663,6 +609,7 @@ static int ccid2_hc_tx_init(struct ccid *ccid, struct sock *sk)
663609
hc->tx_last_cong = ccid2_time_stamp;
664610
setup_timer(&hc->tx_rtotimer, ccid2_hc_tx_rto_expire,
665611
(unsigned long)sk);
612+
INIT_LIST_HEAD(&hc->tx_av_chunks);
666613
return 0;
667614
}
668615

@@ -696,16 +643,17 @@ static void ccid2_hc_rx_packet_recv(struct sock *sk, struct sk_buff *skb)
696643
}
697644

698645
struct ccid_operations ccid2_ops = {
699-
.ccid_id = DCCPC_CCID2,
700-
.ccid_name = "TCP-like",
701-
.ccid_hc_tx_obj_size = sizeof(struct ccid2_hc_tx_sock),
702-
.ccid_hc_tx_init = ccid2_hc_tx_init,
703-
.ccid_hc_tx_exit = ccid2_hc_tx_exit,
704-
.ccid_hc_tx_send_packet = ccid2_hc_tx_send_packet,
705-
.ccid_hc_tx_packet_sent = ccid2_hc_tx_packet_sent,
706-
.ccid_hc_tx_packet_recv = ccid2_hc_tx_packet_recv,
707-
.ccid_hc_rx_obj_size = sizeof(struct ccid2_hc_rx_sock),
708-
.ccid_hc_rx_packet_recv = ccid2_hc_rx_packet_recv,
646+
.ccid_id = DCCPC_CCID2,
647+
.ccid_name = "TCP-like",
648+
.ccid_hc_tx_obj_size = sizeof(struct ccid2_hc_tx_sock),
649+
.ccid_hc_tx_init = ccid2_hc_tx_init,
650+
.ccid_hc_tx_exit = ccid2_hc_tx_exit,
651+
.ccid_hc_tx_send_packet = ccid2_hc_tx_send_packet,
652+
.ccid_hc_tx_packet_sent = ccid2_hc_tx_packet_sent,
653+
.ccid_hc_tx_parse_options = ccid2_hc_tx_parse_options,
654+
.ccid_hc_tx_packet_recv = ccid2_hc_tx_packet_recv,
655+
.ccid_hc_rx_obj_size = sizeof(struct ccid2_hc_rx_sock),
656+
.ccid_hc_rx_packet_recv = ccid2_hc_rx_packet_recv,
709657
};
710658

711659
#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
@@ -55,6 +55,7 @@ struct ccid2_seq {
5555
* @tx_rtt_seq: to decay RTTVAR at most once per flight
5656
* @tx_rpseq: last consecutive seqno
5757
* @tx_rpdupack: dupacks since rpseq
58+
* @tx_av_chunks: list of Ack Vectors received on current skb
5859
*/
5960
struct ccid2_hc_tx_sock {
6061
u32 tx_cwnd;
@@ -79,6 +80,7 @@ struct ccid2_hc_tx_sock {
7980
int tx_rpdupack;
8081
u32 tx_last_cong;
8182
u64 tx_high_ack;
83+
struct list_head tx_av_chunks;
8284
};
8385

8486
static inline bool ccid2_cwnd_network_limited(struct ccid2_hc_tx_sock *hc)

‎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)