Skip to content

Commit

Permalink
ovpndcocli.hpp: implement SessionStats::DCOTransportSource
Browse files Browse the repository at this point in the history
The DCO component now implements the SessionStats::DCOTransportSource interface.
This interface is already used by ovpncli.cpp to retrieve the peer stats
from DCO.

With this patch, also the OvpnDcoCli object can be used to retrieve the
peer stats from kernel space.

Signed-off-by: Antonio Quartulli <antonio@openvpn.net>
  • Loading branch information
ordex committed Jun 9, 2021
1 parent 73664bb commit cbbe9d1
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion openvpn/dco/ovpndcocli.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@

class OvpnDcoClient : public Client,
public KoRekey::Receiver,
public TransportClientParent {
public TransportClientParent,
public SessionStats::DCOTransportSource {
friend class ClientConfig;
friend class GeNL;

Expand Down Expand Up @@ -150,6 +151,8 @@ class OvpnDcoClient : public Client,
transport_factory = tcpconf;
}

config->transport.stats->dco_configure(this);

transport = transport_factory->new_transport_client_obj(io_context, this);
transport->transport_start();
}
Expand Down Expand Up @@ -222,11 +225,31 @@ class OvpnDcoClient : public Client,
salen, ipv4, ipv6);
}

void update_peer_stats(uint32_t peer_id, bool sync) {
const SessionStats::DCOTransportSource::Data old_stats = last_stats;

if (peer_id == OVPN_PEER_ID_UNDEF)
return;

TunBuilderBase *tb = config->builder;
if (tb) {
tb->tun_builder_dco_get_peer(peer_id, sync);
queue_read_pipe(nullptr);
} else {
genl->get_peer(peer_id, sync);
}

last_delta = last_stats - old_stats;
}

virtual void resolve_callback(const openvpn_io::error_code &error,
results_type results) override {}

virtual void stop_() override {
if (!halt) {
/* update stats before deleting peer in kernelspace */
update_peer_stats(peer_id, true);

halt = true;

if (config->builder) {
Expand Down Expand Up @@ -547,10 +570,23 @@ class OvpnDcoClient : public Client,
});
}

virtual SessionStats::DCOTransportSource::Data dco_transport_stats_delta() override {
if (halt) {
/* retrieve the last stats update and erase it to avoid race conditions with other queries */
SessionStats::DCOTransportSource::Data delta = last_delta;
last_delta = SessionStats::DCOTransportSource::Data(0, 0);
return delta;
}

update_peer_stats(peer_id, true);
return last_delta;
}

// used to communicate to kernel via privileged process
std::unique_ptr<openvpn_io::posix::stream_descriptor> pipe;

GeNLImpl::Ptr genl;
TransportClient::Ptr transport;
SessionStats::DCOTransportSource::Data last_stats;
SessionStats::DCOTransportSource::Data last_delta;
};

0 comments on commit cbbe9d1

Please sign in to comment.