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>
(cherry picked from commit
74d5ece4a035fbbd962ba5ea73c19118b82f8f45)
**/
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
*
return 0;
}
+static inline int
+dco_get_peer_stats(struct context *c)
+{
+ return 0;
+}
+
static inline const char *
dco_get_supported_ciphers()
{
return 0;
}
+int
+dco_get_peer_stats(struct context *c)
+{
+ /* Not implemented. */
+ return 0;
+}
+
const char *
dco_get_supported_ciphers()
{
return 0;
}
+int
+dco_get_peer_stats(struct context *c)
+{
+ /* Not implemented. */
+ return 0;
+}
+
bool
dco_available(int msglevel)
{
#include "tun.h"
#include "crypto.h"
#include "ssl_common.h"
+#include "openvpn.h"
#include <bcrypt.h>
#include <winsock2.h>
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)
{
#include "common.h"
#include "manage.h"
#include "openvpn.h"
+#include "dco.h"
#include "memdbg.h"
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);