netfilter: ipt_SYNPROXY: Pass snet into synproxy_send_tcp
[cascardo/linux.git] / net / ipv4 / tcp_input.c
index 0abca28..497adf5 100644 (file)
@@ -753,13 +753,29 @@ static void tcp_rtt_estimator(struct sock *sk, long mrtt_us)
  * TCP pacing, to smooth the burst on large writes when packets
  * in flight is significantly lower than cwnd (or rwin)
  */
+int sysctl_tcp_pacing_ss_ratio __read_mostly = 200;
+int sysctl_tcp_pacing_ca_ratio __read_mostly = 120;
+
 static void tcp_update_pacing_rate(struct sock *sk)
 {
        const struct tcp_sock *tp = tcp_sk(sk);
        u64 rate;
 
        /* set sk_pacing_rate to 200 % of current rate (mss * cwnd / srtt) */
-       rate = (u64)tp->mss_cache * 2 * (USEC_PER_SEC << 3);
+       rate = (u64)tp->mss_cache * ((USEC_PER_SEC / 100) << 3);
+
+       /* current rate is (cwnd * mss) / srtt
+        * In Slow Start [1], set sk_pacing_rate to 200 % the current rate.
+        * In Congestion Avoidance phase, set it to 120 % the current rate.
+        *
+        * [1] : Normal Slow Start condition is (tp->snd_cwnd < tp->snd_ssthresh)
+        *       If snd_cwnd >= (tp->snd_ssthresh / 2), we are approaching
+        *       end of slow start and should slow down.
+        */
+       if (tp->snd_cwnd < tp->snd_ssthresh / 2)
+               rate *= sysctl_tcp_pacing_ss_ratio;
+       else
+               rate *= sysctl_tcp_pacing_ca_ratio;
 
        rate *= max(tp->snd_cwnd, tp->packets_out);
 
@@ -2937,21 +2953,21 @@ static inline bool tcp_ack_update_rtt(struct sock *sk, const int flag,
 }
 
 /* Compute time elapsed between (last) SYNACK and the ACK completing 3WHS. */
-static void tcp_synack_rtt_meas(struct sock *sk, const u32 synack_stamp)
+void tcp_synack_rtt_meas(struct sock *sk, struct request_sock *req)
 {
-       struct tcp_sock *tp = tcp_sk(sk);
-       long seq_rtt_us = -1L;
+       long rtt_us = -1L;
 
-       if (synack_stamp && !tp->total_retrans)
-               seq_rtt_us = jiffies_to_usecs(tcp_time_stamp - synack_stamp);
+       if (req && !req->num_retrans && tcp_rsk(req)->snt_synack.v64) {
+               struct skb_mstamp now;
 
-       /* If the ACK acks both the SYNACK and the (Fast Open'd) data packets
-        * sent in SYN_RECV, SYNACK RTT is the smooth RTT computed in tcp_ack()
-        */
-       if (!tp->srtt_us)
-               tcp_ack_update_rtt(sk, FLAG_SYN_ACKED, seq_rtt_us, -1L);
+               skb_mstamp_get(&now);
+               rtt_us = skb_mstamp_us_delta(&now, &tcp_rsk(req)->snt_synack);
+       }
+
+       tcp_ack_update_rtt(sk, FLAG_SYN_ACKED, rtt_us, -1L);
 }
 
+
 static void tcp_cong_avoid(struct sock *sk, u32 ack, u32 acked)
 {
        const struct inet_connection_sock *icsk = inet_csk(sk);
@@ -5690,7 +5706,6 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
        struct request_sock *req;
        int queued = 0;
        bool acceptable;
-       u32 synack_stamp;
 
        tp->rx_opt.saw_tstamp = 0;
 
@@ -5769,15 +5784,16 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
                if (!acceptable)
                        return 1;
 
+               if (!tp->srtt_us)
+                       tcp_synack_rtt_meas(sk, req);
+
                /* Once we leave TCP_SYN_RECV, we no longer need req
                 * so release it.
                 */
                if (req) {
-                       synack_stamp = tcp_rsk(req)->snt_synack;
                        tp->total_retrans = req->num_retrans;
                        reqsk_fastopen_remove(sk, req, false);
                } else {
-                       synack_stamp = tp->lsndtime;
                        /* Make sure socket is routed, for correct metrics. */
                        icsk->icsk_af_ops->rebuild_header(sk);
                        tcp_init_congestion_control(sk);
@@ -5800,7 +5816,6 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
                tp->snd_una = TCP_SKB_CB(skb)->ack_seq;
                tp->snd_wnd = ntohs(th->window) << tp->rx_opt.snd_wscale;
                tcp_init_wl(tp, TCP_SKB_CB(skb)->seq);
-               tcp_synack_rtt_meas(sk, synack_stamp);
 
                if (tp->rx_opt.tstamp_ok)
                        tp->advmss -= TCPOLEN_TSTAMP_ALIGNED;
@@ -5987,14 +6002,17 @@ static void tcp_ecn_create_request(struct request_sock *req,
        const struct net *net = sock_net(listen_sk);
        bool th_ecn = th->ece && th->cwr;
        bool ect, ecn_ok;
+       u32 ecn_ok_dst;
 
        if (!th_ecn)
                return;
 
        ect = !INET_ECN_is_not_ect(TCP_SKB_CB(skb)->ip_dsfield);
-       ecn_ok = net->ipv4.sysctl_tcp_ecn || dst_feature(dst, RTAX_FEATURE_ECN);
+       ecn_ok_dst = dst_feature(dst, DST_FEATURE_ECN_MASK);
+       ecn_ok = net->ipv4.sysctl_tcp_ecn || ecn_ok_dst;
 
-       if ((!ect && ecn_ok) || tcp_ca_needs_ecn(listen_sk))
+       if ((!ect && ecn_ok) || tcp_ca_needs_ecn(listen_sk) ||
+           (ecn_ok_dst & DST_FEATURE_ECN_CA))
                inet_rsk(req)->ecn_ok = 1;
 }
 
@@ -6008,7 +6026,7 @@ static void tcp_openreq_init(struct request_sock *req,
        req->cookie_ts = 0;
        tcp_rsk(req)->rcv_isn = TCP_SKB_CB(skb)->seq;
        tcp_rsk(req)->rcv_nxt = TCP_SKB_CB(skb)->seq + 1;
-       tcp_rsk(req)->snt_synack = tcp_time_stamp;
+       skb_mstamp_get(&tcp_rsk(req)->snt_synack);
        tcp_rsk(req)->last_oow_ack_time = 0;
        req->mss = rx_opt->mss_clamp;
        req->ts_recent = rx_opt->saw_tstamp ? rx_opt->rcv_tsval : 0;
@@ -6209,6 +6227,7 @@ int tcp_conn_request(struct request_sock_ops *rsk_ops,
        }
 
        tcp_rsk(req)->snt_isn = isn;
+       tcp_rsk(req)->txhash = net_tx_rndhash();
        tcp_openreq_init_rwin(req, sk, dst);
        fastopen = !want_cookie &&
                   tcp_try_fastopen(sk, skb, req, &foc, dst);