[TFRC]: Hide tx history details from the CCIDs
[deliverable/linux.git] / net / dccp / ccids / ccid3.c
index e91c2b9dc27b47146be86fc27a41c2efc80aeb25..49338370eb047c027e172cc63cdb05cb8eef2100 100644 (file)
@@ -40,6 +40,8 @@
 #include "lib/tfrc.h"
 #include "ccid3.h"
 
+#include <asm/unaligned.h>
+
 #ifdef CONFIG_IP_DCCP_CCID3_DEBUG
 static int ccid3_debug;
 #define ccid3_pr_debug(format, a...)   DCCP_PR_DEBUG(ccid3_debug, format, ##a)
@@ -47,7 +49,6 @@ static int ccid3_debug;
 #define ccid3_pr_debug(format, a...)
 #endif
 
-static struct dccp_tx_hist *ccid3_tx_hist;
 static struct dccp_rx_hist *ccid3_rx_hist;
 
 /*
@@ -81,18 +82,21 @@ static void ccid3_hc_tx_set_state(struct sock *sk,
 }
 
 /*
- * Compute the initial sending rate X_init according to RFC 3390:
- *     w_init   =    min(4 * MSS, max(2 * MSS, 4380 bytes))
- *     X_init   =    w_init / RTT
+ * Compute the initial sending rate X_init in the manner of RFC 3390:
+ *
+ *     X_init  =  min(4 * s, max(2 * s, 4380 bytes)) / RTT
+ *
+ * Note that RFC 3390 uses MSS, RFC 4342 refers to RFC 3390, and rfc3448bis
+ * (rev-02) clarifies the use of RFC 3390 with regard to the above formula.
  * For consistency with other parts of the code, X_init is scaled by 2^6.
  */
 static inline u64 rfc3390_initial_rate(struct sock *sk)
 {
-       const struct dccp_sock *dp = dccp_sk(sk);
-       const __u32 w_init = min(4 * dp->dccps_mss_cache,
-                                max(2 * dp->dccps_mss_cache, 4380U));
+       const struct ccid3_hc_tx_sock *hctx = ccid3_hc_tx_sk(sk);
+       const __u32 w_init = min_t(__u32, 4 * hctx->ccid3hctx_s,
+                                  max_t(__u32, 2 * hctx->ccid3hctx_s, 4380));
 
-       return scaled_div(w_init << 6, ccid3_hc_tx_sk(sk)->ccid3hctx_rtt);
+       return scaled_div(w_init << 6, hctx->ccid3hctx_rtt);
 }
 
 /*
@@ -113,34 +117,39 @@ static inline void ccid3_update_send_interval(struct ccid3_hc_tx_sock *hctx)
                       hctx->ccid3hctx_s, (unsigned)(hctx->ccid3hctx_x >> 6));
 
 }
-/*
- * Update X by
- *    If (p > 0)
- *       X_calc = calcX(s, R, p);
- *       X = max(min(X_calc, 2 * X_recv), s / t_mbi);
- *    Else
- *       If (now - tld >= R)
- *          X = max(min(2 * X, 2 * X_recv), s / R);
- *          tld = now;
+
+static u32 ccid3_hc_tx_idle_rtt(struct ccid3_hc_tx_sock *hctx, ktime_t now)
+{
+       u32 delta = ktime_us_delta(now, hctx->ccid3hctx_t_last_win_count);
+
+       return delta / hctx->ccid3hctx_rtt;
+}
+
+/**
+ * ccid3_hc_tx_update_x  -  Update allowed sending rate X
+ * @stamp: most recent time if available - can be left NULL.
+ * This function tracks draft rfc3448bis, check there for latest details.
  *
  * Note: X and X_recv are both stored in units of 64 * bytes/second, to support
  *       fine-grained resolution of sending rates. This requires scaling by 2^6
  *       throughout the code. Only X_calc is unscaled (in bytes/second).
  *
  */
-static void ccid3_hc_tx_update_x(struct sock *sk, struct timeval *now)
+static void ccid3_hc_tx_update_x(struct sock *sk, ktime_t *stamp)
 
 {
        struct ccid3_hc_tx_sock *hctx = ccid3_hc_tx_sk(sk);
        __u64 min_rate = 2 * hctx->ccid3hctx_x_recv;
        const  __u64 old_x = hctx->ccid3hctx_x;
+       ktime_t now = stamp? *stamp : ktime_get_real();
 
        /*
         * Handle IDLE periods: do not reduce below RFC3390 initial sending rate
-        * when idling [RFC 4342, 5.1]. See also draft-ietf-dccp-rfc3448bis.
+        * when idling [RFC 4342, 5.1]. Definition of idling is from rfc3448bis:
+        * a sender is idle if it has not sent anything over a 2-RTT-period.
         * For consistency with X and X_recv, min_rate is also scaled by 2^6.
         */
-       if (unlikely(hctx->ccid3hctx_idle)) {
+       if (ccid3_hc_tx_idle_rtt(hctx, now) >= 2) {
                min_rate = rfc3390_initial_rate(sk);
                min_rate = max(min_rate, 2 * hctx->ccid3hctx_x_recv);
        }
@@ -153,14 +162,14 @@ static void ccid3_hc_tx_update_x(struct sock *sk, struct timeval *now)
                                        (((__u64)hctx->ccid3hctx_s) << 6) /
                                                                TFRC_T_MBI);
 
-       } else if (timeval_delta(now, &hctx->ccid3hctx_t_ld) -
-                       (suseconds_t)hctx->ccid3hctx_rtt >= 0) {
+       } else if (ktime_us_delta(now, hctx->ccid3hctx_t_ld)
+                               - (s64)hctx->ccid3hctx_rtt >= 0) {
 
                hctx->ccid3hctx_x =
                        max(min(2 * hctx->ccid3hctx_x, min_rate),
                            scaled_div(((__u64)hctx->ccid3hctx_s) << 6,
                                       hctx->ccid3hctx_rtt));
-               hctx->ccid3hctx_t_ld = *now;
+               hctx->ccid3hctx_t_ld = now;
        }
 
        if (hctx->ccid3hctx_x != old_x) {
@@ -182,7 +191,7 @@ static inline void ccid3_hc_tx_update_s(struct ccid3_hc_tx_sock *hctx, int len)
 {
        const u16 old_s = hctx->ccid3hctx_s;
 
-       hctx->ccid3hctx_s = old_s == 0 ? len : (9 * old_s + len) / 10;
+       hctx->ccid3hctx_s = tfrc_ewma(hctx->ccid3hctx_s, len, 9);
 
        if (hctx->ccid3hctx_s != old_s)
                ccid3_update_send_interval(hctx);
@@ -214,7 +223,6 @@ static void ccid3_hc_tx_no_feedback_timer(unsigned long data)
 {
        struct sock *sk = (struct sock *)data;
        struct ccid3_hc_tx_sock *hctx = ccid3_hc_tx_sk(sk);
-       struct timeval now;
        unsigned long t_nfb = USEC_PER_SEC / 5;
 
        bh_lock_sock(sk);
@@ -227,8 +235,6 @@ static void ccid3_hc_tx_no_feedback_timer(unsigned long data)
        ccid3_pr_debug("%s(%p, state=%s) - entry \n", dccp_role(sk), sk,
                       ccid3_tx_state_name(hctx->ccid3hctx_state));
 
-       hctx->ccid3hctx_idle = 1;
-
        switch (hctx->ccid3hctx_state) {
        case TFRC_SSTATE_NO_FBACK:
                /* RFC 3448, 4.4: Halve send rate directly */
@@ -241,7 +247,7 @@ static void ccid3_hc_tx_no_feedback_timer(unsigned long data)
                               ccid3_tx_state_name(hctx->ccid3hctx_state),
                               (unsigned)(hctx->ccid3hctx_x >> 6));
                /* The value of R is still undefined and so we can not recompute
-                * the timout value. Keep initial value as per [RFC 4342, 5]. */
+                * the timeout value. Keep initial value as per [RFC 4342, 5]. */
                t_nfb = TFRC_INITIAL_TIMEOUT;
                ccid3_update_send_interval(hctx);
                break;
@@ -265,15 +271,12 @@ static void ccid3_hc_tx_no_feedback_timer(unsigned long data)
                                max(hctx->ccid3hctx_x_recv / 2,
                                    (((__u64)hctx->ccid3hctx_s) << 6) /
                                                              (2 * TFRC_T_MBI));
-
-                       if (hctx->ccid3hctx_p == 0)
-                               dccp_timestamp(sk, &now);
                } else {
                        hctx->ccid3hctx_x_recv = hctx->ccid3hctx_x_calc;
                        hctx->ccid3hctx_x_recv <<= 4;
                }
                /* Now recalculate X [RFC 3448, 4.3, step (4)] */
-               ccid3_hc_tx_update_x(sk, &now);
+               ccid3_hc_tx_update_x(sk, NULL);
                /*
                 * Schedule no feedback timer to expire in
                 * max(t_RTO, 2 * s/X)  =  max(t_RTO, 2 * t_ipi)
@@ -309,8 +312,6 @@ static int ccid3_hc_tx_send_packet(struct sock *sk, struct sk_buff *skb)
        ktime_t now = ktime_get_real();
        s64 delay;
 
-       BUG_ON(hctx == NULL);
-
        /*
         * This function is called only for Data and DataAck packets. Sending
         * zero-sized Data(Ack)s is theoretically possible, but for congestion
@@ -341,10 +342,10 @@ static int ccid3_hc_tx_send_packet(struct sock *sk, struct sk_buff *skb)
                        ccid3_pr_debug("SYN RTT = %uus\n", dp->dccps_syn_rtt);
                        hctx->ccid3hctx_rtt  = dp->dccps_syn_rtt;
                        hctx->ccid3hctx_x    = rfc3390_initial_rate(sk);
-                       hctx->ccid3hctx_t_ld = ktime_to_timeval(now);
+                       hctx->ccid3hctx_t_ld = now;
                } else {
-                       /* Sender does not have RTT sample: X = MSS/second */
-                       hctx->ccid3hctx_x = dp->dccps_mss_cache;
+                       /* Sender does not have RTT sample: X_pps = 1 pkt/sec */
+                       hctx->ccid3hctx_x = hctx->ccid3hctx_s;
                        hctx->ccid3hctx_x <<= 6;
                }
                ccid3_update_send_interval(hctx);
@@ -376,7 +377,6 @@ static int ccid3_hc_tx_send_packet(struct sock *sk, struct sk_buff *skb)
        /* prepare to send now (add options etc.) */
        dp->dccps_hc_tx_insert_options = 1;
        DCCP_SKB_CB(skb)->dccpd_ccval = hctx->ccid3hctx_last_win_count;
-       hctx->ccid3hctx_idle = 0;
 
        /* set the nominal send time for the next following packet */
        hctx->ccid3hctx_t_nom = ktime_add_us(hctx->ccid3hctx_t_nom,
@@ -388,38 +388,21 @@ static void ccid3_hc_tx_packet_sent(struct sock *sk, int more,
                                    unsigned int len)
 {
        struct ccid3_hc_tx_sock *hctx = ccid3_hc_tx_sk(sk);
-       struct timeval now;
-       struct dccp_tx_hist_entry *packet;
-
-       BUG_ON(hctx == NULL);
 
        ccid3_hc_tx_update_s(hctx, len);
 
-       packet = dccp_tx_hist_entry_new(ccid3_tx_hist, GFP_ATOMIC);
-       if (unlikely(packet == NULL)) {
+       if (tfrc_tx_hist_add(&hctx->ccid3hctx_hist, dccp_sk(sk)->dccps_gss))
                DCCP_CRIT("packet history - out of memory!");
-               return;
-       }
-       dccp_tx_hist_add_entry(&hctx->ccid3hctx_hist, packet);
-
-       dccp_timestamp(sk, &now);
-       packet->dccphtx_tstamp = now;
-       packet->dccphtx_seqno  = dccp_sk(sk)->dccps_gss;
-       packet->dccphtx_rtt    = hctx->ccid3hctx_rtt;
-       packet->dccphtx_sent   = 1;
 }
 
 static void ccid3_hc_tx_packet_recv(struct sock *sk, struct sk_buff *skb)
 {
        struct ccid3_hc_tx_sock *hctx = ccid3_hc_tx_sk(sk);
        struct ccid3_options_received *opt_recv;
-       struct dccp_tx_hist_entry *packet;
-       struct timeval now;
+       ktime_t now;
        unsigned long t_nfb;
        u32 pinv, r_sample;
 
-       BUG_ON(hctx == NULL);
-
        /* we are only interested in ACKs */
        if (!(DCCP_SKB_CB(skb)->dccpd_type == DCCP_PKT_ACK ||
              DCCP_SKB_CB(skb)->dccpd_type == DCCP_PKT_DATAACK))
@@ -430,14 +413,15 @@ static void ccid3_hc_tx_packet_recv(struct sock *sk, struct sk_buff *skb)
        switch (hctx->ccid3hctx_state) {
        case TFRC_SSTATE_NO_FBACK:
        case TFRC_SSTATE_FBACK:
-               /* get packet from history to look up t_recvdata */
-               packet = dccp_tx_hist_find_entry(&hctx->ccid3hctx_hist,
-                                             DCCP_SKB_CB(skb)->dccpd_ack_seq);
-               if (unlikely(packet == NULL)) {
-                       DCCP_WARN("%s(%p), seqno %llu(%s) doesn't exist "
-                                 "in history!\n",  dccp_role(sk), sk,
-                           (unsigned long long)DCCP_SKB_CB(skb)->dccpd_ack_seq,
-                               dccp_packet_name(DCCP_SKB_CB(skb)->dccpd_type));
+               now = ktime_get_real();
+
+               /* estimate RTT from history if ACK number is valid */
+               r_sample = tfrc_tx_hist_rtt(hctx->ccid3hctx_hist,
+                                           DCCP_SKB_CB(skb)->dccpd_ack_seq, now);
+               if (r_sample == 0) {
+                       DCCP_WARN("%s(%p): %s with bogus ACK-%llu\n", dccp_role(sk), sk,
+                                 dccp_packet_name(DCCP_SKB_CB(skb)->dccpd_type),
+                                 (unsigned long long)DCCP_SKB_CB(skb)->dccpd_ack_seq);
                        return;
                }
 
@@ -451,29 +435,16 @@ static void ccid3_hc_tx_packet_recv(struct sock *sk, struct sk_buff *skb)
                        hctx->ccid3hctx_p = 0;
                else                                   /* can not exceed 100% */
                        hctx->ccid3hctx_p = 1000000 / pinv;
-
-               dccp_timestamp(sk, &now);
-
                /*
-                * Calculate new round trip sample as per [RFC 3448, 4.3] by
-                *      R_sample  =  (now - t_recvdata) - t_elapsed
+                * Validate new RTT sample and update moving average
                 */
-               r_sample = dccp_sample_rtt(sk, &now, &packet->dccphtx_tstamp);
+               r_sample = dccp_sample_rtt(sk, r_sample);
+               hctx->ccid3hctx_rtt = tfrc_ewma(hctx->ccid3hctx_rtt, r_sample, 9);
 
-               /*
-                * Update RTT estimate by
-                * If (No feedback recv)
-                *    R = R_sample;
-                * Else
-                *    R = q * R + (1 - q) * R_sample;
-                *
-                * q is a constant, RFC 3448 recomments 0.9
-                */
                if (hctx->ccid3hctx_state == TFRC_SSTATE_NO_FBACK) {
                        /*
                         * Larger Initial Windows [RFC 4342, sec. 5]
                         */
-                       hctx->ccid3hctx_rtt  = r_sample;
                        hctx->ccid3hctx_x    = rfc3390_initial_rate(sk);
                        hctx->ccid3hctx_t_ld = now;
 
@@ -487,8 +458,6 @@ static void ccid3_hc_tx_packet_recv(struct sock *sk, struct sk_buff *skb)
 
                        ccid3_hc_tx_set_state(sk, TFRC_SSTATE_FBACK);
                } else {
-                       hctx->ccid3hctx_rtt = (9 * hctx->ccid3hctx_rtt +
-                                                  r_sample) / 10;
 
                        /* Update sending rate (step 4 of [RFC 3448, 4.3]) */
                        if (hctx->ccid3hctx_p > 0)
@@ -511,9 +480,6 @@ static void ccid3_hc_tx_packet_recv(struct sock *sk, struct sk_buff *skb)
                /* unschedule no feedback timer */
                sk_stop_timer(sk, &hctx->ccid3hctx_no_feedback_timer);
 
-               /* remove all packets older than the one acked from history */
-               dccp_tx_hist_purge_older(ccid3_tx_hist,
-                                        &hctx->ccid3hctx_hist, packet);
                /*
                 * As we have calculated new ipi, delta, t_nom it is possible
                 * that we now can send a packet, so wake up dccp_wait_for_ccid
@@ -542,9 +508,6 @@ static void ccid3_hc_tx_packet_recv(struct sock *sk, struct sk_buff *skb)
 
                sk_reset_timer(sk, &hctx->ccid3hctx_no_feedback_timer,
                                   jiffies + usecs_to_jiffies(t_nfb));
-
-               /* set idle flag */
-               hctx->ccid3hctx_idle = 1;
                break;
        case TFRC_SSTATE_NO_SENT:       /* fall through */
        case TFRC_SSTATE_TERM:          /* ignore feedback when closing */
@@ -560,8 +523,7 @@ static int ccid3_hc_tx_parse_options(struct sock *sk, unsigned char option,
        const struct dccp_sock *dp = dccp_sk(sk);
        struct ccid3_hc_tx_sock *hctx = ccid3_hc_tx_sk(sk);
        struct ccid3_options_received *opt_recv;
-
-       BUG_ON(hctx == NULL);
+       __be32 opt_val;
 
        opt_recv = &hctx->ccid3hctx_options_received;
 
@@ -581,8 +543,8 @@ static int ccid3_hc_tx_parse_options(struct sock *sk, unsigned char option,
                                  dccp_role(sk), sk, len);
                        rc = -EINVAL;
                } else {
-                       opt_recv->ccid3or_loss_event_rate =
-                                               ntohl(*(__be32 *)value);
+                       opt_val = get_unaligned((__be32 *)value);
+                       opt_recv->ccid3or_loss_event_rate = ntohl(opt_val);
                        ccid3_pr_debug("%s(%p), LOSS_EVENT_RATE=%u\n",
                                       dccp_role(sk), sk,
                                       opt_recv->ccid3or_loss_event_rate);
@@ -603,8 +565,8 @@ static int ccid3_hc_tx_parse_options(struct sock *sk, unsigned char option,
                                  dccp_role(sk), sk, len);
                        rc = -EINVAL;
                } else {
-                       opt_recv->ccid3or_receive_rate =
-                                               ntohl(*(__be32 *)value);
+                       opt_val = get_unaligned((__be32 *)value);
+                       opt_recv->ccid3or_receive_rate = ntohl(opt_val);
                        ccid3_pr_debug("%s(%p), RECEIVE_RATE=%u\n",
                                       dccp_role(sk), sk,
                                       opt_recv->ccid3or_receive_rate);
@@ -619,15 +581,10 @@ static int ccid3_hc_tx_init(struct ccid *ccid, struct sock *sk)
 {
        struct ccid3_hc_tx_sock *hctx = ccid_priv(ccid);
 
-       hctx->ccid3hctx_s     = 0;
-       hctx->ccid3hctx_rtt   = 0;
        hctx->ccid3hctx_state = TFRC_SSTATE_NO_SENT;
-       INIT_LIST_HEAD(&hctx->ccid3hctx_hist);
-
-       hctx->ccid3hctx_no_feedback_timer.function =
-                               ccid3_hc_tx_no_feedback_timer;
-       hctx->ccid3hctx_no_feedback_timer.data     = (unsigned long)sk;
-       init_timer(&hctx->ccid3hctx_no_feedback_timer);
+       hctx->ccid3hctx_hist = NULL;
+       setup_timer(&hctx->ccid3hctx_no_feedback_timer,
+                       ccid3_hc_tx_no_feedback_timer, (unsigned long)sk);
 
        return 0;
 }
@@ -636,25 +593,21 @@ static void ccid3_hc_tx_exit(struct sock *sk)
 {
        struct ccid3_hc_tx_sock *hctx = ccid3_hc_tx_sk(sk);
 
-       BUG_ON(hctx == NULL);
-
        ccid3_hc_tx_set_state(sk, TFRC_SSTATE_TERM);
        sk_stop_timer(sk, &hctx->ccid3hctx_no_feedback_timer);
 
-       /* Empty packet history */
-       dccp_tx_hist_purge(ccid3_tx_hist, &hctx->ccid3hctx_hist);
+       tfrc_tx_hist_purge(&hctx->ccid3hctx_hist);
 }
 
 static void ccid3_hc_tx_get_info(struct sock *sk, struct tcp_info *info)
 {
-       const struct ccid3_hc_tx_sock *hctx = ccid3_hc_tx_sk(sk);
+       struct ccid3_hc_tx_sock *hctx;
 
        /* Listen socks doesn't have a private CCID block */
        if (sk->sk_state == DCCP_LISTEN)
                return;
 
-       BUG_ON(hctx == NULL);
-
+       hctx = ccid3_hc_tx_sk(sk);
        info->tcpi_rto = hctx->ccid3hctx_t_rto;
        info->tcpi_rtt = hctx->ccid3hctx_rtt;
 }
@@ -662,13 +615,14 @@ static void ccid3_hc_tx_get_info(struct sock *sk, struct tcp_info *info)
 static int ccid3_hc_tx_getsockopt(struct sock *sk, const int optname, int len,
                                  u32 __user *optval, int __user *optlen)
 {
-       const struct ccid3_hc_tx_sock *hctx = ccid3_hc_tx_sk(sk);
+       const struct ccid3_hc_tx_sock *hctx;
        const void *val;
 
        /* Listen socks doesn't have a private CCID block */
        if (sk->sk_state == DCCP_LISTEN)
                return -EINVAL;
 
+       hctx = ccid3_hc_tx_sk(sk);
        switch (optname) {
        case DCCP_SOCKOPT_CCID_TX_INFO:
                if (len < sizeof(hctx->ccid3hctx_tfrc))
@@ -717,11 +671,8 @@ static void ccid3_hc_rx_set_state(struct sock *sk,
 
 static inline void ccid3_hc_rx_update_s(struct ccid3_hc_rx_sock *hcrx, int len)
 {
-       if (unlikely(len == 0)) /* don't update on empty packets (e.g. ACKs) */
-               ccid3_pr_debug("Packet payload length is 0 - not updating\n");
-       else
-               hcrx->ccid3hcrx_s = hcrx->ccid3hcrx_s == 0 ? len :
-                                   (9 * hcrx->ccid3hcrx_s + len) / 10;
+       if (likely(len > 0))    /* don't update on empty packets (e.g. ACKs) */
+               hcrx->ccid3hcrx_s = tfrc_ewma(hcrx->ccid3hcrx_s, len, 9);
 }
 
 static void ccid3_hc_rx_send_feedback(struct sock *sk)
@@ -729,20 +680,20 @@ static void ccid3_hc_rx_send_feedback(struct sock *sk)
        struct ccid3_hc_rx_sock *hcrx = ccid3_hc_rx_sk(sk);
        struct dccp_sock *dp = dccp_sk(sk);
        struct dccp_rx_hist_entry *packet;
-       struct timeval now;
+       ktime_t now;
        suseconds_t delta;
 
        ccid3_pr_debug("%s(%p) - entry \n", dccp_role(sk), sk);
 
-       dccp_timestamp(sk, &now);
+       now = ktime_get_real();
 
        switch (hcrx->ccid3hcrx_state) {
        case TFRC_RSTATE_NO_DATA:
                hcrx->ccid3hcrx_x_recv = 0;
                break;
        case TFRC_RSTATE_DATA:
-               delta = timeval_delta(&now,
-                                     &hcrx->ccid3hcrx_tstamp_last_feedback);
+               delta = ktime_us_delta(now,
+                                      hcrx->ccid3hcrx_tstamp_last_feedback);
                DCCP_BUG_ON(delta < 0);
                hcrx->ccid3hcrx_x_recv =
                        scaled_div32(hcrx->ccid3hcrx_bytes_recv, delta);
@@ -763,11 +714,6 @@ static void ccid3_hc_rx_send_feedback(struct sock *sk)
        hcrx->ccid3hcrx_ccval_last_counter   = packet->dccphrx_ccval;
        hcrx->ccid3hcrx_bytes_recv           = 0;
 
-       /* Elapsed time information [RFC 4340, 13.2] in units of 10 * usecs */
-       delta = timeval_delta(&now, &packet->dccphrx_tstamp);
-       DCCP_BUG_ON(delta < 0);
-       hcrx->ccid3hcrx_elapsed_time = delta / 10;
-
        if (hcrx->ccid3hcrx_p == 0)
                hcrx->ccid3hcrx_pinv = ~0U;     /* see RFC 4342, 8.5 */
        else if (hcrx->ccid3hcrx_p > 1000000) {
@@ -782,14 +728,13 @@ static void ccid3_hc_rx_send_feedback(struct sock *sk)
 
 static int ccid3_hc_rx_insert_options(struct sock *sk, struct sk_buff *skb)
 {
-       const struct ccid3_hc_rx_sock *hcrx = ccid3_hc_rx_sk(sk);
+       const struct ccid3_hc_rx_sock *hcrx;
        __be32 x_recv, pinv;
 
-       BUG_ON(hcrx == NULL);
-
        if (!(sk->sk_state == DCCP_OPEN || sk->sk_state == DCCP_PARTOPEN))
                return 0;
 
+       hcrx = ccid3_hc_rx_sk(sk);
        DCCP_SKB_CB(skb)->dccpd_ccval = hcrx->ccid3hcrx_ccval_last_counter;
 
        if (dccp_packet_without_ack(skb))
@@ -798,10 +743,7 @@ static int ccid3_hc_rx_insert_options(struct sock *sk, struct sk_buff *skb)
        x_recv = htonl(hcrx->ccid3hcrx_x_recv);
        pinv   = htonl(hcrx->ccid3hcrx_pinv);
 
-       if ((hcrx->ccid3hcrx_elapsed_time != 0 &&
-            dccp_insert_option_elapsed_time(sk, skb,
-                                            hcrx->ccid3hcrx_elapsed_time)) ||
-           dccp_insert_option_timestamp(sk, skb) ||
+       if (dccp_insert_option_timestamp(sk, skb) ||
            dccp_insert_option(sk, skb, TFRC_OPT_LOSS_EVENT_RATE,
                               &pinv, sizeof(pinv)) ||
            dccp_insert_option(sk, skb, TFRC_OPT_RECEIVE_RATE,
@@ -839,7 +781,7 @@ static int ccid3_hc_rx_detect_loss(struct sock *sk,
                dccp_li_update_li(sk,
                                  &hcrx->ccid3hcrx_li_hist,
                                  &hcrx->ccid3hcrx_hist,
-                                 &hcrx->ccid3hcrx_tstamp_last_feedback,
+                                 hcrx->ccid3hcrx_tstamp_last_feedback,
                                  hcrx->ccid3hcrx_s,
                                  hcrx->ccid3hcrx_bytes_recv,
                                  hcrx->ccid3hcrx_x_recv,
@@ -876,11 +818,9 @@ static void ccid3_hc_rx_packet_recv(struct sock *sk, struct sk_buff *skb)
        struct ccid3_hc_rx_sock *hcrx = ccid3_hc_rx_sk(sk);
        const struct dccp_options_received *opt_recv;
        struct dccp_rx_hist_entry *packet;
-       struct timeval now;
        u32 p_prev, r_sample, rtt_prev;
        int loss, payload_size;
-
-       BUG_ON(hcrx == NULL);
+       ktime_t now;
 
        opt_recv = &dccp_sk(sk)->dccps_options_received;
 
@@ -891,9 +831,9 @@ static void ccid3_hc_rx_packet_recv(struct sock *sk, struct sk_buff *skb)
        case DCCP_PKT_DATAACK:
                if (opt_recv->dccpor_timestamp_echo == 0)
                        break;
+               r_sample = dccp_timestamp() - opt_recv->dccpor_timestamp_echo;
                rtt_prev = hcrx->ccid3hcrx_rtt;
-               dccp_timestamp(sk, &now);
-               r_sample = dccp_sample_rtt(sk, &now, NULL);
+               r_sample = dccp_sample_rtt(sk, 10 * r_sample);
 
                if (hcrx->ccid3hcrx_state == TFRC_RSTATE_NO_DATA)
                        hcrx->ccid3hcrx_rtt = r_sample;
@@ -912,7 +852,7 @@ static void ccid3_hc_rx_packet_recv(struct sock *sk, struct sk_buff *skb)
                return;
        }
 
-       packet = dccp_rx_hist_entry_new(ccid3_rx_hist, sk, opt_recv->dccpor_ndp,
+       packet = dccp_rx_hist_entry_new(ccid3_rx_hist, opt_recv->dccpor_ndp,
                                        skb, GFP_ATOMIC);
        if (unlikely(packet == NULL)) {
                DCCP_WARN("%s(%p), Not enough mem to add rx packet "
@@ -941,9 +881,9 @@ static void ccid3_hc_rx_packet_recv(struct sock *sk, struct sk_buff *skb)
                if (loss)
                        break;
 
-               dccp_timestamp(sk, &now);
-               if ((timeval_delta(&now, &hcrx->ccid3hcrx_tstamp_last_ack) -
-                    (suseconds_t)hcrx->ccid3hcrx_rtt) >= 0) {
+               now = ktime_get_real();
+               if ((ktime_us_delta(now, hcrx->ccid3hcrx_tstamp_last_ack) -
+                    (s64)hcrx->ccid3hcrx_rtt) >= 0) {
                        hcrx->ccid3hcrx_tstamp_last_ack = now;
                        ccid3_hc_rx_send_feedback(sk);
                }
@@ -984,10 +924,8 @@ static int ccid3_hc_rx_init(struct ccid *ccid, struct sock *sk)
        hcrx->ccid3hcrx_state = TFRC_RSTATE_NO_DATA;
        INIT_LIST_HEAD(&hcrx->ccid3hcrx_hist);
        INIT_LIST_HEAD(&hcrx->ccid3hcrx_li_hist);
-       dccp_timestamp(sk, &hcrx->ccid3hcrx_tstamp_last_ack);
-       hcrx->ccid3hcrx_tstamp_last_feedback = hcrx->ccid3hcrx_tstamp_last_ack;
-       hcrx->ccid3hcrx_s   = 0;
-       hcrx->ccid3hcrx_rtt = 0;
+       hcrx->ccid3hcrx_tstamp_last_feedback =
+               hcrx->ccid3hcrx_tstamp_last_ack = ktime_get_real();
        return 0;
 }
 
@@ -995,8 +933,6 @@ static void ccid3_hc_rx_exit(struct sock *sk)
 {
        struct ccid3_hc_rx_sock *hcrx = ccid3_hc_rx_sk(sk);
 
-       BUG_ON(hcrx == NULL);
-
        ccid3_hc_rx_set_state(sk, TFRC_RSTATE_TERM);
 
        /* Empty packet history */
@@ -1008,14 +944,13 @@ static void ccid3_hc_rx_exit(struct sock *sk)
 
 static void ccid3_hc_rx_get_info(struct sock *sk, struct tcp_info *info)
 {
-       const struct ccid3_hc_rx_sock *hcrx = ccid3_hc_rx_sk(sk);
+       const struct ccid3_hc_rx_sock *hcrx;
 
        /* Listen socks doesn't have a private CCID block */
        if (sk->sk_state == DCCP_LISTEN)
                return;
 
-       BUG_ON(hcrx == NULL);
-
+       hcrx = ccid3_hc_rx_sk(sk);
        info->tcpi_ca_state = hcrx->ccid3hcrx_state;
        info->tcpi_options  |= TCPI_OPT_TIMESTAMPS;
        info->tcpi_rcv_rtt  = hcrx->ccid3hcrx_rtt;
@@ -1024,13 +959,14 @@ static void ccid3_hc_rx_get_info(struct sock *sk, struct tcp_info *info)
 static int ccid3_hc_rx_getsockopt(struct sock *sk, const int optname, int len,
                                  u32 __user *optval, int __user *optlen)
 {
-       const struct ccid3_hc_rx_sock *hcrx = ccid3_hc_rx_sk(sk);
+       const struct ccid3_hc_rx_sock *hcrx;
        const void *val;
 
        /* Listen socks doesn't have a private CCID block */
        if (sk->sk_state == DCCP_LISTEN)
                return -EINVAL;
 
+       hcrx = ccid3_hc_rx_sk(sk);
        switch (optname) {
        case DCCP_SOCKOPT_CCID_RX_INFO:
                if (len < sizeof(hcrx->ccid3hcrx_tfrc))
@@ -1071,7 +1007,7 @@ static struct ccid_operations ccid3 = {
 };
 
 #ifdef CONFIG_IP_DCCP_CCID3_DEBUG
-module_param(ccid3_debug, int, 0444);
+module_param(ccid3_debug, bool, 0444);
 MODULE_PARM_DESC(ccid3_debug, "Enable debug messages");
 #endif
 
@@ -1083,19 +1019,12 @@ static __init int ccid3_module_init(void)
        if (ccid3_rx_hist == NULL)
                goto out;
 
-       ccid3_tx_hist = dccp_tx_hist_new("ccid3");
-       if (ccid3_tx_hist == NULL)
-               goto out_free_rx;
-
        rc = ccid_register(&ccid3);
        if (rc != 0)
-               goto out_free_tx;
+               goto out_free_rx;
 out:
        return rc;
 
-out_free_tx:
-       dccp_tx_hist_delete(ccid3_tx_hist);
-       ccid3_tx_hist = NULL;
 out_free_rx:
        dccp_rx_hist_delete(ccid3_rx_hist);
        ccid3_rx_hist = NULL;
@@ -1107,10 +1036,6 @@ static __exit void ccid3_module_exit(void)
 {
        ccid_unregister(&ccid3);
 
-       if (ccid3_tx_hist != NULL) {
-               dccp_tx_hist_delete(ccid3_tx_hist);
-               ccid3_tx_hist = NULL;
-       }
        if (ccid3_rx_hist != NULL) {
                dccp_rx_hist_delete(ccid3_rx_hist);
                ccid3_rx_hist = NULL;
This page took 0.056113 seconds and 5 git commands to generate.