madwifi: add back a missing part of the mbss vap refactoring
[oweals/openwrt.git] / package / madwifi / patches / 393-mbss_vap_auth.patch
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 *);
6  
7 +static struct ieee80211_node *
8 +lookup_rxnode(struct ieee80211com *ic, struct ieee80211vap *vap, const u_int8_t *addr);
9 +
10  MALLOC_DEFINE(M_80211_NODE, "80211node", "802.11 node state");
11  
12  void
13 @@ -697,7 +700,7 @@ ieee80211_sta_join(struct ieee80211vap *
14         struct ieee80211com *ic = vap->iv_ic;
15         struct ieee80211_node *ni;
16  
17 -       ni = ieee80211_find_node(&ic->ic_sta, se->se_macaddr);
18 +       ni = lookup_rxnode(ic, vap, se->se_macaddr);
19         if (ni == NULL) {
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
23         return ni;
24  }
25  
26 +struct ieee80211vap *
27 +ieee80211_find_rxvap(struct ieee80211com *ic, const u_int8_t *mac)
28 +{
29 +       struct ieee80211vap *vap;
30 +
31 +       TAILQ_FOREACH(vap, &ic->ic_vaps, iv_next) {
32 +               if (IEEE80211_ADDR_EQ(vap->iv_myaddr, mac))
33 +                       return vap;
34 +       }
35 +       return NULL;
36 +}
37 +EXPORT_SYMBOL(ieee80211_find_rxvap);
38 +
39 +static struct ieee80211_node *
40 +lookup_rxnode(struct ieee80211com *ic, struct ieee80211vap *vap,
41 +       const u_int8_t *addr)
42 +{
43 +       struct ieee80211_node_table *nt;
44 +       struct ieee80211_node *ni = NULL;
45 +       int use_bss = 0;
46 +       int hash;
47 +
48 +       nt = &ic->ic_sta;
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))
55 +                               continue;
56 +
57 +                       ieee80211_ref_node(ni);
58 +                       goto out;
59 +               }
60 +       }
61 +
62 +       /* no match found */
63 +       ni = NULL;
64 +
65 +out:
66 +       IEEE80211_NODE_TABLE_UNLOCK_IRQ(nt);
67 +       return ni;
68 +#undef IS_PSPOLL
69 +#undef IS_CTL
70 +}
71 +
72 +
73  /*
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
77   */
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)
83  #else
84 -ieee80211_find_rxnode(struct ieee80211com *ic,
85 +ieee80211_find_rxnode(struct ieee80211com *ic, struct ieee80211vap *vap,
86         const struct ieee80211_frame_min *wh)
87  #endif
88  {
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;
98         const u_int8_t *addr;
99  
100         if (IS_CTL(wh) && !IS_PSPOLL(wh) /*&& !IS_RTS(ah)*/)
101 @@ -1426,32 +1475,24 @@ ieee80211_find_rxnode(struct ieee80211co
102  
103         /* XXX check ic_bss first in station mode */
104         /* XXX 4-address frames? */
105 -       nt = &ic->ic_sta;
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))
114                                         continue;
115  
116                                 if (avp->iv_wdsnode)
117 -                                       return ieee80211_ref_node(avp->iv_wdsnode);
118 -                               else
119 -                                       return NULL;
120 +                                       ni = ieee80211_ref_node(avp->iv_wdsnode);
121                         }
122 +                       if (!(vap->iv_flags_ext & IEEE80211_FEXT_WDS))
123 +                               return NULL;
124 +               } else {
125 +                       return NULL;
126                 }
127         }
128  
129 -#ifdef IEEE80211_DEBUG_REFCNT
130 -       ni = ieee80211_find_node_locked_debug(nt, addr, func, line);
131 -#else
132 -       ni = ieee80211_find_node_locked(nt, addr);
133 -#endif
134 -       IEEE80211_NODE_TABLE_UNLOCK_IRQ(nt);
135 -
136 -       return ni;
137 -#undef IS_PSPOLL
138 -#undef IS_CTL
139 +       return lookup_rxnode(ic, vap, addr);
140  }
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;
147 +       int hash;
148  
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);
153                 else
154                         return NULL;
155         }
156 -       IEEE80211_UNLOCK_IRQ(ic);
157  
158         /*
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)
167 +                       continue;
168 +
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);
173  #else
174 -       ni = ieee80211_find_node_locked(nt, mac);
175 +                       ieee80211_ref_node(ni);
176  #endif
177 +                       goto found;
178 +               }
179 +       }
180 +       ni = NULL;
181 +found:
182         IEEE80211_NODE_TABLE_UNLOCK_IRQ(nt);
183  
184         if (ni == NULL) {
185 @@ -1961,13 +2012,32 @@ remove_worse_nodes(void *arg, struct iee
186                 }
187  }
188  
189 +static void
190 +remove_duplicate_nodes(void *arg, struct ieee80211_node *ni)
191 +{
192 +       struct ieee80211_node *rni = arg;
193 +
194 +       if (ni == rni)
195 +               return;
196 +
197 +       if (ni->ni_vap == rni->ni_vap)
198 +               return;
199 +
200 +       if (!IEEE80211_ADDR_EQ(rni->ni_macaddr, ni->ni_macaddr))
201 +               return;
202 +
203 +       ieee80211_node_leave(ni);
204 +}
205 +
206  void
207  ieee80211_node_join(struct ieee80211_node *ni, int resp)
208  {
209         struct ieee80211com *ic = ni->ni_ic;
210         struct ieee80211vap *vap = ni->ni_vap;
211 +       struct ieee80211_node *tni;
212         int newassoc;
213  
214 +       ieee80211_iterate_nodes(&ic->ic_sta, remove_duplicate_nodes, ni);
215         if (ni->ni_associd == 0) {
216                 u_int16_t aid;
217  
218 --- a/net80211/ieee80211_input.c
219 +++ b/net80211/ieee80211_input.c
220 @@ -216,16 +216,14 @@ ieee80211_input(struct ieee80211vap * va
221  
222         type = -1;                      /* undefined */
223  
224 -       if (!vap)
225 -               goto out;
226 +       if (!vap || !vap->iv_bss || !vap->iv_dev || !vap->iv_ic)
227 +               goto discard;
228  
229         ic = vap->iv_ic;
230 -       if (!ic)
231 -               goto out;
232 -
233         dev = vap->iv_dev;
234 -       if (!dev)
235 -               goto out;
236 +
237 +       if ((vap->iv_dev->flags & (IFF_UP|IFF_RUNNING)) != (IFF_UP|IFF_RUNNING))
238 +               goto discard;
239  
240         /* initialize ni as in the previous API */
241         if (ni_or_null == NULL) {
242 @@ -233,9 +231,10 @@ ieee80211_input(struct ieee80211vap * va
243                  * guarantee its existence during the following call, hence
244                  * briefly grab our own reference. */
245                 ni = ieee80211_ref_node(vap->iv_bss);
246 +               KASSERT(ni != NULL, ("null node"));
247 +       } else {
248 +               ni->ni_inact = ni->ni_inact_reload;
249         }
250 -       KASSERT(ni != NULL, ("null node"));
251 -       ni->ni_inact = ni->ni_inact_reload;
252  
253         KASSERT(skb->len >= sizeof(struct ieee80211_frame_min),
254                 ("frame length too short: %u", skb->len));
255 @@ -844,10 +843,11 @@ ieee80211_input(struct ieee80211vap * va
256  err:
257         vap->iv_devstats.rx_errors++;
258  out:
259 -       if (skb != NULL)
260 -               ieee80211_dev_kfree_skb(&skb);
261         if (ni_or_null == NULL)
262                 ieee80211_unref_node(&ni);
263 +discard:
264 +       if (skb != NULL)
265 +               ieee80211_dev_kfree_skb(&skb);
266         return type;
267  #undef HAS_SEQ
268  }
269 @@ -929,16 +929,23 @@ int
270  ieee80211_input_all(struct ieee80211com *ic,
271         struct sk_buff *skb, int rssi, u_int64_t rtsf)
272  {
273 +       struct ieee80211_frame_min *wh = (struct ieee80211_frame_min *) skb->data;
274         struct ieee80211vap *vap;
275         int type = -1;
276  
277         /* XXX locking */
278         TAILQ_FOREACH(vap, &ic->ic_vaps, iv_next) {
279 +               struct ieee80211_node *ni = NULL;
280                 struct sk_buff *skb1;
281  
282                 if ((vap->iv_dev->flags & (IFF_UP|IFF_RUNNING)) != (IFF_UP|IFF_RUNNING))
283                         continue;
284  
285 +               if ((vap->iv_opmode == IEEE80211_M_HOSTAP) &&
286 +                       !IEEE80211_IS_MULTICAST(wh->i_addr1))
287 +                       continue;
288 +
289 +               ni = ieee80211_find_rxnode(ic, vap, wh);
290                 if (TAILQ_NEXT(vap, iv_next) != NULL) {
291                         skb1 = skb_copy(skb, GFP_ATOMIC);
292                         if (skb1 == NULL) {
293 @@ -950,8 +957,10 @@ ieee80211_input_all(struct ieee80211com 
294                         skb1 = skb;
295                         skb = NULL;
296                 }
297 -               type = ieee80211_input(vap, NULL, skb1, rssi, rtsf);
298 +               type = ieee80211_input(vap, ni, skb1, rssi, rtsf);
299         }
300 +
301 +out:
302         if (skb != NULL)                /* no vaps, reclaim skb */
303                 ieee80211_dev_kfree_skb(&skb);
304         return type;
305 @@ -1146,11 +1155,9 @@ ieee80211_deliver_data(struct ieee80211_
306                          * sending it will not work; just let it be
307                          * delivered normally.
308                          */
309 -                       struct ieee80211_node *ni1 = ieee80211_find_node(
310 -                               &vap->iv_ic->ic_sta, eh->ether_dhost);
311 +                       struct ieee80211_node *ni1 = ieee80211_find_txnode(vap, eh->ether_dhost);
312                         if (ni1 != NULL) {
313 -                               if (ni1->ni_vap == vap &&
314 -                                   ieee80211_node_is_authorized(ni1) &&
315 +                               if (ieee80211_node_is_authorized(ni1) &&
316                                         !ni1->ni_subif &&
317                                     ni1 != vap->iv_bss) {
318  
319 --- a/ath/if_ath.c
320 +++ b/ath/if_ath.c
321 @@ -6578,9 +6578,8 @@ ath_recv_mgmt(struct ieee80211vap * vap,
322  
323         sc->sc_recv_mgmt(vap, ni_or_null, skb, subtype, rssi, rtsf);
324  
325 -
326         /* Lookup the new node if any (this grabs a reference to it) */
327 -       ni = ieee80211_find_rxnode(vap->iv_ic,
328 +       ni = ieee80211_find_rxnode(vap->iv_ic, vap,
329                  (const struct ieee80211_frame_min *)skb->data);
330         if (ni == NULL) {
331                 DPRINTF(sc, ATH_DEBUG_BEACON, "Dropping; node unknown.\n");
332 @@ -6735,7 +6734,9 @@ ath_rx_poll(struct net_device *dev, int 
333         struct ath_desc *ds;
334         struct ath_rx_status *rs;
335         struct sk_buff *skb = NULL;
336 +       struct ieee80211vap *vap;
337         struct ieee80211_node *ni;
338 +       const struct ieee80211_frame_min *wh;
339         unsigned int len;
340         int type;
341         u_int phyerr;
342 @@ -6890,12 +6891,15 @@ rx_accept:
343                 skb_trim(skb, skb->len - IEEE80211_CRC_LEN);
344  
345                 if (mic_fail) {
346 +                       wh = (const struct ieee80211_frame_min *) skb->data;
347 +
348                         /* Ignore control frames which are reported with mic error */
349 -                   if ((((struct ieee80211_frame *)skb->data)->i_fc[0] &
350 +                   if ((wh->i_fc[0] &
351                                         IEEE80211_FC0_TYPE_MASK) == IEEE80211_FC0_TYPE_CTL)
352                                 goto drop_micfail;
353  
354 -                       ni = ieee80211_find_rxnode(ic, (const struct ieee80211_frame_min *) skb->data);
355 +                       vap = ieee80211_find_rxvap(ic, wh->i_addr1);
356 +                       ni = ieee80211_find_rxnode(ic, vap, wh);
357  
358                         if (ni && ni->ni_table) {
359                                 ieee80211_check_mic(ni, skb);
360 @@ -6957,11 +6961,24 @@ drop_micfail:
361                  * for its use.  If the sender is unknown spam the
362                  * frame; it'll be dropped where it's not wanted.
363                  */
364 -               if (rs->rs_keyix != HAL_RXKEYIX_INVALID &&
365 +               wh = (const struct ieee80211_frame_min *) skb->data;
366 +               if ((rs->rs_keyix != HAL_RXKEYIX_INVALID) &&
367                     (ni = sc->sc_keyixmap[rs->rs_keyix]) != NULL) {
368                         /* Fast path: node is present in the key map;
369                          * grab a reference for processing the frame. */
370 -                       ni = ieee80211_ref_node(ni);
371 +                       ieee80211_ref_node(ni);
372 +                       if ((ATH_GET_VAP_ID(wh->i_addr1) !=
373 +                            ATH_GET_VAP_ID(ni->ni_vap->iv_myaddr)) ||
374 +                               ((wh->i_fc[1] & IEEE80211_FC1_DIR_MASK) ==
375 +                                IEEE80211_FC1_DIR_DSTODS)) {
376 +                               /* key cache node lookup is fast, but it can
377 +                                * lead to problems in multi-bss (foreign vap
378 +                                * node reference) or wds (wdsap node ref instead
379 +                                * of base ap node ref).
380 +                                * use slowpath lookup in both cases
381 +                                */
382 +                               goto lookup_slowpath;
383 +                       }
384                         ATH_RSSI_LPF(ATH_NODE(ni)->an_avgrssi, rs->rs_rssi);
385                         type = ieee80211_input(ni->ni_vap, ni, skb, rs->rs_rssi, bf->bf_tsf);
386                         ieee80211_unref_node(&ni);
387 @@ -6970,24 +6987,35 @@ drop_micfail:
388                          * No key index or no entry, do a lookup and
389                          * add the node to the mapping table if possible.
390                          */
391 -                       ni = ieee80211_find_rxnode(ic,
392 -                               (const struct ieee80211_frame_min *)skb->data);
393 +
394 +lookup_slowpath:
395 +                       vap = ieee80211_find_rxvap(ic, wh->i_addr1);
396 +                       if (vap)
397 +                               ni = ieee80211_find_rxnode(ic, vap, wh);
398 +                       else
399 +                               ni = NULL;
400 +
401                         if (ni != NULL) {
402                                 ieee80211_keyix_t keyix;
403  
404                                 ATH_RSSI_LPF(ATH_NODE(ni)->an_avgrssi, rs->rs_rssi);
405 -                               type = ieee80211_input(ni->ni_vap, ni, skb, rs->rs_rssi, bf->bf_tsf);
406 +                               type = ieee80211_input(vap, ni, skb, rs->rs_rssi, bf->bf_tsf);
407                                 /*
408                                  * If the station has a key cache slot assigned
409                                  * update the key->node mapping table.
410                                  */
411                                 keyix = ni->ni_ucastkey.wk_keyix;
412                                 if (keyix != IEEE80211_KEYIX_NONE &&
413 -                                   sc->sc_keyixmap[keyix] == NULL)
414 +                                   sc->sc_keyixmap[keyix] == NULL) {
415                                         sc->sc_keyixmap[keyix] = ieee80211_ref_node(ni);
416 +                               }
417                                 ieee80211_unref_node(&ni);
418 -                       } else
419 -                               type = ieee80211_input_all(ic, skb, rs->rs_rssi, bf->bf_tsf);
420 +                       } else {
421 +                               if (vap)
422 +                                       type = ieee80211_input(vap, NULL, skb, rs->rs_rssi, bf->bf_tsf);
423 +                               else
424 +                                       type = ieee80211_input_all(ic, skb, rs->rs_rssi, bf->bf_tsf);
425 +                       }
426                 }
427  
428                 if (sc->sc_diversity) {
429 --- a/net80211/ieee80211_node.h
430 +++ b/net80211/ieee80211_node.h
431 @@ -286,15 +286,18 @@ struct ieee80211_node *ieee80211_find_no
432         const u_int8_t *);
433  #endif /* #ifdef IEEE80211_DEBUG_REFCNT */
434  
435 +struct ieee80211vap *
436 +ieee80211_find_rxvap(struct ieee80211com *ic, const u_int8_t *mac);
437 +
438  /* Returns a ieee80211_node* with refcount incremented, if found */
439  #ifdef IEEE80211_DEBUG_REFCNT
440 -#define        ieee80211_find_rxnode(_nt, _wh) \
441 -       ieee80211_find_rxnode_debug(_nt, _wh, __func__, __LINE__)
442 +#define        ieee80211_find_rxnode(_nt, _vap, _wh) \
443 +       ieee80211_find_rxnode_debug(_nt, _vap, _wh, __func__, __LINE__)
444  struct ieee80211_node *ieee80211_find_rxnode_debug(struct ieee80211com *,
445 -       const struct ieee80211_frame_min *, const char *, int);
446 +       struct ieee80211vap *, const struct ieee80211_frame_min *, const char *, int);
447  #else
448  struct ieee80211_node *ieee80211_find_rxnode(struct ieee80211com *,
449 -       const struct ieee80211_frame_min *);
450 +       struct ieee80211vap *, const struct ieee80211_frame_min *);
451  #endif /* #ifdef IEEE80211_DEBUG_REFCNT */
452  
453  /* Returns a ieee80211_node* with refcount incremented, if found */