OpenVPN
dco.c
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) 2021-2026 Arne Schwabe <arne@rfc2549.org>
9 * Copyright (C) 2021-2026 Antonio Quartulli <a@unstable.cc>
10 * Copyright (C) 2021-2026 OpenVPN Inc <sales@openvpn.net>
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License version 2
14 * as published by the Free Software Foundation.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program (see the file COPYING included with this
23 * distribution); if not, see <https://www.gnu.org/licenses/>.
24 */
25
26#ifdef HAVE_CONFIG_H
27#include "config.h"
28#endif
29
30#if defined(ENABLE_DCO)
31
32#include "syshead.h"
33#include "crypto.h"
34#include "dco.h"
35#include "errlevel.h"
36#include "multi.h"
37#include "networking.h"
38#include "openvpn.h"
39#include "options.h"
40#include "ssl_common.h"
41#include "ssl_ncp.h"
42#include "tun.h"
43#include "tun_afunix.h"
44
45#if defined(_WIN32)
46#include "dco_win.h"
47#endif
48
49#ifdef HAVE_LIBCAPNG
50#include <cap-ng.h>
51#endif
52
53#if defined(__GNUC__) || defined(__clang__)
54#pragma GCC diagnostic push
55#pragma GCC diagnostic ignored "-Wsign-conversion"
56#endif
57
58static int
59dco_install_key(struct tls_multi *multi, struct key_state *ks, const uint8_t *encrypt_key,
60 const uint8_t *encrypt_iv, const uint8_t *decrypt_key, const uint8_t *decrypt_iv,
61 const char *ciphername)
62
63{
65 msg(D_DCO_DEBUG, "%s: peer_id=%d keyid=%d epoch=%d, currently %d keys installed",
66 __func__, multi->dco_peer_id, ks->key_id, epoch, multi->dco_keys_installed);
67
68 /* Install a key in the PRIMARY slot only when no other key exist.
69 * From that moment on, any new key will be installed in the SECONDARY
70 * slot and will be promoted to PRIMARY when userspace says so (a swap
71 * will be performed in that case)
72 */
73 dco_key_slot_t slot = OVPN_KEY_SLOT_PRIMARY;
74 if (multi->dco_keys_installed > 0)
75 {
77 }
78
79 int ret = dco_new_key(multi->dco, multi->dco_peer_id, ks->key_id, slot, encrypt_key, encrypt_iv,
80 decrypt_key, decrypt_iv, ciphername, epoch);
81 if (ret == 0)
82 {
83 if (multi->dco_keys_installed < 2)
84 {
85 multi->dco_keys_installed++;
86 }
87 ks->dco_status =
89 }
90
91 return ret;
92}
93
94int
95init_key_dco_bi(struct tls_multi *multi, struct key_state *ks, const struct key2 *key2,
96 int key_direction, const char *ciphername, bool server)
97{
98 struct key_direction_state kds;
99 key_direction_state_init(&kds, key_direction);
100
101 return dco_install_key(multi, ks, key2->keys[kds.out_key].cipher, key2->keys[(int)server].hmac,
102 key2->keys[kds.in_key].cipher, key2->keys[1 - (int)server].hmac,
103 ciphername);
104}
105
114static struct key_state *
115dco_get_secondary_key(struct tls_multi *multi, const struct key_state *primary)
116{
117 for (int i = 0; i < KEY_SCAN_SIZE; ++i)
118 {
119 struct key_state *ks = get_key_scan(multi, i);
120 const struct key_ctx_bi *key = &ks->crypto_options.key_ctx_bi;
121
122 if (ks == primary)
123 {
124 continue;
125 }
126
128 {
129 ASSERT(key->initialized);
130 return ks;
131 }
132 }
133
134 return NULL;
135}
136
137bool
138dco_update_keys(dco_context_t *dco, struct tls_multi *multi)
139{
140 /* this function checks if keys have to be swapped or erased, therefore it
141 * can't do much if we don't have any key installed
142 */
143 if (multi->dco_keys_installed == 0)
144 {
145 return true;
146 }
147
148 struct key_state *primary = tls_select_encryption_key(multi);
149 /* no primary key available -> no usable key exists, therefore we should
150 * tell DCO to simply wipe all keys
151 */
152 if (!primary)
153 {
154 msg(D_DCO, "No encryption key found. Purging data channel keys");
155
156 int ret = dco_del_key(dco, multi->dco_peer_id, OVPN_KEY_SLOT_PRIMARY);
157 if (ret < 0)
158 {
159 msg(D_DCO, "Cannot delete primary key during wipe: %s (%d)", strerror(-ret), ret);
160 return false;
161 }
162
164 if (ret < 0)
165 {
166 msg(D_DCO, "Cannot delete secondary key during wipe: %s (%d)", strerror(-ret), ret);
167 return false;
168 }
169
170 multi->dco_keys_installed = 0;
171 return true;
172 }
173
174 /* if we have a primary key, it must have been installed already (keys
175 * are installed upon generation in the TLS code)
176 */
177 if (primary->dco_status == DCO_NOT_INSTALLED)
178 {
179 msg(D_DCO, "DCO key state mismatch: selected primary key is not installed "
180 "(peer_id=%d, key_id=%d, dco_keys_installed=%d)",
181 multi->dco_peer_id, primary->key_id, multi->dco_keys_installed);
182 return false;
183 }
184
185 struct key_state *secondary = dco_get_secondary_key(multi, primary);
186 /* if the current primary key was installed as secondary in DCO,
187 * this means we have promoted it since installation in DCO, and
188 * we now need to tell DCO to swap keys
189 */
190 if (primary->dco_status == DCO_INSTALLED_SECONDARY)
191 {
192 if (secondary)
193 {
195 "Swapping primary and secondary keys to "
196 "primary-id=%d secondary-id=%d",
197 primary->key_id, secondary->key_id);
198 }
199 else
200 {
202 "Swapping primary and secondary keys to "
203 "primary-id=%d secondary-id=(to be deleted)",
204 primary->key_id);
205 }
206
207 if (secondary && secondary->dco_status != DCO_INSTALLED_PRIMARY)
208 {
209 msg(D_DCO, "DCO key state mismatch: expected old primary key is not installed as DCO primary before swap "
210 "(peer_id=%d, new_primary_key_id=%d, old_primary_key_id=%d, old_primary_dco_status=%d, dco_keys_installed=%d)",
211 multi->dco_peer_id, primary->key_id, secondary->key_id, secondary->dco_status, multi->dco_keys_installed);
212 return false;
213 }
214
215 int ret = dco_swap_keys(dco, multi->dco_peer_id);
216 if (ret < 0)
217 {
218 msg(D_DCO, "Cannot swap keys: %s (%d)", strerror(-ret), ret);
219 return false;
220 }
221
223 if (secondary)
224 {
226 }
227 }
228
229 /* if we have no secondary key anymore, inform DCO about it */
230 if (!secondary && multi->dco_keys_installed == 2)
231 {
232 int ret = dco_del_key(dco, multi->dco_peer_id, OVPN_KEY_SLOT_SECONDARY);
233 if (ret < 0)
234 {
235 msg(D_DCO, "Cannot delete secondary key: %s (%d)", strerror(-ret), ret);
236 return false;
237 }
238 multi->dco_keys_installed = 1;
239 }
240
241 /* all keys that are not installed are set to NOT installed. Include also
242 * keys that might even be considered as active keys to be sure*/
243 for (int i = 0; i < TM_SIZE; ++i)
244 {
245 for (int j = 0; j < KS_SIZE; j++)
246 {
247 struct key_state *ks = &multi->session[i].key[j];
248 if (ks != primary && ks != secondary)
249 {
251 }
252 }
253 }
254 return true;
255}
256
257static bool
258dco_check_option_ce(const struct connection_entry *ce, msglvl_t msglevel, int mode)
259{
260 if (ce->fragment)
261 {
262 msg(msglevel, "Note: --fragment disables data channel offload.");
263 return false;
264 }
265
266 if (ce->http_proxy_options)
267 {
268 msg(msglevel, "Note: --http-proxy disables data channel offload.");
269 return false;
270 }
271
272 if (ce->socks_proxy_server)
273 {
274 msg(msglevel, "Note: --socks-proxy disables data channel offload.");
275 return false;
276 }
277
278#if defined(TARGET_FREEBSD)
279 if (ce->local_list)
280 {
281 for (int i = 0; i < ce->local_list->len; i++)
282 {
283 if (!proto_is_dgram(ce->local_list->array[i]->proto))
284 {
285 msg(msglevel, "NOTE: TCP transport disables data channel offload on FreeBSD.");
286 return false;
287 }
288 }
289 }
290#endif
291
292#if defined(_WIN32)
293 if (!proto_is_udp(ce->local_list->array[0]->proto) && mode == MODE_SERVER)
294 {
295 msg(msglevel,
296 "NOTE: TCP transport disables data channel offload on Windows in server mode.");
297 return false;
298 }
299
300 if (!ce->remote && !dco_win_supports_multipeer())
301 {
302 msg(msglevel,
303 "NOTE: --remote is not defined. This DCO version doesn't support multipeer. Disabling Data Channel Offload");
304 return false;
305 }
306
307 if ((mode == MODE_SERVER) && (ce->local_list->len > 1))
308 {
309 msg(msglevel, "NOTE: multiple --local options defined, disabling data channel offload");
310 return false;
311 }
312#endif
313
314 return true;
315}
316
317bool
318dco_check_startup_option(msglvl_t msglevel, const struct options *o)
319{
320 /* check if no dev name was specified at all. In the case,
321 * later logic will most likely stop OpenVPN, so no need to
322 * print any message here.
323 */
324 if (!o->dev)
325 {
326 return false;
327 }
328
329 if (!o->tls_client && !o->tls_server)
330 {
331 msg(msglevel, "No tls-client or tls-server option in configuration "
332 "detected. Disabling data channel offload.");
333 return false;
334 }
335
336 if (dev_type_enum(o->dev, o->dev_type) != DEV_TYPE_TUN)
337 {
338 msg(msglevel, "Note: dev-type not tun, disabling data channel offload.");
339 return false;
340 }
341
342 if (is_tun_afunix(o->dev_node))
343 {
344 msg(msglevel, "Note: afunix tun type selected, disabling data channel offload");
345 return false;
346 }
347
348 if (is_dev_type(o->dev, o->dev_type, "null"))
349 {
350 msg(msglevel, "Note: null tun type selected, disabling data channel offload");
351 return false;
352 }
353
354 if (o->connection_list)
355 {
356 const struct connection_list *l = o->connection_list;
357 for (int i = 0; i < l->len; ++i)
358 {
359 if (!dco_check_option_ce(l->array[i], msglevel, o->mode))
360 {
361 return false;
362 }
363 }
364 }
365 else
366 {
367 if (!dco_check_option_ce(&o->ce, msglevel, o->mode))
368 {
369 return false;
370 }
371 }
372
373#if defined(_WIN32)
374 if ((o->mode == MODE_SERVER) && !dco_win_supports_multipeer())
375 {
376 msg(msglevel,
377 "--mode server is set. This DCO version doesn't support multipeer. Disabling Data Channel Offload");
378 return false;
379 }
380
381 if ((o->mode == MODE_SERVER) && o->ce.local_list->len > 1)
382 {
383 msg(msglevel, "multiple --local options defined, disabling data channel offload");
384 return false;
385 }
386
387#elif defined(TARGET_LINUX)
388 /* if the device name is fixed, we need to check if an interface with this
389 * name already exists. IF it does, it must be a DCO interface, otherwise
390 * DCO has to be disabled in order to continue.
391 */
392 if (tun_name_is_fixed(o->dev))
393 {
395 /* we pass NULL as net_ctx because using DCO on Linux implies that we
396 * are using SITNL and the latter does not need any context. This way we
397 * don't need to have the net_ctx percolate all the way here
398 */
399 int ret = net_iface_type(NULL, o->dev, iftype);
400 if ((ret == 0) && (strcmp(iftype, "ovpn") != 0))
401 {
402 msg(msglevel, "Interface %s exists and is not using the "
403 "ovpn DCO driver. Disabling data channel offload",
404 o->dev);
405 return false;
406 }
407 else if ((ret < 0) && (ret != -ENODEV))
408 {
409 msg(msglevel, "Cannot retrieve type of device %s: %s (%d)", o->dev, strerror(-ret),
410 ret);
411 }
412 }
413#endif /* if defined(_WIN32) */
414
415#if defined(HAVE_LIBCAPNG)
416 /* DCO can't operate without CAP_NET_ADMIN. To retain it when switching user
417 * we need CAP_SETPCAP. CAP_NET_ADMIN also needs to be part of the permitted set
418 * of capabilities in order to retain it.
419 */
420 if (o->username)
421 {
423 {
424 msg(msglevel, "--user specified but lacking CAP_SETPCAP. "
425 "Cannot retain CAP_NET_ADMIN. Disabling data channel offload");
426 return false;
427 }
429 {
430 msg(msglevel, "--user specified but not permitted to retain CAP_NET_ADMIN. "
431 "Disabling data channel offload");
432 return false;
433 }
434 }
435#endif /* if defined(HAVE_LIBCAPNG) */
436
437 if (o->mode == MODE_SERVER && o->topology != TOP_SUBNET)
438 {
439 msg(msglevel, "Note: NOT using '--topology subnet' disables data channel offload.");
440 return false;
441 }
442
443 if (o->management_flags & MF_QUERY_PROXY)
444 {
445 msg(msglevel, "Note: --management-query-proxy disables data channel offload.");
446 return false;
447 }
448
449 /* now that all options have been confirmed to be supported, check
450 * if DCO is truly available on the system
451 */
452 return dco_available(msglevel);
453}
454
455bool
456dco_check_option(msglvl_t msglevel, const struct options *o)
457{
458 /* At this point the ciphers have already been normalised */
459 if (o->enable_ncp_fallback
461 {
462 msg(msglevel,
463 "Note: --data-ciphers-fallback with cipher '%s' "
464 "disables data channel offload.",
465 o->ciphername);
466 return false;
467 }
468
469#if defined(USE_COMP)
470 if (o->comp.alg != COMP_ALG_UNDEF || o->comp.flags & COMP_F_ALLOW_ASYM)
471 {
472 msg(msglevel,
473 "Note: '--allow-compression' is not set to 'no', disabling data channel offload.");
474
475 if (o->mode == MODE_SERVER && !(o->comp.flags & COMP_F_MIGRATE))
476 {
477 /* We can end up here from the multi.c call, only print the
478 * note if it is not already enabled */
479 msg(msglevel, "Consider using the '--compress migrate' option.");
480 }
481 return false;
482 }
483#endif
484
485 struct gc_arena gc = gc_new();
486 char *tmp_ciphers = string_alloc(o->ncp_ciphers, &gc);
487 const char *token;
488 while ((token = strsep(&tmp_ciphers, ":")))
489 {
491 {
492 msg(msglevel,
493 "Note: cipher '%s' in --data-ciphers is not supported "
494 "by ovpn-dco, disabling data channel offload.",
495 token);
496 gc_free(&gc);
497 return false;
498 }
499 /* FreeBSD supports none as cipher type but requires auth none to be
500 * be also enabled */
501 if (strcmp(token, "none") == 0 && strcmp(o->authname, "none") != 0)
502 {
503 msg(msglevel,
504 "Note: cipher '%s' in --data-ciphers is only supported "
505 "with --auth=none by ovpn-dco, disabling data channel "
506 "offload.",
507 token);
508 gc_free(&gc);
509 return false;
510 }
511 }
512 gc_free(&gc);
513
514 return true;
515}
516
517bool
518dco_check_pull_options(msglvl_t msglevel, const struct options *o)
519{
520 if (!o->use_peer_id)
521 {
522 msg(msglevel, "OPTIONS IMPORT: Server did not request DATA_V2 packet "
523 "format required for data channel offload");
524 return false;
525 }
526 return true;
527}
528
529int
531{
532 if (!dco_enabled(&c->options))
533 {
534 return 0;
535 }
536
537 struct link_socket *sock = c->c2.link_sockets[0];
538
540
541 struct sockaddr *remoteaddr = &sock->info.lsa->actual.dest.addr.sa;
542 const struct tls_multi *multi = c->c2.tls_multi;
543#ifdef TARGET_FREEBSD
544 /* In Linux in P2P mode the kernel automatically removes an existing peer
545 * when adding a new peer. FreeBSD needs to explicitly be told to do that */
546 if (c->c2.tls_multi->dco_peer_id != -1)
547 {
549 c->c2.tls_multi->dco_peer_id = -1;
550 }
551#endif
552 int ret = dco_new_peer(&c->c1.tuntap->dco, multi->rx_peer_id, sock->sd, NULL,
553 proto_is_dgram(sock->info.proto) ? remoteaddr : NULL,
554 NULL, NULL);
555 if (ret < 0)
556 {
557 return ret;
558 }
559
560 c->c2.tls_multi->dco_peer_id = multi->rx_peer_id;
561
562 return 0;
563}
564
565void
566dco_remove_peer(struct context *c)
567{
568 if (!dco_enabled(&c->options))
569 {
570 return;
571 }
572
573 if (c->c1.tuntap && c->c2.tls_multi && c->c2.tls_multi->dco_peer_id != -1)
574 {
576 c->c2.tls_multi->dco_peer_id = -1;
577 }
578}
579
580static bool
581dco_multi_get_localaddr(const struct multi_context *m, const struct multi_instance *mi,
582 struct sockaddr_storage *local)
583{
584#if ENABLE_IP_PKTINFO
585 const struct context *c = &mi->context;
586
589 {
590 return false;
591 }
592
593 const struct link_socket_actual *actual = &c->c2.link_socket_infos[0]->lsa->actual;
594
595 switch (actual->dest.addr.sa.sa_family)
596 {
597 case AF_INET:
598 {
599 struct sockaddr_in *sock_in4 = (struct sockaddr_in *)local;
600#if defined(HAVE_IN_PKTINFO) && defined(HAVE_IPI_SPEC_DST)
601 sock_in4->sin_addr = actual->pi.in4.ipi_spec_dst;
602#elif defined(IP_RECVDSTADDR)
603 sock_in4->sin_addr = actual->pi.in4;
604#else
605 /* source IP not available on this platform */
606 return false;
607#endif
608 sock_in4->sin_family = AF_INET;
609 break;
610 }
611
612 case AF_INET6:
613 {
614 struct sockaddr_in6 *sock_in6 = (struct sockaddr_in6 *)local;
615 sock_in6->sin6_addr = actual->pi.in6.ipi6_addr;
616 sock_in6->sin6_family = AF_INET6;
617 break;
618 }
619
620 default:
621 ASSERT(false);
622 }
623
624 return true;
625#else /* if ENABLE_IP_PKTINFO */
626 return false;
627#endif /* if ENABLE_IP_PKTINFO */
628}
629
630int
631dco_multi_add_new_peer(const struct multi_context *m, struct multi_instance *mi)
632{
633 const struct context *c = &mi->context;
634
635 int peer_id = c->c2.tls_multi->rx_peer_id;
636 struct sockaddr *remoteaddr, *localaddr = NULL;
637 struct sockaddr_storage local = { 0 };
638 const socket_descriptor_t sd = c->c2.link_sockets[0]->sd;
639
640
641 if (c->mode == CM_CHILD_TCP)
642 {
643 /* the remote address will be inferred from the TCP socket endpoint */
644 remoteaddr = NULL;
645 }
646 else
647 {
649 remoteaddr = &c->c2.link_socket_infos[0]->lsa->actual.dest.addr.sa;
650 }
651
652 /* In server mode we need to fetch the remote addresses from the push config */
653 struct in_addr vpn_ip4 = { 0 };
654 const struct in_addr *vpn_addr4 = NULL;
656 {
657 vpn_ip4.s_addr = htonl(c->c2.push_ifconfig_local);
658 vpn_addr4 = &vpn_ip4;
659 }
660
661 const struct in6_addr *vpn_addr6 = NULL;
663 {
664 vpn_addr6 = &c->c2.push_ifconfig_ipv6_local;
665 }
666
667 if (dco_multi_get_localaddr(m, mi, &local))
668 {
669 localaddr = (struct sockaddr *)&local;
670 }
671
672 int ret =
673 dco_new_peer(&c->c1.tuntap->dco, peer_id, sd, localaddr, remoteaddr, vpn_addr4, vpn_addr6);
674 if (ret < 0)
675 {
676 return ret;
677 }
678
679 c->c2.tls_multi->dco_peer_id = peer_id;
680
681 return 0;
682}
683
684void
685dco_install_iroute(struct multi_context *m, struct multi_instance *mi, const struct mroute_addr *addr)
686{
687#if defined(TARGET_LINUX) || defined(TARGET_FREEBSD) || defined(_WIN32)
688 if (!dco_enabled(&m->top.options))
689 {
690 return;
691 }
692
693 int addrtype = (addr->type & MR_ADDR_MASK);
694
695 /* If we do not have local IP addr to install, skip the route */
696 if ((addrtype == MR_ADDR_IPV6 && !mi->context.c2.push_ifconfig_ipv6_defined)
697 || (addrtype == MR_ADDR_IPV4 && !mi->context.c2.push_ifconfig_defined))
698 {
699 return;
700 }
701
702#if defined(_WIN32)
703 if (addr->type & MR_ONLINK_DCO_ADDR)
704 {
705 /* Windows does not need these extra routes, so we ignore/skip them */
706 return;
707 }
708#endif
709
710 const struct context *c = &mi->context;
711 if (addrtype == MR_ADDR_IPV6)
712 {
713#if defined(_WIN32)
716#else
717 const struct in6_addr *gateway = &mi->context.c2.push_ifconfig_ipv6_local;
718 if (addr->type & MR_ONLINK_DCO_ADDR)
719 {
720 gateway = NULL;
721 }
722
723 net_route_v6_add(&m->top.net_ctx, &addr->v6.addr, addr->netbits,
724 gateway, c->c1.tuntap->actual_name, 0,
726#endif
727 }
728 else if (addrtype == MR_ADDR_IPV4)
729 {
730#if defined(_WIN32)
733#else
734 in_addr_t dest = htonl(addr->v4.addr);
735 const in_addr_t *gateway = &mi->context.c2.push_ifconfig_local;
736 if (addr->type & MR_ONLINK_DCO_ADDR)
737 {
738 gateway = NULL;
739 }
740
741 net_route_v4_add(&m->top.net_ctx, &dest, addr->netbits, gateway,
743#endif
744 }
745#endif /* if defined(TARGET_LINUX) || defined(TARGET_FREEBSD) || defined(_WIN32) */
746}
747
748void
749dco_delete_iroutes(openvpn_net_ctx_t *net_ctx, const struct context *c)
750{
751#if defined(TARGET_LINUX) || defined(TARGET_FREEBSD) || defined(_WIN32)
752 if (!dco_enabled(&c->options))
753 {
754 return;
755 }
757
758 msg(D_DCO, "DCO: attempt removing iroutes from system table");
759
761 {
762 for (const struct iroute *ir = c->options.iroutes; ir; ir = ir->next)
763 {
764#if defined(_WIN32)
765 dco_win_del_iroute_ipv4(&c->c1.tuntap->dco, htonl(ir->network), ir->netbits);
766#else
767 net_route_v4_del(net_ctx, &ir->network, ir->netbits,
770#endif
771 }
772
773#if !defined(_WIN32)
774 /* Check if we added a host route as the assigned client IP address was
775 * not in the on link scope defined by --ifconfig */
776 in_addr_t ifconfig_local = c->c2.push_ifconfig_local;
777
778 if (multi_check_push_ifconfig_extra_route(&c->options, htonl(ifconfig_local)))
779 {
780 /* On windows we do not install these routes, so we also do not need to delete them */
781 net_route_v4_del(net_ctx, &ifconfig_local, 32, NULL,
783 }
784#endif
785 }
786
788 {
789 for (const struct iroute_ipv6 *ir6 = c->options.iroutes_ipv6; ir6; ir6 = ir6->next)
790 {
791#if defined(_WIN32)
792 dco_win_del_iroute_ipv6(&c->c1.tuntap->dco, ir6->network, ir6->netbits);
793#else
794 net_route_v6_del(net_ctx, &ir6->network, ir6->netbits,
797#endif
798 }
799
800 /* Checked if we added a host route as the assigned client IP address was
801 * outside the --ifconfig-ipv6 tun interface config */
802#if !defined(_WIN32)
803 const struct in6_addr *dest = &c->c2.push_ifconfig_ipv6_local;
805 {
806 /* On windows we do not install these routes, so we also do not need to delete them */
807 net_route_v6_del(net_ctx, dest, 128, NULL,
809 }
810#endif
811 }
812#endif /* if defined(TARGET_LINUX) || defined(TARGET_FREEBSD) || defined(_WIN32) */
813}
814
815#if defined(__GNUC__) || defined(__clang__)
816#pragma GCC diagnostic pop
817#endif
818
819#endif /* defined(ENABLE_DCO) */
char * string_alloc(const char *str, struct gc_arena *gc)
Duplicate a string, allocating memory under garbage collection.
Definition buffer.c:618
static void gc_free(struct gc_arena *a)
Free all allocations in a garbage collection arena.
Definition buffer.h:1974
static struct gc_arena gc_new(void)
Allocate and return a new, empty garbage collection arena.
Definition buffer.h:1958
#define COMP_F_ALLOW_ASYM
Compression was explicitly set to allow asymetric compression.
Definition comp.h:49
#define COMP_F_MIGRATE
push stub-v2 or comp-lzo no when we see a client with comp-lzo in occ
Definition comp.h:47
#define COMP_ALG_UNDEF
Definition comp.h:54
char * strsep(char **stringp, const char *delim)
void key_direction_state_init(struct key_direction_state *kds, int key_direction)
Definition crypto.c:1649
Data Channel Cryptography Module.
#define CO_EPOCH_DATA_KEY_FORMAT
Bit-flag indicating the epoch the data format.
Definition crypto.h:367
static const char * dco_get_supported_ciphers(void)
Definition dco.h:381
static void dco_remove_peer(struct context *c)
Definition dco.h:348
static void dco_delete_iroutes(openvpn_net_ctx_t *net_ctx, const struct context *c)
Definition dco.h:364
static bool dco_check_startup_option(msglvl_t msglevel, const struct options *o)
Definition dco.h:280
static void dco_install_iroute(struct multi_context *m, struct multi_instance *mi, struct mroute_addr *addr)
Definition dco.h:359
static bool dco_check_pull_options(msglvl_t msglevel, const struct options *o)
Definition dco.h:286
static bool dco_available(msglvl_t msglevel)
Definition dco.h:262
static int dco_p2p_add_new_peer(struct context *c)
Definition dco.h:335
static bool dco_check_option(msglvl_t msglevel, const struct options *o)
Definition dco.h:274
static bool dco_update_keys(dco_context_t *dco, struct tls_multi *multi)
Definition dco.h:328
void * dco_context_t
Definition dco.h:259
#define DCO_IROUTE_METRIC
Definition dco.h:46
static int dco_multi_add_new_peer(const struct multi_context *m, struct multi_instance *mi)
Definition dco.h:353
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)
Definition dco.h:321
int dco_del_key(dco_context_t *dco, unsigned int peerid, dco_key_slot_t slot)
Definition dco_win.c:582
int dco_del_peer(dco_context_t *dco, unsigned int peerid)
Definition dco_win.c:467
void dco_win_add_iroute_ipv6(dco_context_t *dco, struct in6_addr dst, unsigned int netbits, unsigned int peer_id)
Definition dco_win.c:1039
void dco_win_del_iroute_ipv4(dco_context_t *dco, in_addr_t dst, unsigned int netbits)
Definition dco_win.c:1060
bool dco_win_supports_multipeer(void)
Definition dco_win.c:1009
void dco_win_del_iroute_ipv6(dco_context_t *dco, struct in6_addr dst, unsigned int netbits)
Definition dco_win.c:1081
int dco_swap_keys(dco_context_t *dco, unsigned int peer_id)
Definition dco_win.c:590
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)
Definition dco_win.c:414
void dco_win_add_iroute_ipv4(dco_context_t *dco, in_addr_t dst, unsigned int netbits, unsigned int peer_id)
Definition dco_win.c:1016
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)
Definition dco_win.c:527
#define D_DCO
Definition errlevel.h:92
#define D_DCO_DEBUG
Definition errlevel.h:115
#define KS_SIZE
Size of the tls_session.key array.
Definition ssl_common.h:476
#define TM_SIZE
Size of the tls_multi.session \ array.
Definition ssl_common.h:557
#define S_GENERATED_KEYS
The data channel keys have been generated The TLS session is fully authenticated when reaching this s...
Definition ssl_common.h:105
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.
Definition ssl.c:4215
#define MF_QUERY_PROXY
Definition manage.h:41
#define MR_ADDR_IPV4
Definition mroute.h:62
#define MR_ONLINK_DCO_ADDR
Definition mroute.h:79
#define MR_ADDR_IPV6
Definition mroute.h:63
#define MR_ADDR_MASK
Definition mroute.h:64
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...
Definition multi.c:4544
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...
Definition multi.c:4524
Header file for server-mode related structures and functions.
#define IFACE_TYPE_LEN_MAX
Definition networking.h:25
void * openvpn_net_ctx_t
Definition networking.h:38
#define msg(flags,...)
Definition error.h:152
unsigned int msglvl_t
Definition error.h:77
#define ASSERT(x)
Definition error.h:221
#define CM_CHILD_TCP
Definition openvpn.h:457
#define MODE_SERVER
Definition options.h:265
static bool dco_enabled(const struct options *o)
Returns whether the current configuration has dco enabled.
Definition options.h:981
@ OVPN_KEY_SLOT_SECONDARY
@ OVPN_KEY_SLOT_PRIMARY
#define DEV_TYPE_TUN
Definition proto.h:35
#define TOP_SUBNET
Definition proto.h:43
#define SF_USE_IP_PKTINFO
Definition socket.h:199
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.
#define KEY_SCAN_SIZE
Definition ssl_common.h:574
@ DCO_INSTALLED_PRIMARY
Definition ssl_common.h:185
@ DCO_INSTALLED_SECONDARY
Definition ssl_common.h:186
@ DCO_NOT_INSTALLED
Definition ssl_common.h:184
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.
Definition ssl_common.h:748
@ KS_AUTH_TRUE
Key state is authenticated.
Definition ssl_common.h:157
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.
Definition ssl_ncp.c:197
Control Channel SSL/Data dynamic negotiation Module This file is split from ssl.h to be able to unit ...
Definition options.h:109
struct local_list * local_list
Definition options.h:110
const char * remote
Definition options.h:116
struct http_proxy_options * http_proxy_options
Definition options.h:124
const char * socks_proxy_server
Definition options.h:125
int fragment
Definition options.h:143
struct tuntap * tuntap
Tun/tap virtual network interface.
Definition openvpn.h:155
bool push_ifconfig_ipv6_defined
Definition openvpn.h:405
bool push_ifconfig_defined
Definition openvpn.h:399
struct tls_multi * tls_multi
TLS state structure for this VPN tunnel.
Definition openvpn.h:300
struct in6_addr push_ifconfig_ipv6_local
Definition openvpn.h:406
struct link_socket ** link_sockets
Definition openvpn.h:220
struct link_socket_info ** link_socket_infos
Definition openvpn.h:221
in_addr_t push_ifconfig_local
Definition openvpn.h:401
Contains all state information for one tunnel.
Definition openvpn.h:445
int mode
Role of this context within the OpenVPN process.
Definition openvpn.h:458
openvpn_net_ctx_t net_ctx
Networking API opaque context.
Definition openvpn.h:472
struct context_2 c2
Level 2 context.
Definition openvpn.h:490
struct options options
Options loaded from command line or configuration file.
Definition openvpn.h:446
struct context_1 c1
Level 1 context.
Definition openvpn.h:489
unsigned int flags
Bit-flags determining behavior of security operation functions.
Definition crypto.h:374
struct key_ctx_bi key_ctx_bi
OpenSSL cipher and HMAC contexts for both sending and receiving directions.
Definition crypto.h:287
Garbage collection arena used to keep track of dynamically allocated memory.
Definition buffer.h:127
Container for bidirectional cipher and HMAC key material.
Definition crypto.h:233
struct key keys[2]
Two unidirectional sets of key material.
Definition crypto.h:236
Container for two sets of OpenSSL cipher and/or HMAC contexts for both sending and receiving directio...
Definition crypto.h:273
Key ordering of the key2.keys array.
Definition crypto.h:252
Security parameter state of one TLS and data channel key session.
Definition ssl_common.h:208
struct crypto_options crypto_options
Definition ssl_common.h:237
enum dco_key_status dco_status
Definition ssl_common.h:271
enum ks_auth_state authenticated
Definition ssl_common.h:259
int key_id
Key id for this key_state, inherited from struct tls_session.
Definition ssl_common.h:217
Container for unidirectional cipher and HMAC key material.
Definition crypto.h:145
uint8_t cipher[MAX_CIPHER_KEY_LENGTH]
Key material for cipher operations.
Definition crypto.h:146
uint8_t hmac[MAX_HMAC_KEY_LENGTH]
Key material for HMAC operations.
Definition crypto.h:148
int proto
Definition options.h:105
struct local_entry ** array
Definition options.h:198
struct mroute_addr::@2::@6 v6
uint8_t addr[OPENVPN_ETH_ALEN]
Definition mroute.h:93
struct mroute_addr::@2::@5 v4
uint8_t type
Definition mroute.h:85
uint8_t netbits
Definition mroute.h:86
Main OpenVPN server state structure.
Definition multi.h:170
struct context top
Storage structure for process-wide configuration.
Definition multi.h:217
Server-mode state structure for one single VPN tunnel.
Definition multi.h:102
struct context context
The context structure storing state for this VPN tunnel.
Definition multi.h:150
union openvpn_sockaddr::@27 addr
struct sockaddr sa
Definition socket_util.h:42
struct connection_list * connection_list
Definition options.h:295
bool use_peer_id
Whether the data channel uses the DATA_V2 header (peer-id).
Definition options.h:703
const char * authname
Definition options.h:579
const char * dev_type
Definition options.h:323
struct iroute_ipv6 * iroutes_ipv6
Definition options.h:513
const char * ncp_ciphers
Definition options.h:578
bool tls_server
Definition options.h:588
bool tls_client
Definition options.h:589
struct iroute * iroutes
Definition options.h:512
unsigned int sockflags
Definition options.h:421
const char * dev_node
Definition options.h:324
const char * dev
Definition options.h:322
Security parameter state for a single VPN tunnel.
Definition ssl_common.h:619
dco_context_t * dco
Definition ssl_common.h:735
struct tls_session session[TM_SIZE]
Array of tls_session objects representing control channel sessions with the remote peer.
Definition ssl_common.h:721
int dco_keys_installed
Definition ssl_common.h:725
uint32_t rx_peer_id
Definition ssl_common.h:707
int dco_peer_id
This is the handle that DCO uses to identify this session with the kernel.
Definition ssl_common.h:733
struct key_state key[KS_SIZE]
Definition ssl_common.h:532
dco_context_t dco
Definition tun.h:247
char * actual_name
Definition tun.h:205
SOCKET socket_descriptor_t
Definition syshead.h:441
uint32_t in_addr_t
Definition syshead.h:52
struct gc_arena gc
Definition test_ssl.c:138
int dev_type_enum(const char *dev, const char *dev_type)
Definition tun.c:527
bool is_dev_type(const char *dev, const char *dev_type, const char *match_type)
Definition tun.c:509
bool tun_name_is_fixed(const char *dev)
Definition tun.c:1826
#define TUNNEL_TYPE(tt)
Definition tun.h:182
static bool is_tun_afunix(const char *devnode)
Checks whether a –dev-node parameter specifies a AF_UNIX device.
Definition tun_afunix.h:61