]> err.no Git - linux-2.6/blobdiff - net/mac80211/sta_info.c
the scheduled ieee80211 softmac removal
[linux-2.6] / net / mac80211 / sta_info.c
index a767042ec4fd19130575cd3a32ff83e0c3053424..3b84c16cf0544cb13c1f72b884d570b866ee5456 100644 (file)
  * for faster lookup and a list for iteration. They are managed using
  * RCU, i.e. access to the list and hash table is protected by RCU.
  *
- * Upon allocating a STA info structure with @sta_info_alloc() or
- * mesh_plink_alloc(), the caller owns that structure. It must then either
- * destroy it using @sta_info_destroy() (which is pretty useless) or insert
- * it into the hash table using @sta_info_insert() which demotes the reference
- * from ownership to a regular RCU-protected reference; if the function
- * is called without protection by an RCU critical section the reference
- * is instantly invalidated.
+ * Upon allocating a STA info structure with sta_info_alloc(), the caller owns
+ * that structure. It must then either destroy it using sta_info_destroy()
+ * (which is pretty useless) or insert it into the hash table using
+ * sta_info_insert() which demotes the reference from ownership to a regular
+ * RCU-protected reference; if the function is called without protection by an
+ * RCU critical section the reference is instantly invalidated.
  *
  * Because there are debugfs entries for each station, and adding those
  * must be able to sleep, it is also possible to "pin" a station entry,
  * that means it can be removed from the hash table but not be freed.
- * See the comment in @__sta_info_unlink() for more information.
+ * See the comment in __sta_info_unlink() for more information.
  *
  * In order to remove a STA info structure, the caller needs to first
- * unlink it (@sta_info_unlink()) from the list and hash tables and
+ * unlink it (sta_info_unlink()) from the list and hash tables and
  * then wait for an RCU synchronisation before it can be freed. Due to
  * the pinning and the possibility of multiple callers trying to remove
- * the same STA info at the same time, @sta_info_unlink() can clear the
+ * the same STA info at the same time, sta_info_unlink() can clear the
  * STA info pointer it is passed to indicate that the STA info is owned
  * by somebody else now.
  *
- * If @sta_info_unlink() did not clear the pointer then the caller owns
+ * If sta_info_unlink() did not clear the pointer then the caller owns
  * the STA info structure now and is responsible of destroying it with
- * a call to @sta_info_destroy(), not before RCU synchronisation, of
+ * a call to sta_info_destroy(), not before RCU synchronisation, of
  * course. Note that sta_info_destroy() must be protected by the RTNL.
  *
  * In all other cases, there is no concept of ownership on a STA entry,
@@ -116,12 +115,13 @@ struct sta_info *sta_info_get_by_idx(struct ieee80211_local *local, int idx,
        int i = 0;
 
        list_for_each_entry_rcu(sta, &local->sta_list, list) {
+               if (dev && dev != sta->sdata->dev)
+                       continue;
                if (i < idx) {
                        ++i;
                        continue;
-               } else if (!dev || dev == sta->sdata->dev) {
-                       return sta;
                }
+               return sta;
        }
 
        return NULL;
@@ -248,6 +248,12 @@ struct sta_info *sta_info_alloc(struct ieee80211_sub_if_data *sdata,
               wiphy_name(local->hw.wiphy), print_mac(mbuf, sta->addr));
 #endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
 
+#ifdef CONFIG_MAC80211_MESH
+       sta->plink_state = PLINK_LISTEN;
+       spin_lock_init(&sta->plink_lock);
+       init_timer(&sta->plink_timer);
+#endif
+
        return sta;
 }
 
@@ -258,7 +264,19 @@ int sta_info_insert(struct sta_info *sta)
        unsigned long flags;
        DECLARE_MAC_BUF(mac);
 
-       WARN_ON(!netif_running(sdata->dev));
+       /*
+        * Can't be a WARN_ON because it can be triggered through a race:
+        * something inserts a STA (on one CPU) without holding the RTNL
+        * and another CPU turns off the net device.
+        */
+       if (unlikely(!netif_running(sdata->dev)))
+               return -ENETDOWN;
+
+       if (WARN_ON(compare_ether_addr(sta->addr, sdata->dev->dev_addr) == 0))
+               return -EINVAL;
+
+       if (WARN_ON(is_multicast_ether_addr(sta->addr)))
+               return -EINVAL;
 
        spin_lock_irqsave(&local->sta_lock, flags);
        /* check if STA exists already */