mac80211: allow mode changes while interface is up
Johannes Berg
maintainerIt might be nicer sometimes to allow mode changes while the interface is up, e.g. from managed to ibss mode, so that IP configuration is retained. This patch changes mac80211 to support that, it effectively internally behaves as though you had actually done a down/change/up cycle.
---
COMPLETELY UNTESTED. If anyone needs this functionality please test and adopt this patch -- I have no interest in pushing it into the kernel.
net/mac80211/iface.c | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-)
net/mac80211/iface.c +25 -11
@@ -749,24 +749,22 @@ static void ieee80211_setup_sdata(structint ieee80211_if_change_type (struct ieee80211_sub_if_data *sdata,enum nl80211_iftype type) { -ASSERT_RTNL (); +int ret =0 ; +bool running = false; +enum nl80211_iftype oldtype; -if (type == sdata->vif.type) -return 0 ; +ASSERT_RTNL ();/* Setting ad-hoc mode on non-IBSS channel is not supported. */ if (sdata->local->oper_channel->flags &IEEE80211_CHAN_NO_IBSS && type ==NL80211_IFTYPE_ADHOC )return -EOPNOTSUPP ; -/* -* We could, here, on changes between IBSS/STA/MESH modes, -* invoke an MLME function instead that disassociates etc. -* and goes into the requested mode. -*/ + oldtype = sdata->vif.type; + running =netif_running (sdata->dev); -if (netif_running (sdata->dev)) -return -EBUSY ; +if (running) +ieee80211_stop (sdata->dev);/* Purge and reset type-dependent state. */ ieee80211_teardown_sdata (sdata->dev);
@@ -778,7 +776,23 @@ int ieee80211_if_change_type(struct ieee sdata->local->hw.conf.channel->band); sdata->drop_unencrypted =0 ; -return 0 ; +if (running) { + ret =ieee80211_open (sdata->dev); +if (ret) { +/* +* ieee80211_open could fail, for example if the user +* wants to have an interface combination now that we +* do not support -- in that case roll back. This has +* to succeed unless we have a driver/mac80211 bug, +* since the interface was there before! +*/ +ieee80211_teardown_sdata (sdata->dev); +ieee80211_setup_sdata (sdata, oldtype); +WARN_ON (ieee80211_open (sdata->dev)); + } + } + +return ret; } int ieee80211_if_add(struct ieee80211_local *local, const char *name,
Quoted 54 lines · On Saturday 21 March 2009 17:39:23 Johannes Berg wrote:
It might be nicer sometimes to allow mode changes while the interface is up, e.g. from managed to ibss mode, so that IP configuration is retained. This patch changes mac80211 to support that, it effectively internally behaves as though you had actually done a down/change/up cycle.
Signed-off-by Johannes Berg <[email protected]>---
COMPLETELY UNTESTED. If anyone needs this functionality please test and adopt this patch -- I have no interest in pushing it into the kernel.net/mac80211/iface.c | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-)net/mac80211/iface.c +8
-10@@ -749,24 +749,22 @@ static void ieee80211_setup_sdata(structint ieee80211_if_change_type (struct ieee80211_sub_if_data *sdata,enum nl80211_iftype type) { -ASSERT_RTNL (); +int ret =0 ; +bool running = false; +enum nl80211_iftype oldtype; -if (type == sdata->vif.type) -return 0 ; +ASSERT_RTNL ();/* Setting ad-hoc mode on non-IBSS channel is not supported. */ if (sdata->local->oper_channel->flags &IEEE80211_CHAN_NO_IBSS && type ==NL80211_IFTYPE_ADHOC )return -EOPNOTSUPP ; -/* -* We could, here, on changes between IBSS/STA/MESH modes, -* invoke an MLME function instead that disassociates etc. -* and goes into the requested mode. -*/ + oldtype = sdata->vif.type; + running =netif_running (sdata->dev); -if (netif_running (sdata->dev)) -return -EBUSY ; +if (running) +ieee80211_stop (sdata->dev);/* Purge and reset type-dependent state. */ ieee80211_teardown_sdata (sdata->dev);@@ -778,7 +776,23 @@ int ieee80211_if_change_type(struct ieee sdata->local->hw.conf.channel->band); sdata->drop_unencrypted =0 ;
net/mac80211/iface.c int ieee80211_if_change_type(struct ieee · line 787
Quoted 10 lines
net/mac80211/iface.c +9
-1-return 0 ; +if (running) { + ret =ieee80211_open (sdata->dev); +if (ret) { +/* +* ieee80211_open could fail, for example if the user +* wants to have an interface combination now that we +* do not support -- in that case roll back. This has +* to succeed unless we have a driver/mac80211 bug, +* since the interface was there before!
What about memory allocation failures?
I think we should check for an error and if one occurs take the interface completely down and return the error to userspace.
Quoted 9 lines
net/mac80211/iface.c +8
-0+*/ +ieee80211_teardown_sdata (sdata->dev); +ieee80211_setup_sdata (sdata, oldtype); +WARN_ON (ieee80211_open (sdata->dev)); + } + } + +return ret; }
Signature · 1 line
Greetings, Michael.
Johannes Berg
maintainerQuoted 6 lines · Michael Buesch
Quoted 6 lines
net/mac80211/iface.c +5
-1-return 0 ; +if (running) { + ret =ieee80211_open (sdata->dev); +if (ret) { +/* +* ieee80211_open could fail, for example if the user
Quoted 8 lines
net/mac80211/iface.c int ieee80211_if_change_type(struct ieee · line 787
Quoted 4 lines
net/mac80211/iface.c +4
-0+* wants to have an interface combination now that we +* do not support -- in that case roll back. This has +* to succeed unless we have a driver/mac80211 bug, +* since the interface was there before! What about memory allocation failures?
I think we should check for an error and if one occurs take the interface completely down and return the error to userspace.
Makes sense, need to audit the code though to verify that ieee80211_stop() doesn't puke if you call it twice in a row (since dev_close() will call it again)
It's only proof-of-concept code -- like I said, I have no interest in it.
johannes
Johannes Berg
maintainerQuoted 7 lines · Johannes Berg
Quoted 3 lines
What about memory allocation failures?
I think we should check for an error and if one occurs take the interface completely down and return the error to userspace.Makes sense, need to audit the code though to verify that
ieee80211_stop()doesn't puke if you call it twice in a row (sincedev_close()will call it again)
In fact, it is _not_ safe to do that, the iff_allmultis/promiscs counters for example will be wrong. Easily worked around though -- shortcut the function if you realise it was already called.
johannes