diff options
author | Johannes Berg <johannes@sipsolutions.net> | 2009-07-13 18:33:35 -0400 |
---|---|---|
committer | John W. Linville <linville@tuxdriver.com> | 2009-07-27 15:24:07 -0400 |
commit | 463d018323851a608eef52a9427b0585005c647f (patch) | |
tree | b5ad2ee6115e6b780c264022cbc20b36d22fe80c /include | |
parent | 5061b0c2b9066de426fbc63f1278d2210e789412 (diff) |
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).
Signed-off-by: Johannes Berg <johannes@sipsolutions.net>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
Diffstat (limited to 'include')
-rw-r--r-- | include/linux/nl80211.h | 9 | ||||
-rw-r--r-- | include/net/cfg80211.h | 40 |
2 files changed, 45 insertions, 4 deletions
diff --git a/include/linux/nl80211.h b/include/linux/nl80211.h index 962e2232a074..cb3dc6027fd9 100644 --- a/include/linux/nl80211.h +++ b/include/linux/nl80211.h | |||
@@ -262,6 +262,9 @@ | |||
262 | * reasons, for this the %NL80211_ATTR_DISCONNECTED_BY_AP and | 262 | * reasons, for this the %NL80211_ATTR_DISCONNECTED_BY_AP and |
263 | * %NL80211_ATTR_REASON_CODE attributes are used. | 263 | * %NL80211_ATTR_REASON_CODE attributes are used. |
264 | * | 264 | * |
265 | * @NL80211_CMD_SET_WIPHY_NETNS: Set a wiphy's netns. Note that all devices | ||
266 | * associated with this wiphy must be down and will follow. | ||
267 | * | ||
265 | * @NL80211_CMD_MAX: highest used command number | 268 | * @NL80211_CMD_MAX: highest used command number |
266 | * @__NL80211_CMD_AFTER_LAST: internal use | 269 | * @__NL80211_CMD_AFTER_LAST: internal use |
267 | */ | 270 | */ |
@@ -336,6 +339,8 @@ enum nl80211_commands { | |||
336 | NL80211_CMD_ROAM, | 339 | NL80211_CMD_ROAM, |
337 | NL80211_CMD_DISCONNECT, | 340 | NL80211_CMD_DISCONNECT, |
338 | 341 | ||
342 | NL80211_CMD_SET_WIPHY_NETNS, | ||
343 | |||
339 | /* add new commands above here */ | 344 | /* add new commands above here */ |
340 | 345 | ||
341 | /* used to define NL80211_CMD_MAX below */ | 346 | /* used to define NL80211_CMD_MAX below */ |
@@ -573,6 +578,8 @@ enum nl80211_commands { | |||
573 | * and join_ibss(), key information is in a nested attribute each | 578 | * and join_ibss(), key information is in a nested attribute each |
574 | * with %NL80211_KEY_* sub-attributes | 579 | * with %NL80211_KEY_* sub-attributes |
575 | * | 580 | * |
581 | * @NL80211_ATTR_PID: Process ID of a network namespace. | ||
582 | * | ||
576 | * @NL80211_ATTR_MAX: highest attribute number currently defined | 583 | * @NL80211_ATTR_MAX: highest attribute number currently defined |
577 | * @__NL80211_ATTR_AFTER_LAST: internal use | 584 | * @__NL80211_ATTR_AFTER_LAST: internal use |
578 | */ | 585 | */ |
@@ -701,6 +708,8 @@ enum nl80211_attrs { | |||
701 | NL80211_ATTR_KEY, | 708 | NL80211_ATTR_KEY, |
702 | NL80211_ATTR_KEYS, | 709 | NL80211_ATTR_KEYS, |
703 | 710 | ||
711 | NL80211_ATTR_PID, | ||
712 | |||
704 | /* add attributes here, update the policy in nl80211.c */ | 713 | /* add attributes here, update the policy in nl80211.c */ |
705 | 714 | ||
706 | __NL80211_ATTR_AFTER_LAST, | 715 | __NL80211_ATTR_AFTER_LAST, |
diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h index a981ca8a5701..0d278777e39c 100644 --- a/include/net/cfg80211.h +++ b/include/net/cfg80211.h | |||
@@ -542,7 +542,7 @@ struct cfg80211_ssid { | |||
542 | * @ie: optional information element(s) to add into Probe Request or %NULL | 542 | * @ie: optional information element(s) to add into Probe Request or %NULL |
543 | * @ie_len: length of ie in octets | 543 | * @ie_len: length of ie in octets |
544 | * @wiphy: the wiphy this was for | 544 | * @wiphy: the wiphy this was for |
545 | * @ifidx: the interface index | 545 | * @dev: the interface |
546 | */ | 546 | */ |
547 | struct cfg80211_scan_request { | 547 | struct cfg80211_scan_request { |
548 | struct cfg80211_ssid *ssids; | 548 | struct cfg80211_ssid *ssids; |
@@ -554,7 +554,7 @@ struct cfg80211_scan_request { | |||
554 | 554 | ||
555 | /* internal */ | 555 | /* internal */ |
556 | struct wiphy *wiphy; | 556 | struct wiphy *wiphy; |
557 | int ifidx; | 557 | struct net_device *dev; |
558 | bool aborted; | 558 | bool aborted; |
559 | }; | 559 | }; |
560 | 560 | ||
@@ -845,7 +845,8 @@ struct cfg80211_bitrate_mask { | |||
845 | * @resume: wiphy device needs to be resumed | 845 | * @resume: wiphy device needs to be resumed |
846 | * | 846 | * |
847 | * @add_virtual_intf: create a new virtual interface with the given name, | 847 | * @add_virtual_intf: create a new virtual interface with the given name, |
848 | * must set the struct wireless_dev's iftype. | 848 | * must set the struct wireless_dev's iftype. Beware: You must create |
849 | * the new netdev in the wiphy's network namespace! | ||
849 | * | 850 | * |
850 | * @del_virtual_intf: remove the virtual interface determined by ifindex. | 851 | * @del_virtual_intf: remove the virtual interface determined by ifindex. |
851 | * | 852 | * |
@@ -937,7 +938,7 @@ struct cfg80211_ops { | |||
937 | int (*add_virtual_intf)(struct wiphy *wiphy, char *name, | 938 | int (*add_virtual_intf)(struct wiphy *wiphy, char *name, |
938 | enum nl80211_iftype type, u32 *flags, | 939 | enum nl80211_iftype type, u32 *flags, |
939 | struct vif_params *params); | 940 | struct vif_params *params); |
940 | int (*del_virtual_intf)(struct wiphy *wiphy, int ifindex); | 941 | int (*del_virtual_intf)(struct wiphy *wiphy, struct net_device *dev); |
941 | int (*change_virtual_intf)(struct wiphy *wiphy, | 942 | int (*change_virtual_intf)(struct wiphy *wiphy, |
942 | struct net_device *dev, | 943 | struct net_device *dev, |
943 | enum nl80211_iftype type, u32 *flags, | 944 | enum nl80211_iftype type, u32 *flags, |
@@ -1088,6 +1089,9 @@ struct cfg80211_ops { | |||
1088 | * @frag_threshold: Fragmentation threshold (dot11FragmentationThreshold); | 1089 | * @frag_threshold: Fragmentation threshold (dot11FragmentationThreshold); |
1089 | * -1 = fragmentation disabled, only odd values >= 256 used | 1090 | * -1 = fragmentation disabled, only odd values >= 256 used |
1090 | * @rts_threshold: RTS threshold (dot11RTSThreshold); -1 = RTS/CTS disabled | 1091 | * @rts_threshold: RTS threshold (dot11RTSThreshold); -1 = RTS/CTS disabled |
1092 | * @net: the network namespace this wiphy currently lives in | ||
1093 | * @netnsok: if set to false, do not allow changing the netns of this | ||
1094 | * wiphy at all | ||
1091 | */ | 1095 | */ |
1092 | struct wiphy { | 1096 | struct wiphy { |
1093 | /* assign these fields before you register the wiphy */ | 1097 | /* assign these fields before you register the wiphy */ |
@@ -1101,6 +1105,8 @@ struct wiphy { | |||
1101 | bool custom_regulatory; | 1105 | bool custom_regulatory; |
1102 | bool strict_regulatory; | 1106 | bool strict_regulatory; |
1103 | 1107 | ||
1108 | bool netnsok; | ||
1109 | |||
1104 | enum cfg80211_signal_type signal_type; | 1110 | enum cfg80211_signal_type signal_type; |
1105 | 1111 | ||
1106 | int bss_priv_size; | 1112 | int bss_priv_size; |
@@ -1139,9 +1145,35 @@ struct wiphy { | |||
1139 | /* dir in debugfs: ieee80211/<wiphyname> */ | 1145 | /* dir in debugfs: ieee80211/<wiphyname> */ |
1140 | struct dentry *debugfsdir; | 1146 | struct dentry *debugfsdir; |
1141 | 1147 | ||
1148 | #ifdef CONFIG_NET_NS | ||
1149 | /* the network namespace this phy lives in currently */ | ||
1150 | struct net *_net; | ||
1151 | #endif | ||
1152 | |||
1142 | char priv[0] __attribute__((__aligned__(NETDEV_ALIGN))); | 1153 | char priv[0] __attribute__((__aligned__(NETDEV_ALIGN))); |
1143 | }; | 1154 | }; |
1144 | 1155 | ||
1156 | #ifdef CONFIG_NET_NS | ||
1157 | static inline struct net *wiphy_net(struct wiphy *wiphy) | ||
1158 | { | ||
1159 | return wiphy->_net; | ||
1160 | } | ||
1161 | |||
1162 | static inline void wiphy_net_set(struct wiphy *wiphy, struct net *net) | ||
1163 | { | ||
1164 | wiphy->_net = net; | ||
1165 | } | ||
1166 | #else | ||
1167 | static inline struct net *wiphy_net(struct wiphy *wiphy) | ||
1168 | { | ||
1169 | return &init_net; | ||
1170 | } | ||
1171 | |||
1172 | static inline void wiphy_net_set(struct wiphy *wiphy, struct net *net) | ||
1173 | { | ||
1174 | } | ||
1175 | #endif | ||
1176 | |||
1145 | /** | 1177 | /** |
1146 | * wiphy_priv - return priv from wiphy | 1178 | * wiphy_priv - return priv from wiphy |
1147 | * | 1179 | * |