Commit d22fbd70 authored by dingtianhong's avatar dingtianhong Committed by David S. Miller

hostap: slight optimization of addr compare

Use possibly more efficient ether_addr_equal
instead of memcmp.

Cc: Jouni Malinen <j@w1.fi>
Cc: John W. Linville <linville@tuxdriver.com>
Cc: linux-wireless@vger.kernel.org
Cc: netdev@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: default avatarWeilong Chen <chenweilong@huawei.com>
Signed-off-by: default avatarDing Tianhong <dingtianhong@huawei.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 5e231c2c
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/export.h> #include <linux/export.h>
#include <linux/etherdevice.h>
#include "hostap_80211.h" #include "hostap_80211.h"
#include "hostap_common.h" #include "hostap_common.h"
...@@ -103,8 +104,7 @@ netdev_tx_t hostap_data_start_xmit(struct sk_buff *skb, ...@@ -103,8 +104,7 @@ netdev_tx_t hostap_data_start_xmit(struct sk_buff *skb,
return NETDEV_TX_OK; return NETDEV_TX_OK;
} else if (local->iw_mode == IW_MODE_INFRA && } else if (local->iw_mode == IW_MODE_INFRA &&
(local->wds_type & HOSTAP_WDS_AP_CLIENT) && (local->wds_type & HOSTAP_WDS_AP_CLIENT) &&
memcmp(skb->data + ETH_ALEN, dev->dev_addr, !ether_addr_equal(skb->data + ETH_ALEN, dev->dev_addr)) {
ETH_ALEN) != 0) {
/* AP client mode: send frames with foreign src addr /* AP client mode: send frames with foreign src addr
* using 4-addr WDS frames */ * using 4-addr WDS frames */
use_wds = WDS_COMPLIANT_FRAME; use_wds = WDS_COMPLIANT_FRAME;
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/export.h> #include <linux/export.h>
#include <linux/moduleparam.h> #include <linux/moduleparam.h>
#include <linux/etherdevice.h>
#include "hostap_wlan.h" #include "hostap_wlan.h"
#include "hostap.h" #include "hostap.h"
...@@ -106,13 +107,12 @@ static void ap_sta_hash_del(struct ap_data *ap, struct sta_info *sta) ...@@ -106,13 +107,12 @@ static void ap_sta_hash_del(struct ap_data *ap, struct sta_info *sta)
s = ap->sta_hash[STA_HASH(sta->addr)]; s = ap->sta_hash[STA_HASH(sta->addr)];
if (s == NULL) return; if (s == NULL) return;
if (memcmp(s->addr, sta->addr, ETH_ALEN) == 0) { if (ether_addr_equal(s->addr, sta->addr)) {
ap->sta_hash[STA_HASH(sta->addr)] = s->hnext; ap->sta_hash[STA_HASH(sta->addr)] = s->hnext;
return; return;
} }
while (s->hnext != NULL && memcmp(s->hnext->addr, sta->addr, ETH_ALEN) while (s->hnext != NULL && !ether_addr_equal(s->hnext->addr, sta->addr))
!= 0)
s = s->hnext; s = s->hnext;
if (s->hnext != NULL) if (s->hnext != NULL)
s->hnext = s->hnext->hnext; s->hnext = s->hnext->hnext;
...@@ -435,7 +435,7 @@ int ap_control_del_mac(struct mac_restrictions *mac_restrictions, u8 *mac) ...@@ -435,7 +435,7 @@ int ap_control_del_mac(struct mac_restrictions *mac_restrictions, u8 *mac)
ptr != &mac_restrictions->mac_list; ptr = ptr->next) { ptr != &mac_restrictions->mac_list; ptr = ptr->next) {
entry = list_entry(ptr, struct mac_entry, list); entry = list_entry(ptr, struct mac_entry, list);
if (memcmp(entry->addr, mac, ETH_ALEN) == 0) { if (ether_addr_equal(entry->addr, mac)) {
list_del(ptr); list_del(ptr);
kfree(entry); kfree(entry);
mac_restrictions->entries--; mac_restrictions->entries--;
...@@ -459,7 +459,7 @@ static int ap_control_mac_deny(struct mac_restrictions *mac_restrictions, ...@@ -459,7 +459,7 @@ static int ap_control_mac_deny(struct mac_restrictions *mac_restrictions,
spin_lock_bh(&mac_restrictions->lock); spin_lock_bh(&mac_restrictions->lock);
list_for_each_entry(entry, &mac_restrictions->mac_list, list) { list_for_each_entry(entry, &mac_restrictions->mac_list, list) {
if (memcmp(entry->addr, mac, ETH_ALEN) == 0) { if (ether_addr_equal(entry->addr, mac)) {
found = 1; found = 1;
break; break;
} }
...@@ -957,7 +957,7 @@ static struct sta_info* ap_get_sta(struct ap_data *ap, u8 *sta) ...@@ -957,7 +957,7 @@ static struct sta_info* ap_get_sta(struct ap_data *ap, u8 *sta)
struct sta_info *s; struct sta_info *s;
s = ap->sta_hash[STA_HASH(sta)]; s = ap->sta_hash[STA_HASH(sta)];
while (s != NULL && memcmp(s->addr, sta, ETH_ALEN) != 0) while (s != NULL && !ether_addr_equal(s->addr, sta))
s = s->hnext; s = s->hnext;
return s; return s;
} }
...@@ -1391,7 +1391,7 @@ static void handle_authen(local_info_t *local, struct sk_buff *skb, ...@@ -1391,7 +1391,7 @@ static void handle_authen(local_info_t *local, struct sk_buff *skb,
status_code = __le16_to_cpu(*pos); status_code = __le16_to_cpu(*pos);
pos++; pos++;
if (memcmp(dev->dev_addr, hdr->addr2, ETH_ALEN) == 0 || if (ether_addr_equal(dev->dev_addr, hdr->addr2) ||
ap_control_mac_deny(&ap->mac_restrictions, hdr->addr2)) { ap_control_mac_deny(&ap->mac_restrictions, hdr->addr2)) {
txt = "authentication denied"; txt = "authentication denied";
resp = WLAN_STATUS_UNSPECIFIED_FAILURE; resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
...@@ -1935,7 +1935,7 @@ static void handle_pspoll(local_info_t *local, ...@@ -1935,7 +1935,7 @@ static void handle_pspoll(local_info_t *local,
PDEBUG(DEBUG_PS2, "handle_pspoll: BSSID=%pM, TA=%pM PWRMGT=%d\n", PDEBUG(DEBUG_PS2, "handle_pspoll: BSSID=%pM, TA=%pM PWRMGT=%d\n",
hdr->addr1, hdr->addr2, !!ieee80211_has_pm(hdr->frame_control)); hdr->addr1, hdr->addr2, !!ieee80211_has_pm(hdr->frame_control));
if (memcmp(hdr->addr1, dev->dev_addr, ETH_ALEN)) { if (!ether_addr_equal(hdr->addr1, dev->dev_addr)) {
PDEBUG(DEBUG_AP, PDEBUG(DEBUG_AP,
"handle_pspoll - addr1(BSSID)=%pM not own MAC\n", "handle_pspoll - addr1(BSSID)=%pM not own MAC\n",
hdr->addr1); hdr->addr1);
...@@ -2230,7 +2230,7 @@ static void handle_ap_item(local_info_t *local, struct sk_buff *skb, ...@@ -2230,7 +2230,7 @@ static void handle_ap_item(local_info_t *local, struct sk_buff *skb,
goto done; goto done;
} }
if (memcmp(hdr->addr1, dev->dev_addr, ETH_ALEN)) { if (!ether_addr_equal(hdr->addr1, dev->dev_addr)) {
PDEBUG(DEBUG_AP, "handle_ap_item - addr1(BSSID)=%pM" PDEBUG(DEBUG_AP, "handle_ap_item - addr1(BSSID)=%pM"
" not own MAC\n", hdr->addr1); " not own MAC\n", hdr->addr1);
goto done; goto done;
...@@ -2267,13 +2267,13 @@ static void handle_ap_item(local_info_t *local, struct sk_buff *skb, ...@@ -2267,13 +2267,13 @@ static void handle_ap_item(local_info_t *local, struct sk_buff *skb,
goto done; goto done;
} }
if (memcmp(hdr->addr1, dev->dev_addr, ETH_ALEN)) { if (!ether_addr_equal(hdr->addr1, dev->dev_addr)) {
PDEBUG(DEBUG_AP, "handle_ap_item - addr1(DA)=%pM" PDEBUG(DEBUG_AP, "handle_ap_item - addr1(DA)=%pM"
" not own MAC\n", hdr->addr1); " not own MAC\n", hdr->addr1);
goto done; goto done;
} }
if (memcmp(hdr->addr3, dev->dev_addr, ETH_ALEN)) { if (!ether_addr_equal(hdr->addr3, dev->dev_addr)) {
PDEBUG(DEBUG_AP, "handle_ap_item - addr3(BSSID)=%pM" PDEBUG(DEBUG_AP, "handle_ap_item - addr3(BSSID)=%pM"
" not own MAC\n", hdr->addr3); " not own MAC\n", hdr->addr3);
goto done; goto done;
...@@ -3035,7 +3035,7 @@ ap_rx_ret hostap_handle_sta_rx(local_info_t *local, struct net_device *dev, ...@@ -3035,7 +3035,7 @@ ap_rx_ret hostap_handle_sta_rx(local_info_t *local, struct net_device *dev,
if (!wds) { if (!wds) {
/* FromDS frame - not for us; probably /* FromDS frame - not for us; probably
* broadcast/multicast in another BSS - drop */ * broadcast/multicast in another BSS - drop */
if (memcmp(hdr->addr1, dev->dev_addr, ETH_ALEN) == 0) { if (ether_addr_equal(hdr->addr1, dev->dev_addr)) {
printk(KERN_DEBUG "Odd.. FromDS packet " printk(KERN_DEBUG "Odd.. FromDS packet "
"received with own BSSID\n"); "received with own BSSID\n");
hostap_dump_rx_80211(dev->name, skb, rx_stats); hostap_dump_rx_80211(dev->name, skb, rx_stats);
...@@ -3044,7 +3044,7 @@ ap_rx_ret hostap_handle_sta_rx(local_info_t *local, struct net_device *dev, ...@@ -3044,7 +3044,7 @@ ap_rx_ret hostap_handle_sta_rx(local_info_t *local, struct net_device *dev,
goto out; goto out;
} }
} else if (stype == IEEE80211_STYPE_NULLFUNC && sta == NULL && } else if (stype == IEEE80211_STYPE_NULLFUNC && sta == NULL &&
memcmp(hdr->addr1, dev->dev_addr, ETH_ALEN) == 0) { ether_addr_equal(hdr->addr1, dev->dev_addr)) {
if (local->hostapd) { if (local->hostapd) {
prism2_rx_80211(local->apdev, skb, rx_stats, prism2_rx_80211(local->apdev, skb, rx_stats,
...@@ -3073,7 +3073,7 @@ ap_rx_ret hostap_handle_sta_rx(local_info_t *local, struct net_device *dev, ...@@ -3073,7 +3073,7 @@ ap_rx_ret hostap_handle_sta_rx(local_info_t *local, struct net_device *dev,
/* If BSSID (Addr3) is foreign, this frame is a normal /* If BSSID (Addr3) is foreign, this frame is a normal
* broadcast frame from an IBSS network. Drop it silently. * broadcast frame from an IBSS network. Drop it silently.
* If BSSID is own, report the dropping of this frame. */ * If BSSID is own, report the dropping of this frame. */
if (memcmp(hdr->addr3, dev->dev_addr, ETH_ALEN) == 0) { if (ether_addr_equal(hdr->addr3, dev->dev_addr)) {
printk(KERN_DEBUG "%s: dropped received packet from %pM" printk(KERN_DEBUG "%s: dropped received packet from %pM"
" with no ToDS flag " " with no ToDS flag "
"(type=0x%02x, subtype=0x%02x)\n", dev->name, "(type=0x%02x, subtype=0x%02x)\n", dev->name,
......
...@@ -2175,7 +2175,7 @@ static void hostap_tx_callback(local_info_t *local, ...@@ -2175,7 +2175,7 @@ static void hostap_tx_callback(local_info_t *local,
struct hostap_tx_callback_info *cb; struct hostap_tx_callback_info *cb;
/* Make sure that frame was from us. */ /* Make sure that frame was from us. */
if (memcmp(txdesc->addr2, local->dev->dev_addr, ETH_ALEN)) { if (!ether_addr_equal(txdesc->addr2, local->dev->dev_addr)) {
printk(KERN_DEBUG "%s: TX callback - foreign frame\n", printk(KERN_DEBUG "%s: TX callback - foreign frame\n",
local->dev->name); local->dev->name);
return; return;
......
...@@ -655,7 +655,7 @@ static int hostap_join_ap(struct net_device *dev) ...@@ -655,7 +655,7 @@ static int hostap_join_ap(struct net_device *dev)
if (!local->last_scan_results) if (!local->last_scan_results)
break; break;
entry = &local->last_scan_results[i]; entry = &local->last_scan_results[i];
if (memcmp(local->preferred_ap, entry->bssid, ETH_ALEN) == 0) { if (ether_addr_equal(local->preferred_ap, entry->bssid)) {
req.channel = entry->chid; req.channel = entry->chid;
break; break;
} }
...@@ -1978,7 +1978,7 @@ static inline int prism2_translate_scan(local_info_t *local, ...@@ -1978,7 +1978,7 @@ static inline int prism2_translate_scan(local_info_t *local,
list_for_each(ptr, &local->bss_list) { list_for_each(ptr, &local->bss_list) {
struct hostap_bss_info *bss; struct hostap_bss_info *bss;
bss = list_entry(ptr, struct hostap_bss_info, list); bss = list_entry(ptr, struct hostap_bss_info, list);
if (memcmp(bss->bssid, scan->bssid, ETH_ALEN) == 0) { if (ether_addr_equal(bss->bssid, scan->bssid)) {
bss->included = 1; bss->included = 1;
current_ev = __prism2_translate_scan( current_ev = __prism2_translate_scan(
local, info, scan, bss, current_ev, local, info, scan, bss, current_ev,
......
...@@ -155,8 +155,7 @@ int prism2_wds_add(local_info_t *local, u8 *remote_addr, ...@@ -155,8 +155,7 @@ int prism2_wds_add(local_info_t *local, u8 *remote_addr,
if (prism2_wds_special_addr(iface->u.wds.remote_addr)) if (prism2_wds_special_addr(iface->u.wds.remote_addr))
empty = iface; empty = iface;
else if (memcmp(iface->u.wds.remote_addr, remote_addr, else if (ether_addr_equal(iface->u.wds.remote_addr, remote_addr)) {
ETH_ALEN) == 0) {
match = iface; match = iface;
break; break;
} }
...@@ -214,8 +213,7 @@ int prism2_wds_del(local_info_t *local, u8 *remote_addr, ...@@ -214,8 +213,7 @@ int prism2_wds_del(local_info_t *local, u8 *remote_addr,
if (iface->type != HOSTAP_INTERFACE_WDS) if (iface->type != HOSTAP_INTERFACE_WDS)
continue; continue;
if (memcmp(iface->u.wds.remote_addr, remote_addr, if (ether_addr_equal(iface->u.wds.remote_addr, remote_addr)) {
ETH_ALEN) == 0) {
selected = iface; selected = iface;
break; break;
} }
...@@ -1085,7 +1083,7 @@ int prism2_sta_deauth(local_info_t *local, u16 reason) ...@@ -1085,7 +1083,7 @@ int prism2_sta_deauth(local_info_t *local, u16 reason)
if (local->iw_mode != IW_MODE_INFRA || if (local->iw_mode != IW_MODE_INFRA ||
is_zero_ether_addr(local->bssid) || is_zero_ether_addr(local->bssid) ||
memcmp(local->bssid, "\x44\x44\x44\x44\x44\x44", ETH_ALEN) == 0) ether_addr_equal(local->bssid, "\x44\x44\x44\x44\x44\x44"))
return 0; return 0;
ret = prism2_sta_send_mgmt(local, local->bssid, IEEE80211_STYPE_DEAUTH, ret = prism2_sta_send_mgmt(local, local->bssid, IEEE80211_STYPE_DEAUTH,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment