From patchwork Mon Dec 12 11:56:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lev Stipakov X-Patchwork-Id: 2901 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:622a:418d:b0:3a5:7962:c21f with SMTP id cd13csp2073084qtb; Mon, 12 Dec 2022 03:57:54 -0800 (PST) X-Google-Smtp-Source: AA0mqf5o6hNW1w2amntJuuEoOuixKiAeBM03aT/M/X6uZCXsK2at+PmKv4tTR3f/MXtRjk4vWZmk X-Received: by 2002:a17:902:d4d1:b0:189:e7e:784c with SMTP id o17-20020a170902d4d100b001890e7e784cmr23771877plg.21.1670846274575; Mon, 12 Dec 2022 03:57:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670846274; cv=none; d=google.com; s=arc-20160816; b=vhbWkQZ3FY3cdAZdig+9Ut9d5LmpfApmoPm/EAlNDp0N7VrSUKkzWjpiaML7DcBjBc 6Ak0gF4WzKleSdGoib1rtTMRrwHrroWs4WxGQNpPg2U7UYIKxZExy+gcBeBFkdHLuhsd x9SZ0lXv3XpEm4RhAM7at3TaCEdQinRmDpdUKtpJlqPWWFAAf8ldxxYUKmxz6HtuNfXf q08kY+ukf/yW2sM60E0CyW6bGuONaHXGaLB7y1GdYRkfDgDu44aAYub4fxZf9oGx4s1E kvyWnXUDXBBmzQn25GmSXNubHAaZPTEb/lsRO30KiDvktxYPDbxG1K1gt48VlLqXwojf nm3w== 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=JLd6s3plr3STwSyEaNF45eCWbBrO/bIczz+6vaKl62s=; b=TVe97sBCgXEjEMR6XcuaCmz8PFTZ6VigocRZvEFD5HIOylxx46QJTsg3isKgavcmbE 60KEdDl6O/uqrSK2QEZfp2mIbsgxH2zBOw8xxjoKeRc8hwnQoOjKihfjHSiavOzL9Rx4 r0ygzYEyfjvfvI+yYgzHaaUogAfEGaJ3Q+G6ZNadu89QBjwioGCNDOly7IqaedFqufc/ mIuII6ILb732E/1yHEc7oXTXSJKqjS+YojW/sEVlzCaNSxgd3soYXmeZoJXJW5pIPdPE JpViSaw3SnUwuT9Z9C1ngxamuWdnXGSjrsCMZFDzm2tefeV82qiY6G4MyNpfrlUCp59E OUvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=IknElRAB; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=b1mbMCzo; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=D6Tr7FQD; 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 jx10-20020a170903138a00b001897919de28si9152497plb.546.2022.12.12.03.57.54 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 12 Dec 2022 03:57:54 -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=IknElRAB; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=b1mbMCzo; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=D6Tr7FQD; 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-2.v29.lw.sourceforge.com) by sfs-ml-2.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1p4hQj-0006Ts-8h; Mon, 12 Dec 2022 11:57:09 +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 ) id 1p4hQh-0006Tm-Ra for openvpn-devel@lists.sourceforge.net; Mon, 12 Dec 2022 11:57:07 +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=56ueTEDj8pt4KpGzg4VMFF8m0UFONoXB8vkVxpxryR4=; b=IknElRAB6WGawD4yi94tGImnp/ l3eRuIt6BbznA1zQRzMkuksA4KrdYtow/f77eSdUdGUciXLWOQ7+mD6G7azZZfCavSeXSpSO6fezQ 8BiUDILkUb4KVem5xacjxqNWZNMcHapsTNbbw6Z7XhyqtKIX1jUbZkSO/CuJyV/bPS6w=; 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=56ueTEDj8pt4KpGzg4VMFF8m0UFONoXB8vkVxpxryR4=; b=b 1mbMCzoUYfWxANYYZoTqFWLYpvxBh1wgCBilDr0PQCqMoya/qax7+Y6ThDyCHgILPZDGsiQDvNK9X U9DTMdnHfPNTUZ8PyrnFUAQBTd8fxLO9Z4vPlD/5TX4AmW+H/gW8G7HGIZpzNmyT63yUmzz1H9Jwi /jjXrxZE3oT6lG+E=; Received: from mail-lf1-f51.google.com ([209.85.167.51]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.95) id 1p4hQe-0000ov-8D for openvpn-devel@lists.sourceforge.net; Mon, 12 Dec 2022 11:57:07 +0000 Received: by mail-lf1-f51.google.com with SMTP id c1so18139891lfi.7 for ; Mon, 12 Dec 2022 03:57:04 -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=56ueTEDj8pt4KpGzg4VMFF8m0UFONoXB8vkVxpxryR4=; b=D6Tr7FQDpO3GbtsVX5RSuFQ0SWP9kdiSfzzNMVWnSwfrKA873oi2kfNI5B3vd3wktJ puYnHAn+hA9tvxk5bd5hElkeL+iCfdzggG3PX/eiwz4cBs6ZGo7m/56BM6KymrWODS94 Fg1b0Waybuwi9p9xn+VOV8ieEKX0fuBYao7e2F4hOBgitXm8DIm8qCwgYMEz0i6NrOAS Pbl0V+WggN9HWlXZBwNVU84MMwzZshnWWJBtAq4pS7Nmy4WOoDxlrlIkf9Ll9iV80Pkh TQjylzdkdsV5C7XbDYo+I6TWG3hyMxzRzbrqI1UfVk/UFw2wzhgplBGl4ybRze1LUoAK Vzkg== 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=56ueTEDj8pt4KpGzg4VMFF8m0UFONoXB8vkVxpxryR4=; b=mcF2QeB9BnlY8Go1Npb1ZjNt2CWZFP0QB/vAlF7oBiQmx+IWKYLeG8qh4++5DM/y3E cq/Me3cI9j7BiQiEaPjaaF7G1lVvkyjDtjnBhsSSUPxHUK5lgcHLJJqYDK96KNLtq/U6 knrHWtw570JFpLBRLJ86kuLOlGwkgh0LMOl8MnUII5nViMhVjS6bSgGim55BjJTFS61L TZqX8zAK//PemvDod/Uhh4mjEkxSaQ/PcXUn9xAa1wLEJ8VY1FdjpMktihtIojf2ZwnO BsZSWrxdgrExP/QDmdKD8knGBMpgApLtkl2F8SYPg1mpSehc7zroDZQbBbzULESmgs1D InyA== X-Gm-Message-State: ANoB5pkwGqoq1xGphG7kVAHqdP7kSUAt0D7UIBp35B0j68pjnWFWWXMy q9OyAc8G0mDAtwt1eeGmV9efDxkDcdk= X-Received: by 2002:a05:6512:c04:b0:4b5:b90a:829d with SMTP id z4-20020a0565120c0400b004b5b90a829dmr3164785lfu.66.1670846217180; Mon, 12 Dec 2022 03:56:57 -0800 (PST) Received: from localhost.localdomain ([2a00:1d50:3:0:b8b1:7329:e3db:7e76]) by smtp.gmail.com with ESMTPSA id b15-20020a056512070f00b004b40c2fccfdsm1611257lfs.59.2022.12.12.03.56.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Dec 2022 03:56:56 -0800 (PST) From: Lev Stipakov To: openvpn-devel@lists.sourceforge.net Date: Mon, 12 Dec 2022 13:56:42 +0200 Message-Id: <20221212115642.2139-1-lstipakov@gmail.com> X-Mailer: git-send-email 2.38.1.windows.1 MIME-Version: 1.0 X-Spam-Score: -0.2 (/) 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: From: Lev Stipakov At the moment BYTECOUNT in, out is pushed if there is traffic. With DCO, userspace process doesn't see the traffic, so we need to add a timer which periodically fetches stats from DCO and pushes to man [...] 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.51 listed in list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [lstipakov[at]gmail.com] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.0 RCVD_IN_MSPIKE_H2 RBL: Average reputation (+2) [209.85.167.51 listed in wl.mailspike.net] -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -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 X-Headers-End: 1p4hQe-0000ov-8D Subject: [Openvpn-devel] [PATCH 2/2] management: add timer to push BYTECOUNT 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?1752009302707148398?= X-GMAIL-MSGID: =?utf-8?q?1752009302707148398?= From: Lev Stipakov At the moment BYTECOUNT in,out is pushed if there is traffic. With DCO, userspace process doesn't see the traffic, so we need to add a timer which periodically fetches stats from DCO and pushes to management client. The timer interval is set by existing "bytecount n" management command. This commit only adds a timer, stats fetching from DCO will be added later. Signed-off-by: Lev Stipakov --- src/openvpn/forward.c | 11 ++++++++-- src/openvpn/manage.c | 51 ++++++++++++++++++++++++++++++++++++------- src/openvpn/manage.h | 10 +++++++-- 3 files changed, 60 insertions(+), 12 deletions(-) diff --git a/src/openvpn/forward.c b/src/openvpn/forward.c index 1cd20a0b..830843c0 100644 --- a/src/openvpn/forward.c +++ b/src/openvpn/forward.c @@ -766,6 +766,13 @@ process_coarse_timers(struct context *c) /* Should we ping the remote? */ check_ping_send(c); + +#ifdef ENABLE_MANAGEMENT + if (management) + { + management_check_bytecount(c, management, &c->c2.timeval); + } +#endif /* ENABLE_MANAGEMENT */ } static void @@ -949,7 +956,7 @@ process_incoming_link_part1(struct context *c, struct link_socket_info *lsi, boo if (management) { management_bytes_client(management, c->c2.buf.len, 0); - management_bytes_server(management, &c->c2.link_read_bytes, &c->c2.link_write_bytes, &c->c2.mda_context); + management_bytes_server(management, c->c2.link_read_bytes, c->c2.link_write_bytes, &c->c2.mda_context); } #endif } @@ -1789,7 +1796,7 @@ process_outgoing_link(struct context *c) if (management) { management_bytes_client(management, 0, size); - management_bytes_server(management, &c->c2.link_read_bytes, &c->c2.link_write_bytes, &c->c2.mda_context); + management_bytes_server(management, c->c2.link_read_bytes, c->c2.link_write_bytes, &c->c2.mda_context); } #endif } diff --git a/src/openvpn/manage.c b/src/openvpn/manage.c index 1f76a23d..ce952d52 100644 --- a/src/openvpn/manage.c +++ b/src/openvpn/manage.c @@ -42,6 +42,7 @@ #include "ssl.h" #include "common.h" #include "manage.h" +#include "openvpn.h" #include "memdbg.h" @@ -463,16 +464,22 @@ man_bytecount(struct management *man, const int update_seconds) if (update_seconds >= 0) { man->connection.bytecount_update_seconds = update_seconds; + event_timeout_init(&man->connection.bytecount_update_interval, + man->connection.bytecount_update_seconds, + now); } else { man->connection.bytecount_update_seconds = 0; + event_timeout_clear(&man->connection.bytecount_update_interval); } msg(M_CLIENT, "SUCCESS: bytecount interval changed"); } static void -man_bytecount_output_client(struct management *man) +man_bytecount_output_client(struct management *man, + counter_type dco_read_bytes, + counter_type dco_write_bytes) { if (man->connection.bytecount_update_seconds > 0 && now >= man->connection.bytecount_last_update @@ -482,8 +489,8 @@ man_bytecount_output_client(struct management *man) char out[32]; /* do in a roundabout way to work around possible mingw or mingw-glibc bug */ - openvpn_snprintf(in, sizeof(in), counter_format, man->persist.bytes_in); - openvpn_snprintf(out, sizeof(out), counter_format, man->persist.bytes_out); + openvpn_snprintf(in, sizeof(in), counter_format, man->persist.bytes_in + dco_read_bytes); + openvpn_snprintf(out, sizeof(out), counter_format, man->persist.bytes_out + dco_write_bytes); msg(M_CLIENT, ">BYTECOUNT:%s,%s", in, out); man->connection.bytecount_last_update = now; } @@ -498,14 +505,14 @@ management_bytes_client(struct management *man, { man->persist.bytes_in += size_in; man->persist.bytes_out += size_out; - man_bytecount_output_client(man); + man_bytecount_output_client(man, 0, 0); } } void management_bytes_server(struct management *man, - const counter_type *bytes_in_total, - const counter_type *bytes_out_total, + const counter_type bytes_in_total, + const counter_type bytes_out_total, struct man_def_auth_context *mdac) { if (man->connection.bytecount_update_seconds > 0 @@ -515,8 +522,8 @@ management_bytes_server(struct management *man, char in[32]; char out[32]; /* do in a roundabout way to work around possible mingw or mingw-glibc bug */ - openvpn_snprintf(in, sizeof(in), counter_format, *bytes_in_total); - openvpn_snprintf(out, sizeof(out), counter_format, *bytes_out_total); + openvpn_snprintf(in, sizeof(in), counter_format, bytes_in_total); + openvpn_snprintf(out, sizeof(out), counter_format, bytes_out_total); msg(M_CLIENT, ">BYTECOUNT_CLI:%lu,%s,%s", mdac->cid, in, out); mdac->bytecount_last_update = now; } @@ -2566,6 +2573,8 @@ man_connection_close(struct management *man) command_line_free(mc->in); buffer_list_free(mc->out); + event_timeout_clear(&mc->bytecount_update_interval); + in_extra_reset(&man->connection, IER_RESET); buffer_list_free(mc->ext_key_input); man_connection_clear(mc); @@ -4061,6 +4070,32 @@ management_sleep(const int n) } } +void +management_check_bytecount(struct context *c, struct management *man, struct timeval *timeval) +{ + 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 (!(man->persist.callback.flags & MCF_SERVER)) + { + man_bytecount_output_client(man, dco_read_bytes, dco_write_bytes); + } + + management_bytes_server(man, + c->c2.link_read_bytes + dco_read_bytes, + c->c2.link_write_bytes + dco_write_bytes, + &c->c2.mda_context); + + event_timeout_modify_wakeup(&man->connection.bytecount_update_interval, + man->connection.bytecount_update_seconds); + } +} + #else /* ifdef ENABLE_MANAGEMENT */ void diff --git a/src/openvpn/manage.h b/src/openvpn/manage.h index 621440be..5a7aafa4 100644 --- a/src/openvpn/manage.h +++ b/src/openvpn/manage.h @@ -296,6 +296,7 @@ struct man_connection { bool echo_realtime; int bytecount_update_seconds; time_t bytecount_last_update; + struct event_timeout bytecount_update_interval; const char *up_query_type; int up_query_mode; @@ -518,10 +519,15 @@ management_bytes_client(struct management *man, void management_bytes_server(struct management *man, - const counter_type *bytes_in_total, - const counter_type *bytes_out_total, + const counter_type bytes_in_total, + const counter_type bytes_out_total, struct man_def_auth_context *mdac); +void +management_check_bytecount(struct context *c, + struct management *man, + struct timeval *timeval); + #endif /* ifdef ENABLE_MANAGEMENT */ /**