management: add timer to output BYTECOUNT
PATCH 1/1 management: add timer to output BYTECOUNT
From: Lev Stipakov <[email protected]...>
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 <n>. 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 <n> seconds.
--- src/openvpn/forward.c | 11 ++++++-- src/openvpn/manage.c | 40 ++++++++++++++++++++++++----- src/openvpn/manage.h | 60 ++++++++++++------------------------------- 3 files changed, 58 insertions(+), 53 deletions(-)
src/openvpn/forward.c +9 -2
@@ -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
src/openvpn/manage.c +33 -7
@@ -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
src/openvpn/manage.h +16 -44
87 lines not on this page · raw message
Signature · 1 line
2.38.1.windows.1
PATCH v2 1/1 management: add timer to output BYTECOUNT
From: Lev Stipakov <[email protected]...>
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 <n>. 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 <n> seconds.
---
v2: handle "bytecount 0" case and disable timer
src/openvpn/forward.c | 11 ++++++-- src/openvpn/manage.c | 42 ++++++++++++++++++++++++------ src/openvpn/manage.h | 60 ++++++++++++------------------------------- 3 files changed, 59 insertions(+), 54 deletions(-)
src/openvpn/forward.c +9 -2
@@ -771,6 +771,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
@@ -953,7 +960,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
@@ -1793,7 +1800,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
src/openvpn/manage.c +34 -8
84 lines not on this page · raw message
src/openvpn/manage.h +16 -44
87 lines not on this page · raw message
Signature · 1 line
2.23.0.windows.1
Am 14.12.22 um 23:42 schrieb Lev Stipakov:
Quoted 16 lines
From: Lev Stipakov <[email protected]...>
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 <n>. 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.
Quoted 7 lines
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 <n> seconds.
Arne, thanks for the review and ACK.
I have done quite a bit of stare-at-code on this patch myself, and think I understand what it does - change from "whenever userland updates the counters, check if mgmt needs to be informed" to "inform mgmt via the coarse timers", because there are no more userland packets to trigger this check. But having the review from someone who understands mgmt much better is very welcome :-)
As a side effect, management_bytes_in() and _out() are consolidated into a single function, which (due to being inlined) should do the same thing with the same efficiency, but it's a bit easier to see what happens.
I have subjected this to the full server/client tests on Linux and FreeBSD, with/without DCO - and everything works as before.
I have also tested this by connecting to the management interface to verify that the counters + event stuff works. No DCO involved, so counters were displayed in the expected intervals and values matched what I expected. Also, "bytecount 0" works to disable it again.
On a (FreeBSD) DCO system, the effect was not exactly what I expected
- I expected to see >BYTECOUNT: updates "with no interesting content", but actually after setting "bytecount 10", nothing happened for a few minutes - and then it started to work as ordered (without data packets, of course). So it seems as the timer activation got delayed somehow -> this is something we need to come back to, when Linux/FreeBSD DCO stats get implemented. Starting with "management-hold", then "bytecount", then "hold release" gave me counters right away. Mysteries...
Your patch has been applied to the master and release/2.6 branch.
commit a9991b3eb6644785421398bff8cb3a728d131713 (master) commit 59a96c3ee05cdb842af0956de0a2ba3ffd993980 (release/2.6)
Author: Lev Stipakov Date: Thu Dec 15 00:42:20 2022 +0200
management: add timer to output BYTECOUNT
Signed-off-by: Lev Stipakov <[email protected]...>
Acked-by: Arne Schwabe <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg25707.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
Hi,
Quoted 4 lines
So it seems as the timer activation got delayed somehow
-> this is something we need to come back to, when Linux/FreeBSD DCO stats get implemented. Starting with "management-hold", then "bytecount", then "hold release" gave me counters right away. Mysteries...
This is because we do not trigger this new timer (for example by calling reset_coarse_timers)
when we init it in man_bytecount(). We do not have "struct context" there to do it.
Follow-up calls to reset_coarse_timers() or process_coarse_timers() will do the trick. However, in DCO case nothing might happen in userspace for a while, hence delay. GUI does "management-hold", sends "bytecount 5" and after that "hold-release".
-Lev
Hi,
Quoted 9 lines · Lev Stipakov
Quoted 4 lines
So it seems as the timer activation got delayed somehow
-> this is something we need to come back to, when Linux/FreeBSD DCO stats get implemented. Starting with "management-hold", then "bytecount", then "hold release" gave me counters right away. Mysteries...This is because we do not trigger this new timer (for example by calling
reset_coarse_timers)
when we init it inman_bytecount(). We do not have "struct context" there to do it.
Ah. I guessed something like this - thanks for explaining why this would not actually be easy to achive.
Quoted 4 lines
Follow-up calls to
reset_coarse_timers()orprocess_coarse_timers()will do the trick. However, in DCO case nothing might happen in userspace for a while, hence delay. GUI does "management-hold", sends "bytecount 5" and after that "hold-release".
This works (tested!), so the point above is not a serious problem.
gert
Signature · 6 lines
"If was one thing all people took for granted, was conviction that if you
feed honest figures into a computer, honest figures come out. Never doubted
it myself till I met a computer with a sense of humor."
Robert A. Heinlein, The Moon is a Harsh Mistress
Gert Doering - Munich, Germany [email protected]...