From: Jiri Pirko <redacted>
Currently, user may choose to move device that is used by mirred action
to another network namespace. That is wrong as the action still remains
in the original namespace and references non-existing ifindex.
See an example to illustrate this:
$ ip link add dummyx1 type dummy
$ ip link add dummyx2 type dummy
$ tc qdisc add dev dummyx1 clsact
$ tc filter add dev dummyx1 ingress protocol all matchall action mirred egress mirror dev dummyx2
$ tc -s filter show dev dummyx1 ingress
filter protocol all pref 49152 matchall
filter protocol all pref 49152 matchall handle 0x1
action order 1: mirred (Egress Mirror to device dummyx2) pipe
index 1 ref 1 bind 1 installed 16 sec used 16 sec
Action statistics:
Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0)
backlog 0b 0p requeues 0
$ ip netns add testx1
$ ip link set dummyx2 netns testx1
$ tc -s filter show dev dummyx1 ingress
filter protocol all pref 49152 matchall
filter protocol all pref 49152 matchall handle 0x1
action order 1: mirred (Egress Mirror to device if13) pipe
^^^^
index 1 ref 1 bind 1 installed 56 sec used 56 sec
Action statistics:
Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0)
backlog 0b 0p requeues 0
It may even happen that this ifindex is used by another totally
unrelated netdevice. So fix this by disallowing the netdevice used by
mirred action to move to another network namespace.
Fixes: ce286d327341 ("[NET]: Implement network device movement between namespaces")
Signed-off-by: Jiri Pirko <redacted>
---
include/linux/netdevice.h | 44 ++++++++++++++++++++++++++++++++++++++++++++
net/core/dev.c | 2 +-
net/sched/act_mirred.c | 8 ++++----
3 files changed, 49 insertions(+), 5 deletions(-)
@@ -8250,7 +8250,7 @@ int dev_change_net_namespace(struct net_device *dev, struct net *net, const char/* Don't allow namespace local devices to be moved. */err=-EINVAL;-if(dev->features&NETIF_F_NETNS_LOCAL)+if(dev->features&NETIF_F_NETNS_LOCAL||dev_netns_blocked(dev))gotoout;/* Ensure the device has been registrered */
@@ -8250,7 +8250,7 @@ int dev_change_net_namespace(struct net_device *dev, struct net *net, const char/* Don't allow namespace local devices to be moved. */err=-EINVAL;-if(dev->features&NETIF_F_NETNS_LOCAL)+if(dev->features&NETIF_F_NETNS_LOCAL||dev_netns_blocked(dev))gotoout;/* Ensure the device has been registrered */
Add the extack arg to dev_change_net_namespace and tell user why the
namespace change is not allowed. And for the netns_blocked case, EINVAL
does not seem the proper error code since the device is legit.
From: Cong Wang <hidden> Date: 2017-11-13 19:54:19
On Mon, Nov 13, 2017 at 6:05 AM, Jiri Pirko [off-list ref] wrote:
From: Jiri Pirko <redacted>
Currently, user may choose to move device that is used by mirred action
to another network namespace. That is wrong as the action still remains
in the original namespace and references non-existing ifindex.
It is a pure display issue, the action itself should function well
because we only use ifindex to lookup netdevice once and
we save the netdevice pointer in action.
If you really want to fix it, just tell iprout2 to display netnsid together
with ifindex.
Mon, Nov 13, 2017 at 08:53:57PM CET, xiyou.wangcong@gmail.com wrote:
On Mon, Nov 13, 2017 at 6:05 AM, Jiri Pirko [off-list ref] wrote:
quoted
From: Jiri Pirko <redacted>
Currently, user may choose to move device that is used by mirred action
to another network namespace. That is wrong as the action still remains
in the original namespace and references non-existing ifindex.
It is a pure display issue, the action itself should function well
because we only use ifindex to lookup netdevice once and
we save the netdevice pointer in action.
If you really want to fix it, just tell iprout2 to display netnsid together
with ifindex.
It is not only display issue. I think it is wrong to let a netdevice
dissapear from underneath the mirred action. You certainly cannot add an
action mirred with device from another net namespace. So should we allow
that?
From: Cong Wang <hidden> Date: 2017-11-14 05:52:03
On Mon, Nov 13, 2017 at 9:17 PM, Jiri Pirko [off-list ref] wrote:
Mon, Nov 13, 2017 at 08:53:57PM CET, xiyou.wangcong@gmail.com wrote:
quoted
On Mon, Nov 13, 2017 at 6:05 AM, Jiri Pirko [off-list ref] wrote:
quoted
From: Jiri Pirko <redacted>
Currently, user may choose to move device that is used by mirred action
to another network namespace. That is wrong as the action still remains
in the original namespace and references non-existing ifindex.
It is a pure display issue, the action itself should function well
because we only use ifindex to lookup netdevice once and
we save the netdevice pointer in action.
If you really want to fix it, just tell iprout2 to display netnsid together
with ifindex.
It is not only display issue. I think it is wrong to let a netdevice
What's wrong with it? Is it mis-functioning?
dissapear from underneath the mirred action. You certainly cannot add an
It disappears only because we don't display it properly, nothing else.
action mirred with device from another net namespace. So should we allow
that?
On the other hand why linking a device to mirred action prevents it
from moving to another netns? Also, device can be moved back too.
I don't see anything wrong with it except displaying it.
Tue, Nov 14, 2017 at 06:51:42AM CET, xiyou.wangcong@gmail.com wrote:
On Mon, Nov 13, 2017 at 9:17 PM, Jiri Pirko [off-list ref] wrote:
quoted
Mon, Nov 13, 2017 at 08:53:57PM CET, xiyou.wangcong@gmail.com wrote:
quoted
On Mon, Nov 13, 2017 at 6:05 AM, Jiri Pirko [off-list ref] wrote:
quoted
From: Jiri Pirko <redacted>
Currently, user may choose to move device that is used by mirred action
to another network namespace. That is wrong as the action still remains
in the original namespace and references non-existing ifindex.
It is a pure display issue, the action itself should function well
because we only use ifindex to lookup netdevice once and
we save the netdevice pointer in action.
If you really want to fix it, just tell iprout2 to display netnsid together
with ifindex.
It is not only display issue. I think it is wrong to let a netdevice
What's wrong with it? Is it mis-functioning?
Nope.
quoted
dissapear from underneath the mirred action. You certainly cannot add an
It disappears only because we don't display it properly, nothing else.
Okay.
quoted
action mirred with device from another net namespace. So should we allow
that?
On the other hand why linking a device to mirred action prevents it
from moving to another netns? Also, device can be moved back too.
I don't see anything wrong with it except displaying it.
Okay. What about my question? Should we allow adding an action mirred
pointing to a netdev in another netns? I think it would make sense in
case we consider movement of mirred device legit.
From: Cong Wang <hidden> Date: 2017-11-14 18:54:12
On Mon, Nov 13, 2017 at 10:35 PM, Jiri Pirko [off-list ref] wrote:
Okay. What about my question? Should we allow adding an action mirred
pointing to a netdev in another netns? I think it would make sense in
case we consider movement of mirred device legit.
I don't think it is possible to add an action pointing to any netdev in
other netns in current code base, you just can't find it.
Moving a netdev after linking it to an action is different, if you want to
argue this using above question. Because we allow other "linking"
netdev to be moved too, like a tunnel device on top of a physical
one (this is why we have netnsid).
The "linking" of a mirred action might not be as strong as a tunnel
device "linking", but the idea is pretty much similar, I don't see
anything fundamentally wrong.