diff mbox

[net-next] Allow to set net namespace for wireless device via RTM_LINK

Message ID 1410467723-2550-1-git-send-email-vadim4j@gmail.com
State Awaiting Upstream, archived
Delegated to: David Miller
Headers show

Commit Message

Vadym Kochan Sept. 11, 2014, 8:35 p.m. UTC
Added new netdev_ops callback for setting namespace in specific
for this device way

Signed-off-by: Vadim Kochan <vadim4j@gmail.com>
---
 include/linux/netdevice.h | 4 ++++
 include/net/cfg80211.h    | 3 +++
 net/core/rtnetlink.c      | 7 ++++++-
 net/mac80211/iface.c      | 6 ++++++
 net/wireless/core.c       | 8 ++++++--
 5 files changed, 25 insertions(+), 3 deletions(-)

Comments

Johannes Berg Sept. 18, 2014, 9:25 p.m. UTC | #1
On Thu, 2014-09-11 at 23:35 +0300, Vadim Kochan wrote:
> Added new netdev_ops callback for setting namespace in specific
> for this device way

> +++ b/include/linux/netdevice.h
> @@ -997,6 +997,8 @@ typedef u16 (*select_queue_fallback_t)(struct net_device *dev,
>   *	Callback to use for xmit over the accelerated station. This
>   *	is used in place of ndo_start_xmit on accelerated net
>   *	devices.
> + * int (*ndo_set_netns)(struct net_device *dev, struct net *net);
> + *      Callback to set net namespace in specific way for this device.

For the record, I don't consider it appropriate to set the net namespace
on one netdev and end up with multiple netdevs switching namespaces ...

As a result, I don't think this should done.

johannes

--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Vadym Kochan Oct. 14, 2014, 12:16 p.m. UTC | #2
On Thu, Sep 18, 2014 at 11:25:35PM +0200, Johannes Berg wrote:
> On Thu, 2014-09-11 at 23:35 +0300, Vadim Kochan wrote:
> > Added new netdev_ops callback for setting namespace in specific
> > for this device way
> 
> > +++ b/include/linux/netdevice.h
> > @@ -997,6 +997,8 @@ typedef u16 (*select_queue_fallback_t)(struct net_device *dev,
> >   *	Callback to use for xmit over the accelerated station. This
> >   *	is used in place of ndo_start_xmit on accelerated net
> >   *	devices.
> > + * int (*ndo_set_netns)(struct net_device *dev, struct net *net);
> > + *      Callback to set net namespace in specific way for this device.
> 
> For the record, I don't consider it appropriate to set the net namespace
> on one netdev and end up with multiple netdevs switching namespaces ...
> 
> As a result, I don't think this should done.
> 
> johannes
> 

The reason for this was to make possible to change netns for wireless
dev via 'ip link' too like for 'iw' util. I just think that changing
namespace for netdev should have the generic way. May be you can suggest
a better way

Thanks,
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Johannes Berg Oct. 20, 2014, 9:47 a.m. UTC | #3
On Tue, 2014-10-14 at 15:16 +0300, vadim4j@gmail.com wrote:

> The reason for this was to make possible to change netns for wireless
> dev via 'ip link' too like for 'iw' util. I just think that changing
> namespace for netdev should have the generic way. May be you can suggest
> a better way

That's a respectable goal, but I think you're way overshooting it and
thus getting it wrong. You're changing the semantics from

 "please switch this interface to that other netns"

to
 "please switch this interface *and all others on this HW* to that other
netns"

which is, in my opinion, something so much more unexpected and prone to
breaking people's setups than returning "not supported" here.

johannes

--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Marcel Holtmann Oct. 20, 2014, 10:46 a.m. UTC | #4
Hi Johannes,

>> The reason for this was to make possible to change netns for wireless
>> dev via 'ip link' too like for 'iw' util. I just think that changing
>> namespace for netdev should have the generic way. May be you can suggest
>> a better way
> 
> That's a respectable goal, but I think you're way overshooting it and
> thus getting it wrong. You're changing the semantics from
> 
> "please switch this interface to that other netns"
> 
> to
> "please switch this interface *and all others on this HW* to that other
> netns"
> 
> which is, in my opinion, something so much more unexpected and prone to
> breaking people's setups than returning "not supported" here.

this is just me thinking out loud and by no means any recommendation on doing this. I am not even sure this is a good idea.

Maybe relaxing the check and allow ip link to move a wireless netdev into a namespace (and having the wiphy follow) could be allowed if it is the only netdev or the original wlan0 that each wiphy creates. I really do not know if this is worth it, but for some simpler container cases it could be beneficial if RTNL can be used instead of having to go through nl80211.

Regards

Marcel

--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Johannes Berg Oct. 20, 2014, 10:52 a.m. UTC | #5
On Mon, 2014-10-20 at 12:46 +0200, Marcel Holtmann wrote:

> Maybe relaxing the check and allow ip link to move a wireless netdev
> into a namespace (and having the wiphy follow) could be allowed if it
> is the only netdev or the original wlan0 that each wiphy creates. I
> really do not know if this is worth it, but for some simpler container
> cases it could be beneficial if RTNL can be used instead of having to
> go through nl80211.

The thought crossed my mind, but

1) it's relatively complex, though by no means impossible
2) it still moves more than you bargained for, since in theory the wiphy
could be
   used to create new interfaces etc.

That said, I'm much more inclined to believe such a patch would be
worthwhile than the original.

johannes

--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Vadym Kochan Dec. 24, 2014, 9:48 a.m. UTC | #6
On Mon, Oct 20, 2014 at 1:52 PM, Johannes Berg
<johannes@sipsolutions.net> wrote:
> On Mon, 2014-10-20 at 12:46 +0200, Marcel Holtmann wrote:
>
>> Maybe relaxing the check and allow ip link to move a wireless netdev
>> into a namespace (and having the wiphy follow) could be allowed if it
>> is the only netdev or the original wlan0 that each wiphy creates. I
>> really do not know if this is worth it, but for some simpler container
>> cases it could be beneficial if RTNL can be used instead of having to
>> go through nl80211.
>
> The thought crossed my mind, but
>
> 1) it's relatively complex, though by no means impossible
> 2) it still moves more than you bargained for, since in theory the wiphy
> could be
>    used to create new interfaces etc.
>
> That said, I'm much more inclined to believe such a patch would be
> worthwhile than the original.
>
> johannes
>

Hi Johannes,

What about the following thoughts:

    1) Set NETIF_F_NETNS_LOCAL for phy wireless device only if there
is at least one virtual interface which was created on it
    2) What about to inherit netns for newer created interfaces from
the phy device ?

Thanks,
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Johannes Berg Jan. 5, 2015, 9:22 a.m. UTC | #7
On Wed, 2014-12-24 at 11:48 +0200, Vadim Kochan wrote:

>     1) Set NETIF_F_NETNS_LOCAL for phy wireless device only if there
> is at least one virtual interface which was created on it

You mean at least two? I'd think the behaviour becomes hard to predict,
but I guess ultimately that'd be somewhat reasonable.

>     2) What about to inherit netns for newer created interfaces from
> the phy device ?

Hmm? This already happens - a given phy is only in a single netns and
all interfaces must be created in the same netns.

johannes

--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index ba72f6b..e5cc49c 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -997,6 +997,8 @@  typedef u16 (*select_queue_fallback_t)(struct net_device *dev,
  *	Callback to use for xmit over the accelerated station. This
  *	is used in place of ndo_start_xmit on accelerated net
  *	devices.
+ * int (*ndo_set_netns)(struct net_device *dev, struct net *net);
+ *      Callback to set net namespace in specific way for this device.
  */
 struct net_device_ops {
 	int			(*ndo_init)(struct net_device *dev);
@@ -1146,6 +1148,8 @@  struct net_device_ops {
 							struct net_device *dev,
 							void *priv);
 	int			(*ndo_get_lock_subclass)(struct net_device *dev);
+	int			(*ndo_set_netns)(struct net_device *dev,
+							struct net *net);
 };
 
 /**
diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h
index ab21299..853f97c 100644
--- a/include/net/cfg80211.h
+++ b/include/net/cfg80211.h
@@ -4844,6 +4844,9 @@  void cfg80211_shutdown_all_interfaces(struct wiphy *wiphy);
 /* ethtool helper */
 void cfg80211_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info);
 
+/* cfg80211_wiphy_switch_netns - switch wiphy dev to net namespace */
+int cfg80211_wiphy_switch_netns(struct wiphy *wiphy, struct net *net);
+
 /* Logging, debugging and troubleshooting/diagnostic helpers. */
 
 /* wiphy_printk helpers, similar to dev_printk */
diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
index a688268..3c2e5e3 100644
--- a/net/core/rtnetlink.c
+++ b/net/core/rtnetlink.c
@@ -1501,7 +1501,12 @@  static int do_setlink(const struct sk_buff *skb,
 			err = -EPERM;
 			goto errout;
 		}
-		err = dev_change_net_namespace(dev, net, ifname);
+
+		if (dev->netdev_ops->ndo_set_netns)
+			err = dev->netdev_ops->ndo_set_netns(dev, net);
+		else
+			err = dev_change_net_namespace(dev, net, ifname);
+
 		put_net(net);
 		if (err)
 			goto errout;
diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
index f75e5f1..7d60367 100644
--- a/net/mac80211/iface.c
+++ b/net/mac80211/iface.c
@@ -1080,6 +1080,11 @@  static u16 ieee80211_netdev_select_queue(struct net_device *dev,
 	return ieee80211_select_queue(IEEE80211_DEV_TO_SUB_IF(dev), skb);
 }
 
+static int ieee80211_set_netns(struct net_device *dev, struct net *net)
+{
+	return cfg80211_wiphy_switch_netns(dev->ieee80211_ptr->wiphy, net);
+}
+
 static const struct net_device_ops ieee80211_dataif_ops = {
 	.ndo_open		= ieee80211_open,
 	.ndo_stop		= ieee80211_stop,
@@ -1089,6 +1094,7 @@  static const struct net_device_ops ieee80211_dataif_ops = {
 	.ndo_change_mtu 	= ieee80211_change_mtu,
 	.ndo_set_mac_address 	= ieee80211_change_mac,
 	.ndo_select_queue	= ieee80211_netdev_select_queue,
+	.ndo_set_netns		= ieee80211_set_netns,
 };
 
 static u16 ieee80211_monitor_select_queue(struct net_device *dev,
diff --git a/net/wireless/core.c b/net/wireless/core.c
index c6620aa..f4742e7 100644
--- a/net/wireless/core.c
+++ b/net/wireless/core.c
@@ -179,6 +179,12 @@  int cfg80211_switch_netns(struct cfg80211_registered_device *rdev,
 	return 0;
 }
 
+int cfg80211_wiphy_switch_netns(struct wiphy *wiphy, struct net *net)
+{
+	return cfg80211_switch_netns(wiphy_to_rdev(wiphy), net);
+}
+EXPORT_SYMBOL(cfg80211_wiphy_switch_netns);
+
 static void cfg80211_rfkill_poll(struct rfkill *rfkill, void *data)
 {
 	struct cfg80211_registered_device *rdev = data;
@@ -898,8 +904,6 @@  static int cfg80211_netdev_notifier_call(struct notifier_block *nb,
 		wdev->identifier = ++rdev->wdev_id;
 		list_add_rcu(&wdev->list, &rdev->wdev_list);
 		rdev->devlist_generation++;
-		/* can only change netns with wiphy */
-		dev->features |= NETIF_F_NETNS_LOCAL;
 
 		if (sysfs_create_link(&dev->dev.kobj, &rdev->wiphy.dev.kobj,
 				      "phy80211")) {