0
0
mirror of https://github.com/OpenVPN/openvpn.git synced 2024-09-20 12:02:28 +02:00

Introduce dco_get_peer_stats API and Windows implementation

dco_get_peer_stats fetches stats for a single peer. This is mostly
useful in client mode. So far only Windows implements that.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20221214211426.227-1-lstipakov@gmail.com>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg25703.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
This commit is contained in:
Lev Stipakov 2022-12-14 23:14:26 +02:00 committed by Gert Doering
parent a9991b3eb6
commit 74d5ece4a0
5 changed files with 62 additions and 2 deletions

View File

@ -235,6 +235,13 @@ void dco_delete_iroutes(struct multi_context *m, struct multi_instance *mi);
**/
int dco_get_peer_stats_multi(dco_context_t *dco, struct multi_context *m);
/**
* Update traffic statistics for single peer
*
* @param c instance context of the peer
**/
int dco_get_peer_stats(struct context *c);
/**
* Retrieve the list of ciphers supported by the current platform
*
@ -362,6 +369,12 @@ dco_get_peer_stats_multi(dco_context_t *dco, struct multi_context *m)
return 0;
}
static inline int
dco_get_peer_stats(struct context *c)
{
return 0;
}
static inline const char *
dco_get_supported_ciphers()
{

View File

@ -743,6 +743,13 @@ dco_get_peer_stats_multi(dco_context_t *dco, struct multi_context *m)
return 0;
}
int
dco_get_peer_stats(struct context *c)
{
/* Not implemented. */
return 0;
}
const char *
dco_get_supported_ciphers()
{

View File

@ -924,6 +924,13 @@ dco_get_peer_stats_multi(dco_context_t *dco, struct multi_context *m)
return 0;
}
int
dco_get_peer_stats(struct context *c)
{
/* Not implemented. */
return 0;
}
bool
dco_available(int msglevel)
{

View File

@ -33,6 +33,7 @@
#include "tun.h"
#include "crypto.h"
#include "ssl_common.h"
#include "openvpn.h"
#include <bcrypt.h>
#include <winsock2.h>
@ -406,6 +407,33 @@ dco_get_peer_stats_multi(dco_context_t *dco, struct multi_context *m)
return 0;
}
int
dco_get_peer_stats(struct context *c)
{
struct tuntap *tt = c->c1.tuntap;
if (!tuntap_defined(tt))
{
return -1;
}
OVPN_STATS stats;
ZeroMemory(&stats, sizeof(OVPN_STATS));
DWORD bytes_returned = 0;
if (!DeviceIoControl(tt->hand, OVPN_IOCTL_GET_STATS, NULL, 0,
&stats, sizeof(stats), &bytes_returned, NULL))
{
msg(M_WARN | M_ERRNO, "DeviceIoControl(OVPN_IOCTL_GET_STATS) failed");
return -1;
}
c->c2.dco_read_bytes = stats.TransportBytesReceived;
c->c2.dco_write_bytes = stats.TransportBytesSent;
return 0;
}
void
dco_event_set(dco_context_t *dco, struct event_set *es, void *arg)
{

View File

@ -43,6 +43,7 @@
#include "common.h"
#include "manage.h"
#include "openvpn.h"
#include "dco.h"
#include "memdbg.h"
@ -4051,11 +4052,15 @@ management_check_bytecount(struct context *c, struct management *man, struct tim
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 (dco_enabled(&c->options) && (dco_get_peer_stats(c) == 0))
{
dco_read_bytes = c->c2.dco_read_bytes;
dco_write_bytes = c->c2.dco_write_bytes;
}
if (!(man->persist.callback.flags & MCF_SERVER))
{
man_bytecount_output_client(man, dco_read_bytes, dco_write_bytes);