30#if defined(ENABLE_DCO)
54dco_install_key(
struct tls_multi *multi,
struct key_state *ks,
const uint8_t *encrypt_key,
55 const uint8_t *encrypt_iv,
const uint8_t *decrypt_key,
const uint8_t *decrypt_iv,
56 const char *ciphername)
60 msg(
D_DCO_DEBUG,
"%s: peer_id=%d keyid=%d epoch=%d, currently %d keys installed",
75 decrypt_key, decrypt_iv, ciphername, epoch);
91 int key_direction,
const char *ciphername,
bool server)
149 msg(
D_DCO,
"No encryption key found. Purging data channel keys");
154 msg(
D_DCO,
"Cannot delete primary key during wipe: %s (%d)", strerror(-ret), ret);
161 msg(
D_DCO,
"Cannot delete secondary key during wipe: %s (%d)", strerror(-ret), ret);
174 msg(
D_DCO,
"DCO key state mismatch: selected primary key is not installed "
175 "(peer_id=%d, key_id=%d, dco_keys_installed=%d)",
180 struct key_state *secondary = dco_get_secondary_key(multi, primary);
190 "Swapping primary and secondary keys to "
191 "primary-id=%d secondary-id=%d",
197 "Swapping primary and secondary keys to "
198 "primary-id=%d secondary-id=(to be deleted)",
204 msg(
D_DCO,
"DCO key state mismatch: expected old primary key is not installed as DCO primary before swap "
205 "(peer_id=%d, new_primary_key_id=%d, old_primary_key_id=%d, old_primary_dco_status=%d, dco_keys_installed=%d)",
213 msg(
D_DCO,
"Cannot swap keys: %s (%d)", strerror(-ret), ret);
230 msg(
D_DCO,
"Cannot delete secondary key: %s (%d)", strerror(-ret), ret);
238 for (
int i = 0; i <
TM_SIZE; ++i)
240 for (
int j = 0; j <
KS_SIZE; j++)
243 if (ks != primary && ks != secondary)
257 msg(msglevel,
"Note: --fragment disables data channel offload.");
263 msg(msglevel,
"Note: --http-proxy disables data channel offload.");
269 msg(msglevel,
"Note: --socks-proxy disables data channel offload.");
273#if defined(TARGET_FREEBSD)
280 msg(msglevel,
"NOTE: TCP transport disables data channel offload on FreeBSD.");
291 "NOTE: TCP transport disables data channel offload on Windows in server mode.");
298 "NOTE: --remote is not defined. This DCO version doesn't support multipeer. Disabling Data Channel Offload");
304 msg(msglevel,
"NOTE: multiple --local options defined, disabling data channel offload");
326 msg(msglevel,
"No tls-client or tls-server option in configuration "
327 "detected. Disabling data channel offload.");
333 msg(msglevel,
"Note: dev-type not tun, disabling data channel offload.");
339 msg(msglevel,
"Note: afunix tun type selected, disabling data channel offload");
345 msg(msglevel,
"Note: null tun type selected, disabling data channel offload");
352 for (
int i = 0; i < l->
len; ++i)
354 if (!dco_check_option_ce(l->
array[i], msglevel, o->
mode))
362 if (!dco_check_option_ce(&o->
ce, msglevel, o->
mode))
372 "--mode server is set. This DCO version doesn't support multipeer. Disabling Data Channel Offload");
378 msg(msglevel,
"multiple --local options defined, disabling data channel offload");
382#elif defined(TARGET_LINUX)
394 int ret = net_iface_type(NULL, o->
dev, iftype);
395 if ((ret == 0) && (strcmp(iftype,
"ovpn") != 0))
397 msg(msglevel,
"Interface %s exists and is not using the "
398 "ovpn DCO driver. Disabling data channel offload",
402 else if ((ret < 0) && (ret != -ENODEV))
404 msg(msglevel,
"Cannot retrieve type of device %s: %s (%d)", o->
dev, strerror(-ret),
410#if defined(HAVE_LIBCAPNG)
417 if (!capng_have_capability(CAPNG_EFFECTIVE, CAP_SETPCAP))
419 msg(msglevel,
"--user specified but lacking CAP_SETPCAP. "
420 "Cannot retain CAP_NET_ADMIN. Disabling data channel offload");
423 if (!capng_have_capability(CAPNG_PERMITTED, CAP_NET_ADMIN))
425 msg(msglevel,
"--user specified but not permitted to retain CAP_NET_ADMIN. "
426 "Disabling data channel offload");
434 msg(msglevel,
"Note: NOT using '--topology subnet' disables data channel offload.");
440 msg(msglevel,
"Note: --management-query-proxy disables data channel offload.");
458 "Note: --data-ciphers-fallback with cipher '%s' "
459 "disables data channel offload.",
468 "Note: '--allow-compression' is not set to 'no', disabling data channel offload.");
474 msg(msglevel,
"Consider using the '--compress migrate' option.");
483 while ((token =
strsep(&tmp_ciphers,
":")))
488 "Note: cipher '%s' in --data-ciphers is not supported "
489 "by ovpn-dco, disabling data channel offload.",
496 if (strcmp(token,
"none") == 0 && strcmp(o->
authname,
"none") != 0)
499 "Note: cipher '%s' in --data-ciphers is only supported "
500 "with --auth=none by ovpn-dco, disabling data channel "
517 msg(msglevel,
"OPTIONS IMPORT: Server did not request DATA_V2 packet "
518 "format required for data channel offload");
577 struct sockaddr_storage *local)
594 struct sockaddr_in *sock_in4 = (
struct sockaddr_in *)local;
595#if defined(HAVE_IN_PKTINFO) && defined(HAVE_IPI_SPEC_DST)
596 sock_in4->sin_addr = actual->pi.in4.ipi_spec_dst;
597#elif defined(IP_RECVDSTADDR)
598 sock_in4->sin_addr = actual->pi.in4;
603 sock_in4->sin_family = AF_INET;
609 struct sockaddr_in6 *sock_in6 = (
struct sockaddr_in6 *)local;
610 sock_in6->sin6_addr = actual->pi.in6.ipi6_addr;
611 sock_in6->sin6_family = AF_INET6;
631 struct sockaddr *remoteaddr, *localaddr = NULL;
632 struct sockaddr_storage local = { 0 };
648 struct in_addr vpn_ip4 = { 0 };
649 const struct in_addr *vpn_addr4 = NULL;
653 vpn_addr4 = &vpn_ip4;
656 const struct in6_addr *vpn_addr6 = NULL;
662 if (dco_multi_get_localaddr(m, mi, &local))
664 localaddr = (
struct sockaddr *)&local;
682#if defined(TARGET_LINUX) || defined(TARGET_FREEBSD) || defined(_WIN32)
746#if defined(TARGET_LINUX) || defined(TARGET_FREEBSD) || defined(_WIN32)
753 msg(
D_DCO,
"DCO: attempt removing iroutes from system table");
762 net_route_v4_del(net_ctx, &ir->network, ir->netbits,
776 net_route_v4_del(net_ctx, &ifconfig_local, 32, NULL,
789 net_route_v6_del(net_ctx, &ir6->network, ir6->netbits,
802 net_route_v6_del(net_ctx, dest, 128, NULL,
char * string_alloc(const char *str, struct gc_arena *gc)
Duplicate a string, allocating memory under garbage collection.
static void gc_free(struct gc_arena *a)
Free all allocations in a garbage collection arena.
static struct gc_arena gc_new(void)
Allocate and return a new, empty garbage collection arena.
#define COMP_F_ALLOW_ASYM
Compression was explicitly set to allow asymetric compression.
#define COMP_F_MIGRATE
push stub-v2 or comp-lzo no when we see a client with comp-lzo in occ
char * strsep(char **stringp, const char *delim)
void key_direction_state_init(struct key_direction_state *kds, int key_direction)
Data Channel Cryptography Module.
#define CO_EPOCH_DATA_KEY_FORMAT
Bit-flag indicating the epoch the data format.
static const char * dco_get_supported_ciphers(void)
static void dco_remove_peer(struct context *c)
static void dco_delete_iroutes(openvpn_net_ctx_t *net_ctx, const struct context *c)
static bool dco_check_startup_option(msglvl_t msglevel, const struct options *o)
static void dco_install_iroute(struct multi_context *m, struct multi_instance *mi, struct mroute_addr *addr)
static bool dco_check_pull_options(msglvl_t msglevel, const struct options *o)
static bool dco_available(msglvl_t msglevel)
static int dco_p2p_add_new_peer(struct context *c)
static bool dco_check_option(msglvl_t msglevel, const struct options *o)
static bool dco_update_keys(dco_context_t *dco, struct tls_multi *multi)
#define DCO_IROUTE_METRIC
static int dco_multi_add_new_peer(const struct multi_context *m, struct multi_instance *mi)
static int init_key_dco_bi(struct tls_multi *multi, struct key_state *ks, const struct key2 *key2, int key_direction, const char *ciphername, bool server)
int dco_del_key(dco_context_t *dco, unsigned int peerid, dco_key_slot_t slot)
int dco_del_peer(dco_context_t *dco, unsigned int peerid)
void dco_win_add_iroute_ipv6(dco_context_t *dco, struct in6_addr dst, unsigned int netbits, unsigned int peer_id)
void dco_win_del_iroute_ipv4(dco_context_t *dco, in_addr_t dst, unsigned int netbits)
bool dco_win_supports_multipeer(void)
void dco_win_del_iroute_ipv6(dco_context_t *dco, struct in6_addr dst, unsigned int netbits)
int dco_swap_keys(dco_context_t *dco, unsigned int peer_id)
int dco_new_peer(dco_context_t *dco, unsigned int peerid, socket_descriptor_t sd, struct sockaddr *localaddr, struct sockaddr *remoteaddr, const struct in_addr *vpn_ipv4, const struct in6_addr *vpn_ipv6)
void dco_win_add_iroute_ipv4(dco_context_t *dco, in_addr_t dst, unsigned int netbits, unsigned int peer_id)
int dco_new_key(dco_context_t *dco, unsigned int peerid, int keyid, dco_key_slot_t slot, const uint8_t *encrypt_key, const uint8_t *encrypt_iv, const uint8_t *decrypt_key, const uint8_t *decrypt_iv, const char *ciphername, bool epoch)
#define KS_SIZE
Size of the tls_session.key array.
#define TM_SIZE
Size of the tls_multi.session \ array.
#define S_GENERATED_KEYS
The data channel keys have been generated The TLS session is fully authenticated when reaching this s...
struct key_state * tls_select_encryption_key(struct tls_multi *multi)
Selects the primary encryption that should be used to encrypt data of an outgoing packet.
#define MR_ONLINK_DCO_ADDR
bool multi_check_push_ifconfig_ipv6_extra_route(const struct options *o, const struct in6_addr *dest)
Determines if the ifconfig_ipv6_local address falls into the range of the local IP addresses of the V...
bool multi_check_push_ifconfig_extra_route(const struct options *o, in_addr_t dest)
Determines if the ifconfig_push_local address falls into the range of the local IP addresses of the V...
Header file for server-mode related structures and functions.
#define IFACE_TYPE_LEN_MAX
static bool dco_enabled(const struct options *o)
Returns whether the current configuration has dco enabled.
@ OVPN_KEY_SLOT_SECONDARY
#define SF_USE_IP_PKTINFO
static bool proto_is_udp(int proto)
Returns if the protocol being used is UDP.
static bool proto_is_dgram(int proto)
Return if the protocol is datagram (UDP).
Control Channel Common Data Structures.
@ DCO_INSTALLED_SECONDARY
static struct key_state * get_key_scan(struct tls_multi *multi, int index)
gets an item of key_state objects in the order they should be scanned by data channel modules.
@ KS_AUTH_TRUE
Key state is authenticated.
bool tls_item_in_cipher_list(const char *item, const char *list)
Return true iff item is present in the colon-separated zero-terminated cipher list.
Control Channel SSL/Data dynamic negotiation Module This file is split from ssl.h to be able to unit ...
struct local_list * local_list
struct http_proxy_options * http_proxy_options
const char * socks_proxy_server
struct connection_entry ** array
struct tuntap * tuntap
Tun/tap virtual network interface.
bool push_ifconfig_ipv6_defined
bool push_ifconfig_defined
struct tls_multi * tls_multi
TLS state structure for this VPN tunnel.
struct in6_addr push_ifconfig_ipv6_local
struct link_socket ** link_sockets
struct link_socket_info ** link_socket_infos
in_addr_t push_ifconfig_local
Contains all state information for one tunnel.
int mode
Role of this context within the OpenVPN process.
openvpn_net_ctx_t net_ctx
Networking API opaque context.
struct context_2 c2
Level 2 context.
struct options options
Options loaded from command line or configuration file.
struct context_1 c1
Level 1 context.
unsigned int flags
Bit-flags determining behavior of security operation functions.
struct key_ctx_bi key_ctx_bi
OpenSSL cipher and HMAC contexts for both sending and receiving directions.
Garbage collection arena used to keep track of dynamically allocated memory.
struct iroute_ipv6 * next
Container for bidirectional cipher and HMAC key material.
struct key keys[2]
Two unidirectional sets of key material.
Container for two sets of OpenSSL cipher and/or HMAC contexts for both sending and receiving directio...
Key ordering of the key2.keys array.
Security parameter state of one TLS and data channel key session.
struct crypto_options crypto_options
enum dco_key_status dco_status
enum ks_auth_state authenticated
int key_id
Key id for this key_state, inherited from struct tls_session.
Container for unidirectional cipher and HMAC key material.
uint8_t cipher[MAX_CIPHER_KEY_LENGTH]
Key material for cipher operations.
uint8_t hmac[MAX_HMAC_KEY_LENGTH]
Key material for HMAC operations.
struct openvpn_sockaddr dest
struct link_socket_actual actual
bool connection_established
struct link_socket_addr * lsa
struct link_socket_info info
struct local_entry ** array
uint8_t addr[OPENVPN_ETH_ALEN]
struct mroute_addr::@201361377123046052363312040316220023015150251140::@324142022017217332104337017226063207330251301017 v6
struct mroute_addr::@201361377123046052363312040316220023015150251140::@363302133323255313212060077174173034011260361234 v4
Main OpenVPN server state structure.
struct context top
Storage structure for process-wide configuration.
Server-mode state structure for one single VPN tunnel.
struct context context
The context structure storing state for this VPN tunnel.
union openvpn_sockaddr::@051240265251124304325377241125360350250341115171 addr
struct compress_options comp
struct connection_list * connection_list
bool use_peer_id
Whether the data channel uses the DATA_V2 header (peer-id).
struct connection_entry ce
struct iroute_ipv6 * iroutes_ipv6
unsigned int management_flags
bool enable_ncp_fallback
If defined fall back to ciphername if NCP fails.
Security parameter state for a single VPN tunnel.
struct tls_session session[TM_SIZE]
Array of tls_session objects representing control channel sessions with the remote peer.
int dco_peer_id
This is the handle that DCO uses to identify this session with the kernel.
struct key_state key[KS_SIZE]
SOCKET socket_descriptor_t
int dev_type_enum(const char *dev, const char *dev_type)
bool is_dev_type(const char *dev, const char *dev_type, const char *match_type)
bool tun_name_is_fixed(const char *dev)
static bool is_tun_afunix(const char *devnode)
Checks whether a –dev-node parameter specifies a AF_UNIX device.