OpenVPN
init.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) 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
23#ifdef HAVE_CONFIG_H
24#include "config.h"
25#endif
26
27#include "syshead.h"
28
29#ifdef ENABLE_SYSTEMD
30#include <systemd/sd-daemon.h>
31#endif
32
33#include "win32.h"
34#include "init.h"
35#include "run_command.h"
36#include "sig.h"
37#include "occ.h"
38#include "list.h"
39#include "otime.h"
40#include "pool.h"
41#include "gremlin.h"
42#include "occ.h"
43#include "pkcs11.h"
44#include "ps.h"
45#include "lladdr.h"
46#include "ping.h"
47#include "ssl_verify.h"
48#include "ssl_ncp.h"
49#include "tls_crypt.h"
50#include "forward.h"
51#include "auth_token.h"
52#include "mss.h"
53#include "mudp.h"
54#include "dco.h"
55#include "tun_afunix.h"
56#include "schedule.h"
57#include "options_string.h"
58#include "resolve.h"
59#include "acc.h"
60
61#include "memdbg.h"
62
63
64static struct context *static_context; /* GLOBAL */
65static const char *saved_pid_file_name; /* GLOBAL */
66
67/*
68 * Crypto initialization flags
69 */
70#define CF_INIT_TLS_MULTI (1 << 1)
71#define CF_INIT_TLS_AUTH_STANDALONE (1 << 2)
72
73static void do_init_first_time(struct context *c);
74
75static bool do_deferred_p2p_ncp(struct context *c);
76
77static void
79{
80 CLEAR(*c);
81}
82
83static void
85{
86 CLEAR(c->c1);
87}
88
89void
91{
92 CLEAR(c->c2);
93}
94
95void
97{
98 const bool first_time_save = c->first_time;
99 const struct context_persist cpsave = c->persist;
100 context_clear(c);
101 c->first_time = first_time_save;
102 c->persist = cpsave;
103}
104
105#if defined(__GNUC__) || defined(__clang__)
106#pragma GCC diagnostic push
107#pragma GCC diagnostic ignored "-Wsign-conversion"
108#endif
109
110/*
111 * Pass tunnel endpoint and MTU parms to a user-supplied script.
112 * Used to execute the up/down script/plugins.
113 */
114static void
115run_up_down(const char *command, const struct plugin_list *plugins, int plugin_type,
116 const char *arg,
117#ifdef _WIN32
118 DWORD adapter_index,
119#endif
120 const char *dev_type, int tun_mtu, const char *ifconfig_local,
121 const char *ifconfig_remote, const char *context, const char *signal_text,
122 const char *script_type, struct env_set *es)
123{
124 if (signal_text)
125 {
126 setenv_str(es, "signal", signal_text);
127 }
128 setenv_str(es, "script_context", context);
129 setenv_int(es, "tun_mtu", tun_mtu);
130 setenv_str(es, "dev", arg);
131 if (dev_type)
132 {
133 setenv_str(es, "dev_type", dev_type);
134 }
135#ifdef _WIN32
136 setenv_int(es, "dev_idx", adapter_index);
137#endif
138
139 if (!ifconfig_local)
140 {
141 ifconfig_local = "";
142 }
143 if (!ifconfig_remote)
144 {
145 ifconfig_remote = "";
146 }
147 if (!context)
148 {
149 context = "";
150 }
151
152 if (plugin_defined(plugins, plugin_type))
153 {
154 struct argv argv = argv_new();
155 ASSERT(arg);
156 argv_printf(&argv, "%s %d 0 %s %s %s", arg, tun_mtu, ifconfig_local, ifconfig_remote,
157 context);
158
159 if (plugin_call(plugins, plugin_type, &argv, NULL, es) != OPENVPN_PLUGIN_FUNC_SUCCESS)
160 {
161 msg(M_FATAL, "ERROR: up/down plugin call failed");
162 }
163
164 argv_free(&argv);
165 }
166
167 if (command)
168 {
169 struct argv argv = argv_new();
170 ASSERT(arg);
171 setenv_str(es, "script_type", script_type);
172 argv_parse_cmd(&argv, command);
173 argv_printf_cat(&argv, "%s %d 0 %s %s %s", arg, tun_mtu, ifconfig_local, ifconfig_remote,
174 context);
176 openvpn_run_script(&argv, es, S_FATAL, "--up/--down");
177 argv_free(&argv);
178 }
179}
180
181/*
182 * Should be called after options->ce is modified at the top
183 * of a SIGUSR1 restart.
184 */
185static void
187{
188 /*
189 * In pull mode, we usually import --ping/--ping-restart parameters from
190 * the server. However we should also set an initial default --ping-restart
191 * for the period of time before we pull the --ping-restart parameter
192 * from the server.
193 */
196 {
199 }
200}
201
202#ifdef ENABLE_MANAGEMENT
203static bool
204management_callback_proxy_cmd(void *arg, const char **p)
205{
206 struct context *c = arg;
207 struct connection_entry *ce = &c->options.ce;
208 struct gc_arena *gc = &c->c2.gc;
209 bool ret = false;
210
211 update_time();
212 if (streq(p[1], "NONE"))
213 {
214 ret = true;
215 }
216 else if (p[2] && p[3])
217 {
218 if (streq(p[1], "HTTP"))
219 {
220 struct http_proxy_options *ho;
221 if (ce->proto != PROTO_TCP && ce->proto != PROTO_TCP_CLIENT)
222 {
223 msg(M_WARN, "HTTP proxy support only works for TCP based connections");
224 return false;
225 }
227 ho->server = string_alloc(p[2], gc);
228 ho->port = string_alloc(p[3], gc);
229 ho->auth_retry = (p[4] && streq(p[4], "nct") ? PAR_NCT : PAR_ALL);
230 ret = true;
231 }
232 else if (streq(p[1], "SOCKS"))
233 {
235 ce->socks_proxy_port = string_alloc(p[3], gc);
236 ret = true;
237 }
238 }
239 else
240 {
241 msg(M_WARN, "Bad proxy command");
242 }
243
245
246 return ret;
247}
248
249static bool
251{
252 const struct connection_list *l = c->options.connection_list;
253 struct connection_entry *ce = &c->options.ce;
254 struct gc_arena gc;
255 bool ret = true;
256
257 update_time();
258 if (management)
259 {
260 gc = gc_new();
261 {
262 struct buffer out = alloc_buf_gc(256, &gc);
263 buf_printf(&out, ">PROXY:%d,%s,%s", (l ? l->current : 0) + 1,
264 (proto_is_udp(ce->proto) ? "UDP" : "TCP"), np(ce->remote));
267 }
269 while (ce->flags & CE_MAN_QUERY_PROXY)
270 {
272 if (IS_SIG(c))
273 {
274 ret = false;
275 break;
276 }
277 }
279 gc_free(&gc);
280 }
281
282 return ret;
283}
284
299static bool
300management_callback_send_cc_message(void *arg, const char *command, const char *parameters)
301{
302 struct context *c = (struct context *)arg;
303 size_t len = strlen(command) + 1;
304 if (parameters)
305 {
306 len += 1 + strlen(parameters);
307 }
308 if (len > PUSH_BUNDLE_SIZE)
309 {
310 return false;
311 }
312
313 struct gc_arena gc = gc_new();
314 struct buffer buf = alloc_buf_gc(len, &gc);
315 ASSERT(buf_printf(&buf, "%s", command));
316 if (parameters)
317 {
318 ASSERT(buf_printf(&buf, ",%s", parameters));
319 }
321
322 gc_free(&gc);
323 return status;
324}
325
326static unsigned int
328{
329 ASSERT(arg);
330 const struct context *c = (struct context *)arg;
331 const struct connection_list *l = c->options.connection_list;
332
333 return l->len;
334}
335
336static bool
337management_callback_remote_entry_get(void *arg, unsigned int index, char **remote)
338{
339 ASSERT(arg);
340 ASSERT(remote);
341
342 struct context *c = (struct context *)arg;
344 bool ret = true;
345
346 if (l->len > 0 && index < (unsigned int)l->len)
347 {
348 const struct connection_entry *ce = l->array[index];
349 const char *proto = proto2ascii(ce->proto, ce->af, false);
350 const char *status = (ce->flags & CE_DISABLED) ? "disabled" : "enabled";
351
352 /* space for output including 3 commas and a nul */
353 size_t len =
354 strlen(ce->remote) + strlen(ce->remote_port) + strlen(proto) + strlen(status) + 3 + 1;
355 char *out = malloc(len);
357
358 snprintf(out, len, "%s,%s,%s,%s", ce->remote, ce->remote_port, proto, status);
359 *remote = out;
360 }
361 else
362 {
363 ret = false;
364 msg(M_WARN, "Out of bounds index in management query for remote entry: index = %u", index);
365 }
366
367 return ret;
368}
369
370static bool
371management_callback_remote_cmd(void *arg, const char **p)
372{
373 struct context *c = (struct context *)arg;
374 struct connection_entry *ce = &c->options.ce;
375 int ret = false;
376 if (p[1]
379 {
380 unsigned int flags = 0;
381 if (!strcmp(p[1], "ACCEPT"))
382 {
384 ret = true;
385 }
386 else if (!strcmp(p[1], "SKIP"))
387 {
389 ret = true;
390 c->options.ce_advance_count = (p[2]) ? atoi(p[2]) : 1;
391 }
392 else if (!strcmp(p[1], "MOD") && p[2] && p[3])
393 {
394 if (strlen(p[2]) < RH_HOST_LEN && strlen(p[3]) < RH_PORT_LEN)
395 {
396 struct remote_host_store *rhs = c->options.rh_store;
397 if (!rhs)
398 {
400 c->options.rh_store = rhs;
401 }
402 strlcpy(rhs->host, p[2], RH_HOST_LEN);
403 strlcpy(rhs->port, p[3], RH_PORT_LEN);
404
405 ce->remote = rhs->host;
406 ce->remote_port = rhs->port;
408 ret = true;
409 }
410 }
411 if (ret)
412 {
415 }
416 }
417 return ret;
418}
419
420static bool
422{
423 struct gc_arena gc = gc_new();
424 volatile struct connection_entry *ce = &c->options.ce;
425 int ce_changed = true; /* presume the connection entry will be changed */
426
427 update_time();
428 if (management)
429 {
430 struct buffer out = alloc_buf_gc(256, &gc);
431
432 buf_printf(&out, ">REMOTE:%s,%s,%s", np(ce->remote), ce->remote_port,
433 proto2ascii(ce->proto, ce->af, false));
436
441 {
443 if (IS_SIG(c))
444 {
445 ce_changed = false; /* connection entry have not been set */
446 break;
447 }
448 }
450 }
451 gc_free(&gc);
452
453 if (ce_changed)
454 {
455 /* If it is likely a connection entry was modified,
456 * check what changed in the flags and that it was not skipped
457 */
458 const int flags = ((ce->flags >> CE_MAN_QUERY_REMOTE_SHIFT) & CE_MAN_QUERY_REMOTE_MASK);
459 ce_changed = (flags != CE_MAN_QUERY_REMOTE_SKIP);
460 }
461 return ce_changed;
462}
463#endif /* ENABLE_MANAGEMENT */
464
476static void
478{
480
481 l->current = -1;
482 if (c->options.remote_random)
483 {
484 for (int i = l->len - 1; i > 0; --i)
485 {
486 const int64_t j = get_random() % (i + 1);
487 if (i != j)
488 {
489 struct connection_entry *tmp;
490 tmp = l->array[i];
491 l->array[i] = l->array[j];
492 l->array[j] = tmp;
493 }
494 }
495 }
496}
497
498/*
499 * Clear the remote address list
500 */
501static void
503{
504 if (lsa->remote_list && free)
505 {
506 freeaddrinfo(lsa->remote_list);
507 }
508 lsa->remote_list = NULL;
509 lsa->current_remote = NULL;
510}
511
512/*
513 * Increment to next connection entry
514 */
515static void
517{
519 bool ce_defined;
520 const struct connection_entry *ce;
521 int n_cycles = 0;
522
523 do
524 {
525 ce_defined = true;
526 if (c->options.no_advance && l->current >= 0)
527 {
528 c->options.no_advance = false;
529 }
530 else
531 {
532 /* Check if there is another resolved address to try for
533 * the current connection */
535 && c->c1.link_socket_addrs[0].current_remote->ai_next
537 {
539 c->c1.link_socket_addrs[0].current_remote->ai_next;
540 }
541 else
542 {
543 c->options.advance_next_remote = false;
544 /* FIXME (schwabe) fix the persist-remote-ip option for real,
545 * this is broken probably ever since connection lists and multiple
546 * remote existed
547 */
549 {
550 /* Connection entry addrinfo objects might have been
551 * resolved earlier but the entry itself might have been
552 * skipped by management on the previous loop.
553 * If so, clear the addrinfo objects as close_instance does
554 */
556 {
559 }
560
561 /* close_instance should have cleared the addrinfo objects */
563 ASSERT(c->c1.link_socket_addrs[0].remote_list == NULL);
564 }
565 else
566 {
569 }
570
571 int advance_count = 1;
572
573 /* If previous connection entry was skipped by management client
574 * with a count to advance by, apply it.
575 */
576 if (c->options.ce_advance_count > 0)
577 {
578 advance_count = c->options.ce_advance_count;
579 }
580
581 /*
582 * Increase the number of connection attempts
583 * If this is connect-retry-max * size(l)
584 * OpenVPN will quit
585 */
586
587 c->options.unsuccessful_attempts += advance_count;
588 l->current += advance_count;
589
590 if (l->current >= l->len)
591 {
592 l->current %= l->len;
593 if (++n_cycles >= 2)
594 {
595 msg(M_FATAL, "No usable connection profiles are present");
596 }
597 }
598 }
599 }
600
602 ce = l->array[l->current];
603
604 if (ce->flags & CE_DISABLED)
605 {
606 ce_defined = false;
607 }
608
609 c->options.ce = *ce;
610
611#ifdef ENABLE_MANAGEMENT
613 {
614 /* allow management interface to override connection entry details */
615 ce_defined = ce_management_query_remote(c);
616 if (IS_SIG(c))
617 {
618 break;
619 }
620 }
621 else if (ce_defined && management && management_query_proxy_enabled(management))
622 {
623 ce_defined = ce_management_query_proxy(c);
624 if (IS_SIG(c))
625 {
626 break;
627 }
628 }
629#endif
630 } while (!ce_defined);
631
632 /* Check if this connection attempt would bring us over the limit */
633 int max_attempts = l->len * c->options.connect_retry_max;
634 if (max_attempts > 0 && c->options.unsuccessful_attempts > (unsigned int)max_attempts)
635 {
636 msg(M_FATAL, "All connections have been connect-retry-max (%d) times unsuccessful, exiting",
638 }
640}
641
642/*
643 * Query for private key and auth-user-pass username/passwords
644 */
645void
647{
648 /* Certificate password input */
649 if (c->options.key_pass_file)
650 {
652 }
653
654 /* Auth user/pass input */
656 {
658#ifdef ENABLE_MANAGEMENT
661#else
664#endif
665 }
666}
667
668/*
669 * Initialize/Uninitialize HTTP or SOCKS proxy
670 */
671
672static void
674{
675 if (c->c1.http_proxy_owned && c->c1.http_proxy)
676 {
678 c->c1.http_proxy = NULL;
679 c->c1.http_proxy_owned = false;
680 }
681 if (c->c1.socks_proxy_owned && c->c1.socks_proxy)
682 {
684 c->c1.socks_proxy = NULL;
685 c->c1.socks_proxy_owned = false;
686 }
687}
688
689static void
691{
692 bool did_http = false;
693
695
697 {
699
700 /* Possible HTTP proxy user/pass input */
702 if (c->c1.http_proxy)
703 {
704 did_http = true;
705 c->c1.http_proxy_owned = true;
706 }
707 }
708
709 if (!did_http && c->options.ce.socks_proxy_server)
710 {
711 c->c1.socks_proxy =
714 if (c->c1.socks_proxy)
715 {
716 c->c1.socks_proxy_owned = true;
717 }
718 }
719}
720
721static void
723{
725}
726
727static void
729{
731}
732
733static void
739
740void
742{
744
746
748
750
751#if defined(ENABLE_PKCS11)
752 if (c->first_time)
753 {
754 int i;
755 pkcs11_initialize(true, c->options.pkcs11_pin_cache_period);
756 for (i = 0; i < MAX_PARMS && c->options.pkcs11_providers[i] != NULL; i++)
757 {
758 pkcs11_addProvider(
759 c->options.pkcs11_providers[i], c->options.pkcs11_protected_authentication[i],
760 c->options.pkcs11_private_mode[i], c->options.pkcs11_cert_private[i]);
761 }
762 }
763#endif
764
765#if 0 /* test get_user_pass with GET_USER_PASS_NEED_OK flag */
766 {
767 /*
768 * In the management interface, you can okay the request by entering "needok token-insertion-request ok"
769 */
770 struct user_pass up;
771 CLEAR(up);
772 strcpy(up.username, "Please insert your cryptographic token"); /* put the high-level message in up.username */
773 get_user_pass(&up, NULL, "token-insertion-request", GET_USER_PASS_MANAGEMENT|GET_USER_PASS_NEED_OK);
774 msg(M_INFO, "RET:%s", up.password); /* will return the third argument to management interface
775 * 'needok' command, usually 'ok' or 'cancel'. */
776 }
777#endif
778
779#ifdef ENABLE_SYSTEMD
780 /* We can report the PID via getpid() to systemd here as OpenVPN will not
781 * do any fork due to daemon() a future call.
782 * See possibly_become_daemon() [init.c] for more details.
783 */
784 sd_notifyf(0, "READY=1\nSTATUS=Pre-connection initialization successful\nMAINPID=%lu",
785 (unsigned long)getpid());
786#endif
787}
788
789void
791{
792 gc_free(&c->c2.gc);
793 gc_free(&c->options.gc);
794 gc_free(&c->gc);
795}
796
797#if PORT_SHARE
798
799static void
800close_port_share(void)
801{
802 if (port_share)
803 {
804 port_share_close(port_share);
805 port_share = NULL;
806 }
807}
808
809static void
810init_port_share(const struct context *c)
811{
812 if (!port_share && (c->options.port_share_host && c->options.port_share_port))
813 {
814 port_share =
815 port_share_open(c->options.port_share_host, c->options.port_share_port,
816 c->c2.frame.buf.payload_size, c->options.port_share_journal_dir);
817 if (port_share == NULL)
818 {
819 msg(M_FATAL, "Fatal error: Port sharing failed");
820 }
821 }
822}
823
824#endif /* if PORT_SHARE */
825
826
827bool
829{
830 /*
831 * Initialize random number seed. random() is only used
832 * when "weak" random numbers are acceptable.
833 * SSL library routines are always used when cryptographically
834 * strong random numbers are required.
835 */
836 struct timeval tv;
837 if (!gettimeofday(&tv, NULL))
838 {
839 const unsigned int seed = (unsigned int)(tv.tv_sec ^ tv.tv_usec);
840 srandom(seed);
841 }
842
843 error_reset(); /* initialize error.c */
844 reset_check_status(); /* initialize status check code in socket.c */
845
846#ifdef _WIN32
847 init_win32();
848#endif
849
850#ifdef OPENVPN_DEBUG_COMMAND_LINE
851 {
852 int i;
853 for (i = 0; i < argc; ++i)
854 {
855 msg(M_INFO, "argv[%d] = '%s'", i, argv[i]);
856 }
857 }
858#endif
859
860 update_time();
861
862 init_ssl_lib();
863
864#ifdef IFCONFIG_POOL_TEST
865 ifconfig_pool_test(0x0A010004, 0x0A0100FF);
866 return false;
867#endif
868
869#ifdef TIME_TEST
870 time_test();
871 return false;
872#endif
873
874#ifdef GEN_PATH_TEST
875 {
876 struct gc_arena gc = gc_new();
877 const char *fn = gen_path("foo", "bar", &gc);
878 printf("%s\n", fn);
879 gc_free(&gc);
880 }
881 return false;
882#endif
883
884#ifdef STATUS_PRINTF_TEST
885 {
886 struct gc_arena gc = gc_new();
887 const char *tmp_file = platform_create_temp_file("/tmp", "foo", &gc);
888 struct status_output *so = status_open(tmp_file, 0, -1, NULL, STATUS_OUTPUT_WRITE);
889 status_printf(so, "%s", "foo");
890 status_printf(so, "%s", "bar");
891 if (!status_close(so))
892 {
893 msg(M_WARN, "STATUS_PRINTF_TEST: %s: write error", tmp_file);
894 }
895 gc_free(&gc);
896 }
897 return false;
898#endif
899
900 return true;
901}
902
903void
905{
906 free_ssl_lib();
907
908#ifdef ENABLE_PKCS11
909 pkcs11_terminate();
910#endif
911
912#if PORT_SHARE
913 close_port_share();
914#endif
915
916#if defined(MEASURE_TLS_HANDSHAKE_STATS)
917 show_tls_performance_stats();
918#endif
919}
920
921void
922init_verb_mute(struct context *c, unsigned int flags)
923{
924 if (flags & IVM_LEVEL_1)
925 {
926 /* set verbosity and mute levels */
930 }
931
932 /* special D_LOG_RW mode */
933 if (flags & IVM_LEVEL_2)
934 {
936 }
937}
938
939/*
940 * Possibly set --dev based on --dev-node.
941 * For example, if --dev-node /tmp/foo/tun, and --dev undefined,
942 * set --dev to tun.
943 */
944void
946{
947 if (!options->dev && options->dev_node)
948 {
949 /* POSIX basename() implementations may modify its arguments */
950 char *dev_node = string_alloc(options->dev_node, NULL);
951 options->dev = basename(dev_node);
952 }
953}
954
955bool
957{
958 /*
959 * OpenSSL info print mode?
960 */
963 {
965 {
967 }
969 {
971 }
973 {
975 }
977 {
980 }
981 if (options->show_curves)
982 {
984 }
985 return true;
986 }
987 return false;
988}
989
990/*
991 * Static pre-shared key generation mode?
992 */
993bool
995{
996 /* should we disable paging? */
997 if (options->mlock && (options->genkey))
998 {
999 platform_mlockall(true);
1000 }
1001
1003 {
1004 int nbits_written;
1005 const char *genkey_filename = options->genkey_filename;
1006
1007 nbits_written = write_key_file(2, genkey_filename);
1008 if (nbits_written < 0)
1009 {
1010 msg(M_FATAL, "Failed to write key file");
1011 }
1012
1013 msg(D_GENKEY | M_NOPREFIX, "Randomly generated %d bit key written to %s", nbits_written,
1014 genkey_filename ? genkey_filename : "stdout");
1015 return true;
1016 }
1018 {
1020 return true;
1021 }
1023 {
1025 {
1026 msg(M_USAGE,
1027 "--genkey tls-crypt-v2-client requires a server key to be set via --tls-crypt-v2 to create a client key");
1028 }
1029
1033 return true;
1034 }
1036 {
1038 return true;
1039 }
1040 else
1041 {
1042 return false;
1043 }
1044}
1045
1046/*
1047 * Persistent TUN/TAP device management mode?
1048 */
1049bool
1051{
1052 if (!options->persist_config)
1053 {
1054 return false;
1055 }
1056
1057 /* sanity check on options for --mktun or --rmtun */
1058 notnull(options->dev, "TUN/TAP device (--dev)");
1061 {
1063 "options --mktun or --rmtun should only be used together with --dev");
1064 }
1065
1066#if defined(ENABLE_DCO)
1067 if (dco_enabled(options))
1068 {
1069 /* creating a DCO interface via --mktun is not supported as it does not
1070 * make much sense. Since DCO is enabled by default, people may run into
1071 * this without knowing, therefore this case should be properly handled.
1072 *
1073 * Disable DCO if --mktun was provided and print a message to let
1074 * user know.
1075 */
1077 {
1078 msg(M_WARN, "Note: --mktun does not support DCO. Creating TUN interface.");
1079 }
1080
1081 options->disable_dco = true;
1082 }
1083#endif
1084
1085#ifdef ENABLE_FEATURE_TUN_PERSIST
1089 {
1090 set_lladdr(ctx, options->dev, options->lladdr, NULL);
1091 }
1092 return true;
1093#else /* ifdef ENABLE_FEATURE_TUN_PERSIST */
1095 "options --mktun and --rmtun are not available on your operating "
1096 "system. Please check 'man tun' (or 'tap'), whether your system "
1097 "supports using 'ifconfig %s create' / 'destroy' to create/remove "
1098 "persistent tunnel interfaces.",
1099 options->dev);
1100#endif
1101 return false;
1102}
1103
1104/*
1105 * Should we become a daemon?
1106 * Return true if we did it.
1107 */
1108bool
1110{
1111 bool ret = false;
1112
1113#ifdef ENABLE_SYSTEMD
1114 /* return without forking if we are running from systemd */
1115 if (sd_notify(0, "READY=0") > 0)
1116 {
1117 return ret;
1118 }
1119#endif
1120
1121 if (options->daemon)
1122 {
1123 /* Don't chdir immediately, but the end of the init sequence, if needed */
1124
1125#if defined(__APPLE__) && defined(__clang__)
1126#pragma clang diagnostic push
1127#pragma clang diagnostic ignored "-Wdeprecated-declarations"
1128#endif
1129 if (daemon(1, options->log) < 0)
1130 {
1131 msg(M_ERR, "daemon() failed or unsupported");
1132 }
1133#if defined(__APPLE__) && defined(__clang__)
1134#pragma clang diagnostic pop
1135#endif
1137 if (options->log)
1138 {
1140 }
1141
1142 ret = true;
1143 }
1144 return ret;
1145}
1146
1147/*
1148 * Actually do UID/GID downgrade, chroot and SELinux context switching, if requested.
1149 */
1150static void
1151do_uid_gid_chroot(struct context *c, bool no_delay)
1152{
1153 static const char why_not[] = "will be delayed because of --client, --pull, or --up-delay";
1154 struct context_0 *c0 = c->c0;
1155
1156 if (c0 && !c0->uid_gid_chroot_set)
1157 {
1158 /* chroot if requested */
1159 if (c->options.chroot_dir)
1160 {
1161 if (no_delay)
1162 {
1164 }
1165 else if (c->first_time)
1166 {
1167 msg(M_INFO, "NOTE: chroot %s", why_not);
1168 }
1169 }
1170
1171 /* set user and/or group if we want to setuid/setgid */
1172 if (c0->uid_gid_specified)
1173 {
1174 if (no_delay)
1175 {
1177 }
1178 else if (c->first_time)
1179 {
1180 msg(M_INFO, "NOTE: UID/GID downgrade %s", why_not);
1181 }
1182 }
1183
1184#ifdef ENABLE_SELINUX
1185 /* Apply a SELinux context in order to restrict what OpenVPN can do
1186 * to _only_ what it is supposed to do after initialization is complete
1187 * (basically just network I/O operations). Doing it after chroot
1188 * requires /proc to be mounted in the chroot (which is annoying indeed
1189 * but doing it before requires more complex SELinux policies.
1190 */
1191 if (c->options.selinux_context)
1192 {
1193 if (no_delay)
1194 {
1195 if (-1 == setcon(c->options.selinux_context))
1196 {
1197 msg(M_ERR, "setcon to '%s' failed; is /proc accessible?",
1198 c->options.selinux_context);
1199 }
1200 else
1201 {
1202 msg(M_INFO, "setcon to '%s' succeeded", c->options.selinux_context);
1203 }
1204 }
1205 else if (c->first_time)
1206 {
1207 msg(M_INFO, "NOTE: setcon %s", why_not);
1208 }
1209 }
1210#endif
1211
1212 /* Privileges are going to be dropped by now (if requested), be sure
1213 * to prevent any future privilege dropping attempts from now on.
1214 */
1215 if (no_delay)
1216 {
1217 c0->uid_gid_chroot_set = true;
1218 }
1219 }
1220}
1221
1222/*
1223 * Return common name in a way that is formatted for
1224 * prepending to msg() output.
1225 */
1226const char *
1227format_common_name(const struct context *c, struct gc_arena *gc)
1228{
1229 struct buffer out = alloc_buf_gc(256, gc);
1230 if (c->c2.tls_multi)
1231 {
1232 buf_printf(&out, "[%s] ", tls_common_name(c->c2.tls_multi, false));
1233 }
1234 return BSTR(&out);
1235}
1236
1237void
1239{
1240#ifdef _WIN32
1242 {
1245 }
1246 else
1247 {
1249
1250 /* put a title on the top window bar */
1252 {
1255 }
1256 }
1257#endif /* ifdef _WIN32 */
1258}
1259
1260void
1262{
1263 c->c2.coarse_timer_wakeup = 0;
1264}
1265
1266/*
1267 * Initialise the server poll timeout timer
1268 * This timer is used in the http/socks proxy setup so it needs to be setup
1269 * before
1270 */
1271static void
1280
1281/*
1282 * Initialize timers
1283 */
1284static void
1285do_init_timers(struct context *c, bool deferred)
1286{
1287 update_time();
1289
1290 /* initialize inactivity timeout */
1292 {
1294 }
1295
1296 /* initialize inactivity timeout */
1297 if (c->options.session_timeout)
1298 {
1300 }
1301
1302 /* initialize pings */
1303 if (dco_enabled(&c->options))
1304 {
1305 /* The DCO kernel module will send the pings instead of user space */
1308 }
1309 else
1310 {
1312 {
1314 }
1315
1317 {
1319 }
1320 }
1321
1322 /* If the auth-token renewal interval is shorter than reneg-sec, arm
1323 * "auth-token renewal" timer to send additional auth-token to update the
1324 * token on the client more often. If not, this happens automatically
1325 * at renegotiation time, without needing an extra event.
1326 */
1329 {
1331 }
1332
1333 if (!deferred)
1334 {
1335 /* initialize connection establishment timer */
1337
1338 /* initialize occ timers */
1339
1340 if (c->options.occ && !TLS_MODE(c) && c->c2.options_string_local
1342 {
1344 }
1345
1346 if (c->options.mtu_test)
1347 {
1349 now);
1350 }
1351
1352 /* initialize tmp_int optimization that limits the number of times we call
1353 * tls_multi_process in the main event loop */
1355 }
1356}
1357
1358/*
1359 * Initialize traffic shaper.
1360 */
1361static void
1363{
1364 /* initialize traffic shaper (i.e. transmit bandwidth limiter) */
1365 if (c->options.shaper)
1366 {
1368 shaper_msg(&c->c2.shaper);
1369 }
1370}
1371
1372/*
1373 * Allocate route list structures for IPv4 and IPv6
1374 * (we do this for IPv4 even if no --route option has been seen, as other
1375 * parts of OpenVPN might want to fill the route-list with info, e.g. DHCP)
1376 */
1377static void
1379{
1380 if (!c->c1.route_list)
1381 {
1382 ALLOC_OBJ_CLEAR_GC(c->c1.route_list, struct route_list, &c->gc);
1383 }
1384 if (c->options.routes_ipv6 && !c->c1.route_ipv6_list)
1385 {
1387 }
1388}
1389
1390
1391/*
1392 * Initialize the route list, resolving any DNS names in route
1393 * options and saving routes in the environment.
1394 */
1395static void
1397 const struct link_socket_info *link_socket_info, struct env_set *es,
1398 openvpn_net_ctx_t *ctx)
1399{
1400 const char *gw = NULL;
1402 int metric = 0;
1403
1404 /* if DCO is enabled we have both regular routes and iroutes in the system
1405 * routing table, and normal routes must have a higher metric for that to
1406 * work so that iroutes are always matched first
1407 */
1408 if (dco_enabled(options))
1409 {
1410 metric = DCO_DEFAULT_METRIC;
1411 }
1412
1413 if (dev == DEV_TYPE_TUN && (options->topology == TOP_NET30 || options->topology == TOP_P2P))
1414 {
1416 }
1418 {
1420 }
1422 {
1423 metric = options->route_default_metric;
1424 }
1425
1426 if (init_route_list(route_list, options->routes, gw, metric,
1428 {
1429 /* copy routes to environment */
1431 }
1432}
1433
1434static void
1436 const struct link_socket_info *link_socket_info, struct env_set *es,
1437 openvpn_net_ctx_t *ctx)
1438{
1439 const char *gw = NULL;
1440 int metric = -1; /* no metric set */
1441
1442 /* see explanation in do_init_route_list() */
1443 if (dco_enabled(options))
1444 {
1445 metric = DCO_DEFAULT_METRIC;
1446 }
1447
1448 gw = options->ifconfig_ipv6_remote; /* default GW = remote end */
1450 {
1452 }
1453
1455 {
1456 metric = options->route_default_metric;
1457 }
1458
1459 /* redirect (IPv6) gateway to VPN? if yes, add a few more specifics
1460 */
1462 {
1463 char *opt_list[] = { "::/3", "2000::/4", "3000::/4", "fc00::/7", NULL };
1464 int i;
1465
1466 for (i = 0; opt_list[i]; i++)
1467 {
1469 string_alloc(opt_list[i], options->routes_ipv6->gc), NULL,
1471 }
1472 }
1473
1476 {
1477 /* copy routes to environment */
1479 }
1480}
1481
1482
1483/*
1484 * Called after all initialization has been completed.
1485 */
1486void
1487initialization_sequence_completed(struct context *c, const unsigned int flags)
1488{
1489 static const char message[] = "Initialization Sequence Completed";
1490
1491 /* Reset the unsuccessful connection counter on complete initialisation */
1493
1494 /* If we delayed UID/GID downgrade or chroot, do it now */
1495 do_uid_gid_chroot(c, true);
1496
1497 /* Test if errors */
1498 if (flags & ISC_ERRORS)
1499 {
1500#ifdef _WIN32
1503 msg(M_INFO, "%s With Errors ( see http://openvpn.net/faq.html#dhcpclientserv )", message);
1504#else
1505#ifdef ENABLE_SYSTEMD
1506 sd_notifyf(0, "STATUS=Failed to start up: %s With Errors\nERRNO=1", message);
1507#endif
1508 msg(M_INFO, "%s With Errors", message);
1509#endif
1510 }
1511 else
1512 {
1513#ifdef ENABLE_SYSTEMD
1514 sd_notifyf(0, "STATUS=%s", message);
1515#endif
1516 msg(M_INFO, "%s", message);
1517 }
1518
1519 /* Flag that we initialized */
1520 if ((flags & (ISC_ERRORS | ISC_SERVER)) == 0)
1521 {
1522 c->options.no_advance = true;
1523 }
1524
1525#ifdef _WIN32
1527#endif
1528
1529#ifdef ENABLE_MANAGEMENT
1530 /* Tell management interface that we initialized */
1531 if (management)
1532 {
1533 const in_addr_t *tun_local = NULL;
1534 const struct in6_addr *tun_local6 = NULL;
1535 struct openvpn_sockaddr local, remote;
1536 const struct link_socket_actual *actual;
1537 socklen_t sa_len = sizeof(local);
1538 const char *detail = "SUCCESS";
1539 if (flags & ISC_ERRORS)
1540 {
1541 detail = "ERROR";
1542 }
1543 /* Flag route error only on platforms where trivial "already exists" errors
1544 * are filtered out. Currently this is the case on Windows or if usng netlink.
1545 */
1546#if defined(_WIN32) || defined(ENABLE_SITNL)
1547 else if (flags & ISC_ROUTE_ERRORS)
1548 {
1549 detail = "ROUTE_ERROR";
1550 }
1551#endif
1552
1553 CLEAR(local);
1554 actual = &get_link_socket_info(c)->lsa->actual;
1555 remote = actual->dest;
1556 getsockname(c->c2.link_sockets[0]->sd, &local.addr.sa, &sa_len);
1557#if ENABLE_IP_PKTINFO
1558 if (!addr_defined(&local))
1559 {
1560 switch (local.addr.sa.sa_family)
1561 {
1562 case AF_INET:
1563#if defined(HAVE_IN_PKTINFO) && defined(HAVE_IPI_SPEC_DST)
1564 local.addr.in4.sin_addr = actual->pi.in4.ipi_spec_dst;
1565#else
1566 local.addr.in4.sin_addr = actual->pi.in4;
1567#endif
1568 break;
1569
1570 case AF_INET6:
1571 local.addr.in6.sin6_addr = actual->pi.in6.ipi6_addr;
1572 break;
1573 }
1574 }
1575#endif
1576
1577 if (c->c1.tuntap)
1578 {
1579 tun_local = &c->c1.tuntap->local;
1580 tun_local6 = &c->c1.tuntap->local_ipv6;
1581 }
1582 management_set_state(management, OPENVPN_STATE_CONNECTED, detail, tun_local, tun_local6,
1583 &local, &remote);
1584 if (tun_local)
1585 {
1587 }
1588 }
1589#endif /* ifdef ENABLE_MANAGEMENT */
1590}
1591
1596static bool
1597route_noexec_enabled(const struct options *o, const struct tuntap *tt)
1598{
1599 return o->route_noexec || (tt && tt->backend_driver == DRIVER_AFUNIX)
1600 || (tt && tt->backend_driver == DRIVER_NULL);
1601}
1602
1603/*
1604 * Possibly add routes and/or call route-up script
1605 * based on options.
1606 */
1607bool
1609 struct route_ipv6_list *route_ipv6_list, const struct tuntap *tt,
1610 const struct plugin_list *plugins, struct env_set *es, openvpn_net_ctx_t *ctx)
1611{
1612 bool ret = true;
1614 {
1617 }
1618#ifdef ENABLE_MANAGEMENT
1619 if (management)
1620 {
1621 management_up_down(management, "UP", es);
1622 }
1623#endif
1624
1625 if (plugin_defined(plugins, OPENVPN_PLUGIN_ROUTE_UP))
1626 {
1627 if (plugin_call(plugins, OPENVPN_PLUGIN_ROUTE_UP, NULL, NULL, es)
1628 != OPENVPN_PLUGIN_FUNC_SUCCESS)
1629 {
1630 msg(M_WARN, "WARNING: route-up plugin call failed");
1631 }
1632 }
1633
1634 if (options->route_script)
1635 {
1636 struct argv argv = argv_new();
1637 setenv_str(es, "script_type", "route-up");
1639 openvpn_run_script(&argv, es, 0, "--route-up");
1640 argv_free(&argv);
1641 }
1642
1643#ifdef _WIN32
1644 if (options->show_net_up)
1645 {
1648 }
1649 else if (check_debug_level(D_SHOW_NET))
1650 {
1653 }
1654#endif
1655 return ret;
1656}
1657
1658/*
1659 * initialize tun/tap device object
1660 */
1661static void
1663{
1669 c->c2.es, &c->net_ctx, c->c1.tuntap);
1670
1672 {
1673 /* Using AF_UNIX trumps using DCO */
1675 }
1676 else if (is_dev_type(c->options.dev, c->options.dev_type, "null"))
1677 {
1679 }
1680#ifdef _WIN32
1681 else
1682 {
1684 }
1685#else
1686 else if (dco_enabled(&c->options))
1687 {
1689 }
1690 else
1691 {
1693 }
1694#endif
1695
1697
1698 c->c1.tuntap_owned = true;
1699}
1700
1701/*
1702 * Open tun/tap device, ifconfig, call up script, etc.
1703 */
1704
1705
1706static bool
1707can_preserve_tun(const struct tuntap *tt)
1708{
1709 if (tt && tt->backend_driver == DRIVER_AFUNIX)
1710 {
1711 return false;
1712 }
1713#ifdef TARGET_ANDROID
1714 return false;
1715#else
1716 return is_tun_type_set(tt);
1717#endif
1718}
1719
1728static void
1729add_wfp_block(const struct context *c)
1730{
1731#if defined(_WIN32)
1732 /* Fortify 'redirect-gateway block-local' with firewall rules? */
1733 bool block_local = block_local_needed(c->c1.route_list);
1734
1735 if (c->options.block_outside_dns || block_local)
1736 {
1737 BOOL dns_only = !block_local;
1738 if (!win_wfp_block(c->c1.tuntap->adapter_index, c->options.msg_channel, dns_only))
1739 {
1740 msg(M_FATAL, "WFP: initialization failed");
1741 }
1742 }
1743#endif
1744}
1745
1754static void
1755del_wfp_block(const struct context *c, unsigned long adapter_index)
1756{
1757#if defined(_WIN32)
1759 {
1760 if (!win_wfp_uninit(adapter_index, c->options.msg_channel))
1761 {
1762 msg(M_FATAL, "WFP: deinitialization failed");
1763 }
1764 }
1765#endif
1766}
1767
1773static bool
1775{
1776 return c->options.ifconfig_noexec
1777 || (c->c1.tuntap && c->c1.tuntap->backend_driver == DRIVER_AFUNIX)
1778 || (c->c1.tuntap && c->c1.tuntap->backend_driver == DRIVER_NULL);
1779}
1780
1781static void
1783{
1784 struct tuntap *tt = c->c1.tuntap;
1785
1786 if (tt->backend_driver == DRIVER_NULL)
1787 {
1789 }
1790 else if (tt->backend_driver == DRIVER_AFUNIX)
1791 {
1792 open_tun_afunix(&c->options, c->c2.frame.tun_mtu, tt, c->c2.es);
1793 }
1794 else
1795 {
1797 }
1798 msg(M_INFO, "%s device [%s] opened", print_tun_backend_driver(tt->backend_driver),
1799 tt->actual_name);
1800}
1801
1802
1803static bool
1804do_open_tun(struct context *c, unsigned int *error_flags)
1805{
1806 struct gc_arena gc = gc_new();
1807 bool ret = false;
1808 *error_flags = 0;
1809
1810 if (!can_preserve_tun(c->c1.tuntap))
1811 {
1812#ifdef TARGET_ANDROID
1813 /* If we emulate persist-tun on android we still have to open a new tun and
1814 * then close the old */
1815 int oldtunfd = -1;
1816 if (c->c1.tuntap)
1817 {
1818 oldtunfd = c->c1.tuntap->fd;
1819 free(c->c1.tuntap->actual_name);
1820 free(c->c1.tuntap);
1821 c->c1.tuntap = NULL;
1822 c->c1.tuntap_owned = false;
1823 }
1824#endif
1825
1826 /* initialize (but do not open) tun/tap object, this also sets
1827 * the backend driver type */
1828 do_init_tun(c);
1829
1830 /* inherit the dco context from the tuntap object */
1831 if (c->c2.tls_multi)
1832 {
1833 c->c2.tls_multi->dco = &c->c1.tuntap->dco;
1834 }
1835
1836#ifdef _WIN32
1837 /* store (hide) interactive service handle in tuntap_options */
1839 msg(D_ROUTE, "interactive service msg_channel=%" PRIuPTR, (intptr_t)c->options.msg_channel);
1840#endif
1841
1842 /* allocate route list structure */
1844
1845 /* parse and resolve the route option list */
1846 ASSERT(c->c2.link_sockets[0]);
1847 if (c->options.routes && c->c1.route_list)
1848 {
1850 c->c2.es, &c->net_ctx);
1851 }
1853 {
1855 &c->c2.link_sockets[0]->info, c->c2.es, &c->net_ctx);
1856 }
1857
1858 /* do ifconfig */
1860 {
1861 /* guess actual tun/tap unit number that will be returned
1862 * by open_tun */
1863 const char *guess =
1865 do_ifconfig(c->c1.tuntap, guess, c->c2.frame.tun_mtu, c->c2.es, &c->net_ctx);
1866 }
1867
1868 /* possibly add routes */
1870 {
1871 /* Ignore route_delay, would cause ROUTE_BEFORE_TUN to be ignored */
1873 c->c1.tuntap, c->plugins, c->c2.es, &c->net_ctx);
1874 *error_flags |= (status ? 0 : ISC_ROUTE_ERRORS);
1875 }
1876#ifdef TARGET_ANDROID
1877 /* Store the old fd inside the fd so open_tun can use it */
1878 c->c1.tuntap->fd = oldtunfd;
1879#endif
1880
1881 if (dco_enabled(&c->options))
1882 {
1883 ovpn_dco_init(c);
1884 }
1885
1886 /* open the tun device */
1888
1889 /* set the hardware address */
1890 if (c->options.lladdr)
1891 {
1893 }
1894
1895 /* do ifconfig */
1897 {
1899 &c->net_ctx);
1900 }
1901
1902 run_dns_up_down(true, &c->options, c->c1.tuntap, &c->persist.duri);
1903
1904 /* run the up script */
1905 run_up_down(c->options.up_script, c->plugins, OPENVPN_PLUGIN_UP, c->c1.tuntap->actual_name,
1906#ifdef _WIN32
1908#endif
1912 NULL, "up", c->c2.es);
1913
1914 add_wfp_block(c);
1915
1916 /* possibly add routes */
1918 {
1920 c->c1.tuntap, c->plugins, c->c2.es, &c->net_ctx);
1921 *error_flags |= (status ? 0 : ISC_ROUTE_ERRORS);
1922 }
1923
1924 ret = true;
1925 static_context = c;
1926 }
1927 else
1928 {
1929 msg(M_INFO, "Preserving previous TUN/TAP instance: %s", c->c1.tuntap->actual_name);
1930
1931 /* explicitly set the ifconfig_* env vars */
1933
1934 run_dns_up_down(true, &c->options, c->c1.tuntap, &c->persist.duri);
1935
1936 /* run the up script if user specified --up-restart */
1937 if (c->options.up_restart)
1938 {
1939 run_up_down(c->options.up_script, c->plugins, OPENVPN_PLUGIN_UP,
1940 c->c1.tuntap->actual_name,
1941#ifdef _WIN32
1943#endif
1947 "restart", NULL, "up", c->c2.es);
1948 }
1949
1950 add_wfp_block(c);
1951 }
1952 gc_free(&gc);
1953 return ret;
1954}
1955
1956/*
1957 * Close TUN/TAP device
1958 */
1959
1960static void
1962{
1963 msg(D_CLOSE, "Closing %s interface", print_tun_backend_driver(c->c1.tuntap->backend_driver));
1964
1965 if (c->c1.tuntap)
1966 {
1968 {
1969 undo_ifconfig(c->c1.tuntap, &c->net_ctx);
1970 }
1972 {
1974 }
1975 else if (c->c1.tuntap->backend_driver == DRIVER_NULL)
1976 {
1977 free(c->c1.tuntap->actual_name);
1978 free(c->c1.tuntap);
1979 }
1980 else
1981 {
1982 close_tun(c->c1.tuntap, &c->net_ctx);
1983 }
1984 c->c1.tuntap = NULL;
1985 }
1986 c->c1.tuntap_owned = false;
1988}
1989
1990static void
1991do_close_tun(struct context *c, bool force)
1992{
1993 /* With dco-win we open tun handle in the very beginning.
1994 * In case when tun wasn't opened - like we haven't connected,
1995 * we still need to close tun handle
1996 */
1998 {
2000 return;
2001 }
2002
2003 if (!c->c1.tuntap || !c->c1.tuntap_owned)
2004 {
2005 return;
2006 }
2007
2008 struct gc_arena gc = gc_new();
2009 const char *tuntap_actual = string_alloc(c->c1.tuntap->actual_name, &gc);
2010 const in_addr_t local = c->c1.tuntap->local;
2011 const in_addr_t remote_netmask = c->c1.tuntap->remote_netmask;
2012 unsigned long adapter_index = 0;
2013#ifdef _WIN32
2014 adapter_index = c->c1.tuntap->adapter_index;
2015#endif
2016
2017 run_dns_up_down(false, &c->options, c->c1.tuntap, &c->persist.duri);
2018
2019 if (force || !(c->sig->signal_received == SIGUSR1 && c->options.persist_tun))
2020 {
2021 static_context = NULL;
2022
2023#ifdef ENABLE_MANAGEMENT
2024 /* tell management layer we are about to close the TUN/TAP device */
2025 if (management)
2026 {
2028 management_up_down(management, "DOWN", c->c2.es);
2029 }
2030#endif
2031
2032 /* delete any routes we added */
2033 if (c->c1.route_list || c->c1.route_ipv6_list)
2034 {
2035 run_up_down(c->options.route_predown_script, c->plugins, OPENVPN_PLUGIN_ROUTE_PREDOWN,
2036 tuntap_actual,
2037#ifdef _WIN32
2038 adapter_index,
2039#endif
2040 NULL, c->c2.frame.tun_mtu, print_in_addr_t(local, IA_EMPTY_IF_UNDEF, &gc),
2041 print_in_addr_t(remote_netmask, IA_EMPTY_IF_UNDEF, &gc), "init",
2043 "route-pre-down", c->c2.es);
2044
2046 ROUTE_OPTION_FLAGS(&c->options), c->c2.es, &c->net_ctx);
2047 }
2048
2049 /* actually close tun/tap device based on --down-pre flag */
2050 if (!c->options.down_pre)
2051 {
2053 }
2054
2055 /* Run the down script -- note that it will run at reduced
2056 * privilege if, for example, "--user" was used. */
2057 run_up_down(c->options.down_script, c->plugins, OPENVPN_PLUGIN_DOWN, tuntap_actual,
2058#ifdef _WIN32
2059 adapter_index,
2060#endif
2061 NULL, c->c2.frame.tun_mtu, print_in_addr_t(local, IA_EMPTY_IF_UNDEF, &gc),
2062 print_in_addr_t(remote_netmask, IA_EMPTY_IF_UNDEF, &gc), "init",
2064 c->c2.es);
2065
2066 del_wfp_block(c, adapter_index);
2067
2068 /* actually close tun/tap device based on --down-pre flag */
2069 if (c->options.down_pre)
2070 {
2072 }
2073 }
2074 else
2075 {
2076 /* run the down script on this restart if --up-restart was specified */
2077 if (c->options.up_restart)
2078 {
2079 run_up_down(c->options.down_script, c->plugins, OPENVPN_PLUGIN_DOWN, tuntap_actual,
2080#ifdef _WIN32
2081 adapter_index,
2082#endif
2083 NULL, c->c2.frame.tun_mtu, print_in_addr_t(local, IA_EMPTY_IF_UNDEF, &gc),
2084 print_in_addr_t(remote_netmask, IA_EMPTY_IF_UNDEF, &gc), "restart",
2086 c->c2.es);
2087 }
2088
2089 del_wfp_block(c, adapter_index);
2090 }
2091 gc_free(&gc);
2092}
2093
2094void
2096{
2097 struct context *c = static_context;
2098 if (c)
2099 {
2100 static_context = NULL;
2101 do_close_tun(c, true);
2102 }
2103}
2104
2105/*
2106 * Handle delayed tun/tap interface bringup due to --up-delay or --pull
2107 */
2108
2113static bool
2115{
2116 const struct sha256_digest zero = { { 0 } };
2117 return memcmp(a, b, sizeof(struct sha256_digest))
2118 || !memcmp(a, &zero, sizeof(struct sha256_digest));
2119}
2120
2126static void
2127add_delim_if_non_empty(struct buffer *buf, const char *header)
2128{
2129 if (BLENZ(buf) > strlen(header))
2130 {
2131 buf_printf(buf, ", ");
2132 }
2133}
2134
2135
2140static void
2142{
2143 struct options *o = &c->options;
2144
2145 struct buffer out;
2146 uint8_t line[1024] = { 0 };
2147 buf_set_write(&out, line, sizeof(line));
2148
2149
2151 {
2152 buf_printf(&out, "Data Channel: cipher '%s'", cipher_kt_name(o->ciphername));
2153 }
2154 else
2155 {
2156 buf_printf(&out, "Data Channel: cipher '%s', auth '%s'", cipher_kt_name(o->ciphername),
2157 md_kt_name(o->authname));
2158 }
2159
2160 if (c->c2.tls_multi && c->c2.tls_multi->use_peer_id)
2161 {
2162 buf_printf(&out, ", rx-peer-id: %u, tx-peer-id: %u", c->c2.tls_multi->rx_peer_id,
2163 c->c2.tls_multi->tx_peer_id);
2164 }
2165
2166#ifdef USE_COMP
2167 if (c->c2.comp_context)
2168 {
2169 buf_printf(&out, ", compression: '%s'", c->c2.comp_context->alg.name);
2170 }
2171#endif
2172
2173 msg(D_HANDSHAKE, "%s", BSTR(&out));
2174
2175 buf_clear(&out);
2176
2177 const char *header = "Timers: ";
2178
2179 buf_printf(&out, "%s", header);
2180
2181 if (o->ping_send_timeout)
2182 {
2183 buf_printf(&out, "ping %d", o->ping_send_timeout);
2184 }
2185
2187 {
2188 /* yes unidirectional ping is possible .... */
2189 add_delim_if_non_empty(&out, header);
2190
2192 {
2193 buf_printf(&out, "ping-exit %d", o->ping_rec_timeout);
2194 }
2195 else
2196 {
2197 buf_printf(&out, "ping-restart %d", o->ping_rec_timeout);
2198 }
2199 }
2200
2201 if (o->inactivity_timeout)
2202 {
2203 add_delim_if_non_empty(&out, header);
2204
2205 buf_printf(&out, "inactive %d", o->inactivity_timeout);
2207 {
2208 buf_printf(&out, " %" PRIu64, o->inactivity_minimum_bytes);
2209 }
2210 }
2211
2212 if (o->session_timeout)
2213 {
2214 add_delim_if_non_empty(&out, header);
2215 buf_printf(&out, "session-timeout %d", o->session_timeout);
2216 }
2217
2218 if (BLENZ(&out) > strlen(header))
2219 {
2220 msg(D_HANDSHAKE, "%s", BSTR(&out));
2221 }
2222
2223 buf_clear(&out);
2224 header = "Protocol options: ";
2225 buf_printf(&out, "%s", header);
2226
2228 {
2229 buf_printf(&out, "explicit-exit-notify %d", c->options.ce.explicit_exit_notification);
2230 }
2232 {
2233 add_delim_if_non_empty(&out, header);
2234
2235 buf_printf(&out, "protocol-flags");
2236
2238 {
2239 buf_printf(&out, " cc-exit");
2240 }
2242 {
2243 buf_printf(&out, " tls-ekm");
2244 }
2246 {
2247 buf_printf(&out, " dyn-tls-crypt");
2248 }
2250 {
2251 buf_printf(&out, " aead-epoch");
2252 }
2253 }
2254
2255 struct tls_multi *multi = c->c2.tls_multi;
2256 if (multi && multi->acc_negotiated_protocols)
2257 {
2258 buf_printf(&out, " custom-control %d A:6 %s",
2260 }
2261
2262 if (BLENZ(&out) > strlen(header))
2263 {
2264 msg(D_HANDSHAKE, "%s", BSTR(&out));
2265 }
2266}
2267
2268
2276static bool
2278{
2279 struct frame *frame_fragment = NULL;
2280#ifdef ENABLE_FRAGMENT
2281 if (c->options.ce.fragment)
2282 {
2283 frame_fragment = &c->c2.frame_fragment;
2284 }
2285#endif
2286
2287 /* The peer-id can also be negotiated without being pushed, so sync the
2288 * option before the frame is recalculated: it decides whether the
2289 * DATA_V2 header is accounted for */
2291
2294 frame_fragment, get_link_socket_info(c),
2295 &c->c1.tuntap->dco))
2296 {
2297 msg(D_TLS_ERRORS, "OPTIONS ERROR: failed to import crypto options");
2298 return false;
2299 }
2300
2301 return true;
2302}
2303
2304bool
2305do_up(struct context *c, bool pulled_options, uint64_t option_types_found)
2306{
2307 unsigned int error_flags = 0;
2308 if (!c->c2.do_up_ran)
2309 {
2311
2312 if (pulled_options)
2313 {
2314 if (!do_deferred_options(c, option_types_found, false))
2315 {
2316 msg(D_PUSH_ERRORS, "ERROR: Failed to apply push options");
2317 return false;
2318 }
2319 }
2320
2321 /* if --up-delay specified, open tun, do ifconfig, and run up script now */
2322 if (c->options.up_delay || PULL_DEFINED(&c->options))
2323 {
2324 c->c2.did_open_tun = do_open_tun(c, &error_flags);
2325 update_time();
2326
2327 /*
2328 * Was tun interface object persisted from previous restart iteration,
2329 * and if so did pulled options string change from previous iteration?
2330 */
2331 if (!c->c2.did_open_tun && PULL_DEFINED(&c->options) && c->c1.tuntap
2334 {
2335 /* if so, close tun, delete routes, then reinitialize tun and add routes */
2336 msg(M_INFO,
2337 "NOTE: Pulled options changed on restart, will need to close and reopen TUN/TAP device.");
2338
2339 bool tt_dco_win = tuntap_is_dco_win(c->c1.tuntap);
2340 do_close_tun(c, true);
2341
2342 if (tt_dco_win)
2343 {
2344 msg(M_NONFATAL, "dco-win doesn't yet support reopening TUN device");
2345 /* prevent link_socket_close() from closing handle with WinSock API */
2347 return false;
2348 }
2349 else
2350 {
2352 c->c2.did_open_tun = do_open_tun(c, &error_flags);
2353 update_time();
2354 }
2355 }
2356 }
2357 }
2358
2359 /* This part needs to be run in p2p mode (without pull) when the client
2360 * reconnects to setup various things (like DCO and NCP cipher) that
2361 * might have changed from the previous connection.
2362 */
2363 if (!c->c2.do_up_ran
2365 {
2366 if (c->mode == MODE_POINT_TO_POINT)
2367 {
2368 /* ovpn-dco requires adding the peer now, before any option can be set,
2369 * but *after* having parsed the pushed peer-id in do_deferred_options()
2370 */
2371 int ret = dco_p2p_add_new_peer(c);
2372 if (ret < 0)
2373 {
2374 msg(D_DCO, "Cannot add peer to DCO: %s (%d)", strerror(-ret), ret);
2375 return false;
2376 }
2377 }
2378
2379 /* do_deferred_options_part2() and do_deferred_p2p_ncp() *must* be
2380 * invoked after open_tun().
2381 * This is required by DCO because we must have created the interface
2382 * and added the peer before we can fiddle with the keys or any other
2383 * data channel per-peer setting.
2384 */
2385 if (pulled_options)
2386 {
2388 {
2389 return false;
2390 }
2391 }
2392 else
2393 {
2394 if (c->mode == MODE_POINT_TO_POINT)
2395 {
2396 if (!do_deferred_p2p_ncp(c))
2397 {
2398 msg(D_TLS_ERRORS, "ERROR: Failed to apply P2P negotiated protocol options");
2399 return false;
2400 }
2401 }
2402 }
2403
2404 if (c->c2.did_open_tun)
2405 {
2407
2408 /* if --route-delay was specified, start timer */
2410 {
2415 }
2416 else
2417 {
2418 /* client/p2p --route-delay undefined */
2419 initialization_sequence_completed(c, error_flags);
2420 }
2421 }
2422 else if (c->options.mode == MODE_POINT_TO_POINT)
2423 {
2424 /* client/p2p restart with --persist-tun */
2425 initialization_sequence_completed(c, error_flags);
2426 }
2427
2429
2430 c->c2.do_up_ran = true;
2431 if (c->c2.tls_multi)
2432 {
2434 }
2435 }
2436 return true;
2437}
2438
2439bool
2440do_update(struct context *c, uint64_t option_types_found)
2441{
2442 /* Not necessary since to receive the update the openvpn
2443 * instance must be up and running but just in case
2444 */
2445 if (!c->c2.do_up_ran)
2446 {
2447 return false;
2448 }
2449
2450 bool tt_dco_win = tuntap_is_dco_win(c->c1.tuntap);
2451 if (tt_dco_win)
2452 {
2453 msg(M_NONFATAL, "dco-win doesn't yet support reopening TUN device");
2454 return false;
2455 }
2456
2457 if (!do_deferred_options(c, option_types_found, true))
2458 {
2459 msg(D_PUSH_ERRORS, "ERROR: Failed to apply push options");
2460 return false;
2461 }
2462
2463 do_close_tun(c, true);
2464
2466 unsigned int error_flags = 0;
2467 c->c2.did_open_tun = do_open_tun(c, &error_flags);
2468 update_time();
2469
2470 if (c->c2.did_open_tun)
2471 {
2472 /* if --route-delay was specified, start timer */
2474 {
2479 }
2480
2481 initialization_sequence_completed(c, error_flags);
2482 }
2483
2485
2486 return true;
2487}
2488
2489/*
2490 * These are the option categories which will be accepted by pull.
2491 */
2492uint64_t
2494{
2499
2500 if (!c->options.route_nopull)
2501 {
2502 flags |= (OPT_P_ROUTE | OPT_P_DHCPDNS);
2503 }
2504
2505 if (c->options.acc_protocols)
2506 {
2507 flags |= OPT_P_ACC;
2508 }
2509
2510 return flags;
2511}
2512
2513static bool
2515{
2516 if (!c->c2.tls_multi)
2517 {
2518 return true;
2519 }
2520
2522
2524
2525 const char *ncp_cipher =
2527
2528 if (ncp_cipher)
2529 {
2530 c->options.ciphername = ncp_cipher;
2531 }
2532 else if (!c->options.enable_ncp_fallback)
2533 {
2534 msg(D_TLS_ERRORS, "ERROR: failed to negotiate cipher with peer and "
2535 "--data-ciphers-fallback not enabled. No usable "
2536 "data channel cipher");
2537 return false;
2538 }
2539
2540 struct frame *frame_fragment = NULL;
2541#ifdef ENABLE_FRAGMENT
2542 if (c->options.ce.fragment)
2543 {
2544 frame_fragment = &c->c2.frame_fragment;
2545 }
2546#endif
2547
2549 frame_fragment, get_link_socket_info(c),
2550 &c->c1.tuntap->dco))
2551 {
2552 msg(D_TLS_ERRORS, "ERROR: failed to set crypto cipher");
2553 return false;
2554 }
2555 return true;
2556}
2557
2558bool
2559do_deferred_options(struct context *c, const uint64_t found, const bool is_update)
2560{
2561 if (found & OPT_P_MESSAGES)
2562 {
2564 msg(D_PUSH, "OPTIONS IMPORT: --verb and/or --mute level changed");
2565 }
2566 if (found & OPT_P_TIMER)
2567 {
2568 do_init_timers(c, true);
2569 msg(D_PUSH_DEBUG, "OPTIONS IMPORT: timers and/or timeouts modified");
2570 }
2571
2572 if (found & OPT_P_EXPLICIT_NOTIFY)
2573 {
2574 /* Client side, so just check the first link_socket */
2577 {
2578 msg(D_PUSH, "OPTIONS IMPORT: --explicit-exit-notify can only be used with --proto udp");
2580 }
2581 else
2582 {
2583 msg(D_PUSH_DEBUG, "OPTIONS IMPORT: explicit notify parm(s) modified");
2584 }
2585 }
2586
2587 if (found & OPT_P_COMP)
2588 {
2590 {
2591 msg(D_PUSH_ERRORS, "OPTIONS ERROR: server pushed compression "
2592 "settings that are not allowed and will result "
2593 "in a non-working connection. "
2594 "See also allow-compression in the manual.");
2595 return false;
2596 }
2597#ifdef USE_COMP
2598 msg(D_PUSH_DEBUG, "OPTIONS IMPORT: compression parms modified");
2599 comp_uninit(c->c2.comp_context);
2600 c->c2.comp_context = comp_init(&c->options.comp);
2601#endif
2602 }
2603
2604 if (found & OPT_P_SHAPER)
2605 {
2606 msg(D_PUSH, "OPTIONS IMPORT: traffic shaper enabled");
2608 }
2609
2610 if (found & OPT_P_SOCKBUF)
2611 {
2612 msg(D_PUSH, "OPTIONS IMPORT: --sndbuf/--rcvbuf options modified");
2613
2614 for (int i = 0; i < c->c1.link_sockets_num; i++)
2615 {
2617 c->options.sndbuf);
2618 }
2619 }
2620
2621 if (found & OPT_P_PERSIST)
2622 {
2623 msg(D_PUSH, "OPTIONS IMPORT: --persist options modified");
2624 }
2625 if (found & OPT_P_UP)
2626 {
2627 msg(D_PUSH, "OPTIONS IMPORT: --ifconfig/up options modified");
2628 }
2629 if (found & OPT_P_ROUTE)
2630 {
2631 msg(D_PUSH, "OPTIONS IMPORT: route options modified");
2632 }
2633 if (found & OPT_P_ROUTE_EXTRAS)
2634 {
2635 msg(D_PUSH, "OPTIONS IMPORT: route-related options modified");
2636 }
2637 if (found & OPT_P_DHCPDNS)
2638 {
2639 msg(D_PUSH, "OPTIONS IMPORT: --ip-win32 and/or --dhcp-option options modified");
2640 }
2641 if (found & OPT_P_SETENV)
2642 {
2643 msg(D_PUSH, "OPTIONS IMPORT: environment modified");
2644 }
2645
2646 if (found & OPT_P_PEER_ID)
2647 {
2648 msg(D_PUSH_DEBUG, "OPTIONS IMPORT: peer-id set");
2649 c->c2.tls_multi->use_peer_id = true;
2652 }
2653
2654 /* process (potentially) pushed options */
2655 if (c->options.pull)
2656 {
2657 /* On PUSH_UPDATE, NCP related flags are never updated, and so the code
2658 * would assume "no cipher pushed = NCP failed" - so, don't call it on
2659 * updates */
2660 if (!is_update && !check_pull_client_ncp(c, found))
2661 {
2662 return false;
2663 }
2664
2665 /* Check if pushed options are compatible with DCO, if enabled */
2667 {
2668 msg(D_PUSH_ERRORS, "OPTIONS ERROR: pushed options are incompatible "
2669 "with data channel offload. Use --disable-dco to connect to "
2670 "this server");
2671 return false;
2672 }
2673 }
2674
2675 /* Ensure that for epoch data format is only enabled if also data v2
2676 * is enabled */
2678 bool datav2_enabled = c->c2.tls_multi->use_peer_id && c->c2.tls_multi->tx_peer_id < MAX_PEER_ID;
2679
2680 if (epoch_data && !datav2_enabled)
2681 {
2682 msg(D_PUSH_ERRORS, "OPTIONS ERROR: Epoch key data format tag requires "
2683 "data v2 (peer-id) to be enabled.");
2684 return false;
2685 }
2686
2687 /* The epoch data format is defined for AEAD ciphers only. A peer may push
2688 * the tag along with a non-AEAD cipher, so this has to be checked here
2689 * rather than trusted */
2690 if (epoch_data && !cipher_kt_mode_aead(c->options.ciphername))
2691 {
2693 "OPTIONS ERROR: Epoch key data format tag requires an AEAD "
2694 "cipher, but '%s' was negotiated.",
2695 c->options.ciphername);
2696 return false;
2697 }
2698
2699
2700 if (found & OPT_P_PUSH_MTU)
2701 {
2702 /* MTU has changed, check that the pushed MTU is small enough to
2703 * be able to change it */
2704 msg(D_PUSH, "OPTIONS IMPORT: tun-mtu set to %d", c->options.ce.tun_mtu);
2705
2706 struct frame *frame = &c->c2.frame;
2707
2709 {
2711 "Server-pushed tun-mtu is too large, please add "
2712 "tun-mtu-max %d in the client configuration",
2713 c->options.ce.tun_mtu);
2714 }
2716 }
2717
2719 {
2720 struct tls_multi *multi = c->c2.tls_multi;
2721 free(multi->acc_negotiated_protocols);
2724
2725 msg(D_PUSH, "OPTIONS IMPORT: ACC protocols: %s, msg len: %d",
2728 }
2729
2730 return true;
2731}
2732
2733/*
2734 * Possible hold on initialization, holdtime is the
2735 * time OpenVPN would wait without management
2736 */
2737static bool
2738do_hold(int holdtime)
2739{
2740#ifdef ENABLE_MANAGEMENT
2741 if (management)
2742 {
2743 /* block until management hold is released */
2744 if (management_hold(management, holdtime))
2745 {
2746 return true;
2747 }
2748 }
2749#endif
2750 return false;
2751}
2752
2753/*
2754 * Sleep before restart.
2755 */
2756static void
2758{
2759 int sec = 2;
2760 int backoff = 0;
2761
2762 switch (c->mode)
2763 {
2764 case CM_TOP:
2765 sec = 1;
2766 break;
2767
2768 case CM_CHILD_UDP:
2769 case CM_CHILD_TCP:
2771 break;
2772 }
2773
2774#ifdef ENABLE_DEBUG
2775 if (GREMLIN_CONNECTION_FLOOD_LEVEL(c->options.gremlin))
2776 {
2777 sec = 0;
2778 }
2779#endif
2780
2782 {
2783 sec = 10;
2784 }
2785
2786 /* Slow down reconnection after 5 retries per remote -- for TCP client or UDP tls-client only */
2787 if (c->mode == CM_CHILD_TCP || (c->options.ce.proto == PROTO_UDP && c->options.tls_client))
2788 {
2789 backoff = (c->options.unsuccessful_attempts / c->options.connection_list->len) - 4;
2790 if (backoff > 0)
2791 {
2792 /* sec is less than 2^16; we can left shift it by up to 15 bits without overflow */
2793 sec = max_int(sec, 1) << min_int(backoff, 15);
2794 }
2796 {
2797 sec = max_int(sec, c->options.server_backoff_time);
2799 }
2800
2802 {
2804 }
2805 }
2806
2808 {
2810 }
2811 else if (c->persist.restart_sleep_seconds == -1)
2812 {
2813 sec = 0;
2814 }
2816
2817 /* do management hold on context restart, i.e. second, third, fourth, etc. initialization */
2818 if (do_hold(sec))
2819 {
2820 sec = 0;
2821 }
2822
2823 if (sec)
2824 {
2825 msg(D_RESTART, "Restart pause, %d second(s)", sec);
2826 management_sleep(sec);
2827 }
2828}
2829
2830/*
2831 * Do a possible pause on context_2 initialization.
2832 */
2833static void
2835{
2836 if (!c->first_time)
2837 {
2839 }
2840 else
2841 {
2842 do_hold(0); /* do management hold on first context initialization */
2843 }
2844}
2845
2846static int
2847get_frame_mtu(struct context *c, const struct options *o)
2848{
2849 size_t mtu;
2850
2851 if (o->ce.link_mtu_defined)
2852 {
2854 /* if we have a link mtu defined we calculate what the old code
2855 * would have come up with as tun-mtu */
2856 size_t overhead = frame_calculate_protocol_header_size(&c->c1.ks.key_type, o, true);
2857 mtu = o->ce.link_mtu - overhead;
2858 }
2859 else
2860 {
2862 mtu = o->ce.tun_mtu;
2863 }
2864
2865 if (mtu < TUN_MTU_MIN)
2866 {
2867 msg(M_WARN, "TUN MTU value (%zu) must be at least %d", mtu, TUN_MTU_MIN);
2868 frame_print(&c->c2.frame, M_FATAL, "MTU is too small");
2869 }
2870 if (mtu > TUN_MTU_MAX)
2871 {
2872 msg(M_WARN, "TUN MTU value (%zu) clamped to %d", mtu, TUN_MTU_MAX);
2873 mtu = TUN_MTU_MAX;
2874 }
2875 return (int)mtu;
2876}
2877
2878/*
2879 * Finalize MTU parameters based on command line or config file options.
2880 */
2881static void
2882frame_finalize_options(struct context *c, const struct options *o)
2883{
2884 if (!o)
2885 {
2886 o = &c->options;
2887 }
2888
2889 struct frame *frame = &c->c2.frame;
2890
2891 frame->tun_mtu = get_frame_mtu(c, o);
2893
2894 /* max mtu needs to be at least as large as the tun mtu */
2896
2897 /* We always allow at least 1600 MTU packets to be received in our buffer
2898 * space to allow server to push "baby giant" MTU sizes */
2900
2901 unsigned int payload_size = frame->tun_max_mtu;
2902
2903 /* we need to be also large enough to hold larger control channel packets
2904 * if configured */
2906
2907 /* The extra tun needs to be added to the payload size */
2908 if (o->ce.tun_mtu_defined)
2909 {
2911 }
2912
2913 /* Add 32 byte of extra space in the buffer to account for small errors
2914 * in the calculation */
2915 payload_size += 32;
2916
2917
2918 /* the space that is reserved before the payload to add extra headers to it
2919 * we always reserve the space for the worst case */
2920 unsigned int headroom = 0;
2921
2922 /* includes IV and packet ID */
2924
2925 /* peer id + opcode */
2926 headroom += 4;
2927
2928 /* socks proxy header */
2930
2931 /* compression header and fragment header (part of the encrypted payload) */
2932 headroom += 1 + 1;
2933
2934 /* Round up headroom to the next multiple of 4 to ensure alignment */
2935 headroom = (headroom + 3) & ~3;
2936
2937 /* Add the headroom to the payloadsize as a received (IP) packet can have
2938 * all the extra headers in it */
2940
2941 /* the space after the payload, this needs some extra buffer space for
2942 * encryption so headroom is probably too much but we do not really care
2943 * the few extra bytes */
2944 unsigned int tailroom = headroom;
2945
2946#ifdef USE_COMP
2948 "MTU: adding %u buffer tailroom for compression for %u "
2949 "bytes of payload",
2950 COMP_EXTRA_BUFFER(payload_size), payload_size);
2951 tailroom += COMP_EXTRA_BUFFER(payload_size);
2952#endif
2953
2957}
2958
2959/*
2960 * Free a key schedule, including OpenSSL components.
2961 */
2962static void
2963key_schedule_free(struct key_schedule *ks, bool free_ssl_ctx)
2964{
2966 if (tls_ctx_initialised(ks->ssl_ctx) && free_ssl_ctx)
2967 {
2968 tls_ctx_free(ks->ssl_ctx);
2969 free(ks->ssl_ctx);
2971 }
2972 CLEAR(*ks);
2973}
2974
2975static void
2977{
2978 const struct options *options = &c->options;
2980
2981 if (c->options.engine)
2982 {
2984 }
2985
2987
2988 /* Initialize packet ID tracking */
2990 "STATIC", 0);
2991
2993
2994 /* Init cipher and hash algorithm */
2996
2998 "test crypto key");
2999
3000 /* Get key schedule */
3002}
3003
3004/*
3005 * Initialize the tls-auth/crypt key context
3006 */
3007static void
3009{
3010 const struct options *options = &c->options;
3011
3012 /* TLS handshake authentication (--tls-auth) */
3014 {
3015 /* Initialize key_type for tls-auth with auth only */
3017 c->c1.ks.tls_auth_key_type.cipher = "none";
3019 if (!md_valid(options->authname))
3020 {
3021 msg(M_FATAL,
3022 "ERROR: tls-auth enabled, but no valid --auth "
3023 "algorithm specified ('%s')",
3024 options->authname);
3025 }
3026
3029 options->ce.key_direction, "Control Channel Authentication",
3030 "tls-auth", &c->c1.ks.original_wrap_keydata);
3031 }
3032
3033 /* TLS handshake encryption+authentication (--tls-crypt) */
3035 {
3039 }
3040
3041 /* tls-crypt with client-specific keys (--tls-crypt-v2) */
3043 {
3044 if (options->tls_server)
3045 {
3049 }
3050 else
3051 {
3055 }
3056 /* We have to ensure that the loaded tls-crypt key is small enough
3057 * to fit into the initial hard reset v3 packet */
3058 int wkc_len = buf_len(&c->c1.ks.tls_crypt_v2_wkc);
3059
3060 /* empty ACK/message id, tls-crypt, Opcode, UDP, ipv6 */
3061 int required_size = 5 + wkc_len + tls_crypt_buf_overhead() + 1 + 8 + 40;
3062
3063 if (required_size > c->options.ce.tls_mtu)
3064 {
3065 msg(M_WARN,
3066 "ERROR: tls-crypt-v2 client key too large to work with "
3067 "requested --max-packet-size %d, requires at least "
3068 "--max-packet-size %d. Packets will ignore requested "
3069 "maximum packet size",
3070 c->options.ce.tls_mtu, required_size);
3071 }
3072 }
3073}
3074
3075/*
3076 * Initialize the persistent component of OpenVPN's TLS mode,
3077 * which is preserved across SIGUSR1 resets.
3078 */
3079static void
3081{
3082 const struct options *options = &c->options;
3083
3085 {
3086 /*
3087 * Initialize the OpenSSL library's global
3088 * SSL context.
3089 */
3090 ASSERT(NULL == c->c1.ks.ssl_ctx);
3093 {
3094 switch (auth_retry_get())
3095 {
3096 case AR_NONE:
3097 msg(M_FATAL, "Error: private key password verification failed");
3098 break;
3099
3100 case AR_INTERACT:
3101 ssl_purge_auth(false);
3102 /* Intentional [[fallthrough]]; */
3103
3104 case AR_NOINTERACT:
3105 /* SOFT-SIGUSR1 -- Password failure error */
3106 register_signal(c->sig, SIGUSR1, "private-key-password-failure");
3107 break;
3108
3109 default:
3110 ASSERT(0);
3111 }
3112 return;
3113 }
3114
3115 /*
3116 * BF-CBC is allowed to be used only when explicitly configured
3117 * as NCP-fallback or when NCP has been disabled or explicitly
3118 * allowed in the in ncp_ciphers list.
3119 * In all other cases do not attempt to initialize BF-CBC as it
3120 * may not even be supported by the underlying SSL library.
3121 *
3122 * Therefore, the key structure has to be initialized when:
3123 * - any non-BF-CBC cipher was selected; or
3124 * - BF-CBC is selected, NCP is enabled and fallback is enabled
3125 * (BF-CBC will be the fallback).
3126 * - BF-CBC is in data-ciphers and we negotiate to use BF-CBC:
3127 * If the negotiated cipher and options->ciphername are the
3128 * same we do not reinit the cipher
3129 *
3130 * Note that BF-CBC will still be part of the OCC string to retain
3131 * backwards compatibility with older clients.
3132 */
3133 const char *ciphername = options->ciphername;
3134 if (streq(options->ciphername, "BF-CBC")
3137 {
3138 ciphername = "none";
3139 }
3140
3141 /* Do not warn if the cipher is used only in OCC */
3142 bool warn = options->enable_ncp_fallback;
3144
3145 /* initialize tls-auth/crypt/crypt-v2 key */
3147
3148 /* initialise auth-token crypto support */
3150 {
3153 }
3154
3155#if 0 /* was: #if ENABLE_INLINE_FILES -- Note that enabling this code will break restarts */
3157 {
3159 c->options.priv_key_file_inline = NULL;
3160 }
3161#endif
3162 }
3163 else
3164 {
3165 msg(D_INIT_MEDIUM, "Re-using SSL/TLS context");
3166
3167 /*
3168 * tls-auth/crypt key can be configured per connection block, therefore
3169 * we must reload it as it may have changed
3170 */
3172 }
3173}
3174
3175static void
3176do_init_crypto_tls(struct context *c, const unsigned int flags)
3177{
3178 const struct options *options = &c->options;
3179 struct tls_options to;
3180 bool packet_id_long_form;
3181
3184
3185 if (c->options.engine)
3186 {
3188 }
3189
3190 /* Make sure we are either a TLS client or server but not both */
3192
3193 /* initialize persistent component */
3195 if (IS_SIG(c))
3196 {
3197 return;
3198 }
3199
3200 /* In short form, unique datagram identifier is 32 bits, in long form 64 bits */
3201 packet_id_long_form = cipher_kt_mode_ofb_cfb(c->c1.ks.key_type.cipher);
3202
3203 /* Set all command-line TLS-related options */
3204 CLEAR(to);
3205
3207 {
3209 }
3210
3212 if (packet_id_long_form)
3213 {
3215 }
3216
3217 to.ssl_ctx = c->c1.ks.ssl_ctx;
3218 to.key_type = c->c1.ks.key_type;
3231 {
3232 /* Add 10% jitter to reneg-sec by default (server side only) */
3233 int jitter_max = max_int(options->renegotiate_seconds / 10, 1);
3234 int auto_jitter = options->mode != MODE_SERVER ? 0 : (int)(get_random() % jitter_max);
3236 }
3237 else
3238 {
3239 /* Add user-specified jitter to reneg-sec */
3241 to.renegotiate_seconds = options->renegotiate_seconds - (int)(get_random() % jitter_max);
3242 }
3244 to.mode = options->mode;
3245 to.pull = options->pull;
3246 if (options->push_peer_info) /* all there is */
3247 {
3248 to.push_peer_info_detail = 3;
3249 }
3250 else if (options->pull) /* pull clients send some details */
3251 {
3252 to.push_peer_info_detail = 2;
3253 }
3254 else if (options->mode == MODE_SERVER) /* server: no peer info at all */
3255 {
3256 to.push_peer_info_detail = 0;
3257 }
3258 else /* default: minimal info to allow NCP in P2P mode */
3259 {
3260 to.push_peer_info_detail = 1;
3261 }
3262
3263 /* Check if the DCO drivers support the epoch data format */
3264 if (dco_enabled(options))
3265 {
3267 }
3268 else
3269 {
3270 to.data_epoch_supported = true;
3271 }
3272
3273 /* should we not xmit any packets until we get an initial
3274 * response from client? */
3275 if (to.server && (c->mode == CM_CHILD_TCP || (c->mode == CM_P2P && options->ce.proto == PROTO_TCP_SERVER)))
3276 {
3277 to.xmit_hold = true;
3278 }
3279
3287 memcpy(to.remote_cert_ku, options->remote_cert_ku, sizeof(to.remote_cert_ku));
3295 to.es = c->c2.es;
3296 to.net_ctx = &c->net_ctx;
3297
3298#ifdef ENABLE_DEBUG
3299 to.gremlin = c->options.gremlin;
3300#endif
3301
3302 to.plugins = c->plugins;
3303
3304#ifdef ENABLE_MANAGEMENT
3305 to.mda_context = &c->c2.mda_context;
3306#endif
3307
3311 to.tmp_dir = options->tmp_dir;
3314 {
3316 }
3325
3327
3328#ifdef ENABLE_MANAGEMENT
3329 to.sci = &options->sc_info;
3330#endif
3331
3332#ifdef USE_COMP
3333 to.comp_options = options->comp;
3334#endif
3335
3337 {
3339 if (to.ekm_size < 16 || to.ekm_size > 4095)
3340 {
3341 to.ekm_size = 0;
3342 }
3343
3345 to.ekm_label_size = strlen(to.ekm_label);
3346 }
3347 else
3348 {
3349 to.ekm_size = 0;
3350 }
3351
3352 /* TLS handshake authentication (--tls-auth) */
3354 {
3355 to.tls_wrap.mode = TLS_WRAP_AUTH;
3356 }
3357
3358 /* TLS handshake encryption (--tls-crypt) */
3360 {
3361 to.tls_wrap.mode = TLS_WRAP_CRYPT;
3362 }
3363
3364 if (to.tls_wrap.mode == TLS_WRAP_AUTH || to.tls_wrap.mode == TLS_WRAP_CRYPT)
3365 {
3369 }
3370
3372 {
3373 to.tls_crypt_v2 = true;
3375
3376 if (options->tls_server)
3377 {
3382 {
3384 }
3385 }
3386 }
3387
3388 /* let the TLS engine know if keys have to be installed in DCO or not */
3390
3391 /*
3392 * Initialize OpenVPN's master TLS-mode object.
3393 */
3394 if (flags & CF_INIT_TLS_MULTI)
3395 {
3396 c->c2.tls_multi = tls_multi_init(&to);
3397 /* inherit the dco context from the tuntap object */
3398 if (c->c1.tuntap)
3399 {
3400 c->c2.tls_multi->dco = &c->c1.tuntap->dco;
3401 }
3402 }
3403
3404 if (flags & CF_INIT_TLS_AUTH_STANDALONE)
3405 {
3408 }
3409}
3410
3411static void
3413{
3414 if (c->c2.tls_multi)
3415 {
3418 frame_print(&c->c2.tls_multi->opt.frame, D_MTU_INFO, "Control Channel MTU parms");
3419
3420 /* Keep the max mtu also in the frame of tls multi so it can access
3421 * it in push_peer_info */
3423 }
3424 if (c->c2.tls_auth_standalone)
3425 {
3427 c->options.ce.tls_mtu);
3428 frame_print(&c->c2.tls_auth_standalone->frame, D_MTU_INFO, "TLS-Auth MTU parms");
3431 }
3432}
3433
3434static void
3436{
3437 /*
3438 * Adjust frame size based on the --tun-mtu-extra parameter.
3439 */
3441 {
3443 }
3444
3445 /*
3446 * Fill in the blanks in the frame parameters structure,
3447 * make sure values are rational, etc.
3448 */
3449 frame_finalize_options(c, NULL);
3450
3451
3452#if defined(ENABLE_FRAGMENT)
3453 /*
3454 * MTU advisories
3455 */
3456 if (c->options.ce.fragment && c->options.mtu_test)
3457 {
3458 msg(M_WARN,
3459 "WARNING: using --fragment and --mtu-test together may produce an inaccurate MTU test result");
3460 }
3461#endif
3462
3463#ifdef ENABLE_FRAGMENT
3464 if (c->options.ce.fragment > 0 && c->options.ce.mssfix > c->options.ce.fragment)
3465 {
3466 msg(M_WARN,
3467 "WARNING: if you use --mssfix and --fragment, you should "
3468 "set --fragment (%d) larger or equal than --mssfix (%d)",
3470 }
3471 if (c->options.ce.fragment > 0 && c->options.ce.mssfix > 0
3473 {
3474 msg(M_WARN, "WARNING: if you use --mssfix and --fragment, you should "
3475 "use the \"mtu\" flag for both or none of of them.");
3476 }
3477#endif
3478}
3479
3480static void
3482{
3483 const struct options *o = &c->options;
3484
3485 if (o->ping_send_timeout && !o->ping_rec_timeout)
3486 {
3487 msg(M_WARN, "WARNING: --ping should normally be used with --ping-restart or --ping-exit");
3488 }
3489
3490 if (o->username || o->groupname || o->chroot_dir
3491#ifdef ENABLE_SELINUX
3492 || o->selinux_context
3493#endif
3494 )
3495 {
3496 if (!o->persist_tun)
3497 {
3498 msg(M_WARN,
3499 "WARNING: you are using user/group/chroot/setcon without persist-tun -- this may cause restarts to fail");
3500 }
3501 }
3502
3503 if (o->chroot_dir && !(o->username && o->groupname))
3504 {
3505 msg(M_WARN,
3506 "WARNING: you are using chroot without specifying user and group -- this may cause the chroot jail to be insecure");
3507 }
3508
3509 if (o->pull && o->ifconfig_local && c->first_time)
3510 {
3511 msg(M_WARN,
3512 "WARNING: using --pull/--client and --ifconfig together is probably not what you want");
3513 }
3514
3516 {
3517 msg(M_WARN,
3518 "NOTE: when bridging your LAN adapter with the TAP adapter, note that the new bridge adapter will often take on its own IP address that is different from what the LAN adapter was previously set to");
3519 }
3520
3521 if (o->mode == MODE_SERVER)
3522 {
3523 if (o->duplicate_cn && o->client_config_dir)
3524 {
3525 msg(M_WARN,
3526 "WARNING: using --duplicate-cn and --client-config-dir together is probably not what you want");
3527 }
3529 {
3530 msg(M_WARN, "WARNING: --ifconfig-pool-persist will not work with --duplicate-cn");
3531 }
3532 if (!o->keepalive_ping || !o->keepalive_timeout)
3533 {
3534 msg(M_WARN, "WARNING: --keepalive option is missing from server config");
3535 }
3536 }
3537
3538 if (o->tls_server)
3539 {
3541 }
3544 && !(o->verify_hash_depth == 0 && o->verify_hash))
3545 {
3546 msg(M_WARN,
3547 "WARNING: No server certificate verification method has been enabled. See http://openvpn.net/howto.html#mitm for more info.");
3548 }
3549 if (o->ns_cert_type)
3550 {
3551 msg(M_WARN, "WARNING: --ns-cert-type is DEPRECATED. Use --remote-cert-tls instead.");
3552 }
3553
3554 /* If a script is used, print appropriate warnings */
3555 if (o->user_script_used)
3556 {
3558 {
3559 msg(M_WARN,
3560 "NOTE: the current --script-security setting may allow this configuration to call user-defined scripts");
3561 }
3562 else if (script_security() >= SSEC_PW_ENV)
3563 {
3564 msg(M_WARN,
3565 "WARNING: the current --script-security setting may allow passwords to be passed to scripts via environmental variables");
3566 }
3567 else
3568 {
3569 msg(M_WARN,
3570 "NOTE: starting with " PACKAGE_NAME
3571 " 2.1, '--script-security 2' or higher is required to call user-defined scripts or executables");
3572 }
3573 }
3574}
3575
3576struct context_buffers *
3578{
3579 struct context_buffers *b;
3580
3582
3583 size_t buf_size = BUF_SIZE(frame);
3584
3585 b->read_link_buf = alloc_buf(buf_size);
3586 b->read_tun_buf = alloc_buf(buf_size);
3587
3588 b->aux_buf = alloc_buf(buf_size);
3589
3590 b->encrypt_buf = alloc_buf(buf_size);
3591 b->decrypt_buf = alloc_buf(buf_size);
3592
3593#ifdef USE_COMP
3594 b->compress_buf = alloc_buf(buf_size);
3595 b->decompress_buf = alloc_buf(buf_size);
3596#endif
3597
3598 return b;
3599}
3600
3601void
3603{
3604 if (b)
3605 {
3608 free_buf(&b->aux_buf);
3609
3610#ifdef USE_COMP
3611 free_buf(&b->compress_buf);
3612 free_buf(&b->decompress_buf);
3613#endif
3614
3615 free_buf(&b->encrypt_buf);
3616 free_buf(&b->decrypt_buf);
3617
3618 free(b);
3619 }
3620}
3621
3622/*
3623 * Now that we know all frame parameters, initialize
3624 * our buffers.
3625 */
3626static void
3628{
3630 c->c2.buffers_owned = true;
3631}
3632
3633#ifdef ENABLE_FRAGMENT
3634/*
3635 * Fragmenting code has buffers to initialize
3636 * once frame parameters are known.
3637 */
3638static void
3640{
3642
3643 /*
3644 * Set frame parameter for fragment code. This is necessary because
3645 * the fragmentation code deals with payloads which have already been
3646 * passed through the compression code.
3647 */
3648 c->c2.frame_fragment = c->c2.frame;
3649
3653}
3654#endif
3655
3656/*
3657 * Allocate our socket object.
3658 */
3659static void
3661{
3662 ASSERT(!c->c2.link_sockets);
3663
3665
3666 for (int i = 0; i < c->c1.link_sockets_num; i++)
3667 {
3669 }
3670 c->c2.link_socket_owned = true;
3671}
3672
3673#if defined(__GNUC__) || defined(__clang__)
3674#pragma GCC diagnostic pop
3675#endif
3676
3677/*
3678 * bind TCP/UDP sockets
3679 */
3680static void
3682{
3683 for (int i = 0; i < c->c1.link_sockets_num; i++)
3684 {
3685 int mode = LS_MODE_DEFAULT;
3686
3687 /* mode allows CM_CHILD_TCP
3688 * instances to inherit acceptable fds
3689 * from a top-level parent */
3690 if (c->options.mode == MODE_SERVER)
3691 {
3692 /* initializing listening socket */
3693 if (c->mode == CM_TOP)
3694 {
3695 mode = LS_MODE_TCP_LISTEN;
3696 }
3697 /* initializing socket to client */
3698 else if (c->mode == CM_CHILD_TCP)
3699 {
3701 }
3702 }
3703
3704 /* init each socket with its specific args */
3705 link_socket_init_phase1(c, i, mode);
3706 }
3707}
3708
3709/*
3710 * finalize TCP/UDP sockets
3711 */
3712static void
3714{
3715 for (int i = 0; i < c->c1.link_sockets_num; i++)
3716 {
3718 }
3719}
3720
3721/*
3722 * Print MTU INFO
3723 */
3724static void
3726{
3727 frame_print(&c->c2.frame, D_MTU_INFO, "Data Channel MTU parms");
3728#ifdef ENABLE_FRAGMENT
3729 if (c->c2.fragment)
3730 {
3731 frame_print(&c->c2.frame_fragment, D_MTU_INFO, "Fragmentation MTU parms");
3732 }
3733#endif
3734}
3735
3736/*
3737 * Get local and remote options compatibility strings.
3738 */
3739static void
3741{
3742 struct gc_arena gc = gc_new();
3743
3745 options_string(&c->options, &c->c2.frame, c->c1.tuntap, &c->net_ctx, false, &gc);
3747 options_string(&c->options, &c->c2.frame, c->c1.tuntap, &c->net_ctx, true, &gc);
3748
3749 msg(D_SHOW_OCC, "Local Options String (VER=%s): '%s'",
3751 msg(D_SHOW_OCC, "Expected Remote Options String (VER=%s): '%s'",
3753
3754 if (c->c2.tls_multi)
3755 {
3758 }
3759
3760 gc_free(&gc);
3761}
3762
3763/*
3764 * These things can only be executed once per program instantiation.
3765 * Set up for possible UID/GID downgrade, but don't do it yet.
3766 * Daemonize if requested.
3767 */
3768static void
3770{
3771 if (c->first_time && !c->c0)
3772 {
3773 struct context_0 *c0;
3774
3775 ALLOC_OBJ_CLEAR_GC(c->c0, struct context_0, &c->gc);
3776 c0 = c->c0;
3777
3778 /* get user and/or group that we want to setuid/setgid to,
3779 * sets also platform_x_state */
3780 bool group_defined = platform_group_get(c->options.groupname, &c0->platform_state_group);
3781 bool user_defined = platform_user_get(c->options.username, &c0->platform_state_user);
3782
3783 c0->uid_gid_specified = user_defined || group_defined;
3784
3785 /* fork the dns script runner to preserve root? */
3786 c->persist.duri.required = user_defined;
3787
3788 /* perform postponed chdir if --daemon */
3789 if (c->did_we_daemonize && c->options.cd_dir == NULL)
3790 {
3791 platform_chdir("/");
3792 }
3793
3794 /* should we change scheduling priority? */
3796 }
3797}
3798
3799/*
3800 * free buffers
3801 */
3802static void
3804{
3805 if (c->c2.buffers_owned)
3806 {
3808 c->c2.buffers = NULL;
3809 c->c2.buffers_owned = false;
3810 }
3811}
3812
3813/*
3814 * close TLS
3815 */
3816static void
3818{
3819 if (c->c2.tls_multi)
3820 {
3821 tls_multi_free(c->c2.tls_multi, true);
3822 c->c2.tls_multi = NULL;
3823 }
3824
3825 /* free options compatibility strings */
3826 free(c->c2.options_string_local);
3827 free(c->c2.options_string_remote);
3828
3830
3831 if (c->c2.pulled_options_state)
3832 {
3835 }
3836
3838}
3839
3840/*
3841 * Free key schedules
3842 */
3843static void
3844do_close_free_key_schedule(struct context *c, bool free_ssl_ctx)
3845{
3846 /*
3847 * always free the tls_auth/crypt key. The key will
3848 * be reloaded from memory (pre-cached)
3849 */
3852 CLEAR(c->c1.ks.tls_wrap_key);
3855
3856 if (!(c->sig->signal_received == SIGUSR1))
3857 {
3858 key_schedule_free(&c->c1.ks, free_ssl_ctx);
3859 }
3860}
3861
3862/*
3863 * Close TCP/UDP connection
3864 */
3865static void
3867{
3868 if (c->c2.link_sockets && c->c2.link_socket_owned)
3869 {
3870 for (int i = 0; i < c->c1.link_sockets_num; i++)
3871 {
3872 /* in dco-win case, link socket is a tun handle which is
3873 * closed in do_close_tun(). Set it to UNDEFINED so
3874 * we won't use WinSock API to close it. */
3875 if (tuntap_is_dco_win(c->c1.tuntap))
3876 {
3878 }
3879
3881 }
3882 c->c2.link_sockets = NULL;
3883 }
3884
3885
3886 /* Preserve the resolved list of remote if the user request to or if we want
3887 * reconnect to the same host again or there are still addresses that need
3888 * to be tried */
3889 if (!(c->sig->signal_received == SIGUSR1
3890 && ((c->options.persist_remote_ip)
3891 || (c->sig->source != SIG_SOURCE_HARD
3893 && c->c1.link_socket_addrs[0].current_remote->ai_next)
3894 || c->options.no_advance)))))
3895 {
3897 }
3898
3899 /* Clear the remote actual address when persist_remote_ip is not in use */
3901 {
3902 for (int i = 0; i < c->c1.link_sockets_num; i++)
3903 {
3905 }
3906 }
3907
3909 {
3910 for (int i = 0; i < c->c1.link_sockets_num; i++)
3911 {
3913 {
3914 freeaddrinfo(c->c1.link_socket_addrs[i].bind_local);
3915 }
3916
3917 c->c1.link_socket_addrs[i].bind_local = NULL;
3918 }
3919 }
3920}
3921
3922/*
3923 * Close packet-id persistence file
3924 */
3925static void
3930
3931#ifdef ENABLE_FRAGMENT
3932/*
3933 * Close fragmentation handler.
3934 */
3935static void
3937{
3938 if (c->c2.fragment)
3939 {
3941 c->c2.fragment = NULL;
3942 }
3943}
3944#endif
3945
3946/*
3947 * Open and close our event objects.
3948 */
3949
3950static void
3951do_event_set_init(struct context *c, bool need_us_timeout)
3952{
3953 unsigned int flags = 0;
3954
3956
3957 flags |= EVENT_METHOD_FAST;
3958
3959 if (need_us_timeout)
3960 {
3961 flags |= EVENT_METHOD_US_TIMEOUT;
3962 }
3963
3964 c->c2.event_set = event_set_init(&c->c2.event_set_max, flags);
3965 c->c2.event_set_owned = true;
3966}
3967
3968static void
3970{
3971 if (c->c2.event_set && c->c2.event_set_owned)
3972 {
3974 c->c2.event_set = NULL;
3975 c->c2.event_set_owned = false;
3976 }
3977}
3978
3979/*
3980 * Open and close --status file
3981 */
3982
3983static void
3985{
3986 if (!c->c1.status_output)
3987 {
3988 c->c1.status_output =
3991 c->c1.status_output_owned = true;
3992 }
3993}
3994
3995static void
3997{
3998 if (!(c->sig->signal_received == SIGUSR1))
3999 {
4001 {
4003 c->c1.status_output = NULL;
4004 c->c1.status_output_owned = false;
4005 }
4006 }
4007}
4008
4009/*
4010 * Handle ifconfig-pool persistence object.
4011 */
4012static void
4023
4024static void
4026{
4027 if (!(c->sig->signal_received == SIGUSR1))
4028 {
4030 {
4032 c->c1.ifconfig_pool_persist = NULL;
4034 }
4035 }
4036}
4037
4038/*
4039 * Inherit environmental variables
4040 */
4041
4042static void
4043do_inherit_env(struct context *c, const struct env_set *src)
4044{
4045 c->c2.es = env_set_create(NULL);
4046 c->c2.es_owned = true;
4047 env_set_inherit(c->c2.es, src);
4048}
4049
4050static void
4052{
4053 if (c->c2.es && c->c2.es_owned)
4054 {
4055 env_set_destroy(c->c2.es);
4056 c->c2.es = NULL;
4057 c->c2.es_owned = false;
4058 }
4059}
4060
4061static void
4063{
4064 if (c->options.tls_exit)
4065 {
4067 }
4068 else
4069 {
4071 }
4072}
4073
4074#ifdef ENABLE_PLUGIN
4075
4076void
4078{
4079 if (c->options.plugin_list && !c->plugins)
4080 {
4082 c->plugins_owned = true;
4083 }
4084}
4085
4086void
4087open_plugins(struct context *c, const bool import_options, int init_point)
4088{
4089 if (c->plugins && c->plugins_owned)
4090 {
4091 if (import_options)
4092 {
4093 struct plugin_return pr, config;
4094 plugin_return_init(&pr);
4095 plugin_list_open(c->plugins, c->options.plugin_list, &pr, c->c2.es, init_point);
4096 plugin_return_get_column(&pr, &config, "config");
4097 if (plugin_return_defined(&config))
4098 {
4099 int i;
4100 for (i = 0; i < config.n; ++i)
4101 {
4102 uint64_t option_types_found = 0;
4103 if (config.list[i] && config.list[i]->value)
4104 {
4106 &c->options, config.list[i]->value, D_IMPORT_ERRORS | M_OPTERR,
4107 OPT_P_DEFAULT & ~OPT_P_PLUGIN, &option_types_found, c->es);
4108 }
4109 }
4110 }
4111 plugin_return_free(&pr);
4112 }
4113 else
4114 {
4115 plugin_list_open(c->plugins, c->options.plugin_list, NULL, c->c2.es, init_point);
4116 }
4117 }
4118}
4119
4120static void
4122{
4123 if (c->plugins && c->plugins_owned && !(c->sig->signal_received == SIGUSR1))
4124 {
4126 c->plugins = NULL;
4127 c->plugins_owned = false;
4128 }
4129}
4130
4131static void
4132do_inherit_plugins(struct context *c, const struct context *src)
4133{
4134 if (!c->plugins && src->plugins)
4135 {
4137 c->plugins_owned = true;
4138 }
4139}
4140
4141#endif /* ifdef ENABLE_PLUGIN */
4142
4143#ifdef ENABLE_MANAGEMENT
4144
4145static void
4146management_callback_status_p2p(void *arg, const int version, struct status_output *so)
4147{
4148 struct context *c = (struct context *)arg;
4149 print_status(c, so);
4150}
4151
4152void
4153management_show_net_callback(void *arg, const msglvl_t msglevel)
4154{
4155#ifdef _WIN32
4156 show_routes(msglevel);
4157 show_adapters(msglevel);
4158 msg(msglevel, "END");
4159#else
4160 msg(msglevel, "ERROR: Sorry, this command is currently only implemented on Windows");
4161#endif
4162}
4163
4164#ifdef TARGET_ANDROID
4165int
4166management_callback_network_change(void *arg, bool samenetwork)
4167{
4168 /* Check if the client should translate the network change to a SIGUSR1 to
4169 * reestablish the connection or just reprotect the socket
4170 *
4171 * At the moment just assume that, for all settings that use pull (not
4172 * --static) and are not using peer-id reestablishing the connection is
4173 * required (unless the network is the same)
4174 *
4175 * The function returns -1 on invalid fd and -2 if the socket cannot be
4176 * reused. On the -2 return value the man_network_change function triggers
4177 * a SIGUSR1 to force a reconnect.
4178 */
4179
4180 int socketfd = -1;
4181 struct context *c = (struct context *)arg;
4182 if (!c->c2.link_sockets || !c->c2.link_sockets[0])
4183 {
4184 return -1;
4185 }
4186 if (c->c2.link_sockets[0]->sd == SOCKET_UNDEFINED)
4187 {
4188 return -1;
4189 }
4190
4191 /* On some newer Android handsets, changing to a different network
4192 * often does not trigger a TCP reset but continue using the old
4193 * connection (e.g. using mobile connection when WiFi becomes available */
4194 const struct link_socket_info *lsi = get_link_socket_info(c);
4195 if (lsi && proto_is_tcp(lsi->proto) && !samenetwork)
4196 {
4197 return -2;
4198 }
4199
4200 socketfd = c->c2.link_sockets[0]->sd;
4201 if (!c->options.pull || c->c2.tls_multi->use_peer_id || samenetwork)
4202 {
4203 return socketfd;
4204 }
4205 else
4206 {
4207 return -2;
4208 }
4209}
4210#endif /* ifdef TARGET_ANDROID */
4211
4212static bool
4214 struct buffer_list *input) /* ownership transferred */
4215{
4216 struct context *c = arg;
4217
4218 bool ret = false;
4219 if (buffer_list_defined(input) && c->c2.tls_multi)
4220 {
4221 struct tls_multi *multi = c->c2.tls_multi;
4222 struct tls_session *session = &multi->session[TM_ACTIVE];
4223
4224 ret = management_send_acc_message(c, multi, session, input);
4225 }
4226
4227 buffer_list_free(input);
4228 return ret;
4229}
4230#endif /* ifdef ENABLE_MANAGEMENT */
4231
4232void
4234{
4235#ifdef ENABLE_MANAGEMENT
4236 if (management)
4237 {
4238 struct management_callback cb;
4239 CLEAR(cb);
4240 cb.arg = c;
4247#ifdef TARGET_ANDROID
4248 cb.network_change = management_callback_network_change;
4249#endif
4253 }
4254#endif
4255}
4256
4257#ifdef ENABLE_MANAGEMENT
4258
4259void
4261{
4262 if (!management)
4263 {
4265 }
4266}
4267
4268bool
4270{
4271 /* initialize management layer */
4272 if (management)
4273 {
4274 if (c->options.management_addr)
4275 {
4276 unsigned int flags = c->options.management_flags;
4277 if (c->options.mode == MODE_SERVER)
4278 {
4279 flags |= MF_SERVER;
4280 }
4281 if (management_open(
4287 {
4289 NULL);
4290 }
4291
4292 /* initial management hold, called early, before first context initialization */
4293 do_hold(0);
4294 if (IS_SIG(c))
4295 {
4296 msg(M_WARN, "Signal received from management interface, exiting");
4297 return false;
4298 }
4299 }
4300 else
4301 {
4303 }
4304 }
4305 return true;
4306}
4307
4308void
4310{
4311 if (management)
4312 {
4314 management = NULL;
4315 }
4316}
4317
4318#endif /* ifdef ENABLE_MANAGEMENT */
4319
4320
4321void
4323{
4324#ifdef ENABLE_MANAGEMENT
4325 if (management)
4326 {
4328 }
4329#endif
4330}
4331
4332void
4334{
4335#ifdef ENABLE_MANAGEMENT
4336 if (management)
4337 {
4339 }
4340#endif
4341}
4342
4343/*
4344 * Initialize a tunnel instance.
4345 */
4346static void
4347init_instance(struct context *c, const struct env_set *env, const unsigned int flags)
4348{
4349 const struct options *options = &c->options;
4350 const bool child = (c->mode == CM_CHILD_TCP || c->mode == CM_CHILD_UDP);
4351
4352 /* init garbage collection level */
4353 gc_init(&c->c2.gc);
4354
4355 /* inherit environmental variables */
4356 if (env)
4357 {
4358 do_inherit_env(c, env);
4359 }
4360
4361 if (c->mode == CM_P2P)
4362 {
4364 }
4365
4366 /* possible sleep or management hold if restart */
4367 if (c->mode == CM_P2P || c->mode == CM_TOP)
4368 {
4370 if (IS_SIG(c))
4371 {
4372 goto sig;
4373 }
4374 }
4375
4377 {
4378 do_preresolve(c);
4379 if (IS_SIG(c))
4380 {
4381 goto sig;
4382 }
4383 }
4384
4385 /* Resets all values to the initial values from the config where needed */
4386 pre_connect_restore(&c->options, &c->c2.gc);
4387
4388 /* map in current connection entry */
4390
4391 /* should we disable paging? */
4392 if (c->first_time && options->mlock)
4393 {
4394 platform_mlockall(true);
4395 }
4396
4397 /* get passwords if undefined */
4398 if (auth_retry_get() == AR_INTERACT)
4399 {
4401 }
4402
4403 /* initialize context level 2 --verb/--mute parms */
4405
4406 /* set error message delay for non-server modes */
4407 if (c->mode == CM_P2P)
4408 {
4410 }
4411
4412 /* warn about inconsistent options */
4413 if (c->mode == CM_P2P || c->mode == CM_TOP)
4414 {
4416 }
4417
4418#ifdef ENABLE_PLUGIN
4419 /* initialize plugins */
4420 if (c->mode == CM_P2P || c->mode == CM_TOP)
4421 {
4422 open_plugins(c, false, OPENVPN_PLUGIN_INIT_PRE_DAEMON);
4423 }
4424#endif
4425
4426 /* should we throw a signal on TLS errors? */
4428
4429 /* open --status file */
4430 if (c->mode == CM_P2P || c->mode == CM_TOP)
4431 {
4433 }
4434
4435 /* open --ifconfig-pool-persist file */
4436 if (c->mode == CM_TOP)
4437 {
4439 }
4440
4441 /* reset OCC state */
4442 if (c->mode == CM_P2P || child)
4443 {
4444 c->c2.occ_op = occ_reset_op();
4445 }
4446
4447 /* our wait-for-i/o objects, different for posix vs. win32 */
4448 if (c->mode == CM_P2P || c->mode == CM_TOP)
4449 {
4451 }
4452 else if (c->mode == CM_CHILD_TCP)
4453 {
4454 do_event_set_init(c, false);
4455 }
4456
4457 /* initialize HTTP or SOCKS proxy object at scope level 2 */
4458 init_proxy(c);
4459
4460 /* allocate our socket object */
4461 if (c->mode == CM_P2P || c->mode == CM_TOP || c->mode == CM_CHILD_TCP)
4462 {
4464 }
4465
4466#ifdef ENABLE_FRAGMENT
4467 /* initialize internal fragmentation object */
4468 if (options->ce.fragment && (c->mode == CM_P2P || child))
4469 {
4470 c->c2.fragment = fragment_init(&c->c2.frame);
4471 }
4472#endif
4473
4474 /* init crypto layer */
4475 {
4476 unsigned int crypto_flags = 0;
4477 if (c->mode == CM_TOP)
4478 {
4479 crypto_flags = CF_INIT_TLS_AUTH_STANDALONE;
4480 }
4481 else if (c->mode == CM_P2P)
4482 {
4483 crypto_flags = CF_INIT_TLS_MULTI;
4484 }
4485 else if (child)
4486 {
4487 crypto_flags = CF_INIT_TLS_MULTI;
4488 }
4489 do_init_crypto_tls(c, crypto_flags);
4490 if (IS_SIG(c) && !child)
4491 {
4492 goto sig;
4493 }
4494 }
4495
4496#ifdef USE_COMP
4497 /* initialize compression library. */
4498 if (comp_enabled(&options->comp) && (c->mode == CM_P2P || child))
4499 {
4500 c->c2.comp_context = comp_init(&options->comp);
4501 }
4502#endif
4503
4504 /* initialize MTU variables */
4505 do_init_frame(c);
4506
4507 /* initialize TLS MTU variables */
4509
4510 /* init workspace buffers whose size is derived from frame size */
4511 if (c->mode == CM_P2P || c->mode == CM_CHILD_TCP)
4512 {
4513 do_init_buffers(c);
4514 }
4515
4516#ifdef ENABLE_FRAGMENT
4517 /* initialize internal fragmentation capability with known frame size */
4518 if (options->ce.fragment && (c->mode == CM_P2P || child))
4519 {
4521 }
4522#endif
4523
4524 /* bind the TCP/UDP socket */
4525 if (c->mode == CM_P2P || c->mode == CM_TOP || c->mode == CM_CHILD_TCP)
4526 {
4528 }
4529
4530 /* initialize tun/tap device object,
4531 * open tun/tap device, ifconfig, run up script, etc. */
4532 if (!(options->up_delay || PULL_DEFINED(options)) && (c->mode == CM_P2P || c->mode == CM_TOP))
4533 {
4534 unsigned int error_flags = 0;
4535 c->c2.did_open_tun = do_open_tun(c, &error_flags);
4536 }
4537
4538 /* print MTU info */
4540
4541 /* get local and remote options compatibility strings */
4542 if (c->mode == CM_P2P || child)
4543 {
4545 }
4546
4547 /* initialize output speed limiter */
4548 if (c->mode == CM_P2P)
4549 {
4551 }
4552
4553 /* do one-time inits, and possibly become a daemon here */
4555
4556#ifdef ENABLE_PLUGIN
4557 /* initialize plugins */
4558 if (c->mode == CM_P2P || c->mode == CM_TOP)
4559 {
4560 open_plugins(c, false, OPENVPN_PLUGIN_INIT_POST_DAEMON);
4561 }
4562#endif
4563
4564 /* initialise connect timeout timer */
4566
4567 /* finalize the TCP/UDP socket */
4568 if (c->mode == CM_P2P || c->mode == CM_TOP || c->mode == CM_CHILD_TCP)
4569 {
4571
4572
4573 /* Update dynamic frame calculation as exact transport socket information
4574 * (IP vs IPv6) may be only available after socket phase2 has finished.
4575 * This is only needed for --static or no crypto, NCP will recalculate this
4576 * in tls_session_update_crypto_params (P2MP) */
4577 for (int i = 0; i < c->c1.link_sockets_num; i++)
4578 {
4580 &c->c2.link_sockets[i]->info);
4581 }
4582 }
4583
4584 /*
4585 * Actually do UID/GID downgrade, and chroot, if requested.
4586 * May be delayed by --client, --pull, or --up-delay.
4587 */
4589
4590 /* initialize timers */
4591 if (c->mode == CM_P2P || child)
4592 {
4593 do_init_timers(c, false);
4594 }
4595
4596#ifdef ENABLE_PLUGIN
4597 /* initialize plugins */
4598 if (c->mode == CM_P2P || c->mode == CM_TOP)
4599 {
4600 open_plugins(c, false, OPENVPN_PLUGIN_INIT_POST_UID_CHANGE);
4601 }
4602#endif
4603
4604#if PORT_SHARE
4605 /* share OpenVPN port with foreign (such as HTTPS) server */
4606 if (c->first_time && (c->mode == CM_P2P || c->mode == CM_TOP))
4607 {
4608 init_port_share(c);
4609 }
4610#endif
4611
4612 /* Check for signals */
4613 if (IS_SIG(c))
4614 {
4615 goto sig;
4616 }
4617
4618 return;
4619
4620sig:
4621 if (!c->sig->signal_text)
4622 {
4623 c->sig->signal_text = "init_instance";
4624 }
4625 close_context(c, -1, flags);
4626 return;
4627}
4628
4629/*
4630 * Initialize a tunnel instance, handle pre and post-init
4631 * signal settings.
4632 */
4633void
4634init_instance_handle_signals(struct context *c, const struct env_set *env, const unsigned int flags)
4635{
4637 init_instance(c, env, flags);
4639
4640 /*
4641 * This is done so that signals thrown during
4642 * initialization can bring us back to
4643 * a management hold.
4644 */
4645 if (IS_SIG(c))
4646 {
4647 remap_signal(c);
4649 }
4650}
4651
4652/*
4653 * Close a tunnel instance.
4654 */
4655void
4657{
4658 /* close event objects */
4660
4661 if (c->mode == CM_P2P || c->mode == CM_CHILD_TCP || c->mode == CM_CHILD_UDP
4662 || c->mode == CM_TOP)
4663 {
4664#ifdef USE_COMP
4665 if (c->c2.comp_context)
4666 {
4667 comp_uninit(c->c2.comp_context);
4668 c->c2.comp_context = NULL;
4669 }
4670#endif
4671
4672 /* free buffers */
4674
4675 /* close peer for DCO if enabled, needs peer-id so must be done before
4676 * closing TLS contexts */
4677 dco_remove_peer(c);
4678
4679 /* close TLS */
4680 do_close_tls(c);
4681
4682 /* free key schedules */
4683 do_close_free_key_schedule(c, (c->mode == CM_P2P || c->mode == CM_TOP));
4684
4685 /* close TCP/UDP connection */
4687
4688 /* close TUN/TAP device */
4689 do_close_tun(c, false);
4690
4691#ifdef ENABLE_MANAGEMENT
4692 if (management)
4693 {
4695 }
4696#endif
4697
4698#ifdef ENABLE_PLUGIN
4699 /* call plugin close functions and unload */
4701#endif
4702
4703 /* close packet-id persistence file */
4705
4706 /* close --status file */
4708
4709#ifdef ENABLE_FRAGMENT
4710 /* close fragmentation handler */
4712#endif
4713
4714 /* close --ifconfig-pool-persist obj */
4716
4717 /* free up environmental variable store */
4719
4720 /* close HTTP or SOCKS proxy */
4721 uninit_proxy(c);
4722
4723 /* garbage collect */
4724 gc_free(&c->c2.gc);
4725 }
4726}
4727
4728void
4729inherit_context_child(struct context *dest, const struct context *src, struct link_socket *sock)
4730{
4731 CLEAR(*dest);
4732
4733 /* proto_is_dgram will ASSERT(0) if proto is invalid */
4735
4736 dest->gc = gc_new();
4737
4738 ALLOC_OBJ_CLEAR_GC(dest->sig, struct signal_info, &dest->gc);
4739
4740 /* c1 init */
4741 dest->c1.link_sockets_num = 1;
4743
4744 dest->c1.ks.key_type = src->c1.ks.key_type;
4745 /* inherit SSL context */
4746 dest->c1.ks.ssl_ctx = src->c1.ks.ssl_ctx;
4747 dest->c1.ks.tls_wrap_key = src->c1.ks.tls_wrap_key;
4750
4751 /* inherit auth-token */
4752 dest->c1.ks.auth_token_key = src->c1.ks.auth_token_key;
4753
4754 /* options */
4755 dest->options = src->options;
4756 dest->options.ce.proto = sock->info.proto;
4757 options_detach(&dest->options);
4758
4759 dest->c2.event_set = src->c2.event_set;
4760
4761 if (dest->mode == CM_CHILD_TCP)
4762 {
4763 /*
4764 * The CM_TOP context does the socket listen(),
4765 * and the CM_CHILD_TCP context does the accept().
4766 */
4767 dest->c2.accept_from = sock;
4768 }
4769
4770#ifdef ENABLE_PLUGIN
4771 /* inherit plugins */
4772 do_inherit_plugins(dest, src);
4773#endif
4774
4775 /* context init */
4776
4777 /* inherit tun/tap interface object now as it may be required
4778 * to initialize the DCO context in init_instance()
4779 */
4780 dest->c1.tuntap = src->c1.tuntap;
4781
4782 /* UDP inherits some extra things which TCP does not */
4783 if (dest->mode == CM_CHILD_UDP)
4784 {
4785 ASSERT(!dest->c2.link_sockets);
4786 ASSERT(dest->options.ce.local_list);
4787
4788 /* inherit buffers */
4789 dest->c2.buffers = src->c2.buffers;
4790
4791 ALLOC_ARRAY_GC(dest->c2.link_sockets, struct link_socket *, 1, &dest->gc);
4792
4793 /* inherit parent link_socket and tuntap */
4794 dest->c2.link_sockets[0] = sock;
4795
4796 ALLOC_ARRAY_GC(dest->c2.link_socket_infos, struct link_socket_info *, 1, &dest->gc);
4797 ALLOC_OBJ_GC(dest->c2.link_socket_infos[0], struct link_socket_info, &dest->gc);
4798 *dest->c2.link_socket_infos[0] = sock->info;
4799
4800 /* locally override some link_socket_info fields */
4801 dest->c2.link_socket_infos[0]->lsa = &dest->c1.link_socket_addrs[0];
4803 }
4804
4806}
4807
4808void
4809inherit_context_top(struct context *dest, const struct context *src)
4810{
4811 /* copy parent */
4812 *dest = *src;
4813
4814 /*
4815 * CM_TOP_CLONE will prevent close_instance from freeing or closing
4816 * resources owned by the parent.
4817 *
4818 * Also note that CM_TOP_CLONE context objects are
4819 * closed by multi_top_free in multi.c.
4820 */
4821 dest->mode = CM_TOP_CLONE;
4822
4823 dest->first_time = false;
4824 dest->c0 = NULL;
4825
4826 options_detach(&dest->options);
4827 gc_detach(&dest->gc);
4828 gc_detach(&dest->c2.gc);
4829
4830 /* detach plugins */
4831 dest->plugins_owned = false;
4832
4833 dest->c2.tls_multi = NULL;
4834
4835 /* detach c1 ownership */
4836 dest->c1.tuntap_owned = false;
4837 dest->c1.status_output_owned = false;
4838 dest->c1.ifconfig_pool_persist_owned = false;
4839
4840 /* detach c2 ownership */
4841 dest->c2.event_set_owned = false;
4842 dest->c2.link_socket_owned = false;
4843 dest->c2.buffers_owned = false;
4844 dest->c2.es_owned = false;
4845
4846 dest->c2.event_set = NULL;
4847 do_event_set_init(dest, false);
4848
4849#ifdef USE_COMP
4850 dest->c2.comp_context = NULL;
4851#endif
4852}
4853
4854void
4855close_context(struct context *c, int sig, unsigned int flags)
4856{
4857 ASSERT(c);
4858 ASSERT(c->sig);
4859
4860 if (sig >= 0)
4861 {
4862 register_signal(c->sig, sig, "close_context");
4863 }
4864
4865 if (c->sig->signal_received == SIGUSR1)
4866 {
4867 if ((flags & CC_USR1_TO_HUP)
4868 || (c->sig->source == SIG_SOURCE_HARD && (flags & CC_HARD_USR1_TO_HUP)))
4869 {
4870 register_signal(c->sig, SIGHUP, "close_context usr1 to hup");
4871 }
4872 }
4873
4874 if (!(flags & CC_NO_CLOSE))
4875 {
4876 close_instance(c);
4877 }
4878
4879 if (flags & CC_GC_FREE)
4880 {
4881 context_gc_free(c);
4882 }
4883}
4884
4885/* Write our PID to a file */
4886void
4887write_pid_file(const char *filename, const char *chroot_dir)
4888{
4889 if (filename)
4890 {
4891 unsigned int pid = 0;
4892 FILE *fp = platform_fopen(filename, "w");
4893 if (!fp)
4894 {
4895 msg(M_ERR, "Open error on pid file %s", filename);
4896 return;
4897 }
4898
4899 pid = platform_getpid();
4900 fprintf(fp, "%u\n", pid);
4901 if (fclose(fp))
4902 {
4903 msg(M_ERR, "Close error on pid file %s", filename);
4904 }
4905
4906 /* remember file name so it can be deleted "out of context" later */
4907 /* (the chroot case is more complex and not handled today) */
4908 if (!chroot_dir)
4909 {
4910 saved_pid_file_name = strdup(filename);
4912 {
4913 msg(M_FATAL, "Failed allocate memory saved_pid_file_name");
4914 }
4915 }
4916 }
4917}
4918
4919/* remove PID file on exit, called from openvpn_exit() */
4920void
4922{
4924 {
4926 }
4927}
4928
4929
4930/*
4931 * Do a loopback test
4932 * on the crypto subsystem.
4933 */
4934void
4936{
4937 /* print version number */
4938 msg(M_INFO, "%s", title_string);
4939 const struct options *options = &c->options;
4940
4943 context_init_1(c);
4946
4948
4950
4951 key_schedule_free(&c->c1.ks, true);
4953
4954 context_gc_free(c);
4955}
void notify_client_acc_protocols(struct tls_multi *multi)
Notifies a client via management interface of the negotiated app custom protocols.
Definition acc.c:447
void argv_msg(const msglvl_t msglevel, const struct argv *a)
Write the arguments stored in a struct argv via the msg() command.
Definition argv.c:242
void argv_parse_cmd(struct argv *argres, const char *cmdstr)
Parses a command string, tokenizes it and puts each element into a separate struct argv argument slot...
Definition argv.c:490
void argv_free(struct argv *a)
Frees all memory allocations allocated by the struct argv related functions.
Definition argv.c:101
bool argv_printf(struct argv *argres, const char *format,...)
printf() variant which populates a struct argv.
Definition argv.c:447
bool argv_printf_cat(struct argv *argres, const char *format,...)
printf() inspired argv concatenation.
Definition argv.c:471
struct argv argv_new(void)
Allocates a new struct argv and ensures it is initialised.
Definition argv.c:87
void auth_token_write_server_key_file(const char *filename)
Generate a auth-token server secret key, and write to file.
Definition auth_token.c:136
void auth_token_init_secret(struct key_ctx *key_ctx, const char *key_file, bool key_inline)
Loads an HMAC secret from a file or if no file is present generates a epheremal secret for the run ti...
Definition auth_token.c:142
bool buffer_list_defined(const struct buffer_list *ol)
Checks if the list is valid and non-empty.
Definition buffer.c:1204
void free_buf(struct buffer *buf)
Free the memory allocated for a buffer.
Definition buffer.c:174
void buf_clear(struct buffer *buf)
Zeroise and reset a buffer.
Definition buffer.c:153
bool buf_printf(struct buffer *buf, const char *format,...)
printf-style append to a buffer with overflow check.
Definition buffer.c:231
void string_clear(char *str)
Securely clear a null-terminated string.
Definition buffer.c:651
void buffer_list_free(struct buffer_list *ol)
Frees a buffer list and all the buffers in it.
Definition buffer.c:1194
struct buffer alloc_buf_gc(size_t size, struct gc_arena *gc)
Allocate a buffer of the given size under garbage collection.
Definition buffer.c:77
struct buffer alloc_buf(size_t size)
Allocate a buffer of the given size.
Definition buffer.c:60
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_detach(struct gc_arena *a)
Detach all allocations from an arena without freeing them.
Definition buffer.h:1947
#define BSTR(buf)
Return the buffer content pointer cast to char *.
Definition buffer.h:157
#define ALLOC_ARRAY_GC(dptr, type, n, gc)
Allocate a garbage-collected array of n elements of the given type.
Definition buffer.h:2065
#define streq(x, y)
helper to work around the semantics of the strcmp() return value
Definition buffer.h:1822
#define ALLOC_ARRAY_CLEAR_GC(dptr, type, n, gc)
Allocate and zero-initialise a garbage-collected array of n elements.
Definition buffer.h:2091
static void gc_init(struct gc_arena *a)
Initialise a garbage collection arena to an empty state.
Definition buffer.h:1932
static int buf_len(const struct buffer *buf)
Return the length of the buffer content.
Definition buffer.h:462
static void buf_set_write(struct buffer *buf, uint8_t *data, size_t size)
Initialise a buffer with an externally provided writable memory region.
Definition buffer.h:658
#define ALLOC_OBJ_CLEAR_GC(dptr, type, gc)
Allocate and zero-initialise a garbage-collected object of the given type.
Definition buffer.h:2132
#define ALLOC_OBJ_GC(dptr, type, gc)
Allocate a garbage-collected object of the given type (uninitialised).
Definition buffer.h:2120
#define BLENZ(buf)
Return the length of the buffer content as a size_t.
Definition buffer.h:153
static void check_malloc_return(void *p)
Abort if a memory allocation returned NULL.
Definition buffer.h:2144
static void gc_free(struct gc_arena *a)
Free all allocations in a garbage collection arena.
Definition buffer.h:1974
#define ALLOC_OBJ_CLEAR(dptr, type)
Allocate and zero-initialise memory for a single object of the given type.
Definition buffer.h:2036
static struct gc_arena gc_new(void)
Allocate and return a new, empty garbage collection arena.
Definition buffer.h:1958
#define PUSH_BUNDLE_SIZE
Definition common.h:89
bool check_compression_settings_valid(const struct compress_options *info, msglvl_t msglevel)
Checks if the compression settings are valid.
Definition comp.c:156
char * basename(char *filename)
int daemon(int nochdir, int noclose)
size_t strlcpy(char *dest, const char *src, size_t maxlen)
void free_key_ctx_bi(struct key_ctx_bi *ctx)
Definition crypto.c:1098
void init_key_type(struct key_type *kt, const char *ciphername, const char *authname, bool warn)
Initialize a key_type structure with.
Definition crypto.c:872
void test_crypto(struct crypto_options *co, const struct frame *frame)
Definition crypto.c:1162
int write_key_file(const int nkeys, const char *filename)
Write nkeys 1024-bits keys to file.
Definition crypto.c:1517
unsigned int crypto_max_overhead(void)
Return the worst-case OpenVPN crypto overhead (in bytes).
Definition crypto.c:847
int64_t get_random(void)
an analogue to the random() function, but use prng_bytes and also int64_t instead of long to avoid LL...
Definition crypto.c:1703
void generate_test_crypto_random_key(const struct key_type *key_type, struct key_ctx_bi *ctx, const char *key_name)
Generate a random key and initialise ctx to be used the in the crypto random test.
Definition crypto.c:1290
void crypto_read_openvpn_key(const struct key_type *key_type, struct key_ctx_bi *ctx, const char *key_file, bool key_inline, const int key_direction, const char *key_name, const char *opt_name, struct key2 *keydata)
Definition crypto.c:1251
void free_key_ctx(struct key_ctx *ctx)
Definition crypto.c:1079
#define CO_PACKET_ID_LONG_FORM
Bit-flag indicating whether to use OpenVPN's long packet ID format.
Definition crypto.h:335
#define CO_USE_TLS_KEY_MATERIAL_EXPORT
Bit-flag indicating that data channel key derivation is done using TLS keying material export [RFC570...
Definition crypto.h:347
#define CO_USE_DYNAMIC_TLS_CRYPT
Bit-flag indicating that renegotiations are using tls-crypt with a TLS-EKM derived key.
Definition crypto.h:363
#define CO_EPOCH_DATA_KEY_FORMAT
Bit-flag indicating the epoch the data format.
Definition crypto.h:367
#define CO_MUTE_REPLAY_WARNINGS
Bit-flag indicating not to display replay warnings.
Definition crypto.h:344
#define CO_FORCE_TLSCRYPTV2_COOKIE
Bit-flag indicating that we do not allow clients that do not support resending the wrapped client key...
Definition crypto.h:355
#define CO_USE_CC_EXIT_NOTIFY
Bit-flag indicating that explicit exit notifies should be sent via the control channel instead of usi...
Definition crypto.h:359
static bool key_ctx_bi_defined(const struct key_ctx_bi *key)
Definition crypto.h:642
void show_available_engines(void)
bool cipher_kt_mode_aead(const char *ciphername)
Check if the supplied cipher is a supported AEAD mode cipher.
void show_available_ciphers(void)
bool md_valid(const char *digest)
Return if a message digest parameters is valid given the name of the digest.
bool cipher_kt_mode_ofb_cfb(const char *ciphername)
Check if the supplied cipher is a supported OFB or CFB mode cipher.
const char * md_kt_name(const char *mdname)
Retrieve a string describing the digest digest (e.g.
const char * cipher_kt_name(const char *ciphername)
Retrieve a normalised string describing the cipher (e.g.
void crypto_init_lib_engine(const char *engine_name)
void md_ctx_cleanup(md_ctx_t *ctx)
void show_available_digests(void)
void md_ctx_free(md_ctx_t *ctx)
#define DCO_DEFAULT_METRIC
Definition dco.h:47
static void dco_remove_peer(struct context *c)
Definition dco.h:348
static bool dco_supports_epoch_data(const struct context *c)
Definition dco.h:387
static bool dco_check_pull_options(msglvl_t msglevel, const struct options *o)
Definition dco.h:286
static bool ovpn_dco_init(struct context *c)
Definition dco.h:292
static int dco_p2p_add_new_peer(struct context *c)
Definition dco.h:335
void run_dns_up_down(bool up, struct options *o, const struct tuntap *tt, struct dns_updown_runner_info *duri)
Invokes the action associated with bringing DNS up or down.
Definition dns.c:892
void env_set_destroy(struct env_set *es)
Definition env_set.c:165
void setenv_int(struct env_set *es, const char *name, int value)
Definition env_set.c:289
void setenv_str(struct env_set *es, const char *name, const char *value)
Definition env_set.c:305
void env_set_inherit(struct env_set *es, const struct env_set *src)
Definition env_set.c:260
struct env_set * env_set_create(struct gc_arena *gc)
Definition env_set.c:155
#define D_MTU_DEBUG
Definition errlevel.h:123
#define D_SHOW_OCC
Definition errlevel.h:147
#define D_PUSH
Definition errlevel.h:81
#define D_SHOW_NET
Definition errlevel.h:129
#define P2P_ERROR_DELAY_MS
Definition errlevel.h:40
#define D_RESTART
Definition errlevel.h:80
#define D_IMPORT_ERRORS
Definition errlevel.h:63
#define D_CLOSE
Definition errlevel.h:71
#define D_PUSH_DEBUG
Definition errlevel.h:146
#define D_DCO
Definition errlevel.h:92
#define D_HANDSHAKE
Definition errlevel.h:70
#define D_GENKEY
Definition errlevel.h:77
#define D_MTU_INFO
Definition errlevel.h:102
#define D_PUSH_ERRORS
Definition errlevel.h:66
#define D_INIT_MEDIUM
Definition errlevel.h:101
#define D_TLS_ERRORS
Definition errlevel.h:58
#define D_READ_WRITE
Definition errlevel.h:163
#define M_INFO
Definition errlevel.h:54
#define D_LOG_RW
Definition errlevel.h:107
#define D_ROUTE
Definition errlevel.h:78
#define D_LINK_ERRORS
Definition errlevel.h:56
struct event_set * event_set_init(int *maxevents, unsigned int flags)
Definition event.c:1205
#define EVENT_METHOD_FAST
Definition event.h:79
#define EVENT_METHOD_US_TIMEOUT
Definition event.h:78
static void event_free(struct event_set *es)
Definition event.h:159
bool send_control_channel_string(struct context *c, const char *str, msglvl_t msglevel)
Definition forward.c:414
Interface functions to the internal and external multiplexers.
static struct link_socket_info * get_link_socket_info(struct context *c)
Definition forward.h:351
struct tls_multi * tls_multi_init(const struct tls_options *tls_options)
Allocate and initialize a tls_multi structure.
Definition ssl.c:1193
void tls_init_control_channel_frame_parameters(struct frame *frame, int tls_mtu)
Definition ssl.c:162
void tls_multi_free(struct tls_multi *multi, bool clear)
Cleanup a tls_multi structure and free associated memory allocations.
Definition ssl.c:1286
void tls_multi_init_finalize(struct tls_multi *multi, int tls_mtu)
Finalize initialization of a tls_multi structure.
Definition ssl.c:1211
struct tls_auth_standalone * tls_auth_standalone_init(const struct tls_options *tls_options, struct gc_arena *gc)
Definition ssl.c:1234
void tls_auth_standalone_free(struct tls_auth_standalone *tas)
Frees a standalone tls-auth verification object.
Definition ssl.c:1259
#define TM_ACTIVE
Active tls_session.
Definition ssl_common.h:552
void tls_multi_init_set_options(struct tls_multi *multi, const char *local, const char *remote)
Definition ssl.c:1275
void fragment_frame_init(struct fragment_master *f, const struct frame *frame)
Allocate internal packet buffers for a fragment_master structure.
Definition fragment.c:130
struct fragment_master * fragment_init(struct frame *frame)
Allocate and initialize a fragment_master structure.
Definition fragment.c:97
void fragment_free(struct fragment_master *f)
Free a fragment_master structure and its internal packet buffers.
Definition fragment.c:121
void tls_crypt_init_key(struct key_ctx_bi *key, struct key2 *keydata, const char *key_file, bool key_inline, bool tls_server)
Initialize a key_ctx_bi structure for use with --tls-crypt.
Definition tls_crypt.c:62
void tls_crypt_v2_init_server_key(struct key_ctx *key_ctx, bool encrypt, const char *key_file, bool key_inline)
Initialize a tls-crypt-v2 server key (used to encrypt/decrypt client keys).
Definition tls_crypt.c:341
void tls_crypt_v2_write_client_key_file(const char *filename, const char *b64_metadata, const char *server_key_file, bool server_key_inline)
Generate a tls-crypt-v2 client key, and write to file.
Definition tls_crypt.c:716
unsigned int tls_crypt_buf_overhead(void)
Returns the maximum overhead (in bytes) added to the destination buffer by tls_crypt_wrap().
Definition tls_crypt.c:56
void tls_crypt_v2_write_server_key_file(const char *filename)
Generate a tls-crypt-v2 server key, and write to file.
Definition tls_crypt.c:705
void tls_crypt_v2_init_client_key(struct key_ctx_bi *key, struct key2 *original_key, struct buffer *wkc_buf, const char *key_file, bool key_inline)
Initialize a tls-crypt-v2 client key.
Definition tls_crypt.c:317
static bool do_open_tun(struct context *c, unsigned int *error_flags)
Definition init.c:1804
void uninit_management_callback(void)
Definition init.c:4322
static bool can_preserve_tun(const struct tuntap *tt)
Definition init.c:1707
static void uninit_proxy(struct context *c)
Definition init.c:728
bool open_management(struct context *c)
Definition init.c:4269
static void do_init_first_time(struct context *c)
Definition init.c:3769
static void do_init_route_list(const struct options *options, struct route_list *route_list, const struct link_socket_info *link_socket_info, struct env_set *es, openvpn_net_ctx_t *ctx)
Definition init.c:1396
static void do_init_tls_wrap_key(struct context *c)
Definition init.c:3008
static bool management_callback_remote_cmd(void *arg, const char **p)
Definition init.c:371
bool do_genkey(const struct options *options)
Definition init.c:994
static void next_connection_entry(struct context *c)
Definition init.c:516
static void do_init_crypto_test(struct context *c)
Definition init.c:2976
void initialization_sequence_completed(struct context *c, const unsigned int flags)
Definition init.c:1487
void open_plugins(struct context *c, const bool import_options, int init_point)
Definition init.c:4087
bool do_update(struct context *c, uint64_t option_types_found)
A simplified version of the do_up() function.
Definition init.c:2440
static void tls_print_deferred_options_results(struct context *c)
Prints the results of options imported for the data channel.
Definition init.c:2141
static const char * saved_pid_file_name
Definition init.c:65
void init_verb_mute(struct context *c, unsigned int flags)
Definition init.c:922
static void do_uid_gid_chroot(struct context *c, bool no_delay)
Definition init.c:1151
static bool management_acc_msg(void *arg, struct buffer_list *input)
Definition init.c:4213
static void do_close_link_socket(struct context *c)
Definition init.c:3866
static unsigned int management_callback_remote_entry_count(void *arg)
Definition init.c:327
static void do_signal_on_tls_errors(struct context *c)
Definition init.c:4062
static void key_schedule_free(struct key_schedule *ks, bool free_ssl_ctx)
Definition init.c:2963
static void do_init_tun(struct context *c)
Definition init.c:1662
static void do_option_warnings(struct context *c)
Definition init.c:3481
static void do_link_socket_addr_new(struct context *c)
Definition init.c:734
void close_instance(struct context *c)
Definition init.c:4656
static void do_init_route_ipv6_list(const struct options *options, struct route_ipv6_list *route_ipv6_list, const struct link_socket_info *link_socket_info, struct env_set *es, openvpn_net_ctx_t *ctx)
Definition init.c:1435
static void do_init_frame(struct context *c)
Definition init.c:3435
void persist_client_stats(struct context *c)
Definition init.c:4333
void inherit_context_top(struct context *dest, const struct context *src)
Definition init.c:4809
static bool ce_management_query_proxy(struct context *c)
Definition init.c:250
static void do_init_frame_tls(struct context *c)
Definition init.c:3412
static void do_init_traffic_shaper(struct context *c)
Definition init.c:1362
static bool route_noexec_enabled(const struct options *o, const struct tuntap *tt)
Determine if external route commands should be executed based on configured options and backend drive...
Definition init.c:1597
static bool ifconfig_noexec_enabled(const struct context *c)
Determines if ifconfig execution should be disabled because of a.
Definition init.c:1774
static void clear_remote_addrlist(struct link_socket_addr *lsa, bool free)
Definition init.c:502
static void do_print_data_channel_mtu_parms(struct context *c)
Definition init.c:3725
void init_plugins(struct context *c)
Definition init.c:4077
void free_context_buffers(struct context_buffers *b)
Definition init.c:3602
static void do_init_timers(struct context *c, bool deferred)
Definition init.c:1285
static void context_clear(struct context *c)
Definition init.c:78
static void context_clear_1(struct context *c)
Definition init.c:84
static void do_alloc_route_list(struct context *c)
Definition init.c:1378
static void do_close_status_output(struct context *c)
Definition init.c:3996
static void do_event_set_init(struct context *c, bool need_us_timeout)
Definition init.c:3951
static struct context * static_context
Definition init.c:64
static void do_init_fragment(struct context *c)
Definition init.c:3639
#define CF_INIT_TLS_MULTI
Definition init.c:70
void context_init_1(struct context *c)
Definition init.c:741
void do_test_crypto(struct context *c)
Definition init.c:4935
void pre_setup(const struct options *options)
Definition init.c:1238
static void do_link_socket_new(struct context *c)
Definition init.c:3660
static void do_close_free_key_schedule(struct context *c, bool free_ssl_ctx)
Definition init.c:3844
static bool management_callback_proxy_cmd(void *arg, const char **p)
Definition init.c:204
void reset_coarse_timers(struct context *c)
Definition init.c:1261
static void do_open_ifconfig_pool_persist(struct context *c)
Definition init.c:4013
static void do_close_ifconfig_pool_persist(struct context *c)
Definition init.c:4025
static void do_close_tun(struct context *c, bool force)
Definition init.c:1991
void init_management(void)
Definition init.c:4260
void uninit_static(void)
Definition init.c:904
void init_instance_handle_signals(struct context *c, const struct env_set *env, const unsigned int flags)
Definition init.c:4634
static void do_init_crypto_tls(struct context *c, const unsigned int flags)
Definition init.c:3176
void write_pid_file(const char *filename, const char *chroot_dir)
Definition init.c:4887
void context_gc_free(struct context *c)
Definition init.c:790
static void socket_restart_pause(struct context *c)
Definition init.c:2757
static void do_open_status_output(struct context *c)
Definition init.c:3984
const char * format_common_name(const struct context *c, struct gc_arena *gc)
Definition init.c:1227
void init_options_dev(struct options *options)
Definition init.c:945
static void do_close_free_buf(struct context *c)
Definition init.c:3803
void init_query_passwords(const struct context *c)
Query for private key and auth-user-pass username/passwords.
Definition init.c:646
void inherit_context_child(struct context *dest, const struct context *src, struct link_socket *sock)
Definition init.c:4729
static void do_compute_occ_strings(struct context *c)
Definition init.c:3740
void context_clear_2(struct context *c)
Definition init.c:90
static void do_close_fragment(struct context *c)
Definition init.c:3936
static void update_options_ce_post(struct options *options)
Definition init.c:186
static void management_callback_status_p2p(void *arg, const int version, struct status_output *so)
Definition init.c:4146
uint64_t pull_permission_mask(const struct context *c)
Definition init.c:2493
void remove_pid_file(void)
Definition init.c:4921
static void add_delim_if_non_empty(struct buffer *buf, const char *header)
Helper function for tls_print_deferred_options_results Adds the ", " delimitor if there already some ...
Definition init.c:2127
bool print_openssl_info(const struct options *options)
Definition init.c:956
void close_context(struct context *c, int sig, unsigned int flags)
Definition init.c:4855
static bool ce_management_query_remote(struct context *c)
Definition init.c:421
static void open_tun_backend(struct context *c)
Definition init.c:1782
static void do_close_event_set(struct context *c)
Definition init.c:3969
bool do_persist_tuntap(struct options *options, openvpn_net_ctx_t *ctx)
Definition init.c:1050
static bool do_hold(int holdtime)
Definition init.c:2738
void tun_abort(void)
Definition init.c:2095
static void do_init_server_poll_timeout(struct context *c)
Definition init.c:1272
static void do_close_plugins(struct context *c)
Definition init.c:4121
static void do_init_socket_phase1(struct context *c)
Definition init.c:3681
bool do_deferred_options(struct context *c, const uint64_t found, const bool is_update)
Definition init.c:2559
static int get_frame_mtu(struct context *c, const struct options *o)
Definition init.c:2847
static void init_instance(struct context *c, const struct env_set *env, const unsigned int flags)
Definition init.c:4347
bool init_static(void)
Definition init.c:828
static void do_init_crypto_tls_c1(struct context *c)
Definition init.c:3080
static void frame_finalize_options(struct context *c, const struct options *o)
Definition init.c:2882
static void uninit_proxy_dowork(struct context *c)
Definition init.c:673
static bool options_hash_changed_or_zero(const struct sha256_digest *a, const struct sha256_digest *b)
Helper for do_up().
Definition init.c:2114
static void do_close_tun_simple(struct context *c)
Definition init.c:1961
static void do_inherit_plugins(struct context *c, const struct context *src)
Definition init.c:4132
static void run_up_down(const char *command, const struct plugin_list *plugins, int plugin_type, const char *arg, DWORD adapter_index, const char *dev_type, int tun_mtu, const char *ifconfig_local, const char *ifconfig_remote, const char *context, const char *signal_text, const char *script_type, struct env_set *es)
Definition init.c:115
static void do_init_socket_phase2(struct context *c)
Definition init.c:3713
bool possibly_become_daemon(const struct options *options)
Definition init.c:1109
static bool management_callback_remote_entry_get(void *arg, unsigned int index, char **remote)
Definition init.c:337
static void init_connection_list(struct context *c)
Initialize and possibly randomize the connection list.
Definition init.c:477
static void init_proxy_dowork(struct context *c)
Definition init.c:690
static void do_close_packet_id(struct context *c)
Definition init.c:3926
static void do_startup_pause(struct context *c)
Definition init.c:2834
static bool do_deferred_p2p_ncp(struct context *c)
Definition init.c:2514
#define CF_INIT_TLS_AUTH_STANDALONE
Definition init.c:71
static void del_wfp_block(const struct context *c, unsigned long adapter_index)
Remove any WFP block filters previously added.
Definition init.c:1755
static bool do_deferred_options_part2(struct context *c)
This function is expected to be invoked after open_tun() was performed.
Definition init.c:2277
bool do_up(struct context *c, bool pulled_options, uint64_t option_types_found)
Definition init.c:2305
static void do_env_set_destroy(struct context *c)
Definition init.c:4051
static void do_init_buffers(struct context *c)
Definition init.c:3627
static void init_proxy(struct context *c)
Definition init.c:722
void init_management_callback_p2p(struct context *c)
Definition init.c:4233
static bool management_callback_send_cc_message(void *arg, const char *command, const char *parameters)
This method sends a custom control channel message.
Definition init.c:300
bool do_route(const struct options *options, struct route_list *route_list, struct route_ipv6_list *route_ipv6_list, const struct tuntap *tt, const struct plugin_list *plugins, struct env_set *es, openvpn_net_ctx_t *ctx)
Definition init.c:1608
static void do_inherit_env(struct context *c, const struct env_set *src)
Definition init.c:4043
void context_clear_all_except_first_time(struct context *c)
Definition init.c:96
struct context_buffers * init_context_buffers(const struct frame *frame)
Definition init.c:3577
static void do_close_tls(struct context *c)
Definition init.c:3817
void close_management(void)
Definition init.c:4309
static void add_wfp_block(const struct context *c)
Add WFP filters to block traffic to local networks.
Definition init.c:1729
void management_show_net_callback(void *arg, const msglvl_t msglevel)
Definition init.c:4153
#define ISC_ERRORS
Definition init.h:120
#define CC_GC_FREE
Definition init.h:109
#define IVM_LEVEL_2
Definition init.h:45
#define ISC_ROUTE_ERRORS
Definition init.h:122
#define IVM_LEVEL_1
Definition init.h:44
#define CC_USR1_TO_HUP
Definition init.h:110
#define BASE_N_EVENTS
Definition init.h:32
#define CC_HARD_USR1_TO_HUP
Definition init.h:111
#define ISC_SERVER
Definition init.h:121
#define CC_NO_CLOSE
Definition init.h:112
static int min_int(int x, int y)
Definition integer.h:105
static int max_int(int x, int y)
Definition integer.h:92
static unsigned int max_uint(unsigned int x, unsigned int y)
Definition integer.h:53
static SERVICE_STATUS status
Definition interactive.c:52
void interval_init(struct interval *top, int horizon, int refresh)
Definition interval.c:34
static void event_timeout_init(struct event_timeout *et, interval_t n, const time_t last)
Initialises a timer struct.
Definition interval.h:172
static void event_timeout_clear(struct event_timeout *et)
Clears the timeout and reset all values to 0.
Definition interval.h:153
int set_lladdr(const openvpn_net_ctx_t *ctx, const char *ifname, const char *lladdr, const struct env_set *es)
Definition lladdr.c:51
void management_pre_tunnel_close(struct management *man)
Definition manage.c:3268
void management_clear_callback(struct management *man)
Definition manage.c:2939
bool management_send_acc_message(struct context *c, struct tls_multi *multi, struct tls_session *session, struct buffer_list *input)
Definition manage.c:4406
void management_sleep(const unsigned int n)
A sleep function that services the management layer for n seconds rather than doing nothing.
Definition manage.c:4462
struct management * management_init(void)
Definition manage.c:2869
void management_notify_client_close(const struct management *man, struct man_def_auth_context *mdac, const struct env_set *es)
Definition manage.c:3185
void management_event_loop_n_seconds(struct management *man, unsigned int sec)
Definition manage.c:3622
void management_notify_generic(const char *str)
Definition manage.c:3101
void management_close(struct management *man)
Definition manage.c:2922
void management_set_state(struct management *man, const int state, const char *detail, const in_addr_t *tun_local_ip, const struct in6_addr *tun_local_ip6, const struct openvpn_sockaddr *local, const struct openvpn_sockaddr *remote)
Definition manage.c:2948
bool management_open(struct management *man, const char *addr, const char *port, const char *pass_file, const char *client_user, const char *client_group, const int log_history_cache, const int echo_buffer_size, const int state_buffer_size, const int remap_sigusr1, const unsigned int flags)
Definition manage.c:2883
void man_persist_client_stats(struct management *man, struct context *c)
Definition manage.c:4392
void management_set_callback(struct management *man, const struct management_callback *cb)
Definition manage.c:2932
bool management_hold(struct management *man, unsigned int holdtime)
Definition manage.c:4020
void management_post_tunnel_open(struct management *man, const in_addr_t tun_local_ip)
Definition manage.c:3245
void management_up_down(const struct management *man, const char *updown, const struct env_set *es)
Definition manage.c:3085
static bool management_query_remote_enabled(const struct management *man)
Definition manage.h:436
#define OPENVPN_STATE_CONNECTING
Definition manage.h:460
static bool management_query_proxy_enabled(const struct management *man)
Definition manage.h:442
#define OPENVPN_STATE_CONNECTED
Definition manage.h:463
#define MF_SERVER
Definition manage.h:27
void set_std_files_to_null(bool stdin_only)
Definition misc.c:55
#define GET_USER_PASS_MANAGEMENT
Definition misc.h:113
#define GET_USER_PASS_NEED_OK
Definition misc.h:116
static bool get_user_pass(struct user_pass *up, const char *auth_file, const char *prefix, const unsigned int flags)
Retrieves the user credentials from various sources depending on the flags.
Definition misc.h:155
void frame_calculate_dynamic(struct frame *frame, const struct key_type *kt, const struct options *options, const struct link_socket_info *lsi)
Set the –mssfix option.
Definition mss.c:326
size_t frame_calculate_protocol_header_size(const struct key_type *kt, const struct options *options, bool occ)
Calculates the size of the OpenVPN protocol header.
Definition mtu.c:73
void frame_print(const struct frame *frame, msglvl_t msglevel, const char *prefix)
Definition mtu.c:188
#define TUN_MTU_MAX_MIN
Definition mtu.h:79
#define BUF_SIZE(f)
Definition mtu.h:188
#define TUN_MTU_MAX
Maximum MTU we accept for MTU related options.
Definition mtu.h:74
#define TUN_MTU_MIN
Definition mtu.h:59
#define SOCKS_UDPv4_HEADROOM
Definition mtu.h:106
static const char * np(const char *str)
Definition multi-auth.c:146
void * openvpn_net_ctx_t
Definition networking.h:38
#define OCC_MTU_LOAD_INTERVAL_SECONDS
Definition occ.h:61
static int occ_reset_op(void)
Definition occ.h:101
#define OCC_INTERVAL_SECONDS
Definition occ.h:45
#define CLEAR(x)
Definition basic.h:32
void error_reset(void)
Definition error.c:157
bool set_mute_cutoff(const int cutoff)
Definition error.c:119
void set_check_status(unsigned int info_level, unsigned int verbose_level)
Definition error.c:616
void reset_check_status(void)
Definition error.c:609
bool set_debug_level(const int level, const unsigned int flags)
Definition error.c:103
#define M_OPTERR
Definition error.h:101
static bool check_debug_level(msglvl_t level)
Definition error.h:253
#define SDL_CONSTRAIN
Definition error.h:203
#define M_NOPREFIX
Definition error.h:98
#define M_USAGE
Definition error.h:107
#define M_FATAL
Definition error.h:90
static void set_check_status_error_delay(unsigned int milliseconds)
Definition error.h:319
#define M_NONFATAL
Definition error.h:91
#define M_ERR
Definition error.h:106
#define msg(flags,...)
Definition error.h:152
unsigned int msglvl_t
Definition error.h:77
#define ASSERT(x)
Definition error.h:221
#define M_WARN
Definition error.h:92
#define TLS_MODE(c)
Definition openvpn.h:515
#define CM_P2P
Definition openvpn.h:453
#define CM_TOP_CLONE
Definition openvpn.h:455
#define CM_CHILD_TCP
Definition openvpn.h:457
#define CM_CHILD_UDP
Definition openvpn.h:456
#define MAX_PEER_ID
Definition openvpn.h:526
#define CM_TOP
Definition openvpn.h:454
void options_detach(struct options *o)
Definition options.c:1260
void pre_connect_restore(struct options *o, struct gc_arena *gc)
Definition options.c:2391
const char title_string[]
Definition options.c:75
int auth_retry_get(void)
Definition options.c:3288
void notnull(const char *arg, const char *description)
Definition options.c:3431
#define MODE_POINT_TO_POINT
Definition options.h:264
#define OPT_P_UP
Definition options.h:742
#define CE_MAN_QUERY_REMOTE_QUERY
Definition options.h:158
#define OPT_P_NCP
Negotiable crypto parameters.
Definition options.h:753
#define OPT_P_ECHO
Definition options.h:761
#define MODE_SERVER
Definition options.h:265
#define OPT_P_EXPLICIT_NOTIFY
Definition options.h:760
#define CE_MAN_QUERY_REMOTE_SKIP
Definition options.h:161
#define AR_INTERACT
Definition options.h:960
#define OPT_P_SHAPER
Definition options.h:747
static bool dco_enabled(const struct options *o)
Returns whether the current configuration has dco enabled.
Definition options.h:981
void options_string_import(struct options *options, const char *config, const msglvl_t msglevel, const uint64_t permission_mask, uint64_t *option_types_found, struct env_set *es)
#define OPT_P_SOCKFLAGS
Definition options.h:767
#define SHAPER_DEFINED(opt)
Definition options.h:786
#define CE_MAN_QUERY_REMOTE_MOD
Definition options.h:160
#define CE_MAN_QUERY_PROXY
Definition options.h:156
#define OPT_P_MESSAGES
Definition options.h:752
#define OPT_P_SETENV
Definition options.h:746
#define OPT_P_SOCKBUF
Definition options.h:766
#define CE_MAN_QUERY_REMOTE_MASK
Definition options.h:162
#define OPT_P_PLUGIN
Definition options.h:765
#define OPT_P_TIMER
Definition options.h:748
#define PING_RESTART
Definition options.h:356
#define RH_PORT_LEN
Definition options.h:235
#define OPT_P_DEFAULT
Definition options.h:776
#define CE_MAN_QUERY_REMOTE_SHIFT
Definition options.h:163
#define OPT_P_DHCPDNS
Definition options.h:744
#define OPT_P_PULL_MODE
Definition options.h:764
@ GENKEY_AUTH_TOKEN
Definition options.h:244
@ GENKEY_SECRET
Definition options.h:241
@ GENKEY_TLS_CRYPTV2_SERVER
Definition options.h:243
@ GENKEY_TLS_CRYPTV2_CLIENT
Definition options.h:242
#define OPT_P_PUSH_MTU
Definition options.h:771
#define AR_NONE
Definition options.h:959
#define AR_NOINTERACT
Definition options.h:961
#define RH_HOST_LEN
Definition options.h:233
#define OPT_P_PERSIST
Definition options.h:749
#define MAX_PARMS
Definition options.h:51
#define PING_UNDEF
Definition options.h:354
#define CE_MAN_QUERY_REMOTE_ACCEPT
Definition options.h:159
#define PULL_DEFINED(opt)
Definition options.h:778
#define ROUTE_OPTION_FLAGS(o)
Definition options.h:781
#define PING_EXIT
Definition options.h:355
#define OPT_P_COMP
Definition options.h:751
#define OPT_P_ROUTE_EXTRAS
Definition options.h:763
#define OPT_P_PEER_ID
Definition options.h:769
#define OPT_P_ACC
Definition options.h:773
#define OPT_P_ROUTE
Definition options.h:743
#define CE_DISABLED
Definition options.h:155
const char * options_string_version(const char *s, struct gc_arena *gc)
char * options_string(const struct options *o, const struct frame *frame, struct tuntap *tt, openvpn_net_ctx_t *ctx, bool remote, struct gc_arena *gc)
Build an options string to represent data channel encryption options.
time_t now
Definition otime.c:33
static void update_time(void)
Definition otime.h:84
void time_test(void)
void packet_id_init(struct packet_id *p, int seq_backtrack, int time_backtrack, const char *name, int unit)
Definition packet_id.c:96
void packet_id_free(struct packet_id *p)
Definition packet_id.c:126
#define PRE_PULL_INITIAL_PING_RESTART
Definition ping.h:32
unsigned int platform_getpid(void)
Definition platform.c:338
const char * platform_create_temp_file(const char *directory, const char *prefix, struct gc_arena *gc)
Create a temporary file in directory, returns the filename of the created file.
Definition platform.c:545
void platform_user_group_set(const struct platform_state_user *user_state, const struct platform_state_group *group_state, struct context *c)
Definition platform.c:223
void platform_nice(int niceval)
Definition platform.c:316
bool platform_user_get(const char *username, struct platform_state_user *state)
Definition platform.c:85
bool platform_unlink(const char *filename)
Definition platform.c:492
FILE * platform_fopen(const char *path, const char *mode)
Definition platform.c:505
int platform_chdir(const char *dir)
Definition platform.c:397
void platform_mlockall(bool print_msg)
Definition platform.c:349
void platform_chroot(const char *path)
Definition platform.c:54
bool platform_group_get(const char *groupname, struct platform_state_group *state)
Definition platform.c:129
void plugin_list_close(struct plugin_list *pl)
Definition plugin.c:884
void plugin_return_free(struct plugin_return *pr)
Definition plugin.c:1001
struct plugin_list * plugin_list_inherit(const struct plugin_list *src)
Definition plugin.c:705
struct plugin_list * plugin_list_init(const struct plugin_option_list *list)
Definition plugin.c:779
void plugin_return_get_column(const struct plugin_return *src, struct plugin_return *dest, const char *colname)
Definition plugin.c:987
bool plugin_defined(const struct plugin_list *pl, const int type)
Definition plugin.c:919
void plugin_list_open(struct plugin_list *pl, const struct plugin_option_list *list, struct plugin_return *pr, const struct env_set *es, const int init_point)
Definition plugin.c:789
static void plugin_return_init(struct plugin_return *pr)
Definition plugin.h:163
static int plugin_call(const struct plugin_list *pl, const int type, const struct argv *av, struct plugin_return *pr, struct env_set *es)
Definition plugin.h:195
static bool plugin_return_defined(const struct plugin_return *pr)
Definition plugin.h:157
struct ifconfig_pool_persist * ifconfig_pool_persist_init(const char *filename, int refresh_freq)
Definition pool.c:542
void ifconfig_pool_persist_close(struct ifconfig_pool_persist *persist)
Definition pool.c:564
#define TOP_NET30
Definition proto.h:41
#define DEV_TYPE_TUN
Definition proto.h:35
#define TOP_P2P
Definition proto.h:42
void http_proxy_close(struct http_proxy_info *hp)
Definition proxy.c:531
struct http_proxy_info * http_proxy_new(const struct http_proxy_options *o)
Definition proxy.c:486
struct http_proxy_options * init_http_proxy_options_once(struct http_proxy_options **hpo, struct gc_arena *gc)
Definition proxy.c:44
#define PAR_NCT
Definition proxy.h:51
#define PAR_ALL
Definition proxy.h:50
void do_preresolve(struct context *c)
Definition resolve.c:573
DNS resolution.
bool add_routes(struct route_list *rl, struct route_ipv6_list *rl6, const struct tuntap *tt, unsigned int flags, const struct env_set *es, openvpn_net_ctx_t *ctx)
Definition route.c:1098
void setenv_routes_ipv6(struct env_set *es, const struct route_ipv6_list *rl6)
Definition route.c:1369
bool block_local_needed(const struct route_list *rl)
Get the decision whether to block traffic to local networks while the VPN is connected.
Definition route.c:591
bool init_route_ipv6_list(struct route_ipv6_list *rl6, const struct route_ipv6_option_list *opt6, const char *remote_endpoint, int default_metric, const struct in6_addr *remote_host_ipv6, struct env_set *es, openvpn_net_ctx_t *ctx)
Definition route.c:745
void add_route_ipv6_to_option_list(struct route_ipv6_option_list *l, const char *prefix, const char *gateway, const char *metric, int table_id)
Definition route.c:497
bool init_route_list(struct route_list *rl, const struct route_option_list *opt, const char *remote_endpoint, int default_metric, in_addr_t remote_host, struct env_set *es, openvpn_net_ctx_t *ctx)
Definition route.c:599
void delete_routes(struct route_list *rl, struct route_ipv6_list *rl6, const struct tuntap *tt, unsigned int flags, const struct env_set *es, openvpn_net_ctx_t *ctx)
Definition route.c:1163
void show_routes(msglvl_t msglevel)
Definition route.c:3011
void setenv_routes(struct env_set *es, const struct route_list *rl)
Definition route.c:1339
static int route_did_redirect_default_gateway(const struct route_list *rl)
Definition route.h:411
#define RG_REROUTE_GW
Definition route.h:91
int script_security(void)
Definition run_command.c:42
#define S_FATAL
Definition run_command.h:50
#define SSEC_SCRIPTS
allow calling of built-in programs and user-defined scripts
Definition run_command.h:35
static int openvpn_run_script(const struct argv *a, const struct env_set *es, const unsigned int flags, const char *hook)
Will run a script and return the exit code of the script if between 0 and 255, -1 otherwise.
Definition run_command.h:89
#define SSEC_PW_ENV
allow calling of built-in programs and user-defined scripts that may receive a password as an environ...
Definition run_command.h:38
void shaper_msg(struct shaper *s)
Definition shaper.c:87
static void shaper_init(struct shaper *s, int bytes_per_second)
Definition shaper.h:85
void post_init_signal_catch(void)
Definition sig.c:421
void print_status(struct context *c, struct status_output *so)
Definition sig.c:478
void pre_init_signal_catch(void)
Definition sig.c:392
void remap_signal(struct context *c)
Definition sig.c:582
const char * signal_description(const int signum, const char *sigtext)
Definition sig.c:105
void restore_signal_state(void)
Definition sig.c:460
void register_signal(struct signal_info *si, int signum, const char *signal_text)
Register a soft signal in the signal_info struct si respecting priority.
Definition sig.c:228
#define IS_SIG(c)
Definition sig.h:47
#define SIG_SOURCE_HARD
Definition sig.h:30
static void siphash_key_init(uint8_t *key)
Initialises a SIPHASH key with a random value.
Definition siphash.h:85
void link_socket_init_phase1(struct context *c, int sock_index, int mode)
Definition socket.c:977
void link_socket_init_phase2(struct context *c, struct link_socket *sock)
Definition socket.c:1332
void link_socket_update_buffer_sizes(struct link_socket *sock, int rcvbuf, int sndbuf)
Definition socket.c:161
const struct in6_addr * link_socket_current_remote_ipv6(const struct link_socket_info *info)
Definition socket.c:1635
void link_socket_close(struct link_socket *sock)
Definition socket.c:1442
in_addr_t link_socket_current_remote(const struct link_socket_info *info)
Definition socket.c:1601
struct link_socket * link_socket_new(void)
Definition socket.c:963
#define LS_MODE_TCP_ACCEPT_FROM
Definition socket.h:189
#define LS_MODE_DEFAULT
Definition socket.h:187
#define LS_MODE_TCP_LISTEN
Definition socket.h:188
const char * proto2ascii(int proto, sa_family_t af, bool display_form)
const char * print_in_addr_t(in_addr_t addr, unsigned int flags, struct gc_arena *gc)
#define IA_EMPTY_IF_UNDEF
Definition socket_util.h:89
static bool proto_is_udp(int proto)
Returns if the protocol being used is UDP.
@ PROTO_UDP
@ PROTO_TCP
@ PROTO_TCP_CLIENT
@ PROTO_TCP_SERVER
static bool proto_is_tcp(int proto)
returns if the proto is a TCP variant (tcp-server, tcp-client or tcp)
static bool proto_is_dgram(int proto)
Return if the protocol is datagram (UDP).
static bool addr_defined(const struct openvpn_sockaddr *addr)
struct socks_proxy_info * socks_proxy_new(const char *server, const char *port, const char *authfile)
Definition socks.c:52
void socks_proxy_close(struct socks_proxy_info *sp)
Definition socks.c:79
void ssl_purge_auth(const bool auth_user_pass_only)
Definition ssl.c:411
struct tls_root_ctx * init_ssl(const struct options *options, bool in_chroot)
Build master SSL context object that serves for the whole of OpenVPN instantiation.
Definition ssl.c:541
bool tls_session_update_crypto_params(struct tls_multi *multi, struct tls_session *session, struct options *options, struct frame *frame, struct frame *frame_fragment, const struct link_socket_info *lsi, dco_context_t *dco)
Update TLS session crypto parameters (cipher and auth) and derive data channel keys based on the supp...
Definition ssl.c:1731
void auth_user_pass_setup(const char *auth_file, bool is_inline, bool username_only, const struct static_challenge_info *sci)
Definition ssl.c:318
void pem_password_setup(const char *auth_file)
Definition ssl.c:273
void init_ssl_lib(void)
Definition ssl.c:250
void free_ssl_lib(void)
Definition ssl.c:258
void enable_auth_user_pass(void)
Definition ssl.c:312
void show_available_tls_ciphers(const char *cipher_list, const char *cipher_list_tls13, const char *tls_cert_profile)
Definition ssl.c:4404
#define TLS_MULTI_HORIZON
Definition ssl.h:61
#define TLS_MULTI_REFRESH
Definition ssl.h:60
void tls_ctx_free(struct tls_root_ctx *ctx)
Frees the library-specific TLSv1 context.
void show_available_curves(void)
Show the available elliptic curves in the crypto library.
bool tls_ctx_initialised(const struct tls_root_ctx *ctx)
Checks whether the given TLS context is initialised.
@ CAS_CONNECT_DONE
Definition ssl_common.h:601
@ CAS_RECONNECT_PENDING
session has already successful established (CAS_CONNECT_DONE) but has a reconnect and needs to redo s...
Definition ssl_common.h:600
bool check_pull_client_ncp(struct context *c, const uint64_t found)
Checks whether the cipher negotiation is in an acceptable state and we continue to connect or should ...
Definition ssl_ncp.c:302
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
const char * get_p2p_ncp_cipher(struct tls_session *session, const char *peer_info, struct gc_arena *gc)
Determines the best common cipher from both peers IV_CIPHER lists.
Definition ssl_ncp.c:347
Control Channel SSL/Data dynamic negotiation Module This file is split from ssl.h to be able to unit ...
const char * tls_common_name(const struct tls_multi *multi, const bool null)
Returns the common name field for the given tunnel.
Definition ssl_verify.c:107
Control Channel Verification Module.
#define VERIFY_X509_NONE
Definition ssl_verify.h:68
#define NS_CERT_CHECK_SERVER
Do not perform Netscape certificate type verification.
Definition ssl_verify.h:252
void status_printf(struct status_output *so, const char *format,...)
Definition status.c:221
struct status_output * status_open(const char *filename, const int refresh_freq, const int msglevel, const struct virtual_output *vout, const unsigned int flags)
Definition status.c:64
bool status_close(struct status_output *so)
Definition status.c:187
#define STATUS_OUTPUT_WRITE
Definition status.h:51
Definition argv.h:35
A singly-linked list of buffers, with head/tail pointers for O(1) push.
Definition buffer.h:2168
Wrapper structure for dynamically allocated memory.
Definition buffer.h:71
int len
Length in bytes of the actual content within the allocated memory.
Definition buffer.h:76
Definition options.h:109
struct local_list * local_list
Definition options.h:110
int tun_mtu_max
Definition options.h:131
int connect_retry_seconds
Definition options.h:121
bool tls_crypt_v2_force_cookie
Definition options.h:181
int link_mtu
Definition options.h:136
bool link_mtu_defined
Definition options.h:137
int tun_mtu_extra
Definition options.h:134
int connect_retry_seconds_max
Definition options.h:122
int mssfix
Definition options.h:146
const char * tls_crypt_file
Definition options.h:172
const char * tls_crypt_v2_file
Definition options.h:177
bool tun_mtu_extra_defined
Definition options.h:135
const char * remote
Definition options.h:116
int connect_timeout
Definition options.h:123
const char * socks_proxy_port
Definition options.h:126
bool mssfix_encap
Definition options.h:148
struct http_proxy_options * http_proxy_options
Definition options.h:124
bool tls_crypt_file_inline
Definition options.h:173
bool tls_auth_file_inline
Definition options.h:168
bool tun_mtu_defined
Definition options.h:133
int tls_mtu
Definition options.h:138
int explicit_exit_notification
Definition options.h:152
const char * socks_proxy_authfile
Definition options.h:127
const char * remote_port
Definition options.h:115
bool fragment_encap
Definition options.h:144
const char * socks_proxy_server
Definition options.h:125
int fragment
Definition options.h:143
int proto
Definition options.h:111
sa_family_t af
Definition options.h:112
const char * tls_auth_file
Definition options.h:167
int tun_mtu
Definition options.h:129
int key_direction
Definition options.h:169
bool tls_crypt_v2_file_inline
Definition options.h:178
unsigned int flags
Definition options.h:164
struct connection_entry ** array
Definition options.h:206
Level 0 context containing information related to the OpenVPN process.
Definition openvpn.h:123
struct platform_state_group platform_state_group
Definition openvpn.h:129
struct platform_state_user platform_state_user
Definition openvpn.h:128
bool uid_gid_chroot_set
Definition openvpn.h:127
bool uid_gid_specified
Definition openvpn.h:125
struct key_schedule ks
Definition openvpn.h:150
struct ifconfig_pool_persist * ifconfig_pool_persist
Definition openvpn.h:180
bool http_proxy_owned
Definition openvpn.h:173
struct status_output * status_output
Definition openvpn.h:168
struct route_list * route_list
List of routing information.
Definition openvpn.h:160
struct link_socket_addr * link_socket_addrs
Local and remote addresses on the external network.
Definition openvpn.h:145
struct sha256_digest pulled_options_digest_save
Hash of option strings received from the remote OpenVPN server.
Definition openvpn.h:184
int link_sockets_num
Definition openvpn.h:144
bool status_output_owned
Definition openvpn.h:169
struct route_ipv6_list * route_ipv6_list
Definition openvpn.h:165
struct http_proxy_info * http_proxy
Definition openvpn.h:172
bool socks_proxy_owned
Definition openvpn.h:177
bool tuntap_owned
Whether the tun/tap interface should be cleaned up when this context is cleaned up.
Definition openvpn.h:156
bool ifconfig_pool_persist_owned
Definition openvpn.h:181
struct socks_proxy_info * socks_proxy
Definition openvpn.h:176
struct tuntap * tuntap
Tun/tap virtual network interface.
Definition openvpn.h:155
char * options_string_local
Definition openvpn.h:273
struct event_timeout occ_mtu_load_test_interval
Definition openvpn.h:294
struct event_timeout server_poll_interval
Definition openvpn.h:382
struct fragment_master * fragment
Definition openvpn.h:235
bool do_up_ran
Definition openvpn.h:385
char * options_string_remote
Definition openvpn.h:274
struct event_timeout route_wakeup_expire
Definition openvpn.h:358
struct event_timeout ping_send_interval
Definition openvpn.h:260
bool did_open_tun
Definition openvpn.h:361
md_ctx_t * pulled_options_state
Definition openvpn.h:415
bool es_owned
Definition openvpn.h:395
struct man_def_auth_context mda_context
Definition openvpn.h:424
const struct link_socket * accept_from
Definition openvpn.h:225
struct tls_auth_standalone * tls_auth_standalone
TLS state structure required for the initial authentication of a client's connection attempt.
Definition openvpn.h:303
int occ_op
Definition openvpn.h:276
struct env_set * es
Definition openvpn.h:394
struct interval tmp_int
Definition openvpn.h:320
struct event_timeout auth_token_renewal_interval
Definition openvpn.h:270
bool link_socket_owned
Definition openvpn.h:223
struct event_timeout wait_for_connect
Definition openvpn.h:259
struct shaper shaper
Definition openvpn.h:242
struct tls_multi * tls_multi
TLS state structure for this VPN tunnel.
Definition openvpn.h:300
time_t coarse_timer_wakeup
Definition openvpn.h:373
struct frame frame
Definition openvpn.h:231
struct frame frame_fragment
Definition openvpn.h:236
struct crypto_options crypto_options
Security parameters and crypto state used by the Data Channel Crypto module to process data channel p...
Definition openvpn.h:325
bool buffers_owned
Definition openvpn.h:342
struct event_timeout occ_interval
Definition openvpn.h:278
struct link_socket ** link_sockets
Definition openvpn.h:220
struct link_socket_info ** link_socket_infos
Definition openvpn.h:221
uint8_t session_id_key[SIPHASH_KEY_SIZE]
the siphash secret we use to generate and verify our syn cookie like session ids from the server.
Definition openvpn.h:315
struct event_timeout session_interval
Definition openvpn.h:267
bool log_rw
Definition openvpn.h:354
int event_set_max
Definition openvpn.h:214
struct gc_arena gc
Garbage collection arena for allocations done in the level 2 scope of this context_2 structure.
Definition openvpn.h:208
struct sha256_digest pulled_options_digest
Definition openvpn.h:416
struct event_set * event_set
Definition openvpn.h:213
struct context_buffers * buffers
Definition openvpn.h:341
struct event_timeout route_wakeup
Definition openvpn.h:357
int tls_exit_signal
Definition openvpn.h:323
struct event_timeout inactivity_interval
Definition openvpn.h:264
struct event_timeout ping_rec_interval
Definition openvpn.h:261
bool event_set_owned
Definition openvpn.h:215
struct buffer read_link_buf
Definition openvpn.h:99
struct buffer encrypt_buf
Definition openvpn.h:86
struct buffer read_tun_buf
Definition openvpn.h:100
struct buffer decrypt_buf
Definition openvpn.h:87
struct buffer aux_buf
Definition openvpn.h:83
int restart_sleep_seconds
Definition openvpn.h:108
struct dns_updown_runner_info duri
Definition openvpn.h:109
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
struct context_0 * c0
Level 0 context.
Definition openvpn.h:488
bool did_we_daemonize
Whether demonization has already taken place.
Definition openvpn.h:481
bool first_time
True on the first iteration of OpenVPN's main loop.
Definition openvpn.h:449
struct signal_info * sig
Internal error signaling object.
Definition openvpn.h:474
openvpn_net_ctx_t net_ctx
Networking API opaque context.
Definition openvpn.h:472
struct plugin_list * plugins
List of plug-ins.
Definition openvpn.h:476
struct context_2 c2
Level 2 context.
Definition openvpn.h:490
struct env_set * es
Set of environment variables.
Definition openvpn.h:470
struct options options
Options loaded from command line or configuration file.
Definition openvpn.h:446
bool plugins_owned
Whether the plug-ins should be cleaned up when this context is cleaned up.
Definition openvpn.h:477
struct gc_arena gc
Garbage collection arena for allocations done in the scope of this context structure.
Definition openvpn.h:466
struct context_1 c1
Level 1 context.
Definition openvpn.h:489
struct context_persist persist
Persistent context.
Definition openvpn.h:486
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
struct packet_id packet_id
Current packet ID state for both sending and receiving directions.
Definition crypto.h:326
Packet geometry parameters.
Definition mtu.h:113
int tun_mtu
the (user) configured tun-mtu.
Definition mtu.h:147
struct frame::@074234134026241341315172337061247271261307273127 buf
int payload_size
the maximum size that a payload that our buffers can hold from either tun device or network link.
Definition mtu.h:118
int tun_max_mtu
the maximum tun-mtu size the buffers are are sized for.
Definition mtu.h:157
int extra_tun
Maximum number of bytes in excess of the tun/tap MTU that might be read from or written to the virtua...
Definition mtu.h:161
int headroom
the headroom in the buffer, this is choosen to allow all potential header to be added before the pack...
Definition mtu.h:124
int tailroom
the tailroom in the buffer.
Definition mtu.h:128
Garbage collection arena used to keep track of dynamically allocated memory.
Definition buffer.h:127
const char * port
Definition proxy.h:47
const char * server
Definition proxy.h:46
struct buffer tls_crypt_v2_wkc
Wrapped client key.
Definition openvpn.h:73
struct key2 original_wrap_keydata
original tls-crypt key preserved to xored into the tls_crypt renegotiation key
Definition openvpn.h:71
struct key_type key_type
Definition openvpn.h:58
struct key_ctx auth_token_key
Definition openvpn.h:74
struct key_type tls_auth_key_type
Definition openvpn.h:67
struct key_ctx_bi tls_wrap_key
Definition openvpn.h:68
struct key_ctx_bi static_key
Definition openvpn.h:61
struct tls_root_ctx * ssl_ctx
Definition openvpn.h:64
struct key_ctx tls_crypt_v2_server_key
Definition openvpn.h:72
const char * cipher
const name of the cipher
Definition crypto.h:135
const char * digest
Message digest static parameters.
Definition crypto.h:136
const char * special_state_msg
Definition manage.h:239
bool(* acc_msg)(void *arg, struct buffer_list *msg)
Definition manage.h:197
void(* status)(void *arg, const int version, struct status_output *so)
Definition manage.h:178
bool(* remote_entry_get)(void *arg, unsigned int index, char **remote)
Definition manage.h:205
unsigned int(* remote_entry_count)(void *arg)
Definition manage.h:204
bool(* send_cc_message)(void *arg, const char *message, const char *parameter)
Definition manage.h:184
bool(* proxy_cmd)(void *arg, const char **p)
Definition manage.h:199
void(* show_net)(void *arg, const msglvl_t msglevel)
Definition manage.h:179
unsigned int flags
Definition manage.h:176
bool(* remote_cmd)(void *arg, const char **p)
Definition manage.h:200
struct man_persist persist
Definition manage.h:344
union openvpn_sockaddr::@051240265251124304325377241125360350250341115171 addr
struct sockaddr sa
Definition socket_util.h:42
struct sockaddr_in in4
Definition socket_util.h:43
struct sockaddr_in6 in6
Definition socket_util.h:44
int rcvbuf
Definition options.h:413
bool resolve_in_advance
Definition options.h:368
bool route_nopull
Definition options.h:437
const char * genkey_extra_data
Definition options.h:290
struct compress_options comp
Definition options.h:410
const char * acc_protocols
The app custom control protocols we should announce as supported.
Definition options.h:713
bool persist_config
Definition options.h:278
struct connection_list * connection_list
Definition options.h:295
const char * management_port
Definition options.h:447
const char * ifconfig_ipv6_remote
Definition options.h:331
int server_backoff_time
Definition options.h:310
int auth_token_renewal
Definition options.h:546
const char * tmp_dir
Definition options.h:466
bool push_peer_info
Definition options.h:681
bool daemon
Definition options.h:391
int route_default_metric
Definition options.h:429
int renegotiate_seconds_min
Definition options.h:644
const char * auth_token_secret_file
Definition options.h:547
unsigned int imported_protocol_flags
Definition options.h:735
const char * tls_export_peer_cert_dir
Definition options.h:609
bool crl_file_inline
Definition options.h:613
const char * down_script
Definition options.h:386
hash_algo_type verify_hash_algo
Definition options.h:619
int replay_time
Definition options.h:584
int management_state_buffer_size
Definition options.h:451
bool duplicate_cn
Definition options.h:528
int shaper
Definition options.h:334
int management_echo_buffer_size
Definition options.h:450
bool show_net_up
Definition options.h:694
bool verify_hash_no_ca
Definition options.h:621
bool use_peer_id
Whether the data channel uses the DATA_V2 header (peer-id).
Definition options.h:703
unsigned remote_cert_ku[MAX_PARMS]
Definition options.h:616
bool server_bridge_defined
Definition options.h:481
const char * keying_material_exporter_label
Definition options.h:707
const char * status_file
Definition options.h:406
unsigned int ssl_flags
Definition options.h:622
bool route_noexec
Definition options.h:430
bool ifconfig_nowarn
Definition options.h:333
const char * remote_cert_eku
Definition options.h:617
int tls_timeout
Definition options.h:638
bool test_crypto
Definition options.h:585
bool up_delay
Definition options.h:389
bool server_bridge_proxy_dhcp
Definition options.h:479
const char * authname
Definition options.h:579
const char * exit_event_name
Definition options.h:692
const char * ifconfig_ipv6_local
Definition options.h:329
int replay_window
Definition options.h:583
int mute
Definition options.h:400
bool auth_user_pass_verify_script_via_file
Definition options.h:542
const char * dev_type
Definition options.h:323
int persist_mode
Definition options.h:279
int ifconfig_pool_persist_refresh_freq
Definition options.h:493
int pushed_acc_max_message_length
the maximum length of an ACC control channel message via push message
Definition options.h:722
bool show_digests
Definition options.h:283
const char * up_script
Definition options.h:385
int ce_advance_count
Definition options.h:306
bool single_session
Definition options.h:679
struct remote_host_store * rh_store
Definition options.h:316
int verify_hash_depth
Definition options.h:620
bool route_delay_defined
Definition options.h:433
const char * tls_crypt_v2_file
Definition options.h:669
int management_log_history_cache
Definition options.h:449
uint32_t peer_id
Definition options.h:704
struct route_option_list * routes
Definition options.h:434
int keepalive_timeout
Definition options.h:343
int64_t inactivity_minimum_bytes
Definition options.h:346
bool block_outside_dns
Definition options.h:696
bool tls_exit
Definition options.h:683
bool show_engines
Definition options.h:284
HANDLE msg_channel
Definition options.h:691
const char * key_pass_file
Definition options.h:281
bool mute_replay_warnings
Definition options.h:582
int inactivity_timeout
Definition options.h:345
unsigned int unsuccessful_attempts
Definition options.h:304
int handshake_window
Definition options.h:651
const char * ifconfig_local
Definition options.h:327
char * x509_username_field[MAX_PARMS]
Definition options.h:654
struct connection_entry ce
Definition options.h:294
const char * pushed_acc_negotiated_protocols
the protocols that are negotiated with the peer.
Definition options.h:718
bool user_script_used
Definition options.h:387
bool show_tls_ciphers
Definition options.h:285
struct tuntap_options tuntap_options
Definition options.h:371
struct verify_hash_list * verify_hash
Definition options.h:618
const char * tls_cert_profile
Definition options.h:606
int64_t renegotiate_packets
Definition options.h:642
unsigned int management_flags
Definition options.h:459
const char * route_default_gateway
Definition options.h:426
bool exit_event_initial_state
Definition options.h:693
struct static_challenge_info sc_info
Definition options.h:569
bool auth_token_call_auth
Definition options.h:544
int topology
Definition options.h:326
bool disable_dco
Definition options.h:374
const char * ncp_ciphers
Definition options.h:578
bool genkey
Definition options.h:287
const char * ciphername
Definition options.h:573
const char * auth_user_pass_file
Definition options.h:561
int tls_crypt_v2_max_age
Definition options.h:676
const char * username
Definition options.h:377
struct plugin_option_list * plugin_list
Definition options.h:462
int auth_token_lifetime
Definition options.h:545
int ns_cert_type
Definition options.h:615
const char * tls_crypt_v2_verify_script
Definition options.h:674
int mode
Definition options.h:266
bool tls_server
Definition options.h:588
const char * auth_user_pass_verify_script
Definition options.h:541
int connect_retry_max
Definition options.h:293
bool pull
Definition options.h:557
bool show_curves
Definition options.h:286
const char * route_ipv6_default_gateway
Definition options.h:427
bool tls_client
Definition options.h:589
bool auth_token_generate
Definition options.h:543
bool priv_key_file_inline
Definition options.h:600
const char * tls_verify
Definition options.h:608
const char * crl_file
Definition options.h:612
int ping_rec_timeout_action
Definition options.h:357
bool auth_user_pass_file_inline
Definition options.h:562
bool show_ciphers
Definition options.h:282
bool enable_ncp_fallback
If defined fall back to ciphername if NCP fails.
Definition options.h:574
const char * route_predown_script
Definition options.h:425
int route_delay_window
Definition options.h:432
bool mlock
Definition options.h:340
int64_t aead_usage_limit_override
Debug override to trigger AEAD usage limit early.
Definition options.h:647
int sndbuf
Definition options.h:414
struct gc_arena gc
Definition options.h:258
bool down_pre
Definition options.h:388
bool persist_tun
Definition options.h:359
int route_default_table_id
Definition options.h:428
bool auth_token_secret_file_inline
Definition options.h:548
const char * config
Definition options.h:261
int keying_material_exporter_length
Definition options.h:708
bool mtu_test
Definition options.h:338
int verify_x509_type
Definition options.h:610
const char * cipher_list_tls13
Definition options.h:604
int status_file_update_freq
Definition options.h:408
const char * management_client_user
Definition options.h:453
const char * cipher_list
Definition options.h:603
bool ccd_exclusive
Definition options.h:507
const char * genkey_filename
Definition options.h:289
const struct x509_track * x509_track
Definition options.h:685
const char * chroot_dir
Definition options.h:379
bool auth_user_pass_username_only
Definition options.h:563
bool log
Definition options.h:395
int renegotiate_seconds
Definition options.h:643
int ping_rec_timeout
Definition options.h:351
const char * engine
Definition options.h:580
const char * management_addr
Definition options.h:446
const char * verify_x509_name
Definition options.h:611
int ping_send_timeout
Definition options.h:350
bool remote_random
Definition options.h:320
int route_delay
Definition options.h:431
const char * dev_node
Definition options.h:324
const char * client_crresponse_script
Definition options.h:505
struct route_ipv6_option_list * routes_ipv6
Definition options.h:435
bool persist_remote_ip
Definition options.h:361
bool up_restart
Definition options.h:390
int keepalive_ping
Definition options.h:342
bool no_advance
Definition options.h:299
bool tls_crypt_v2_file_inline
Definition options.h:670
const char * groupname
Definition options.h:378
const char * cd_dir
Definition options.h:380
int nice
Definition options.h:398
int transition_window
Definition options.h:657
const char * ifconfig_remote_netmask
Definition options.h:328
const char * lladdr
Definition options.h:325
int verbosity
Definition options.h:399
int session_timeout
Definition options.h:348
enum tun_driver_type windows_driver
Definition options.h:697
int remap_sigusr1
Definition options.h:393
int64_t renegotiate_bytes
Definition options.h:641
const char * route_script
Definition options.h:424
const char * management_user_pass
Definition options.h:448
bool occ
Definition options.h:443
bool ifconfig_noexec
Definition options.h:332
const char * dev
Definition options.h:322
const char * management_client_group
Definition options.h:454
const char * client_config_dir
Definition options.h:506
enum genkey_type genkey_type
Definition options.h:288
bool advance_next_remote
Definition options.h:302
const char * ifconfig_pool_persist_filename
Definition options.h:492
int ifconfig_ipv6_netbits
Definition options.h:330
bool persist_local_ip
Definition options.h:360
struct openvpn_plugin_string_list * list[MAX_PLUGINS]
Definition plugin.h:106
char port[RH_PORT_LEN]
Definition options.h:236
char host[RH_HOST_LEN]
Definition options.h:234
unsigned int flags
Definition route.h:113
struct gc_arena * gc
Definition route.h:115
Wrapper struct to pass around SHA256 digests.
Definition crypto.h:126
const char * signal_text
Definition sig.h:44
volatile int signal_received
Definition sig.h:42
volatile int source
Definition sig.h:43
unsigned int flags
Definition status.h:52
struct frame frame
Definition ssl_pkt.h:81
struct buffer workbuf
Definition ssl_pkt.h:80
struct tls_wrap_ctx tls_wrap
Definition ssl_pkt.h:79
Security parameter state for a single VPN tunnel.
Definition ssl_common.h:619
dco_context_t * dco
Definition ssl_common.h:735
char * peer_info
A multi-line string of general-purpose info received from peer over control channel.
Definition ssl_common.h:680
enum multi_status multi_state
Definition ssl_common.h:640
int acc_max_message_length
the maximum length of an ACC control channel message
Definition ssl_common.h:741
struct tls_options opt
Definition ssl_common.h:624
struct tls_session session[TM_SIZE]
Array of tls_session objects representing control channel sessions with the remote peer.
Definition ssl_common.h:721
bool use_peer_id
Definition ssl_common.h:709
uint32_t tx_peer_id
Definition ssl_common.h:708
char * acc_negotiated_protocols
the protocols that are negotiated with the peer.
Definition ssl_common.h:738
uint32_t rx_peer_id
Definition ssl_common.h:707
int64_t renegotiate_bytes
Definition ssl_common.h:344
struct key_ctx auth_token_key
Definition ssl_common.h:412
uint64_t aead_usage_limit_override
Debug only option that allows overriding the usage limit This allows testing key rotation by using ve...
Definition ssl_common.h:353
unsigned int auth_token_renewal
Definition ssl_common.h:410
struct env_set * es
Definition ssl_common.h:418
unsigned int auth_token_lifetime
Definition ssl_common.h:409
struct tls_wrap_ctx tls_wrap
TLS handshake wrapping state.
Definition ssl_common.h:391
size_t ekm_label_size
Definition ssl_common.h:456
unsigned int crypto_flags
Definition ssl_common.h:372
unsigned remote_cert_ku[MAX_PARMS]
Definition ssl_common.h:363
interval_t packet_timeout
Definition ssl_common.h:343
const char * auth_user_pass_file
Definition ssl_common.h:401
const char * client_crresponse_script
Definition ssl_common.h:397
const struct static_challenge_info * sci
Definition ssl_common.h:448
openvpn_net_ctx_t * net_ctx
Definition ssl_common.h:419
const char * tmp_dir
Definition ssl_common.h:399
interval_t renegotiate_seconds
Definition ssl_common.h:354
struct frame frame
Definition ssl_common.h:393
int64_t renegotiate_packets
Definition ssl_common.h:345
bool auth_user_pass_file_inline
Definition ssl_common.h:402
int verify_hash_depth
Definition ssl_common.h:366
const struct plugin_list * plugins
Definition ssl_common.h:420
const char * client_config_dir_exclusive
Definition ssl_common.h:415
bool tls_crypt_v2
Definition ssl_common.h:386
const char * export_peer_cert_dir
Definition ssl_common.h:400
char * x509_username_field[MAX_PARMS]
Definition ssl_common.h:369
int tls_crypt_v2_max_age
Definition ssl_common.h:388
const char * verify_command
Definition ssl_common.h:357
struct verify_hash_list * verify_hash
Definition ssl_common.h:365
const char * ekm_label
Definition ssl_common.h:455
size_t ekm_size
Definition ssl_common.h:457
int transition_window
Definition ssl_common.h:341
const char * config_ciphername
Definition ssl_common.h:377
const char * acc_protocols
The app custom control protocols we should announce as supported.
Definition ssl_common.h:462
int verify_x509_type
Definition ssl_common.h:358
bool single_session
Definition ssl_common.h:327
bool data_epoch_supported
whether our underlying data channel supports new data channel features (epoch keys with AEAD tag at t...
Definition ssl_common.h:384
const char * verify_x509_name
Definition ssl_common.h:359
bool crl_file_inline
Definition ssl_common.h:361
const struct x509_track * x509_track
Definition ssl_common.h:445
bool verify_hash_no_ca
Definition ssl_common.h:367
struct man_def_auth_context * mda_context
Definition ssl_common.h:442
const char * tls_crypt_v2_verify_script
Definition ssl_common.h:387
bool auth_user_pass_verify_script_via_file
Definition ssl_common.h:398
const char * config_ncp_ciphers
Definition ssl_common.h:378
unsigned int ssl_flags
Definition ssl_common.h:439
bool auth_token_generate
Generate auth-tokens on successful user/pass auth,seet via options->auth_token_generate.
Definition ssl_common.h:405
struct key_type key_type
Definition ssl_common.h:313
int push_peer_info_detail
The detail of info we push in peer info.
Definition ssl_common.h:340
struct tls_root_ctx * ssl_ctx
Definition ssl_common.h:310
hash_algo_type verify_hash_algo
Definition ssl_common.h:368
bool auth_token_call_auth
always call normal authentication
Definition ssl_common.h:408
const char * crl_file
Definition ssl_common.h:360
int handshake_window
Definition ssl_common.h:342
bool dco_enabled
Whether keys have to be installed in DCO or not.
Definition ssl_common.h:459
const char * auth_user_pass_verify_script
Definition ssl_common.h:396
const char * remote_cert_eku
Definition ssl_common.h:364
bool auth_user_pass_username_only
Definition ssl_common.h:403
int replay_window
Definition ssl_common.h:374
Security parameter state of a single session within a VPN tunnel.
Definition ssl_common.h:497
enum tls_wrap_ctx::@317033145106102005365073042374303036003032271350 mode
Control channel wrapping mode.
struct crypto_options opt
Crypto state.
Definition ssl_common.h:283
struct buffer work
Work buffer (only for –tls-crypt).
Definition ssl_common.h:284
struct key_ctx tls_crypt_v2_server_key
Decrypts client keys.
Definition ssl_common.h:285
const struct buffer * tls_crypt_v2_wkc
Wrapped client key, sent to server.
Definition ssl_common.h:286
struct key2 original_wrap_keydata
original key data to be xored in to the key for dynamic tls-crypt.
Definition ssl_common.h:298
HANDLE msg_channel
Definition tun.h:86
Definition tun.h:181
in_addr_t local
Definition tun.h:208
DWORD adapter_index
Definition tun.h:232
enum tun_driver_type backend_driver
The backend driver that used for this tun/tap device.
Definition tun.h:191
struct tuntap_options options
Definition tun.h:203
struct in6_addr local_ipv6
Definition tun.h:211
dco_context_t dco
Definition tun.h:247
char * actual_name
Definition tun.h:205
in_addr_t remote_netmask
Definition tun.h:209
char password[USER_PASS_LEN]
Definition misc.h:71
char username[USER_PASS_LEN]
Definition misc.h:70
#define SIGHUP
Definition syshead.h:55
#define srandom
Definition syshead.h:44
#define SOCKET_UNDEFINED
Definition syshead.h:439
#define SIGTERM
Definition syshead.h:59
#define SIGUSR1
Definition syshead.h:57
uint32_t in_addr_t
Definition syshead.h:52
struct gc_arena gc
Definition test_ssl.c:138
struct tuntap * init_tun(const char *dev, const char *dev_type, int topology, const char *ifconfig_local_parm, const char *ifconfig_remote_netmask_parm, const char *ifconfig_ipv6_local_parm, int ifconfig_ipv6_netbits_parm, const char *ifconfig_ipv6_remote_parm, const struct addrinfo *local_public, const struct addrinfo *remote_public, const bool strict_warn, struct env_set *es, openvpn_net_ctx_t *ctx, struct tuntap *tt)
Definition tun.c:839
void open_tun(const char *dev, const char *dev_type, const char *dev_node, struct tuntap *tt, openvpn_net_ctx_t *ctx)
Definition tun.c:6101
int dev_type_enum(const char *dev, const char *dev_type)
Definition tun.c:527
void fork_register_dns_action(const struct tuntap *tt)
Definition tun.c:5493
bool is_dev_type(const char *dev, const char *dev_type, const char *match_type)
Definition tun.c:509
void do_ifconfig(struct tuntap *tt, const char *ifname, int tun_mtu, const struct env_set *es, openvpn_net_ctx_t *ctx)
do_ifconfig - configure the tunnel interface
Definition tun.c:1581
const char * dev_type_string(const char *dev, const char *dev_type)
Definition tun.c:546
void close_tun(struct tuntap *tt, openvpn_net_ctx_t *ctx)
Definition tun.c:6257
void show_adapters(msglvl_t msglevel)
Definition tun.c:4758
void warn_on_use_of_common_subnets(openvpn_net_ctx_t *ctx)
Definition tun.c:676
void undo_ifconfig(const struct tuntap *tt, openvpn_net_ctx_t *ctx)
undo_ifconfig - undo configuration of the tunnel interface
Definition tun.c:1675
void init_tun_post(struct tuntap *tt, const struct frame *frame, const struct tuntap_options *options)
Definition tun.c:963
const char * guess_tuntap_dev(const char *dev, const char *dev_type, const char *dev_node, struct gc_arena *gc)
Definition tun.c:566
void do_ifconfig_setenv(const struct tuntap *tt, struct env_set *es)
Definition tun.c:790
void tun_standby_init(struct tuntap *tt)
Definition tun.c:5411
const char * print_tun_backend_driver(enum tun_driver_type driver)
Return a string representation of the tun backed driver type.
Definition tun.c:59
#define IFCONFIG_AFTER_TUN_OPEN
Definition tun.h:349
#define IFCONFIG_BEFORE_TUN_OPEN
Definition tun.h:348
static int ifconfig_order(const struct tuntap *tt)
Definition tun.h:354
static int route_order(const struct tuntap *tt)
Definition tun.h:384
@ DRIVER_NULL
Definition tun.h:52
@ DRIVER_GENERIC_TUNTAP
Definition tun.h:47
@ DRIVER_AFUNIX
using an AF_UNIX socket to pass packets from/to an external program.
Definition tun.h:51
@ DRIVER_DCO
Definition tun.h:53
#define ROUTE_AFTER_TUN
Definition tun.h:380
static bool tuntap_is_dco_win(const struct tuntap *tt)
Definition tun.h:532
static void open_tun_null(struct tuntap *tt)
Definition tun.h:637
#define ROUTE_BEFORE_TUN
Definition tun.h:379
static bool is_tun_type_set(const struct tuntap *tt)
Definition tun.h:631
void open_tun_afunix(const struct options *o, int mtu, struct tuntap *tt, const struct env_set *orig_env)
Opens an AF_UNIX based tun device.
Definition tun_afunix.c:82
void close_tun_afunix(struct tuntap *tt)
Closes the socket used for the AF_UNIX based device.
Definition tun_afunix.c:134
static bool is_tun_afunix(const char *devnode)
Checks whether a –dev-node parameter specifies a AF_UNIX device.
Definition tun_afunix.h:61
void win32_signal_open(struct win32_signal *ws, int force, const char *exit_event_name, bool exit_event_initial_state)
Definition win32.c:554
bool win_wfp_block(const NET_IFINDEX index, const HANDLE msg_channel, BOOL dns_only)
Definition win32.c:1256
void window_title_generate(const char *title)
Definition win32.c:826
void window_title_save(struct window_title *wt)
Definition win32.c:800
bool win_wfp_uninit(const NET_IFINDEX index, const HANDLE msg_channel)
Definition win32.c:1305
void init_win32(void)
Definition win32.c:110
#define WSO_MODE_CONSOLE
Definition win32.h:160
#define WSO_FORCE_SERVICE
Definition win32.h:174
#define WSO_FORCE_CONSOLE
Definition win32.h:175