From patchwork Fri Jul 23 11:09:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo-Andres Hofmann X-Patchwork-Id: 4555 Return-Path: Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384 client-signature ECDSA (P-384) client-digest SHA384) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by web04.haj.ipfire.org (Postfix) with ESMTPS id 4GWRRv00Bfz3xGr for ; Fri, 23 Jul 2021 11:10:02 +0000 (UTC) Received: from mail02.haj.ipfire.org (mail02.haj.ipfire.org [172.28.1.201]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384 client-signature ECDSA (P-384) client-digest SHA384) (Client CN "mail02.haj.ipfire.org", Issuer "R3" (verified OK)) by mail01.ipfire.org (Postfix) with ESMTPS id 4GWRRs3RVCz27x; Fri, 23 Jul 2021 11:10:01 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4GWRRs0z0Gz2xkW; Fri, 23 Jul 2021 11:10:01 +0000 (UTC) Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384 client-signature ECDSA (P-384) client-digest SHA384) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by mail02.haj.ipfire.org (Postfix) with ESMTPS id 4GWRRr3Mz8z2xS9 for ; Fri, 23 Jul 2021 11:10:00 +0000 (UTC) Received: from arche.uberspace.de (arche.uberspace.de [185.26.156.147]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mail01.ipfire.org (Postfix) with ESMTPS id 4GWRRk6wCRzwx for ; Fri, 23 Jul 2021 11:09:54 +0000 (UTC) Received: (qmail 21329 invoked from network); 23 Jul 2021 11:09:53 -0000 Received: from localhost (HELO localhost) (127.0.0.1) by arche.uberspace.de with SMTP; 23 Jul 2021 11:09:53 -0000 From: Leo-Andres Hofmann To: development@lists.ipfire.org Subject: [PATCH] network-functions.pl: Improve wifi_get_link_quality Date: Fri, 23 Jul 2021 13:09:42 +0200 Message-Id: <20210723110942.679-1-hofmann@leo-andres.de> X-Mailer: git-send-email 2.27.0.windows.1 MIME-Version: 1.0 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=lists.ipfire.org; s=202003rsa; t=1627038595; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=KmNg8M+K0dmg0u7CjTI4uSY8nZRNXiqeavnVbWtHzz4=; b=oiP1F6UzfZIRH5ur4Y8BVtzucPKEpmfdVukF19ATJqB1gMzkdcXjfZ5WwpLLgNzEhaB9St 3s1mn9Hd8IvXssa1Ts/f5VJevv9I5paCctFub2ZV3Ggp6nnJYH0dqQQquoNBmzYoIa+f5K UUF6SQDb8hcw0hkZtIExmhdFgTumuJ6gC3V/qCbmzPnBbDBns9zgxRNvvkXMMGYvINK0Fu ACAQbiocC0UyynUznSFzklQznMlTcrAyXy/6L7FYxP5K/HabPlBW/4uwY3waXEjvvRNztw tnpNh+5kQb8GWjDycqjw83o3soEGbW//W9w8EvUFmdwkwB5l/xkCCZjRqPeEDA== ARC-Seal: i=1; s=202003rsa; d=lists.ipfire.org; t=1627038595; a=rsa-sha256; cv=none; b=iYhL8ySDbBBcoYDOOiK1EdOecrgEwDYs2BdKuffyFJ5re28uUZ6hbUoZnwQYa6Kf/qoR2o jntWMdNafyfb0L8r9TLF6vd8ktMaUiZg+hMilpSSGbE2v7+o4MkY3Dz+jUbLM7NzQPr4UP rAc64j0Zz8U1H1+DKs4FMCYKBJCUi0Hi3UQOuimwwytfGvrsr6m5329u7mfSaNYd6T8Ms+ Lfxcb8y94Yd7Ze+vv3bLuofx7mMeFQ1sJ5DxjybslRD41yapxZDcR9S6zMNmuHTRBZn5GY XJoCJFybFkpvKc4ZqABD/pCLDP04SoIelUHWE97l0NZJoosl0VC/uYYJulnOgQ== ARC-Authentication-Results: i=1; mail01.ipfire.org; dkim=none; spf=pass (mail01.ipfire.org: domain of hofmann@leo-andres.de designates 185.26.156.147 as permitted sender) smtp.mailfrom=hofmann@leo-andres.de X-Rspamd-Queue-Id: 4GWRRk6wCRzwx Authentication-Results: mail01.ipfire.org; dkim=none; dmarc=none; spf=pass (mail01.ipfire.org: domain of hofmann@leo-andres.de designates 185.26.156.147 as permitted sender) smtp.mailfrom=hofmann@leo-andres.de X-Rspamd-Server: mail01.haj.ipfire.org X-Spamd-Result: default: False [0.94 / 11.00]; MX_INVALID(0.50)[]; R_MISSING_CHARSET(2.50)[]; IP_REPUTATION_HAM(-0.48)[asn: 205766(-0.13), country: DE(-0.01), ip: 185.26.156.147(-0.34)]; TO_DN_NONE(0.00)[]; BROKEN_CONTENT_TYPE(1.50)[]; R_SPF_ALLOW(-0.20)[+mx]; ARC_SIGNED(0.00)[lists.ipfire.org:s=202003rsa:i=1]; FROM_EQ_ENVFROM(0.00)[]; R_DKIM_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; ASN(0.00)[asn:205766, ipnet:185.26.156.0/24, country:DE]; RCVD_TLS_LAST(0.00)[]; BAYES_HAM(-3.00)[99.99%]; ARC_NA(0.00)[]; FROM_HAS_DN(0.00)[]; SPF_REPUTATION_HAM(-0.78)[-0.77916322830469]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; DMARC_NA(0.00)[leo-andres.de]; RCPT_COUNT_ONE(0.00)[1]; MID_CONTAINS_FROM(1.00)[]; RCVD_COUNT_TWO(0.00)[2] X-BeenThere: development@lists.ipfire.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: IPFire development talk List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: development-bounces@lists.ipfire.org Sender: "Development" iwconfig doesn't return values for "Link Quality" if the interface is disconnected, causing a division by zero error. If there are odd values, the resulting percentage may contain many decimal places. This patch makes wifi_get_link_quality return zero instead of failing and rounds the percentage to a more meaningful integer. Signed-off-by: Leo-Andres Hofmann Reviewed-by: Michael Tremer --- config/cfgroot/network-functions.pl | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/config/cfgroot/network-functions.pl b/config/cfgroot/network-functions.pl index b7a840559..c0abc76b5 100644 --- a/config/cfgroot/network-functions.pl +++ b/config/cfgroot/network-functions.pl @@ -403,7 +403,11 @@ sub wifi_get_link_quality($) { my ($cur, $max) = $status =~ /Link Quality=(\d+)\/(\d+)/; - return $cur * 100 / $max; + if($max > 0) { + return sprintf('%.0f', ($cur * 100) / $max); + } + + return 0; } sub wifi_get_signal_level($) {