CVS commit: src/tests/net/inpcb

2023-08-05 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Aug  5 13:25:26 UTC 2023

Modified Files:
src/tests/net/inpcb: t_inpcb_bind.sh

Log Message:
tests/net/inpcb: Tests require root.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/net/inpcb/t_inpcb_bind.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/net/inpcb/t_inpcb_bind.sh
diff -u src/tests/net/inpcb/t_inpcb_bind.sh:1.1 src/tests/net/inpcb/t_inpcb_bind.sh:1.2
--- src/tests/net/inpcb/t_inpcb_bind.sh:1.1	Thu Nov 17 08:40:23 2022
+++ src/tests/net/inpcb/t_inpcb_bind.sh	Sat Aug  5 13:25:26 2023
@@ -1,4 +1,4 @@
-#	$NetBSD: t_inpcb_bind.sh,v 1.1 2022/11/17 08:40:23 ozaki-r Exp $
+#	$NetBSD: t_inpcb_bind.sh,v 1.2 2023/08/05 13:25:26 riastradh Exp $
 #
 # Copyright (c) 2022 Internet Initiative Japan Inc.
 # All rights reserved.
@@ -70,6 +70,7 @@ add_test()
 	eval "${name}_head() {
 			atf_set descr \"${desc}\"
 			atf_set require.progs rump_server
+			atf_set require.user root
 		}
 	${name}_body() {
 			test_${name}



CVS commit: src/tests/net/inpcb

2023-08-05 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Aug  5 13:25:26 UTC 2023

Modified Files:
src/tests/net/inpcb: t_inpcb_bind.sh

Log Message:
tests/net/inpcb: Tests require root.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/net/inpcb/t_inpcb_bind.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/tests/net/inpcb

2022-11-17 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Thu Nov 17 08:42:56 UTC 2022

Added Files:
src/tests/net/inpcb: t_broadcast_bind.sh

Log Message:
tests: add t_broadcast_bind.sh


To generate a diff of this commit:
cvs rdiff -u -r0 -r1.1 src/tests/net/inpcb/t_broadcast_bind.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Added files:

Index: src/tests/net/inpcb/t_broadcast_bind.sh
diff -u /dev/null src/tests/net/inpcb/t_broadcast_bind.sh:1.1
--- /dev/null	Thu Nov 17 08:42:56 2022
+++ src/tests/net/inpcb/t_broadcast_bind.sh	Thu Nov 17 08:42:56 2022
@@ -0,0 +1,75 @@
+#	$NetBSD: t_broadcast_bind.sh,v 1.1 2022/11/17 08:42:56 ozaki-r Exp $
+#
+# Copyright (c) 2022 Internet Initiative Japan Inc.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#notice, this list of conditions and the following disclaimer in the
+#documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+
+SOCK=unix://broadcast_bind
+BUS=./bus
+
+DEBUG=${DEBUG:-false}
+NAME="broadcast_bind"
+
+test_broadcast_bind_basic()
+{
+	#local insfx=$(jot -s '.' -r 2 0 255)
+	local insfx="0.0"
+	local inaddr="10.$insfx.10"
+	local badaddr="10.$insfx.22"
+	local bcaddr="10.$insfx.255"
+	local prog="$(atf_get_srcdir)/broadcast_bind"
+
+	rump_server_start $SOCK
+	rump_server_add_iface $SOCK shmif0 $BUS
+
+	export RUMP_SERVER=$SOCK
+	atf_check -s exit:0 rump.ifconfig shmif0 $inaddr/24
+	atf_check -s exit:0 $HIJACKING $prog $inaddr $badaddr $bcaddr
+}
+
+add_test()
+{
+	local name="${NAME}_$1"
+	local desc="$2"
+
+	atf_test_case "${name}" cleanup
+	eval "${name}_head() {
+			atf_set descr \"${desc}\"
+			atf_set require.progs rump_server
+		}
+	${name}_body() {
+			test_${name}
+		}
+	${name}_cleanup() {
+			\$DEBUG && dump
+			cleanup
+		}"
+	atf_add_test_case "${name}"
+}
+
+atf_init_test_cases()
+{
+
+	add_test basic	"bind(2)ing with broadcast and inexistant addresses"
+}



CVS commit: src/tests/net/inpcb

2022-11-17 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Thu Nov 17 08:42:56 UTC 2022

Added Files:
src/tests/net/inpcb: t_broadcast_bind.sh

Log Message:
tests: add t_broadcast_bind.sh


To generate a diff of this commit:
cvs rdiff -u -r0 -r1.1 src/tests/net/inpcb/t_broadcast_bind.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/tests/net/inpcb

2022-11-17 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Thu Nov 17 08:42:06 UTC 2022

Modified Files:
src/tests/net/inpcb: broadcast_bind.c

Log Message:
tests: tweak broadcast_bind.c for NetBSD


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/net/inpcb/broadcast_bind.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/net/inpcb/broadcast_bind.c
diff -u src/tests/net/inpcb/broadcast_bind.c:1.1 src/tests/net/inpcb/broadcast_bind.c:1.2
--- src/tests/net/inpcb/broadcast_bind.c:1.1	Thu Nov 17 08:41:16 2022
+++ src/tests/net/inpcb/broadcast_bind.c	Thu Nov 17 08:42:06 2022
@@ -1,3 +1,4 @@
+/* $NetBSD: broadcast_bind.c,v 1.2 2022/11/17 08:42:06 ozaki-r Exp $ */
 /* $OpenBSD: broadcast_bind.c,v 1.2 2015/12/02 20:45:00 mpi Exp $ */
 
 /*
@@ -30,7 +31,7 @@
 #include 
 
 
-int
+static int
 test_bind(char *paddr, struct in_addr *addr, u_int16_t port, int type,
 int expected_errno)
 {
@@ -100,7 +101,11 @@ main(int argc, char *argv[])
 	rc = 0;
 	rc |= test_bind(argv[1], _addr, port, SOCK_STREAM, 0);
 	rc |= test_bind(argv[2], _addr, port, SOCK_STREAM, EADDRNOTAVAIL);
+#ifdef __NetBSD__
+	rc |= test_bind(argv[3], _addr, port, SOCK_STREAM, 0);
+#else
 	rc |= test_bind(argv[3], _addr, port, SOCK_STREAM, EADDRNOTAVAIL);
+#endif
 
 	rc |= test_bind(argv[2], _addr, port, SOCK_STREAM, EADDRNOTAVAIL);
 	rc |= test_bind(argv[3], _addr, port, SOCK_DGRAM, 0);



CVS commit: src/tests/net/inpcb

2022-11-17 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Thu Nov 17 08:42:06 UTC 2022

Modified Files:
src/tests/net/inpcb: broadcast_bind.c

Log Message:
tests: tweak broadcast_bind.c for NetBSD


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/net/inpcb/broadcast_bind.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/tests/net/inpcb

2022-11-17 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Thu Nov 17 08:41:16 UTC 2022

Added Files:
src/tests/net/inpcb: broadcast_bind.c

Log Message:
tests: import broadcast_bind.c from OpenBSD

As of $OpenBSD: broadcast_bind.c,v 1.2 2015/12/02 20:45:00 mpi Exp $


To generate a diff of this commit:
cvs rdiff -u -r0 -r1.1 src/tests/net/inpcb/broadcast_bind.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Added files:

Index: src/tests/net/inpcb/broadcast_bind.c
diff -u /dev/null src/tests/net/inpcb/broadcast_bind.c:1.1
--- /dev/null	Thu Nov 17 08:41:16 2022
+++ src/tests/net/inpcb/broadcast_bind.c	Thu Nov 17 08:41:16 2022
@@ -0,0 +1,109 @@
+/* $OpenBSD: broadcast_bind.c,v 1.2 2015/12/02 20:45:00 mpi Exp $ */
+
+/*
+ * Copyright (c) 2015 Vincent Gross 
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+#include 
+
+#include 
+
+
+int
+test_bind(char *paddr, struct in_addr *addr, u_int16_t port, int type,
+int expected_errno)
+{
+	int s, rc;
+	struct sockaddr_in sin;
+
+	memset(, 0, sizeof(sin));
+	sin.sin_family = AF_INET;
+	sin.sin_len = sizeof(sin);
+	sin.sin_port = htons(port);
+	memcpy(_addr, addr, sizeof(*addr));
+
+	s = socket(PF_INET, type, 0);
+	if (s < 0) {
+		warn("socket(PF_INET, %d, 0)", type);
+		return (1);
+	}
+
+	rc = bind(s, (struct sockaddr *), sin.sin_len);
+	if ((rc == 0 && expected_errno == 0) ||
+	(rc != 0 && expected_errno == errno)) {
+		close(s);
+		return (0);
+	}
+
+	warn("bind(%s,%d) (type %d) expected %d, got %d", paddr, port, type,
+	expected_errno, errno);
+	close(s);
+
+	return (1);
+}
+
+int
+main(int argc, char *argv[])
+{
+	int rc;
+	struct in_addr uc_addr, err_addr, bc_addr;
+	int port = 3;
+
+	if (argc != 4)
+		errx(1, "needs 2 arguments:   ");
+
+	rc = inet_pton(AF_INET, argv[1], _addr);
+	if (rc != 1) {
+		if (rc)
+			err(1, "inet_pton(unicast)");
+		else
+			errx(1, "inet_pton(unicast): error parsing %s",
+			argv[1]);
+	}
+	rc = inet_pton(AF_INET, argv[2], _addr);
+	if (rc != 1) {
+		if (rc)
+			err(1, "inet_pton(error)");
+		else
+			errx(1, "inet_pton(error): error parsing %s", argv[2]);
+	}
+	rc = inet_pton(AF_INET, argv[3], _addr);
+	if (rc != 1) {
+		if (rc)
+			err(1, "inet_pton(broadcast)");
+		else
+			errx(1, "inet_pton(broadcast): error parsing %s",
+			argv[3]);
+	}
+
+	rc = 0;
+	rc |= test_bind(argv[1], _addr, port, SOCK_STREAM, 0);
+	rc |= test_bind(argv[2], _addr, port, SOCK_STREAM, EADDRNOTAVAIL);
+	rc |= test_bind(argv[3], _addr, port, SOCK_STREAM, EADDRNOTAVAIL);
+
+	rc |= test_bind(argv[2], _addr, port, SOCK_STREAM, EADDRNOTAVAIL);
+	rc |= test_bind(argv[3], _addr, port, SOCK_DGRAM, 0);
+
+	return (rc);
+}



CVS commit: src/tests/net/inpcb

2022-11-17 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Thu Nov 17 08:41:16 UTC 2022

Added Files:
src/tests/net/inpcb: broadcast_bind.c

Log Message:
tests: import broadcast_bind.c from OpenBSD

As of $OpenBSD: broadcast_bind.c,v 1.2 2015/12/02 20:45:00 mpi Exp $


To generate a diff of this commit:
cvs rdiff -u -r0 -r1.1 src/tests/net/inpcb/broadcast_bind.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/tests/net/inpcb

2022-11-17 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Thu Nov 17 08:40:24 UTC 2022

Added Files:
src/tests/net/inpcb: t_inpcb_bind.sh

Log Message:
tests: add t_inpcb_bind.sh


To generate a diff of this commit:
cvs rdiff -u -r0 -r1.1 src/tests/net/inpcb/t_inpcb_bind.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Added files:

Index: src/tests/net/inpcb/t_inpcb_bind.sh
diff -u /dev/null src/tests/net/inpcb/t_inpcb_bind.sh:1.1
--- /dev/null	Thu Nov 17 08:40:24 2022
+++ src/tests/net/inpcb/t_inpcb_bind.sh	Thu Nov 17 08:40:23 2022
@@ -0,0 +1,89 @@
+#	$NetBSD: t_inpcb_bind.sh,v 1.1 2022/11/17 08:40:23 ozaki-r Exp $
+#
+# Copyright (c) 2022 Internet Initiative Japan Inc.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#notice, this list of conditions and the following disclaimer in the
+#documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+
+SOCK=unix://inpcb_bind
+BUS=./bus
+
+DEBUG=${DEBUG:-false}
+NAME="inpcb_bind"
+
+test_inpcb_bind_ipv4()
+{
+	local addr="10.0.0.10"
+	local port=23000
+	local prog="$(atf_get_srcdir)/inpcb_bind"
+
+	rump_server_start $SOCK
+	rump_server_add_iface $SOCK shmif0 $BUS
+
+	export RUMP_SERVER=$SOCK
+	atf_check -s exit:0 rump.ifconfig shmif0 $addr/24
+	atf_check -s exit:0 -o ignore $HIJACKING $prog $addr $port
+	atf_check -s exit:0 -o ignore $HIJACKING $prog 224.0.2.1 $port $addr
+}
+
+test_inpcb_bind_ipv6()
+{
+	local addr="fc00::10"
+	local port=23000
+	local prog="$(atf_get_srcdir)/inpcb_bind"
+
+	rump_server_start $SOCK netinet6
+	rump_server_add_iface $SOCK shmif0 $BUS
+
+	export RUMP_SERVER=$SOCK
+	atf_check -s exit:0 rump.ifconfig shmif0 inet6 $addr/64
+	atf_check -s exit:0 -o ignore $HIJACKING $prog $addr $port
+	atf_check -s exit:0 -o ignore $HIJACKING $prog ff1e::123 $port $addr
+}
+
+add_test()
+{
+	local name="${NAME}_$1"
+	local desc="$2"
+
+	atf_test_case "${name}" cleanup
+	eval "${name}_head() {
+			atf_set descr \"${desc}\"
+			atf_set require.progs rump_server
+		}
+	${name}_body() {
+			test_${name}
+		}
+	${name}_cleanup() {
+			\$DEBUG && dump
+			cleanup
+		}"
+	atf_add_test_case "${name}"
+}
+
+atf_init_test_cases()
+{
+
+	add_test ipv4	"tests for inpcb_bind (ipv4)"
+	add_test ipv6	"tests for inpcb_bind (ipv6)"
+}



CVS commit: src/tests/net/inpcb

2022-11-17 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Thu Nov 17 08:40:24 UTC 2022

Added Files:
src/tests/net/inpcb: t_inpcb_bind.sh

Log Message:
tests: add t_inpcb_bind.sh


To generate a diff of this commit:
cvs rdiff -u -r0 -r1.1 src/tests/net/inpcb/t_inpcb_bind.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/tests/net/inpcb

2022-11-17 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Thu Nov 17 08:38:58 UTC 2022

Modified Files:
src/tests/net/inpcb: inpcb_bind.c

Log Message:
tests: make inpcb_bind.c buildable


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/net/inpcb/inpcb_bind.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/net/inpcb/inpcb_bind.c
diff -u src/tests/net/inpcb/inpcb_bind.c:1.1 src/tests/net/inpcb/inpcb_bind.c:1.2
--- src/tests/net/inpcb/inpcb_bind.c:1.1	Thu Nov 17 08:38:08 2022
+++ src/tests/net/inpcb/inpcb_bind.c	Thu Nov 17 08:38:58 2022
@@ -1,3 +1,4 @@
+/* $NetBSD: inpcb_bind.c,v 1.2 2022/11/17 08:38:58 ozaki-r Exp $ */
 /* $OpenBSD: runtest.c,v 1.7 2022/04/10 14:08:35 claudio Exp $ */
 /*
  * Copyright (c) 2015 Vincent Gross 
@@ -29,12 +30,11 @@
 #include 
 #include 
 
-int
+static int
 runtest(int *sockp, struct addrinfo *ai, int reuseaddr, int reuseport,
 void *mreq, int expected)
 {
 	int error, optval;
-	struct ip_mreq imr;
 
 	*sockp = socket(ai->ai_family, ai->ai_socktype, 0);
 	if (*sockp == -1) {
@@ -106,7 +106,7 @@ runtest(int *sockp, struct addrinfo *ai,
 	return (0);
 }
 
-void
+static void
 cleanup(int *fds, int num_fds)
 {
 	while (num_fds-- > 0)
@@ -114,7 +114,7 @@ cleanup(int *fds, int num_fds)
 			err(2, "unable to clean up sockets, aborting");
 }
 
-int
+static int
 unicast_testsuite(struct addrinfo *local, struct addrinfo *any)
 {
 	int test_rc, rc, *s;
@@ -180,12 +180,11 @@ unicast_testsuite(struct addrinfo *local
 	return (test_rc);
 }
 
-int
+static int
 mcast_reuse_testsuite(struct addrinfo *local, void *mr)
 {
 	int test_rc, rc, *s;
 	int sockets[6];
-	int testnum = 1;
 
 	test_rc = 0;
 	rc = 0; s = sockets;
@@ -266,13 +265,12 @@ mcast_reuse_testsuite(struct addrinfo *l
 	return (test_rc);
 }
 
-int
+static int
 mcast6_testsuite(struct addrinfo *local, struct ipv6_mreq *local_mreq,
 struct addrinfo *any, struct ipv6_mreq *any_mreq)
 {
 	int test_rc, rc, *s;
 	int sockets[4];
-	int testnum = 1;
 
 	test_rc = 0;
 	rc = 0; s = sockets;
@@ -350,11 +348,10 @@ main(int argc, char *argv[])
 	char *baddr_s, *bport_s, *bmifa_s;
 	struct addrinfo hints, *baddr, *any, *mifa;
 	struct ifaddrs *ifap, *curifa;
-	struct ip_mreq local_imr, any_imr;
+	struct ip_mreq local_imr;
 	struct ipv6_mreq local_i6mr, any_i6mr;
 	struct sockaddr_in *sin;
 	struct sockaddr_in6 *sin6;
-	int *s;
 
 	memset(, 0, sizeof(hints));
 	hints.ai_flags = AI_ADDRCONFIG | AI_NUMERICHOST | AI_NUMERICSERV | \
@@ -373,7 +370,7 @@ main(int argc, char *argv[])
 	if ((error = getaddrinfo(NULL, bport_s, , )))
 		errx(2, "getaddrinfo(NULL,%s): %s", bport_s,
 		gai_strerror(error));
-	any->ai_canonname = "*";
+	any->ai_canonname = strdup("*");
 
 	switch (baddr->ai_family) {
 	case AF_INET:



CVS commit: src/tests/net/inpcb

2022-11-17 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Thu Nov 17 08:38:58 UTC 2022

Modified Files:
src/tests/net/inpcb: inpcb_bind.c

Log Message:
tests: make inpcb_bind.c buildable


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/net/inpcb/inpcb_bind.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/tests/net/inpcb

2022-11-17 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Thu Nov 17 08:38:08 UTC 2022

Added Files:
src/tests/net/inpcb: inpcb_bind.c

Log Message:
tests: import in_pcbbind/runtest.c from OpenBSD as inpcb_bind.c

As of $OpenBSD: runtest.c,v 1.7 2022/04/10 14:08:35 claudio Exp $


To generate a diff of this commit:
cvs rdiff -u -r0 -r1.1 src/tests/net/inpcb/inpcb_bind.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Added files:

Index: src/tests/net/inpcb/inpcb_bind.c
diff -u /dev/null src/tests/net/inpcb/inpcb_bind.c:1.1
--- /dev/null	Thu Nov 17 08:38:08 2022
+++ src/tests/net/inpcb/inpcb_bind.c	Thu Nov 17 08:38:08 2022
@@ -0,0 +1,455 @@
+/* $OpenBSD: runtest.c,v 1.7 2022/04/10 14:08:35 claudio Exp $ */
+/*
+ * Copyright (c) 2015 Vincent Gross 
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+int
+runtest(int *sockp, struct addrinfo *ai, int reuseaddr, int reuseport,
+void *mreq, int expected)
+{
+	int error, optval;
+	struct ip_mreq imr;
+
+	*sockp = socket(ai->ai_family, ai->ai_socktype, 0);
+	if (*sockp == -1) {
+		warn("%s : socket()", ai->ai_canonname);
+		return (3);
+	}
+
+	if (reuseaddr) {
+		optval = 1;
+		error = setsockopt(*sockp, SOL_SOCKET, SO_REUSEADDR,
+		, sizeof(int));
+		if (error) {
+			warn("%s : setsockopt(SO_REUSEADDR)", ai->ai_canonname);
+			return (2);
+		}
+	}
+
+	if (reuseport) {
+		optval = 1;
+		error = setsockopt(*sockp, SOL_SOCKET, SO_REUSEPORT,
+		, sizeof(int));
+		if (error) {
+			warn("%s : setsockopt(SO_REUSEPORT)", ai->ai_canonname);
+			return (2);
+		}
+	}
+
+	if (mreq) {
+		switch (ai->ai_family) {
+		case AF_INET6:
+			error = setsockopt(*sockp, IPPROTO_IPV6, IPV6_JOIN_GROUP,
+			mreq, sizeof(struct ipv6_mreq));
+			if (error) {
+warn("%s : setsockopt(IPV6_JOIN_GROUP)",
+ai->ai_canonname);
+return (2);
+			}
+			break;
+		case AF_INET:
+			error = setsockopt(*sockp, IPPROTO_IP, IP_ADD_MEMBERSHIP,
+			mreq, sizeof(struct ip_mreq));
+			if (error) {
+warn("%s : setsockopt(IP_ADD_MEMBERSHIP)",
+ai->ai_canonname);
+return (2);
+			}
+			break;
+		default:
+			warnx("%s : trying to join multicast group in unknown AF",
+			ai->ai_canonname);
+			return (2);
+		}
+	}
+
+
+	error = bind(*sockp, ai->ai_addr, ai->ai_addrlen);
+	if (error && (expected == 0 || expected != errno)) {
+		warn("bind(%s,%s,%s)", ai->ai_canonname,
+		reuseaddr ? "REUSEADDR" : "", reuseport ? "REUSEPORT" : "");
+		return (1);
+	}
+	if (error == 0 && expected != 0) {
+		warnx("bind(%s,%s,%s) succeeded, expected : %s", ai->ai_canonname,
+		reuseaddr ? "REUSEADDR" : "", reuseport ? "REUSEPORT" : "",
+		strerror(expected));
+		return (1);
+	}
+
+	return (0);
+}
+
+void
+cleanup(int *fds, int num_fds)
+{
+	while (num_fds-- > 0)
+		if (close(*fds++) && errno != EBADF)
+			err(2, "unable to clean up sockets, aborting");
+}
+
+int
+unicast_testsuite(struct addrinfo *local, struct addrinfo *any)
+{
+	int test_rc, rc, *s;
+	int sockets[4];
+
+	test_rc = 0;
+	rc = 0; s = sockets;
+	rc |= runtest(s++, local, 0, 0, NULL, 0);
+	rc |= runtest(s++, any,   0, 0, NULL, EADDRINUSE);
+	rc |= runtest(s++, any,   1, 0, NULL, 0);
+	cleanup(sockets, 3);
+	test_rc |= rc;
+	if (rc)
+		warnx("%s : test #%d failed", __func__, 1);
+
+	rc = 0; s = sockets;
+	rc |= runtest(s++, any,   0, 0, NULL, 0);
+	rc |= runtest(s++, local, 0, 0, NULL, EADDRINUSE);
+	rc |= runtest(s++, local, 1, 0, NULL, 0);
+	cleanup(sockets, 3);
+	test_rc |= rc;
+	if (rc)
+		warnx("%s : test #%d failed", __func__, 2);
+
+	rc = 0; s = sockets;
+	rc |= runtest(s++, local, 0, 1, NULL, 0);
+	rc |= runtest(s++, local, 0, 1, NULL, 0);
+	rc |= runtest(s++, local, 1, 0, NULL, EADDRINUSE);
+	rc |= runtest(s++, local, 0, 0, NULL, EADDRINUSE);
+	cleanup(sockets, 4);
+	test_rc |= rc;
+	if (rc)
+		warnx("%s : test #%d failed", __func__, 3);
+
+	rc = 0; s = sockets;
+	rc |= runtest(s++, any, 0, 1, NULL, 0);
+	rc |= runtest(s++, any, 0, 1, NULL, 0);
+	rc |= runtest(s++, any, 1, 0, NULL, EADDRINUSE);
+	rc |= runtest(s++, any, 0, 0, NULL, EADDRINUSE);
+	cleanup(sockets, 4);
+	test_rc |= rc;
+	if (rc)
+		

CVS commit: src/tests/net/inpcb

2022-11-17 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Thu Nov 17 08:38:08 UTC 2022

Added Files:
src/tests/net/inpcb: inpcb_bind.c

Log Message:
tests: import in_pcbbind/runtest.c from OpenBSD as inpcb_bind.c

As of $OpenBSD: runtest.c,v 1.7 2022/04/10 14:08:35 claudio Exp $


To generate a diff of this commit:
cvs rdiff -u -r0 -r1.1 src/tests/net/inpcb/inpcb_bind.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.