Skip to content

Commit 0af29bd

Browse files
committed
Merge: selftests: netfilter: re-sync with upstream [9.7]
MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/6383 JIRA: https://issues.redhat.com/browse/RHEL-21061 This series re-syncs the cs-9 netfilter selftests with upstream. Main reason is that we miss multiple test cases and those that we have are not very reliable due to either expecting particular versions of netcat or certain distro-provided sysctl defaults (rp_filter for instance). After this change, netfilter selftests reside in same location in upstream, cs-9 and cs-10. Known delta to upstream: - No xt_string.sh test, needs kernel changes we don't have - No conntrack_dump_flush test case, needs feature we don't have - No conntrack_reverse_clash test case, needs changes we don't have - No packetdrill tests - No sctp and udp conntrack race tests in nft_queue.sh, needs functional changes we don't have - nf_conntrack_helper.sh is unchanged, cs-9 still has the "autoassign helper" sysctl. Also means the test still fails on upstream kernels. While the number of backported commits is huge, there are no functional kernel changes here. Changes are only in netfilter selftests and the spec file to adjust for the changed test dir location. Also, easy to validate/diff the scripts vs. upstream/cs-10. Signed-off-by: Florian Westphal <[email protected]> Approved-by: Jan Stancek <[email protected]> Approved-by: Eder Zulian <[email protected]> Approved-by: Hangbin Liu <[email protected]> Approved-by: CKI KWF Bot <[email protected]> Merged-by: Augusto Caringi <[email protected]>
2 parents b827968 + 4663f4b commit 0af29bd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+4203
-2934
lines changed

MAINTAINERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13421,6 +13421,7 @@ F: net/*/netfilter.c
1342113421
F: net/*/netfilter/
1342213422
F: net/bridge/br_netfilter*.c
1342313423
F: net/netfilter/
13424+
F: tools/testing/selftests/net/netfilter/
1342413425

1342513426
NETROM NETWORK LAYER
1342613427
M: Ralf Baechle <[email protected]>

redhat/kernel.spec.template

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2780,7 +2780,7 @@ fi
27802780
pushd tools/testing/selftests
27812781
# We need to install here because we need to call make with ARCH set which
27822782
# doesn't seem possible to do in the install section.
2783-
%{make} %{?_smp_mflags} ARCH=$Arch V=1 TARGETS="bpf cgroup mm livepatch net net/forwarding net/mptcp netfilter tc-testing memfd drivers/net/bonding iommu cachestat drivers/net" SKIP_TARGETS="" FORCE_TARGETS=1 INSTALL_PATH=%{buildroot}%{_libexecdir}/kselftests VMLINUX_H="${RPM_VMLINUX_H}" DEFAULT_INSTALL_HDR_PATH=0 install
2783+
%{make} %{?_smp_mflags} ARCH=$Arch V=1 TARGETS="bpf cgroup mm livepatch net net/forwarding net/mptcp net/netfilter tc-testing memfd drivers/net/bonding iommu cachestat drivers/net" SKIP_TARGETS="" FORCE_TARGETS=1 INSTALL_PATH=%{buildroot}%{_libexecdir}/kselftests VMLINUX_H="${RPM_VMLINUX_H}" DEFAULT_INSTALL_HDR_PATH=0 install
27842784

27852785
# 'make install' for bpf is broken and upstream refuses to fix it.
27862786
# Install the needed files manually.
@@ -3158,11 +3158,11 @@ find -type d -exec install -d %{buildroot}%{_libexecdir}/kselftests/livepatch/{}
31583158
find -type f -executable -exec install -D -m755 {} %{buildroot}%{_libexecdir}/kselftests/livepatch/{} \;
31593159
find -type f ! -executable -exec install -D -m644 {} %{buildroot}%{_libexecdir}/kselftests/livepatch/{} \;
31603160
popd
3161-
# install netfilter selftests
3162-
pushd tools/testing/selftests/netfilter
3163-
find -type d -exec install -d %{buildroot}%{_libexecdir}/kselftests/netfilter/{} \;
3164-
find -type f -executable -exec install -D -m755 {} %{buildroot}%{_libexecdir}/kselftests/netfilter/{} \;
3165-
find -type f ! -executable -exec install -D -m644 {} %{buildroot}%{_libexecdir}/kselftests/netfilter/{} \;
3161+
# install net/netfilter selftests
3162+
pushd tools/testing/selftests/net/netfilter
3163+
find -type d -exec install -d %{buildroot}%{_libexecdir}/kselftests/net/netfilter/{} \;
3164+
find -type f -executable -exec install -D -m755 {} %{buildroot}%{_libexecdir}/kselftests/net/netfilter/{} \;
3165+
find -type f ! -executable -exec install -D -m644 {} %{buildroot}%{_libexecdir}/kselftests/net/netfilter/{} \;
31663166
popd
31673167

31683168
# install memfd selftests
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# SPDX-License-Identifier: GPL-2.0-only
2-
nf-queue
3-
connect_close
42
audit_logread
3+
connect_close
4+
sctp_collision
5+
nf_queue
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# SPDX-License-Identifier: GPL-2.0
2+
3+
top_srcdir = ../../../../..
4+
5+
HOSTPKG_CONFIG := pkg-config
6+
MNL_CFLAGS := $(shell $(HOSTPKG_CONFIG) --cflags libmnl 2>/dev/null)
7+
MNL_LDLIBS := $(shell $(HOSTPKG_CONFIG) --libs libmnl 2>/dev/null || echo -lmnl)
8+
9+
TEST_PROGS := br_netfilter.sh bridge_brouter.sh
10+
TEST_PROGS += br_netfilter_queue.sh
11+
TEST_PROGS += conntrack_icmp_related.sh
12+
TEST_PROGS += conntrack_ipip_mtu.sh
13+
TEST_PROGS += conntrack_tcp_unreplied.sh
14+
TEST_PROGS += conntrack_sctp_collision.sh
15+
TEST_PROGS += conntrack_vrf.sh
16+
TEST_PROGS += ipvs.sh
17+
TEST_PROGS += nf_nat_edemux.sh
18+
TEST_PROGS += nft_audit.sh
19+
TEST_PROGS += nft_concat_range.sh
20+
TEST_PROGS += nft_conntrack_helper.sh
21+
TEST_PROGS += nft_fib.sh
22+
TEST_PROGS += nft_flowtable.sh
23+
TEST_PROGS += nft_meta.sh
24+
TEST_PROGS += nft_nat.sh
25+
TEST_PROGS += nft_nat_zones.sh
26+
TEST_PROGS += nft_queue.sh
27+
TEST_PROGS += nft_synproxy.sh
28+
TEST_PROGS += nft_tproxy_tcp.sh
29+
TEST_PROGS += nft_tproxy_udp.sh
30+
TEST_PROGS += nft_zones_many.sh
31+
TEST_PROGS += rpath.sh
32+
TEST_PROGS += vxlan_mtu_frag.sh
33+
34+
TEST_PROGS_EXTENDED = nft_concat_range_perf.sh
35+
36+
TEST_GEN_FILES = audit_logread
37+
TEST_GEN_FILES += connect_close nf_queue
38+
TEST_GEN_FILES += sctp_collision
39+
40+
include ../../lib.mk
41+
42+
$(OUTPUT)/nf_queue: CFLAGS += $(MNL_CFLAGS)
43+
$(OUTPUT)/nf_queue: LDLIBS += $(MNL_LDLIBS)
44+
45+
TEST_FILES := lib.sh
46+
47+
TEST_INCLUDES := \
48+
../lib.sh
Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
#!/bin/bash
2+
# SPDX-License-Identifier: GPL-2.0
3+
#
4+
# Test for legacy br_netfilter module combined with connection tracking,
5+
# a combination that doesn't really work.
6+
# Multicast/broadcast packets race for hash table insertion.
7+
8+
# eth0 br0 eth0
9+
# setup is: ns1 <->,ns0 <-> ns3
10+
# ns2 <-' `'-> ns4
11+
12+
source lib.sh
13+
14+
checktool "nft --version" "run test without nft tool"
15+
16+
cleanup() {
17+
cleanup_all_ns
18+
}
19+
20+
trap cleanup EXIT
21+
22+
setup_ns ns0 ns1 ns2 ns3 ns4
23+
24+
ret=0
25+
26+
do_ping()
27+
{
28+
fromns="$1"
29+
dstip="$2"
30+
31+
if ! ip netns exec "$fromns" ping -c 1 -q "$dstip" > /dev/null; then
32+
echo "ERROR: ping from $fromns to $dstip"
33+
ip netns exec "$ns0" nft list ruleset
34+
ret=1
35+
fi
36+
}
37+
38+
bcast_ping()
39+
{
40+
fromns="$1"
41+
dstip="$2"
42+
43+
local packets=500
44+
45+
[ "$KSFT_MACHINE_SLOW" = yes ] && packets=100
46+
47+
for i in $(seq 1 $packets); do
48+
if ! ip netns exec "$fromns" ping -q -f -b -c 1 -q "$dstip" > /dev/null 2>&1; then
49+
echo "ERROR: ping -b from $fromns to $dstip"
50+
ip netns exec "$ns0" nft list ruleset
51+
ret=1
52+
break
53+
fi
54+
done
55+
}
56+
57+
ip netns exec "$ns0" sysctl -q net.ipv4.conf.all.rp_filter=0
58+
ip netns exec "$ns0" sysctl -q net.ipv4.conf.default.rp_filter=0
59+
60+
if ! ip link add veth1 netns "$ns0" type veth peer name eth0 netns "$ns1"; then
61+
echo "SKIP: Can't create veth device"
62+
exit $ksft_skip
63+
fi
64+
65+
ip link add veth2 netns "$ns0" type veth peer name eth0 netns "$ns2"
66+
ip link add veth3 netns "$ns0" type veth peer name eth0 netns "$ns3"
67+
ip link add veth4 netns "$ns0" type veth peer name eth0 netns "$ns4"
68+
69+
for i in $(seq 1 4); do
70+
ip -net "$ns0" link set "veth$i" up
71+
done
72+
73+
if ! ip -net "$ns0" link add br0 type bridge stp_state 0 forward_delay 0 nf_call_iptables 1 nf_call_ip6tables 1 nf_call_arptables 1; then
74+
echo "SKIP: Can't create bridge br0"
75+
exit $ksft_skip
76+
fi
77+
78+
# make veth0,1,2 part of bridge.
79+
for i in $(seq 1 3); do
80+
ip -net "$ns0" link set "veth$i" master br0
81+
done
82+
83+
# add a macvlan on top of the bridge.
84+
MACVLAN_ADDR=ba:f3:13:37:42:23
85+
ip -net "$ns0" link add link br0 name macvlan0 type macvlan mode private
86+
ip -net "$ns0" link set macvlan0 address ${MACVLAN_ADDR}
87+
ip -net "$ns0" link set macvlan0 up
88+
ip -net "$ns0" addr add 10.23.0.1/24 dev macvlan0
89+
90+
# add a macvlan on top of veth4.
91+
MACVLAN_ADDR=ba:f3:13:37:42:24
92+
ip -net "$ns0" link add link veth4 name macvlan4 type macvlan mode passthru
93+
ip -net "$ns0" link set macvlan4 address ${MACVLAN_ADDR}
94+
ip -net "$ns0" link set macvlan4 up
95+
96+
# make the macvlan part of the bridge.
97+
# veth4 is not a bridge port, only the macvlan on top of it.
98+
ip -net "$ns0" link set macvlan4 master br0
99+
100+
ip -net "$ns0" link set br0 up
101+
ip -net "$ns0" addr add 10.0.0.1/24 dev br0
102+
103+
modprobe -q br_netfilter
104+
if ! ip netns exec "$ns0" sysctl -q net.bridge.bridge-nf-call-iptables=1; then
105+
echo "SKIP: bridge netfilter not available"
106+
ret=$ksft_skip
107+
fi
108+
109+
# for testing, so namespaces will reply to ping -b probes.
110+
ip netns exec "$ns0" sysctl -q net.ipv4.icmp_echo_ignore_broadcasts=0
111+
112+
# enable conntrack in ns0 and drop broadcast packets in forward to
113+
# avoid them from getting confirmed in the postrouting hook before
114+
# the cloned skb is passed up the stack.
115+
ip netns exec "$ns0" nft -f - <<EOF
116+
table ip filter {
117+
chain input {
118+
type filter hook input priority 1; policy accept
119+
iifname br0 counter
120+
ct state new accept
121+
}
122+
}
123+
124+
table bridge filter {
125+
chain forward {
126+
type filter hook forward priority 0; policy accept
127+
meta pkttype broadcast ip protocol icmp counter drop
128+
}
129+
}
130+
EOF
131+
132+
# place 1, 2 & 3 in same subnet, connected via ns0:br0.
133+
# ns4 is placed in same subnet as well, but its not
134+
# part of the bridge: the corresponding veth4 is not
135+
# part of the bridge, only its macvlan interface.
136+
for i in $(seq 1 4); do
137+
eval ip -net \$ns"$i" link set eth0 up
138+
done
139+
for i in $(seq 1 2); do
140+
eval ip -net \$ns"$i" addr add "10.0.0.1$i/24" dev eth0
141+
done
142+
143+
ip -net "$ns3" addr add 10.23.0.13/24 dev eth0
144+
ip -net "$ns4" addr add 10.23.0.14/24 dev eth0
145+
146+
# test basic connectivity
147+
do_ping "$ns1" 10.0.0.12
148+
do_ping "$ns3" 10.23.0.1
149+
do_ping "$ns4" 10.23.0.1
150+
151+
bcast_ping "$ns1" 10.0.0.255
152+
153+
# This should deliver broadcast to macvlan0, which is on top of ns0:br0.
154+
bcast_ping "$ns3" 10.23.0.255
155+
156+
# same, this time via veth4:macvlan4.
157+
bcast_ping "$ns4" 10.23.0.255
158+
159+
read t < /proc/sys/kernel/tainted
160+
if [ "$t" -eq 0 ];then
161+
echo PASS: kernel not tainted
162+
else
163+
echo ERROR: kernel is tainted
164+
ret=1
165+
fi
166+
167+
exit $ret
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#!/bin/bash
2+
3+
source lib.sh
4+
5+
checktool "nft --version" "run test without nft tool"
6+
7+
cleanup() {
8+
cleanup_all_ns
9+
}
10+
11+
setup_ns c1 c2 c3 sender
12+
13+
trap cleanup EXIT
14+
15+
nf_queue_wait()
16+
{
17+
grep -q "^ *$1 " "/proc/self/net/netfilter/nfnetlink_queue"
18+
}
19+
20+
port_add() {
21+
ns="$1"
22+
dev="$2"
23+
a="$3"
24+
25+
ip link add name "$dev" type veth peer name "$dev" netns "$ns"
26+
27+
ip -net "$ns" addr add 192.168.1."$a"/24 dev "$dev"
28+
ip -net "$ns" link set "$dev" up
29+
30+
ip link set "$dev" master br0
31+
ip link set "$dev" up
32+
}
33+
34+
[ "${1}" != "run" ] && { unshare -n "${0}" run; exit $?; }
35+
36+
ip link add br0 type bridge
37+
ip addr add 192.168.1.254/24 dev br0
38+
39+
port_add "$c1" "c1" 1
40+
port_add "$c2" "c2" 2
41+
port_add "$c3" "c3" 3
42+
port_add "$sender" "sender" 253
43+
44+
ip link set br0 up
45+
46+
modprobe -q br_netfilter
47+
48+
sysctl net.bridge.bridge-nf-call-iptables=1 || exit 1
49+
50+
ip netns exec "$sender" ping -I sender -c1 192.168.1.1 || exit 1
51+
ip netns exec "$sender" ping -I sender -c1 192.168.1.2 || exit 2
52+
ip netns exec "$sender" ping -I sender -c1 192.168.1.3 || exit 3
53+
54+
nft -f /dev/stdin <<EOF
55+
table ip filter {
56+
chain forward {
57+
type filter hook forward priority 0; policy accept;
58+
ct state new counter
59+
ip protocol icmp counter queue num 0 bypass
60+
}
61+
}
62+
EOF
63+
./nf_queue -t 5 > /dev/null &
64+
65+
busywait 5000 nf_queue_wait
66+
67+
for i in $(seq 1 5); do conntrack -F > /dev/null 2> /dev/null; sleep 0.1 ; done &
68+
ip netns exec "$sender" ping -I sender -f -c 50 -b 192.168.1.255
69+
70+
read t < /proc/sys/kernel/tainted
71+
if [ "$t" -eq 0 ];then
72+
echo PASS: kernel not tainted
73+
else
74+
echo ERROR: kernel is tainted
75+
exit 1
76+
fi
77+
78+
exit 0

0 commit comments

Comments
 (0)