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

2020-09-08 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue Sep  8 14:13:50 UTC 2020

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

Log Message:
Add tests for IP_BINDANY, IPV6_BINDANY


To generate a diff of this commit:
cvs rdiff -u -r1.24 -r1.25 src/tests/net/net/Makefile
cvs rdiff -u -r0 -r1.1 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/Makefile
diff -u src/tests/net/net/Makefile:1.24 src/tests/net/net/Makefile:1.25
--- src/tests/net/net/Makefile:1.24	Mon Jul  6 14:45:25 2020
+++ src/tests/net/net/Makefile	Tue Sep  8 10:13:50 2020
@@ -1,11 +1,12 @@
-# $NetBSD: Makefile,v 1.24 2020/07/06 18:45:25 christos Exp $
+# $NetBSD: Makefile,v 1.25 2020/09/08 14:13:50 christos Exp $
 #
 
 .include 
 
 TESTSDIR=	${TESTSBASE}/net/net
 
-TESTS_C=	t_unix
+TESTS_C=	t_bind
+TESTS_C+=	t_unix
 TESTS_C+=	t_mapped
 TESTS_C+=	t_tcp
 TESTS_C+=	t_udp

Added files:

Index: src/tests/net/net/t_bind.c
diff -u /dev/null src/tests/net/net/t_bind.c:1.1
--- /dev/null	Tue Sep  8 10:13:50 2020
+++ src/tests/net/net/t_bind.c	Tue Sep  8 10:13:50 2020
@@ -0,0 +1,180 @@
+/*	$NetBSD: t_bind.c,v 1.1 2020/09/08 14:13:50 christos Exp $	*/
+
+/*-
+ * Copyright (c) 2020 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Christos Zoulas.
+ *
+ * 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.
+ */
+
+#define _GNU_SOURCE
+
+#include 
+#ifdef __RCSID
+__RCSID("$Id: t_bind.c,v 1.1 2020/09/08 14:13:50 christos Exp $");
+#endif
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "util.h"
+
+#include "test.h"
+
+static int
+mksocket(int sfam)
+{
+	int o, p;
+	switch (sfam) {
+	case AF_INET:
+		o = IP_BINDANY;
+		p = IPPROTO_IP;
+		break;
+	case AF_INET6:
+		o = IPV6_BINDANY;
+		p = IPPROTO_IPV6;
+		break;
+	default:
+		FAIL("family");
+	}
+	int fd = socket(sfam, SOCK_STREAM, 0);
+	if (fd == -1)
+		FAIL("socket");
+	int f = 1;
+	if (setsockopt(fd, p, o, , sizeof(f)) == -1) {
+		close(fd);
+		FAIL("setsockopt");
+	}
+	return fd;
+fail:
+	return -1;
+}
+
+static socklen_t
+mkserver(int sfam, struct sockaddr_storage *ss)
+{
+	struct sockaddr_in *sin;
+	struct sockaddr_in6 *sin6;
+
+	memset(ss, 0, sizeof(*ss));
+	ss->ss_family = sfam;
+	switch (sfam) {
+	case AF_INET:
+		sin = (struct sockaddr_in *)ss;
+		sin->sin_port = htons(12345);
+#ifdef BSD4_4
+		sin->sin_len = sizeof(*sin);
+#endif
+		inet_pton(sfam, "1.1.1.1", >sin_addr);
+		return sizeof(*sin);
+	case AF_INET6:
+		sin6 = (struct sockaddr_in6 *)ss;
+		sin6->sin6_port = htons(12345);
+#ifdef BSD4_4
+		sin6->sin6_len = sizeof(*sin6);
+#endif
+		inet_pton(sfam, "2010:2020:2030:2040:2050:2060:2070:2080",
+		>sin6_addr);
+		return sizeof(*sin6);
+	default:
+		FAIL("bad family");
+	}
+fail:
+	return -1;
+}
+
+static int
+test(int sfam)
+{
+	int sfd = -1;
+	struct sockaddr_storage saddr;
+	socklen_t slen;
+
+	sfd = mksocket(sfam);
+	slen = mkserver(sfam, );
+
+	if (bind(sfd, (struct sockaddr *), slen) == -1) {
+		FAIL("bind");
+	}
+	return 0;
+fail:
+	return -1;
+}
+
+#ifndef TEST
+
+ATF_TC(bindany_4);
+ATF_TC_HEAD(bindany_4, tc)
+{
+
+	atf_tc_set_md_var(tc, "descr", "Check AF_INET bindany");
+}
+
+ATF_TC_BODY(bindany_4, tc)
+{
+	test(AF_INET);
+}
+
+ATF_TC(bindany_6);
+ATF_TC_HEAD(bindany_6, tc)
+{
+
+	atf_tc_set_md_var(tc, "descr", "Check AF_INET6 bindany");
+}
+
+ATF_TC_BODY(bindany_6, tc)
+{
+	test(AF_INET6);
+}
+

CVS commit: src/tests/net/net

2020-09-08 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue Sep  8 14:13:50 UTC 2020

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

Log Message:
Add tests for IP_BINDANY, IPV6_BINDANY


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

2020-08-28 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Aug 28 14:18:29 UTC 2020

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

Log Message:
Nix trailing whitespace.


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

2020-08-28 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Aug 28 14:18:29 UTC 2020

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

Log Message:
Nix trailing whitespace.


To generate a diff of this commit:
cvs rdiff -u -r1.23 -r1.24 src/tests/net/net/t_unix.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_unix.c
diff -u src/tests/net/net/t_unix.c:1.23 src/tests/net/net/t_unix.c:1.24
--- src/tests/net/net/t_unix.c:1.23	Fri Aug 28 13:56:29 2020
+++ src/tests/net/net/t_unix.c	Fri Aug 28 14:18:29 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_unix.c,v 1.23 2020/08/28 13:56:29 christos Exp $	*/
+/*	$NetBSD: t_unix.c,v 1.24 2020/08/28 14:18:29 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -39,7 +39,7 @@
 #define _GNU_SOURCE
 #include 
 #ifdef __RCSID
-__RCSID("$Id: t_unix.c,v 1.23 2020/08/28 13:56:29 christos Exp $");
+__RCSID("$Id: t_unix.c,v 1.24 2020/08/28 14:18:29 riastradh Exp $");
 #else
 #define getprogname() argv[0]
 #endif
@@ -208,7 +208,7 @@ check_cred(int fd, bool statit, pid_t ch
 		}
 	}
 	fflush(stdout);
-	
+
 	CHECK_EQUAL(euid, uid, s);
 	CHECK_EQUAL(egid, gid, s);
 	CHECK_EQUAL(pid, checkpid, s);
@@ -237,7 +237,7 @@ test(bool forkit, bool closeit, bool sta
 		FAIL("socket(server)");
 
 	slen = len + OF + 1;
-	
+
 	if ((sun = calloc(1, slen)) == NULL)
 		FAIL("calloc");
 
@@ -351,7 +351,7 @@ test(bool forkit, bool closeit, bool sta
 		for (size_t i = 0; i < slen - OF; i++)
 			if (sock_addr->sun_path[i] != sun->sun_path[i])
 FAIL("sock_addr.sun_path[%zu] %d != "
-"sun->sun_path[%zu] %d\n", i, 
+"sun->sun_path[%zu] %d\n", i,
 sock_addr->sun_path[i], i,
 sun->sun_path[i]);
 



CVS commit: src/tests/net/net

2020-08-28 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri Aug 28 13:56:30 UTC 2020

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

Log Message:
When running the tests with atf-run the directory we are running in is
drwx-- so when we change to a different user, we can't find the socket
we created.

Make a directory and put the socket in there. Of course now atf can't
record its results as a different user, but that is not fatal.

tc-se:FATAL ERROR: Cannot create results file '/tmp/atf-run.9vOjFd/tcr': \
Permission denied


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

2020-08-28 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri Aug 28 13:56:30 UTC 2020

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

Log Message:
When running the tests with atf-run the directory we are running in is
drwx-- so when we change to a different user, we can't find the socket
we created.

Make a directory and put the socket in there. Of course now atf can't
record its results as a different user, but that is not fatal.

tc-se:FATAL ERROR: Cannot create results file '/tmp/atf-run.9vOjFd/tcr': \
Permission denied


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 src/tests/net/net/t_unix.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_unix.c
diff -u src/tests/net/net/t_unix.c:1.22 src/tests/net/net/t_unix.c:1.23
--- src/tests/net/net/t_unix.c:1.22	Fri Aug 28 07:46:05 2020
+++ src/tests/net/net/t_unix.c	Fri Aug 28 09:56:29 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_unix.c,v 1.22 2020/08/28 11:46:05 christos Exp $	*/
+/*	$NetBSD: t_unix.c,v 1.23 2020/08/28 13:56:29 christos Exp $	*/
 
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -39,7 +39,7 @@
 #define _GNU_SOURCE
 #include 
 #ifdef __RCSID
-__RCSID("$Id: t_unix.c,v 1.22 2020/08/28 11:46:05 christos Exp $");
+__RCSID("$Id: t_unix.c,v 1.23 2020/08/28 13:56:29 christos Exp $");
 #else
 #define getprogname() argv[0]
 #endif
@@ -241,6 +241,12 @@ test(bool forkit, bool closeit, bool sta
 	if ((sun = calloc(1, slen)) == NULL)
 		FAIL("calloc");
 
+	if (mkdir("sock", 0777) == -1)
+		FAIL("mkdir");
+
+	if (chdir("sock") == -1)
+		FAIL("chdir");
+
 	memset(sun->sun_path, 'a', len);
 	sun->sun_path[len] = '\0';
 	(void)unlink(sun->sun_path);
@@ -251,6 +257,8 @@ test(bool forkit, bool closeit, bool sta
 #endif
 	sun->sun_family = AF_UNIX;
 
+	unlink(sun->sun_path);
+
 	if (bind(srvr, (struct sockaddr *)sun, sl) == -1) {
 		if (errno == EINVAL && sl >= 256) {
 			close(srvr);



CVS commit: src/tests/net/net

2020-08-28 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri Aug 28 11:46:05 UTC 2020

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

Log Message:
Remove unneeded sete{u,g}id pointed out by kre.
Remove dup unlink.


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/tests/net/net/t_unix.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_unix.c
diff -u src/tests/net/net/t_unix.c:1.21 src/tests/net/net/t_unix.c:1.22
--- src/tests/net/net/t_unix.c:1.21	Thu Aug 27 10:00:01 2020
+++ src/tests/net/net/t_unix.c	Fri Aug 28 07:46:05 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_unix.c,v 1.21 2020/08/27 14:00:01 christos Exp $	*/
+/*	$NetBSD: t_unix.c,v 1.22 2020/08/28 11:46:05 christos Exp $	*/
 
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -39,7 +39,7 @@
 #define _GNU_SOURCE
 #include 
 #ifdef __RCSID
-__RCSID("$Id: t_unix.c,v 1.21 2020/08/27 14:00:01 christos Exp $");
+__RCSID("$Id: t_unix.c,v 1.22 2020/08/28 11:46:05 christos Exp $");
 #else
 #define getprogname() argv[0]
 #endif
@@ -251,8 +251,6 @@ test(bool forkit, bool closeit, bool sta
 #endif
 	sun->sun_family = AF_UNIX;
 
-	unlink(sun->sun_path);
-
 	if (bind(srvr, (struct sockaddr *)sun, sl) == -1) {
 		if (errno == EINVAL && sl >= 256) {
 			close(srvr);
@@ -272,23 +270,19 @@ test(bool forkit, bool closeit, bool sta
 			srvrpid = getppid();
 			clntpid = getpid();
 			if (srvruid == 0) {
-clntuid = UID;
-clntgid = GID;
-setgid(clntgid);
-setegid(clntgid);
-setuid(clntuid);
-seteuid(clntuid);
+setgid(clntgid = GID);
+setuid(clntuid = UID);
 			} else {
-clntuid = srvruid;
 clntgid = srvrgid;
+clntuid = srvruid;
 			}
 			break;
 		case -1:
 			FAIL("fork");
 		default:
 			if (srvruid == 0) {
-clntuid = UID;
 clntgid = GID;
+clntuid = UID;
 			}
 			break;
 		}



CVS commit: src/tests/net/net

2020-08-28 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri Aug 28 11:46:05 UTC 2020

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

Log Message:
Remove unneeded sete{u,g}id pointed out by kre.
Remove dup unlink.


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

2020-08-27 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Aug 27 14:00:01 UTC 2020

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

Log Message:
- when running as root, create the socket under a different uid/gid to verify
  that it works properly with different users opening the socket.
- verify that linux works the same for both getpeereid() and fstat()


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/tests/net/net/t_unix.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_unix.c
diff -u src/tests/net/net/t_unix.c:1.20 src/tests/net/net/t_unix.c:1.21
--- src/tests/net/net/t_unix.c:1.20	Wed Aug 26 18:52:58 2020
+++ src/tests/net/net/t_unix.c	Thu Aug 27 10:00:01 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_unix.c,v 1.20 2020/08/26 22:52:58 christos Exp $	*/
+/*	$NetBSD: t_unix.c,v 1.21 2020/08/27 14:00:01 christos Exp $	*/
 
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -36,9 +36,10 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
+#define _GNU_SOURCE
 #include 
 #ifdef __RCSID
-__RCSID("$Id: t_unix.c,v 1.20 2020/08/26 22:52:58 christos Exp $");
+__RCSID("$Id: t_unix.c,v 1.21 2020/08/27 14:00:01 christos Exp $");
 #else
 #define getprogname() argv[0]
 #endif
@@ -58,12 +59,19 @@ __RCSID("$Id: t_unix.c,v 1.20 2020/08/26
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
 
 #include "test.h"
 
+#define UID 666
+#define GID 999
+
+uid_t srvruid, clntuid;
+gid_t srvrgid, clntgid;
+
 #define OF offsetof(struct sockaddr_un, sun_path)
 
 static void
@@ -130,28 +138,42 @@ fail:
 static int
 peercred(int s, uid_t *euid, gid_t *egid, pid_t *pid)
 {
+#ifdef SO_PEERCRED
+	/* Linux */
+# define unpcbid ucred
+# define unp_euid uid
+# define unp_egid gid
+# define unp_pid pid
+# define LOCAL_PEEREID SO_PEERCRED
+# define LEVEL SOL_SOCKET
+#else
+# define LEVEL 0
+#endif
+
 #ifdef LOCAL_PEEREID
+	/* NetBSD */
 	struct unpcbid cred;
 	socklen_t crl;
 	crl = sizeof(cred);
-	if (getsockopt(s, 0, LOCAL_PEEREID, , ) == -1)
+	if (getsockopt(s, LEVEL, LOCAL_PEEREID, , ) == -1)
 		return -1;
 	*euid = cred.unp_euid;
 	*egid = cred.unp_egid;
 	*pid = cred.unp_pid;
 	return 0;
 #else
+	/* FreeBSD */
 	*pid = -1;
 	return getpeereid(s, euid, egid);
 #endif
 }
 
 static int
-check_cred(int fd, bool statit, pid_t checkpid, const char *s)
+check_cred(int fd, bool statit, pid_t checkpid, pid_t otherpid, const char *s)
 {
 	pid_t pid;
-	uid_t euid;
-	gid_t egid;
+	uid_t euid, uid;
+	gid_t egid, gid;
 
 	if (statit) {
 		struct stat st;
@@ -167,8 +189,28 @@ check_cred(int fd, bool statit, pid_t ch
 	printf("%s(%s) euid=%jd egid=%jd pid=%jd\n",
 	statit ? "fstat" : "peercred", s,
 	(intmax_t)euid, (intmax_t)egid, (intmax_t)pid);
-	CHECK_EQUAL(euid, geteuid(), s);
-	CHECK_EQUAL(egid, getegid(), s);
+
+	if (statit) {
+		if (strcmp(s, "server") == 0) {
+			uid = srvruid;
+			gid = srvrgid;
+		} else {
+			uid = clntuid;
+			gid = clntgid;
+		}
+	} else {
+		if (checkpid != otherpid && strcmp(s, "server") == 0) {
+			uid = clntuid;
+			gid = clntgid;
+		} else {
+			uid = srvruid;
+			gid = srvrgid;
+		}
+	}
+	fflush(stdout);
+	
+	CHECK_EQUAL(euid, uid, s);
+	CHECK_EQUAL(egid, gid, s);
 	CHECK_EQUAL(pid, checkpid, s);
 	return 0;
 fail:
@@ -187,6 +229,8 @@ test(bool forkit, bool closeit, bool sta
 	socklen_t peer_addrlen;
 	struct sockaddr_un peer_addr;
 
+	srvruid = geteuid();
+	srvrgid = getegid();
 	srvrpid = clntpid = getpid();
 	srvr = socket(AF_UNIX, SOCK_STREAM, 0);
 	if (srvr == -1)
@@ -207,6 +251,8 @@ test(bool forkit, bool closeit, bool sta
 #endif
 	sun->sun_family = AF_UNIX;
 
+	unlink(sun->sun_path);
+
 	if (bind(srvr, (struct sockaddr *)sun, sl) == -1) {
 		if (errno == EINVAL && sl >= 256) {
 			close(srvr);
@@ -214,6 +260,8 @@ test(bool forkit, bool closeit, bool sta
 		}
 		FAIL("bind");
 	}
+	if (chmod(sun->sun_path, 0777) == -1)
+		FAIL("chmod `%s'", sun->sun_path);
 
 	if (listen(srvr, SOMAXCONN) == -1)
 		FAIL("listen");
@@ -223,10 +271,25 @@ test(bool forkit, bool closeit, bool sta
 		case 0:	/* child */
 			srvrpid = getppid();
 			clntpid = getpid();
+			if (srvruid == 0) {
+clntuid = UID;
+clntgid = GID;
+setgid(clntgid);
+setegid(clntgid);
+setuid(clntuid);
+seteuid(clntuid);
+			} else {
+clntuid = srvruid;
+clntgid = srvrgid;
+			}
 			break;
 		case -1:
 			FAIL("fork");
 		default:
+			if (srvruid == 0) {
+clntuid = UID;
+clntgid = GID;
+			}
 			break;
 		}
 	}
@@ -238,7 +301,7 @@ test(bool forkit, bool closeit, bool sta
 
 		if (connect(clnt, (const struct sockaddr *)sun, sl) == -1)
 			FAIL("connect");
-		check_cred(clnt, statit, srvrpid, "client");
+		check_cred(clnt, statit, srvrpid, clntpid, "client");
 
 	}
 
@@ -261,7 +324,7 @@ test(bool forkit, bool closeit, bool sta
 	}
 
 	if (srvrpid == getpid()) {
-		check_cred(acpt, statit, clntpid, "server");
+		check_cred(acpt, statit, clntpid, srvrpid, 

CVS commit: src/tests/net/net

2020-08-27 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Aug 27 14:00:01 UTC 2020

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

Log Message:
- when running as root, create the socket under a different uid/gid to verify
  that it works properly with different users opening the socket.
- verify that linux works the same for both getpeereid() and fstat()


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

2020-08-26 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed Aug 26 22:52:58 UTC 2020

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

Log Message:
Check that fstat returns the correct socket owner


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/tests/net/net/t_unix.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_unix.c
diff -u src/tests/net/net/t_unix.c:1.19 src/tests/net/net/t_unix.c:1.20
--- src/tests/net/net/t_unix.c:1.19	Mon Jul  6 12:24:06 2020
+++ src/tests/net/net/t_unix.c	Wed Aug 26 18:52:58 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_unix.c,v 1.19 2020/07/06 16:24:06 christos Exp $	*/
+/*	$NetBSD: t_unix.c,v 1.20 2020/08/26 22:52:58 christos Exp $	*/
 
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -38,7 +38,7 @@
 
 #include 
 #ifdef __RCSID
-__RCSID("$Id: t_unix.c,v 1.19 2020/07/06 16:24:06 christos Exp $");
+__RCSID("$Id: t_unix.c,v 1.20 2020/08/26 22:52:58 christos Exp $");
 #else
 #define getprogname() argv[0]
 #endif
@@ -52,6 +52,7 @@ __RCSID("$Id: t_unix.c,v 1.19 2020/07/06
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -146,13 +147,40 @@ peercred(int s, uid_t *euid, gid_t *egid
 }
 
 static int
-test(bool forkit, bool closeit, size_t len)
+check_cred(int fd, bool statit, pid_t checkpid, const char *s)
+{
+	pid_t pid;
+	uid_t euid;
+	gid_t egid;
+
+	if (statit) {
+		struct stat st;
+		if (fstat(fd, ) == -1)
+			FAIL("fstat (%s)", s);
+		euid = st.st_uid;
+		egid = st.st_gid;
+		pid = checkpid;
+	} else {
+		if (peercred(fd, , , ) == -1)
+			FAIL("peercred (%s)", s);
+	}
+	printf("%s(%s) euid=%jd egid=%jd pid=%jd\n",
+	statit ? "fstat" : "peercred", s,
+	(intmax_t)euid, (intmax_t)egid, (intmax_t)pid);
+	CHECK_EQUAL(euid, geteuid(), s);
+	CHECK_EQUAL(egid, getegid(), s);
+	CHECK_EQUAL(pid, checkpid, s);
+	return 0;
+fail:
+	return -1;
+}
+
+static int
+test(bool forkit, bool closeit, bool statit, size_t len)
 {
 	size_t slen;
 	socklen_t sl;
 	int srvr = -1, clnt = -1, acpt = -1;
-	uid_t euid;
-	gid_t egid;
 	pid_t srvrpid, clntpid;
 	struct sockaddr_un *sock_addr = NULL, *sun = NULL;
 	socklen_t sock_addrlen;
@@ -204,26 +232,18 @@ test(bool forkit, bool closeit, size_t l
 	}
 
 	if (clntpid == getpid()) {
-		pid_t pid = srvrpid;
 		clnt = socket(AF_UNIX, SOCK_STREAM, 0);
 		if (clnt == -1)
 			FAIL("socket(client)");
 
 		if (connect(clnt, (const struct sockaddr *)sun, sl) == -1)
 			FAIL("connect");
+		check_cred(clnt, statit, srvrpid, "client");
 
-		if (peercred(clnt, , , ) == -1)
-			FAIL("peercred (client)");
-		printf("peercred(client) euid=%jd egid=%jd pid=%jd\n",
-			(intmax_t)euid, (intmax_t)egid, (intmax_t)pid);
-		CHECK_EQUAL(euid, geteuid(), "client");
-		CHECK_EQUAL(egid, getegid(), "client");
-		CHECK_EQUAL(pid, srvrpid, "client");
 	}
 
 	if (srvrpid == getpid()) {
 		acpt = acc(srvr);
-
 		peer_addrlen = sizeof(peer_addr);
 		memset(_addr, 0, sizeof(peer_addr));
 		if (getpeername(acpt, (struct sockaddr *)_addr,
@@ -241,15 +261,7 @@ test(bool forkit, bool closeit, size_t l
 	}
 
 	if (srvrpid == getpid()) {
-		pid_t pid = clntpid;
-		if (peercred(acpt, , , ) == -1)
-			FAIL("peercred (server)");
-		printf("peercred(server) euid=%jd egid=%jd pid=%jd\n",
-			(intmax_t)euid, (intmax_t)egid, (intmax_t)pid);
-		CHECK_EQUAL(euid, geteuid(), "server");
-		CHECK_EQUAL(egid, getegid(), "server");
-		CHECK_EQUAL(pid, clntpid, "server");
-
+		check_cred(acpt, statit, clntpid, "server");
 		if ((sock_addr = calloc(1, slen)) == NULL)
 			FAIL("calloc");
 		sock_addrlen = slen;
@@ -322,8 +334,8 @@ ATF_TC_HEAD(sockaddr_un_len_exceed, tc)
 
 ATF_TC_BODY(sockaddr_un_len_exceed, tc)
 {
-	ATF_REQUIRE_MSG(test(false, false, 254) == -1,
-	"test(false, false, 254): %s", strerror(errno));
+	ATF_REQUIRE_MSG(test(false, false, false, 254) == -1,
+	"test(false, false, false, 254): %s", strerror(errno));
 }
 
 ATF_TC(sockaddr_un_len_max);
@@ -337,8 +349,8 @@ ATF_TC_HEAD(sockaddr_un_len_max, tc)
 
 ATF_TC_BODY(sockaddr_un_len_max, tc)
 {
-	ATF_REQUIRE_MSG(test(false, false, 253) == 0,
-	"test(false, false, 253): %s", strerror(errno));
+	ATF_REQUIRE_MSG(test(false, false, false, 253) == 0,
+	"test(false, false, false, 253): %s", strerror(errno));
 }
 
 ATF_TC(sockaddr_un_closed);
@@ -351,8 +363,8 @@ ATF_TC_HEAD(sockaddr_un_closed, tc)
 
 ATF_TC_BODY(sockaddr_un_closed, tc)
 {
-	ATF_REQUIRE_MSG(test(false, true, 100) == 0,
-	"test(false, true, 100): %s", strerror(errno));
+	ATF_REQUIRE_MSG(test(false, true, false, 100) == 0,
+	"test(false, true, false, 100): %s", strerror(errno));
 }
 
 ATF_TC(sockaddr_un_local_peereid);
@@ -365,8 +377,22 @@ ATF_TC_HEAD(sockaddr_un_local_peereid, t
 
 ATF_TC_BODY(sockaddr_un_local_peereid, tc)
 {
-	ATF_REQUIRE_MSG(test(true, true, 100) == 0,
-	"test(true, true, 100): %s", strerror(errno));
+	ATF_REQUIRE_MSG(test(true, true, false, 100) == 0,
+	"test(true, 

CVS commit: src/tests/net/net

2020-08-26 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed Aug 26 22:52:58 UTC 2020

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

Log Message:
Check that fstat returns the correct socket owner


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

2020-07-06 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Jul  6 18:45:26 UTC 2020

Modified Files:
src/tests/net/net: Makefile
Added Files:
src/tests/net/net: t_mapped.c

Log Message:
add a test for v4 mapped addresses


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

2020-07-06 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Jul  6 18:45:26 UTC 2020

Modified Files:
src/tests/net/net: Makefile
Added Files:
src/tests/net/net: t_mapped.c

Log Message:
add a test for v4 mapped addresses


To generate a diff of this commit:
cvs rdiff -u -r1.23 -r1.24 src/tests/net/net/Makefile
cvs rdiff -u -r0 -r1.1 src/tests/net/net/t_mapped.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/Makefile
diff -u src/tests/net/net/Makefile:1.23 src/tests/net/net/Makefile:1.24
--- src/tests/net/net/Makefile:1.23	Sun Mar  1 13:08:16 2020
+++ src/tests/net/net/Makefile	Mon Jul  6 14:45:25 2020
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.23 2020/03/01 18:08:16 christos Exp $
+# $NetBSD: Makefile,v 1.24 2020/07/06 18:45:25 christos Exp $
 #
 
 .include 
@@ -6,6 +6,7 @@
 TESTSDIR=	${TESTSBASE}/net/net
 
 TESTS_C=	t_unix
+TESTS_C+=	t_mapped
 TESTS_C+=	t_tcp
 TESTS_C+=	t_udp
 TESTS_C+=	t_pktinfo
@@ -26,4 +27,6 @@ LDADD.t_pktinfo_send+=	${LIBRUMPBASE}
 LDADD.t_raw+=	-lrumpnet_local -lrumpnet_netinet -lrumpnet_net
 LDADD.t_raw+=	-lrumpnet ${LIBRUMPBASE}
 
+LDADD.t_mapped+=	-lutil
+
 .include 

Added files:

Index: src/tests/net/net/t_mapped.c
diff -u /dev/null src/tests/net/net/t_mapped.c:1.1
--- /dev/null	Mon Jul  6 14:45:26 2020
+++ src/tests/net/net/t_mapped.c	Mon Jul  6 14:45:25 2020
@@ -0,0 +1,320 @@
+/*	$NetBSD: t_mapped.c,v 1.1 2020/07/06 18:45:25 christos Exp $	*/
+
+/*-
+ * Copyright (c) 2020 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Christos Zoulas.
+ *
+ * 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.
+ */
+
+#define _GNU_SOURCE
+
+#include 
+#ifdef __RCSID
+__RCSID("$Id: t_mapped.c,v 1.1 2020/07/06 18:45:25 christos Exp $");
+#endif
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "util.h"
+
+#include "test.h"
+
+static char mymsg[] = "hi mom!";
+
+static void
+print(const char *msg, const struct sockaddr *addr)
+{
+	char buf[1024];
+
+	sockaddr_snprintf(buf, sizeof(buf), "%a:%p", addr);
+	printf("%s: %s\n", msg, buf);
+}
+
+static int
+mksocket(int sfam)
+{
+	int fd = socket(sfam, SOCK_STREAM, 0);
+	if (fd ==  -1)
+		FAIL("socket");
+	if (sfam != AF_INET6)
+		return fd;
+	int f = 0;
+#if 0
+	/* crashes the kernel, should not be allowed kernel only? */
+	if (setsockopt(fd, IPPROTO_IPV6, 24 /* IPV6_2292RTHDR */,
+	, sizeof(f)) == -1)
+		FAIL("setsockopt");
+#endif
+	if (setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, , sizeof(f)) == -1)
+		FAIL("setsockopt");
+	return fd;
+fail:
+	return -1;
+}
+
+static socklen_t
+mkserver(int sfam, struct sockaddr_storage *ss)
+{
+	struct sockaddr_in *sin;
+	struct sockaddr_in6 *sin6;
+
+	memset(ss, 0, sizeof(*ss));
+	ss->ss_family = sfam;
+	switch (sfam) {
+	case AF_INET:
+		sin = (struct sockaddr_in *)ss;
+		sin->sin_port = htons(12345);
+#ifdef BSD4_4
+		sin->sin_len = sizeof(*sin);
+#endif
+		return sizeof(*sin);
+	case AF_INET6:
+		sin6 = (struct sockaddr_in6 *)ss;
+		sin6->sin6_port = htons(12345);
+#ifdef BSD4_4
+		sin6->sin6_len = sizeof(*sin6);
+#endif
+		return sizeof(*sin6);
+	default:
+		FAIL("bad family");
+	}
+fail:
+	return -1;
+}
+
+#if 0
+static const struct in6_addr in6addr_loopback = IN6ADDR_LOOPBACK_INIT;
+#endif
+static socklen_t
+mkclient(int sfam, struct sockaddr_storage *ss)
+{
+	struct sockaddr_in *sin;
+	struct sockaddr_in6 *sin6;
+
+	memset(ss, 0, sizeof(*ss));
+	ss->ss_family = sfam;
+	switch (sfam) {
+	case AF_INET:
+		sin = 

CVS commit: src/tests/net/net

2020-07-06 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Jul  6 16:24:06 UTC 2020

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

Log Message:
don't open the socket twice.


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/tests/net/net/t_unix.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_unix.c
diff -u src/tests/net/net/t_unix.c:1.18 src/tests/net/net/t_unix.c:1.19
--- src/tests/net/net/t_unix.c:1.18	Sat Apr 13 21:45:30 2019
+++ src/tests/net/net/t_unix.c	Mon Jul  6 12:24:06 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_unix.c,v 1.18 2019/04/14 01:45:30 christos Exp $	*/
+/*	$NetBSD: t_unix.c,v 1.19 2020/07/06 16:24:06 christos Exp $	*/
 
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -38,7 +38,7 @@
 
 #include 
 #ifdef __RCSID
-__RCSID("$Id: t_unix.c,v 1.18 2019/04/14 01:45:30 christos Exp $");
+__RCSID("$Id: t_unix.c,v 1.19 2020/07/06 16:24:06 christos Exp $");
 #else
 #define getprogname() argv[0]
 #endif
@@ -162,17 +162,13 @@ test(bool forkit, bool closeit, size_t l
 	srvrpid = clntpid = getpid();
 	srvr = socket(AF_UNIX, SOCK_STREAM, 0);
 	if (srvr == -1)
-		FAIL("socket(srvrer)");
+		FAIL("socket(server)");
 
 	slen = len + OF + 1;
 	
 	if ((sun = calloc(1, slen)) == NULL)
 		FAIL("calloc");
 
-	srvr = socket(AF_UNIX, SOCK_STREAM, 0);
-	if (srvr == -1)
-		FAIL("socket");
-
 	memset(sun->sun_path, 'a', len);
 	sun->sun_path[len] = '\0';
 	(void)unlink(sun->sun_path);



CVS commit: src/tests/net/net

2020-07-06 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Jul  6 16:24:06 UTC 2020

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

Log Message:
don't open the socket twice.


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

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
 
 }



CVS commit: src/tests/net/net

2019-04-13 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Apr 14 01:45:30 UTC 2019

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

Log Message:
ifix uninialized pid


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/tests/net/net/t_unix.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_unix.c
diff -u src/tests/net/net/t_unix.c:1.17 src/tests/net/net/t_unix.c:1.18
--- src/tests/net/net/t_unix.c:1.17	Sat Feb 17 15:16:18 2018
+++ src/tests/net/net/t_unix.c	Sat Apr 13 21:45:30 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_unix.c,v 1.17 2018/02/17 20:16:18 christos Exp $	*/
+/*	$NetBSD: t_unix.c,v 1.18 2019/04/14 01:45:30 christos Exp $	*/
 
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -38,7 +38,7 @@
 
 #include 
 #ifdef __RCSID
-__RCSID("$Id: t_unix.c,v 1.17 2018/02/17 20:16:18 christos Exp $");
+__RCSID("$Id: t_unix.c,v 1.18 2019/04/14 01:45:30 christos Exp $");
 #else
 #define getprogname() argv[0]
 #endif
@@ -140,6 +140,7 @@ peercred(int s, uid_t *euid, gid_t *egid
 	*pid = cred.unp_pid;
 	return 0;
 #else
+	*pid = -1;
 	return getpeereid(s, euid, egid);
 #endif
 }



CVS commit: src/tests/net/net

2019-04-13 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Apr 14 01:45:30 UTC 2019

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

Log Message:
ifix uninialized pid


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

2018-04-26 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Thu Apr 26 06:23:33 UTC 2018

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

Log Message:
Remove ping6_opts_hops, "-g" does not exist anymore (RH0 removed).


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

2018-04-26 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Thu Apr 26 06:23:33 UTC 2018

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

Log Message:
Remove ping6_opts_hops, "-g" does not exist anymore (RH0 removed).


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/tests/net/net/t_ping6_opts.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_ping6_opts.sh
diff -u src/tests/net/net/t_ping6_opts.sh:1.8 src/tests/net/net/t_ping6_opts.sh:1.9
--- src/tests/net/net/t_ping6_opts.sh:1.8	Fri Nov 25 08:51:17 2016
+++ src/tests/net/net/t_ping6_opts.sh	Thu Apr 26 06:23:33 2018
@@ -1,4 +1,4 @@
-#	$NetBSD: t_ping6_opts.sh,v 1.8 2016/11/25 08:51:17 ozaki-r Exp $
+#	$NetBSD: t_ping6_opts.sh,v 1.9 2018/04/26 06:23:33 maxv Exp $
 #
 # Copyright (c) 2016 Internet Initiative Japan Inc.
 # All rights reserved.
@@ -292,89 +292,10 @@ ping6_opts_gateway_cleanup()
 	cleanup
 }
 
-atf_test_case ping6_opts_hops cleanup
-ping6_opts_hops_head()
-{
-
-	atf_set "descr" "tests of ping6 hops (Type 0 Routing Header)"
-	atf_set "require.progs" "rump_server"
-}
-
-ping6_opts_hops_body()
-{
-	local my_macaddr=
-	local gw_shmif0_macaddr=
-	local gw_shmif2_macaddr=
-
-	setup6
-	setup_forwarding6
-
-	my_macaddr=$(get_macaddr ${SOCKSRC} shmif0)
-	gw_shmif0_macaddr=$(get_macaddr ${SOCKFWD} shmif0)
-
-	export RUMP_SERVER=$SOCKSRC
-	atf_check -s exit:0 -o ignore rump.ping6 -n -c 1 -X $TIMEOUT $IP6DST
-	check_echo_request_pkt_with_macaddr \
-	$my_macaddr $gw_shmif0_macaddr $IP6SRC $IP6DST
-
-	rump_server_add_iface $SOCKFWD shmif2 $BUS_SRCGW
-	export RUMP_SERVER=$SOCKFWD
-	atf_check -s exit:0 rump.ifconfig shmif2 inet6 $IP6SRCGW2
-	atf_check -s exit:0 rump.ifconfig -w 10
-	gw_shmif2_macaddr=$(get_macaddr ${SOCKFWD} shmif2)
-
-	export RUMP_SERVER=$SOCKSRC
-	atf_check -s exit:0 -o ignore rump.ping6 -n -c 1 -X $TIMEOUT $IP6DST
-	check_echo_request_pkt_with_macaddr \
-	$my_macaddr $gw_shmif0_macaddr $IP6SRC $IP6DST
-
-	# ping6 hops
-
-	# ping6 fails expectedly because the kernel doesn't support
-	# to receive packets with type 0 routing headers, but we can
-	# check whether a sent packet is correct.
-	atf_check -s not-exit:0 -o ignore rump.ping6 -n -c 1 -X $TIMEOUT \
-	$IP6SRCGW $IP6DST
-	check_echo_request_pkt_with_macaddr_and_rthdr0 \
-	$my_macaddr $gw_shmif0_macaddr $IP6SRC $IP6SRCGW $IP6DST
-
-	atf_check -s not-exit:0 -o ignore rump.ping6 -n -c 1 -X $TIMEOUT \
-	$IP6SRCGW2 $IP6DST
-	check_echo_request_pkt_with_macaddr_and_rthdr0 \
-	$my_macaddr $gw_shmif2_macaddr $IP6SRC $IP6SRCGW2 $IP6DST
-
-	# ping6 -g  hops
-	atf_check -s not-exit:0 -o ignore rump.ping6 -n -c 1 -X $TIMEOUT \
-	-g $IP6SRCGW $IP6SRCGW $IP6DST
-	check_echo_request_pkt_with_macaddr_and_rthdr0 \
-	$my_macaddr $gw_shmif0_macaddr $IP6SRC $IP6SRCGW $IP6DST
-
-	atf_check -s not-exit:0 -o ignore rump.ping6 -n -c 1 -X $TIMEOUT \
-	-g $IP6SRCGW2 $IP6SRCGW2 $IP6DST
-	check_echo_request_pkt_with_macaddr_and_rthdr0 \
-	$my_macaddr $gw_shmif2_macaddr $IP6SRC $IP6SRCGW2 $IP6DST
-
-	# ping6 -g  hops, but different nexthops (is it valid?)
-	atf_check -s not-exit:0 -o ignore rump.ping6 -n -c 1 -X $TIMEOUT \
-	-g $IP6SRCGW $IP6SRCGW2 $IP6DST
-	check_echo_request_pkt_with_macaddr_and_rthdr0 \
-	$my_macaddr $gw_shmif0_macaddr $IP6SRC $IP6SRCGW2 $IP6DST
-
-	rump_server_destroy_ifaces
-}
-
-ping6_opts_hops_cleanup()
-{
-
-	$DEBUG && dump
-	cleanup
-}
-
 atf_init_test_cases()
 {
 
 	atf_add_test_case ping6_opts_sourceaddr
 	atf_add_test_case ping6_opts_interface
 	atf_add_test_case ping6_opts_gateway
-	atf_add_test_case ping6_opts_hops
 }



CVS commit: src/tests/net/net

2018-02-17 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Feb 17 20:16:19 UTC 2018

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

Log Message:
make it compile again for those who don't have LOCAL_PEERCRED


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

2018-02-17 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Feb 17 20:16:19 UTC 2018

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

Log Message:
make it compile again for those who don't have LOCAL_PEERCRED


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/tests/net/net/t_unix.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_unix.c
diff -u src/tests/net/net/t_unix.c:1.16 src/tests/net/net/t_unix.c:1.17
--- src/tests/net/net/t_unix.c:1.16	Sat Feb 17 11:34:18 2018
+++ src/tests/net/net/t_unix.c	Sat Feb 17 15:16:18 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_unix.c,v 1.16 2018/02/17 16:34:18 christos Exp $	*/
+/*	$NetBSD: t_unix.c,v 1.17 2018/02/17 20:16:18 christos Exp $	*/
 
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -38,7 +38,7 @@
 
 #include 
 #ifdef __RCSID
-__RCSID("$Id: t_unix.c,v 1.16 2018/02/17 16:34:18 christos Exp $");
+__RCSID("$Id: t_unix.c,v 1.17 2018/02/17 20:16:18 christos Exp $");
 #else
 #define getprogname() argv[0]
 #endif
@@ -127,17 +127,36 @@ fail:
 }
 
 static int
+peercred(int s, uid_t *euid, gid_t *egid, pid_t *pid)
+{
+#ifdef LOCAL_PEEREID
+	struct unpcbid cred;
+	socklen_t crl;
+	crl = sizeof(cred);
+	if (getsockopt(s, 0, LOCAL_PEEREID, , ) == -1)
+		return -1;
+	*euid = cred.unp_euid;
+	*egid = cred.unp_egid;
+	*pid = cred.unp_pid;
+	return 0;
+#else
+	return getpeereid(s, euid, egid);
+#endif
+}
+
+static int
 test(bool forkit, bool closeit, size_t len)
 {
 	size_t slen;
-	socklen_t sl, crl;
+	socklen_t sl;
 	int srvr = -1, clnt = -1, acpt = -1;
+	uid_t euid;
+	gid_t egid;
 	pid_t srvrpid, clntpid;
 	struct sockaddr_un *sock_addr = NULL, *sun = NULL;
 	socklen_t sock_addrlen;
 	socklen_t peer_addrlen;
 	struct sockaddr_un peer_addr;
-	struct unpcbid cred;
 
 	srvrpid = clntpid = getpid();
 	srvr = socket(AF_UNIX, SOCK_STREAM, 0);
@@ -188,6 +207,7 @@ test(bool forkit, bool closeit, size_t l
 	}
 
 	if (clntpid == getpid()) {
+		pid_t pid = srvrpid;
 		clnt = socket(AF_UNIX, SOCK_STREAM, 0);
 		if (clnt == -1)
 			FAIL("socket(client)");
@@ -195,12 +215,13 @@ test(bool forkit, bool closeit, size_t l
 		if (connect(clnt, (const struct sockaddr *)sun, sl) == -1)
 			FAIL("connect");
 
-		crl = sizeof(cred);
-		if (getsockopt(clnt, 0, LOCAL_PEEREID, , ) == -1)
-			FAIL("getsockopt()");
-		CHECK_EQUAL(cred.unp_euid, geteuid(), "client");
-		CHECK_EQUAL(cred.unp_egid, getegid(), "client");
-		CHECK_EQUAL(cred.unp_pid, srvrpid, "client");
+		if (peercred(clnt, , , ) == -1)
+			FAIL("peercred (client)");
+		printf("peercred(client) euid=%jd egid=%jd pid=%jd\n",
+			(intmax_t)euid, (intmax_t)egid, (intmax_t)pid);
+		CHECK_EQUAL(euid, geteuid(), "client");
+		CHECK_EQUAL(egid, getegid(), "client");
+		CHECK_EQUAL(pid, srvrpid, "client");
 	}
 
 	if (srvrpid == getpid()) {
@@ -223,12 +244,14 @@ test(bool forkit, bool closeit, size_t l
 	}
 
 	if (srvrpid == getpid()) {
-		crl = sizeof(cred);
-		if (getsockopt(acpt, 0, LOCAL_PEEREID, , ) == -1)
-			FAIL("getsockopt()");
-		CHECK_EQUAL(cred.unp_euid, geteuid(), "server");
-		CHECK_EQUAL(cred.unp_egid, getegid(), "server");
-		CHECK_EQUAL(cred.unp_pid, clntpid, "client");
+		pid_t pid = clntpid;
+		if (peercred(acpt, , , ) == -1)
+			FAIL("peercred (server)");
+		printf("peercred(server) euid=%jd egid=%jd pid=%jd\n",
+			(intmax_t)euid, (intmax_t)egid, (intmax_t)pid);
+		CHECK_EQUAL(euid, geteuid(), "server");
+		CHECK_EQUAL(egid, getegid(), "server");
+		CHECK_EQUAL(pid, clntpid, "server");
 
 		if ((sock_addr = calloc(1, slen)) == NULL)
 			FAIL("calloc");



CVS commit: src/tests/net/net

2018-02-17 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Feb 17 16:34:18 UTC 2018

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

Log Message:
Add a test demonstrating thst LOCAL_PEEREID is busted.


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

2018-02-17 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Feb 17 16:34:18 UTC 2018

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

Log Message:
Add a test demonstrating thst LOCAL_PEEREID is busted.


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/tests/net/net/t_unix.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_unix.c
diff -u src/tests/net/net/t_unix.c:1.15 src/tests/net/net/t_unix.c:1.16
--- src/tests/net/net/t_unix.c:1.15	Fri Feb 16 17:17:17 2018
+++ src/tests/net/net/t_unix.c	Sat Feb 17 11:34:18 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_unix.c,v 1.15 2018/02/16 22:17:17 christos Exp $	*/
+/*	$NetBSD: t_unix.c,v 1.16 2018/02/17 16:34:18 christos Exp $	*/
 
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -38,7 +38,7 @@
 
 #include 
 #ifdef __RCSID
-__RCSID("$Id: t_unix.c,v 1.15 2018/02/16 22:17:17 christos Exp $");
+__RCSID("$Id: t_unix.c,v 1.16 2018/02/17 16:34:18 christos Exp $");
 #else
 #define getprogname() argv[0]
 #endif
@@ -51,6 +51,7 @@ __RCSID("$Id: t_unix.c,v 1.15 2018/02/16
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -126,18 +127,19 @@ fail:
 }
 
 static int
-test(bool closeit, size_t len)
+test(bool forkit, bool closeit, size_t len)
 {
 	size_t slen;
-	socklen_t sl;
+	socklen_t sl, crl;
 	int srvr = -1, clnt = -1, acpt = -1;
-	uid_t euid;
-	gid_t egid;
+	pid_t srvrpid, clntpid;
 	struct sockaddr_un *sock_addr = NULL, *sun = NULL;
 	socklen_t sock_addrlen;
 	socklen_t peer_addrlen;
 	struct sockaddr_un peer_addr;
+	struct unpcbid cred;
 
+	srvrpid = clntpid = getpid();
 	srvr = socket(AF_UNIX, SOCK_STREAM, 0);
 	if (srvr == -1)
 		FAIL("socket(srvrer)");
@@ -172,70 +174,99 @@ test(bool closeit, size_t len)
 	if (listen(srvr, SOMAXCONN) == -1)
 		FAIL("listen");
 
-	clnt = socket(AF_UNIX, SOCK_STREAM, 0);
-	if (clnt == -1)
-		FAIL("socket(client)");
-
-	if (connect(clnt, (const struct sockaddr *)sun, sl) == -1)
-		FAIL("connect");
-
-	if (getpeereid(clnt, , ) == -1)
-		FAIL("getpeereid(clnt)");
-	CHECK_EQUAL(euid, geteuid(), "client");
-	CHECK_EQUAL(egid, getegid(), "client");
-
-
-	acpt = acc(srvr);
-
-	peer_addrlen = sizeof(peer_addr);
-	memset(_addr, 0, sizeof(peer_addr));
-	if (getpeername(acpt, (struct sockaddr *)_addr,
-	_addrlen) == -1)
-		FAIL("getpeername");
-	print("peer", _addr, peer_addrlen);
-
-	if (closeit) {
-		if (close(clnt) == -1)
-			FAIL("close");
-		clnt = -1;
+	if (forkit) {
+		switch (clntpid = fork()) {
+		case 0:	/* child */
+			srvrpid = getppid();
+			clntpid = getpid();
+			break;
+		case -1:
+			FAIL("fork");
+		default:
+			break;
+		}
 	}
 
-	/* This is not symmetric? It is supposed to work! */
-	if (getpeereid(acpt, , ) == -1)
-		FAIL("getpeereid(srvr)");
-	CHECK_EQUAL(euid, geteuid(), "server");
-	CHECK_EQUAL(egid, getegid(), "server");
+	if (clntpid == getpid()) {
+		clnt = socket(AF_UNIX, SOCK_STREAM, 0);
+		if (clnt == -1)
+			FAIL("socket(client)");
+
+		if (connect(clnt, (const struct sockaddr *)sun, sl) == -1)
+			FAIL("connect");
+
+		crl = sizeof(cred);
+		if (getsockopt(clnt, 0, LOCAL_PEEREID, , ) == -1)
+			FAIL("getsockopt()");
+		CHECK_EQUAL(cred.unp_euid, geteuid(), "client");
+		CHECK_EQUAL(cred.unp_egid, getegid(), "client");
+		CHECK_EQUAL(cred.unp_pid, srvrpid, "client");
+	}
 
-	if ((sock_addr = calloc(1, slen)) == NULL)
-		FAIL("calloc");
-	sock_addrlen = slen;
-	if (getsockname(srvr, (struct sockaddr *)sock_addr, _addrlen)
-	== -1)
-		FAIL("getsockname");
-	print("sock", sock_addr, sock_addrlen);
-
-	if (sock_addr->sun_family != AF_UNIX)
-		FAIL("sock_addr->sun_family %d != AF_UNIX",
-		sock_addr->sun_family);
-
-	len += OF;
-	if (sock_addrlen LX != len)
-		FAIL("sock_addr_len %zu != %zu", (size_t)sock_addrlen, len);
+	if (srvrpid == getpid()) {
+		acpt = acc(srvr);
+
+		peer_addrlen = sizeof(peer_addr);
+		memset(_addr, 0, sizeof(peer_addr));
+		if (getpeername(acpt, (struct sockaddr *)_addr,
+		_addrlen) == -1)
+			FAIL("getpeername");
+		print("peer", _addr, peer_addrlen);
+	}
+
+	if (clntpid == getpid()) {
+		if (closeit) {
+			if (close(clnt) == -1)
+FAIL("close");
+			clnt = -1;
+		}
+	}
+
+	if (srvrpid == getpid()) {
+		crl = sizeof(cred);
+		if (getsockopt(acpt, 0, LOCAL_PEEREID, , ) == -1)
+			FAIL("getsockopt()");
+		CHECK_EQUAL(cred.unp_euid, geteuid(), "server");
+		CHECK_EQUAL(cred.unp_egid, getegid(), "server");
+		CHECK_EQUAL(cred.unp_pid, clntpid, "client");
+
+		if ((sock_addr = calloc(1, slen)) == NULL)
+			FAIL("calloc");
+		sock_addrlen = slen;
+		if (getsockname(srvr, (struct sockaddr *)sock_addr,
+		_addrlen) == -1)
+			FAIL("getsockname");
+		print("sock", sock_addr, sock_addrlen);
+
+		if (sock_addr->sun_family != AF_UNIX)
+			FAIL("sock_addr->sun_family %d != AF_UNIX",
+			sock_addr->sun_family);
+
+		len += OF;
+		if (sock_addrlen LX != len)
+			FAIL("sock_addr_len %zu != %zu", (size_t)sock_addrlen,
+			 

CVS commit: src/tests/net/net

2018-02-16 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Feb 17 00:28:47 UTC 2018

Modified Files:
src/tests/net/net: test.h

Log Message:
remove clause 3, 4.


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

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/test.h
diff -u src/tests/net/net/test.h:1.1 src/tests/net/net/test.h:1.2
--- src/tests/net/net/test.h:1.1	Fri Feb 16 11:23:15 2018
+++ src/tests/net/net/test.h	Fri Feb 16 19:28:47 2018
@@ -13,13 +13,6 @@
  * 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.
- * 3. All advertising materials mentioning features or use of this software
- *must display the following acknowledgement:
- *This product includes software developed by the NetBSD
- *Foundation, Inc. and its contributors.
- * 4. Neither the name of The NetBSD Foundation nor the names of its
- *contributors may be used to endorse or promote products derived
- *from this software without specific prior written permission.
  *
  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED



CVS commit: src/tests/net/net

2018-02-16 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Feb 17 00:28:47 UTC 2018

Modified Files:
src/tests/net/net: test.h

Log Message:
remove clause 3, 4.


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

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

2018-02-16 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri Feb 16 22:20:18 UTC 2018

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

Log Message:
Use the same variable name for the accepted socket as with the AF_LOCAL test.
Call getpeereid on the accepted socket.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 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

2018-02-16 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri Feb 16 22:20:18 UTC 2018

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

Log Message:
Use the same variable name for the accepted socket as with the AF_LOCAL test.
Call getpeereid on the accepted socket.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 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.9 src/tests/net/net/t_tcp.c:1.10
--- src/tests/net/net/t_tcp.c:1.9	Fri Feb 16 14:24:16 2018
+++ src/tests/net/net/t_tcp.c	Fri Feb 16 17:20:18 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_tcp.c,v 1.9 2018/02/16 19:24:16 christos Exp $	*/
+/*	$NetBSD: t_tcp.c,v 1.10 2018/02/16 22:20:18 christos Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
 
 #include 
 #ifdef __RCSID
-__RCSID("$Id: t_tcp.c,v 1.9 2018/02/16 19:24:16 christos Exp $");
+__RCSID("$Id: t_tcp.c,v 1.10 2018/02/16 22:20:18 christos Exp $");
 #endif
 
 /* Example code. Should block; does with accept not paccept. */
@@ -71,7 +71,7 @@ static void 
 paccept_block(sa_family_t sfamily, sa_family_t cfamily,
 bool pacceptblock, bool fcntlblock)
 {
-	int srvr = -1, clnt = -1, as = -1;
+	int srvr = -1, clnt = -1, acpt = -1;
 	int ok, fl;
 	int count = 5;
 	ssize_t n;
@@ -154,7 +154,7 @@ paccept_block(sa_family_t sfamily, sa_fa
 	ok = connect(clnt, (struct sockaddr *) , addrlen);
 	if (ok != -1 || errno != EINPROGRESS)
 		FAIL("expected connect to fail");
-	as = paccept(srvr, NULL, NULL, NULL, pacceptblock ? 0 : SOCK_NONBLOCK);
+	acpt = paccept(srvr, NULL, NULL, NULL, pacceptblock ? 0 : SOCK_NONBLOCK);
 again:
 	ok = connect(clnt, (struct sockaddr *) , addrlen);
 	if (ok == -1 && errno != EISCONN) {
@@ -182,29 +182,30 @@ again:
 		FAIL("fnctl setfl");
 #endif
 
+	if (acpt == -1) {		/* not true under NetBSD */
+		acpt = paccept(srvr, NULL, NULL, NULL,
+		pacceptblock ? 0 : SOCK_NONBLOCK);
+		if (acpt == -1)
+			FAIL("paccept");
+	}
 	/* This is supposed to only work on Unix sockets but returns garbage */
 	if (getpeereid(clnt, , ) != -1)
 		FAIL("getpeereid(clnt)");
 	/* This is supposed to only work on Unix sockets but returns garbage */
-	if (getpeereid(srvr, , ) != -1)
+	if (getpeereid(acpt, , ) != -1)
 		FAIL("getpeereid(srvr)");
 
-	if (as == -1) {		/* not true under NetBSD */
-		as = paccept(srvr, NULL, NULL, NULL, pacceptblock ? 0 : SOCK_NONBLOCK);
-		if (as == -1)
-			FAIL("paccept");
-	}
 	if (fcntlblock) {
-		fl = fcntl(as, F_GETFL, 0);
+		fl = fcntl(acpt, F_GETFL, 0);
 		if (fl == -1)
 			FAIL("fnctl");
 		if (fl != (O_RDWR|O_NONBLOCK))
 			FAIL("fl 0x%x != 0x%x\n", fl, O_RDWR|O_NONBLOCK);
-		ok = fcntl(as, F_SETFL, fl & ~O_NONBLOCK);
+		ok = fcntl(acpt, F_SETFL, fl & ~O_NONBLOCK);
 		if (ok == -1)
 			FAIL("fnctl setfl");
 
-		fl = fcntl(as, F_GETFL, 0);
+		fl = fcntl(acpt, F_GETFL, 0);
 		if (fl & O_NONBLOCK)
 			FAIL("fl non blocking after reset");
 	}
@@ -213,7 +214,7 @@ again:
 	sigemptyset(_mask);
 	sigaction(SIGALRM, , NULL);
 	alarm(1);
-	n = read(as, buf, 10);
+	n = read(acpt, buf, 10);
 
 	if (pacceptblock || fcntlblock) {
 		if (n == -1 && errno != EINTR)
@@ -226,7 +227,7 @@ again:
 fail:
 	close(srvr);
 	close(clnt);
-	close(as);
+	close(acpt);
 }
 
 #ifndef TEST



CVS commit: src/tests/net/net

2018-02-16 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri Feb 16 22:17:17 UTC 2018

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

Log Message:
make sure we call getpeername on the accepted socket!


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/tests/net/net/t_unix.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_unix.c
diff -u src/tests/net/net/t_unix.c:1.14 src/tests/net/net/t_unix.c:1.15
--- src/tests/net/net/t_unix.c:1.14	Fri Feb 16 11:30:20 2018
+++ src/tests/net/net/t_unix.c	Fri Feb 16 17:17:17 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_unix.c,v 1.14 2018/02/16 16:30:20 christos Exp $	*/
+/*	$NetBSD: t_unix.c,v 1.15 2018/02/16 22:17:17 christos Exp $	*/
 
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -38,7 +38,7 @@
 
 #include 
 #ifdef __RCSID
-__RCSID("$Id: t_unix.c,v 1.14 2018/02/16 16:30:20 christos Exp $");
+__RCSID("$Id: t_unix.c,v 1.15 2018/02/16 22:17:17 christos Exp $");
 #else
 #define getprogname() argv[0]
 #endif
@@ -135,6 +135,8 @@ test(bool closeit, size_t len)
 	gid_t egid;
 	struct sockaddr_un *sock_addr = NULL, *sun = NULL;
 	socklen_t sock_addrlen;
+	socklen_t peer_addrlen;
+	struct sockaddr_un peer_addr;
 
 	srvr = socket(AF_UNIX, SOCK_STREAM, 0);
 	if (srvr == -1)
@@ -182,13 +184,15 @@ test(bool closeit, size_t len)
 	CHECK_EQUAL(euid, geteuid(), "client");
 	CHECK_EQUAL(egid, getegid(), "client");
 
-#if 0
-	/* This is not symmetric? It is supposed to work! */
-	if (getpeereid(srvr, , ) == -1)
-		FAIL("getpeereid(srvr)");
-	CHECK_EQUAL(euid, geteuid(), "server");
-	CHECK_EQUAL(egid, getegid(), "server");
-#endif
+
+	acpt = acc(srvr);
+
+	peer_addrlen = sizeof(peer_addr);
+	memset(_addr, 0, sizeof(peer_addr));
+	if (getpeername(acpt, (struct sockaddr *)_addr,
+	_addrlen) == -1)
+		FAIL("getpeername");
+	print("peer", _addr, peer_addrlen);
 
 	if (closeit) {
 		if (close(clnt) == -1)
@@ -196,23 +200,11 @@ test(bool closeit, size_t len)
 		clnt = -1;
 	}
 
-	acpt = acc(srvr);
-#if 0
-	/*
-	 * Both linux and NetBSD return ENOTCONN, why?
-	 */
-	if (!closeit) {
-		socklen_t peer_addrlen;
-		sockaddr_un peer_addr;
-
-		peer_addrlen = sizeof(peer_addr);
-		memset(_addr, 0, sizeof(peer_addr));
-		if (getpeername(srvr, (struct sockaddr *)_addr,
-		_addrlen) == -1)
-			FAIL("getpeername");
-		print("peer", _addr, peer_addrlen);
-	}
-#endif
+	/* This is not symmetric? It is supposed to work! */
+	if (getpeereid(acpt, , ) == -1)
+		FAIL("getpeereid(srvr)");
+	CHECK_EQUAL(euid, geteuid(), "server");
+	CHECK_EQUAL(egid, getegid(), "server");
 
 	if ((sock_addr = calloc(1, slen)) == NULL)
 		FAIL("calloc");



CVS commit: src/tests/net/net

2018-02-16 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri Feb 16 22:17:17 UTC 2018

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

Log Message:
make sure we call getpeername on the accepted socket!


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

2018-02-16 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri Feb 16 19:24:16 UTC 2018

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

Log Message:
ensure that getpeereid does not succeed on tcp sockets.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 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

2018-02-16 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri Feb 16 19:24:16 UTC 2018

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

Log Message:
ensure that getpeereid does not succeed on tcp sockets.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 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.8 src/tests/net/net/t_tcp.c:1.9
--- src/tests/net/net/t_tcp.c:1.8	Fri Feb 16 11:30:20 2018
+++ src/tests/net/net/t_tcp.c	Fri Feb 16 14:24:16 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_tcp.c,v 1.8 2018/02/16 16:30:20 christos Exp $	*/
+/*	$NetBSD: t_tcp.c,v 1.9 2018/02/16 19:24:16 christos Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
 
 #include 
 #ifdef __RCSID
-__RCSID("$Id: t_tcp.c,v 1.8 2018/02/16 16:30:20 christos Exp $");
+__RCSID("$Id: t_tcp.c,v 1.9 2018/02/16 19:24:16 christos Exp $");
 #endif
 
 /* Example code. Should block; does with accept not paccept. */
@@ -183,17 +183,11 @@ again:
 #endif
 
 	/* This is supposed to only work on Unix sockets but returns garbage */
-	if (getpeereid(clnt, , ) == -1)
+	if (getpeereid(clnt, , ) != -1)
 		FAIL("getpeereid(clnt)");
-	CHECK_EQUAL(euid, geteuid(), "client");
-	CHECK_EQUAL(egid, getegid(), "client");
-
 	/* This is supposed to only work on Unix sockets but returns garbage */
-	if (getpeereid(srvr, , ) == -1)
+	if (getpeereid(srvr, , ) != -1)
 		FAIL("getpeereid(srvr)");
-	CHECK_EQUAL(euid, geteuid(), "server");
-	CHECK_EQUAL(egid, getegid(), "server");
-
 
 	if (as == -1) {		/* not true under NetBSD */
 		as = paccept(srvr, NULL, NULL, NULL, pacceptblock ? 0 : SOCK_NONBLOCK);



CVS commit: src/tests/net/net

2018-02-16 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri Feb 16 16:30:20 UTC 2018

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

Log Message:
explain what's going on before we fix it.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/tests/net/net/t_tcp.c
cvs rdiff -u -r1.13 -r1.14 src/tests/net/net/t_unix.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.7 src/tests/net/net/t_tcp.c:1.8
--- src/tests/net/net/t_tcp.c:1.7	Fri Feb 16 11:23:15 2018
+++ src/tests/net/net/t_tcp.c	Fri Feb 16 11:30:20 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_tcp.c,v 1.7 2018/02/16 16:23:15 christos Exp $	*/
+/*	$NetBSD: t_tcp.c,v 1.8 2018/02/16 16:30:20 christos Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
 
 #include 
 #ifdef __RCSID
-__RCSID("$Id: t_tcp.c,v 1.7 2018/02/16 16:23:15 christos Exp $");
+__RCSID("$Id: t_tcp.c,v 1.8 2018/02/16 16:30:20 christos Exp $");
 #endif
 
 /* Example code. Should block; does with accept not paccept. */
@@ -182,12 +182,13 @@ again:
 		FAIL("fnctl setfl");
 #endif
 
+	/* This is supposed to only work on Unix sockets but returns garbage */
 	if (getpeereid(clnt, , ) == -1)
 		FAIL("getpeereid(clnt)");
 	CHECK_EQUAL(euid, geteuid(), "client");
 	CHECK_EQUAL(egid, getegid(), "client");
 
-	/* This is not symmetric? */
+	/* This is supposed to only work on Unix sockets but returns garbage */
 	if (getpeereid(srvr, , ) == -1)
 		FAIL("getpeereid(srvr)");
 	CHECK_EQUAL(euid, geteuid(), "server");

Index: src/tests/net/net/t_unix.c
diff -u src/tests/net/net/t_unix.c:1.13 src/tests/net/net/t_unix.c:1.14
--- src/tests/net/net/t_unix.c:1.13	Fri Feb 16 11:23:15 2018
+++ src/tests/net/net/t_unix.c	Fri Feb 16 11:30:20 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_unix.c,v 1.13 2018/02/16 16:23:15 christos Exp $	*/
+/*	$NetBSD: t_unix.c,v 1.14 2018/02/16 16:30:20 christos Exp $	*/
 
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -38,7 +38,7 @@
 
 #include 
 #ifdef __RCSID
-__RCSID("$Id: t_unix.c,v 1.13 2018/02/16 16:23:15 christos Exp $");
+__RCSID("$Id: t_unix.c,v 1.14 2018/02/16 16:30:20 christos Exp $");
 #else
 #define getprogname() argv[0]
 #endif
@@ -183,7 +183,7 @@ test(bool closeit, size_t len)
 	CHECK_EQUAL(egid, getegid(), "client");
 
 #if 0
-	/* This is not symmetric? */
+	/* This is not symmetric? It is supposed to work! */
 	if (getpeereid(srvr, , ) == -1)
 		FAIL("getpeereid(srvr)");
 	CHECK_EQUAL(euid, geteuid(), "server");



CVS commit: src/tests/net/net

2018-02-16 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri Feb 16 16:30:20 UTC 2018

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

Log Message:
explain what's going on before we fix it.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/tests/net/net/t_tcp.c
cvs rdiff -u -r1.13 -r1.14 src/tests/net/net/t_unix.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

2018-02-16 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri Feb 16 16:23:15 UTC 2018

Modified Files:
src/tests/net/net: t_tcp.c t_unix.c
Added Files:
src/tests/net/net: test.h

Log Message:
add getpeereid tests for non-unix sockets, returns garbage...


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/tests/net/net/t_tcp.c
cvs rdiff -u -r1.12 -r1.13 src/tests/net/net/t_unix.c
cvs rdiff -u -r0 -r1.1 src/tests/net/net/test.h

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.6 src/tests/net/net/t_tcp.c:1.7
--- src/tests/net/net/t_tcp.c:1.6	Mon Aug 28 06:19:57 2017
+++ src/tests/net/net/t_tcp.c	Fri Feb 16 11:23:15 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_tcp.c,v 1.6 2017/08/28 10:19:57 christos Exp $	*/
+/*	$NetBSD: t_tcp.c,v 1.7 2018/02/16 16:23:15 christos Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
 
 #include 
 #ifdef __RCSID
-__RCSID("$Id: t_tcp.c,v 1.6 2017/08/28 10:19:57 christos Exp $");
+__RCSID("$Id: t_tcp.c,v 1.7 2018/02/16 16:23:15 christos Exp $");
 #endif
 
 /* Example code. Should block; does with accept not paccept. */
@@ -55,20 +55,8 @@ __RCSID("$Id: t_tcp.c,v 1.6 2017/08/28 1
 #include 
 #include 
 
-#ifdef TEST
-#define FAIL(msg)  err(EXIT_FAILURE, msg)
-#define FAILX(msg, ...)  err(EXIT_FAILURE, msg, ## __VA_ARGS__)
-#else 
-#include  
-#define FAIL(msg)  do { \
-		ATF_CHECK_MSG(0, msg " (%s)", strerror(errno)); \
-		goto fail; \
-	} while (/*CONSTCOND*/0)
-#define FAILX(msg, ...)  do { \
-	ATF_CHECK_MSG(0, msg, ## __VA_ARGS__); \
-	goto fail; \
-	} while (/*CONSTCOND*/0)
-#endif
+
+#include "test.h"
 
 #ifdef __linux__
 #define paccept(a, b, c, d, e) accept4((a), (b), (c), (e))
@@ -93,6 +81,8 @@ paccept_block(sa_family_t sfamily, sa_fa
 	struct sockaddr_in6 *sin6;
 	struct sigaction sa;
 	socklen_t slen;
+	uid_t euid;
+	gid_t egid;
 
 	srvr = socket(sfamily, SOCK_STREAM | SOCK_NONBLOCK, 0);
 	if (srvr == -1)
@@ -192,6 +182,18 @@ again:
 		FAIL("fnctl setfl");
 #endif
 
+	if (getpeereid(clnt, , ) == -1)
+		FAIL("getpeereid(clnt)");
+	CHECK_EQUAL(euid, geteuid(), "client");
+	CHECK_EQUAL(egid, getegid(), "client");
+
+	/* This is not symmetric? */
+	if (getpeereid(srvr, , ) == -1)
+		FAIL("getpeereid(srvr)");
+	CHECK_EQUAL(euid, geteuid(), "server");
+	CHECK_EQUAL(egid, getegid(), "server");
+
+
 	if (as == -1) {		/* not true under NetBSD */
 		as = paccept(srvr, NULL, NULL, NULL, pacceptblock ? 0 : SOCK_NONBLOCK);
 		if (as == -1)
@@ -202,7 +204,7 @@ again:
 		if (fl == -1)
 			FAIL("fnctl");
 		if (fl != (O_RDWR|O_NONBLOCK))
-			FAILX("fl 0x%x != 0x%x\n", fl, O_RDWR|O_NONBLOCK);
+			FAIL("fl 0x%x != 0x%x\n", fl, O_RDWR|O_NONBLOCK);
 		ok = fcntl(as, F_SETFL, fl & ~O_NONBLOCK);
 		if (ok == -1)
 			FAIL("fnctl setfl");

Index: src/tests/net/net/t_unix.c
diff -u src/tests/net/net/t_unix.c:1.12 src/tests/net/net/t_unix.c:1.13
--- src/tests/net/net/t_unix.c:1.12	Fri Feb 16 11:08:22 2018
+++ src/tests/net/net/t_unix.c	Fri Feb 16 11:23:15 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_unix.c,v 1.12 2018/02/16 16:08:22 christos Exp $	*/
+/*	$NetBSD: t_unix.c,v 1.13 2018/02/16 16:23:15 christos Exp $	*/
 
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -38,7 +38,7 @@
 
 #include 
 #ifdef __RCSID
-__RCSID("$Id: t_unix.c,v 1.12 2018/02/16 16:08:22 christos Exp $");
+__RCSID("$Id: t_unix.c,v 1.13 2018/02/16 16:23:15 christos Exp $");
 #else
 #define getprogname() argv[0]
 #endif
@@ -60,20 +60,7 @@ __RCSID("$Id: t_unix.c,v 1.12 2018/02/16
 #include 
 #include 
 
-#ifdef TEST
-#define FAIL(msg, ...)	err(EXIT_FAILURE, msg, ## __VA_ARGS__)
-#define CHECK_EQUAL(a, b) if ((a) != (b)) \
-errx(EXIT_FAILURE, # a "(%ju) != " # b "(%ju)", (uintmax_t)(a), (uintmax_t)((b));
-#else
-
-#include 
-#define FAIL(msg, ...)	\
-	do { \
-		ATF_CHECK_MSG(0, msg, ## __VA_ARGS__); \
-		goto fail; \
-	} while (/*CONSTCOND*/0)
-#define CHECK_EQUAL(a, b) ATF_CHECK_EQ(a, b) 
-#endif
+#include "test.h"
 
 #define OF offsetof(struct sockaddr_un, sun_path)
 
@@ -192,15 +179,15 @@ test(bool closeit, size_t len)
 
 	if (getpeereid(clnt, , ) == -1)
 		FAIL("getpeereid(clnt)");
-	CHECK_EQUAL(euid, geteuid());
-	CHECK_EQUAL(egid, getegid());
+	CHECK_EQUAL(euid, geteuid(), "client");
+	CHECK_EQUAL(egid, getegid(), "client");
 
 #if 0
 	/* This is not symmetric? */
 	if (getpeereid(srvr, , ) == -1)
 		FAIL("getpeereid(srvr)");
-	CHECK_EQUAL(euid, geteuid());
-	CHECK_EQUAL(egid, getegid());
+	CHECK_EQUAL(euid, geteuid(), "server");
+	CHECK_EQUAL(egid, getegid(), "server");
 #endif
 
 	if (closeit) {

Added files:

Index: src/tests/net/net/test.h
diff -u /dev/null src/tests/net/net/test.h:1.1
--- /dev/null	Fri Feb 16 11:23:15 2018
+++ src/tests/net/net/test.h	Fri Feb 16 11:23:15 2018
@@ -0,0 +1,55 @@
+/*-
+ * Copyright (c) 2018 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived 

CVS commit: src/tests/net/net

2018-02-16 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri Feb 16 16:23:15 UTC 2018

Modified Files:
src/tests/net/net: t_tcp.c t_unix.c
Added Files:
src/tests/net/net: test.h

Log Message:
add getpeereid tests for non-unix sockets, returns garbage...


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/tests/net/net/t_tcp.c
cvs rdiff -u -r1.12 -r1.13 src/tests/net/net/t_unix.c
cvs rdiff -u -r0 -r1.1 src/tests/net/net/test.h

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

2018-02-16 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri Feb 16 16:08:22 UTC 2018

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

Log Message:
add a getpeeeid test.


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

2018-02-16 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri Feb 16 16:08:22 UTC 2018

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

Log Message:
add a getpeeeid test.


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/tests/net/net/t_unix.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_unix.c
diff -u src/tests/net/net/t_unix.c:1.11 src/tests/net/net/t_unix.c:1.12
--- src/tests/net/net/t_unix.c:1.11	Wed Nov 13 16:41:23 2013
+++ src/tests/net/net/t_unix.c	Fri Feb 16 11:08:22 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_unix.c,v 1.11 2013/11/13 21:41:23 christos Exp $	*/
+/*	$NetBSD: t_unix.c,v 1.12 2018/02/16 16:08:22 christos Exp $	*/
 
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -38,7 +38,7 @@
 
 #include 
 #ifdef __RCSID
-__RCSID("$Id: t_unix.c,v 1.11 2013/11/13 21:41:23 christos Exp $");
+__RCSID("$Id: t_unix.c,v 1.12 2018/02/16 16:08:22 christos Exp $");
 #else
 #define getprogname() argv[0]
 #endif
@@ -62,6 +62,8 @@ __RCSID("$Id: t_unix.c,v 1.11 2013/11/13
 
 #ifdef TEST
 #define FAIL(msg, ...)	err(EXIT_FAILURE, msg, ## __VA_ARGS__)
+#define CHECK_EQUAL(a, b) if ((a) != (b)) \
+errx(EXIT_FAILURE, # a "(%ju) != " # b "(%ju)", (uintmax_t)(a), (uintmax_t)((b));
 #else
 
 #include 
@@ -70,7 +72,7 @@ __RCSID("$Id: t_unix.c,v 1.11 2013/11/13
 		ATF_CHECK_MSG(0, msg, ## __VA_ARGS__); \
 		goto fail; \
 	} while (/*CONSTCOND*/0)
-
+#define CHECK_EQUAL(a, b) ATF_CHECK_EQ(a, b) 
 #endif
 
 #define OF offsetof(struct sockaddr_un, sun_path)
@@ -142,6 +144,8 @@ test(bool closeit, size_t len)
 	size_t slen;
 	socklen_t sl;
 	int srvr = -1, clnt = -1, acpt = -1;
+	uid_t euid;
+	gid_t egid;
 	struct sockaddr_un *sock_addr = NULL, *sun = NULL;
 	socklen_t sock_addrlen;
 
@@ -186,6 +190,19 @@ test(bool closeit, size_t len)
 	if (connect(clnt, (const struct sockaddr *)sun, sl) == -1)
 		FAIL("connect");
 
+	if (getpeereid(clnt, , ) == -1)
+		FAIL("getpeereid(clnt)");
+	CHECK_EQUAL(euid, geteuid());
+	CHECK_EQUAL(egid, getegid());
+
+#if 0
+	/* This is not symmetric? */
+	if (getpeereid(srvr, , ) == -1)
+		FAIL("getpeereid(srvr)");
+	CHECK_EQUAL(euid, geteuid());
+	CHECK_EQUAL(egid, getegid());
+#endif
+
 	if (closeit) {
 		if (close(clnt) == -1)
 			FAIL("close");



CVS commit: src/tests/net/net

2018-02-08 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Fri Feb  9 03:53:07 UTC 2018

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

Log Message:
Fix ping_opts_gateway and ping_opts_recordroute

We need to enable the options of source routing on all rump kernels.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/tests/net/net/t_ping_opts.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_ping_opts.sh
diff -u src/tests/net/net/t_ping_opts.sh:1.2 src/tests/net/net/t_ping_opts.sh:1.3
--- src/tests/net/net/t_ping_opts.sh:1.2	Thu Feb  8 09:56:19 2018
+++ src/tests/net/net/t_ping_opts.sh	Fri Feb  9 03:53:07 2018
@@ -1,4 +1,4 @@
-#	$NetBSD: t_ping_opts.sh,v 1.2 2018/02/08 09:56:19 maxv Exp $
+#	$NetBSD: t_ping_opts.sh,v 1.3 2018/02/09 03:53:07 ozaki-r Exp $
 #
 # Copyright (c) 2017 Internet Initiative Japan Inc.
 # All rights reserved.
@@ -206,9 +206,6 @@ ping_opts_gateway_body()
 	my_macaddr=$(get_macaddr ${SOCKSRC} shmif0)
 	gw_shmif0_macaddr=$(get_macaddr ${SOCKFWD} shmif0)
 
-	atf_check -s exit:0 rump.sysctl -q -w net.inet.ip.allowsrcrt=1
-	atf_check -s exit:0 rump.sysctl -q -w net.inet.ip.forwsrcrt=1
-
 	export RUMP_SERVER=$SOCKSRC
 	atf_check -s exit:0 -o ignore rump.ping $PING_OPTS $IPDST
 	check_echo_request_pkt_with_macaddr \
@@ -225,6 +222,22 @@ ping_opts_gateway_body()
 	check_echo_request_pkt_with_macaddr \
 	$my_macaddr $gw_shmif0_macaddr $IPSRC $IPDST
 
+	export RUMP_SERVER=$SOCKSRC
+	# ping -g 
+	# By default source-routed packets are prohibited
+	atf_check -s not-exit:0 -o match:'Net prohibited access' \
+	rump.ping $PING_OPTS -g $IPSRCGW $IPDST
+
+	# Enable the options of source routing
+	export RUMP_SERVER=$SOCKSRC
+	atf_check -s exit:0 rump.sysctl -q -w net.inet.ip.allowsrcrt=1
+	export RUMP_SERVER=$SOCKDST
+	atf_check -s exit:0 rump.sysctl -q -w net.inet.ip.allowsrcrt=1
+	export RUMP_SERVER=$SOCKFWD
+	atf_check -s exit:0 rump.sysctl -q -w net.inet.ip.allowsrcrt=1
+	atf_check -s exit:0 rump.sysctl -q -w net.inet.ip.forwsrcrt=1
+
+	export RUMP_SERVER=$SOCKSRC
 	# ping -g 
 	atf_check -s exit:0 -o ignore rump.ping $PING_OPTS \
 	-g $IPSRCGW $IPDST
@@ -238,9 +251,6 @@ ping_opts_gateway_body()
 	check_echo_request_pkt_with_macaddr \
 	$my_macaddr $gw_shmif2_macaddr $IPSRC $IPSRCGW2
 
-	atf_check -s exit:0 rump.sysctl -q -w net.inet.ip.allowsrcrt=0
-	atf_check -s exit:0 rump.sysctl -q -w net.inet.ip.forwsrcrt=0
-
 	rump_server_destroy_ifaces
 }
 
@@ -308,6 +318,16 @@ ping_opts_recordroute_body()
 	$my_macaddr $gw_shmif0_macaddr $IPSRC $IPDST
 	check_recorded_routes $out
 
+	# Enable the options of source routing
+	export RUMP_SERVER=$SOCKSRC
+	atf_check -s exit:0 rump.sysctl -q -w net.inet.ip.allowsrcrt=1
+	export RUMP_SERVER=$SOCKDST
+	atf_check -s exit:0 rump.sysctl -q -w net.inet.ip.allowsrcrt=1
+	export RUMP_SERVER=$SOCKFWD
+	atf_check -s exit:0 rump.sysctl -q -w net.inet.ip.allowsrcrt=1
+	atf_check -s exit:0 rump.sysctl -q -w net.inet.ip.forwsrcrt=1
+
+	export RUMP_SERVER=$SOCKSRC
 	# ping -R -g 
 	atf_check -s exit:0 -o save:$out rump.ping $PING_OPTS \
 	-R -g $IPSRCGW $IPDST



CVS commit: src/tests/net/net

2018-02-08 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Fri Feb  9 03:53:07 UTC 2018

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

Log Message:
Fix ping_opts_gateway and ping_opts_recordroute

We need to enable the options of source routing on all rump kernels.


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

2018-02-08 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Thu Feb  8 09:56:19 UTC 2018

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

Log Message:
Now that we don't allow source-routed packets by default, set allowsrcrt=1
and forwsrcrt=1. Should fix the ATF failure.


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

2018-02-08 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Thu Feb  8 09:56:19 UTC 2018

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

Log Message:
Now that we don't allow source-routed packets by default, set allowsrcrt=1
and forwsrcrt=1. Should fix the ATF failure.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/net/net/t_ping_opts.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_ping_opts.sh
diff -u src/tests/net/net/t_ping_opts.sh:1.1 src/tests/net/net/t_ping_opts.sh:1.2
--- src/tests/net/net/t_ping_opts.sh:1.1	Fri Mar 31 06:41:40 2017
+++ src/tests/net/net/t_ping_opts.sh	Thu Feb  8 09:56:19 2018
@@ -1,4 +1,4 @@
-#	$NetBSD: t_ping_opts.sh,v 1.1 2017/03/31 06:41:40 ozaki-r Exp $
+#	$NetBSD: t_ping_opts.sh,v 1.2 2018/02/08 09:56:19 maxv Exp $
 #
 # Copyright (c) 2017 Internet Initiative Japan Inc.
 # All rights reserved.
@@ -206,6 +206,9 @@ ping_opts_gateway_body()
 	my_macaddr=$(get_macaddr ${SOCKSRC} shmif0)
 	gw_shmif0_macaddr=$(get_macaddr ${SOCKFWD} shmif0)
 
+	atf_check -s exit:0 rump.sysctl -q -w net.inet.ip.allowsrcrt=1
+	atf_check -s exit:0 rump.sysctl -q -w net.inet.ip.forwsrcrt=1
+
 	export RUMP_SERVER=$SOCKSRC
 	atf_check -s exit:0 -o ignore rump.ping $PING_OPTS $IPDST
 	check_echo_request_pkt_with_macaddr \
@@ -235,6 +238,9 @@ ping_opts_gateway_body()
 	check_echo_request_pkt_with_macaddr \
 	$my_macaddr $gw_shmif2_macaddr $IPSRC $IPSRCGW2
 
+	atf_check -s exit:0 rump.sysctl -q -w net.inet.ip.allowsrcrt=0
+	atf_check -s exit:0 rump.sysctl -q -w net.inet.ip.forwsrcrt=0
+
 	rump_server_destroy_ifaces
 }
 



CVS commit: src/tests/net/net

2017-12-30 Thread Andreas Gustafsson
Module Name:src
Committed By:   gson
Date:   Sat Dec 30 22:02:34 UTC 2017

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

Log Message:
Use the default ATF timeout instead of a reduced one of 5 seconds,
which isn't enough for pmax under gxemul on babylon5.netbsd.org.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/tests/net/net/t_pktinfo_send.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_pktinfo_send.c
diff -u src/tests/net/net/t_pktinfo_send.c:1.2 src/tests/net/net/t_pktinfo_send.c:1.3
--- src/tests/net/net/t_pktinfo_send.c:1.2	Mon Dec 11 05:47:18 2017
+++ src/tests/net/net/t_pktinfo_send.c	Sat Dec 30 22:02:34 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_pktinfo_send.c,v 1.2 2017/12/11 05:47:18 ryo Exp $	*/
+/*	$NetBSD: t_pktinfo_send.c,v 1.3 2017/12/30 22:02:34 gson Exp $	*/
 
 /*-
  * Copyright (c) 2017 Internet Initiative Japan Inc.
@@ -27,7 +27,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include 
-__RCSID("$NetBSD: t_pktinfo_send.c,v 1.2 2017/12/11 05:47:18 ryo Exp $");
+__RCSID("$NetBSD: t_pktinfo_send.c,v 1.3 2017/12/30 22:02:34 gson Exp $");
 
 #include 
 #include 
@@ -223,7 +223,6 @@ ATF_TC(pktinfo_send_unbound);
 ATF_TC_HEAD(pktinfo_send_unbound, tc)
 {
 	atf_tc_set_md_var(tc, "descr", "sendmsg with IP_PKTINFO");
-	atf_tc_set_md_var(tc, "timeout", "5");
 }
 ATF_TC_BODY(pktinfo_send_unbound, tc)
 {
@@ -247,7 +246,6 @@ ATF_TC_HEAD(pktinfo_send_bindany, tc)
 {
 	atf_tc_set_md_var(tc, "descr",
 	"sendmsg with IP_PKTINFO on bind(INADDR_ANY) socket");
-	atf_tc_set_md_var(tc, "timeout", "5");
 }
 ATF_TC_BODY(pktinfo_send_bindany, tc)
 {
@@ -272,7 +270,6 @@ ATF_TC_HEAD(pktinfo_send_bindaddr, tc)
 {
 	atf_tc_set_md_var(tc, "descr",
 	"sendmsg with IP_PKTINFO on bind(addr:0) socket");
-	atf_tc_set_md_var(tc, "timeout", "5");
 }
 ATF_TC_BODY(pktinfo_send_bindaddr, tc)
 {
@@ -297,7 +294,6 @@ ATF_TC_HEAD(pktinfo_send_bindport, tc)
 {
 	atf_tc_set_md_var(tc, "descr",
 	"sendmsg with IP_PKTINFO on bind(INADDR_ANY:12345) socket");
-	atf_tc_set_md_var(tc, "timeout", "5");
 }
 ATF_TC_BODY(pktinfo_send_bindport, tc)
 {
@@ -322,7 +318,6 @@ ATF_TC_HEAD(pktinfo_send_bindaddrport, t
 {
 	atf_tc_set_md_var(tc, "descr",
 	"sendmsg with IP_PKTINFO on bind(addr:12345) socket");
-	atf_tc_set_md_var(tc, "timeout", "5");
 }
 ATF_TC_BODY(pktinfo_send_bindaddrport, tc)
 {
@@ -347,7 +342,6 @@ ATF_TC_HEAD(pktinfo_send_bindother, tc)
 {
 	atf_tc_set_md_var(tc, "descr",
 	"sendmsg with IP_PKTINFO from address bound by other socket");
-	atf_tc_set_md_var(tc, "timeout", "5");
 }
 ATF_TC_BODY(pktinfo_send_bindother, tc)
 {
@@ -374,7 +368,6 @@ ATF_TC_HEAD(pktinfo_send_connected, tc)
 {
 	atf_tc_set_md_var(tc, "descr",
 	"sendmsg with IP_PKTINFO on connected socket");
-	atf_tc_set_md_var(tc, "timeout", "5");
 }
 ATF_TC_BODY(pktinfo_send_connected, tc)
 {
@@ -412,7 +405,6 @@ ATF_TC_HEAD(pktinfo_send_notown, tc)
 {
 	atf_tc_set_md_var(tc, "descr",
 	"sendmsg with IP_PKTINFO from no-own address");
-	atf_tc_set_md_var(tc, "timeout", "5");
 }
 ATF_TC_BODY(pktinfo_send_notown, tc)
 {
@@ -445,7 +437,6 @@ ATF_TC_HEAD(pktinfo_send_notown_bind, tc
 {
 	atf_tc_set_md_var(tc, "descr",
 	"sendmsg with IP_PKTINFO from no-own address on bind socket");
-	atf_tc_set_md_var(tc, "timeout", "5");
 }
 ATF_TC_BODY(pktinfo_send_notown_bind, tc)
 {
@@ -493,7 +484,6 @@ ATF_TC_HEAD(pktinfo_send_rawip, tc)
 {
 	atf_tc_set_md_var(tc, "descr",
 	"sendmsg raw-ip with IP_PKTINFO");
-	atf_tc_set_md_var(tc, "timeout", "5");
 }
 ATF_TC_BODY(pktinfo_send_rawip, tc)
 {
@@ -526,7 +516,6 @@ ATF_TC_HEAD(pktinfo_send_rawip_notown, t
 {
 	atf_tc_set_md_var(tc, "descr",
 	"sendmsg raw-ip with IP_PKTINFO from no-own address");
-	atf_tc_set_md_var(tc, "timeout", "5");
 }
 ATF_TC_BODY(pktinfo_send_rawip_notown, tc)
 {
@@ -564,7 +553,6 @@ ATF_TC_HEAD(pktinfo_send_invalidarg, tc)
 {
 	atf_tc_set_md_var(tc, "descr",
 	"sendmsg IP_PKTINFO with invalid argument");
-	atf_tc_set_md_var(tc, "timeout", "5");
 }
 ATF_TC_BODY(pktinfo_send_invalidarg, tc)
 {
@@ -603,7 +591,6 @@ ATF_TC_HEAD(pktinfo_send_ifindex, tc)
 {
 	atf_tc_set_md_var(tc, "descr",
 	"sendmsg with IP_PKTINFO to specified interface");
-	atf_tc_set_md_var(tc, "timeout", "5");
 }
 ATF_TC_BODY(pktinfo_send_ifindex, tc)
 {
@@ -700,7 +687,6 @@ ATF_TC_HEAD(pktinfo_send_multicast, tc)
 	atf_tc_set_md_var(tc, "descr",
 	"sendmsg with IP_PKTINFO to multicast address"
 	" and specified interface");
-	atf_tc_set_md_var(tc, "timeout", "5");
 }
 ATF_TC_BODY(pktinfo_send_multicast, tc)
 {



CVS commit: src/tests/net/net

2017-12-30 Thread Andreas Gustafsson
Module Name:src
Committed By:   gson
Date:   Sat Dec 30 22:02:34 UTC 2017

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

Log Message:
Use the default ATF timeout instead of a reduced one of 5 seconds,
which isn't enough for pmax under gxemul on babylon5.netbsd.org.


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

2017-08-28 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Aug 28 10:19:57 UTC 2017

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

Log Message:
add tests for 4->6 connections.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 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.5 src/tests/net/net/t_tcp.c:1.6
--- src/tests/net/net/t_tcp.c:1.5	Mon Aug 28 05:30:29 2017
+++ src/tests/net/net/t_tcp.c	Mon Aug 28 06:19:57 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_tcp.c,v 1.5 2017/08/28 09:30:29 christos Exp $	*/
+/*	$NetBSD: t_tcp.c,v 1.6 2017/08/28 10:19:57 christos Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
 
 #include 
 #ifdef __RCSID
-__RCSID("$Id: t_tcp.c,v 1.5 2017/08/28 09:30:29 christos Exp $");
+__RCSID("$Id: t_tcp.c,v 1.6 2017/08/28 10:19:57 christos Exp $");
 #endif
 
 /* Example code. Should block; does with accept not paccept. */
@@ -46,6 +46,7 @@ __RCSID("$Id: t_tcp.c,v 1.5 2017/08/28 0
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -55,10 +56,18 @@ __RCSID("$Id: t_tcp.c,v 1.5 2017/08/28 0
 #include 
 
 #ifdef TEST
-#define FAIL(msg, ...)  err(EXIT_FAILURE, msg, ## __VA_ARGS__)
+#define FAIL(msg)  err(EXIT_FAILURE, msg)
+#define FAILX(msg, ...)  err(EXIT_FAILURE, msg, ## __VA_ARGS__)
 #else 
 #include  
-#define FAIL(msg, ...)  ATF_CHECK_MSG(0, msg, ## __VA_ARGS__); goto fail
+#define FAIL(msg)  do { \
+		ATF_CHECK_MSG(0, msg " (%s)", strerror(errno)); \
+		goto fail; \
+	} while (/*CONSTCOND*/0)
+#define FAILX(msg, ...)  do { \
+	ATF_CHECK_MSG(0, msg, ## __VA_ARGS__); \
+	goto fail; \
+	} while (/*CONSTCOND*/0)
 #endif
 
 #ifdef __linux__
@@ -71,10 +80,12 @@ ding(int al)
 }
 
 static void 
-paccept_block(sa_family_t family, bool pacceptblock, bool fcntlblock)
+paccept_block(sa_family_t sfamily, sa_family_t cfamily,
+bool pacceptblock, bool fcntlblock)
 {
 	int srvr = -1, clnt = -1, as = -1;
 	int ok, fl;
+	int count = 5;
 	ssize_t n;
 	char buf[10];
 	struct sockaddr_storage ss, bs;
@@ -83,12 +94,12 @@ paccept_block(sa_family_t family, bool p
 	struct sigaction sa;
 	socklen_t slen;
 
-	srvr = socket(family, SOCK_STREAM | SOCK_NONBLOCK, 0);
+	srvr = socket(sfamily, SOCK_STREAM | SOCK_NONBLOCK, 0);
 	if (srvr == -1)
 		FAIL("socket");
 
 	memset(, 0, sizeof(ss));
-	switch (ss.ss_family = family) {
+	switch (ss.ss_family = sfamily) {
 	case AF_INET:
 		sin = (void *)
 		slen = sizeof(*sin);
@@ -99,7 +110,11 @@ paccept_block(sa_family_t family, bool p
 		sin6 = (void *)
 		slen = sizeof(*sin6);
 		sin6->sin6_port = htons(0);
-		sin6->sin6_addr = in6addr_loopback;
+		if (sfamily == AF_INET6 && cfamily == AF_INET) {
+			sin6->sin6_addr = in6addr_any;
+		} else {
+			sin6->sin6_addr = in6addr_loopback;
+		}
 		break;
 	default:
 		errno = EINVAL;
@@ -108,6 +123,12 @@ paccept_block(sa_family_t family, bool p
 #ifdef BSD4_4
 	ss.ss_len = slen;
 #endif
+	if (sfamily == AF_INET6 && cfamily == AF_INET) {
+		int off = 0;
+		if (setsockopt(srvr, IPPROTO_IPV6, IPV6_V6ONLY,
+		(void *), sizeof(off)) == -1)
+			FAIL("setsockopt IPV6_V6ONLY");
+	}
 
 	ok = bind(srvr, (const struct sockaddr *), slen);
 	if (ok == -1)
@@ -122,18 +143,44 @@ paccept_block(sa_family_t family, bool p
 	if (ok == -1)
 		FAIL("listen");
 
-	clnt = socket(family, SOCK_STREAM | SOCK_NONBLOCK, 0);
+	clnt = socket(cfamily, SOCK_STREAM | SOCK_NONBLOCK, 0);
 	if (clnt == -1)
 		FAIL("socket");
 
+	if (sfamily == AF_INET6 && cfamily == AF_INET) {
+		ss = bs;
+		sin6 = (void *)
+		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_addr.s_addr = htonl(INADDR_LOOPBACK);
+	}
+
 	/* may not connect first time */
 	ok = connect(clnt, (struct sockaddr *) , addrlen);
 	if (ok != -1 || errno != EINPROGRESS)
 		FAIL("expected connect to fail");
 	as = paccept(srvr, NULL, NULL, NULL, pacceptblock ? 0 : SOCK_NONBLOCK);
+again:
 	ok = connect(clnt, (struct sockaddr *) , addrlen);
-	if (ok == -1 && errno != EISCONN)
+	if (ok == -1 && errno != EISCONN) {
+		if (count-- && errno == EALREADY) {
+			fprintf(stderr, "retry\n");
+			struct timespec ts;
+			ts.tv_sec = 0;
+			ts.tv_nsec = 100;
+			nanosleep(, NULL);
+#if 0
+			sched_yield();
+#endif
+			goto again;
+		}
 		FAIL("connect failed");
+	}
 
 #if 0
 	fl = fcntl(srvr, F_GETFL, 0);
@@ -155,7 +202,7 @@ paccept_block(sa_family_t family, bool p
 		if (fl == -1)
 			FAIL("fnctl");
 		if (fl != (O_RDWR|O_NONBLOCK))
-			FAIL("fl 0x%x != 0x%x\n", fl, O_RDWR|O_NONBLOCK);
+			FAILX("fl 0x%x != 0x%x\n", fl, O_RDWR|O_NONBLOCK);
 		ok = fcntl(as, F_SETFL, fl & ~O_NONBLOCK);
 		if (ok == -1)
 			FAIL("fnctl setfl");
@@ -187,101 +234,143 @@ fail:
 
 #ifndef TEST
 
-ATF_TC(paccept4_reset_nonblock);

CVS commit: src/tests/net/net

2017-08-28 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Aug 28 10:19:57 UTC 2017

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

Log Message:
add tests for 4->6 connections.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 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

2017-08-28 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Aug 28 09:30:29 UTC 2017

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

Log Message:
add v6 tests


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 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.4 src/tests/net/net/t_tcp.c:1.5
--- src/tests/net/net/t_tcp.c:1.4	Fri Mar  4 13:52:01 2016
+++ src/tests/net/net/t_tcp.c	Mon Aug 28 05:30:29 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_tcp.c,v 1.4 2016/03/04 18:52:01 christos Exp $	*/
+/*	$NetBSD: t_tcp.c,v 1.5 2017/08/28 09:30:29 christos Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
 
 #include 
 #ifdef __RCSID
-__RCSID("$Id: t_tcp.c,v 1.4 2016/03/04 18:52:01 christos Exp $");
+__RCSID("$Id: t_tcp.c,v 1.5 2017/08/28 09:30:29 christos Exp $");
 #endif
 
 /* Example code. Should block; does with accept not paccept. */
@@ -71,32 +71,50 @@ ding(int al)
 }
 
 static void 
-paccept_block(bool pacceptblock, bool fcntlblock)
+paccept_block(sa_family_t family, bool pacceptblock, bool fcntlblock)
 {
 	int srvr = -1, clnt = -1, as = -1;
 	int ok, fl;
 	ssize_t n;
 	char buf[10];
-	struct sockaddr_in sin, ba;
+	struct sockaddr_storage ss, bs;
+	struct sockaddr_in *sin;
+	struct sockaddr_in6 *sin6;
 	struct sigaction sa;
+	socklen_t slen;
 
-	srvr = socket(AF_INET, SOCK_STREAM | SOCK_NONBLOCK, 0);
+	srvr = socket(family, SOCK_STREAM | SOCK_NONBLOCK, 0);
 	if (srvr == -1)
 		FAIL("socket");
 
-	memset(, 0, sizeof(sin));
-	sin.sin_family = AF_INET;
+	memset(, 0, sizeof(ss));
+	switch (ss.ss_family = family) {
+	case AF_INET:
+		sin = (void *)
+		slen = sizeof(*sin);
+		sin->sin_port = htons(0);
+		sin->sin_addr.s_addr = htonl(INADDR_LOOPBACK);
+		break;
+	case AF_INET6:
+		sin6 = (void *)
+		slen = sizeof(*sin6);
+		sin6->sin6_port = htons(0);
+		sin6->sin6_addr = in6addr_loopback;
+		break;
+	default:
+		errno = EINVAL;
+		FAIL("bad family");
+	}
 #ifdef BSD4_4
-	sin.sin_len = sizeof(sin);
+	ss.ss_len = slen;
 #endif
-	sin.sin_port = htons(0);
-	sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
-	ok = bind(srvr, (const struct sockaddr *), (socklen_t)sizeof(sin));
+
+	ok = bind(srvr, (const struct sockaddr *), slen);
 	if (ok == -1)
 		FAIL("bind");
 
-	socklen_t addrlen = sizeof(struct sockaddr_in);
-	ok = getsockname(srvr, (struct sockaddr *), );
+	socklen_t addrlen = slen;
+	ok = getsockname(srvr, (struct sockaddr *), );
 	if (ok == -1)
 		FAIL("getsockname");
 
@@ -104,16 +122,16 @@ paccept_block(bool pacceptblock, bool fc
 	if (ok == -1)
 		FAIL("listen");
 
-	clnt = socket(AF_INET, SOCK_STREAM | SOCK_NONBLOCK, 0);
+	clnt = socket(family, SOCK_STREAM | SOCK_NONBLOCK, 0);
 	if (clnt == -1)
 		FAIL("socket");
 
 	/* may not connect first time */
-	ok = connect(clnt, (struct sockaddr *) , addrlen);
+	ok = connect(clnt, (struct sockaddr *) , addrlen);
 	if (ok != -1 || errno != EINPROGRESS)
 		FAIL("expected connect to fail");
 	as = paccept(srvr, NULL, NULL, NULL, pacceptblock ? 0 : SOCK_NONBLOCK);
-	ok = connect(clnt, (struct sockaddr *) , addrlen);
+	ok = connect(clnt, (struct sockaddr *) , addrlen);
 	if (ok == -1 && errno != EISCONN)
 		FAIL("connect failed");
 
@@ -169,59 +187,101 @@ fail:
 
 #ifndef TEST
 
-ATF_TC(paccept_reset_nonblock);
-ATF_TC_HEAD(paccept_reset_nonblock, tc)
+ATF_TC(paccept4_reset_nonblock);
+ATF_TC_HEAD(paccept4_reset_nonblock, tc)
+{
+
+	atf_tc_set_md_var(tc, "descr", "Check that paccept(2) resets "
+	"the non-blocking flag on non-blocking sockets (ipv4)");
+}
+
+ATF_TC_BODY(paccept4_reset_nonblock, tc)
+{
+	paccept_block(AF_INET, true, false);
+}
+
+ATF_TC(fcntl4_reset_nonblock);
+ATF_TC_HEAD(fcntl4_reset_nonblock, tc)
+{
+
+	atf_tc_set_md_var(tc, "descr", "Check that fcntl(2) resets "
+	"the non-blocking flag on non-blocking sockets (ipv4)");
+}
+
+ATF_TC_BODY(fcntl4_reset_nonblock, tc)
+{
+	paccept_block(AF_INET, false, true);
+}
+
+ATF_TC(paccept4_nonblock);
+ATF_TC_HEAD(paccept4_nonblock, tc)
+{
+
+	atf_tc_set_md_var(tc, "descr", "Check that fcntl(2) resets "
+	"the non-blocking flag on non-blocking sockets (ipv4)");
+}
+
+ATF_TC_BODY(paccept4_nonblock, tc)
+{
+	paccept_block(AF_INET, false, false);
+}
+
+ATF_TC(paccept6_reset_nonblock);
+ATF_TC_HEAD(paccept6_reset_nonblock, tc)
 {
 
 	atf_tc_set_md_var(tc, "descr", "Check that paccept(2) resets "
-	"the non-blocking flag on non-blocking sockets");
+	"the non-blocking flag on non-blocking sockets (ipv6)");
 }
 
-ATF_TC_BODY(paccept_reset_nonblock, tc)
+ATF_TC_BODY(paccept6_reset_nonblock, tc)
 {
-	paccept_block(true, false);
+	paccept_block(AF_INET6, true, false);
 }
 
-ATF_TC(fcntl_reset_nonblock);
-ATF_TC_HEAD(fcntl_reset_nonblock, tc)
+ATF_TC(fcntl6_reset_nonblock);
+ATF_TC_HEAD(fcntl6_reset_nonblock, tc)
 {
 
 	atf_tc_set_md_var(tc, "descr", "Check that fcntl(2) resets "
-	"the 

CVS commit: src/tests/net/net

2017-08-28 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Aug 28 09:30:29 UTC 2017

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

Log Message:
add v6 tests


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 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

2017-03-31 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Fri Mar 31 06:41:40 UTC 2017

Modified Files:
src/tests/net/net: Makefile
Added Files:
src/tests/net/net: t_ping_opts.sh

Log Message:
Add test cases for ping options


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/tests/net/net/Makefile
cvs rdiff -u -r0 -r1.1 src/tests/net/net/t_ping_opts.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/Makefile
diff -u src/tests/net/net/Makefile:1.19 src/tests/net/net/Makefile:1.20
--- src/tests/net/net/Makefile:1.19	Thu Nov 24 08:52:20 2016
+++ src/tests/net/net/Makefile	Fri Mar 31 06:41:40 2017
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.19 2016/11/24 08:52:20 ozaki-r Exp $
+# $NetBSD: Makefile,v 1.20 2017/03/31 06:41:40 ozaki-r Exp $
 #
 
 .include 
@@ -13,7 +13,7 @@ TESTS_C+=	t_pktinfo
 TESTS_C+=	t_raw
 
 .for name in forwarding ipaddress ipv6address ipv6_lifetime mtudisc mtudisc6 \
-ping6_opts
+ping_opts ping6_opts
 TESTS_SH+=		t_${name}
 TESTS_SH_SRC_t_${name}=	../net_common.sh t_${name}.sh
 .endfor

Added files:

Index: src/tests/net/net/t_ping_opts.sh
diff -u /dev/null src/tests/net/net/t_ping_opts.sh:1.1
--- /dev/null	Fri Mar 31 06:41:40 2017
+++ src/tests/net/net/t_ping_opts.sh	Fri Mar 31 06:41:40 2017
@@ -0,0 +1,338 @@
+#	$NetBSD: t_ping_opts.sh,v 1.1 2017/03/31 06:41:40 ozaki-r Exp $
+#
+# Copyright (c) 2017 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.
+#
+
+SOCKSRC=unix://ping_opts1
+SOCKFWD=unix://ping_opts2
+SOCKDST=unix://ping_opts3
+IPSRC=10.0.1.2
+IPSRCGW=10.0.1.1
+IPDSTGW=10.0.2.1
+IPDST=10.0.2.2
+BUS_SRCGW=bus1
+BUS_DSTGW=bus2
+
+IPSRC2=10.0.1.3
+IPSRCGW2=10.0.1.254
+
+DEBUG=${DEBUG:-false}
+TIMEOUT=1
+PING_OPTS="-n -c 1 -w $TIMEOUT"
+
+#
+# Utility functions
+#
+setup_endpoint()
+{
+	local sock=${1}
+	local addr=${2}
+	local bus=${3}
+	local gw=${4}
+
+	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 rump.route add default ${gw}
+	atf_check -s exit:0 rump.ifconfig shmif0 up
+	atf_check -s exit:0 rump.ifconfig -w 10
+
+	if $DEBUG; then
+		rump.ifconfig shmif0
+		rump.netstat -nr
+	fi
+}
+
+setup_forwarder()
+{
+
+	rump_server_add_iface $SOCKFWD shmif0 $BUS_SRCGW
+	rump_server_add_iface $SOCKFWD shmif1 $BUS_DSTGW
+
+	export RUMP_SERVER=$SOCKFWD
+
+	atf_check -s exit:0 rump.ifconfig shmif0 ${IPSRCGW}/24
+	atf_check -s exit:0 rump.ifconfig shmif1 ${IPDSTGW}/24
+
+	atf_check -s exit:0 rump.ifconfig shmif0 up
+	atf_check -s exit:0 rump.ifconfig shmif1 up
+	atf_check -s exit:0 rump.ifconfig -w 10
+
+	if $DEBUG; then
+		rump.netstat -nr
+		rump.sysctl net.inet.ip.forwarding
+	fi
+}
+
+setup_forwarding()
+{
+
+	export RUMP_SERVER=$SOCKFWD
+	atf_check -s exit:0 -o ignore rump.sysctl -w net.inet.ip.forwarding=1
+}
+
+setup()
+{
+
+	rump_server_start $SOCKSRC
+	rump_server_start $SOCKFWD
+	rump_server_start $SOCKDST
+
+	setup_endpoint $SOCKSRC $IPSRC $BUS_SRCGW $IPSRCGW
+	setup_endpoint $SOCKDST $IPDST $BUS_DSTGW $IPDSTGW
+	setup_forwarder
+}
+
+check_echo_request_pkt()
+{
+	local pkt="$1 > $2: .+ echo request"
+
+	extract_new_packets $BUS_SRCGW > ./out
+	$DEBUG && echo $pkt
+	$DEBUG && cat ./out
+	atf_check -s exit:0 -o match:"$pkt" cat ./out
+}
+
+check_echo_request_pkt_with_macaddr()
+{
+	local pkt="$1 > $2, .+ $3 > $4: .+ echo request"
+
+	extract_new_packets $BUS_SRCGW > ./out
+	$DEBUG && echo $pkt
+	$DEBUG && cat ./out
+	atf_check -s exit:0 -o match:"$pkt" cat ./out
+}
+
+check_echo_request_pkt_with_macaddr_and_rthdr0()
+{
+	local pkt=
+
+	pkt="$1 > 

CVS commit: src/tests/net/net

2017-03-31 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Fri Mar 31 06:41:40 UTC 2017

Modified Files:
src/tests/net/net: Makefile
Added Files:
src/tests/net/net: t_ping_opts.sh

Log Message:
Add test cases for ping options


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

2017-03-05 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Mon Mar  6 07:33:27 UTC 2017

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

Log Message:
Add a test case for net.inet.ip.mtudisctimeout

The test case just reproduces PR kern/52029 and needs more tests.


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

2017-03-05 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Mon Mar  6 07:33:27 UTC 2017

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

Log Message:
Add a test case for net.inet.ip.mtudisctimeout

The test case just reproduces PR kern/52029 and needs more tests.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/tests/net/net/t_mtudisc.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_mtudisc.sh
diff -u src/tests/net/net/t_mtudisc.sh:1.9 src/tests/net/net/t_mtudisc.sh:1.10
--- src/tests/net/net/t_mtudisc.sh:1.9	Thu Feb 16 08:12:47 2017
+++ src/tests/net/net/t_mtudisc.sh	Mon Mar  6 07:33:27 2017
@@ -1,4 +1,4 @@
-#	$NetBSD: t_mtudisc.sh,v 1.9 2017/02/16 08:12:47 ozaki-r Exp $
+#	$NetBSD: t_mtudisc.sh,v 1.10 2017/03/06 07:33:27 ozaki-r Exp $
 #
 # Copyright (c) 2016 Internet Initiative Japan Inc.
 # All rights reserved.
@@ -175,12 +175,42 @@ mtudisc_basic_body()
 
 mtudisc_basic_cleanup()
 {
+
 	$DEBUG && dump
 	stop_nc_server
 	cleanup
 }
 
+atf_test_case mtudisc_timeout cleanup
+mtudisc_timeout_head()
+{
+
+	atf_set "descr" "Tests for IPv4 Path MTU Dicorvery timeout behavior"
+	atf_set "require.progs" "rump_server nc"
+}
+
+mtudisc_timeout_body()
+{
+
+	rump_server_start $SOCKLOCAL
+
+	export RUMP_SERVER=$SOCKLOCAL
+	atf_check -s exit:0 -o match:'600 -> 600' \
+	rump.sysctl -w net.inet.ip.mtudisctimeout=600
+
+	# TODO more tests
+}
+
+mtudisc_timeout_cleanup()
+{
+
+	$DEBUG && dump
+	cleanup
+}
+
 atf_init_test_cases()
 {
+
 	atf_add_test_case mtudisc_basic
+	atf_add_test_case mtudisc_timeout
 }



CVS commit: src/tests/net/net

2017-02-20 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Mon Feb 20 09:58:59 UTC 2017

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

Log Message:
Add basic tests for forwarding fragmented packets


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

2017-02-20 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Mon Feb 20 09:58:59 UTC 2017

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

Log Message:
Add basic tests for forwarding fragmented packets


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/tests/net/net/t_forwarding.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_forwarding.sh
diff -u src/tests/net/net/t_forwarding.sh:1.19 src/tests/net/net/t_forwarding.sh:1.20
--- src/tests/net/net/t_forwarding.sh:1.19	Fri Nov 25 08:51:17 2016
+++ src/tests/net/net/t_forwarding.sh	Mon Feb 20 09:58:58 2017
@@ -1,4 +1,4 @@
-#	$NetBSD: t_forwarding.sh,v 1.19 2016/11/25 08:51:17 ozaki-r Exp $
+#	$NetBSD: t_forwarding.sh,v 1.20 2017/02/20 09:58:58 ozaki-r Exp $
 #
 # Copyright (c) 2015 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -47,6 +47,7 @@ atf_test_case ipforwarding_v6 cleanup
 atf_test_case ipforwarding_fastforward_v4 cleanup
 atf_test_case ipforwarding_fastforward_v6 cleanup
 atf_test_case ipforwarding_misc cleanup
+atf_test_case ipforwarding_fragment_v4 cleanup
 
 ipforwarding_v4_head()
 {
@@ -78,6 +79,12 @@ ipforwarding_misc_head()
 	atf_set "require.progs" "rump_server"
 }
 
+ipforwarding_fragment_v4_head()
+{
+	atf_set "descr" "Tests for fragmented packet forwarding (IPv4)"
+	atf_set "require.progs" "rump_server"
+}
+
 setup_endpoint()
 {
 	sock=${1}
@@ -150,6 +157,18 @@ setup_forwarder()
 	fi
 }
 
+prepare_file()
+{
+	local file=$1
+	local data="0123456789"
+
+	touch $file
+	for i in `seq 1 512`
+	do
+		echo $data >> $file
+	done
+}
+
 setup()
 {
 	rump_server_start $SOCKSRC
@@ -398,6 +417,22 @@ test_hoplimit()
 	$DEBUG && rump.ifconfig -v shmif0
 }
 
+setup_mtu()
+{
+	local mtu=$1
+
+	export RUMP_SERVER=$SOCKFWD
+	atf_check -s exit:0 rump.ifconfig shmif0 mtu $mtu
+}
+
+disable_mtudisc()
+{
+	local mtu=$1
+
+	export RUMP_SERVER=$SOCKDST
+	atf_check -s exit:0 -o ignore rump.sysctl -w -q net.inet.ip.mtudisc=0
+}
+
 ipforwarding_v4_body()
 {
 	setup
@@ -487,6 +522,37 @@ ipforwarding_misc_body()
 	return 0
 }
 
+ipforwarding_fragment_v4_body()
+{
+	setup
+	test_setup
+
+	setup_forwarding
+	test_setup_forwarding
+
+	prepare_file $HTML_FILE
+	start_httpd $SOCKDST $IP4DST
+	$DEBUG && rump.netstat -a
+	setup_mtu 1000
+	disable_mtudisc
+
+	extract_new_packets bus1 > ./out
+	extract_new_packets bus2 > ./out
+
+	test_http_get $IP4DST
+
+	# Packets of MTU size sent from the server
+	extract_new_packets bus2 > ./out
+	atf_check -s exit:0 -o match:'length 1514' cat ./out
+
+	# The packets are fragmented down to 1000
+	extract_new_packets bus1 > ./out
+	atf_check -s exit:0 -o match:'length 1010' cat ./out
+	atf_check -s exit:0 -o match:'length 538' cat ./out
+
+	teardown_interfaces
+}
+
 ipforwarding_v4_cleanup()
 {
 	$DEBUG && dump
@@ -520,6 +586,13 @@ ipforwarding_misc_cleanup()
 	cleanup
 }
 
+ipforwarding_fragment_v4_cleanup()
+{
+	$DEBUG && dump
+	stop_httpd
+	cleanup
+}
+
 atf_init_test_cases()
 {
 	atf_add_test_case ipforwarding_v4
@@ -527,4 +600,5 @@ atf_init_test_cases()
 	atf_add_test_case ipforwarding_fastforward_v4
 	atf_add_test_case ipforwarding_fastforward_v6
 	atf_add_test_case ipforwarding_misc
+	atf_add_test_case ipforwarding_fragment_v4
 }



CVS commit: src/tests/net/net

2017-02-20 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Mon Feb 20 09:00:09 UTC 2017

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

Log Message:
Add simple tests of behaviors of alias addresses


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

2017-02-20 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Mon Feb 20 09:00:09 UTC 2017

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

Log Message:
Add simple tests of behaviors of alias addresses


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/tests/net/net/t_ipaddress.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_ipaddress.sh
diff -u src/tests/net/net/t_ipaddress.sh:1.9 src/tests/net/net/t_ipaddress.sh:1.10
--- src/tests/net/net/t_ipaddress.sh:1.9	Thu Dec 15 02:43:56 2016
+++ src/tests/net/net/t_ipaddress.sh	Mon Feb 20 09:00:08 2017
@@ -1,4 +1,4 @@
-#	$NetBSD: t_ipaddress.sh,v 1.9 2016/12/15 02:43:56 ozaki-r Exp $
+#	$NetBSD: t_ipaddress.sh,v 1.10 2017/02/20 09:00:08 ozaki-r Exp $
 #
 # Copyright (c) 2015 Internet Initiative Japan Inc.
 # All rights reserved.
@@ -184,10 +184,65 @@ add_test()
 	atf_add_test_case "ipaddr_${name}"
 }
 
+test_alias_address()
+{
+	local ip=10.0.0.1
+	local net=10.0.0/24
+	local ip_a1=10.0.0.2
+
+	rump_server_start $SOCK_LOCAL
+	rump_server_add_iface $SOCK_LOCAL shmif0 $BUS
+
+	export RUMP_SERVER=$SOCK_LOCAL
+
+	# Assign a primary address and an alias address
+	atf_check -s exit:0 rump.ifconfig shmif0 $ip/24
+	atf_check -s exit:0 rump.ifconfig shmif0 $ip_a1/24 alias
+	atf_check -s exit:0 rump.ifconfig shmif0 up
+	atf_check -s exit:0 rump.ifconfig -w 10
+
+	$DEBUG && rump.ifconfig shmif0
+	$DEBUG && rump.netstat -nr -f inet
+
+	atf_check -s exit:0 -o match:"inet $ip" rump.ifconfig shmif0
+	atf_check -s exit:0 -o match:"inet $ip_a1" rump.ifconfig shmif0
+	check_route $ip 'link#2' UHl lo0
+	check_route $ip_a1 'link#2' UHl lo0
+	check_route $net 'link#2' UC shmif0
+
+	# Delete the primary address
+	atf_check -s exit:0 rump.ifconfig shmif0 $ip delete
+
+	$DEBUG && rump.ifconfig shmif0
+	$DEBUG && rump.netstat -nr -f inet
+
+	atf_check -s exit:0 -o not-match:"inet $ip" rump.ifconfig shmif0
+	atf_check -s exit:0 -o match:"inet $ip_a1" rump.ifconfig shmif0
+	check_route_no_entry $ip
+	check_route $ip_a1 'link#2' UHl lo0
+	check_route $net 'link#2' UC shmif0
+
+	# The alias address is now primary, so assigning a new address
+	# without 'alias' will overwrite the alias address
+	atf_check -s exit:0 rump.ifconfig shmif0 $ip/24
+
+	$DEBUG && rump.ifconfig shmif0
+	$DEBUG && rump.netstat -nr -f inet
+
+	atf_check -s exit:0 -o match:"inet $ip" rump.ifconfig shmif0
+	atf_check -s exit:0 -o not-match:"inet $ip_a1" rump.ifconfig shmif0
+	check_route $ip 'link#2' UHl lo0
+	check_route_no_entry $ip_a1
+	check_route $net 'link#2' UC shmif0
+
+	rump_server_destroy_ifaces
+}
+
 atf_init_test_cases()
 {
 
 	add_test same_address	"Assigning/deleting an IP address twice"
 	add_test same_address6	"Assigning/deleting an IPv6 address twice"
 	add_test auto_linklocal	"Assigning an IPv6 link-local address automatically"
+	add_test alias_address	"Tests of behaviors of alias addresses"
 }



CVS commit: src/tests/net/net

2016-12-20 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Wed Dec 21 01:16:18 UTC 2016

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

Log Message:
Suppress harmless warning message

rump.netstat: sysctlnametomib: net.inet6.udp6.pcblist: No such file or directory


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

2016-12-20 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Wed Dec 21 01:16:18 UTC 2016

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

Log Message:
Suppress harmless warning message

rump.netstat: sysctlnametomib: net.inet6.udp6.pcblist: No such file or directory


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/tests/net/net/t_mtudisc.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_mtudisc.sh
diff -u src/tests/net/net/t_mtudisc.sh:1.7 src/tests/net/net/t_mtudisc.sh:1.8
--- src/tests/net/net/t_mtudisc.sh:1.7	Fri Nov 25 08:51:17 2016
+++ src/tests/net/net/t_mtudisc.sh	Wed Dec 21 01:16:18 2016
@@ -1,4 +1,4 @@
-#	$NetBSD: t_mtudisc.sh,v 1.7 2016/11/25 08:51:17 ozaki-r Exp $
+#	$NetBSD: t_mtudisc.sh,v 1.8 2016/12/21 01:16:18 ozaki-r Exp $
 #
 # Copyright (c) 2016 Internet Initiative Japan Inc.
 # All rights reserved.
@@ -126,7 +126,7 @@ mtudisc_basic_body()
 	# Start httpd daemon
 	prepare_download_file $HTML_FILE
 	start_httpd $SOCKREMOTE $remote_ip
-	$DEBUG && rump.netstat -a
+	$DEBUG && rump.netstat -a -f inet
 
 	# Teach the peer thar 10.0.0.2(local serer) is behind 10.0.1.1(gateway server)
 	atf_check -s exit:0 -o ignore rump.route add $local_ip/32 $gateway_remote_ip



CVS commit: src/tests/net/net

2016-12-14 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Thu Dec 15 02:43:56 UTC 2016

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

Log Message:
Fix that cleanup doesn't run when DEBUG=false


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/tests/net/net/t_ipaddress.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_ipaddress.sh
diff -u src/tests/net/net/t_ipaddress.sh:1.8 src/tests/net/net/t_ipaddress.sh:1.9
--- src/tests/net/net/t_ipaddress.sh:1.8	Fri Nov 25 08:51:17 2016
+++ src/tests/net/net/t_ipaddress.sh	Thu Dec 15 02:43:56 2016
@@ -1,4 +1,4 @@
-#	$NetBSD: t_ipaddress.sh,v 1.8 2016/11/25 08:51:17 ozaki-r Exp $
+#	$NetBSD: t_ipaddress.sh,v 1.9 2016/12/15 02:43:56 ozaki-r Exp $
 #
 # Copyright (c) 2015 Internet Initiative Japan Inc.
 # All rights reserved.
@@ -178,7 +178,7 @@ add_test()
 			test_${name}; \
 		}; \
 	ipaddr_${name}_cleanup() { \
-			$DEBUG && dump \
+			$DEBUG && dump; \
 			cleanup; \
 		}"
 	atf_add_test_case "ipaddr_${name}"



CVS commit: src/tests/net/net

2016-12-14 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Thu Dec 15 02:43:56 UTC 2016

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

Log Message:
Fix that cleanup doesn't run when DEBUG=false


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

2016-12-13 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Wed Dec 14 02:50:42 UTC 2016

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

Log Message:
Rename dump because it's used in net_common.sh


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 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.11 src/tests/net/net/t_ipv6address.sh:1.12
--- src/tests/net/net/t_ipv6address.sh:1.11	Thu Nov 24 09:06:09 2016
+++ src/tests/net/net/t_ipv6address.sh	Wed Dec 14 02:50:42 2016
@@ -1,4 +1,4 @@
-#	$NetBSD: t_ipv6address.sh,v 1.11 2016/11/24 09:06:09 ozaki-r Exp $
+#	$NetBSD: t_ipv6address.sh,v 1.12 2016/12/14 02:50:42 ozaki-r Exp $
 #
 # Copyright (c) 2015 Internet Initiative Japan Inc.
 # All rights reserved.
@@ -215,7 +215,7 @@ dump_bus()
 	shmif_dumpbus -p - ${BUS2}   2>/dev/null| tcpdump -n -e -r -
 }
 
-dump()
+_dump()
 {
 
 	export RUMP_SERVER=${SOCKSRC}
@@ -287,7 +287,7 @@ linklocal_body()
 	atf_check -s exit:0 -o ignore rump.ifconfig -w 10
 
 	$DEBUG && rump.ifconfig shmif0
-	$DEBUG && dump
+	$DEBUG && _dump
 
 	export RUMP_SERVER=${SOCKSRC}
 	atf_check -s exit:0 -o match:"0.0% packet loss" \
@@ -332,7 +332,7 @@ linklocal_body()
 linklocal_cleanup()
 {
 
-	$DEBUG && dump
+	$DEBUG && _dump
 	$DEBUG && dump_bus
 	cleanup_rump_servers
 }



CVS commit: src/tests/net/net

2016-12-13 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Wed Dec 14 02:50:42 UTC 2016

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

Log Message:
Rename dump because it's used in net_common.sh


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

2016-11-25 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Fri Nov 25 08:10:12 UTC 2016

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

Log Message:
Add missing head functions


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/tests/net/net/t_forwarding.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_forwarding.sh
diff -u src/tests/net/net/t_forwarding.sh:1.17 src/tests/net/net/t_forwarding.sh:1.18
--- src/tests/net/net/t_forwarding.sh:1.17	Thu Nov 24 11:54:57 2016
+++ src/tests/net/net/t_forwarding.sh	Fri Nov 25 08:10:12 2016
@@ -1,4 +1,4 @@
-#	$NetBSD: t_forwarding.sh,v 1.17 2016/11/24 11:54:57 ozaki-r Exp $
+#	$NetBSD: t_forwarding.sh,v 1.18 2016/11/25 08:10:12 ozaki-r Exp $
 #
 # Copyright (c) 2015 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -63,6 +63,18 @@ ipforwarding_v6_head()
 	atf_set "require.progs" "rump_server"
 }
 
+ipforwarding_fastforward_v4_head()
+{
+	atf_set "descr" "Tests for IPv4 fastforward"
+	atf_set "require.progs" "rump_server"
+}
+
+ipforwarding_fastforward_v6_head()
+{
+	atf_set "descr" "Tests for IPv6 fastfoward"
+	atf_set "require.progs" "rump_server"
+}
+
 ipforwarding_misc_head()
 {
 	atf_set "descr" "Does IPv4 forwarding tests"



CVS commit: src/tests/net/net

2016-11-25 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Fri Nov 25 08:10:12 UTC 2016

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

Log Message:
Add missing head functions


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

2016-11-23 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Thu Nov 24 07:32:20 UTC 2016

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

Log Message:
Make tests strict

Connected routes have 'C' flag.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/tests/net/net/t_ipaddress.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_ipaddress.sh
diff -u src/tests/net/net/t_ipaddress.sh:1.5 src/tests/net/net/t_ipaddress.sh:1.6
--- src/tests/net/net/t_ipaddress.sh:1.5	Mon Nov  7 05:25:37 2016
+++ src/tests/net/net/t_ipaddress.sh	Thu Nov 24 07:32:19 2016
@@ -1,4 +1,4 @@
-#	$NetBSD: t_ipaddress.sh,v 1.5 2016/11/07 05:25:37 ozaki-r Exp $
+#	$NetBSD: t_ipaddress.sh,v 1.6 2016/11/24 07:32:19 ozaki-r Exp $
 #
 # Copyright (c) 2015 Internet Initiative Japan Inc.
 # All rights reserved.
@@ -69,7 +69,7 @@ test_same_address()
 	check_entry $ip UHl
 	check_entry $ip lo0
 	check_entry $ip 'link#2'
-	check_entry $net U
+	check_entry $net UC
 	check_entry $net shmif0
 	check_entry $net 'link#2'
 
@@ -90,7 +90,7 @@ test_same_address()
 	check_entry $ip UHl
 	check_entry $ip lo0
 	check_entry $ip 'link#2'
-	check_entry $net U
+	check_entry $net UC
 	check_entry $net shmif0
 	check_entry $net 'link#2'
 
@@ -122,7 +122,7 @@ test_same_address6()
 	check_entry $ip UHl
 	check_entry $ip lo0
 	check_entry $ip 'link#2'
-	check_entry $net U
+	check_entry $net UC
 	check_entry $net shmif0
 	check_entry $net 'link#2'
 
@@ -143,7 +143,7 @@ test_same_address6()
 	check_entry $ip UHl
 	check_entry $ip lo0
 	check_entry $ip 'link#2'
-	check_entry $net U
+	check_entry $net UC
 	check_entry $net shmif0
 	check_entry $net 'link#2'
 



CVS commit: src/tests/net/net

2016-11-23 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Thu Nov 24 07:32:20 UTC 2016

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

Log Message:
Make tests strict

Connected routes have 'C' flag.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/tests/net/net/t_ipaddress.sh

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



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


CVS commit: src/tests/net/net

2016-11-06 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Mon Nov  7 05:44:48 UTC 2016

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

Log Message:
Add tests for combination use of -g option and hops optional argument


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/tests/net/net/t_ping6_opts.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_ping6_opts.sh
diff -u src/tests/net/net/t_ping6_opts.sh:1.3 src/tests/net/net/t_ping6_opts.sh:1.4
--- src/tests/net/net/t_ping6_opts.sh:1.3	Mon Nov  7 05:25:37 2016
+++ src/tests/net/net/t_ping6_opts.sh	Mon Nov  7 05:44:48 2016
@@ -1,4 +1,4 @@
-#	$NetBSD: t_ping6_opts.sh,v 1.3 2016/11/07 05:25:37 ozaki-r Exp $
+#	$NetBSD: t_ping6_opts.sh,v 1.4 2016/11/07 05:44:48 ozaki-r Exp $
 #
 # Copyright (c) 2016 Internet Initiative Japan Inc.
 # All rights reserved.
@@ -398,6 +398,23 @@ ping6_opts_hops_body()
 	$IP6SRCGW2 $IP6DST
 	check_echo_request_pkt_with_macaddr_and_rthdr0 \
 	$my_macaddr $gw_shmif2_macaddr $IP6SRC $IP6SRCGW2 $IP6DST
+
+	# ping6 -g  hops
+	atf_check -s not-exit:0 -o ignore rump.ping6 -n -c 1 -X $TIMEOUT \
+	-g $IP6SRCGW $IP6SRCGW $IP6DST
+	check_echo_request_pkt_with_macaddr_and_rthdr0 \
+	$my_macaddr $gw_shmif0_macaddr $IP6SRC $IP6SRCGW $IP6DST
+
+	atf_check -s not-exit:0 -o ignore rump.ping6 -n -c 1 -X $TIMEOUT \
+	-g $IP6SRCGW2 $IP6SRCGW2 $IP6DST
+	check_echo_request_pkt_with_macaddr_and_rthdr0 \
+	$my_macaddr $gw_shmif2_macaddr $IP6SRC $IP6SRCGW2 $IP6DST
+
+	# ping6 -g  hops, but different nexthops (is it valid?)
+	atf_check -s not-exit:0 -o ignore rump.ping6 -n -c 1 -X $TIMEOUT \
+	-g $IP6SRCGW $IP6SRCGW2 $IP6DST
+	check_echo_request_pkt_with_macaddr_and_rthdr0 \
+	$my_macaddr $gw_shmif0_macaddr $IP6SRC $IP6SRCGW2 $IP6DST
 }
 
 ping6_opts_hops_cleanup()



CVS commit: src/tests/net/net

2016-11-06 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Mon Nov  7 05:44:48 UTC 2016

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

Log Message:
Add tests for combination use of -g option and hops optional argument


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

2016-11-06 Thread Ryota Ozaki
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.


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

2016-11-06 Thread Ryota Ozaki
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.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/net/net/t_ping6_opts.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_ping6_opts.sh
diff -u src/tests/net/net/t_ping6_opts.sh:1.1 src/tests/net/net/t_ping6_opts.sh:1.2
--- src/tests/net/net/t_ping6_opts.sh:1.1	Mon Oct 31 10:38:25 2016
+++ src/tests/net/net/t_ping6_opts.sh	Mon Nov  7 04:43:14 2016
@@ -1,4 +1,4 @@
-#	$NetBSD: t_ping6_opts.sh,v 1.1 2016/10/31 10:38:25 ozaki-r Exp $
+#	$NetBSD: t_ping6_opts.sh,v 1.2 2016/11/07 04:43:14 ozaki-r Exp $
 #
 # Copyright (c) 2016 Internet Initiative Japan Inc.
 # All rights reserved.
@@ -160,6 +160,20 @@ check_echo_request_pkt_with_macaddr()
 	atf_check -s exit:0 -o match:"$pkt" cat ./out
 }
 
+check_echo_request_pkt_with_macaddr_and_rthdr0()
+{
+	local pkt=
+
+	pkt="$1 > $2, .+ $3 > $4:"
+	pkt="$pkt srcrt \\(len=2, type=0, segleft=1, \\[0\\]$5\\)"
+	pkt="$pkt .+ echo request"
+
+	extract_new_packets $BUS_SRCGW > ./out
+	$DEBUG && echo $pkt
+	$DEBUG && cat ./out
+	atf_check -s exit:0 -o match:"$pkt" cat ./out
+}
+
 dump()
 {
 
@@ -333,10 +347,71 @@ ping6_opts_gateway_cleanup()
 	cleanup
 }
 
+atf_test_case ping6_opts_hops cleanup
+ping6_opts_hops_head()
+{
+
+	atf_set "descr" "tests of ping6 hops (Type 0 Routing Header)"
+	atf_set "require.progs" "rump_server"
+}
+
+ping6_opts_hops_body()
+{
+	local my_macaddr=
+	local gw_shmif0_macaddr=
+	local gw_shmif2_macaddr=
+
+	setup6
+	setup_forwarding6
+
+	my_macaddr=$(get_macaddr ${SOCKSRC} shmif0)
+	gw_shmif0_macaddr=$(get_macaddr ${SOCKFWD} shmif0)
+
+	export RUMP_SERVER=$SOCKSRC
+	atf_check -s exit:0 -o ignore rump.ping6 -n -c 1 -X $TIMEOUT $IP6DST
+	check_echo_request_pkt_with_macaddr \
+	$my_macaddr $gw_shmif0_macaddr $IP6SRC $IP6DST
+
+	export RUMP_SERVER=$SOCKFWD
+	atf_check -s exit:0 rump.ifconfig shmif2 create
+	atf_check -s exit:0 rump.ifconfig shmif2 linkstr $BUS_SRCGW
+	atf_check -s exit:0 rump.ifconfig shmif2 inet6 $IP6SRCGW2
+	atf_check -s exit:0 rump.ifconfig -w 10
+	gw_shmif2_macaddr=$(get_macaddr ${SOCKFWD} shmif2)
+
+	export RUMP_SERVER=$SOCKSRC
+	atf_check -s exit:0 -o ignore rump.ping6 -n -c 1 -X $TIMEOUT $IP6DST
+	check_echo_request_pkt_with_macaddr \
+	$my_macaddr $gw_shmif0_macaddr $IP6SRC $IP6DST
+
+	# ping6 hops
+
+	# ping6 fails expectedly because the kernel doesn't support
+	# to receive packets with type 0 routing headers, but we can
+	# check whether a sent packet is correct.
+	atf_check -s not-exit:0 -o ignore rump.ping6 -n -c 1 -X $TIMEOUT \
+	$IP6SRCGW $IP6DST
+	check_echo_request_pkt_with_macaddr_and_rthdr0 \
+	$my_macaddr $gw_shmif0_macaddr $IP6SRC $IP6SRCGW $IP6DST
+
+	atf_check -s not-exit:0 -o ignore rump.ping6 -n -c 1 -X $TIMEOUT \
+	$IP6SRCGW2 $IP6DST
+	check_echo_request_pkt_with_macaddr_and_rthdr0 \
+	$my_macaddr $gw_shmif2_macaddr $IP6SRC $IP6SRCGW2 $IP6DST
+}
+
+ping6_opts_hops_cleanup()
+{
+
+	$DEBUG && dump
+	cleanup
+}
+
 atf_init_test_cases()
 {
 
 	atf_add_test_case ping6_opts_sourceaddr
 	atf_add_test_case ping6_opts_interface
 	atf_add_test_case ping6_opts_gateway
+	atf_add_test_case ping6_opts_hops
 }



CVS commit: src/tests/net/net

2016-10-05 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Thu Oct  6 02:44:48 UTC 2016

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

Log Message:
PR bin/51532 - kill the test http server before terminating


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/net/net/t_mtudisc.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_mtudisc.sh
diff -u src/tests/net/net/t_mtudisc.sh:1.1 src/tests/net/net/t_mtudisc.sh:1.2
--- src/tests/net/net/t_mtudisc.sh:1.1	Tue Oct  4 04:15:25 2016
+++ src/tests/net/net/t_mtudisc.sh	Thu Oct  6 02:44:48 2016
@@ -1,4 +1,4 @@
-#	$NetBSD: t_mtudisc.sh,v 1.1 2016/10/04 04:15:25 ozaki-r Exp $
+#	$NetBSD: t_mtudisc.sh,v 1.2 2016/10/06 02:44:48 kre Exp $
 #
 # Copyright (c) 2016 Internet Initiative Japan Inc.
 # All rights reserved.
@@ -207,6 +207,7 @@ mtudisc_basic_body()
 	atf_check -s exit:0 \
 		-o match:"^10.0.0.2 +10.0.1.1 +UGHS +- +- +1280 +shmif0" \
 		rump.netstat -nr -f inet
+
 }
 
 cleanup()
@@ -240,6 +241,7 @@ dump()
 mtudisc_basic_cleanup()
 {
 	$DEBUG && dump
+	kill "$(cat ${HTTPD_PID})"
 	env RUMP_SERVER=$SOCKLOCAL rump.halt
 	env RUMP_SERVER=$SOCKGATEWAY rump.halt
 	env RUMP_SERVER=$SOCKREMOTE rump.halt



CVS commit: src/tests/net/net

2016-10-05 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Thu Oct  6 02:44:48 UTC 2016

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

Log Message:
PR bin/51532 - kill the test http server before terminating


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

2016-10-03 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Tue Oct  4 03:43:15 UTC 2016

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

Log Message:
Add tests for sysctl net.inet6.ip6.auto_linklocal

>From suzu-ken@IIJ


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/tests/net/net/t_ipaddress.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_ipaddress.sh
diff -u src/tests/net/net/t_ipaddress.sh:1.3 src/tests/net/net/t_ipaddress.sh:1.4
--- src/tests/net/net/t_ipaddress.sh:1.3	Wed Aug 10 21:33:52 2016
+++ src/tests/net/net/t_ipaddress.sh	Tue Oct  4 03:43:15 2016
@@ -1,4 +1,4 @@
-#	$NetBSD: t_ipaddress.sh,v 1.3 2016/08/10 21:33:52 kre Exp $
+#	$NetBSD: t_ipaddress.sh,v 1.4 2016/10/04 03:43:15 ozaki-r Exp $
 #
 # Copyright (c) 2015 Internet Initiative Japan Inc.
 # All rights reserved.
@@ -156,6 +156,44 @@ test_same_address6()
 	check_entry_fail $net
 }
 
+test_auto_linklocal()
+{
+	atf_check -s exit:0 ${SERVER6} ${SOCK_LOCAL}
+	export RUMP_SERVER=$SOCK_LOCAL
+
+	#
+	# Test enabled auto linklocal
+	#
+
+	# Check default value
+	atf_check -s exit:0 -o match:"1" rump.sysctl -n net.inet6.ip6.auto_linklocal
+
+	atf_check -s exit:0 -o ignore rump.ifconfig shmif0 create
+	atf_check -s exit:0 -o ignore rump.ifconfig shmif0 linkstr ${BUS}
+	atf_check -s exit:0 -o ignore rump.ifconfig shmif0 up
+	atf_check -s exit:0 -o ignore rump.ifconfig -w 10
+
+	$DEBUG && rump.netstat -nr -f inet
+
+	# IPv6 link-local address is set
+	atf_check -s exit:0 -o match:"inet6 fe80::" rump.ifconfig shmif0
+
+	#
+	# Test disabled auto linklocal
+	#
+	atf_check -s exit:0 -o ignore rump.sysctl -w -q net.inet6.ip6.auto_linklocal=0
+
+	atf_check -s exit:0 -o ignore rump.ifconfig shmif1 create
+	atf_check -s exit:0 -o ignore rump.ifconfig shmif1 linkstr ${BUS}
+	atf_check -s exit:0 -o ignore rump.ifconfig shmif1 up
+	atf_check -s exit:0 -o ignore rump.ifconfig -w 10
+
+	$DEBUG && rump.netstat -nr -f inet
+
+	# IPv6 link-local address is not set
+	atf_check -s exit:0 -o not-match:"inet6 fe80::" rump.ifconfig shmif1
+}
+
 cleanup()
 {
 
@@ -187,4 +225,5 @@ atf_init_test_cases()
 
 	add_test same_address	"Assigning/deleting an IP address twice"
 	add_test same_address6	"Assigning/deleting an IPv6 address twice"
+	add_test auto_linklocal	"Assigning an IPv6 link-local address automatically"
 }



CVS commit: src/tests/net/net

2016-10-03 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Mon Oct  3 17:59:27 UTC 2016

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

Log Message:
80 column violation fixes, hopefully minor readability improvements.
No intended functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 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

2016-10-03 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Mon Oct  3 17:59:27 UTC 2016

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

Log Message:
80 column violation fixes, hopefully minor readability improvements.
No intended functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 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.8 src/tests/net/net/t_ipv6address.sh:1.9
--- src/tests/net/net/t_ipv6address.sh:1.8	Sun Oct  2 04:29:25 2016
+++ src/tests/net/net/t_ipv6address.sh	Mon Oct  3 17:59:27 2016
@@ -1,4 +1,4 @@
-#	$NetBSD: t_ipv6address.sh,v 1.8 2016/10/02 04:29:25 kre Exp $
+#	$NetBSD: t_ipv6address.sh,v 1.9 2016/10/03 17:59:27 kre Exp $
 #
 # Copyright (c) 2015 Internet Initiative Japan Inc.
 # All rights reserved.
@@ -24,8 +24,9 @@
 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 # POSSIBILITY OF SUCH DAMAGE.
 
-SERVER="rump_server -lrumpnet -lrumpnet_net -lrumpnet_netinet -lrumpnet_shmif -lrumpdev"
-SERVER6="$SERVER -lrumpnet_netinet6"
+SERVER="rump_server -lrumpnet -lrumpnet_net -lrumpnet_netinet"
+SERVER="${SERVER} -lrumpnet_shmif -lrumpdev"
+SERVER6="${SERVER} -lrumpnet_netinet6"
 
 SOCKSRC=unix://commsock1
 SOCKFWD=unix://commsock2
@@ -124,35 +125,35 @@ setup_route()
 	local fwd_if1_lladdr=`get_lladdr ${SOCKFWD} shmif1`
 
 	export RUMP_SERVER=${SOCKSRC}
-	atf_check -s ignore -o ignore -e ignore rump.route delete -inet6 default \
-	${fwd_if0_lladdr}%shmif0
-	atf_check -s exit:0 -o match:"add net default:" rump.route add -inet6 default \
-	${fwd_if0_lladdr}%shmif0
+	atf_check -s ignore -o ignore -e ignore \
+	rump.route delete -inet6 default ${fwd_if0_lladdr}%shmif0
+	atf_check -s exit:0 -o match:"add net default:" \
+	rump.route add-inet6 default ${fwd_if0_lladdr}%shmif0
 	atf_check -s exit:0 rump.ifconfig shmif1 inet6 ${IP6SRC}
 	atf_check -s exit:0 -o ignore rump.ifconfig -w 10
 	$DEBUG && rump.netstat -rn -f inet6
 	unset RUMP_SERVER
 
 	export RUMP_SERVER=${SOCKDST}
-	atf_check -s ignore -o ignore -e ignore rump.route delete -inet6 default \
-	${fwd_if1_lladdr}%shmif0
-	atf_check -s exit:0 -o match:"add net default:" rump.route add -inet6 default \
-	${fwd_if1_lladdr}%shmif0
+	atf_check -s ignore -o ignore -e ignore \
+	rump.route delete -inet6 default ${fwd_if1_lladdr}%shmif0
+	atf_check -s exit:0 -o match:"add net default:" \
+	rump.route add-inet6 default ${fwd_if1_lladdr}%shmif0
 	atf_check -s exit:0 rump.ifconfig shmif1 inet6 ${IP6DST}
 	atf_check -s exit:0 -o ignore rump.ifconfig -w 10
 	$DEBUG && rump.netstat -rn -f inet6
 	unset RUMP_SERVER
 
 	export RUMP_SERVER=${SOCKFWD}
-	atf_check -s ignore -o ignore -e ignore rump.route delete -inet6 ${IP6SRCNW} \
-	${src_if0_lladdr}%shmif0
-	atf_check -s exit:0 -o match:"add net" rump.route add -inet6 ${IP6SRCNW} \
-	${src_if0_lladdr}%shmif0
-
-	atf_check -s ignore -o ignore -e ignore rump.route delete -inet6 ${IP6DSTNW} \
-	${dst_if0_lladdr}%shmif1
-	atf_check -s exit:0 -o match:"add net" rump.route add -inet6 ${IP6DSTNW} \
-	${dst_if0_lladdr}%shmif1
+	atf_check -s ignore -o ignore -e ignore \
+	rump.route delete -inet6 ${IP6SRCNW} ${src_if0_lladdr}%shmif0
+	atf_check -s exit:0 -o match:"add net" \
+	rump.route add-inet6 ${IP6SRCNW} ${src_if0_lladdr}%shmif0
+
+	atf_check -s ignore -o ignore -e ignore \
+	rump.route delete -inet6 ${IP6DSTNW} ${dst_if0_lladdr}%shmif1
+	atf_check -s exit:0 -o match:"add net" \
+	rump.route add-inet6 ${IP6DSTNW} ${dst_if0_lladdr}%shmif1
 	atf_check -s exit:0 -o ignore rump.ifconfig -w 10
 	$DEBUG && rump.netstat -rn -f inet6
 	unset RUMP_SERVER
@@ -221,8 +222,8 @@ dump_bus()
 
 	shmif_dumpbus -p - ${BUSSRC} 2>/dev/null| tcpdump -n -e -r -
 	shmif_dumpbus -p - ${BUSDST} 2>/dev/null| tcpdump -n -e -r -
-	shmif_dumpbus -p - ${BUS1} 2>/dev/null| tcpdump -n -e -r -
-	shmif_dumpbus -p - ${BUS2} 2>/dev/null| tcpdump -n -e -r -
+	shmif_dumpbus -p - ${BUS1}   2>/dev/null| tcpdump -n -e -r -
+	shmif_dumpbus -p - ${BUS2}   2>/dev/null| tcpdump -n -e -r -
 }
 
 dump()
@@ -242,8 +243,10 @@ dump()
 
 linklocal_head()
 {
-	atf_set "descr" "Test for bassically function of the IPv6 linklocal address"
-	atf_set "require.progs" "rump_server rump.route rump.ifconfig rump.ping6"
+	atf_set "descr" \
+	"Test for bassically function of the IPv6 linklocal address"
+	atf_set "require.progs" \
+	"rump_server rump.route rump.ifconfig rump.ping6"
 }
 
 linklocal_body()
@@ -271,7 +274,7 @@ linklocal_body()
 	atf_check -s ignore -o empty -e ignore \
 	-x "shmif_dumpbus -p - ${BUSSRC} | tcpdump -r - -n -p icmp6"
 	atf_check -s ignore -o not-empty -e ignore \
-	-x "shmif_dumpbus -p - ${BUS1} | tcpdump -r - -n -p icmp6"
+	-x "shmif_dumpbus -p - ${BUS1}   | tcpdump -r - -n -p 

CVS commit: src/tests/net/net

2016-10-02 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Sun Oct  2 15:27:32 UTC 2016

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

Log Message:
This test works fine on real hardware, but due to PR kern/43997 (qemu
timing problems) fails when run under qemu.   Attempt to compensate
for that (by skipping the problematic test case) when running in qemu.

This should be reverted when the PR gets fixed (either in qemu or in
the NetBSD kernel).


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

2016-10-02 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Sun Oct  2 15:27:32 UTC 2016

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

Log Message:
This test works fine on real hardware, but due to PR kern/43997 (qemu
timing problems) fails when run under qemu.   Attempt to compensate
for that (by skipping the problematic test case) when running in qemu.

This should be reverted when the PR gets fixed (either in qemu or in
the NetBSD kernel).


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/tests/net/net/t_ipv6_lifetime.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_ipv6_lifetime.sh
diff -u src/tests/net/net/t_ipv6_lifetime.sh:1.3 src/tests/net/net/t_ipv6_lifetime.sh:1.4
--- src/tests/net/net/t_ipv6_lifetime.sh:1.3	Fri Sep 16 00:44:14 2016
+++ src/tests/net/net/t_ipv6_lifetime.sh	Sun Oct  2 15:27:32 2016
@@ -1,4 +1,4 @@
-#	$NetBSD: t_ipv6_lifetime.sh,v 1.3 2016/09/16 00:44:14 ozaki-r Exp $
+#	$NetBSD: t_ipv6_lifetime.sh,v 1.4 2016/10/02 15:27:32 kre Exp $
 #
 # Copyright (c) 2015 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -89,12 +89,23 @@ basic_body()
 	# Shouldn't remain anymore
 	atf_check -s exit:0 -o not-match:"$ip" rump.ifconfig -L shmif0
 
+	# Setting both preferred and valid lifetimes (pltime > vltime)
+	atf_check -s not-exit:0 -e match:'Invalid argument' rump.ifconfig \
+	shmif0 inet6 $ip pltime $(($time * 2)) vltime $time
+
 	# Setting both preferred and valid lifetimes (pltime < vltime)
 	atf_check -s exit:0 rump.ifconfig shmif0 inet6 $ip \
 	pltime $time vltime $((time * 2))
 	$DEBUG && rump.ifconfig -L shmif0
 	atf_check -s exit:0 -o match:'pltime' rump.ifconfig -L shmif0
 	atf_check -s exit:0 -o match:'vltime' rump.ifconfig -L shmif0
+
+	if sysctl machdep.cpu_brand 2>/dev/null | grep QEMU >/dev/null 2>&1
+	then
+		atf_check -s exit:0 rump.ifconfig shmif0 inet6 $ip delete
+		atf_skip "unreliable under qemu, skip until PR kern/43997 fixed"
+	fi
+
 	atf_check -s exit:0 sleep $(($time + $bonus))
 	$DEBUG && rump.ifconfig -L shmif0
 	# Should remain but marked as deprecated
@@ -104,10 +115,6 @@ basic_body()
 	# Shouldn't remain anymore
 	atf_check -s exit:0 -o not-match:"$ip" rump.ifconfig -L shmif0
 
-	# Setting both preferred and valid lifetimes (pltime > vltime)
-	atf_check -s not-exit:0 -e match:'Invalid argument' rump.ifconfig \
-	shmif0 inet6 $ip pltime $(($time * 2)) vltime $time
-
 	return 0
 }
 



CVS commit: src/tests/net/net

2016-10-01 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Sun Oct  2 04:29:25 UTC 2016

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

Log Message:
More adaptation to new ifconfig output format - prefix length is now
appended to the address, rather than a second parameter, so needs to be
deleted if just the bare address is what we want (which it is here).


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 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

2016-10-01 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Sun Oct  2 04:29:25 UTC 2016

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

Log Message:
More adaptation to new ifconfig output format - prefix length is now
appended to the address, rather than a second parameter, so needs to be
deleted if just the bare address is what we want (which it is here).


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 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.7 src/tests/net/net/t_ipv6address.sh:1.8
--- src/tests/net/net/t_ipv6address.sh:1.7	Wed Aug 10 21:33:52 2016
+++ src/tests/net/net/t_ipv6address.sh	Sun Oct  2 04:29:25 2016
@@ -1,4 +1,4 @@
-#	$NetBSD: t_ipv6address.sh,v 1.7 2016/08/10 21:33:52 kre Exp $
+#	$NetBSD: t_ipv6address.sh,v 1.8 2016/10/02 04:29:25 kre Exp $
 #
 # Copyright (c) 2015 Internet Initiative Japan Inc.
 # All rights reserved.
@@ -202,7 +202,7 @@ get_lladdr()
 {
 	export RUMP_SERVER=${1}
 	rump.ifconfig ${2} inet6 | grep "fe80" \
-	| awk '{print $2}' | sed -e "s/%$2//g"
+	| awk '{print $2}' | sed -e "s/%$2//g" -e 's;/[0-9]*$;;'
 	unset RUMP_SERVER
 
 	return 0



CVS commit: src/tests/net/net

2016-09-15 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Fri Sep 16 00:44:14 UTC 2016

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

Log Message:
Ignore case in deprecated


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/tests/net/net/t_ipv6_lifetime.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_ipv6_lifetime.sh
diff -u src/tests/net/net/t_ipv6_lifetime.sh:1.2 src/tests/net/net/t_ipv6_lifetime.sh:1.3
--- src/tests/net/net/t_ipv6_lifetime.sh:1.2	Wed Aug 10 21:33:52 2016
+++ src/tests/net/net/t_ipv6_lifetime.sh	Fri Sep 16 00:44:14 2016
@@ -1,4 +1,4 @@
-#	$NetBSD: t_ipv6_lifetime.sh,v 1.2 2016/08/10 21:33:52 kre Exp $
+#	$NetBSD: t_ipv6_lifetime.sh,v 1.3 2016/09/16 00:44:14 ozaki-r Exp $
 #
 # Copyright (c) 2015 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -33,6 +33,8 @@ BUS=./bus
 
 DEBUG=false
 
+deprecated="[Dd][Ee][Pp][Rr][Ee][Cc][Aa][Tt][Ee][Dd]"
+
 atf_test_case basic cleanup
 
 basic_head()
@@ -69,7 +71,7 @@ basic_body()
 	atf_check -s exit:0 sleep $(($time + $bonus))
 	$DEBUG && rump.ifconfig -L shmif0
 	# Should remain but marked as deprecated
-	atf_check -s exit:0 -o match:'deprecated' rump.ifconfig -L shmif0
+	atf_check -s exit:0 -o match:"$ip.+$deprecated" rump.ifconfig -L shmif0
 	atf_check -s exit:0 rump.ifconfig shmif0 inet6 $ip delete
 
 	# Setting only a valid lifetime (invalid)
@@ -96,7 +98,7 @@ basic_body()
 	atf_check -s exit:0 sleep $(($time + $bonus))
 	$DEBUG && rump.ifconfig -L shmif0
 	# Should remain but marked as deprecated
-	atf_check -s exit:0 -o match:'deprecated' rump.ifconfig -L shmif0
+	atf_check -s exit:0 -o match:"$ip.+$deprecated" rump.ifconfig -L shmif0
 	atf_check -s exit:0 sleep $(($time + $bonus))
 	$DEBUG && rump.ifconfig -L shmif0
 	# Shouldn't remain anymore



CVS commit: src/tests/net/net

2016-09-15 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Fri Sep 16 00:44:14 UTC 2016

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

Log Message:
Ignore case in deprecated


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

2016-08-10 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Wed Aug 10 21:33:52 UTC 2016

Modified Files:
src/tests/net/net: t_forwarding.sh t_ipaddress.sh t_ipv6_lifetime.sh
t_ipv6address.sh

Log Message:
+ -lrumpdev


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/tests/net/net/t_forwarding.sh
cvs rdiff -u -r1.2 -r1.3 src/tests/net/net/t_ipaddress.sh
cvs rdiff -u -r1.1 -r1.2 src/tests/net/net/t_ipv6_lifetime.sh
cvs rdiff -u -r1.6 -r1.7 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_forwarding.sh
diff -u src/tests/net/net/t_forwarding.sh:1.14 src/tests/net/net/t_forwarding.sh:1.15
--- src/tests/net/net/t_forwarding.sh:1.14	Wed Jun 29 07:29:04 2016
+++ src/tests/net/net/t_forwarding.sh	Wed Aug 10 21:33:52 2016
@@ -1,4 +1,4 @@
-#	$NetBSD: t_forwarding.sh,v 1.14 2016/06/29 07:29:04 ozaki-r Exp $
+#	$NetBSD: t_forwarding.sh,v 1.15 2016/08/10 21:33:52 kre Exp $
 #
 # Copyright (c) 2015 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -25,8 +25,8 @@
 # POSSIBILITY OF SUCH DAMAGE.
 #
 
-inetserver="rump_server -lrumpnet -lrumpnet_net -lrumpnet_netinet -lrumpnet_shmif"
-inet6server="rump_server -lrumpnet -lrumpnet_net -lrumpnet_netinet -lrumpnet_netinet6 -lrumpnet_shmif"
+inetserver="rump_server -lrumpnet -lrumpnet_net -lrumpnet_netinet -lrumpnet_shmif -lrumpdev"
+inet6server="rump_server -lrumpnet -lrumpnet_net -lrumpnet_netinet -lrumpnet_netinet6 -lrumpnet_shmif -lrumpdev"
 
 SOCKSRC=unix://commsock1
 SOCKFWD=unix://commsock2

Index: src/tests/net/net/t_ipaddress.sh
diff -u src/tests/net/net/t_ipaddress.sh:1.2 src/tests/net/net/t_ipaddress.sh:1.3
--- src/tests/net/net/t_ipaddress.sh:1.2	Mon Apr  4 07:37:08 2016
+++ src/tests/net/net/t_ipaddress.sh	Wed Aug 10 21:33:52 2016
@@ -1,4 +1,4 @@
-#	$NetBSD: t_ipaddress.sh,v 1.2 2016/04/04 07:37:08 ozaki-r Exp $
+#	$NetBSD: t_ipaddress.sh,v 1.3 2016/08/10 21:33:52 kre Exp $
 #
 # Copyright (c) 2015 Internet Initiative Japan Inc.
 # All rights reserved.
@@ -25,7 +25,7 @@
 # POSSIBILITY OF SUCH DAMAGE.
 #
 
-SERVER="rump_server -lrumpnet -lrumpnet_net -lrumpnet_netinet -lrumpnet_shmif"
+SERVER="rump_server -lrumpnet -lrumpnet_net -lrumpnet_netinet -lrumpnet_shmif -lrumpdev"
 SERVER6="$SERVER -lrumpnet_netinet6"
 SOCK_LOCAL=unix://commsock1
 BUS=bus

Index: src/tests/net/net/t_ipv6_lifetime.sh
diff -u src/tests/net/net/t_ipv6_lifetime.sh:1.1 src/tests/net/net/t_ipv6_lifetime.sh:1.2
--- src/tests/net/net/t_ipv6_lifetime.sh:1.1	Thu Aug  6 08:23:14 2015
+++ src/tests/net/net/t_ipv6_lifetime.sh	Wed Aug 10 21:33:52 2016
@@ -1,4 +1,4 @@
-#	$NetBSD: t_ipv6_lifetime.sh,v 1.1 2015/08/06 08:23:14 ozaki-r Exp $
+#	$NetBSD: t_ipv6_lifetime.sh,v 1.2 2016/08/10 21:33:52 kre Exp $
 #
 # Copyright (c) 2015 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -25,7 +25,7 @@
 # POSSIBILITY OF SUCH DAMAGE.
 #
 
-INET6SERVER="rump_server -lrumpnet -lrumpnet_net -lrumpnet_netinet"
+INET6SERVER="rump_server -lrumpnet -lrumpnet_net -lrumpnet_netinet -lrumpdev"
 INET6SERVER="$INET6SERVER -lrumpnet_netinet6 -lrumpnet_shmif"
 
 SOCK=unix://sock

Index: src/tests/net/net/t_ipv6address.sh
diff -u src/tests/net/net/t_ipv6address.sh:1.6 src/tests/net/net/t_ipv6address.sh:1.7
--- src/tests/net/net/t_ipv6address.sh:1.6	Sun Mar 13 17:26:05 2016
+++ src/tests/net/net/t_ipv6address.sh	Wed Aug 10 21:33:52 2016
@@ -1,4 +1,4 @@
-#	$NetBSD: t_ipv6address.sh,v 1.6 2016/03/13 17:26:05 ozaki-r Exp $
+#	$NetBSD: t_ipv6address.sh,v 1.7 2016/08/10 21:33:52 kre Exp $
 #
 # Copyright (c) 2015 Internet Initiative Japan Inc.
 # All rights reserved.
@@ -24,7 +24,7 @@
 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 # POSSIBILITY OF SUCH DAMAGE.
 
-SERVER="rump_server -lrumpnet -lrumpnet_net -lrumpnet_netinet -lrumpnet_shmif"
+SERVER="rump_server -lrumpnet -lrumpnet_net -lrumpnet_netinet -lrumpnet_shmif -lrumpdev"
 SERVER6="$SERVER -lrumpnet_netinet6"
 
 SOCKSRC=unix://commsock1



CVS commit: src/tests/net/net

2016-08-10 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Wed Aug 10 21:33:52 UTC 2016

Modified Files:
src/tests/net/net: t_forwarding.sh t_ipaddress.sh t_ipv6_lifetime.sh
t_ipv6address.sh

Log Message:
+ -lrumpdev


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/tests/net/net/t_forwarding.sh
cvs rdiff -u -r1.2 -r1.3 src/tests/net/net/t_ipaddress.sh
cvs rdiff -u -r1.1 -r1.2 src/tests/net/net/t_ipv6_lifetime.sh
cvs rdiff -u -r1.6 -r1.7 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.



  1   2   >