diff options
author | Damien Bergamini <damien@cvs.openbsd.org> | 2009-01-28 17:15:22 +0000 |
---|---|---|
committer | Damien Bergamini <damien@cvs.openbsd.org> | 2009-01-28 17:15:22 +0000 |
commit | fb3f10120ee99ec591063a1f25fb79f32c78cd01 (patch) | |
tree | 89bcc42e091bf850fefc0d233bcda89e47530023 | |
parent | 6b2c2b39f1604a9e6733df499ad0a07c98092f82 (diff) |
In ieee80211_find_node(), roll our own RB_FIND() based on the key (macaddr)
instead of resorting to horrid hacks/casts.
Restore the ieee80211_node structure back to its original state.
-rw-r--r-- | sys/net80211/ieee80211_node.c | 20 | ||||
-rw-r--r-- | sys/net80211/ieee80211_node.h | 12 |
2 files changed, 22 insertions, 10 deletions
diff --git a/sys/net80211/ieee80211_node.c b/sys/net80211/ieee80211_node.c index ff6ff062f7e..e034fd6e730 100644 --- a/sys/net80211/ieee80211_node.c +++ b/sys/net80211/ieee80211_node.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ieee80211_node.c,v 1.52 2009/01/27 17:02:29 damien Exp $ */ +/* $OpenBSD: ieee80211_node.c,v 1.53 2009/01/28 17:15:21 damien Exp $ */ /* $NetBSD: ieee80211_node.c,v 1.14 2004/05/09 09:18:47 dyoung Exp $ */ /*- @@ -812,9 +812,21 @@ ieee80211_dup_bss(struct ieee80211com *ic, const u_int8_t *macaddr) struct ieee80211_node * ieee80211_find_node(struct ieee80211com *ic, const u_int8_t *macaddr) { - /* XXX ugly, but avoids a full node structure in the stack */ - return (RB_FIND(ieee80211_tree, &ic->ic_tree, - (struct ieee80211_node *)macaddr)); + struct ieee80211_node *ni; + int cmp; + + /* similar to RB_FIND except we compare keys, not nodes */ + ni = RB_ROOT(&ic->ic_tree); + while (ni != NULL) { + cmp = memcmp(macaddr, ni->ni_macaddr, IEEE80211_ADDR_LEN); + if (cmp < 0) + ni = RB_LEFT(ni, ni_node); + else if (cmp > 0) + ni = RB_RIGHT(ni, ni_node); + else + break; + } + return ni; } /* diff --git a/sys/net80211/ieee80211_node.h b/sys/net80211/ieee80211_node.h index 0cf7a12a896..961ace16a8f 100644 --- a/sys/net80211/ieee80211_node.h +++ b/sys/net80211/ieee80211_node.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ieee80211_node.h,v 1.37 2009/01/26 21:55:58 damien Exp $ */ +/* $OpenBSD: ieee80211_node.h,v 1.38 2009/01/28 17:15:21 damien Exp $ */ /* $NetBSD: ieee80211_node.h,v 1.9 2004/04/30 22:57:32 dyoung Exp $ */ /*- @@ -137,9 +137,7 @@ struct ieee80211_ba { * the ieee80211com structure. */ struct ieee80211_node { - /* ni_macaddr must be the first field for RB_FIND() */ - u_int8_t ni_macaddr[IEEE80211_ADDR_LEN]; - u_int8_t ni_bssid[IEEE80211_ADDR_LEN]; + RB_ENTRY(ieee80211_node) ni_node; struct ieee80211com *ni_ic; /* back-pointer */ @@ -150,6 +148,10 @@ struct ieee80211_node { u_int32_t ni_rstamp; /* recv timestamp */ u_int8_t ni_rssi; /* recv ssi */ + /* header */ + u_int8_t ni_macaddr[IEEE80211_ADDR_LEN]; + u_int8_t ni_bssid[IEEE80211_ADDR_LEN]; + /* beacon, probe response */ u_int8_t ni_tstamp[8]; /* from last rcv'd beacon */ u_int16_t ni_intval; /* beacon interval */ @@ -237,8 +239,6 @@ struct ieee80211_node { #define IEEE80211_NODE_HT 0x0400 /* HT negotiated */ #define IEEE80211_NODE_SA_QUERY 0x0800 /* SA Query in progress */ #define IEEE80211_NODE_SA_QUERY_FAILED 0x1000 /* last SA Query failed */ - - RB_ENTRY(ieee80211_node) ni_node; }; RB_HEAD(ieee80211_tree, ieee80211_node); |