Module Name: src Committed By: yamaguchi Date: Fri Jul 9 05:54:11 UTC 2021
Modified Files: src/distrib/sets/lists/debug: mi src/distrib/sets/lists/tests: mi src/tests/net: net_common.sh src/tests/net/if_vlan: Makefile t_vlan.sh Added Files: src/tests/net/if_vlan: bpfopen.c Log Message: added tests for IFF_PROMISC of vlan(4) To generate a diff of this commit: cvs rdiff -u -r1.354 -r1.355 src/distrib/sets/lists/debug/mi cvs rdiff -u -r1.1079 -r1.1080 src/distrib/sets/lists/tests/mi cvs rdiff -u -r1.41 -r1.42 src/tests/net/net_common.sh cvs rdiff -u -r1.2 -r1.3 src/tests/net/if_vlan/Makefile cvs rdiff -u -r0 -r1.1 src/tests/net/if_vlan/bpfopen.c cvs rdiff -u -r1.19 -r1.20 src/tests/net/if_vlan/t_vlan.sh Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/distrib/sets/lists/debug/mi diff -u src/distrib/sets/lists/debug/mi:1.354 src/distrib/sets/lists/debug/mi:1.355 --- src/distrib/sets/lists/debug/mi:1.354 Thu Jul 8 09:16:24 2021 +++ src/distrib/sets/lists/debug/mi Fri Jul 9 05:54:11 2021 @@ -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 Index: src/distrib/sets/lists/tests/mi diff -u src/distrib/sets/lists/tests/mi:1.1079 src/distrib/sets/lists/tests/mi:1.1080 --- src/distrib/sets/lists/tests/mi:1.1079 Thu Jul 8 09:16:24 2021 +++ src/distrib/sets/lists/tests/mi Fri Jul 9 05:54:11 2021 @@ -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 Index: src/tests/net/net_common.sh diff -u src/tests/net/net_common.sh:1.41 src/tests/net/net_common.sh:1.42 --- src/tests/net/net_common.sh:1.41 Wed Apr 1 00:49:04 2020 +++ src/tests/net/net_common.sh Fri Jul 9 05:54:11 2021 @@ -1,4 +1,4 @@ -# $NetBSD: net_common.sh,v 1.41 2020/04/01 00:49:04 christos Exp $ +# $NetBSD: net_common.sh,v 1.42 2021/07/09 05:54:11 yamaguchi Exp $ # # Copyright (c) 2016 Internet Initiative Japan Inc. # All rights reserved. @@ -180,6 +180,7 @@ CRYPTO_LIBS="$BASIC_LIBS -lrumpdev -lrum -lrumpkern_z -lrumpkern_crypto" NPF_LIBS="$BASIC_LIBS -lrumpdev -lrumpvfs -lrumpdev_bpf -lrumpnet_npf" CRYPTO_NPF_LIBS="$CRYPTO_LIBS -lrumpvfs -lrumpdev_bpf -lrumpnet_npf" +BPF_LIBS="$BASIC_LIBS -lrumpdev -lrumpvfs -lrumpdev_bpf" # We cannot keep variables between test phases, so need to store in files _rump_server_socks=./.__socks @@ -315,6 +316,24 @@ rump_server_crypto_npf_start() return 0 } +rump_server_bpf_start() +{ + local sock=$1 + local lib= + local libs="$BPF_LIBS" + + shift 1 + + for lib + do + libs="$libs -lrumpnet_$lib" + done + + _rump_server_start_common $sock $libs + + return 0 +} + rump_server_add_iface() { local sock=$1 Index: src/tests/net/if_vlan/Makefile diff -u src/tests/net/if_vlan/Makefile:1.2 src/tests/net/if_vlan/Makefile:1.3 --- src/tests/net/if_vlan/Makefile:1.2 Thu Jun 14 08:22:52 2018 +++ src/tests/net/if_vlan/Makefile Fri Jul 9 05:54:11 2021 @@ -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 @@ PROGS= siocXmulti MAN.siocXmulti= #empty BINDIR.siocXmulti= ${TESTSDIR} +PROGS+= bpfopen +MAN.bpfopen= #empty +BINDIR.bpfopen= ${TESTSDIR} + .include <bsd.test.mk> Index: src/tests/net/if_vlan/t_vlan.sh diff -u src/tests/net/if_vlan/t_vlan.sh:1.19 src/tests/net/if_vlan/t_vlan.sh:1.20 --- src/tests/net/if_vlan/t_vlan.sh:1.19 Tue Jul 6 01:18:22 2021 +++ src/tests/net/if_vlan/t_vlan.sh Fri Jul 9 05:54:11 2021 @@ -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 @@ vlan_multicast6_cleanup() 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 \ + rump.ping -c 3 -i 0.2 $IP_LOCAL0 + + export RUMP_SERVER=$SOCK_LOCAL + atf_check -s exit:0 -o match:'input:.*errors' \ + rump.ifconfig -v vlan0 + + kill -TERM $pid + sleep 2 + + atf_check -s exit:0 -o not-match:'PROMISC' rump.ifconfig vlan0 + atf_check -s exit:0 -o not-match:'PROMISC' rump.ifconfig shmif0 +} + +vlan_promisc_cleanup() +{ + + $DEBUG && dump + cleanup +} + atf_init_test_cases() { @@ -907,6 +1005,7 @@ atf_init_test_cases() atf_add_test_case vlan_configs atf_add_test_case vlan_bridge atf_add_test_case vlan_multicast + atf_add_test_case vlan_promisc atf_add_test_case vlan_create_destroy6 atf_add_test_case vlan_basic6 Added files: Index: src/tests/net/if_vlan/bpfopen.c diff -u /dev/null src/tests/net/if_vlan/bpfopen.c:1.1 --- /dev/null Fri Jul 9 05:54:11 2021 +++ src/tests/net/if_vlan/bpfopen.c Fri Jul 9 05:54:11 2021 @@ -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; +}