Module Name:    src
Committed By:   roy
Date:           Wed Sep 30 14:43:15 UTC 2020

Modified Files:
        src/tests/net/if_tap: Makefile t_tap.sh
Added Files:
        src/tests/net/if_tap: rump_open_tap.c

Log Message:
tap(4): update the test so that we can open the tap to ping across a bridge

ping with tap closed to ensure it fails
ping with tap open to ensure it works


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/tests/net/if_tap/Makefile
cvs rdiff -u -r0 -r1.1 src/tests/net/if_tap/rump_open_tap.c
cvs rdiff -u -r1.10 -r1.11 src/tests/net/if_tap/t_tap.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/if_tap/Makefile
diff -u src/tests/net/if_tap/Makefile:1.2 src/tests/net/if_tap/Makefile:1.3
--- src/tests/net/if_tap/Makefile:1.2	Fri Nov 25 08:51:16 2016
+++ src/tests/net/if_tap/Makefile	Wed Sep 30 14:43:15 2020
@@ -1,8 +1,13 @@
-# $NetBSD: Makefile,v 1.2 2016/11/25 08:51:16 ozaki-r Exp $
+# $NetBSD: Makefile,v 1.3 2020/09/30 14:43:15 roy Exp $
 #
 
 .include <bsd.own.mk>
 
+PROG=		rump_open_tap
+MAN=
+DPADD=		${LIBRUMPRES}
+LDADD=		-lrumpres
+
 TESTSDIR=	${TESTSBASE}/net/if_tap
 
 .for name in tap

Index: src/tests/net/if_tap/t_tap.sh
diff -u src/tests/net/if_tap/t_tap.sh:1.10 src/tests/net/if_tap/t_tap.sh:1.11
--- src/tests/net/if_tap/t_tap.sh:1.10	Mon Aug 19 03:22:05 2019
+++ src/tests/net/if_tap/t_tap.sh	Wed Sep 30 14:43:15 2020
@@ -1,4 +1,4 @@
-#	$NetBSD: t_tap.sh,v 1.10 2019/08/19 03:22:05 ozaki-r Exp $
+#	$NetBSD: t_tap.sh,v 1.11 2020/09/30 14:43:15 roy Exp $
 #
 # Copyright (c) 2016 Internet Initiative Japan Inc.
 # All rights reserved.
@@ -34,6 +34,7 @@ IP4_REMOTE=10.0.0.3
 IP6_LOCAL=fc00::1
 IP6_TAP=fc00::2
 IP6_REMOTE=fc00::3
+TAP_PID=./.__tap.pid
 
 DEBUG=${DEBUG:-false}
 TIMEOUT=1
@@ -130,6 +131,7 @@ tap_bridged_head()
 
 tap_bridged_body()
 {
+	local src="$(atf_get_srcdir)"
 
 	rump_server_fs_start $SOCK_LOCAL netinet6 tap bridge
 	rump_server_fs_start $SOCK_REMOTE netinet6 tap
@@ -146,7 +148,6 @@ tap_bridged_body()
 	atf_check -s exit:0 rump.ifconfig tap0 $IP4_TAP
 	atf_check -s exit:0 rump.ifconfig tap0 inet6 $IP6_TAP
 	atf_check -s exit:0 rump.ifconfig tap0 up
-	atf_check -s exit:0 rump.ifconfig -w 10
 
 	rump_server_add_iface $SOCK_LOCAL bridge0
 	atf_check -s exit:0 rump.ifconfig bridge0 up
@@ -155,6 +156,8 @@ tap_bridged_body()
 	atf_check -s exit:0 brconfig bridge0 add tap0
 	unset LD_PRELOAD
 
+	atf_check -s exit:0 rump.ifconfig -w 10
+
 	export RUMP_SERVER=${SOCK_REMOTE}
 
 	atf_check -s exit:0 rump.ifconfig shmif0 $IP4_REMOTE
@@ -162,10 +165,22 @@ tap_bridged_body()
 	atf_check -s exit:0 rump.ifconfig shmif0 up
 	atf_check -s exit:0 rump.ifconfig -w 10
 
+	# shmif0 on the server bridge is active, we expect this to work
 	atf_check -s exit:0 -o ignore rump.ping -n -w $TIMEOUT -c 1 $IP4_LOCAL
-	atf_check -s exit:0 -o ignore rump.ping -n -w $TIMEOUT -c 1 $IP4_TAP
-
 	atf_check -s exit:0 -o ignore rump.ping6 -n -X $TIMEOUT -c 1 $IP6_LOCAL
+
+	# The tap is not open, we expect this to fail
+	atf_check -s not-exit:0 -o ignore rump.ping -n -w $TIMEOUT -c 1 $IP4_TAP
+	atf_check -s not-exit:0 -o ignore rump.ping6 -n -X $TIMEOUT -c 1 $IP6_TAP
+
+	# Open the tap on the server
+	export RUMP_SERVER=${SOCK_LOCAL}
+	atf_check -s exit:0 "$src"/rump_open_tap /dev/tap0 $TAP_PID
+	atf_check -s exit:0 rump.ifconfig -w 10
+
+	# Now we can ping the tap address
+	export RUMP_SERVER=${SOCK_LOCAL}
+	atf_check -s exit:0 -o ignore rump.ping -n -w $TIMEOUT -c 1 $IP4_TAP
 	atf_check -s exit:0 -o ignore rump.ping6 -n -X $TIMEOUT -c 1 $IP6_TAP
 
 	rump_server_destroy_ifaces
@@ -174,6 +189,11 @@ tap_bridged_body()
 tap_bridged_cleanup()
 {
 
+        if [ -f $TAP_PID ]; then
+		kill -9 $(cat $TAP_PID)
+		rm -f $TAP_PID
+		sleep 1
+	fi
 	$DEBUG && dump
 	cleanup
 }

Added files:

Index: src/tests/net/if_tap/rump_open_tap.c
diff -u /dev/null src/tests/net/if_tap/rump_open_tap.c:1.1
--- /dev/null	Wed Sep 30 14:43:15 2020
+++ src/tests/net/if_tap/rump_open_tap.c	Wed Sep 30 14:43:15 2020
@@ -0,0 +1,79 @@
+/* $NetBSD: rump_open_tap.c,v 1.1 2020/09/30 14:43:15 roy Exp $ */
+
+/*
+ * Copyright (c) 2020 The NetBSD Foundation, Inc.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Roy Marples.
+ *
+ * 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 ``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 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 <sys/cdefs.h>
+__RCSID("$NetBSD: rump_open_tap.c,v 1.1 2020/09/30 14:43:15 roy Exp $");
+
+#include <err.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include <rump/rump_syscalls.h>
+#include <rump/rumpclient.h>
+
+int
+main(int argc, char **argv)
+{
+	int fd;
+
+	if (argc < 2)
+		errx(EXIT_FAILURE, "No path specified");
+
+	rumpclient_init();
+
+	fd = rump_sys_open(argv[1], O_RDWR);
+	if (fd == -1)
+		err(EXIT_FAILURE, "open: %s", argv[1]);
+
+	if (argc > 2) {
+		FILE *fp;
+		pid_t pid;
+
+		fp = fopen(argv[2], "w");
+		if (fp == NULL)
+			err(EXIT_FAILURE, "fopen: %s", argv[2]);
+
+		pid = fork();
+		switch (pid) {
+		case -1:
+			err(EXIT_FAILURE, "fork");
+		case 0:
+			break;
+		default:
+			fprintf(fp, "%d\n", pid);
+			exit(EXIT_SUCCESS);
+		}
+	}
+
+	/* Spin with the fd open */
+	for (;;)
+		sleep(100);
+}

Reply via email to