diff options
author | Gerrit Renker <gerrit@erg.abdn.ac.uk> | 2006-11-28 16:55:06 -0500 |
---|---|---|
committer | David S. Miller <davem@sunset.davemloft.net> | 2006-12-03 00:31:02 -0500 |
commit | 6b57c93dc3aa0115b589cb89ef862d46ab9bd95e (patch) | |
tree | f825b1288d7839ade26225bb0a630540e38ffe41 /net/dccp/ccids | |
parent | a79ef76f4d8424324c2f108824a7398571193f43 (diff) |
[DCCP]: Use `unsigned' for packet lengths
This patch implements a suggestion by Ian McDonald and
1) Avoids tests against negative packet lengths by using unsigned int
for packet payload lengths in the CCID send_packet()/packet_sent() routines
2) As a consequence, it removes an now unnecessary test with regard to `len > 0'
in ccid3_hc_tx_packet_sent: that condition is always true, since
* negative packet lengths are avoided
* ccid3_hc_tx_send_packet flags an error whenever the payload length is 0.
As a consequence, ccid3_hc_tx_packet_sent is never called as all errors
returned by ccid_hc_tx_send_packet are caught in dccp_write_xmit
3) Removes the third argument of ccid_hc_tx_send_packet (the `len' parameter),
since it is currently always set to skb->len. The code is updated with regard
to this parameter change.
Signed-off-by: Gerrit Renker <gerrit@erg.abdn.ac.uk>
Signed-off-by: Ian McDonald <ian.mcdonald@jandi.co.nz>
Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
Diffstat (limited to 'net/dccp/ccids')
-rw-r--r-- | net/dccp/ccids/ccid2.c | 5 | ||||
-rw-r--r-- | net/dccp/ccids/ccid3.c | 83 |
2 files changed, 40 insertions, 48 deletions
diff --git a/net/dccp/ccids/ccid2.c b/net/dccp/ccids/ccid2.c index 207f7f9b36ca..2555be8f4790 100644 --- a/net/dccp/ccids/ccid2.c +++ b/net/dccp/ccids/ccid2.c | |||
@@ -125,8 +125,7 @@ static int ccid2_hc_tx_alloc_seq(struct ccid2_hc_tx_sock *hctx, int num, | |||
125 | return 0; | 125 | return 0; |
126 | } | 126 | } |
127 | 127 | ||
128 | static int ccid2_hc_tx_send_packet(struct sock *sk, | 128 | static int ccid2_hc_tx_send_packet(struct sock *sk, struct sk_buff *skb) |
129 | struct sk_buff *skb, int len) | ||
130 | { | 129 | { |
131 | struct ccid2_hc_tx_sock *hctx; | 130 | struct ccid2_hc_tx_sock *hctx; |
132 | 131 | ||
@@ -268,7 +267,7 @@ static void ccid2_start_rto_timer(struct sock *sk) | |||
268 | jiffies + hctx->ccid2hctx_rto); | 267 | jiffies + hctx->ccid2hctx_rto); |
269 | } | 268 | } |
270 | 269 | ||
271 | static void ccid2_hc_tx_packet_sent(struct sock *sk, int more, int len) | 270 | static void ccid2_hc_tx_packet_sent(struct sock *sk, int more, unsigned int len) |
272 | { | 271 | { |
273 | struct dccp_sock *dp = dccp_sk(sk); | 272 | struct dccp_sock *dp = dccp_sk(sk); |
274 | struct ccid2_hc_tx_sock *hctx = ccid2_hc_tx_sk(sk); | 273 | struct ccid2_hc_tx_sock *hctx = ccid2_hc_tx_sk(sk); |
diff --git a/net/dccp/ccids/ccid3.c b/net/dccp/ccids/ccid3.c index aa5440ee20ae..70ebe705eb75 100644 --- a/net/dccp/ccids/ccid3.c +++ b/net/dccp/ccids/ccid3.c | |||
@@ -272,8 +272,7 @@ out: | |||
272 | * = 0: can send immediately | 272 | * = 0: can send immediately |
273 | * < 0: error condition; do not send packet | 273 | * < 0: error condition; do not send packet |
274 | */ | 274 | */ |
275 | static int ccid3_hc_tx_send_packet(struct sock *sk, | 275 | static int ccid3_hc_tx_send_packet(struct sock *sk, struct sk_buff *skb) |
276 | struct sk_buff *skb, int len) | ||
277 | { | 276 | { |
278 | struct dccp_sock *dp = dccp_sk(sk); | 277 | struct dccp_sock *dp = dccp_sk(sk); |
279 | struct ccid3_hc_tx_sock *hctx = ccid3_hc_tx_sk(sk); | 278 | struct ccid3_hc_tx_sock *hctx = ccid3_hc_tx_sk(sk); |
@@ -288,7 +287,7 @@ static int ccid3_hc_tx_send_packet(struct sock *sk, | |||
288 | * zero-sized Data(Ack)s is theoretically possible, but for congestion | 287 | * zero-sized Data(Ack)s is theoretically possible, but for congestion |
289 | * control this case is pathological - ignore it. | 288 | * control this case is pathological - ignore it. |
290 | */ | 289 | */ |
291 | if (unlikely(len == 0)) | 290 | if (unlikely(skb->len == 0)) |
292 | return -EBADMSG; | 291 | return -EBADMSG; |
293 | 292 | ||
294 | /* See if last packet allocated was not sent */ | 293 | /* See if last packet allocated was not sent */ |
@@ -317,7 +316,7 @@ static int ccid3_hc_tx_send_packet(struct sock *sk, | |||
317 | ccid3_hc_tx_set_state(sk, TFRC_SSTATE_NO_FBACK); | 316 | ccid3_hc_tx_set_state(sk, TFRC_SSTATE_NO_FBACK); |
318 | 317 | ||
319 | /* Set initial sending rate to 1 packet per second */ | 318 | /* Set initial sending rate to 1 packet per second */ |
320 | ccid3_hc_tx_update_s(hctx, len); | 319 | ccid3_hc_tx_update_s(hctx, skb->len); |
321 | hctx->ccid3hctx_x = hctx->ccid3hctx_s; | 320 | hctx->ccid3hctx_x = hctx->ccid3hctx_s; |
322 | 321 | ||
323 | /* First timeout, according to [RFC 3448, 4.2], is 1 second */ | 322 | /* First timeout, according to [RFC 3448, 4.2], is 1 second */ |
@@ -356,59 +355,53 @@ static int ccid3_hc_tx_send_packet(struct sock *sk, | |||
356 | return 0; | 355 | return 0; |
357 | } | 356 | } |
358 | 357 | ||
359 | static void ccid3_hc_tx_packet_sent(struct sock *sk, int more, int len) | 358 | static void ccid3_hc_tx_packet_sent(struct sock *sk, int more, unsigned int len) |
360 | { | 359 | { |
361 | const struct dccp_sock *dp = dccp_sk(sk); | 360 | const struct dccp_sock *dp = dccp_sk(sk); |
362 | struct ccid3_hc_tx_sock *hctx = ccid3_hc_tx_sk(sk); | 361 | struct ccid3_hc_tx_sock *hctx = ccid3_hc_tx_sk(sk); |
363 | struct timeval now; | 362 | struct timeval now; |
363 | unsigned long quarter_rtt; | ||
364 | struct dccp_tx_hist_entry *packet; | ||
364 | 365 | ||
365 | BUG_ON(hctx == NULL); | 366 | BUG_ON(hctx == NULL); |
366 | 367 | ||
367 | dccp_timestamp(sk, &now); | 368 | dccp_timestamp(sk, &now); |
368 | 369 | ||
369 | /* check if we have sent a data packet */ | 370 | ccid3_hc_tx_update_s(hctx, len); |
370 | if (len > 0) { | ||
371 | unsigned long quarter_rtt; | ||
372 | struct dccp_tx_hist_entry *packet; | ||
373 | 371 | ||
374 | ccid3_hc_tx_update_s(hctx, len); | 372 | packet = dccp_tx_hist_head(&hctx->ccid3hctx_hist); |
373 | if (unlikely(packet == NULL)) { | ||
374 | DCCP_WARN("packet doesn't exist in history!\n"); | ||
375 | return; | ||
376 | } | ||
377 | if (unlikely(packet->dccphtx_sent)) { | ||
378 | DCCP_WARN("no unsent packet in history!\n"); | ||
379 | return; | ||
380 | } | ||
381 | packet->dccphtx_tstamp = now; | ||
382 | packet->dccphtx_seqno = dp->dccps_gss; | ||
383 | /* | ||
384 | * Check if win_count have changed | ||
385 | * Algorithm in "8.1. Window Counter Value" in RFC 4342. | ||
386 | */ | ||
387 | quarter_rtt = timeval_delta(&now, &hctx->ccid3hctx_t_last_win_count); | ||
388 | if (likely(hctx->ccid3hctx_rtt > 8)) | ||
389 | quarter_rtt /= hctx->ccid3hctx_rtt / 4; | ||
375 | 390 | ||
376 | packet = dccp_tx_hist_head(&hctx->ccid3hctx_hist); | 391 | if (quarter_rtt > 0) { |
377 | if (unlikely(packet == NULL)) { | 392 | hctx->ccid3hctx_t_last_win_count = now; |
378 | DCCP_WARN("packet doesn't exist in history!\n"); | 393 | hctx->ccid3hctx_last_win_count = (hctx->ccid3hctx_last_win_count + |
379 | return; | 394 | min_t(unsigned long, quarter_rtt, 5)) % 16; |
380 | } | 395 | ccid3_pr_debug("%s, sk=%p, window changed from " |
381 | if (unlikely(packet->dccphtx_sent)) { | 396 | "%u to %u!\n", |
382 | DCCP_WARN("no unsent packet in history!\n"); | 397 | dccp_role(sk), sk, |
383 | return; | 398 | packet->dccphtx_ccval, |
384 | } | 399 | hctx->ccid3hctx_last_win_count); |
385 | packet->dccphtx_tstamp = now; | 400 | } |
386 | packet->dccphtx_seqno = dp->dccps_gss; | ||
387 | /* | ||
388 | * Check if win_count have changed | ||
389 | * Algorithm in "8.1. Window Counter Value" in RFC 4342. | ||
390 | */ | ||
391 | quarter_rtt = timeval_delta(&now, &hctx->ccid3hctx_t_last_win_count); | ||
392 | if (likely(hctx->ccid3hctx_rtt > 8)) | ||
393 | quarter_rtt /= hctx->ccid3hctx_rtt / 4; | ||
394 | |||
395 | if (quarter_rtt > 0) { | ||
396 | hctx->ccid3hctx_t_last_win_count = now; | ||
397 | hctx->ccid3hctx_last_win_count = (hctx->ccid3hctx_last_win_count + | ||
398 | min_t(unsigned long, quarter_rtt, 5)) % 16; | ||
399 | ccid3_pr_debug("%s, sk=%p, window changed from " | ||
400 | "%u to %u!\n", | ||
401 | dccp_role(sk), sk, | ||
402 | packet->dccphtx_ccval, | ||
403 | hctx->ccid3hctx_last_win_count); | ||
404 | } | ||
405 | 401 | ||
406 | hctx->ccid3hctx_idle = 0; | 402 | hctx->ccid3hctx_idle = 0; |
407 | packet->dccphtx_rtt = hctx->ccid3hctx_rtt; | 403 | packet->dccphtx_rtt = hctx->ccid3hctx_rtt; |
408 | packet->dccphtx_sent = 1; | 404 | packet->dccphtx_sent = 1; |
409 | } else | ||
410 | ccid3_pr_debug("%s, sk=%p, seqno=%llu NOT inserted!\n", | ||
411 | dccp_role(sk), sk, dp->dccps_gss); | ||
412 | } | 405 | } |
413 | 406 | ||
414 | static void ccid3_hc_tx_packet_recv(struct sock *sk, struct sk_buff *skb) | 407 | static void ccid3_hc_tx_packet_recv(struct sock *sk, struct sk_buff *skb) |