0
0
mirror of https://github.com/OpenVPN/openvpn3.git synced 2024-09-20 04:02:15 +02:00

ovpndcocli: prepend control packet with peer-id when using TunBuilder

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>
This commit is contained in:
Antonio Quartulli 2021-02-23 16:25:49 +01:00
parent c52ac988ab
commit 7b9db69e0f
No known key found for this signature in database
GPG Key ID: 20C8E22F5B1610AB

View File

@ -156,23 +156,21 @@ public:
if (peer_id == OVPN_PEER_ID_UNDEF)
return transport->transport_send_const(buf);
return send(buf);
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 {
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
genl->send_data(peer_id, buf.c_data(), buf.size());
return true;
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) {