tcp: be more strict before accepting ECN negociation
authorEric Dumazet <edumazet@google.com>
Fri, 4 May 2012 05:14:02 +0000 (05:14 +0000)
committerDavid S. Miller <davem@davemloft.net>
Fri, 4 May 2012 16:05:27 +0000 (12:05 -0400)
It appears some networks play bad games with the two bits reserved for
ECN. This can trigger false congestion notifications and very slow
transferts.

Since RFC 3168 (6.1.1) forbids SYN packets to carry CT bits, we can
disable TCP ECN negociation if it happens we receive mangled CT bits in
the SYN packet.

Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Perry Lorier <perryl@google.com>
Cc: Matt Mathis <mattmathis@google.com>
Cc: Yuchung Cheng <ycheng@google.com>
Cc: Neal Cardwell <ncardwell@google.com>
Cc: Wilmer van der Gaast <wilmer@google.com>
Cc: Ankur Jain <jankur@google.com>
Cc: Tom Herbert <therbert@google.com>
Cc: Dave Täht <dave.taht@bufferbloat.net>
Acked-by: Neal Cardwell <ncardwell@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/net/tcp.h
net/ipv4/tcp_ipv4.c
net/ipv6/tcp_ipv6.c

index c826ed7b007b0a5483061bc21e2f11d55b28814b..92faa6a7ea972ab29617f4b71e1d06aef1632d1b 100644 (file)
@@ -367,13 +367,6 @@ static inline void tcp_dec_quickack_mode(struct sock *sk,
 #define        TCP_ECN_DEMAND_CWR      4
 #define        TCP_ECN_SEEN            8
 
-static __inline__ void
-TCP_ECN_create_request(struct request_sock *req, struct tcphdr *th)
-{
-       if (sysctl_tcp_ecn && th->ece && th->cwr)
-               inet_rsk(req)->ecn_ok = 1;
-}
-
 enum tcp_tw_status {
        TCP_TW_SUCCESS = 0,
        TCP_TW_RST = 1,
@@ -671,6 +664,22 @@ struct tcp_skb_cb {
 
 #define TCP_SKB_CB(__skb)      ((struct tcp_skb_cb *)&((__skb)->cb[0]))
 
+/* RFC3168 : 6.1.1 SYN packets must not have ECT/ECN bits set
+ *
+ * If we receive a SYN packet with these bits set, it means a network is
+ * playing bad games with TOS bits. In order to avoid possible false congestion
+ * notifications, we disable TCP ECN negociation.
+ */
+static inline void
+TCP_ECN_create_request(struct request_sock *req, const struct sk_buff *skb)
+{
+       const struct tcphdr *th = tcp_hdr(skb);
+
+       if (sysctl_tcp_ecn && th->ece && th->cwr &&
+           INET_ECN_is_not_ect(TCP_SKB_CB(skb)->ip_dsfield))
+               inet_rsk(req)->ecn_ok = 1;
+}
+
 /* Due to TSO, an SKB can be composed of multiple actual
  * packets.  To keep these tracked properly, we use this.
  */
index cf97e9821d76b352f0f786f1201967db8dd0d6ea..4ff5e1f70d16a80014356b11b643df64f1221b70 100644 (file)
@@ -1368,7 +1368,7 @@ int tcp_v4_conn_request(struct sock *sk, struct sk_buff *skb)
                goto drop_and_free;
 
        if (!want_cookie || tmp_opt.tstamp_ok)
-               TCP_ECN_create_request(req, tcp_hdr(skb));
+               TCP_ECN_create_request(req, skb);
 
        if (want_cookie) {
                isn = cookie_v4_init_sequence(sk, skb, &req->mss);
index 57b210969834f869344b18443d1a8b3671b333c0..078d039e8fd23ed08a853506a607ac25b140b735 100644 (file)
@@ -1140,7 +1140,7 @@ static int tcp_v6_conn_request(struct sock *sk, struct sk_buff *skb)
        treq->rmt_addr = ipv6_hdr(skb)->saddr;
        treq->loc_addr = ipv6_hdr(skb)->daddr;
        if (!want_cookie || tmp_opt.tstamp_ok)
-               TCP_ECN_create_request(req, tcp_hdr(skb));
+               TCP_ECN_create_request(req, skb);
 
        treq->iif = sk->sk_bound_dev_if;
 
This page took 0.051669 seconds and 5 git commands to generate.