xref: /freebsd/contrib/netbsd-tests/ipf/t_nat_ipf_exec.sh (revision 0b3105a37d7adcadcb720112fed4dc4e8040be99)
1# $NetBSD: t_nat_ipf_exec.sh,v 1.7 2012/07/07 23:29:44 pgoyette Exp $
2#
3# Copyright (c) 2008, 2010 The NetBSD Foundation, Inc.
4# All rights reserved.
5#
6# Redistribution and use in source and binary forms, with or without
7# modification, are permitted provided that the following conditions
8# are met:
9# 1. Redistributions of source code must retain the above copyright
10#    notice, this list of conditions and the following disclaimer.
11# 2. Redistributions in binary form must reproduce the above copyright
12#    notice, this list of conditions and the following disclaimer in the
13#    documentation and/or other materials provided with the distribution.
14#
15# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
16# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
19# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25# POSSIBILITY OF SUCH DAMAGE.
26#
27#
28# (C)opyright 1993-1996 by Darren Reed.
29#
30# See the IPFILTER.LICENCE file for details on licencing.
31#
32
33natipftest()
34{
35	h_copydata $1
36	cp $(atf_get_srcdir)/regress/$1.nat nat
37	cp $(atf_get_srcdir)/regress/$1.ipf ipf
38	many=$2
39	infmt=$3
40	outfmt=$4
41	shift
42	shift
43	shift
44	shift
45	args=$@
46
47	if [ $outfmt = hex ] ; then
48		format="-xF $infmt"
49	else
50		format="-F $infmt"
51	fi
52
53	case $many in
54	single)
55		{ while read rule; do
56			atf_check -o save:save -x "echo \"$rule\" | \
57ipftest -R $format -b -r ipf -N - -i in $args"
58			cat save >>out
59			echo "-------------------------------" >>out
60		done; } <nat
61		;;
62	multi)
63		atf_check -o save:out ipftest -R $args \
64			$format -b -r ipf -N nat -i in
65		echo "-------------------------------" >>out
66		;;
67	esac
68
69	diff -u exp out || atf_fail "results differ"
70}
71
72test_case ni1 natipftest multi hex hex -T update_ipid=1
73test_case ni2 natipftest single hex hex -T update_ipid=1
74test_case ni3 natipftest single hex hex -T update_ipid=1
75test_case ni4 natipftest single hex hex -T update_ipid=1
76test_case ni5 natipftest single hex hex -T update_ipid=1
77test_case ni6 natipftest multi hex text -T update_ipid=1 -D
78test_case ni7 natipftest single hex hex -T update_ipid=1
79test_case ni8 natipftest single hex hex -T update_ipid=1
80test_case ni9 natipftest single hex hex -T update_ipid=1
81test_case ni10 natipftest single hex hex -T update_ipid=1
82test_case ni11 natipftest single hex hex -T update_ipid=1
83test_case ni12 natipftest single hex hex -T update_ipid=1
84test_case ni13 natipftest single hex hex -T update_ipid=1
85test_case ni14 natipftest single hex hex -T update_ipid=1
86test_case ni15 natipftest single hex hex -T update_ipid=1
87test_case ni16 natipftest single hex hex -T update_ipid=1
88test_case ni17 natipftest multi text text
89test_case ni18 natipftest multi text text
90test_case ni19 natipftest single hex hex -T update_ipid=0
91test_case ni20 natipftest single hex hex -T update_ipid=0 -D
92test_case ni21 natipftest multi text text
93test_case ni23 natipftest multi text text -D
94
95atf_init_test_cases()
96{
97	atf_add_test_case ni1
98	atf_add_test_case ni2
99	atf_add_test_case ni3
100	atf_add_test_case ni4
101	atf_add_test_case ni5
102	atf_add_test_case ni6
103	atf_add_test_case ni7
104	atf_add_test_case ni8
105	atf_add_test_case ni9
106	atf_add_test_case ni10
107	atf_add_test_case ni11
108	atf_add_test_case ni12
109	atf_add_test_case ni13
110	atf_add_test_case ni14
111	atf_add_test_case ni15
112	atf_add_test_case ni16
113	atf_add_test_case ni17
114	atf_add_test_case ni18
115	atf_add_test_case ni19
116	atf_add_test_case ni20
117	atf_add_test_case ni21
118	atf_add_test_case ni23
119
120}
121