| Message ID | 20230321231003.3582-1-a@unstable.cc |
|---|---|
| State | Changes Requested |
| Headers |
Return-Path: <openvpn-devel-bounces@lists.sourceforge.net>
Delivered-To: patchwork@openvpn.net
Received: by 2002:a05:7300:2310:b0:9f:bfa4:120f with SMTP id r16csp2769446dye;
Tue, 21 Mar 2023 16:11:16 -0700 (PDT)
X-Google-Smtp-Source:
AK7set8vjjIgLD1sjneVqFgs+lWGCQzVaLdQtFnJLCryAguzF9P639+zQf0yUcT2Ihr4BfQouEAG
X-Received: by 2002:a62:7996:0:b0:5f1:f57a:b0c3 with SMTP id
u144-20020a627996000000b005f1f57ab0c3mr1678068pfc.5.1679440276107;
Tue, 21 Mar 2023 16:11:16 -0700 (PDT)
ARC-Seal: i=1; a=rsa-sha256; t=1679440276; cv=none;
d=google.com; s=arc-20160816;
b=ALdGEvdpbypnj8o6WFVyBZakbRYYuqtscWzyAYO435BllK/7x/+Tg5eiD0akiQQJy/
SCARu7tszx12Ua1+PVrTrwYQJXDv7+z7oTbgsqw1KT3aElbRK58y8bDgwcV8Nmx4jJZa
4WHfghjrJurtuk5m5WcX3eSfMyktnXsdgN9gkv0VtJAgvTkZpt8k9yVNx4VtXVbn+AQM
c9i5v1Nm4bWYLVnKrjjcwE/FvLST9VSoD2jDZ7L6N4BxU1fVAE3w2mnQDT0QOMXGjZwi
C5CJNFBEAhYzl65L8OxptWu7pru9IqlQdQUFiK+l2msTimfJScAVgvZtmeNjOqJRa44g
Na0g==
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=vyVCToJLBBaB4FzqMS3Ig968u9DGPU54zx0Od3kb/H4=;
b=ifdJdnC6rt3QuKUTlJm9eIs07UxfmT1M/gUXtPbpMoPo/WmLWJIjn157ZPGtJL6xkW
wFHiIl795VJHnhOwSSYCWP+Gxbah6k5jf+ix5NrdFAHuhOIB5nh3wxT7SkM1VM1vboiE
WOF0is9xK7hEliYLE7b85O72+do9g0rcPvNBdpCfMj6Qqg/hqVQjFeZr/G8b2lzJ2o0l
+6Sw07dOYasZsPDfdhBrRfsO6AIIM2ontseX1SjmoUq8tYD6DHlCLw73nPsjqpedV8HS
F7TRFydwRIAOpyRLQLjSkOCxSOfNPbHnlWBMNvD7lR04u5Qi4zUixOV4uY2SwsQBFe9d
bQSA==
ARC-Authentication-Results: i=1; mx.google.com;
dkim=neutral (body hash did not verify) header.i=@sourceforge.net
header.s=x header.b=i9QZ8Ijh;
dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x
header.b=hq3EDykA;
dkim=fail header.i=@unstable.cc header.s=20220809-q8oc
header.b=NwM+Pdz9;
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
x9-20020aa79a49000000b006260aac226csi13629776pfj.369.2023.03.21.16.11.15
(version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128);
Tue, 21 Mar 2023 16:11:16 -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=i9QZ8Ijh;
dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x
header.b=hq3EDykA;
dkim=fail header.i=@unstable.cc header.s=20220809-q8oc
header.b=NwM+Pdz9;
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 <openvpn-devel-bounces@lists.sourceforge.net>)
id 1pel7V-0006wn-6e;
Tue, 21 Mar 2023 23:10:21 +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 <a@unstable.cc>) id 1pel7P-0006wZ-DT
for openvpn-devel@lists.sourceforge.net;
Tue, 21 Mar 2023 23:10:16 +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=kJAjBEFSQpVhLf3C0BjJ/dt3aQNVWWUPb45B3KF5wA8=; b=i9QZ8Ijhdcgec1Hnemve0Jyug4
kNITDCl3XdwTuBVdl/4TXHUvmgwxBfDRJVnZLhsgyA70516L6BTknwXUXwmYTVRE37NEJ5+9QqGoL
z52+EPINNYTsJbuaXgb/gdEoMJU93dKLT9HSYllMQmh/pi1KeTnD/p6XbJGr1FugVsio=;
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=kJAjBEFSQpVhLf3C0BjJ/dt3aQNVWWUPb45B3KF5wA8=; b=h
q3EDykAmeiCwypRDivnXQOZ7VLqhgKFqAWLPxyPyhZeOjANtoY8+2DRFRbMsLqPbKvZv9EU0dnMm2
/lLW3XfYBdTD+XUUwvEHm1SYzs2Qevcd1ysPJpYgggEC+INAH6dhs18KUl0gOA9CKhW3Yng4DkDr0
T68EsYBE6KH3uK38=;
Received: from mailout-l3b-97.contactoffice.com ([212.3.242.97])
by sfi-mx-1.v28.lw.sourceforge.com with esmtps
(TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95)
id 1pel7N-00Fzrj-Nk for openvpn-devel@lists.sourceforge.net;
Tue, 21 Mar 2023 23:10:15 +0000
Received: from smtpauth2.co-bxl (smtpauth2.co-bxl [10.2.0.24])
by mailout-l3b-97.contactoffice.com (Postfix) with ESMTP id 8762F543;
Wed, 22 Mar 2023 00:10:06 +0100 (CET)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1679440206;
s=20220809-q8oc; d=unstable.cc; i=a@unstable.cc;
h=From:To:Cc:Subject:Date:Message-Id:MIME-Version:Content-Transfer-Encoding;
l=1835; bh=kJAjBEFSQpVhLf3C0BjJ/dt3aQNVWWUPb45B3KF5wA8=;
b=NwM+Pdz9GJeviCIuToT4zl+iJ2PqhpaD1EvJsATP8zNP6grd4xKyAUcp6KT7yDZ+
/uCvm/jJgUEwDc/ovqfJDalkk1xuJzjFA3IqRLaz0C/3aY9X6Er07dAQfhhFqZOmTkT
cNDrXTxtS8AdFfRU1gKoo8ad2cwf6YngOk1+XQVkSGcn3l+LfLRNW1jkFv+dzr3CcuJ
mHUa5qv3JQG1zbHtaMbQybqEbGWaGgNfO+TxX4k62Uk0xwYQToKO8brHMaE+6BvV4Z2
aj1HMoyuKoc00RsS3jDFg/dJobCBfyfQksWUuNbnM66Avz6eqZSSHkUsJ4WCcxFh4p+
Xp46rHNQ/g==
Received: by smtp.mailfence.com with ESMTPSA ;
Wed, 22 Mar 2023 00:10:04 +0100 (CET)
From: Antonio Quartulli <a@unstable.cc>
To: openvpn-devel@lists.sourceforge.net
Date: Wed, 22 Mar 2023 00:10:03 +0100
Message-Id: <20230321231003.3582-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.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.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_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: 1pel7N-00Fzrj-Nk
Subject: [Openvpn-devel] [PATCH] 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: <openvpn-devel.lists.sourceforge.net>
List-Unsubscribe: <https://lists.sourceforge.net/lists/options/openvpn-devel>,
<mailto:openvpn-devel-request@lists.sourceforge.net?subject=unsubscribe>
List-Archive:
<http://sourceforge.net/mailarchive/forum.php?forum_name=openvpn-devel>
List-Post: <mailto:openvpn-devel@lists.sourceforge.net>
List-Help: <mailto:openvpn-devel-request@lists.sourceforge.net?subject=help>
List-Subscribe: <https://lists.sourceforge.net/lists/listinfo/openvpn-devel>,
<mailto:openvpn-devel-request@lists.sourceforge.net?subject=subscribe>
Cc: Kristof Provost <kp@netgate.com>, Antonio Quartulli <a@unstable.cc>
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Errors-To: openvpn-devel-bounces@lists.sourceforge.net
X-getmail-retrieved-from-mailbox: Inbox
X-GMAIL-THRID: =?utf-8?q?1761020767180542442?=
X-GMAIL-MSGID: =?utf-8?q?1761020767180542442?=
|
| Series |
[Openvpn-devel] dco_freebsd: use m->instances[] instead of m->hash
|
|
Commit Message
Antonio Quartulli
March 21, 2023, 11:10 p.m. UTC
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 <kp@netgate.com>
Change-Id: I8d8af6f872146604a9710edf443db65df48ac3cb
Signed-off-by: Antonio Quartulli <a@unstable.cc>
---
NOTE: not tested because I have no FreeBSD environment and I
can't find how to kick off the buildbot
---
src/openvpn/dco_freebsd.c | 22 +++++-----------------
1 file changed, 5 insertions(+), 17 deletions(-)
Comments
Hi, On 22/03/2023 00:10, Antonio Quartulli wrote: > 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 <kp@netgate.com> If the patch is suitable for merging, please change the above to kp@FreeBSD.org before moving on. Cheers, > Change-Id: I8d8af6f872146604a9710edf443db65df48ac3cb > Signed-off-by: Antonio Quartulli <a@unstable.cc> > --- > NOTE: not tested because I have no FreeBSD environment and I > can't find how to kick off the buildbot > --- > src/openvpn/dco_freebsd.c | 22 +++++----------------- > 1 file changed, 5 insertions(+), 17 deletions(-) > > diff --git a/src/openvpn/dco_freebsd.c b/src/openvpn/dco_freebsd.c > index 225b3cf8..ae8c1380 100644 > --- a/src/openvpn/dco_freebsd.c > +++ b/src/openvpn/dco_freebsd.c > @@ -674,27 +674,15 @@ 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))) > + struct multi_instance *mi = m->instances[peer_id]; > + if (!mi) > { > - 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_INFO, "Peer %d 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
Am 22.03.23 um 00:10 schrieb Antonio Quartulli: > 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. > Acked-By: Arne Schwabe <arne@rfc2549.org> Arne
Hi, On Wed, Mar 22, 2023 at 12:10:03AM +0100, Antonio Quartulli wrote: > + struct multi_instance *mi = m->instances[peer_id]; > + if (!mi) > { This (and undoubtedly the same code in dco_linux.c) is trusting the kernel to never return peer_id values that are outside the array boundaries. Is this what we want? I'd strongly prefer to have a check like this here if ((peer_id < m->max_clients) && (m->instances[peer_id])) { ... } (which is what we do in multi_process_incoming_dco(), for example) Note: in p2p mode, peer-id is something random, usually much bigger than max_clients - now this *should* never be called in p2p mode, but I still do not have a good feeling without the bounds check. gert
Hi, On 22/03/2023 08:14, Gert Doering wrote: > Hi, > > On Wed, Mar 22, 2023 at 12:10:03AM +0100, Antonio Quartulli wrote: >> + struct multi_instance *mi = m->instances[peer_id]; >> + if (!mi) >> { > > This (and undoubtedly the same code in dco_linux.c) is trusting the > kernel to never return peer_id values that are outside the array > boundaries. very good catch. > > Is this what we want? no. we should not trust an external source. Will send v2 for this and v3 for dco-linux > > I'd strongly prefer to have a check like this here > > if ((peer_id < m->max_clients) && (m->instances[peer_id])) > { > ... > } > > (which is what we do in multi_process_incoming_dco(), for example) > > > Note: in p2p mode, peer-id is something random, usually much bigger > than max_clients - now this *should* never be called in p2p mode, but > I still do not have a good feeling without the bounds check. > > gert
diff --git a/src/openvpn/dco_freebsd.c b/src/openvpn/dco_freebsd.c index 225b3cf8..ae8c1380 100644 --- a/src/openvpn/dco_freebsd.c +++ b/src/openvpn/dco_freebsd.c @@ -674,27 +674,15 @@ 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))) + struct multi_instance *mi = m->instances[peer_id]; + if (!mi) { - 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_INFO, "Peer %d 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