diff mbox

[RFC,3/5] mac80211: always default to address compatible with mask

Message ID 1370612179-24385-4-git-send-email-moorray3@wp.pl (mailing list archive)
State Not Applicable, archived
Headers show

Commit Message

Jakub Kici?ski June 7, 2013, 1:36 p.m. UTC
From: Jakub Kicinski <kubakici@wp.pl>

Currently default mac address for new interfaces
is set to perm_addr. It can be addr_mask-wise
incompatible with other addresses if user have
changed address of existing interfaces manualy.

This is especially important after introduction
of active monitors. We have to make sure that
monitor interfaces have mac addresses that fall
into addr_mask, otherwise hardware may not
acknowledge frames.

Signed-off-by: Jakub Kicinski <kubakici@wp.pl>
---
 net/mac80211/iface.c | 21 ++++++++++-----------
 1 file changed, 10 insertions(+), 11 deletions(-)
diff mbox

Patch

diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
index 38898b3..1f26980 100644
--- a/net/mac80211/iface.c
+++ b/net/mac80211/iface.c
@@ -1468,17 +1468,7 @@  static void __ieee80211_assign_perm_addr(struct ieee80211_local *local,
 		return;
 	}
 
-	/*
-	 * 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;
-	}
+	m = perm_addr;
 	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);
@@ -1529,6 +1519,15 @@  static void ieee80211_assign_perm_addr(struct ieee80211_local *local,
 
 	mutex_lock(&local->iflist_mtx);
 
+	/* After manual mac change default addr may no longer fit into mask. */
+	if (!is_zero_ether_addr(local->hw.wiphy->addr_mask) &&
+	    !list_empty(&local->interfaces)) {
+		sdata = list_first_entry(&local->interfaces,
+					 struct ieee80211_sub_if_data,
+					 list);
+		memcpy(perm_addr, sdata->vif.addr, ETH_ALEN);
+	}
+
 	switch (type) {
 	case NL80211_IFTYPE_MONITOR:
 		/* doesn't matter */