tests: shell: add packetpath test for meta ibrhwdr
PATCH 1/1 tests: shell: add packetpath test for meta ibrhwdr
The test checks that the packets are processed by the bridge device and not forwarded.
---
Please keep on mind that this requires:
* https://lore.kernel.org/netfilter-devel/[email protected]/
* https://lore.kernel.org/netfilter-devel/[email protected]/
--- tests/shell/features/meta_ibrhwdr.nft | 8 ++ .../shell/testcases/packetpath/bridge_pass_up | 83 +++++++++++++++++++ 2 files changed, 91 insertions(+) create mode 100644 tests/shell/features/meta_ibrhwdr.nft create mode 100755 tests/shell/testcases/packetpath/bridge_pass_up
tests/shell/features/meta_ibrhwdr.nft new file +8 -0
@@ -0,0 +1,8 @@ +# cbd2257dc96e ("netfilter: nft_meta_bridge: introduce NFT_META_BRI_IIFHWADDR support") +# v6.16-rc2-16052-gcbd2257dc96e +table bridge nat { + chain PREROUTING { + type filter hook prerouting priority 0; policy accept; + ether daddr set meta ibrhwdr + } +}
tests/shell/testcases/packetpath/bridge_pass_up new file +83 -0
83 lines not on this page · raw message
Signature · 1 line
2.51.0
Quoted 21 lines · Fernando Fernandez Mancera
The test checks that the packets are processed by the bridge device and not forwarded.
Signed-off-by Fernando Fernandez Mancera <[email protected]>---
Please keep on mind that this requires:
* https://lore.kernel.org/netfilter-devel/[email protected]/
* https://lore.kernel.org/netfilter-devel/[email protected]/--- tests/shell/features/meta_ibrhwdr.nft | 8 ++ .../shell/testcases/packetpath/bridge_pass_up | 83 +++++++++++++++++++ 2 files changed, 91 insertions(+)create mode 100644 tests/shell/features/meta_ibrhwdr.nft create mode 100755 tests/shell/testcases/packetpath/bridge_pass_up
tests/shell/features/meta_ibrhwdr.nft new file +0
-0
tests/shell/features/meta_ibrhwdr.nft line 2
Quoted 2 lines
tests/shell/features/meta_ibrhwdr.nft new file +2
-0@@ -0,0 +1,8 @@ +# cbd2257dc96e ("netfilter: nft_meta_bridge: introduce NFT_META_BRI_IIFHWADDR support") +# v6.16-rc2-16052-gcbd2257dc96e
I just noticed this version is wrong. Probably I need to wait until 6.18-rc1 and resend this. Anyway, feedback on the test is more than welcome :-)
Florian Westphal
maintainerQuoted 6 lines · Fernando Fernandez Mancera
tests/shell/features/meta_ibrhwdr.nft line 2
Quoted 2 lines
tests/shell/features/meta_ibrhwdr.nft new file +2
-0+# cbd2257dc96e ("netfilter: nft_meta_bridge: introduce NFT_META_BRI_IIFHWADDR support") +# v6.16-rc2-16052-gcbd2257dc96eI just noticed this version is wrong. Probably I need to wait until 6.18-rc1 and resend this. Anyway, feedback on the test is more than welcome :-)
No worries, this looks good!
Do you think it makes sense to also add a counter-hook in ipv4 input?
Quoted 11 lines · Florian Westphal
Quoted 6 lines · Fernando Fernandez Mancera
tests/shell/features/meta_ibrhwdr.nft line 2
Quoted 2 lines
tests/shell/features/meta_ibrhwdr.nft new file +2
-0+# cbd2257dc96e ("netfilter: nft_meta_bridge: introduce NFT_META_BRI_IIFHWADDR support") +# v6.16-rc2-16052-gcbd2257dc96eI just noticed this version is wrong. Probably I need to wait until 6.18-rc1 and resend this. Anyway, feedback on the test is more than welcome :-)
No worries, this looks good!
Do you think it makes sense to also add a counter-hook in ipv4 input?
I don't think so as in $ns2 the counter would be always zero, with or without the meta ibrhwdr rule.
Thanks!
Florian Westphal
maintainerQuoted 2 lines · Fernando Fernandez Mancera
The test checks that the packets are processed by the bridge device and not forwarded.
OK, I think it would make sense to also check that we can do something useful with the packet.
Quoted 5 lines
(quoted diff) +5
-0+ +ip -net "$ns1" link set veth0 up +ip -net "$ns2" link set veth0 up +ip -net "$ns3" link set veth1 up +ip -net "$ns2" link set veth1 up
Review
Quoted 10 lines
(quoted diff) +10
-0+ip -net "$ns2" link set br0 up + +ip -net "$ns1" addr add 10.1.1.10/24 dev veth0 +ip -net "$ns3" addr add 10.1.1.20/24 dev veth1 + +ip netns exec "$ns2" $NFT -f /dev/stdin <<"EOF" +table bridge nat { + chain PREROUTING { + type filter hook prerouting priority 0; policy accept; + ether daddr de:ad:00:00:be:ef meta pkttype set host ether daddr set meta ibrhwdr
While this indeed is enough to check the bridge 'redirect to input' maybe it would make sense to also check that we can do something useful with it?
The bridge has no ip address, so I don't really see the point why anyone would redirect the packet locally to begin with.
Quoted 6 lines
(quoted diff) +6
-0+table bridge donotprocess { + chain FORWARD { + type filter hook forward priority 0; policy accept; + ip protocol icmp ether saddr da:d3:00:01:02:03 counter + } +}
Review
Quoted 10 lines
(quoted diff) +10
-0+EOF + +ip netns exec "$ns1" ping -c 1 10.1.1.20 || true + +set +e + +ip netns exec "$ns2" $NFT list table bridge process | grep 'counter packets 0' +if [ $? -eq 0 ] +then + exit 1
I think it would be nice to display WHERE its failing so that someone looking at testout.log doesn't have to re-run with added "set -x" or "echo failed at".
To give some ideas (this isn't fleshed out):
tests/shell/testcases/packetpath/bridge_pass_up +12 -1
@@ -38,14 +38,18 @@ ip -net "$ns3" link set veth1 up ip -net "$ns2" link set veth1 up ip -net "$ns2" link set br0 up +ip netns exec "$ns2" sysctl -q net.ipv4.ip_forward=1 + ip -net "$ns1" addr add 10.1.1.10/24 dev veth0 ip -net "$ns3" addr add 10.1.1.20/24 dev veth1 +ip -net "$ns2" addr add 10.1.1.1/24 dev br0 ip netns exec "$ns2" $NFT -f /dev/stdin <<"EOF" table bridge nat { chain PREROUTING { type filter hook prerouting priority 0; policy accept; - ether daddr de:ad:00:00:be:ef meta pkttype set host ether daddr set meta ibrhwdr + ether daddr de:ad:00:00:be:ef meta pkttype set host ether daddr set meta ibrhwdr meta mark set 1 } }
@@ -62,9 +66,19 @@ table bridge donotprocess { ip protocol icmp ether saddr da:d3:00:01:02:03 counter } } + +table ip process { + chain FORWARD { + type filter hook forward priority 0; policy accept; + ip protocol icmp mark 1 counter + } + +} EOF
ALTERNATIVELY one could check INPUT instead (no fwd sysctl) by also doing 'ip daddr set 10.1.1.1' in bridge or ip prerouting and then checking if the packet made it to the ip input hook.
I only ever saw 3 cases of this 'bridge hijacking' implemented via meta ibrhwdr:
1. Push packets up to mangle them via NAT. In most cases people did this with br_netfilter + iptables, but it would be nice to make sure we have a working alternative to that thing.
2. Push packet to local host/application, e.g. for TPROXY intercept.
3. Push packet to local host for forwarding/policy routing.
I think that 'it arrived in ip input or forwarding'
would be good because then the above (tproxy, nat, etc. should "just work").
But if you think checking bridge input is enough, thats fine.
Quoted 27 lines · Florian Westphal
Quoted 2 lines · Fernando Fernandez Mancera
The test checks that the packets are processed by the bridge device and not forwarded.
OK, I think it would make sense to also check that we can do something useful with the packet.
Quoted 5 lines
(quoted diff) +5
-0+ +ip -net "$ns1" link set veth0 up +ip -net "$ns2" link set veth0 up +ip -net "$ns3" link set veth1 up +ip -net "$ns2" link set veth1 upReview
Quoted 10 lines
(quoted diff) +10
-0+ip -net "$ns2" link set br0 up + +ip -net "$ns1" addr add 10.1.1.10/24 dev veth0 +ip -net "$ns3" addr add 10.1.1.20/24 dev veth1 + +ip netns exec "$ns2" $NFT -f /dev/stdin <<"EOF" +table bridge nat { + chain PREROUTING { + type filter hook prerouting priority 0; policy accept; + ether daddr de:ad:00:00:be:ef meta pkttype set host ether daddr set meta ibrhwdrWhile this indeed is enough to check the bridge 'redirect to input' maybe it would make sense to also check that we can do something useful with it?
Quoted 3 lines
The bridge has no ip address, so I don't really see the point why anyone would redirect the packet locally to begin with.
Thanks for explaining Florian, right I was trying to keep the test as simple as possible, of course this situation is not useful at all user-case wise.
Quoted 48 lines
Quoted 6 lines
(quoted diff) +6
-0+table bridge donotprocess { + chain FORWARD { + type filter hook forward priority 0; policy accept; + ip protocol icmp ether saddr da:d3:00:01:02:03 counter + } +}Review
Quoted 10 lines
(quoted diff) +10
-0+EOF + +ip netns exec "$ns1" ping -c 1 10.1.1.20 || true + +set +e + +ip netns exec "$ns2" $NFT list table bridge process | grep 'counter packets 0' +if [ $? -eq 0 ] +then + exit 1I think it would be nice to display WHERE its failing so that someone looking at testout.log doesn't have to re-run with added "set -x" or "echo failed at".
To give some ideas (this isn't fleshed out):
tests/shell/testcases/packetpath/bridge_pass_up +4
-1@@ -38,14 +38,18 @@ ip -net "$ns3" link set veth1 up ip -net "$ns2" link set veth1 up ip -net "$ns2" link set br0 up +ip netns exec "$ns2" sysctl -q net.ipv4.ip_forward=1 + ip -net "$ns1" addr add 10.1.1.10/24 dev veth0 ip -net "$ns3" addr add 10.1.1.20/24 dev veth1 +ip -net "$ns2" addr add 10.1.1.1/24 dev br0 ip netns exec "$ns2" $NFT -f /dev/stdin <<"EOF" table bridge nat { chain PREROUTING { type filter hook prerouting priority 0; policy accept; - ether daddr de:ad:00:00:be:ef meta pkttype set host ether daddr set meta ibrhwdr + ether daddr de:ad:00:00:be:ef meta pkttype set host ether daddr set meta ibrhwdr meta mark set 1 } }@@ -62,9 +66,19 @@ table bridge donotprocess { ip protocol icmp ether saddr da:d3:00:01:02:03 counter }
tests/shell/testcases/packetpath/bridge_pass_up table bridge donotprocess { · line 77
Quoted 10 lines
tests/shell/testcases/packetpath/bridge_pass_up +8
-0} + +table ip process { + chain FORWARD { + type filter hook forward priority 0; policy accept; + ip protocol icmp mark 1 counter + } + +} EOF
This changes looks good to me, let me add them to the patch and test them. Thank you!