lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <a932c40e59f648d9d2771f9533cbc01cd4c0935c.1718138187.git.zhuyifei@google.com>
Date: Tue, 11 Jun 2024 20:42:45 +0000
From: YiFei Zhu <zhuyifei@...gle.com>
To: netdev@...r.kernel.org, bpf@...r.kernel.org
Cc: "Björn Töpel" <bjorn@...nel.org>, Magnus Karlsson <magnus.karlsson@...el.com>, 
	Maciej Fijalkowski <maciej.fijalkowski@...el.com>, Jonathan Lemon <jonathan.lemon@...il.com>, 
	Alexei Starovoitov <ast@...nel.org>, Daniel Borkmann <daniel@...earbox.net>, 
	"David S . Miller" <davem@...emloft.net>, Jakub Kicinski <kuba@...nel.org>, 
	Jesper Dangaard Brouer <hawk@...nel.org>, John Fastabend <john.fastabend@...il.com>, 
	Andrii Nakryiko <andrii@...nel.org>, Stanislav Fomichev <sdf@...gle.com>, 
	Willem de Bruijn <willemb@...gle.com>
Subject: [RFC PATCH net-next 1/3] selftests/bpf: Move rxq_num helper from
 xdp_hw_metadata to network_helpers

This helper may be useful for other AF_XDP tests, such as xsk_hw.
Moving it out so we don't need to copy-paste that function.

I also changed the function from directly calling error(1, errno, ...)
to returning an error because I don't think it makes sense for a
library function to outright kill the process if the function fails.

Signed-off-by: YiFei Zhu <zhuyifei@...gle.com>
---
 tools/testing/selftests/bpf/network_helpers.c | 27 +++++++++++++++++++
 tools/testing/selftests/bpf/network_helpers.h |  2 ++
 tools/testing/selftests/bpf/xdp_hw_metadata.c | 27 ++-----------------
 3 files changed, 31 insertions(+), 25 deletions(-)

diff --git a/tools/testing/selftests/bpf/network_helpers.c b/tools/testing/selftests/bpf/network_helpers.c
index 35250e6cde7f..4c3bef07df23 100644
--- a/tools/testing/selftests/bpf/network_helpers.c
+++ b/tools/testing/selftests/bpf/network_helpers.c
@@ -569,6 +569,33 @@ int set_hw_ring_size(char *ifname, struct ethtool_ringparam *ring_param)
 	return 0;
 }
 
+int rxq_num(const char *ifname)
+{
+	struct ethtool_channels ch = {
+		.cmd = ETHTOOL_GCHANNELS,
+	};
+	struct ifreq ifr = {
+		.ifr_data = (void *)&ch,
+	};
+	strncpy(ifr.ifr_name, ifname, IF_NAMESIZE - 1);
+	int fd, ret, err;
+
+	fd = socket(AF_UNIX, SOCK_DGRAM, 0);
+	if (fd < 0)
+		return -errno;
+
+	ret = ioctl(fd, SIOCETHTOOL, &ifr);
+	if (ret < 0) {
+		err = errno;
+		close(fd);
+		return -err;
+	}
+
+	close(fd);
+
+	return ch.rx_count + ch.combined_count;
+}
+
 struct send_recv_arg {
 	int		fd;
 	uint32_t	bytes;
diff --git a/tools/testing/selftests/bpf/network_helpers.h b/tools/testing/selftests/bpf/network_helpers.h
index 883c7ea9d8d5..b09c3bbd5b62 100644
--- a/tools/testing/selftests/bpf/network_helpers.h
+++ b/tools/testing/selftests/bpf/network_helpers.h
@@ -72,6 +72,8 @@ int get_socket_local_port(int sock_fd);
 int get_hw_ring_size(char *ifname, struct ethtool_ringparam *ring_param);
 int set_hw_ring_size(char *ifname, struct ethtool_ringparam *ring_param);
 
+int rxq_num(const char *ifname);
+
 struct nstoken;
 /**
  * open_netns() - Switch to specified network namespace by name.
diff --git a/tools/testing/selftests/bpf/xdp_hw_metadata.c b/tools/testing/selftests/bpf/xdp_hw_metadata.c
index 6f9956eed797..f038a624fd1f 100644
--- a/tools/testing/selftests/bpf/xdp_hw_metadata.c
+++ b/tools/testing/selftests/bpf/xdp_hw_metadata.c
@@ -495,31 +495,6 @@ static int verify_metadata(struct xsk *rx_xsk, int rxq, int server_fd, clockid_t
 	return 0;
 }
 
-static int rxq_num(const char *ifname)
-{
-	struct ethtool_channels ch = {
-		.cmd = ETHTOOL_GCHANNELS,
-	};
-
-	struct ifreq ifr = {
-		.ifr_data = (void *)&ch,
-	};
-	strncpy(ifr.ifr_name, ifname, IF_NAMESIZE - 1);
-	int fd, ret;
-
-	fd = socket(AF_UNIX, SOCK_DGRAM, 0);
-	if (fd < 0)
-		error(1, errno, "socket");
-
-	ret = ioctl(fd, SIOCETHTOOL, &ifr);
-	if (ret < 0)
-		error(1, errno, "ioctl(SIOCETHTOOL)");
-
-	close(fd);
-
-	return ch.rx_count + ch.combined_count;
-}
-
 static void hwtstamp_ioctl(int op, const char *ifname, struct hwtstamp_config *cfg)
 {
 	struct ifreq ifr = {
@@ -668,6 +643,8 @@ int main(int argc, char *argv[])
 	read_args(argc, argv);
 
 	rxq = rxq_num(ifname);
+	if (rxq < 0)
+		error(1, -rxq, "rxq_num");
 
 	printf("rxq: %d\n", rxq);
 
-- 
2.45.2.505.gda0bf45e8d-goog


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ