From patchwork Wed Mar 22 10:06:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antonio Quartulli X-Patchwork-Id: 3147 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:7300:2310:b0:9f:bfa4:120f with SMTP id r16csp3070399dye; Wed, 22 Mar 2023 03:07:15 -0700 (PDT) X-Google-Smtp-Source: AK7set8q/QqbI5YEPBSLlsEINYsmtyHww8Ve1hRUOcqaFB6ryZVCg952JE82J+/OqFTzKVoU1Lkv X-Received: by 2002:a05:6a20:4c91:b0:d9:3aa9:20e3 with SMTP id fq17-20020a056a204c9100b000d93aa920e3mr4326923pzb.0.1679479635120; Wed, 22 Mar 2023 03:07:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679479635; cv=none; d=google.com; s=arc-20160816; b=mmviD6bbF2mBwcpzkZppfIncVWV0jxYdP7VI2Y5R5Pqg8yfbF2Rm/fFmdbq6/6qJtR miYbWYtx4PKq6LFfm8XY7RTQX//R1jkDevIqH0pyRfUwExCtiXy/HJm0pQL0H8cN36Q3 lt9h3GPJKxR4xGIhINjVkX5id8WFWAJnHXhlAauuxSNGKFW+BaP41ZxAHkLpkBZd06kK 7jJJ88Yzb9CpmSOoqNLUEK/gI7e0I5mjV47gZFU6D76IZ9+7HWQTY5TrLxNB81K3rPzL TtvJVpeaZeuaSlwYei3FVY8S3SrTcQ1v2XNoa3WL7iuBzZK99V/LW1EmkoBdk+MeTSuP Sj3Q== 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:references:in-reply-to:message-id:date:to:from :dkim-signature:dkim-signature:dkim-signature; bh=2roLAGlWN1kSV/R6we5qEGoEy9bXCNFTWehV9qVobSg=; b=jDmq5uNXXvXtRDpb8GUMuccpGa+ICWHcipspCbCoIvYRB91Z+v7h5I+fO0FZGi8/7I +FDEVL44b/TQAb/kZwWCFsktsCjJPcr82IpEnmaYpkhtQcub2D5Az+KsvUt1XUIOHj+3 upp1vo+An6gMfI0LDaLG/xzqov7d1A2fIwDSJbs5a0O5xJodJO72AbtR8KlioXoJv9vR oKcosop8ecWe0I9Krj+LoTyVNjRVU3SeyowZtFJtc9GwycFNL3IXMeu7X2D9HQ66BYta Secs/2CIkFNz/iGDwpcgm+PfucW2AN6X3ObRXXkZjt5+TuIOpFgDhOUZGn3a5HUZauP1 PkJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=Jq5ELyHY; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=MAHkEtin; dkim=fail header.i=@unstable.cc header.s=20220809-q8oc header.b=mTdBgJYN; 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 m128-20020a632686000000b005030e1ccafdsi17456219pgm.69.2023.03.22.03.07.14 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 22 Mar 2023 03:07:15 -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=Jq5ELyHY; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=MAHkEtin; dkim=fail header.i=@unstable.cc header.s=20220809-q8oc header.b=mTdBgJYN; 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-4.v29.lw.sourceforge.com) by sfs-ml-4.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1pevMi-0006IY-MN; Wed, 22 Mar 2023 10:06:46 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-4.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1pevMh-0006IR-0o for openvpn-devel@lists.sourceforge.net; Wed, 22 Mar 2023 10:06:45 +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:References: In-Reply-To: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:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=4JvgTggFNYsnUQQ9miJSKwt08JydaqLo7lWOLruPJxc=; b=Jq5ELyHYiRU0XdGWM0SSDLZnfZ bXUyakZh1l/c0HY/9j2D9SecmFe/Huuuqbx42h2BaeFJ3Ng7z7lHoRZu5rmueeoc/4INdQwNnCeTm D86EonYCDZFg14sics0RtcO2ZDz5VrY4C6iIMeDHSC/AtCn3bcKmmb0E06iRGJXuBt/Q=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: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:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=4JvgTggFNYsnUQQ9miJSKwt08JydaqLo7lWOLruPJxc=; b=MAHkEtinx4fPJ2IM4ucCS1DUhc NPwG3y5dYj3J84ooM54CZr1S++oXwLq8VBa8sk9Ynq7jwJ/TeCxRJb1heSpAK2xV/GTvOTeuXYDdQ BWcwSTz44J4ULvlsCuAOk2y3ykJsTOK0vq1p6C/Z74ceIOX+qXmeKG099f4K1ifd9dPQ=; Received: from wilbur.contactoffice.com ([212.3.242.68]) by sfi-mx-1.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1pevMc-00GQeZ-AL for openvpn-devel@lists.sourceforge.net; Wed, 22 Mar 2023 10:06:44 +0000 Received: from smtpauth2.co-bxl (smtpauth2.co-bxl [10.2.0.24]) by wilbur.contactoffice.com (Postfix) with ESMTP id EEEE1B5E; Wed, 22 Mar 2023 11:06:31 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1679479591; s=20220809-q8oc; d=unstable.cc; i=a@unstable.cc; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; l=2004; bh=4JvgTggFNYsnUQQ9miJSKwt08JydaqLo7lWOLruPJxc=; b=mTdBgJYNKLau0OtmIxvQ1kD7rJFGXIHAXHUQSafYjb0FHuYlyhiV/H7OJI4SHioN rIrOaJzqrY14qblh+s9z7zH6zS6cBN0TbTLngu8YWn7mbpAyFA9iXdDZh7u9X0P6v2/ jHmeCF4Vf7tKNgx3+dZW3JP00q2SEI9IgsMmQlkBbSf7iUTpLpwHONvKhUZaxZKzBsI pazkvL1xLOV36ohafn1/wkc24pKS0eIhOoCvopKGHe2wbHyMyyNdVWRBhHSDVdKJ3K5 ivNJ28ENuS60nsIDD1rU5LYG+7KXjHtJYJe1VeU96l+TXklpxboGW8uqQYKdiPuXUhK 9/tkIluUZQ== Received: by smtp.mailfence.com with ESMTPSA ; Wed, 22 Mar 2023 11:06:29 +0100 (CET) From: Antonio Quartulli To: openvpn-devel@lists.sourceforge.net Date: Wed, 22 Mar 2023 11:06:09 +0100 Message-Id: <20230322100610.14234-1-a@unstable.cc> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230321231003.3582-1-a@unstable.cc> References: 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.20 X-ContactOffice-Account: com:375058688 X-Spam-Score: -0.9 (/) X-Spam-Report: Spam detection software, running on the system "util-spamd-1.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.68 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_EF Message has a valid DKIM or DK signature from envelope-from 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_AU Message has a valid DKIM or DK signature from author's domain X-Headers-End: 1pevMc-00GQeZ-AL Subject: [Openvpn-devel] [PATCH v2] 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: Kristof Provost , 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?1761062037740799904?= 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 --- src/openvpn/dco_freebsd.c | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/src/openvpn/dco_freebsd.c b/src/openvpn/dco_freebsd.c index 225b3cf8..ec93eb61 100644 --- a/src/openvpn/dco_freebsd.c +++ b/src/openvpn/dco_freebsd.c @@ -674,27 +674,24 @@ 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; + struct multi_instance *mi; - hash_iterator_init(m->hash, &hi); - - while ((he = hash_iterator_next(&hi))) + if (peer_id >= m->max_clients) { - 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 retrieve stats for peer %u. ID is invalid (out of bound)!", + peerid); + return; + } + mi = m->instances[peer_id]; + if (!mi) + { + msg(M_INFO, "Peer %u returned by kernel, but not found locally", peerid); return; } - msg(M_INFO, "Peer %d returned by kernel, but not found locally", peerid); + mi->context.c2.dco_read_bytes = nvlist_get_number(nvl, "in"); + mi->context.c2.dco_write_bytes = nvlist_get_number(nvl, "out"); } int