netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH bpf-next v2 0/2] selftests/bpf: use ifname instead of ifindex in XDP
@ 2023-03-09 17:32 Lorenzo Bianconi
  2023-03-09 17:32 ` [PATCH bpf-next v2 1/2] selftests/bpf: use ifname instead of ifindex in XDP compliance test tool Lorenzo Bianconi
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Lorenzo Bianconi @ 2023-03-09 17:32 UTC (permalink / raw)
  To: bpf; +Cc: netdev, ast, andrii, lorenzo.bianconi, daniel

Use interface name instead of interface index in XDP compliance test tool logs.
Improve XDP compliance test tool error messages.

Changes since v1:
- split previous patch in two logically separated patches

Lorenzo Bianconi (2):
  selftests/bpf: use ifname instead of ifindex in XDP compliance test
    tool
  selftests/bpf: improve error logs in XDP compliance test tool

 tools/testing/selftests/bpf/xdp_features.c | 67 ++++++++++++++--------
 1 file changed, 43 insertions(+), 24 deletions(-)

-- 
2.39.2


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

* [PATCH bpf-next v2 1/2] selftests/bpf: use ifname instead of ifindex in XDP compliance test tool
  2023-03-09 17:32 [PATCH bpf-next v2 0/2] selftests/bpf: use ifname instead of ifindex in XDP Lorenzo Bianconi
@ 2023-03-09 17:32 ` Lorenzo Bianconi
  2023-03-09 17:32 ` [PATCH bpf-next v2 2/2] selftests/bpf: improve error logs " Lorenzo Bianconi
  2023-03-09 20:00 ` [PATCH bpf-next v2 0/2] selftests/bpf: use ifname instead of ifindex in XDP patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: Lorenzo Bianconi @ 2023-03-09 17:32 UTC (permalink / raw)
  To: bpf; +Cc: netdev, ast, andrii, lorenzo.bianconi, daniel

Rely on interface name instead of interface index in error messages or
logs from XDP compliance test tool.

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
---
 tools/testing/selftests/bpf/xdp_features.c | 44 +++++++++++++---------
 1 file changed, 27 insertions(+), 17 deletions(-)

diff --git a/tools/testing/selftests/bpf/xdp_features.c b/tools/testing/selftests/bpf/xdp_features.c
index fce12165213b..b060a0d24e44 100644
--- a/tools/testing/selftests/bpf/xdp_features.c
+++ b/tools/testing/selftests/bpf/xdp_features.c
@@ -25,6 +25,7 @@
 
 static struct env {
 	bool verbosity;
+	char ifname[IF_NAMESIZE];
 	int ifindex;
 	bool is_tester;
 	struct {
@@ -179,7 +180,7 @@ static error_t parse_arg(int key, char *arg, struct argp_state *state)
 		env.ifindex = if_nametoindex(arg);
 		if (!env.ifindex)
 			env.ifindex = strtoul(arg, NULL, 0);
-		if (!env.ifindex) {
+		if (!env.ifindex || !if_indextoname(env.ifindex, env.ifname)) {
 			fprintf(stderr,
 				"Bad interface index or name (%d): %s\n",
 				errno, strerror(errno));
@@ -205,6 +206,7 @@ static void set_env_default(void)
 	env.feature.drv_feature = NETDEV_XDP_ACT_NDO_XMIT;
 	env.feature.action = -EINVAL;
 	env.ifindex = -ENODEV;
+	strcpy(env.ifname, "unknown");
 	make_sockaddr(AF_INET6, "::ffff:127.0.0.1", DUT_CTRL_PORT,
 		      &env.dut_ctrl_addr, NULL);
 	make_sockaddr(AF_INET6, "::ffff:127.0.0.1", DUT_ECHO_PORT,
@@ -248,15 +250,18 @@ static int dut_run_echo_thread(pthread_t *t, int *sockfd)
 	sockfd = start_reuseport_server(AF_INET6, SOCK_DGRAM, NULL,
 					DUT_ECHO_PORT, 0, 1);
 	if (!sockfd) {
-		fprintf(stderr, "Failed to create echo socket\n");
+		fprintf(stderr,
+			"Failed creating data UDP socket on device %s\n",
+			env.ifname);
 		return -errno;
 	}
 
 	/* start echo channel */
 	err = pthread_create(t, NULL, dut_echo_thread, sockfd);
 	if (err) {
-		fprintf(stderr, "Failed creating dut_echo thread: %s\n",
-			strerror(-err));
+		fprintf(stderr,
+			"Failed creating data UDP thread on device %s: %s\n",
+			env.ifname, strerror(-err));
 		free_fds(sockfd, 1);
 		return -EINVAL;
 	}
@@ -320,9 +325,8 @@ static int dut_attach_xdp_prog(struct xdp_features *skel, int flags)
 
 	err = bpf_xdp_attach(env.ifindex, bpf_program__fd(prog), flags, NULL);
 	if (err)
-		fprintf(stderr,
-			"Failed to attach XDP program to ifindex %d\n",
-			env.ifindex);
+		fprintf(stderr, "Failed attaching XDP program to device %s\n",
+			env.ifname);
 	return err;
 }
 
@@ -358,13 +362,16 @@ static int dut_run(struct xdp_features *skel)
 	sockfd = start_reuseport_server(AF_INET6, SOCK_STREAM, NULL,
 					DUT_CTRL_PORT, 0, 1);
 	if (!sockfd) {
-		fprintf(stderr, "Failed to create DUT socket\n");
+		fprintf(stderr,
+			"Failed creating control socket on device %s\n", env.ifname);
 		return -errno;
 	}
 
 	ctrl_sockfd = accept(*sockfd, (struct sockaddr *)&ctrl_addr, &addrlen);
 	if (ctrl_sockfd < 0) {
-		fprintf(stderr, "Failed to accept connection on DUT socket\n");
+		fprintf(stderr,
+			"Failed accepting connections on device %s control socket\n",
+			env.ifname);
 		free_fds(sockfd, 1);
 		return -errno;
 	}
@@ -422,8 +429,8 @@ static int dut_run(struct xdp_features *skel)
 					    &opts);
 			if (err) {
 				fprintf(stderr,
-					"Failed to query XDP cap for ifindex %d\n",
-					env.ifindex);
+					"Failed querying XDP cap for device %s\n",
+					env.ifname);
 				goto end_thread;
 			}
 
@@ -540,7 +547,9 @@ static int send_echo_msg(void)
 
 	sockfd = socket(AF_INET6, SOCK_DGRAM, 0);
 	if (sockfd < 0) {
-		fprintf(stderr, "Failed to create echo socket\n");
+		fprintf(stderr,
+			"Failed creating data UDP socket on device %s\n",
+			env.ifname);
 		return -errno;
 	}
 
@@ -596,8 +605,8 @@ static int tester_run(struct xdp_features *skel)
 
 	err = bpf_xdp_attach(env.ifindex, bpf_program__fd(prog), flags, NULL);
 	if (err) {
-		fprintf(stderr, "Failed to attach XDP program to ifindex %d\n",
-			env.ifindex);
+		fprintf(stderr, "Failed attaching XDP program to device %s\n",
+			env.ifname);
 		goto out;
 	}
 
@@ -653,7 +662,7 @@ int main(int argc, char **argv)
 		return err;
 
 	if (env.ifindex < 0) {
-		fprintf(stderr, "Invalid ifindex\n");
+		fprintf(stderr, "Invalid device name %s\n", env.ifname);
 		return -ENODEV;
 	}
 
@@ -684,11 +693,12 @@ int main(int argc, char **argv)
 
 	if (env.is_tester) {
 		/* Tester */
-		fprintf(stdout, "Starting tester on device %d\n", env.ifindex);
+		fprintf(stdout, "Starting tester service on device %s\n",
+			env.ifname);
 		err = tester_run(skel);
 	} else {
 		/* DUT */
-		fprintf(stdout, "Starting DUT on device %d\n", env.ifindex);
+		fprintf(stdout, "Starting test on device %s\n", env.ifname);
 		err = dut_run(skel);
 	}
 
-- 
2.39.2


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

* [PATCH bpf-next v2 2/2] selftests/bpf: improve error logs in XDP compliance test tool
  2023-03-09 17:32 [PATCH bpf-next v2 0/2] selftests/bpf: use ifname instead of ifindex in XDP Lorenzo Bianconi
  2023-03-09 17:32 ` [PATCH bpf-next v2 1/2] selftests/bpf: use ifname instead of ifindex in XDP compliance test tool Lorenzo Bianconi
@ 2023-03-09 17:32 ` Lorenzo Bianconi
  2023-03-09 20:00 ` [PATCH bpf-next v2 0/2] selftests/bpf: use ifname instead of ifindex in XDP patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: Lorenzo Bianconi @ 2023-03-09 17:32 UTC (permalink / raw)
  To: bpf; +Cc: netdev, ast, andrii, lorenzo.bianconi, daniel

Improve some error logs reported in the XDP compliance test tool

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
---
 tools/testing/selftests/bpf/xdp_features.c | 23 +++++++++++++++-------
 1 file changed, 16 insertions(+), 7 deletions(-)

diff --git a/tools/testing/selftests/bpf/xdp_features.c b/tools/testing/selftests/bpf/xdp_features.c
index b060a0d24e44..b449788fbd39 100644
--- a/tools/testing/selftests/bpf/xdp_features.c
+++ b/tools/testing/selftests/bpf/xdp_features.c
@@ -152,20 +152,26 @@ static error_t parse_arg(int key, char *arg, struct argp_state *state)
 	case 'D':
 		if (make_sockaddr(AF_INET6, arg, DUT_ECHO_PORT,
 				  &env.dut_addr, NULL)) {
-			fprintf(stderr, "Invalid DUT address: %s\n", arg);
+			fprintf(stderr,
+				"Invalid address assigned to the Device Under Test: %s\n",
+				arg);
 			return ARGP_ERR_UNKNOWN;
 		}
 		break;
 	case 'C':
 		if (make_sockaddr(AF_INET6, arg, DUT_CTRL_PORT,
 				  &env.dut_ctrl_addr, NULL)) {
-			fprintf(stderr, "Invalid DUT CTRL address: %s\n", arg);
+			fprintf(stderr,
+				"Invalid address assigned to the Device Under Test: %s\n",
+				arg);
 			return ARGP_ERR_UNKNOWN;
 		}
 		break;
 	case 'T':
 		if (make_sockaddr(AF_INET6, arg, 0, &env.tester_addr, NULL)) {
-			fprintf(stderr, "Invalid Tester address: %s\n", arg);
+			fprintf(stderr,
+				"Invalid address assigned to the Tester device: %s\n",
+				arg);
 			return ARGP_ERR_UNKNOWN;
 		}
 		break;
@@ -454,7 +460,8 @@ static int dut_run(struct xdp_features *skel)
 						   &key, sizeof(key),
 						   &val, sizeof(val), 0);
 			if (err) {
-				fprintf(stderr, "bpf_map_lookup_elem failed\n");
+				fprintf(stderr,
+					"bpf_map_lookup_elem failed (%d)\n", err);
 				goto end_thread;
 			}
 
@@ -496,7 +503,7 @@ static bool tester_collect_detected_cap(struct xdp_features *skel,
 	err = bpf_map__lookup_elem(skel->maps.stats, &key, sizeof(key),
 				   &val, sizeof(val), 0);
 	if (err) {
-		fprintf(stderr, "bpf_map_lookup_elem failed\n");
+		fprintf(stderr, "bpf_map_lookup_elem failed (%d)\n", err);
 		return false;
 	}
 
@@ -574,7 +581,8 @@ static int tester_run(struct xdp_features *skel)
 
 	sockfd = socket(AF_INET6, SOCK_STREAM, 0);
 	if (sockfd < 0) {
-		fprintf(stderr, "Failed to create tester socket\n");
+		fprintf(stderr,
+			"Failed creating tester service control socket\n");
 		return -errno;
 	}
 
@@ -584,7 +592,8 @@ static int tester_run(struct xdp_features *skel)
 	err = connect(sockfd, (struct sockaddr *)&env.dut_ctrl_addr,
 		      sizeof(env.dut_ctrl_addr));
 	if (err) {
-		fprintf(stderr, "Failed to connect to the DUT\n");
+		fprintf(stderr,
+			"Failed connecting to the Device Under Test control socket\n");
 		return -errno;
 	}
 
-- 
2.39.2


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

* Re: [PATCH bpf-next v2 0/2] selftests/bpf: use ifname instead of ifindex in XDP
  2023-03-09 17:32 [PATCH bpf-next v2 0/2] selftests/bpf: use ifname instead of ifindex in XDP Lorenzo Bianconi
  2023-03-09 17:32 ` [PATCH bpf-next v2 1/2] selftests/bpf: use ifname instead of ifindex in XDP compliance test tool Lorenzo Bianconi
  2023-03-09 17:32 ` [PATCH bpf-next v2 2/2] selftests/bpf: improve error logs " Lorenzo Bianconi
@ 2023-03-09 20:00 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: patchwork-bot+netdevbpf @ 2023-03-09 20:00 UTC (permalink / raw)
  To: Lorenzo Bianconi; +Cc: bpf, netdev, ast, andrii, lorenzo.bianconi, daniel

Hello:

This series was applied to bpf/bpf-next.git (master)
by Daniel Borkmann <daniel@iogearbox.net>:

On Thu,  9 Mar 2023 18:32:39 +0100 you wrote:
> Use interface name instead of interface index in XDP compliance test tool logs.
> Improve XDP compliance test tool error messages.
> 
> Changes since v1:
> - split previous patch in two logically separated patches
> 
> Lorenzo Bianconi (2):
>   selftests/bpf: use ifname instead of ifindex in XDP compliance test
>     tool
>   selftests/bpf: improve error logs in XDP compliance test tool
> 
> [...]

Here is the summary with links:
  - [bpf-next,v2,1/2] selftests/bpf: use ifname instead of ifindex in XDP compliance test tool
    https://git.kernel.org/bpf/bpf-next/c/27a36bc3cdd5
  - [bpf-next,v2,2/2] selftests/bpf: improve error logs in XDP compliance test tool
    https://git.kernel.org/bpf/bpf-next/c/c1cd734c1bb3

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] 4+ messages in thread

end of thread, other threads:[~2023-03-09 20:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-03-09 17:32 [PATCH bpf-next v2 0/2] selftests/bpf: use ifname instead of ifindex in XDP Lorenzo Bianconi
2023-03-09 17:32 ` [PATCH bpf-next v2 1/2] selftests/bpf: use ifname instead of ifindex in XDP compliance test tool Lorenzo Bianconi
2023-03-09 17:32 ` [PATCH bpf-next v2 2/2] selftests/bpf: improve error logs " Lorenzo Bianconi
2023-03-09 20:00 ` [PATCH bpf-next v2 0/2] selftests/bpf: use ifname instead of ifindex in XDP patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).