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