[PATCH net-next v2 2/2] selftests: drv-net: ncdevmem: gracefully retry bind()

Mina Almasry <[email protected]>
Newsgroups gmane.linux.kernel,gmane.linux.network
Message-ID <[email protected]>
During tests, ethnl_rings_set randomly bounces the link causing a
transient IPv6 Duplicate Address Detection "tentative" race, resulting
in spurious -EADDRNOTAVAIL aborts inside the ncdevmem server.

Add a simple 10 second retry loop around bind() to absorb the link bounce.

Signed-off-by: Mina Almasry <[email protected]>
---
v2:
- Refactored C99 mid-scope variables to strictly adhere to C89 styling.
- Dropped single-line curly brace avoidance syntax.
v1: https://patchwork.kernel.org/project/netdevbpf/patch/[email protected]/
---
 tools/testing/selftests/drivers/net/hw/ncdevmem.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/tools/testing/selftests/drivers/net/hw/ncdevmem.c b/tools/testing/selftests/drivers/net/hw/ncdevmem.c
index ffe1d5c1fa4e1..67901a0123e8c 100644
--- a/tools/testing/selftests/drivers/net/hw/ncdevmem.c
+++ b/tools/testing/selftests/drivers/net/hw/ncdevmem.c
@@ -843,6 +843,7 @@ static int do_server(struct memory_buffer *mem)
 	char iobuf[819200];
 	int ret, err = -1;
 	char buffer[256];
+	int retries = 10;
 	int socket_fd;
 	int client_fd;
 
@@ -898,7 +899,12 @@ static int do_server(struct memory_buffer *mem)
 	fprintf(stderr, "binding to address %s:%d\n", server_ip,
 		ntohs(server_sin.sin6_port));
 
-	ret = bind(socket_fd, &server_sin, sizeof(server_sin));
+	while (retries--) {
+		ret = bind(socket_fd, &server_sin, sizeof(server_sin));
+		if (!ret)
+			break;
+		sleep(1);
+	}
 	if (ret) {
 		pr_err("Failed to bind");
 		goto err_close_socket;
-- 
2.55.0.571.g244d577d93-goog
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.