From 856440c0941992f6b32cd92f9f688e4aaa816c02 Mon Sep 17 00:00:00 2001 From: roy Date: Wed, 30 Sep 2020 14:43:15 +0000 Subject: [PATCH] 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 --- tests/net/if_tap/Makefile | 7 ++- tests/net/if_tap/rump_open_tap.c | 79 ++++++++++++++++++++++++++++++++ tests/net/if_tap/t_tap.sh | 28 +++++++++-- 3 files changed, 109 insertions(+), 5 deletions(-) create mode 100644 tests/net/if_tap/rump_open_tap.c diff --git a/tests/net/if_tap/Makefile b/tests/net/if_tap/Makefile index e3d06c930c44..e8b55ffaf242 100644 --- a/tests/net/if_tap/Makefile +++ b/tests/net/if_tap/Makefile @@ -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 +PROG= rump_open_tap +MAN= +DPADD= ${LIBRUMPRES} +LDADD= -lrumpres + TESTSDIR= ${TESTSBASE}/net/if_tap .for name in tap diff --git a/tests/net/if_tap/rump_open_tap.c b/tests/net/if_tap/rump_open_tap.c new file mode 100644 index 000000000000..9701dc724838 --- /dev/null +++ b/tests/net/if_tap/rump_open_tap.c @@ -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 +__RCSID("$NetBSD: rump_open_tap.c,v 1.1 2020/09/30 14:43:15 roy Exp $"); + +#include +#include +#include +#include +#include + +#include +#include + +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); +} diff --git a/tests/net/if_tap/t_tap.sh b/tests/net/if_tap/t_tap.sh index 5d4bb4fa7a82..1b60731d9037 100644 --- a/tests/net/if_tap/t_tap.sh +++ b/tests/net/if_tap/t_tap.sh @@ -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 }