From nobody Mon Mar 24 02:45:55 2025 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4ZLcqs4WYqz5rBr6; Mon, 24 Mar 2025 02:46:01 +0000 (UTC) (envelope-from kp@FreeBSD.org) Received: from smtp.freebsd.org (smtp.freebsd.org [96.47.72.83]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "smtp.freebsd.org", Issuer "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4ZLcqs3t5gz3VyG; Mon, 24 Mar 2025 02:46:01 +0000 (UTC) (envelope-from kp@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1742784361; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=zm9k6Yv5w0MYeKOas1S5L0lrFYAAbj2BO+wCT2SKj+Y=; b=Qhz9gUb41xNg0JXnn7E4bS3XZqIfkFkKG9t0ZlrrvMtcRGLBkFWlW6C2wYMQuUDClHnbqf uz69VwihPlcPLUxQ9ZF6RmJIyfbZMo7hDpRbyI62ppcOrewu5aKTo4zAeNN+QxurRPSeLC OMbymeHvBItnyXiTigpnAM0WZB0wA1lM2Eag9tPAaTV/tQ7xVzqIpcUPjyZxxCJ8M+bbVi gt2nHS52SRBv+KwQkRTLrTHfBeH000Q2A11tuBYKxvVOhpPdspR+df1+QC5U2pcLxVxDyy 8H32ObryKrcVrjC8NSdBF1YZ9UlpDKYLgGXfWOlenMPi1PQSlLdWIJFRIFWOqA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1742784361; a=rsa-sha256; cv=none; b=KGnaspWItcrArEtOW9S0n8yRV/a2jzihLYmA5NflXUqp4h9CaRx8o2kAYldLvo5fIiwqzx z+Ew2OMgZhZX2Di4mzZa3ftznkvb9G4TJq1sZUbbX1Sl0SAGNI7mT5WFIcvMjdasAQAQEB +MAhheOJEpgxKfj46+O7kSLBbiFAWM4xeBQ4FvNwtBhNFhJxsKaa0GEei/QwKUsEg2DHpg 9CNfUioDio8zcyWt/y3mgJlVkKpHnJ7UYfIs0Zl/zPoLbh5S7ufQ553pIEihN6qRVSd91M sPsZ14X6bdlqvHz3oZjrocn7ESsTfb1bJA+142iUgHPsFDO3tyIOsIvVDkCwzA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1742784361; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=zm9k6Yv5w0MYeKOas1S5L0lrFYAAbj2BO+wCT2SKj+Y=; b=IDu478F/ry26lrkVJ2wwHvzrJ2sxwFLMl4b+Ph0/SML/M7BYaXuTQ618y7GTVxBHdGu5le XesUHFyZKeJsUAs8qDiTuOgAvE1Kyht86ygxiU9p/klwbdkHkFkcC5/2hPmno5/E3Y9FUd Ni/2VccxtSZM7eMb8lUSbvR5iBr2N7Gj1uP+46MK4IyIL0WgRoUqpxw37is/PWCvarq6WX 1bLrgUigh7EJBYFkFU4v0GYrrb89fJhQK0giNg9lnx5Qo/a6eJiD/tHkUQHPCUCCyZd1wG nyrgiIKhVcbJaHqkoYTvGNn2up/Rgas6bEqUsjGq9hjBxQvlMUjhy3Qpng4KvA== Received: from venus.codepro.be (venus.codepro.be [5.9.86.228]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "mx1.codepro.be", Issuer "R10" (verified OK)) (Authenticated sender: kp) by smtp.freebsd.org (Postfix) with ESMTPSA id 4ZLcqs1tPFz19kr; Mon, 24 Mar 2025 02:46:01 +0000 (UTC) (envelope-from kp@FreeBSD.org) Received: by venus.codepro.be (Postfix, authenticated sender kp) id 0DA4F1ED05; Mon, 24 Mar 2025 03:45:57 +0100 (CET) From: Kristof Provost To: Gleb Smirnoff Cc: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org Subject: Re: git: 0849f1634a70 - main - tests/netinet: add test for IP_MULTICAST_IF Date: Mon, 24 Mar 2025 11:45:55 +0900 X-Mailer: MailMate (2.0r6222) Message-ID: <7440BE85-66E8-4D1A-AC15-8B944F5C2951@FreeBSD.org> In-Reply-To: <202503222340.52MNekCX071219@gitrepo.freebsd.org> References: <202503222340.52MNekCX071219@gitrepo.freebsd.org> List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="=_MailMate_B28CA915-06EB-49CD-961F-2ADDD3DDDB4D_=" --=_MailMate_B28CA915-06EB-49CD-961F-2ADDD3DDDB4D_= Content-Type: text/plain; charset=UTF-8; format=flowed; markup=markdown Content-Transfer-Encoding: quoted-printable On 23 Mar 2025, at 8:40, Gleb Smirnoff wrote: > The branch main has been updated by glebius: > > URL: = > https://cgit.FreeBSD.org/src/commit/?id=3D0849f1634a70099b90256ceece52a= 598eeb3280e > > commit 0849f1634a70099b90256ceece52a598eeb3280e > Author: Gleb Smirnoff > AuthorDate: 2025-03-22 22:44:20 +0000 > Commit: Gleb Smirnoff > CommitDate: 2025-03-22 23:39:50 +0000 > > tests/netinet: add test for IP_MULTICAST_IF > It bugs me a little that we have to jump through hoops to get a C = program running in a specific jail/network setup. It=E2=80=99s somewhat common for that to happen, and I=E2=80=99m sure the= re=E2=80=99d be = more cases if it were easier to do (e.g. the getaddrinfo tests you=E2=80=99= ve = been working on could be even more useful with a custom DNS server, so = in their own vnet jail). I took a stab at that: diff --git a/tests/sys/netinet/multicast.sh = b/tests/sys/netinet/multicast.sh index eb2b962dac70..7476daeb832a 100644 --- a/tests/sys/netinet/multicast.sh +++ b/tests/sys/netinet/multicast.sh @@ -26,6 +26,15 @@ . $(atf_get_srcdir)/../common/vnet.subr +ctest_j() +{ + jail=3D$1 + shift + + cc -x c - -o tmp || atf_fail "Failed to build" + jexec $jail `pwd`/tmp $@ || atf_fail "Test program failed" +} + # See regression fixed in baad45c9c12028964acd0b58096f3aaa0fb22859 atf_test_case "IP_MULTICAST_IF" "cleanup" IP_MULTICAST_IF_head() @@ -33,7 +42,6 @@ IP_MULTICAST_IF_head() atf_set descr \ 'sendto() for IP_MULTICAST_IF socket does not do routing = lookup' atf_set require.user root - } IP_MULTICAST_IF_body() @@ -46,8 +54,45 @@ IP_MULTICAST_IF_body() vnet_mkjail mjail ${epair}a 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 + + ctest_j mjail 192.0.2.1 < +#include +#include +#include +#include + +int +main(int argc, char *argv[]) +{ + struct sockaddr_in sin =3D { + .sin_family =3D AF_INET, + .sin_len =3D sizeof(struct sockaddr_in), + }; + struct in_addr in; + int s, rv; + + if (argc < 2) + errx(1, "Usage: %s IPv4-address", argv[0]); + + if (inet_pton(AF_INET, argv[1], &in) !=3D 1) + err(1, "inet_pton(%s) failed", argv[1]); + + assert((s =3D socket(PF_INET, SOCK_DGRAM, 0)) > 0); + assert(bind(s, (struct sockaddr *)&sin, sizeof(sin)) =3D=3D 0); + assert(setsockopt(s, IPPROTO_IP, IP_MULTICAST_IF, &in, = sizeof(in)) + =3D=3D 0); + /* RFC 6676 */ + assert(inet_pton(AF_INET, "233.252.0.1", &sin.sin_addr) =3D=3D 1= ); + sin.sin_port =3D htons(6676); + rv =3D sendto(s, &sin, sizeof(sin), 0, + (struct sockaddr *)&sin, sizeof(sin)); + if (rv !=3D sizeof(sin)) + err(1, "sendto failed"); + + return (0); +} +EOF } IP_MULTICAST_IF_cleanup() The downside is that we=E2=80=99re compiling the C test code on every run= , but = I expect test programs to be tiny, so that=E2=80=99s not too much of a co= st. Does this seem useful to you too? Best regards, Kristof --=_MailMate_B28CA915-06EB-49CD-961F-2ADDD3DDDB4D_= Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable

On 23 Mar 2025, at 8:40, Gleb Smirnoff wrote:

The branch main has been updated by glebius:

URL: https://cgit.FreeBSD.org/src/co= mmit/?id=3D0849f1634a70099b90256ceece52a598eeb3280e

commit 0849f1634a70099b90256ceece52a598eeb3280e
Author: Gleb Smirnoff glebius@= FreeBSD.org
AuthorDate: 2025-03-22 22:44:20 +0000
Commit: Gleb Smirnoff glebius@= FreeBSD.org
CommitDate: 2025-03-22 23:39:50 +0000

te=
sts/netinet: add test for IP_MULTICAST_IF

It bugs me a little that we have to jump through hoops to= get a C program running in a specific jail/network setup.
It=E2=80=99s somewhat common for that to happen, and I=E2=80=99m sure the= re=E2=80=99d be more cases if it were easier to do (e.g. the getaddrinfo = tests you=E2=80=99ve been working on could be even more useful with a cus= tom DNS server, so in their own vnet jail).

I took a stab at that:

di=
ff --git a/tests/sys/netinet/multicast.sh b/tests/sys/netinet/multicast.s=
h
index eb2b962dac70..7476daeb832a 100644
--- a/tests/sys/netinet/multicast.sh
+++ b/tests/sys/netinet/multicast.sh
@@ -26,6 +26,15 @@

 . $(atf_get_srcdir)/../common/vnet.subr

+ctest_j()
+{
+       jail=3D$1
+       shift
+
+       cc -x c - -o tmp || atf_fail "Failed to build"
+       jexec $jail `pwd`/tmp $@ || atf_fail "Test program failed&qu=
ot;
+}
+
 # See regression fixed in baad45c9c12028964acd0b58096f3aaa0fb22859
 atf_test_case "IP_MULTICAST_IF" "cleanup"
 IP_MULTICAST_IF_head()
@@ -33,7 +42,6 @@ IP_MULTICAST_IF_head()
        atf_set descr \
            'sendto() for IP_MULTICAST_IF socket does not do routing look=
up'
        atf_set require.user root
-
 }

 IP_MULTICAST_IF_body()
@@ -46,8 +54,45 @@ IP_MULTICAST_IF_body()
        vnet_mkjail mjail ${epair}a
        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
+
+       ctest_j mjail 192.0.2.1 <<EOF
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <assert.h>
+#include <err.h>
+
+int
+main(int argc, char *argv[])
+{
+       struct sockaddr_in sin =3D {
+               .sin_family =3D AF_INET,
+               .sin_len =3D sizeof(struct sockaddr_in),
+       };
+       struct in_addr in;
+       int s, rv;
+
+       if (argc < 2)
+               errx(1, "Usage: %s IPv4-address", argv[0]);
+
+       if (inet_pton(AF_INET, argv[1], &in) !=3D 1)
+               err(1, "inet_pton(%s) failed", argv[1]);
+
+       assert((s =3D socket(PF_INET, SOCK_DGRAM, 0)) > 0);
+       assert(bind(s, (struct sockaddr *)&sin, sizeof(sin)) =3D=3D 0=
);
+       assert(setsockopt(s, IPPROTO_IP, IP_MULTICAST_IF, &in, sizeof=
(in))
+         =3D=3D 0);
+       /* RFC 6676 */
+       assert(inet_pton(AF_INET, "233.252.0.1", &sin.sin_a=
ddr) =3D=3D 1);
+       sin.sin_port =3D htons(6676);
+       rv =3D sendto(s, &sin, sizeof(sin), 0,
+           (struct sockaddr *)&sin, sizeof(sin));
+       if (rv !=3D sizeof(sin))
+               err(1, "sendto failed");
+
+       return (0);
+}
+EOF
 }

 IP_MULTICAST_IF_cleanup()

The downside is that we=E2=80=99re compiling the C test c= ode on every run, but I expect test programs to be tiny, so that=E2=80=99= s not too much of a cost.

Does this seem useful to you too?

Best regards,
Kristof

--=_MailMate_B28CA915-06EB-49CD-961F-2ADDD3DDDB4D_=--