Skip to content

Commit 525de9a

Browse files
committed
Merge ra.kernel.org:/pub/scm/linux/kernel/git/netfilter/nf
Pablo Neira Ayuso says: ==================== Netfilter fixes for net The following patchset contains Netfilter fixes for net: 1) Add selftest for nft_synproxy, from Florian Westphal. 2) xt_socket destroy path incorrectly disables IPv4 defrag for IPv6 traffic (typo), from Eric Dumazet. 3) Fix exit value selftest nft_concat_range.sh, from Hangbin Liu. 4) nft_synproxy disables the IPv4 hooks if the IPv6 hooks fail to be registered. 5) disable rp_filter on router in selftest nft_fib.sh, also from Hangbin Liu. ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents dcd5426 + bbe4c08 commit 525de9a

File tree

6 files changed

+124
-4
lines changed

6 files changed

+124
-4
lines changed

net/netfilter/nft_synproxy.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,10 @@ static int nft_synproxy_do_init(const struct nft_ctx *ctx,
191191
if (err)
192192
goto nf_ct_failure;
193193
err = nf_synproxy_ipv6_init(snet, ctx->net);
194-
if (err)
194+
if (err) {
195+
nf_synproxy_ipv4_fini(snet, ctx->net);
195196
goto nf_ct_failure;
197+
}
196198
break;
197199
}
198200

net/netfilter/xt_socket.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ static void socket_mt_destroy(const struct xt_mtdtor_param *par)
221221
if (par->family == NFPROTO_IPV4)
222222
nf_defrag_ipv4_disable(par->net);
223223
else if (par->family == NFPROTO_IPV6)
224-
nf_defrag_ipv4_disable(par->net);
224+
nf_defrag_ipv6_disable(par->net);
225225
}
226226

227227
static struct xt_match socket_mt_reg[] __read_mostly = {

tools/testing/selftests/netfilter/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ TEST_PROGS := nft_trans_stress.sh nft_fib.sh nft_nat.sh bridge_brouter.sh \
66
nft_concat_range.sh nft_conntrack_helper.sh \
77
nft_queue.sh nft_meta.sh nf_nat_edemux.sh \
88
ipip-conntrack-mtu.sh conntrack_tcp_unreplied.sh \
9-
conntrack_vrf.sh
9+
conntrack_vrf.sh nft_synproxy.sh
1010

1111
LDLIBS = -lmnl
1212
TEST_GEN_FILES = nf-queue

tools/testing/selftests/netfilter/nft_concat_range.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1601,4 +1601,4 @@ for name in ${TESTS}; do
16011601
done
16021602
done
16031603

1604-
[ ${passed} -eq 0 ] && exit ${KSELFTEST_SKIP}
1604+
[ ${passed} -eq 0 ] && exit ${KSELFTEST_SKIP} || exit 0

tools/testing/selftests/netfilter/nft_fib.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ test_ping() {
174174
ip netns exec ${nsrouter} sysctl net.ipv6.conf.all.forwarding=1 > /dev/null
175175
ip netns exec ${nsrouter} sysctl net.ipv4.conf.veth0.forwarding=1 > /dev/null
176176
ip netns exec ${nsrouter} sysctl net.ipv4.conf.veth1.forwarding=1 > /dev/null
177+
ip netns exec ${nsrouter} sysctl net.ipv4.conf.veth0.rp_filter=0 > /dev/null
177178

178179
sleep 3
179180

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
#!/bin/bash
2+
# SPDX-License-Identifier: GPL-2.0
3+
#
4+
5+
# Kselftest framework requirement - SKIP code is 4.
6+
ksft_skip=4
7+
ret=0
8+
9+
rnd=$(mktemp -u XXXXXXXX)
10+
nsr="nsr-$rnd" # synproxy machine
11+
ns1="ns1-$rnd" # iperf client
12+
ns2="ns2-$rnd" # iperf server
13+
14+
checktool (){
15+
if ! $1 > /dev/null 2>&1; then
16+
echo "SKIP: Could not $2"
17+
exit $ksft_skip
18+
fi
19+
}
20+
21+
checktool "nft --version" "run test without nft tool"
22+
checktool "ip -Version" "run test without ip tool"
23+
checktool "iperf3 --version" "run test without iperf3"
24+
checktool "ip netns add $nsr" "create net namespace"
25+
26+
modprobe -q nf_conntrack
27+
28+
ip netns add $ns1
29+
ip netns add $ns2
30+
31+
cleanup() {
32+
ip netns pids $ns1 | xargs kill 2>/dev/null
33+
ip netns pids $ns2 | xargs kill 2>/dev/null
34+
ip netns del $ns1
35+
ip netns del $ns2
36+
37+
ip netns del $nsr
38+
}
39+
40+
trap cleanup EXIT
41+
42+
ip link add veth0 netns $nsr type veth peer name eth0 netns $ns1
43+
ip link add veth1 netns $nsr type veth peer name eth0 netns $ns2
44+
45+
for dev in lo veth0 veth1; do
46+
ip -net $nsr link set $dev up
47+
done
48+
49+
ip -net $nsr addr add 10.0.1.1/24 dev veth0
50+
ip -net $nsr addr add 10.0.2.1/24 dev veth1
51+
52+
ip netns exec $nsr sysctl -q net.ipv4.conf.veth0.forwarding=1
53+
ip netns exec $nsr sysctl -q net.ipv4.conf.veth1.forwarding=1
54+
ip netns exec $nsr sysctl -q net.netfilter.nf_conntrack_tcp_loose=0
55+
56+
for n in $ns1 $ns2; do
57+
ip -net $n link set lo up
58+
ip -net $n link set eth0 up
59+
done
60+
ip -net $ns1 addr add 10.0.1.99/24 dev eth0
61+
ip -net $ns2 addr add 10.0.2.99/24 dev eth0
62+
ip -net $ns1 route add default via 10.0.1.1
63+
ip -net $ns2 route add default via 10.0.2.1
64+
65+
# test basic connectivity
66+
if ! ip netns exec $ns1 ping -c 1 -q 10.0.2.99 > /dev/null; then
67+
echo "ERROR: $ns1 cannot reach $ns2" 1>&2
68+
exit 1
69+
fi
70+
71+
if ! ip netns exec $ns2 ping -c 1 -q 10.0.1.99 > /dev/null; then
72+
echo "ERROR: $ns2 cannot reach $ns1" 1>&2
73+
exit 1
74+
fi
75+
76+
ip netns exec $ns2 iperf3 -s > /dev/null 2>&1 &
77+
# ip netns exec $nsr tcpdump -vvv -n -i veth1 tcp | head -n 10 &
78+
79+
sleep 1
80+
81+
ip netns exec $nsr nft -f - <<EOF
82+
table inet filter {
83+
chain prerouting {
84+
type filter hook prerouting priority -300; policy accept;
85+
meta iif veth0 tcp flags syn counter notrack
86+
}
87+
88+
chain forward {
89+
type filter hook forward priority 0; policy accept;
90+
91+
ct state new,established counter accept
92+
93+
meta iif veth0 meta l4proto tcp ct state untracked,invalid synproxy mss 1460 sack-perm timestamp
94+
95+
ct state invalid counter drop
96+
97+
# make ns2 unreachable w.o. tcp synproxy
98+
tcp flags syn counter drop
99+
}
100+
}
101+
EOF
102+
if [ $? -ne 0 ]; then
103+
echo "SKIP: Cannot add nft synproxy"
104+
exit $ksft_skip
105+
fi
106+
107+
ip netns exec $ns1 timeout 5 iperf3 -c 10.0.2.99 -n $((1 * 1024 * 1024)) > /dev/null
108+
109+
if [ $? -ne 0 ]; then
110+
echo "FAIL: iperf3 returned an error" 1>&2
111+
ret=$?
112+
ip netns exec $nsr nft list ruleset
113+
else
114+
echo "PASS: synproxy connection successful"
115+
fi
116+
117+
exit $ret

0 commit comments

Comments
 (0)