Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/tests/net/if_vlan added tests for IFF_PROMISC of vlan(4)
details: https://anonhg.NetBSD.org/src/rev/a45a1c03d784
branches: trunk
changeset: 984463:a45a1c03d784
user: yamaguchi <yamaguchi%NetBSD.org@localhost>
date: Fri Jul 09 05:54:11 2021 +0000
description:
added tests for IFF_PROMISC of vlan(4)
diffstat:
distrib/sets/lists/debug/mi | 3 +-
distrib/sets/lists/tests/mi | 3 +-
tests/net/if_vlan/Makefile | 6 +-
tests/net/if_vlan/bpfopen.c | 153 ++++++++++++++++++++++++++++++++++++++++++++
tests/net/if_vlan/t_vlan.sh | 101 ++++++++++++++++++++++++++++-
tests/net/net_common.sh | 21 +++++-
6 files changed, 282 insertions(+), 5 deletions(-)
diffs (truncated from 373 to 300 lines):
diff -r c768eabe99e4 -r a45a1c03d784 distrib/sets/lists/debug/mi
--- a/distrib/sets/lists/debug/mi Fri Jul 09 01:29:20 2021 +0000
+++ b/distrib/sets/lists/debug/mi Fri Jul 09 05:54:11 2021 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.354 2021/07/08 09:16:24 christos Exp $
+# $NetBSD: mi,v 1.355 2021/07/09 05:54:11 yamaguchi Exp $
./etc/mtree/set.debug comp-sys-root
./usr/lib comp-sys-usr compatdir
./usr/lib/i18n/libBIG5_g.a comp-c-debuglib debuglib,compatfile
@@ -2396,6 +2396,7 @@
./usr/libdata/debug/usr/tests/net/if/t_compat.debug tests-net-debug debug,atf,rump
./usr/libdata/debug/usr/tests/net/if_loop/t_pr.debug tests-net-debug debug,atf,rump
./usr/libdata/debug/usr/tests/net/if_tap/rump_open_tap.debug tests-net-debug debug,atf,rump
+./usr/libdata/debug/usr/tests/net/if_vlan/bpfopen.debug tests-net-debug debug,atf,rump
./usr/libdata/debug/usr/tests/net/if_vlan/siocXmulti.debug tests-net-debug debug,atf,rump
./usr/libdata/debug/usr/tests/net/in_cksum/in_cksum.debug tests-net-debug debug,atf,compattestfile
./usr/libdata/debug/usr/tests/net/ipsec/natt_terminator.debug tests-net-debug debug,atf,rump
diff -r c768eabe99e4 -r a45a1c03d784 distrib/sets/lists/tests/mi
--- a/distrib/sets/lists/tests/mi Fri Jul 09 01:29:20 2021 +0000
+++ b/distrib/sets/lists/tests/mi Fri Jul 09 05:54:11 2021 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1079 2021/07/08 09:16:24 christos Exp $
+# $NetBSD: mi,v 1.1080 2021/07/09 05:54:11 yamaguchi Exp $
#
# Note: don't delete entries from here - mark them as "obsolete" instead.
#
@@ -4142,6 +4142,7 @@
./usr/tests/net/if_vlan tests-net-tests compattestfile,atf
./usr/tests/net/if_vlan/Atffile tests-net-tests atf,rump
./usr/tests/net/if_vlan/Kyuafile tests-net-tests atf,rump,kyua
+./usr/tests/net/if_vlan/bpfopen tests-net-tests atf,rump
./usr/tests/net/if_vlan/siocXmulti tests-net-tests atf,rump
./usr/tests/net/if_vlan/t_vlan tests-net-tests atf,rump
./usr/tests/net/if_wg tests-net-tests compattestfile,atf
diff -r c768eabe99e4 -r a45a1c03d784 tests/net/if_vlan/Makefile
--- a/tests/net/if_vlan/Makefile Fri Jul 09 01:29:20 2021 +0000
+++ b/tests/net/if_vlan/Makefile Fri Jul 09 05:54:11 2021 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.2 2018/06/14 08:22:52 yamaguchi Exp $
+# $NetBSD: Makefile,v 1.3 2021/07/09 05:54:11 yamaguchi Exp $
#
.include <bsd.own.mk>
@@ -14,4 +14,8 @@
MAN.siocXmulti= #empty
BINDIR.siocXmulti= ${TESTSDIR}
+PROGS+= bpfopen
+MAN.bpfopen= #empty
+BINDIR.bpfopen= ${TESTSDIR}
+
.include <bsd.test.mk>
diff -r c768eabe99e4 -r a45a1c03d784 tests/net/if_vlan/bpfopen.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/net/if_vlan/bpfopen.c Fri Jul 09 05:54:11 2021 +0000
@@ -0,0 +1,153 @@
+/* $NetBSD: bpfopen.c,v 1.1 2021/07/09 05:54:11 yamaguchi Exp $ */
+
+/*
+ * Copyright (c) 2021 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.
+ */
+
+#include <sys/cdefs.h>
+__RCSID("$NetBSD: bpfopen.c,v 1.1 2021/07/09 05:54:11 yamaguchi Exp $");
+
+#include <sys/param.h>
+#include <sys/ioctl.h>
+
+#include <net/if.h>
+#include <net/bpf.h>
+
+#include <err.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <poll.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <signal.h>
+#include <unistd.h>
+
+enum {
+ ARG_PROG = 0,
+ ARG_HOST,
+ ARG_IFNAME,
+ ARG_NUM
+};
+
+enum {
+ PFD_BPF = 0,
+ PFD_NUM
+};
+
+static void sighandler(int);
+
+static sig_atomic_t quit;
+
+static void
+usage(void)
+{
+
+ fprintf(stderr, "%s {-r|-h} <ifname>\n"
+ "\t-r: rump_server\n"
+ "\t-h: host\n",
+ getprogname());
+ exit(1);
+}
+
+int
+main(int argc, char *argv[])
+{
+ struct ifreq ifr;
+ struct pollfd pfd[PFD_NUM];
+ const char *bpf_path;
+ int n, bpfd, nfds;
+ size_t bufsiz;
+ char *buf;
+
+ if (argc != ARG_NUM)
+ usage();
+
+ if (strcmp(argv[ARG_HOST], "-h") == 0) {
+ bpf_path = "/dev/bpf";
+ } else if (strcmp(argv[ARG_HOST], "-r") == 0){
+ bpf_path = "/rump/dev/bpf";
+ } else {
+ errx(1, "-r or -h");
+ }
+
+ bpfd = open(bpf_path, O_RDONLY);
+ if (bpfd < 0)
+ err(1, "open %s", bpf_path);
+
+ memset(&ifr, 0, sizeof(ifr));
+ strlcpy(ifr.ifr_name, argv[ARG_IFNAME],
+ sizeof(ifr.ifr_name));
+ if (ioctl(bpfd, BIOCSETIF, &ifr) != 0)
+ err(1, "BIOCSETIF");
+ if (ioctl(bpfd, BIOCPROMISC, NULL) != 0)
+ err(1, "BIOCPROMISC");
+ if (ioctl(bpfd, BIOCGBLEN, &bufsiz) != 0)
+ err(1, "BIOCGBLEN");
+ bufsiz = MIN(bufsiz, BPF_DFLTBUFSIZE * 4);
+
+ buf = malloc(bufsiz);
+ if (buf == NULL)
+ err(1, "malloc");
+
+ quit = 0;
+ signal(SIGTERM, sighandler);
+ signal(SIGQUIT, sighandler);
+ signal(SIGINT, sighandler);
+ signal(SIGHUP, sighandler);
+
+ fprintf(stderr, "bpf open %s\n", ifr.ifr_name);
+ while (quit == 0) {
+ pfd[PFD_BPF].fd = bpfd;
+ pfd[PFD_BPF].events = POLLIN;
+
+ nfds = poll(pfd, PFD_NUM, 1 * 1000);
+ if (nfds == -1 && errno != EINTR) {
+ warn("poll");
+ quit = 1;
+ }
+
+ if (nfds > 0 && (pfd[PFD_BPF].revents & POLLIN)) {
+ /* read & drop */
+ memset(buf, 0, sizeof(bufsiz));
+ n = read(pfd[PFD_BPF].fd, buf, bufsiz);
+ if (n < 0)
+ quit = 1;
+ }
+ }
+
+ close(bpfd);
+ free(buf);
+ fprintf(stderr, "closed\n");
+
+ return 0;
+}
+
+static void
+sighandler(int signo)
+{
+
+ quit = 1;
+}
diff -r c768eabe99e4 -r a45a1c03d784 tests/net/if_vlan/t_vlan.sh
--- a/tests/net/if_vlan/t_vlan.sh Fri Jul 09 01:29:20 2021 +0000
+++ b/tests/net/if_vlan/t_vlan.sh Fri Jul 09 05:54:11 2021 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: t_vlan.sh,v 1.19 2021/07/06 01:18:22 yamaguchi Exp $
+# $NetBSD: t_vlan.sh,v 1.20 2021/07/09 05:54:11 yamaguchi Exp $
#
# Copyright (c) 2016 Internet Initiative Japan Inc.
# All rights reserved.
@@ -897,6 +897,104 @@
cleanup
}
+atf_test_case vlan_promisc cleanup
+vlan_promisc_head()
+{
+
+ atf_set "descr" "tests of IFF_PROMISC of vlan"
+ atf_set "require.progs" "rump_server"
+}
+
+vlan_promisc_body()
+{
+ local atf_ifconfig="atf_check -s exit:0 rump.ifconfig"
+ local atf_brconfig="atf_check -s exit:0 $HIJACKING /sbin/brconfig"
+ local atf_arp="atf_check -s exit:0 rump.arp"
+ local bpfopen="$HIJACKING $(atf_get_srcdir)/bpfopen"
+ local macaddr=""
+
+ rump_server_bpf_start $SOCK_LOCAL vlan bridge
+ rump_server_start $SOCK_REMOTE vlan
+
+ rump_server_add_iface $SOCK_LOCAL shmif0 $BUS
+ rump_server_add_iface $SOCK_LOCAL shmif1
+ rump_server_add_iface $SOCK_LOCAL vlan0
+ rump_server_add_iface $SOCK_LOCAL vlan1
+ rump_server_add_iface $SOCK_LOCAL bridge0
+
+ rump_server_add_iface $SOCK_REMOTE shmif0 $BUS
+ rump_server_add_iface $SOCK_REMOTE vlan0
+
+ macaddr=$(get_macaddr $SOCK_LOCAL shmif1)
+
+ export RUMP_SERVER=$SOCK_REMOTE
+ $atf_ifconfig vlan0 vlan 1 vlanif shmif0
+ $atf_ifconfig shmif0 up
+ $atf_ifconfig vlan0 inet $IP_REMOTE0/24
+ $atf_ifconfig vlan0 up
+ $atf_ifconfig -w 10
+ $atf_arp -s $IP_LOCAL0 $macaddr
+
+ export RUMP_SERVER=$SOCK_LOCAL
+ $atf_ifconfig bridge0 mtu 1496
+ #
+ # When vlan IF is PROMISC, the parent is also PROMISC
+ #
+ $atf_ifconfig vlan0 vlan 1 vlanif shmif0
+ $atf_ifconfig shmif0 up
+ $atf_ifconfig vlan0 up
+
+ atf_check -s exit:0 -o not-match:'PROMISC' rump.ifconfig vlan0
+ atf_check -s exit:0 -o not-match:'PROMISC' rump.ifconfig shmif0
+
+ $atf_brconfig bridge0 add vlan0
+ $atf_ifconfig bridge0 up
+ atf_check -s exit:0 -o match:'PROMISC' rump.ifconfig vlan0
+ atf_check -s exit:0 -o match:'PROMISC' rump.ifconfig shmif0
+
+ $atf_ifconfig bridge0 down
+ $atf_brconfig bridge0 delete vlan0
+ atf_check -s exit:0 -o not-match:'PROMISC' rump.ifconfig vlan0
+ atf_check -s exit:0 -o not-match:'PROMISC' rump.ifconfig shmif0
+ $atf_ifconfig vlan0 -vlanif
+
+ #
+ # drop unicast packets that is not for the host
+ #
+ $atf_ifconfig vlan0 vlan 1 vlanif shmif0
+ $atf_ifconfig -w 10
+
+ $bpfopen -r shmif0 &
+ pid=$!
+
+ atf_check -s exit:0 -o not-match:'PROMISC' rump.ifconfig vlan0
+ atf_check -s exit:0 -o match:'PROMISC' rump.ifconfig shmif0
+ atf_check -s exit:0 -o ignore rump.ifconfig -z vlan0
+ atf_check -s exit:0 -o not-match:'input:.*errors' \
+ rump.ifconfig -v vlan0
+
+ export RUMP_SERVER=$SOCK_REMOTE
+ atf_check -s not-exit:0 -o ignore -e ignore \
Home |
Main Index |
Thread Index |
Old Index