net/sched: act_mirred: Fix infinite loop
Subsystems (4)
Jamal Hadi Salim
maintainerPATCH 1/2 net/sched: act_mirred: Fix infinite loop
When doing multiport mirroring we dont detect infinite loops.
Example (see the first accompanying tdc test):
packet showing up on port0 ingress mirred redirect --> port1 egress packet showing up on port1 egress mirred redirect --> port0 ingress
Example 2 (see the second accompanying tdc test)
port0 egress --> port1 ingress --> port0 egress
Fix this by remembering the source dev where mirred ran as opposed to destination/target dev
--- net/sched/act_mirred.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/sched/act_mirred.c +1 -1
@@ -453,7 +453,7 @@ TC_INDIRECT_SCOPE int tcf_mirred_act(struct sk_buff *skb,return retval; } - xmit->sched_mirred_dev[xmit->sched_mirred_nest++] = dev; + xmit->sched_mirred_dev[xmit->sched_mirred_nest++] = skb->dev; m_mac_header_xmit =READ_ONCE (m->tcfm_mac_header_xmit); m_eaction =READ_ONCE (m->tcfm_eaction);
Signature · 1 line
2.34.1
Jamal Hadi Salim
maintainerPATCH 2/2 selftests/tc-testing: Add test cases exercising mirred redirects (with loops)
From: Victor Nogueira <[email protected]>
Add two tdc test cases for mirred which cause loops.
The first one does a redirect dev1 ingress -> dummy egress -> dev1 ingress The second one does a redirect dummy egress -> dev1 ingress -> dummy egress
--- .../tc-testing/tc-tests/actions/mirred.json | 103 ++++++++++++++++++ 1 file changed, 103 insertions(+)
tools/testing/selftests/tc-testing/tc-tests/actions/mirred.json +103 -0
@@ -1052,5 +1052,108 @@ "$TC qdisc del dev $DEV1 ingress_block 21 clsact", "$TC actions flush action mirred" ] + }, + { + "id": "6941", + "name": "Redirect multiport: dev1 ingress -> dummy egress -> dev1 ingress (Loop)", + "category": [ + "filter", + "mirred" + ], + "plugins": { + "requires": [ + "nsPlugin", + "scapyPlugin" + ] + }, + "scapy": { + "iface": "$DEV0", + "count": 1, + "packet": "Ether()/IP(dst='10.10.10.1', src='10.10.10.10')/ICMP()" + }, + "setup": [ + "$IP link set dev $DUMMY up || true", + "$TC qdisc add dev $DEV1 clsact", + "$TC filter add dev $DEV1 ingress protocol ip prio 10 matchall action mirred egress redirect dev $DUMMY index 1", + "$IP addr add 10.10.10.10/24 dev $DUMMY || true", + "$TC qdisc add dev $DUMMY clsact", + "$TC filter add dev $DUMMY egress protocol ip prio 10 matchall action mirred ingress redirect dev $DEV1 index 2" + ], + "cmdUnderTest": "$TC -j -s actions get action mirred index 1", + "expExitCode": "0", + "verifyCmd": "$TC -j -s actions get action mirred index 1", + "matchJSON": [ + { + "total acts": 0 + }, + { + "actions": [ + { + "order": 1, + "kind": "mirred", + "mirred_action": "redirect", + "direction": "egress", + "index": 1, + "stats": { + "packets": 1 + }, + "not_in_hw": true + } + ] + } + ], + "teardown": [ + "$TC qdisc del dev $DEV1 clsact", + "$TC qdisc del dev $DUMMY clsact" + ] + }, + { + "id": "ceb4", + "name": "Redirect multiport: dummy egress -> dev1 ingress -> dummy egress (Loop)", + "category": [ + "filter", + "mirred" + ], + "plugins": { + "requires": [ + "nsPlugin" + ] + }, + "setup": [ + "$IP link set dev $DUMMY up || true", + "$IP addr add 10.10.10.10/24 dev $DUMMY || true", + "$TC qdisc add dev $DUMMY clsact", + "$TC filter add dev $DUMMY egress protocol ip prio 10 matchall action mirred ingress redirect dev $DEV1 index 1", + "$TC qdisc add dev $DEV1 clsact", + "$TC filter add dev $DEV1 ingress protocol ip prio 10 matchall action mirred egress redirect dev $DUMMY index 2" + ], + "cmdUnderTest": "ping -c1 -W0.01 -I $DUMMY 10.10.10.1", + "expExitCode": "1", + "verifyCmd": "$TC -j -s actions get action mirred index 1", + "matchJSON": [ + { + "total acts": 0 + }, + { + "actions": [ + { + "order": 1, + "kind": "mirred", + "mirred_action": "redirect", + "direction": "ingress", + "index": 1, + "stats": { + "packets": 2, + "overlimits": 1 + }, + "not_in_hw": true + } + ] + } + ], + "teardown": [ + "$TC qdisc del dev $DUMMY clsact", + "$TC qdisc del dev $DEV1 clsact" + ] } ]
Signature · 1 line
2.34.1
Jakub Kicinski
maintainerQuoted 6 lines · On Mon, 24 Nov 2025 15:08:24 -0500 Jamal Hadi Salim wrote:
When doing multiport mirroring we dont detect infinite loops.
Example (see the first accompanying tdc test):
packet showing up on port0 ingress mirred redirect --> port1 egress packet showing up on port1 egress mirred redirect --> port0 ingress
Quoted 8 lines
Example 2 (see the second accompanying tdc test)
port0 egress --> port1 ingress --> port0 egressFix this by remembering the source dev where mirred ran as opposed to destination/target dev
Fixes fe946a751d9b ("net/sched: act_mirred: add loop detection")Signed-off-by Jamal Hadi Salim <[email protected]>
Hm, this breaks net/fib_tests.sh:
# 23.80 [+0.00] IPv4 rp_filter tests
# 25.63 [+1.84] TEST: rp_filter passes local packets [FAIL] # 26.65 [+1.02] TEST: rp_filter passes loopback packets [FAIL]
https://netdev-3.bots.linux.dev/vmksft-net/results/400301/10-fib-tests-sh/stdout
Not making a statement on whether the fix itself is acceptable but if it is we gotta fix that test too..
Signature · 1 line
pw-bot: cr
Jamal Hadi Salim
maintainerQuoted 19 lines · Jakub Kicinski
Quoted 6 lines · On Mon, 24 Nov 2025 15:08:24 -0500 Jamal Hadi Salim wrote:
When doing multiport mirroring we dont detect infinite loops.
Example (see the first accompanying tdc test):
packet showing up on port0 ingress mirred redirect --> port1 egress packet showing up on port1 egress mirred redirect --> port0 ingressQuoted 8 lines
Example 2 (see the second accompanying tdc test)
port0 egress --> port1 ingress --> port0 egressFix this by remembering the source dev where mirred ran as opposed to destination/target dev
Fixes fe946a751d9b ("net/sched: act_mirred: add loop detection")Signed-off-by Jamal Hadi Salim <[email protected]>Hm, this breaks
net/fib_tests.sh:
Quoted 8 lines
# 23.80 [+0.00] IPv4
rp_filtertests# 25.63 [+1.84] TEST: rp_filter passes local packets [FAIL] # 26.65 [+1.02] TEST: rp_filter passes loopback packets [FAIL]https://netdev-3.bots.linux.dev/vmksft-net/results/400301/10-fib-tests-sh/stdout
Not making a statement on whether the fix itself is acceptable but if it is we gotta fix that test too..
Sigh. I will look into it later.
Note: Fixing this (and the netem loop issue) would have been trivial if we had those two skb ttl fields that were taken away. The human hours spent trying to detect and prevent infinite loops!
cheers,
jamal
Quoted 2 lines
--
pw-bot: cr
Jamal Hadi Salim
maintainerQuoted 27 lines · Jamal Hadi Salim
Quoted 25 lines · Jakub Kicinski
Quoted 6 lines · On Mon, 24 Nov 2025 15:08:24 -0500 Jamal Hadi Salim wrote:
When doing multiport mirroring we dont detect infinite loops.
Example (see the first accompanying tdc test):
packet showing up on port0 ingress mirred redirect --> port1 egress packet showing up on port1 egress mirred redirect --> port0 ingressQuoted 8 lines
Example 2 (see the second accompanying tdc test)
port0 egress --> port1 ingress --> port0 egressFix this by remembering the source dev where mirred ran as opposed to destination/target dev
Fixes fe946a751d9b ("net/sched: act_mirred: add loop detection")Signed-off-by Jamal Hadi Salim <[email protected]>Hm, this breaks
net/fib_tests.sh:# 23.80 [+0.00] IPv4
rp_filtertests# 25.63 [+1.84] TEST: rp_filter passes local packets [FAIL] # 26.65 [+1.02] TEST: rp_filter passes loopback packets [FAIL]https://netdev-3.bots.linux.dev/vmksft-net/results/400301/10-fib-tests-sh/stdout
Quoted 8 lines
Quoted 2 lines
Not making a statement on whether the fix itself is acceptable but if it is we gotta fix that test too..
Sigh. I will look into it later.
Note: Fixing this (and the netem loop issue) would have been trivial if we had those two skb ttl fields that were taken away. The human hours spent trying to detect and prevent infinite loops!
Ok, I spent time on this and frankly cant find a way to fix the infinite loop that avoids adding _a lot more_ complexity. We need loop state to be associated with the skb. I will restore the two skb bits and test. From inspection, i see one bit free but i may be able to steal a bit from somewhere. I will post an RFC and at minimal that will start a discussion and maybe someone will come up with a better way of solving this.
Eric, there's another issue as well involving example port0:egress->port0:egress - I have a patch but will post it later after some testing.
cheers,
jamal
Quoted 46 lines · Jamal Hadi Salim
Quoted 27 lines · Jamal Hadi Salim
Quoted 25 lines · Jakub Kicinski
Quoted 6 lines · On Mon, 24 Nov 2025 15:08:24 -0500 Jamal Hadi Salim wrote:
When doing multiport mirroring we dont detect infinite loops.
Example (see the first accompanying tdc test):
packet showing up on port0 ingress mirred redirect --> port1 egress packet showing up on port1 egress mirred redirect --> port0 ingressQuoted 8 lines
Example 2 (see the second accompanying tdc test)
port0 egress --> port1 ingress --> port0 egressFix this by remembering the source dev where mirred ran as opposed to destination/target dev
Fixes fe946a751d9b ("net/sched: act_mirred: add loop detection")Signed-off-by Jamal Hadi Salim <[email protected]>Hm, this breaks
net/fib_tests.sh:# 23.80 [+0.00] IPv4
rp_filtertests# 25.63 [+1.84] TEST: rp_filter passes local packets [FAIL] # 26.65 [+1.02] TEST: rp_filter passes loopback packets [FAIL]https://netdev-3.bots.linux.dev/vmksft-net/results/400301/10-fib-tests-sh/stdout
Quoted 8 lines
Quoted 2 lines
Not making a statement on whether the fix itself is acceptable but if it is we gotta fix that test too..
Sigh. I will look into it later.
Note: Fixing this (and the netem loop issue) would have been trivial if we had those two skb ttl fields that were taken away. The human hours spent trying to detect and prevent infinite loops!Ok, I spent time on this and frankly cant find a way to fix the infinite loop that avoids adding _a lot
more_complexity. We need loop state to be associated with the skb. I will restore the two skb bits and test. From inspection, i see one bit free but i may be able to steal a bit from somewhere. I will post an RFC and at minimal that will start a discussion and maybe someone will come up with a better way of solving this.
Quoted 3 lines
Eric, there's another issue as well involving example port0:egress->port0:egress - I have a patch but will post it later after some testing.
Adding bits for mirred in skb would be quite unfortunate.
Argument of 'we have available space, let's use/waste it' is not very appealing.
Do we really need to accept more than one mirred ?
What is a legitimate/realistic use for MIRRED_NEST_LIMIT == 4 ?
Jamal Hadi Salim
maintainerQuoted 52 lines · Eric Dumazet
Quoted 46 lines · Jamal Hadi Salim
Quoted 27 lines · Jamal Hadi Salim
Quoted 25 lines · Jakub Kicinski
Quoted 6 lines · On Mon, 24 Nov 2025 15:08:24 -0500 Jamal Hadi Salim wrote:
When doing multiport mirroring we dont detect infinite loops.
Example (see the first accompanying tdc test):
packet showing up on port0 ingress mirred redirect --> port1 egress packet showing up on port1 egress mirred redirect --> port0 ingressQuoted 8 lines
Example 2 (see the second accompanying tdc test)
port0 egress --> port1 ingress --> port0 egressFix this by remembering the source dev where mirred ran as opposed to destination/target dev
Fixes fe946a751d9b ("net/sched: act_mirred: add loop detection")Signed-off-by Jamal Hadi Salim <[email protected]>Hm, this breaks
net/fib_tests.sh:# 23.80 [+0.00] IPv4
rp_filtertests# 25.63 [+1.84] TEST: rp_filter passes local packets [FAIL] # 26.65 [+1.02] TEST: rp_filter passes loopback packets [FAIL]https://netdev-3.bots.linux.dev/vmksft-net/results/400301/10-fib-tests-sh/stdout
Quoted 8 lines
Quoted 2 lines
Not making a statement on whether the fix itself is acceptable but if it is we gotta fix that test too..
Sigh. I will look into it later.
Note: Fixing this (and the netem loop issue) would have been trivial if we had those two skb ttl fields that were taken away. The human hours spent trying to detect and prevent infinite loops!Ok, I spent time on this and frankly cant find a way to fix the infinite loop that avoids adding _a lot
more_complexity. We need loop state to be associated with the skb. I will restore the two skb bits and test. From inspection, i see one bit free but i may be able to steal a bit from somewhere. I will post an RFC and at minimal that will start a discussion and maybe someone will come up with a better way of solving this.Quoted 3 lines
Eric, there's another issue as well involving example port0:egress->port0:egress - I have a patch but will post it later after some testing.
Quoted 6 lines
Adding bits for mirred in skb would be quite unfortunate.
Argument of 'we have available space, let's use/waste it' is not very appealing.Do we really need to accept more than one mirred ?
What is a legitimate/realistic use for
MIRRED_NEST_LIMIT== 4 ?
It's the multiport redirection, particularly to ingress. When it get redirected to ingress it will get queued and then transitioned back. xmit struct wont catch this as a recursion, so MIRRED_NEST_LIMIT will not help you.
Example (see the first accompanying tdc test):
packet showing up on port0:ingress mirred redirect --> port1:egress packet showing up on port1:egress mirred redirect --> port0:ingress
cheers,
jamal
Quoted 7 lines · Jamal Hadi Salim
It's the multiport redirection, particularly to ingress. When it get redirected to ingress it will get queued and then transitioned back. xmit struct wont catch this as a recursion, so
MIRRED_NEST_LIMITwill not help you.
Example (see the first accompanying tdc test):
packet showing up on port0:ingress mirred redirect --> port1:egress packet showing up on port1:egress mirred redirect --> port0:ingress
Have you tried recording both devices ?
net/sched/act_mirred.c +0 -0
100644
net/sched/act_mirred.c +5 -3
@@ -445,15 +445,17 @@ TC_INDIRECT_SCOPE int tcf_mirred_act(struct sk_buff *skb,return retval; }for (i =0 ; i < xmit->sched_mirred_nest; i++) { -if (xmit->sched_mirred_dev[i] != dev) +if (xmit->sched_mirred_dev[i] != dev && + xmit->sched_mirred_dev[i] != skb->dev)continue ; -pr_notice_once ("tc mirred: loop on device %s\n" , -netdev_name (dev)); +pr_notice_once ("tc mirred: loop on device %s/%s\n" , +netdev_name (dev),netdev_name (skb->dev));tcf_action_inc_overlimit_qstats (&m->common);return retval; } xmit->sched_mirred_dev[xmit->sched_mirred_nest++] = dev; + xmit->sched_mirred_dev[xmit->sched_mirred_nest++] = skb->dev; m_mac_header_xmit =READ_ONCE (m->tcfm_mac_header_xmit); m_eaction =READ_ONCE (m->tcfm_eaction);
Jamal Hadi Salim
maintainerQuoted 29 lines · Eric Dumazet
Quoted 7 lines · Jamal Hadi Salim
It's the multiport redirection, particularly to ingress. When it get redirected to ingress it will get queued and then transitioned back. xmit struct wont catch this as a recursion, so
MIRRED_NEST_LIMITwill not help you.
Example (see the first accompanying tdc test):
packet showing up on port0:ingress mirred redirect --> port1:egress packet showing up on port1:egress mirred redirect --> port0:ingressHave you tried recording both devices ?
net/sched/act_mirred.c +0
-0100644
net/sched/act_mirred.c +3
-3@@ -445,15 +445,17 @@ TC_INDIRECT_SCOPE int tcf_mirred_act(struct sk_buff *skb,return retval; }for (i =0 ; i < xmit->sched_mirred_nest; i++) { -if (xmit->sched_mirred_dev[i] != dev) +if (xmit->sched_mirred_dev[i] != dev && + xmit->sched_mirred_dev[i] != skb->dev)continue ; -pr_notice_once ("tc mirred: loop on device %s\n" , -netdev_name (dev)); + pr_notice_once("tc mirred: loop on device %s/%s\n",
net/sched/act_mirred.c TC_INDIRECT_SCOPE int tcf_mirred_act(struct sk_buff *skb, · line 461
Quoted 10 lines
net/sched/act_mirred.c +2
-0+ netdev_name(dev), netdev_name(skb->dev));tcf_action_inc_overlimit_qstats (&m->common);return retval; } xmit->sched_mirred_dev[xmit->sched_mirred_nest++] = dev; + xmit->sched_mirred_dev[xmit->sched_mirred_nest++] = skb->dev; m_mac_header_xmit =READ_ONCE (m->tcfm_mac_header_xmit); m_eaction =READ_ONCE (m->tcfm_eaction);
Will try this in a bit. From outset i dont think it will help. But here's what i tested and it works. Of course needs a lot more scrutiny and testing but should be able to explain the idea.
cheers,
jamal
Jamal Hadi Salim
maintainerQuoted 29 lines · Eric Dumazet
Quoted 7 lines · Jamal Hadi Salim
It's the multiport redirection, particularly to ingress. When it get redirected to ingress it will get queued and then transitioned back. xmit struct wont catch this as a recursion, so
MIRRED_NEST_LIMITwill not help you.
Example (see the first accompanying tdc test):
packet showing up on port0:ingress mirred redirect --> port1:egress packet showing up on port1:egress mirred redirect --> port0:ingressHave you tried recording both devices ?
net/sched/act_mirred.c +0
-0100644
net/sched/act_mirred.c +3
-3@@ -445,15 +445,17 @@ TC_INDIRECT_SCOPE int tcf_mirred_act(struct sk_buff *skb,return retval; }for (i =0 ; i < xmit->sched_mirred_nest; i++) { -if (xmit->sched_mirred_dev[i] != dev) +if (xmit->sched_mirred_dev[i] != dev && + xmit->sched_mirred_dev[i] != skb->dev)continue ; -pr_notice_once ("tc mirred: loop on device %s\n" , -netdev_name (dev)); + pr_notice_once("tc mirred: loop on device %s/%s\n",
net/sched/act_mirred.c TC_INDIRECT_SCOPE int tcf_mirred_act(struct sk_buff *skb, · line 461
Quoted 10 lines
net/sched/act_mirred.c +2
-0+ netdev_name(dev), netdev_name(skb->dev));tcf_action_inc_overlimit_qstats (&m->common);return retval; } xmit->sched_mirred_dev[xmit->sched_mirred_nest++] = dev; + xmit->sched_mirred_dev[xmit->sched_mirred_nest++] = skb->dev; m_mac_header_xmit =READ_ONCE (m->tcfm_mac_header_xmit); m_eaction =READ_ONCE (m->tcfm_eaction);
Did you mean not to decrement sched_mirred_nest twice? I dont have time today but will continue early AM.
cheers,
jamal
Quoted 36 lines · Jamal Hadi Salim
Quoted 34 lines · Eric Dumazet
Quoted 7 lines · Jamal Hadi Salim
It's the multiport redirection, particularly to ingress. When it get redirected to ingress it will get queued and then transitioned back. xmit struct wont catch this as a recursion, so
MIRRED_NEST_LIMITwill not help you.
Example (see the first accompanying tdc test):
packet showing up on port0:ingress mirred redirect --> port1:egress packet showing up on port1:egress mirred redirect --> port0:ingressHave you tried recording both devices ?
net/sched/act_mirred.c +0
-0100644
net/sched/act_mirred.c +4
-3@@ -445,15 +445,17 @@ TC_INDIRECT_SCOPE int tcf_mirred_act(struct sk_buff *skb,return retval; }for (i =0 ; i < xmit->sched_mirred_nest; i++) { -if (xmit->sched_mirred_dev[i] != dev) +if (xmit->sched_mirred_dev[i] != dev && + xmit->sched_mirred_dev[i] != skb->dev)continue ; -pr_notice_once ("tc mirred: loop on device %s\n" , -netdev_name (dev)); +pr_notice_once ("tc mirred: loop on device %s/%s\n" , +netdev_name (dev),netdev_name (skb->dev));tcf_action_inc_overlimit_qstats (&m->common);return retval; }
Quoted 7 lines
net/sched/act_mirred.c TC_INDIRECT_SCOPE int tcf_mirred_act(struct sk_buff *skb, · line 461
Quoted 5 lines
net/sched/act_mirred.c +1
-0xmit->sched_mirred_dev[xmit->sched_mirred_nest++] = dev; + xmit->sched_mirred_dev[xmit->sched_mirred_nest++] = skb->dev; m_mac_header_xmit =READ_ONCE (m->tcfm_mac_header_xmit); m_eaction =READ_ONCE (m->tcfm_eaction);Did you mean not to decrement
sched_mirred_nesttwice?
No, sorry, we should decrement twice of course.
Quoted 4 lines
I dont have time today but will continue early AM.
cheers,
jamal
Jamal Hadi Salim
maintainerQuoted 41 lines · Eric Dumazet
Quoted 39 lines · Jamal Hadi Salim
Quoted 37 lines · Eric Dumazet
Quoted 7 lines · Jamal Hadi Salim
It's the multiport redirection, particularly to ingress. When it get redirected to ingress it will get queued and then transitioned back. xmit struct wont catch this as a recursion, so
MIRRED_NEST_LIMITwill not help you.
Example (see the first accompanying tdc test):
packet showing up on port0:ingress mirred redirect --> port1:egress packet showing up on port1:egress mirred redirect --> port0:ingressHave you tried recording both devices ?
net/sched/act_mirred.c +0
-0100644
net/sched/act_mirred.c +5
-3@@ -445,15 +445,17 @@ TC_INDIRECT_SCOPE int tcf_mirred_act(struct sk_buff *skb,return retval; }for (i =0 ; i < xmit->sched_mirred_nest; i++) { -if (xmit->sched_mirred_dev[i] != dev) +if (xmit->sched_mirred_dev[i] != dev && + xmit->sched_mirred_dev[i] != skb->dev)continue ; -pr_notice_once ("tc mirred: loop on device %s\n" , -netdev_name (dev)); +pr_notice_once ("tc mirred: loop on device %s/%s\n" , +netdev_name (dev),netdev_name (skb->dev));tcf_action_inc_overlimit_qstats (&m->common);return retval; } xmit->sched_mirred_dev[xmit->sched_mirred_nest++] = dev; + xmit->sched_mirred_dev[xmit->sched_mirred_nest++] = skb->dev;
Quoted 7 lines
Quoted 4 lines
net/sched/act_mirred.c TC_INDIRECT_SCOPE int tcf_mirred_act(struct sk_buff *skb, · line 461
Quoted 2 lines
net/sched/act_mirred.c +0
-0m_mac_header_xmit =READ_ONCE (m->tcfm_mac_header_xmit); m_eaction =READ_ONCE (m->tcfm_eaction);Did you mean not to decrement
sched_mirred_nesttwice?No, sorry, we should decrement twice of course.
Ok, I tested.
While it "fixes" it - it's not really a fix. It works by ignoring direction. Example, this is not a loop but currently would be claimed to be a loop because port0 appears twice:
port0 ingress --> port1 ingress --> port1 egress
Note: port0 ingress and port0 egress cannot create a loop.
cheers,
jamal
Quoted 51 lines · Jamal Hadi Salim
Quoted 41 lines · Eric Dumazet
Quoted 39 lines · Jamal Hadi Salim
Quoted 37 lines · Eric Dumazet
Quoted 7 lines · Jamal Hadi Salim
It's the multiport redirection, particularly to ingress. When it get redirected to ingress it will get queued and then transitioned back. xmit struct wont catch this as a recursion, so
MIRRED_NEST_LIMITwill not help you.
Example (see the first accompanying tdc test):
packet showing up on port0:ingress mirred redirect --> port1:egress packet showing up on port1:egress mirred redirect --> port0:ingressHave you tried recording both devices ?
net/sched/act_mirred.c +0
-0100644
net/sched/act_mirred.c +5
-3@@ -445,15 +445,17 @@ TC_INDIRECT_SCOPE int tcf_mirred_act(struct sk_buff *skb,return retval; }for (i =0 ; i < xmit->sched_mirred_nest; i++) { -if (xmit->sched_mirred_dev[i] != dev) +if (xmit->sched_mirred_dev[i] != dev && + xmit->sched_mirred_dev[i] != skb->dev)continue ; -pr_notice_once ("tc mirred: loop on device %s\n" , -netdev_name (dev)); +pr_notice_once ("tc mirred: loop on device %s/%s\n" , +netdev_name (dev),netdev_name (skb->dev));tcf_action_inc_overlimit_qstats (&m->common);return retval; } xmit->sched_mirred_dev[xmit->sched_mirred_nest++] = dev; + xmit->sched_mirred_dev[xmit->sched_mirred_nest++] = skb->dev;Quoted 7 lines
Quoted 4 lines
net/sched/act_mirred.c TC_INDIRECT_SCOPE int tcf_mirred_act(struct sk_buff *skb, · line 461
Quoted 2 lines
net/sched/act_mirred.c +0
-0m_mac_header_xmit =READ_ONCE (m->tcfm_mac_header_xmit); m_eaction =READ_ONCE (m->tcfm_eaction);Did you mean not to decrement
sched_mirred_nesttwice?No, sorry, we should decrement twice of course.
Quoted 6 lines
Ok, I tested.
While it "fixes" it - it's not really a fix. It works by ignoring direction. Example, this is not a loop but currently would be claimed to be a loop because port0 appears twice:
port0 ingress --> port1 ingress --> port1 egress
Note: port0 ingress and port0 egress cannot create a loop.
I am not familiar with this stuff, can the direction be known and taken into account ?
Really, anything but adding new bits in sk_buff.
Jamal Hadi Salim
maintainerQuoted 60 lines · Eric Dumazet
Quoted 51 lines · Jamal Hadi Salim
Quoted 41 lines · Eric Dumazet
Quoted 39 lines · Jamal Hadi Salim
Quoted 37 lines · Eric Dumazet
Quoted 7 lines · Jamal Hadi Salim
It's the multiport redirection, particularly to ingress. When it get redirected to ingress it will get queued and then transitioned back. xmit struct wont catch this as a recursion, so
MIRRED_NEST_LIMITwill not help you.
Example (see the first accompanying tdc test):
packet showing up on port0:ingress mirred redirect --> port1:egress packet showing up on port1:egress mirred redirect --> port0:ingressHave you tried recording both devices ?
net/sched/act_mirred.c +0
-0100644
net/sched/act_mirred.c +5
-3@@ -445,15 +445,17 @@ TC_INDIRECT_SCOPE int tcf_mirred_act(struct sk_buff *skb,return retval; }for (i =0 ; i < xmit->sched_mirred_nest; i++) { -if (xmit->sched_mirred_dev[i] != dev) +if (xmit->sched_mirred_dev[i] != dev && + xmit->sched_mirred_dev[i] != skb->dev)continue ; -pr_notice_once ("tc mirred: loop on device %s\n" , -netdev_name (dev)); +pr_notice_once ("tc mirred: loop on device %s/%s\n" , +netdev_name (dev),netdev_name (skb->dev));tcf_action_inc_overlimit_qstats (&m->common);return retval; } xmit->sched_mirred_dev[xmit->sched_mirred_nest++] = dev; + xmit->sched_mirred_dev[xmit->sched_mirred_nest++] = skb->dev;Quoted 7 lines
Quoted 4 lines
net/sched/act_mirred.c TC_INDIRECT_SCOPE int tcf_mirred_act(struct sk_buff *skb, · line 461
Quoted 2 lines
net/sched/act_mirred.c +0
-0m_mac_header_xmit =READ_ONCE (m->tcfm_mac_header_xmit); m_eaction =READ_ONCE (m->tcfm_eaction);Did you mean not to decrement
sched_mirred_nesttwice?No, sorry, we should decrement twice of course.
Quoted 6 lines
Ok, I tested.
While it "fixes" it - it's not really a fix. It works by ignoring direction. Example, this is not a loop but currently would be claimed to be a loop because port0 appears twice:
port0 ingress --> port1 ingress --> port1 egress
Note: port0 ingress and port0 egress cannot create a loop.
Quoted 3 lines
I am not familiar with this stuff, can the direction be known and taken into account ?
Yes, it can.
To figure the target direction see tcf_mirred_act_wants_ingress() and to get what the current direction see code like:at_ingress = skb_at_tc_ingress(skb);
Quoted 1 line
Really, anything but adding new bits in
sk_buff.
If we can fix it without restoring those two bits i will be happy. To repeat something i said earlier:
The bigger challenge is somewhere along the way (after removing those two bits) we ended sending the egress->ingress to netif_rx() (see tcf_mirred_forward()), so any flow with that kind of setup will nullify your xmit count i.e when we come back for the next leg the xmit counter will be 0.
cheers,
jamal
Jamal Hadi Salim
maintainerQuoted 73 lines · Jamal Hadi Salim
Quoted 60 lines · Eric Dumazet
Quoted 51 lines · Jamal Hadi Salim
Quoted 41 lines · Eric Dumazet
Quoted 39 lines · Jamal Hadi Salim
Quoted 37 lines · Eric Dumazet
Quoted 7 lines · Jamal Hadi Salim
It's the multiport redirection, particularly to ingress. When it get redirected to ingress it will get queued and then transitioned back. xmit struct wont catch this as a recursion, so
MIRRED_NEST_LIMITwill not help you.
Example (see the first accompanying tdc test):
packet showing up on port0:ingress mirred redirect --> port1:egress packet showing up on port1:egress mirred redirect --> port0:ingressHave you tried recording both devices ?
net/sched/act_mirred.c +0
-0100644
net/sched/act_mirred.c +5
-3@@ -445,15 +445,17 @@ TC_INDIRECT_SCOPE int tcf_mirred_act(struct sk_buff *skb,return retval; }for (i =0 ; i < xmit->sched_mirred_nest; i++) { -if (xmit->sched_mirred_dev[i] != dev) +if (xmit->sched_mirred_dev[i] != dev && + xmit->sched_mirred_dev[i] != skb->dev)continue ; -pr_notice_once ("tc mirred: loop on device %s\n" , -netdev_name (dev)); +pr_notice_once ("tc mirred: loop on device %s/%s\n" , +netdev_name (dev),netdev_name (skb->dev));tcf_action_inc_overlimit_qstats (&m->common);return retval; } xmit->sched_mirred_dev[xmit->sched_mirred_nest++] = dev; + xmit->sched_mirred_dev[xmit->sched_mirred_nest++] = skb->dev;Quoted 7 lines
Quoted 4 lines
net/sched/act_mirred.c TC_INDIRECT_SCOPE int tcf_mirred_act(struct sk_buff *skb, · line 461
Quoted 2 lines
net/sched/act_mirred.c +0
-0m_mac_header_xmit =READ_ONCE (m->tcfm_mac_header_xmit); m_eaction =READ_ONCE (m->tcfm_eaction);Did you mean not to decrement
sched_mirred_nesttwice?No, sorry, we should decrement twice of course.
Quoted 6 lines
Ok, I tested.
While it "fixes" it - it's not really a fix. It works by ignoring direction. Example, this is not a loop but currently would be claimed to be a loop because port0 appears twice:
port0 ingress --> port1 ingress --> port1 egress
Note: port0 ingress and port0 egress cannot create a loop.Quoted 3 lines
I am not familiar with this stuff, can the direction be known and taken into account ?
Yes, it can.
To figure the target direction seetcf_mirred_act_wants_ingress()and to get what the current direction see code like:at_ingress=skb_at_tc_ingress(skb);Quoted 1 line
Really, anything but adding new bits in
sk_buff.
Quoted 8 lines
If we can fix it without restoring those two bits i will be happy. To repeat something i said earlier:
The bigger challenge is somewhere along the way (after removing those two bits) we ended sending theegress->ingresstonetif_rx()(seetcf_mirred_forward()), so any flow with that kind of setup will nullify your xmit count i.e when we come back for the next leg the xmit counter will be 0.
BTW, I have the attached patch but was waiting to see how this discussion is heading.
It's when you have something like port0 egress --> port0 egress and you use something like drr as root qdisc.
-- a/net/sched/act_mirred.c
+++ b/net/sched/act_mirred.c
@@ -281,6 +281,14 @@ static int tcf_mirred_to_dev(struct sk_buff *skb, struct tcf_mirred *m,
want_ingress = tcf_mirred_act_wants_ingress(m_eaction);
+ if (dev == skb->dev && want_ingress == at_ingress) {
+ pr_notice_once("tc mirred: Loop (%s:%s --> %s:%s)\n",
+ netdev_name(skb->dev),
+ at_ingress?"ingress":"egress",
+ netdev_name(dev),
+ want_ingress?"ingress":"egress");
+ goto err_cant_do;
+ }
/* All mirred/redirected skbs should clear previous ct info */
nf_reset_ct(skb_to_send);
if (want_ingress && !at_ingress) /* drop dst for egress -> ingress */cheers,
jamal
Jamal Hadi Salim
maintainerQuoted 106 lines · Jamal Hadi Salim
Quoted 73 lines · Jamal Hadi Salim
Quoted 60 lines · Eric Dumazet
Quoted 51 lines · Jamal Hadi Salim
Quoted 41 lines · Eric Dumazet
Quoted 39 lines · Jamal Hadi Salim
Quoted 37 lines · Eric Dumazet
Quoted 7 lines · Jamal Hadi Salim
It's the multiport redirection, particularly to ingress. When it get redirected to ingress it will get queued and then transitioned back. xmit struct wont catch this as a recursion, so
MIRRED_NEST_LIMITwill not help you.
Example (see the first accompanying tdc test):
packet showing up on port0:ingress mirred redirect --> port1:egress packet showing up on port1:egress mirred redirect --> port0:ingressHave you tried recording both devices ?
net/sched/act_mirred.c +0
-0100644
net/sched/act_mirred.c +5
-3@@ -445,15 +445,17 @@ TC_INDIRECT_SCOPE int tcf_mirred_act(struct sk_buff *skb,return retval; }for (i =0 ; i < xmit->sched_mirred_nest; i++) { -if (xmit->sched_mirred_dev[i] != dev) +if (xmit->sched_mirred_dev[i] != dev && + xmit->sched_mirred_dev[i] != skb->dev)continue ; -pr_notice_once ("tc mirred: loop on device %s\n" , -netdev_name (dev)); +pr_notice_once ("tc mirred: loop on device %s/%s\n" , +netdev_name (dev),netdev_name (skb->dev));tcf_action_inc_overlimit_qstats (&m->common);return retval; } xmit->sched_mirred_dev[xmit->sched_mirred_nest++] = dev; + xmit->sched_mirred_dev[xmit->sched_mirred_nest++] = skb->dev;Quoted 7 lines
Quoted 4 lines
net/sched/act_mirred.c TC_INDIRECT_SCOPE int tcf_mirred_act(struct sk_buff *skb, · line 461
Quoted 2 lines
net/sched/act_mirred.c +0
-0m_mac_header_xmit =READ_ONCE (m->tcfm_mac_header_xmit); m_eaction =READ_ONCE (m->tcfm_eaction);Did you mean not to decrement
sched_mirred_nesttwice?No, sorry, we should decrement twice of course.
Quoted 6 lines
Ok, I tested.
While it "fixes" it - it's not really a fix. It works by ignoring direction. Example, this is not a loop but currently would be claimed to be a loop because port0 appears twice:
port0 ingress --> port1 ingress --> port1 egress
Note: port0 ingress and port0 egress cannot create a loop.Quoted 3 lines
I am not familiar with this stuff, can the direction be known and taken into account ?
Yes, it can.
To figure the target direction seetcf_mirred_act_wants_ingress()and to get what the current direction see code like:at_ingress=skb_at_tc_ingress(skb);Quoted 1 line
Really, anything but adding new bits in
sk_buff.Quoted 8 lines
If we can fix it without restoring those two bits i will be happy. To repeat something i said earlier:
The bigger challenge is somewhere along the way (after removing those two bits) we ended sending theegress->ingresstonetif_rx()(seetcf_mirred_forward()), so any flow with that kind of setup will nullify your xmit count i.e when we come back for the next leg the xmit counter will be 0.BTW, I have the attached patch but was waiting to see how this discussion is heading.
It's when you have something like port0 egress --> port0 egress and you use something like drr as root qdisc.--
a/net/sched/act_mirred.c
+++b/net/sched/act_mirred.c(quoted diff) +8
-0@@ -281,6 +281,14 @@ static int tcf_mirred_to_dev(struct sk_buff *skb, struct tcf_mirred *m, want_ingress = tcf_mirred_act_wants_ingress(m_eaction); + if (dev == skb->dev && want_ingress == at_ingress) { + pr_notice_once("tc mirred: Loop (%s:%s --> %s:%s)\n", + netdev_name(skb->dev), + at_ingress?"ingress":"egress", + netdev_name(dev), + want_ingress?"ingress":"egress"); + goto err_cant_do; + } /* All mirred/redirected skbs should clear previous ct info */ nf_reset_ct(skb_to_send);
Quoted 2 lines
if (want_ingress && !at_ingress) /* drop dst for egress -> ingress */
Eric,
Are you still looking at this?
cheers,
jamal
Jamal Hadi Salim
maintainerQuoted 98 lines · Jamal Hadi Salim
Quoted 96 lines · Jamal Hadi Salim
Quoted 73 lines · Jamal Hadi Salim
Quoted 60 lines · Eric Dumazet
Quoted 51 lines · Jamal Hadi Salim
Quoted 41 lines · Eric Dumazet
Quoted 39 lines · Jamal Hadi Salim
Quoted 37 lines · Eric Dumazet
Quoted 7 lines · Jamal Hadi Salim
It's the multiport redirection, particularly to ingress. When it get redirected to ingress it will get queued and then transitioned back. xmit struct wont catch this as a recursion, so
MIRRED_NEST_LIMITwill not help you.
Example (see the first accompanying tdc test):
packet showing up on port0:ingress mirred redirect --> port1:egress packet showing up on port1:egress mirred redirect --> port0:ingressHave you tried recording both devices ?
net/sched/act_mirred.c +0
-0100644
net/sched/act_mirred.c +5
-3@@ -445,15 +445,17 @@ TC_INDIRECT_SCOPE int tcf_mirred_act(struct sk_buff *skb,return retval; }for (i =0 ; i < xmit->sched_mirred_nest; i++) { -if (xmit->sched_mirred_dev[i] != dev) +if (xmit->sched_mirred_dev[i] != dev && + xmit->sched_mirred_dev[i] != skb->dev)continue ; -pr_notice_once ("tc mirred: loop on device %s\n" , -netdev_name (dev)); +pr_notice_once ("tc mirred: loop on device %s/%s\n" , +netdev_name (dev),netdev_name (skb->dev));tcf_action_inc_overlimit_qstats (&m->common);return retval; } xmit->sched_mirred_dev[xmit->sched_mirred_nest++] = dev; + xmit->sched_mirred_dev[xmit->sched_mirred_nest++] = skb->dev;Quoted 7 lines
Quoted 4 lines
net/sched/act_mirred.c TC_INDIRECT_SCOPE int tcf_mirred_act(struct sk_buff *skb, · line 461
Quoted 2 lines
net/sched/act_mirred.c +0
-0m_mac_header_xmit =READ_ONCE (m->tcfm_mac_header_xmit); m_eaction =READ_ONCE (m->tcfm_eaction);Did you mean not to decrement
sched_mirred_nesttwice?No, sorry, we should decrement twice of course.
Quoted 6 lines
Ok, I tested.
While it "fixes" it - it's not really a fix. It works by ignoring direction. Example, this is not a loop but currently would be claimed to be a loop because port0 appears twice:
port0 ingress --> port1 ingress --> port1 egress
Note: port0 ingress and port0 egress cannot create a loop.Quoted 3 lines
I am not familiar with this stuff, can the direction be known and taken into account ?
Yes, it can.
To figure the target direction seetcf_mirred_act_wants_ingress()and to get what the current direction see code like:at_ingress=skb_at_tc_ingress(skb);Quoted 1 line
Really, anything but adding new bits in
sk_buff.Quoted 8 lines
If we can fix it without restoring those two bits i will be happy. To repeat something i said earlier:
The bigger challenge is somewhere along the way (after removing those two bits) we ended sending theegress->ingresstonetif_rx()(seetcf_mirred_forward()), so any flow with that kind of setup will nullify your xmit count i.e when we come back for the next leg the xmit counter will be 0.BTW, I have the attached patch but was waiting to see how this discussion is heading.
It's when you have something like port0 egress --> port0 egress and you use something like drr as root qdisc.--
a/net/sched/act_mirred.c
+++b/net/sched/act_mirred.c(quoted diff) +0
-0@@ -281,6 +281,14 @@ static int tcf_mirred_to_dev(struct sk_buff *skb, struct tcf_mirred *m, want_ingress = tcf_mirred_act_wants_ingress(m_eaction);
Quoted 16 lines
Quoted 10 lines
(quoted diff) +8
-0+ if (dev == skb->dev && want_ingress == at_ingress) { + pr_notice_once("tc mirred: Loop (%s:%s --> %s:%s)\n", + netdev_name(skb->dev), + at_ingress?"ingress":"egress", + netdev_name(dev), + want_ingress?"ingress":"egress"); + goto err_cant_do; + } /* All mirred/redirected skbs should clear previous ct info */ nf_reset_ct(skb_to_send);Quoted 2 lines
if (want_ingress && !at_ingress) /* drop dst for egress -> ingress */Eric,
Are you still looking at this?
i will send a bunch of RFC patches. Maybe one is a clear "easy fix", so i will send that one out against net. Just a bit of testing needed.
cheers,
jamal
Quoted 2 lines
cheers,
jamal