From patchwork Wed Mar 22 19:27:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antonio Quartulli X-Patchwork-Id: 3153 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:7300:2310:b0:9f:bfa4:120f with SMTP id r16csp3452457dye; Wed, 22 Mar 2023 12:28:21 -0700 (PDT) X-Google-Smtp-Source: AK7set+e8EuE8L4crCRGtPVC3Etk4SDO3YONyzqRl1Xip7c1SWv/JEUPyHuqIi61h1AC9wDKP6AB X-Received: by 2002:a62:17c3:0:b0:627:e2a5:be16 with SMTP id 186-20020a6217c3000000b00627e2a5be16mr3828717pfx.6.1679513301126; Wed, 22 Mar 2023 12:28:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679513301; cv=none; d=google.com; s=arc-20160816; b=ChGCrsPkDHXJohNaRP5ybaNBgG+uLEiQ9ZaKz8PwIV7qOU98VEncqwg4IUZjcRG0wE XdAmQf22hRT+NJdvPWnViRWpHEtoLc4+3NKlpIWmMIO0JZ/3LbmqMgaZur11o9Tx40B/ s+IhWcfzVwtHYEH052nHdW9WBvyWkGAbmlu/RdsGAIhbRgnggDKn3FWrZS+PBUNNBopu 368jlYC9GCGcKUrtCPLEph4+/UqZTLaXP7W1KKtk70m8aLmRKX+ZlYjiDsKdIlCCmNEe j8f24AT3acOAToizbjVvpU9Z7GZf93MgGZtMtGESoLyqszzjJQgHdAZreTJB5yKGHZU+ gXbA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:content-transfer-encoding:cc:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence:subject :mime-version:message-id:date:to:from:dkim-signature:dkim-signature :dkim-signature; bh=plai36EsHXtpR2cgqX6eu4EjQ3cHlQ0ITOFBkhaVHYs=; b=v5MZC06IwM69PxQ0vMhJx+QPdvRoKrJp0srAs2o6Qar+V9r19woK+KrD8Nh47Vm8ys cj3I0ndeLuAKjtOTiT8i2dKO4LRKn15fOJwAfIGxZGAjjKnGdANSJOZzvmXIIzZOski/ aH7UqxMj2ZOI8VYJWqTv5GS+VGmUM1V14Gfxa1Lnx5m8glKkzEhNR/KpZogOOlKkEXM+ JTz0KBi3BGzAy/+91qkdCX4qpX3MrL0E09X65INnT8BPfrfOBlLWQwr43Dz3arHTF1w5 /2F0rV5KaIxCurtuzK99lEZeJYINjYX6u0mWYBKvlOZiDRbfzdXCB3mI3i3Ozndr9mzs rWVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=VbI+cYlG; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=V1uHVEEz; dkim=fail header.i=@unstable.cc header.s=20220809-q8oc header.b=kQEQrQjo; spf=pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) smtp.mailfrom=openvpn-devel-bounces@lists.sourceforge.net Received: from lists.sourceforge.net ([216.105.38.7]) by mx.google.com with ESMTPS id x7-20020aa79567000000b005a8851e7559si15709028pfq.256.2023.03.22.12.28.20 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 22 Mar 2023 12:28:21 -0700 (PDT) Received-SPF: pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) client-ip=216.105.38.7; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=VbI+cYlG; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=V1uHVEEz; dkim=fail header.i=@unstable.cc header.s=20220809-q8oc header.b=kQEQrQjo; spf=pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) smtp.mailfrom=openvpn-devel-bounces@lists.sourceforge.net Received: from [127.0.0.1] (helo=sfs-ml-2.v29.lw.sourceforge.com) by sfs-ml-2.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1pf47q-0007KK-3D; Wed, 22 Mar 2023 19:27:58 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-2.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1pf47p-0007K1-6n for openvpn-devel@lists.sourceforge.net; Wed, 22 Mar 2023 19:27:57 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=fHnbifJ8Qynuy3GQpcXrAvijKNLBna4/ySbfnrC3TSE=; b=VbI+cYlGMudgLY4bUJj2/xz41+ S0x7KrSHpQv+yz1CL76gUf9x899aI836wcrSiAc9RAmgCDuBf0mN2gXjNZlQpUSv8b4ip7tCSYa+b Hl6pRhO22ZY4mGLZyWJGF6071fZJR+50WigT5SA56n4I1HKCZJ9VUAKrofpI6lDWMV7Q=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:Message-Id:Date:Subject:Cc:To:From :Sender:Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Id:List-Help:List-Unsubscribe:List-Subscribe:List-Post: List-Owner:List-Archive; bh=fHnbifJ8Qynuy3GQpcXrAvijKNLBna4/ySbfnrC3TSE=; b=V 1uHVEEzzCK4MAAhMUGMxJ8dlc7G/D4slZInBBJNJq9wsHsAvjYzllM7wbCgoBpWGDJm870slf+KtH npD9iup7FRPn4nbO2aaYPIA4elfMliRQtphL5CjF3Jj/5Ipll4X293zXB4nSN7RViPTL5A+KxeqBt 6g0ZZNUGTMk4iOG0=; Received: from mailout-l3b-97.contactoffice.com ([212.3.242.97]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1pf47h-0000h6-RS for openvpn-devel@lists.sourceforge.net; Wed, 22 Mar 2023 19:27:57 +0000 Received: from smtpauth2.co-bxl (smtpauth2.co-bxl [10.2.0.24]) by mailout-l3b-97.contactoffice.com (Postfix) with ESMTP id AA776A10; Wed, 22 Mar 2023 20:27:39 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1679513259; s=20220809-q8oc; d=unstable.cc; i=a@unstable.cc; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version:Content-Transfer-Encoding; l=1939; bh=fHnbifJ8Qynuy3GQpcXrAvijKNLBna4/ySbfnrC3TSE=; b=kQEQrQjoHjMjP/HwtykeF6y6o1wayagcAm7AECfqcQdhsS1CpwWZmkr4wfu+vAir 6NjuRz8rk7ZKUqZwZW+iK1qVEi7+yXaNbEQOO8IBfJHyIj9d5oYmD4isfJejKp1bXxx tfF65qFrmksxHJZpR0/WQoVXHnmW6MLei9bJS62t53JY8tbDFjyLavRSomZdvdATQpd ru5CuhuDGGL96EuqekNJKpcJgeL+i5YAHb9D78hobPw1BroNkFprD1RMAbnywH0CXVP FPsGKS9CP1jFXOfuWLLyA9sHSPdKgJthXeAR+jLtkoJSFolA97V/UP6NqLzgvhB9K+t mQNazQVeOw== Received: by smtp.mailfence.com with ESMTPSA ; Wed, 22 Mar 2023 20:27:36 +0100 (CET) From: Antonio Quartulli To: openvpn-devel@lists.sourceforge.net Date: Wed, 22 Mar 2023 20:27:33 +0100 Message-Id: <20230322192733.20295-1-a@unstable.cc> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-Spam-Flag: NO X-Spam-Status: No, hits=-2.9 required=4.7 symbols=ALL_TRUSTED, BAYES_00 device=10.2.0.21 X-ContactOffice-Account: com:375058688 X-Spam-Score: -0.9 (/) X-Spam-Report: Spam detection software, running on the system "util-spamd-2.v13.lw.sourceforge.com", 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: When retrieving the multi_instance of a specific peer, there is no need to peform a linear search across the whole m->hash list. We can directly access the needed object via m->instances[peer-id] in c [...] Content analysis details: (-0.9 points, 6.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at https://www.dnswl.org/, low trust [212.3.242.97 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.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-Headers-End: 1pf47h-0000h6-RS Subject: [Openvpn-devel] [PATCH v3] dco-freebsd: use m->instances[] instead of m->hash X-BeenThere: openvpn-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Antonio Quartulli Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox X-GMAIL-THRID: =?utf-8?q?1761062037740799904?= X-GMAIL-MSGID: =?utf-8?q?1761097339223728384?= When retrieving the multi_instance of a specific peer, there is no need to peform a linear search across the whole m->hash list. We can directly access the needed object via m->instances[peer-id] in constant time (and just one line of code). Adapt the dco-freebsd code to do so. Cc: Kristof Provost Change-Id: I8d8af6f872146604a9710edf443db65df48ac3cb Signed-off-by: Antonio Quartulli --- NOTE: not tested because I have no FreeBSD environment Changes from v1: * added boundary check on peer-id Changes from v2: * use one check only instead of two --- src/openvpn/dco_freebsd.c | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/src/openvpn/dco_freebsd.c b/src/openvpn/dco_freebsd.c index 225b3cf8..54ec16ff 100644 --- a/src/openvpn/dco_freebsd.c +++ b/src/openvpn/dco_freebsd.c @@ -674,27 +674,18 @@ dco_event_set(dco_context_t *dco, struct event_set *es, void *arg) static void dco_update_peer_stat(struct multi_context *m, uint32_t peerid, const nvlist_t *nvl) { - struct hash_element *he; - struct hash_iterator hi; - hash_iterator_init(m->hash, &hi); - - while ((he = hash_iterator_next(&hi))) + if (peer_id >= m->max_clients || !m->instances[peer_id]) { - struct multi_instance *mi = (struct multi_instance *) he->value; - - if (mi->context.c2.tls_multi->peer_id != peerid) - { - continue; - } - - mi->context.c2.dco_read_bytes = nvlist_get_number(nvl, "in"); - mi->context.c2.dco_write_bytes = nvlist_get_number(nvl, "out"); - + msg(M_WARN, "Cannot store DCO stats for peer %u", + peerid); return; } - msg(M_INFO, "Peer %d returned by kernel, but not found locally", peerid); + struct multi_instance *mi = m->instances[peer_id]; + + mi->context.c2.dco_read_bytes = nvlist_get_number(nvl, "in"); + mi->context.c2.dco_write_bytes = nvlist_get_number(nvl, "out"); } int