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: <31c93d3d050cadf75aaa833aca4b6614666ba8de.1728303615.git.gur.stavi@huawei.com>
Date: Mon, 7 Oct 2024 15:40:25 +0300
From: Gur Stavi <gur.stavi@...wei.com>
To: Gur Stavi <gur.stavi@...wei.com>
CC: <netdev@...r.kernel.org>, <linux-kernel@...r.kernel.org>, "David S.
 Miller" <davem@...emloft.net>, Eric Dumazet <edumazet@...gle.com>, Jakub
 Kicinski <kuba@...nel.org>, Paolo Abeni <pabeni@...hat.com>
Subject: [PATCH net-next v01 2/4] selftests: net/psock_fanout: add loopback up/down toggle facility

Prepare to test setsockopt with PACKET_FANOUT on a link that is down.

Signed-off-by: Gur Stavi <gur.stavi@...wei.com>
---
 tools/testing/selftests/net/psock_fanout.c | 38 ++++++++++++++++++++++
 1 file changed, 38 insertions(+)

diff --git a/tools/testing/selftests/net/psock_fanout.c b/tools/testing/selftests/net/psock_fanout.c
index 4f31e92ebd96..a8b22494a635 100644
--- a/tools/testing/selftests/net/psock_fanout.c
+++ b/tools/testing/selftests/net/psock_fanout.c
@@ -48,6 +48,7 @@
 #include <string.h>
 #include <sys/mman.h>
 #include <sys/socket.h>
+#include <sys/ioctl.h>
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <unistd.h>
@@ -58,6 +59,43 @@
 #define RING_NUM_FRAMES			20
 
 static uint32_t cfg_max_num_members;
+static int lo_up_down_toggled;
+
+static void loopback_up_down_toggle(void)
+{
+	struct ifreq ifreq = {};
+	int fd, err;
+
+	fd = socket(AF_PACKET, SOCK_RAW, 0);
+	if (fd == -1)
+		return;
+	strcpy(ifreq.ifr_name, "lo");
+	err = ioctl(fd, SIOCGIFFLAGS, &ifreq);
+	if (err) {
+		perror("SIOCGIFFLAGS");
+		exit(1);
+	}
+	ifreq.ifr_flags ^= IFF_UP;
+	err = ioctl(fd, SIOCSIFFLAGS, &ifreq);
+	if (err) {
+		perror("SIOCSIFFLAGS");
+		exit(1);
+	}
+	lo_up_down_toggled ^= 1;
+	close(fd);
+}
+
+static void loopback_up_down_restore(void)
+{
+	if (lo_up_down_toggled)
+		loopback_up_down_toggle();
+}
+
+static int cleanup_and_exit(int status)
+{
+	loopback_up_down_restore();
+	exit(status);
+}
 
 /* Open a socket in a given fanout mode.
  * @return -1 if mode is bad, a valid socket otherwise */
-- 
2.45.2


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ