From patchwork Tue Nov 15 16:55:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andre Heider X-Patchwork-Id: 1704199 X-Patchwork-Delegate: hauke@hauke-m.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.openwrt.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=4zXZNrhW; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=STgFdHsW; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4NBXRR4j5hz23mh for ; Wed, 16 Nov 2022 03:57:39 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:To :From:Reply-To:Cc:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=WKHbjvTsc+Z7j1VRaU3DFaAPDTweBnp7NuaPMk+J43c=; b=4zXZNrhWVhy1md 5oKgzgsgWA7vT73U4YkUR9n46R3Bik3+SZE1kNaPIHlN45wsDyXwSBq2C5jFDk3x1Dkh9Yt4duCGQ 6hcH8mHZZbT3x1/WqFLB/XY3ssYHAlRr5oG28bLaBF918Pcn9kWsVzEl//0ceTKokJJgN4ZupL7/U weuLF/aXfw2LkGBV9cQnYJoVfctiyd94iqNPC5JApR1w32Q43TCZiH7ss9US2Uo4y8zm5O5UQlvXH eR5juWX6rED88kH8Rd8mLRj58D9StgIWI3HOjY2OIuykRIv6C8eviBbXxUxUxOq33BZ1LePvTqZe+ IvIbscvsdu2nvuAwv4lQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ouzDc-00DHCi-OQ; Tue, 15 Nov 2022 16:55:29 +0000 Received: from mail-ej1-x62d.google.com ([2a00:1450:4864:20::62d]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1ouzDX-00DH9p-U3 for openwrt-devel@lists.openwrt.org; Tue, 15 Nov 2022 16:55:25 +0000 Received: by mail-ej1-x62d.google.com with SMTP id bj12so37486441ejb.13 for ; Tue, 15 Nov 2022 08:55:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=anm8yNseiH5g7cY0NpLCNlw0aXODK8OaE4HEL7x5Myc=; b=STgFdHsWjvZEXd2c0n8GXUiATwVgfwhHF4f6U1ejAQEfUjYLkB4BRhkZJap4NJ6ZfJ mFatsJFHq6yEnX2vipPF2FAMITpTdZw0NjLdnpTh8hFz2Nn0kgl3yG3NRCwJR+x58I1b MXqtJuQVIoRn5SB1Yh8Rbgmnc4+dbNwm8Tpet+eFJZ4ebJOJQajdzG9YAo3UJj3MDNt2 ySR6QCCYiiATKFzOjiUxhm599e8+WtiQYnN9s3tP+++USiDo0BvbYYh4MEt8KDCNEW0b vJD0GM2JUCBAcXEQ1OWQzbhs6n7bqWjWE56OXrceEJBguXXGDFZSJHhCiNOKBc+FviYY SH0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=anm8yNseiH5g7cY0NpLCNlw0aXODK8OaE4HEL7x5Myc=; b=EbryMng/dn17eUL2f2lVaG6qglxkZtRqbg4MhnTwX82A9sj+SKv2+ySgPULzgOEL09 RzbT0LmhgBcUlVySXuxPydevOtoIXkVsgIoMg6GA6f2d6jiYHAdGFPH8RBvJpue9mEbC a3azbv9MU3NIOt44UUA/8kdmwE08mLTqYlEOEFOPGYLYjQ/KZ3oI/k+1XaoXdwiw3lTN BZ0D/iOHYTS6rOr1Jclsj3UGjvG5tWOqnYNiV4OO/amhNaHEUW6qoZO2AXGTIkA+4uPX 1lY8jVFaKgbxQV1ZmnWih7I7MKXn1K516IL/uc9HvKtjcMpQjXbkShv6ozijCxyOc5qp 3+xg== X-Gm-Message-State: ANoB5pmfrnEV4qjVeWpphDPXJ548Zaz+uGWhUN2MiT5RjGFwQ3+OEKo9 E/y9pcpmxrU4iIC+QwNkhgLMZcM7U9Y= X-Google-Smtp-Source: AA0mqf6b/GmX+3AR1XLnpuMJIqn8xhnamrvdfrK8bvGcB6eyK4VoRP4WPFI/3IgbIkBFX89yVUo9xA== X-Received: by 2002:a17:906:ae47:b0:78d:a871:737c with SMTP id lf7-20020a170906ae4700b0078da871737cmr14465268ejb.597.1668531320283; Tue, 15 Nov 2022 08:55:20 -0800 (PST) Received: from mamamia.internal (a89-182-186-105.net-htp.de. [89.182.186.105]) by smtp.gmail.com with ESMTPSA id q17-20020a170906a09100b0077909095acasm5791615ejy.143.2022.11.15.08.55.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Nov 2022 08:55:19 -0800 (PST) From: Andre Heider To: openwrt-devel@lists.openwrt.org Subject: [PATCH 1/2] iwinfo: nl80211: don't guess if a name is an ifname Date: Tue, 15 Nov 2022 17:55:17 +0100 Message-Id: <20221115165518.1667524-1-a.heider@gmail.com> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221115_085523_999287_C7E33AF1 X-CRM114-Status: GOOD ( 12.45 ) X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: It's too slow to do it all over again and again, especially with e.g. luci constantly polling. Before: $ time iwinfo phy0 info real 0m 0.54s $ time iwinfo radio0 info real 0m 0.70s $ time ubus call luci-rpc getWirelessDevices real 0m 0.67s Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:62d listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [a.heider[at]gmail.com] -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org It's too slow to do it all over again and again, especially with e.g. luci constantly polling. Before: $ time iwinfo phy0 info real 0m 0.54s $ time iwinfo radio0 info real 0m 0.70s $ time ubus call luci-rpc getWirelessDevices real 0m 0.67s After: $ time iwinfo phy0 info real 0m 0.04s $ time iwinfo radio0 info real 0m 0.09s $ time ubus call luci-rpc getWirelessDevices real 0m 0.17s Signed-off-by: Andre Heider --- iwinfo_nl80211.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/iwinfo_nl80211.c b/iwinfo_nl80211.c index 77fddee..77a65ed 100644 --- a/iwinfo_nl80211.c +++ b/iwinfo_nl80211.c @@ -22,6 +22,7 @@ * Parts of this code are derived from the Linux iw utility. */ +#include #include #include #include @@ -411,6 +412,15 @@ out: return idx; } +static bool nl80211_is_ifname(const char *name) +{ + struct stat st; + char buffer[PATH_MAX]; + + snprintf(buffer, sizeof(buffer), "/sys/class/net/%s", name); + return !lstat(buffer, &st); +} + static struct nl80211_msg_conveyor * nl80211_msg(const char *ifname, int cmd, int flags) { @@ -426,10 +436,9 @@ static struct nl80211_msg_conveyor * nl80211_msg(const char *ifname, if (!strncmp(ifname, "mon.", 4)) ifidx = if_nametoindex(&ifname[4]); - else + else if (nl80211_is_ifname(ifname)) ifidx = if_nametoindex(ifname); - - if (!ifidx) { + else { phyidx = nl80211_phy_idx_from_phy(ifname); if (phyidx < 0) phyidx = nl80211_phy_idx_from_uci(ifname);