Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src Add test cases for multicast address handling of vlan(4)



details:   https://anonhg.NetBSD.org/src/rev/5f01f6a26178
branches:  trunk
changeset: 323406:5f01f6a26178
user:      yamaguchi <yamaguchi%NetBSD.org@localhost>
date:      Thu Jun 14 08:22:52 2018 +0000

description:
Add test cases for multicast address handling of vlan(4)

ok ozaki-r@

diffstat:

 distrib/sets/lists/debug/mi    |    3 +-
 distrib/sets/lists/tests/mi    |    3 +-
 tests/net/if_vlan/Makefile     |    6 +-
 tests/net/if_vlan/siocXmulti.c |   88 ++++++++++++++++++++++++++++
 tests/net/if_vlan/t_vlan.sh    |  125 ++++++++++++++++++++++++++++++++++++++++-
 5 files changed, 221 insertions(+), 4 deletions(-)

diffs (truncated from 305 to 300 lines):

diff -r 0c841ef1514b -r 5f01f6a26178 distrib/sets/lists/debug/mi
--- a/distrib/sets/lists/debug/mi       Thu Jun 14 08:06:07 2018 +0000
+++ b/distrib/sets/lists/debug/mi       Thu Jun 14 08:22:52 2018 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.250 2018/05/28 21:05:00 chs Exp $
+# $NetBSD: mi,v 1.251 2018/06/14 08:22:52 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
@@ -2294,6 +2294,7 @@
 ./usr/libdata/debug/usr/tests/net/if/ifconf.debug              tests-net-debug         debug,atf,rump
 ./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_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
 ./usr/libdata/debug/usr/tests/net/mcast/mcast.debug            tests-net-debug         debug,atf,rump
diff -r 0c841ef1514b -r 5f01f6a26178 distrib/sets/lists/tests/mi
--- a/distrib/sets/lists/tests/mi       Thu Jun 14 08:06:07 2018 +0000
+++ b/distrib/sets/lists/tests/mi       Thu Jun 14 08:22:52 2018 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.785 2018/05/25 15:42:48 martin Exp $
+# $NetBSD: mi,v 1.786 2018/06/14 08:22:52 yamaguchi Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -3332,6 +3332,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/siocXmulti             tests-net-tests         atf,rump
 ./usr/tests/net/if_vlan/t_vlan                 tests-net-tests         atf,rump
 ./usr/tests/net/in_cksum                       tests-net-tests         compattestfile,atf
 ./usr/tests/net/in_cksum/Atffile               tests-net-tests         compattestfile,atf
diff -r 0c841ef1514b -r 5f01f6a26178 tests/net/if_vlan/Makefile
--- a/tests/net/if_vlan/Makefile        Thu Jun 14 08:06:07 2018 +0000
+++ b/tests/net/if_vlan/Makefile        Thu Jun 14 08:22:52 2018 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.1 2016/11/26 03:19:49 ozaki-r Exp $
+# $NetBSD: Makefile,v 1.2 2018/06/14 08:22:52 yamaguchi Exp $
 #
 
 .include <bsd.own.mk>
@@ -10,4 +10,8 @@
 TESTS_SH_SRC_t_${name}=        ../net_common.sh t_${name}.sh
 .endfor
 
+PROGS=                 siocXmulti
+MAN.siocXmulti=                #empty
+BINDIR.siocXmulti=     ${TESTSDIR}
+
 .include <bsd.test.mk>
diff -r 0c841ef1514b -r 5f01f6a26178 tests/net/if_vlan/siocXmulti.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/net/if_vlan/siocXmulti.c    Thu Jun 14 08:22:52 2018 +0000
@@ -0,0 +1,88 @@
+
+#include <sys/socket.h>
+#include <sys/ioctl.h>
+
+#include <net/if.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <strings.h>
+#include <unistd.h>
+#include <err.h>
+
+enum{
+       ARG_PROG = 0,
+       ARG_OP,
+       ARG_IFNAME,
+       ARG_ADDR,
+       ARG_NUM
+};
+
+static void
+usage(void)
+{
+
+       printf("%s <add|del> <ifname> <IPv4 addr>\n",
+           getprogname());
+       exit(1);
+}
+
+int
+main(int argc, char *argv[])
+{
+       int                      fd, rv;
+       unsigned long            req;
+       struct ifreq             ifr;
+       unsigned int             ifidx;
+       struct sockaddr_in      *sin;
+       struct sockaddr_in6     *sin6;
+
+       bzero(&ifr, sizeof(ifr));
+
+       if (argc != ARG_NUM)
+               usage();
+
+       if (strcmp(argv[ARG_OP], "add") == 0)
+               req = SIOCADDMULTI;
+       else if (strcmp(argv[ARG_OP], "del") == 0)
+               req = SIOCDELMULTI;
+       else
+               usage();
+
+       ifidx = if_nametoindex(argv[ARG_IFNAME]);
+       if (ifidx == 0)
+               err(1, "if_nametoindex(%s)", argv[ARG_IFNAME]);
+
+       strncpy(ifr.ifr_name, argv[ARG_IFNAME], sizeof(ifr.ifr_name));
+
+       sin = (struct sockaddr_in *)&ifr.ifr_addr;
+       sin->sin_family = AF_INET;
+       sin->sin_len = sizeof(*sin);
+       rv = inet_pton(AF_INET, argv[ARG_ADDR], &sin->sin_addr);
+
+       if (rv != 1) {
+               sin6 = (struct sockaddr_in6 *)&ifr.ifr_addr;
+               sin6->sin6_family = AF_INET6;
+               sin6->sin6_len = sizeof(*sin6);
+               rv = inet_pton(AF_INET6, argv[ARG_ADDR], &sin6->sin6_addr);
+
+               if (rv != 1)
+                       errx(1, "inet_pton(%s)", argv[ARG_ADDR]);
+       }
+
+       fd = socket(AF_INET, SOCK_DGRAM, 0);
+       if (fd < 0)
+               err(1, "socket");
+
+       if (ioctl(fd, req, (caddr_t)&ifr) < 0) {
+               err(1, "ioctl(%s)",
+                   (req == SIOCADDMULTI) ? "SIOCADDMULTI" : "SIOCDELMULTI");
+       }
+
+       close(fd);
+
+       return 0;
+}
diff -r 0c841ef1514b -r 5f01f6a26178 tests/net/if_vlan/t_vlan.sh
--- a/tests/net/if_vlan/t_vlan.sh       Thu Jun 14 08:06:07 2018 +0000
+++ b/tests/net/if_vlan/t_vlan.sh       Thu Jun 14 08:22:52 2018 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: t_vlan.sh,v 1.9 2018/06/12 04:21:22 ozaki-r Exp $
+#      $NetBSD: t_vlan.sh,v 1.10 2018/06/14 08:22:52 yamaguchi Exp $
 #
 # Copyright (c) 2016 Internet Initiative Japan Inc.
 # All rights reserved.
@@ -32,10 +32,14 @@
 IP_LOCAL1=10.0.1.1
 IP_REMOTE0=10.0.0.2
 IP_REMOTE1=10.0.1.2
+IP_MCADDR0=224.0.0.10
 IP6_LOCAL0=fc00:0::1
 IP6_LOCAL1=fc00:1::1
 IP6_REMOTE0=fc00:0::2
 IP6_REMOTE1=fc00:1::2
+IP6_MCADDR0=ff11::10
+ETH_IP_MCADDR0=01:00:5e:00:00:0a
+ETH_IP6_MCADDR0=33:33:00:00:00:10
 
 DEBUG=${DEBUG:-false}
 
@@ -598,6 +602,123 @@
        cleanup
 }
 
+vlan_multicast_body_common()
+{
+
+       local af="inet"
+       local local0=$IP_LOCAL0
+       local local1=$IP_LOCAL1
+       local mcaddr=$IP_MCADDR0
+       local eth_mcaddr=$ETH_IP_MCADDR0
+       local prefix=24
+       local siocXmulti="$(atf_get_srcdir)/siocXmulti"
+
+       if [ x"$1" =  x"inet6" ]; then
+               af="inet6"
+               prefix=64
+               local0=$IP6_LOCAL0
+               local1=$IP6_LOCAL1
+               mcaddr=$IP6_MCADDR0
+               eth_mcaddr=$ETH_IP6_MCADDR0
+       fi
+
+       export RUMP_SERVER=$SOCK_LOCAL
+
+       atf_check -s exit:0 rump.ifconfig shmif0 create
+       atf_check -s exit:0 rump.ifconfig shmif0 linkstr net0 up
+       atf_check -s exit:0 rump.ifconfig vlan0 create
+       atf_check -s exit:0 rump.ifconfig vlan0 vlan 10 vlanif shmif0
+       atf_check -s exit:0 rump.ifconfig vlan0 $af $local0/$prefix up
+       atf_check -s exit:0 rump.ifconfig vlan1 create
+       atf_check -s exit:0 rump.ifconfig vlan1 vlan 11 vlanif shmif0
+       atf_check -s exit:0 rump.ifconfig vlan1 $af $local1/$prefix up
+       atf_check -s exit:0 rump.ifconfig -w 10
+
+       # check the initial state
+       atf_check -s exit:0 -o not-match:"$eth_mcaddr" $HIJACKING ifmcstat
+
+       # add a multicast address
+       atf_check -s exit:0 $HIJACKING $siocXmulti add vlan0 $mcaddr
+       atf_check -s exit:0 -o match:"$eth_mcaddr" $HIJACKING ifmcstat
+
+       # delete the address
+       atf_check -s exit:0 $HIJACKING $siocXmulti del vlan0 $mcaddr
+       atf_check -s exit:0 -o not-match:"$eth_mcaddr" $HIJACKING ifmcstat
+
+       # delete a non-existing address
+       atf_check -s not-exit:0 -e ignore $HIJACKING $siocXmulti del vlan0 $mcaddr
+
+       # add an address to different interfaces
+       atf_check -s exit:0 $HIJACKING $siocXmulti add vlan0 $mcaddr
+       atf_check -s exit:0 $HIJACKING $siocXmulti add vlan1 $mcaddr
+       atf_check -s exit:0 -o match:"${eth_mcaddr}: 2" $HIJACKING ifmcstat
+       atf_check -s exit:0 $HIJACKING $siocXmulti del vlan0 $mcaddr
+
+       # delete the address with invalid interface
+       atf_check -s not-exit:0 -e match:"Device not configured" \
+           $HIJACKING $siocXmulti del vlan0 $mcaddr
+
+       atf_check -s exit:0 $HIJACKING $siocXmulti del vlan1 $mcaddr
+
+       # add and delete a same address more than once
+       atf_check -s exit:0 $HIJACKING $siocXmulti add vlan0 $mcaddr
+       atf_check -s exit:0 $HIJACKING $siocXmulti add vlan0 $mcaddr
+       atf_check -s exit:0 $HIJACKING $siocXmulti add vlan0 $mcaddr
+       atf_check -s exit:0 -o match:"${eth_mcaddr}: 3" $HIJACKING ifmcstat
+       atf_check -s exit:0 $HIJACKING $siocXmulti del vlan0 $mcaddr
+       atf_check -s exit:0 $HIJACKING $siocXmulti del vlan0 $mcaddr
+       atf_check -s exit:0 $HIJACKING $siocXmulti del vlan0 $mcaddr
+       atf_check -s exit:0 -o not-match:"$eth_mcaddr" $HIJACKING ifmcstat
+
+       # delete all address added to parent device when remove
+       # the config of parent interface
+       atf_check -s exit:0 $HIJACKING $siocXmulti add vlan0 $mcaddr
+       atf_check -s exit:0 $HIJACKING $siocXmulti add vlan0 $mcaddr
+       atf_check -s exit:0 $HIJACKING $siocXmulti add vlan0 $mcaddr
+       atf_check -s exit:0 rump.ifconfig vlan0 -vlanif shmif0
+       atf_check -s exit:0 -o not-match:"$eth_mcaddr" $HIJACKING ifmcstat
+}
+
+atf_test_case vlan_multicast cleanup
+vlan_multicast_head()
+{
+       atf_set "descr" "tests of multicast address adding and deleting"
+       atf_set "require.progs" "rump_server"
+}
+
+vlan_multicast_body()
+{
+       rump_server_start $SOCK_LOCAL vlan
+
+       vlan_multicast_body_common inet
+}
+
+vlan_multicast_cleanup()
+{
+       $DEBUG && dump
+       cleanup
+}
+
+atf_test_case vlan_multicast6 cleanup
+vlan_multicast6_head()
+{
+       atf_set "descr" "tests of multicast address adding and deleting with IPv6"
+       atf_set "require.progs" "rump_server"
+}
+
+vlan_multicast6_body()
+{
+       rump_server_start $SOCK_LOCAL vlan netinet6
+
+       vlan_multicast_body_common inet6
+}
+
+vlan_multicast6_cleanup()
+{
+       $DEBUG && dump
+       cleanup
+}
+
 atf_init_test_cases()
 {
 
@@ -606,10 +727,12 @@
        atf_add_test_case vlan_vlanid
        atf_add_test_case vlan_configs
        atf_add_test_case vlan_bridge
+       atf_add_test_case vlan_multicast
 
        atf_add_test_case vlan_create_destroy6
        atf_add_test_case vlan_basic6



Home | Main Index | Thread Index | Old Index