aboutsummaryrefslogtreecommitdiffstats
path: root/net/dccp/ccids
diff options
context:
space:
mode:
Diffstat (limited to 'net/dccp/ccids')
-rw-r--r--net/dccp/ccids/ccid3.c163
-rw-r--r--net/dccp/ccids/ccid3.h14
-rw-r--r--net/dccp/ccids/lib/packet_history.h3
3 files changed, 100 insertions, 80 deletions
diff --git a/net/dccp/ccids/ccid3.c b/net/dccp/ccids/ccid3.c
index 7bf3b3a91e97..ea30012dd195 100644
--- a/net/dccp/ccids/ccid3.c
+++ b/net/dccp/ccids/ccid3.c
@@ -43,12 +43,22 @@
43#include "ccid3.h" 43#include "ccid3.h"
44 44
45/* 45/*
46 * Reason for maths with 10 here is to avoid 32 bit overflow when a is big. 46 * Reason for maths here is to avoid 32 bit overflow when a is big.
47 * With this we get close to the limit.
47 */ 48 */
48static inline u32 usecs_div(const u32 a, const u32 b) 49static inline u32 usecs_div(const u32 a, const u32 b)
49{ 50{
50 const u32 tmp = a * (USEC_PER_SEC / 10); 51 const u32 div = a < (UINT_MAX / (USEC_PER_SEC / 10)) ? 10 :
51 return b > 20 ? tmp / (b / 10) : tmp; 52 a < (UINT_MAX / (USEC_PER_SEC / 50)) ? 50 :
53 a < (UINT_MAX / (USEC_PER_SEC / 100)) ? 100 :
54 a < (UINT_MAX / (USEC_PER_SEC / 500)) ? 500 :
55 a < (UINT_MAX / (USEC_PER_SEC / 1000)) ? 1000 :
56 a < (UINT_MAX / (USEC_PER_SEC / 5000)) ? 5000 :
57 a < (UINT_MAX / (USEC_PER_SEC / 10000)) ? 10000 :
58 a < (UINT_MAX / (USEC_PER_SEC / 50000)) ? 50000 :
59 100000;
60 const u32 tmp = a * (USEC_PER_SEC / div);
61 return (b >= 2 * div) ? tmp / (b / div) : tmp;
52} 62}
53 63
54static int ccid3_debug; 64static int ccid3_debug;
@@ -102,8 +112,7 @@ static const char *ccid3_tx_state_name(enum ccid3_hc_tx_states state)
102static inline void ccid3_hc_tx_set_state(struct sock *sk, 112static inline void ccid3_hc_tx_set_state(struct sock *sk,
103 enum ccid3_hc_tx_states state) 113 enum ccid3_hc_tx_states state)
104{ 114{
105 struct dccp_sock *dp = dccp_sk(sk); 115 struct ccid3_hc_tx_sock *hctx = ccid3_hc_tx_sk(sk);
106 struct ccid3_hc_tx_sock *hctx = dp->dccps_hc_tx_ccid_private;
107 enum ccid3_hc_tx_states oldstate = hctx->ccid3hctx_state; 116 enum ccid3_hc_tx_states oldstate = hctx->ccid3hctx_state;
108 117
109 ccid3_pr_debug("%s(%p) %-8.8s -> %s\n", 118 ccid3_pr_debug("%s(%p) %-8.8s -> %s\n",
@@ -144,8 +153,7 @@ static inline void ccid3_calc_new_delta(struct ccid3_hc_tx_sock *hctx)
144 */ 153 */
145static void ccid3_hc_tx_update_x(struct sock *sk) 154static void ccid3_hc_tx_update_x(struct sock *sk)
146{ 155{
147 struct dccp_sock *dp = dccp_sk(sk); 156 struct ccid3_hc_tx_sock *hctx = ccid3_hc_tx_sk(sk);
148 struct ccid3_hc_tx_sock *hctx = dp->dccps_hc_tx_ccid_private;
149 157
150 /* To avoid large error in calcX */ 158 /* To avoid large error in calcX */
151 if (hctx->ccid3hctx_p >= TFRC_SMALLEST_P) { 159 if (hctx->ccid3hctx_p >= TFRC_SMALLEST_P) {
@@ -159,7 +167,7 @@ static void ccid3_hc_tx_update_x(struct sock *sk)
159 } else { 167 } else {
160 struct timeval now; 168 struct timeval now;
161 169
162 do_gettimeofday(&now); 170 dccp_timestamp(sk, &now);
163 if (timeval_delta(&now, &hctx->ccid3hctx_t_ld) >= 171 if (timeval_delta(&now, &hctx->ccid3hctx_t_ld) >=
164 hctx->ccid3hctx_rtt) { 172 hctx->ccid3hctx_rtt) {
165 hctx->ccid3hctx_x = max_t(u32, min_t(u32, hctx->ccid3hctx_x_recv, 173 hctx->ccid3hctx_x = max_t(u32, min_t(u32, hctx->ccid3hctx_x_recv,
@@ -174,9 +182,8 @@ static void ccid3_hc_tx_update_x(struct sock *sk)
174static void ccid3_hc_tx_no_feedback_timer(unsigned long data) 182static void ccid3_hc_tx_no_feedback_timer(unsigned long data)
175{ 183{
176 struct sock *sk = (struct sock *)data; 184 struct sock *sk = (struct sock *)data;
177 struct dccp_sock *dp = dccp_sk(sk);
178 unsigned long next_tmout = 0; 185 unsigned long next_tmout = 0;
179 struct ccid3_hc_tx_sock *hctx = dp->dccps_hc_tx_ccid_private; 186 struct ccid3_hc_tx_sock *hctx = ccid3_hc_tx_sk(sk);
180 187
181 bh_lock_sock(sk); 188 bh_lock_sock(sk);
182 if (sock_owned_by_user(sk)) { 189 if (sock_owned_by_user(sk)) {
@@ -274,7 +281,7 @@ static int ccid3_hc_tx_send_packet(struct sock *sk,
274 struct sk_buff *skb, int len) 281 struct sk_buff *skb, int len)
275{ 282{
276 struct dccp_sock *dp = dccp_sk(sk); 283 struct dccp_sock *dp = dccp_sk(sk);
277 struct ccid3_hc_tx_sock *hctx = dp->dccps_hc_tx_ccid_private; 284 struct ccid3_hc_tx_sock *hctx = ccid3_hc_tx_sk(sk);
278 struct dccp_tx_hist_entry *new_packet; 285 struct dccp_tx_hist_entry *new_packet;
279 struct timeval now; 286 struct timeval now;
280 long delay; 287 long delay;
@@ -307,7 +314,7 @@ static int ccid3_hc_tx_send_packet(struct sock *sk,
307 dccp_tx_hist_add_entry(&hctx->ccid3hctx_hist, new_packet); 314 dccp_tx_hist_add_entry(&hctx->ccid3hctx_hist, new_packet);
308 } 315 }
309 316
310 do_gettimeofday(&now); 317 dccp_timestamp(sk, &now);
311 318
312 switch (hctx->ccid3hctx_state) { 319 switch (hctx->ccid3hctx_state) {
313 case TFRC_SSTATE_NO_SENT: 320 case TFRC_SSTATE_NO_SENT:
@@ -348,18 +355,20 @@ static int ccid3_hc_tx_send_packet(struct sock *sk,
348 } 355 }
349 356
350 /* Can we send? if so add options and add to packet history */ 357 /* Can we send? if so add options and add to packet history */
351 if (rc == 0) 358 if (rc == 0) {
359 dp->dccps_hc_tx_insert_options = 1;
352 new_packet->dccphtx_ccval = 360 new_packet->dccphtx_ccval =
353 DCCP_SKB_CB(skb)->dccpd_ccval = 361 DCCP_SKB_CB(skb)->dccpd_ccval =
354 hctx->ccid3hctx_last_win_count; 362 hctx->ccid3hctx_last_win_count;
363 }
355out: 364out:
356 return rc; 365 return rc;
357} 366}
358 367
359static void ccid3_hc_tx_packet_sent(struct sock *sk, int more, int len) 368static void ccid3_hc_tx_packet_sent(struct sock *sk, int more, int len)
360{ 369{
361 struct dccp_sock *dp = dccp_sk(sk); 370 const struct dccp_sock *dp = dccp_sk(sk);
362 struct ccid3_hc_tx_sock *hctx = dp->dccps_hc_tx_ccid_private; 371 struct ccid3_hc_tx_sock *hctx = ccid3_hc_tx_sk(sk);
363 struct timeval now; 372 struct timeval now;
364 373
365 BUG_ON(hctx == NULL); 374 BUG_ON(hctx == NULL);
@@ -370,7 +379,7 @@ static void ccid3_hc_tx_packet_sent(struct sock *sk, int more, int len)
370 return; 379 return;
371 } 380 }
372 381
373 do_gettimeofday(&now); 382 dccp_timestamp(sk, &now);
374 383
375 /* check if we have sent a data packet */ 384 /* check if we have sent a data packet */
376 if (len > 0) { 385 if (len > 0) {
@@ -445,10 +454,11 @@ static void ccid3_hc_tx_packet_sent(struct sock *sk, int more, int len)
445 454
446static void ccid3_hc_tx_packet_recv(struct sock *sk, struct sk_buff *skb) 455static void ccid3_hc_tx_packet_recv(struct sock *sk, struct sk_buff *skb)
447{ 456{
448 struct dccp_sock *dp = dccp_sk(sk); 457 const struct dccp_sock *dp = dccp_sk(sk);
449 struct ccid3_hc_tx_sock *hctx = dp->dccps_hc_tx_ccid_private; 458 struct ccid3_hc_tx_sock *hctx = ccid3_hc_tx_sk(sk);
450 struct ccid3_options_received *opt_recv; 459 struct ccid3_options_received *opt_recv;
451 struct dccp_tx_hist_entry *packet; 460 struct dccp_tx_hist_entry *packet;
461 struct timeval now;
452 unsigned long next_tmout; 462 unsigned long next_tmout;
453 u32 t_elapsed; 463 u32 t_elapsed;
454 u32 pinv; 464 u32 pinv;
@@ -471,7 +481,7 @@ static void ccid3_hc_tx_packet_recv(struct sock *sk, struct sk_buff *skb)
471 481
472 opt_recv = &hctx->ccid3hctx_options_received; 482 opt_recv = &hctx->ccid3hctx_options_received;
473 483
474 t_elapsed = dp->dccps_options_received.dccpor_elapsed_time; 484 t_elapsed = dp->dccps_options_received.dccpor_elapsed_time * 10;
475 x_recv = opt_recv->ccid3or_receive_rate; 485 x_recv = opt_recv->ccid3or_receive_rate;
476 pinv = opt_recv->ccid3or_loss_event_rate; 486 pinv = opt_recv->ccid3or_loss_event_rate;
477 487
@@ -496,9 +506,14 @@ static void ccid3_hc_tx_packet_recv(struct sock *sk, struct sk_buff *skb)
496 } 506 }
497 507
498 /* Update RTT */ 508 /* Update RTT */
499 r_sample = timeval_now_delta(&packet->dccphtx_tstamp); 509 dccp_timestamp(sk, &now);
500 /* FIXME: */ 510 r_sample = timeval_delta(&now, &packet->dccphtx_tstamp);
501 // r_sample -= usecs_to_jiffies(t_elapsed * 10); 511 if (unlikely(r_sample <= t_elapsed))
512 LIMIT_NETDEBUG(KERN_WARNING
513 "%s: r_sample=%uus, t_elapsed=%uus\n",
514 __FUNCTION__, r_sample, t_elapsed);
515 else
516 r_sample -= t_elapsed;
502 517
503 /* Update RTT estimate by 518 /* Update RTT estimate by
504 * If (No feedback recv) 519 * If (No feedback recv)
@@ -591,8 +606,7 @@ static void ccid3_hc_tx_packet_recv(struct sock *sk, struct sk_buff *skb)
591 606
592static void ccid3_hc_tx_insert_options(struct sock *sk, struct sk_buff *skb) 607static void ccid3_hc_tx_insert_options(struct sock *sk, struct sk_buff *skb)
593{ 608{
594 const struct dccp_sock *dp = dccp_sk(sk); 609 struct ccid3_hc_tx_sock *hctx = ccid3_hc_tx_sk(sk);
595 struct ccid3_hc_tx_sock *hctx = dp->dccps_hc_tx_ccid_private;
596 610
597 if (hctx == NULL || !(sk->sk_state == DCCP_OPEN || 611 if (hctx == NULL || !(sk->sk_state == DCCP_OPEN ||
598 sk->sk_state == DCCP_PARTOPEN)) 612 sk->sk_state == DCCP_PARTOPEN))
@@ -606,8 +620,8 @@ static int ccid3_hc_tx_parse_options(struct sock *sk, unsigned char option,
606 unsigned char *value) 620 unsigned char *value)
607{ 621{
608 int rc = 0; 622 int rc = 0;
609 struct dccp_sock *dp = dccp_sk(sk); 623 const struct dccp_sock *dp = dccp_sk(sk);
610 struct ccid3_hc_tx_sock *hctx = dp->dccps_hc_tx_ccid_private; 624 struct ccid3_hc_tx_sock *hctx = ccid3_hc_tx_sk(sk);
611 struct ccid3_options_received *opt_recv; 625 struct ccid3_options_received *opt_recv;
612 626
613 if (hctx == NULL) 627 if (hctx == NULL)
@@ -670,11 +684,11 @@ static int ccid3_hc_tx_init(struct sock *sk)
670 684
671 ccid3_pr_debug("%s, sk=%p\n", dccp_role(sk), sk); 685 ccid3_pr_debug("%s, sk=%p\n", dccp_role(sk), sk);
672 686
673 hctx = dp->dccps_hc_tx_ccid_private = kmalloc(sizeof(*hctx), 687 dp->dccps_hc_tx_ccid_private = kmalloc(sizeof(*hctx), gfp_any());
674 gfp_any()); 688 if (dp->dccps_hc_tx_ccid_private == NULL)
675 if (hctx == NULL)
676 return -ENOMEM; 689 return -ENOMEM;
677 690
691 hctx = ccid3_hc_tx_sk(sk);
678 memset(hctx, 0, sizeof(*hctx)); 692 memset(hctx, 0, sizeof(*hctx));
679 693
680 if (dp->dccps_packet_size >= TFRC_MIN_PACKET_SIZE && 694 if (dp->dccps_packet_size >= TFRC_MIN_PACKET_SIZE &&
@@ -696,7 +710,7 @@ static int ccid3_hc_tx_init(struct sock *sk)
696static void ccid3_hc_tx_exit(struct sock *sk) 710static void ccid3_hc_tx_exit(struct sock *sk)
697{ 711{
698 struct dccp_sock *dp = dccp_sk(sk); 712 struct dccp_sock *dp = dccp_sk(sk);
699 struct ccid3_hc_tx_sock *hctx = dp->dccps_hc_tx_ccid_private; 713 struct ccid3_hc_tx_sock *hctx = ccid3_hc_tx_sk(sk);
700 714
701 ccid3_pr_debug("%s, sk=%p\n", dccp_role(sk), sk); 715 ccid3_pr_debug("%s, sk=%p\n", dccp_role(sk), sk);
702 BUG_ON(hctx == NULL); 716 BUG_ON(hctx == NULL);
@@ -738,8 +752,7 @@ static const char *ccid3_rx_state_name(enum ccid3_hc_rx_states state)
738static inline void ccid3_hc_rx_set_state(struct sock *sk, 752static inline void ccid3_hc_rx_set_state(struct sock *sk,
739 enum ccid3_hc_rx_states state) 753 enum ccid3_hc_rx_states state)
740{ 754{
741 struct dccp_sock *dp = dccp_sk(sk); 755 struct ccid3_hc_rx_sock *hcrx = ccid3_hc_rx_sk(sk);
742 struct ccid3_hc_rx_sock *hcrx = dp->dccps_hc_rx_ccid_private;
743 enum ccid3_hc_rx_states oldstate = hcrx->ccid3hcrx_state; 756 enum ccid3_hc_rx_states oldstate = hcrx->ccid3hcrx_state;
744 757
745 ccid3_pr_debug("%s(%p) %-8.8s -> %s\n", 758 ccid3_pr_debug("%s(%p) %-8.8s -> %s\n",
@@ -751,14 +764,14 @@ static inline void ccid3_hc_rx_set_state(struct sock *sk,
751 764
752static void ccid3_hc_rx_send_feedback(struct sock *sk) 765static void ccid3_hc_rx_send_feedback(struct sock *sk)
753{ 766{
767 struct ccid3_hc_rx_sock *hcrx = ccid3_hc_rx_sk(sk);
754 struct dccp_sock *dp = dccp_sk(sk); 768 struct dccp_sock *dp = dccp_sk(sk);
755 struct ccid3_hc_rx_sock *hcrx = dp->dccps_hc_rx_ccid_private;
756 struct dccp_rx_hist_entry *packet; 769 struct dccp_rx_hist_entry *packet;
757 struct timeval now; 770 struct timeval now;
758 771
759 ccid3_pr_debug("%s, sk=%p\n", dccp_role(sk), sk); 772 ccid3_pr_debug("%s, sk=%p\n", dccp_role(sk), sk);
760 773
761 do_gettimeofday(&now); 774 dccp_timestamp(sk, &now);
762 775
763 switch (hcrx->ccid3hcrx_state) { 776 switch (hcrx->ccid3hcrx_state) {
764 case TFRC_RSTATE_NO_DATA: 777 case TFRC_RSTATE_NO_DATA:
@@ -767,11 +780,8 @@ static void ccid3_hc_rx_send_feedback(struct sock *sk)
767 case TFRC_RSTATE_DATA: { 780 case TFRC_RSTATE_DATA: {
768 const u32 delta = timeval_delta(&now, 781 const u32 delta = timeval_delta(&now,
769 &hcrx->ccid3hcrx_tstamp_last_feedback); 782 &hcrx->ccid3hcrx_tstamp_last_feedback);
770 783 hcrx->ccid3hcrx_x_recv = usecs_div(hcrx->ccid3hcrx_bytes_recv,
771 hcrx->ccid3hcrx_x_recv = (hcrx->ccid3hcrx_bytes_recv * 784 delta);
772 USEC_PER_SEC);
773 if (likely(delta > 1))
774 hcrx->ccid3hcrx_x_recv /= delta;
775 } 785 }
776 break; 786 break;
777 default: 787 default:
@@ -801,14 +811,14 @@ static void ccid3_hc_rx_send_feedback(struct sock *sk)
801 hcrx->ccid3hcrx_pinv = ~0; 811 hcrx->ccid3hcrx_pinv = ~0;
802 else 812 else
803 hcrx->ccid3hcrx_pinv = 1000000 / hcrx->ccid3hcrx_p; 813 hcrx->ccid3hcrx_pinv = 1000000 / hcrx->ccid3hcrx_p;
814 dp->dccps_hc_rx_insert_options = 1;
804 dccp_send_ack(sk); 815 dccp_send_ack(sk);
805} 816}
806 817
807static void ccid3_hc_rx_insert_options(struct sock *sk, struct sk_buff *skb) 818static void ccid3_hc_rx_insert_options(struct sock *sk, struct sk_buff *skb)
808{ 819{
809 const struct dccp_sock *dp = dccp_sk(sk); 820 struct ccid3_hc_rx_sock *hcrx = ccid3_hc_rx_sk(sk);
810 u32 x_recv, pinv; 821 u32 x_recv, pinv;
811 struct ccid3_hc_rx_sock *hcrx = dp->dccps_hc_rx_ccid_private;
812 822
813 if (hcrx == NULL || !(sk->sk_state == DCCP_OPEN || 823 if (hcrx == NULL || !(sk->sk_state == DCCP_OPEN ||
814 sk->sk_state == DCCP_PARTOPEN)) 824 sk->sk_state == DCCP_PARTOPEN))
@@ -837,8 +847,7 @@ static void ccid3_hc_rx_insert_options(struct sock *sk, struct sk_buff *skb)
837 847
838static u32 ccid3_hc_rx_calc_first_li(struct sock *sk) 848static u32 ccid3_hc_rx_calc_first_li(struct sock *sk)
839{ 849{
840 struct dccp_sock *dp = dccp_sk(sk); 850 struct ccid3_hc_rx_sock *hcrx = ccid3_hc_rx_sk(sk);
841 struct ccid3_hc_rx_sock *hcrx = dp->dccps_hc_rx_ccid_private;
842 struct dccp_rx_hist_entry *entry, *next, *tail = NULL; 851 struct dccp_rx_hist_entry *entry, *next, *tail = NULL;
843 u32 rtt, delta, x_recv, fval, p, tmp2; 852 u32 rtt, delta, x_recv, fval, p, tmp2;
844 struct timeval tstamp = { 0, }; 853 struct timeval tstamp = { 0, };
@@ -889,10 +898,9 @@ found:
889 if (rtt == 0) 898 if (rtt == 0)
890 rtt = 1; 899 rtt = 1;
891 900
892 delta = timeval_now_delta(&hcrx->ccid3hcrx_tstamp_last_feedback); 901 dccp_timestamp(sk, &tstamp);
893 x_recv = hcrx->ccid3hcrx_bytes_recv * USEC_PER_SEC; 902 delta = timeval_delta(&tstamp, &hcrx->ccid3hcrx_tstamp_last_feedback);
894 if (likely(delta > 1)) 903 x_recv = usecs_div(hcrx->ccid3hcrx_bytes_recv, delta);
895 x_recv /= delta;
896 904
897 tmp1 = (u64)x_recv * (u64)rtt; 905 tmp1 = (u64)x_recv * (u64)rtt;
898 do_div(tmp1,10000000); 906 do_div(tmp1,10000000);
@@ -911,8 +919,7 @@ found:
911 919
912static void ccid3_hc_rx_update_li(struct sock *sk, u64 seq_loss, u8 win_loss) 920static void ccid3_hc_rx_update_li(struct sock *sk, u64 seq_loss, u8 win_loss)
913{ 921{
914 struct dccp_sock *dp = dccp_sk(sk); 922 struct ccid3_hc_rx_sock *hcrx = ccid3_hc_rx_sk(sk);
915 struct ccid3_hc_rx_sock *hcrx = dp->dccps_hc_rx_ccid_private;
916 923
917 if (seq_loss != DCCP_MAX_SEQNO + 1 && 924 if (seq_loss != DCCP_MAX_SEQNO + 1 &&
918 list_empty(&hcrx->ccid3hcrx_li_hist)) { 925 list_empty(&hcrx->ccid3hcrx_li_hist)) {
@@ -930,8 +937,7 @@ static void ccid3_hc_rx_update_li(struct sock *sk, u64 seq_loss, u8 win_loss)
930 937
931static void ccid3_hc_rx_detect_loss(struct sock *sk) 938static void ccid3_hc_rx_detect_loss(struct sock *sk)
932{ 939{
933 struct dccp_sock *dp = dccp_sk(sk); 940 struct ccid3_hc_rx_sock *hcrx = ccid3_hc_rx_sk(sk);
934 struct ccid3_hc_rx_sock *hcrx = dp->dccps_hc_rx_ccid_private;
935 u8 win_loss; 941 u8 win_loss;
936 const u64 seq_loss = dccp_rx_hist_detect_loss(&hcrx->ccid3hcrx_hist, 942 const u64 seq_loss = dccp_rx_hist_detect_loss(&hcrx->ccid3hcrx_hist,
937 &hcrx->ccid3hcrx_li_hist, 943 &hcrx->ccid3hcrx_li_hist,
@@ -942,13 +948,12 @@ static void ccid3_hc_rx_detect_loss(struct sock *sk)
942 948
943static void ccid3_hc_rx_packet_recv(struct sock *sk, struct sk_buff *skb) 949static void ccid3_hc_rx_packet_recv(struct sock *sk, struct sk_buff *skb)
944{ 950{
945 struct dccp_sock *dp = dccp_sk(sk); 951 struct ccid3_hc_rx_sock *hcrx = ccid3_hc_rx_sk(sk);
946 struct ccid3_hc_rx_sock *hcrx = dp->dccps_hc_rx_ccid_private;
947 const struct dccp_options_received *opt_recv; 952 const struct dccp_options_received *opt_recv;
948 struct dccp_rx_hist_entry *packet; 953 struct dccp_rx_hist_entry *packet;
949 struct timeval now; 954 struct timeval now;
950 u8 win_count; 955 u8 win_count;
951 u32 p_prev; 956 u32 p_prev, r_sample, t_elapsed;
952 int ins; 957 int ins;
953 958
954 if (hcrx == NULL) 959 if (hcrx == NULL)
@@ -957,7 +962,7 @@ static void ccid3_hc_rx_packet_recv(struct sock *sk, struct sk_buff *skb)
957 BUG_ON(!(hcrx->ccid3hcrx_state == TFRC_RSTATE_NO_DATA || 962 BUG_ON(!(hcrx->ccid3hcrx_state == TFRC_RSTATE_NO_DATA ||
958 hcrx->ccid3hcrx_state == TFRC_RSTATE_DATA)); 963 hcrx->ccid3hcrx_state == TFRC_RSTATE_DATA));
959 964
960 opt_recv = &dp->dccps_options_received; 965 opt_recv = &dccp_sk(sk)->dccps_options_received;
961 966
962 switch (DCCP_SKB_CB(skb)->dccpd_type) { 967 switch (DCCP_SKB_CB(skb)->dccpd_type) {
963 case DCCP_PKT_ACK: 968 case DCCP_PKT_ACK:
@@ -967,10 +972,24 @@ static void ccid3_hc_rx_packet_recv(struct sock *sk, struct sk_buff *skb)
967 if (opt_recv->dccpor_timestamp_echo == 0) 972 if (opt_recv->dccpor_timestamp_echo == 0)
968 break; 973 break;
969 p_prev = hcrx->ccid3hcrx_rtt; 974 p_prev = hcrx->ccid3hcrx_rtt;
970 do_gettimeofday(&now); 975 dccp_timestamp(sk, &now);
971 hcrx->ccid3hcrx_rtt = timeval_usecs(&now) - 976 timeval_sub_usecs(&now, opt_recv->dccpor_timestamp_echo * 10);
972 (opt_recv->dccpor_timestamp_echo - 977 r_sample = timeval_usecs(&now);
973 opt_recv->dccpor_elapsed_time) * 10; 978 t_elapsed = opt_recv->dccpor_elapsed_time * 10;
979
980 if (unlikely(r_sample <= t_elapsed))
981 LIMIT_NETDEBUG(KERN_WARNING
982 "%s: r_sample=%uus, t_elapsed=%uus\n",
983 __FUNCTION__, r_sample, t_elapsed);
984 else
985 r_sample -= t_elapsed;
986
987 if (hcrx->ccid3hcrx_state == TFRC_RSTATE_NO_DATA)
988 hcrx->ccid3hcrx_rtt = r_sample;
989 else
990 hcrx->ccid3hcrx_rtt = (hcrx->ccid3hcrx_rtt * 9) / 10 +
991 r_sample / 10;
992
974 if (p_prev != hcrx->ccid3hcrx_rtt) 993 if (p_prev != hcrx->ccid3hcrx_rtt)
975 ccid3_pr_debug("%s, New RTT=%luus, elapsed time=%u\n", 994 ccid3_pr_debug("%s, New RTT=%luus, elapsed time=%u\n",
976 dccp_role(sk), hcrx->ccid3hcrx_rtt, 995 dccp_role(sk), hcrx->ccid3hcrx_rtt,
@@ -985,7 +1004,7 @@ static void ccid3_hc_rx_packet_recv(struct sock *sk, struct sk_buff *skb)
985 return; 1004 return;
986 } 1005 }
987 1006
988 packet = dccp_rx_hist_entry_new(ccid3_rx_hist, opt_recv->dccpor_ndp, 1007 packet = dccp_rx_hist_entry_new(ccid3_rx_hist, sk, opt_recv->dccpor_ndp,
989 skb, SLAB_ATOMIC); 1008 skb, SLAB_ATOMIC);
990 if (packet == NULL) { 1009 if (packet == NULL) {
991 ccid3_pr_debug("%s, sk=%p, Not enough mem to add rx packet " 1010 ccid3_pr_debug("%s, sk=%p, Not enough mem to add rx packet "
@@ -1017,7 +1036,7 @@ static void ccid3_hc_rx_packet_recv(struct sock *sk, struct sk_buff *skb)
1017 if (ins != 0) 1036 if (ins != 0)
1018 break; 1037 break;
1019 1038
1020 do_gettimeofday(&now); 1039 dccp_timestamp(sk, &now);
1021 if (timeval_delta(&now, &hcrx->ccid3hcrx_tstamp_last_ack) >= 1040 if (timeval_delta(&now, &hcrx->ccid3hcrx_tstamp_last_ack) >=
1022 hcrx->ccid3hcrx_rtt) { 1041 hcrx->ccid3hcrx_rtt) {
1023 hcrx->ccid3hcrx_tstamp_last_ack = now; 1042 hcrx->ccid3hcrx_tstamp_last_ack = now;
@@ -1056,11 +1075,11 @@ static int ccid3_hc_rx_init(struct sock *sk)
1056 1075
1057 ccid3_pr_debug("%s, sk=%p\n", dccp_role(sk), sk); 1076 ccid3_pr_debug("%s, sk=%p\n", dccp_role(sk), sk);
1058 1077
1059 hcrx = dp->dccps_hc_rx_ccid_private = kmalloc(sizeof(*hcrx), 1078 dp->dccps_hc_rx_ccid_private = kmalloc(sizeof(*hcrx), gfp_any());
1060 gfp_any()); 1079 if (dp->dccps_hc_rx_ccid_private == NULL)
1061 if (hcrx == NULL)
1062 return -ENOMEM; 1080 return -ENOMEM;
1063 1081
1082 hcrx = ccid3_hc_rx_sk(sk);
1064 memset(hcrx, 0, sizeof(*hcrx)); 1083 memset(hcrx, 0, sizeof(*hcrx));
1065 1084
1066 if (dp->dccps_packet_size >= TFRC_MIN_PACKET_SIZE && 1085 if (dp->dccps_packet_size >= TFRC_MIN_PACKET_SIZE &&
@@ -1072,18 +1091,16 @@ static int ccid3_hc_rx_init(struct sock *sk)
1072 hcrx->ccid3hcrx_state = TFRC_RSTATE_NO_DATA; 1091 hcrx->ccid3hcrx_state = TFRC_RSTATE_NO_DATA;
1073 INIT_LIST_HEAD(&hcrx->ccid3hcrx_hist); 1092 INIT_LIST_HEAD(&hcrx->ccid3hcrx_hist);
1074 INIT_LIST_HEAD(&hcrx->ccid3hcrx_li_hist); 1093 INIT_LIST_HEAD(&hcrx->ccid3hcrx_li_hist);
1075 /* 1094 dccp_timestamp(sk, &hcrx->ccid3hcrx_tstamp_last_ack);
1076 * XXX this seems to be paranoid, need to think more about this, for 1095 hcrx->ccid3hcrx_tstamp_last_feedback = hcrx->ccid3hcrx_tstamp_last_ack;
1077 * now start with something different than zero. -acme 1096 hcrx->ccid3hcrx_rtt = 5000; /* XXX 5ms for now... */
1078 */
1079 hcrx->ccid3hcrx_rtt = USEC_PER_SEC / 5;
1080 return 0; 1097 return 0;
1081} 1098}
1082 1099
1083static void ccid3_hc_rx_exit(struct sock *sk) 1100static void ccid3_hc_rx_exit(struct sock *sk)
1084{ 1101{
1102 struct ccid3_hc_rx_sock *hcrx = ccid3_hc_rx_sk(sk);
1085 struct dccp_sock *dp = dccp_sk(sk); 1103 struct dccp_sock *dp = dccp_sk(sk);
1086 struct ccid3_hc_rx_sock *hcrx = dp->dccps_hc_rx_ccid_private;
1087 1104
1088 ccid3_pr_debug("%s, sk=%p\n", dccp_role(sk), sk); 1105 ccid3_pr_debug("%s, sk=%p\n", dccp_role(sk), sk);
1089 1106
@@ -1104,8 +1121,7 @@ static void ccid3_hc_rx_exit(struct sock *sk)
1104 1121
1105static void ccid3_hc_rx_get_info(struct sock *sk, struct tcp_info *info) 1122static void ccid3_hc_rx_get_info(struct sock *sk, struct tcp_info *info)
1106{ 1123{
1107 const struct dccp_sock *dp = dccp_sk(sk); 1124 const struct ccid3_hc_rx_sock *hcrx = ccid3_hc_rx_sk(sk);
1108 const struct ccid3_hc_rx_sock *hcrx = dp->dccps_hc_rx_ccid_private;
1109 1125
1110 if (hcrx == NULL) 1126 if (hcrx == NULL)
1111 return; 1127 return;
@@ -1117,8 +1133,7 @@ static void ccid3_hc_rx_get_info(struct sock *sk, struct tcp_info *info)
1117 1133
1118static void ccid3_hc_tx_get_info(struct sock *sk, struct tcp_info *info) 1134static void ccid3_hc_tx_get_info(struct sock *sk, struct tcp_info *info)
1119{ 1135{
1120 const struct dccp_sock *dp = dccp_sk(sk); 1136 const struct ccid3_hc_tx_sock *hctx = ccid3_hc_tx_sk(sk);
1121 const struct ccid3_hc_tx_sock *hctx = dp->dccps_hc_tx_ccid_private;
1122 1137
1123 if (hctx == NULL) 1138 if (hctx == NULL)
1124 return; 1139 return;
diff --git a/net/dccp/ccids/ccid3.h b/net/dccp/ccids/ccid3.h
index ee8cbace6630..d16f00d784f3 100644
--- a/net/dccp/ccids/ccid3.h
+++ b/net/dccp/ccids/ccid3.h
@@ -115,7 +115,7 @@ struct ccid3_hc_rx_sock {
115 u64 ccid3hcrx_seqno_last_counter:48, 115 u64 ccid3hcrx_seqno_last_counter:48,
116 ccid3hcrx_state:8, 116 ccid3hcrx_state:8,
117 ccid3hcrx_last_counter:4; 117 ccid3hcrx_last_counter:4;
118 unsigned long ccid3hcrx_rtt; 118 u32 ccid3hcrx_rtt;
119 u32 ccid3hcrx_p; 119 u32 ccid3hcrx_p;
120 u32 ccid3hcrx_bytes_recv; 120 u32 ccid3hcrx_bytes_recv;
121 struct timeval ccid3hcrx_tstamp_last_feedback; 121 struct timeval ccid3hcrx_tstamp_last_feedback;
@@ -128,10 +128,14 @@ struct ccid3_hc_rx_sock {
128 u32 ccid3hcrx_x_recv; 128 u32 ccid3hcrx_x_recv;
129}; 129};
130 130
131#define ccid3_hc_tx_field(s,field) (s->dccps_hc_tx_ccid_private == NULL ? 0 : \ 131static inline struct ccid3_hc_tx_sock *ccid3_hc_tx_sk(const struct sock *sk)
132 ((struct ccid3_hc_tx_sock *)s->dccps_hc_tx_ccid_private)->ccid3hctx_##field) 132{
133 return dccp_sk(sk)->dccps_hc_tx_ccid_private;
134}
133 135
134#define ccid3_hc_rx_field(s,field) (s->dccps_hc_rx_ccid_private == NULL ? 0 : \ 136static inline struct ccid3_hc_rx_sock *ccid3_hc_rx_sk(const struct sock *sk)
135 ((struct ccid3_hc_rx_sock *)s->dccps_hc_rx_ccid_private)->ccid3hcrx_##field) 137{
138 return dccp_sk(sk)->dccps_hc_rx_ccid_private;
139}
136 140
137#endif /* _DCCP_CCID3_H_ */ 141#endif /* _DCCP_CCID3_H_ */
diff --git a/net/dccp/ccids/lib/packet_history.h b/net/dccp/ccids/lib/packet_history.h
index fb90a91aa93d..b375ebdb7dcf 100644
--- a/net/dccp/ccids/lib/packet_history.h
+++ b/net/dccp/ccids/lib/packet_history.h
@@ -134,6 +134,7 @@ static inline struct dccp_tx_hist_entry *
134 134
135static inline struct dccp_rx_hist_entry * 135static inline struct dccp_rx_hist_entry *
136 dccp_rx_hist_entry_new(struct dccp_rx_hist *hist, 136 dccp_rx_hist_entry_new(struct dccp_rx_hist *hist,
137 const struct sock *sk,
137 const u32 ndp, 138 const u32 ndp,
138 const struct sk_buff *skb, 139 const struct sk_buff *skb,
139 const unsigned int __nocast prio) 140 const unsigned int __nocast prio)
@@ -148,7 +149,7 @@ static inline struct dccp_rx_hist_entry *
148 entry->dccphrx_ccval = dh->dccph_ccval; 149 entry->dccphrx_ccval = dh->dccph_ccval;
149 entry->dccphrx_type = dh->dccph_type; 150 entry->dccphrx_type = dh->dccph_type;
150 entry->dccphrx_ndp = ndp; 151 entry->dccphrx_ndp = ndp;
151 do_gettimeofday(&(entry->dccphrx_tstamp)); 152 dccp_timestamp(sk, &entry->dccphrx_tstamp);
152 } 153 }
153 154
154 return entry; 155 return entry;