31#ifndef OPENVPN_SSL_OOB_PROBE_H
32#define OPENVPN_SSL_OOB_PROBE_H
85 return write_u16(buf, msg_type);
96 std::uint16_t msg_type;
97 return read_u16(buf, msg_type) && msg_type == expected_msg_type;
114 return write_u16(buf, field) && write_u16(buf, value_len);
123 std::uint16_t field, value_len;
124 if (!read_u16(buf, field) || !read_u16(buf, value_len))
128 .value_len = value_len};
139 if (value_len < consumed)
141 const std::size_t rest = value_len - consumed;
142 if (buf.
size() < rest)
157inline std::optional<std::uint16_t>
find_tlv(
Buffer &buf, std::uint16_t wanted_type)
159 while (buf.
size() >= 4)
164 if (hdr->type == wanted_type)
165 return hdr->value_len;
171 if (buf.
size() < hdr->value_len)
195 && write_u32(buf,
flags);
203 static std::optional<ProbeParameter>
read(
Buffer &buf, std::uint16_t value_len)
242 && write_u32(buf,
flags);
246 static std::optional<ProbeReply>
read(
Buffer &buf, std::uint16_t value_len)
size_t size() const
Returns the size of the buffer in T objects.
void advance(const size_t delta)
Advances the buffer by the specified delta.
size_t remaining(const size_t tailroom=0) const
Return the number of additional T objects that can be added before capacity is reached (without consi...
void write(Buffer &buf) const
designed to represent an optional reference to an object of type T
bool read_u32(Buffer &buf, std::uint32_t &out)
Read a big-endian uint32 from buf into out; false if fewer than 4 bytes.
bool read_u16(Buffer &buf, std::uint16_t &out)
Read a big-endian uint16 from buf into out; false if fewer than 2 bytes.
bool write_u16(Buffer &buf, std::uint16_t v)
Append a big-endian uint16 to buf; false if there is no room.
bool write_u64(Buffer &buf, std::uint64_t v)
Append a big-endian uint64 to buf; false if there is no room.
bool read_u64(Buffer &buf, std::uint64_t &out)
Read a big-endian uint64 from buf into out; false if fewer than 8 bytes.
bool write_u32(Buffer &buf, std::uint32_t v)
Append a big-endian uint32 to buf; false if there is no room.
bool server_probe_write(Buffer &buf, const ProbeParameter ¶m)
Write a complete SERVER_PROBE (message header + probe_parameter TLV). Client.
bool msg_read_header(Buffer &buf, std::uint16_t expected_msg_type)
bool client_reply_write(Buffer &buf, const ProbeReply &reply)
Write a complete PROBE_REPLY (message header + probe_reply TLV). Server.
std::optional< ProbeReply > client_reply_read(Buffer &buf)
std::optional< TlvHeader > tlv_read_header(Buffer &buf)
bool skip_trailing(Buffer &buf, std::uint16_t value_len, std::size_t consumed)
std::optional< std::uint16_t > find_tlv(Buffer &buf, std::uint16_t wanted_type)
std::optional< ProbeParameter > server_probe_read(Buffer &buf)
bool msg_write_header(Buffer &buf, std::uint16_t msg_type)
Write an OOB message-type header (the 16-bit type preceding the TLVs).
bool tlv_write_header(Buffer &buf, std::uint16_t type, bool optional, std::uint16_t value_len)
Write a TLV header (type + optional flag + value length) to buf.
probe parameter TLV (sent by the client in a SERVER_PROBE).
static constexpr std::size_t WIRE_LEN
static std::optional< ProbeParameter > read(Buffer &buf, std::uint16_t value_len)
bool write(Buffer &buf) const
Append this parameter as a complete TLV (header + value) to buf.
std::uint32_t flags
client capability flags, currently must be 0
std::uint64_t timestamp
client clock as a UNIX timestamp
probe reply TLV (sent by the server in a PROBE_REPLY).
ProtoSessionID peer_session_id
echoes the session id of the request
std::uint16_t weight
DNS-SRV style weight.
std::uint16_t connect_lifetime
seconds the reply is valid as a handshake shortcut
std::uint32_t flags
server behaviour flags (REPLY_FLAG_*)
std::uint16_t priority
DNS-SRV style priority (lower preferred)
std::uint16_t max_latency_diff
candidate-band margin (ms); 0 = client default
static std::optional< ProbeReply > read(Buffer &buf, std::uint16_t value_len)
Read a probe_reply TLV value of value_len bytes; see ProbeParameter::read().
bool write(Buffer &buf) const
Append this reply as a complete TLV (header + value) to buf.
static constexpr std::size_t WIRE_LEN