aboutsummaryrefslogtreecommitdiffstats
path: root/net/dccp
diff options
context:
space:
mode:
authorGerrit Renker <gerrit@erg.abdn.ac.uk>2006-11-28 16:55:06 -0500
committerDavid S. Miller <davem@sunset.davemloft.net>2006-12-03 00:31:02 -0500
commit6b57c93dc3aa0115b589cb89ef862d46ab9bd95e (patch)
treef825b1288d7839ade26225bb0a630540e38ffe41 /net/dccp
parenta79ef76f4d8424324c2f108824a7398571193f43 (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')
-rw-r--r--net/dccp/ccid.h12
-rw-r--r--net/dccp/ccids/ccid2.c5
-rw-r--r--net/dccp/ccids/ccid3.c83
-rw-r--r--net/dccp/output.c6
4 files changed, 48 insertions, 58 deletions
diff --git a/net/dccp/ccid.h b/net/dccp/ccid.h
index f7eb6c613414..c7c29514dce8 100644
--- a/net/dccp/ccid.h
+++ b/net/dccp/ccid.h
@@ -52,9 +52,9 @@ struct ccid_operations {
52 unsigned char len, u16 idx, 52 unsigned char len, u16 idx,
53 unsigned char* value); 53 unsigned char* value);
54 int (*ccid_hc_tx_send_packet)(struct sock *sk, 54 int (*ccid_hc_tx_send_packet)(struct sock *sk,
55 struct sk_buff *skb, int len); 55 struct sk_buff *skb);
56 void (*ccid_hc_tx_packet_sent)(struct sock *sk, int more, 56 void (*ccid_hc_tx_packet_sent)(struct sock *sk,
57 int len); 57 int more, unsigned int len);
58 void (*ccid_hc_rx_get_info)(struct sock *sk, 58 void (*ccid_hc_rx_get_info)(struct sock *sk,
59 struct tcp_info *info); 59 struct tcp_info *info);
60 void (*ccid_hc_tx_get_info)(struct sock *sk, 60 void (*ccid_hc_tx_get_info)(struct sock *sk,
@@ -94,16 +94,16 @@ extern void ccid_hc_rx_delete(struct ccid *ccid, struct sock *sk);
94extern void ccid_hc_tx_delete(struct ccid *ccid, struct sock *sk); 94extern void ccid_hc_tx_delete(struct ccid *ccid, struct sock *sk);
95 95
96static inline int ccid_hc_tx_send_packet(struct ccid *ccid, struct sock *sk, 96static inline int ccid_hc_tx_send_packet(struct ccid *ccid, struct sock *sk,
97 struct sk_buff *skb, int len) 97 struct sk_buff *skb)
98{ 98{
99 int rc = 0; 99 int rc = 0;
100 if (ccid->ccid_ops->ccid_hc_tx_send_packet != NULL) 100 if (ccid->ccid_ops->ccid_hc_tx_send_packet != NULL)
101 rc = ccid->ccid_ops->ccid_hc_tx_send_packet(sk, skb, len); 101 rc = ccid->ccid_ops->ccid_hc_tx_send_packet(sk, skb);
102 return rc; 102 return rc;
103} 103}
104 104
105static inline void ccid_hc_tx_packet_sent(struct ccid *ccid, struct sock *sk, 105static inline void ccid_hc_tx_packet_sent(struct ccid *ccid, struct sock *sk,
106 int more, int len) 106 int more, unsigned int len)
107{ 107{
108 if (ccid->ccid_ops->ccid_hc_tx_packet_sent != NULL) 108 if (ccid->ccid_ops->ccid_hc_tx_packet_sent != NULL)
109 ccid->ccid_ops->ccid_hc_tx_packet_sent(sk, more, len); 109 ccid->ccid_ops->ccid_hc_tx_packet_sent(sk, more, len);
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
128static int ccid2_hc_tx_send_packet(struct sock *sk, 128static 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
271static void ccid2_hc_tx_packet_sent(struct sock *sk, int more, int len) 270static 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 */
275static int ccid3_hc_tx_send_packet(struct sock *sk, 275static 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
359static void ccid3_hc_tx_packet_sent(struct sock *sk, int more, int len) 358static 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
414static void ccid3_hc_tx_packet_recv(struct sock *sk, struct sk_buff *skb) 407static void ccid3_hc_tx_packet_recv(struct sock *sk, struct sk_buff *skb)
diff --git a/net/dccp/output.c b/net/dccp/output.c
index bfd9c5757897..400c30b6fcae 100644
--- a/net/dccp/output.c
+++ b/net/dccp/output.c
@@ -195,8 +195,7 @@ static int dccp_wait_for_ccid(struct sock *sk, struct sk_buff *skb,
195 if (signal_pending(current)) 195 if (signal_pending(current))
196 goto do_interrupted; 196 goto do_interrupted;
197 197
198 rc = ccid_hc_tx_send_packet(dp->dccps_hc_tx_ccid, sk, skb, 198 rc = ccid_hc_tx_send_packet(dp->dccps_hc_tx_ccid, sk, skb);
199 skb->len);
200 if (rc <= 0) 199 if (rc <= 0)
201 break; 200 break;
202 delay = msecs_to_jiffies(rc); 201 delay = msecs_to_jiffies(rc);
@@ -245,8 +244,7 @@ void dccp_write_xmit(struct sock *sk, int block)
245 this we have other issues */ 244 this we have other issues */
246 245
247 while ((skb = skb_peek(&sk->sk_write_queue))) { 246 while ((skb = skb_peek(&sk->sk_write_queue))) {
248 int err = ccid_hc_tx_send_packet(dp->dccps_hc_tx_ccid, sk, skb, 247 int err = ccid_hc_tx_send_packet(dp->dccps_hc_tx_ccid, sk, skb);
249 skb->len);
250 248
251 if (err > 0) { 249 if (err > 0) {
252 if (!block) { 250 if (!block) {