From: Selva Nair Date: Thu, 15 Dec 2022 23:21:04 +0000 (-0500) Subject: Persist DCO client data channel traffic stats on restart X-Git-Tag: v2.7_alpha1~629 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0fdbb288db06792d5dd29acd14205d751041513d;p=thirdparty%2Fopenvpn.git Persist DCO client data channel traffic stats on restart Signed-off-by: Selva Nair Acked-by: Lev Stipakov Message-Id: <20221215232104.1181936-1-selva.nair@gmail.com> URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg25742.html Signed-off-by: Gert Doering --- diff --git a/src/openvpn/init.c b/src/openvpn/init.c index 219bff84c..e36014730 100644 --- a/src/openvpn/init.c +++ b/src/openvpn/init.c @@ -4165,6 +4165,17 @@ uninit_management_callback(void) #endif } +void +persist_client_stats(struct context *c) +{ +#ifdef ENABLE_MANAGEMENT + if (management) + { + man_persist_client_stats(management, c); + } +#endif +} + /* * Initialize a tunnel instance, handle pre and post-init * signal settings. diff --git a/src/openvpn/init.h b/src/openvpn/init.h index f53b65eee..d0fb6ea13 100644 --- a/src/openvpn/init.h +++ b/src/openvpn/init.h @@ -147,4 +147,6 @@ void write_pid_file(const char *filename, const char *chroot_dir); void remove_pid_file(void); +void persist_client_stats(struct context *c); + #endif /* ifndef INIT_H */ diff --git a/src/openvpn/manage.c b/src/openvpn/manage.c index 9349b62ad..b11de224d 100644 --- a/src/openvpn/manage.c +++ b/src/openvpn/manage.c @@ -4068,6 +4068,19 @@ management_check_bytecount(struct context *c, struct management *man, struct tim } } +/* DCO resets stats on reconnect. Since client expects stats + * to be preserved across reconnects, we need to save DCO + * stats before tearing the tunnel down. + */ +void +man_persist_client_stats(struct management *man, struct context *c) +{ + if (dco_enabled(&c->options) && (dco_get_peer_stats(c) == 0)) + { + management_bytes_client(man, c->c2.dco_read_bytes, c->c2.dco_write_bytes); + } +} + #else /* ifdef ENABLE_MANAGEMENT */ void diff --git a/src/openvpn/manage.h b/src/openvpn/manage.h index 700b15cfb..30291e42b 100644 --- a/src/openvpn/manage.h +++ b/src/openvpn/manage.h @@ -548,6 +548,9 @@ management_bytes_server(struct management *man, } } +void +man_persist_client_stats(struct management *man, struct context *c); + #endif /* ifdef ENABLE_MANAGEMENT */ /** diff --git a/src/openvpn/openvpn.c b/src/openvpn/openvpn.c index 15e21452b..413a750b0 100644 --- a/src/openvpn/openvpn.c +++ b/src/openvpn/openvpn.c @@ -97,6 +97,8 @@ tunnel_point_to_point(struct context *c) perf_pop(); } + persist_client_stats(c); + uninit_management_callback(); /* tear down tunnel instance (unless --persist-tun) */