From patchwork Fri Apr 6 23:04:14 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Greear X-Patchwork-Id: 151283 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from maxx.maxx.shmoo.com (maxx.shmoo.com [205.134.188.171]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "maxx.shmoo.com", Issuer "CA Cert Signing Authority" (not verified)) by ozlabs.org (Postfix) with ESMTPS id 40CF3B702E for ; Sat, 7 Apr 2012 09:05:17 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id C004A9C220; Fri, 6 Apr 2012 19:05:14 -0400 (EDT) X-Virus-Scanned: amavisd-new at maxx.shmoo.com Received: from maxx.maxx.shmoo.com ([127.0.0.1]) by localhost (maxx.shmoo.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id kI+tHbbujhlF; Fri, 6 Apr 2012 19:05:14 -0400 (EDT) Received: from maxx.shmoo.com (localhost [127.0.0.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id 11F789C1E5; Fri, 6 Apr 2012 19:05:02 -0400 (EDT) X-Original-To: mailman-post+hostap@maxx.shmoo.com Delivered-To: mailman-post+hostap@maxx.shmoo.com Received: from localhost (localhost [127.0.0.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id 8A14D9C1CE for ; Fri, 6 Apr 2012 19:05:00 -0400 (EDT) X-Virus-Scanned: amavisd-new at maxx.shmoo.com Received: from maxx.maxx.shmoo.com ([127.0.0.1]) by localhost (maxx.shmoo.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id WolMlk7XOxRR for ; Fri, 6 Apr 2012 19:04:55 -0400 (EDT) Received: from ns3.lanforge.com (mail.candelatech.com [208.74.158.172]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by maxx.maxx.shmoo.com (Postfix) with ESMTPS id AC47F17C016 for ; Fri, 6 Apr 2012 19:04:55 -0400 (EDT) Received: from fs3.candelatech.com (firewall.candelatech.com [70.89.124.249]) by ns3.lanforge.com (8.14.2/8.14.2) with ESMTP id q36N4ZCw027852 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 6 Apr 2012 16:04:49 -0700 From: greearb@candelatech.com To: hostap@lists.shmoo.com Subject: [PATCH 3/3] supplicant: Allow limiting number of concurrent associations. Date: Fri, 6 Apr 2012 16:04:14 -0700 Message-Id: <1333753454-21306-3-git-send-email-greearb@candelatech.com> X-Mailer: git-send-email 1.7.3.4 In-Reply-To: <1333753454-21306-1-git-send-email-greearb@candelatech.com> References: <1333753454-21306-1-git-send-email-greearb@candelatech.com> Cc: Ben Greear X-BeenThere: hostap@lists.shmoo.com X-Mailman-Version: 2.1.9 Precedence: list List-Id: HostAP Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: hostap-bounces@lists.shmoo.com Errors-To: hostap-bounces@lists.shmoo.com From: Ben Greear When using lots of virtual clients, it may be useful to limit the number that attempt to connect to the AP at once. Limitting the associations per scan response is an easy way to do this. Signed-hostap: Ben Greear --- :100644 100644 bf838b1... f3261b2... M wpa_supplicant/config.c :100644 100644 c15f02b... 6d95330... M wpa_supplicant/config.h :100644 100644 cce57c2... a428d71... M wpa_supplicant/events.c wpa_supplicant/config.c | 2 ++ wpa_supplicant/config.h | 7 +++++++ wpa_supplicant/events.c | 21 +++++++++++++++++++++ 3 files changed, 30 insertions(+), 0 deletions(-) diff --git a/wpa_supplicant/config.c b/wpa_supplicant/config.c index bf838b1..f3261b2 100644 --- a/wpa_supplicant/config.c +++ b/wpa_supplicant/config.c @@ -2493,6 +2493,7 @@ struct wpa_config * wpa_config_alloc_empty(const char *ctrl_interface, config->max_num_sta = DEFAULT_MAX_NUM_STA; config->access_network_type = DEFAULT_ACCESS_NETWORK_TYPE; config->min_scan_gap = DEFAULT_MIN_SCAN_GAP; + config->max_assoc_per_scan = DEFAULT_MAX_ASSOC_PER_SCAN; if (ctrl_interface) config->ctrl_interface = os_strdup(ctrl_interface); @@ -2834,6 +2835,7 @@ static const struct global_parse_data global_fields[] = { { INT(dot11RSNAConfigPMKReauthThreshold), 0 }, { INT(dot11RSNAConfigSATimeout), 0 }, { INT(min_scan_gap), 0 }, + { INT(max_assoc_per_scan), 0 }, #ifndef CONFIG_NO_CONFIG_WRITE { INT(update_config), 0 }, #endif /* CONFIG_NO_CONFIG_WRITE */ diff --git a/wpa_supplicant/config.h b/wpa_supplicant/config.h index c15f02b..6d95330 100644 --- a/wpa_supplicant/config.h +++ b/wpa_supplicant/config.h @@ -24,6 +24,7 @@ #define DEFAULT_MAX_NUM_STA 128 #define DEFAULT_ACCESS_NETWORK_TYPE 15 #define DEFAULT_MIN_SCAN_GAP 0 +#define DEFAULT_MAX_ASSOC_PER_SCAN 25 #include "config_ssid.h" #include "wps/wps.h" @@ -581,6 +582,12 @@ struct wpa_config { /* Minimum interval between scan requests, in seconds */ int min_scan_gap; + /* Maximum number of association requests per scan results + * This can be used to stop a thundering herd of hundreds of + * virtual stations from all trying to associate at once. + */ + int max_assoc_per_scan; + /** * interworking - Whether Interworking (IEEE 802.11u) is enabled */ diff --git a/wpa_supplicant/events.c b/wpa_supplicant/events.c index cce57c2..a428d71 100644 --- a/wpa_supplicant/events.c +++ b/wpa_supplicant/events.c @@ -41,6 +41,8 @@ #include "offchannel.h" +static int num_assoc_reqs; + static int wpa_supplicant_select_config(struct wpa_supplicant *wpa_s) { struct wpa_ssid *ssid, *old_ssid; @@ -848,6 +850,15 @@ int wpa_supplicant_connect(struct wpa_supplicant *wpa_s, wpa_supplicant_req_new_scan(wpa_s, 10, 0); return 0; } + + if (num_assoc_reqs >= wpa_s->conf->max_assoc_per_scan) { + wpa_dbg(wpa_s, MSG_DEBUG, + "Deferring association attempt, reqs: %i, max: %i", + num_assoc_reqs, wpa_s->conf->max_assoc_per_scan); + return 0; + } + num_assoc_reqs++; + wpa_msg(wpa_s, MSG_DEBUG, "Request association: " "reassociate: %d selected: "MACSTR " bssid: " MACSTR " pending: " MACSTR " wpa_state: %s", @@ -1130,6 +1141,14 @@ static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s, wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found"); ssid = wpa_supplicant_pick_new_network(wpa_s); if (ssid) { + if (num_assoc_reqs >= wpa_s->conf->max_assoc_per_scan) { + wpa_dbg(wpa_s, MSG_DEBUG, + "Deferring association, reqs: %i, max: %i", + num_assoc_reqs, wpa_s->conf->max_assoc_per_scan); + return 0; + } + num_assoc_reqs++; + wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network"); wpa_supplicant_associate(wpa_s, NULL, ssid); wpa_supplicant_rsn_preauth_scan_results(wpa_s); @@ -1164,6 +1183,8 @@ static void wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s, const char *rn, *rn2; struct wpa_supplicant *ifs; + num_assoc_reqs = 0; + if (_wpa_supplicant_event_scan_results(wpa_s, data) < 0) { /* * If no scan results could be fetched, then no need to