netfilter: nft_flow_offload: Fix reverse route lookup
authorwenxu <wenxu@ucloud.cn>
Wed, 9 Jan 2019 02:40:11 +0000 (10:40 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 27 Feb 2019 09:08:53 +0000 (10:08 +0100)
[ Upstream commit a799aea0988ea0d1b1f263e996fdad2f6133c680 ]

Using the following example:

client 1.1.1.7 ---> 2.2.2.7 which dnat to 10.0.0.7 server

The first reply packet (ie. syn+ack) uses an incorrect destination
address for the reverse route lookup since it uses:

daddr = ct->tuplehash[!dir].tuple.dst.u3.ip;

which is 2.2.2.7 in the scenario that is described above, while this
should be:

daddr = ct->tuplehash[dir].tuple.src.u3.ip;

that is 10.0.0.7.

Signed-off-by: wenxu <wenxu@ucloud.cn>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
net/netfilter/nft_flow_offload.c

index 5fd4c57c79cc900a77b57e0f7aa1810a58083772..e0c04851a349365c0cd8e40010154ade65cac733 100644 (file)
@@ -29,10 +29,10 @@ static int nft_flow_route(const struct nft_pktinfo *pkt,
        memset(&fl, 0, sizeof(fl));
        switch (nft_pf(pkt)) {
        case NFPROTO_IPV4:
-               fl.u.ip4.daddr = ct->tuplehash[!dir].tuple.dst.u3.ip;
+               fl.u.ip4.daddr = ct->tuplehash[dir].tuple.src.u3.ip;
                break;
        case NFPROTO_IPV6:
-               fl.u.ip6.daddr = ct->tuplehash[!dir].tuple.dst.u3.in6;
+               fl.u.ip6.daddr = ct->tuplehash[dir].tuple.src.u3.in6;
                break;
        }