| Message ID | 20221214164824.172-1-lstipakov@gmail.com |
|---|---|
| State | Superseded |
| Headers |
Return-Path: <openvpn-devel-bounces@lists.sourceforge.net>
Delivered-To: patchwork@openvpn.net
Received: by 2002:a05:622a:418d:b0:3a5:7962:c21f with SMTP id
cd13csp402810qtb;
Wed, 14 Dec 2022 08:49:07 -0800 (PST)
X-Google-Smtp-Source:
AA0mqf6/A1JMVFxmQ8/HQPP2DDa33rKhUpBX3bDPdYv6gLrvziEOMI3+XBx1mVEDYCc/fIzF67rc
X-Received: by 2002:a17:902:f785:b0:188:b800:3335 with SMTP id
q5-20020a170902f78500b00188b8003335mr29594778pln.67.1671036547327;
Wed, 14 Dec 2022 08:49:07 -0800 (PST)
ARC-Seal: i=1; a=rsa-sha256; t=1671036547; cv=none;
d=google.com; s=arc-20160816;
b=NTMmkiyGeLZLa6v8OToXCwcWJtvd5j7KNKgfwVW45Mq+BkHZ6UetOlWUjozLNlB/jg
lgi2qLqDsI5pOZeB1fkNMgyAhUHPdR0dD4nBbgQXGMEGPHfmJAfBEUmpJAs12FsSEibK
oJ9+M/kCtULU1ouu0GBWbuEtnE5ZxWq1TYyY5wFI1uGtg/p04CeUhbeEmnsYBqadwcOX
OsXoKt5+t3eHkcU0EKKh/aGbmBmSI790h7qsSuuhssQphDGgevnyqP0PucstRaPoYBpg
gB15b++e1p6V0Ev0fRracWIWJDNc0NEdZH98gCKxlj79O5yhMwigApwaRy7OwIQlOgKZ
4v6g==
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=+BSz8xFVo3ck0M386Vkin5B+gGEJ/fzr1sBizLl6l8A=;
b=eqmXG9nGVSml8HOh62KrZf5Cz1jGu8kHyzZkdncpn9+tTzY6MNYdf11dgzWm4GRzua
0fBrBOAkwR9h7r4I1+1hd1q35OtOTEYUKpFoyYlr7TAex+5heYaLYRhDswPtJPuS6jYu
IrK9bL6cg0ZBAuR81VRFVrSa+AEuT/mgJ70PCmIXFN+P+nqDT9kzvQo0+emhcJ6D8uff
FRTJvBtZnevN8Z5bhzp4GFQXqk1RTmD0Hr4GjcmU1GlsOgvzli82bRW7MJIb9LwY4YIi
ULOkJjOYB/iEj7ajn4kExQ/HkNSfxmkb57pxPcBA5zQRCNwzzf92najlFN6YPUA68D5b
gUNw==
ARC-Authentication-Results: i=1; mx.google.com;
dkim=neutral (body hash did not verify) header.i=@sourceforge.net
header.s=x header.b=eQ1sDIf3;
dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x
header.b=HXXcOp98;
dkim=neutral (body hash did not verify) header.i=@gmail.com
header.s=20210112 header.b=Sv5jXCVP;
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;
dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com
Received: from lists.sourceforge.net (lists.sourceforge.net. [216.105.38.7])
by mx.google.com with ESMTPS id
n8-20020a170902e54800b0018907d64909si3436482plf.325.2022.12.14.08.49.07
(version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128);
Wed, 14 Dec 2022 08:49:07 -0800 (PST)
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=eQ1sDIf3;
dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x
header.b=HXXcOp98;
dkim=neutral (body hash did not verify) header.i=@gmail.com
header.s=20210112 header.b=Sv5jXCVP;
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;
dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com
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 <openvpn-devel-bounces@lists.sourceforge.net>)
id 1p5Uw3-0004pE-0s;
Wed, 14 Dec 2022 16:48:47 +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 <lstipakov@gmail.com>) id 1p5Uw2-0004p8-0i
for openvpn-devel@lists.sourceforge.net;
Wed, 14 Dec 2022 16:48:46 +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=DqXMs8It/xCBvMyE19MX7c23b1UxWWwqI+rYJyyP+ak=; b=eQ1sDIf3cgScHKCfWAq5557cbY
SAnjxAGZr2cdn6728wtU8tyG77LQ5l1a3iieTx+zS7hQIPJE+GxHvs0QfNvTl68hfwQrkGaY4Tgpt
fjXlO6jcdrGVtpFVA33w5bi9Be/wL6vzPBwcbnm67zobhVBz6I5aVXU0MrubTmqf/ooc=;
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=DqXMs8It/xCBvMyE19MX7c23b1UxWWwqI+rYJyyP+ak=; b=H
XXcOp98PiyN2oP78uw9R1NbslfTatkxxCQSAwShzaJjiO03w0OsAlg9UAaR/a70yuwIXsnFJL1Dve
RtwjJ/xgYXHKZVGucDtxzhpzjGdfDwvgDU1emaF1MWVt+iSiKI/1KlTnY2XKO24CHVYuVpDpudXiR
4WbisG/azmias08g=;
Received: from mail-lf1-f54.google.com ([209.85.167.54])
by sfi-mx-2.v28.lw.sourceforge.com with esmtps
(TLS1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.95)
id 1p5Uw1-00064p-8X for openvpn-devel@lists.sourceforge.net;
Wed, 14 Dec 2022 16:48:45 +0000
Received: by mail-lf1-f54.google.com with SMTP id y25so11407383lfa.9
for <openvpn-devel@lists.sourceforge.net>;
Wed, 14 Dec 2022 08:48:45 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112;
h=content-transfer-encoding:mime-version:message-id:date:subject:cc
:to:from:from:to:cc:subject:date:message-id:reply-to;
bh=DqXMs8It/xCBvMyE19MX7c23b1UxWWwqI+rYJyyP+ak=;
b=Sv5jXCVPI8wz/nbyM7+B03Gzzd0/z71qN6rJSht9UXkU+E+wYCfh3V8KAwkuZ+DhkG
D0vpniJgQp2hkISZfy4gPK7usMGjtyNqKKoxWyxUqSQhO/ubWxdyQTquJRVxQtoOVCOe
IUPyPKCxHhUKC0lkXMx+4k3uHDful3JRQwaCbLPqZTFkWzYzkUIy/ZQ+twxt/RhprIl/
4kqssrpK2blIuyNtx8kr6hJBNfALwG7mEPEZDIuWIEhi+R374XetR0KqqqX/uMG6Jzmw
SWLeEJOfkaDUmyWpIKoHztwQq4e8/NLaktyPATaJoJ0EJ6WNHAXUCmhgs23un6feBWja
xlNw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20210112;
h=content-transfer-encoding:mime-version:message-id:date:subject:cc
:to:from:x-gm-message-state:from:to:cc:subject:date:message-id
:reply-to;
bh=DqXMs8It/xCBvMyE19MX7c23b1UxWWwqI+rYJyyP+ak=;
b=5fT42XU/Z5+0cz8TC53kuAcUZuaPBO30mO/D6w8+t2xF6H4Pn98E+8Q1tqlP0SrU8+
qGCSYlJkf/udH/b+K6tUsnMpeL912IrS6igzac3kKJGDgemS1vqOI0/xUY8vSXBEZ7+W
1M76FRcHwcql6euy3v9FTlFsyKmhBAXjnqMnwg/b3jwN7XdkTUdL7pK1Cpj0EWxzbLjq
Mz9G76+6S9/NPLAyoaOlBwj8yb5SrTk3ar1r2TCJq9Rx3xld8x37WrFKNkDPG4oFunF5
n4B813BxfftasxL/ZMPtsniuX9HtZuRRJGfCxZgdtqy4Y145NkP7TfQUh0umNG+tuEi4
Am2A==
X-Gm-Message-State: ANoB5pns0iqVQkwPY3TukZDT7z62N+2NNt7jGJMIv53utq48XsENNgcf
pinSZhFD4WWDsSYWNnq6vd7Bcra+prE=
X-Received: by 2002:a05:6512:b81:b0:4a4:68b9:66bf with SMTP id
b1-20020a0565120b8100b004a468b966bfmr9671414lfv.10.1671036518334;
Wed, 14 Dec 2022 08:48:38 -0800 (PST)
Received: from LAPTOP-4L3N7KFS.localdomain (81-175-157-115.bb.dnainternet.fi.
[81.175.157.115]) by smtp.gmail.com with ESMTPSA id
j1-20020a056512344100b004b48cc444ccsm879330lfr.100.2022.12.14.08.48.37
(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
Wed, 14 Dec 2022 08:48:37 -0800 (PST)
From: Lev Stipakov <lstipakov@gmail.com>
To: openvpn-devel@lists.sourceforge.net
Date: Wed, 14 Dec 2022 18:48:24 +0200
Message-Id: <20221214164824.172-1-lstipakov@gmail.com>
X-Mailer: git-send-email 2.34.1
MIME-Version: 1.0
X-Spam-Score: -0.2 (/)
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: Lev Stipakov dco_get_peer_stats fetches stats for a
single peer. This is mostly useful in client mode. So far only Windows
implements
that. Signed-off-by: Lev Stipakov --- src/openvpn/dco.h | 13 +++++++++++++
src/openvpn/dco_freebsd.c | 7 +++++++ src/openvpn/dco_linux.c | 7 +++++++
src/openvpn/dco_win.c | 28 ++++++++++++++++++++++++++++ [...]
Content analysis details: (-0.2 points, 6.0 required)
pts rule name description
---- ----------------------
--------------------------------------------------
-0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/,
no trust [209.85.167.54 listed in list.dnswl.org]
0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record
-0.0 SPF_PASS SPF: sender matches SPF record
0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail
provider [lstipakov[at]gmail.com]
-0.0 RCVD_IN_MSPIKE_H2 RBL: Average reputation (+2)
[209.85.167.54 listed in wl.mailspike.net]
-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
-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
X-Headers-End: 1p5Uw1-00064p-8X
Subject: [Openvpn-devel] [PATCH] Introduce dco_get_peer_stats API and
Windows implementation
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: Lev Stipakov <lev@openvpn.net>
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?1752208818666694775?=
X-GMAIL-MSGID: =?utf-8?q?1752208818666694775?=
|
| Series |
[Openvpn-devel] Introduce dco_get_peer_stats API and Windows implementation
|
|
Commit Message
Lev Stipakov
Dec. 14, 2022, 4:48 p.m. UTC
From: Lev Stipakov <lev@openvpn.net> dco_get_peer_stats fetches stats for a single peer. This is mostly useful in client mode. So far only Windows implements that. Signed-off-by: Lev Stipakov <lev@openvpn.net> --- src/openvpn/dco.h | 13 +++++++++++++ src/openvpn/dco_freebsd.c | 7 +++++++ src/openvpn/dco_linux.c | 7 +++++++ src/openvpn/dco_win.c | 28 ++++++++++++++++++++++++++++ src/openvpn/manage.c | 9 +++++++-- 5 files changed, 62 insertions(+), 2 deletions(-)
Comments
Hi, On Wed, Dec 14, 2022 at 11:49 AM Lev Stipakov <lstipakov@gmail.com> wrote: > From: Lev Stipakov <lev@openvpn.net> > > dco_get_peer_stats fetches stats for a single peer. This is mostly > useful in client mode. So far only Windows implements that. > Good to see this happening.. Do you have a link to a build including this patch for a quick test? Does this data from the driver include both control and data channel bytes? Right now what the GUI receives as bytecount is not zero, I suppose the daemon is reporting the control channel traffic. By the way: + msg(M_WARN | M_ERRNO, "DeviceIoControl(OVPN_IOCTL_SET_PEER) failed"); That would be OVPN_IOCTL_GET_STATS Selva
Hi, > Good to see this happening.. Turns out there is a bug in the driver at the moment - it doesn't update OUT bytes. This particular API hasn't been used in a while. > Does this data from the driver include both control and data channel bytes? Yes, at the moment those are "link" bytes and they include both control and data channels. > Right now what the GUI receives as bytecount is not zero, I suppose the daemon is reporting the control channel traffic. Yes. I will fix it in the driver so that it reports only data channel bytes, since control channel bytes are already counted in userspace. > That would be OVPN_IOCTL_GET_STATS Let me send v2 with fixed error message text and produce an MSI with the driver fixes.
Hi, On Wed, Dec 14, 2022 at 2:06 PM Lev Stipakov <lstipakov@gmail.com> wrote: > > > Right now what the GUI receives as bytecount is not zero, I suppose the > daemon is reporting the control channel traffic. > > Yes. I will fix it in the driver so that it reports only data channel > bytes, since control channel bytes are already counted in userspace. This data will also show up as stats on the adapter (device node) and should include all traffic that passes through it, no? The userspace reporting can handle either approach as long as all dco platforms count stats the same way. Selva
> This data will also show up as stats on the adapter (device node) and should include all traffic that passes through it, no? System adapter stats show only tun traffic - the one driver indicates to NetAdapter. For BYTECOUNT we (userspace client) currently show link traffic - encapsulated control and data packets. > The userspace reporting can handle either approach as long as all dco platforms count stats the same way. On Windows control packets are handled by userspace via link read/write routines (which use device handle from CreateFile). Both FreeBSD and Linux implementations use additional, netlink-based (or FreeBSD analogue) channel to send/receive control packets, so existing link read/write routines are not called (except initial handshake, before socket handover to kernel) and therefore stats for control packets are not duplicated.
Hi, On Wed, Dec 14, 2022 at 10:50:19PM +0200, Lev Stipakov wrote: > On Windows control packets are handled by userspace via link > read/write routines (which use device handle from CreateFile). Both > FreeBSD and Linux implementations use additional, netlink-based (or > FreeBSD analogue) channel to send/receive control packets, > so existing link read/write routines are not called (except initial > handshake, before socket handover to kernel) and therefore stats for > control packets are not duplicated. FreeBSD uses standard socket read/write calls for control packets. The "tunnel control packets through the ioctl() interface" method was never used by the kernel and will be removed from OpenVPN in kp's 4/4 patch (to be merged soon). But since the FreeBSD kernel does not count control packets (I've been told that it "sniffs" the socket and only removes "interesting" packets, the rest is passed through to userland - so control packets are not handled by kernel), there is no duplication. No idea about the Linux details... Antonio? gert
Hi, Selva has asked about a build which includes this patch. Here is MSI installer which incorporates required client patches - management: add timer to output BYTECOUNT - Introduce dco_get_peer_stats API and Windows implementation and a new driver version (0.8.3) with stats fixes. https://github.com/lstipakov/openvpn-build/actions/runs/3699097077 -Lev
Hi, On Wed, Dec 14, 2022 at 1:55 PM Selva Nair <selva.nair@gmail.com> wrote: > Hi, > > On Wed, Dec 14, 2022 at 11:49 AM Lev Stipakov <lstipakov@gmail.com> wrote: > >> From: Lev Stipakov <lev@openvpn.net> >> >> dco_get_peer_stats fetches stats for a single peer. This is mostly >> useful in client mode. So far only Windows implements that. >> > > Good to see this happening.. Do you have a link to a build including this > patch for a quick test? > At last I built this and gave it a quick test including the patch for management i/f. Also used the latest dco-win driver (0.8.3) with the stats fixes. I see two issues: (1) Bytes out for data are still not getting reported -- I see a small number even after transferring large amount of data indicating only control channel bytes shown (2) On reconnect, the stats revert back to what looks like the accumulated control channel stats. As if the stats in the driver is getting reset. This happens even on SIGUSR1 restart which can happen automatically on auth-failure token expiry, for example. Selva P.S. I couldn't compare this with the non-dco behaviour as it seems reconnecting with the wintun adapter is no longer working -- I get all wintun adapters are currently in use error on reconnect while a disconnect/connect fixes it. This is unrelated -- will test further and report separately.
Hi On Wed, Dec 14, 2022 at 6:09 PM Lev Stipakov <lstipakov@gmail.com> wrote: > Hi, > > Selva has asked about a build which includes this patch. > > Here is MSI installer which incorporates required client patches > > - management: add timer to output BYTECOUNT > - Introduce dco_get_peer_stats API and Windows implementation > > and a new driver version (0.8.3) with stats fixes. > > https://github.com/lstipakov/openvpn-build/actions/runs/3699097077 Thanks. Tested again using this. Ignore my previous comment about Out bytes not reported. Something must be wrong with my build --- this one shows in and out bytes correctly. But the problem with data getting reset on reconnect is real. Selva
More on the data channel traffic stats getting reset on reconnect: >> Here is MSI installer which incorporates required client patches >> >> - management: add timer to output BYTECOUNT >> - Introduce dco_get_peer_stats API and Windows implementation >> >> and a new driver version (0.8.3) with stats fixes. >> >> https://github.com/lstipakov/openvpn-build/actions/runs/3699097077 > > > Thanks. > > Tested again using this. Ignore my previous comment about Out bytes not > reported. Something must be wrong with my build --- this one shows in and > out bytes correctly. But the problem with data getting reset on > reconnect is real. > In non-dco use, the stats as persisted by the management interface are not reset throughout the lifetime of the process. With dco, what the driver provides is "Peer Stats" which is reset in OvpnPeerNew() (linux appears to do the same). A quick option would be to move the zero-ing to OvpnEvtFileCleanup() which, I guess, would work at least when persist-tun is in use. Or in a new callback that gets called on tun-open. But then it wont be strictly "Peer Stats". Otherwise we need a way to add the current data channel stats to the accumulated control-channel stats just before SIGUSR1 and SIGHUP. Or learn to live with the new paradigm. Selva >
Hi, > In non-dco use, the stats as persisted by the management interface are not reset throughout the lifetime of the process. With dco, what the driver provides is "Peer Stats" which is reset in OvpnPeerNew() (linux appears to do the same). A quick option > would be to move the zero-ing to OvpnEvtFileCleanup() which, I guess, would work at least when persist-tun is in use. Yeah, without persist-tun client closes the handle, which triggers OvpnEvtFileCleanup(), which would reset stats. > Or in a new callback that gets called on tun-open. But then it wont be strictly "Peer Stats". Yeah that might be an option, to have RESET_STATS ioctl. Also I wonder if the driver could remember, say, the last pid, and then reset stats on NEW_PEER if pid != last pid. Since pids are recycled, we might "leak" stats in unfortunate cases, but that's okay I guess?
Hi, On 15/12/2022 10:31, Lev Stipakov wrote: > Hi, > >> In non-dco use, the stats as persisted by the management interface are not reset throughout the lifetime of the process. With dco, what the driver provides is "Peer Stats" which is reset in OvpnPeerNew() (linux appears to do the same). A quick option > would be to move the zero-ing to OvpnEvtFileCleanup() which, I guess, would work at least when persist-tun is in use. > > Yeah, without persist-tun client closes the handle, which triggers > OvpnEvtFileCleanup(), which would reset stats. > >> Or in a new callback that gets called on tun-open. But then it wont be strictly "Peer Stats". > > Yeah that might be an option, to have RESET_STATS ioctl. > > Also I wonder if the driver could remember, say, the last pid, and > then reset stats on NEW_PEER if pid != last pid. Since pids are > recycled, we might "leak" stats in unfortunate cases, but that's okay > I guess? > Sorry for jumping in the discussion a bit late. IMHO the stats belong to the Peer object. Let's not forget that, apart from windows, DCO supports multi-peer mode, therefore we have to consider that case as well. Due to the above, I'd "reset" the stats when a new peer object is instantiated. Basically when a new peer object is instantiated it should come with empty stats, as expected. If the desired behvaiour in userspace is to keep the stats persistent across a number of events, it should simply be userspace to keep those stats. This way we don't mix up the logic of counting the bytes per peer, and keeping a general picture of the VPN process. Cheers,
Hi, On Thu, Dec 15, 2022 at 5:15 AM Antonio Quartulli <a@unstable.cc> wrote: > Hi, > > On 15/12/2022 10:31, Lev Stipakov wrote: > > Hi, > > > >> In non-dco use, the stats as persisted by the management interface are > not reset throughout the lifetime of the process. With dco, what the driver > provides is "Peer Stats" which is reset in OvpnPeerNew() (linux appears to > do the same). A quick option > would be to move the zero-ing to > OvpnEvtFileCleanup() which, I guess, would work at least when persist-tun > is in use. > > > > Yeah, without persist-tun client closes the handle, which triggers > > OvpnEvtFileCleanup(), which would reset stats. > Currently its worse than that -- stats is reset in OvpnNewPeer() which would happen (I guess) even if the tun handle is not closed. My suggestion was to move it to OvpnEvtFileCleanup() which will help those who use persist-tun. But all that is moot based on Antonio's explanation below -- this is Peer Stats, not adapter stats, so it has to reset as it is done now... I was treating it like the stats in a network interface which would be reset only on rare events lke adapter reset or driver update or reboot. > > > >> Or in a new callback that gets called on tun-open. But then it wont be > strictly "Peer Stats". > > > > Yeah that might be an option, to have RESET_STATS ioctl. > > > > Also I wonder if the driver could remember, say, the last pid, and > > then reset stats on NEW_PEER if pid != last pid. Since pids are > > recycled, we might "leak" stats in unfortunate cases, but that's okay > > I guess? > > > > Sorry for jumping in the discussion a bit late. > > IMHO the stats belong to the Peer object. > Let's not forget that, apart from windows, DCO supports multi-peer mode, > therefore we have to consider that case as well. > > Due to the above, I'd "reset" the stats when a new peer object is > instantiated. Basically when a new peer object is instantiated it should > come with empty stats, as expected. > > If the desired behvaiour in userspace is to keep the stats persistent > across a number of events, it should simply be userspace to keep those > stats. > > This way we don't mix up the logic of counting the bytes per peer, and > keeping a general picture of the VPN process. > Good point. I was late to realize that Peer Stats has to remain as it is to make sense in multi-peer scenarios. In that case we'll have to find a way to persist the stats across NEW_PEER controls within the client process. Possibly we can merge the current patch for openvpn.exe and then improve it later in bug-fix releases of 2.6? Selva
Hi, On Thu, Dec 15, 2022 at 07:49:53AM -0500, Selva Nair wrote: > Possibly we can merge the current patch > for openvpn.exe and then improve it later in bug-fix releases of 2.6? This was my thinking as well - so the patch is in, and provides at least some statistics, and room for improvements :-) gert
Hi, On 15/12/2022 13:55, Gert Doering wrote: > Hi, > > On Thu, Dec 15, 2022 at 07:49:53AM -0500, Selva Nair wrote: >> Possibly we can merge the current patch >> for openvpn.exe and then improve it later in bug-fix releases of 2.6? > > This was my thinking as well - so the patch is in, and provides at > least some statistics, and room for improvements :-) Yeah, this was the best course of action in my opinion as well. Cheers,
diff --git a/src/openvpn/dco.h b/src/openvpn/dco.h index 9a34d5b6..866aa0fb 100644 --- a/src/openvpn/dco.h +++ b/src/openvpn/dco.h @@ -235,6 +235,13 @@ void dco_delete_iroutes(struct multi_context *m, struct multi_instance *mi); **/ int dco_get_peer_stats_multi(dco_context_t *dco, struct multi_context *m); +/** + * Update traffic statistics for single peer + * + * @param c instance context of the peer + **/ +int dco_get_peer_stats(struct context *c); + /** * Retrieve the list of ciphers supported by the current platform * @@ -362,6 +369,12 @@ dco_get_peer_stats_multi(dco_context_t *dco, struct multi_context *m) return 0; } +static inline int +dco_get_peer_stats(struct context *c) +{ + return 0; +} + static inline const char * dco_get_supported_ciphers() { diff --git a/src/openvpn/dco_freebsd.c b/src/openvpn/dco_freebsd.c index 8d342159..7c46f64e 100644 --- a/src/openvpn/dco_freebsd.c +++ b/src/openvpn/dco_freebsd.c @@ -722,6 +722,13 @@ dco_get_peer_stats_multi(dco_context_t *dco, struct multi_context *m) return 0; } +int +dco_get_peer_stats(struct context *c) +{ + /* Not implemented. */ + return 0; +} + const char * dco_get_supported_ciphers() { diff --git a/src/openvpn/dco_linux.c b/src/openvpn/dco_linux.c index 200d0b19..222537fc 100644 --- a/src/openvpn/dco_linux.c +++ b/src/openvpn/dco_linux.c @@ -924,6 +924,13 @@ dco_get_peer_stats_multi(dco_context_t *dco, struct multi_context *m) return 0; } +int +dco_get_peer_stats(struct context *c) +{ + /* Not implemented. */ + return 0; +} + bool dco_available(int msglevel) { diff --git a/src/openvpn/dco_win.c b/src/openvpn/dco_win.c index 675dece2..b85665eb 100644 --- a/src/openvpn/dco_win.c +++ b/src/openvpn/dco_win.c @@ -33,6 +33,7 @@ #include "tun.h" #include "crypto.h" #include "ssl_common.h" +#include "openvpn.h" #include <bcrypt.h> #include <winsock2.h> @@ -406,6 +407,33 @@ dco_get_peer_stats_multi(dco_context_t *dco, struct multi_context *m) return 0; } +int +dco_get_peer_stats(struct context *c) +{ + struct tuntap *tt = c->c1.tuntap; + + if (!tuntap_defined(tt)) + { + return -1; + } + + OVPN_STATS stats; + ZeroMemory(&stats, sizeof(OVPN_STATS)); + + DWORD bytes_returned = 0; + if (!DeviceIoControl(tt->hand, OVPN_IOCTL_GET_STATS, NULL, 0, + &stats, sizeof(stats), &bytes_returned, NULL)) + { + msg(M_WARN | M_ERRNO, "DeviceIoControl(OVPN_IOCTL_SET_PEER) failed"); + return -1; + } + + c->c2.dco_read_bytes = stats.TransportBytesReceived; + c->c2.dco_write_bytes = stats.TransportBytesSent; + + return 0; +} + void dco_event_set(dco_context_t *dco, struct event_set *es, void *arg) { diff --git a/src/openvpn/manage.c b/src/openvpn/manage.c index 435efaf8..2c0bb6a8 100644 --- a/src/openvpn/manage.c +++ b/src/openvpn/manage.c @@ -43,6 +43,7 @@ #include "common.h" #include "manage.h" #include "openvpn.h" +#include "dco.h" #include "memdbg.h" @@ -4051,11 +4052,15 @@ management_check_bytecount(struct context *c, struct management *man, struct tim if (event_timeout_trigger(&man->connection.bytecount_update_interval, timeval, ETT_DEFAULT)) { - /* TODO: get stats from DCO */ - counter_type dco_read_bytes = 0; counter_type dco_write_bytes = 0; + if (dco_enabled(&c->options) && (dco_get_peer_stats(c) == 0)) + { + dco_read_bytes = c->c2.dco_read_bytes; + dco_write_bytes = c->c2.dco_write_bytes; + } + if (!(man->persist.callback.flags & MCF_SERVER)) { man_bytecount_output_client(man, dco_read_bytes, dco_write_bytes);