cfg80211: clean up properly on interface type change
Johannes Berg
maintainerPATCH 1/1 cfg80211: clean up properly on interface type change
When the interface type changes while connected, and the driver does not require the interface to be down for a type change, it is currently possible to get very strange results unless the driver takes special care, which it shouldn't have to.
To fix this, take care to disconnect/leave IBSS when changing the interface type -- even if the driver may fail the call. Also process all events that may be pending to avoid running into a situation where an event is reported but only processed after the type has already changed, which would lead to missing events and warnings.
A side effect of this is that you will have disconnected or left the IBSS even if the mode change ultimately fails, but since the intention was to change it and thus leave or disconnect, this is not a problem.
--- net/wireless/core.c | 53 ---------------------- net/wireless/core.h | 4 + net/wireless/nl80211.c | 16 ------ net/wireless/util.c | 105 +++++++++++++++++++++++++++++++++++++++++++++ net/wireless/wext-compat.c | 16 +----- 5 files changed, 114 insertions(+), 80 deletions(-)
net/wireless/core.c +1 -52
@@ -293,68 +293,17 @@ static void cfg80211_rfkill_sync_work(stcfg80211_rfkill_set_block (rdev,rfkill_blocked (rdev->rfkill)); } -static void cfg80211_process_events (struct wireless_dev *wdev) -{ -struct cfg80211_event *ev; -unsigned long flags; - -spin_lock_irqsave (&wdev->event_lock, flags); -while (!list_empty (&wdev->event_list)) { - ev =list_first_entry (&wdev->event_list, - struct cfg80211_event, list); -list_del (&ev->list); -spin_unlock_irqrestore (&wdev->event_lock, flags); - -wdev_lock (wdev); -switch (ev->type) { -case EVENT_CONNECT_RESULT : -__cfg80211_connect_result ( - wdev->netdev, ev->cr.bssid, - ev->cr.req_ie, ev->cr.req_ie_len, - ev->cr.resp_ie, ev->cr.resp_ie_len, - ev->cr.status, - ev->cr.status ==WLAN_STATUS_SUCCESS , -NULL ); -break ; -case EVENT_ROAMED : -__cfg80211_roamed (wdev, ev->rm.bssid, - ev->rm.req_ie, ev->rm.req_ie_len, - ev->rm.resp_ie, ev->rm.resp_ie_len); -break ; -case EVENT_DISCONNECTED : -__cfg80211_disconnected (wdev->netdev, - ev->dc.ie, ev->dc.ie_len, - ev->dc.reason, true); -break ; -case EVENT_IBSS_JOINED : -__cfg80211_ibss_joined (wdev->netdev, ev->ij.bssid); -break ; - } -wdev_unlock (wdev); - -kfree (ev); - -spin_lock_irqsave (&wdev->event_lock, flags); - } -spin_unlock_irqrestore (&wdev->event_lock, flags); -} -static void cfg80211_event_work (struct work_struct *work) {struct cfg80211_registered_device *rdev; -struct wireless_dev *wdev; rdev = container_of(work, struct cfg80211_registered_device, event_work);rtnl_lock ();cfg80211_lock_rdev (rdev); -mutex_lock (&rdev->devlist_mtx); -list_for_each_entry (wdev, &rdev->netdev_list, list) -cfg80211_process_events (wdev); - -mutex_unlock (&rdev->devlist_mtx); +cfg80211_process_rdev_events (rdev);cfg80211_unlock_rdev (rdev);rtnl_unlock (); }
net/wireless/core.h +4 -0
@@ -372,6 +372,10 @@ void cfg80211_sme_disassoc(struct net_devoid __cfg80211_scan_done (struct work_struct *wk);void ___cfg80211_scan_done (struct cfg80211_registered_device *rdev,bool leak);void cfg80211_upload_connect_keys (struct wireless_dev *wdev); +int cfg80211_change_iface (struct cfg80211_registered_device *rdev, +struct net_device *dev,enum nl80211_iftype ntype, +u32 *flags,struct vif_params *params); +void cfg80211_process_rdev_events (struct cfg80211_registered_device *rdev);struct ieee80211_channel * rdev_fixed_channel(struct cfg80211_registered_device *rdev,
net/wireless/nl80211.c +1 -15
@@ -977,12 +977,6 @@ static int nl80211_set_interface(struct } } -if (!rdev->ops->change_virtual_intf || - !(rdev->wiphy.interface_modes & (1 << ntype))) { - err = -EOPNOTSUPP ; - goto unlock; - } -if (info->attrs[NL80211_ATTR_MESH_ID ]) {if (ntype !=NL80211_IFTYPE_MESH_POINT ) { err = -EINVAL ;
@@ -1008,18 +1002,10 @@ static int nl80211_set_interface(struct }if (change) - err = rdev->ops->change_virtual_intf (&rdev->wiphy, dev, - ntype, flags, ¶ms); + err =cfg80211_change_iface (rdev, dev, ntype, flags, ¶ms);else err =0 ; -WARN_ON (!err && dev->ieee80211_ptr->iftype != ntype); - -if (!err && (ntype != otype)) { -if (otype ==NL80211_IFTYPE_ADHOC ) -cfg80211_clear_ibss (dev, false); - } - unlock:dev_put (dev);cfg80211_unlock_rdev (rdev);
net/wireless/util.c +105 -0
108 lines not on this page · raw message
net/wireless/wext-compat.c +3 -13
@@ -70,18 +70,8 @@ int cfg80211_wext_siwmode(struct net_devenum nl80211_iftype type;int ret; -if (!wdev) -return -EOPNOTSUPP ; - rdev =wiphy_to_dev (wdev->wiphy); -if (!rdev->ops->change_virtual_intf) -return -EOPNOTSUPP ; - -/* don't support changing VLANs, you just re-create them */ -if (wdev->iftype ==NL80211_IFTYPE_AP_VLAN ) -return -EOPNOTSUPP ; -switch (*mode) {case IW_MODE_INFRA : type =NL80211_IFTYPE_STATION ;
@@ -104,9 +94,9 @@ int cfg80211_wext_siwmode(struct net_devmemset (&vifparams,0 ,sizeof (vifparams)); - ret = rdev->ops->change_virtual_intf (wdev->wiphy, dev, type, -NULL , &vifparams); -WARN_ON (!ret && wdev->iftype != type); +cfg80211_lock_rdev (rdev); + ret =cfg80211_change_iface (rdev, dev, type,NULL , &vifparams); +cfg80211_unlock_rdev (rdev);return ret; }
Johannes Berg
maintainerPATCH v2 1/1 cfg80211: clean up properly on interface type change
When the interface type changes while connected, and the driver does not require the interface to be down for a type change, it is currently possible to get very strange results unless the driver takes special care, which it shouldn't have to.
To fix this, take care to disconnect/leave IBSS when changing the interface type -- even if the driver may fail the call. Also process all events that may be pending to avoid running into a situation where an event is reported but only processed after the type has already changed, which would lead to missing events and warnings.
A side effect of this is that you will have disconnected or left the IBSS even if the mode change ultimately fails, but since the intention was to change it and thus leave or disconnect, this is not a problem.
---
v2: rebase on current wireless-testing, sorry
net/wireless/core.c | 54 ---------------------- net/wireless/core.h | 4 + net/wireless/nl80211.c | 16 ------ net/wireless/util.c | 108 +++++++++++++++++++++++++++++++++++++++++++++ net/wireless/wext-compat.c | 16 +----- 5 files changed, 117 insertions(+), 81 deletions(-)
net/wireless/core.c +1 -53
@@ -294,69 +294,17 @@ static void cfg80211_rfkill_sync_work(stcfg80211_rfkill_set_block (rdev,rfkill_blocked (rdev->rfkill)); } -static void cfg80211_process_events (struct wireless_dev *wdev) -{ -struct cfg80211_event *ev; -unsigned long flags; - -spin_lock_irqsave (&wdev->event_lock, flags); -while (!list_empty (&wdev->event_list)) { - ev =list_first_entry (&wdev->event_list, - struct cfg80211_event, list); -list_del (&ev->list); -spin_unlock_irqrestore (&wdev->event_lock, flags); - -wdev_lock (wdev); -switch (ev->type) { -case EVENT_CONNECT_RESULT : -__cfg80211_connect_result ( - wdev->netdev,is_zero_ether_addr (ev->cr.bssid) ? -NULL : ev->cr.bssid, - ev->cr.req_ie, ev->cr.req_ie_len, - ev->cr.resp_ie, ev->cr.resp_ie_len, - ev->cr.status, - ev->cr.status ==WLAN_STATUS_SUCCESS , -NULL ); -break ; -case EVENT_ROAMED : -__cfg80211_roamed (wdev, ev->rm.bssid, - ev->rm.req_ie, ev->rm.req_ie_len, - ev->rm.resp_ie, ev->rm.resp_ie_len); -break ; -case EVENT_DISCONNECTED : -__cfg80211_disconnected (wdev->netdev, - ev->dc.ie, ev->dc.ie_len, - ev->dc.reason, true); -break ; -case EVENT_IBSS_JOINED : -__cfg80211_ibss_joined (wdev->netdev, ev->ij.bssid); -break ; - } -wdev_unlock (wdev); - -kfree (ev); - -spin_lock_irqsave (&wdev->event_lock, flags); - } -spin_unlock_irqrestore (&wdev->event_lock, flags); -} -static void cfg80211_event_work (struct work_struct *work) {struct cfg80211_registered_device *rdev; -struct wireless_dev *wdev; rdev = container_of(work, struct cfg80211_registered_device, event_work);rtnl_lock ();cfg80211_lock_rdev (rdev); -mutex_lock (&rdev->devlist_mtx); -list_for_each_entry (wdev, &rdev->netdev_list, list) -cfg80211_process_events (wdev); - -mutex_unlock (&rdev->devlist_mtx); +cfg80211_process_rdev_events (rdev);cfg80211_unlock_rdev (rdev);rtnl_unlock (); }
net/wireless/core.h +4 -0
@@ -372,6 +372,10 @@ void cfg80211_sme_disassoc(struct net_devoid __cfg80211_scan_done (struct work_struct *wk);void ___cfg80211_scan_done (struct cfg80211_registered_device *rdev,bool leak);void cfg80211_upload_connect_keys (struct wireless_dev *wdev); +int cfg80211_change_iface (struct cfg80211_registered_device *rdev, +struct net_device *dev,enum nl80211_iftype ntype, +u32 *flags,struct vif_params *params); +void cfg80211_process_rdev_events (struct cfg80211_registered_device *rdev);struct ieee80211_channel * rdev_fixed_channel(struct cfg80211_registered_device *rdev,
net/wireless/nl80211.c +1 -15
@@ -977,12 +977,6 @@ static int nl80211_set_interface(struct } } -if (!rdev->ops->change_virtual_intf || - !(rdev->wiphy.interface_modes & (1 << ntype))) { - err = -EOPNOTSUPP ; - goto unlock; - } -if (info->attrs[NL80211_ATTR_MESH_ID ]) {if (ntype !=NL80211_IFTYPE_MESH_POINT ) { err = -EINVAL ;
@@ -1008,18 +1002,10 @@ static int nl80211_set_interface(struct }if (change) - err = rdev->ops->change_virtual_intf (&rdev->wiphy, dev, - ntype, flags, ¶ms); + err =cfg80211_change_iface (rdev, dev, ntype, flags, ¶ms);else err =0 ; -WARN_ON (!err && dev->ieee80211_ptr->iftype != ntype); - -if (!err && (ntype != otype)) { -if (otype ==NL80211_IFTYPE_ADHOC ) -cfg80211_clear_ibss (dev, false); - } - unlock:dev_put (dev);cfg80211_unlock_rdev (rdev);
net/wireless/util.c +108 -0
111 lines not on this page · raw message
net/wireless/wext-compat.c +3 -13
@@ -70,18 +70,8 @@ int cfg80211_wext_siwmode(struct net_devenum nl80211_iftype type;int ret; -if (!wdev) -return -EOPNOTSUPP ; - rdev =wiphy_to_dev (wdev->wiphy); -if (!rdev->ops->change_virtual_intf) -return -EOPNOTSUPP ; - -/* don't support changing VLANs, you just re-create them */ -if (wdev->iftype ==NL80211_IFTYPE_AP_VLAN ) -return -EOPNOTSUPP ; -switch (*mode) {case IW_MODE_INFRA : type =NL80211_IFTYPE_STATION ;
@@ -104,9 +94,9 @@ int cfg80211_wext_siwmode(struct net_devmemset (&vifparams,0 ,sizeof (vifparams)); - ret = rdev->ops->change_virtual_intf (wdev->wiphy, dev, type, -NULL , &vifparams); -WARN_ON (!ret && wdev->iftype != type); +cfg80211_lock_rdev (rdev); + ret =cfg80211_change_iface (rdev, dev, type,NULL , &vifparams); +cfg80211_unlock_rdev (rdev);return ret; }