[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <a9366e02-5b12-967f-621a-3ffc979101d1@huawei.com>
Date: Mon, 17 Jun 2019 10:31:59 +0800
From: "Luoshijie (Poincare Lab)" <luoshijie1@...wei.com>
To: David Ahern <dsahern@...il.com>, <davem@...emloft.net>,
<tgraf@...g.ch>
CC: <netdev@...r.kernel.org>, <viro@...iv.linux.org.uk>
Subject: Re: [PATCH] ipv4: fix inet_select_addr() when enable route_localnet
On 2019/6/15 9:00, David Ahern wrote:
> On 6/14/19 10:55 AM, luoshijie wrote:
>> From: Shijie Luo <luoshijie1@...wei.com>
>>
>> Suppose we have two interfaces eth0 and eth1 in two hosts, follow
>> the same steps in the two hosts:
>> # sysctl -w net.ipv4.conf.eth1.route_localnet=1
>> # sysctl -w net.ipv4.conf.eth1.arp_announce=2
>> # ip route del 127.0.0.0/8 dev lo table local
>> and then set ip to eth1 in host1 like:
>> # ifconfig eth1 127.25.3.4/24
>> set ip to eth2 in host2 and ping host1:
>> # ifconfig eth1 127.25.3.14/24
>> # ping -I eth1 127.25.3.4
>> Well, host2 cannot connect to host1.
>
> Since you already have the commands, create a test script in
> tools/testing/selftests/net that uses network namespaces for host1 and
> host2 and demonstrates the problem. There quite a few examples in that
> directory to use as a template. eg., see icmp_redirect.sh
>
Thanks for your advice, I will follow it to add a testcase to demonstrate the problem.
>> diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
>> index ea4bd8a52..325fafd4b 100644
>> --- a/net/ipv4/devinet.c
>> +++ b/net/ipv4/devinet.c
>> @@ -1249,14 +1249,19 @@ __be32 inet_select_addr(const struct net_device *dev, __be32 dst, int scope)
>> struct in_device *in_dev;
>> struct net *net = dev_net(dev);
>> int master_idx;
>> + unsigned char localnet_scope = RT_SCOPE_HOST;
>
> net code uses reverse xmas tree ordering. ie., move that up.
>
>>
>> rcu_read_lock();
>> in_dev = __in_dev_get_rcu(dev);
>> if (!in_dev)
>> goto no_in_dev;
>>
>> + if (unlikely(IN_DEV_ROUTE_LOCALNET(in_dev))) {
>> + localnet_scope = RT_SCOPE_LINK;
>> + }
>> +
>
> brackets are not needed.
>
>
>> for_primary_ifa(in_dev) {
>> - if (ifa->ifa_scope > scope)
>> + if (min(ifa->ifa_scope, localnet_scope) > scope)
>> continue;
>> if (!dst || inet_ifa_match(dst, ifa)) {
>> addr = ifa->ifa_local;
>>
>
>
> .
>
Thanks for your reply and I really appreciate your advice very much.
I will soon add the testcase and submit the V2 patch.
Powered by blists - more mailing lists