All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net-next 0/2] ipv4: Invalidate neighbour for broadcast address upon address addition
@ 2022-02-19 15:45 Ido Schimmel
  2022-02-19 15:45 ` [PATCH net-next 1/2] " Ido Schimmel
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Ido Schimmel @ 2022-02-19 15:45 UTC (permalink / raw)
  To: netdev; +Cc: davem, kuba, dsahern, wanghai38, mlxsw, Ido Schimmel

Patch #1 solves a recently reported issue [1]. See detailed description
in the changelog.

Patch #2 adds a matching test case.

Targeting at net-next since as far as I can tell this use case never
worked.

There are no regressions in fib_tests.sh with this change:

 # ./fib_tests.sh
 ...
 Tests passed: 186
 Tests failed:   0

[1] https://lore.kernel.org/netdev/55a04a8f-56f3-f73c-2aea-2195923f09d1@huawei.com/

Ido Schimmel (2):
  ipv4: Invalidate neighbour for broadcast address upon address addition
  selftests: fib_test: Add a test case for IPv4 broadcast neighbours

 include/net/arp.h                        |  1 +
 net/ipv4/arp.c                           |  9 +++-
 net/ipv4/fib_frontend.c                  |  5 +-
 tools/testing/selftests/net/fib_tests.sh | 58 +++++++++++++++++++++++-
 4 files changed, 69 insertions(+), 4 deletions(-)

-- 
2.33.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH net-next 1/2] ipv4: Invalidate neighbour for broadcast address upon address addition
  2022-02-19 15:45 [PATCH net-next 0/2] ipv4: Invalidate neighbour for broadcast address upon address addition Ido Schimmel
@ 2022-02-19 15:45 ` Ido Schimmel
  2022-02-21  4:44   ` wanghai (M)
  2022-02-19 15:45 ` [PATCH net-next 2/2] selftests: fib_test: Add a test case for IPv4 broadcast neighbours Ido Schimmel
  2022-02-21 12:00 ` [PATCH net-next 0/2] ipv4: Invalidate neighbour for broadcast address upon address addition patchwork-bot+netdevbpf
  2 siblings, 1 reply; 5+ messages in thread
From: Ido Schimmel @ 2022-02-19 15:45 UTC (permalink / raw)
  To: netdev; +Cc: davem, kuba, dsahern, wanghai38, mlxsw, Ido Schimmel

In case user space sends a packet destined to a broadcast address when a
matching broadcast route is not configured, the kernel will create a
unicast neighbour entry that will never be resolved [1].

When the broadcast route is configured, the unicast neighbour entry will
not be invalidated and continue to linger, resulting in packets being
dropped.

Solve this by invalidating unresolved neighbour entries for broadcast
addresses after routes for these addresses are internally configured by
the kernel. This allows the kernel to create a broadcast neighbour entry
following the next route lookup.

Another possible solution that is more generic but also more complex is
to have the ARP code register a listener to the FIB notification chain
and invalidate matching neighbour entries upon the addition of broadcast
routes.

It is also possible to wave off the issue as a user space problem, but
it seems a bit excessive to expect user space to be that intimately
familiar with the inner workings of the FIB/neighbour kernel code.

[1] https://lore.kernel.org/netdev/55a04a8f-56f3-f73c-2aea-2195923f09d1@huawei.com/

Reported-by: Wang Hai <wanghai38@huawei.com>
Signed-off-by: Ido Schimmel <idosch@nvidia.com>
---
Wang Hai, please retest as I have changed the patch a bit.
---
 include/net/arp.h       | 1 +
 net/ipv4/arp.c          | 9 +++++++--
 net/ipv4/fib_frontend.c | 5 ++++-
 3 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/include/net/arp.h b/include/net/arp.h
index 031374ac2f22..d7ef4ec71dfe 100644
--- a/include/net/arp.h
+++ b/include/net/arp.h
@@ -65,6 +65,7 @@ void arp_send(int type, int ptype, __be32 dest_ip,
 	      const unsigned char *src_hw, const unsigned char *th);
 int arp_mc_map(__be32 addr, u8 *haddr, struct net_device *dev, int dir);
 void arp_ifdown(struct net_device *dev);
+int arp_invalidate(struct net_device *dev, __be32 ip, bool force);
 
 struct sk_buff *arp_create(int type, int ptype, __be32 dest_ip,
 			   struct net_device *dev, __be32 src_ip,
diff --git a/net/ipv4/arp.c b/net/ipv4/arp.c
index 4db0325f6e1a..dc28f0588e54 100644
--- a/net/ipv4/arp.c
+++ b/net/ipv4/arp.c
@@ -1116,13 +1116,18 @@ static int arp_req_get(struct arpreq *r, struct net_device *dev)
 	return err;
 }
 
-static int arp_invalidate(struct net_device *dev, __be32 ip)
+int arp_invalidate(struct net_device *dev, __be32 ip, bool force)
 {
 	struct neighbour *neigh = neigh_lookup(&arp_tbl, &ip, dev);
 	int err = -ENXIO;
 	struct neigh_table *tbl = &arp_tbl;
 
 	if (neigh) {
+		if ((neigh->nud_state & NUD_VALID) && !force) {
+			neigh_release(neigh);
+			return 0;
+		}
+
 		if (neigh->nud_state & ~NUD_NOARP)
 			err = neigh_update(neigh, NULL, NUD_FAILED,
 					   NEIGH_UPDATE_F_OVERRIDE|
@@ -1169,7 +1174,7 @@ static int arp_req_delete(struct net *net, struct arpreq *r,
 		if (!dev)
 			return -EINVAL;
 	}
-	return arp_invalidate(dev, ip);
+	return arp_invalidate(dev, ip, true);
 }
 
 /*
diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
index e0730c4d07d6..7408051632ac 100644
--- a/net/ipv4/fib_frontend.c
+++ b/net/ipv4/fib_frontend.c
@@ -1124,9 +1124,11 @@ void fib_add_ifaddr(struct in_ifaddr *ifa)
 		return;
 
 	/* Add broadcast address, if it is explicitly assigned. */
-	if (ifa->ifa_broadcast && ifa->ifa_broadcast != htonl(0xFFFFFFFF))
+	if (ifa->ifa_broadcast && ifa->ifa_broadcast != htonl(0xFFFFFFFF)) {
 		fib_magic(RTM_NEWROUTE, RTN_BROADCAST, ifa->ifa_broadcast, 32,
 			  prim, 0);
+		arp_invalidate(dev, ifa->ifa_broadcast, false);
+	}
 
 	if (!ipv4_is_zeronet(prefix) && !(ifa->ifa_flags & IFA_F_SECONDARY) &&
 	    (prefix != addr || ifa->ifa_prefixlen < 32)) {
@@ -1140,6 +1142,7 @@ void fib_add_ifaddr(struct in_ifaddr *ifa)
 		if (ifa->ifa_prefixlen < 31) {
 			fib_magic(RTM_NEWROUTE, RTN_BROADCAST, prefix | ~mask,
 				  32, prim, 0);
+			arp_invalidate(dev, prefix | ~mask, false);
 		}
 	}
 }
-- 
2.33.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH net-next 2/2] selftests: fib_test: Add a test case for IPv4 broadcast neighbours
  2022-02-19 15:45 [PATCH net-next 0/2] ipv4: Invalidate neighbour for broadcast address upon address addition Ido Schimmel
  2022-02-19 15:45 ` [PATCH net-next 1/2] " Ido Schimmel
@ 2022-02-19 15:45 ` Ido Schimmel
  2022-02-21 12:00 ` [PATCH net-next 0/2] ipv4: Invalidate neighbour for broadcast address upon address addition patchwork-bot+netdevbpf
  2 siblings, 0 replies; 5+ messages in thread
From: Ido Schimmel @ 2022-02-19 15:45 UTC (permalink / raw)
  To: netdev; +Cc: davem, kuba, dsahern, wanghai38, mlxsw, Ido Schimmel

Test that resolved neighbours for IPv4 broadcast addresses are
unaffected by the configuration of matching broadcast routes, whereas
unresolved neighbours are invalidated.

Without previous patch:

 # ./fib_tests.sh -t ipv4_bcast_neigh

 IPv4 broadcast neighbour tests
     TEST: Resolved neighbour for broadcast address                      [ OK ]
     TEST: Resolved neighbour for network broadcast address              [ OK ]
     TEST: Unresolved neighbour for broadcast address                    [FAIL]
     TEST: Unresolved neighbour for network broadcast address            [FAIL]

 Tests passed:   2
 Tests failed:   2

With previous patch:

 # ./fib_tests.sh -t ipv4_bcast_neigh

 IPv4 broadcast neighbour tests
     TEST: Resolved neighbour for broadcast address                      [ OK ]
     TEST: Resolved neighbour for network broadcast address              [ OK ]
     TEST: Unresolved neighbour for broadcast address                    [ OK ]
     TEST: Unresolved neighbour for network broadcast address            [ OK ]

 Tests passed:   4
 Tests failed:   0

Signed-off-by: Ido Schimmel <idosch@nvidia.com>
---
 tools/testing/selftests/net/fib_tests.sh | 58 +++++++++++++++++++++++-
 1 file changed, 57 insertions(+), 1 deletion(-)

diff --git a/tools/testing/selftests/net/fib_tests.sh b/tools/testing/selftests/net/fib_tests.sh
index e2690cc42da3..2271a8727f62 100755
--- a/tools/testing/selftests/net/fib_tests.sh
+++ b/tools/testing/selftests/net/fib_tests.sh
@@ -9,7 +9,7 @@ ret=0
 ksft_skip=4
 
 # all tests in this script. Can be overridden with -t option
-TESTS="unregister down carrier nexthop suppress ipv6_rt ipv4_rt ipv6_addr_metric ipv4_addr_metric ipv6_route_metrics ipv4_route_metrics ipv4_route_v6_gw rp_filter ipv4_del_addr ipv4_mangle ipv6_mangle"
+TESTS="unregister down carrier nexthop suppress ipv6_rt ipv4_rt ipv6_addr_metric ipv4_addr_metric ipv6_route_metrics ipv4_route_metrics ipv4_route_v6_gw rp_filter ipv4_del_addr ipv4_mangle ipv6_mangle ipv4_bcast_neigh"
 
 VERBOSE=0
 PAUSE_ON_FAIL=no
@@ -1954,6 +1954,61 @@ ipv6_mangle_test()
 	route_cleanup
 }
 
+ip_neigh_get_check()
+{
+	ip neigh help 2>&1 | grep -q 'ip neigh get'
+	if [ $? -ne 0 ]; then
+		echo "iproute2 command does not support neigh get. Skipping test"
+		return 1
+	fi
+
+	return 0
+}
+
+ipv4_bcast_neigh_test()
+{
+	local rc
+
+	echo
+	echo "IPv4 broadcast neighbour tests"
+
+	ip_neigh_get_check || return 1
+
+	setup
+
+	set -e
+	run_cmd "$IP neigh add 192.0.2.111 lladdr 00:11:22:33:44:55 nud perm dev dummy0"
+	run_cmd "$IP neigh add 192.0.2.255 lladdr 00:11:22:33:44:55 nud perm dev dummy0"
+
+	run_cmd "$IP neigh get 192.0.2.111 dev dummy0"
+	run_cmd "$IP neigh get 192.0.2.255 dev dummy0"
+
+	run_cmd "$IP address add 192.0.2.1/24 broadcast 192.0.2.111 dev dummy0"
+
+	run_cmd "$IP neigh add 203.0.113.111 nud failed dev dummy0"
+	run_cmd "$IP neigh add 203.0.113.255 nud failed dev dummy0"
+
+	run_cmd "$IP neigh get 203.0.113.111 dev dummy0"
+	run_cmd "$IP neigh get 203.0.113.255 dev dummy0"
+
+	run_cmd "$IP address add 203.0.113.1/24 broadcast 203.0.113.111 dev dummy0"
+	set +e
+
+	run_cmd "$IP neigh get 192.0.2.111 dev dummy0"
+	log_test $? 0 "Resolved neighbour for broadcast address"
+
+	run_cmd "$IP neigh get 192.0.2.255 dev dummy0"
+	log_test $? 0 "Resolved neighbour for network broadcast address"
+
+	run_cmd "$IP neigh get 203.0.113.111 dev dummy0"
+	log_test $? 2 "Unresolved neighbour for broadcast address"
+
+	run_cmd "$IP neigh get 203.0.113.255 dev dummy0"
+	log_test $? 2 "Unresolved neighbour for network broadcast address"
+
+	cleanup
+}
+
 ################################################################################
 # usage
 
@@ -2028,6 +2083,7 @@ do
 	ipv4_route_v6_gw)		ipv4_route_v6_gw_test;;
 	ipv4_mangle)			ipv4_mangle_test;;
 	ipv6_mangle)			ipv6_mangle_test;;
+	ipv4_bcast_neigh)		ipv4_bcast_neigh_test;;
 
 	help) echo "Test names: $TESTS"; exit 0;;
 	esac
-- 
2.33.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH net-next 1/2] ipv4: Invalidate neighbour for broadcast address upon address addition
  2022-02-19 15:45 ` [PATCH net-next 1/2] " Ido Schimmel
@ 2022-02-21  4:44   ` wanghai (M)
  0 siblings, 0 replies; 5+ messages in thread
From: wanghai (M) @ 2022-02-21  4:44 UTC (permalink / raw)
  To: Ido Schimmel, netdev; +Cc: davem, kuba, dsahern, mlxsw


在 2022/2/19 23:45, Ido Schimmel 写道:
> In case user space sends a packet destined to a broadcast address when a
> matching broadcast route is not configured, the kernel will create a
> unicast neighbour entry that will never be resolved [1].
>
> When the broadcast route is configured, the unicast neighbour entry will
> not be invalidated and continue to linger, resulting in packets being
> dropped.
>
> Solve this by invalidating unresolved neighbour entries for broadcast
> addresses after routes for these addresses are internally configured by
> the kernel. This allows the kernel to create a broadcast neighbour entry
> following the next route lookup.
>
> Another possible solution that is more generic but also more complex is
> to have the ARP code register a listener to the FIB notification chain
> and invalidate matching neighbour entries upon the addition of broadcast
> routes.
>
> It is also possible to wave off the issue as a user space problem, but
> it seems a bit excessive to expect user space to be that intimately
> familiar with the inner workings of the FIB/neighbour kernel code.
>
> [1] https://lore.kernel.org/netdev/55a04a8f-56f3-f73c-2aea-2195923f09d1@huawei.com/
>
> Reported-by: Wang Hai <wanghai38@huawei.com>
> Signed-off-by: Ido Schimmel <idosch@nvidia.com>
> ---
> Wang Hai, please retest as I have changed the patch a bit.
Thanks, retested and it worked.

Tested-by: Wang Hai <wanghai38@huawei.com>

-- 
Wang Hai


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH net-next 0/2] ipv4: Invalidate neighbour for broadcast address upon address addition
  2022-02-19 15:45 [PATCH net-next 0/2] ipv4: Invalidate neighbour for broadcast address upon address addition Ido Schimmel
  2022-02-19 15:45 ` [PATCH net-next 1/2] " Ido Schimmel
  2022-02-19 15:45 ` [PATCH net-next 2/2] selftests: fib_test: Add a test case for IPv4 broadcast neighbours Ido Schimmel
@ 2022-02-21 12:00 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 5+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-02-21 12:00 UTC (permalink / raw)
  To: Ido Schimmel; +Cc: netdev, davem, kuba, dsahern, wanghai38, mlxsw

Hello:

This series was applied to netdev/net-next.git (master)
by David S. Miller <davem@davemloft.net>:

On Sat, 19 Feb 2022 17:45:18 +0200 you wrote:
> Patch #1 solves a recently reported issue [1]. See detailed description
> in the changelog.
> 
> Patch #2 adds a matching test case.
> 
> Targeting at net-next since as far as I can tell this use case never
> worked.
> 
> [...]

Here is the summary with links:
  - [net-next,1/2] ipv4: Invalidate neighbour for broadcast address upon address addition
    https://git.kernel.org/netdev/net-next/c/0c51e12e218f
  - [net-next,2/2] selftests: fib_test: Add a test case for IPv4 broadcast neighbours
    https://git.kernel.org/netdev/net-next/c/25bd462fa42f

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-02-21 12:01 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-19 15:45 [PATCH net-next 0/2] ipv4: Invalidate neighbour for broadcast address upon address addition Ido Schimmel
2022-02-19 15:45 ` [PATCH net-next 1/2] " Ido Schimmel
2022-02-21  4:44   ` wanghai (M)
2022-02-19 15:45 ` [PATCH net-next 2/2] selftests: fib_test: Add a test case for IPv4 broadcast neighbours Ido Schimmel
2022-02-21 12:00 ` [PATCH net-next 0/2] ipv4: Invalidate neighbour for broadcast address upon address addition patchwork-bot+netdevbpf

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.