net: notify users when an iface cannot change its netns
Subsystems (3)
v3 cover net: notify users when an iface cannot change its netns
This series adds a way to see if an interface cannot be moved to another netns.
v2 -> v3:
- don't copy patch #1 to [email protected]
- remove the 'Fixes:' tag
v1 -> v2:
- target the series to net-next
- patch #1:
+ use NLA_REJECT for the nl policy
+ update the rt link spec
- patch #2: plumb extack in __dev_change_net_namespace()
Documentation/netlink/specs/rt_link.yaml | 3 +++ include/linux/netdevice.h | 5 ++-- include/uapi/linux/if_link.h | 1 + net/core/dev.c | 41 +++++++++++++++++++++++++------- net/core/rtnetlink.c | 5 +++- 5 files changed, 44 insertions(+), 11 deletions(-)
Comments are welcome.
Regards,
Nicolas
PATCH v3 1/2 net: advertise 'netns local' property via netlink
Since commit 05c1280a2bcf ("netdev_features: convert NETIF_F_NETNS_LOCAL to dev->netns_local"), there is no way to see if the netns_local property is set on a device. Let's add a netlink attribute to advertise it.
--- Documentation/netlink/specs/rt_link.yaml | 3 +++ include/uapi/linux/if_link.h | 1 + net/core/rtnetlink.c | 3 +++ 3 files changed, 7 insertions(+)
Documentation/netlink/specs/rt_link.yaml +3 -0
@@ -1148,6 +1148,9 @@ attribute-sets: name: max-pacing-offload-horizon type: uint doc: EDT offload horizon supported by the device (in nsec). + - + name: netns-local + type: u8 - name: af-spec-attrs attributes:
include/uapi/linux/if_link.h +1 -0
@@ -378,6 +378,7 @@ enum {IFLA_GRO_IPV4_MAX_SIZE ,IFLA_DPLL_PIN ,IFLA_MAX_PACING_OFFLOAD_HORIZON , +IFLA_NETNS_LOCAL , __IFLA_MAX };
net/core/rtnetlink.c +3 -0
@@ -1292,6 +1292,7 @@ static noinline size_t if_nlmsg_size(const struct net_device *dev, +nla_total_size (4 )/* IFLA_TSO_MAX_SEGS */ +nla_total_size (1 )/* IFLA_OPERSTATE */ +nla_total_size (1 )/* IFLA_LINKMODE */ + +nla_total_size (1 )/* IFLA_NETNS_LOCAL */ +nla_total_size (4 )/* IFLA_CARRIER_CHANGES */ +nla_total_size (4 )/* IFLA_LINK_NETNSID */ +nla_total_size (4 )/* IFLA_GROUP */
@@ -2046,6 +2047,7 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb,netif_running (dev) ?READ_ONCE (dev->operstate) : IF_OPER_DOWN) ||nla_put_u8 (skb,IFLA_LINKMODE ,READ_ONCE (dev->link_mode)) || +nla_put_u8 (skb,IFLA_NETNS_LOCAL , dev->netns_local) ||nla_put_u32 (skb,IFLA_MTU ,READ_ONCE (dev->mtu)) ||nla_put_u32 (skb,IFLA_MIN_MTU ,READ_ONCE (dev->min_mtu)) || nla_put_u32(skb, IFLA_MAX_MTU, READ_ONCE(dev->max_mtu)) ||
@@ -2234,6 +2236,7 @@ static const struct nla_policy ifla_policy[IFLA_MAX+1] = { [IFLA_ALLMULTI] = { .type = NLA_REJECT }, [IFLA_GSO_IPV4_MAX_SIZE] = NLA_POLICY_MIN(NLA_U32, MAX_TCP_HEADER + 1), [IFLA_GRO_IPV4_MAX_SIZE] = { .type = NLA_U32 }, + [IFLA_NETNS_LOCAL] = { .type = NLA_REJECT }, };static const struct nla_policy ifla_info_policy[IFLA_INFO_MAX +1 ] = {
Signature · 1 line
2.47.1
Re: [PATCH net-next v3 1/2] net: advertise 'netns local' property via netlink
Quoted 7 lines · Nicolas Dichtel
Since commit
05c1280a2bcf("netdev_features: convertNETIF_F_NETNS_LOCALtodev->netns_local"), there is no way to see if thenetns_localproperty is set on a device. Let's add a netlink attribute to advertise it.Signed-off-by Nicolas Dichtel <[email protected]>---
Re: [PATCH net-next v3 1/2] net: advertise 'netns local' property via netlink
In reply to Nicolas DichtelFrom: Nicolas Dichtel <[email protected]>
Date: Thu, 20 Feb 2025 14:02:35 +0100
Quoted 5 lines
Since commit
05c1280a2bcf("netdev_features: convertNETIF_F_NETNS_LOCALtodev->netns_local"), there is no way to see if thenetns_localproperty is set on a device. Let's add a netlink attribute to advertise it.Signed-off-by Nicolas Dichtel <[email protected]>
Meh, I was sure nobody looks at those read-only Ethtool "features"...
Quoted 5 lines
--- Documentation/netlink/specs/rt_link.yaml | 3 +++ include/uapi/linux/if_link.h | 1 + net/core/rtnetlink.c | 3 +++ 3 files changed, 7 insertions(+)
Thanks,
Olek
Re: [PATCH net-next v3 1/2] net: advertise 'netns local' property via netlink
In reply to Nicolas DichtelFrom: Nicolas Dichtel <[email protected]>
Date: Thu, 20 Feb 2025 14:02:35 +0100
Quoted 5 lines
Since commit
05c1280a2bcf("netdev_features: convertNETIF_F_NETNS_LOCALtodev->netns_local"), there is no way to see if thenetns_localproperty is set on a device. Let's add a netlink attribute to advertise it.Signed-off-by Nicolas Dichtel <[email protected]>
PATCH v3 2/2 net: plumb extack in __dev_change_net_namespace()
In reply to Nicolas DichtelIt could be hard to understand why the netlink command fails. For example, if dev->netns_local is set, the error is "Invalid argument".
--- include/linux/netdevice.h | 5 +++-- net/core/dev.c | 41 +++++++++++++++++++++++++++++++-------- net/core/rtnetlink.c | 2 +- 3 files changed, 37 insertions(+), 11 deletions(-)
include/linux/netdevice.h +3 -2
@@ -4155,12 +4155,13 @@ int dev_change_flags(struct net_device *dev, unsigned int flags,int dev_set_alias (struct net_device *,const char *,size_t );int dev_get_alias (const struct net_device *,char *,size_t );int __dev_change_net_namespace (struct net_device *dev,struct net *net, -const char *pat,int new_ifindex); +const char *pat,int new_ifindex, +struct netlink_ext_ack *extack);static inline int dev_change_net_namespace (struct net_device *dev,struct net *net,const char *pat) { -return __dev_change_net_namespace (dev, net, pat,0 ); +return __dev_change_net_namespace (dev, net, pat,0 ,NULL ); }int __dev_set_mtu (struct net_device *,int );int dev_set_mtu (struct net_device *,int );
net/core/dev.c +33 -8
88 lines not on this page · raw message
net/core/rtnetlink.c +1 -1
@@ -3028,7 +3028,7 @@ static int do_setlink(const struct sk_buff *skb, struct net_device *dev, new_ifindex =nla_get_s32_default (tb[IFLA_NEW_IFINDEX ],0 ); - err =__dev_change_net_namespace (dev, tgt_net, pat, new_ifindex); + err =__dev_change_net_namespace (dev, tgt_net, pat, new_ifindex, extack);if (err) goto errout;
Signature · 1 line
2.47.1
Re: [PATCH net-next v3 2/2] net: plumb extack in __dev_change_net_namespace()
Quoted 4 lines · Nicolas Dichtel
It could be hard to understand why the netlink command fails. For example, if
dev->netns_localis set, the error is "Invalid argument".
After your patch, a new message is : " "The interface has the 'netns local' property""
Honestly, I am not sure we export to user space the concept of 'netns local'
"This interface netns is not allowed to be changed" or something like that ?
Re: [PATCH net-next v3 2/2] net: plumb extack in __dev_change_net_namespace()
Le 20/02/2025 à 14:17, Eric Dumazet a écrit :
Quoted 7 lines
Quoted 4 lines · Nicolas Dichtel
It could be hard to understand why the netlink command fails. For example, if
dev->netns_localis set, the error is "Invalid argument".
Quoted 6 lines
After your patch, a new message is : " "The interface has the 'netns local' property""
Honestly, I am not sure we export to user space the concept of 'netns local'
"This interface netns is not allowed to be changed" or something like that ?
Frankly, I was hesitating. I used 'netns local' to ease the link with the new netlink attribute, and with what was displayed by ethtool for a long time. I don't have a strong opinion about this.
Eric Dumazet
Reviewed-byRe: [PATCH net-next v3 2/2] net: plumb extack in __dev_change_net_namespace()
Quoted 12 lines · Nicolas Dichtel
Quoted 10 lines · Eric Dumazet
Quoted 4 lines · Nicolas Dichtel
It could be hard to understand why the netlink command fails. For example, if
dev->netns_localis set, the error is "Invalid argument".After your patch, a new message is : " "The interface has the 'netns local' property""
Quoted 6 lines
Quoted 3 lines
Honestly, I am not sure we export to user space the concept of 'netns local'
"This interface netns is not allowed to be changed" or something like that ?
Frankly, I was hesitating. I used 'netns local' to ease the link with the new netlink attribute, and with what was displayed by ethtool for a long time. I don't have a strong opinion about this.
No strong opinion either, I always have been confused by NETNS_LOCAL choice.
Re: [PATCH net-next v3 2/2] net: plumb extack in __dev_change_net_namespace()
Le 20/02/2025 à 14:24, Eric Dumazet a écrit :
Quoted 14 lines
Quoted 12 lines · Nicolas Dichtel
Quoted 10 lines · Eric Dumazet
Quoted 4 lines · Nicolas Dichtel
It could be hard to understand why the netlink command fails. For example, if
dev->netns_localis set, the error is "Invalid argument".After your patch, a new message is : " "The interface has the 'netns local' property""
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Honestly, I am not sure we export to user space the concept of 'netns local'
"This interface netns is not allowed to be changed" or something like that ?
Frankly, I was hesitating. I used 'netns local' to ease the link with the new netlink attribute, and with what was displayed by ethtool for a long time. I don't have a strong opinion about this.
No strong opinion either, I always have been confused by
NETNS_LOCALchoice.
Yes, it's not obvious. Maybe it could be renamed before exposing it to userspace via netlink.
What about 'netns-locked'? Does someone have a better proposal?
Re: [PATCH net-next v3 2/2] net: plumb extack in __dev_change_net_namespace()
From: Nicolas Dichtel <[email protected]>
Date: Thu, 20 Feb 2025 16:11:43 +0100
Quoted 18 lines · Eric Dumazet
Quoted 17 lines
Quoted 15 lines · Nicolas Dichtel
Quoted 13 lines · Eric Dumazet
Quoted 4 lines · Nicolas Dichtel
It could be hard to understand why the netlink command fails. For example, if
dev->netns_localis set, the error is "Invalid argument".After your patch, a new message is : " "The interface has the 'netns local' property""
Honestly, I am not sure we export to user space the concept of 'netns local'
"This interface netns is not allowed to be changed" or something like that ?
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
Frankly, I was hesitating. I used 'netns local' to ease the link with the new netlink attribute, and with what was displayed by ethtool for a long time. I don't have a strong opinion about this.
No strong opinion either, I always have been confused by
NETNS_LOCALchoice.Yes, it's not obvious. Maybe it could be renamed before exposing it to userspace via netlink.
What about 'netns-locked'? Does someone have a better proposal?
Maybe NETNS_IMMUTABLE and netns-immutable ?
Then we can say "The interface netns is immutable" in extack.