From patchwork Wed Dec 14 16:48:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lev Stipakov X-Patchwork-Id: 2911 Return-Path: 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 ) 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 ) 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 ; 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 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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Lev Stipakov 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?= 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 ++++++++++++++++++++++++++++ src/openvpn/manage.c | 9 +++++++-- 5 files changed, 62 insertions(+), 2 deletions(-) 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 #include @@ -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);