* [RFT] mac80211: allow mode changes while interface is up
@ 2009-03-21 16:39 Johannes Berg
2009-03-21 16:45 ` Michael Buesch
0 siblings, 1 reply; 4+ messages in thread
From: Johannes Berg @ 2009-03-21 16:39 UTC (permalink / raw)
To: linux-wireless
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 <johannes@sipsolutions.net>
---
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(-)
--- wireless-testing.orig/net/mac80211/iface.c 2009-03-21 17:20:23.000000000 +0100
+++ wireless-testing/net/mac80211/iface.c 2009-03-21 17:26:59.000000000 +0100
@@ -749,24 +749,22 @@ static void ieee80211_setup_sdata(struct
int 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,
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [RFT] mac80211: allow mode changes while interface is up
2009-03-21 16:39 [RFT] mac80211: allow mode changes while interface is up Johannes Berg
@ 2009-03-21 16:45 ` Michael Buesch
2009-03-21 16:56 ` Johannes Berg
0 siblings, 1 reply; 4+ messages in thread
From: Michael Buesch @ 2009-03-21 16:45 UTC (permalink / raw)
To: Johannes Berg; +Cc: linux-wireless
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 <johannes@sipsolutions.net>
> ---
> 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(-)
>
> --- wireless-testing.orig/net/mac80211/iface.c 2009-03-21 17:20:23.000000000 +0100
> +++ wireless-testing/net/mac80211/iface.c 2009-03-21 17:26:59.000000000 +0100
> @@ -749,24 +749,22 @@ static void ieee80211_setup_sdata(struct
> int 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!
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.
> + */
> + ieee80211_teardown_sdata(sdata->dev);
> + ieee80211_setup_sdata(sdata, oldtype);
> + WARN_ON(ieee80211_open(sdata->dev));
> + }
> + }
> +
> + return ret;
> }
--
Greetings, Michael.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [RFT] mac80211: allow mode changes while interface is up
2009-03-21 16:45 ` Michael Buesch
@ 2009-03-21 16:56 ` Johannes Berg
2009-03-21 17:13 ` Johannes Berg
0 siblings, 1 reply; 4+ messages in thread
From: Johannes Berg @ 2009-03-21 16:56 UTC (permalink / raw)
To: Michael Buesch; +Cc: linux-wireless
[-- Attachment #1: Type: text/plain, Size: 901 bytes --]
On Sat, 2009-03-21 at 17:45 +0100, Michael Buesch wrote:
> > - 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.
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
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 836 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [RFT] mac80211: allow mode changes while interface is up
2009-03-21 16:56 ` Johannes Berg
@ 2009-03-21 17:13 ` Johannes Berg
0 siblings, 0 replies; 4+ messages in thread
From: Johannes Berg @ 2009-03-21 17:13 UTC (permalink / raw)
To: Michael Buesch; +Cc: linux-wireless
[-- Attachment #1: Type: text/plain, Size: 617 bytes --]
On Sat, 2009-03-21 at 17:56 +0100, Johannes Berg wrote:
> > 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)
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
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 836 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2009-03-21 17:13 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-03-21 16:39 [RFT] mac80211: allow mode changes while interface is up Johannes Berg
2009-03-21 16:45 ` Michael Buesch
2009-03-21 16:56 ` Johannes Berg
2009-03-21 17:13 ` Johannes Berg
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).