From patchwork Tue Jun 30 12:19:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Theil X-Patchwork-Id: 1319824 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2001:8b0:10b:1231::1; helo=merlin.infradead.org; envelope-from=hostap-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=tu-ilmenau.de Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=merlin.20170209 header.b=HfPzR1sX; dkim-atps=neutral Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49x3N81lgqz9sTT for ; Tue, 30 Jun 2020 22:20:24 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=EGms9HEAIt4cSaCKZak7YYhuy+JSedapECaGzam1kf0=; b=HfPzR1sX3GXlftwL+6dHiqQsN +v2a3V0k38iYEgW1viNyYdqmy4/doE5sy4zhNSqOc+tmMZmPgcJ0eRxNpn4AV/22qGDm0QZatcQv1 1TZwGO3kKcXdj6ItGfBQIPyZwKqzQQmd8mk/NAdtBERV/sel1S3yQH2iuZpGn6l3wkHtT/B0b5A6D kU7pF6XbpnqF52+ttNNzrQw6760VeP6HRLDLUhWlqyke/ektuAEtiUls9pky9w1ms2CIVvy0Fc6in ZjPW1174Pxwnmcq+gxFpyNzlPiGi5PKobcSGH8lSMDOkr1umlYe2idAFWOgtmVDkwzOLyuxGAwYVU WUz/cy9rg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jqFEr-00037g-Gt; Tue, 30 Jun 2020 12:19:49 +0000 Received: from smail.rz.tu-ilmenau.de ([141.24.186.67]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jqFEX-0002zf-9T for hostap@lists.infradead.org; Tue, 30 Jun 2020 12:19:30 +0000 Received: from legolas.prakinf.tu-ilmenau.de (unknown [141.24.207.116]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smail.rz.tu-ilmenau.de (Postfix) with ESMTPSA id 97ACD58008D; Tue, 30 Jun 2020 14:19:21 +0200 (CEST) From: Markus Theil To: hostap@lists.infradead.org Subject: [PATCH v2 12/12] mesh: use deterministic channel on channel switch Date: Tue, 30 Jun 2020 14:19:07 +0200 Message-Id: <20200630121907.132751-13-markus.theil@tu-ilmenau.de> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200630121907.132751-1-markus.theil@tu-ilmenau.de> References: <20200630121907.132751-1-markus.theil@tu-ilmenau.de> MIME-Version: 1.0 X-Spam-Note: CRM114 invocation failed X-Spam-Score: -2.3 (--) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-2.3 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [141.24.186.67 listed in list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 SPF_NONE SPF: sender does not publish an SPF Record X-BeenThere: hostap@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: masashi.honma@gmail.com, Markus Theil Sender: "Hostap" Errors-To: hostap-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org This patch uses a deterministic channel on DFS channel switch in mesh networks. Otherwise, when switching to a usable but not available channel, no CSA can be sent and a random channel is choosen without notification of other nodes. It is then quite likely, that the mesh network gets disconnected. Fix this by using a deterministic number, based on the sha256 hash of the mesh ID, in order to use at least a different number in each mesh network. Signed-off-by: Markus Theil --- src/ap/dfs.c | 20 +++++++++++++++++++- src/drivers/driver_nl80211.c | 4 ++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/ap/dfs.c b/src/ap/dfs.c index 25dad3482..8f3630bf8 100644 --- a/src/ap/dfs.c +++ b/src/ap/dfs.c @@ -17,6 +17,7 @@ #include "ap_drv_ops.h" #include "drivers/driver.h" #include "dfs.h" +#include "crypto/crypto.h" static int dfs_get_used_n_chans(struct hostapd_iface *iface, int *seg1) @@ -480,9 +481,14 @@ dfs_get_valid_channel(struct hostapd_iface *iface, int num_available_chandefs; int chan_idx, chan_idx2; int sec_chan_idx_80p80 = -1; + bool is_mesh = false; int i; u32 _rand; +#ifdef CONFIG_MESH + is_mesh = iface->mconf; +#endif + wpa_printf(MSG_DEBUG, "DFS: Selecting random channel"); *secondary_channel = 0; *oper_centr_freq_seg0_idx = 0; @@ -502,8 +508,20 @@ dfs_get_valid_channel(struct hostapd_iface *iface, if (num_available_chandefs == 0) return NULL; - if (os_get_random((u8 *) &_rand, sizeof(_rand)) < 0) + /* try to use deterministic channel in mesh, so that both sides + * have a chance to switch to the same channel */ + if (is_mesh) { +#ifdef CONFIG_MESH + u64 hash[4]; + const u8 *meshid[1] = { &iface->mconf->meshid[0] }; + const size_t meshid_len = iface->mconf->meshid_len; + + sha256_vector(1, meshid, &meshid_len, (u8 *)&hash[0]); + _rand = hash[0] + hash[1] + hash[2] + hash[3]; +#endif + } else if (os_get_random((u8 *) &_rand, sizeof(_rand)) < 0) return NULL; + chan_idx = _rand % num_available_chandefs; dfs_find_channel(iface, &chan, chan_idx, skip_radar); if (!chan) { diff --git a/src/drivers/driver_nl80211.c b/src/drivers/driver_nl80211.c index d922eda74..18521f832 100644 --- a/src/drivers/driver_nl80211.c +++ b/src/drivers/driver_nl80211.c @@ -9568,6 +9568,10 @@ static int nl80211_switch_channel(void *priv, struct csa_settings *settings) if (ret) goto error; + if (drv->nlmode == NL80211_IFTYPE_MESH_POINT) { + nla_put_flag(msg, NL80211_ATTR_HANDLE_DFS); + } + /* beacon_csa params */ beacon_csa = nla_nest_start(msg, NL80211_ATTR_CSA_IES); if (!beacon_csa)