[PKT_SCHED]: Some typo fixes in net/sched/Kconfig
[safe/jmp/linux-2.6] / net / ipv4 / tcp_input.c
index e5d1c2c..fec8a7a 100644 (file)
@@ -140,7 +140,7 @@ static void tcp_measure_rcv_mss(struct sock *sk,
                 *
                 * "len" is invariant segment length, including TCP header.
                 */
-               len += skb->data - skb->h.raw;
+               len += skb->data - skb_transport_header(skb);
                if (len >= TCP_MIN_RCVMSS + sizeof(struct tcphdr) ||
                    /* If PSH is not set, packet should be
                     * full sized, provided peer TCP is not badly broken.
@@ -148,7 +148,7 @@ static void tcp_measure_rcv_mss(struct sock *sk,
                     * to handle super-low mtu links fairly.
                     */
                    (len >= TCP_MIN_MSS + sizeof(struct tcphdr) &&
-                    !(tcp_flag_word(skb->h.th)&TCP_REMNANT))) {
+                    !(tcp_flag_word(tcp_hdr(skb)) & TCP_REMNANT))) {
                        /* Subtract also invariant (if peer is RFC compliant),
                         * tcp header plus fixed timestamp option length.
                         * Resulting "len" is MSS free of SACK jitter.
@@ -235,9 +235,9 @@ static void tcp_fixup_sndbuf(struct sock *sk)
  */
 
 /* Slow part of check#2. */
-static int __tcp_grow_window(const struct sock *sk, struct tcp_sock *tp,
-                            const struct sk_buff *skb)
+static int __tcp_grow_window(const struct sock *sk, const struct sk_buff *skb)
 {
+       struct tcp_sock *tp = tcp_sk(sk);
        /* Optimize this! */
        int truesize = tcp_win_from_space(skb->truesize)/2;
        int window = tcp_win_from_space(sysctl_tcp_rmem[2])/2;
@@ -252,9 +252,11 @@ static int __tcp_grow_window(const struct sock *sk, struct tcp_sock *tp,
        return 0;
 }
 
-static void tcp_grow_window(struct sock *sk, struct tcp_sock *tp,
+static void tcp_grow_window(struct sock *sk,
                            struct sk_buff *skb)
 {
+       struct tcp_sock *tp = tcp_sk(sk);
+
        /* Check #1 */
        if (tp->rcv_ssthresh < tp->window_clamp &&
            (int)tp->rcv_ssthresh < tcp_space(sk) &&
@@ -267,7 +269,7 @@ static void tcp_grow_window(struct sock *sk, struct tcp_sock *tp,
                if (tcp_win_from_space(skb->truesize) <= skb->len)
                        incr = 2*tp->advmss;
                else
-                       incr = __tcp_grow_window(sk, tp, skb);
+                       incr = __tcp_grow_window(sk, skb);
 
                if (incr) {
                        tp->rcv_ssthresh = min(tp->rcv_ssthresh + incr, tp->window_clamp);
@@ -330,8 +332,9 @@ static void tcp_init_buffer_space(struct sock *sk)
 }
 
 /* 5. Recalculate window clamp after socket hit its memory bounds. */
-static void tcp_clamp_window(struct sock *sk, struct tcp_sock *tp)
+static void tcp_clamp_window(struct sock *sk)
 {
+       struct tcp_sock *tp = tcp_sk(sk);
        struct inet_connection_sock *icsk = inet_csk(sk);
 
        icsk->icsk_ack.quick = 0;
@@ -503,8 +506,9 @@ new_measure:
  * each ACK we send, he increments snd_cwnd and transmits more of his
  * queue.  -DaveM
  */
-static void tcp_event_data_recv(struct sock *sk, struct tcp_sock *tp, struct sk_buff *skb)
+static void tcp_event_data_recv(struct sock *sk, struct sk_buff *skb)
 {
+       struct tcp_sock *tp = tcp_sk(sk);
        struct inet_connection_sock *icsk = inet_csk(sk);
        u32 now;
 
@@ -545,7 +549,7 @@ static void tcp_event_data_recv(struct sock *sk, struct tcp_sock *tp, struct sk_
        TCP_ECN_check_ce(tp, skb);
 
        if (skb->len >= 128)
-               tcp_grow_window(sk, tp, skb);
+               tcp_grow_window(sk, skb);
 }
 
 /* Called to compute a smoothed rtt estimate. The data fed to this
@@ -940,7 +944,8 @@ tcp_sacktag_write_queue(struct sock *sk, struct sk_buff *ack_skb, u32 prior_snd_
 {
        const struct inet_connection_sock *icsk = inet_csk(sk);
        struct tcp_sock *tp = tcp_sk(sk);
-       unsigned char *ptr = ack_skb->h.raw + TCP_SKB_CB(ack_skb)->sacked;
+       unsigned char *ptr = (skb_transport_header(ack_skb) +
+                             TCP_SKB_CB(ack_skb)->sacked);
        struct tcp_sack_block_wire *sp = (struct tcp_sack_block_wire *)(ptr+2);
        struct sk_buff *cached_skb;
        int num_sacks = (ptr[1] - TCPOLEN_SACK_BASE)>>3;
@@ -948,7 +953,7 @@ tcp_sacktag_write_queue(struct sock *sk, struct sk_buff *ack_skb, u32 prior_snd_
        int prior_fackets;
        u32 lost_retrans = 0;
        int flag = 0;
-       int dup_sack = 0;
+       int found_dup_sack = 0;
        int cached_fack_count;
        int i;
        int first_sack_index;
@@ -959,20 +964,20 @@ tcp_sacktag_write_queue(struct sock *sk, struct sk_buff *ack_skb, u32 prior_snd_
 
        /* Check for D-SACK. */
        if (before(ntohl(sp[0].start_seq), TCP_SKB_CB(ack_skb)->ack_seq)) {
-               dup_sack = 1;
+               found_dup_sack = 1;
                tp->rx_opt.sack_ok |= 4;
                NET_INC_STATS_BH(LINUX_MIB_TCPDSACKRECV);
        } else if (num_sacks > 1 &&
                        !after(ntohl(sp[0].end_seq), ntohl(sp[1].end_seq)) &&
                        !before(ntohl(sp[0].start_seq), ntohl(sp[1].start_seq))) {
-               dup_sack = 1;
+               found_dup_sack = 1;
                tp->rx_opt.sack_ok |= 4;
                NET_INC_STATS_BH(LINUX_MIB_TCPDSACKOFORECV);
        }
 
        /* D-SACK for already forgotten data...
         * Do dumb counting. */
-       if (dup_sack &&
+       if (found_dup_sack &&
                        !after(ntohl(sp[0].end_seq), prior_snd_una) &&
                        after(ntohl(sp[0].end_seq), tp->undo_marker))
                tp->undo_retrans--;
@@ -1053,6 +1058,7 @@ tcp_sacktag_write_queue(struct sock *sk, struct sk_buff *ack_skb, u32 prior_snd_
                __u32 start_seq = ntohl(sp->start_seq);
                __u32 end_seq = ntohl(sp->end_seq);
                int fack_count;
+               int dup_sack = (found_dup_sack && (i == first_sack_index));
 
                skb = cached_skb;
                fack_count = cached_fack_count;
@@ -1260,20 +1266,15 @@ tcp_sacktag_write_queue(struct sock *sk, struct sk_buff *ack_skb, u32 prior_snd_
        return flag;
 }
 
-/* F-RTO can only be used if these conditions are satisfied:
- *  - there must be some unsent new data
- *  - the advertised window should allow sending it
- *  - TCP has never retransmitted anything other than head (SACK enhanced
- *    variant from Appendix B of RFC4138 is more robust here)
+/* F-RTO can only be used if TCP has never retransmitted anything other than
+ * head (SACK enhanced variant from Appendix B of RFC4138 is more robust here)
  */
 int tcp_use_frto(struct sock *sk)
 {
        const struct tcp_sock *tp = tcp_sk(sk);
        struct sk_buff *skb;
 
-       if (!sysctl_tcp_frto || !tcp_send_head(sk) ||
-               after(TCP_SKB_CB(tcp_send_head(sk))->end_seq,
-                     tp->snd_una + tp->snd_wnd))
+       if (!sysctl_tcp_frto)
                return 0;
 
        if (IsSackFrto())
@@ -1397,7 +1398,9 @@ static void tcp_enter_frto_loss(struct sock *sk, int allowed_segments, int flag)
                 * waiting for the first ACK and did not get it)...
                 */
                if ((tp->frto_counter == 1) && !(flag&FLAG_DATA_ACKED)) {
-                       tp->retrans_out += tcp_skb_pcount(skb);
+                       /* For some reason this R-bit might get cleared? */
+                       if (TCP_SKB_CB(skb)->sacked & TCPCB_SACKED_RETRANS)
+                               tp->retrans_out += tcp_skb_pcount(skb);
                        /* ...enter this if branch just for the first segment */
                        flag |= FLAG_DATA_ACKED;
                } else {
@@ -1501,6 +1504,8 @@ void tcp_enter_loss(struct sock *sk, int how)
        tcp_set_ca_state(sk, TCP_CA_Loss);
        tp->high_seq = tp->snd_nxt;
        TCP_ECN_queue_cwr(tp);
+       /* Abort FRTO algorithm if one is in progress */
+       tp->frto_counter = 0;
 
        clear_all_retrans_hints(tp);
 }
@@ -1540,8 +1545,10 @@ static inline int tcp_skb_timedout(struct sock *sk, struct sk_buff *skb)
        return (tcp_time_stamp - TCP_SKB_CB(skb)->when > inet_csk(sk)->icsk_rto);
 }
 
-static inline int tcp_head_timedout(struct sock *sk, struct tcp_sock *tp)
+static inline int tcp_head_timedout(struct sock *sk)
 {
+       struct tcp_sock *tp = tcp_sk(sk);
+
        return tp->packets_out &&
               tcp_skb_timedout(sk, tcp_write_queue_head(sk));
 }
@@ -1639,8 +1646,9 @@ static inline int tcp_head_timedout(struct sock *sk, struct tcp_sock *tp)
  * Main question: may we further continue forward transmission
  * with the same cwnd?
  */
-static int tcp_time_to_recover(struct sock *sk, struct tcp_sock *tp)
+static int tcp_time_to_recover(struct sock *sk)
 {
+       struct tcp_sock *tp = tcp_sk(sk);
        __u32 packets_out;
 
        /* Do not perform any recovery during FRTO algorithm */
@@ -1658,7 +1666,7 @@ static int tcp_time_to_recover(struct sock *sk, struct tcp_sock *tp)
        /* Trick#3 : when we use RFC2988 timer restart, fast
         * retransmit can be triggered by timeout of queue head.
         */
-       if (tcp_head_timedout(sk, tp))
+       if (tcp_head_timedout(sk))
                return 1;
 
        /* Trick#4: It is still not OK... But will it be useful to delay
@@ -1667,7 +1675,7 @@ static int tcp_time_to_recover(struct sock *sk, struct tcp_sock *tp)
        packets_out = tp->packets_out;
        if (packets_out <= tp->reordering &&
            tp->sacked_out >= max_t(__u32, packets_out/2, sysctl_tcp_reordering) &&
-           !tcp_may_send_now(sk, tp)) {
+           !tcp_may_send_now(sk)) {
                /* We have nothing to send. This connection is limited
                 * either by receiver window or by application.
                 */
@@ -1707,8 +1715,10 @@ static void tcp_add_reno_sack(struct sock *sk)
 
 /* Account for ACK, ACKing some data in Reno Recovery phase. */
 
-static void tcp_remove_reno_sacks(struct sock *sk, struct tcp_sock *tp, int acked)
+static void tcp_remove_reno_sacks(struct sock *sk, int acked)
 {
+       struct tcp_sock *tp = tcp_sk(sk);
+
        if (acked > 0) {
                /* One ACK acked hole. The rest eat duplicate ACKs. */
                if (acked-1 >= tp->sacked_out)
@@ -1727,9 +1737,10 @@ static inline void tcp_reset_reno_sack(struct tcp_sock *tp)
 }
 
 /* Mark head of queue up as lost. */
-static void tcp_mark_head_lost(struct sock *sk, struct tcp_sock *tp,
+static void tcp_mark_head_lost(struct sock *sk,
                               int packets, u32 high_seq)
 {
+       struct tcp_sock *tp = tcp_sk(sk);
        struct sk_buff *skb;
        int cnt;
 
@@ -1770,15 +1781,17 @@ static void tcp_mark_head_lost(struct sock *sk, struct tcp_sock *tp,
 
 /* Account newly detected lost packet(s) */
 
-static void tcp_update_scoreboard(struct sock *sk, struct tcp_sock *tp)
+static void tcp_update_scoreboard(struct sock *sk)
 {
+       struct tcp_sock *tp = tcp_sk(sk);
+
        if (IsFack(tp)) {
                int lost = tp->fackets_out - tp->reordering;
                if (lost <= 0)
                        lost = 1;
-               tcp_mark_head_lost(sk, tp, lost, tp->high_seq);
+               tcp_mark_head_lost(sk, lost, tp->high_seq);
        } else {
-               tcp_mark_head_lost(sk, tp, 1, tp->high_seq);
+               tcp_mark_head_lost(sk, 1, tp->high_seq);
        }
 
        /* New heuristics: it is possible only after we switched
@@ -1786,7 +1799,7 @@ static void tcp_update_scoreboard(struct sock *sk, struct tcp_sock *tp)
         * Hence, we can detect timed out packets during fast
         * retransmit without falling to slow start.
         */
-       if (!IsReno(tp) && tcp_head_timedout(sk, tp)) {
+       if (!IsReno(tp) && tcp_head_timedout(sk)) {
                struct sk_buff *skb;
 
                skb = tp->scoreboard_skb_hint ? tp->scoreboard_skb_hint
@@ -1866,9 +1879,11 @@ static inline int tcp_packet_delayed(struct tcp_sock *tp)
 /* Undo procedures. */
 
 #if FASTRETRANS_DEBUG > 1
-static void DBGUNDO(struct sock *sk, struct tcp_sock *tp, const char *msg)
+static void DBGUNDO(struct sock *sk, const char *msg)
 {
+       struct tcp_sock *tp = tcp_sk(sk);
        struct inet_sock *inet = inet_sk(sk);
+
        printk(KERN_DEBUG "Undo %s %u.%u.%u.%u/%u c%u l%u ss%u/%u p%u\n",
               msg,
               NIPQUAD(inet->daddr), ntohs(inet->dport),
@@ -1914,13 +1929,15 @@ static inline int tcp_may_undo(struct tcp_sock *tp)
 }
 
 /* People celebrate: "We love our President!" */
-static int tcp_try_undo_recovery(struct sock *sk, struct tcp_sock *tp)
+static int tcp_try_undo_recovery(struct sock *sk)
 {
+       struct tcp_sock *tp = tcp_sk(sk);
+
        if (tcp_may_undo(tp)) {
                /* Happy end! We did not retransmit anything
                 * or our original transmission succeeded.
                 */
-               DBGUNDO(sk, tp, inet_csk(sk)->icsk_ca_state == TCP_CA_Loss ? "loss" : "retrans");
+               DBGUNDO(sk, inet_csk(sk)->icsk_ca_state == TCP_CA_Loss ? "loss" : "retrans");
                tcp_undo_cwr(sk, 1);
                if (inet_csk(sk)->icsk_ca_state == TCP_CA_Loss)
                        NET_INC_STATS_BH(LINUX_MIB_TCPLOSSUNDO);
@@ -1940,10 +1957,12 @@ static int tcp_try_undo_recovery(struct sock *sk, struct tcp_sock *tp)
 }
 
 /* Try to undo cwnd reduction, because D-SACKs acked all retransmitted data */
-static void tcp_try_undo_dsack(struct sock *sk, struct tcp_sock *tp)
+static void tcp_try_undo_dsack(struct sock *sk)
 {
+       struct tcp_sock *tp = tcp_sk(sk);
+
        if (tp->undo_marker && !tp->undo_retrans) {
-               DBGUNDO(sk, tp, "D-SACK");
+               DBGUNDO(sk, "D-SACK");
                tcp_undo_cwr(sk, 1);
                tp->undo_marker = 0;
                NET_INC_STATS_BH(LINUX_MIB_TCPDSACKUNDO);
@@ -1952,9 +1971,9 @@ static void tcp_try_undo_dsack(struct sock *sk, struct tcp_sock *tp)
 
 /* Undo during fast recovery after partial ACK. */
 
-static int tcp_try_undo_partial(struct sock *sk, struct tcp_sock *tp,
-                               int acked)
+static int tcp_try_undo_partial(struct sock *sk, int acked)
 {
+       struct tcp_sock *tp = tcp_sk(sk);
        /* Partial ACK arrived. Force Hoe's retransmit. */
        int failed = IsReno(tp) || tp->fackets_out>tp->reordering;
 
@@ -1967,7 +1986,7 @@ static int tcp_try_undo_partial(struct sock *sk, struct tcp_sock *tp,
 
                tcp_update_reordering(sk, tcp_fackets_out(tp) + acked, 1);
 
-               DBGUNDO(sk, tp, "Hoe");
+               DBGUNDO(sk, "Hoe");
                tcp_undo_cwr(sk, 0);
                NET_INC_STATS_BH(LINUX_MIB_TCPPARTIALUNDO);
 
@@ -1981,8 +2000,10 @@ static int tcp_try_undo_partial(struct sock *sk, struct tcp_sock *tp,
 }
 
 /* Undo during loss recovery after partial ACK. */
-static int tcp_try_undo_loss(struct sock *sk, struct tcp_sock *tp)
+static int tcp_try_undo_loss(struct sock *sk)
 {
+       struct tcp_sock *tp = tcp_sk(sk);
+
        if (tcp_may_undo(tp)) {
                struct sk_buff *skb;
                tcp_for_write_queue(skb, sk) {
@@ -1993,7 +2014,7 @@ static int tcp_try_undo_loss(struct sock *sk, struct tcp_sock *tp)
 
                clear_all_retrans_hints(tp);
 
-               DBGUNDO(sk, tp, "partial loss");
+               DBGUNDO(sk, "partial loss");
                tp->lost_out = 0;
                tp->left_out = tp->sacked_out;
                tcp_undo_cwr(sk, 1);
@@ -2015,9 +2036,11 @@ static inline void tcp_complete_cwr(struct sock *sk)
        tcp_ca_event(sk, CA_EVENT_COMPLETE_CWR);
 }
 
-static void tcp_try_to_open(struct sock *sk, struct tcp_sock *tp, int flag)
+static void tcp_try_to_open(struct sock *sk, int flag)
 {
-       tp->left_out = tp->sacked_out;
+       struct tcp_sock *tp = tcp_sk(sk);
+
+       tcp_sync_left_out(tp);
 
        if (tp->retrans_out == 0)
                tp->retrans_stamp = 0;
@@ -2110,7 +2133,7 @@ tcp_fastretrans_alert(struct sock *sk, u32 prior_snd_una,
            before(tp->snd_una, tp->high_seq) &&
            icsk->icsk_ca_state != TCP_CA_Open &&
            tp->fackets_out > tp->reordering) {
-               tcp_mark_head_lost(sk, tp, tp->fackets_out-tp->reordering, tp->high_seq);
+               tcp_mark_head_lost(sk, tp->fackets_out-tp->reordering, tp->high_seq);
                NET_INC_STATS_BH(LINUX_MIB_TCPLOSS);
        }
 
@@ -2126,7 +2149,7 @@ tcp_fastretrans_alert(struct sock *sk, u32 prior_snd_una,
                switch (icsk->icsk_ca_state) {
                case TCP_CA_Loss:
                        icsk->icsk_retransmits = 0;
-                       if (tcp_try_undo_recovery(sk, tp))
+                       if (tcp_try_undo_recovery(sk))
                                return;
                        break;
 
@@ -2140,7 +2163,7 @@ tcp_fastretrans_alert(struct sock *sk, u32 prior_snd_una,
                        break;
 
                case TCP_CA_Disorder:
-                       tcp_try_undo_dsack(sk, tp);
+                       tcp_try_undo_dsack(sk);
                        if (!tp->undo_marker ||
                            /* For SACK case do not Open to allow to undo
                             * catching for all duplicate ACKs. */
@@ -2153,7 +2176,7 @@ tcp_fastretrans_alert(struct sock *sk, u32 prior_snd_una,
                case TCP_CA_Recovery:
                        if (IsReno(tp))
                                tcp_reset_reno_sack(tp);
-                       if (tcp_try_undo_recovery(sk, tp))
+                       if (tcp_try_undo_recovery(sk))
                                return;
                        tcp_complete_cwr(sk);
                        break;
@@ -2169,14 +2192,14 @@ tcp_fastretrans_alert(struct sock *sk, u32 prior_snd_una,
                } else {
                        int acked = prior_packets - tp->packets_out;
                        if (IsReno(tp))
-                               tcp_remove_reno_sacks(sk, tp, acked);
-                       is_dupack = tcp_try_undo_partial(sk, tp, acked);
+                               tcp_remove_reno_sacks(sk, acked);
+                       is_dupack = tcp_try_undo_partial(sk, acked);
                }
                break;
        case TCP_CA_Loss:
                if (flag&FLAG_DATA_ACKED)
                        icsk->icsk_retransmits = 0;
-               if (!tcp_try_undo_loss(sk, tp)) {
+               if (!tcp_try_undo_loss(sk)) {
                        tcp_moderate_cwnd(tp);
                        tcp_xmit_retransmit_queue(sk);
                        return;
@@ -2193,10 +2216,10 @@ tcp_fastretrans_alert(struct sock *sk, u32 prior_snd_una,
                }
 
                if (icsk->icsk_ca_state == TCP_CA_Disorder)
-                       tcp_try_undo_dsack(sk, tp);
+                       tcp_try_undo_dsack(sk);
 
-               if (!tcp_time_to_recover(sk, tp)) {
-                       tcp_try_to_open(sk, tp, flag);
+               if (!tcp_time_to_recover(sk)) {
+                       tcp_try_to_open(sk, flag);
                        return;
                }
 
@@ -2235,8 +2258,8 @@ tcp_fastretrans_alert(struct sock *sk, u32 prior_snd_una,
                tcp_set_ca_state(sk, TCP_CA_Recovery);
        }
 
-       if (is_dupack || tcp_head_timedout(sk, tp))
-               tcp_update_scoreboard(sk, tp);
+       if (is_dupack || tcp_head_timedout(sk))
+               tcp_update_scoreboard(sk);
        tcp_cwnd_down(sk);
        tcp_xmit_retransmit_queue(sk);
 }
@@ -2300,11 +2323,11 @@ static inline void tcp_ack_update_rtt(struct sock *sk, const int flag,
                tcp_ack_no_tstamp(sk, seq_rtt, flag);
 }
 
-static void tcp_cong_avoid(struct sock *sk, u32 ack, u32 rtt,
+static void tcp_cong_avoid(struct sock *sk, u32 ack,
                           u32 in_flight, int good)
 {
        const struct inet_connection_sock *icsk = inet_csk(sk);
-       icsk->icsk_ca_ops->cong_avoid(sk, ack, rtt, in_flight, good);
+       icsk->icsk_ca_ops->cong_avoid(sk, ack, in_flight, good);
        tcp_sk(sk)->snd_cwnd_stamp = tcp_time_stamp;
 }
 
@@ -2312,8 +2335,10 @@ static void tcp_cong_avoid(struct sock *sk, u32 ack, u32 rtt,
  * RFC2988 recommends to restart timer to now+rto.
  */
 
-static void tcp_ack_packets_out(struct sock *sk, struct tcp_sock *tp)
+static void tcp_ack_packets_out(struct sock *sk)
 {
+       struct tcp_sock *tp = tcp_sk(sk);
+
        if (!tp->packets_out) {
                inet_csk_clear_xmit_timer(sk, ICSK_TIME_RETRANS);
        } else {
@@ -2377,14 +2402,6 @@ static int tcp_tso_acked(struct sock *sk, struct sk_buff *skb,
        return acked;
 }
 
-static u32 tcp_usrtt(struct timeval *tv)
-{
-       struct timeval now;
-
-       do_gettimeofday(&now);
-       return (now.tv_sec - tv->tv_sec) * 1000000 + (now.tv_usec - tv->tv_usec);
-}
-
 /* Remove acknowledged frames from the retransmission queue. */
 static int tcp_clean_rtx_queue(struct sock *sk, __s32 *seq_rtt_p)
 {
@@ -2393,11 +2410,9 @@ static int tcp_clean_rtx_queue(struct sock *sk, __s32 *seq_rtt_p)
        struct sk_buff *skb;
        __u32 now = tcp_time_stamp;
        int acked = 0;
+       int prior_packets = tp->packets_out;
        __s32 seq_rtt = -1;
-       u32 pkts_acked = 0;
-       void (*rtt_sample)(struct sock *sk, u32 usrtt)
-               = icsk->icsk_ca_ops->rtt_sample;
-       struct timeval tv = { .tv_sec = 0, .tv_usec = 0 };
+       ktime_t last_ackt = net_invalid_timestamp();
 
        while ((skb = tcp_write_queue_head(sk)) &&
               skb != tcp_send_head(sk)) {
@@ -2425,7 +2440,6 @@ static int tcp_clean_rtx_queue(struct sock *sk, __s32 *seq_rtt_p)
                 */
                if (!(scb->flags & TCPCB_FLAG_SYN)) {
                        acked |= FLAG_DATA_ACKED;
-                       ++pkts_acked;
                } else {
                        acked |= FLAG_SYN_ACKED;
                        tp->retrans_stamp = 0;
@@ -2446,7 +2460,7 @@ static int tcp_clean_rtx_queue(struct sock *sk, __s32 *seq_rtt_p)
                                seq_rtt = -1;
                        } else if (seq_rtt < 0) {
                                seq_rtt = now - scb->when;
-                               skb_get_timestamp(skb, &tv);
+                               last_ackt = skb->tstamp;
                        }
                        if (sacked & TCPCB_SACKED_ACKED)
                                tp->sacked_out -= tcp_skb_pcount(skb);
@@ -2459,7 +2473,7 @@ static int tcp_clean_rtx_queue(struct sock *sk, __s32 *seq_rtt_p)
                        }
                } else if (seq_rtt < 0) {
                        seq_rtt = now - scb->when;
-                       skb_get_timestamp(skb, &tv);
+                       last_ackt = skb->tstamp;
                }
                tcp_dec_pcount_approx(&tp->fackets_out, skb);
                tcp_packets_out_dec(tp, skb);
@@ -2469,13 +2483,19 @@ static int tcp_clean_rtx_queue(struct sock *sk, __s32 *seq_rtt_p)
        }
 
        if (acked&FLAG_ACKED) {
+               u32 pkts_acked = prior_packets - tp->packets_out;
+               const struct tcp_congestion_ops *ca_ops
+                       = inet_csk(sk)->icsk_ca_ops;
+
                tcp_ack_update_rtt(sk, acked, seq_rtt);
-               tcp_ack_packets_out(sk, tp);
-               if (rtt_sample && !(acked & FLAG_RETRANS_DATA_ACKED))
-                       (*rtt_sample)(sk, tcp_usrtt(&tv));
+               tcp_ack_packets_out(sk);
+
+               /* Is the ACK triggering packet unambiguous? */
+               if (acked & FLAG_RETRANS_DATA_ACKED)
+                       last_ackt = net_invalid_timestamp();
 
-               if (icsk->icsk_ca_ops->pkts_acked)
-                       icsk->icsk_ca_ops->pkts_acked(sk, pkts_acked);
+               if (ca_ops->pkts_acked)
+                       ca_ops->pkts_acked(sk, pkts_acked, last_ackt);
        }
 
 #if FASTRETRANS_DEBUG > 0
@@ -2555,13 +2575,14 @@ static inline int tcp_may_update_window(const struct tcp_sock *tp, const u32 ack
  * Window update algorithm, described in RFC793/RFC1122 (used in linux-2.2
  * and in FreeBSD. NetBSD's one is even worse.) is wrong.
  */
-static int tcp_ack_update_window(struct sock *sk, struct tcp_sock *tp,
-                                struct sk_buff *skb, u32 ack, u32 ack_seq)
+static int tcp_ack_update_window(struct sock *sk, struct sk_buff *skb, u32 ack,
+                                u32 ack_seq)
 {
+       struct tcp_sock *tp = tcp_sk(sk);
        int flag = 0;
-       u32 nwin = ntohs(skb->h.th->window);
+       u32 nwin = ntohs(tcp_hdr(skb)->window);
 
-       if (likely(!skb->h.th->syn))
+       if (likely(!tcp_hdr(skb)->syn))
                nwin <<= tp->rx_opt.snd_wscale;
 
        if (tcp_may_update_window(tp, ack, ack_seq, nwin)) {
@@ -2575,7 +2596,7 @@ static int tcp_ack_update_window(struct sock *sk, struct tcp_sock *tp,
                         * fast path is recovered for sending TCP.
                         */
                        tp->pred_flags = 0;
-                       tcp_fast_path_check(sk, tp);
+                       tcp_fast_path_check(sk);
 
                        if (nwin > tp->max_window) {
                                tp->max_window = nwin;
@@ -2596,6 +2617,7 @@ static void tcp_conservative_spur_to_response(struct tcp_sock *tp)
 {
        tp->snd_cwnd = min(tp->snd_cwnd, tp->snd_ssthresh);
        tp->snd_cwnd_cnt = 0;
+       TCP_ECN_queue_cwr(tp);
        tcp_moderate_cwnd(tp);
 }
 
@@ -2625,7 +2647,9 @@ static void tcp_undo_spur_to_response(struct sock *sk, int flag)
  *                  algorithm is not part of the F-RTO detection algorithm
  *                  given in RFC4138 but can be selected separately).
  * Otherwise (basically on duplicate ACK), RTO was (likely) caused by a loss
- * and TCP falls back to conventional RTO recovery.
+ * and TCP falls back to conventional RTO recovery. F-RTO allows overriding
+ * of Nagle, this is done using frto_counter states 2 and 3, when a new data
+ * segment of any size sent during F-RTO, state 2 is upgraded to 3.
  *
  * Rationale: if the RTO was spurious, new ACKs should arrive from the
  * original window even after we transmit two new data segments.
@@ -2654,7 +2678,7 @@ static int tcp_process_frto(struct sock *sk, u32 prior_snd_una, int flag)
                inet_csk(sk)->icsk_retransmits = 0;
 
        if (!before(tp->snd_una, tp->frto_highmark)) {
-               tcp_enter_frto_loss(sk, tp->frto_counter + 1, flag);
+               tcp_enter_frto_loss(sk, (tp->frto_counter == 1 ? 2 : 3), flag);
                return 1;
        }
 
@@ -2680,7 +2704,7 @@ static int tcp_process_frto(struct sock *sk, u32 prior_snd_una, int flag)
                        return 1;
                }
 
-               if ((tp->frto_counter == 2) &&
+               if ((tp->frto_counter >= 2) &&
                    (!(flag&FLAG_FORWARD_PROGRESS) ||
                     ((flag&FLAG_DATA_SACKED) && !(flag&FLAG_ONLY_ORIG_SACKED)))) {
                        /* RFC4138 shortcoming (see comment above) */
@@ -2693,10 +2717,19 @@ static int tcp_process_frto(struct sock *sk, u32 prior_snd_una, int flag)
        }
 
        if (tp->frto_counter == 1) {
+               /* Sending of the next skb must be allowed or no FRTO */
+               if (!tcp_send_head(sk) ||
+                   after(TCP_SKB_CB(tcp_send_head(sk))->end_seq,
+                                    tp->snd_una + tp->snd_wnd)) {
+                       tcp_enter_frto_loss(sk, (tp->frto_counter == 1 ? 2 : 3),
+                                           flag);
+                       return 1;
+               }
+
                tp->snd_cwnd = tcp_packets_in_flight(tp) + 2;
                tp->frto_counter = 2;
                return 1;
-       } else /* frto_counter == 2 */ {
+       } else {
                switch (sysctl_tcp_frto_response) {
                case 2:
                        tcp_undo_spur_to_response(sk, flag);
@@ -2707,7 +2740,7 @@ static int tcp_process_frto(struct sock *sk, u32 prior_snd_una, int flag)
                default:
                        tcp_ratehalving_spur_to_response(sk);
                        break;
-               };
+               }
                tp->frto_counter = 0;
        }
        return 0;
@@ -2761,12 +2794,12 @@ static int tcp_ack(struct sock *sk, struct sk_buff *skb, int flag)
                else
                        NET_INC_STATS_BH(LINUX_MIB_TCPPUREACKS);
 
-               flag |= tcp_ack_update_window(sk, tp, skb, ack, ack_seq);
+               flag |= tcp_ack_update_window(sk, skb, ack, ack_seq);
 
                if (TCP_SKB_CB(skb)->sacked)
                        flag |= tcp_sacktag_write_queue(sk, skb, prior_snd_una);
 
-               if (TCP_ECN_rcv_ecn_echo(tp, skb->h.th))
+               if (TCP_ECN_rcv_ecn_echo(tp, tcp_hdr(skb)))
                        flag |= FLAG_ECE;
 
                tcp_ca_event(sk, CA_EVENT_SLOW_ACK);
@@ -2793,11 +2826,11 @@ static int tcp_ack(struct sock *sk, struct sk_buff *skb, int flag)
                /* Advance CWND, if state allows this. */
                if ((flag & FLAG_DATA_ACKED) && !frto_cwnd &&
                    tcp_may_raise_cwnd(sk, flag))
-                       tcp_cong_avoid(sk, ack,  seq_rtt, prior_in_flight, 0);
+                       tcp_cong_avoid(sk, ack, prior_in_flight, 0);
                tcp_fastretrans_alert(sk, prior_snd_una, prior_packets, flag);
        } else {
                if ((flag & FLAG_DATA_ACKED) && !frto_cwnd)
-                       tcp_cong_avoid(sk, ack, seq_rtt, prior_in_flight, 1);
+                       tcp_cong_avoid(sk, ack, prior_in_flight, 1);
        }
 
        if ((flag & FLAG_FORWARD_PROGRESS) || !(flag&FLAG_NOT_DUP))
@@ -2833,7 +2866,7 @@ uninteresting_ack:
 void tcp_parse_options(struct sk_buff *skb, struct tcp_options_received *opt_rx, int estab)
 {
        unsigned char *ptr;
-       struct tcphdr *th = skb->h.th;
+       struct tcphdr *th = tcp_hdr(skb);
        int length=(th->doff*4)-sizeof(struct tcphdr);
 
        ptr = (unsigned char *)(th + 1);
@@ -2906,6 +2939,7 @@ void tcp_parse_options(struct sk_buff *skb, struct tcp_options_received *opt_rx,
                                           opt_rx->sack_ok) {
                                                TCP_SKB_CB(skb)->sacked = (ptr - 2) - (unsigned char *)th;
                                        }
+                                       break;
 #ifdef CONFIG_TCP_MD5SIG
                                case TCPOPT_MD5SIG:
                                        /*
@@ -2914,10 +2948,11 @@ void tcp_parse_options(struct sk_buff *skb, struct tcp_options_received *opt_rx,
                                         */
                                        break;
 #endif
-                               };
+                               }
+
                                ptr+=opsize-2;
                                length-=opsize;
-               };
+               }
        }
 }
 
@@ -2995,7 +3030,7 @@ static inline void tcp_replace_ts_recent(struct tcp_sock *tp, u32 seq)
 static int tcp_disordered_ack(const struct sock *sk, const struct sk_buff *skb)
 {
        struct tcp_sock *tp = tcp_sk(sk);
-       struct tcphdr *th = skb->h.th;
+       struct tcphdr *th = tcp_hdr(skb);
        u32 seq = TCP_SKB_CB(skb)->seq;
        u32 ack = TCP_SKB_CB(skb)->ack_seq;
 
@@ -3123,7 +3158,7 @@ static void tcp_fin(struct sk_buff *skb, struct sock *sk, struct tcphdr *th)
                        printk(KERN_ERR "%s: Impossible, sk->sk_state=%d\n",
                               __FUNCTION__, sk->sk_state);
                        break;
-       };
+       }
 
        /* It _is_ possible, that we have something out-of-order _after_ FIN.
         * Probably, we should reset in this case. For now drop them.
@@ -3357,8 +3392,8 @@ static void tcp_ofo_queue(struct sock *sk)
                __skb_unlink(skb, &tp->out_of_order_queue);
                __skb_queue_tail(&sk->sk_receive_queue, skb);
                tp->rcv_nxt = TCP_SKB_CB(skb)->end_seq;
-               if (skb->h.th->fin)
-                       tcp_fin(skb, sk, skb->h.th);
+               if (tcp_hdr(skb)->fin)
+                       tcp_fin(skb, sk, tcp_hdr(skb));
        }
 }
 
@@ -3366,7 +3401,7 @@ static int tcp_prune_queue(struct sock *sk);
 
 static void tcp_data_queue(struct sock *sk, struct sk_buff *skb)
 {
-       struct tcphdr *th = skb->h.th;
+       struct tcphdr *th = tcp_hdr(skb);
        struct tcp_sock *tp = tcp_sk(sk);
        int eaten = -1;
 
@@ -3424,7 +3459,7 @@ queue_and_out:
                }
                tp->rcv_nxt = TCP_SKB_CB(skb)->end_seq;
                if (skb->len)
-                       tcp_event_data_recv(sk, tp, skb);
+                       tcp_event_data_recv(sk, skb);
                if (th->fin)
                        tcp_fin(skb, sk, th);
 
@@ -3441,7 +3476,7 @@ queue_and_out:
                if (tp->rx_opt.num_sacks)
                        tcp_sack_remove(tp);
 
-               tcp_fast_path_check(sk, tp);
+               tcp_fast_path_check(sk);
 
                if (eaten > 0)
                        __kfree_skb(skb);
@@ -3605,7 +3640,7 @@ tcp_collapse(struct sock *sk, struct sk_buff_head *list,
                 * - bloated or contains data before "start" or
                 *   overlaps to the next one.
                 */
-               if (!skb->h.th->syn && !skb->h.th->fin &&
+               if (!tcp_hdr(skb)->syn && !tcp_hdr(skb)->fin &&
                    (tcp_win_from_space(skb->truesize) > skb->len ||
                     before(TCP_SKB_CB(skb)->seq, start) ||
                     (skb->next != tail &&
@@ -3616,7 +3651,7 @@ tcp_collapse(struct sock *sk, struct sk_buff_head *list,
                start = TCP_SKB_CB(skb)->end_seq;
                skb = skb->next;
        }
-       if (skb == tail || skb->h.th->syn || skb->h.th->fin)
+       if (skb == tail || tcp_hdr(skb)->syn || tcp_hdr(skb)->fin)
                return;
 
        while (before(start, end)) {
@@ -3633,10 +3668,11 @@ tcp_collapse(struct sock *sk, struct sk_buff_head *list,
                if (!nskb)
                        return;
 
-               nskb->mac.raw = nskb->data + (skb->mac.raw - skb->head);
-               nskb->nh.raw = nskb->data + (skb->nh.raw - skb->head);
-               nskb->h.raw = nskb->data + (skb->h.raw - skb->head);
-
+               skb_set_mac_header(nskb, skb_mac_header(skb) - skb->head);
+               skb_set_network_header(nskb, (skb_network_header(skb) -
+                                             skb->head));
+               skb_set_transport_header(nskb, (skb_transport_header(skb) -
+                                               skb->head));
                skb_reserve(nskb, header);
                memcpy(nskb->head, skb->head, header);
                memcpy(nskb->cb, skb->cb, sizeof(skb->cb));
@@ -3664,7 +3700,9 @@ tcp_collapse(struct sock *sk, struct sk_buff_head *list,
                                __kfree_skb(skb);
                                NET_INC_STATS_BH(LINUX_MIB_TCPRCVCOLLAPSED);
                                skb = next;
-                               if (skb == tail || skb->h.th->syn || skb->h.th->fin)
+                               if (skb == tail ||
+                                   tcp_hdr(skb)->syn ||
+                                   tcp_hdr(skb)->fin)
                                        return;
                        }
                }
@@ -3729,7 +3767,7 @@ static int tcp_prune_queue(struct sock *sk)
        NET_INC_STATS_BH(LINUX_MIB_PRUNECALLED);
 
        if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf)
-               tcp_clamp_window(sk, tp);
+               tcp_clamp_window(sk);
        else if (tcp_memory_pressure)
                tp->rcv_ssthresh = min(tp->rcv_ssthresh, 4U * tp->advmss);
 
@@ -3798,8 +3836,10 @@ void tcp_cwnd_application_limited(struct sock *sk)
        tp->snd_cwnd_stamp = tcp_time_stamp;
 }
 
-static int tcp_should_expand_sndbuf(struct sock *sk, struct tcp_sock *tp)
+static int tcp_should_expand_sndbuf(struct sock *sk)
 {
+       struct tcp_sock *tp = tcp_sk(sk);
+
        /* If the user specified a specific send buffer setting, do
         * not modify it.
         */
@@ -3831,7 +3871,7 @@ static void tcp_new_space(struct sock *sk)
 {
        struct tcp_sock *tp = tcp_sk(sk);
 
-       if (tcp_should_expand_sndbuf(sk, tp)) {
+       if (tcp_should_expand_sndbuf(sk)) {
                int sndmem = max_t(u32, tp->rx_opt.mss_clamp, tp->mss_cache) +
                        MAX_TCP_HEADER + 16 + sizeof(struct sk_buff),
                    demanded = max_t(unsigned int, tp->snd_cwnd,
@@ -3855,9 +3895,9 @@ static void tcp_check_space(struct sock *sk)
        }
 }
 
-static inline void tcp_data_snd_check(struct sock *sk, struct tcp_sock *tp)
+static inline void tcp_data_snd_check(struct sock *sk)
 {
-       tcp_push_pending_frames(sk, tp);
+       tcp_push_pending_frames(sk);
        tcp_check_space(sk);
 }
 
@@ -4005,7 +4045,7 @@ static int tcp_copy_to_iovec(struct sock *sk, struct sk_buff *skb, int hlen)
        int err;
 
        local_bh_enable();
-       if (skb->ip_summed==CHECKSUM_UNNECESSARY)
+       if (skb_csum_unnecessary(skb))
                err = skb_copy_datagram_iovec(skb, hlen, tp->ucopy.iov, chunk);
        else
                err = skb_copy_and_csum_datagram_iovec(skb, hlen,
@@ -4037,7 +4077,7 @@ static __sum16 __tcp_checksum_complete_user(struct sock *sk, struct sk_buff *skb
 
 static inline int tcp_checksum_complete_user(struct sock *sk, struct sk_buff *skb)
 {
-       return skb->ip_summed != CHECKSUM_UNNECESSARY &&
+       return !skb_csum_unnecessary(skb) &&
                __tcp_checksum_complete_user(sk, skb);
 }
 
@@ -4055,7 +4095,7 @@ static int tcp_dma_try_early_copy(struct sock *sk, struct sk_buff *skb, int hlen
        if (!tp->ucopy.dma_chan && tp->ucopy.pinned_list)
                tp->ucopy.dma_chan = get_softnet_dma();
 
-       if (tp->ucopy.dma_chan && skb->ip_summed == CHECKSUM_UNNECESSARY) {
+       if (tp->ucopy.dma_chan && skb_csum_unnecessary(skb)) {
 
                dma_cookie = dma_skb_copy_datagram_iovec(tp->ucopy.dma_chan,
                        skb, hlen, tp->ucopy.iov, chunk, tp->ucopy.pinned_list);
@@ -4071,7 +4111,7 @@ static int tcp_dma_try_early_copy(struct sock *sk, struct sk_buff *skb, int hlen
                tcp_rcv_space_adjust(sk);
 
                if ((tp->ucopy.len == 0) ||
-                   (tcp_flag_word(skb->h.th) & TCP_FLAG_PSH) ||
+                   (tcp_flag_word(tcp_hdr(skb)) & TCP_FLAG_PSH) ||
                    (atomic_read(&sk->sk_rmem_alloc) > (sk->sk_rcvbuf >> 1))) {
                        tp->ucopy.wakeup = 1;
                        sk->sk_data_ready(sk, 0);
@@ -4191,7 +4231,7 @@ int tcp_rcv_established(struct sock *sk, struct sk_buff *skb,
                                 */
                                tcp_ack(sk, skb, 0);
                                __kfree_skb(skb);
-                               tcp_data_snd_check(sk, tp);
+                               tcp_data_snd_check(sk);
                                return 0;
                        } else { /* Header too small */
                                TCP_INC_STATS_BH(TCP_MIB_INERRS);
@@ -4262,12 +4302,12 @@ int tcp_rcv_established(struct sock *sk, struct sk_buff *skb,
                                tp->rcv_nxt = TCP_SKB_CB(skb)->end_seq;
                        }
 
-                       tcp_event_data_recv(sk, tp, skb);
+                       tcp_event_data_recv(sk, skb);
 
                        if (TCP_SKB_CB(skb)->ack_seq != tp->snd_una) {
                                /* Well, only one small jumplet in fast path... */
                                tcp_ack(sk, skb, FLAG_DATA);
-                               tcp_data_snd_check(sk, tp);
+                               tcp_data_snd_check(sk);
                                if (!inet_csk_ack_scheduled(sk))
                                        goto no_ack;
                        }
@@ -4350,7 +4390,7 @@ step5:
        /* step 7: process the segment text */
        tcp_data_queue(sk, skb);
 
-       tcp_data_snd_check(sk, tp);
+       tcp_data_snd_check(sk);
        tcp_ack_snd_check(sk);
        return 0;
 
@@ -4667,7 +4707,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
                /* Do step6 onward by hand. */
                tcp_urg(sk, skb, th);
                __kfree_skb(skb);
-               tcp_data_snd_check(sk, tp);
+               tcp_data_snd_check(sk);
                return 0;
        }
 
@@ -4859,7 +4899,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
 
        /* tcp_data could move socket to TIME-WAIT */
        if (sk->sk_state != TCP_CLOSE) {
-               tcp_data_snd_check(sk, tp);
+               tcp_data_snd_check(sk);
                tcp_ack_snd_check(sk);
        }