mac80211: Allow single vif mac address change with addr_mask
PATCH 1/1 mac80211: Allow single vif mac address change with addr_mask
When changing the MAC address of a single vif mac80211 will check if the new address fits into the address mask specified by the driver. This only needs to be done when using multiple BSSIDs. Hence, check the new address only against all other vifs.
Resolves:
https://bugzilla.kernel.org/show_bug.cgi?id=57371
--- net/mac80211/iface.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-)
net/mac80211/iface.c +10 -6
@@ -159,9 +159,10 @@ static int ieee80211_change_mtu(struct net_device *dev, int new_mtu)return 0 ; } -static int ieee80211_verify_mac (struct ieee80211_local *local,u8 *addr) +static int ieee80211_verify_mac (struct ieee80211_sub_if_data *sdata,u8 *addr) { -struct ieee80211_sub_if_data *sdata; +struct ieee80211_local *local = sdata->local; +struct ieee80211_sub_if_data *iter;u64 new, mask, tmp;u8 *m;int ret =0 ;
@@ -181,11 +182,14 @@ static int ieee80211_verify_mac(struct ieee80211_local *local, u8 *addr)mutex_lock (&local->iflist_mtx); -list_for_each_entry (sdata, &local->interfaces, list) { -if (sdata->vif.type ==NL80211_IFTYPE_MONITOR ) +list_for_each_entry (iter, &local->interfaces, list) { +if (iter == sdata) +continue ; + +if (iter->vif.type ==NL80211_IFTYPE_MONITOR )continue ; - m = sdata->vif.addr; + m = iter->vif.addr; tmp = ((u64 )m[0 ] <<5 *8 ) | ((u64 )m[1 ] <<4 *8 ) | ((u64 )m[2 ] <<3 *8 ) | ((u64 )m[3 ] <<2 *8 ) | ((u64 )m[4 ] <<1 *8 ) | ((u64 )m[5 ] <<0 *8 );
@@ -209,7 +213,7 @@ static int ieee80211_change_mac(struct net_device *dev, void *addr)if (ieee80211_sdata_running (sdata))return -EBUSY ; - ret =ieee80211_verify_mac (sdata->local, sa->sa_data); + ret =ieee80211_verify_mac (sdata, sa->sa_data);if (ret)return ret;
Signature · 1 line
1.7.10.4
Quoted 4 lines · Helmut Schaa
When changing the MAC address of a single vif mac80211 will check if the new address fits into the address mask specified by the driver. This only needs to be done when using multiple BSSIDs. Hence, check the new address only against all other vifs.
Oh, I see that you already posted this patch for review!
I think we should also take care of the way addresses for new interfaces are chosen otherwise they'll just pick up perm_addr and we will end up with incompatible MACs.
I created a patch for a user who reported this problem to rt2x00 ML independently from Helmut.
--->8------------------
Quoted 1 line
From
63b32f4509d2c2bcf0ad791faa624b56a1947748Mon Sep 17 00:00:00 2001
From: Jakub Kicinski <[email protected]>
Date: Tue, 21 May 2013 13:05:43 +0200
Subject: [PATCH] mac80211: allow changing mac address on mac-masking devices
Some devices support multiple MAC addresses by
masking last few bits of the address. Address
compatibility has to be checked only when there
is more than one interface - otherwise we can
just overwrite current address.
While at it fix inverted flow at the end ofieee80211_change_mac.
--- net/mac80211/iface.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-)
net/mac80211/iface.c +18 -4
@@ -159,8 +159,9 @@ static int ieee80211_change_mtu(struct net_device *dev, int new_mtu)return 0 ; } -static int ieee80211_verify_mac (struct ieee80211_local *local,u8 *addr) +static int ieee80211_verify_mac (struct ieee80211_sub_if_data *target,u8 *addr) { +struct ieee80211_local *local = target->local;struct ieee80211_sub_if_data *sdata;u64 new, mask, tmp;u8 *m;
@@ -184,6 +185,8 @@ static int ieee80211_verify_mac(struct ieee80211_local *local, u8 *addr)list_for_each_entry (sdata, &local->interfaces, list) {if (sdata->vif.type ==NL80211_IFTYPE_MONITOR )continue ; +if (sdata == target) +continue ; m = sdata->vif.addr; tmp = ((u64)m[0] << 5*8) | ((u64)m[1] << 4*8) |
@@ -209,14 +212,15 @@ static int ieee80211_change_mac(struct net_device *dev, void *addr)if (ieee80211_sdata_running (sdata))return -EBUSY ; - ret =ieee80211_verify_mac (sdata->local, sa->sa_data); + ret =ieee80211_verify_mac (sdata, sa->sa_data);if (ret)return ret; ret =eth_mac_addr (dev, sa); +if (ret) +return ret; -if (ret ==0 ) -memcpy (sdata->vif.addr, sa->sa_data,ETH_ALEN ); +memcpy (sdata->vif.addr, sa->sa_data,ETH_ALEN );return ret; }
@@ -1479,7 +1483,17 @@ static void ieee80211_assign_perm_addr(struct ieee80211_local *local,break ; } +/* +* Pick address of existing interface in case user changed +* MAC address manually, default to perm_addr. +*/ m = local->hw.wiphy->perm_addr; +list_for_each_entry (sdata, &local->interfaces, list) { +if (sdata->vif.type ==NL80211_IFTYPE_MONITOR ) +continue ; + m = sdata->vif.addr; +break ; + } start = ((u64 )m[0 ] <<5 *8 ) | ((u64 )m[1 ] <<4 *8 ) | ((u64 )m[2 ] <<3 *8 ) | ((u64 )m[3 ] <<2 *8 ) | ((u64 )m[4 ] <<1 *8 ) | ((u64 )m[5 ] <<0 *8 );
Signature · 1 line
1.8.1.4
Quoted 11 lines · Jakub Kiciński
Quoted 4 lines · Helmut Schaa
When changing the MAC address of a single vif mac80211 will check if the new address fits into the address mask specified by the driver. This only needs to be done when using multiple BSSIDs. Hence, check the new address only against all other vifs.
Oh, I see that you already posted this patch for review!
I think we should also take care of the way addresses for new interfaces are chosen otherwise they'll just pick up
perm_addrand we will end up with incompatible MACs.
Maybe you could send the assign_pem_addr changes as a follow up patch?
[...]
Quoted 8 lines
net/mac80211/iface.c +4
-0@@ -1479,7 +1483,17 @@ static void ieee80211_assign_perm_addr(struct ieee80211_local *local,break ; } +/* +* Pick address of existing interface in case user changed +* MAC address manually, default to perm_addr. +*/
net/mac80211/iface.c static void ieee80211_assign_perm_addr(struct ieee80211_local *local, · line 1499
Quoted 10 lines
net/mac80211/iface.c +6
-0m = local->hw.wiphy->perm_addr; +list_for_each_entry (sdata, &local->interfaces, list) { +if (sdata->vif.type ==NL80211_IFTYPE_MONITOR ) +continue ; + m = sdata->vif.addr; +break ; + } start = ((u64 )m[0 ] <<5 *8 ) | ((u64 )m[1 ] <<4 *8 ) | ((u64 )m[2 ] <<3 *8 ) | ((u64 )m[3 ] <<2 *8 ) | ((u64 )m[4 ] <<1 *8 ) | ((u64 )m[5 ] <<0 *8 );
This is only relevant if the driver registered a addr_mask with mac80211. So, maybe you could only select a new address (!=perm_addr) if the perm_addr is not covered by the addr_mask?
Helmut
Quoted 7 lines · Helmut Schaa
Quoted 6 lines · Jakub Kiciński
Quoted 4 lines · Helmut Schaa
When changing the MAC address of a single vif mac80211 will check if the new address fits into the address mask specified by the driver. This only needs to be done when using multiple BSSIDs. Hence, check the new address only against all other vifs.
Quoted 7 lines
Quoted 5 lines
Oh, I see that you already posted this patch for review!
I think we should also take care of the way addresses for new interfaces are chosen otherwise they'll just pick up
perm_addrand we will end up with incompatible MACs.Maybe you could send the
assign_pem_addrchanges as a follow up patch?
I would rather not, I think it would be messy. Or is your patch already merged somewhere?
Perhaps you could incorporate the change to assign_pem_addr into your patch and send v2 adding my Sign-off?
Quoted 14 lines
Quoted 14 lines
net/mac80211/iface.c +9
-0@@ -1479,7 +1483,17 @@ static void ieee80211_assign_perm_addr(struct ieee80211_local *local,break ; } +/* +* Pick address of existing interface in case user changed +* MAC address manually, default to perm_addr. +*/ m = local->hw.wiphy->perm_addr; +list_for_each_entry (sdata, &local->interfaces, list) { +if (sdata->vif.type ==NL80211_IFTYPE_MONITOR ) +continue ; + m = sdata->vif.addr; +break ;
Quoted 8 lines
net/mac80211/iface.c static void ieee80211_assign_perm_addr(struct ieee80211_local *local, · line 1499
Quoted 4 lines
net/mac80211/iface.c +1
-0+ } start = ((u64 )m[0 ] <<5 *8 ) | ((u64 )m[1 ] <<4 *8 ) | ((u64 )m[2 ] <<3 *8 ) | ((u64 )m[3 ] <<2 *8 ) | ((u64 )m[4 ] <<1 *8 ) | ((u64 )m[5 ] <<0 *8 );This is only relevant if the driver registered a
addr_maskwith mac80211. So, maybe you could only select a new address (!=perm_addr) if theperm_addris not covered by theaddr_mask?
I'm not sure I understand all the internal logic, but if driver doesn't set addr_mask it will always get one of wiphy->addresses or perm_addr and leave on line 1468 [1] before reaching this code.
[1]http://git.kernel.org/cgit/linux/kernel/git/jberg/mac80211-next.git/tree/net/mac80211/iface.c#n1468
-- Kuba
Quoted 2 lines · Jakub Kiciński
Perhaps you could incorporate the change to
assign_pem_addrinto your patch and send v2 adding my Sign-off?
Will do.
Quoted 23 lines
Quoted 14 lines
Quoted 14 lines
net/mac80211/iface.c +9
-0@@ -1479,7 +1483,17 @@ static void ieee80211_assign_perm_addr(struct ieee80211_local *local,break ; } +/* +* Pick address of existing interface in case user changed +* MAC address manually, default to perm_addr. +*/ m = local->hw.wiphy->perm_addr; +list_for_each_entry (sdata, &local->interfaces, list) { +if (sdata->vif.type ==NL80211_IFTYPE_MONITOR ) +continue ; + m = sdata->vif.addr; +break ;Quoted 8 lines
net/mac80211/iface.c static void ieee80211_assign_perm_addr(struct ieee80211_local *local, · line 1499
Quoted 4 lines
net/mac80211/iface.c +1
-0+ } start = ((u64 )m[0 ] <<5 *8 ) | ((u64 )m[1 ] <<4 *8 ) | ((u64 )m[2 ] <<3 *8 ) | ((u64 )m[3 ] <<2 *8 ) | ((u64 )m[4 ] <<1 *8 ) | ((u64 )m[5 ] <<0 *8 );This is only relevant if the driver registered a
addr_maskwith mac80211. So, maybe you could only select a new address (!=perm_addr) if theperm_addris not covered by theaddr_mask?
Quoted 4 lines
I'm not sure I understand all the internal logic, but if driver doesn't set
addr_maskit will always get one ofwiphy->addressesorperm_addrand leave on line 1468 [1] before reaching this code.
My fault. This is indeed correct.
Johannes, please drop this patch. I'll respin.
Thanks,
Helmut
R: [PATCH] mac80211: Allow single vif mac address change with addr_mask
In reply to Helmut SchaaTested right now against compat-drivers-2013-03-28-5-u and I can confirm it works.
Thank you for your effort!
Alessandro Lannocca
-----Messaggio originale-----
Da: Helmut Schaa [mailto:[email protected]]
Inviato: martedì 21 maggio 2013 14.55
A: [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Helmut Schaa; Alessandro Lannocca; Bruno Randolf
Oggetto: [PATCH] mac80211: Allow single vif mac address change with addr_mask
When changing the MAC address of a single vif mac80211 will check if the new address fits into the address mask specified by the driver. This only needs to be done when using multiple BSSIDs. Hence, check the new address only against all other vifs.
Resolves:
https://bugzilla.kernel.org/show_bug.cgi?id=57371
--- net/mac80211/iface.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-)
net/mac80211/iface.c index renamed from net/mac80211/iface.c +0 -0
60f1ce5..c1a8c79 100644
net/mac80211/iface.c +0 -0
@@ -159,9 +159,10 @@ static int ieee80211_change_mtu(struct net_device *dev,
int new_mtu)
return 0;
}
-static int ieee80211_verify_mac(struct ieee80211_local *local, u8 *addr) +static int ieee80211_verify_mac(struct ieee80211_sub_if_data *sdata, u8 +*addr)
{
- struct ieee80211_sub_if_data *sdata;
+ struct ieee80211_local *local = sdata->local;
+ struct ieee80211_sub_if_data *iter;
u64 new, mask, tmp;
u8 *m;
int ret = 0;
@@ -181,11 +182,14 @@ static int ieee80211_verify_mac(struct ieee80211_local *local, u8 *addr)
mutex_lock(&local->iflist_mtx);
- list_for_each_entry(sdata, &local->interfaces, list) {
- if (sdata->vif.type == NL80211_IFTYPE_MONITOR)
+ list_for_each_entry(iter, &local->interfaces, list) {
+ if (iter == sdata)
+ continue;
+
+ if (iter->vif.type == NL80211_IFTYPE_MONITOR)
continue;
- m = sdata->vif.addr;
+ m = iter->vif.addr;
tmp = ((u64)m[0] << 5*8) | ((u64)m[1] << 4*8) |
((u64)m[2] << 3*8) | ((u64)m[3] << 2*8) | ((u64)m[4] << 1*8) | ((u64)m[5] << 0*8); @@ -209,7
+213,7 @@ static int ieee80211_change_mac(struct net_device *dev, void *addr)
if (ieee80211_sdata_running(sdata))
return -EBUSY;
- ret = ieee80211_verify_mac(sdata->local, sa->sa_data);
+ ret = ieee80211_verify_mac(sdata, sa->sa_data);
if (ret)
return ret;
--
1.7.10.4
PATCH v2 1/1 mac80211: Allow single vif mac address change with addr_mask
In reply to Helmut SchaaWhen changing the MAC address of a single vif mac80211 will check if the new address fits into the address mask specified by the driver. This only needs to be done when using multiple BSSIDs. Hence, check the new address only against all other vifs.
Also fix the MAC address assignment on new interfaces if the user changed the address of a vif such that perm_addr is not covered by addr_mask anymore.
Resolves:
https://bugzilla.kernel.org/show_bug.cgi?id=57371
--- net/mac80211/iface.c | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-)
net/mac80211/iface.c +20 -6
@@ -159,9 +159,10 @@ static int ieee80211_change_mtu(struct net_device *dev, int new_mtu)return 0 ; } -static int ieee80211_verify_mac (struct ieee80211_local *local,u8 *addr) +static int ieee80211_verify_mac (struct ieee80211_sub_if_data *sdata,u8 *addr) { -struct ieee80211_sub_if_data *sdata; +struct ieee80211_local *local = sdata->local; +struct ieee80211_sub_if_data *iter;u64 new, mask, tmp;u8 *m;int ret =0 ;
@@ -181,11 +182,14 @@ static int ieee80211_verify_mac(struct ieee80211_local *local, u8 *addr)mutex_lock (&local->iflist_mtx); -list_for_each_entry (sdata, &local->interfaces, list) { -if (sdata->vif.type ==NL80211_IFTYPE_MONITOR ) +list_for_each_entry (iter, &local->interfaces, list) { +if (iter == sdata)continue ; - m = sdata->vif.addr; +if (iter->vif.type ==NL80211_IFTYPE_MONITOR ) +continue ; + + m = iter->vif.addr; tmp = ((u64 )m[0 ] <<5 *8 ) | ((u64 )m[1 ] <<4 *8 ) | ((u64 )m[2 ] <<3 *8 ) | ((u64 )m[3 ] <<2 *8 ) | ((u64 )m[4 ] <<1 *8 ) | ((u64 )m[5 ] <<0 *8 );
@@ -209,7 +213,7 @@ static int ieee80211_change_mac(struct net_device *dev, void *addr)if (ieee80211_sdata_running (sdata))return -EBUSY ; - ret =ieee80211_verify_mac (sdata->local, sa->sa_data); + ret =ieee80211_verify_mac (sdata, sa->sa_data);if (ret)return ret;
@@ -1479,7 +1483,17 @@ static void ieee80211_assign_perm_addr(struct ieee80211_local *local,break ; } +/* +* Pick address of existing interface in case user changed +* MAC address manually, default to perm_addr. +*/ m = local->hw.wiphy->perm_addr; +list_for_each_entry (sdata, &local->interfaces, list) { +if (sdata->vif.type ==NL80211_IFTYPE_MONITOR ) +continue ; + m = sdata->vif.addr; +break ; + } start = ((u64 )m[0 ] <<5 *8 ) | ((u64 )m[1 ] <<4 *8 ) | ((u64 )m[2 ] <<3 *8 ) | ((u64 )m[3 ] <<2 *8 ) | ((u64 )m[4 ] <<1 *8 ) | ((u64 )m[5 ] <<0 *8 );
Signature · 1 line
1.7.10.4
Johannes Berg
maintainerQuoted 11 lines · Helmut Schaa
When changing the MAC address of a single vif mac80211 will check if the new address fits into the address mask specified by the driver. This only needs to be done when using multiple BSSIDs. Hence, check the new address only against all other vifs.
Also fix the MAC address assignment on new interfaces if the user changed the address of a vif such that
perm_addris not covered byaddr_maskanymore.
Applied for 3.10, thanks.
johannes