From: vgross Date: Mon, 26 Oct 2015 08:04:10 +0000 (+0000) Subject: Add regress test on local route insertions X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=99f77f33dfe8eeb51f9dcb19fcf4f65e84763381;p=openbsd Add regress test on local route insertions --- diff --git a/regress/sys/net/Makefile b/regress/sys/net/Makefile index 087c40c6def..01ac6582bad 100644 --- a/regress/sys/net/Makefile +++ b/regress/sys/net/Makefile @@ -1,6 +1,6 @@ -# $OpenBSD: Makefile,v 1.6 2014/07/12 21:41:49 bluhm Exp $ +# $OpenBSD: Makefile,v 1.7 2015/10/26 08:04:10 vgross Exp $ -SUBDIR += pf_divert pf_forward pf_fragment +SUBDIR += pf_divert pf_forward pf_fragment rdomains .MAIN: regress diff --git a/regress/sys/net/rdomains/Makefile b/regress/sys/net/rdomains/Makefile new file mode 100644 index 00000000000..f5336d3b674 --- /dev/null +++ b/regress/sys/net/rdomains/Makefile @@ -0,0 +1,11 @@ +# $OpenBSD: Makefile,v 1.1 2015/10/26 08:04:10 vgross Exp $ + +DIR= ${.CURDIR}/../../net/rdomains + +REGRESS_TARGETS= run-regress-ifalocal +REGRESS_ROOT_TARGETS= $(REGRESS_TARGETS) + +run-regress-ifalocal: + sh $(DIR)/ifalocal.sh + +.include diff --git a/regress/sys/net/rdomains/ifalocal.sh b/regress/sys/net/rdomains/ifalocal.sh new file mode 100644 index 00000000000..16ef7637cb3 --- /dev/null +++ b/regress/sys/net/rdomains/ifalocal.sh @@ -0,0 +1,117 @@ +# $OpenBSD: ifalocal.sh,v 1.1 2015/10/26 08:04:10 vgross Exp $ + +# Copyright (c) 2015 Vincent Gross +# +# Permission to use, copy, modify, and distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + + +iface_exists() +{ + ifconfig_out=`ifconfig "$1" 2>&1` + [ "${ifconfig_out}" != "$1: no such interface" ] +} + +rtable_exists() +{ + route_show_out=`route -T "$1" -n show -inet 2>&1` + [ "$route_show_out" != "route: routing table $1: No such file or directory" ] +} + +local_route_count() +{ + matches=`route -T $3 -n show | awk -v "ifp=$2" -v "dest=$1" \ + '$1 == dest && $3 == "UHLl" && $8 == ifp { matches++ } END { print 0 + matches }'` + if [ "$matches" -ne "$4" ]; then + fmt >&2 << EOM +expected $4 routes to $1 with ifp $2 in rtable $3, found $matches +EOM + return 1 + fi + return 0 +} + + +cleanup() +{ + route -T 6 flush + ifconfig vether6 destroy + route -T 5 flush + ifconfig vether5 destroy + route -T 4 flush + ifconfig vether4 destroy + route -T 3 flush + ifconfig vether3 destroy +} + +cleanup_and_die() +{ + echo "$1" >&2 + cleanup + exit 1 +} + +test_rc=true + +fail_test() +{ + test_rc=false +} + +if false; then +if iface_exists vether3 || iface_exists vether4 || + iface_exists vether5 || iface_exists vether6 ; then + cat >&2 << EOM +this test needs to create interfaces vether0, vether1, vether2 and vether3, +please destroy them before running this test. +EOM + exit 1 +fi +fi + +ifconfig vether3 create rdomain 3 || cleanup_and_die "Error while creating vether3" +ifconfig vether4 create rdomain 3 || cleanup_and_die "Error while creating vether4" +ifconfig vether5 create rdomain 5 || cleanup_and_die "Error while creating vether5" +ifconfig vether6 create rdomain 5 || cleanup_and_die "Error while creating vether6" + +rtable_exists 3 || cleanup_and_die "Error: rtable 3 does not exist but should" +rtable_exists 5 || cleanup_and_die "Error: rtable 5 does not exist but should" + +ifconfig vether3 10.0.0.1/24 up +route -T 4 add -iface -ifp vether3 10.0.0.0/28 10.0.0.1 +rtable_exists 4 || cleanup_and_die "Error: rtable 4 does not exist but should" + +local_route_count 10.0.0.1 vether3 3 1 || test_fail +local_route_count 10.0.0.1 vether3 4 0 || test_fail + +route -T 4 exec ifconfig vether4 10.0.0.2/24 up +local_route_count 10.0.0.2 vether4 3 1 || test_fail +local_route_count 10.0.0.2 vether4 4 0 || test_fail +local_route_count 10.0.0.1 vether3 3 1 || test_fail +local_route_count 10.0.0.1 vether3 4 0 || test_fail + +ifconfig vether5 10.0.0.1/24 up +route -T 6 add -iface -ifp vether5 10.0.0.0/28 10.0.0.1 +rtable_exists 6 || cleanup_and_die "Error: rtable 6 does not exist but should" + +local_route_count 10.0.0.1 vether5 5 1 || test_fail +local_route_count 10.0.0.1 vether5 6 0 || test_fail + +route -T 6 exec ifconfig vether6 10.0.0.2/24 up +local_route_count 10.0.0.2 vether6 5 1 || test_fail +local_route_count 10.0.0.2 vether6 6 0 || test_fail +local_route_count 10.0.0.1 vether5 5 1 || test_fail +local_route_count 10.0.0.1 vether5 6 0 || test_fail + +cleanup + +$test_rc