Skip to content

Commit d22fbd7

Browse files
dingtianhongdavem330
authored andcommitted
hostap: slight optimization of addr compare
Use possibly more efficient ether_addr_equal instead of memcmp. Cc: Jouni Malinen <[email protected]> Cc: John W. Linville <[email protected]> Cc: [email protected] Cc: [email protected] Cc: [email protected] Signed-off-by: Weilong Chen <[email protected]> Signed-off-by: Ding Tianhong <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 5e231c2 commit d22fbd7

File tree

5 files changed

+22
-24
lines changed

5 files changed

+22
-24
lines changed

drivers/net/wireless/hostap/hostap_80211_tx.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include <linux/slab.h>
22
#include <linux/export.h>
3+
#include <linux/etherdevice.h>
34

45
#include "hostap_80211.h"
56
#include "hostap_common.h"
@@ -103,8 +104,7 @@ netdev_tx_t hostap_data_start_xmit(struct sk_buff *skb,
103104
return NETDEV_TX_OK;
104105
} else if (local->iw_mode == IW_MODE_INFRA &&
105106
(local->wds_type & HOSTAP_WDS_AP_CLIENT) &&
106-
memcmp(skb->data + ETH_ALEN, dev->dev_addr,
107-
ETH_ALEN) != 0) {
107+
!ether_addr_equal(skb->data + ETH_ALEN, dev->dev_addr)) {
108108
/* AP client mode: send frames with foreign src addr
109109
* using 4-addr WDS frames */
110110
use_wds = WDS_COMPLIANT_FRAME;

drivers/net/wireless/hostap/hostap_ap.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <linux/slab.h>
2525
#include <linux/export.h>
2626
#include <linux/moduleparam.h>
27+
#include <linux/etherdevice.h>
2728

2829
#include "hostap_wlan.h"
2930
#include "hostap.h"
@@ -106,13 +107,12 @@ static void ap_sta_hash_del(struct ap_data *ap, struct sta_info *sta)
106107

107108
s = ap->sta_hash[STA_HASH(sta->addr)];
108109
if (s == NULL) return;
109-
if (memcmp(s->addr, sta->addr, ETH_ALEN) == 0) {
110+
if (ether_addr_equal(s->addr, sta->addr)) {
110111
ap->sta_hash[STA_HASH(sta->addr)] = s->hnext;
111112
return;
112113
}
113114

114-
while (s->hnext != NULL && memcmp(s->hnext->addr, sta->addr, ETH_ALEN)
115-
!= 0)
115+
while (s->hnext != NULL && !ether_addr_equal(s->hnext->addr, sta->addr))
116116
s = s->hnext;
117117
if (s->hnext != NULL)
118118
s->hnext = s->hnext->hnext;
@@ -435,7 +435,7 @@ int ap_control_del_mac(struct mac_restrictions *mac_restrictions, u8 *mac)
435435
ptr != &mac_restrictions->mac_list; ptr = ptr->next) {
436436
entry = list_entry(ptr, struct mac_entry, list);
437437

438-
if (memcmp(entry->addr, mac, ETH_ALEN) == 0) {
438+
if (ether_addr_equal(entry->addr, mac)) {
439439
list_del(ptr);
440440
kfree(entry);
441441
mac_restrictions->entries--;
@@ -459,7 +459,7 @@ static int ap_control_mac_deny(struct mac_restrictions *mac_restrictions,
459459

460460
spin_lock_bh(&mac_restrictions->lock);
461461
list_for_each_entry(entry, &mac_restrictions->mac_list, list) {
462-
if (memcmp(entry->addr, mac, ETH_ALEN) == 0) {
462+
if (ether_addr_equal(entry->addr, mac)) {
463463
found = 1;
464464
break;
465465
}
@@ -957,7 +957,7 @@ static struct sta_info* ap_get_sta(struct ap_data *ap, u8 *sta)
957957
struct sta_info *s;
958958

959959
s = ap->sta_hash[STA_HASH(sta)];
960-
while (s != NULL && memcmp(s->addr, sta, ETH_ALEN) != 0)
960+
while (s != NULL && !ether_addr_equal(s->addr, sta))
961961
s = s->hnext;
962962
return s;
963963
}
@@ -1391,7 +1391,7 @@ static void handle_authen(local_info_t *local, struct sk_buff *skb,
13911391
status_code = __le16_to_cpu(*pos);
13921392
pos++;
13931393

1394-
if (memcmp(dev->dev_addr, hdr->addr2, ETH_ALEN) == 0 ||
1394+
if (ether_addr_equal(dev->dev_addr, hdr->addr2) ||
13951395
ap_control_mac_deny(&ap->mac_restrictions, hdr->addr2)) {
13961396
txt = "authentication denied";
13971397
resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
@@ -1935,7 +1935,7 @@ static void handle_pspoll(local_info_t *local,
19351935
PDEBUG(DEBUG_PS2, "handle_pspoll: BSSID=%pM, TA=%pM PWRMGT=%d\n",
19361936
hdr->addr1, hdr->addr2, !!ieee80211_has_pm(hdr->frame_control));
19371937

1938-
if (memcmp(hdr->addr1, dev->dev_addr, ETH_ALEN)) {
1938+
if (!ether_addr_equal(hdr->addr1, dev->dev_addr)) {
19391939
PDEBUG(DEBUG_AP,
19401940
"handle_pspoll - addr1(BSSID)=%pM not own MAC\n",
19411941
hdr->addr1);
@@ -2230,7 +2230,7 @@ static void handle_ap_item(local_info_t *local, struct sk_buff *skb,
22302230
goto done;
22312231
}
22322232

2233-
if (memcmp(hdr->addr1, dev->dev_addr, ETH_ALEN)) {
2233+
if (!ether_addr_equal(hdr->addr1, dev->dev_addr)) {
22342234
PDEBUG(DEBUG_AP, "handle_ap_item - addr1(BSSID)=%pM"
22352235
" not own MAC\n", hdr->addr1);
22362236
goto done;
@@ -2267,13 +2267,13 @@ static void handle_ap_item(local_info_t *local, struct sk_buff *skb,
22672267
goto done;
22682268
}
22692269

2270-
if (memcmp(hdr->addr1, dev->dev_addr, ETH_ALEN)) {
2270+
if (!ether_addr_equal(hdr->addr1, dev->dev_addr)) {
22712271
PDEBUG(DEBUG_AP, "handle_ap_item - addr1(DA)=%pM"
22722272
" not own MAC\n", hdr->addr1);
22732273
goto done;
22742274
}
22752275

2276-
if (memcmp(hdr->addr3, dev->dev_addr, ETH_ALEN)) {
2276+
if (!ether_addr_equal(hdr->addr3, dev->dev_addr)) {
22772277
PDEBUG(DEBUG_AP, "handle_ap_item - addr3(BSSID)=%pM"
22782278
" not own MAC\n", hdr->addr3);
22792279
goto done;
@@ -3035,7 +3035,7 @@ ap_rx_ret hostap_handle_sta_rx(local_info_t *local, struct net_device *dev,
30353035
if (!wds) {
30363036
/* FromDS frame - not for us; probably
30373037
* broadcast/multicast in another BSS - drop */
3038-
if (memcmp(hdr->addr1, dev->dev_addr, ETH_ALEN) == 0) {
3038+
if (ether_addr_equal(hdr->addr1, dev->dev_addr)) {
30393039
printk(KERN_DEBUG "Odd.. FromDS packet "
30403040
"received with own BSSID\n");
30413041
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,
30443044
goto out;
30453045
}
30463046
} else if (stype == IEEE80211_STYPE_NULLFUNC && sta == NULL &&
3047-
memcmp(hdr->addr1, dev->dev_addr, ETH_ALEN) == 0) {
3047+
ether_addr_equal(hdr->addr1, dev->dev_addr)) {
30483048

30493049
if (local->hostapd) {
30503050
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,
30733073
/* If BSSID (Addr3) is foreign, this frame is a normal
30743074
* broadcast frame from an IBSS network. Drop it silently.
30753075
* If BSSID is own, report the dropping of this frame. */
3076-
if (memcmp(hdr->addr3, dev->dev_addr, ETH_ALEN) == 0) {
3076+
if (ether_addr_equal(hdr->addr3, dev->dev_addr)) {
30773077
printk(KERN_DEBUG "%s: dropped received packet from %pM"
30783078
" with no ToDS flag "
30793079
"(type=0x%02x, subtype=0x%02x)\n", dev->name,

drivers/net/wireless/hostap/hostap_hw.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2175,7 +2175,7 @@ static void hostap_tx_callback(local_info_t *local,
21752175
struct hostap_tx_callback_info *cb;
21762176

21772177
/* Make sure that frame was from us. */
2178-
if (memcmp(txdesc->addr2, local->dev->dev_addr, ETH_ALEN)) {
2178+
if (!ether_addr_equal(txdesc->addr2, local->dev->dev_addr)) {
21792179
printk(KERN_DEBUG "%s: TX callback - foreign frame\n",
21802180
local->dev->name);
21812181
return;

drivers/net/wireless/hostap/hostap_ioctl.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -655,7 +655,7 @@ static int hostap_join_ap(struct net_device *dev)
655655
if (!local->last_scan_results)
656656
break;
657657
entry = &local->last_scan_results[i];
658-
if (memcmp(local->preferred_ap, entry->bssid, ETH_ALEN) == 0) {
658+
if (ether_addr_equal(local->preferred_ap, entry->bssid)) {
659659
req.channel = entry->chid;
660660
break;
661661
}
@@ -1978,7 +1978,7 @@ static inline int prism2_translate_scan(local_info_t *local,
19781978
list_for_each(ptr, &local->bss_list) {
19791979
struct hostap_bss_info *bss;
19801980
bss = list_entry(ptr, struct hostap_bss_info, list);
1981-
if (memcmp(bss->bssid, scan->bssid, ETH_ALEN) == 0) {
1981+
if (ether_addr_equal(bss->bssid, scan->bssid)) {
19821982
bss->included = 1;
19831983
current_ev = __prism2_translate_scan(
19841984
local, info, scan, bss, current_ev,

drivers/net/wireless/hostap/hostap_main.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,7 @@ int prism2_wds_add(local_info_t *local, u8 *remote_addr,
155155

156156
if (prism2_wds_special_addr(iface->u.wds.remote_addr))
157157
empty = iface;
158-
else if (memcmp(iface->u.wds.remote_addr, remote_addr,
159-
ETH_ALEN) == 0) {
158+
else if (ether_addr_equal(iface->u.wds.remote_addr, remote_addr)) {
160159
match = iface;
161160
break;
162161
}
@@ -214,8 +213,7 @@ int prism2_wds_del(local_info_t *local, u8 *remote_addr,
214213
if (iface->type != HOSTAP_INTERFACE_WDS)
215214
continue;
216215

217-
if (memcmp(iface->u.wds.remote_addr, remote_addr,
218-
ETH_ALEN) == 0) {
216+
if (ether_addr_equal(iface->u.wds.remote_addr, remote_addr)) {
219217
selected = iface;
220218
break;
221219
}
@@ -1085,7 +1083,7 @@ int prism2_sta_deauth(local_info_t *local, u16 reason)
10851083

10861084
if (local->iw_mode != IW_MODE_INFRA ||
10871085
is_zero_ether_addr(local->bssid) ||
1088-
memcmp(local->bssid, "\x44\x44\x44\x44\x44\x44", ETH_ALEN) == 0)
1086+
ether_addr_equal(local->bssid, "\x44\x44\x44\x44\x44\x44"))
10891087
return 0;
10901088

10911089
ret = prism2_sta_send_mgmt(local, local->bssid, IEEE80211_STYPE_DEAUTH,

0 commit comments

Comments
 (0)