CVS commit: src/tests/net/net

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

Modified Files:
src/tests/net/net: t_bind.c

Log Message:
tests/net/net/t_bind: IP_BINDANY and IPV6_BINDANY require root.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/net/net/t_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/net

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

Modified Files:
src/tests/net/net: t_bind.c

Log Message:
tests/net/net/t_bind: IP_BINDANY and IPV6_BINDANY require root.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/net/net/t_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/net/t_bind.c
diff -u src/tests/net/net/t_bind.c:1.1 src/tests/net/net/t_bind.c:1.2
--- src/tests/net/net/t_bind.c:1.1	Tue Sep  8 14:13:50 2020
+++ src/tests/net/net/t_bind.c	Sat Aug  5 13:22:49 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_bind.c,v 1.1 2020/09/08 14:13:50 christos Exp $	*/
+/*	$NetBSD: t_bind.c,v 1.2 2023/08/05 13:22:49 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -33,7 +33,7 @@
 
 #include 
 #ifdef __RCSID
-__RCSID("$Id: t_bind.c,v 1.1 2020/09/08 14:13:50 christos Exp $");
+__RCSID("$Id: t_bind.c,v 1.2 2023/08/05 13:22:49 riastradh Exp $");
 #endif
 
 #include 
@@ -144,6 +144,7 @@ ATF_TC_HEAD(bindany_4, tc)
 {
 
 	atf_tc_set_md_var(tc, "descr", "Check AF_INET bindany");
+	atf_tc_set_md_var(tc, "require.user", "root");
 }
 
 ATF_TC_BODY(bindany_4, tc)
@@ -156,6 +157,7 @@ ATF_TC_HEAD(bindany_6, tc)
 {
 
 	atf_tc_set_md_var(tc, "descr", "Check AF_INET6 bindany");
+	atf_tc_set_md_var(tc, "require.user", "root");
 }
 
 ATF_TC_BODY(bindany_6, tc)



CVS commit: src/tests/net/net

2022-11-29 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Wed Nov 30 07:48:43 UTC 2022

Modified Files:
src/tests/net/net: Makefile

Log Message:
tests: restore a line removed accidentally


To generate a diff of this commit:
cvs rdiff -u -r1.27 -r1.28 src/tests/net/net/Makefile

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/net/Makefile
diff -u src/tests/net/net/Makefile:1.27 src/tests/net/net/Makefile:1.28
--- src/tests/net/net/Makefile:1.27	Wed Nov 30 06:07:51 2022
+++ src/tests/net/net/Makefile	Wed Nov 30 07:48:43 2022
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.27 2022/11/30 06:07:51 ozaki-r Exp $
+# $NetBSD: Makefile,v 1.28 2022/11/30 07:48:43 ozaki-r Exp $
 #
 
 .include 
@@ -11,6 +11,7 @@ TESTS_C+=	t_mapped
 TESTS_C+=	t_tcp
 TESTS_C+=	t_udp
 TESTS_C+=	t_pktinfo
+TESTS_C+=	t_socket_afinet
 TESTS_C+=	t_ip_reass
 .if (${MKRUMP} != "no") && !defined(BSD_MK_COMPAT_FILE)
 TESTS_C+=	t_pktinfo_send



CVS commit: src/tests/net/net

2022-11-29 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Wed Nov 30 07:48:43 UTC 2022

Modified Files:
src/tests/net/net: Makefile

Log Message:
tests: restore a line removed accidentally


To generate a diff of this commit:
cvs rdiff -u -r1.27 -r1.28 src/tests/net/net/Makefile

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



CVS commit: src/tests/net/net

2022-11-29 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Wed Nov 30 06:06:36 UTC 2022

Modified Files:
src/tests/net/net: t_ip_reass.c

Log Message:
tests: tweak t_ip_reass.c for NetBSD

The test is modified to run on rump kernels.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/net/net/t_ip_reass.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/net/t_ip_reass.c
diff -u src/tests/net/net/t_ip_reass.c:1.1 src/tests/net/net/t_ip_reass.c:1.2
--- src/tests/net/net/t_ip_reass.c:1.1	Wed Nov 30 06:05:58 2022
+++ src/tests/net/net/t_ip_reass.c	Wed Nov 30 06:06:36 2022
@@ -1,3 +1,5 @@
+/*	$NetBSD: t_ip_reass.c,v 1.2 2022/11/30 06:06:36 ozaki-r Exp $	*/
+
 /*-
  * Copyright (c) 2018 The FreeBSD Foundation
  *
@@ -28,7 +30,13 @@
  */
 
 #include 
+
+#ifdef __NetBSD__
+__RCSID("$NetBSD: t_ip_reass.c,v 1.2 2022/11/30 06:06:36 ozaki-r Exp $");
+#define USE_RUMPKERNEL	1
+#else
 __FBSDID("$FreeBSD$");
+#endif
 
 #include 
 #include 
@@ -50,8 +58,25 @@ __FBSDID("$FreeBSD$");
 #include 
 #include 
 
+#ifdef USE_RUMPKERNEL
+#include 
+#include 
+#include 
+#include "h_macros.h"
+
+#define ioctl	rump_sys_ioctl
+#define close	rump_sys_close
+#define write	rump_sys_write
+#endif
+
 #include 
 
+#ifdef __NetBSD__
+struct ipstat {
+	uint64_t ips_ipstat[IP_NSTATS];
+};
+#endif
+
 struct lopacket {
 	u_int		family;
 	struct ip	hdr;
@@ -141,10 +166,15 @@ open_lobpf(in_addr_t *addrp)
 	struct ifaddrs *ifa, *ifap;
 	int error, fd;
 
+#ifdef USE_RUMPKERNEL
+	rump_init();
+	RL(fd = rump_sys_open("/dev/bpf", O_RDWR));
+#else
 	fd = open("/dev/bpf0", O_RDWR);
 	if (fd < 0 && errno == ENOENT)
 		atf_tc_skip("no BPF device available");
 	ATF_REQUIRE_MSG(fd >= 0, "open(/dev/bpf0): %s", strerror(errno));
+#endif
 
 	error = getifaddrs();
 	ATF_REQUIRE(error == 0);
@@ -181,10 +211,21 @@ get_ipstat(struct ipstat *stat)
 	ATF_REQUIRE(len == sizeof(*stat));
 }
 
+#ifdef __NetBSD__
 #define	CHECK_IP_COUNTER(oldp, newp, counter)\
-	ATF_REQUIRE_MSG((oldp)->ips_ ## counter < (newp)->ips_ ## counter, \
+	ATF_REQUIRE_MSG((oldp)->ips_ipstat[counter] < (newp)->ips_ipstat[counter], \
 	"ips_" #counter " wasn't incremented (%ju vs. %ju)",	\
+	(uintmax_t)old.ips_ipstat[counter], (uintmax_t)new.ips_ipstat[counter]);
+#define fragdropped	IP_STAT_FRAGDROPPED
+#define toosmall	IP_STAT_TOOSMALL
+#define toolong		IP_STAT_TOOLONG
+#define badfrags	IP_STAT_BADFRAGS
+#else
+#define	CHECK_IP_COUNTER(oldp, newp, counter)\
+	ATF_REQUIRE_MSG((oldp)->ips_ ## counter < (newp)->ips_ ## counter, \
+	#counter " wasn't incremented (%ju vs. %ju)",	\
 	(uintmax_t)old.ips_ ## counter, (uintmax_t)new.ips_## counter);
+#endif
 
 /*
  * Make sure a fragment with MF set doesn't come after the last fragment of a
@@ -306,14 +347,21 @@ ATF_TC_BODY(ip_reass__zero_length_fragme
 	get_ipstat();
 	write_lopacket(fd, packet1);
 	get_ipstat();
+#ifdef __NetBSD__
+	CHECK_IP_COUNTER(, , badfrags);
+#else
 	CHECK_IP_COUNTER(, , toosmall);
 	CHECK_IP_COUNTER(, , fragdropped);
+#endif
 
 	get_ipstat();
 	write_lopacket(fd, packet2);
 	get_ipstat();
+	/* NetBSD doesn't reject a packet of zero length w/o MF */
+#ifndef __NetBSD__
 	CHECK_IP_COUNTER(, , toosmall);
 	CHECK_IP_COUNTER(, , fragdropped);
+#endif
 
 	error = close(fd);
 	ATF_REQUIRE(error == 0);
@@ -359,13 +407,17 @@ ATF_TC_BODY(ip_reass__large_fragment, tc
 	write_lopacket(fd, packet1);
 	get_ipstat();
 	CHECK_IP_COUNTER(, , toolong);
+#ifndef __NetBSD__
 	CHECK_IP_COUNTER(, , fragdropped);
+#endif
 
 	get_ipstat();
 	write_lopacket(fd, packet2);
 	get_ipstat();
 	CHECK_IP_COUNTER(, , toolong);
+#ifndef __NetBSD__
 	CHECK_IP_COUNTER(, , fragdropped);
+#endif
 
 	error = close(fd);
 	ATF_REQUIRE(error == 0);



CVS commit: src/tests/net/net

2022-11-29 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Wed Nov 30 06:06:36 UTC 2022

Modified Files:
src/tests/net/net: t_ip_reass.c

Log Message:
tests: tweak t_ip_reass.c for NetBSD

The test is modified to run on rump kernels.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/net/net/t_ip_reass.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/net

2022-11-29 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Wed Nov 30 06:05:58 UTC 2022

Added Files:
src/tests/net/net: t_ip_reass.c

Log Message:
tests: import ip_reass_test.c from FreeBSD as t_ip_reass.c

As of:
commit 9ed1e4ecd4e9eb3bde16f52a937a6fa86a971638
Author: Mark Johnston 
Date:   Tue Nov 20 18:13:18 2018 +

Plug a trivial memory leak.

CID:1396911
MFC with:   r340485


To generate a diff of this commit:
cvs rdiff -u -r0 -r1.1 src/tests/net/net/t_ip_reass.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/net/t_ip_reass.c
diff -u /dev/null src/tests/net/net/t_ip_reass.c:1.1
--- /dev/null	Wed Nov 30 06:05:58 2022
+++ src/tests/net/net/t_ip_reass.c	Wed Nov 30 06:05:58 2022
@@ -0,0 +1,383 @@
+/*-
+ * Copyright (c) 2018 The FreeBSD Foundation
+ *
+ * This software was developed by Mark Johnston under sponsorship from
+ * the FreeBSD Foundation.
+ *
+ * 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 AUTHOR 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 AUTHOR 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.
+ */
+
+#include 
+__FBSDID("$FreeBSD$");
+
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+struct lopacket {
+	u_int		family;
+	struct ip	hdr;
+	char		payload[];
+};
+
+static void
+update_cksum(struct ip *ip)
+{
+	size_t i;
+	uint32_t cksum;
+	uint16_t *cksump;
+
+	ip->ip_sum = 0;
+	cksump = (uint16_t *)ip;
+	for (cksum = 0, i = 0; i < sizeof(*ip) / sizeof(*cksump); cksump++, i++)
+		cksum += ntohs(*cksump);
+	cksum = (cksum >> 16) + (cksum & 0x);
+	cksum = ~(cksum + (cksum >> 16));
+	ip->ip_sum = htons((uint16_t)cksum);
+}
+
+static struct lopacket *
+alloc_lopacket(in_addr_t dstaddr, size_t payloadlen)
+{
+	struct ip *ip;
+	struct lopacket *packet;
+	size_t pktlen;
+
+	pktlen = sizeof(*packet) + payloadlen;
+	packet = malloc(pktlen);
+	ATF_REQUIRE(packet != NULL);
+
+	memset(packet, 0, pktlen);
+	packet->family = AF_INET;
+
+	ip = >hdr;
+	ip->ip_hl = sizeof(struct ip) >> 2;
+	ip->ip_v = 4;
+	ip->ip_tos = 0;
+	ip->ip_len = htons(sizeof(*ip) + payloadlen);
+	ip->ip_id = 0;
+	ip->ip_off = 0;
+	ip->ip_ttl = 1;
+	ip->ip_p = IPPROTO_IP;
+	ip->ip_sum = 0;
+	ip->ip_src.s_addr = dstaddr;
+	ip->ip_dst.s_addr = dstaddr;
+	update_cksum(ip);
+
+	return (packet);
+}
+
+static void
+free_lopacket(struct lopacket *packet)
+{
+
+	free(packet);
+}
+
+static void
+write_lopacket(int bpffd, struct lopacket *packet)
+{
+	struct timespec ts;
+	ssize_t n;
+	size_t len;
+
+	len = sizeof(packet->family) + ntohs(packet->hdr.ip_len);
+	n = write(bpffd, packet, len);
+	ATF_REQUIRE_MSG(n >= 0, "packet write failed: %s", strerror(errno));
+	ATF_REQUIRE_MSG((size_t)n == len, "wrote %zd bytes instead of %zu",
+	n, len);
+
+	/*
+	 * Loopback packets are dispatched asynchronously, give netisr some
+	 * time.
+	 */
+	ts.tv_sec = 0;
+	ts.tv_nsec = 500; /* 5ms */
+	(void)nanosleep(, NULL);
+}
+
+static int
+open_lobpf(in_addr_t *addrp)
+{
+	struct ifreq ifr;
+	struct ifaddrs *ifa, *ifap;
+	int error, fd;
+
+	fd = open("/dev/bpf0", O_RDWR);
+	if (fd < 0 && errno == ENOENT)
+		atf_tc_skip("no BPF device available");
+	ATF_REQUIRE_MSG(fd >= 0, "open(/dev/bpf0): %s", strerror(errno));
+
+	error = getifaddrs();
+	ATF_REQUIRE(error == 0);
+	for (ifa = ifap; ifa != NULL; ifa = ifa->ifa_next)
+		if ((ifa->ifa_flags & IFF_LOOPBACK) != 0 &&
+		ifa->ifa_addr->sa_family == AF_INET)
+			break;
+	if (ifa == NULL)
+		atf_tc_skip("no loopback address found");
+
+	memset(, 0, sizeof(ifr));
+	strlcpy(ifr.ifr_name, ifa->ifa_name, IFNAMSIZ);
+	error = ioctl(fd, 

CVS commit: src/tests/net/net

2022-11-29 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Wed Nov 30 06:05:58 UTC 2022

Added Files:
src/tests/net/net: t_ip_reass.c

Log Message:
tests: import ip_reass_test.c from FreeBSD as t_ip_reass.c

As of:
commit 9ed1e4ecd4e9eb3bde16f52a937a6fa86a971638
Author: Mark Johnston 
Date:   Tue Nov 20 18:13:18 2018 +

Plug a trivial memory leak.

CID:1396911
MFC with:   r340485


To generate a diff of this commit:
cvs rdiff -u -r0 -r1.1 src/tests/net/net/t_ip_reass.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/net

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

Modified Files:
src/tests/net/net: t_socket_afinet.c

Log Message:
tests: make t_socket_afinet.c run on rump kernel


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/net/net/t_socket_afinet.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/net/t_socket_afinet.c
diff -u src/tests/net/net/t_socket_afinet.c:1.1 src/tests/net/net/t_socket_afinet.c:1.2
--- src/tests/net/net/t_socket_afinet.c:1.1	Thu Nov 17 08:33:27 2022
+++ src/tests/net/net/t_socket_afinet.c	Thu Nov 17 08:34:39 2022
@@ -1,3 +1,5 @@
+/*	$NetBSD: t_socket_afinet.c,v 1.2 2022/11/17 08:34:39 ozaki-r Exp $	*/
+
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
  *
@@ -26,7 +28,12 @@
  */
 
 #include 
+#ifdef __NetBSD__
+__RCSID("$NetBSD: t_socket_afinet.c,v 1.2 2022/11/17 08:34:39 ozaki-r Exp $");
+#define USE_RUMPKERNEL	1
+#else
 __FBSDID("$FreeBSD$");
+#endif
 
 #include 
 #include 
@@ -35,11 +42,30 @@ __FBSDID("$FreeBSD$");
 
 #include 
 
+#ifdef USE_RUMPKERNEL
+#include 
+#include 
+
+#define socket	rump_sys_socket
+#define bind	rump_sys_bind
+#define listen	rump_sys_listen
+#define connect	rump_sys_connect
+#define write	rump_sys_write
+#define poll	rump_sys_poll
+#define close	rump_sys_close
+
+#define RUMP_INIT()	rump_init()
+#else
+#define RUMP_INIT()	do { } while (0)
+#endif
+
 ATF_TC_WITHOUT_HEAD(socket_afinet);
 ATF_TC_BODY(socket_afinet, tc)
 {
 	int sd;
 
+	RUMP_INIT();
+
 	sd = socket(PF_INET, SOCK_DGRAM, 0);
 	ATF_CHECK(sd >= 0);
 
@@ -52,6 +78,12 @@ ATF_TC_BODY(socket_afinet_bind_zero, tc)
 	int sd, rc;
 	struct sockaddr_in sin;
 
+	RUMP_INIT();
+
+#ifdef __NetBSD__
+	atf_tc_expect_fail("NetBSD doesn't allow sin_family == 0 (sin_len == 0 too)");
+#endif
+
 	if (atf_tc_get_config_var_as_bool_wd(tc, "ci", false))
 		atf_tc_skip("doesn't work when mac_portacl(4) loaded (https://bugs.freebsd.org/238781)");
 
@@ -76,6 +108,8 @@ ATF_TC_BODY(socket_afinet_bind_ok, tc)
 	int sd, rc;
 	struct sockaddr_in sin;
 
+	RUMP_INIT();
+
 	sd = socket(PF_INET, SOCK_DGRAM, 0);
 	ATF_CHECK(sd >= 0);
 
@@ -90,6 +124,7 @@ ATF_TC_BODY(socket_afinet_bind_ok, tc)
 	close(sd);
 }
 
+#ifdef POLLRDHUP
 ATF_TC_WITHOUT_HEAD(socket_afinet_poll_no_rdhup);
 ATF_TC_BODY(socket_afinet_poll_no_rdhup, tc)
 {
@@ -98,6 +133,8 @@ ATF_TC_BODY(socket_afinet_poll_no_rdhup,
 	struct pollfd pfd;
 	int one = 1;
 
+	RUMP_INIT();
+
 	/* Verify that we don't expose POLLRDHUP if not requested. */
 
 	/* Server setup. */
@@ -158,6 +195,8 @@ ATF_TC_BODY(socket_afinet_poll_rdhup, tc
 	char buffer;
 	int one = 1;
 
+	RUMP_INIT();
+
 	/* Verify that server sees POLLRDHUP if it asks for it. */
 
 	/* Server setup. */
@@ -227,6 +266,7 @@ ATF_TC_BODY(socket_afinet_poll_rdhup, tc
 	close(ss2);
 	close(ss);
 }
+#endif /* POLLRDHUP */
 
 ATF_TP_ADD_TCS(tp)
 {
@@ -234,8 +274,10 @@ ATF_TP_ADD_TCS(tp)
 	ATF_TP_ADD_TC(tp, socket_afinet);
 	ATF_TP_ADD_TC(tp, socket_afinet_bind_zero);
 	ATF_TP_ADD_TC(tp, socket_afinet_bind_ok);
+#ifdef POLLRDHUP
 	ATF_TP_ADD_TC(tp, socket_afinet_poll_no_rdhup);
 	ATF_TP_ADD_TC(tp, socket_afinet_poll_rdhup);
+#endif
 
 	return atf_no_error();
 }



CVS commit: src/tests/net/net

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

Modified Files:
src/tests/net/net: t_socket_afinet.c

Log Message:
tests: make t_socket_afinet.c run on rump kernel


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/net/net/t_socket_afinet.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/net

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

Added Files:
src/tests/net/net: t_socket_afinet.c

Log Message:
tests: import socket_afinet.c from FreeBSD as t_socket_afinet.c

As of:
commit 32efde896e19d229ee2cf09fe7e6ab0fbf6e
Author: Thomas Munro 
Date:   Wed Apr 28 21:31:38 2021 +1200

poll(2): Add POLLRDHUP.


To generate a diff of this commit:
cvs rdiff -u -r0 -r1.1 src/tests/net/net/t_socket_afinet.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/net/t_socket_afinet.c
diff -u /dev/null src/tests/net/net/t_socket_afinet.c:1.1
--- /dev/null	Thu Nov 17 08:33:27 2022
+++ src/tests/net/net/t_socket_afinet.c	Thu Nov 17 08:33:27 2022
@@ -0,0 +1,241 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ *
+ * Copyright (c) 2019 Bjoern A. Zeeb
+ *
+ * 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 AUTHOR 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 AUTHOR 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.
+ */
+
+#include 
+__FBSDID("$FreeBSD$");
+
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+ATF_TC_WITHOUT_HEAD(socket_afinet);
+ATF_TC_BODY(socket_afinet, tc)
+{
+	int sd;
+
+	sd = socket(PF_INET, SOCK_DGRAM, 0);
+	ATF_CHECK(sd >= 0);
+
+	close(sd);
+}
+
+ATF_TC_WITHOUT_HEAD(socket_afinet_bind_zero);
+ATF_TC_BODY(socket_afinet_bind_zero, tc)
+{
+	int sd, rc;
+	struct sockaddr_in sin;
+
+	if (atf_tc_get_config_var_as_bool_wd(tc, "ci", false))
+		atf_tc_skip("doesn't work when mac_portacl(4) loaded (https://bugs.freebsd.org/238781)");
+
+	sd = socket(PF_INET, SOCK_DGRAM, 0);
+	ATF_CHECK(sd >= 0);
+
+	bzero(, sizeof(sin));
+	/*
+	 * For AF_INET we do not check the family in in_pcbbind_setup(9),
+	 * sa_len gets set from the syscall argument in getsockaddr(9),
+	 * so we bind to 0:0.
+	 */
+	rc = bind(sd, (struct sockaddr *), sizeof(sin));
+	ATF_CHECK_EQ(0, rc);
+
+	close(sd);
+}
+
+ATF_TC_WITHOUT_HEAD(socket_afinet_bind_ok);
+ATF_TC_BODY(socket_afinet_bind_ok, tc)
+{
+	int sd, rc;
+	struct sockaddr_in sin;
+
+	sd = socket(PF_INET, SOCK_DGRAM, 0);
+	ATF_CHECK(sd >= 0);
+
+	bzero(, sizeof(sin));
+	sin.sin_family = AF_INET;
+	sin.sin_len = sizeof(sin);
+	sin.sin_port = htons();
+	sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
+	rc = bind(sd, (struct sockaddr *), sizeof(sin));
+	ATF_CHECK_EQ(0, rc);
+
+	close(sd);
+}
+
+ATF_TC_WITHOUT_HEAD(socket_afinet_poll_no_rdhup);
+ATF_TC_BODY(socket_afinet_poll_no_rdhup, tc)
+{
+	int ss, ss2, cs, rc;
+	struct sockaddr_in sin;
+	struct pollfd pfd;
+	int one = 1;
+
+	/* Verify that we don't expose POLLRDHUP if not requested. */
+
+	/* Server setup. */
+	ss = socket(PF_INET, SOCK_STREAM, 0);
+	ATF_CHECK(ss >= 0);
+	rc = setsockopt(ss, SOL_SOCKET, SO_REUSEPORT, , sizeof(one));
+	ATF_CHECK_EQ(0, rc);
+	bzero(, sizeof(sin));
+	sin.sin_family = AF_INET;
+	sin.sin_len = sizeof(sin);
+	sin.sin_port = htons();
+	sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
+	rc = bind(ss, (struct sockaddr *), sizeof(sin));
+	ATF_CHECK_EQ(0, rc);
+	rc = listen(ss, 1);
+	ATF_CHECK_EQ(0, rc);
+
+	/* Client connects, server accepts. */
+	cs = socket(PF_INET, SOCK_STREAM, 0);
+	ATF_CHECK(cs >= 0);
+	rc = connect(cs, (struct sockaddr *), sizeof(sin));
+	ATF_CHECK_EQ(0, rc);
+	ss2 = accept(ss, NULL, NULL);
+	ATF_CHECK(ss2 >= 0);
+
+	/* Server can write, sees only POLLOUT. */
+	pfd.fd = ss2;
+	pfd.events = POLLIN | POLLOUT;
+	rc = poll(, 1, 0);
+	ATF_CHECK_EQ(1, rc);
+	ATF_CHECK_EQ(POLLOUT, pfd.revents);
+
+	/* Client closes socket! */
+	rc = close(cs);
+	ATF_CHECK_EQ(0, rc);
+
+	/*
+	 * Server now sees POLLIN, but not POLLRDHUP because we didn't ask.
+	 * Need non-zero timeout to wait for the FIN to arrive and trigger the
+	 * socket to become readable.
+	 */
+	pfd.fd = ss2;

CVS commit: src/tests/net/net

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

Added Files:
src/tests/net/net: t_socket_afinet.c

Log Message:
tests: import socket_afinet.c from FreeBSD as t_socket_afinet.c

As of:
commit 32efde896e19d229ee2cf09fe7e6ab0fbf6e
Author: Thomas Munro 
Date:   Wed Apr 28 21:31:38 2021 +1200

poll(2): Add POLLRDHUP.


To generate a diff of this commit:
cvs rdiff -u -r0 -r1.1 src/tests/net/net/t_socket_afinet.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/net

2021-11-08 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Mon Nov  8 10:57:09 UTC 2021

Modified Files:
src/tests/net/net: t_tcp.c

Log Message:
Fix (a kind of) violation of strict aliasing rule.

Due to the rule, "sin" and "sin6" can be treated as restrict pointers.
Compilers seem to be confused by structure copy for those pointed by
them before assignments.

For aarch64eb, GCC 9 and 10 compile t_tcp.c rev 1.11 into a code, where
fetch for "sin6->sin6_port" is preceding the structure copy "ss = bs".
This results in failure of connect(2) with EADDRNOOTAVAIL.


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/tests/net/net/t_tcp.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/net

2021-11-08 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Mon Nov  8 10:57:09 UTC 2021

Modified Files:
src/tests/net/net: t_tcp.c

Log Message:
Fix (a kind of) violation of strict aliasing rule.

Due to the rule, "sin" and "sin6" can be treated as restrict pointers.
Compilers seem to be confused by structure copy for those pointed by
them before assignments.

For aarch64eb, GCC 9 and 10 compile t_tcp.c rev 1.11 into a code, where
fetch for "sin6->sin6_port" is preceding the structure copy "ss = bs".
This results in failure of connect(2) with EADDRNOOTAVAIL.


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/tests/net/net/t_tcp.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/net/t_tcp.c
diff -u src/tests/net/net/t_tcp.c:1.11 src/tests/net/net/t_tcp.c:1.12
--- src/tests/net/net/t_tcp.c:1.11	Sat Oct 26 23:08:27 2019
+++ src/tests/net/net/t_tcp.c	Mon Nov  8 10:57:09 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_tcp.c,v 1.11 2019/10/26 23:08:27 christos Exp $	*/
+/*	$NetBSD: t_tcp.c,v 1.12 2021/11/08 10:57:09 rin Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
 
 #include 
 #ifdef __RCSID
-__RCSID("$Id: t_tcp.c,v 1.11 2019/10/26 23:08:27 christos Exp $");
+__RCSID("$Id: t_tcp.c,v 1.12 2021/11/08 10:57:09 rin Exp $");
 #endif
 
 /* Example code. Should block; does with accept not accept4_. */
@@ -139,15 +139,14 @@ accept_test(sa_family_t sfamily, sa_fami
 		FAIL("socket");
 
 	if (sfamily == AF_INET6 && cfamily == AF_INET) {
-		ss = bs;
-		sin6 = (void *)
+		in_port_t port = ((struct sockaddr_in6 *))->sin6_port;
 		sin = (void *)
 		addrlen = sizeof(*sin);
 #ifdef BSD4_4
 		sin->sin_len = sizeof(*sin);
 #endif
 		sin->sin_family = AF_INET;
-		sin->sin_port = sin6->sin6_port;
+		sin->sin_port = port;
 		sin->sin_addr.s_addr = htonl(INADDR_LOOPBACK);
 	}
 



CVS commit: src/tests/net/net

2019-08-26 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Mon Aug 26 07:41:51 UTC 2019

Modified Files:
src/tests/net/net: t_ipv6address.sh

Log Message:
tests: add tests for IPv6 link-local addresses with a scope ID

Setting an address with a scope ID doesn't work for rump.ifconfig for some
reasons and needs $HIJACKING for now.  The bug should be fixed someday.


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/tests/net/net/t_ipv6address.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/net

2019-08-26 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Mon Aug 26 07:41:51 UTC 2019

Modified Files:
src/tests/net/net: t_ipv6address.sh

Log Message:
tests: add tests for IPv6 link-local addresses with a scope ID

Setting an address with a scope ID doesn't work for rump.ifconfig for some
reasons and needs $HIJACKING for now.  The bug should be fixed someday.


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/tests/net/net/t_ipv6address.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/net/t_ipv6address.sh
diff -u src/tests/net/net/t_ipv6address.sh:1.15 src/tests/net/net/t_ipv6address.sh:1.16
--- src/tests/net/net/t_ipv6address.sh:1.15	Mon May 13 17:55:09 2019
+++ src/tests/net/net/t_ipv6address.sh	Mon Aug 26 07:41:50 2019
@@ -1,4 +1,4 @@
-#	$NetBSD: t_ipv6address.sh,v 1.15 2019/05/13 17:55:09 bad Exp $
+#	$NetBSD: t_ipv6address.sh,v 1.16 2019/08/26 07:41:50 ozaki-r Exp $
 #
 # Copyright (c) 2015 Internet Initiative Japan Inc.
 # All rights reserved.
@@ -247,6 +247,7 @@ linklocal_body()
 	local dst_if0_lladdr=`get_linklocal_addr ${SOCKDST} shmif0`
 	local fwd_if0_lladdr=`get_linklocal_addr ${SOCKFWD} shmif0`
 	local fwd_if1_lladdr=`get_linklocal_addr ${SOCKFWD} shmif1`
+	local lladdr=fe80::2
 
 	export RUMP_SERVER=${SOCKSRC}
 	$DEBUG && rump.ifconfig
@@ -325,6 +326,19 @@ linklocal_body()
 	atf_check -s ignore -o not-empty -e ignore \
 	-x "shmif_dumpbus -p - ${BUS2} | tcpdump -r - -n -p icmp6"
 
+	# Setting a link-local address with a scope ID
+	# XXX need $HIJACKING for some reasons
+	cleanup_bus
+	export RUMP_SERVER=${SOCKFWD}
+	$DEBUG && rump.ifconfig shmif0
+	atf_check -s exit:0 $HIJACKING rump.ifconfig shmif0 inet6 $lladdr%shmif0/64
+	export RUMP_SERVER=${SOCKSRC}
+	atf_check -s exit:0 -o match:"0.0% packet loss" rump.ping6 -c 1 \
+	-X $TIMEOUT -n $lladdr
+	export RUMP_SERVER=${SOCKDST}
+	atf_check -s not-exit:0 -o match:"100.0% packet loss" rump.ping6 -c 1 \
+	-X $TIMEOUT -n $lladdr
+
 	unset RUMP_SERVER
 
 }



Re: CVS commit: src/tests/net/net

2016-11-06 Thread Ryota Ozaki
On Mon, Nov 7, 2016 at 1:43 PM, Ryota Ozaki  wrote:
> Module Name:src
> Committed By:   ozaki-r
> Date:   Mon Nov  7 04:43:14 UTC 2016
>
> Modified Files:
> src/tests/net/net: t_ping6_opts.sh
>
> Log Message:
> Add tests of ping6 hops optional argument (Type 0 Routing Headers)
>
> Note that ping6 with the argument can send packets with routing headers
> but the kernel doesn't support receiving the packets so that ping6 fails.
> Nevertheless, we can test whether sent packets are correct or not.

BTW, should we remove the functionality of sending packets with Type 0
Routing Headers in favor of RFC 5095?

  ozaki-r


Re: CVS commit: src/tests/net/net

2011-09-30 Thread Jukka Ruohonen
On Wed, Sep 28, 2011 at 12:13:03PM -0400, Christos Zoulas wrote:
 Module Name:  src
 Committed By: christos
 Date: Wed Sep 28 16:13:03 UTC 2011
 
 Modified Files:
   src/tests/net/net: Makefile
 Added Files:
   src/tests/net/net: t_unix.c
 
 Log Message:
 Add a unix socket pathname size limit test.

This fails, probably because it does not follow the atf(7) API:

tps-count: 1
tp-start: t_unix, 2
tc-start: sockaddr_un_len_exceed
tc-end: sockaddr_un_len_exceed, passed
tc-start: sockaddr_un_len_max
tc-end: sockaddr_un_len_max, failed, Test case exited normally but failed to
create the results file: Failed to open /tmp/atf-run.03735a/tcr
tp-end: t_unix

- Jukka.


Re: CVS commit: src/tests/net/net

2011-09-30 Thread Julio Merino

On 9/30/11 2:17 PM, Christos Zoulas wrote:

On Sep 30,  5:37pm, jruoho...@iki.fi (Jukka Ruohonen) wrote:
-- Subject: Re: CVS commit: src/tests/net/net

| This fails, probably because it does not follow the atf(7) API:
|
| tps-count: 1
| tp-start: t_unix, 2
| tc-start: sockaddr_un_len_exceed
| tc-end: sockaddr_un_len_exceed, passed
| tc-start: sockaddr_un_len_max
| tc-end: sockaddr_un_len_max, failed, Test case exited normally but failed to
| create the results file: Failed to open /tmp/atf-run.03735a/tcr
| tp-end: t_unix

Can you be more specific? What does it need to do?


Use ATF_FAIL instead of err() to signal errors.