OpenVPN
control_msg.h
Go to the documentation of this file.
1/*
2 * OpenVPN -- An application to securely tunnel IP networks
3 * over a single TCP/UDP port, with support for SSL/TLS-based
4 * session authentication and key exchange,
5 * packet encryption, packet authentication, and
6 * packet compression.
7 *
8 * Copyright (C) 2002-2026 OpenVPN Inc <sales@openvpn.net>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2
12 * as published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, see <https://www.gnu.org/licenses/>.
21 */
22
36
37#ifndef CONTROL_MSG_H
38#define CONTROL_MSG_H
39
40#include "buffer.h"
41
42/* TLV types */
43#define TLV_TYPE_EARLY_NEG_FLAGS 0x0001 /* early negotiation, in the reset packets */
44#define TLV_TYPE_PROBE_REQUEST 0x0002 /* a client probing a server, in P_CONTROL_V2 */
45#define TLV_TYPE_PROBE_REPLY 0x0003 /* the server's answer, in P_CONTROL_V2 */
46
47/* A TLV header is a 16-bit type/optional field plus a 16-bit length */
48#define CTRL_MSG_TLV_HEADER_LEN 4
49
50/* bit layout of the first 16-bit field */
51#define CTRL_MSG_TLV_OPTIONAL_FLAG 0x8000
52#define CTRL_MSG_TLV_TYPE_MASK 0x7fff
53
57{
58 uint16_t type;
59 bool optional;
60 uint16_t value_len;
61};
62
73bool ctrl_msg_tlv_write_header(struct buffer *buf, uint16_t type, bool optional,
74 uint16_t value_len);
75
81bool ctrl_msg_tlv_write_u16(struct buffer *buf, uint16_t type, bool optional, uint16_t value);
82
90bool ctrl_msg_tlv_peek_header(const struct buffer *buf, struct ctrl_msg_tlv_header *hdr);
91
108bool ctrl_msg_tlv_next(struct buffer *buf, struct ctrl_msg_tlv_header *hdr, struct buffer *value);
109
132bool ctrl_msg_find_tlv(struct buffer *payload, uint16_t wanted_type, struct buffer *value);
133
134#endif /* ifndef CONTROL_MSG_H */
Buffer management functions and garbage collection.
bool ctrl_msg_tlv_write_u16(struct buffer *buf, uint16_t type, bool optional, uint16_t value)
Write a complete TLV whose value is a single 16-bit integer to buf.
Definition control_msg.c:53
bool ctrl_msg_tlv_peek_header(const struct buffer *buf, struct ctrl_msg_tlv_header *hdr)
Read a TLV header from buf without consuming it.
Definition control_msg.c:60
bool ctrl_msg_tlv_write_header(struct buffer *buf, uint16_t type, bool optional, uint16_t value_len)
Write a TLV header (type + optional flag + value length) to buf.
Definition control_msg.c:32
bool ctrl_msg_find_tlv(struct buffer *payload, uint16_t wanted_type, struct buffer *value)
Scan payload for the TLV of type wanted_type, skipping any other TLV type that is marked optional.
Definition control_msg.c:96
bool ctrl_msg_tlv_next(struct buffer *buf, struct ctrl_msg_tlv_header *hdr, struct buffer *value)
Read the next TLV from buf, advancing past its header and value.
Definition control_msg.c:76
Wrapper structure for dynamically allocated memory.
Definition buffer.h:71
The header every TLV carries: the 15-bit type and optional flag packed into the first 16-bit field,...
Definition control_msg.h:57
bool optional
value of the optional flag
Definition control_msg.h:59
uint16_t value_len
length of the value following the header
Definition control_msg.h:60
uint16_t type
the 15-bit TLV type
Definition control_msg.h:58