Skip to content

Commit

Permalink
ovpndcocli: prepend control packet with peer-id when using TunBuilder
Browse files Browse the repository at this point in the history
The TunBuilder implementation needs to know which peer to send the
control packet to and for this reason the ovpndcocli component is now
prepending the data with 4 bytes representing the peer-id of the
destination.

Since this approach is incompatible with sending a const Buffer (as it
cannot be modified), send() has to allocate a temporary buffer for the
purpose.

While at it, make transport_send(Buffer) obsolete, as ovpndcocli
is not expected to handle data packets (sent as non-const).

Signed-off-by: Antonio Quartulli <antonio@openvpn.net>
  • Loading branch information
ordex committed Feb 24, 2021
1 parent c52ac98 commit 7b9db69
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions openvpn/dco/ovpndcocli.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,25 +156,23 @@ class OvpnDcoClient : public Client,
if (peer_id == OVPN_PEER_ID_UNDEF)
return transport->transport_send_const(buf);

return send(buf);
}

virtual bool transport_send(BufferAllocated &buf) override {
if (peer_id == OVPN_PEER_ID_UNDEF)
return transport->transport_send(buf);

return send(buf);
}

bool send(const Buffer &buf) {
if (config->builder)
pipe->write_some(buf.const_buffer());
else
if (config->builder) {
Buffer tmp(buf);
tmp.prepend(&peer_id, sizeof(peer_id));
pipe->write_some(tmp.const_buffer());
} else {
genl->send_data(peer_id, buf.c_data(), buf.size());
}

return true;
}

virtual bool transport_send(BufferAllocated &buf) override {
OPENVPN_THROW(dcocli_error,
"Non-const send expected for data channel only, but "
"ovpndcocli is not expected to handle data packets");
}

void get_remote_sockaddr(struct sockaddr_storage &sa, socklen_t &salen) {
memset(&sa, 0, sizeof(sa));

Expand Down

0 comments on commit 7b9db69

Please sign in to comment.