[Openvpn-devel] [S] Change in openvpn[master]: Don't call bytecount client logic in server mode

2025-08-29 Thread stipa (Code Review)
stipa has abandoned this change. ( 
http://gerrit.openvpn.net/c/openvpn/+/1157?usp=email )

Change subject: Don't call bytecount client logic in server mode
..


Abandoned

Will be superceded
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1157?usp=email
To unsubscribe, or for help writing mail filters, visit 
http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I7bc7de284fdbfd4be26a907ecd5c21c075bc5ac4
Gerrit-Change-Number: 1157
Gerrit-PatchSet: 2
Gerrit-Owner: stipa 
Gerrit-Reviewer: flichtenheld 
Gerrit-Reviewer: plaisthos 
Gerrit-CC: openvpn-devel 
Gerrit-MessageType: abandon
___
Openvpn-devel mailing list
Openvpn-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openvpn-devel


[Openvpn-devel] [M] Change in openvpn[master]: Refactor management bytecount tracking

2025-08-29 Thread stipa (Code Review)
Attention is currently required from: flichtenheld, plaisthos.

Hello plaisthos, flichtenheld,

I'd like you to do a code review.
Please visit

http://gerrit.openvpn.net/c/openvpn/+/1162?usp=email

to review the following change.


Change subject: Refactor management bytecount tracking
..

Refactor management bytecount tracking

There are few issues with it:

 - when using DCO, the server part doesn't output BYTECOUNT_CLI
 since process_incoming_link_part1/process_outgoing_link are not called

 - when using DCO, the server part applies bytecount timer to the each
 connection, unneccessary making too many calls to the kernel and also
 uses incorect BYTECOUNT output.

 - client part outputs counters using timer, server part utilizes
 traffic activity -> inconsistency

Following changes have been made:

 - Use timer to output counters in client and server mode. Code which
 deals with bytecount on traffic activity has been removed. This unifies
 DCO and non-DCO, as well as client and server mode

 - In server mode, peers stats are fetched with the single ioctl call

 - Per-packet stats are not persisted anymore in the client mode during
   traffic activity. Instead cumulative stats (including DCO stats) are
   persisted when the session closes.

GitHub: https://github.com/OpenVPN/openvpn/issues/820

Change-Id: I43a93f0d84f01fd808a64115e1b8c3b806706491
Signed-off-by: Lev Stipakov 
---
M src/openvpn/forward.c
M src/openvpn/manage.c
M src/openvpn/manage.h
M src/openvpn/multi.c
4 files changed, 62 insertions(+), 71 deletions(-)



  git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/62/1162/1

diff --git a/src/openvpn/forward.c b/src/openvpn/forward.c
index 75ca9d5..03b6a0c 100644
--- a/src/openvpn/forward.c
+++ b/src/openvpn/forward.c
@@ -818,7 +818,7 @@
 #ifdef ENABLE_MANAGEMENT
 if (management)
 {
-management_check_bytecount(c, management, &c->c2.timeval);
+management_check_bytecount_client(c, management, &c->c2.timeval);
 }
 #endif /* ENABLE_MANAGEMENT */
 }
@@ -998,14 +998,6 @@
 }
 #endif
 c->c2.original_recv_size = c->c2.buf.len;
-#ifdef ENABLE_MANAGEMENT
-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);
-}
-#endif
 }
 else
 {
@@ -1823,14 +1815,6 @@
 mmap_stats->link_write_bytes = link_write_bytes_global;
 }
 #endif
-#ifdef ENABLE_MANAGEMENT
-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);
-}
-#endif
 }
 }

diff --git a/src/openvpn/manage.c b/src/openvpn/manage.c
index aed04f5..bcc7250 100644
--- a/src/openvpn/manage.c
+++ b/src/openvpn/manage.c
@@ -41,6 +41,7 @@
 #include "manage.h"
 #include "openvpn.h"
 #include "dco.h"
+#include "multi.h"

 #include "memdbg.h"

@@ -517,29 +518,27 @@
 }

 static void
-man_bytecount_output_client(struct management *man, counter_type 
dco_read_bytes,
-counter_type dco_write_bytes)
+man_bytecount_output_client(counter_type bytes_in_total, counter_type 
bytes_out_total)
 {
 char in[32];
 char out[32];

 /* do in a roundabout way to work around possible mingw or mingw-glibc bug 
*/
-snprintf(in, sizeof(in), counter_format, man->persist.bytes_in + 
dco_read_bytes);
-snprintf(out, sizeof(out), counter_format, man->persist.bytes_out + 
dco_write_bytes);
+snprintf(in, sizeof(in), counter_format, bytes_in_total);
+snprintf(out, sizeof(out), counter_format, bytes_out_total);
 msg(M_CLIENT, ">BYTECOUNT:%s,%s", in, out);
 }

-void
-man_bytecount_output_server(const counter_type *bytes_in_total, const 
counter_type *bytes_out_total,
+static void
+man_bytecount_output_server(const counter_type bytes_in_total, const 
counter_type bytes_out_total,
 struct man_def_auth_context *mdac)
 {
 char in[32];
 char out[32];
 /* do in a roundabout way to work around possible mingw or mingw-glibc bug 
*/
-snprintf(in, sizeof(in), counter_format, *bytes_in_total);
-snprintf(out, sizeof(out), counter_format, *bytes_out_total);
+snprintf(in, sizeof(in), counter_format, bytes_in_total);
+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;
 }

 static void
@@ -4065,42 +4064,70 @@
 }

 void
-management_check_bytecount(struct context *c, struct management *man, struct 
timeval *timeval)
+management_check_bytecount_clien

[Openvpn-devel] [M] Change in openvpn[master]: Add new unit test module test_socket

2025-08-29 Thread flichtenheld (Code Review)
Attention is currently required from: plaisthos.

Hello plaisthos,

I'd like you to reexamine a change. Please visit

http://gerrit.openvpn.net/c/openvpn/+/1160?usp=email

to look at the new patch set (#2).


Change subject: Add new unit test module test_socket
..

Add new unit test module test_socket

With a first UT that tests add_in6_addr() (and
print_in6_addr implicitly).

Change-Id: If546f64a4554b292623bfcfe9ee53bac17dfa803
Signed-off-by: Frank Lichtenheld 
---
M CMakeLists.txt
M tests/unit_tests/openvpn/Makefile.am
M tests/unit_tests/openvpn/mock_management.c
A tests/unit_tests/openvpn/test_socket.c
4 files changed, 158 insertions(+), 10 deletions(-)


  git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/60/1160/2

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 45044af..6ca08fb 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -653,6 +653,7 @@
 "test_packet_id"
 "test_pkt"
 "test_provider"
+"test_socket"
 "test_ssl"
 "test_user_pass"
 "test_push_update_msg"
@@ -849,6 +850,15 @@
 src/openvpn/base64.c
 )

+target_sources(test_socket PRIVATE
+tests/unit_tests/openvpn/mock_get_random.c
+tests/unit_tests/openvpn/mock_management.c
+tests/unit_tests/openvpn/mock_win32_execve.c
+src/openvpn/env_set.c
+src/openvpn/run_command.c
+src/openvpn/socket_util.c
+)
+
 target_sources(test_user_pass PRIVATE
 tests/unit_tests/openvpn/mock_get_random.c
 tests/unit_tests/openvpn/mock_win32_execve.c
diff --git a/tests/unit_tests/openvpn/Makefile.am 
b/tests/unit_tests/openvpn/Makefile.am
index b24e03c..07d3ee9 100644
--- a/tests/unit_tests/openvpn/Makefile.am
+++ b/tests/unit_tests/openvpn/Makefile.am
@@ -4,23 +4,17 @@

 AM_TESTSUITE_SUMMARY_HEADER = ' for $(PACKAGE_STRING) Unit-Tests'

-test_binaries=
+test_binaries = crypto_testdriver packet_id_testdriver auth_token_testdriver \
+   ncp_testdriver misc_testdriver pkt_testdriver ssl_testdriver \
+   user_pass_testdriver push_update_msg_testdriver provider_testdriver 
socket_testdriver

 if HAVE_LD_WRAP_SUPPORT
 test_binaries += argv_testdriver buffer_testdriver
-endif
-
-test_binaries += crypto_testdriver packet_id_testdriver auth_token_testdriver 
ncp_testdriver misc_testdriver \
-   pkt_testdriver ssl_testdriver user_pass_testdriver 
push_update_msg_testdriver
-
-if HAVE_LD_WRAP_SUPPORT
 if !WIN32
 test_binaries += tls_crypt_testdriver
 endif
 endif

-test_binaries += provider_testdriver
-
 if WIN32
 test_binaries += cryptoapi_testdriver
 LDADD = -lws2_32
@@ -343,4 +337,22 @@
$(top_srcdir)/src/openvpn/platform.c \
$(top_srcdir)/src/openvpn/push_util.c \
$(top_srcdir)/src/openvpn/options_util.c \
-   $(top_srcdir)/src/openvpn/otime.c
\ No newline at end of file
+   $(top_srcdir)/src/openvpn/otime.c
+
+socket_testdriver_CFLAGS  = \
+   -I$(top_srcdir)/include -I$(top_srcdir)/src/compat 
-I$(top_srcdir)/src/openvpn \
+   -DSOURCEDIR=\"$(top_srcdir)\" @TEST_CFLAGS@
+
+socket_testdriver_LDFLAGS = @TEST_LDFLAGS@
+
+socket_testdriver_SOURCES = test_socket.c \
+   mock_msg.c test_common.h  \
+   mock_get_random.c \
+   mock_management.c \
+   $(top_srcdir)/src/openvpn/buffer.c \
+   $(top_srcdir)/src/openvpn/win32-util.c \
+   $(top_srcdir)/src/openvpn/platform.c \
+   $(top_srcdir)/src/openvpn/env_set.c \
+   $(top_srcdir)/src/openvpn/run_command.c \
+   $(top_srcdir)/src/openvpn/socket_util.c
+
diff --git a/tests/unit_tests/openvpn/mock_management.c 
b/tests/unit_tests/openvpn/mock_management.c
index b24e4c4..ea470ca 100644
--- a/tests/unit_tests/openvpn/mock_management.c
+++ b/tests/unit_tests/openvpn/mock_management.c
@@ -46,4 +46,19 @@
 {
 return NULL;
 }
+
+void
+management_set_state(struct management *man, const int state, const char 
*detail,
+ const in_addr_t *tun_local_ip, const struct in6_addr 
*tun_local_ip6,
+ const struct openvpn_sockaddr *local_addr,
+ const struct openvpn_sockaddr *remote_addr)
+{
+}
+
+void
+management_sleep(const int n)
+{
+}
+
+
 #endif
diff --git a/tests/unit_tests/openvpn/test_socket.c 
b/tests/unit_tests/openvpn/test_socket.c
new file mode 100644
index 000..a73c53a
--- /dev/null
+++ b/tests/unit_tests/openvpn/test_socket.c
@@ -0,0 +1,111 @@
+/*
+ *  OpenVPN -- An application to securely tunnel IP networks
+ * over a single UDP port, with support for SSL/TLS-based
+ * session authentication and key exchange,
+ * packet encryption, packet authentication, and
+ * packet compression.
+ *
+ *  Copyright (C) 2021-2025 Arne Schwabe 
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2
+ *  as published by the Free Softw

[Openvpn-devel] [M] Change in openvpn[master]: Add new unit test module test_socket

2025-08-29 Thread flichtenheld (Code Review)
Attention is currently required from: plaisthos.

Hello plaisthos,

I'd like you to reexamine a change. Please visit

http://gerrit.openvpn.net/c/openvpn/+/1160?usp=email

to look at the new patch set (#3).


Change subject: Add new unit test module test_socket
..

Add new unit test module test_socket

With a first UT that tests add_in6_addr() (and
print_in6_addr implicitly).

Change-Id: If546f64a4554b292623bfcfe9ee53bac17dfa803
Signed-off-by: Frank Lichtenheld 
---
M CMakeLists.txt
M tests/unit_tests/openvpn/Makefile.am
M tests/unit_tests/openvpn/mock_management.c
A tests/unit_tests/openvpn/test_socket.c
4 files changed, 157 insertions(+), 10 deletions(-)


  git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/60/1160/3

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 45044af..6ca08fb 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -653,6 +653,7 @@
 "test_packet_id"
 "test_pkt"
 "test_provider"
+"test_socket"
 "test_ssl"
 "test_user_pass"
 "test_push_update_msg"
@@ -849,6 +850,15 @@
 src/openvpn/base64.c
 )

+target_sources(test_socket PRIVATE
+tests/unit_tests/openvpn/mock_get_random.c
+tests/unit_tests/openvpn/mock_management.c
+tests/unit_tests/openvpn/mock_win32_execve.c
+src/openvpn/env_set.c
+src/openvpn/run_command.c
+src/openvpn/socket_util.c
+)
+
 target_sources(test_user_pass PRIVATE
 tests/unit_tests/openvpn/mock_get_random.c
 tests/unit_tests/openvpn/mock_win32_execve.c
diff --git a/tests/unit_tests/openvpn/Makefile.am 
b/tests/unit_tests/openvpn/Makefile.am
index b24e03c..d030185 100644
--- a/tests/unit_tests/openvpn/Makefile.am
+++ b/tests/unit_tests/openvpn/Makefile.am
@@ -4,23 +4,17 @@

 AM_TESTSUITE_SUMMARY_HEADER = ' for $(PACKAGE_STRING) Unit-Tests'

-test_binaries=
+test_binaries = crypto_testdriver packet_id_testdriver auth_token_testdriver \
+   ncp_testdriver misc_testdriver pkt_testdriver ssl_testdriver \
+   user_pass_testdriver push_update_msg_testdriver provider_testdriver 
socket_testdriver

 if HAVE_LD_WRAP_SUPPORT
 test_binaries += argv_testdriver buffer_testdriver
-endif
-
-test_binaries += crypto_testdriver packet_id_testdriver auth_token_testdriver 
ncp_testdriver misc_testdriver \
-   pkt_testdriver ssl_testdriver user_pass_testdriver 
push_update_msg_testdriver
-
-if HAVE_LD_WRAP_SUPPORT
 if !WIN32
 test_binaries += tls_crypt_testdriver
 endif
 endif

-test_binaries += provider_testdriver
-
 if WIN32
 test_binaries += cryptoapi_testdriver
 LDADD = -lws2_32
@@ -343,4 +337,22 @@
$(top_srcdir)/src/openvpn/platform.c \
$(top_srcdir)/src/openvpn/push_util.c \
$(top_srcdir)/src/openvpn/options_util.c \
-   $(top_srcdir)/src/openvpn/otime.c
\ No newline at end of file
+   $(top_srcdir)/src/openvpn/otime.c
+
+socket_testdriver_CFLAGS  = \
+   -I$(top_srcdir)/include -I$(top_srcdir)/src/compat 
-I$(top_srcdir)/src/openvpn \
+   -DSOURCEDIR=\"$(top_srcdir)\" @TEST_CFLAGS@
+
+socket_testdriver_LDFLAGS = @TEST_LDFLAGS@ $(SOCKETS_LIBS)
+
+socket_testdriver_SOURCES = test_socket.c \
+   mock_msg.c test_common.h  \
+   mock_get_random.c \
+   mock_management.c \
+   $(top_srcdir)/src/openvpn/buffer.c \
+   $(top_srcdir)/src/openvpn/win32-util.c \
+   $(top_srcdir)/src/openvpn/platform.c \
+   $(top_srcdir)/src/openvpn/env_set.c \
+   $(top_srcdir)/src/openvpn/run_command.c \
+   $(top_srcdir)/src/openvpn/socket_util.c
+
diff --git a/tests/unit_tests/openvpn/mock_management.c 
b/tests/unit_tests/openvpn/mock_management.c
index b24e4c4..28e541c 100644
--- a/tests/unit_tests/openvpn/mock_management.c
+++ b/tests/unit_tests/openvpn/mock_management.c
@@ -46,4 +46,18 @@
 {
 return NULL;
 }
+
+void
+management_set_state(struct management *man, const int state, const char 
*detail,
+ const in_addr_t *tun_local_ip, const struct in6_addr 
*tun_local_ip6,
+ const struct openvpn_sockaddr *local_addr,
+ const struct openvpn_sockaddr *remote_addr)
+{
+}
+
 #endif
+
+void
+management_sleep(const int n)
+{
+}
diff --git a/tests/unit_tests/openvpn/test_socket.c 
b/tests/unit_tests/openvpn/test_socket.c
new file mode 100644
index 000..a73c53a
--- /dev/null
+++ b/tests/unit_tests/openvpn/test_socket.c
@@ -0,0 +1,111 @@
+/*
+ *  OpenVPN -- An application to securely tunnel IP networks
+ * over a single UDP port, with support for SSL/TLS-based
+ * session authentication and key exchange,
+ * packet encryption, packet authentication, and
+ * packet compression.
+ *
+ *  Copyright (C) 2021-2025 Arne Schwabe 
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2
+ *  as published by 

[Openvpn-devel] [S] Change in openvpn[master]: management: resync timer on bytecount interval change

2025-08-29 Thread stipa (Code Review)
Attention is currently required from: plaisthos, ralf_lici.

stipa has posted comments on this change. ( 
http://gerrit.openvpn.net/c/openvpn/+/1113?usp=email )

Change subject: management: resync timer on bytecount interval change
..


Patch Set 2: Code-Review+2

(1 comment)

Patchset:

PS2:
LGTM.

I am not quite sure why this is needed, at least in my tests I never had to 
wait for a long for timer to be fired and the new value applied, but I guess 
make it more real-time won't harm.



--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1113?usp=email
To unsubscribe, or for help writing mail filters, visit 
http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ic0035d52e0ea123398318870d2f4d21af927a602
Gerrit-Change-Number: 1113
Gerrit-PatchSet: 2
Gerrit-Owner: ralf_lici 
Gerrit-Reviewer: flichtenheld 
Gerrit-Reviewer: plaisthos 
Gerrit-Reviewer: stipa 
Gerrit-CC: openvpn-devel 
Gerrit-Attention: plaisthos 
Gerrit-Attention: ralf_lici 
Gerrit-Comment-Date: Fri, 29 Aug 2025 12:04:40 +
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment
___
Openvpn-devel mailing list
Openvpn-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openvpn-devel


[Openvpn-devel] [M] Change in openvpn[master]: Refactor management bytecount tracking

2025-08-29 Thread ralf_lici (Code Review)
Attention is currently required from: flichtenheld, plaisthos, stipa.

ralf_lici has posted comments on this change. ( 
http://gerrit.openvpn.net/c/openvpn/+/1162?usp=email )

Change subject: Refactor management bytecount tracking
..


Patch Set 1: Code-Review+2

(1 comment)

Patchset:

PS1:
Tested on Linux and it works perfectly.



--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1162?usp=email
To unsubscribe, or for help writing mail filters, visit 
http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I43a93f0d84f01fd808a64115e1b8c3b806706491
Gerrit-Change-Number: 1162
Gerrit-PatchSet: 1
Gerrit-Owner: stipa 
Gerrit-Reviewer: flichtenheld 
Gerrit-Reviewer: plaisthos 
Gerrit-Reviewer: ralf_lici 
Gerrit-CC: openvpn-devel 
Gerrit-Attention: plaisthos 
Gerrit-Attention: flichtenheld 
Gerrit-Attention: stipa 
Gerrit-Comment-Date: Fri, 29 Aug 2025 14:25:36 +
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment
___
Openvpn-devel mailing list
Openvpn-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openvpn-devel


[Openvpn-devel] [M] Change in openvpn[master]: Add new unit test module test_socket

2025-08-29 Thread flichtenheld (Code Review)
Attention is currently required from: plaisthos.

Hello plaisthos,

I'd like you to reexamine a change. Please visit

http://gerrit.openvpn.net/c/openvpn/+/1160?usp=email

to look at the new patch set (#4).


Change subject: Add new unit test module test_socket
..

Add new unit test module test_socket

With a first UT that tests add_in6_addr() (and
print_in6_addr implicitly).

Change-Id: If546f64a4554b292623bfcfe9ee53bac17dfa803
Signed-off-by: Frank Lichtenheld 
---
M CMakeLists.txt
M tests/unit_tests/openvpn/Makefile.am
M tests/unit_tests/openvpn/mock_management.c
A tests/unit_tests/openvpn/test_socket.c
4 files changed, 177 insertions(+), 12 deletions(-)


  git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/60/1160/4

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 45044af..35513e9 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -628,9 +628,11 @@
 target_compile_options(openvpn PRIVATE -DPLUGIN_LIBDIR=\"${PLUGIN_DIR}\")

 find_library(resolv resolv)
-# some platform like BSDs already include resolver functionality in the 
libc and not have an extra resolv library
+# some platform like BSDs already include resolver functionality in the 
libc
+# and do not have an extra resolv library
 if (${resolv} OR APPLE)
-target_link_libraries(openvpn PUBLIC -lresolv)
+set(RESOLV_LIBRARIES resolv)
+target_link_libraries(openvpn PUBLIC ${RESOLV_LIBRARIES})
 endif ()
 endif ()

@@ -653,6 +655,7 @@
 "test_packet_id"
 "test_pkt"
 "test_provider"
+"test_socket"
 "test_ssl"
 "test_user_pass"
 "test_push_update_msg"
@@ -849,6 +852,16 @@
 src/openvpn/base64.c
 )

+target_link_libraries(test_socket PUBLIC ${RESOLV_LIBRARIES})
+target_sources(test_socket PRIVATE
+tests/unit_tests/openvpn/mock_get_random.c
+tests/unit_tests/openvpn/mock_management.c
+tests/unit_tests/openvpn/mock_win32_execve.c
+src/openvpn/env_set.c
+src/openvpn/run_command.c
+src/openvpn/socket_util.c
+)
+
 target_sources(test_user_pass PRIVATE
 tests/unit_tests/openvpn/mock_get_random.c
 tests/unit_tests/openvpn/mock_win32_execve.c
diff --git a/tests/unit_tests/openvpn/Makefile.am 
b/tests/unit_tests/openvpn/Makefile.am
index b24e03c..d030185 100644
--- a/tests/unit_tests/openvpn/Makefile.am
+++ b/tests/unit_tests/openvpn/Makefile.am
@@ -4,23 +4,17 @@

 AM_TESTSUITE_SUMMARY_HEADER = ' for $(PACKAGE_STRING) Unit-Tests'

-test_binaries=
+test_binaries = crypto_testdriver packet_id_testdriver auth_token_testdriver \
+   ncp_testdriver misc_testdriver pkt_testdriver ssl_testdriver \
+   user_pass_testdriver push_update_msg_testdriver provider_testdriver 
socket_testdriver

 if HAVE_LD_WRAP_SUPPORT
 test_binaries += argv_testdriver buffer_testdriver
-endif
-
-test_binaries += crypto_testdriver packet_id_testdriver auth_token_testdriver 
ncp_testdriver misc_testdriver \
-   pkt_testdriver ssl_testdriver user_pass_testdriver 
push_update_msg_testdriver
-
-if HAVE_LD_WRAP_SUPPORT
 if !WIN32
 test_binaries += tls_crypt_testdriver
 endif
 endif

-test_binaries += provider_testdriver
-
 if WIN32
 test_binaries += cryptoapi_testdriver
 LDADD = -lws2_32
@@ -343,4 +337,22 @@
$(top_srcdir)/src/openvpn/platform.c \
$(top_srcdir)/src/openvpn/push_util.c \
$(top_srcdir)/src/openvpn/options_util.c \
-   $(top_srcdir)/src/openvpn/otime.c
\ No newline at end of file
+   $(top_srcdir)/src/openvpn/otime.c
+
+socket_testdriver_CFLAGS  = \
+   -I$(top_srcdir)/include -I$(top_srcdir)/src/compat 
-I$(top_srcdir)/src/openvpn \
+   -DSOURCEDIR=\"$(top_srcdir)\" @TEST_CFLAGS@
+
+socket_testdriver_LDFLAGS = @TEST_LDFLAGS@ $(SOCKETS_LIBS)
+
+socket_testdriver_SOURCES = test_socket.c \
+   mock_msg.c test_common.h  \
+   mock_get_random.c \
+   mock_management.c \
+   $(top_srcdir)/src/openvpn/buffer.c \
+   $(top_srcdir)/src/openvpn/win32-util.c \
+   $(top_srcdir)/src/openvpn/platform.c \
+   $(top_srcdir)/src/openvpn/env_set.c \
+   $(top_srcdir)/src/openvpn/run_command.c \
+   $(top_srcdir)/src/openvpn/socket_util.c
+
diff --git a/tests/unit_tests/openvpn/mock_management.c 
b/tests/unit_tests/openvpn/mock_management.c
index b24e4c4..28e541c 100644
--- a/tests/unit_tests/openvpn/mock_management.c
+++ b/tests/unit_tests/openvpn/mock_management.c
@@ -46,4 +46,18 @@
 {
 return NULL;
 }
+
+void
+management_set_state(struct management *man, const int state, const char 
*detail,
+ const in_addr_t *tun_local_ip, const struct in6_addr 
*tun_local_ip6,
+ const struct openvpn_sockaddr *local_addr,
+ const struct openvpn_sockaddr *remote_addr)
+{
+}
+
 #endif
+
+void
+management_sleep(const int n)
+{
+}
diff --git a/tests/unit_tests/openvpn/test_socket.c 
b/

[Openvpn-devel] [PATCH v1] Refactor management bytecount tracking

2025-08-29 Thread Gert Doering
From: Lev Stipakov 

There are few issues with it:

 - when using DCO, the server part doesn't output BYTECOUNT_CLI
 since process_incoming_link_part1/process_outgoing_link are not called

 - when using DCO, the server part applies bytecount timer to the each
 connection, unneccessary making too many calls to the kernel and also
 uses incorect BYTECOUNT output.

 - client part outputs counters using timer, server part utilizes
 traffic activity -> inconsistency

Following changes have been made:

 - Use timer to output counters in client and server mode. Code which
 deals with bytecount on traffic activity has been removed. This unifies
 DCO and non-DCO, as well as client and server mode

 - In server mode, peers stats are fetched with the single ioctl call

 - Per-packet stats are not persisted anymore in the client mode during
   traffic activity. Instead cumulative stats (including DCO stats) are
   persisted when the session closes.

GitHub: https://github.com/OpenVPN/openvpn/issues/820

Change-Id: I43a93f0d84f01fd808a64115e1b8c3b806706491
Signed-off-by: Lev Stipakov 
Acked-by: Ralf Lici 
---

This change was reviewed on Gerrit and approved by at least one
developer. I request to merge it to master.

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1162
This mail reflects revision 1 of this Change.

Acked-by according to Gerrit (reflected above):
Ralf Lici 


diff --git a/src/openvpn/forward.c b/src/openvpn/forward.c
index 75ca9d5..03b6a0c 100644
--- a/src/openvpn/forward.c
+++ b/src/openvpn/forward.c
@@ -818,7 +818,7 @@
 #ifdef ENABLE_MANAGEMENT
 if (management)
 {
-management_check_bytecount(c, management, &c->c2.timeval);
+management_check_bytecount_client(c, management, &c->c2.timeval);
 }
 #endif /* ENABLE_MANAGEMENT */
 }
@@ -998,14 +998,6 @@
 }
 #endif
 c->c2.original_recv_size = c->c2.buf.len;
-#ifdef ENABLE_MANAGEMENT
-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);
-}
-#endif
 }
 else
 {
@@ -1823,14 +1815,6 @@
 mmap_stats->link_write_bytes = link_write_bytes_global;
 }
 #endif
-#ifdef ENABLE_MANAGEMENT
-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);
-}
-#endif
 }
 }
 
diff --git a/src/openvpn/manage.c b/src/openvpn/manage.c
index aed04f5..bcc7250 100644
--- a/src/openvpn/manage.c
+++ b/src/openvpn/manage.c
@@ -41,6 +41,7 @@
 #include "manage.h"
 #include "openvpn.h"
 #include "dco.h"
+#include "multi.h"
 
 #include "memdbg.h"
 
@@ -517,29 +518,27 @@
 }
 
 static void
-man_bytecount_output_client(struct management *man, counter_type 
dco_read_bytes,
-counter_type dco_write_bytes)
+man_bytecount_output_client(counter_type bytes_in_total, counter_type 
bytes_out_total)
 {
 char in[32];
 char out[32];
 
 /* do in a roundabout way to work around possible mingw or mingw-glibc bug 
*/
-snprintf(in, sizeof(in), counter_format, man->persist.bytes_in + 
dco_read_bytes);
-snprintf(out, sizeof(out), counter_format, man->persist.bytes_out + 
dco_write_bytes);
+snprintf(in, sizeof(in), counter_format, bytes_in_total);
+snprintf(out, sizeof(out), counter_format, bytes_out_total);
 msg(M_CLIENT, ">BYTECOUNT:%s,%s", in, out);
 }
 
-void
-man_bytecount_output_server(const counter_type *bytes_in_total, const 
counter_type *bytes_out_total,
+static void
+man_bytecount_output_server(const counter_type bytes_in_total, const 
counter_type bytes_out_total,
 struct man_def_auth_context *mdac)
 {
 char in[32];
 char out[32];
 /* do in a roundabout way to work around possible mingw or mingw-glibc bug 
*/
-snprintf(in, sizeof(in), counter_format, *bytes_in_total);
-snprintf(out, sizeof(out), counter_format, *bytes_out_total);
+snprintf(in, sizeof(in), counter_format, bytes_in_total);
+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;
 }
 
 static void
@@ -4065,42 +4064,70 @@
 }
 
 void
-management_check_bytecount(struct context *c, struct management *man, struct 
timeval *timeval)
+management_check_bytecount_client(struct context *c, struct management *man, 
struct timeval *timeval)
 {
-if (event_timeout_trigger(&man->connection.bytecount_update_interval, 
timeval, ETT_DEFAULT))
+if (!(man->persist.callback.flags & MCF_SERVER) && 
event_timeout_trigger(&man->connection.bytecount_update_inter

[Openvpn-devel] [PATCH v2] management: resync timer on bytecount interval change

2025-08-29 Thread Gert Doering
From: Ralf Lici 

coarse_timer_wakeup tracks when the next timer-driven task will occur.
When a user issues `bytecount n` on the management interface but the
existing wakeup is more than n seconds ahead, bandwidth logging won’t
run until that original timer fires, delaying logs.

Introduce a flag to detect when the bytecount interval changes and,
when set, recalculate coarse_timer_wakeup so logging fires exactly
n seconds after the command. This guarantees bytecount adheres to the
user-specified interval.

Change-Id: Ic0035d52e0ea123398318870d2f4d21af927a602
Signed-off-by: Ralf Lici 
Acked-by: Lev Stipakov 
---

This change was reviewed on Gerrit and approved by at least one
developer. I request to merge it to master.

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1113
This mail reflects revision 2 of this Change.

Acked-by according to Gerrit (reflected above):
Lev Stipakov 


diff --git a/src/openvpn/forward.c b/src/openvpn/forward.c
index dfc6708..1c9b4f8 100644
--- a/src/openvpn/forward.c
+++ b/src/openvpn/forward.c
@@ -838,6 +838,19 @@
 static void
 check_coarse_timers(struct context *c)
 {
+#ifdef ENABLE_MANAGEMENT
+/* The 'bytecount' command starts a timer at runtime, but it would not be
+ * processed if coarse_timer_wakeup was previously set to a higher value.
+ * Therefore, if the command has arrived, we reset coarse_timer_wakeup in
+ * to order to update it accordingly.
+ */
+if (management && management->connection.bytecount_interval_changed)
+{
+reset_coarse_timers(c);
+management->connection.bytecount_interval_changed = false;
+}
+#endif /* ENABLE_MANAGEMENT */
+
 if (now < c->c2.coarse_timer_wakeup)
 {
 context_reschedule_sec(c, c->c2.coarse_timer_wakeup - now);
diff --git a/src/openvpn/manage.c b/src/openvpn/manage.c
index 8836e79..0df78ee 100644
--- a/src/openvpn/manage.c
+++ b/src/openvpn/manage.c
@@ -503,6 +503,7 @@
 man->connection.bytecount_update_seconds = 0;
 event_timeout_clear(&man->connection.bytecount_update_interval);
 }
+man->connection.bytecount_interval_changed = true;
 msg(M_CLIENT, "SUCCESS: bytecount interval changed");
 }
 
diff --git a/src/openvpn/manage.h b/src/openvpn/manage.h
index eb19a4e..00e3931 100644
--- a/src/openvpn/manage.h
+++ b/src/openvpn/manage.h
@@ -318,6 +318,7 @@
 bool state_realtime;
 bool log_realtime;
 bool echo_realtime;
+bool bytecount_interval_changed;
 int bytecount_update_seconds;
 struct event_timeout bytecount_update_interval;
 


___
Openvpn-devel mailing list
Openvpn-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openvpn-devel