From: Pablo Neira Ayuso <pablo@netfilter.org> Date: 2021-11-18 22:26:31
Hi,
The following patchset contains Netfilter/IPVS fixes for net:
1) Add selftest for vrf+conntrack, from Florian Westphal.
2) Extend nfqueue selftest to cover nfqueue, also from Florian.
3) Remove duplicated include in nft_payload, from Wan Jiabing.
4) Several improvements to the nat port shadowing selftest,
from Phil Sutter.
5) Fix filtering of reply tuple in ctnetlink, from Florent Fourcot.
6) Do not override error with -EINVAL in filter setup path, also
from Florent.
7) Honor sysctl_expire_nodest_conn regardless conn_reuse_mode for
reused connections, from yangxingwu.
8) Replace snprintf() by sysfs_emit() in xt_IDLETIMER as reported
by Coccinelle, from Jing Yao.
9) Incorrect IPv6 tunnel match in flowtable offload, from Will
Mortensen.
10) Switch port shadow selftest to use socat, from Florian Westphal.
Please, pull these changes from:
git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf.git
Thanks.
----------------------------------------------------------------
The following changes since commit c45231a7668d6b632534f692b10592ea375b55b0:
litex_liteeth: Fix a double free in the remove function (2021-11-07 21:51:17 +0000)
are available in the Git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf.git HEAD
for you to fetch changes up to a2acf0c0e2da29950d0361a3b5ea05e8d0351dfe:
selftests: nft_nat: switch port shadow test cases to socat (2021-11-15 12:02:11 +0100)
----------------------------------------------------------------
Florent Fourcot (2):
netfilter: ctnetlink: fix filtering with CTA_TUPLE_REPLY
netfilter: ctnetlink: do not erase error code with EINVAL
Florian Westphal (3):
selftests: netfilter: add a vrf+conntrack testcase
selftests: netfilter: extend nfqueue tests to cover vrf device
selftests: nft_nat: switch port shadow test cases to socat
Jing Yao (1):
netfilter: xt_IDLETIMER: replace snprintf in show functions with sysfs_emit
Phil Sutter (2):
selftests: nft_nat: Improve port shadow test stability
selftests: nft_nat: Simplify port shadow notrack test
Wan Jiabing (1):
netfilter: nft_payload: Remove duplicated include in nft_payload.c
Will Mortensen (1):
netfilter: flowtable: fix IPv6 tunnel addr match
yangxingwu (1):
netfilter: ipvs: Fix reuse connection if RS weight is 0
Documentation/networking/ipvs-sysctl.rst | 3 +-
net/netfilter/ipvs/ip_vs_core.c | 8 +-
net/netfilter/nf_conntrack_netlink.c | 6 +-
net/netfilter/nf_flow_table_offload.c | 4 +-
net/netfilter/nft_payload.c | 1 -
net/netfilter/xt_IDLETIMER.c | 4 +-
tools/testing/selftests/netfilter/Makefile | 3 +-
tools/testing/selftests/netfilter/conntrack_vrf.sh | 219 +++++++++++++++++++++
tools/testing/selftests/netfilter/nft_nat.sh | 33 +++-
tools/testing/selftests/netfilter/nft_queue.sh | 54 +++++
10 files changed, 309 insertions(+), 26 deletions(-)
create mode 100755 tools/testing/selftests/netfilter/conntrack_vrf.sh
From: Pablo Neira Ayuso <pablo@netfilter.org> Date: 2021-11-18 22:26:32
From: Florian Westphal <fw@strlen.de>
Rework the reproducer for the vrf+conntrack regression reported
by Eugene into a selftest and also add a test for ip masquerading
that Lahav fixed recently.
With net or net-next tree, the first test fails and the latter
two pass.
With 09e856d54bda5f28 ("vrf: Reset skb conntrack connection on VRF rcv")
reverted first test passes but the last two fail.
A proper fix needs more work, for time being a revert seems to be
the best choice, snat/masquerade did not work before the fix.
Link: https://lore.kernel.org/netdev/378ca299-4474-7e9a-3d36-2350c8c98995@gmail.com/T/#m95358a31810df7392f541f99d187227bc75c9963
Reported-by: Eugene Crosser <redacted>
Cc: Lahav Schlesinger <redacted>
Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
tools/testing/selftests/netfilter/Makefile | 3 +-
.../selftests/netfilter/conntrack_vrf.sh | 219 ++++++++++++++++++
2 files changed, 221 insertions(+), 1 deletion(-)
create mode 100755 tools/testing/selftests/netfilter/conntrack_vrf.sh
@@ -0,0 +1,219 @@+#!/bin/sh++# This script demonstrates interaction of conntrack and vrf.+# The vrf driver calls the netfilter hooks again, with oif/iif+# pointing at the VRF device.+#+# For ingress, this means first iteration has iifname of lower/real+# device. In this script, thats veth0.+# Second iteration is iifname set to vrf device, tvrf in this script.+#+# For egress, this is reversed: first iteration has the vrf device,+# second iteration is done with the lower/real/veth0 device.+#+# test_ct_zone_in demonstrates unexpected change of nftables+# behavior # caused by commit 09e856d54bda5f28 "vrf: Reset skb conntrack+# connection on VRF rcv"+#+# It was possible to assign conntrack zone to a packet (or mark it for+# `notracking`) in the prerouting chain before conntrack, based on real iif.+#+# After the change, the zone assignment is lost and the zone is assigned based+# on the VRF master interface (in case such a rule exists).+# assignment is lost. Instead, assignment based on the `iif` matching+# Thus it is impossible to distinguish packets based on the original+# interface.+#+# test_masquerade_vrf and test_masquerade_veth0 demonstrate the problem+# that was supposed to be fixed by the commit mentioned above to make sure+# that any fix to test case 1 won't break masquerade again.++ksft_skip=4++IP0=172.30.30.1+IP1=172.30.30.2+PFXL=30+ret=0++sfx=$(mktemp-u"XXXXXXXX")+ns0="ns0-$sfx"+ns1="ns1-$sfx"++cleanup()+{+ipnetnspids$ns0|xargskill2>/dev/null+ipnetnspids$ns1|xargskill2>/dev/null++ipnetnsdel$ns0$ns1+}++nft--version>/dev/null2>&1+if[$?-ne0];then+echo"SKIP: Could not run test without nft tool"+exit$ksft_skip+fi++ip-Version>/dev/null2>&1+if[$?-ne0];then+echo"SKIP: Could not run test without ip tool"+exit$ksft_skip+fi++ipnetnsadd"$ns0"+if[$?-ne0];then+echo"SKIP: Could not create net namespace $ns0"+exit$ksft_skip+fi+ipnetnsadd"$ns1"++trapcleanupEXIT++ipnetnsexec$ns0sysctl-q-wnet.ipv4.conf.default.rp_filter=0+ipnetnsexec$ns0sysctl-q-wnet.ipv4.conf.all.rp_filter=0+ipnetnsexec$ns0sysctl-q-wnet.ipv4.conf.all.rp_filter=0++iplinkaddveth0netns"$ns0"typevethpeernameveth0netns"$ns1">/dev/null2>&1+if[$?-ne0];then+echo"SKIP: Could not add veth device"+exit$ksft_skip+fi++ip-net$ns0liaddtvrftypevrftable9876+if[$?-ne0];then+echo"SKIP: Could not add vrf device"+exit$ksft_skip+fi++ip-net$ns0lisetloup++ip-net$ns0lisetveth0mastertvrf+ip-net$ns0lisettvrfup+ip-net$ns0lisetveth0up+ip-net$ns1lisetveth0up++ip-net$ns0addradd$IP0/$PFXLdevveth0+ip-net$ns1addradd$IP1/$PFXLdevveth0++ipnetnsexec$ns1iperf3-s>/dev/null2>&1&+if[$?-ne0];then+echo"SKIP: Could not start iperf3"+exit$ksft_skip+fi++# test vrf ingress handling.+# The incoming connection should be placed in conntrack zone 1,+# as decided by the first iteration of the ruleset.+test_ct_zone_in()+{+ipnetnsexec$ns0nft-f-<<EOF+tabletestct{+chainrawpre{+typefilterhookpreroutingpriorityraw;++iif{veth0,tvrf}countermetanftraceset1+iifveth0counterctzoneset1counterreturn+iiftvrfcounterctzoneset2counterreturn+ipprotocolicmpcounter+notrackcounter+}++chainrawout{+typefilterhookoutputpriorityraw;++oifveth0counterctzoneset1counterreturn+oiftvrfcounterctzoneset2counterreturn+notrackcounter+}+}+EOF+ipnetnsexec$ns1ping-W1-c1-Iveth0$IP0>/dev/null++# should be in zone 1, not zone 2+count=$(ipnetnsexec$ns0conntrack-L-s$IP1-d$IP0-picmp--zone12>/dev/null|wc-l)+if[$count-eq1];then+echo"PASS: entry found in conntrack zone 1"+else+echo"FAIL: entry not found in conntrack zone 1"+count=$(ipnetnsexec$ns0conntrack-L-s$IP1-d$IP0-picmp--zone22>/dev/null|wc-l)+if[$count-eq1];then+echo"FAIL: entry found in zone 2 instead"+else+echo"FAIL: entry not in zone 1 or 2, dumping table"+ipnetnsexec$ns0conntrack-L+ipnetnsexec$ns0nftlistruleset+fi+fi+}++# add masq rule that gets evaluated w. outif set to vrf device.+# This tests the first iteration of the packet through conntrack,+# oifname is the vrf device.+test_masquerade_vrf()+{+ipnetnsexec$ns0conntrack-F2>/dev/null++ipnetnsexec$ns0nft-f-<<EOF+flushruleset+tableipnat{+chainpostrouting{+typenathookpostroutingpriority0;+# NB: masquerade should always be combined with 'oif(name) bla',+# lack of this is intentional here, we want to exercise double-snat.+ipsaddr172.30.30.0/30countermasqueraderandom+}+}+EOF+ipnetnsexec$ns0ipvrfexectvrfiperf3-t1-c$IP1>/dev/null+if[$?-ne0];then+echo"FAIL: iperf3 connect failure with masquerade + sport rewrite on vrf device"+ret=1+return+fi++# must also check that nat table was evaluated on second (lower device) iteration.+ipnetnsexec$ns0nftlisttableipnat|grep-q'counter packets 2'+if[$?-eq0];then+echo"PASS: iperf3 connect with masquerade + sport rewrite on vrf device"+else+echo"FAIL: vrf masq rule has unexpected counter value"+ret=1+fi+}++# add masq rule that gets evaluated w. outif set to veth device.+# This tests the 2nd iteration of the packet through conntrack,+# oifname is the lower device (veth0 in this case).+test_masquerade_veth()+{+ipnetnsexec$ns0conntrack-F2>/dev/null+ipnetnsexec$ns0nft-f-<<EOF+flushruleset+tableipnat{+chainpostrouting{+typenathookpostroutingpriority0;+metaoifveth0ipsaddr172.30.30.0/30countermasqueraderandom+}+}+EOF+ipnetnsexec$ns0ipvrfexectvrfiperf3-t1-c$IP1>/dev/null+if[$?-ne0];then+echo"FAIL: iperf3 connect failure with masquerade + sport rewrite on veth device"+ret=1+return+fi++# must also check that nat table was evaluated on second (lower device) iteration.+ipnetnsexec$ns0nftlisttableipnat|grep-q'counter packets 2'+if[$?-eq0];then+echo"PASS: iperf3 connect with masquerade + sport rewrite on veth device"+else+echo"FAIL: vrf masq rule has unexpected counter value"+ret=1+fi+}++test_ct_zone_in+test_masquerade_vrf+test_masquerade_veth++exit$ret
From: Pablo Neira Ayuso <pablo@netfilter.org> Date: 2021-11-18 22:26:34
From: Florian Westphal <fw@strlen.de>
VRF device calls the output/postrouting hooks so packet should be seeon
with oifname tvrf and once with eth0.
Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
.../testing/selftests/netfilter/nft_queue.sh | 54 +++++++++++++++++++
1 file changed, 54 insertions(+)
From: Pablo Neira Ayuso <pablo@netfilter.org> Date: 2021-11-18 22:26:38
From: Phil Sutter <phil@nwl.cc>
Setup phase in test_port_shadow() relied upon a race-condition:
Listening nc on port 1405 was started in background before attempting to
create the fake conntrack entry using the same source port. If listening
nc won, fake conntrack entry could not be created causing wrong
behaviour. Reorder nc calls to fix this and introduce a short delay
before testing the setup to wait for listening nc process startup.
Fixes: 465f15a6d1a8f ("selftests: nft_nat: add udp hole punch test case")
Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
tools/testing/selftests/netfilter/nft_nat.sh | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
@@ -759,14 +759,16 @@ test_port_shadow()localresult=""locallogmsg=""+# make shadow entry, from client (ns2), going to (ns1), port 41404, sport 1405.+echo"fake-entry"|ipnetnsexec"$ns2"nc-w1-p1405-u"$daddrc"41404>/dev/null+echoROUTER|ipnetnsexec"$ns0"nc-w5-u-l-p1405>/dev/null2>&1&nc_r=$!echoCLIENT|ipnetnsexec"$ns2"nc-w5-u-l-p1405>/dev/null2>&1&nc_c=$!-# make shadow entry, from client (ns2), going to (ns1), port 41404, sport 1405.-echo"fake-entry"|ipnetnsexec"$ns2"nc-w1-p1405-u"$daddrc"41404>/dev/null+sleep0.3# ns1 tries to connect to ns0:1405. With default settings this should connect# to client, it matches the conntrack entry created above.
From: Pablo Neira Ayuso <pablo@netfilter.org> Date: 2021-11-18 22:26:41
From: Wan Jiabing <redacted>
Fix following checkincludes.pl warning:
./net/netfilter/nft_payload.c: linux/ip.h is included more than once.
Signed-off-by: Wan Jiabing <redacted>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
net/netfilter/nft_payload.c | 1 -
1 file changed, 1 deletion(-)
From: Pablo Neira Ayuso <pablo@netfilter.org> Date: 2021-11-18 22:26:42
From: Jing Yao <redacted>
coccicheck complains about the use of snprintf() in sysfs show
functions:
WARNING use scnprintf or sprintf
Use sysfs_emit instead of scnprintf, snprintf or sprintf makes more
sense.
Reported-by: Zeal Robot <redacted>
Signed-off-by: Jing Yao <redacted>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
net/netfilter/xt_IDLETIMER.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
From: Pablo Neira Ayuso <pablo@netfilter.org> Date: 2021-11-18 22:26:42
From: Phil Sutter <phil@nwl.cc>
The second rule in prerouting chain was probably a leftover: The router
listens on veth0, so not tracking connections via that interface is
sufficient. Likewise, the rule in output chain can be limited to that
interface as well.
Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
tools/testing/selftests/netfilter/nft_nat.sh | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
From: Pablo Neira Ayuso <pablo@netfilter.org> Date: 2021-11-18 22:26:42
From: yangxingwu <redacted>
We are changing expire_nodest_conn to work even for reused connections when
conn_reuse_mode=0, just as what was done with commit dc7b3eb900aa ("ipvs:
Fix reuse connection if real server is dead").
For controlled and persistent connections, the new connection will get the
needed real server depending on the rules in ip_vs_check_template().
Fixes: d752c3645717 ("ipvs: allow rescheduling of new connections when port reuse is detected")
Co-developed-by: Chuanqi Liu <redacted>
Signed-off-by: Chuanqi Liu <redacted>
Signed-off-by: yangxingwu <redacted>
Acked-by: Simon Horman <horms@verge.net.au>
Acked-by: Julian Anastasov <ja@ssi.bg>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
Documentation/networking/ipvs-sysctl.rst | 3 +--
net/netfilter/ipvs/ip_vs_core.c | 8 ++++----
2 files changed, 5 insertions(+), 6 deletions(-)
@@ -37,8 +37,7 @@ conn_reuse_mode - INTEGER 0: disable any special handling on port reuse. The new connection will be delivered to the same real server that was- servicing the previous connection. This will effectively- disable expire_nodest_conn.+ servicing the previous connection. bit 1: enable rescheduling of new connections when it is safe. That is, whenever expire_nodest_conn and for TCP sockets, when
From: Pablo Neira Ayuso <pablo@netfilter.org> Date: 2021-11-18 22:26:43
From: Florian Westphal <fw@strlen.de>
There are now at least three distinct flavours of netcat/nc tool:
'original' version, one version ported from openbsd and nmap-ncat.
The script only works with original because it sets SOREUSEPORT option.
Other nc versions return 'port already in use' error and port shadow test fails:
PASS: inet IPv6 redirection for ns2-hMHcaRvx
nc: bind failed: Address already in use
ERROR: portshadow test default: got reply from "ROUTER", not CLIENT as intended
Switch to socat instead.
Reported-by: kernel test robot <redacted>
Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
tools/testing/selftests/netfilter/nft_nat.sh | 26 ++++++++++++++------
1 file changed, 19 insertions(+), 7 deletions(-)
@@ -760,20 +760,20 @@ test_port_shadow()locallogmsg=""# make shadow entry, from client (ns2), going to (ns1), port 41404, sport 1405.-echo"fake-entry"|ipnetnsexec"$ns2"nc-w1-p1405-u"$daddrc"41404>/dev/null+echo"fake-entry"|ipnetnsexec"$ns2"timeout1socat-uSTDINUDP:"$daddrc":41404,sourceport=1405-echoROUTER|ipnetnsexec"$ns0"nc-w5-u-l-p1405>/dev/null2>&1&-nc_r=$!+echoROUTER|ipnetnsexec"$ns0"timeout5socat-uSTDINUDP4-LISTEN:1405&+sc_r=$!-echoCLIENT|ipnetnsexec"$ns2"nc-w5-u-l-p1405>/dev/null2>&1&-nc_c=$!+echoCLIENT|ipnetnsexec"$ns2"timeout5socat-uSTDINUDP4-LISTEN:1405,reuseport&+sc_c=$!sleep0.3# ns1 tries to connect to ns0:1405. With default settings this should connect# to client, it matches the conntrack entry created above.-result=$(echo""|ipnetnsexec"$ns1"nc-w1-p41404-u"$daddrs"1405)+result=$(echo"data"|ipnetnsexec"$ns1"timeout1socat-UDP:"$daddrs":1405,sourceport=41404)if["$result"="$expect"];thenecho"PASS: portshadow test $test: got reply from ${expect}${logmsg}"
@@ -782,7 +782,7 @@ test_port_shadow()ret=1fi-kill$nc_r$nc_c2>/dev/null+kill$sc_r$sc_c2>/dev/null# flush udp entries for next test round, if anyipnetnsexec"$ns0"conntrack-F>/dev/null2>&1
@@ -852,6 +852,18 @@ test_port_shadowing(){localfamily="ip"+conntrack-h>/dev/null2>&1+if[$?-ne0];then+echo"SKIP: Could not run nat port shadowing test without conntrack tool"+return+fi++socat-h>/dev/null2>&1+if[$?-ne0];then+echo"SKIP: Could not run nat port shadowing test without socat tool"+return+fi+ipnetnsexec"$ns0"sysctlnet.ipv4.conf.veth0.forwarding=1>/dev/nullipnetnsexec"$ns0"sysctlnet.ipv4.conf.veth1.forwarding=1>/dev/null
From: Pablo Neira Ayuso <pablo@netfilter.org> Date: 2021-11-18 22:26:43
From: Will Mortensen <redacted>
Previously the IPv6 addresses in the key were clobbered and the mask was
left unset.
I haven't tested this; I noticed it while skimming the code to
understand an unrelated issue.
Fixes: cfab6dbd0ecf ("netfilter: flowtable: add tunnel match offload support")
Cc: wenxu <redacted>
Signed-off-by: Will Mortensen <redacted>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
net/netfilter/nf_flow_table_offload.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
Hello:
This series was applied to netdev/net.git (master)
by Pablo Neira Ayuso [off-list ref]:
On Thu, 18 Nov 2021 23:26:08 +0100 you wrote:
From: Florian Westphal <fw@strlen.de>
Rework the reproducer for the vrf+conntrack regression reported
by Eugene into a selftest and also add a test for ip masquerading
that Lahav fixed recently.
With net or net-next tree, the first test fails and the latter
two pass.
[...]