Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp1107894rwb; Thu, 11 Aug 2022 16:17:54 -0700 (PDT) X-Google-Smtp-Source: AA6agR4fSHU2vUnGRC1x2RbQPlh6aH3YZPkpKXg8hQ1X9N6AS3reN2guSzzuQU+He/hwS2wbB19r X-Received: by 2002:a17:90a:86c7:b0:1f4:fb4b:78b4 with SMTP id y7-20020a17090a86c700b001f4fb4b78b4mr11115785pjv.51.1660259874558; Thu, 11 Aug 2022 16:17:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660259874; cv=none; d=google.com; s=arc-20160816; b=vXp0mmgsEHOSFpBmGBUrqQLPFPhO8txf1U6w1cs0nqi8Eet6gTAVaHQGf/rb69arjR 40+lexf7T0/6ymlB8FxNw1VZqIc+4orMDkGhYcFfc4VzFp3GCvoCR0oh4Ku2t+FYjSVm oEKA9IhSPl7AMFJxe6NVROfcTLRGoWI8eFU07UTP4T3nKvCsguKOohShvC3lljYbC+7p XSxZHZrV/+tJwrk5RWjnsP4lO8cjJswDVBKPrjEH3qZFRAxhP3TvsxI23pt8WljlJBQm w2aQ2fbkmWGrBPPyexfxAbZ/qB1vBP7vQ+DuuhPyzpmdcP+4kl2fjggpcmEoDdR9IhM/ c7vQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=hjICE/2oXuWorxZLYXxrFvZDSwvja9RzSR9cgFDoRnw=; b=JOetNeJ89DVBymIyjwlFVqTncbx3Q5xoqAG1qlV0lcLrTpThz9L33fDUBS6gLh/ABh 9eWOVdyfEUnr5qJBKYXxyicx1nUPgF0gV5/6v/NhwmQIH/yNfaZUDRbuLR/flMI+5YE2 SCn0VhwOBzZ45Ol2zZhQHoczXTgiBW7Se3njg2KoNVqHPPuEk5jMtkiAUfqWUXaTDZmU /9oEUL+/vzAiRToeHsIPlcjng2loMLp4Ru2aFTcohlYL8uWN1Okl4EIF7TcyatJMYOF5 pHm97P8TB28D1HexKZudwIQGYnbhJCuYtF/LwGumZB2UOAljmeVMv72iuih1BUgIitIm bZBA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=awTEIvPb; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v18-20020a637a12000000b004129d17d75dsi767391pgc.704.2022.08.11.16.17.38; Thu, 11 Aug 2022 16:17:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=awTEIvPb; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235497AbiHKXNu (ORCPT + 65 others); Thu, 11 Aug 2022 19:13:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46258 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229833AbiHKXNs (ORCPT ); Thu, 11 Aug 2022 19:13:48 -0400 Received: from mail-pf1-x429.google.com (mail-pf1-x429.google.com [IPv6:2607:f8b0:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F0613A062A for ; Thu, 11 Aug 2022 16:13:45 -0700 (PDT) Received: by mail-pf1-x429.google.com with SMTP id q19so17726652pfg.8 for ; Thu, 11 Aug 2022 16:13:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=hjICE/2oXuWorxZLYXxrFvZDSwvja9RzSR9cgFDoRnw=; b=awTEIvPbuCK6Ko67nttrHPrapC5scDQ8U/6FxoFiWqeqU1doYSF/boG5zPv7JYS7Jc YW8GB2x0daibVDpXVZuWpZd2821hZ1v8PVo/2J0fR2l22h1aAwL62AxD+ZxBq1vNJloS k1AkQIh4AzryezjuG+yStxcGBiItd+5UjgU8HRWl3XNN4a232t7V2ubT7ffaHzIwJIe/ v+3qPs6pTdCu8VKFWpw7yj2AmEQxMmNJL3dcKZTj3gAeCniyYnXdEyMrJEOHDam1Gqf/ 0R0X94aE2cxoTFnOINRX1UFE8EoauEa8rXcpH7A4q0N0+3jVsV/8h23sHbskF3T5FHFX om3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=hjICE/2oXuWorxZLYXxrFvZDSwvja9RzSR9cgFDoRnw=; b=AwdyPs3KtU1Kjl5blieWeiQhcxvru54XVx/BXLuCHCjTl/DU0PxI+ZyYiYf1Ncz1XV 6u6jmR/bYCPMO+BBMZoHyFNfmeUuMtKOH7ZfIEBJZBDXfK3gREbIYklV5P/CTLRT8AON WfSVVOvx4kKU4MWnaZMa5hprIarjcq2bFcMRhF3ai2MSOyFleccRHf9p/5hcRdF0CHJh zQGZzIawJiEwVppNMUbl6CCkF4p8ynxr/HYyeGoGTeyO0Cg7frdA/PWvW/kInyrj2M4l zz6pxuNAsVtDiqPh2I8vPd5TSGODvwybyUtJCSP/6+b9ABLVVQ4RBcGTaSbISPXC4AHw Q8Lw== X-Gm-Message-State: ACgBeo0OnBtlSR4WBu7YATeoYmWrHKZaMELj8qnqcgXpaKxnHXGbvsta lNy/N4CyW/wIswm7QnhDO47J5El0Iw4= X-Received: by 2002:a63:1315:0:b0:421:5af6:8c26 with SMTP id i21-20020a631315000000b004215af68c26mr968741pgl.166.1660259625292; Thu, 11 Aug 2022 16:13:45 -0700 (PDT) Received: from jprestwo-xps.none ([50.39.168.145]) by smtp.gmail.com with ESMTPSA id z6-20020a170903018600b0016d2db82962sm227644plg.16.2022.08.11.16.13.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Aug 2022 16:13:44 -0700 (PDT) From: James Prestwood To: linux-wireless@vger.kernel.org Cc: James Prestwood Subject: [PATCH v2 2/2] mac80211: Support POWERED_ADDR_CHANGE feature Date: Thu, 11 Aug 2022 16:13:38 -0700 Message-Id: <20220811231338.563794-3-prestwoj@gmail.com> X-Mailer: git-send-email 2.34.3 In-Reply-To: <20220811231338.563794-1-prestwoj@gmail.com> References: <20220811231338.563794-1-prestwoj@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org Adds support in mac80211 for NL80211_EXT_FEATURE_POWERED_ADDR_CHANGE. The motivation behind this functionality is to fix limitations of address randomization on frequencies which are disallowed in world roaming. The way things work now, if a client wants to randomize their address per-connection it must power down the device, change the MAC, and power back up. Here lies a problem since powering down the device may result in frequencies being disabled (until the regdom is set). If the desired BSS is on one such frequency the client is unable to connect once the phy is powered again. For mac80211 based devices changing the MAC while powered is possible but currently disallowed (-EBUSY). This patch adds some logic to allow a MAC change while powered by removing the interface, changing the MAC, and adding it again. mac80211 will advertise support for this feature so userspace can determine the best course of action e.g. disallow address randomization on certain frequencies if not supported. There are certain limitations put on this which simplify the logic: - No active connection - No offchannel work, including scanning. Signed-off-by: James Prestwood --- net/mac80211/iface.c | 67 ++++++++++++++++++++++++++++++++++++++++++-- net/mac80211/main.c | 2 ++ 2 files changed, 67 insertions(+), 2 deletions(-) diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c index 1a9ada411879..7c8772d8427a 100644 --- a/net/mac80211/iface.c +++ b/net/mac80211/iface.c @@ -199,15 +199,73 @@ static int ieee80211_verify_mac(struct ieee80211_sub_if_data *sdata, u8 *addr, return ret; } +static int ieee80211_can_powered_addr_change(struct ieee80211_sub_if_data *sdata) +{ + struct ieee80211_roc_work *roc; + struct ieee80211_local *local = sdata->local; + struct ieee80211_sub_if_data *scan_sdata; + int ret = 0; + + /* To be the most flexible here we want to only limit changing the + * address if the specific interface is doing offchannel work or + * scanning. + */ + if (netif_carrier_ok(sdata->dev)) + return -EBUSY; + + mutex_lock(&local->mtx); + + /* First check no ROC work is happening on this iface */ + list_for_each_entry(roc, &local->roc_list, list) { + if (roc->sdata != sdata) + continue; + + if (roc->started) { + ret = -EBUSY; + goto unlock; + } + } + + /* And if this iface is scanning */ + if (local->scanning) { + scan_sdata = rcu_dereference_protected(local->scan_sdata, + lockdep_is_held(&local->mtx)); + if (sdata == scan_sdata) + ret = -EBUSY; + } + + switch (sdata->vif.type) { + case NL80211_IFTYPE_STATION: + case NL80211_IFTYPE_P2P_CLIENT: + /* More interface types could be added here but changing the + * address while powered makes the most sense in client modes. + */ + break; + default: + return -EOPNOTSUPP; + } + +unlock: + mutex_unlock(&local->mtx); + return ret; +} + static int ieee80211_change_mac(struct net_device *dev, void *addr) { struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); + struct ieee80211_local *local = sdata->local; struct sockaddr *sa = addr; bool check_dup = true; + bool live = false; int ret; - if (ieee80211_sdata_running(sdata)) - return -EBUSY; + if (ieee80211_sdata_running(sdata)) { + ret = ieee80211_can_powered_addr_change(sdata); + if (ret) + return ret; + + live = true; + } if (sdata->vif.type == NL80211_IFTYPE_MONITOR && !(sdata->u.mntr.flags & MONITOR_FLAG_ACTIVE)) @@ -217,7 +275,11 @@ static int ieee80211_change_mac(struct net_device *dev, void *addr) if (ret) return ret; + if (live) + drv_remove_interface(local, sdata); ret = eth_mac_addr(dev, sa); + if (live) + ret = drv_add_interface(local, sdata); if (ret == 0) memcpy(sdata->vif.addr, sa->sa_data, ETH_ALEN); @@ -2128,6 +2190,7 @@ int ieee80211_if_add(struct ieee80211_local *local, const char *name, sdata->u.mgd.use_4addr = params->use_4addr; ndev->features |= local->hw.netdev_features; + ndev->priv_flags |= IFF_LIVE_ADDR_CHANGE; ndev->hw_features |= ndev->features & MAC80211_SUPPORTED_FEATURES_TX; diff --git a/net/mac80211/main.c b/net/mac80211/main.c index 5a385d4146b9..3aeb5e598263 100644 --- a/net/mac80211/main.c +++ b/net/mac80211/main.c @@ -616,6 +616,8 @@ struct ieee80211_hw *ieee80211_alloc_hw_nm(size_t priv_data_len, NL80211_EXT_FEATURE_CONTROL_PORT_OVER_NL80211_TX_STATUS); wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_SCAN_FREQ_KHZ); + wiphy_ext_feature_set(wiphy, + NL80211_EXT_FEATURE_POWERED_ADDR_CHANGE); if (!ops->hw_scan) { wiphy->features |= NL80211_FEATURE_LOW_PRIORITY_SCAN | -- 2.34.3