Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 1 Oct 2025 21:24:24 GMT
From:      Gleb Smirnoff <glebius@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: 36f2eda25171 - main - tests/netinet: rename and extend sendto-IP_MULTICAST_IF.c
Message-ID:  <202510012124.591LOOqX063994@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by glebius:

URL: https://cgit.FreeBSD.org/src/commit/?id=36f2eda251713d4d38f41cf269876b069e3897ff

commit 36f2eda251713d4d38f41cf269876b069e3897ff
Author:     Gleb Smirnoff <glebius@FreeBSD.org>
AuthorDate: 2025-09-30 02:34:13 +0000
Commit:     Gleb Smirnoff <glebius@FreeBSD.org>
CommitDate: 2025-10-01 19:41:52 +0000

    tests/netinet: rename and extend sendto-IP_MULTICAST_IF.c
    
    Rename this test helper app to multicast-send.c.  Extend it to send
    from/to arbitrary addresses and arbitrary payload so that it can be used
    in more test scenarios.
---
 ObsoleteFiles.inc                                  |  3 ++
 tests/sys/netinet/Makefile                         |  2 +-
 .../{sendto-IP_MULTICAST_IF.c => multicast-send.c} | 62 +++++++++++++++++-----
 tests/sys/netinet/multicast.sh                     |  3 +-
 4 files changed, 54 insertions(+), 16 deletions(-)

diff --git a/ObsoleteFiles.inc b/ObsoleteFiles.inc
index 55202d1c100c..539ab7d54460 100644
--- a/ObsoleteFiles.inc
+++ b/ObsoleteFiles.inc
@@ -51,6 +51,9 @@
 #   xargs -n1 | sort | uniq -d;
 # done
 
+# 20251001: test helper sendto-IP_MULTICAST_IF renamed
+OLD_FILES+=usr/tests/sys/netinet/sendto-IP_MULTICAST_IF
+
 # 20250930: Rename wlanstats to wlanstat
 OLD_FILES+=usr/sbin/wlanstats
 OLD_FILES+=usr/share/man/man8/wlanstats.8.gz
diff --git a/tests/sys/netinet/Makefile b/tests/sys/netinet/Makefile
index cc525bf24480..1880709112c8 100644
--- a/tests/sys/netinet/Makefile
+++ b/tests/sys/netinet/Makefile
@@ -48,7 +48,7 @@ TEST_METADATA.forward+=	required_programs="python"	\
 TEST_METADATA.output+=	required_programs="python"
 TEST_METADATA.redirect+= required_programs="python"
 
-PROGS=	udp_dontroute tcp_user_cookie sendto-IP_MULTICAST_IF
+PROGS=	udp_dontroute tcp_user_cookie multicast-send
 
 ${PACKAGE}FILES+=		redirect.py
 
diff --git a/tests/sys/netinet/sendto-IP_MULTICAST_IF.c b/tests/sys/netinet/multicast-send.c
similarity index 56%
rename from tests/sys/netinet/sendto-IP_MULTICAST_IF.c
rename to tests/sys/netinet/multicast-send.c
index d478e4da0b3b..f10b2b6338dd 100644
--- a/tests/sys/netinet/sendto-IP_MULTICAST_IF.c
+++ b/tests/sys/netinet/multicast-send.c
@@ -28,35 +28,69 @@
 #include <sys/socket.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
+#include <net/if.h>
 #include <assert.h>
+#include <errno.h>
+#include <limits.h>
+#include <stdbool.h>
+#include <stdlib.h>
+#include <string.h>
 #include <err.h>
 
+static in_port_t
+atop(const char *c)
+{
+	unsigned long ul;
+
+	errno = 0;
+	if ((ul = strtol(c, NULL, 10)) < 1 || ul > IPPORT_MAX || errno != 0)
+		err(1, "can't parse %s", c);
+
+	return ((in_port_t)ul);
+}
+
 int
 main(int argc, char *argv[])
 {
-	struct sockaddr_in sin = {
+	struct sockaddr_in src = {
+		.sin_family = AF_INET,
+		.sin_len = sizeof(struct sockaddr_in),
+	}, dst = {
 		.sin_family = AF_INET,
 		.sin_len = sizeof(struct sockaddr_in),
 	};
+	struct ip_mreqn mreqn;
 	struct in_addr in;
-	int s, rv;
+	int s;
+	bool index;
 
-	if (argc < 2)
-		errx(1, "Usage: %s IPv4-address", argv[0]);
+	if (argc < 7)
+		errx(1, "Usage: %s src-IPv4 src-port dst-IPv4 dst-port "
+		    "interface payload", argv[0]);
 
-	if (inet_pton(AF_INET, argv[1], &in) != 1)
+	if (inet_pton(AF_INET, argv[1], &src.sin_addr) != 1)
 		err(1, "inet_pton(%s) failed", argv[1]);
+	src.sin_port = htons(atop(argv[2]));
+	if (inet_pton(AF_INET, argv[3], &dst.sin_addr) != 1)
+		err(1, "inet_pton(%s) failed", argv[3]);
+	dst.sin_port = htons(atop(argv[4]));
+	if (inet_pton(AF_INET, argv[5], &in) == 1)
+		index = false;
+	else if ((mreqn.imr_ifindex = if_nametoindex(argv[5])) > 0)
+		index = true;
+	else
+		err(1, "if_nametoindex(%s) failed", argv[5]);
 
 	assert((s = socket(PF_INET, SOCK_DGRAM, 0)) > 0);
-	assert(bind(s, (struct sockaddr *)&sin, sizeof(sin)) == 0);
-	assert(setsockopt(s, IPPROTO_IP, IP_MULTICAST_IF, &in, sizeof(in))
-	  == 0);
-	/* RFC 6676 */
-	assert(inet_pton(AF_INET, "233.252.0.1", &sin.sin_addr) == 1);
-	sin.sin_port = htons(6676);
-	rv = sendto(s, &sin, sizeof(sin), 0,
-	    (struct sockaddr *)&sin, sizeof(sin));
-	if (rv != sizeof(sin))
+	assert(bind(s, (struct sockaddr *)&src, sizeof(src)) == 0);
+	if (index)
+		assert(setsockopt(s, IPPROTO_IP, IP_MULTICAST_IF, &mreqn,
+		    sizeof(mreqn)) == 0);
+	else
+		assert(setsockopt(s, IPPROTO_IP, IP_MULTICAST_IF, &in,
+		    sizeof(in)) == 0);
+	if (sendto(s, argv[6], strlen(argv[6]) + 1, 0, (struct sockaddr *)&dst,
+	    sizeof(dst)) != (ssize_t)strlen(argv[6]) + 1)
 		err(1, "sendto failed");
 
 	return (0);
diff --git a/tests/sys/netinet/multicast.sh b/tests/sys/netinet/multicast.sh
index eb2b962dac70..1826e1e7c4ee 100644
--- a/tests/sys/netinet/multicast.sh
+++ b/tests/sys/netinet/multicast.sh
@@ -47,7 +47,8 @@ IP_MULTICAST_IF_body()
 	jexec mjail ifconfig ${epair}a up
 	jexec mjail ifconfig ${epair}a 192.0.2.1/24
 	atf_check -s exit:0 -o empty \
-	    jexec mjail $(atf_get_srcdir)/sendto-IP_MULTICAST_IF 192.0.2.1
+	    jexec mjail $(atf_get_srcdir)/multicast-send \
+	    0.0.0.0 0 233.252.0.1 6676 192.0.2.1 hello
 }
 
 IP_MULTICAST_IF_cleanup()



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202510012124.591LOOqX063994>