cfg80211: make aware of net namespaces
Subsystems (4)
RFC 1/1 cfg80211: make aware of net namespaces
In order to make cfg80211/nl80211 aware of network namespaces, we have to do the following things:
* del_virtual_intf method takes an interface index rather than a netdev pointer - simply change this
* nl80211 uses init_net a lot, it changes to use the sender's network namespace
* scan requests use the interface index, hold a netdev pointer and reference instead
* we want a wiphy and its associated virtual interfaces to be in one netns together, so
- we need to be able to change ns for a given interface, so export dev_change_net_namespace()
- for each virtual interface set the NETIF_F_NETNS_LOCAL flag, and clear that flag only when the wiphy changes ns, to disallow breaking this invariant
* when a network namespace goes away, we need to reparent the wiphy to init_net
* cfg80211 users that support creating virtual interfaces must create them in the wiphy's namespace, currently this affects only mac80211
The end result is that you can now switch an entire wiphy into a different network namespace with the new command
iw phy#<idx> set netns <pid>
and all virtual interfaces will follow (or the operation fails).
--- include/linux/nl80211.h | 9 ++ include/net/cfg80211.h | 17 +++- net/core/dev.c | 1 net/mac80211/cfg.c | 14 --- net/mac80211/iface.c | 1 net/wireless/core.c | 75 ++++++++++++++++++-- net/wireless/core.h | 5 + net/wireless/nl80211.c | 178 +++++++++++++++++++++++++++++++++--------------- net/wireless/scan.c | 15 +--- 9 files changed, 231 insertions(+), 84 deletions(-)
include/net/cfg80211.h +13 -4
@@ -542,7 +542,7 @@ struct cfg80211_ssid {* @ie: optional information element(s) to add into Probe Request or %NULL * @ie_len: length of ie in octets * @wiphy: the wiphy this was for -* @ifidx: the interface index +* @dev: the interface */ struct cfg80211_scan_request {struct cfg80211_ssid *ssids;
@@ -554,7 +554,7 @@ struct cfg80211_scan_request {/* internal */ struct wiphy *wiphy; -int ifidx; +struct net_device *dev; };/**
@@ -781,7 +781,8 @@ enum tx_power_setting {* @resume: wiphy device needs to be resumed * * @add_virtual_intf: create a new virtual interface with the given name, -* must set the struct wireless_dev's iftype. +* must set the struct wireless_dev's iftype. Beware: You must create +* the new netdev in the wiphy's network namespace! * * @del_virtual_intf: remove the virtual interface determined by ifindex. *
@@ -865,7 +866,7 @@ struct cfg80211_ops {int (*add_virtual_intf)(struct wiphy *wiphy,char *name,enum nl80211_iftype type,u32 *flags,struct vif_params *params); -int (*del_virtual_intf)(struct wiphy *wiphy,int ifindex); +int (*del_virtual_intf)(struct wiphy *wiphy,struct net_device *dev); int (*change_virtual_intf)(struct wiphy *wiphy, struct net_device *dev, enum nl80211_iftype type, u32 *flags,
@@ -993,6 +994,9 @@ struct cfg80211_ops {* @frag_threshold: Fragmentation threshold (dot11FragmentationThreshold); * -1 = fragmentation disabled, only odd values >= 256 used * @rts_threshold: RTS threshold (dot11RTSThreshold); -1 = RTS/CTS disabled +* @net: the network namespace this wiphy currently lives in +* @netnsok: if set to false, do not allow changing the netns of this +* wiphy at all */ struct wiphy {/* assign these fields before you register the wiphy */
@@ -1006,6 +1010,8 @@ struct wiphy {bool custom_regulatory;bool strict_regulatory; +bool netnsok; +enum cfg80211_signal_type signal_type;int bss_priv_size;
@@ -1044,6 +1050,9 @@ struct wiphy {/* dir in debugfs: ieee80211/<wiphyname> */ struct dentry *debugfsdir; +/* the network namespace this phy lives in currently */ +struct net *net; + char priv[0] __attribute__((__aligned__(NETDEV_ALIGN))); };
net/mac80211/cfg.c +2 -12
@@ -57,19 +57,9 @@ static int ieee80211_add_iface(struct wireturn 0 ; } -static int ieee80211_del_iface (struct wiphy *wiphy,int ifindex) +static int ieee80211_del_iface (struct wiphy *wiphy,struct net_device *dev) { -struct net_device *dev; -struct ieee80211_sub_if_data *sdata; - -/* we're under RTNL */ - dev =__dev_get_by_index (&init_net, ifindex); -if (!dev) -return -ENODEV ; - - sdata =IEEE80211_DEV_TO_SUB_IF (dev); - -ieee80211_if_remove (sdata); +ieee80211_if_remove (IEEE80211_DEV_TO_SUB_IF (dev));return 0 ; }
net/wireless/nl80211.c +124 -54
534 lines not on this page · raw message
net/wireless/core.c +70 -5
132 lines not on this page · raw message
net/wireless/core.h +4 -1
@@ -144,10 +144,13 @@ struct wiphy *wiphy_idx_to_wiphy(int wip/* identical to cfg80211_get_dev_from_info but only operate on ifindex */ extern struct cfg80211_registered_device * -cfg80211_get_dev_from_ifindex (int ifindex); +cfg80211_get_dev_from_ifindex (struct net *net,int ifindex);extern void cfg80211_put_dev (struct cfg80211_registered_device *drv); +int cfg80211_switch_netns (struct cfg80211_registered_device *drv, +struct net *net); +/* free object */ extern void cfg80211_dev_free (struct cfg80211_registered_device *drv);
net/wireless/scan.c +7 -8
@@ -24,9 +24,7 @@ void cfg80211_scan_done(struct cfg80211_union iwreq_data wrqu;#endif - dev =dev_get_by_index (&init_net, request->ifidx); -if (!dev) - goto out; + dev = request->dev;WARN_ON (request !=wiphy_to_dev (request->wiphy)->scan_req);
@@ -47,7 +45,6 @@ void cfg80211_scan_done(struct cfg80211_dev_put (dev); - out:kfree (request); }EXPORT_SYMBOL (cfg80211_scan_done);
@@ -586,7 +583,7 @@ int cfg80211_wext_siwscan(struct net_devif (!netif_running (dev))return -ENETDOWN ; - rdev =cfg80211_get_dev_from_ifindex (dev->ifindex); + rdev =cfg80211_get_dev_from_ifindex (dev_net (dev), dev->ifindex);if (IS_ERR (rdev))return PTR_ERR (rdev);
@@ -611,7 +608,7 @@ int cfg80211_wext_siwscan(struct net_dev } creq->wiphy = wiphy; - creq->ifidx = dev->ifindex; + creq->dev = dev; creq->ssids = (void *)(creq +1 ); creq->channels = (void *)(creq->ssids +1 ); creq->n_channels = n_channels;
@@ -648,8 +645,10 @@ int cfg80211_wext_siwscan(struct net_devif (err) { rdev->scan_req =NULL ;kfree (creq); - }else + }else {nl80211_send_scan_start (rdev, dev); +dev_hold (dev); + } out:cfg80211_put_dev (rdev);return err;
@@ -942,7 +941,7 @@ int cfg80211_wext_giwscan(struct net_devif (!netif_running (dev))return -ENETDOWN ; - rdev =cfg80211_get_dev_from_ifindex (dev->ifindex); + rdev =cfg80211_get_dev_from_ifindex (dev_net (dev), dev->ifindex);if (IS_ERR (rdev))return PTR_ERR (rdev);
net/mac80211/iface.c +1 -0
@@ -812,6 +812,7 @@ int ieee80211_if_add(struct ieee80211_lo name, ieee80211_if_setup);if (!ndev)return -ENOMEM ; +dev_net_set (ndev, local->hw.wiphy->net); ndev->needed_headroom = local->tx_headroom +4 *6 /* four MAC addresses */
include/linux/nl80211.h +9 -0
@@ -242,6 +242,9 @@* @NL80211_CMD_LEAVE_IBSS: Leave the IBSS -- no special arguments, the IBSS is * determined by the network interface. * +* @NL80211_CMD_SET_WIPHY_NETNS: Set a wiphy's netns. Note that all devices +* associated with this wiphy must be down and will follow. +* * @NL80211_CMD_MAX: highest used command number * @__NL80211_CMD_AFTER_LAST: internal use */
@@ -310,6 +313,8 @@ enum nl80211_commands {NL80211_CMD_JOIN_IBSS ,NL80211_CMD_LEAVE_IBSS , + NL80211_CMD_SET_WIPHY_NETNS, +/* add new commands above here */ /* used to define NL80211_CMD_MAX below */
@@ -511,6 +516,8 @@ enum nl80211_commands {* authorized by user space. Otherwise, port is marked authorized by * default in station mode. * +* @NL80211_ATTR_PID: Process ID of a network namespace. +* * @NL80211_ATTR_MAX: highest attribute number currently defined * @__NL80211_ATTR_AFTER_LAST: internal use */
@@ -619,6 +626,8 @@ enum nl80211_attrs {NL80211_ATTR_CONTROL_PORT , +NL80211_ATTR_PID , +/* add attributes here, update the policy in nl80211.c */ __NL80211_ATTR_AFTER_LAST,
net/core/dev.c +1 -0
@@ -5011,6 +5011,7 @@ int dev_change_net_namespace(struct net_ out:return err; } +EXPORT_SYMBOL_GPL (dev_change_net_namespace); static int dev_cpu_callback(struct notifier_block *nfb, unsigned long action,
--
To unsubscribe from this list: send the line "unsubscribe linux-wireless" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html