xref: /freebsd/sbin/pfctl/tests/pfctl_test.c (revision aeddee83341eb3b847fb4862db5cd0a553bf4a36)
144ec023cSAlex Richardson /*-
244ec023cSAlex Richardson  * SPDX-License-Identifier: BSD-2-Clause
344ec023cSAlex Richardson  *
444ec023cSAlex Richardson  * Copyright 2020 Alex Richardson <arichardson@FreeBSD.org>
544ec023cSAlex Richardson  *
644ec023cSAlex Richardson  * This software was developed by SRI International and the University of
744ec023cSAlex Richardson  * Cambridge Computer Laboratory (Department of Computer Science and
844ec023cSAlex Richardson  * Technology) under DARPA contract HR0011-18-C-0016 ("ECATS"), as part of the
944ec023cSAlex Richardson  * DARPA SSITH research programme.
1044ec023cSAlex Richardson  *
1144ec023cSAlex Richardson  * This work was supported by Innovate UK project 105694, "Digital Security by
1244ec023cSAlex Richardson  * Design (DSbD) Technology Platform Prototype".
1344ec023cSAlex Richardson  *
1444ec023cSAlex Richardson  * Redistribution and use in source and binary forms, with or without
1544ec023cSAlex Richardson  * modification, are permitted provided that the following conditions are met:
1644ec023cSAlex Richardson  * 1. Redistributions of source code must retain the above copyright notice,
1744ec023cSAlex Richardson  *    this list of conditions and the following disclaimer.
1844ec023cSAlex Richardson  * 2. Redistributions in binary form must reproduce the above copyright notice,
1944ec023cSAlex Richardson  *    this list of conditions and the following disclaimer in the documentation
2044ec023cSAlex Richardson  *    and/or other materials provided with the distribution.
2144ec023cSAlex Richardson  *
2244ec023cSAlex Richardson  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY
2344ec023cSAlex Richardson  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
2444ec023cSAlex Richardson  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
2544ec023cSAlex Richardson  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY
2644ec023cSAlex Richardson  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
2744ec023cSAlex Richardson  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
2844ec023cSAlex Richardson  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
2944ec023cSAlex Richardson  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
3044ec023cSAlex Richardson  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
3144ec023cSAlex Richardson  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3244ec023cSAlex Richardson  */
3332e86a82SWarner Losh 
3444ec023cSAlex Richardson #include <sys/types.h>
3544ec023cSAlex Richardson #include <sys/param.h>
3644ec023cSAlex Richardson #include <err.h>
3744ec023cSAlex Richardson #include <errno.h>
3844ec023cSAlex Richardson #include <fcntl.h>
3944ec023cSAlex Richardson #include <stdbool.h>
4044ec023cSAlex Richardson #include <stdio.h>
4144ec023cSAlex Richardson #include <stdlib.h>
4244ec023cSAlex Richardson #include <spawn.h>
4344ec023cSAlex Richardson #include <sys/module.h>
4444ec023cSAlex Richardson #include <sys/sbuf.h>
4544ec023cSAlex Richardson #include <sys/stat.h>
4644ec023cSAlex Richardson #include <sys/wait.h>
4744ec023cSAlex Richardson 
4844ec023cSAlex Richardson #include <atf-c.h>
4944ec023cSAlex Richardson 
5044ec023cSAlex Richardson /*
5144ec023cSAlex Richardson  * Tests 0001-0999 are copied from OpenBSD's regress/sbin/pfctl.
5244ec023cSAlex Richardson  * Tests 1001-1999 are ours (FreeBSD's own).
5344ec023cSAlex Richardson  *
5444ec023cSAlex Richardson  * pf: Run pfctl -nv on pfNNNN.in and check that the output matches pfNNNN.ok.
5544ec023cSAlex Richardson  *     Copied from OpenBSD.  Main differences are some things not working
5644ec023cSAlex Richardson  *     in FreeBSD:
5744ec023cSAlex Richardson  *         * The action 'match'
5844ec023cSAlex Richardson  *         * The command 'set reassemble'
5944ec023cSAlex Richardson  *         * The 'from'/'to' options together with 'route-to'
6044ec023cSAlex Richardson  *         * The option 'scrub' (it is an action in FreeBSD)
6144ec023cSAlex Richardson  *         * Accepting undefined routing tables in actions (??: see pf0093.in)
6244ec023cSAlex Richardson  *         * The 'route' option
6344ec023cSAlex Richardson  *         * The 'set queue def' option
6444ec023cSAlex Richardson  * selfpf: Feed pfctl output through pfctl again and verify it stays the same.
6544ec023cSAlex Richardson  *         Copied from OpenBSD.
6644ec023cSAlex Richardson  */
6744ec023cSAlex Richardson 
6844ec023cSAlex Richardson static bool
check_pf_module_available(void)69d80b9f8dSAdrian Chadd check_pf_module_available(void)
7044ec023cSAlex Richardson {
7144ec023cSAlex Richardson 	int modid;
7244ec023cSAlex Richardson 	struct module_stat stat;
7344ec023cSAlex Richardson 
7444ec023cSAlex Richardson 	if ((modid = modfind("pf")) < 0) {
7544ec023cSAlex Richardson 		warn("pf module not found");
7644ec023cSAlex Richardson 		return false;
7744ec023cSAlex Richardson 	}
7844ec023cSAlex Richardson 	stat.version = sizeof(struct module_stat);
7944ec023cSAlex Richardson 	if (modstat(modid, &stat) < 0) {
8044ec023cSAlex Richardson 		warn("can't stat pf module id %d", modid);
8144ec023cSAlex Richardson 		return false;
8244ec023cSAlex Richardson 	}
8344ec023cSAlex Richardson 	return (true);
8444ec023cSAlex Richardson }
8544ec023cSAlex Richardson 
8644ec023cSAlex Richardson extern char **environ;
8744ec023cSAlex Richardson 
8844ec023cSAlex Richardson static struct sbuf *
read_fd(int fd,size_t sizehint)8944ec023cSAlex Richardson read_fd(int fd, size_t sizehint)
9044ec023cSAlex Richardson {
9144ec023cSAlex Richardson 	struct sbuf *sb;
9244ec023cSAlex Richardson 	ssize_t count;
9344ec023cSAlex Richardson 	char buffer[MAXBSIZE];
9444ec023cSAlex Richardson 
9544ec023cSAlex Richardson 	sb = sbuf_new(NULL, NULL, sizehint, SBUF_AUTOEXTEND);
9644ec023cSAlex Richardson 	errno = 0;
9744ec023cSAlex Richardson 	while ((count = read(fd, buffer, sizeof(buffer) - 1)) > 0) {
9844ec023cSAlex Richardson 		sbuf_bcat(sb, buffer, count);
9944ec023cSAlex Richardson 	}
10044ec023cSAlex Richardson 	ATF_REQUIRE_ERRNO(0, count == 0 && "Should have reached EOF");
10144ec023cSAlex Richardson 	sbuf_finish(sb); /* Ensure NULL-termination */
10244ec023cSAlex Richardson 	return (sb);
10344ec023cSAlex Richardson }
10444ec023cSAlex Richardson 
10544ec023cSAlex Richardson static struct sbuf *
read_file(const char * filename)10644ec023cSAlex Richardson read_file(const char *filename)
10744ec023cSAlex Richardson {
10844ec023cSAlex Richardson 	struct stat s;
10944ec023cSAlex Richardson 	struct sbuf *result;
11044ec023cSAlex Richardson 	int fd;
11144ec023cSAlex Richardson 
11244ec023cSAlex Richardson 	errno = 0;
11344ec023cSAlex Richardson 	ATF_REQUIRE_EQ_MSG(stat(filename, &s), 0, "cannot stat %s", filename);
11444ec023cSAlex Richardson 	fd = open(filename, O_RDONLY);
11544ec023cSAlex Richardson 	ATF_REQUIRE_ERRNO(0, fd > 0);
11644ec023cSAlex Richardson 	result = read_fd(fd, s.st_size);
11744ec023cSAlex Richardson 	ATF_REQUIRE_ERRNO(0, close(fd) == 0);
11844ec023cSAlex Richardson 	return (result);
11944ec023cSAlex Richardson }
12044ec023cSAlex Richardson 
12144ec023cSAlex Richardson static void
run_command_pipe(const char * argv[],struct sbuf ** output)122*aeddee83SKajetan Staszkiewicz run_command_pipe(const char *argv[], struct sbuf **output)
12344ec023cSAlex Richardson {
124*aeddee83SKajetan Staszkiewicz 	posix_spawn_file_actions_t action;
12544ec023cSAlex Richardson 	pid_t pid;
12644ec023cSAlex Richardson 	int pipefds[2];
127*aeddee83SKajetan Staszkiewicz 	int status;
128*aeddee83SKajetan Staszkiewicz 
129*aeddee83SKajetan Staszkiewicz 	ATF_REQUIRE_ERRNO(0, pipe(pipefds) == 0);
130*aeddee83SKajetan Staszkiewicz 
131*aeddee83SKajetan Staszkiewicz 	posix_spawn_file_actions_init(&action);
132*aeddee83SKajetan Staszkiewicz 	posix_spawn_file_actions_addclose(&action, STDIN_FILENO);
133*aeddee83SKajetan Staszkiewicz 	posix_spawn_file_actions_addclose(&action, pipefds[1]);
134*aeddee83SKajetan Staszkiewicz 	posix_spawn_file_actions_adddup2(&action, pipefds[0], STDOUT_FILENO);
135*aeddee83SKajetan Staszkiewicz 	posix_spawn_file_actions_adddup2(&action, pipefds[0], STDERR_FILENO);
136*aeddee83SKajetan Staszkiewicz 
137*aeddee83SKajetan Staszkiewicz 	printf("Running ");
138*aeddee83SKajetan Staszkiewicz 	for (int i=0; argv[i] != NULL; i++)
139*aeddee83SKajetan Staszkiewicz 		printf("%s ", argv[i]);
140*aeddee83SKajetan Staszkiewicz 	printf("\n");
141*aeddee83SKajetan Staszkiewicz 
142*aeddee83SKajetan Staszkiewicz 	status = posix_spawnp(
143*aeddee83SKajetan Staszkiewicz 	    &pid, argv[0], &action, NULL, __DECONST(char **, argv), environ);
144*aeddee83SKajetan Staszkiewicz 	ATF_REQUIRE_EQ_MSG(
145*aeddee83SKajetan Staszkiewicz 	    status, 0, "posix_spawn failed: %s", strerror(errno));
146*aeddee83SKajetan Staszkiewicz 	posix_spawn_file_actions_destroy(&action);
147*aeddee83SKajetan Staszkiewicz 	close(pipefds[0]);
148*aeddee83SKajetan Staszkiewicz 
149*aeddee83SKajetan Staszkiewicz 	(*output) = read_fd(pipefds[1], 0);
150*aeddee83SKajetan Staszkiewicz 	printf("---\n%s---\n", sbuf_data(*output));
151*aeddee83SKajetan Staszkiewicz 	ATF_REQUIRE_EQ(waitpid(pid, &status, 0), pid);
152*aeddee83SKajetan Staszkiewicz 	ATF_REQUIRE_MSG(WIFEXITED(status),
153*aeddee83SKajetan Staszkiewicz 	    "%s returned non-zero! Output:\n %s", argv[0], sbuf_data(*output));
154*aeddee83SKajetan Staszkiewicz 	close(pipefds[1]);
155*aeddee83SKajetan Staszkiewicz }
156*aeddee83SKajetan Staszkiewicz 
157*aeddee83SKajetan Staszkiewicz static void
run_command(const char * argv[])158*aeddee83SKajetan Staszkiewicz run_command(const char *argv[])
159*aeddee83SKajetan Staszkiewicz {
160*aeddee83SKajetan Staszkiewicz 	posix_spawn_file_actions_t action;
161*aeddee83SKajetan Staszkiewicz 	pid_t pid;
162*aeddee83SKajetan Staszkiewicz 	int status;
163*aeddee83SKajetan Staszkiewicz 
164*aeddee83SKajetan Staszkiewicz 	posix_spawn_file_actions_init(&action);
165*aeddee83SKajetan Staszkiewicz 	posix_spawn_file_actions_addopen(&action, STDOUT_FILENO, "/dev/null", O_WRONLY, 0);
166*aeddee83SKajetan Staszkiewicz 	posix_spawn_file_actions_addopen(&action, STDERR_FILENO, "/dev/null", O_WRONLY, 0);
167*aeddee83SKajetan Staszkiewicz 	posix_spawn_file_actions_addopen(&action, STDIN_FILENO, "/dev/zero", O_RDONLY, 0);
168*aeddee83SKajetan Staszkiewicz 
169*aeddee83SKajetan Staszkiewicz 	printf("Running ");
170*aeddee83SKajetan Staszkiewicz 	for (int i=0; argv[i] != NULL; i++)
171*aeddee83SKajetan Staszkiewicz 		printf("%s ", argv[i]);
172*aeddee83SKajetan Staszkiewicz 	printf("\n");
173*aeddee83SKajetan Staszkiewicz 
174*aeddee83SKajetan Staszkiewicz 	status = posix_spawnp(
175*aeddee83SKajetan Staszkiewicz 	    &pid, argv[0], &action, NULL, __DECONST(char **, argv), environ);
176*aeddee83SKajetan Staszkiewicz 	posix_spawn_file_actions_destroy(&action);
177*aeddee83SKajetan Staszkiewicz 	waitpid(pid, &status, 0);
178*aeddee83SKajetan Staszkiewicz }
179*aeddee83SKajetan Staszkiewicz 
180*aeddee83SKajetan Staszkiewicz static void
run_pfctl_test(const char * input_path,const char * output_path,const atf_tc_t * tc,bool test_failure)181*aeddee83SKajetan Staszkiewicz run_pfctl_test(const char *input_path, const char *output_path,
182*aeddee83SKajetan Staszkiewicz     const atf_tc_t *tc, bool test_failure)
183*aeddee83SKajetan Staszkiewicz {
18444ec023cSAlex Richardson 	char input_files_path[PATH_MAX];
18544ec023cSAlex Richardson 	struct sbuf *expected_output;
18644ec023cSAlex Richardson 	struct sbuf *real_output;
18744ec023cSAlex Richardson 
18844ec023cSAlex Richardson 	if (!check_pf_module_available())
18944ec023cSAlex Richardson 		atf_tc_skip("pf(4) is not loaded");
19044ec023cSAlex Richardson 
19144ec023cSAlex Richardson 	/* The test inputs need to be able to use relative includes. */
19244ec023cSAlex Richardson 	snprintf(input_files_path, sizeof(input_files_path), "%s/files",
19344ec023cSAlex Richardson 	    atf_tc_get_config_var(tc, "srcdir"));
19444ec023cSAlex Richardson 	ATF_REQUIRE_ERRNO(0, chdir(input_files_path) == 0);
195*aeddee83SKajetan Staszkiewicz 	expected_output = read_file(output_path);
19644ec023cSAlex Richardson 
19744ec023cSAlex Richardson 	const char *argv[] = { "pfctl", "-o", "none", "-nvf", input_path,
19844ec023cSAlex Richardson 	    NULL };
199*aeddee83SKajetan Staszkiewicz 	run_command_pipe(argv, &real_output);
20044ec023cSAlex Richardson 
201*aeddee83SKajetan Staszkiewicz 	if (test_failure) {
202*aeddee83SKajetan Staszkiewicz 		/*
203*aeddee83SKajetan Staszkiewicz 		 * Error output contains additional strings like line number
204*aeddee83SKajetan Staszkiewicz 		 * or "skipping rule due to errors", so use regexp to see
205*aeddee83SKajetan Staszkiewicz 		 * if the expected error message is there somewhere.
206*aeddee83SKajetan Staszkiewicz 		 */
207*aeddee83SKajetan Staszkiewicz 		ATF_CHECK_MATCH(sbuf_data(expected_output), sbuf_data(real_output));
208*aeddee83SKajetan Staszkiewicz 		sbuf_delete(expected_output);
209*aeddee83SKajetan Staszkiewicz 	} else {
21044ec023cSAlex Richardson 		ATF_CHECK_STREQ(sbuf_data(expected_output), sbuf_data(real_output));
21144ec023cSAlex Richardson 		sbuf_delete(expected_output);
212*aeddee83SKajetan Staszkiewicz 	}
213*aeddee83SKajetan Staszkiewicz 
21444ec023cSAlex Richardson 	sbuf_delete(real_output);
215*aeddee83SKajetan Staszkiewicz }
216*aeddee83SKajetan Staszkiewicz 
217*aeddee83SKajetan Staszkiewicz static void
do_pf_test_iface_create(const char * number)218*aeddee83SKajetan Staszkiewicz do_pf_test_iface_create(const char *number)
219*aeddee83SKajetan Staszkiewicz {
220*aeddee83SKajetan Staszkiewicz 	struct sbuf	*ifconfig_output;
221*aeddee83SKajetan Staszkiewicz 	char		ifname[16] = {0};
222*aeddee83SKajetan Staszkiewicz 
223*aeddee83SKajetan Staszkiewicz 	snprintf(ifname, sizeof(ifname), "vlan%s", number);
224*aeddee83SKajetan Staszkiewicz 	const char *argv[] = { "ifconfig", ifname, "create", NULL};
225*aeddee83SKajetan Staszkiewicz 	run_command_pipe(argv, &ifconfig_output);
226*aeddee83SKajetan Staszkiewicz 	sbuf_delete(ifconfig_output);
227*aeddee83SKajetan Staszkiewicz 
228*aeddee83SKajetan Staszkiewicz 	const char *argv_inet[] = { "ifconfig", ifname, "inet", "203.0.113.5/30", NULL};
229*aeddee83SKajetan Staszkiewicz 	run_command_pipe(argv_inet, &ifconfig_output);
230*aeddee83SKajetan Staszkiewicz 	sbuf_delete(ifconfig_output);
231*aeddee83SKajetan Staszkiewicz 
232*aeddee83SKajetan Staszkiewicz 	const char *argv_inet6[] = { "ifconfig", ifname, "inet6", "2001:db8::203.0.113.5/126", NULL};
233*aeddee83SKajetan Staszkiewicz 	run_command_pipe(argv_inet6, &ifconfig_output);
234*aeddee83SKajetan Staszkiewicz 	sbuf_delete(ifconfig_output);
235*aeddee83SKajetan Staszkiewicz 
236*aeddee83SKajetan Staszkiewicz 	const char *argv_show[] = { "ifconfig", ifname, NULL};
237*aeddee83SKajetan Staszkiewicz 	run_command_pipe(argv_show, &ifconfig_output);
238*aeddee83SKajetan Staszkiewicz 	sbuf_delete(ifconfig_output);
239*aeddee83SKajetan Staszkiewicz }
240*aeddee83SKajetan Staszkiewicz 
241*aeddee83SKajetan Staszkiewicz static void
do_pf_test_iface_remove(const char * number)242*aeddee83SKajetan Staszkiewicz do_pf_test_iface_remove(const char *number)
243*aeddee83SKajetan Staszkiewicz {
244*aeddee83SKajetan Staszkiewicz 	char		ifname[16] = {0};
245*aeddee83SKajetan Staszkiewicz 
246*aeddee83SKajetan Staszkiewicz 	snprintf(ifname, sizeof(ifname), "vlan%s", number);
247*aeddee83SKajetan Staszkiewicz 	const char *argv[] = { "ifconfig", ifname, "destroy", NULL};
248*aeddee83SKajetan Staszkiewicz 	run_command(argv);
24944ec023cSAlex Richardson }
25044ec023cSAlex Richardson 
25144ec023cSAlex Richardson static void
do_pf_test(const char * number,const atf_tc_t * tc)25244ec023cSAlex Richardson do_pf_test(const char *number, const atf_tc_t *tc)
25344ec023cSAlex Richardson {
25444ec023cSAlex Richardson 	char *input_path;
25544ec023cSAlex Richardson 	char *expected_path;
25644ec023cSAlex Richardson 	asprintf(&input_path, "%s/files/pf%s.in",
25744ec023cSAlex Richardson 	    atf_tc_get_config_var(tc, "srcdir"), number);
25844ec023cSAlex Richardson 	asprintf(&expected_path, "%s/files/pf%s.ok",
25944ec023cSAlex Richardson 	    atf_tc_get_config_var(tc, "srcdir"), number);
260*aeddee83SKajetan Staszkiewicz 	run_pfctl_test(input_path, expected_path, tc, false);
261*aeddee83SKajetan Staszkiewicz 	free(input_path);
262*aeddee83SKajetan Staszkiewicz 	free(expected_path);
263*aeddee83SKajetan Staszkiewicz }
264*aeddee83SKajetan Staszkiewicz 
265*aeddee83SKajetan Staszkiewicz static void
do_pf_test_fail(const char * number,const atf_tc_t * tc)266*aeddee83SKajetan Staszkiewicz do_pf_test_fail(const char *number, const atf_tc_t *tc)
267*aeddee83SKajetan Staszkiewicz {
268*aeddee83SKajetan Staszkiewicz 	char *input_path;
269*aeddee83SKajetan Staszkiewicz 	char *expected_path;
270*aeddee83SKajetan Staszkiewicz 	asprintf(&input_path, "%s/files/pf%s.in",
271*aeddee83SKajetan Staszkiewicz 	    atf_tc_get_config_var(tc, "srcdir"), number);
272*aeddee83SKajetan Staszkiewicz 	asprintf(&expected_path, "%s/files/pf%s.fail",
273*aeddee83SKajetan Staszkiewicz 	    atf_tc_get_config_var(tc, "srcdir"), number);
274*aeddee83SKajetan Staszkiewicz 	run_pfctl_test(input_path, expected_path, tc, true);
27544ec023cSAlex Richardson 	free(input_path);
27644ec023cSAlex Richardson 	free(expected_path);
27744ec023cSAlex Richardson }
27844ec023cSAlex Richardson 
27944ec023cSAlex Richardson static void
do_selfpf_test(const char * number,const atf_tc_t * tc)28044ec023cSAlex Richardson do_selfpf_test(const char *number, const atf_tc_t *tc)
28144ec023cSAlex Richardson {
28244ec023cSAlex Richardson 	char *expected_path;
28344ec023cSAlex Richardson 	asprintf(&expected_path, "%s/files/pf%s.ok",
28444ec023cSAlex Richardson 	    atf_tc_get_config_var(tc, "srcdir"), number);
285*aeddee83SKajetan Staszkiewicz 	run_pfctl_test(expected_path, expected_path, tc, false);
28644ec023cSAlex Richardson 	free(expected_path);
28744ec023cSAlex Richardson }
28844ec023cSAlex Richardson 
289*aeddee83SKajetan Staszkiewicz /* Standard tests perform the normal test and then the selfpf test */
29044ec023cSAlex Richardson #define PFCTL_TEST(number, descr)				\
29144ec023cSAlex Richardson 	ATF_TC(pf##number);					\
29244ec023cSAlex Richardson 	ATF_TC_HEAD(pf##number, tc)				\
29344ec023cSAlex Richardson 	{							\
29444ec023cSAlex Richardson 		atf_tc_set_md_var(tc, "descr", descr);		\
29544ec023cSAlex Richardson 	}							\
29644ec023cSAlex Richardson 	ATF_TC_BODY(pf##number, tc)				\
29744ec023cSAlex Richardson 	{							\
29844ec023cSAlex Richardson 		do_pf_test(#number, tc);			\
29944ec023cSAlex Richardson 	}							\
30044ec023cSAlex Richardson 	ATF_TC(selfpf##number);					\
30144ec023cSAlex Richardson 	ATF_TC_HEAD(selfpf##number, tc)				\
30244ec023cSAlex Richardson 	{							\
30344ec023cSAlex Richardson 		atf_tc_set_md_var(tc, "descr", "Self " descr);	\
30444ec023cSAlex Richardson 	}							\
30544ec023cSAlex Richardson 	ATF_TC_BODY(selfpf##number, tc)				\
30644ec023cSAlex Richardson 	{							\
30744ec023cSAlex Richardson 		do_selfpf_test(#number, tc);			\
30844ec023cSAlex Richardson 	}
309*aeddee83SKajetan Staszkiewicz /* Tests for failure perform only the normal test */
310*aeddee83SKajetan Staszkiewicz #define PFCTL_TEST_FAIL(number, descr)				\
311*aeddee83SKajetan Staszkiewicz 	ATF_TC(pf##number);					\
312*aeddee83SKajetan Staszkiewicz 	ATF_TC_HEAD(pf##number, tc)				\
313*aeddee83SKajetan Staszkiewicz 	{							\
314*aeddee83SKajetan Staszkiewicz 		atf_tc_set_md_var(tc, "descr", descr);		\
315*aeddee83SKajetan Staszkiewicz 	}							\
316*aeddee83SKajetan Staszkiewicz 	ATF_TC_BODY(pf##number, tc)				\
317*aeddee83SKajetan Staszkiewicz 	{							\
318*aeddee83SKajetan Staszkiewicz 		do_pf_test_fail(#number, tc);			\
319*aeddee83SKajetan Staszkiewicz 	}
320*aeddee83SKajetan Staszkiewicz /* Tests with interface perform only the normal test */
321*aeddee83SKajetan Staszkiewicz #define PFCTL_TEST_IFACE(number, descr)				\
322*aeddee83SKajetan Staszkiewicz 	ATF_TC_WITH_CLEANUP(pf##number);			\
323*aeddee83SKajetan Staszkiewicz 	ATF_TC_HEAD(pf##number, tc)				\
324*aeddee83SKajetan Staszkiewicz 	{							\
325*aeddee83SKajetan Staszkiewicz 		atf_tc_set_md_var(tc, "descr", descr);		\
326*aeddee83SKajetan Staszkiewicz 		atf_tc_set_md_var(tc, "execenv", "jail");	\
327*aeddee83SKajetan Staszkiewicz 		atf_tc_set_md_var(tc, "execenv.jail.params", "vnet");	\
328*aeddee83SKajetan Staszkiewicz 	}							\
329*aeddee83SKajetan Staszkiewicz 	ATF_TC_BODY(pf##number, tc)				\
330*aeddee83SKajetan Staszkiewicz 	{							\
331*aeddee83SKajetan Staszkiewicz 		do_pf_test_iface_create(#number);		\
332*aeddee83SKajetan Staszkiewicz 		do_pf_test(#number, tc);			\
333*aeddee83SKajetan Staszkiewicz 	}							\
334*aeddee83SKajetan Staszkiewicz 	ATF_TC_CLEANUP(pf##number, tc)				\
335*aeddee83SKajetan Staszkiewicz 	{							\
336*aeddee83SKajetan Staszkiewicz 		do_pf_test_iface_remove(#number);		\
337*aeddee83SKajetan Staszkiewicz 	}
33844ec023cSAlex Richardson #include "pfctl_test_list.inc"
33944ec023cSAlex Richardson #undef PFCTL_TEST
340*aeddee83SKajetan Staszkiewicz #undef PFCTL_TEST_FAIL
341*aeddee83SKajetan Staszkiewicz #undef PFCTL_TEST_IFACE
34244ec023cSAlex Richardson 
ATF_TP_ADD_TCS(tp)34344ec023cSAlex Richardson ATF_TP_ADD_TCS(tp)
34444ec023cSAlex Richardson {
34544ec023cSAlex Richardson #define PFCTL_TEST(number, descr)		\
34644ec023cSAlex Richardson 	ATF_TP_ADD_TC(tp, pf##number);		\
34744ec023cSAlex Richardson 	ATF_TP_ADD_TC(tp, selfpf##number);
348*aeddee83SKajetan Staszkiewicz #define PFCTL_TEST_FAIL(number, descr)		\
349*aeddee83SKajetan Staszkiewicz 	ATF_TP_ADD_TC(tp, pf##number);
350*aeddee83SKajetan Staszkiewicz #define PFCTL_TEST_IFACE(number, descr)		\
351*aeddee83SKajetan Staszkiewicz 	ATF_TP_ADD_TC(tp, pf##number);
35244ec023cSAlex Richardson #include "pfctl_test_list.inc"
35344ec023cSAlex Richardson #undef PFCTL_TEST
354*aeddee83SKajetan Staszkiewicz #undef PFCTL_TEST_FAIL
355*aeddee83SKajetan Staszkiewicz #undef PFCTL_TEST_IFACE
35644ec023cSAlex Richardson 
35744ec023cSAlex Richardson 	return atf_no_error();
35844ec023cSAlex Richardson }
359