Added new netdev_ops callback for setting namespace in specific
for this device way
Signed-off-by: Vadim Kochan <[email protected]>
---
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(-)
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")) {
--
2.1.0
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
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,
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
On Tue, 2014-10-14 at 15:16 +0300, [email protected] 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
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
On Mon, Oct 20, 2014 at 1:52 PM, Johannes Berg
<[email protected]> 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,
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
On Mon, 2015-01-12 at 11:07 +0200, Vadim Kochan wrote:
> Would you please explain why wireless devs related to the same phy
> can't live in separated network namespaces ?
Well, they interact very deeply, for example the # of virtual interfaces
is often severely limited, and they often have to be using a single
channel, etc. It thus doesn't really make sense to try to separate them.
Also, if you really want to use it reliably, you should use a single
hostapd or wpa_supplicant process controlling all virtual interfaces,
which clearly isn't possible in multiple network namespaces.
johannes
Thank you! Seems reasonably for me.
The question is not related to the thread:
May be this is not very good idea to copy behavior from other
tools but what do you think about
add the same ability to use named network namespaces as it is
done in iproute2 - from /var/run/netns ?
Thanks,
On Mon, Jan 12, 2015 at 11:42 AM, Johannes Berg
<[email protected]> wrote:
> On Mon, 2015-01-12 at 11:07 +0200, Vadim Kochan wrote:
>
>> Would you please explain why wireless devs related to the same phy
>> can't live in separated network namespaces ?
>
> Well, they interact very deeply, for example the # of virtual interfaces
> is often severely limited, and they often have to be using a single
> channel, etc. It thus doesn't really make sense to try to separate them.
>
> Also, if you really want to use it reliably, you should use a single
> hostapd or wpa_supplicant process controlling all virtual interfaces,
> which clearly isn't possible in multiple network namespaces.
>
> johannes
>
On Mon, 2015-01-12 at 11:57 +0200, Vadim Kochan wrote:
> Thank you! Seems reasonably for me.
>
> The question is not related to the thread:
> May be this is not very good idea to copy behavior from other
> tools but what do you think about
> add the same ability to use named network namespaces as it is
> done in iproute2 - from /var/run/netns ?
I have no objection to that of course - I believe it didn't exist back
when I wrote this code, or at least I didn't know about it then :)
johannes
On Mon, Jan 5, 2015 at 11:22 AM, Johannes Berg
<[email protected]> wrote:
> 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
>
Hi,
Would you please explain why wireless devs related to the same phy
can't live in separated network namespaces ?
Thanks,