From patchwork Tue Dec 13 10:31: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: 2902 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:622a:418d:b0:3a5:7962:c21f with SMTP id cd13csp2640948qtb; Tue, 13 Dec 2022 02:32:45 -0800 (PST) X-Google-Smtp-Source: AA0mqf7x7FoDVAT/KcRoMwoguqkNuwQACgXIkRf51rfEAbcKQG7TpQP8PQyEgsdLD1IRoLFU07kW X-Received: by 2002:a62:640f:0:b0:574:f1bc:bbee with SMTP id y15-20020a62640f000000b00574f1bcbbeemr17569592pfb.31.1670927564809; Tue, 13 Dec 2022 02:32:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670927564; cv=none; d=google.com; s=arc-20160816; b=ELHRIG+IZhBrccGMF53OERMToJtYajrgreUbfgb1quyQh2D/dbaI80gEqMwaHMMisC Grfel56DUYaV99fiQMgBsic8T1cFWEYcpFBDpVAO6Ea5k5Sh+VIa8dHnGqwGCaUC/7g6 A4NTQHGYtZp8DvTCtyk2bBFqUYk7p7yGDXG3Tv0CKTk7JbHrW7T8/BP9tUpOsiviO/KC GrF92iEAw9m3iPArBxxnkC0n4okH24X5250FaGBiDh3Eze7Lamlxbywek5yhplPDh+8M Fflwh/xWzoNrxpTX9Ypw39IaZP2ZIxZi+wNFKJL4CwI0dp9KHoSkOiC1FYh3hqI+RGcP jLiw== 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=/SDhdAILo8bVbLZqhNoq5mE16U1F2HWHVpYkw1pL1xM=; b=qs4g/wpP1bXN3qWDvbyx2ux1bwUKnmSZwY/A/k7u9Mo5eobL9oFG3CVgOonH5vku3C 0Tf/TfZt/VfsK9Nhb7vMsrqOu7F8p6qDpuqB4IQfKACbryAfMU/ZR3E65aNC3RNJQFeG jy4B9O+TZTd91yLdxHjgVEvGNt/eg18R2YZDWWfF/5Ixhva+tTloC2GcoA96Bmt6Nw7r +2xYRfK1mWk+hXpzIC955myXQvQWfOlRvh7loobHJFagFoWvCQt0auXrJR8g96OPiJk9 any01TLCHpeKBnNVubDpGekA7AQDqCEz19a+u4X1ugXSdgd/hmZPe4Po2DxC1Bg7e+cE VgsA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=aSWDPIXJ; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=izlqufNV; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=O205G5Yw; 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 y36-20020a056a001ca400b00557c8a20395si11317055pfw.120.2022.12.13.02.32.44 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 13 Dec 2022 02:32:44 -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=aSWDPIXJ; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=izlqufNV; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=O205G5Yw; 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 1p52a5-0007Ua-Ay; Tue, 13 Dec 2022 10:32:13 +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 1p52a2-0007UP-Df for openvpn-devel@lists.sourceforge.net; Tue, 13 Dec 2022 10:32:10 +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=u9fTa/LyCcfBmaw/CjNCMA0R5ouT8eYK68E232sWuXA=; b=aSWDPIXJanSlcm7kE3sxOJvWO6 1bZBsMpTnc/6pzP8zL0Cmp5+ef1EZPflXBMvl917pIbBHSuLzOzAYHu16ChE/qYNMeDN0UlIpJwlB XXJ70T5Quqgm2i9rx48kCWwkioySboz+Rl6ZkPVtcxLyWWYua5jlnQt3l7aLWm9aRX0w=; 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=u9fTa/LyCcfBmaw/CjNCMA0R5ouT8eYK68E232sWuXA=; b=i zlqufNVYv26JMAGh71RaUg75WGhsNjLCHTLF1blfsK3g8QGeRTiK/b5FTAhtO3mdBvFKvuSlrSj08 JTGwf5Ehx2s0Xo3X1rmO0UaqrzcMBzVdh6+AD3oTFiiBbqnVFqmkwGJHUDV6vm/ihQAeocKkg/EJE mI1HcCChhkg/DK9w=; Received: from mail-lj1-f176.google.com ([209.85.208.176]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.95) id 1p52Zx-000091-5U for openvpn-devel@lists.sourceforge.net; Tue, 13 Dec 2022 10:32:10 +0000 Received: by mail-lj1-f176.google.com with SMTP id z4so2839102ljq.6 for ; Tue, 13 Dec 2022 02:32:05 -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=u9fTa/LyCcfBmaw/CjNCMA0R5ouT8eYK68E232sWuXA=; b=O205G5Yw98vyCRCABfLQLeJoYBRby8NfnRxvv0lbWiu6MwqPjGquIqep08aLIve1lI ZT1lcITDW/vqQP1tezLTbLnW+HgRPNyLF/5VyXO71E4mzrWPZpQ/PVPyvSAq5Py2yPwI 0jx7YEMVORu+ctl2uWzWieTnACKx+OpkqDlfm9hnS0012QZY68mZ+kg8/bLUDSyrIV/f zxysQvI7IqOEbpCeJFWJpxisUZGENetFXzrOaJxI4mu9JgYTN1R/7L4uOpQkp7g39e6z narmZw7+YUxJPR1FeDEqit6DRWEvg9v7c7YAkP/IVKn2M4kHb+/22fGDfjIWzHLB1tw3 HBBQ== 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=u9fTa/LyCcfBmaw/CjNCMA0R5ouT8eYK68E232sWuXA=; b=PaiiR6fsVDKF/QBg4SKgBK+ecFeOOM5Rrh1TpP1WweZ6jYwfZltlAft4ydNgzoaj+R ud8+nQOrGaIYxtTBwS8ARlblrQUTnOEXjHFGunTECfQ0o5ieh9qOvymPrUT0amjfKLTy JRMrthDxLNk2oZNr68V60TlMbgRg/r3vQPcfwaUjbyq0EG0JoKsjlL+oAAsYzRFQuXk3 wMbvTsWSkMRRctanxebRxjAMNpnlEy+aZXZlMasMyoXHtvz5tUPHc8MGQlxNTvDTsJoA uRe9fIeVQzrZ2Cs0A6KA8kfOKAqAQPm7+VmH1Qv8JcitsqUuzyk2lPAAIcV7NMhzJraF 1fTQ== X-Gm-Message-State: ANoB5pl+919SlxB/TtK//Y0BFEWN+KbmVLDFj31+cSmGvRu5dige/3I0 ag/gKxeOSszyVg/D3222M7HBVTCrqJo= X-Received: by 2002:a2e:bf1e:0:b0:279:9954:f675 with SMTP id c30-20020a2ebf1e000000b002799954f675mr5728521ljr.21.1670927518024; Tue, 13 Dec 2022 02:31:58 -0800 (PST) Received: from localhost.localdomain ([2a00:1d50:3:0:6bb8:4a62:3984:f58f]) by smtp.gmail.com with ESMTPSA id a8-20020a05651c030800b0027a081bfee9sm214530ljp.43.2022.12.13.02.31.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Dec 2022 02:31:57 -0800 (PST) From: Lev Stipakov To: openvpn-devel@lists.sourceforge.net Date: Tue, 13 Dec 2022 12:31:42 +0200 Message-Id: <20221213103142.1960-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-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 BYTECOUNT on management interface is used to display client stats, for example by openvpn-gui. At the moment BYTECOUNT is sent if there is a traffic. With DCO, userspace process doesn't see data chann [...] Content analysis details: (-0.2 points, 6.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -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 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 RCVD_IN_MSPIKE_H2 RBL: Average reputation (+2) [209.85.208.176 listed in wl.mailspike.net] -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [209.85.208.176 listed in list.dnswl.org] -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -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_AU Message has a valid DKIM or DK signature from author's domain X-Headers-End: 1p52Zx-000091-5U Subject: [Openvpn-devel] [PATCH] management: add timer to output 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?1752094541896189428?= X-GMAIL-MSGID: =?utf-8?q?1752094541896189428?= From: Lev Stipakov BYTECOUNT on management interface is used to display client stats, for example by openvpn-gui. At the moment BYTECOUNT is sent if there is a traffic. With DCO, userspace process doesn't see data channel traffic, BYTECOUNT is not sent and therefore stats are not updated. Fix displaying DCO client stats by adding a timer, which is triggerd every n seconds, where n is set by existing management command bytecount . Output stats, taking into account stats from DCO, when timer is triggered. While on it, simplify bytecount routines call chains - inlining functions which are used only once. DCO stats fetching is not yet implemented. Stats for the server mode (BYTECOUNT_CLI) are unaffected by this change - to output those in timer callback we would need to enumerate all peers, and I am not sure we want to output stats for all peers every seconds. Signed-off-by: Lev Stipakov --- src/openvpn/forward.c | 11 ++++++-- src/openvpn/manage.c | 40 ++++++++++++++++++++++++----- src/openvpn/manage.h | 60 ++++++++++++------------------------------- 3 files changed, 58 insertions(+), 53 deletions(-) diff --git a/src/openvpn/forward.c b/src/openvpn/forward.c index 5cd7eaa6..3c424cc1 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 @@ -948,7 +955,7 @@ process_incoming_link_part1(struct context *c, struct link_socket_info *lsi, boo #ifdef ENABLE_MANAGEMENT if (management) { - management_bytes_in(management, c->c2.buf.len); + 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); } #endif @@ -1788,7 +1795,7 @@ process_outgoing_link(struct context *c) #ifdef ENABLE_MANAGEMENT if (management) { - management_bytes_out(management, size); + management_bytes_client(management, 0, size); 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 5b288eab..435efaf8 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,29 +464,34 @@ 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"); } -void -man_bytecount_output_client(struct management *man) +static void +man_bytecount_output_client(struct management *man, + counter_type dco_read_bytes, + counter_type dco_write_bytes) { 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, 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; } void -man_bytecount_output_server(struct management *man, - const counter_type *bytes_in_total, +man_bytecount_output_server(const counter_type *bytes_in_total, const counter_type *bytes_out_total, struct man_def_auth_context *mdac) { @@ -2542,6 +2548,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); @@ -4037,6 +4045,24 @@ 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); + } + } +} + #else /* ifdef ENABLE_MANAGEMENT */ void diff --git a/src/openvpn/manage.h b/src/openvpn/manage.h index f46274e6..700b15cf 100644 --- a/src/openvpn/manage.h +++ b/src/openvpn/manage.h @@ -295,7 +295,7 @@ struct man_connection { bool log_realtime; 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; @@ -512,55 +512,27 @@ void management_auth_token(struct management *man, const char *token); * These functions drive the bytecount in/out counters. */ -void man_bytecount_output_client(struct management *man); - -static inline void -man_bytecount_possible_output_client(struct management *man) -{ - if (man->connection.bytecount_update_seconds > 0 - && now >= man->connection.bytecount_last_update - + man->connection.bytecount_update_seconds) - { - man_bytecount_output_client(man); - } -} - -static inline void -management_bytes_out_client(struct management *man, const int size) -{ - man->persist.bytes_out += size; - man_bytecount_possible_output_client(man); -} - -static inline void -management_bytes_in_client(struct management *man, const int size) -{ - man->persist.bytes_in += size; - man_bytecount_possible_output_client(man); -} - -static inline void -management_bytes_out(struct management *man, const int size) -{ - if (!(man->persist.callback.flags & MCF_SERVER)) - { - management_bytes_out_client(man, size); - } -} +void +management_check_bytecount(struct context *c, + struct management *man, + struct timeval *timeval); static inline void -management_bytes_in(struct management *man, const int size) +management_bytes_client(struct management *man, + const int size_in, + const int size_out) { if (!(man->persist.callback.flags & MCF_SERVER)) { - management_bytes_in_client(man, size); + man->persist.bytes_in += size_in; + man->persist.bytes_out += size_out; } } -void man_bytecount_output_server(struct management *man, - const counter_type *bytes_in_total, - const counter_type *bytes_out_total, - struct man_def_auth_context *mdac); +void +man_bytecount_output_server(const counter_type *bytes_in_total, + const counter_type *bytes_out_total, + struct man_def_auth_context *mdac); static inline void management_bytes_server(struct management *man, @@ -570,9 +542,9 @@ management_bytes_server(struct management *man, { if (man->connection.bytecount_update_seconds > 0 && now >= mdac->bytecount_last_update + man->connection.bytecount_update_seconds - && (mdac->flags & (DAF_CONNECTION_ESTABLISHED|DAF_CONNECTION_CLOSED)) == DAF_CONNECTION_ESTABLISHED) + && (mdac->flags & (DAF_CONNECTION_ESTABLISHED | DAF_CONNECTION_CLOSED)) == DAF_CONNECTION_ESTABLISHED) { - man_bytecount_output_server(man, bytes_in_total, bytes_out_total, mdac); + man_bytecount_output_server(bytes_in_total, bytes_out_total, mdac); } }