Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-src
Path: blob/main/tests/sys/netpfil/ipfw/table.sh
96309 views
1
# SPDX-License-Identifier: BSD-2-Clause
2
#
3
# Copyright (c) 2026 Gleb Smirnoff <[email protected]>
4
#
5
# Redistribution and use in source and binary forms, with or without
6
# modification, are permitted provided that the following conditions
7
# are met:
8
# 1. Redistributions of source code must retain the above copyright
9
# notice, this list of conditions and the following disclaimer.
10
# 2. Redistributions in binary form must reproduce the above copyright
11
# notice, this list of conditions and the following disclaimer in the
12
# documentation and/or other materials provided with the distribution.
13
#
14
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24
# SUCH DAMAGE.
25
26
. $(atf_get_srcdir)/../common/utils.subr
27
28
atf_test_case "fuzz" "cleanup"
29
fuzz_head()
30
{
31
atf_set descr 'Create couple tables and fuzzes them'
32
atf_set require.user root
33
}
34
35
fuzz_body()
36
{
37
firewall_init "ipfw"
38
39
epair=$(vnet_mkepair)
40
vnet_mkjail sender ${epair}a
41
jexec sender ifconfig ${epair}a 192.0.2.0/31 up
42
jexec sender route add 10.0.0.0/8 192.0.2.1
43
44
vnet_mkjail receiver ${epair}b
45
jexec receiver ifconfig lo0 127.0.0.1/8 up
46
jexec receiver ifconfig ${epair}b 192.0.2.1/31 up
47
jexec receiver route add 10.0.0.0/8 -blackhole -iface lo0
48
49
jexec receiver ipfw add 100 count ip from any to table\(tb0\)
50
jexec receiver ipfw add 200 count ip from any to table\(tb1\)
51
52
( jexec sender sh -c \
53
'while true; do \
54
oct=$(od -An -N1 -tu1 < /dev/urandom); \
55
oct=$(echo $oct); \
56
ping -c 5 -i .01 -W .01 10.0.0.${oct} >/dev/null; \
57
done' ) &
58
pinger=$!
59
60
( jexec receiver sh -c \
61
'while true; do \
62
set -- $(od -An -N2 -tu1 < /dev/urandom); \
63
ipfw -q table tb$(($1 % 2)) add 10.0.0.$2; \
64
done' ) &
65
adder=$!
66
67
( jexec receiver sh -c \
68
'while true; do \
69
set -- $(od -An -N2 -tu1 < /dev/urandom); \
70
ipfw -q table tb$(($1 % 2)) del 10.0.0.$2; \
71
done' ) &
72
deleter=$!
73
74
( jexec receiver sh -c \
75
'while true; do \
76
ipfw table tb0 swap tb1; \
77
sleep .25; \
78
done' ) &
79
swapper=$!
80
81
sleep 30
82
kill $pinger
83
kill $adder
84
kill $deleter
85
kill $swapper
86
}
87
88
fuzz_cleanup()
89
{
90
firewall_cleanup $1
91
}
92
93
atf_init_test_cases()
94
{
95
atf_add_test_case "fuzz"
96
}
97
98