| Message ID | 20230323080341.51624-1-gert@greenie.muc.de |
|---|---|
| State | Accepted |
| 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 r16csp3807271dye;
Thu, 23 Mar 2023 01:16:25 -0700 (PDT)
X-Google-Smtp-Source:
AK7set/OdSsZJiDhJzisH9y4pCfibmg3D/+NQYSKiT1Xc6Ew+abAzkX/9ihKQeUe0UYHdSfxIMNV
X-Received: by 2002:a62:5bc2:0:b0:627:ea7a:ff46 with SMTP id
p185-20020a625bc2000000b00627ea7aff46mr5520849pfb.16.1679559385131;
Thu, 23 Mar 2023 01:16:25 -0700 (PDT)
ARC-Seal: i=1; a=rsa-sha256; t=1679559385; cv=none;
d=google.com; s=arc-20160816;
b=GaHUQztiJ2N7Qgo3t1kFaH9MzxIQqygoUxU4W1NYh7ia9YA9927fl6fuTGblGIcBzq
Eoq16d0SvNAIs+k+QpGU0W74eKyobNOswOiv680vL49uq1ZHCiKR8Ez1LKrlb4AqQmyz
mmwSan7BmxFU4rK2EIXiGdsyTX4b4J4XD6JhULPwu8hOwtCe/3iHkpVSCWJh6wtRj0n/
WLaFfWcRaXJtdHL645qP34ErKYO3mstLFs8fSTTT03Y3jTtsAAT4KSCr9u/CjrT2lIat
V3odgoyxjh93vLs1vonjwTkrqzwXDcfcdveAkiHiuvlVu62GrOzhYV2VfqnPoxiLa8RR
k0Wg==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com;
s=arc-20160816;
h=errors-to:content-transfer-encoding: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;
bh=5KQZtE9nm/hjDyONFAEGdrNqXTsEw4gfHfVnyRUpKEw=;
b=Qst/Qft/g1zRJ5SQIdIOlXVK0gS3XhYJE/8HrnP7kw/0uJuNJJ/pnQLxxIJhWgrCD0
6HP9MuYzvHspJQMNO/xV9cpxlHpyjIR4PvYHH5H9DyHh5O39NbvOQKefHlNMpE8DyJDz
2UMgJp/eN6eiuOifjzoJNQsgJ0wU7VuTyrnS52mTOzBDfbK7EGKbqAFOHAmky5Tyf6w+
P4zGdWCLLB4riVuOXtQfFXsPmEyy1mCmdeJeGLwzGfQQGBJXXRowqnDjDVZglNIvO2BL
6Yoa8ImVGt8j3dosAeguy9UXhs7qvS339ySpV0A004Eob5AG9dYeNdefvqiGEYNDy+a0
DIEg==
ARC-Authentication-Results: i=1; mx.google.com;
dkim=neutral (body hash did not verify) header.i=@sourceforge.net
header.s=x header.b=g5TVIiBD;
dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x
header.b=Zq9RFkxp;
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
s13-20020a63924d000000b0050f5a18f73asi14077518pgn.754.2023.03.23.01.16.24
(version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128);
Thu, 23 Mar 2023 01:16:25 -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=g5TVIiBD;
dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x
header.b=Zq9RFkxp;
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-1.v29.lw.sourceforge.com)
by sfs-ml-1.v29.lw.sourceforge.com with esmtp (Exim 4.95)
(envelope-from <openvpn-devel-bounces@lists.sourceforge.net>)
id 1pfG77-0000Y2-MO;
Thu, 23 Mar 2023 08:16:02 +0000
Received: from [172.30.20.202] (helo=mx.sourceforge.net)
by sfs-ml-1.v29.lw.sourceforge.com with esmtps (TLS1.2) tls
TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95)
(envelope-from <gert@fbsd14.ov.greenie.net>) id 1pfG75-0000Wn-LV
for openvpn-devel@lists.sourceforge.net;
Thu, 23 Mar 2023 08:16:00 +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:To:From:Sender:Reply-To:Cc: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=+3dy8vDm7fD7aNL6NjuaHmh803bLCqWn7d9TYsQNJkk=; b=g5TVIiBDf5WGjVsRWs/Z1Tnna/
EsPlB2JkUunhE12lFGTstyGQQInlYVDcdTYpKsOQCb3QlTV9ninJsAeUOaTiPWnAj16/NigzuiV04
nmkoR0FI0JiERuB4EWowNaPhIh/py2TrwhwBVT7/O+nkSDK39GJJRWCksC91DiKfd918=;
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:To:From:Sender:Reply-To:Cc: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=+3dy8vDm7fD7aNL6NjuaHmh803bLCqWn7d9TYsQNJkk=; b=Zq9RFkxpWmeyUNos741gB0p1S+
4PXlsniouEDeUY7+ptSv62KIqWbWH1rCjeGv2IxLE8fCz7C/Ofgis3e+yYxhvPT+VglZwb4/k2WzU
fcL9KtcmQ/pzkQjYgNSHJd43udCKG6AxQooVcxzj14upRRxTIZa87lqBs41axWU9eses=;
Received: from vmail1.greenie.net ([195.30.8.66])
by sfi-mx-2.v28.lw.sourceforge.com with esmtps
(TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95)
id 1pfG74-0007TQ-Rb for openvpn-devel@lists.sourceforge.net;
Thu, 23 Mar 2023 08:16:00 +0000
Received: from fbsd14.ov.greenie.net (fbsd14.ov.greenie.net
[IPv6:2001:608:0:814:0:0:fb00:14])
by vmail1.greenie.net (8.17.1/8.16.1) with ESMTP id 32N83gEd057780
for <openvpn-devel@lists.sourceforge.net>;
Thu, 23 Mar 2023 09:03:42 +0100 (CET)
Received: from gert (uid 1001) (envelope-from gert@fbsd14.ov.greenie.net)
id c1db9 by fbsd14.ov.greenie.net (DragonFly Mail Agent v0.13+ on
fbsd14.ov.greenie.net); Thu, 23 Mar 2023 09:03:42 +0100
From: Gert Doering <gert@greenie.muc.de>
To: openvpn-devel@lists.sourceforge.net
Date: Thu, 23 Mar 2023 09:03:41 +0100
Message-Id: <20230323080341.51624-1-gert@greenie.muc.de>
X-Mailer: git-send-email 2.39.2
In-Reply-To: <20230322192733.20295-1-a@unstable.cc>
References: <20230322192733.20295-1-a@unstable.cc>
MIME-Version: 1.0
X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.4
(vmail1.greenie.net [IPv6:2001:608:1:995a:20c:29ff:feb8:10eb]);
Thu, 23 Mar 2023 09:03:42 +0100 (CET)
X-Spam-Score: -2.0 (--)
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: From: Antonio Quartulli <a@unstable.cc> 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: (-2.0 points, 6.0 required)
pts rule name description
---- ----------------------
--------------------------------------------------
0.2 HEADER_FROM_DIFFERENT_DOMAINS From and EnvelopeFrom 2nd level
mail domains are different
-2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/,
medium trust [195.30.8.66 listed in list.dnswl.org]
0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record
0.0 SPF_NONE SPF: sender does not publish an SPF Record
0.0 UNPARSEABLE_RELAY Informational: message has unparseable relay
lines
X-Headers-End: 1pfG74-0007TQ-Rb
Subject: [Openvpn-devel] [PATCH v4] 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>
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?1761062037740799904?=
X-GMAIL-MSGID: =?utf-8?q?1761145662237268138?=
|
| Series |
[Openvpn-devel,v4] dco-freebsd: use m->instances[] instead of m->hash
|
|
Commit Message
Gert Doering
March 23, 2023, 8:03 a.m. UTC
From: Antonio Quartulli <a@unstable.cc> 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. v4: use "peerid" everywhere as that's what FreeBSD does, change message text Cc: Kristof Provost <kp@FreeBSD.org> Change-Id: I8d8af6f872146604a9710edf443db65df48ac3cb Signed-off-by: Antonio Quartulli <a@unstable.cc> --- src/openvpn/dco_freebsd.c | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-)
Comments
Hi, On 23/03/2023 09:03, Gert Doering wrote: > From: Antonio Quartulli <a@unstable.cc> > > 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. > > v4: use "peerid" everywhere as that's what FreeBSD does, change message text > > Cc: Kristof Provost <kp@FreeBSD.org> > Change-Id: I8d8af6f872146604a9710edf443db65df48ac3cb > Signed-off-by: Antonio Quartulli <a@unstable.cc> > --- > src/openvpn/dco_freebsd.c | 22 ++++++---------------- > 1 file changed, 6 insertions(+), 16 deletions(-) > > diff --git a/src/openvpn/dco_freebsd.c b/src/openvpn/dco_freebsd.c > index 225b3cf8..a334d5d2 100644 > --- a/src/openvpn/dco_freebsd.c > +++ b/src/openvpn/dco_freebsd.c > @@ -674,27 +674,17 @@ 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 (peerid >= m->max_clients || !m->instances[peerid]) > { > - 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, "dco_update_peer_stat: invalid peer ID %d returned by kernel", peerid); I'd prefer to use __func__ here, but it is noted that dco_freebsd.c seldomly uses this approach. For this reason I think hardcoding the function name is fine for now. Later on we can do a full cleanup. > return; > } > > - msg(M_INFO, "Peer %d returned by kernel, but not found locally", peerid); > + struct multi_instance *mi = m->instances[peerid]; > + > + mi->context.c2.dco_read_bytes = nvlist_get_number(nvl, "in"); > + mi->context.c2.dco_write_bytes = nvlist_get_number(nvl, "out"); > } > > int This patch is basically my v3 with the peerid fixed and the message changed. I can't ACK since this patch bears my own signature, but I am fine with the applied modification. Cheers,
Am 23.03.23 um 09:03 schrieb Gert Doering: > From: Antonio Quartulli <a@unstable.cc> > > 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. > > v4: use "peerid" everywhere as that's what FreeBSD does, change message text > > Cc: Kristof Provost <kp@FreeBSD.org> > Change-Id: I8d8af6f872146604a9710edf443db65df48ac3cb > Signed-off-by: Antonio Quartulli <a@unstable.cc> > --- > src/openvpn/dco_freebsd.c | 22 ++++++---------------- > 1 file changed, 6 insertions(+), 16 deletions(-) > > diff --git a/src/openvpn/dco_freebsd.c b/src/openvpn/dco_freebsd.c > index 225b3cf8..a334d5d2 100644 > --- a/src/openvpn/dco_freebsd.c > +++ b/src/openvpn/dco_freebsd.c > @@ -674,27 +674,17 @@ 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 (peerid >= m->max_clients || !m->instances[peerid]) > { > - 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, "dco_update_peer_stat: invalid peer ID %d returned by kernel", peerid); > return; > } > > - msg(M_INFO, "Peer %d returned by kernel, but not found locally", peerid); > + struct multi_instance *mi = m->instances[peerid]; > + > + mi->context.c2.dco_read_bytes = nvlist_get_number(nvl, "in"); > + mi->context.c2.dco_write_bytes = nvlist_get_number(nvl, "out"); > } > > int Acked-By: Arne Schwabe <arne@rfc2549.org>
As this patch has a bit of mixed history "who wrote it, who ACKed it,
what happened afterwards" I decided to record the ACK from Arne and
Kristof.
v4 has been tested on FreeBSD with DCO enabled, p2mp udp server, one client
being connected all the time and the other client reconnecting (moving
between peer-id 1 and 2), packets going back and forth, looking at the
resulting counters. Everything looked as expected.
(This is basically an optimization that was discussed in November
already but nobody followed up on it - and with the upcoming Linux DCO
counter patches, the topic "why use iterator when you have an array?"
resurfaced - thanks, Antonio, for covering FreeBSD too)
Your patch has been applied to the master and release/2.6 branch.
commit 03145f223236df90b35d1db444319fd3f785792b (master)
commit 5acefd944c6a8a4338b5105ffe6b9ffce6bad330 (release/2.6)
Author: Antonio Quartulli
Date: Thu Mar 23 09:03:41 2023 +0100
dco-freebsd: use m->instances[] instead of m->hash
Signed-off-by: Antonio Quartulli <a@unstable.cc>
Acked-by: Arne Schwabe <arne@rfc2549.org>
Acked-by: Kristof Provost <kp@freebsd.org>
Message-Id: <20230323080341.51624-1-gert@greenie.muc.de>
URL: https://www.mail-archive.com/search?l=mid&q=20230323080341.51624-1-gert@greenie.muc.de
Signed-off-by: Gert Doering <gert@greenie.muc.de>
--
kind regards,
Gert Doering
diff --git a/src/openvpn/dco_freebsd.c b/src/openvpn/dco_freebsd.c index 225b3cf8..a334d5d2 100644 --- a/src/openvpn/dco_freebsd.c +++ b/src/openvpn/dco_freebsd.c @@ -674,27 +674,17 @@ 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 (peerid >= m->max_clients || !m->instances[peerid]) { - 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, "dco_update_peer_stat: invalid peer ID %d returned by kernel", peerid); return; } - msg(M_INFO, "Peer %d returned by kernel, but not found locally", peerid); + struct multi_instance *mi = m->instances[peerid]; + + mi->context.c2.dco_read_bytes = nvlist_get_number(nvl, "in"); + mi->context.c2.dco_write_bytes = nvlist_get_number(nvl, "out"); } int