1 --- a/net80211/ieee80211_node.c
2 +++ b/net80211/ieee80211_node.c
3 @@ -123,6 +123,9 @@ static void ieee80211_node_table_cleanup
4 static void ieee80211_node_table_reset(struct ieee80211_node_table *,
5 struct ieee80211vap *);
7 +static struct ieee80211_node *
8 +lookup_rxnode(struct ieee80211com *ic, struct ieee80211vap *vap, const u_int8_t *addr);
10 MALLOC_DEFINE(M_80211_NODE, "80211node", "802.11 node state");
13 @@ -697,7 +700,7 @@ ieee80211_sta_join(struct ieee80211vap *
14 struct ieee80211com *ic = vap->iv_ic;
15 struct ieee80211_node *ni;
17 - ni = ieee80211_find_node(&ic->ic_sta, se->se_macaddr);
18 + ni = lookup_rxnode(ic, vap, se->se_macaddr);
20 ni = ieee80211_alloc_node_table(vap, se->se_macaddr);
21 IEEE80211_DPRINTF(vap, IEEE80211_MSG_ASSOC,
22 @@ -1391,6 +1394,53 @@ ieee80211_add_neighbor(struct ieee80211v
26 +struct ieee80211vap *
27 +ieee80211_find_rxvap(struct ieee80211com *ic, const u_int8_t *mac)
29 + struct ieee80211vap *vap;
31 + TAILQ_FOREACH(vap, &ic->ic_vaps, iv_next) {
32 + if (IEEE80211_ADDR_EQ(vap->iv_myaddr, mac))
37 +EXPORT_SYMBOL(ieee80211_find_rxvap);
39 +static struct ieee80211_node *
40 +lookup_rxnode(struct ieee80211com *ic, struct ieee80211vap *vap,
41 + const u_int8_t *addr)
43 + struct ieee80211_node_table *nt;
44 + struct ieee80211_node *ni = NULL;
49 + IEEE80211_NODE_TABLE_LOCK_IRQ(nt);
50 + hash = IEEE80211_NODE_HASH(addr);
51 + LIST_FOREACH(ni, &nt->nt_hash[hash], ni_hash) {
52 + if (IEEE80211_ADDR_EQ(ni->ni_macaddr, addr)) {
53 + /* allow multiple nodes on different vaps */
54 + if (vap && (ni->ni_vap != vap))
57 + ieee80211_ref_node(ni);
62 + /* no match found */
66 + IEEE80211_NODE_TABLE_UNLOCK_IRQ(nt);
74 * Return the node for the sender of a frame; if the sender is unknown return
75 * NULL. The caller is expected to deal with this. (The frame is sent to all
76 @@ -1400,10 +1450,10 @@ ieee80211_add_neighbor(struct ieee80211v
78 struct ieee80211_node *
79 #ifdef IEEE80211_DEBUG_REFCNT
80 -ieee80211_find_rxnode_debug(struct ieee80211com *ic,
81 +ieee80211_find_rxnode_debug(struct ieee80211com *ic, struct ieee80211vap *vap,
82 const struct ieee80211_frame_min *wh, const char *func, int line)
84 -ieee80211_find_rxnode(struct ieee80211com *ic,
85 +ieee80211_find_rxnode(struct ieee80211com *ic, struct ieee80211vap *vap,
86 const struct ieee80211_frame_min *wh)
89 @@ -1411,9 +1461,8 @@ ieee80211_find_rxnode(struct ieee80211co
90 ((wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK) == IEEE80211_FC0_TYPE_CTL)
91 #define IS_PSPOLL(wh) \
92 ((wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK) == IEEE80211_FC0_SUBTYPE_PS_POLL)
93 - struct ieee80211_node_table *nt;
94 - struct ieee80211_node *ni;
95 - struct ieee80211vap *vap, *avp;
96 + struct ieee80211_node *ni = NULL;
97 + struct ieee80211vap *avp;
100 if (IS_CTL(wh) && !IS_PSPOLL(wh) /*&& !IS_RTS(ah)*/)
101 @@ -1426,32 +1475,24 @@ ieee80211_find_rxnode(struct ieee80211co
103 /* XXX check ic_bss first in station mode */
104 /* XXX 4-address frames? */
106 - IEEE80211_NODE_TABLE_LOCK_IRQ(nt);
107 if ((wh->i_fc[1] & IEEE80211_FC1_DIR_MASK) == IEEE80211_FC1_DIR_DSTODS) {
108 - TAILQ_FOREACH(vap, &ic->ic_vaps, iv_next) {
109 + if (vap) { /* assume unicast if vap is set, mcast not supported for wds */
110 TAILQ_FOREACH(avp, &vap->iv_wdslinks, iv_wdsnext) {
111 - if (!IEEE80211_ADDR_EQ(addr, avp->wds_mac))
112 + if (!IEEE80211_ADDR_EQ(addr, avp->wds_mac) ||
113 + !IEEE80211_ADDR_EQ(wh->i_addr1, avp->iv_myaddr))
117 - return ieee80211_ref_node(avp->iv_wdsnode);
120 + ni = ieee80211_ref_node(avp->iv_wdsnode);
122 + if (!(vap->iv_flags_ext & IEEE80211_FEXT_WDS))
129 -#ifdef IEEE80211_DEBUG_REFCNT
130 - ni = ieee80211_find_node_locked_debug(nt, addr, func, line);
132 - ni = ieee80211_find_node_locked(nt, addr);
134 - IEEE80211_NODE_TABLE_UNLOCK_IRQ(nt);
139 + return lookup_rxnode(ic, vap, addr);
141 #ifdef IEEE80211_DEBUG_REFCNT
142 EXPORT_SYMBOL(ieee80211_find_rxnode_debug);
143 @@ -1476,15 +1517,14 @@ ieee80211_find_txnode(struct ieee80211va
144 struct ieee80211com *ic = vap->iv_ic;
145 struct ieee80211_node_table *nt;
146 struct ieee80211_node *ni = NULL;
149 - IEEE80211_LOCK_IRQ(ic);
150 if (vap->iv_opmode == IEEE80211_M_WDS) {
151 if (vap->iv_wdsnode && (vap->iv_state == IEEE80211_S_RUN))
152 return ieee80211_ref_node(vap->iv_wdsnode);
156 - IEEE80211_UNLOCK_IRQ(ic);
159 * The destination address should be in the node table
160 @@ -1502,11 +1542,22 @@ ieee80211_find_txnode(struct ieee80211va
161 /* XXX: Can't hold lock across dup_bss due to recursive locking. */
162 nt = &vap->iv_ic->ic_sta;
163 IEEE80211_NODE_TABLE_LOCK_IRQ(nt);
164 + hash = IEEE80211_NODE_HASH(mac);
165 + LIST_FOREACH(ni, &nt->nt_hash[hash], ni_hash) {
166 + if (ni->ni_vap != vap)
169 + if (IEEE80211_ADDR_EQ(ni->ni_macaddr, mac)) {
170 #ifdef IEEE80211_DEBUG_REFCNT
171 - ni = ieee80211_find_node_locked_debug(nt, mac, func, line);
172 + ieee80211_ref_node_debug(ni, func, line);
174 - ni = ieee80211_find_node_locked(nt, mac);
175 + ieee80211_ref_node(ni);
182 IEEE80211_NODE_TABLE_UNLOCK_IRQ(nt);
185 @@ -1961,13 +2012,29 @@ remove_worse_nodes(void *arg, struct iee
190 +remove_duplicate_nodes(void *arg, struct ieee80211_node *ni)
192 + struct ieee80211_node *rni = arg;
197 + if (ni->ni_vap == rni->ni_vap)
200 + ieee80211_node_leave(ni);
204 ieee80211_node_join(struct ieee80211_node *ni, int resp)
206 struct ieee80211com *ic = ni->ni_ic;
207 struct ieee80211vap *vap = ni->ni_vap;
208 + struct ieee80211_node *tni;
211 + ieee80211_iterate_nodes(&ic->ic_sta, remove_duplicate_nodes, ni);
212 if (ni->ni_associd == 0) {
215 --- a/net80211/ieee80211_input.c
216 +++ b/net80211/ieee80211_input.c
217 @@ -216,16 +216,14 @@ ieee80211_input(struct ieee80211vap * va
219 type = -1; /* undefined */
223 + if (!vap || !vap->iv_bss || !vap->iv_dev || !vap->iv_ic)
234 + if ((vap->iv_dev->flags & (IFF_UP|IFF_RUNNING)) != (IFF_UP|IFF_RUNNING))
237 /* initialize ni as in the previous API */
238 if (ni_or_null == NULL) {
239 @@ -233,9 +231,10 @@ ieee80211_input(struct ieee80211vap * va
240 * guarantee its existence during the following call, hence
241 * briefly grab our own reference. */
242 ni = ieee80211_ref_node(vap->iv_bss);
243 + KASSERT(ni != NULL, ("null node"));
245 + ni->ni_inact = ni->ni_inact_reload;
247 - KASSERT(ni != NULL, ("null node"));
248 - ni->ni_inact = ni->ni_inact_reload;
250 KASSERT(skb->len >= sizeof(struct ieee80211_frame_min),
251 ("frame length too short: %u", skb->len));
252 @@ -848,10 +847,11 @@ ieee80211_input(struct ieee80211vap * va
254 vap->iv_devstats.rx_errors++;
257 - ieee80211_dev_kfree_skb(&skb);
258 if (ni_or_null == NULL)
259 ieee80211_unref_node(&ni);
262 + ieee80211_dev_kfree_skb(&skb);
266 @@ -933,16 +933,23 @@ int
267 ieee80211_input_all(struct ieee80211com *ic,
268 struct sk_buff *skb, int rssi, u_int64_t rtsf)
270 + struct ieee80211_frame_min *wh = (struct ieee80211_frame_min *) skb->data;
271 struct ieee80211vap *vap;
275 TAILQ_FOREACH(vap, &ic->ic_vaps, iv_next) {
276 + struct ieee80211_node *ni = NULL;
277 struct sk_buff *skb1;
279 if ((vap->iv_dev->flags & (IFF_UP|IFF_RUNNING)) != (IFF_UP|IFF_RUNNING))
282 + if ((vap->iv_opmode == IEEE80211_M_HOSTAP) &&
283 + !IEEE80211_IS_MULTICAST(wh->i_addr1))
286 + ni = ieee80211_find_rxnode(ic, vap, wh);
287 if (TAILQ_NEXT(vap, iv_next) != NULL) {
288 skb1 = skb_copy(skb, GFP_ATOMIC);
290 @@ -954,8 +961,10 @@ ieee80211_input_all(struct ieee80211com
294 - type = ieee80211_input(vap, NULL, skb1, rssi, rtsf);
295 + type = ieee80211_input(vap, ni, skb1, rssi, rtsf);
299 if (skb != NULL) /* no vaps, reclaim skb */
300 ieee80211_dev_kfree_skb(&skb);
302 @@ -1146,11 +1155,9 @@ ieee80211_deliver_data(struct ieee80211_
303 * sending it will not work; just let it be
304 * delivered normally.
306 - struct ieee80211_node *ni1 = ieee80211_find_node(
307 - &vap->iv_ic->ic_sta, eh->ether_dhost);
308 + struct ieee80211_node *ni1 = ieee80211_find_txnode(vap, eh->ether_dhost);
310 - if (ni1->ni_vap == vap &&
311 - ieee80211_node_is_authorized(ni1) &&
312 + if (ieee80211_node_is_authorized(ni1) &&
314 ni1 != vap->iv_bss) {
318 @@ -6577,9 +6577,8 @@ ath_recv_mgmt(struct ieee80211vap * vap,
320 sc->sc_recv_mgmt(vap, ni_or_null, skb, subtype, rssi, rtsf);
323 /* Lookup the new node if any (this grabs a reference to it) */
324 - ni = ieee80211_find_rxnode(vap->iv_ic,
325 + ni = ieee80211_find_rxnode(vap->iv_ic, vap,
326 (const struct ieee80211_frame_min *)skb->data);
328 DPRINTF(sc, ATH_DEBUG_BEACON, "Dropping; node unknown.\n");
329 @@ -6734,7 +6733,9 @@ ath_rx_poll(struct net_device *dev, int
331 struct ath_rx_status *rs;
332 struct sk_buff *skb = NULL;
333 + struct ieee80211vap *vap;
334 struct ieee80211_node *ni;
335 + const struct ieee80211_frame_min *wh;
339 @@ -6889,12 +6890,15 @@ rx_accept:
340 skb_trim(skb, skb->len - IEEE80211_CRC_LEN);
343 + wh = (const struct ieee80211_frame_min *) skb->data;
345 /* Ignore control frames which are reported with mic error */
346 - if ((((struct ieee80211_frame *)skb->data)->i_fc[0] &
348 IEEE80211_FC0_TYPE_MASK) == IEEE80211_FC0_TYPE_CTL)
351 - ni = ieee80211_find_rxnode(ic, (const struct ieee80211_frame_min *) skb->data);
352 + vap = ieee80211_find_rxvap(ic, wh->i_addr1);
353 + ni = ieee80211_find_rxnode(ic, vap, wh);
355 if (ni && ni->ni_table) {
356 ieee80211_check_mic(ni, skb);
357 @@ -6956,11 +6960,24 @@ drop_micfail:
358 * for its use. If the sender is unknown spam the
359 * frame; it'll be dropped where it's not wanted.
361 - if (rs->rs_keyix != HAL_RXKEYIX_INVALID &&
362 + wh = (const struct ieee80211_frame_min *) skb->data;
363 + if ((rs->rs_keyix != HAL_RXKEYIX_INVALID) &&
364 (ni = sc->sc_keyixmap[rs->rs_keyix]) != NULL) {
365 /* Fast path: node is present in the key map;
366 * grab a reference for processing the frame. */
367 - ni = ieee80211_ref_node(ni);
368 + ieee80211_ref_node(ni);
369 + if ((ATH_GET_VAP_ID(wh->i_addr1) !=
370 + ATH_GET_VAP_ID(ni->ni_vap->iv_myaddr)) ||
371 + ((wh->i_fc[1] & IEEE80211_FC1_DIR_MASK) ==
372 + IEEE80211_FC1_DIR_DSTODS)) {
373 + /* key cache node lookup is fast, but it can
374 + * lead to problems in multi-bss (foreign vap
375 + * node reference) or wds (wdsap node ref instead
376 + * of base ap node ref).
377 + * use slowpath lookup in both cases
379 + goto lookup_slowpath;
381 ATH_RSSI_LPF(ATH_NODE(ni)->an_avgrssi, rs->rs_rssi);
382 type = ieee80211_input(ni->ni_vap, ni, skb, rs->rs_rssi, bf->bf_tsf);
383 ieee80211_unref_node(&ni);
384 @@ -6969,24 +6986,35 @@ drop_micfail:
385 * No key index or no entry, do a lookup and
386 * add the node to the mapping table if possible.
388 - ni = ieee80211_find_rxnode(ic,
389 - (const struct ieee80211_frame_min *)skb->data);
392 + vap = ieee80211_find_rxvap(ic, wh->i_addr1);
394 + ni = ieee80211_find_rxnode(ic, vap, wh);
399 ieee80211_keyix_t keyix;
401 ATH_RSSI_LPF(ATH_NODE(ni)->an_avgrssi, rs->rs_rssi);
402 - type = ieee80211_input(ni->ni_vap, ni, skb, rs->rs_rssi, bf->bf_tsf);
403 + type = ieee80211_input(vap, ni, skb, rs->rs_rssi, bf->bf_tsf);
405 * If the station has a key cache slot assigned
406 * update the key->node mapping table.
408 keyix = ni->ni_ucastkey.wk_keyix;
409 if (keyix != IEEE80211_KEYIX_NONE &&
410 - sc->sc_keyixmap[keyix] == NULL)
411 + sc->sc_keyixmap[keyix] == NULL) {
412 sc->sc_keyixmap[keyix] = ieee80211_ref_node(ni);
414 ieee80211_unref_node(&ni);
416 - type = ieee80211_input_all(ic, skb, rs->rs_rssi, bf->bf_tsf);
419 + type = ieee80211_input(vap, NULL, skb, rs->rs_rssi, bf->bf_tsf);
421 + type = ieee80211_input_all(ic, skb, rs->rs_rssi, bf->bf_tsf);
425 if (sc->sc_diversity) {
426 --- a/net80211/ieee80211_node.h
427 +++ b/net80211/ieee80211_node.h
428 @@ -286,15 +286,18 @@ struct ieee80211_node *ieee80211_find_no
430 #endif /* #ifdef IEEE80211_DEBUG_REFCNT */
432 +struct ieee80211vap *
433 +ieee80211_find_rxvap(struct ieee80211com *ic, const u_int8_t *mac);
435 /* Returns a ieee80211_node* with refcount incremented, if found */
436 #ifdef IEEE80211_DEBUG_REFCNT
437 -#define ieee80211_find_rxnode(_nt, _wh) \
438 - ieee80211_find_rxnode_debug(_nt, _wh, __func__, __LINE__)
439 +#define ieee80211_find_rxnode(_nt, _vap, _wh) \
440 + ieee80211_find_rxnode_debug(_nt, _vap, _wh, __func__, __LINE__)
441 struct ieee80211_node *ieee80211_find_rxnode_debug(struct ieee80211com *,
442 - const struct ieee80211_frame_min *, const char *, int);
443 + struct ieee80211vap *, const struct ieee80211_frame_min *, const char *, int);
445 struct ieee80211_node *ieee80211_find_rxnode(struct ieee80211com *,
446 - const struct ieee80211_frame_min *);
447 + struct ieee80211vap *, const struct ieee80211_frame_min *);
448 #endif /* #ifdef IEEE80211_DEBUG_REFCNT */
450 /* Returns a ieee80211_node* with refcount incremented, if found */