ipv6: tcp: send consistent autoflowlabel in TIME_WAIT state
authorEric Dumazet <edumazet@google.com>
Sun, 9 Jun 2019 00:58:51 +0000 (17:58 -0700)
committerDavid S. Miller <davem@davemloft.net>
Mon, 10 Jun 2019 03:10:19 +0000 (20:10 -0700)
In case autoflowlabel is in action, skb_get_hash_flowi6()
derives a non zero skb->hash to the flowlabel.

If skb->hash is zero, a flow dissection is performed.

Since all TCP skbs sent from ESTABLISH state inherit their
skb->hash from sk->sk_txhash, we better keep a copy
of sk->sk_txhash into the TIME_WAIT socket.

After this patch, ACK or RST packets sent on behalf of
a TIME_WAIT socket have the flowlabel that was previously
used by the flow.

Signed-off-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/net/inet_timewait_sock.h
net/ipv4/tcp_minisocks.c
net/ipv6/tcp_ipv6.c

index c2f756aedc5453576d67076b20b7c5fa0e64de8a..aef38c140014600dbf88b1d664bad1b0adf63668 100644 (file)
@@ -70,6 +70,7 @@ struct inet_timewait_sock {
                                tw_flowlabel    : 20,
                                tw_pad          : 2,    /* 2 bits hole */
                                tw_tos          : 8;
+       u32                     tw_txhash;
        struct timer_list       tw_timer;
        struct inet_bind_bucket *tw_tb;
 };
index 7c35731816e23fe0f82351d3848bf13379efad5f..11011e8386dc97254a752514e4e6f77a068efaf4 100644 (file)
@@ -283,6 +283,7 @@ void tcp_time_wait(struct sock *sk, int state, int timeo)
                        tw->tw_v6_rcv_saddr = sk->sk_v6_rcv_saddr;
                        tw->tw_tclass = np->tclass;
                        tw->tw_flowlabel = be32_to_cpu(np->flow_label & IPV6_FLOWLABEL_MASK);
+                       tw->tw_txhash = sk->sk_txhash;
                        tw->tw_ipv6only = sk->sk_ipv6only;
                }
 #endif
index c1da52c7f990f2fa3e020e3f3a33934149ad225e..ad7039137a20f9ad8581d9ca01347c67aa8a8433 100644 (file)
@@ -883,9 +883,16 @@ static void tcp_v6_send_response(const struct sock *sk, struct sk_buff *skb, u32
                fl6.flowi6_oif = oif;
        }
 
-       if (sk)
-               mark = (sk->sk_state == TCP_TIME_WAIT) ?
-                       inet_twsk(sk)->tw_mark : sk->sk_mark;
+       if (sk) {
+               if (sk->sk_state == TCP_TIME_WAIT) {
+                       mark = inet_twsk(sk)->tw_mark;
+                       /* autoflowlabel relies on buff->hash */
+                       skb_set_hash(buff, inet_twsk(sk)->tw_txhash,
+                                    PKT_HASH_TYPE_L4);
+               } else {
+                       mark = sk->sk_mark;
+               }
+       }
        fl6.flowi6_mark = IP6_REPLY_MARK(net, skb->mark) ?: mark;
        fl6.fl6_dport = t1->dest;
        fl6.fl6_sport = t1->source;