diff options
author | Johannes Berg <johannes@sipsolutions.net> | 2008-02-25 10:27:47 -0500 |
---|---|---|
committer | John W. Linville <linville@tuxdriver.com> | 2008-03-06 15:30:47 -0500 |
commit | 73651ee6396c499ccb59ebc84c9274db01ed026d (patch) | |
tree | 1d59027cbdaec732f3e1378770cbf7b42b48cd70 /net/mac80211 | |
parent | d0709a65181beb787ef3f58cfe45536a2bb254c8 (diff) |
mac80211: split sta_info_add
sta_info_add() has two functions: allocating a station info
structure and inserting it into the hash table/list. Splitting
these two functions allows allocating with GFP_KERNEL in many
places instead of GFP_ATOMIC which is now required by the RCU
protection. Additionally, in many places RCU protection is now
no longer needed at all because between sta_info_alloc() and
sta_info_insert() the caller owns the structure.
This fixes a few race conditions with setting initial flags
and similar, but not all (see comments in ieee80211_sta.c and
cfg.c). More documentation on the existing races will be in
a follow-up patch.
Signed-off-by: Johannes Berg <johannes@sipsolutions.net>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
Diffstat (limited to 'net/mac80211')
-rw-r--r-- | net/mac80211/cfg.c | 42 | ||||
-rw-r--r-- | net/mac80211/ieee80211.c | 18 | ||||
-rw-r--r-- | net/mac80211/ieee80211_sta.c | 44 | ||||
-rw-r--r-- | net/mac80211/mesh.h | 4 | ||||
-rw-r--r-- | net/mac80211/mesh_plink.c | 43 | ||||
-rw-r--r-- | net/mac80211/sta_info.c | 72 | ||||
-rw-r--r-- | net/mac80211/sta_info.h | 17 |
7 files changed, 166 insertions, 74 deletions
diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c index e9ba6fcc0e45..6263cfc148c0 100644 --- a/net/mac80211/cfg.c +++ b/net/mac80211/cfg.c | |||
@@ -571,6 +571,12 @@ static void sta_apply_parameters(struct ieee80211_local *local, | |||
571 | struct ieee80211_supported_band *sband; | 571 | struct ieee80211_supported_band *sband; |
572 | struct ieee80211_sub_if_data *sdata = sta->sdata; | 572 | struct ieee80211_sub_if_data *sdata = sta->sdata; |
573 | 573 | ||
574 | /* | ||
575 | * FIXME: updating the flags is racy when this function is | ||
576 | * called from ieee80211_change_station(), this will | ||
577 | * be resolved in a future patch. | ||
578 | */ | ||
579 | |||
574 | if (params->station_flags & STATION_FLAG_CHANGED) { | 580 | if (params->station_flags & STATION_FLAG_CHANGED) { |
575 | sta->flags &= ~WLAN_STA_AUTHORIZED; | 581 | sta->flags &= ~WLAN_STA_AUTHORIZED; |
576 | if (params->station_flags & STATION_FLAG_AUTHORIZED) | 582 | if (params->station_flags & STATION_FLAG_AUTHORIZED) |
@@ -585,6 +591,13 @@ static void sta_apply_parameters(struct ieee80211_local *local, | |||
585 | sta->flags |= WLAN_STA_WME; | 591 | sta->flags |= WLAN_STA_WME; |
586 | } | 592 | } |
587 | 593 | ||
594 | /* | ||
595 | * FIXME: updating the following information is racy when this | ||
596 | * function is called from ieee80211_change_station(). | ||
597 | * However, all this information should be static so | ||
598 | * maybe we should just reject attemps to change it. | ||
599 | */ | ||
600 | |||
588 | if (params->aid) { | 601 | if (params->aid) { |
589 | sta->aid = params->aid; | 602 | sta->aid = params->aid; |
590 | if (sta->aid > IEEE80211_MAX_AID) | 603 | if (sta->aid > IEEE80211_MAX_AID) |
@@ -626,6 +639,7 @@ static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev, | |||
626 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); | 639 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
627 | struct sta_info *sta; | 640 | struct sta_info *sta; |
628 | struct ieee80211_sub_if_data *sdata; | 641 | struct ieee80211_sub_if_data *sdata; |
642 | int err; | ||
629 | 643 | ||
630 | /* Prevent a race with changing the rate control algorithm */ | 644 | /* Prevent a race with changing the rate control algorithm */ |
631 | if (!netif_running(dev)) | 645 | if (!netif_running(dev)) |
@@ -641,16 +655,11 @@ static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev, | |||
641 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); | 655 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
642 | 656 | ||
643 | if (ieee80211_vif_is_mesh(&sdata->vif)) | 657 | if (ieee80211_vif_is_mesh(&sdata->vif)) |
644 | sta = mesh_plink_add(mac, DEFAULT_RATES, sdata); | 658 | sta = mesh_plink_alloc(sdata, mac, DEFAULT_RATES, GFP_KERNEL); |
645 | else | 659 | else |
646 | sta = sta_info_add(sdata, mac); | 660 | sta = sta_info_alloc(sdata, mac, GFP_KERNEL); |
647 | 661 | if (!sta) | |
648 | if (IS_ERR(sta)) | 662 | return -ENOMEM; |
649 | return PTR_ERR(sta); | ||
650 | |||
651 | if (sdata->vif.type == IEEE80211_IF_TYPE_VLAN || | ||
652 | sdata->vif.type == IEEE80211_IF_TYPE_AP) | ||
653 | ieee80211_send_layer2_update(sta); | ||
654 | 663 | ||
655 | sta->flags = WLAN_STA_AUTH | WLAN_STA_ASSOC; | 664 | sta->flags = WLAN_STA_AUTH | WLAN_STA_ASSOC; |
656 | 665 | ||
@@ -658,6 +667,21 @@ static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev, | |||
658 | 667 | ||
659 | rate_control_rate_init(sta, local); | 668 | rate_control_rate_init(sta, local); |
660 | 669 | ||
670 | rcu_read_lock(); | ||
671 | |||
672 | err = sta_info_insert(sta); | ||
673 | if (err) { | ||
674 | sta_info_destroy(sta); | ||
675 | rcu_read_unlock(); | ||
676 | return err; | ||
677 | } | ||
678 | |||
679 | if (sdata->vif.type == IEEE80211_IF_TYPE_VLAN || | ||
680 | sdata->vif.type == IEEE80211_IF_TYPE_AP) | ||
681 | ieee80211_send_layer2_update(sta); | ||
682 | |||
683 | rcu_read_unlock(); | ||
684 | |||
661 | return 0; | 685 | return 0; |
662 | } | 686 | } |
663 | 687 | ||
diff --git a/net/mac80211/ieee80211.c b/net/mac80211/ieee80211.c index 85b1391375c0..22cba82a0c6f 100644 --- a/net/mac80211/ieee80211.c +++ b/net/mac80211/ieee80211.c | |||
@@ -899,6 +899,7 @@ int ieee80211_if_update_wds(struct net_device *dev, u8 *remote_addr) | |||
899 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); | 899 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
900 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | 900 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
901 | struct sta_info *sta; | 901 | struct sta_info *sta; |
902 | int err; | ||
902 | DECLARE_MAC_BUF(mac); | 903 | DECLARE_MAC_BUF(mac); |
903 | 904 | ||
904 | might_sleep(); | 905 | might_sleep(); |
@@ -906,16 +907,19 @@ int ieee80211_if_update_wds(struct net_device *dev, u8 *remote_addr) | |||
906 | if (compare_ether_addr(remote_addr, sdata->u.wds.remote_addr) == 0) | 907 | if (compare_ether_addr(remote_addr, sdata->u.wds.remote_addr) == 0) |
907 | return 0; | 908 | return 0; |
908 | 909 | ||
909 | rcu_read_lock(); | ||
910 | |||
911 | /* Create STA entry for the new peer */ | 910 | /* Create STA entry for the new peer */ |
912 | sta = sta_info_add(sdata, remote_addr); | 911 | sta = sta_info_alloc(sdata, remote_addr, GFP_KERNEL); |
913 | if (IS_ERR(sta)) { | 912 | if (!sta) |
914 | rcu_read_unlock(); | 913 | return -ENOMEM; |
915 | return PTR_ERR(sta); | ||
916 | } | ||
917 | 914 | ||
918 | sta->flags |= WLAN_STA_AUTHORIZED; | 915 | sta->flags |= WLAN_STA_AUTHORIZED; |
916 | err = sta_info_insert(sta); | ||
917 | if (err) { | ||
918 | sta_info_destroy(sta); | ||
919 | return err; | ||
920 | } | ||
921 | |||
922 | rcu_read_lock(); | ||
919 | 923 | ||
920 | /* Remove STA entry for the old peer */ | 924 | /* Remove STA entry for the old peer */ |
921 | sta = sta_info_get(local, sdata->u.wds.remote_addr); | 925 | sta = sta_info_get(local, sdata->u.wds.remote_addr); |
diff --git a/net/mac80211/ieee80211_sta.c b/net/mac80211/ieee80211_sta.c index a3e96eb59eb0..892b5f96a427 100644 --- a/net/mac80211/ieee80211_sta.c +++ b/net/mac80211/ieee80211_sta.c | |||
@@ -1454,7 +1454,7 @@ void sta_addba_resp_timer_expired(unsigned long data) | |||
1454 | { | 1454 | { |
1455 | /* not an elegant detour, but there is no choice as the timer passes | 1455 | /* not an elegant detour, but there is no choice as the timer passes |
1456 | * only one argument, and both sta_info and TID are needed, so init | 1456 | * only one argument, and both sta_info and TID are needed, so init |
1457 | * flow in sta_info_add gives the TID as data, while the timer_to_id | 1457 | * flow in sta_info_create gives the TID as data, while the timer_to_id |
1458 | * array gives the sta through container_of */ | 1458 | * array gives the sta through container_of */ |
1459 | u16 tid = *(int *)data; | 1459 | u16 tid = *(int *)data; |
1460 | struct sta_info *temp_sta = container_of((void *)data, | 1460 | struct sta_info *temp_sta = container_of((void *)data, |
@@ -1505,7 +1505,7 @@ void sta_rx_agg_session_timer_expired(unsigned long data) | |||
1505 | { | 1505 | { |
1506 | /* not an elegant detour, but there is no choice as the timer passes | 1506 | /* not an elegant detour, but there is no choice as the timer passes |
1507 | * only one argument, and verious sta_info are needed here, so init | 1507 | * only one argument, and verious sta_info are needed here, so init |
1508 | * flow in sta_info_add gives the TID as data, while the timer_to_id | 1508 | * flow in sta_info_create gives the TID as data, while the timer_to_id |
1509 | * array gives the sta through container_of */ | 1509 | * array gives the sta through container_of */ |
1510 | u8 *ptid = (u8 *)data; | 1510 | u8 *ptid = (u8 *)data; |
1511 | u8 *timer_to_id = ptid - *ptid; | 1511 | u8 *timer_to_id = ptid - *ptid; |
@@ -1829,11 +1829,12 @@ static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata, | |||
1829 | sta = sta_info_get(local, ifsta->bssid); | 1829 | sta = sta_info_get(local, ifsta->bssid); |
1830 | if (!sta) { | 1830 | if (!sta) { |
1831 | struct ieee80211_sta_bss *bss; | 1831 | struct ieee80211_sta_bss *bss; |
1832 | int err; | ||
1832 | 1833 | ||
1833 | sta = sta_info_add(sdata, ifsta->bssid); | 1834 | sta = sta_info_alloc(sdata, ifsta->bssid, GFP_ATOMIC); |
1834 | if (IS_ERR(sta)) { | 1835 | if (!sta) { |
1835 | printk(KERN_DEBUG "%s: failed to add STA entry for the" | 1836 | printk(KERN_DEBUG "%s: failed to alloc STA entry for" |
1836 | " AP (error %ld)\n", dev->name, PTR_ERR(sta)); | 1837 | " the AP\n", dev->name); |
1837 | rcu_read_unlock(); | 1838 | rcu_read_unlock(); |
1838 | return; | 1839 | return; |
1839 | } | 1840 | } |
@@ -1846,8 +1847,27 @@ static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata, | |||
1846 | sta->last_noise = bss->noise; | 1847 | sta->last_noise = bss->noise; |
1847 | ieee80211_rx_bss_put(dev, bss); | 1848 | ieee80211_rx_bss_put(dev, bss); |
1848 | } | 1849 | } |
1850 | |||
1851 | err = sta_info_insert(sta); | ||
1852 | if (err) { | ||
1853 | printk(KERN_DEBUG "%s: failed to insert STA entry for" | ||
1854 | " the AP (error %d)\n", dev->name, err); | ||
1855 | sta_info_destroy(sta); | ||
1856 | rcu_read_unlock(); | ||
1857 | return; | ||
1858 | } | ||
1849 | } | 1859 | } |
1850 | 1860 | ||
1861 | /* | ||
1862 | * FIXME: Do we really need to update the sta_info's information here? | ||
1863 | * We already know about the AP (we found it in our list) so it | ||
1864 | * should already be filled with the right info, no? | ||
1865 | * As is stands, all this is racy because typically we assume | ||
1866 | * the information that is filled in here (except flags) doesn't | ||
1867 | * change while a STA structure is alive. As such, it should move | ||
1868 | * to between the sta_info_alloc() and sta_info_insert() above. | ||
1869 | */ | ||
1870 | |||
1851 | sta->flags |= WLAN_STA_AUTH | WLAN_STA_ASSOC | WLAN_STA_ASSOC_AP | | 1871 | sta->flags |= WLAN_STA_AUTH | WLAN_STA_ASSOC | WLAN_STA_ASSOC_AP | |
1852 | WLAN_STA_AUTHORIZED; | 1872 | WLAN_STA_AUTHORIZED; |
1853 | 1873 | ||
@@ -2588,10 +2608,8 @@ static void ieee80211_rx_bss_info(struct net_device *dev, | |||
2588 | "local TSF - IBSS merge with BSSID %s\n", | 2608 | "local TSF - IBSS merge with BSSID %s\n", |
2589 | dev->name, print_mac(mac, mgmt->bssid)); | 2609 | dev->name, print_mac(mac, mgmt->bssid)); |
2590 | ieee80211_sta_join_ibss(dev, &sdata->u.sta, bss); | 2610 | ieee80211_sta_join_ibss(dev, &sdata->u.sta, bss); |
2591 | rcu_read_lock(); | ||
2592 | ieee80211_ibss_add_sta(dev, NULL, | 2611 | ieee80211_ibss_add_sta(dev, NULL, |
2593 | mgmt->bssid, mgmt->sa); | 2612 | mgmt->bssid, mgmt->sa); |
2594 | rcu_read_unlock(); | ||
2595 | } | 2613 | } |
2596 | } | 2614 | } |
2597 | 2615 | ||
@@ -4023,7 +4041,6 @@ int ieee80211_sta_set_extra_ie(struct net_device *dev, char *ie, size_t len) | |||
4023 | } | 4041 | } |
4024 | 4042 | ||
4025 | 4043 | ||
4026 | /* must be called under RCU read lock */ | ||
4027 | struct sta_info * ieee80211_ibss_add_sta(struct net_device *dev, | 4044 | struct sta_info * ieee80211_ibss_add_sta(struct net_device *dev, |
4028 | struct sk_buff *skb, u8 *bssid, | 4045 | struct sk_buff *skb, u8 *bssid, |
4029 | u8 *addr) | 4046 | u8 *addr) |
@@ -4046,8 +4063,8 @@ struct sta_info * ieee80211_ibss_add_sta(struct net_device *dev, | |||
4046 | printk(KERN_DEBUG "%s: Adding new IBSS station %s (dev=%s)\n", | 4063 | printk(KERN_DEBUG "%s: Adding new IBSS station %s (dev=%s)\n", |
4047 | wiphy_name(local->hw.wiphy), print_mac(mac, addr), dev->name); | 4064 | wiphy_name(local->hw.wiphy), print_mac(mac, addr), dev->name); |
4048 | 4065 | ||
4049 | sta = sta_info_add(sdata, addr); | 4066 | sta = sta_info_alloc(sdata, addr, GFP_ATOMIC); |
4050 | if (IS_ERR(sta)) | 4067 | if (!sta) |
4051 | return NULL; | 4068 | return NULL; |
4052 | 4069 | ||
4053 | sta->flags |= WLAN_STA_AUTHORIZED; | 4070 | sta->flags |= WLAN_STA_AUTHORIZED; |
@@ -4057,6 +4074,11 @@ struct sta_info * ieee80211_ibss_add_sta(struct net_device *dev, | |||
4057 | 4074 | ||
4058 | rate_control_rate_init(sta, local); | 4075 | rate_control_rate_init(sta, local); |
4059 | 4076 | ||
4077 | if (sta_info_insert(sta)) { | ||
4078 | sta_info_destroy(sta); | ||
4079 | return NULL; | ||
4080 | } | ||
4081 | |||
4060 | return sta; | 4082 | return sta; |
4061 | } | 4083 | } |
4062 | 4084 | ||
diff --git a/net/mac80211/mesh.h b/net/mac80211/mesh.h index 576eee83d859..aee0b9eb36e3 100644 --- a/net/mac80211/mesh.h +++ b/net/mac80211/mesh.h | |||
@@ -232,8 +232,8 @@ void mesh_neighbour_update(u8 *hw_addr, u64 rates, struct net_device *dev, | |||
232 | bool mesh_peer_accepts_plinks(struct ieee802_11_elems *ie, | 232 | bool mesh_peer_accepts_plinks(struct ieee802_11_elems *ie, |
233 | struct net_device *dev); | 233 | struct net_device *dev); |
234 | void mesh_accept_plinks_update(struct ieee80211_sub_if_data *sdata); | 234 | void mesh_accept_plinks_update(struct ieee80211_sub_if_data *sdata); |
235 | struct sta_info *mesh_plink_add(u8 *hw_addr, u64 rates, | 235 | struct sta_info *mesh_plink_alloc(struct ieee80211_sub_if_data *sdata, |
236 | struct ieee80211_sub_if_data *sdata); | 236 | u8 *hw_addr, u64 rates, gfp_t gfp); |
237 | void mesh_plink_broken(struct sta_info *sta); | 237 | void mesh_plink_broken(struct sta_info *sta); |
238 | void mesh_plink_deactivate(struct sta_info *sta); | 238 | void mesh_plink_deactivate(struct sta_info *sta); |
239 | int mesh_plink_open(struct sta_info *sta); | 239 | int mesh_plink_open(struct sta_info *sta); |
diff --git a/net/mac80211/mesh_plink.c b/net/mac80211/mesh_plink.c index c2b80500ae72..85cb75d53c43 100644 --- a/net/mac80211/mesh_plink.c +++ b/net/mac80211/mesh_plink.c | |||
@@ -89,44 +89,41 @@ static inline void mesh_plink_fsm_restart(struct sta_info *sta) | |||
89 | } | 89 | } |
90 | 90 | ||
91 | /** | 91 | /** |
92 | * mesh_plink_add - allocate and add a new mesh peer link | 92 | * mesh_plink_alloc - allocate a new mesh peer link |
93 | * | 93 | * |
94 | * @sdata: local mesh interface | ||
94 | * @hw_addr: hardware address (ETH_ALEN length) | 95 | * @hw_addr: hardware address (ETH_ALEN length) |
95 | * @rates: rates the mesh peer supports | 96 | * @rates: rates the mesh peer supports |
96 | * @dev: local mesh interface | ||
97 | * | 97 | * |
98 | * The initial state of the new plink is set to LISTEN | 98 | * The initial state of the new plink is set to LISTEN |
99 | * | 99 | * |
100 | * Returns: non-NULL on success, ERR_PTR() on error. | 100 | * Returns: NULL on error. |
101 | */ | 101 | */ |
102 | struct sta_info *mesh_plink_add(u8 *hw_addr, u64 rates, | 102 | struct sta_info *mesh_plink_alloc(struct ieee80211_sub_if_data *sdata, |
103 | struct ieee80211_sub_if_data *sdata) | 103 | u8 *hw_addr, u64 rates, gfp_t gfp) |
104 | { | 104 | { |
105 | struct ieee80211_local *local = sdata->local; | 105 | struct ieee80211_local *local = sdata->local; |
106 | struct sta_info *sta; | 106 | struct sta_info *sta; |
107 | 107 | ||
108 | if (compare_ether_addr(hw_addr, sdata->dev->dev_addr) == 0) | 108 | if (compare_ether_addr(hw_addr, sdata->dev->dev_addr) == 0) |
109 | /* never add ourselves as neighbours */ | 109 | /* never add ourselves as neighbours */ |
110 | return ERR_PTR(-EINVAL); | 110 | return NULL; |
111 | 111 | ||
112 | if (is_multicast_ether_addr(hw_addr)) | 112 | if (is_multicast_ether_addr(hw_addr)) |
113 | return ERR_PTR(-EINVAL); | 113 | return NULL; |
114 | 114 | ||
115 | if (local->num_sta >= MESH_MAX_PLINKS) | 115 | if (local->num_sta >= MESH_MAX_PLINKS) |
116 | return ERR_PTR(-ENOSPC); | 116 | return NULL; |
117 | 117 | ||
118 | sta = sta_info_add(sdata, hw_addr); | 118 | sta = sta_info_alloc(sdata, hw_addr, gfp); |
119 | if (IS_ERR(sta)) | 119 | if (!sta) |
120 | return sta; | 120 | return NULL; |
121 | 121 | ||
122 | sta->plink_state = LISTEN; | 122 | sta->plink_state = LISTEN; |
123 | spin_lock_init(&sta->plink_lock); | 123 | spin_lock_init(&sta->plink_lock); |
124 | init_timer(&sta->plink_timer); | 124 | init_timer(&sta->plink_timer); |
125 | sta->flags |= WLAN_STA_AUTHORIZED; | 125 | sta->flags |= WLAN_STA_AUTHORIZED; |
126 | sta->supp_rates[local->hw.conf.channel->band] = rates; | 126 | sta->supp_rates[local->hw.conf.channel->band] = rates; |
127 | rate_control_rate_init(sta, local); | ||
128 | |||
129 | mesh_accept_plinks_update(sdata); | ||
130 | 127 | ||
131 | return sta; | 128 | return sta; |
132 | } | 129 | } |
@@ -252,8 +249,13 @@ void mesh_neighbour_update(u8 *hw_addr, u64 rates, struct net_device *dev, | |||
252 | 249 | ||
253 | sta = sta_info_get(local, hw_addr); | 250 | sta = sta_info_get(local, hw_addr); |
254 | if (!sta) { | 251 | if (!sta) { |
255 | sta = mesh_plink_add(hw_addr, rates, sdata); | 252 | sta = mesh_plink_alloc(sdata, hw_addr, rates, GFP_ATOMIC); |
256 | if (IS_ERR(sta)) { | 253 | if (!sta) { |
254 | rcu_read_unlock(); | ||
255 | return; | ||
256 | } | ||
257 | if (sta_info_insert(sta)) { | ||
258 | sta_info_destroy(sta); | ||
257 | rcu_read_unlock(); | 259 | rcu_read_unlock(); |
258 | return; | 260 | return; |
259 | } | 261 | } |
@@ -516,12 +518,17 @@ void mesh_rx_plink_frame(struct net_device *dev, struct ieee80211_mgmt *mgmt, | |||
516 | } | 518 | } |
517 | 519 | ||
518 | rates = ieee80211_sta_get_rates(local, &elems, rx_status->band); | 520 | rates = ieee80211_sta_get_rates(local, &elems, rx_status->band); |
519 | sta = mesh_plink_add(mgmt->sa, rates, sdata); | 521 | sta = mesh_plink_alloc(sdata, mgmt->sa, rates, GFP_ATOMIC); |
520 | if (IS_ERR(sta)) { | 522 | if (!sta) { |
521 | mpl_dbg("Mesh plink error: plink table full\n"); | 523 | mpl_dbg("Mesh plink error: plink table full\n"); |
522 | rcu_read_unlock(); | 524 | rcu_read_unlock(); |
523 | return; | 525 | return; |
524 | } | 526 | } |
527 | if (sta_info_insert(sta)) { | ||
528 | sta_info_destroy(sta); | ||
529 | rcu_read_unlock(); | ||
530 | return; | ||
531 | } | ||
525 | event = OPN_ACPT; | 532 | event = OPN_ACPT; |
526 | spin_lock_bh(&sta->plink_lock); | 533 | spin_lock_bh(&sta->plink_lock); |
527 | } else { | 534 | } else { |
diff --git a/net/mac80211/sta_info.c b/net/mac80211/sta_info.c index ee5b66abc0f1..a230a9597398 100644 --- a/net/mac80211/sta_info.c +++ b/net/mac80211/sta_info.c | |||
@@ -31,12 +31,13 @@ | |||
31 | * for faster lookup and a list for iteration. They are managed using | 31 | * for faster lookup and a list for iteration. They are managed using |
32 | * RCU, i.e. access to the list and hash table is protected by RCU. | 32 | * RCU, i.e. access to the list and hash table is protected by RCU. |
33 | * | 33 | * |
34 | * STA info structures are always "alive" when they are added with | 34 | * Upon allocating a STA info structure with @sta_info_alloc() or |
35 | * @sta_info_add() [this may be changed in the future to allow allocating | 35 | * mesh_plink_alloc(), the caller owns that structure. It must then either |
36 | * outside of a critical section!], they are then added to the hash | 36 | * destroy it using @sta_info_destroy() (which is pretty useless) or insert |
37 | * table and list. Therefore, @sta_info_add() must also be RCU protected, | 37 | * it into the hash table using @sta_info_insert() which demotes the reference |
38 | * also, the caller of @sta_info_add() cannot assume that it owns the | 38 | * from ownership to a regular RCU-protected reference; if the function |
39 | * structure. | 39 | * is called without protection by an RCU critical section the reference |
40 | * is instantly invalidated. | ||
40 | * | 41 | * |
41 | * Because there are debugfs entries for each station, and adding those | 42 | * Because there are debugfs entries for each station, and adding those |
42 | * must be able to sleep, it is also possible to "pin" a station entry, | 43 | * must be able to sleep, it is also possible to "pin" a station entry, |
@@ -131,6 +132,10 @@ void sta_info_destroy(struct sta_info *sta) | |||
131 | struct ieee80211_local *local = sta->local; | 132 | struct ieee80211_local *local = sta->local; |
132 | struct sk_buff *skb; | 133 | struct sk_buff *skb; |
133 | int i; | 134 | int i; |
135 | DECLARE_MAC_BUF(mbuf); | ||
136 | |||
137 | if (!sta) | ||
138 | return; | ||
134 | 139 | ||
135 | ASSERT_RTNL(); | 140 | ASSERT_RTNL(); |
136 | might_sleep(); | 141 | might_sleep(); |
@@ -171,6 +176,11 @@ void sta_info_destroy(struct sta_info *sta) | |||
171 | rate_control_free_sta(sta->rate_ctrl, sta->rate_ctrl_priv); | 176 | rate_control_free_sta(sta->rate_ctrl, sta->rate_ctrl_priv); |
172 | rate_control_put(sta->rate_ctrl); | 177 | rate_control_put(sta->rate_ctrl); |
173 | 178 | ||
179 | #ifdef CONFIG_MAC80211_VERBOSE_DEBUG | ||
180 | printk(KERN_DEBUG "%s: Destroyed STA %s\n", | ||
181 | wiphy_name(local->hw.wiphy), print_mac(mbuf, sta->addr)); | ||
182 | #endif /* CONFIG_MAC80211_VERBOSE_DEBUG */ | ||
183 | |||
174 | kfree(sta); | 184 | kfree(sta); |
175 | } | 185 | } |
176 | 186 | ||
@@ -183,18 +193,17 @@ static void sta_info_hash_add(struct ieee80211_local *local, | |||
183 | rcu_assign_pointer(local->sta_hash[STA_HASH(sta->addr)], sta); | 193 | rcu_assign_pointer(local->sta_hash[STA_HASH(sta->addr)], sta); |
184 | } | 194 | } |
185 | 195 | ||
186 | struct sta_info *sta_info_add(struct ieee80211_sub_if_data *sdata, | 196 | struct sta_info *sta_info_alloc(struct ieee80211_sub_if_data *sdata, |
187 | u8 *addr) | 197 | u8 *addr, gfp_t gfp) |
188 | { | 198 | { |
189 | struct ieee80211_local *local = sdata->local; | 199 | struct ieee80211_local *local = sdata->local; |
190 | struct sta_info *sta; | 200 | struct sta_info *sta; |
191 | int i; | 201 | int i; |
192 | DECLARE_MAC_BUF(mac); | 202 | DECLARE_MAC_BUF(mbuf); |
193 | unsigned long flags; | ||
194 | 203 | ||
195 | sta = kzalloc(sizeof(*sta), GFP_ATOMIC); | 204 | sta = kzalloc(sizeof(*sta), gfp); |
196 | if (!sta) | 205 | if (!sta) |
197 | return ERR_PTR(-ENOMEM); | 206 | return NULL; |
198 | 207 | ||
199 | memcpy(sta->addr, addr, ETH_ALEN); | 208 | memcpy(sta->addr, addr, ETH_ALEN); |
200 | sta->local = local; | 209 | sta->local = local; |
@@ -202,11 +211,11 @@ struct sta_info *sta_info_add(struct ieee80211_sub_if_data *sdata, | |||
202 | 211 | ||
203 | sta->rate_ctrl = rate_control_get(local->rate_ctrl); | 212 | sta->rate_ctrl = rate_control_get(local->rate_ctrl); |
204 | sta->rate_ctrl_priv = rate_control_alloc_sta(sta->rate_ctrl, | 213 | sta->rate_ctrl_priv = rate_control_alloc_sta(sta->rate_ctrl, |
205 | GFP_ATOMIC); | 214 | gfp); |
206 | if (!sta->rate_ctrl_priv) { | 215 | if (!sta->rate_ctrl_priv) { |
207 | rate_control_put(sta->rate_ctrl); | 216 | rate_control_put(sta->rate_ctrl); |
208 | kfree(sta); | 217 | kfree(sta); |
209 | return ERR_PTR(-ENOMEM); | 218 | return NULL; |
210 | } | 219 | } |
211 | 220 | ||
212 | spin_lock_init(&sta->ampdu_mlme.ampdu_rx); | 221 | spin_lock_init(&sta->ampdu_mlme.ampdu_rx); |
@@ -233,11 +242,27 @@ struct sta_info *sta_info_add(struct ieee80211_sub_if_data *sdata, | |||
233 | } | 242 | } |
234 | skb_queue_head_init(&sta->ps_tx_buf); | 243 | skb_queue_head_init(&sta->ps_tx_buf); |
235 | skb_queue_head_init(&sta->tx_filtered); | 244 | skb_queue_head_init(&sta->tx_filtered); |
245 | |||
246 | #ifdef CONFIG_MAC80211_VERBOSE_DEBUG | ||
247 | printk(KERN_DEBUG "%s: Allocated STA %s\n", | ||
248 | wiphy_name(local->hw.wiphy), print_mac(mbuf, sta->addr)); | ||
249 | #endif /* CONFIG_MAC80211_VERBOSE_DEBUG */ | ||
250 | |||
251 | return sta; | ||
252 | } | ||
253 | |||
254 | int sta_info_insert(struct sta_info *sta) | ||
255 | { | ||
256 | struct ieee80211_local *local = sta->local; | ||
257 | struct ieee80211_sub_if_data *sdata = sta->sdata; | ||
258 | unsigned long flags; | ||
259 | DECLARE_MAC_BUF(mac); | ||
260 | |||
236 | spin_lock_irqsave(&local->sta_lock, flags); | 261 | spin_lock_irqsave(&local->sta_lock, flags); |
237 | /* check if STA exists already */ | 262 | /* check if STA exists already */ |
238 | if (__sta_info_find(local, addr)) { | 263 | if (__sta_info_find(local, sta->addr)) { |
239 | spin_unlock_irqrestore(&local->sta_lock, flags); | 264 | spin_unlock_irqrestore(&local->sta_lock, flags); |
240 | return ERR_PTR(-EEXIST); | 265 | return -EEXIST; |
241 | } | 266 | } |
242 | list_add(&sta->list, &local->sta_list); | 267 | list_add(&sta->list, &local->sta_list); |
243 | local->num_sta++; | 268 | local->num_sta++; |
@@ -249,16 +274,16 @@ struct sta_info *sta_info_add(struct ieee80211_sub_if_data *sdata, | |||
249 | sdata = sdata->u.vlan.ap; | 274 | sdata = sdata->u.vlan.ap; |
250 | 275 | ||
251 | local->ops->sta_notify(local_to_hw(local), &sdata->vif, | 276 | local->ops->sta_notify(local_to_hw(local), &sdata->vif, |
252 | STA_NOTIFY_ADD, addr); | 277 | STA_NOTIFY_ADD, sta->addr); |
253 | } | 278 | } |
254 | 279 | ||
255 | spin_unlock_irqrestore(&local->sta_lock, flags); | ||
256 | |||
257 | #ifdef CONFIG_MAC80211_VERBOSE_DEBUG | 280 | #ifdef CONFIG_MAC80211_VERBOSE_DEBUG |
258 | printk(KERN_DEBUG "%s: Added STA %s\n", | 281 | printk(KERN_DEBUG "%s: Inserted STA %s\n", |
259 | wiphy_name(local->hw.wiphy), print_mac(mac, addr)); | 282 | wiphy_name(local->hw.wiphy), print_mac(mac, sta->addr)); |
260 | #endif /* CONFIG_MAC80211_VERBOSE_DEBUG */ | 283 | #endif /* CONFIG_MAC80211_VERBOSE_DEBUG */ |
261 | 284 | ||
285 | spin_unlock_irqrestore(&local->sta_lock, flags); | ||
286 | |||
262 | #ifdef CONFIG_MAC80211_DEBUGFS | 287 | #ifdef CONFIG_MAC80211_DEBUGFS |
263 | /* debugfs entry adding might sleep, so schedule process | 288 | /* debugfs entry adding might sleep, so schedule process |
264 | * context task for adding entry for STAs that do not yet | 289 | * context task for adding entry for STAs that do not yet |
@@ -266,7 +291,10 @@ struct sta_info *sta_info_add(struct ieee80211_sub_if_data *sdata, | |||
266 | queue_work(local->hw.workqueue, &local->sta_debugfs_add); | 291 | queue_work(local->hw.workqueue, &local->sta_debugfs_add); |
267 | #endif | 292 | #endif |
268 | 293 | ||
269 | return sta; | 294 | if (ieee80211_vif_is_mesh(&sdata->vif)) |
295 | mesh_accept_plinks_update(sdata); | ||
296 | |||
297 | return 0; | ||
270 | } | 298 | } |
271 | 299 | ||
272 | static inline void __bss_tim_set(struct ieee80211_if_ap *bss, u16 aid) | 300 | static inline void __bss_tim_set(struct ieee80211_if_ap *bss, u16 aid) |
diff --git a/net/mac80211/sta_info.h b/net/mac80211/sta_info.h index 787124c253af..3f788228eeff 100644 --- a/net/mac80211/sta_info.h +++ b/net/mac80211/sta_info.h | |||
@@ -283,12 +283,19 @@ struct sta_info *sta_info_get(struct ieee80211_local *local, u8 *addr); | |||
283 | struct sta_info *sta_info_get_by_idx(struct ieee80211_local *local, int idx, | 283 | struct sta_info *sta_info_get_by_idx(struct ieee80211_local *local, int idx, |
284 | struct net_device *dev); | 284 | struct net_device *dev); |
285 | /* | 285 | /* |
286 | * Add a new STA info, must be under RCU read lock | 286 | * Create a new STA info, caller owns returned structure |
287 | * because otherwise the returned reference isn't | 287 | * until sta_info_insert(). |
288 | * necessarily valid long enough. | ||
289 | */ | 288 | */ |
290 | struct sta_info *sta_info_add(struct ieee80211_sub_if_data *sdata, | 289 | struct sta_info *sta_info_alloc(struct ieee80211_sub_if_data *sdata, |
291 | u8 *addr); | 290 | u8 *addr, gfp_t gfp); |
291 | /* | ||
292 | * Insert STA info into hash table/list, returns zero or a | ||
293 | * -EEXIST if (if the same MAC address is already present). | ||
294 | * | ||
295 | * Calling this without RCU protection makes the caller | ||
296 | * relinquish its reference to @sta. | ||
297 | */ | ||
298 | int sta_info_insert(struct sta_info *sta); | ||
292 | /* | 299 | /* |
293 | * Unlink a STA info from the hash table/list. | 300 | * Unlink a STA info from the hash table/list. |
294 | * This can NULL the STA pointer if somebody else | 301 | * This can NULL the STA pointer if somebody else |