OpenVPN
options.c
Go to the documentation of this file.
1/*
2 * OpenVPN -- An application to securely tunnel IP networks
3 * over a single 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 * Copyright (C) 2008-2026 David Sommerseth <dazo@eurephia.org>
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2
13 * as published by the Free Software Foundation.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License along
21 * with this program; if not, see <https://www.gnu.org/licenses/>.
22 */
23
24/*
25 * 2004-01-28: Added Socks5 proxy support
26 * (Christof Meerwald, https://cmeerw.org)
27 */
28
29#ifdef HAVE_CONFIG_H
30#include "config.h"
31#endif
32#ifdef HAVE_CONFIG_VERSION_H
33#include "config-version.h"
34#endif
35
36#include "syshead.h"
37
38#include "acc.h"
39#include "buffer.h"
40#include "error.h"
41#include "common.h"
42#include "run_command.h"
43#include "shaper.h"
44#include "crypto.h"
45#include "ssl.h"
46#include "ssl_ncp.h"
47#include "options.h"
48#include "misc.h"
49#include "socket_util.h"
50#include "packet_id.h"
51#include "pkcs11.h"
52#include "win32.h"
53#include "push.h"
54#include "pool.h"
55#include "proto.h"
56#include "helper.h"
57#include "manage.h"
58#include "forward.h"
59#include "ssl_verify.h"
60#include "platform.h"
61#include "xkey_common.h"
62#include "dco.h"
63#include "options_util.h"
64#include "tun_afunix.h"
65#include "domain_helper.h"
66#include "mbuf.h"
67#include "check_file_access.h"
68#include "resolve.h"
69
70#include <ctype.h>
71
72#include "memdbg.h"
73#include "options_util.h"
74
76#ifdef CONFIGURE_GIT_REVISION
77 " [git:" CONFIGURE_GIT_REVISION CONFIGURE_GIT_FLAGS "]"
78#endif
79 " " TARGET_ALIAS
80#if defined(ENABLE_CRYPTO_MBEDTLS)
81 " [SSL (mbed TLS)]"
82#elif defined(ENABLE_CRYPTO_OPENSSL)
83 " [SSL (OpenSSL)]"
84#else
85 " [SSL]"
86#endif /* defined(ENABLE_CRYPTO_MBEDTLS) */
87#ifdef USE_COMP
88#ifdef ENABLE_LZO
89 " [LZO]"
90#endif
91#ifdef ENABLE_LZ4
92 " [LZ4]"
93#endif
94#ifdef ENABLE_COMP_STUB
95 " [COMP_STUB]"
96#endif
97#endif /* USE_COMP */
98#if EPOLL
99 " [EPOLL]"
100#endif
101#ifdef PRODUCT_TAP_DEBUG
102 " [TAPDBG]"
103#endif
104#ifdef ENABLE_PKCS11
105 " [PKCS11]"
106#endif
107#if ENABLE_IP_PKTINFO
108#if defined(HAVE_IN_PKTINFO) && defined(HAVE_IPI_SPEC_DST)
109 " [MH/PKTINFO]"
110#elif defined(IP_RECVDSTADDR)
111 " [MH/RECVDA]"
112#endif
113#endif
114 " [AEAD]"
115#ifdef ENABLE_DCO
116 " [DCO]"
117#endif
118#ifdef ENABLE_SMALL
119 " [SMALL]"
120#endif
121#ifdef ENABLE_DEBUG
122 " [DEBUG]"
123#endif
124#ifdef CONFIGURE_GIT_REVISION
125 " built on " __DATE__
126#endif
127
128 ;
129
130#ifndef ENABLE_SMALL
131
132static const char usage_message[] =
133 "%s\n"
134 "\n"
135 "General Options:\n"
136 "--config file : Read configuration options from file.\n"
137 "--help : Show options.\n"
138 "--version : Show copyright and version information.\n"
139 "\n"
140 "Tunnel Options:\n"
141 "--local host|* [port]: Local host name or IP address and port for bind.\n"
142 " If specified, OpenVPN will bindto this address. If unspecified,\n"
143 " OpenVPN will bind to all interfaces. '*' can be used as hostname\n"
144 " and means 'any host' (OpenVPN will listen on what is returned by the OS).\n"
145 " On a client, or in point-to-point mode, this can only be specified once (1 socket).\n"
146 " On an OpenVPN setup running as ``--server``, this can be specified multiple times\n"
147 " to open multiple listening sockets on different addresses and/or different ports.\n"
148 " In order to specify multiple listen ports without specifying an address, use '*'\n"
149 " to signal 'use what the operating system gives you as default', for\n"
150 " 'all IPv4 addresses' use '0.0.0.0', for 'all IPv6 addresses' use '::'.\n"
151 " ``--local`` implies ``--bind``.\n"
152 "--remote host [port] : Remote host name or ip address.\n"
153 "--remote-random : If multiple --remote options specified, choose one randomly.\n"
154 "--remote-random-hostname : Add a random string to remote DNS name.\n"
155 "--mode m : Major mode, m = 'p2p' (default, point-to-point) or 'server'.\n"
156 "--proto p : Use protocol p for communicating with peer.\n"
157 " p = udp (default), tcp-server, tcp-client\n"
158 " udp4, tcp4-server, tcp4-client\n"
159 " udp6, tcp6-server, tcp6-client\n"
160 "--proto-force p : only consider protocol p in list of connection profiles.\n"
161 " p = udp or tcp\n"
162 "--connect-retry n [m] : For client, number of seconds to wait between\n"
163 " connection retries (default=%d). On repeated retries\n"
164 " the wait time is exponentially increased to a maximum of m\n"
165 " (default=%d).\n"
166 "--connect-retry-max n : Maximum connection attempt retries, default infinite.\n"
167 "--http-proxy s p [up] [auth] : Connect to remote host\n"
168 " through an HTTP proxy at address s and port p.\n"
169 " If proxy authentication is required,\n"
170 " up is a file containing username/password on 2 lines, or\n"
171 " 'stdin' to prompt from console.\n"
172 "--http-proxy s p 'auto[-nct]' : Like the above directive, but automatically\n"
173 " determine auth method and query for username/password\n"
174 " if needed. auto-nct disables weak proxy auth methods.\n"
175 "--http-proxy-option type [parm] : Set extended HTTP proxy options.\n"
176 " Repeat to set multiple options.\n"
177 " VERSION version (default=1.0)\n"
178 " AGENT user-agent\n"
179 "--socks-proxy s [p] [up] : Connect to remote host through a Socks5 proxy at\n"
180 " address s and port p (default port = 1080).\n"
181 " If proxy authentication is required,\n"
182 " up is a file containing username/password on 2 lines, or\n"
183 " 'stdin' to prompt for console.\n"
184 "--socks-proxy-retry : Retry indefinitely on Socks proxy errors.\n"
185 "--resolv-retry n: If hostname resolve fails for --remote, retry\n"
186 " resolve for n seconds before failing (disabled by default).\n"
187 " Set n=\"infinite\" to retry indefinitely.\n"
188 "--preresolve : Resolve configured --remote, --local, and proxy hostnames at startup.\n"
189 "--float : Allow remote to change its IP address/port, such as through\n"
190 " DHCP (this is the default if --remote is not used).\n"
191 "--ipchange cmd : Run command cmd on remote ip address initial\n"
192 " setting or change -- execute as: cmd ip-address port#\n"
193 "--port port : TCP/UDP port # for both local and remote.\n"
194 "--lport port : TCP/UDP port # for local (default=%s). Implies --bind.\n"
195 "--rport port : TCP/UDP port # for remote (default=%s).\n"
196 "--bind : Bind to local address and port. (This is the default unless\n"
197 " --proto tcp-client"
198 " or --http-proxy"
199 " or --socks-proxy"
200 " is used).\n"
201 "--nobind : Do not bind to local address and port.\n"
202 "--dev tunX|tapX : tun/tap device (X can be omitted for dynamic device).\n"
203 " Defaults to \"tun\" if neither --dev nor --dev-type is given.\n"
204 "--dev-type dt : Which device type are we using? (dt = tun or tap) Use\n"
205 " this option only if the tun/tap device used with --dev\n"
206 " does not begin with \"tun\" or \"tap\".\n"
207 "--dev-node node : Explicitly set the device node rather than using\n"
208 " /dev/net/tun, /dev/tun, /dev/tap, etc.\n"
209#if defined(ENABLE_DCO)
210 "--disable-dco : Do not attempt using Data Channel Offload.\n"
211#endif
212 "--lladdr hw : Set the link layer address of the tap device.\n"
213 "--topology t : Set --dev tun topology: 'net30', 'p2p', or 'subnet'.\n"
214#ifdef ENABLE_IPROUTE
215 "--iproute cmd : Use this command instead of default " IPROUTE_PATH ".\n"
216#endif
217 "--ifconfig l rn : TUN: configure device to use IP address l as a local\n"
218 " endpoint and rn as a remote endpoint. l & rn should be\n"
219 " swapped on the other peer. l & rn must be private\n"
220 " addresses outside of the subnets used by either peer.\n"
221 " TAP: configure device to use IP address l as a local\n"
222 " endpoint and rn as a subnet mask.\n"
223 "--ifconfig-ipv6 l r : configure device to use IPv6 address l as local\n"
224 " endpoint (as a /64) and r as remote endpoint\n"
225 "--ifconfig-noexec : Don't actually execute ifconfig/netsh command, instead\n"
226 " pass --ifconfig parms by environment to scripts.\n"
227 "--ifconfig-nowarn : Don't warn if the --ifconfig option on this side of the\n"
228 " connection doesn't match the remote side.\n"
229#ifdef TARGET_LINUX
230 "--route-table table_id : Specify a custom routing table for use with --route(-ipv6).\n"
231 " If not specified, the id of the default routing table will be used.\n"
232#endif
233 "--route network [netmask] [gateway] [metric] :\n"
234 " Add route to routing table after connection\n"
235 " is established. Multiple routes can be specified.\n"
236 " netmask default: 255.255.255.255\n"
237 " gateway default: taken from --route-gateway or --ifconfig\n"
238 " Specify default by leaving blank or setting to \"default\".\n"
239 "--route-ipv6 network/bits [gateway] [metric] :\n"
240 " Add IPv6 route to routing table after connection\n"
241 " is established. Multiple routes can be specified.\n"
242 " gateway default: taken from --route-ipv6-gateway or 'remote'\n"
243 " in --ifconfig-ipv6\n"
244 "--route-gateway gw|'dhcp' : Specify a default gateway for use with --route.\n"
245 "--route-ipv6-gateway gw : Specify a default gateway for use with --route-ipv6.\n"
246 "--route-metric m : Specify a default metric for use with --route.\n"
247 "--route-delay n [w] : Delay n seconds after connection initiation before\n"
248 " adding routes (may be 0). If not specified, routes will\n"
249 " be added immediately after tun/tap open. On Windows, wait\n"
250 " up to w seconds for TUN/TAP adapter to come up.\n"
251 "--route-up cmd : Run command cmd after routes are added.\n"
252 "--route-pre-down cmd : Run command cmd before routes are removed.\n"
253 "--route-noexec : Don't add routes automatically. Instead pass routes to\n"
254 " --route-up script using environmental variables.\n"
255 "--route-nopull : When used with --client or --pull, accept options pushed\n"
256 " by server EXCEPT for routes, dns, and dhcp options.\n"
257 "--allow-pull-fqdn : Allow client to pull DNS names from server for\n"
258 " --ifconfig, --route, and --route-gateway.\n"
259 "--redirect-gateway [flags]: Automatically execute routing\n"
260 " commands to redirect all outgoing IP traffic through the\n"
261 " VPN. Add 'local' flag if both " PACKAGE_NAME " servers are directly\n"
262 " connected via a common subnet, such as with WiFi.\n"
263 " Add 'def1' flag to set default route using using 0.0.0.0/1\n"
264 " and 128.0.0.0/1 rather than 0.0.0.0/0. Add 'bypass-dhcp'\n"
265 " flag to add a direct route to DHCP server, bypassing tunnel.\n"
266 " Add 'bypass-dns' flag to similarly bypass tunnel for DNS.\n"
267 "--redirect-private [flags]: Like --redirect-gateway, but omit actually changing\n"
268 " the default gateway. Useful when pushing private subnets.\n"
269 "--block-ipv6 : (Client) Instead sending IPv6 to the server generate\n"
270 " ICMPv6 host unreachable messages on the client.\n"
271 " (Server) Instead of forwarding IPv6 packets send\n"
272 " ICMPv6 host unreachable packets to the client.\n"
273 "--client-nat snat|dnat network netmask alias : on client add 1-to-1 NAT rule.\n"
274 "--push-peer-info : (client only) push client info to server.\n"
275 "--setenv name value : Set a custom environmental variable to pass to script.\n"
276 "--setenv FORWARD_COMPATIBLE 1 : Relax config file syntax checking to allow\n"
277 " directives for future OpenVPN versions to be ignored.\n"
278 "--ignore-unknown-option opt1 opt2 ...: Relax config file syntax. Allow\n"
279 " these options to be ignored when unknown\n"
280 "--script-security level: Where level can be:\n"
281 " 0 -- strictly no calling of external programs\n"
282 " 1 -- (default) only call built-ins such as ifconfig\n"
283 " 2 -- allow calling of built-ins and scripts\n"
284 " 3 -- allow password to be passed to scripts via env\n"
285 "--shaper n : Restrict output to peer to n bytes per second.\n"
286 "--keepalive n m : Helper option for setting timeouts in server mode. Send\n"
287 " ping once every n seconds, restart if ping not received\n"
288 " for m seconds.\n"
289 "--inactive n [bytes] : Exit after n seconds of activity on tun/tap device\n"
290 " produces a combined in/out byte count < bytes.\n"
291 "--session-timeout n: Limit connection time to n seconds.\n"
292 "--ping-exit n : Exit if n seconds pass without reception of remote ping.\n"
293 "--ping-restart n: Restart if n seconds pass without reception of remote ping.\n"
294 "--ping-timer-rem: Run the --ping-exit/--ping-restart timer only if we have a\n"
295 " remote address.\n"
296 "--ping n : Ping remote once every n seconds over TCP/UDP port.\n"
297#if ENABLE_IP_PKTINFO
298 "--multihome : Configure a multi-homed UDP server.\n"
299#endif
300 "--remap-usr1 s : On SIGUSR1 signals, remap signal (s='SIGHUP' or 'SIGTERM').\n"
301 "--persist-tun : Keep tun/tap device open across SIGUSR1 or --ping-restart.\n"
302 "--persist-remote-ip : Keep remote IP address across SIGUSR1 or --ping-restart.\n"
303 "--persist-local-ip : Keep local IP address across SIGUSR1 or --ping-restart.\n"
304#if PASSTOS_CAPABILITY
305 "--passtos : TOS passthrough (applies to IPv4 only).\n"
306#endif
307 "--tun-mtu n : Take the tun/tap device MTU to be n and derive the\n"
308 " TCP/UDP MTU from it (default=%d).\n"
309 "--tun-mtu-extra n : Assume that tun/tap device might return as many\n"
310 " as n bytes more than the tun-mtu size on read\n"
311 " (default TUN=0 TAP=%d).\n"
312 "--tun-mtu-max n : Maximum pushable MTU (default and minimum=%d).\n"
313 "--link-mtu n : Take the TCP/UDP device MTU to be n and derive the tun MTU\n"
314 " from it.\n"
315 "--mtu-disc type : Should we do Path MTU discovery on TCP/UDP channel?\n"
316 " 'no' -- Never send DF (Don't Fragment) frames\n"
317 " 'maybe' -- Use per-route hints\n"
318 " 'yes' -- Always DF (Don't Fragment)\n"
319 "--mtu-test : Empirically measure and report MTU.\n"
320#ifdef ENABLE_FRAGMENT
321 "--fragment max : Enable internal datagram fragmentation so that no UDP\n"
322 " datagrams are sent which are larger than max bytes.\n"
323 " Adds 4 bytes of overhead per datagram.\n"
324#endif
325 "--mssfix [n] : Set upper bound on TCP MSS, default = tun-mtu size\n"
326 " or --fragment max value, whichever is lower.\n"
327 "--sndbuf size : Set the TCP/UDP send buffer size.\n"
328 "--rcvbuf size : Set the TCP/UDP receive buffer size.\n"
329#if defined(TARGET_LINUX)
330 "--mark value : Mark encrypted packets being sent with value. The mark value\n"
331 " can be matched in policy routing and packetfilter rules.\n"
332 "--bind-dev dev : Bind to the given device when making connection to a peer or\n"
333 " listening for connections. This allows sending encrypted packets\n"
334 " via a VRF present on the system.\n"
335#endif
336 "--txqueuelen n : Set the tun/tap TX queue length to n (Linux only).\n"
337 "--mlock : Disable Paging -- ensures key material and tunnel\n"
338 " data will never be written to disk.\n"
339 "--up cmd : Run command cmd after successful tun device open.\n"
340 " Execute as: cmd tun/tap-dev tun-mtu link-mtu \\\n"
341 " ifconfig-local-ip ifconfig-remote-ip\n"
342 " (pre --user or --group UID/GID change)\n"
343 "--up-delay : Delay tun/tap open and possible --up script execution\n"
344 " until after TCP/UDP connection establishment with peer.\n"
345 "--down cmd : Run command cmd after tun device close.\n"
346 " (post --user/--group UID/GID change and/or --chroot)\n"
347 " (command parameters are same as --up option)\n"
348 "--down-pre : Run --down command before TUN/TAP close.\n"
349 "--up-restart : Run up/down commands for all restarts including those\n"
350 " caused by --ping-restart or SIGUSR1\n"
351 "--user user : Set UID to user after initialization.\n"
352 "--group group : Set GID to group after initialization.\n"
353 "--chroot dir : Chroot to this directory after initialization.\n"
354#ifdef ENABLE_SELINUX
355 "--setcon context: Apply this SELinux context after initialization.\n"
356#endif
357 "--cd dir : Change to this directory before initialization.\n"
358 "--daemon [name] : Become a daemon after initialization.\n"
359 " The optional 'name' parameter will be passed\n"
360 " as the program name to the system logger.\n"
361 "--syslog [name] : Output to syslog, but do not become a daemon.\n"
362 " See --daemon above for a description of the 'name' parm.\n"
363 "--log file : Output log to file which is created/truncated on open.\n"
364 "--log-append file : Append log to file, or create file if nonexistent.\n"
365 "--suppress-timestamps : Don't log timestamps to stdout/stderr.\n"
366 "--machine-readable-output : Always log timestamp, message flags to stdout/stderr.\n"
367 "--writepid file : Write main process ID to file.\n"
368 "--nice n : Change process priority (>0 = lower, <0 = higher).\n"
369 "--echo [parms ...] : Echo parameters to log output.\n"
370 "--verb n : Set output verbosity to n (default=%d):\n"
371 " (Level 3 is recommended if you want a good summary\n"
372 " of what's happening without being swamped by output).\n"
373 " : 0 -- no output except fatal errors\n"
374 " : 1 -- startup info + connection initiated messages +\n"
375 " non-fatal encryption & net errors\n"
376 " : 2,3 -- show TLS negotiations & route info\n"
377 " : 4 -- show parameters\n"
378 " : 5 -- show 'RrWw' chars on console for each packet sent\n"
379 " and received from TCP/UDP (caps) or tun/tap (lc)\n"
380 " : 6 to 11 -- debug messages of increasing verbosity\n"
381 "--mute n : Log at most n consecutive messages in the same category.\n"
382 "--status file [n] : Write operational status to file every n seconds.\n"
383 "--status-version [n] : Choose the status file format version number.\n"
384 " Currently, n can be 1, 2, or 3 (default=1).\n"
385 "--disable-occ : (DEPRECATED) Disable options consistency check between peers.\n"
386#ifdef ENABLE_DEBUG
387 "--gremlin mask : Special stress testing mode (for debugging only).\n"
388#endif
389#if defined(USE_COMP)
390 "--compress alg : Use compression algorithm alg\n"
391 "--allow-compression: Specify whether compression should be allowed\n"
392#if defined(ENABLE_LZO)
393 "--comp-lzo : Use LZO compression -- may add up to 1 byte per\n"
394 " packet for incompressible data.\n"
395 "--comp-noadapt : Don't use adaptive compression when --comp-lzo\n"
396 " is specified.\n"
397#endif
398#endif
399#ifdef ENABLE_MANAGEMENT
400 "--management ip port [pass] : Enable a TCP server on ip:port to handle\n"
401 " management functions. pass is a password file\n"
402 " or 'stdin' to prompt from console.\n"
403#if UNIX_SOCK_SUPPORT
404 " To listen on a unix domain socket, specific the pathname\n"
405 " in place of ip and use 'unix' as the port number.\n"
406#endif
407 "--management-client : Management interface will connect as a TCP client to\n"
408 " ip/port rather than listen as a TCP server.\n"
409 "--management-query-passwords : Query management channel for private key\n"
410 " and auth-user-pass passwords.\n"
411 "--management-query-proxy : Query management channel for proxy information.\n"
412 "--management-query-remote : Query management channel for --remote directive.\n"
413 "--management-hold : Start " PACKAGE_NAME " in a hibernating state, until a client\n"
414 " of the management interface explicitly starts it.\n"
415 "--management-signal : Issue SIGUSR1 when management disconnect event occurs.\n"
416 "--management-forget-disconnect : Forget passwords when management disconnect\n"
417 " event occurs.\n"
418 "--management-up-down : Report tunnel up/down events to management interface.\n"
419 "--management-log-cache n : Cache n lines of log file history for usage\n"
420 " by the management channel.\n"
421#if UNIX_SOCK_SUPPORT
422 "--management-client-user u : When management interface is a unix socket, only\n"
423 " allow connections from user u.\n"
424 "--management-client-group g : When management interface is a unix socket, only\n"
425 " allow connections from group g.\n"
426#endif
427 "--management-client-auth : gives management interface client the responsibility\n"
428 " to authenticate clients after their client certificate\n"
429 " has been verified.\n"
430#endif /* ifdef ENABLE_MANAGEMENT */
431#ifdef ENABLE_PLUGIN
432 "--plugin m [str]: Load plug-in module m passing str as an argument\n"
433 " to its initialization function.\n"
434#endif
435 "--vlan-tagging : Enable 802.1Q-based VLAN tagging.\n"
436 "--vlan-accept tagged|untagged|all : Set VLAN tagging mode. Default is 'all'.\n"
437 "--vlan-pvid v : Sets the Port VLAN Identifier. Defaults to 1.\n"
438 "\n"
439 "Multi-Client Server options (when --mode server is used):\n"
440 "--server network netmask : Helper option to easily configure server mode.\n"
441 "--server-ipv6 network/bits : Configure IPv6 server mode.\n"
442 "--server-bridge [IP netmask pool-start-IP pool-end-IP] : Helper option to\n"
443 " easily configure ethernet bridging server mode.\n"
444 "--push \"option\" : Push a config file option back to the peer for remote\n"
445 " execution. Peer must specify --pull in its config file.\n"
446 "--push-reset : Don't inherit global push list for specific\n"
447 " client instance.\n"
448 "--push-remove opt : Remove options matching 'opt' from the push list for\n"
449 " a specific client instance.\n"
450 "--ifconfig-pool start-IP end-IP [netmask] : Set aside a pool of subnets\n"
451 " to be dynamically allocated to connecting clients.\n"
452 "--ifconfig-pool-persist file [seconds] : Persist/unpersist ifconfig-pool\n"
453 " data to file, at seconds intervals (default=600).\n"
454 " If seconds=0, file will be treated as read-only.\n"
455 "--ifconfig-ipv6-pool base-IP/bits : set aside an IPv6 network block\n"
456 " to be dynamically allocated to connecting clients.\n"
457 "--ifconfig-push local remote-netmask : Push an ifconfig option to remote,\n"
458 " overrides --ifconfig-pool dynamic allocation.\n"
459 " Only valid in a client-specific config file.\n"
460 "--ifconfig-ipv6-push local/bits remote : Push an ifconfig-ipv6 option to\n"
461 " remote, overrides --ifconfig-ipv6-pool allocation.\n"
462 " Only valid in a client-specific config file.\n"
463 "--iroute network [netmask] : Route subnet to client.\n"
464 "--iroute-ipv6 network/bits : Route IPv6 subnet to client.\n"
465 " Sets up internal routes only.\n"
466 " Only valid in a client-specific config file.\n"
467 "--disable : Client is disabled.\n"
468 " Only valid in a client-specific config file.\n"
469 "--override-username: Overrides the client-specific username to be used.\n"
470 " Only valid in a client-specific config file.\n"
471 "--verify-client-cert [none|optional|require] : perform no, optional or\n"
472 " mandatory client certificate verification.\n"
473 " Default is to require the client to supply a certificate.\n"
474 "--username-as-common-name : For auth-user-pass authentication, use\n"
475 " the authenticated username as the common name,\n"
476 " rather than the common name from the client cert.\n"
477 "--auth-user-pass-verify cmd method: Query client for username/password and\n"
478 " run command cmd to verify. If method='via-env', pass\n"
479 " user/pass via environment, if method='via-file', pass\n"
480 " user/pass via temporary file.\n"
481 "--auth-gen-token [lifetime] Generate a random authentication token which is pushed\n"
482 " to each client, replacing the password. Useful when\n"
483 " OTP based two-factor auth mechanisms are in use and\n"
484 " --reneg-* options are enabled. Optionally a lifetime in seconds\n"
485 " for generated tokens can be set.\n"
486 "--auth-user-pass-optional : Allow connections by clients that don't\n"
487 " specify a username/password.\n"
488 "--client-to-client : Internally route client-to-client traffic.\n"
489 "--duplicate-cn : Allow multiple clients with the same common name to\n"
490 " concurrently connect.\n"
491 "--client-connect cmd : Run command cmd on client connection.\n"
492 "--client-disconnect cmd : Run command cmd on client disconnection.\n"
493 "--client-config-dir dir : Directory for custom client config files.\n"
494 "--ccd-exclusive : Refuse connection unless custom client config is found.\n"
495 "--tmp-dir dir : Temporary directory, used for --client-connect return file and plugin communication.\n"
496 "--hash-size r v : Set the size of the real address hash table to r and the\n"
497 " virtual address table to v.\n"
498 "--bcast-buffers n : Allocate n broadcast buffers.\n"
499 "--tcp-queue-limit n : Maximum number of queued TCP output packets.\n"
500 "--tcp-nodelay : In server mode, push TCP_NODELAY to clients (it is\n"
501 " enabled by default on the local socket).\n"
502 "--learn-address cmd : Run command cmd to validate client virtual addresses.\n"
503 "--connect-freq n s : Allow a maximum of n new connections per s seconds.\n"
504 "--connect-freq-initial n s : Allow a maximum of n replies for initial connections attempts per s seconds.\n"
505 "--max-clients n : Allow a maximum of n simultaneously connected clients.\n"
506 "--max-routes-per-client n : Allow a maximum of n internal routes per client.\n"
507 "--stale-routes-check n [t] : Remove routes with a last activity timestamp\n"
508 " older than n seconds. Run this check every t\n"
509 " seconds (defaults to n).\n"
510 "--explicit-exit-notify [n] : In UDP server mode send [RESTART] command on exit/restart to connected\n"
511 " clients. n = 1 - reconnect to same server,\n"
512 " 2 - advance to next server, default=1.\n"
513#if PORT_SHARE
514 "--port-share host port [dir] : When run in TCP mode, proxy incoming HTTPS\n"
515 " sessions to a web server at host:port. dir specifies an\n"
516 " optional directory to write origin IP:port data.\n"
517#endif
518 "\n"
519 "Client options (when connecting to a multi-client server):\n"
520 "--client : Helper option to easily configure client mode.\n"
521 "--auth-user-pass [up] : Authenticate with server using username/password.\n"
522 " up is a file containing the username on the first line,\n"
523 " and a password on the second. If either the password or both\n"
524 " the username and the password are omitted OpenVPN will prompt\n"
525 " for them from console. If [up] is 'username-only', only username\n"
526 " will be prompted for from console or management interface.\n"
527 "--pull : Accept certain config file options from the peer as if they\n"
528 " were part of the local config file. Must be specified\n"
529 " when connecting to a '--mode server' remote host.\n"
530 "--pull-filter accept|ignore|reject t : Filter each option received from the\n"
531 " server if it starts with the text t. The action flag accept,\n"
532 " ignore or reject causes the option to be allowed, removed or\n"
533 " rejected with error. May be specified multiple times, and\n"
534 " each filter is applied in the order of appearance.\n"
535 "--dns server <n> <option> <value> [value ...] : Configure option for DNS server #n\n"
536 " Valid options are :\n"
537 " address <addr[:port]> [addr[:port] ...] : server addresses 4/6\n"
538 " resolve-domains <domain> [domain ...] : split domains\n"
539 " dnssec <yes|no|optional> : option to use DNSSEC\n"
540 " transport <DoH|DoT> : query server over HTTPS / TLS\n"
541 " sni <domain> : DNS server name indication\n"
542 "--dns search-domains <domain> [domain ...]:\n"
543 " Add domains to DNS domain search list\n"
544 "--dns-updown cmd|force|disable : Run cmd as user defined dns config command,\n"
545 " force running the default script or disable running it.\n"
546 "--auth-retry t : How to handle auth failures. Set t to\n"
547 " none (default), interact, or nointeract.\n"
548 "--static-challenge t e [<scrv1|concat>]: Enable static challenge/response protocol using\n"
549 " challenge text t, with e indicating echo flag (0|1)\n"
550 " and optional argument scrv1 or concat to use SCRV1 protocol or"
551 " concatenate response with password. Default is scrv1.\n"
552 "--connect-timeout n : when polling possible remote servers to connect to\n"
553 " in a round-robin fashion, spend no more than n seconds\n"
554 " waiting for a response before trying the next server.\n"
555 "--allow-recursive-routing : When this option is set, OpenVPN will not drop\n"
556 " incoming tun packets with same destination as host.\n"
557 "--explicit-exit-notify [n] : On exit/restart, send exit signal to\n"
558 " server/remote. n = # of retries, default=1.\n"
559 "\n"
560 "Data Channel Encryption Options (must be compatible between peers):\n"
561 "--auth alg : Authenticate packets with HMAC using message\n"
562 " digest algorithm alg (default=%s).\n"
563 " (usually adds 16 or 20 bytes per packet)\n"
564 " Set alg=none to disable authentication.\n"
565 "--cipher alg : Ignored. You should usually use --data-ciphers instead.\n"
566 "--data-ciphers list : List of ciphers that are allowed to be negotiated.\n"
567#ifndef ENABLE_CRYPTO_MBEDTLS
568 "--engine [name] : Enable OpenSSL hardware crypto engine functionality.\n"
569#endif
570 "--mute-replay-warnings : Silence the output of replay warnings to log file.\n"
571 "--replay-window n [t] : Use a replay protection sliding window of size n\n"
572 " and a time window of t seconds.\n"
573 " Default n=%d t=%d\n"
574 "--test-crypto : Run a self-test of crypto features enabled.\n"
575 " For debugging only.\n"
576 "\n"
577 "TLS Key Negotiation Options:\n"
578 "(These options are meaningful only for TLS-mode)\n"
579 "--tls-server : Enable TLS and assume server role during TLS handshake.\n"
580 "--tls-client : Enable TLS and assume client role during TLS handshake.\n"
581 "--ca file : Certificate authority file in .pem format containing\n"
582 " root certificate.\n"
583#ifndef ENABLE_CRYPTO_MBEDTLS
584 "--capath dir : A directory of trusted certificates (CAs"
585 " and CRLs).\n"
586#endif /* ENABLE_CRYPTO_MBEDTLS */
587 "--dh file : File containing Diffie Hellman parameters\n"
588 " in .pem format (for --tls-server only).\n"
589 " Use \"openssl dhparam -out dh1024.pem 1024\" to generate.\n"
590 "--cert file : Local certificate in .pem format or a URI -- must be signed\n"
591 " by a Certificate Authority in --ca file used by the peer.\n"
592 "--extra-certs file : one or more PEM certs that complete the cert chain.\n"
593 "--key file : Local private key in .pem format or a URI.\n"
594 "--tls-version-min <version> ['or-highest'] : sets the minimum TLS version we\n"
595 " will accept from the peer. If version is unrecognized and 'or-highest'\n"
596 " is specified, require max TLS version supported by SSL implementation.\n"
597 "--tls-version-max <version> : sets the maximum TLS version we will use.\n"
598#ifndef ENABLE_CRYPTO_MBEDTLS
599 "--pkcs12 file : PKCS#12 file containing local private key, local certificate\n"
600 " and optionally the root CA certificate.\n"
601 "--x509-username-field : Field in x509 certificate containing the username.\n"
602 " Default is CN in the Subject field.\n"
603#endif
604 "--verify-hash hash [algo] : Specify fingerprint for level-1 certificate.\n"
605 " Valid algo flags are SHA1 and SHA256. \n"
606#ifdef _WIN32
607 "--cryptoapicert select-string : Load the certificate and private key from the\n"
608 " Windows Certificate System Store.\n"
609#endif
610 "--tls-cipher l : A list l of allowable TLS ciphers separated by : (optional).\n"
611 "--tls-ciphersuites l: A list of allowed TLS 1.3 cipher suites separated by : (optional)\n"
612 " : Use --show-tls to see a list of supported TLS ciphers (suites).\n"
613 "--tls-cert-profile p : Set the allowed certificate crypto algorithm profile\n"
614 " (default=legacy).\n"
615#ifndef ENABLE_CRYPTO_MBEDTLS
616 "--providers l : A list l of OpenSSL providers to load.\n"
617#endif
618 "--tls-timeout n : Packet retransmit timeout on TLS control channel\n"
619 " if no ACK from remote within n seconds (default=%d).\n"
620 "--reneg-bytes n : Renegotiate data chan. key after n bytes sent and recvd.\n"
621 "--reneg-pkts n : Renegotiate data chan. key after n packets sent and recvd.\n"
622 "--reneg-sec max [min] : Renegotiate data chan. key after at most max (default=%d)\n"
623 " and at least min (defaults to 90%% of max on servers and equal\n"
624 " to max on clients).\n"
625 "--hand-window n : Data channel key exchange must finalize within n seconds\n"
626 " of handshake initiation by any peer (default=%d).\n"
627 "--tran-window n : Transition window -- old key can live this many seconds\n"
628 " after new key renegotiation begins (default=%d).\n"
629 "--single-session: Allow only one session (reset state on restart).\n"
630 "--tls-exit : Exit on TLS negotiation failure.\n"
631 "--tls-auth f [d]: Add an additional layer of authentication on top of the TLS\n"
632 " control channel to protect against attacks on the TLS stack\n"
633 " and DoS attacks.\n"
634 " f (required) is a shared-secret key file.\n"
635 " The optional d parameter controls key directionality.\n"
636 "--tls-crypt key : Add an additional layer of authenticated encryption on top\n"
637 " of the TLS control channel to hide the TLS certificate,\n"
638 " provide basic post-quantum security and protect against\n"
639 " attacks on the TLS stack and DoS attacks.\n"
640 " key (required) provides the pre-shared key file.\n"
641 "--tls-crypt-v2 key : For clients: use key as a client-specific tls-crypt key.\n"
642 " For servers: use key to decrypt client-specific keys. For\n"
643 " key generation (--genkey tls-crypt-v2-client): use key to\n"
644 " encrypt generated client-specific key. (See --tls-crypt.)\n"
645 "--genkey tls-crypt-v2-client [keyfile] [base64 metadata]: Generate a\n"
646 " fresh tls-crypt-v2 client key, and store to\n"
647 " keyfile. If supplied, include metadata in wrapped key.\n"
648 "--genkey tls-crypt-v2-server [keyfile] [base64 metadata]: Generate a\n"
649 " fresh tls-crypt-v2 server key, and store to keyfile\n"
650 "--tls-crypt-v2-verify cmd : Run command cmd to verify the metadata of the\n"
651 " client-supplied tls-crypt-v2 client key\n"
652 "--tls-crypt-v2-max-age n : Only accept tls-crypt-v2 client keys that have a\n"
653 " timestamp which is at most n days old.\n"
654 "--askpass [file]: Get PEM password from controlling tty before we daemonize.\n"
655 "--auth-nocache : Don't cache --askpass or --auth-user-pass passwords.\n"
656 "--crl-verify crl ['dir']: Check peer certificate against a CRL.\n"
657 "--tls-verify cmd: Run command cmd to verify the X509 name of a\n"
658 " pending TLS connection that has otherwise passed all other\n"
659 " tests of certification. cmd should return 0 to allow\n"
660 " TLS handshake to proceed, or 1 to fail. (cmd is\n"
661 " executed as 'cmd certificate_depth subject')\n"
662 "--verify-x509-name name: Accept connections only from a host with X509 subject\n"
663 " DN name. The remote host must also pass all other tests\n"
664 " of verification.\n"
665#ifndef ENABLE_CRYPTO_MBEDTLS
666 "--ns-cert-type t: (DEPRECATED) Require that peer certificate was signed with \n"
667 " an explicit nsCertType designation t = 'client' | 'server'.\n"
668#endif
669 "--x509-track x : Save peer X509 attribute x in environment for use by\n"
670 " plugins and management interface.\n"
671 "--keying-material-exporter label len : Save Exported Keying Material (RFC5705)\n"
672 " of len bytes (min. 16 bytes) using label in environment for use by plugins.\n"
673 "--remote-cert-ku v ... : Require that the peer certificate was signed with\n"
674 " explicit key usage, you can specify more than one value.\n"
675 " value should be given in hex format.\n"
676 "--remote-cert-eku oid : Require that the peer certificate was signed with\n"
677 " explicit extended key usage. Extended key usage can be encoded\n"
678 " as an object identifier or OpenSSL string representation.\n"
679 "--remote-cert-tls t: Require that peer certificate was signed with explicit\n"
680 " key usage and extended key usage based on RFC3280 TLS rules.\n"
681 " t = 'client' | 'server'.\n"
682#ifdef ENABLE_PKCS11
683 "\n"
684 "PKCS#11 Options:\n"
685 "--pkcs11-providers provider ... : PKCS#11 provider to load.\n"
686 "--pkcs11-protected-authentication [0|1] ... : Use PKCS#11 protected authentication\n"
687 " path. Set for each provider.\n"
688 "--pkcs11-private-mode hex ... : PKCS#11 private key mode mask.\n"
689 " 0 : Try to determine automatically (default).\n"
690 " 1 : Use Sign.\n"
691 " 2 : Use SignRecover.\n"
692 " 4 : Use Decrypt.\n"
693 " 8 : Use Unwrap.\n"
694 "--pkcs11-cert-private [0|1] ... : Set if login should be performed before\n"
695 " certificate can be accessed. Set for each provider.\n"
696 "--pkcs11-pin-cache seconds : Number of seconds to cache PIN. The default is -1\n"
697 " cache until token is removed.\n"
698 "--pkcs11-id-management : Acquire identity from management interface.\n"
699 "--pkcs11-id serialized-id 'id' : Identity to use, get using standalone --show-pkcs11-ids\n"
700#endif /* ENABLE_PKCS11 */
701 "\n"
702 "SSL Library information:\n"
703 "--show-ciphers : Show cipher algorithms to use with --cipher option.\n"
704 "--show-digests : Show message digest algorithms to use with --auth option.\n"
705 "--show-engines : Show hardware crypto accelerator engines (if available).\n"
706 "--show-tls : Show all TLS ciphers (TLS used only as a control channel).\n"
707#ifdef _WIN32
708 "\n"
709 "Windows Specific:\n"
710 "--win-sys path : Pathname of Windows system directory. Default is the pathname\n"
711 " from SystemRoot environment variable.\n"
712 "--ip-win32 method : When using --ifconfig on Windows, set TAP-Windows adapter\n"
713 " IP address using method = manual, netsh, ipapi,\n"
714 " dynamic, or adaptive (default = adaptive).\n"
715 " Dynamic method allows two optional parameters:\n"
716 " offset: DHCP server address offset (> -256 and < 256).\n"
717 " If 0, use network address, if >0, take nth\n"
718 " address forward from network address, if <0,\n"
719 " take nth address backward from broadcast\n"
720 " address.\n"
721 " Default is 0.\n"
722 " lease-time: Lease time in seconds.\n"
723 " Default is one year.\n"
724 "--route-method : Which method to use for adding routes on Windows?\n"
725 " adaptive (default) -- Try ipapi then fall back to exe.\n"
726 " ipapi -- Use IP helper API.\n"
727 " exe -- Call the route.exe shell command.\n"
728 "--dhcp-option type [parm] : Set extended TAP-Windows properties, must\n"
729 " be used with --ip-win32 dynamic. For options\n"
730 " which allow multiple addresses,\n"
731 " --dhcp-option must be repeated.\n"
732 " DOMAIN name : Set DNS suffix\n"
733 " DOMAIN-SEARCH entry : Add entry to DNS domain search list\n"
734 " DNS addr : Set domain name server address(es) (IPv4 and IPv6)\n"
735 " NTP : Set NTP server address(es)\n"
736 " NBDD : Set NBDD server address(es)\n"
737 " WINS addr : Set WINS server address(es)\n"
738 " NBT type : Set NetBIOS over TCP/IP Node type\n"
739 " 1: B, 2: P, 4: M, 8: H\n"
740 " NBS id : Set NetBIOS scope ID\n"
741 " DISABLE-NBT : Disable Netbios-over-TCP/IP.\n"
742 "--dhcp-renew : Ask Windows to renew the TAP adapter lease on startup.\n"
743 "--dhcp-pre-release : Ask Windows to release the previous TAP adapter lease on\n"
744 " startup.\n"
745 "--register-dns : Run ipconfig /flushdns and ipconfig /registerdns\n"
746 " on connection initiation.\n"
747 "--tap-sleep n : Sleep for n seconds after TAP adapter open before\n"
748 " attempting to set adapter properties.\n"
749 "--pause-exit : When run from a console window, pause before exiting.\n"
750 "--service ex [0|1] : For use when " PACKAGE_NAME " is being instantiated by a\n"
751 " service, and should not be used directly by end-users.\n"
752 " ex is the name of an event object which, when\n"
753 " signaled, will cause " PACKAGE_NAME " to exit. A second\n"
754 " optional parameter controls the initial state of ex.\n"
755 "--show-net-up : Show " PACKAGE_NAME "'s view of routing table and net adapter list\n"
756 " after TAP adapter is up and routes have been added.\n"
757 "--block-outside-dns : Block DNS on other network adapters to prevent DNS leaks\n"
758 "Windows Standalone Options:\n"
759 "\n"
760 "--show-adapters : Show all TAP-Windows adapters.\n"
761 "--show-net : Show " PACKAGE_NAME "'s view of routing table and net adapter list.\n"
762 "--show-valid-subnets : Show valid subnets for --dev tun emulation.\n"
763 "--allow-nonadmin [TAP-adapter] : Allow " PACKAGE_NAME " running without admin privileges\n"
764 " to access TAP adapter.\n"
765#endif /* ifdef _WIN32 */
766 "\n"
767 "Generate a new key :\n"
768 "--genkey tls-auth file : Generate a new random key of type and write to file\n"
769 " (for use with --tls-auth or --tls-crypt)."
770#ifdef ENABLE_FEATURE_TUN_PERSIST
771 "\n"
772 "Tun/tap config mode:\n"
773 "--mktun : Create a persistent tunnel.\n"
774 "--rmtun : Remove a persistent tunnel.\n"
775 "--dev tunX|tapX : tun/tap device\n"
776 "--dev-type dt : Device type. See tunnel options above for details.\n"
777 "--user user : User to set privilege to.\n"
778 "--group group : Group to set privilege to.\n"
779#endif
780#ifdef ENABLE_PKCS11
781 "\n"
782 "PKCS#11 standalone options:\n"
783#ifdef DEFAULT_PKCS11_MODULE
784 "--show-pkcs11-ids [provider] [cert_private] : Show PKCS#11 available ids.\n"
785#else
786 "--show-pkcs11-ids provider [cert_private] : Show PKCS#11 available ids.\n"
787#endif
788 " --verb option can be added *BEFORE* this.\n"
789#endif /* ENABLE_PKCS11 */
790 "\n"
791 "General Standalone Options:\n"
792#ifndef ENABLE_SMALL
793 "--show-gateway [address]: Show info about gateway [to v4/v6 address].\n"
794#endif
795 ;
796
797#endif /* !ENABLE_SMALL */
798
799/*
800 * This is where the options defaults go.
801 * Any option not explicitly set here
802 * will be set to 0.
803 */
804void
806{
807 CLEAR(*o);
808 gc_init(&o->gc);
810
812 o->dev = "tun";
813 o->topology = TOP_UNDEF;
814 o->ce.proto = PROTO_UDP;
815 o->ce.af = AF_UNSPEC;
816 o->ce.bind_ipv6_only = false;
819 o->ce.connect_timeout = 120;
820 o->connect_retry_max = 0;
822 o->verbosity = 1;
824 o->status_file_version = 1;
825 o->ce.bind_local = true;
827 o->ce.occ_mtu = 0;
830 o->ce.mtu_discover_type = -1;
831 o->ce.mssfix = 0;
832 o->ce.mssfix_default = true;
833 o->ce.mssfix_encap = true;
835 o->route_delay_window = 30;
837 o->resolve_in_advance = false;
838 o->proto_force = -1;
839 o->occ = true;
840#ifdef ENABLE_MANAGEMENT
844#endif
845#ifdef ENABLE_FEATURE_TUN_PERSIST
846 o->persist_mode = 1;
847#endif
848#ifdef _WIN32
849#if 0
851#else
853#endif
854 o->tuntap_options.dhcp_lease_time = 31536000; /* one year */
855 /* use network address as internal DHCP server address */
858 o->block_outside_dns = false;
860#endif
862 o->vlan_pvid = 1;
863 o->n_bcast_buf = 256;
864 o->tcp_queue_limit = 64;
865 o->max_clients = 1024;
866 o->cf_initial_per = 10;
867 o->cf_initial_max = 100;
868 o->max_routes_per_client = 256;
872 o->authname = "SHA1";
876 o->tls_timeout = 2;
877 o->renegotiate_bytes = -1;
878 o->renegotiate_seconds = 3600;
880 o->handshake_window = 60;
881 o->transition_window = 3600;
882 o->tls_cert_profile = NULL;
883 o->ecdh_curve = NULL;
885#ifdef ENABLE_PKCS11
886 o->pkcs11_pin_cache_period = -1;
887#endif /* ENABLE_PKCS11 */
888
889 /* P2MP server context features */
890 o->auth_token_generate = false;
891
892 /* Set default --tmp-dir */
894
895 o->allow_recursive_routing = false;
896
897#ifndef ENABLE_DCO
898 o->disable_dco = true;
899#endif /* ENABLE_DCO */
900
901#ifdef ENABLE_DNS_UPDOWN_BY_DEFAULT
902 o->dns_options.updown = DEFAULT_DNS_UPDOWN;
903#endif /* ENABLE_DNS_UPDOWN_BY_DEFAULT */
904}
905
906void
908{
909 if (o->connection_list)
910 {
912 }
913 if (o->remote_list)
914 {
915 CLEAR(*o->remote_list);
916 }
917
918 gc_free(&o->gc);
920}
921
922static void
923setenv_connection_entry(struct env_set *es, const struct connection_entry *e, const int i)
924{
925 setenv_str_i(es, "remote", e->remote, i);
926 setenv_str_i(es, "remote_port", e->remote_port, i);
927
928 if (e->http_proxy_options)
929 {
930 setenv_str_i(es, "http_proxy_server", e->http_proxy_options->server, i);
931 setenv_str_i(es, "http_proxy_port", e->http_proxy_options->port, i);
932 }
933 if (e->socks_proxy_server)
934 {
935 setenv_str_i(es, "socks_proxy_server", e->socks_proxy_server, i);
936 setenv_str_i(es, "socks_proxy_port", e->socks_proxy_port, i);
937 }
938}
939
940static void
941setenv_local_entry(struct env_set *es, const struct local_entry *e, const int i)
942{
943 setenv_str_i(es, "proto", proto2ascii(e->proto, AF_UNSPEC, false), i);
944 setenv_str_i(es, "local", e->local, i);
945 setenv_str_i(es, "local_port", e->port, i);
946}
947
948#if defined(__GNUC__) || defined(__clang__)
949#pragma GCC diagnostic push
950#pragma GCC diagnostic ignored "-Wsign-conversion"
951#endif
952
953void
954setenv_settings(struct env_set *es, const struct options *o)
955{
956 setenv_str(es, "config", o->config);
957 setenv_int(es, "verb", o->verbosity);
958 setenv_int(es, "daemon", o->daemon);
959 setenv_int(es, "daemon_log_redirect", o->log);
960 setenv_long_long(es, "daemon_start_time", time(NULL));
961 setenv_int(es, "daemon_pid", platform_getpid());
962
963 if (o->connection_list)
964 {
965 int i;
966 for (i = 0; i < o->connection_list->len; ++i)
967 {
969 }
970 }
971 else
972 {
973 setenv_connection_entry(es, &o->ce, 1);
974 }
975
976 if (o->ce.local_list)
977 {
978 for (int i = 0; i < o->ce.local_list->len; i++)
979 {
980 setenv_local_entry(es, o->ce.local_list->array[i], i + 1);
981 }
982 }
983}
984
985#ifndef _WIN32
986static void
987setenv_foreign_option(struct options *o, const char *option, const char *value, struct env_set *es)
988{
989 struct gc_arena gc = gc_new();
992 bool good = true;
993
994 good &= buf_printf(&env_name, "foreign_option_%d", o->foreign_option_index + 1);
995 if (value)
996 {
997 good &= buf_printf(&env_value, "dhcp-option %s %s", option, value);
998 }
999 else
1000 {
1001 good &= buf_printf(&env_value, "dhcp-option %s", option);
1002 }
1003 if (good)
1004 {
1006 ++o->foreign_option_index;
1007 }
1008 else
1009 {
1010 msg(M_WARN, "foreign_option: name/value overflow");
1011 }
1012 gc_free(&gc);
1013}
1014
1015#if !defined(TARGET_ANDROID)
1016static void
1017delete_all_dhcp_fo(struct options *o, struct env_item **list)
1018{
1019 struct env_item *current, *prev;
1020
1021 ASSERT(list);
1022
1023 for (current = *list, prev = NULL; current != NULL; current = current->next)
1024 {
1025 if (!strncmp(current->string, "foreign_option_", sizeof("foreign_option_") - 1))
1026 {
1027 const char *tmp_value = strchr(current->string, '=');
1028 if (tmp_value && ++tmp_value)
1029 {
1030 if (!strncmp(tmp_value, "dhcp-option ", sizeof("dhcp-option ") - 1))
1031 {
1032 if (prev)
1033 {
1034 prev->next = current->next;
1035 }
1036 else
1037 {
1038 *list = current->next;
1039 }
1041 }
1042 }
1043 }
1044 prev = current;
1045 }
1046}
1047#endif /* if !defined(TARGET_ANDROID) */
1048
1049#endif /* ifndef _WIN32 */
1050
1056static char *
1057get_ipv6_addr_no_netbits(const char *addr, struct gc_arena *gc)
1058{
1059 const char *end = strchr(addr, '/');
1060 char *ret = NULL;
1061 if (NULL == end)
1062 {
1063 ret = string_alloc(addr, gc);
1064 }
1065 else
1066 {
1067 size_t len = end - addr;
1068 ret = gc_malloc(len + 1, true, gc);
1069 memcpy(ret, addr, len);
1070 }
1071 return ret;
1072}
1082static struct verify_hash_list *
1083parse_hash_fingerprint(const char *str, int nbytes, msglvl_t msglevel, struct gc_arena *gc)
1084{
1085 int i = 0;
1086 const char *cp = str;
1087
1088 struct verify_hash_list *ret;
1090
1091 char term = 0;
1092 unsigned int byte;
1093
1094 while (*cp && i < nbytes)
1095 {
1096 /* valid segments consist of exactly two hex digits, then ':' or EOS */
1097 if (!isxdigit(cp[0]) || !isxdigit(cp[1]) || (cp[2] != ':' && cp[2] != '\0')
1098 || sscanf(cp, "%x", &byte) != 1)
1099 {
1100 msg(msglevel, "format error in hash fingerprint: %s", str);
1101 break;
1102 }
1103
1104 ret->hash[i++] = (uint8_t)byte;
1105
1106 term = cp[2];
1107 if (term == '\0')
1108 {
1109 break;
1110 }
1111 cp += 3;
1112 }
1113 if (i < nbytes)
1114 {
1115 msg(msglevel, "hash fingerprint is wrong length - expected %d bytes, got %d: %s", nbytes, i,
1116 str);
1117 }
1118 else if (term != '\0')
1119 {
1120 msg(msglevel, "hash fingerprint too long - expected only %d bytes: %s", nbytes, str);
1121 }
1122 return ret;
1123}
1124
1135static struct verify_hash_list *
1136parse_hash_fingerprint_multiline(const char *str, int nbytes, msglvl_t msglevel,
1137 struct gc_arena *gc)
1138{
1139 struct gc_arena gc_temp = gc_new();
1140 char *lines = string_alloc(str, &gc_temp);
1141
1142 struct verify_hash_list *ret = NULL;
1143
1144 const char *line;
1145 while ((line = strsep(&lines, "\n")))
1146 {
1147 /* ignore leading whitespace */
1148 while (isspace(*line))
1149 {
1150 line++;
1151 }
1152 /* skip empty lines and comment lines */
1153 if (strlen(line) == 0 || *line == '#' || *line == ';')
1154 {
1155 continue;
1156 }
1157
1158 struct verify_hash_list *hash = parse_hash_fingerprint(line, nbytes, msglevel, gc);
1159
1160 if (!hash)
1161 {
1162 gc_free(&gc_temp);
1163 return NULL;
1164 }
1165
1166 hash->next = ret;
1167 ret = hash;
1168 }
1169 gc_free(&gc_temp);
1170
1171 return ret;
1172}
1173
1174static void
1175dhcp_option_dns6_parse(const char *parm, struct in6_addr *dns6_list, unsigned int *len, msglvl_t msglevel)
1176{
1177 struct in6_addr addr;
1178 if (*len >= N_DHCP_ADDR)
1179 {
1180 msg(msglevel, "--dhcp-option DNS: maximum of %u IPv6 dns servers can be specified",
1181 N_DHCP_ADDR);
1182 }
1183 else if (get_ipv6_addr(parm, &addr, NULL, msglevel))
1184 {
1185 dns6_list[(*len)++] = addr;
1186 }
1187}
1188static void
1189dhcp_option_address_parse(const char *name, const char *parm, in_addr_t *array, unsigned int *len,
1190 msglvl_t msglevel)
1191{
1192 if (*len >= N_DHCP_ADDR)
1193 {
1194 msg(msglevel, "--dhcp-option %s: maximum of %u %s servers can be specified", name,
1195 N_DHCP_ADDR, name);
1196 }
1197 else
1198 {
1199 if (ip_addr_dotted_quad_safe(parm)) /* FQDN -- IP address only */
1200 {
1201 bool error = false;
1202 const in_addr_t addr = get_ip_addr(parm, msglevel, &error);
1203 if (!error)
1204 {
1205 array[(*len)++] = addr;
1206 }
1207 }
1208 else
1209 {
1210 msg(msglevel, "dhcp-option parameter %s '%s' must be an IP address", name, parm);
1211 }
1212 }
1213}
1214
1215static void
1216option_iroute(struct options *o, const char *network_str, const char *netmask_str,
1217 msglvl_t msglevel)
1218{
1219 struct iroute *ir;
1220
1221 ALLOC_OBJ_GC(ir, struct iroute, &o->gc);
1222 ir->network = getaddr(GETADDR_HOST_ORDER, network_str, 0, NULL, NULL);
1223 ir->netbits = 32; /* host route if no netmask given */
1224
1225 if (netmask_str)
1226 {
1227 const in_addr_t netmask = getaddr(GETADDR_HOST_ORDER, netmask_str, 0, NULL, NULL);
1228 ir->netbits = netmask_to_netbits2(netmask);
1229
1230 if (ir->netbits < 0)
1231 {
1232 msg(msglevel, "in --iroute %s %s : Bad network/subnet specification", network_str,
1233 netmask_str);
1234 return;
1235 }
1236 }
1237
1238 ir->next = o->iroutes;
1239 o->iroutes = ir;
1240}
1241
1242static void
1243option_iroute_ipv6(struct options *o, const char *prefix_str, msglvl_t msglevel)
1244{
1245 struct iroute_ipv6 *ir;
1246
1247 ALLOC_OBJ_GC(ir, struct iroute_ipv6, &o->gc);
1248
1249 if (!get_ipv6_addr(prefix_str, &ir->network, &ir->netbits, msglevel))
1250 {
1251 msg(msglevel, "in --iroute-ipv6 %s: Bad IPv6 prefix specification", prefix_str);
1252 return;
1253 }
1254
1255 ir->next = o->iroutes_ipv6;
1256 o->iroutes_ipv6 = ir;
1257}
1258
1259void
1261{
1262 /* The options struct carries two gc_arena's (one generic and one specific
1263 * to the DNS settings), which the by-value options
1264 * copy in inherit_context_child()/inherit_context_top() shares with the
1265 * source.
1266 *
1267 * Detach both (i.e. re-initialize them), otherwise child's call of
1268 * gc_free() (or context teardown) would free allocations the source
1269 * context still references, leading to a use-after-free (and subsequent
1270 * double-free).
1271 */
1272 gc_detach(&o->gc);
1274 o->routes = NULL;
1275 o->client_nat = NULL;
1276 clone_push_list(o);
1277}
1278
1279void
1281{
1282 if (!options->routes)
1283 {
1285 }
1286}
1287
1288static void
1296
1297static void
1299{
1300 if (!options->client_nat)
1301 {
1303 }
1304}
1305
1306#ifdef ENABLE_MANAGEMENT
1307
1308static struct http_proxy_options *
1309parse_http_proxy_override(const char *server, const char *port, const char *flags,
1310 struct gc_arena *gc)
1311{
1312 if (server && port)
1313 {
1314 struct http_proxy_options *ho;
1316 ho->server = string_alloc(server, gc);
1317 ho->port = port;
1318 if (flags && !strcmp(flags, "nct"))
1319 {
1320 ho->auth_retry = PAR_NCT;
1321 }
1322 else
1323 {
1324 ho->auth_retry = PAR_ALL;
1325 }
1326 ho->http_version = "1.0";
1327 ho->user_agent = "OpenVPN-Autoproxy/1.0";
1328 return ho;
1329 }
1330 else
1331 {
1332 return NULL;
1333 }
1334}
1335
1336static void
1338{
1339 const struct connection_list *l = o->connection_list;
1340 int i;
1341 bool succeed = false;
1342 for (i = 0; i < l->len; ++i)
1343 {
1344 struct connection_entry *ce = l->array[i];
1345 if (ce->proto == PROTO_TCP_CLIENT || ce->proto == PROTO_TCP)
1346 {
1348 succeed = true;
1349 }
1350 }
1351 if (succeed)
1352 {
1353 for (i = 0; i < l->len; ++i)
1354 {
1355 struct connection_entry *ce = l->array[i];
1356 if (ce->proto == PROTO_UDP)
1357 {
1358 ce->flags |= CE_DISABLED;
1359 }
1360 }
1361 }
1362 else
1363 {
1364 msg(M_WARN,
1365 "Note: option http-proxy-override ignored because no TCP-based connection profiles are defined");
1366 }
1367}
1368
1369#endif /* ifdef ENABLE_MANAGEMENT */
1370
1371static struct local_list *
1373{
1374 if (!ce->local_list)
1375 {
1377 }
1378 return ce->local_list;
1379}
1380
1381static struct local_entry *
1382alloc_local_entry(struct connection_entry *ce, const msglvl_t msglevel, struct gc_arena *gc)
1383{
1385 struct local_entry *e;
1386
1387 if (l->len >= l->capacity)
1388 {
1389 const int new_cap = l->capacity + 1;
1390 const size_t elem_size = sizeof(*l->array);
1391
1392 struct local_entry **new_array = gc_realloc(l->array, new_cap * elem_size, gc);
1393 if (!new_array)
1394 {
1395 msg(msglevel,
1396 "Unable to process more local options: out of memory. Number of entries = %d",
1397 l->len);
1398 return NULL;
1399 }
1400
1401 l->array = new_array;
1402 l->capacity = new_cap;
1403 }
1404
1405 ALLOC_OBJ_CLEAR_GC(e, struct local_entry, gc);
1406 e->proto = PROTO_NONE;
1407 l->array[l->len++] = e;
1408
1409 return e;
1410}
1411
1412static struct connection_list *
1421
1422static struct connection_entry *
1424{
1426 struct connection_entry *e;
1427
1428 if (l->len == l->capacity)
1429 {
1430 int capacity = l->capacity + CONNECTION_LIST_SIZE;
1431 struct connection_entry **ce =
1432 gc_realloc(l->array, capacity * sizeof(struct connection_entry *), &options->gc);
1433 if (ce == NULL)
1434 {
1435 msg(msglevel,
1436 "Unable to process more connection options: out of memory. Number of entries = %d",
1437 l->len);
1438 return NULL;
1439 }
1440 l->array = ce;
1441 l->capacity = capacity;
1442 }
1444 l->array[l->len++] = e;
1445 return e;
1446}
1447
1448static struct remote_list *
1450{
1451 if (!options->remote_list)
1452 {
1454 }
1455 return options->remote_list;
1456}
1457
1458static struct remote_entry *
1460{
1462 struct remote_entry *e;
1463
1464 if (l->len == l->capacity)
1465 {
1466 int capacity = l->capacity + CONNECTION_LIST_SIZE;
1467 struct remote_entry **re =
1468 gc_realloc(l->array, capacity * sizeof(struct remote_entry *), &options->gc);
1469 if (re == NULL)
1470 {
1471 msg(msglevel,
1472 "Unable to process more remote options: out of memory. Number of entries = %d",
1473 l->len);
1474 return NULL;
1475 }
1476 l->array = re;
1477 l->capacity = capacity;
1478 }
1479 ALLOC_OBJ_GC(e, struct remote_entry, &options->gc);
1480 l->array[l->len++] = e;
1481 return e;
1482}
1483
1484static struct pull_filter_list *
1486{
1487 if (!o->pull_filter_list)
1488 {
1490 }
1491 return o->pull_filter_list;
1492}
1493
1494static struct pull_filter *
1496{
1498 struct pull_filter *f;
1499
1500 ALLOC_OBJ_CLEAR_GC(f, struct pull_filter, &o->gc);
1501 if (l->head)
1502 {
1503 ASSERT(l->tail);
1504 l->tail->next = f;
1505 }
1506 else
1507 {
1508 ASSERT(!l->tail);
1509 l->head = f;
1510 }
1511 l->tail = f;
1512 return f;
1513}
1514
1515static void
1517{
1518 if (re->remote)
1519 {
1520 ce->remote = re->remote;
1521 }
1522 if (re->remote_port)
1523 {
1524 ce->remote_port = re->remote_port;
1525 }
1526 if (re->proto >= 0)
1527 {
1528 ce->proto = re->proto;
1529 }
1530 if (re->af > 0)
1531 {
1532 ce->af = re->af;
1533 }
1534}
1535
1536static void
1537connection_entry_preload_key(const char **key_file, bool *key_inline, struct gc_arena *gc)
1538{
1539 if (key_file && *key_file && !(*key_inline))
1540 {
1541 struct buffer in = buffer_read_from_file(*key_file, gc);
1542 if (!buf_valid(&in))
1543 {
1544 msg(M_FATAL, "Cannot pre-load keyfile (%s)", *key_file);
1545 }
1546
1547 *key_file = (const char *)in.data;
1548 *key_inline = true;
1549 }
1550}
1551
1552static void
1554{
1555#ifdef ENABLE_CRYPTO_MBEDTLS
1556 if (options->ca_path)
1557 {
1558 msg(M_USAGE, "Parameter --capath cannot be used with the mbed TLS version of OpenVPN.");
1559 }
1560#endif
1561
1564 || options->ca_path
1565#endif
1566 )
1567 {
1568 return;
1569 }
1570
1571 const char *const str = "You must define CA file (--ca)"
1572#ifndef ENABLE_CRYPTO_MBEDTLS
1573 " or CA path (--capath)"
1574#endif
1575 " and/or peer fingerprint verification (--peer-fingerprint)";
1576 msg(M_USAGE, "%s", str);
1577}
1578
1579#define MUST_BE_UNDEF(parm, parm_name) \
1580 if (options->parm != defaults.parm) \
1581 { \
1582 msg(M_USAGE, use_err, parm_name); \
1583 }
1584#define MUST_BE_FALSE(condition, parm_name) \
1585 if (condition) \
1586 { \
1587 msg(M_USAGE, use_err, parm_name); \
1588 }
1589
1590static void
1592{
1593 if (options->test_crypto)
1594 {
1595 return;
1596 }
1597 struct options defaults;
1598 int dev = DEV_TYPE_UNDEF;
1599 bool pull = false;
1600
1601 init_options(&defaults);
1602
1603 notnull(options->dev, "TUN/TAP device (--dev)");
1604
1605 /*
1606 * Get tun/tap/null device type
1607 */
1609
1610 /*
1611 * If "proto tcp" is specified, make sure we know whether it is
1612 * tcp-client or tcp-server.
1613 */
1614 if (ce->proto == PROTO_TCP)
1615 {
1616 msg(M_USAGE, "--proto tcp is ambiguous in this context. Please specify "
1617 "--proto tcp-server or --proto tcp-client");
1618 }
1619
1620 /*
1621 * Sanity check on Client mode
1622 */
1623
1624 if (options->mode != MODE_SERVER && ce->local_list->len > 1)
1625 {
1626 msg(M_USAGE, "multiple --local statements only allowed in --server mode");
1627 }
1628
1629 if (options->lladdr && dev != DEV_TYPE_TAP)
1630 {
1631 msg(M_USAGE, "--lladdr can only be used in --dev tap mode");
1632 }
1633
1634 /*
1635 * Sanity check on MTU parameters
1636 */
1638 {
1639 msg(M_USAGE, "only one of --tun-mtu or --link-mtu may be defined");
1640 }
1641
1643 {
1644 msg(M_USAGE, "--mtu-test only makes sense with --proto udp");
1645 }
1646
1647 /* will we be pulling options from server? */
1648 pull = options->pull;
1649
1650 /*
1651 * Sanity check on --local, --remote, and --ifconfig
1652 */
1653
1656 {
1657 msg(M_USAGE, "--local and --remote addresses must be distinct from --ifconfig "
1658 "addresses");
1659 }
1660
1662 {
1663 msg(M_USAGE, "local and remote/netmask --ifconfig addresses must be different");
1664 }
1665
1666 if (ce->bind_defined && !ce->bind_local)
1667 {
1668 msg(M_USAGE, "--bind and --nobind can't be used together");
1669 }
1670
1672 {
1673 msg(M_USAGE, "--lport and --nobind don't make sense when used together");
1674 }
1675
1676 if (!ce->remote && !ce->bind_local)
1677 {
1678 msg(M_USAGE, "--nobind doesn't make sense unless used with --remote");
1679 }
1680
1681 for (int i = 0; i < ce->local_list->len; i++)
1682 {
1683 const struct local_entry *le = ce->local_list->array[i];
1684
1685 if (proto_is_net(le->proto) && string_defined_equal(le->local, ce->remote)
1687 {
1688 msg(M_USAGE, "--remote and one of the --local addresses are the same");
1689 }
1690
1693 {
1694 msg(M_USAGE, "--local addresses must be distinct from --ifconfig addresses");
1695 }
1696
1697 if (le->local && !ce->bind_local)
1698 {
1699 msg(M_USAGE, "--local and --nobind don't make sense when used together");
1700 }
1701 }
1702
1703 /*
1704 * Check for consistency of management options
1705 */
1706#ifdef ENABLE_MANAGEMENT
1710 {
1711 msg(M_USAGE,
1712 "--management is not specified, however one or more options which modify the behavior of --management were specified");
1713 }
1714
1717 {
1718 msg(M_USAGE, "--management-client-(user|group) can only be used on unix domain sockets");
1719 }
1720
1723 {
1724 msg(M_WARN, "WARNING: Using --management on a TCP port WITHOUT "
1725 "passwords is STRONGLY discouraged and considered insecure");
1726 }
1727
1728#endif /* ifdef ENABLE_MANAGEMENT */
1729
1730#if !defined(HAVE_XKEY_PROVIDER)
1733 {
1734 msg(M_FATAL, "management-external-key with TLS 1.3 or later requires "
1735 "nopadding argument/support");
1736 }
1737#endif
1738 /*
1739 * Windows-specific options.
1740 */
1741
1742#ifdef _WIN32
1743 if (dev == DEV_TYPE_TUN
1745 {
1746 msg(M_USAGE, "On Windows, --ifconfig is required when --dev tun is used");
1747 }
1748
1751 {
1752 msg(M_USAGE, "On Windows, --ip-win32 doesn't make sense unless --ifconfig is also used");
1753 }
1754
1756 {
1757 const char *prefix = "Some --dhcp-option or --dns options require DHCP server";
1759 {
1760 msg(M_USAGE, "%s, which is not supported by the selected %s driver", prefix,
1762 }
1765 {
1766 msg(M_USAGE, "%s, which requires --ip-win32 dynamic or adaptive", prefix);
1767 }
1768 }
1769#endif /* ifdef _WIN32 */
1770
1771 /*
1772 * Check that protocol options make sense.
1773 */
1774
1775#ifdef ENABLE_FRAGMENT
1776 if (!proto_is_udp(ce->proto) && ce->fragment)
1777 {
1778 msg(M_USAGE, "--fragment can only be used with --proto udp");
1779 }
1780#endif
1781
1782 if (!ce->remote && ce->proto == PROTO_TCP_CLIENT)
1783 {
1784 msg(M_USAGE, "--remote MUST be used in TCP Client mode");
1785 }
1786
1787 if ((ce->http_proxy_options) && ce->proto != PROTO_TCP_CLIENT)
1788 {
1789 msg(M_USAGE, "--http-proxy MUST be used in TCP Client mode (i.e. --proto "
1790 "tcp-client)");
1791 }
1792
1793 if ((ce->http_proxy_options) && !ce->http_proxy_options->server)
1794 {
1795 msg(M_USAGE, "--http-proxy not specified but other http proxy options present");
1796 }
1797
1799 {
1800 msg(M_USAGE, "--http-proxy can not be used together with --socks-proxy");
1801 }
1802
1803 if (ce->socks_proxy_server && ce->proto == PROTO_TCP_SERVER)
1804 {
1805 msg(M_USAGE, "--socks-proxy can not be used in TCP Server mode");
1806 }
1807
1808 if (ce->proto == PROTO_TCP_SERVER && (options->connection_list->len > 1))
1809 {
1810 msg(M_USAGE, "TCP server mode allows at most one --remote address");
1811 }
1812
1813 /*
1814 * Check consistency of --mode server options.
1815 */
1816 if (options->mode == MODE_SERVER)
1817 {
1818 const char use_err[] = "--%s cannot be used with --mode server.";
1819
1820#define USAGE_VALID_SERVER_PROTOS \
1821 "--mode server currently only supports " \
1822 "--proto values of udp, tcp-server, tcp4-server, or tcp6-server"
1823#ifdef TARGET_ANDROID
1824 msg(M_FATAL, "--mode server not supported on Android");
1825#endif
1826 if (!(dev == DEV_TYPE_TUN || dev == DEV_TYPE_TAP))
1827 {
1828 msg(M_USAGE, "--mode server only works with --dev tun or --dev tap");
1829 }
1830 MUST_BE_UNDEF(pull, "pull");
1832 {
1833 msg(M_WARN, "--pull-filter ignored for --mode server");
1834 }
1835 if (!(proto_is_udp(ce->proto) || ce->proto == PROTO_TCP_SERVER))
1836 {
1838 }
1839#if PORT_SHARE
1840 bool has_tcp = false;
1841 for (int i = 0; i < ce->local_list->len && !has_tcp; i++)
1842 {
1843 has_tcp = (ce->local_list->array[i]->proto == PROTO_TCP_SERVER);
1844 }
1845 if ((options->port_share_host || options->port_share_port)
1846 && !has_tcp)
1847 {
1848 msg(M_USAGE, "--port-share only works in TCP server mode "
1849 "(--proto values of tcp-server, tcp4-server, or tcp6-server)");
1850 }
1851#endif
1852 if (!options->tls_server)
1853 {
1854 msg(M_USAGE, "--mode server requires --tls-server");
1855 }
1856 MUST_BE_FALSE(ce->remote, "remote");
1857 MUST_BE_FALSE(!ce->bind_local, "nobind");
1858 MUST_BE_FALSE(ce->http_proxy_options, "http-proxy");
1859 MUST_BE_FALSE(ce->socks_proxy_server, "socks-proxy");
1860 /* <connection> blocks force to have a remote embedded, so we check
1861 * for the --remote and bail out if it is present
1862 */
1864 {
1865 msg(M_USAGE, "<connection> cannot be used with --mode server");
1866 }
1867
1868 MUST_BE_UNDEF(shaper, "shaper");
1869 if (options->ipchange)
1870 {
1871 msg(M_USAGE, "--ipchange cannot be used with --mode server (use "
1872 "--client-connect instead)");
1873 }
1874 if (!(proto_is_dgram(ce->proto) || ce->proto == PROTO_TCP_SERVER))
1875 {
1877 }
1878 if (!proto_is_udp(ce->proto) && (options->cf_max || options->cf_per))
1879 {
1880 msg(M_USAGE,
1881 "--connect-freq only works with --mode server --proto udp. Try --max-clients instead.");
1882 }
1883 if (!(dev == DEV_TYPE_TAP || (dev == DEV_TYPE_TUN && options->topology == TOP_SUBNET))
1885 {
1886 msg(M_USAGE,
1887 "The third parameter to --ifconfig-pool (netmask) is only valid in --dev tap mode");
1888 }
1890 {
1891 msg(M_USAGE,
1892 "--redirect-gateway cannot be used with --mode server (however --push \"redirect-gateway\" is fine)");
1893 }
1894 MUST_BE_UNDEF(route_delay_defined, "route-delay");
1895 MUST_BE_UNDEF(up_delay, "up-delay");
1898 {
1899 msg(M_USAGE,
1900 "--ifconfig-pool-persist must be used with --ifconfig-pool or --ifconfig-ipv6-pool");
1901 }
1903 {
1904 msg(M_USAGE, "--ifconfig-ipv6-pool needs --ifconfig-ipv6");
1905 }
1906 MUST_BE_UNDEF(allow_recursive_routing, "allow-recursive-routing");
1908 {
1909 msg(M_USAGE,
1910 "--auth-user-pass cannot be used with --mode server (it should be used on the client side only)");
1911 }
1913 {
1914 msg(M_USAGE, "--ccd-exclusive must be used with --client-config-dir");
1915 }
1917 {
1918 msg(M_USAGE, "--auth-gen-token needs a non-infinite "
1919 "--renegotiate_seconds setting");
1920 }
1923 {
1924 msg(M_USAGE,
1925 "--auth-gen-token renewal time needs to be at least "
1926 " two times --hand-window (%d).",
1928 }
1931 {
1932 const char *use_err =
1933 "--%s must be used with --management-client-auth, an --auth-user-pass-verify script, or plugin";
1934
1937 "verify-client-cert none|optional");
1939 "username-as-common-name");
1941 "auth-user-pass-optional");
1942 }
1943
1944 if (options->vlan_tagging && dev != DEV_TYPE_TAP)
1945 {
1946 msg(M_USAGE, "--vlan-tagging must be used with --dev tap");
1947 }
1948 if (!options->vlan_tagging)
1949 {
1950 const char use_err[] = "--%s requires --vlan-tagging";
1951 MUST_BE_UNDEF(vlan_accept, "vlan-accept");
1952 MUST_BE_UNDEF(vlan_pvid, "vlan-pvid");
1953 }
1954
1956 {
1957 msg(M_INFO, "NOTE: TCP_NODELAY is always enabled locally; "
1958 "--tcp-nodelay is now only useful to push the flag to "
1959 "clients older than 2.7.6.");
1960 }
1961 }
1962 else
1963 {
1964 const char use_err[] = "--%s requires --mode server";
1965 /*
1966 * When not in server mode, err if parameters are
1967 * specified which require --mode server.
1968 */
1969 MUST_BE_UNDEF(ifconfig_pool_defined, "ifconfig-pool");
1970 MUST_BE_UNDEF(ifconfig_pool_persist_filename, "ifconfig-pool-persist");
1971 MUST_BE_UNDEF(ifconfig_ipv6_pool_defined, "ifconfig-ipv6-pool");
1972 MUST_BE_UNDEF(real_hash_size, "hash-size");
1973 MUST_BE_UNDEF(virtual_hash_size, "hash-size");
1974 MUST_BE_UNDEF(learn_address_script, "learn-address");
1975 MUST_BE_UNDEF(client_connect_script, "client-connect");
1976 MUST_BE_UNDEF(client_crresponse_script, "client-crresponse");
1977 MUST_BE_UNDEF(client_disconnect_script, "client-disconnect");
1978 MUST_BE_UNDEF(client_config_dir, "client-config-dir");
1979 MUST_BE_UNDEF(ccd_exclusive, "ccd-exclusive");
1980 MUST_BE_UNDEF(enable_c2c, "client-to-client");
1981 MUST_BE_UNDEF(duplicate_cn, "duplicate-cn");
1982 MUST_BE_UNDEF(cf_max, "connect-freq");
1983 MUST_BE_UNDEF(cf_per, "connect-freq");
1986 "verify-client-cert");
1987 MUST_BE_FALSE(options->ssl_flags & SSLF_USERNAME_AS_COMMON_NAME, "username-as-common-name");
1988 MUST_BE_FALSE(options->ssl_flags & SSLF_AUTH_USER_PASS_OPTIONAL, "auth-user-pass-optional");
1990 {
1991 msg(M_WARN, "DEPRECATED OPTION: --tcp-nodelay is always enabled on clients");
1992 }
1993 MUST_BE_UNDEF(auth_user_pass_verify_script, "auth-user-pass-verify");
1994 MUST_BE_UNDEF(auth_token_generate, "auth-gen-token");
1995#if PORT_SHARE
1996 if (options->port_share_host || options->port_share_port)
1997 {
1998 msg(M_USAGE,
1999 "--port-share requires TCP server mode (--mode server --proto tcp-server)");
2000 }
2001#endif
2002 MUST_BE_UNDEF(stale_routes_check_interval, "stale-routes-check");
2003 MUST_BE_UNDEF(vlan_tagging, "vlan-tagging");
2004 MUST_BE_UNDEF(vlan_accept, "vlan-accept");
2005 MUST_BE_UNDEF(vlan_pvid, "vlan-pvid");
2006 MUST_BE_UNDEF(force_key_material_export, "force-key-material-export");
2007
2008 if (options->push_list.head)
2009 {
2010 msg(M_WARN, "Note: Using --push without --mode server is an "
2011 "unsupported configuration. Negotiation of OpenVPN "
2012 "features is expected to fail.");
2013 }
2014 }
2015
2016 /*
2017 * SSL/TLS mode sanity checks.
2018 */
2020 {
2021 msg(M_USAGE, "OpenVPN configuration must use either --tls-server or --tls-client");
2022 }
2023
2025 {
2026 msg(M_WARN, "WARNING: POTENTIALLY DANGEROUS OPTION "
2027 "--verify-client-cert none|optional "
2028 "may accept clients which do not present a certificate");
2029 }
2030
2031 const unsigned int tls_ver_max =
2033 const unsigned int tls_ver_min =
2035
2036 if (tls_ver_max > 0 && tls_ver_max < tls_ver_min)
2037 {
2038 msg(M_USAGE, "--tls-version-min bigger than --tls-version-max");
2039 }
2040
2042#ifdef ENABLE_PKCS11
2043 if (!options->pkcs11_providers[0] && options->pkcs11_id)
2044 {
2045 msg(M_WARN, "Option pkcs11-id is ignored as no pkcs11-providers are specified");
2046 }
2047 else if (!options->pkcs11_providers[0] && options->pkcs11_id_management)
2048 {
2049 msg(M_WARN,
2050 "Option pkcs11-id-management is ignored as no pkcs11-providers are specified");
2051 }
2052
2053 if (options->pkcs11_providers[0])
2054 {
2055 if (options->pkcs11_id_management && options->pkcs11_id != NULL)
2056 {
2057 msg(M_USAGE,
2058 "Parameter --pkcs11-id cannot be used when --pkcs11-id-management is also specified.");
2059 }
2060 if (!options->pkcs11_id_management && options->pkcs11_id == NULL)
2061 {
2062 msg(M_USAGE,
2063 "Parameter --pkcs11-id or --pkcs11-id-management should be specified.");
2064 }
2065 const char use_err[] =
2066 "Parameter --%s cannot be used when --pkcs11-provider is also specified.";
2067 MUST_BE_UNDEF(cert_file, "cert");
2068 MUST_BE_UNDEF(priv_key_file, "key");
2069 MUST_BE_UNDEF(pkcs12_file, "pkcs12");
2070 MUST_BE_FALSE(options->management_flags & MF_EXTERNAL_KEY, "management-external-key");
2071 MUST_BE_FALSE(options->management_flags & MF_EXTERNAL_CERT, "management-external-cert");
2072#ifdef ENABLE_CRYPTOAPI
2073 MUST_BE_UNDEF(cryptoapi_cert, "cryptoapicert");
2074#endif
2075 }
2076 else
2077#endif /* ifdef ENABLE_PKCS11 */
2078#ifdef ENABLE_CRYPTOAPI
2080 {
2081 const char use_err[] =
2082 "Parameter --%s cannot be used when --cryptoapicert is also specified.";
2083 MUST_BE_UNDEF(cert_file, "cert");
2084 MUST_BE_UNDEF(priv_key_file, "key");
2085 MUST_BE_UNDEF(pkcs12_file, "pkcs12");
2086 MUST_BE_FALSE(options->management_flags & MF_EXTERNAL_KEY, "management-external-key");
2087 MUST_BE_FALSE(options->management_flags & MF_EXTERNAL_CERT, "management-external-cert");
2088 }
2089 else
2090#endif
2091 if (options->pkcs12_file)
2092 {
2093#ifdef ENABLE_CRYPTO_MBEDTLS
2094 msg(M_USAGE, "Parameter --pkcs12 cannot be used with the mbed TLS version of OpenVPN.");
2095#else
2096 const char use_err[] = "Parameter --%s cannot be used when --pkcs12 is also specified.";
2097 MUST_BE_UNDEF(ca_path, "capath");
2098 MUST_BE_UNDEF(cert_file, "cert");
2099 MUST_BE_UNDEF(priv_key_file, "key");
2100 MUST_BE_FALSE(options->management_flags & MF_EXTERNAL_KEY, "management-external-key");
2101 MUST_BE_FALSE(options->management_flags & MF_EXTERNAL_CERT, "management-external-cert");
2102#endif /* ifdef ENABLE_CRYPTO_MBEDTLS */
2103 }
2104 else /* cert/key from none of pkcs11, pkcs12, cryptoapi */
2105 {
2107 {
2108 msg(M_USAGE, "--key and --management-external-key are mutually exclusive");
2109 }
2111 {
2112 if (options->cert_file)
2113 {
2114 msg(M_USAGE, "--cert and --management-external-cert are mutually exclusive");
2115 }
2117 {
2118 msg(M_USAGE,
2119 "--management-external-cert must be used with --management-external-key");
2120 }
2121 }
2122 if (pull)
2123 {
2124 const int sum =
2126 + ((options->priv_key_file != NULL)
2128
2129 if (sum == 0)
2130 {
2132 {
2133 msg(M_USAGE, "No client-side authentication method is "
2134 "specified. You must use either "
2135 "--cert/--key, --pkcs12, or "
2136 "--auth-user-pass");
2137 }
2138 }
2139 else if (sum != 2)
2140 {
2141 msg(M_USAGE, "If you use one of --cert or --key, you must use them both");
2142 }
2143 }
2144 else
2145 {
2147 {
2149 "certificate file (--cert) or PKCS#12 file (--pkcs12)");
2150 }
2152 {
2154 "private key file (--key) or PKCS#12 file (--pkcs12)");
2155 }
2156 }
2157 }
2158 if (ce->tls_auth_file && ce->tls_crypt_file)
2159 {
2160 msg(M_USAGE, "--tls-auth and --tls-crypt are mutually exclusive");
2161 }
2163 && (ce->tls_auth_file || ce->tls_crypt_file))
2164 {
2165 msg(M_USAGE,
2166 "--tls-crypt-v2, --tls-auth and --tls-crypt are mutually exclusive in client mode");
2167 }
2168
2169
2171 {
2172 msg(M_USAGE, "--auth-user-pass requires --pull");
2173 }
2174
2175 uninit_options(&defaults);
2176}
2177
2178#undef MUST_BE_UNDEF
2179#undef MUST_BE_FALSE
2180
2181static void
2183{
2184 const int dev = dev_type_enum(o->dev, o->dev_type);
2185
2187 {
2188 if (ce->proto == PROTO_TCP)
2189 {
2190 ce->proto = PROTO_TCP_SERVER;
2191 o->ce.proto = ce->proto;
2192 }
2193 }
2194
2195 if (o->mode != MODE_SERVER)
2196 {
2197 if (ce->proto == PROTO_TCP)
2198 {
2199 ce->proto = PROTO_TCP_CLIENT;
2200 o->ce.proto = ce->proto;
2201 }
2202 }
2203
2204 /* an option is present that requires local bind to enabled */
2205 bool need_bind = ce->local_port_defined || ce->bind_defined || ce->local_list;
2206
2207 /* socks proxy is enabled */
2208 bool uses_socks = ce->proto == PROTO_UDP && ce->socks_proxy_server;
2209
2210 /* If binding is not forced by an explicit option and we have (at least)
2211 * one of --tcp-client, --pull (or --client), or socks we do not bind
2212 * locally to have "normal" IP client behaviour of a random source port */
2213 if (!need_bind && (ce->proto == PROTO_TCP_CLIENT || uses_socks || o->pull))
2214 {
2215 ce->bind_local = false;
2216 }
2217
2218 if (!ce->bind_local)
2219 {
2220 ce->local_port = NULL;
2221 }
2222
2223 /* if protocol forcing is enabled, disable all protocols
2224 * except for the forced one
2225 */
2226 if (o->proto_force >= 0 && o->proto_force != ce->proto)
2227 {
2228 ce->flags |= CE_DISABLED;
2229 }
2230
2231 if (ce->http_proxy_options)
2232 {
2234 }
2235
2236 /* our socks code is not fully IPv6 enabled yet (TCP works, UDP not)
2237 * so fall back to IPv4-only (trac #1221)
2238 */
2239 if (ce->socks_proxy_server && proto_is_udp(ce->proto) && ce->af != AF_INET)
2240 {
2241 if (ce->af == AF_INET6)
2242 {
2243 msg(M_INFO, "WARNING: '--proto udp6' is not compatible with "
2244 "'--socks-proxy' today. Forcing IPv4 mode.");
2245 }
2246 else
2247 {
2248 msg(M_INFO, "NOTICE: dual-stack mode for '--proto udp' does not "
2249 "work correctly with '--socks-proxy' today. Forcing IPv4.");
2250 }
2251 ce->af = AF_INET;
2252 }
2253
2254 /*
2255 * Set MTU defaults
2256 */
2257 {
2258 if (!ce->tun_mtu_defined && !ce->link_mtu_defined)
2259 {
2260 ce->tun_mtu_defined = true;
2261 }
2262 if ((dev == DEV_TYPE_TAP) && !ce->tun_mtu_extra_defined)
2263 {
2264 ce->tun_mtu_extra_defined = true;
2266 }
2267 }
2268
2269 /*
2270 * If --mssfix is supplied without a parameter or not specified at all,
2271 * default it to --fragment value, if --fragment is specified and otherwise
2272 * to the default if tun-mtu is 1500
2273 */
2274 if (o->ce.mssfix_default)
2275 {
2276#ifdef ENABLE_FRAGMENT
2277 if (ce->fragment)
2278 {
2279 ce->mssfix = ce->fragment;
2280 }
2281 else
2282#endif
2283 if (ce->tun_mtu_defined)
2284 {
2285 if (o->ce.tun_mtu == TUN_MTU_DEFAULT)
2286 {
2287 /* We want to only set mssfix default value if we use a default
2288 * MTU Size, otherwise the different size of tun should either
2289 * already solve the problem or mssfix might artifically make the
2290 * payload packets smaller without mssfix 0 */
2291 ce->mssfix = MSSFIX_DEFAULT;
2292 ce->mssfix_encap = true;
2293 }
2294 else
2295 {
2296 /* We still apply the mssfix value but only adjust it to the
2297 * size of the tun interface. */
2298 ce->mssfix = ce->tun_mtu;
2299 ce->mssfix_fixed = true;
2300 }
2301 }
2302 }
2303
2304 /*
2305 * Set per-connection block tls-auth/crypt/crypto-v2 fields if undefined.
2306 *
2307 * At the end only one of these will be really set because the parser
2308 * logic prevents configurations where more are set.
2309 */
2310 if (!ce->tls_auth_file && !ce->tls_crypt_file && !ce->tls_crypt_v2_file)
2311 {
2315
2318
2321 }
2322
2323 /* Pre-cache tls-auth/crypt(-v2) key file if
2324 * keys were not already embedded in the config file.
2325 */
2329
2330
2332 {
2333 msg(M_WARN, "NOTICE: --explicit-exit-notify ignored for --proto tcp");
2335 }
2336}
2337
2338static void
2339options_postprocess_mutate_le(const struct connection_entry *ce, struct local_entry *le, int mode)
2340{
2341 /* use the global port if none is specified */
2342 if (!le->port)
2343 {
2344 le->port = ce->local_port;
2345 }
2346 /* use the global proto if none is specified and
2347 * allow proto bindings on server mode only */
2348 if (!le->proto || mode == MODE_POINT_TO_POINT)
2349 {
2350 le->proto = ce->proto;
2351 }
2352}
2353
2354#ifdef _WIN32
2355/* If iservice is in use, we need def1 method for redirect-gateway */
2356static void
2358{
2359 if (opt->routes && opt->route_method == ROUTE_METHOD_SERVICE
2360 && opt->routes->flags & RG_REROUTE_GW && !(opt->routes->flags & RG_DEF1))
2361 {
2362 msg(M_INFO, "Flag 'def1' added to --redirect-gateway (iservice is in use)");
2363 opt->routes->flags |= RG_DEF1;
2364 }
2365}
2366#endif /* ifdef _WIN32 */
2367
2368/*
2369 * Save/Restore certain option defaults before --pull is applied.
2370 */
2371
2372static void
2374{
2379
2380 if (o->routes)
2381 {
2383 o->pre_connect->routes_defined = true;
2384 }
2385 if (o->routes_ipv6)
2386 {
2389 }
2390 if (o->client_nat)
2391 {
2394 }
2395
2398
2401
2403
2404 /* NCP related options that can be overwritten by a push */
2406 o->pre_connect->authname = o->authname;
2407
2408 /* Ping related options should be reset to the config values on reconnect */
2412
2413 /* Miscellaneous Options */
2414 o->pre_connect->comp = o->comp;
2415}
2416
2417void
2419{
2420 const struct options_pre_connect *pp = o->pre_connect;
2421 if (pp)
2422 {
2424 if (pp->tuntap_options_defined)
2425 {
2427 }
2428
2429 if (pp->routes_defined)
2430 {
2431 rol_check_alloc(o);
2433 }
2434 else
2435 {
2436 o->routes = NULL;
2437 }
2438
2439 if (pp->routes_ipv6_defined)
2440 {
2443 }
2444 else
2445 {
2446 o->routes_ipv6 = NULL;
2447 }
2448
2451
2454
2455 /* Free DNS options and reset them to pre-pull state */
2456 gc_free(&o->dns_options.gc);
2457 struct gc_arena dns_gc = gc_new();
2458 o->dns_options = clone_dns_options(&pp->dns_options, &dns_gc);
2459 o->dns_options.gc = dns_gc;
2460
2461 if (pp->client_nat_defined)
2462 {
2465 }
2466 else
2467 {
2468 o->client_nat = NULL;
2469 }
2470
2472
2473 o->ciphername = pp->ciphername;
2474 o->authname = pp->authname;
2475
2479
2480 /* Miscellaneous Options */
2481 o->comp = pp->comp;
2482 }
2483
2484 o->push_continuation = 0;
2490}
2491
2492static void
2494{
2495#ifdef _WIN32
2496 const int dev = dev_type_enum(options->dev, options->dev_type);
2497
2498 /* when using ovpn-dco, kernel doesn't send DHCP requests, so don't use it */
2502 {
2504 }
2505
2506 if ((dev == DEV_TYPE_TUN || dev == DEV_TYPE_TAP) && !options->route_delay_defined)
2507 {
2508 /* delay may only be necessary when we perform DHCP handshake */
2511 if ((options->mode == MODE_POINT_TO_POINT) && dhcp)
2512 {
2514 options->route_delay = 5; /* Vista sometimes has a race without this */
2515 }
2516 }
2517
2519 {
2521 options->ifconfig_noexec = false;
2522 }
2523
2525
2526 /*
2527 * Check consistency of --mode server options.
2528 */
2529 if (options->mode == MODE_SERVER)
2530 {
2531 /*
2532 * We need to explicitly set --tap-sleep because
2533 * we do not schedule event timers in the top-level context.
2534 */
2537 {
2539 }
2541 }
2542#endif /* ifdef _WIN32 */
2543
2544#ifdef DEFAULT_PKCS11_MODULE
2545 /* If p11-kit is present on the system then load its p11-kit-proxy.so
2546 * by default if the user asks for PKCS#11 without otherwise specifying
2547 * the module to use. */
2548 if (!options->pkcs11_providers[0] && (options->pkcs11_id || options->pkcs11_id_management))
2549 {
2550 options->pkcs11_providers[0] = DEFAULT_PKCS11_MODULE;
2551 }
2552#endif
2553}
2554
2555static void
2557{
2558 if (o->connection_list)
2559 {
2560 int i;
2561 for (i = 0; i < o->connection_list->len; ++i)
2562 {
2564 }
2565 }
2566 else
2567 {
2569 }
2570
2572
2573 if (dco_enabled(o))
2574 {
2575 if (o->enable_c2c)
2576 {
2577 msg(M_WARN, "Note: --client-to-client has no effect when using data "
2578 "channel offload: packets are always sent to the VPN "
2579 "interface and then routed based on the system routing table");
2580 }
2581
2582 if (o->renegotiate_bytes > 0 || o->renegotiate_packets)
2583 {
2584 msg(M_WARN, "Note: '--reneg-bytes' and '--reneg-pkts' are not supported "
2585 "by data channel offload; automatic key renegotiation "
2586 "mechanisms are sufficient for modern ciphers. "
2587 "Ignoring these options.");
2588 }
2589 }
2590}
2591
2592static void
2594{
2595 if (!o->pull && !(o->mode == MODE_SERVER))
2596 {
2597 /* If the cipher is not set, use the old default of BF-CBC. We will
2598 * warn that this is deprecated on cipher initialisation, no need
2599 * to warn here as well */
2600 if (!o->ciphername)
2601 {
2602 o->ciphername = "BF-CBC";
2603 }
2604 else
2605 {
2606 o->enable_ncp_fallback = true;
2607 }
2608 return;
2609 }
2610
2611 /* pull or P2MP mode */
2612 if (!o->ciphername)
2613 {
2614 /* We still need to set the ciphername to BF-CBC since various other
2615 * parts of OpenVPN assert that the ciphername is set */
2616 o->ciphername = "BF-CBC";
2617
2618 msg(M_INFO,
2619 "Note: --cipher is not set. OpenVPN versions before 2.5 "
2620 "defaulted to BF-CBC as fallback when cipher negotiation "
2621 "failed in this case. If you need this fallback please add "
2622 "'--data-ciphers-fallback BF-CBC' to your configuration "
2623 "and/or add BF-CBC to --data-ciphers. E.g. "
2624 "--data-ciphers %s:BF-CBC",
2625 o->ncp_ciphers_conf);
2626 }
2628 {
2629 msg(M_WARN,
2630 "DEPRECATED OPTION: --cipher set to '%s' but missing in "
2631 "--data-ciphers (%s). OpenVPN ignores --cipher for cipher "
2632 "negotiations. ",
2634 }
2635}
2636
2652static bool
2653need_compatibility_before(const struct options *o, unsigned int version)
2654{
2655 return o->backwards_compatible != 0 && o->backwards_compatible < version;
2656}
2657
2662static void
2664{
2665 /* TLS min version is not set */
2666 unsigned int tls_ver_min = (o->ssl_flags >> SSLF_TLS_VERSION_MIN_SHIFT) & SSLF_TLS_VERSION_MIN_MASK;
2667 if (tls_ver_min == 0)
2668 {
2669 unsigned int tls_ver_max = (o->ssl_flags >> SSLF_TLS_VERSION_MAX_SHIFT) & SSLF_TLS_VERSION_MAX_MASK;
2670 if (need_compatibility_before(o, 20307))
2671 {
2672 /* 2.3.6 and earlier have TLS 1.0 only, set minimum to TLS 1.0 */
2674 }
2675 else if (tls_ver_max == 0 || tls_ver_max >= TLS_VER_1_2)
2676 {
2677 /* Use TLS 1.2 as proper default */
2679 }
2680 else
2681 {
2682 /* Maximize the minimum version */
2683 o->ssl_flags |= (tls_ver_max << SSLF_TLS_VERSION_MIN_SHIFT);
2684 }
2685 }
2686
2687 if (need_compatibility_before(o, 20400))
2688 {
2689 if (!o->ciphername)
2690 {
2691 /* If ciphername is not set default to BF-CBC when targeting these
2692 * old versions that do not have NCP */
2693 o->ciphername = "BF-CBC";
2694 }
2695 /* Versions < 2.4.0 additionally might be compiled with --enable-small and
2696 * not have OCC strings required for "poor man's NCP" */
2697 o->enable_ncp_fallback = true;
2698 }
2699
2700 /* Versions < 2.5.0 do need --cipher in the list of accepted ciphers.
2701 * Version 2.4 probably does not need it but NCP was not so
2702 * good with 2.4 and ncp-disable might be more common on 2.4 peers.
2703 * Only do this iff --cipher is set (explicitly or by compat mode
2704 * < 2.4.0, see above). This is not 100% correct backwards compatible
2705 * behaviour but 2.5 already behaved like this */
2706 if (o->ciphername && need_compatibility_before(o, 20500)
2708 {
2710 }
2711
2712#ifdef USE_COMP
2713 /* Compression is deprecated and we do not want to announce support for it
2714 * by default anymore, additionally DCO breaks with compression.
2715 *
2716 * Disable compression by default starting with 2.6.0 if no other
2717 * compression related option has been explicitly set */
2718 if (!need_compatibility_before(o, 20600) && (o->comp.flags == 0))
2719 {
2720 if (!comp_non_stub_enabled(&o->comp))
2721 {
2723 }
2724 }
2725#else /* ifdef USE_COMP */
2727#endif
2728}
2729
2730static void
2732{
2733 if (!check_tls_prf_working())
2734 {
2735 msg(D_TLS_ERRORS, "Warning: TLS 1.0 PRF with MD5+SHA1 PRF is not "
2736 "supported by the TLS library. Your system does not support this "
2737 "calculation anymore or your security policy (e.g. FIPS 140-2) "
2738 "forbids it. Connections will only work with peers running "
2739 "OpenVPN 2.6.0 or higher)");
2740 if (o->mode == MODE_SERVER)
2741 {
2742 msg(M_WARN, "Automatically enabling option "
2743 "--force-tls-key-material-export");
2744 o->force_key_material_export = true;
2745 }
2746 }
2747}
2748
2749#if defined(_WIN32) || defined(TARGET_ANDROID)
2758static void
2760{
2761 struct dns_options *dns = &o->dns_options;
2762 struct tuntap_options *tt = &o->tuntap_options;
2763 if (!dns->servers)
2764 {
2765 /* Copy --dhcp-options to tuntap_options */
2766 struct dhcp_options *dhcp = &dns->from_dhcp;
2767 ASSERT(sizeof(dhcp->dns) == sizeof(tt->dns));
2768 ASSERT(sizeof(dhcp->dns6) == sizeof(tt->dns6));
2769 ASSERT(sizeof(dhcp->domain_search_list) == sizeof(tt->domain_search_list));
2770
2771 tt->domain = dhcp->domain;
2772 tt->dns_len = dhcp->dns_len;
2773 tt->dns6_len = dhcp->dns6_len;
2774
2775 memcpy(tt->dns, dhcp->dns, sizeof(tt->dns));
2776 memcpy(tt->dns6, dhcp->dns6, sizeof(tt->dns6));
2777
2778 tt->domain_search_list_len = dhcp->domain_search_list_len;
2779 for (size_t i = 0; i < SIZE(tt->domain_search_list); ++i)
2780 {
2781 tt->domain_search_list[i] = dhcp->domain_search_list[i];
2782 }
2783
2784 return;
2785 }
2786
2787#if defined(_WIN32)
2789 {
2790 return; /* Not in DHCP mode */
2791 }
2792#endif /* if defined(_WIN32) */
2793
2794 /* Copy --dns options to tuntap_options */
2795
2796 const struct dns_domain *d = dns->search_domains;
2797 if (d)
2798 {
2799 tt->domain_search_list_len = 0;
2800 }
2801
2802 while (d && tt->domain_search_list_len + 1 < N_SEARCH_LIST_LEN)
2803 {
2805 d = d->next;
2806 }
2807 if (d)
2808 {
2809 msg(M_WARN, "WARNING: couldn't copy all --dns search-domains to TUN/TAP");
2810 }
2811
2812 tt->dns_len = 0;
2813 tt->dns6_len = 0;
2814
2815 const struct dns_server *s = dns->servers;
2816 while (s)
2817 {
2818 bool non_standard_server_port = false;
2819 for (size_t i = 0; i < s->addr_count; ++i)
2820 {
2821 if (s->addr[i].port && s->addr[i].port != 53)
2822 {
2823 non_standard_server_port = true;
2824 break;
2825 }
2826 }
2827 if ((s->transport && s->transport != DNS_TRANSPORT_PLAIN)
2828 || (s->dnssec && s->dnssec != DNS_SECURITY_NO) || non_standard_server_port)
2829 {
2830 /* Skip servers requiring unsupported config to be set */
2831 s = s->next;
2832 }
2833 else
2834 {
2835 bool overflow = false;
2836 for (size_t i = 0; i < s->addr_count; ++i)
2837 {
2838 if (s->addr[i].family == AF_INET && tt->dns_len + 1 < N_DHCP_ADDR)
2839 {
2840 tt->dns[tt->dns_len++] = ntohl(s->addr[i].in.a4.s_addr);
2841 }
2842 else if (tt->dns6_len + 1 < N_DHCP_ADDR)
2843 {
2844 tt->dns6[tt->dns6_len++] = s->addr[i].in.a6;
2845 }
2846 else
2847 {
2848 overflow = true;
2849 }
2850 }
2851 if (overflow)
2852 {
2853 msg(M_WARN, "WARNING: couldn't copy all --dns server addresses to TUN/TAP");
2854 }
2856 return;
2857 }
2858 }
2859}
2860
2861#else /* if defined(_WIN32) || defined(TARGET_ANDROID) */
2862
2873static void
2874dhcp_options_postprocess_dns(struct options *o, struct env_set *es)
2875{
2876 struct gc_arena gc = gc_new();
2877 struct dns_options *dns = &o->dns_options;
2878
2879 if (is_tun_afunix(o->dev_node))
2880 {
2881 /* Disable running dns-updown script with lwipovpn */
2883 dns->updown = NULL;
2884 }
2885
2886 if (dns->servers || dns_updown_user_set(dns) || dns_updown_forced(dns))
2887 {
2888 /* Clean up env from --dhcp-option DNS config */
2889 struct buffer name = alloc_buf_gc(OPTION_PARM_SIZE, &gc);
2890 struct buffer value = alloc_buf_gc(OPTION_PARM_SIZE, &gc);
2891
2892 const int fo_count = o->foreign_option_index;
2893 o->foreign_option_index = 0;
2894
2895 for (int i = 1; i <= fo_count; ++i)
2896 {
2897 buf_clear(&name);
2898 buf_printf(&name, "foreign_option_%d", i);
2899 const char *env_str = env_set_get(es, BSTR(&name));
2900 const char *item_val = strchr(env_str, '=') + 1;
2901 buf_clear(&value);
2902 buf_printf(&value, "%s", item_val);
2903
2904 /* Remove foreign option item from env set */
2905 env_set_del(es, BSTR(&name));
2906
2907 item_val = BSTR(&value);
2908 if (strncmp(item_val, "dhcp-option ", 12) != 0
2909 || (strncmp(item_val + 12, "ADAPTER-DOMAIN-SUFFIX ", 22) != 0
2910 && strncmp(item_val + 12, "DOMAIN-SEARCH ", 14) != 0
2911 && strncmp(item_val + 12, "DOMAIN ", 7) != 0
2912 && strncmp(item_val + 12, "DNS6 ", 5) != 0
2913 && strncmp(item_val + 12, "DNS ", 4) != 0))
2914 {
2915 /* Re-set the item with potentially updated name */
2916 buf_clear(&name);
2917 buf_printf(&name, "foreign_option_%d", ++o->foreign_option_index);
2918 setenv_str(es, BSTR(&name), BSTR(&value));
2919 }
2920 }
2921 }
2922
2923 if (!dns->servers)
2924 {
2925 /* Copy --dhcp-options to dns_options */
2926 struct dhcp_options *dhcp = &dns->from_dhcp;
2927
2928 if (dhcp->dns_len || dhcp->dns6_len)
2929 {
2930 struct dns_domain **entry = &dns->search_domains;
2931 ALLOC_OBJ_CLEAR_GC(*entry, struct dns_domain, &dns->gc);
2932 struct dns_domain *domain = *entry;
2933 domain->name = dhcp->domain;
2934 entry = &domain->next;
2935
2936 for (unsigned int i = 0; i < dhcp->domain_search_list_len; ++i)
2937 {
2938 ALLOC_OBJ_CLEAR_GC(*entry, struct dns_domain, &dns->gc);
2939 struct dns_domain *search_domain = *entry;
2940 search_domain->name = dhcp->domain_search_list[i];
2941 entry = &search_domain->next;
2942 }
2943
2944 struct dns_server *server = dns_server_get(&dns->servers, 0, &dns->gc);
2945 const size_t max_addrs = SIZE(server->addr);
2946 for (unsigned int i = 0; i < dhcp->dns_len && server->addr_count < max_addrs; ++i)
2947 {
2948 server->addr[server->addr_count].in.a4.s_addr = htonl(dhcp->dns[i]);
2949 server->addr[server->addr_count].family = AF_INET;
2950 server->addr_count += 1;
2951 }
2952 for (unsigned int i = 0; i < dhcp->dns6_len && server->addr_count < max_addrs; ++i)
2953 {
2954 server->addr[server->addr_count].in.a6 = dhcp->dns6[i];
2955 server->addr[server->addr_count].family = AF_INET6;
2956 server->addr_count += 1;
2957 }
2958 }
2959 }
2960 else if (o->up_script && !dns_updown_user_set(dns) && !dns_updown_forced(dns))
2961 {
2962 /* Set foreign option env vars from --dns config */
2963 const struct dns_domain *d = dns->search_domains;
2964 while (d)
2965 {
2966 setenv_foreign_option(o, "DOMAIN", d->name, es);
2967 d = d->next;
2968 }
2969
2970 const struct dns_server *s = dns->servers;
2971 while (s)
2972 {
2973 bool non_standard_server_port = false;
2974 for (size_t i = 0; i < s->addr_count; ++i)
2975 {
2976 if (s->addr[i].port && s->addr[i].port != 53)
2977 {
2978 non_standard_server_port = true;
2979 break;
2980 }
2981 }
2982 if ((s->transport && s->transport != DNS_TRANSPORT_PLAIN)
2983 || (s->dnssec && s->dnssec != DNS_SECURITY_NO) || non_standard_server_port)
2984 {
2985 /* Skip servers requiring unsupported config to be set */
2986 s = s->next;
2987 }
2988 else
2989 {
2990 for (size_t i = 0; i < s->addr_count; ++i)
2991 {
2992 const char *option;
2993 const char *value;
2994 if (s->addr[i].family == AF_INET)
2995 {
2996 option = "DNS";
2997 value = print_in_addr_t(s->addr[i].in.a4.s_addr, IA_NET_ORDER, &gc);
2998 }
2999 else
3000 {
3001 option = "DNS6";
3002 value = print_in6_addr(s->addr[i].in.a6, 0, &gc);
3003 }
3004 setenv_foreign_option(o, option, value, es);
3005 }
3006 break;
3007 }
3008 }
3009 }
3010
3011 gc_free(&gc);
3012}
3013#endif /* if defined(_WIN32) || defined(TARGET_ANDROID) */
3018static void
3020{
3021 if (!o->real_hash_size)
3022 {
3023 o->real_hash_size = 4 * o->max_clients;
3024 }
3025 if (!o->virtual_hash_size)
3026 {
3027 o->virtual_hash_size = 4 * o->max_clients;
3028 }
3029 if (!o->sid_hash_size)
3030 {
3032 }
3033}
3034
3035static void
3037{
3038 /*
3039 * Process helper-type options which map to other, more complex
3040 * sequences of options.
3041 */
3043 /* must be called after helpers that might set --mode */
3047
3048 if (o->mode == MODE_SERVER)
3049 {
3051 }
3052
3056
3059 if (o->ncp_ciphers == NULL)
3060 {
3061 msg(M_USAGE, "--data-ciphers list contains unsupported ciphers or is too long.");
3062 }
3063
3064 if (o->remote_list && !o->connection_list)
3065 {
3066 /*
3067 * Convert remotes into connection list
3068 */
3069 const struct remote_list *rl = o->remote_list;
3070 for (int i = 0; i < rl->len; ++i)
3071 {
3072 const struct remote_entry *re = rl->array[i];
3073 struct connection_entry ce = o->ce;
3074 struct connection_entry *ace;
3075
3076 ASSERT(re->remote);
3077 connection_entry_load_re(&ce, re);
3079 ASSERT(ace);
3080 *ace = ce;
3081 }
3082 }
3083 else if (!o->remote_list && !o->connection_list)
3084 {
3085 struct connection_entry *ace;
3087 ASSERT(ace);
3088 *ace = o->ce;
3089 }
3090
3092 for (int i = 0; i < o->connection_list->len; ++i)
3093 {
3095 }
3096
3097 if (o->ce.local_list)
3098 {
3099 for (int i = 0; i < o->ce.local_list->len; i++)
3100 {
3102 }
3103
3104 for (int i = 0; i < o->ce.local_list->len; i++)
3105 {
3106 if (o->ce.local_list->array[i]->proto == PROTO_TCP)
3107 {
3109 }
3110 else if (o->ce.local_list->array[i]->proto == PROTO_NONE)
3111 {
3112 o->ce.local_list->array[i]->proto = o->ce.proto;
3113 }
3114 }
3115 }
3116 else
3117 {
3118 /* if no 'local' directive was specified, convert the global port
3119 * setting to a listen entry */
3120 struct local_entry *e = alloc_local_entry(&o->ce, M_USAGE, &o->gc);
3121 ASSERT(e);
3122 e->port = o->ce.local_port;
3123 e->proto = o->ce.proto;
3124 }
3125
3126 /* use the same listen list for every outgoing connection */
3127 for (int i = 0; i < o->connection_list->len; ++i)
3128 {
3130 }
3131
3132 if (o->tls_server)
3133 {
3134 if (o->dh_file && streq(o->dh_file, "none"))
3135 {
3136 o->dh_file = NULL;
3137 }
3138 }
3139 else if (o->dh_file)
3140 {
3141 /* DH file is only meaningful in a tls-server context. */
3142 msg(M_WARN, "WARNING: Ignoring option 'dh' in tls-client mode, please only "
3143 "include this in your server configuration");
3144 o->dh_file = NULL;
3145 }
3146#if ENABLE_MANAGEMENT
3147 if (o->http_proxy_override)
3148 {
3150 }
3151#endif
3152 if (!o->ca_file && !o->ca_path && o->verify_hash && o->verify_hash_depth == 0)
3153 {
3154 msg(M_INFO, "Using certificate fingerprint to verify peer (no CA "
3155 "option set). ");
3156 o->verify_hash_no_ca = true;
3157 }
3158
3159 if (o->config && streq(o->config, "stdin") && o->remap_sigusr1 == SIGHUP)
3160 {
3161 msg(M_USAGE, "Options 'config stdin' and 'remap-usr1 SIGHUP' are "
3162 "incompatible with each other.");
3163 }
3164
3165 if (dco_enabled(o))
3166 {
3167 /* check if any option should force disabling DCO */
3169 }
3170#ifdef USE_COMP
3171 if (dco_enabled(o))
3172 {
3174 }
3175#endif
3176
3177#ifdef _WIN32
3178 if (dco_enabled(o))
3179 {
3181 }
3182 else
3183 {
3185 }
3186#else /* _WIN32 */
3187 if (dco_enabled(o) && o->dev_node)
3188 {
3189 msg(M_WARN, "Note: ignoring --dev-node as it has no effect when using "
3190 "data channel offload");
3191 o->dev_node = NULL;
3192 }
3193#endif /* _WIN32 */
3194
3195 /* this depends on o->windows_driver, which is set above */
3197
3198 /* check that compression settings in the options are okay */
3200
3201 /*
3202 * Save certain parms before modifying options during connect, especially
3203 * when using --pull
3204 */
3205 if (o->pull)
3206 {
3208 }
3209 else
3210 {
3211#if defined(_WIN32) || defined(TARGET_ANDROID)
3213#else
3214 dhcp_options_postprocess_dns(o, es);
3215#endif
3216 }
3218 {
3220 }
3221#if ENABLE_MANAGEMENT
3223 {
3224 msg(M_USAGE, "'auth-user-pass username-only' cannot be used with static challenge");
3225 }
3226#endif
3228}
3229
3230/*
3231 * Sanity check on options.
3232 * Also set some options based on other
3233 * options.
3234 */
3235void
3237{
3240#ifndef ENABLE_SMALL
3242#endif
3243}
3244
3245/*
3246 * Sanity check on options after more options were pulled from server.
3247 * Also time to modify some options based on other options.
3248 */
3249bool
3251{
3252 bool success = dns_options_verify(D_PUSH_ERRORS, &o->dns_options);
3253 if (success)
3254 {
3256#if defined(_WIN32) || defined(TARGET_ANDROID)
3258#else
3259 dhcp_options_postprocess_dns(o, es);
3260#endif
3261 }
3262 return success;
3263}
3264
3265/*
3266 * parse/print topology coding
3267 */
3268
3269int
3270parse_topology(const char *str, const msglvl_t msglevel)
3271{
3272 if (streq(str, "net30"))
3273 {
3274 return TOP_NET30;
3275 }
3276 else if (streq(str, "p2p"))
3277 {
3278 return TOP_P2P;
3279 }
3280 else if (streq(str, "subnet"))
3281 {
3282 return TOP_SUBNET;
3283 }
3284 else
3285 {
3286 msg(msglevel, "--topology must be net30, p2p, or subnet");
3287 return TOP_UNDEF;
3288 }
3289}
3290
3291const char *
3292print_topology(const int topology)
3293{
3294 switch (topology)
3295 {
3296 case TOP_UNDEF:
3297 return "undef";
3298
3299 case TOP_NET30:
3300 return "net30";
3301
3302 case TOP_P2P:
3303 return "p2p";
3304
3305 case TOP_SUBNET:
3306 return "subnet";
3307
3308 default:
3309 return "unknown";
3310 }
3311}
3312
3313/*
3314 * Manage auth-retry variable
3315 */
3316
3317static int global_auth_retry; /* GLOBAL */
3318
3319int
3321{
3322 return global_auth_retry;
3323}
3324
3325bool
3326auth_retry_set(const msglvl_t msglevel, const char *option)
3327{
3328 if (streq(option, "interact"))
3329 {
3331 }
3332 else if (streq(option, "nointeract"))
3333 {
3335 }
3336 else if (streq(option, "none"))
3337 {
3339 }
3340 else
3341 {
3342 msg(msglevel, "--auth-retry method must be 'interact', 'nointeract', or 'none'");
3343 return false;
3344 }
3345 return true;
3346}
3347
3348const char *
3350{
3351 switch (global_auth_retry)
3352 {
3353 case AR_NONE:
3354 return "none";
3355
3356 case AR_NOINTERACT:
3357 return "nointeract";
3358
3359 case AR_INTERACT:
3360 return "interact";
3361
3362 default:
3363 return "???";
3364 }
3365}
3366
3367/*
3368 * Print the help message.
3369 */
3370void
3372{
3373 FILE *fp = msg_fp(0);
3374
3375#ifdef ENABLE_SMALL
3376
3377 fprintf(fp, "Usage message not available\n");
3378
3379#else
3380
3381 struct options o;
3382 init_options(&o);
3383
3389 fflush(fp);
3390
3391#endif /* ENABLE_SMALL */
3392
3393 openvpn_exit(OPENVPN_EXIT_STATUS_USAGE); /* exit point */
3394}
3395
3396void
3398{
3399 msg(M_WARN | M_NOPREFIX, "Use --help for more information.");
3400 openvpn_exit(OPENVPN_EXIT_STATUS_USAGE); /* exit point */
3401}
3402
3403#ifdef _WIN32
3404void
3405show_windows_version(const unsigned int flags)
3406{
3407 struct gc_arena gc = gc_new();
3408 msg(flags, "Windows version: %s", win32_version_string(&gc));
3409 gc_free(&gc);
3410}
3411#endif
3412
3413void
3414show_dco_version(const unsigned int flags)
3415{
3416#ifdef ENABLE_DCO
3417 struct gc_arena gc = gc_new();
3418 msg(flags, "DCO version: %s", dco_version_string(&gc));
3419 gc_free(&gc);
3420#endif
3421}
3422
3423void
3424show_library_versions(const unsigned int flags)
3425{
3426#ifdef ENABLE_LZO
3427#define LZO_LIB_VER_STR ", LZO ", lzo_version_string()
3428#else
3429#define LZO_LIB_VER_STR "", ""
3430#endif
3431
3432 msg(flags, "library versions: %s%s%s", get_ssl_library_version(), LZO_LIB_VER_STR);
3433
3434#undef LZO_LIB_VER_STR
3435}
3436
3437static void
3439{
3442#ifdef _WIN32
3444#endif
3446 msg(M_INFO | M_NOPREFIX, "Originally developed by James Yonan");
3447 msg(M_INFO | M_NOPREFIX, "Copyright (C) 2002-2026 OpenVPN Inc <sales@openvpn.net>");
3448#ifndef ENABLE_SMALL
3449#ifdef CONFIGURE_DEFINES
3450 msg(M_INFO | M_NOPREFIX, "Compile time defines: %s", CONFIGURE_DEFINES);
3451#endif
3452#ifdef CONFIGURE_SPECIAL_BUILD
3453 msg(M_INFO | M_NOPREFIX, "special build: %s", CONFIGURE_SPECIAL_BUILD);
3454#endif
3455#endif
3456
3458
3460}
3461
3462void
3463notnull(const char *arg, const char *description)
3464{
3465 if (!arg)
3466 {
3467 msg(M_USAGE, "You must define %s", description);
3468 }
3469}
3470
3471#if 0
3472static void
3473ping_rec_err(msglvl_t msglevel)
3474{
3475 msg(msglevel, "only one of --ping-exit or --ping-restart options may be specified");
3476}
3477#endif
3478
3479#ifdef _WIN32 /* This function is only used when compiling on Windows */
3480static unsigned int
3481atou(const char *str)
3482{
3483 unsigned int val = 0;
3484 sscanf(str, "%u", &val);
3485 return val;
3486}
3487#endif
3488
3489#define VERIFY_PERMISSION(mask) \
3490 { \
3491 if (!verify_permission(p[0], file, line, (mask), permission_mask, option_types_found, \
3492 msglevel, options, is_inline)) \
3493 { \
3494 goto err; \
3495 } \
3496 }
3497
3498static bool
3499verify_permission(const char *name, const char *file, int line, const uint64_t type,
3500 const uint64_t allowed, uint64_t *found, const msglvl_t msglevel,
3501 const struct options *options, bool is_inline)
3502{
3503 if (!(type & allowed))
3504 {
3505 msg(msglevel, "option '%s' cannot be used in this context (%s)", name, file);
3506 return false;
3507 }
3508
3509 if (is_inline && !(type & OPT_P_INLINE))
3510 {
3511 msg(msglevel, "option '%s' is not expected to be inline (%s:%d)", name, file, line);
3512 return false;
3513 }
3514
3515 if (found)
3516 {
3517 *found |= type;
3518 }
3519
3520#ifndef ENABLE_SMALL
3521 /* Check if this options is allowed in connection block,
3522 * but we are currently not in a connection block
3523 * unless this is a pushed option.
3524 * Parsing a connection block uses a temporary options struct without
3525 * connection_list
3526 */
3527
3528 if ((type & OPT_P_CONNECTION) && options->connection_list && !(allowed & OPT_P_PULL_MODE))
3529 {
3530 if (file)
3531 {
3532 msg(M_WARN, "Option '%s' in %s:%d is ignored by previous <connection> blocks ", name,
3533 file, line);
3534 }
3535 else
3536 {
3537 msg(M_WARN, "Option '%s' is ignored by previous <connection> blocks", name);
3538 }
3539 }
3540#endif
3541 return true;
3542}
3543
3544/*
3545 * Check that an option doesn't have too
3546 * many parameters.
3547 */
3548
3549#define NM_QUOTE_HINT (1 << 0)
3550
3551static bool
3552no_more_than_n_args(const msglvl_t msglevel, char *p[], const int max, const unsigned int flags)
3553{
3554 const int len = string_array_len((const char **)p);
3555
3556 if (!len)
3557 {
3558 return false;
3559 }
3560
3561 if (len > max)
3562 {
3563 msg(msglevel, "the --%s directive should have at most %d parameter%s.%s", p[0], max - 1,
3564 max >= 3 ? "s" : "",
3565 (flags & NM_QUOTE_HINT)
3566 ? " To pass a list of arguments as one of the parameters, try enclosing them in double quotes (\"\")."
3567 : "");
3568 return false;
3569 }
3570 else
3571 {
3572 return true;
3573 }
3574}
3575
3576static inline msglvl_t
3578{
3579 return options->forward_compatible ? M_WARN : msglevel;
3580}
3581
3582/* Return M_WARN for an unknown option listed in --ignore-unknown-option */
3583static msglvl_t
3584msglevel_unknown_option(const struct options *options, const char *name, const msglvl_t msglevel)
3585{
3586 for (int i = 0; options->ignore_unknown_option && options->ignore_unknown_option[i]; i++)
3587 {
3588 if (streq(name, options->ignore_unknown_option[i]))
3589 {
3590 return M_WARN;
3591 }
3592 }
3593 return msglevel;
3594}
3595
3596/* If IPv4 routes were installed, delete them and forget the configured ones */
3597static void
3598reset_routes_v4(struct context *c, struct options *options, const struct env_set *es)
3599{
3600 if (c->c1.route_list)
3601 {
3603 &c->net_ctx);
3604 if (options->routes)
3605 {
3606 options->routes->routes = NULL;
3607 options->routes->flags = 0;
3608 }
3609 }
3610}
3611
3612/* If IPv6 routes were installed, delete them and forget the configured ones */
3613static void
3614reset_routes_v6(struct context *c, struct options *options, const struct env_set *es)
3615{
3616 if (c->c1.route_ipv6_list)
3617 {
3619 es, &c->net_ctx);
3620 if (options->routes_ipv6)
3621 {
3624 }
3625 }
3626}
3627
3628static void
3630{
3631 if (options->routes)
3632 {
3633 options->routes->flags = 0;
3634 }
3635 if (options->routes_ipv6)
3636 {
3638 }
3639 env_set_del(es, "route_redirect_gateway_ipv4");
3640 env_set_del(es, "route_redirect_gateway_ipv6");
3641}
3642
3643static void
3649
3650static void
3652{
3653#if defined(_WIN32) || defined(TARGET_ANDROID)
3655
3656 o->domain = NULL;
3657 o->netbios_scope = NULL;
3658 o->netbios_node_type = 0;
3659 o->dns6_len = 0;
3660 CLEAR(o->dns6);
3661 o->dns_len = 0;
3662 CLEAR(o->dns);
3663 o->wins_len = 0;
3664 CLEAR(o->wins);
3665 o->ntp_len = 0;
3666 CLEAR(o->ntp);
3667 o->nbdd_len = 0;
3668 CLEAR(o->nbdd);
3671 o->disable_nbt = 0;
3672 o->dhcp_options = 0;
3674
3675#if defined(TARGET_ANDROID)
3676 o->http_proxy_port = 0;
3677 o->http_proxy = NULL;
3678#endif
3679#else /* if defined(_WIN32) || defined(TARGET_ANDROID) */
3680 delete_all_dhcp_fo(options, &es->list);
3681#endif /* if defined(_WIN32) || defined(TARGET_ANDROID) */
3682}
3683
3684void
3685remove_option(struct context *c, struct options *options, char *p[], bool is_inline,
3686 const char *file, int line, const msglvl_t msglevel,
3687 const uint64_t permission_mask, uint64_t *option_types_found,
3688 struct env_set *es)
3689{
3690 msglvl_t msglevel_fc = msglevel_forward_compatible(options, msglevel);
3691
3692 if (streq(p[0], "ifconfig") && !p[1])
3693 {
3695 options->ifconfig_local = NULL;
3697 }
3698 else if (streq(p[0], "ifconfig-ipv6") && !p[1])
3699 {
3704 }
3705 else if (streq(p[0], "route") && !p[1])
3706 {
3708 reset_routes_v4(c, options, es);
3709 }
3710 else if (streq(p[0], "route-ipv6") && !p[1])
3711 {
3713 reset_routes_v6(c, options, es);
3714 }
3715 else if (streq(p[0], "route-gateway") && !p[1])
3716 {
3720 }
3721 else if (streq(p[0], "route-metric") && !p[1])
3722 {
3725 }
3726 else if (streq(p[0], "push-continuation") && !p[1])
3727 {
3730 }
3731 else if ((streq(p[0], "redirect-gateway") || streq(p[0], "redirect-private")) && !p[1])
3732 {
3735 }
3736 else if (streq(p[0], "dns") && !p[1])
3737 {
3740 }
3741 else if (streq(p[0], "topology") && !p[1])
3742 {
3746 }
3747 else if (streq(p[0], "tun-mtu") && !p[1])
3748 {
3751 options->ce.tun_mtu_defined = false;
3752 options->ce.occ_mtu = 0;
3753 }
3754 else if (streq(p[0], "block-ipv6") && !p[1])
3755 {
3757 options->block_ipv6 = false;
3758 }
3759 else if (streq(p[0], "dhcp-option") && !p[1])
3760 {
3763 }
3764#ifdef _WIN32
3765 else if (streq(p[0], "block-outside-dns") && !p[1])
3766 {
3768 options->block_outside_dns = false;
3769 }
3770#endif
3771 else
3772 {
3773 msg(msglevel_unknown_option(options, p[0], msglevel_fc),
3774 "Unrecognized option or missing or extra parameter(s) in %s:%d: -%s (%s)", file, line,
3775 p[0], PACKAGE_VERSION);
3776 }
3777 return;
3778err:
3779 msg(msglevel, "Error occurred trying to remove %s option", p[0]);
3780}
3781
3782
3783static bool
3784check_route_option(struct options *options, char *p[], const msglvl_t msglevel, bool pull_mode)
3785{
3787 if (pull_mode)
3788 {
3790 && !is_special_addr(p[1])) /* FQDN -- may be DNS name */
3791 {
3792 msg(msglevel, "route parameter network/IP '%s' must be a valid address", p[1]);
3793 return false;
3794 }
3795 if (p[2] && !ip_addr_dotted_quad_safe(p[2])) /* FQDN -- must be IP address */
3796 {
3797 msg(msglevel, "route parameter netmask '%s' must be an IP address", p[2]);
3798 return false;
3799 }
3800 if (p[3] && !ip_or_dns_addr_safe(p[3], options->allow_pull_fqdn)
3801 && !is_special_addr(p[3])) /* FQDN -- may be DNS name */
3802 {
3803 msg(msglevel, "route parameter gateway '%s' must be a valid address", p[3]);
3804 return false;
3805 }
3806 }
3807 return true;
3808}
3809
3810
3811static bool
3812check_route6_option(struct options *options, char *p[], const msglvl_t msglevel, bool pull_mode)
3813{
3815 if (pull_mode)
3816 {
3817 if (!ipv6_addr_safe_hexplusbits(p[1]))
3818 {
3819 msg(msglevel, "route-ipv6 parameter network/IP '%s' must be a valid address", p[1]);
3820 return false;
3821 }
3822 if (p[2] && !ipv6_addr_safe(p[2]))
3823 {
3824 msg(msglevel, "route-ipv6 parameter gateway '%s' must be a valid address", p[2]);
3825 return false;
3826 }
3827 /* p[3] is metric, if present */
3828 }
3829 return true;
3830}
3831
3832static bool
3833check_dns_option(struct options *options, char *p[], const msglvl_t msglevel, bool pull_mode)
3834{
3835 if (streq(p[1], "search-domains") && p[2])
3836 {
3839 {
3840 msg(msglevel, "--dns %s contain invalid characters", p[1]);
3841 return false;
3842 }
3843 }
3844 else if (streq(p[1], "server") && p[2] && p[3] && p[4])
3845 {
3846 long priority;
3847 if (!dns_server_priority_parse(&priority, p[2], pull_mode))
3848 {
3849 msg(msglevel, "--dns server: invalid priority value '%s'", p[2]);
3850 return false;
3851 }
3852
3853 struct dns_server *server =
3855
3856 if (streq(p[3], "address"))
3857 {
3858 for (int i = 4; p[i]; ++i)
3859 {
3860 if (!dns_server_addr_parse(server, p[i]))
3861 {
3862 msg(msglevel, "--dns server %ld: malformed address or maximum exceeded '%s'",
3863 priority, p[i]);
3864 return false;
3865 }
3866 }
3867 }
3868 else if (streq(p[3], "resolve-domains"))
3869 {
3870 if (!dns_domain_list_append(&server->domains, &p[4], &options->dns_options.gc))
3871 {
3872 msg(msglevel, "--dns server %ld: %s contain invalid characters", priority, p[3]);
3873 return false;
3874 }
3875 }
3876 else if (streq(p[3], "dnssec") && !p[5])
3877 {
3878 if (streq(p[4], "yes"))
3879 {
3880 server->dnssec = DNS_SECURITY_YES;
3881 }
3882 else if (streq(p[4], "no"))
3883 {
3884 server->dnssec = DNS_SECURITY_NO;
3885 }
3886 else if (streq(p[4], "optional"))
3887 {
3888 server->dnssec = DNS_SECURITY_OPTIONAL;
3889 }
3890 else
3891 {
3892 msg(msglevel, "--dns server %ld: malformed dnssec value '%s'", priority, p[4]);
3893 return false;
3894 }
3895 }
3896 else if (streq(p[3], "transport") && !p[5])
3897 {
3898 if (streq(p[4], "plain"))
3899 {
3901 }
3902 else if (streq(p[4], "DoH"))
3903 {
3905 }
3906 else if (streq(p[4], "DoT"))
3907 {
3908 server->transport = DNS_TRANSPORT_TLS;
3909 }
3910 else
3911 {
3912 msg(msglevel, "--dns server %ld: malformed transport value '%s'", priority, p[4]);
3913 return false;
3914 }
3915 }
3916 else if (streq(p[3], "sni") && !p[5])
3917 {
3918 if (!validate_domain(p[4]))
3919 {
3920 msg(msglevel, "--dns server %ld: %s contains invalid characters", priority, p[3]);
3921 return false;
3922 }
3923 server->sni = p[4];
3924 }
3925 else
3926 {
3927 msg(msglevel,
3928 "--dns server %ld: unknown option type '%s' or missing or unknown parameter",
3929 priority, p[3]);
3930 return false;
3931 }
3932 }
3933 else
3934 {
3935 msg(msglevel, "--dns: unknown option type '%s' or missing or unknown parameter", p[1]);
3936 return false;
3937 }
3938 return true;
3939}
3940
3941void
3942update_option(struct context *c, struct options *options, char *p[], bool is_inline,
3943 const char *file, int line, const int level, const msglvl_t msglevel,
3944 const uint64_t permission_mask, uint64_t *option_types_found,
3945 struct env_set *es)
3946{
3947 const bool pull_mode = BOOL_CAST(permission_mask & OPT_P_PULL_MODE);
3948 ASSERT(MAX_PARMS >= 7);
3949
3950 if (streq(p[0], "route") && p[1] && !p[5])
3951 {
3953 {
3955 if (!check_route_option(options, p, msglevel, pull_mode))
3956 {
3957 goto err;
3958 }
3959 reset_routes_v4(c, options, es);
3961 }
3962 }
3963 else if (streq(p[0], "route-ipv6") && p[1] && !p[4])
3964 {
3966 {
3968 if (!check_route6_option(options, p, msglevel, pull_mode))
3969 {
3970 goto err;
3971 }
3972 reset_routes_v6(c, options, es);
3974 }
3975 }
3976 else if (streq(p[0], "redirect-gateway") || streq(p[0], "redirect-private"))
3977 {
3979 {
3983 }
3984 }
3985 else if (streq(p[0], "dns") && p[1])
3986 {
3988 {
3990 if (!check_dns_option(options, p, msglevel, pull_mode))
3991 {
3992 goto err;
3993 }
3996 }
3997 }
3998 else if (streq(p[0], "dhcp-option") && p[1] && !p[3])
3999 {
4001 {
4005 }
4006 }
4007 add_option(options, p, is_inline, file, line, level, msglevel, permission_mask,
4008 option_types_found, es);
4009 return;
4010err:
4011 msg(msglevel, "Error occurred trying to update %s option", p[0]);
4012}
4013
4014static void
4015set_user_script(struct options *options, const char **script, const char *new_script,
4016 const char *type, bool in_chroot)
4017{
4018 if (*script)
4019 {
4020 msg(M_WARN,
4021 "Multiple --%s scripts defined. "
4022 "The previously configured script is overridden.",
4023 type);
4024 }
4025 *script = new_script;
4026 options->user_script_used = true;
4027
4028#ifndef ENABLE_SMALL
4029 {
4030 char script_name[100];
4031 snprintf(script_name, sizeof(script_name), "--%s script", type);
4032
4033 if (check_cmd_access(*script, script_name, (in_chroot ? options->chroot_dir : NULL)))
4034 {
4035 msg(M_USAGE, "Please correct this error.");
4036 }
4037 }
4038#endif
4039}
4040
4041static void
4043{
4044 if (comp_non_stub_enabled(info))
4045 {
4046 msg(M_WARN, "WARNING: Compression for receiving enabled. "
4047 "Compression has been used in the past to break encryption. "
4048 "Compression support is deprecated and we recommend to disable "
4049 "it completely.");
4050 }
4051}
4052
4053bool
4055{
4057#ifdef ENABLE_PKCS11
4058 ret = ret || (options->pkcs11_providers[0] != NULL);
4059#endif
4060#ifdef ENABLE_CRYPTOAPI
4061 ret = ret || options->cryptoapi_cert;
4062#endif
4063
4064 return ret;
4065}
4066
4067#if defined(__GNUC__) || defined(__clang__)
4068#pragma GCC diagnostic push
4069#pragma GCC diagnostic ignored "-Wsign-compare"
4070#endif
4071
4072void
4073add_option(struct options *options, char *p[], bool is_inline, const char *file, int line,
4074 const int level, const msglvl_t msglevel, const uint64_t permission_mask,
4075 uint64_t *option_types_found, struct env_set *es)
4076{
4077 struct gc_arena gc = gc_new();
4078 const bool pull_mode = BOOL_CAST(permission_mask & OPT_P_PULL_MODE);
4079 msglvl_t msglevel_fc = msglevel_forward_compatible(options, msglevel);
4080
4081 ASSERT(MAX_PARMS >= 7);
4082
4083 /*
4084 * If directive begins with "setenv opt" prefix, don't raise an error if
4085 * directive is unrecognized.
4086 */
4087 if (streq(p[0], "setenv") && p[1] && streq(p[1], "opt") && !(permission_mask & OPT_P_PULL_MODE))
4088 {
4089 if (!p[2])
4090 {
4091 p[2] = "setenv opt"; /* will trigger an error that includes setenv opt */
4092 }
4093 p += 2;
4094 msglevel_fc = M_WARN;
4095 }
4096
4097 if (!file)
4098 {
4099 file = "[CMD-LINE]";
4100 line = 1;
4101 }
4102 if (streq(p[0], "help"))
4103 {
4105 usage();
4106 if (p[1])
4107 {
4108 msg(msglevel, "--help does not accept any parameters");
4109 goto err;
4110 }
4111 }
4112 if (streq(p[0], "version") && !p[1])
4113 {
4115 usage_version();
4116 }
4117 else if (streq(p[0], "config") && p[1] && !p[2])
4118 {
4120
4121 /* save first config file only in options */
4122 if (!options->config)
4123 {
4124 options->config = p[1];
4125 }
4126
4127 read_config_file(options, p[1], level, file, line, msglevel, permission_mask,
4128 option_types_found, es);
4129 }
4130#ifndef ENABLE_SMALL
4131 else if (streq(p[0], "show-gateway") && !p[2])
4132 {
4133 struct route_gateway_info rgi;
4134 struct route_ipv6_gateway_info rgi6;
4135 in_addr_t remote_ipv4 = 0;
4136 struct in6_addr remote_ipv6 = IN6ADDR_ANY_INIT;
4137 openvpn_net_ctx_t net_ctx;
4139 if (p[1])
4140 {
4141 /* try parsing the argument as a v4 or v6 address - if
4142 * possible, the output will show the exact route there, and
4143 * "the default route" for the other protocol
4144 */
4145 remote_ipv4 = get_ip_addr(p[1], M_WARN, NULL);
4146 get_ipv6_addr(p[1], &remote_ipv6, NULL, M_WARN);
4147 }
4148 net_ctx_init(NULL, &net_ctx);
4149 get_default_gateway(&rgi, remote_ipv4, &net_ctx);
4150 get_default_gateway_ipv6(&rgi6, &remote_ipv6, &net_ctx);
4151 print_default_gateway(M_INFO, &rgi, &rgi6);
4152 openvpn_exit(OPENVPN_EXIT_STATUS_GOOD); /* exit point */
4153 }
4154#endif
4155 else if (streq(p[0], "echo") || streq(p[0], "parameter"))
4156 {
4157 struct buffer string = alloc_buf_gc(OPTION_PARM_SIZE, &gc);
4158 int j;
4159 bool good = true;
4160
4162
4163 for (j = 1; j < MAX_PARMS; ++j)
4164 {
4165 if (!p[j])
4166 {
4167 break;
4168 }
4169 if (j > 1)
4170 {
4171 good &= buf_printf(&string, " ");
4172 }
4173 good &= buf_printf(&string, "%s", p[j]);
4174 }
4175 if (good)
4176 {
4177 /* only message-related ECHO are logged, since other ECHOs
4178 * can potentially include security-sensitive strings */
4179 if (p[1] && strncmp(p[1], "msg", 3) == 0)
4180 {
4181 msg(M_INFO, "%s:%s", pull_mode ? "ECHO-PULL" : "ECHO", BSTR(&string));
4182 }
4183#ifdef ENABLE_MANAGEMENT
4184 if (management)
4185 {
4187 }
4188#endif
4189 }
4190 else
4191 {
4192 msg(M_WARN, "echo/parameter option overflow");
4193 }
4194 }
4195#ifdef ENABLE_MANAGEMENT
4196 else if (streq(p[0], "management") && p[1] && p[2] && !p[4])
4197 {
4199 if (streq(p[2], "unix"))
4200 {
4201#if UNIX_SOCK_SUPPORT
4203#else
4204 msg(msglevel, "MANAGEMENT: this platform does not support unix domain sockets");
4205 goto err;
4206#endif
4207 }
4208
4211 if (p[3])
4212 {
4214 }
4215 }
4216 else if (streq(p[0], "management-client-user") && p[1] && !p[2])
4217 {
4220 }
4221 else if (streq(p[0], "management-client-group") && p[1] && !p[2])
4222 {
4225 }
4226 else if (streq(p[0], "management-query-passwords") && !p[1])
4227 {
4230 }
4231 else if (streq(p[0], "management-query-remote") && !p[1])
4232 {
4235 }
4236 else if (streq(p[0], "management-query-proxy") && !p[1])
4237 {
4240 }
4241 else if (streq(p[0], "management-hold") && !p[1])
4242 {
4245 }
4246 else if (streq(p[0], "management-signal") && !p[1])
4247 {
4250 }
4251 else if (streq(p[0], "management-forget-disconnect") && !p[1])
4252 {
4255 }
4256 else if (streq(p[0], "management-up-down") && !p[1])
4257 {
4260 }
4261 else if (streq(p[0], "management-client") && !p[1])
4262 {
4265 }
4266 else if (streq(p[0], "management-external-key"))
4267 {
4269 for (int j = 1; j < MAX_PARMS && p[j] != NULL; ++j)
4270 {
4271 if (streq(p[j], "nopadding"))
4272 {
4274 }
4275 else if (streq(p[j], "pkcs1"))
4276 {
4278 }
4279 else if (streq(p[j], "pss"))
4280 {
4282 }
4283 else if (streq(p[j], "digest"))
4284 {
4286 }
4287 else
4288 {
4289 msg(msglevel, "Unknown management-external-key flag: %s", p[j]);
4290 }
4291 }
4292 /*
4293 * When no option is present, assume that only PKCS1
4294 * padding is supported
4295 */
4297 {
4299 }
4301 }
4302 else if (streq(p[0], "management-external-cert") && p[1] && !p[2])
4303 {
4307 }
4308 else if (streq(p[0], "management-client-auth") && !p[1])
4309 {
4312 }
4313 else if (streq(p[0], "management-log-cache") && p[1] && !p[2])
4314 {
4317 p[0], 1, INT_MAX, msglevel))
4318 {
4319 goto err;
4320 }
4321 }
4322#endif /* ifdef ENABLE_MANAGEMENT */
4323#ifdef ENABLE_PLUGIN
4324 else if (streq(p[0], "plugin") && p[1])
4325 {
4327 if (!options->plugin_list)
4328 {
4330 }
4332 {
4333 msg(msglevel, "plugin add failed: %s", p[1]);
4334 goto err;
4335 }
4336 }
4337#endif
4338 else if (streq(p[0], "mode") && p[1] && !p[2])
4339 {
4341 if (streq(p[1], "p2p"))
4342 {
4344 }
4345 else if (streq(p[1], "server"))
4346 {
4348 }
4349 else
4350 {
4351 msg(msglevel, "Bad --mode parameter: %s", p[1]);
4352 goto err;
4353 }
4354 }
4355 else if (streq(p[0], "dev") && p[1] && !p[2])
4356 {
4358 options->dev = p[1];
4359 }
4360 else if (streq(p[0], "dev-type") && p[1] && !p[2])
4361 {
4363 options->dev_type = p[1];
4364 }
4365#ifdef _WIN32
4366 else if (streq(p[0], "windows-driver") && p[1] && !p[2])
4367 {
4369 msg(M_WARN,
4370 "DEPRECATED OPTION: windows-driver: In OpenVPN 2.7, the default Windows driver is ovpn-dco. "
4371 "If incompatible options are used, OpenVPN will fall back to tap-windows6. Wintun support has been removed.");
4372 }
4373#endif
4374 else if (streq(p[0], "disable-dco"))
4375 {
4376 options->disable_dco = true;
4377 }
4378 else if (streq(p[0], "dev-node") && p[1] && !p[2])
4379 {
4381 options->dev_node = p[1];
4382 }
4383 else if (streq(p[0], "lladdr") && p[1] && !p[2])
4384 {
4386 if (mac_addr_safe(p[1])) /* MAC address only */
4387 {
4388 options->lladdr = p[1];
4389 }
4390 else
4391 {
4392 msg(msglevel, "lladdr parm '%s' must be a MAC address", p[1]);
4393 goto err;
4394 }
4395 }
4396 else if (streq(p[0], "topology") && p[1] && !p[2])
4397 {
4399 options->topology = parse_topology(p[1], msglevel);
4400 }
4401 else if (streq(p[0], "tun-ipv6") && !p[1])
4402 {
4403 if (!pull_mode)
4404 {
4405 msg(M_WARN,
4406 "Note: option tun-ipv6 is ignored because modern operating systems do not need special IPv6 tun handling anymore.");
4407 }
4408 }
4409#ifdef ENABLE_IPROUTE
4410 else if (streq(p[0], "iproute") && p[1] && !p[2])
4411 {
4413 iproute_path = p[1];
4414 }
4415#endif
4416 else if (streq(p[0], "ifconfig") && p[1] && p[2] && !p[3])
4417 {
4420 && ip_or_dns_addr_safe(p[2], options->allow_pull_fqdn)) /* FQDN -- may be DNS name */
4421 {
4422 options->ifconfig_local = p[1];
4424 }
4425 else
4426 {
4427 msg(msglevel, "ifconfig parms '%s' and '%s' must be valid addresses", p[1], p[2]);
4428 goto err;
4429 }
4430 }
4431 else if (streq(p[0], "ifconfig-ipv6") && p[1] && p[2] && !p[3])
4432 {
4433 unsigned int netbits;
4434
4436 if (get_ipv6_addr(p[1], NULL, &netbits, msglevel) && ipv6_addr_safe(p[2]))
4437 {
4439 {
4440 msg(msglevel, "ifconfig-ipv6: /netbits must be between 64 and 124, not '/%u'",
4441 netbits);
4442 goto err;
4443 }
4444
4446 options->ifconfig_ipv6_netbits = netbits;
4448 }
4449 else
4450 {
4451 msg(msglevel, "ifconfig-ipv6 parms '%s' and '%s' must be valid addresses", p[1], p[2]);
4452 goto err;
4453 }
4454 }
4455 else if (streq(p[0], "ifconfig-noexec") && !p[1])
4456 {
4458 options->ifconfig_noexec = true;
4459 }
4460 else if (streq(p[0], "ifconfig-nowarn") && !p[1])
4461 {
4463 options->ifconfig_nowarn = true;
4464 }
4465 else if (streq(p[0], "local") && p[1] && !p[4])
4466 {
4467 struct local_entry *e;
4468
4470
4472 ASSERT(e);
4473
4474 /* '*' is treated as 'ask the system to get some socket',
4475 * therefore force binding on a particular address only when
4476 * actually specified. */
4477 if (strcmp(p[1], "*") != 0)
4478 {
4479 e->local = p[1];
4480 }
4481
4482 if (p[2])
4483 {
4484 e->port = p[2];
4485 }
4486
4487 if (p[3])
4488 {
4489 e->proto = ascii2proto(p[3]);
4490 }
4491 }
4492 else if (streq(p[0], "remote-random") && !p[1])
4493 {
4495 options->remote_random = true;
4496 }
4497 else if (streq(p[0], "connection") && p[1] && !p[3])
4498 {
4500 if (is_inline)
4501 {
4502 struct options sub;
4503 struct connection_entry *e;
4504
4505 init_options(&sub);
4506 sub.ce = options->ce;
4507 read_config_string("[CONNECTION-OPTIONS]", &sub, p[1], msglevel, OPT_P_CONNECTION,
4508 option_types_found, es);
4509 if (!sub.ce.remote)
4510 {
4511 msg(msglevel,
4512 "Each 'connection' block must contain exactly one 'remote' directive");
4513 uninit_options(&sub);
4514 goto err;
4515 }
4516
4517 e = alloc_connection_entry(options, msglevel);
4518 if (!e)
4519 {
4520 uninit_options(&sub);
4521 goto err;
4522 }
4523 *e = sub.ce;
4524 gc_transfer(&options->gc, &sub.gc);
4525 uninit_options(&sub);
4526 }
4527 }
4528 else if (streq(p[0], "ignore-unknown-option") && p[1])
4529 {
4530 int i;
4531 int j;
4532 int numignored = 0;
4533 const char **ignore;
4534
4536 /* Find out how many options to be ignored */
4537 for (i = 1; p[i]; i++)
4538 {
4539 numignored++;
4540 }
4541
4542 /* add number of options already ignored */
4544 {
4545 numignored++;
4546 }
4547
4548 /* Allocate array */
4549 ALLOC_ARRAY_GC(ignore, const char *, numignored + 1, &options->gc);
4551 {
4552 ignore[i] = options->ignore_unknown_option[i];
4553 }
4554
4556
4557 for (j = 1; p[j]; j++)
4558 {
4559 /* Allow the user to specify ignore-unknown-option --opt too */
4560 if (p[j][0] == '-' && p[j][1] == '-')
4561 {
4562 options->ignore_unknown_option[i] = (p[j] + 2);
4563 }
4564 else
4565 {
4566 options->ignore_unknown_option[i] = p[j];
4567 }
4568 i++;
4569 }
4570
4571 options->ignore_unknown_option[i] = NULL;
4572 }
4573#if ENABLE_MANAGEMENT
4574 else if (streq(p[0], "http-proxy-override") && p[1] && p[2] && !p[4])
4575 {
4579 {
4580 goto err;
4581 }
4582 }
4583#endif
4584 else if (streq(p[0], "remote") && p[1] && !p[4])
4585 {
4586 struct remote_entry re;
4587 re.remote = re.remote_port = NULL;
4588 re.proto = -1;
4589 re.af = 0;
4590
4592 re.remote = p[1];
4593 if (p[2])
4594 {
4595 re.remote_port = p[2];
4596 if (p[3])
4597 {
4598 const int proto = ascii2proto(p[3]);
4599 const sa_family_t af = ascii2af(p[3]);
4600 if (proto < 0)
4601 {
4602 msg(msglevel, "remote: bad protocol associated with host %s: '%s'", p[1], p[3]);
4603 goto err;
4604 }
4605 re.proto = proto;
4606 re.af = af;
4607 }
4608 }
4609 if (permission_mask & OPT_P_GENERAL)
4610 {
4611 struct remote_entry *e = alloc_remote_entry(options, msglevel);
4612 if (!e)
4613 {
4614 goto err;
4615 }
4616 *e = re;
4617 }
4618 else if (permission_mask & OPT_P_CONNECTION)
4619 {
4621 }
4622 }
4623 else if (streq(p[0], "resolv-retry") && p[1] && !p[2])
4624 {
4626 if (streq(p[1], "infinite"))
4627 {
4629 }
4630 else
4631 {
4632 options->resolve_retry_seconds = positive_atoi(p[1], msglevel);
4633 }
4634 }
4635 else if ((streq(p[0], "preresolve") || streq(p[0], "ip-remote-hint")) && !p[2])
4636 {
4639 /* Note the ip-remote-hint and the argument p[1] are for
4640 * backward compatibility */
4641 if (p[1])
4642 {
4643 options->ip_remote_hint = p[1];
4644 }
4645 }
4646 else if (streq(p[0], "connect-retry") && p[1] && !p[3])
4647 {
4649 options->ce.connect_retry_seconds = positive_atoi(p[1], msglevel);
4650 /*
4651 * Limit the base value of retry wait interval to 16 bits to avoid
4652 * overflow when scaled up for exponential backoff
4653 */
4654 if (options->ce.connect_retry_seconds > 0xFFFF)
4655 {
4657 msg(M_WARN, "connect retry wait interval truncated to %d",
4659 }
4660
4661 if (p[2])
4662 {
4665 }
4666 }
4667 else if ((streq(p[0], "connect-timeout") || streq(p[0], "server-poll-timeout")) && p[1]
4668 && !p[2])
4669 {
4671 options->ce.connect_timeout = positive_atoi(p[1], msglevel);
4672 }
4673 else if (streq(p[0], "connect-retry-max") && p[1] && !p[2])
4674 {
4676 options->connect_retry_max = positive_atoi(p[1], msglevel);
4677 }
4678 else if (streq(p[0], "ipchange") && p[1])
4679 {
4681 if (!no_more_than_n_args(msglevel, p, 2, NM_QUOTE_HINT))
4682 {
4683 goto err;
4684 }
4686 string_substitute(p[1], ',', ' ', &options->gc), "ipchange", true);
4687 }
4688 else if (streq(p[0], "float") && !p[1])
4689 {
4691 options->ce.remote_float = true;
4692 }
4693#ifdef ENABLE_DEBUG
4694 else if (streq(p[0], "gremlin") && p[1] && !p[2])
4695 {
4697 options->gremlin = positive_atoi(p[1], msglevel);
4698 }
4699#endif
4700 else if (streq(p[0], "chroot") && p[1] && !p[2])
4701 {
4703 options->chroot_dir = p[1];
4704 }
4705 else if (streq(p[0], "cd") && p[1] && !p[2])
4706 {
4708 if (platform_chdir(p[1]))
4709 {
4710 msg(M_ERR, "cd to '%s' failed", p[1]);
4711 goto err;
4712 }
4713 options->cd_dir = p[1];
4714 }
4715#ifdef ENABLE_SELINUX
4716 else if (streq(p[0], "setcon") && p[1] && !p[2])
4717 {
4719 options->selinux_context = p[1];
4720 }
4721#endif
4722 else if (streq(p[0], "writepid") && p[1] && !p[2])
4723 {
4725 options->writepid = p[1];
4726 }
4727 else if (streq(p[0], "up") && p[1])
4728 {
4730 if (!no_more_than_n_args(msglevel, p, 2, NM_QUOTE_HINT))
4731 {
4732 goto err;
4733 }
4734 set_user_script(options, &options->up_script, p[1], "up", false);
4735 }
4736 else if (streq(p[0], "down") && p[1])
4737 {
4739 if (!no_more_than_n_args(msglevel, p, 2, NM_QUOTE_HINT))
4740 {
4741 goto err;
4742 }
4743 set_user_script(options, &options->down_script, p[1], "down", true);
4744 }
4745 else if (streq(p[0], "down-pre") && !p[1])
4746 {
4748 options->down_pre = true;
4749 }
4750 else if (streq(p[0], "up-delay") && !p[1])
4751 {
4753 options->up_delay = true;
4754 }
4755 else if (streq(p[0], "up-restart") && !p[1])
4756 {
4758 options->up_restart = true;
4759 }
4760 else if (streq(p[0], "syslog") && !p[2])
4761 {
4763 open_syslog(p[1], false);
4764 }
4765 else if (streq(p[0], "daemon") && !p[2])
4766 {
4767 bool didit = false;
4769 if (!options->daemon)
4770 {
4771 options->daemon = didit = true;
4772 open_syslog(p[1], false);
4773 }
4774 if (p[1])
4775 {
4776 if (!didit)
4777 {
4778 msg(M_WARN,
4779 "WARNING: Multiple --daemon directives specified, ignoring --daemon %s. (Note that initscripts sometimes add their own --daemon directive.)",
4780 p[1]);
4781 goto err;
4782 }
4783 }
4784 }
4785 else if (streq(p[0], "log") && p[1] && !p[2])
4786 {
4788 options->log = true;
4789 redirect_stdout_stderr(p[1], false);
4790 }
4791 else if (streq(p[0], "suppress-timestamps") && !p[1])
4792 {
4796 }
4797 else if (streq(p[0], "machine-readable-output") && !p[1])
4798 {
4802 }
4803 else if (streq(p[0], "log-append") && p[1] && !p[2])
4804 {
4806 options->log = true;
4807 redirect_stdout_stderr(p[1], true);
4808 }
4809 else if (streq(p[0], "mlock") && !p[1])
4810 {
4812 options->mlock = true;
4813 }
4814#if ENABLE_IP_PKTINFO
4815 else if (streq(p[0], "multihome") && !p[2])
4816 {
4819 if (p[1] && streq(p[1], "same-interface"))
4820 {
4822 }
4823 else if (p[1])
4824 {
4825 msg(msglevel, "Unknown parameter to --multihome: %s", p[1]);
4826 }
4827 }
4828#endif
4829 else if (streq(p[0], "verb") && p[1] && !p[2])
4830 {
4832 options->verbosity = positive_atoi(p[1], msglevel);
4834 {
4835 /* We pass this flag to the SSL library to avoid
4836 * mbed TLS always generating debug level logging */
4838 }
4839#ifdef ENABLE_SMALL
4840 /* Warn when a debug verbosity is supplied when built without debug support */
4841 if (options->verbosity >= 7)
4842 {
4843 msg(M_WARN,
4844 "NOTE: debug verbosity (--verb %d) is enabled but this build is "
4845 "built with --enable-small that lacks support for high --verb settings",
4847 }
4848#endif
4849 }
4850 else if (streq(p[0], "mute") && p[1] && !p[2])
4851 {
4853 options->mute = positive_atoi(p[1], msglevel);
4854 }
4855 else if (streq(p[0], "errors-to-stderr") && !p[1])
4856 {
4859 }
4860 else if (streq(p[0], "status") && p[1] && !p[3])
4861 {
4863 options->status_file = p[1];
4864 if (p[2])
4865 {
4867 }
4868 }
4869 else if (streq(p[0], "status-version") && p[1] && !p[2])
4870 {
4872 if (!atoi_constrained(p[1], &options->status_file_version, p[0], 1, 3, msglevel))
4873 {
4874 goto err;
4875 }
4876 }
4877 else if (streq(p[0], "remap-usr1") && p[1] && !p[2])
4878 {
4880 if (streq(p[1], "SIGHUP"))
4881 {
4883 }
4884 else if (streq(p[1], "SIGTERM"))
4885 {
4887 }
4888 else
4889 {
4890 msg(msglevel, "--remap-usr1 parm must be 'SIGHUP' or 'SIGTERM'");
4891 goto err;
4892 }
4893 }
4894 else if ((streq(p[0], "link-mtu") || streq(p[0], "udp-mtu")) && p[1] && !p[2])
4895 {
4897 options->ce.link_mtu = positive_atoi(p[1], msglevel);
4898 options->ce.link_mtu_defined = true;
4899 }
4900 else if (streq(p[0], "tun-mtu") && p[1] && !p[3])
4901 {
4903 if (atoi_constrained(p[1], &options->ce.tun_mtu, "tun-mtu", TUN_MTU_MIN, TUN_MTU_MAX, msglevel))
4904 {
4905 options->ce.tun_mtu_defined = true;
4906 if (p[2])
4907 {
4908 atoi_constrained(p[2], &options->ce.occ_mtu, "tun-mtu occ-mtu", TUN_MTU_MIN, TUN_MTU_MAX, msglevel);
4909 }
4910 else
4911 {
4912 options->ce.occ_mtu = 0;
4913 }
4914 }
4915 }
4916 else if (streq(p[0], "tun-mtu-max") && p[1] && !p[2])
4917 {
4920 }
4921 else if (streq(p[0], "tun-mtu-extra") && p[1] && !p[2])
4922 {
4924 if (atoi_constrained(p[1], &options->ce.tun_mtu_extra, p[0], 0, TUN_MTU_MAX, msglevel))
4925 {
4927 }
4928 }
4929 else if (streq(p[0], "max-packet-size") && p[1] && !p[2])
4930 {
4932 int maxmtu = positive_atoi(p[1], msglevel);
4934
4935 if (maxmtu < TLS_CHANNEL_MTU_MIN || maxmtu > TLS_CHANNEL_BUF_SIZE)
4936 {
4937 msg(M_WARN,
4938 "Note: max-packet-size value outside of allowed "
4939 "control channel packet size (%d to %d), will use %d "
4940 "instead.",
4942 }
4943
4944 /* also set mssfix maxmtu mtu */
4945 options->ce.mssfix = maxmtu;
4946 options->ce.mssfix_default = false;
4947 options->ce.mssfix_encap = true;
4948 }
4949#ifdef ENABLE_FRAGMENT
4950 else if (streq(p[0], "mtu-dynamic"))
4951 {
4953 msg(msglevel, "--mtu-dynamic has been replaced by --fragment");
4954 goto err;
4955 }
4956 else if (streq(p[0], "fragment") && p[1] && !p[3])
4957 {
4959 if (!atoi_constrained(p[1], &options->ce.fragment, p[0], 68, INT_MAX, msglevel))
4960 {
4961 goto err;
4962 }
4963
4964 if (p[2] && streq(p[2], "mtu"))
4965 {
4966 options->ce.fragment_encap = true;
4967 }
4968 else if (p[2])
4969 {
4970 msg(msglevel, "Unknown parameter to --fragment: %s", p[2]);
4971 }
4972 }
4973#endif /* ifdef ENABLE_FRAGMENT */
4974 else if (streq(p[0], "mtu-disc") && p[1] && !p[2])
4975 {
4978 }
4979 else if (streq(p[0], "mtu-test") && !p[1])
4980 {
4982 options->mtu_test = true;
4983 }
4984 else if (streq(p[0], "nice") && p[1] && !p[2])
4985 {
4987 options->nice = atoi_warn(p[1], msglevel);
4988 }
4989 else if (streq(p[0], "rcvbuf") && p[1] && !p[2])
4990 {
4992 options->rcvbuf = positive_atoi(p[1], msglevel);
4993 }
4994 else if (streq(p[0], "sndbuf") && p[1] && !p[2])
4995 {
4997 options->sndbuf = positive_atoi(p[1], msglevel);
4998 }
4999 else if (streq(p[0], "mark") && p[1] && !p[2])
5000 {
5001#if defined(TARGET_LINUX)
5003 options->mark = atoi_warn(p[1], msglevel);
5004#endif
5005 }
5006 else if (streq(p[0], "socket-flags"))
5007 {
5008 int j;
5010 for (j = 1; j < MAX_PARMS && p[j]; ++j)
5011 {
5012 /* TCP_NODELAY is enabled by default; the flag is still accepted
5013 * for backwards compatibility but no longer has any effect */
5014 if (!streq(p[j], "TCP_NODELAY"))
5015 {
5016 msg(msglevel, "unknown socket flag: %s", p[j]);
5017 }
5018 }
5019 }
5020#ifdef TARGET_LINUX
5021 else if (streq(p[0], "bind-dev") && p[1])
5022 {
5024 if (strlen(p[1]) < IFNAMSIZ)
5025 {
5026 options->bind_dev = p[1];
5027 }
5028 else
5029 {
5030 msg(msglevel, "argument to --bind-dev is longer than allowed %d", IFNAMSIZ - 1);
5031 goto err;
5032 }
5033 }
5034#endif
5035 else if (streq(p[0], "txqueuelen") && p[1] && !p[2])
5036 {
5038#ifdef TARGET_LINUX
5039 options->tuntap_options.txqueuelen = positive_atoi(p[1], msglevel);
5040#else
5041 msg(msglevel, "--txqueuelen not supported on this OS");
5042 goto err;
5043#endif
5044 }
5045 else if (streq(p[0], "shaper") && p[1] && !p[2])
5046 {
5048 if (!atoi_constrained(p[1], &options->shaper, p[0], SHAPER_MIN, SHAPER_MAX, msglevel))
5049 {
5050 goto err;
5051 }
5052 }
5053 else if (streq(p[0], "port") && p[1] && !p[2])
5054 {
5057 }
5058 else if (streq(p[0], "lport") && p[1] && !p[2])
5059 {
5061
5062 /* only trigger bind() if port is not 0 (or --local is used) */
5063 if (!streq(p[1], "0"))
5064 {
5066 }
5067 options->ce.local_port = p[1];
5068 }
5069 else if (streq(p[0], "rport") && p[1] && !p[2])
5070 {
5072 options->ce.remote_port = p[1];
5073 }
5074 else if (streq(p[0], "bind") && !p[2])
5075 {
5077 options->ce.bind_defined = true;
5078 if (p[1] && streq(p[1], "ipv6only"))
5079 {
5080 options->ce.bind_ipv6_only = true;
5081 }
5082 }
5083 else if (streq(p[0], "nobind") && !p[1])
5084 {
5086 options->ce.bind_local = false;
5087 }
5088 else if (streq(p[0], "fast-io") && !p[1])
5089 {
5091 msg(M_WARN, "DEPRECATED OPTION: --fast-io option ignored.");
5092 }
5093 else if (streq(p[0], "inactive") && p[1] && !p[3])
5094 {
5096 options->inactivity_timeout = positive_atoi(p[1], msglevel);
5097 if (p[2])
5098 {
5099 positive_atoll(p[2], &options->inactivity_minimum_bytes, p[0], msglevel);
5100 if (options->inactivity_minimum_bytes > INT_MAX)
5101 {
5102 msg(M_WARN,
5103 "WARNING: '--inactive' with a 'bytes' value"
5104 " >2 Gbyte was silently ignored in older versions. If "
5105 " your VPN exits unexpectedly with 'Inactivity timeout'"
5106 " in %d seconds, revisit this value.",
5108 }
5109 }
5110 }
5111 else if (streq(p[0], "session-timeout") && p[1] && !p[2])
5112 {
5114 options->session_timeout = positive_atoi(p[1], msglevel);
5115 }
5116 else if (streq(p[0], "proto") && p[1] && !p[2])
5117 {
5119 int proto = ascii2proto(p[1]);
5120 sa_family_t af = ascii2af(p[1]);
5121 if (proto < 0)
5122 {
5123 msg(msglevel, "Bad protocol: '%s'. Allowed protocols with --proto option: %s", p[1],
5125 goto err;
5126 }
5127 options->ce.proto = proto;
5128 options->ce.af = af;
5129 }
5130 else if (streq(p[0], "proto-force") && p[1] && !p[2])
5131 {
5132 int proto_force;
5134 proto_force = ascii2proto(p[1]);
5135 if (proto_force < 0)
5136 {
5137 msg(msglevel, "Bad --proto-force protocol: '%s'", p[1]);
5138 goto err;
5139 }
5140 options->proto_force = proto_force;
5141 }
5142 else if (streq(p[0], "http-proxy") && p[1] && !p[5])
5143 {
5144 struct http_proxy_options *ho;
5145
5147
5148 {
5149 if (!p[2])
5150 {
5151 msg(msglevel, "http-proxy port number not defined");
5152 goto err;
5153 }
5154
5156
5157 ho->server = p[1];
5158 ho->port = p[2];
5159 }
5160
5161 if (p[3])
5162 {
5163 /* auto -- try to figure out proxy addr, port, and type automatically */
5164 /* auto-nct -- disable proxy auth cleartext protocols (i.e. basic auth) */
5165 if (streq(p[3], "auto"))
5166 {
5167 ho->auth_retry = PAR_ALL;
5168 }
5169 else if (streq(p[3], "auto-nct"))
5170 {
5171 ho->auth_retry = PAR_NCT;
5172 }
5173 else
5174 {
5175 ho->auth_method_string = "basic";
5176 ho->auth_file = p[3];
5177
5178 if (p[4])
5179 {
5180 ho->auth_method_string = p[4];
5181 }
5182 }
5183 }
5184 else
5185 {
5186 ho->auth_method_string = "none";
5187 }
5188 }
5189 else if (streq(p[0], "http-proxy-user-pass") && p[1])
5190 {
5191 struct http_proxy_options *ho;
5194 ho->auth_file_up = p[1];
5195 ho->inline_creds = is_inline;
5196 }
5197 else if (streq(p[0], "http-proxy-retry") || streq(p[0], "socks-proxy-retry") || streq(p[0], "http-proxy-timeout"))
5198 {
5200 msg(M_WARN, "DEPRECATED OPTION: %s option ignored.", p[0]);
5201 }
5202 else if (streq(p[0], "http-proxy-option") && p[1] && !p[4])
5203 {
5204 struct http_proxy_options *ho;
5205
5208
5209 if (streq(p[1], "VERSION") && p[2] && !p[3])
5210 {
5211 ho->http_version = p[2];
5212 }
5213 else if (streq(p[1], "AGENT") && p[2] && !p[3])
5214 {
5215 ho->user_agent = p[2];
5216 }
5217 else if ((streq(p[1], "EXT1") || streq(p[1], "EXT2") || streq(p[1], "CUSTOM-HEADER"))
5218 && p[2])
5219 {
5220 /* In the wild patched versions use both EXT1/2 and CUSTOM-HEADER
5221 * with either two argument or one */
5222
5223 struct http_custom_header *custom_header = NULL;
5224 int i;
5225 /* Find the first free header */
5226 for (i = 0; i < MAX_CUSTOM_HTTP_HEADER; i++)
5227 {
5228 if (!ho->custom_headers[i].name)
5229 {
5230 custom_header = &ho->custom_headers[i];
5231 break;
5232 }
5233 }
5234 if (!custom_header)
5235 {
5236 msg(msglevel, "Cannot use more than %d http-proxy-option CUSTOM-HEADER : '%s'",
5238 }
5239 else
5240 {
5241 /* We will save p[2] and p[3], the proxy code will detect if
5242 * p[3] is NULL */
5243 custom_header->name = p[2];
5244 custom_header->content = p[3];
5245 }
5246 }
5247 else
5248 {
5249 msg(msglevel, "Bad http-proxy-option or missing or extra parameter: '%s'", p[1]);
5250 }
5251 }
5252 else if (streq(p[0], "socks-proxy") && p[1] && !p[4])
5253 {
5255
5256 if (p[2])
5257 {
5258 options->ce.socks_proxy_port = p[2];
5259 }
5260 else
5261 {
5262 options->ce.socks_proxy_port = "1080";
5263 }
5265 options->ce.socks_proxy_authfile = p[3]; /* might be NULL */
5266 }
5267 else if (streq(p[0], "keepalive") && p[1] && p[2] && !p[3])
5268 {
5270 atoi_constrained(p[1], &options->keepalive_ping, "keepalive ping",
5271 1, PING_TIMEOUT_MAX, msglevel);
5272 atoi_constrained(p[2], &options->keepalive_timeout, "keepalive timeout",
5273 1, PING_TIMEOUT_MAX, msglevel);
5274 }
5275 else if (streq(p[0], "ping") && p[1] && !p[2])
5276 {
5279 0, PING_TIMEOUT_MAX, msglevel);
5280 }
5281 else if (streq(p[0], "ping-exit") && p[1] && !p[2])
5282 {
5285 0, PING_TIMEOUT_MAX, msglevel);
5287 }
5288 else if (streq(p[0], "ping-restart") && p[1] && !p[2])
5289 {
5292 0, PING_TIMEOUT_MAX, msglevel);
5294 }
5295 else if (streq(p[0], "ping-timer-rem") && !p[1])
5296 {
5298 options->ping_timer_remote = true;
5299 }
5300 else if (streq(p[0], "explicit-exit-notify") && !p[2])
5301 {
5303 if (p[1])
5304 {
5306 }
5307 else
5308 {
5310 }
5311 }
5312 else if (streq(p[0], "persist-tun") && !p[1])
5313 {
5315 options->persist_tun = true;
5316 }
5317 else if (streq(p[0], "persist-key") && !p[1])
5318 {
5320 msg(M_WARN, "DEPRECATED OPTION: --persist-key option ignored. "
5321 "Keys are now always persisted across restarts. ");
5322 }
5323 else if (streq(p[0], "persist-local-ip") && !p[1])
5324 {
5326 options->persist_local_ip = true;
5327 }
5328 else if (streq(p[0], "persist-remote-ip") && !p[1])
5329 {
5331 options->persist_remote_ip = true;
5332 }
5333 else if (streq(p[0], "client-nat") && p[1] && p[2] && p[3] && p[4] && !p[5])
5334 {
5337 add_client_nat_to_option_list(options->client_nat, p[1], p[2], p[3], p[4], msglevel);
5338 }
5339 else if (streq(p[0], "route-table") && p[1] && !p[2])
5340 {
5341#ifndef ENABLE_SITNL
5342 msg(M_WARN, "NOTE: --route-table is supported only on Linux when SITNL is built-in");
5343#endif
5345 options->route_default_table_id = positive_atoi(p[1], msglevel);
5346 }
5347 else if (streq(p[0], "route") && p[1] && !p[5])
5348 {
5350 if (!check_route_option(options, p, msglevel, pull_mode))
5351 {
5352 goto err;
5353 }
5354 add_route_to_option_list(options->routes, p[1], p[2], p[3], p[4],
5356 }
5357 else if (streq(p[0], "route-ipv6") && p[1] && !p[4])
5358 {
5360 if (!check_route6_option(options, p, msglevel, pull_mode))
5361 {
5362 goto err;
5363 }
5366 }
5367 else if (streq(p[0], "max-routes") && !p[2])
5368 {
5369 msg(M_WARN, "DEPRECATED OPTION: --max-routes option ignored.");
5370 }
5371 else if (streq(p[0], "route-gateway") && p[1] && !p[2])
5372 {
5374 if (streq(p[1], "dhcp"))
5375 {
5377 }
5378 else
5379 {
5381 || is_special_addr(p[1])) /* FQDN -- may be DNS name */
5382 {
5384 }
5385 else
5386 {
5387 msg(msglevel, "route-gateway parm '%s' must be a valid address", p[1]);
5388 goto err;
5389 }
5390 }
5391 }
5392 else if (streq(p[0], "route-ipv6-gateway") && p[1] && !p[2])
5393 {
5394 if (ipv6_addr_safe(p[1]))
5395 {
5397 }
5398 else
5399 {
5400 msg(msglevel, "route-ipv6-gateway parm '%s' must be a valid address", p[1]);
5401 goto err;
5402 }
5403 }
5404 else if (streq(p[0], "route-metric") && p[1] && !p[2])
5405 {
5407 options->route_default_metric = positive_atoi(p[1], msglevel);
5408 }
5409 else if (streq(p[0], "route-delay") && !p[3])
5410 {
5413 if (p[1])
5414 {
5415 options->route_delay = positive_atoi(p[1], msglevel);
5416 if (p[2])
5417 {
5418 options->route_delay_window = positive_atoi(p[2], msglevel);
5419 }
5420 }
5421 else
5422 {
5423 options->route_delay = 0;
5424 }
5425 }
5426 else if (streq(p[0], "route-up") && p[1])
5427 {
5429 if (!no_more_than_n_args(msglevel, p, 2, NM_QUOTE_HINT))
5430 {
5431 goto err;
5432 }
5433 set_user_script(options, &options->route_script, p[1], "route-up", false);
5434 }
5435 else if (streq(p[0], "route-pre-down") && p[1])
5436 {
5438 if (!no_more_than_n_args(msglevel, p, 2, NM_QUOTE_HINT))
5439 {
5440 goto err;
5441 }
5442 set_user_script(options, &options->route_predown_script, p[1], "route-pre-down", true);
5443 }
5444 else if (streq(p[0], "route-noexec") && !p[1])
5445 {
5447 options->route_noexec = true;
5448 }
5449 else if (streq(p[0], "route-nopull") && !p[1])
5450 {
5452 options->route_nopull = true;
5453 }
5454 else if (streq(p[0], "pull-filter") && p[1] && p[2] && !p[3])
5455 {
5456 struct pull_filter *f;
5459
5460 if (strcmp("accept", p[1]) == 0)
5461 {
5462 f->type = PUF_TYPE_ACCEPT;
5463 }
5464 else if (strcmp("ignore", p[1]) == 0)
5465 {
5466 f->type = PUF_TYPE_IGNORE;
5467 }
5468 else if (strcmp("reject", p[1]) == 0)
5469 {
5470 f->type = PUF_TYPE_REJECT;
5471 }
5472 else
5473 {
5474 msg(msglevel, "Unknown --pull-filter type: %s", p[1]);
5475 goto err;
5476 }
5477 f->pattern = p[2];
5478 f->size = strlen(p[2]);
5479 }
5480 else if (streq(p[0], "allow-pull-fqdn") && !p[1])
5481 {
5483 options->allow_pull_fqdn = true;
5484 }
5485 else if (streq(p[0], "redirect-gateway") || streq(p[0], "redirect-private"))
5486 {
5487 int j;
5490
5491 if (options->routes->flags & RG_ENABLE)
5492 {
5493 msg(M_WARN, "WARNING: You have specified redirect-gateway and "
5494 "redirect-private at the same time (or the same option "
5495 "multiple times). This is not well supported and may lead to "
5496 "unexpected results");
5497 }
5498
5500
5501 if (streq(p[0], "redirect-gateway"))
5502 {
5504 }
5505 for (j = 1; j < MAX_PARMS && p[j] != NULL; ++j)
5506 {
5507 if (streq(p[j], "local"))
5508 {
5510 }
5511 else if (streq(p[j], "autolocal"))
5512 {
5514 }
5515 else if (streq(p[j], "def1"))
5516 {
5517#ifndef TARGET_ANDROID
5518 /* The hack that def1 uses to split 0.0.0.0 into 0.0.0.0/1 and
5519 * 128.0.0.0/1 is not needed on Android and will even
5520 * make some Android implementations (e.g. Samsung)
5521 * misbehave, so silently ignore the flag and always use
5522 * 0.0.0.0/0 instead */
5524#endif
5525 }
5526 else if (streq(p[j], "bypass-dhcp"))
5527 {
5529 }
5530 else if (streq(p[j], "bypass-dns"))
5531 {
5533 }
5534 else if (streq(p[j], "block-local"))
5535 {
5537 }
5538 else if (streq(p[j], "ipv6"))
5539 {
5542 }
5543 else if (streq(p[j], "!ipv4"))
5544 {
5546 }
5547 else
5548 {
5549 msg(msglevel, "unknown --%s flag: %s", p[0], p[j]);
5550 goto err;
5551 }
5552 }
5554 {
5555 setenv_int(es, "route_redirect_gateway_ipv4",
5556 (options->routes->flags & RG_BLOCK_LOCAL) ? 2 : 1);
5557 }
5559 {
5560 setenv_int(es, "route_redirect_gateway_ipv6",
5561 (options->routes->flags & RG_BLOCK_LOCAL) ? 2 : 1);
5562 }
5563#ifdef _WIN32
5564 /* we need this here to handle pushed --redirect-gateway */
5566#endif
5567 }
5568 else if (streq(p[0], "block-ipv6") && !p[1])
5569 {
5571 options->block_ipv6 = true;
5572 }
5573 else if (streq(p[0], "remote-random-hostname") && !p[1])
5574 {
5577 }
5578 else if (streq(p[0], "setenv") && p[1] && !p[3])
5579 {
5581 if (streq(p[1], "REMOTE_RANDOM_HOSTNAME") && !p[2])
5582 {
5584 }
5585 else if (streq(p[1], "GENERIC_CONFIG"))
5586 {
5587 msg(msglevel, "this is a generic configuration and cannot directly be used");
5588 goto err;
5589 }
5590 else if (streq(p[1], "PUSH_PEER_INFO") && !p[2])
5591 {
5592 options->push_peer_info = true;
5593 }
5594 else if (streq(p[1], "SERVER_POLL_TIMEOUT") && p[2])
5595 {
5596 options->ce.connect_timeout = positive_atoi(p[2], msglevel);
5597 }
5598 else
5599 {
5600 if (streq(p[1], "FORWARD_COMPATIBLE") && p[2] && streq(p[2], "1"))
5601 {
5603 }
5604 setenv_str(es, p[1], p[2] ? p[2] : "");
5605 }
5606 }
5607 else if (streq(p[0], "compat-mode") && p[1] && !p[3])
5608 {
5609 unsigned int major, minor, patch;
5610 if (!(sscanf(p[1], "%u.%u.%u", &major, &minor, &patch) == 3))
5611 {
5612 msg(msglevel, "cannot parse version number for --compat-mode: %s", p[1]);
5613 goto err;
5614 }
5615
5616 options->backwards_compatible = major * 10000 + minor * 100 + patch;
5617 }
5618 else if (streq(p[0], "setenv-safe") && p[1] && !p[3])
5619 {
5621 setenv_str_safe(es, p[1], p[2] ? p[2] : "");
5622 }
5623 else if (streq(p[0], "script-security") && p[1] && !p[2])
5624 {
5626 int security;
5627 if (atoi_constrained(p[1], &security, p[0], SSEC_NONE, SSEC_PW_ENV, msglevel))
5628 {
5629 script_security_set(security);
5630 }
5631 }
5632 else if (streq(p[0], "mssfix") && !p[3])
5633 {
5635 if (p[1])
5636 {
5637 int mssfix;
5638 if (!atoi_constrained(p[1], &mssfix, p[0], 0, UINT16_MAX, msglevel))
5639 {
5640 goto err;
5641 }
5642 if (mssfix != 0 && mssfix < TLS_CHANNEL_MTU_MIN)
5643 {
5644 msg(msglevel, "mssfix needs to be >= %d, not %d", TLS_CHANNEL_MTU_MIN, mssfix);
5645 goto err;
5646 }
5647
5648 /* value specified, assume encapsulation is not
5649 * included unless "mtu" follows later */
5650 options->ce.mssfix = mssfix;
5651 options->ce.mssfix_encap = false;
5652 options->ce.mssfix_default = false;
5653 }
5654 else
5655 {
5656 /* Set MTU to default values */
5657 options->ce.mssfix_default = true;
5658 options->ce.mssfix_encap = true;
5659 options->ce.mssfix_fixed = false;
5660 }
5661
5662 if (p[2] && streq(p[2], "mtu"))
5663 {
5664 options->ce.mssfix_encap = true;
5665 }
5666 else if (p[2] && streq(p[2], "fixed"))
5667 {
5668 options->ce.mssfix_fixed = true;
5669 }
5670 else if (p[2])
5671 {
5672 msg(msglevel, "Unknown parameter to --mssfix: %s", p[2]);
5673 }
5674 }
5675 else if (streq(p[0], "disable-occ") && !p[1])
5676 {
5678 options->occ = false;
5679 }
5680 else if (streq(p[0], "server") && p[1] && p[2] && !p[4])
5681 {
5682 const int lev = M_WARN;
5683 bool error = false;
5684 in_addr_t network, netmask;
5685
5687 network = get_ip_addr(p[1], lev, &error);
5688 netmask = get_ip_addr(p[2], lev, &error);
5689 if (error || !network || !netmask)
5690 {
5691 msg(msglevel, "error parsing --server parameters");
5692 goto err;
5693 }
5694 options->server_defined = true;
5695 options->server_network = network;
5696 options->server_netmask = netmask;
5697
5698 if (p[3])
5699 {
5700 if (streq(p[3], "nopool"))
5701 {
5703 }
5704 else
5705 {
5706 msg(msglevel, "error parsing --server: %s is not a recognized flag", p[3]);
5707 goto err;
5708 }
5709 }
5710 }
5711 else if (streq(p[0], "server-ipv6") && p[1] && !p[2])
5712 {
5713 const int lev = M_WARN;
5714 struct in6_addr network;
5715 unsigned int netbits = 0;
5716
5718 if (!get_ipv6_addr(p[1], &network, &netbits, lev))
5719 {
5720 msg(msglevel, "error parsing --server-ipv6 parameter");
5721 goto err;
5722 }
5723 if (netbits < 64 || netbits > 124)
5724 {
5725 msg(msglevel, "--server-ipv6 settings: network must be between /64 and /124 (not /%u)",
5726 netbits);
5727
5728 goto err;
5729 }
5731 options->server_network_ipv6 = network;
5732 options->server_netbits_ipv6 = netbits;
5733 }
5734 else if (streq(p[0], "server-bridge") && p[1] && p[2] && p[3] && p[4] && !p[5])
5735 {
5736 const int lev = M_WARN;
5737 bool error = false;
5738 in_addr_t ip, netmask, pool_start, pool_end;
5739
5741 ip = get_ip_addr(p[1], lev, &error);
5742 netmask = get_ip_addr(p[2], lev, &error);
5743 pool_start = get_ip_addr(p[3], lev, &error);
5744 pool_end = get_ip_addr(p[4], lev, &error);
5745 if (error || !ip || !netmask || !pool_start || !pool_end)
5746 {
5747 msg(msglevel, "error parsing --server-bridge parameters");
5748 goto err;
5749 }
5752 options->server_bridge_netmask = netmask;
5753 options->server_bridge_pool_start = pool_start;
5754 options->server_bridge_pool_end = pool_end;
5755 }
5756 else if (streq(p[0], "server-bridge") && p[1] && streq(p[1], "nogw") && !p[2])
5757 {
5761 }
5762 else if (streq(p[0], "server-bridge") && !p[1])
5763 {
5766 }
5767 else if (streq(p[0], "push") && p[1] && !p[2])
5768 {
5770 push_options(options, &p[1], msglevel, &options->gc);
5771 }
5772 else if (streq(p[0], "push-reset") && !p[1])
5773 {
5776 }
5777 else if (streq(p[0], "push-remove") && p[1] && !p[2])
5778 {
5780 msg(D_PUSH, "PUSH_REMOVE '%s'", p[1]);
5782 }
5783 else if (streq(p[0], "ifconfig-pool") && p[1] && p[2] && !p[4])
5784 {
5785 const int lev = M_WARN;
5786 bool error = false;
5787 in_addr_t start, end, netmask = 0;
5788
5790 start = get_ip_addr(p[1], lev, &error);
5791 end = get_ip_addr(p[2], lev, &error);
5792 if (p[3])
5793 {
5794 netmask = get_ip_addr(p[3], lev, &error);
5795 }
5796 if (error)
5797 {
5798 msg(msglevel, "error parsing --ifconfig-pool parameters");
5799 goto err;
5800 }
5801 if (!ifconfig_pool_verify_range(msglevel, start, end))
5802 {
5803 goto err;
5804 }
5805
5809 if (netmask)
5810 {
5811 options->ifconfig_pool_netmask = netmask;
5812 }
5813 }
5814 else if (streq(p[0], "ifconfig-pool-persist") && p[1] && !p[3])
5815 {
5818 if (p[2])
5819 {
5821 }
5822 }
5823 else if (streq(p[0], "ifconfig-ipv6-pool") && p[1] && !p[2])
5824 {
5825 const int lev = M_WARN;
5826 struct in6_addr network;
5827 unsigned int netbits = 0;
5828
5830 if (!get_ipv6_addr(p[1], &network, &netbits, lev))
5831 {
5832 msg(msglevel, "error parsing --ifconfig-ipv6-pool parameters");
5833 goto err;
5834 }
5835 if (netbits < 64 || netbits > 124)
5836 {
5837 msg(msglevel,
5838 "--ifconfig-ipv6-pool settings: network must be between /64 and /124 (not /%u)",
5839 netbits);
5840 goto err;
5841 }
5842
5846 }
5847 else if (streq(p[0], "hash-size") && p[1] && p[2] && !p[4])
5848 {
5849 int real, virtual;
5850
5852 if (!atoi_constrained(p[1], &real, "hash-size real", 1, INT_MAX, msglevel)
5853 || !atoi_constrained(p[2], &virtual, "hash-size virtual", 1, INT_MAX, msglevel))
5854 {
5855 goto err;
5856 }
5857 options->real_hash_size = (uint32_t)real;
5858 options->virtual_hash_size = (uint32_t)virtual;
5859
5860 if (p[3])
5861 {
5862 int sid;
5863 if (!atoi_constrained(p[3], &sid, "hash-size sid", 1, INT_MAX, msglevel))
5864 {
5865 goto err;
5866 }
5867 options->sid_hash_size = (uint32_t)sid;
5868 }
5869 }
5870 else if (streq(p[0], "connect-freq") && p[1] && p[2] && !p[3])
5871 {
5872 int cf_max, cf_per;
5873
5875 if (!atoi_constrained(p[1], &cf_max, "connect-freq n", 1, INT_MAX, msglevel)
5876 || !atoi_constrained(p[2], &cf_per, "connect-freq seconds", 1, INT_MAX, msglevel))
5877 {
5878 goto err;
5879 }
5880 options->cf_max = cf_max;
5881 options->cf_per = cf_per;
5882 }
5883 else if (streq(p[0], "connect-freq-initial") && p[1] && p[2] && !p[3])
5884 {
5885 int cf_max, cf_per;
5886
5888 if (!atoi_constrained(p[1], &cf_max, "connect-freq-initial n", 1, INT_MAX, msglevel)
5889 || !atoi_constrained(p[2], &cf_per, "connect-freq-initial seconds", 1, INT_MAX, msglevel))
5890 {
5891 goto err;
5892 }
5893 options->cf_initial_max = cf_max;
5894 options->cf_initial_per = cf_per;
5895 }
5896 else if (streq(p[0], "max-clients") && p[1] && !p[2])
5897 {
5899 if (!atoi_constrained(p[1], (int *)&options->max_clients, p[0], 1, MAX_PEER_ID - 1, msglevel))
5900 {
5901 goto err;
5902 }
5903 }
5904 else if (streq(p[0], "max-routes-per-client") && p[1] && !p[2])
5905 {
5907 atoi_constrained(p[1], &options->max_routes_per_client, p[0], 1, INT_MAX, msglevel);
5908 }
5909 else if (streq(p[0], "client-cert-not-required") && !p[1])
5910 {
5912 msg(M_FATAL,
5913 "REMOVED OPTION: --client-cert-not-required, use '--verify-client-cert none' instead");
5914 }
5915 else if (streq(p[0], "verify-client-cert") && !p[2])
5916 {
5918
5919 /* Reset any existing flags */
5920 options->ssl_flags &= ~SSLF_CLIENT_CERT_OPTIONAL;
5921 options->ssl_flags &= ~SSLF_CLIENT_CERT_NOT_REQUIRED;
5922 if (p[1])
5923 {
5924 if (streq(p[1], "none"))
5925 {
5927 }
5928 else if (streq(p[1], "optional"))
5929 {
5931 }
5932 else if (!streq(p[1], "require"))
5933 {
5934 msg(msglevel,
5935 "parameter to --verify-client-cert must be 'none', 'optional' or 'require'");
5936 goto err;
5937 }
5938 }
5939 }
5940 else if (streq(p[0], "username-as-common-name") && !p[1])
5941 {
5944 }
5945 else if (streq(p[0], "auth-user-pass-optional") && !p[1])
5946 {
5949 }
5950 else if (streq(p[0], "opt-verify") && !p[1])
5951 {
5953 msg(M_INFO, "DEPRECATED OPTION: --opt-verify was removed in OpenVPN 2.7.");
5954 }
5955 else if (streq(p[0], "auth-user-pass-verify") && p[1])
5956 {
5958 if (!no_more_than_n_args(msglevel, p, 3, NM_QUOTE_HINT))
5959 {
5960 goto err;
5961 }
5962 if (p[2])
5963 {
5964 if (streq(p[2], "via-env"))
5965 {
5967 }
5968 else if (streq(p[2], "via-file"))
5969 {
5971 }
5972 else
5973 {
5974 msg(msglevel,
5975 "second parm to --auth-user-pass-verify must be 'via-env' or 'via-file'");
5976 goto err;
5977 }
5978 }
5979 else
5980 {
5981 msg(msglevel,
5982 "--auth-user-pass-verify requires a second parameter ('via-env' or 'via-file')");
5983 goto err;
5984 }
5986 "auth-user-pass-verify", true);
5987 }
5988 else if (streq(p[0], "auth-gen-token"))
5989 {
5992 options->auth_token_lifetime = p[1] ? positive_atoi(p[1], msglevel) : 0;
5993
5994 for (int i = 2; i < MAX_PARMS && p[i] != NULL; i++)
5995 {
5996 /* the second parameter can be the renewal time */
5997 if (i == 2 && valid_integer(p[i], true))
5998 {
5999 options->auth_token_renewal = positive_atoi(p[i], msglevel);
6000 }
6001 else if (streq(p[i], "external-auth"))
6002 {
6004 }
6005 else
6006 {
6007 msg(msglevel, "Invalid argument to auth-gen-token: %s (%d)", p[i], i);
6008 }
6009 }
6010 }
6011 else if (streq(p[0], "auth-gen-token-secret") && p[1] && !p[2])
6012 {
6016 }
6017 else if (streq(p[0], "client-connect") && p[1])
6018 {
6020 if (!no_more_than_n_args(msglevel, p, 2, NM_QUOTE_HINT))
6021 {
6022 goto err;
6023 }
6024 set_user_script(options, &options->client_connect_script, p[1], "client-connect", true);
6025 }
6026 else if (streq(p[0], "client-crresponse") && p[1])
6027 {
6029 if (!no_more_than_n_args(msglevel, p, 2, NM_QUOTE_HINT))
6030 {
6031 goto err;
6032 }
6033 set_user_script(options, &options->client_crresponse_script, p[1], "client-crresponse",
6034 true);
6035 }
6036 else if (streq(p[0], "client-disconnect") && p[1])
6037 {
6039 if (!no_more_than_n_args(msglevel, p, 2, NM_QUOTE_HINT))
6040 {
6041 goto err;
6042 }
6043 set_user_script(options, &options->client_disconnect_script, p[1], "client-disconnect",
6044 true);
6045 }
6046 else if (streq(p[0], "learn-address") && p[1])
6047 {
6049 if (!no_more_than_n_args(msglevel, p, 2, NM_QUOTE_HINT))
6050 {
6051 goto err;
6052 }
6053 set_user_script(options, &options->learn_address_script, p[1], "learn-address", true);
6054 }
6055 else if (streq(p[0], "tmp-dir") && p[1] && !p[2])
6056 {
6058 options->tmp_dir = p[1];
6059 }
6060 else if (streq(p[0], "client-config-dir") && p[1] && !p[2])
6061 {
6063 options->client_config_dir = p[1];
6064 }
6065 else if (streq(p[0], "ccd-exclusive") && !p[1])
6066 {
6068 options->ccd_exclusive = true;
6069 }
6070 else if (streq(p[0], "bcast-buffers") && p[1] && !p[2])
6071 {
6073 atoi_constrained(p[1], &options->n_bcast_buf, p[0], 1, MBUF_SIZE_MAX, msglevel);
6074 }
6075 else if (streq(p[0], "tcp-queue-limit") && p[1] && !p[2])
6076 {
6078 atoi_constrained(p[1], &options->tcp_queue_limit, p[0], 1, INT_MAX, msglevel);
6079 }
6080#if PORT_SHARE
6081 else if (streq(p[0], "port-share") && p[1] && p[2] && !p[4])
6082 {
6084 options->port_share_host = p[1];
6085 options->port_share_port = p[2];
6086 options->port_share_journal_dir = p[3];
6087 }
6088#endif
6089 else if (streq(p[0], "client-to-client") && !p[1])
6090 {
6092 options->enable_c2c = true;
6093 }
6094 else if (streq(p[0], "duplicate-cn") && !p[1])
6095 {
6097 options->duplicate_cn = true;
6098 }
6099 else if (streq(p[0], "iroute") && p[1] && !p[3])
6100 {
6102 option_iroute(options, p[1], p[2], msglevel);
6103 }
6104 else if (streq(p[0], "iroute-ipv6") && p[1] && !p[2])
6105 {
6107 option_iroute_ipv6(options, p[1], msglevel);
6108 }
6109 else if (streq(p[0], "ifconfig-push") && p[1] && p[2] && !p[4])
6110 {
6111 in_addr_t local, remote_netmask;
6112
6114 local = getaddr(GETADDR_HOST_ORDER | GETADDR_RESOLVE, p[1], 0, NULL, NULL);
6115 remote_netmask = getaddr(GETADDR_HOST_ORDER | GETADDR_RESOLVE, p[2], 0, NULL, NULL);
6116 if (local && remote_netmask)
6117 {
6120 options->push_ifconfig_remote_netmask = remote_netmask;
6121 if (p[3])
6122 {
6124 getaddr(GETADDR_HOST_ORDER | GETADDR_RESOLVE, p[3], 0, NULL, NULL);
6125 }
6126 }
6127 else
6128 {
6129 msg(msglevel, "cannot parse --ifconfig-push addresses");
6130 goto err;
6131 }
6132 }
6133 else if (streq(p[0], "ifconfig-push-constraint") && p[1] && p[2] && !p[3])
6134 {
6135 in_addr_t network, netmask;
6136
6138 network = getaddr(GETADDR_HOST_ORDER | GETADDR_RESOLVE, p[1], 0, NULL, NULL);
6139 netmask = getaddr(GETADDR_HOST_ORDER, p[2], 0, NULL, NULL);
6140 if (network && netmask)
6141 {
6145 }
6146 else
6147 {
6148 msg(msglevel, "cannot parse --ifconfig-push-constraint addresses");
6149 goto err;
6150 }
6151 }
6152 else if (streq(p[0], "ifconfig-ipv6-push") && p[1] && !p[3])
6153 {
6154 struct in6_addr local, remote;
6155 unsigned int netbits;
6156
6158
6159 if (!get_ipv6_addr(p[1], &local, &netbits, msglevel))
6160 {
6161 msg(msglevel, "cannot parse --ifconfig-ipv6-push addresses");
6162 goto err;
6163 }
6164
6165 if (p[2])
6166 {
6167 if (!get_ipv6_addr(p[2], &remote, NULL, msglevel))
6168 {
6169 msg(msglevel, "cannot parse --ifconfig-ipv6-push addresses");
6170 goto err;
6171 }
6172 }
6173 else
6174 {
6176 || !get_ipv6_addr(options->ifconfig_ipv6_local, &remote, NULL, msglevel))
6177 {
6178 msg(msglevel,
6179 "second argument to --ifconfig-ipv6-push missing and no global --ifconfig-ipv6 address set");
6180 goto err;
6181 }
6182 }
6183
6189 }
6190 else if (streq(p[0], "disable") && !p[1])
6191 {
6193 options->disable = true;
6194 }
6195 else if (streq(p[0], "override-username") && p[1] && !p[2])
6196 {
6198 if (strlen(p[1]) >= USER_PASS_LEN)
6199 {
6200 msg(msglevel,
6201 "override-username exceeds the maximum length of %d "
6202 "characters",
6203 USER_PASS_LEN - 1);
6204
6205 /* disable the connection since ignoring the request to
6206 * set another username might cause serious problems */
6207 options->disable = true;
6208 }
6209 else
6210 {
6211 options->override_username = p[1];
6212 }
6213 }
6214 else if (streq(p[0], "tcp-nodelay") && !p[1])
6215 {
6218 }
6219 else if (streq(p[0], "stale-routes-check") && p[1] && !p[3])
6220 {
6221 int ageing_time, check_interval;
6222
6224 if (!atoi_constrained(p[1], &ageing_time, "stale-routes-check age", 1, INT_MAX, msglevel))
6225 {
6226 goto err;
6227 }
6228
6229 if (p[2])
6230 {
6231 if (!atoi_constrained(p[2], &check_interval,
6232 "stale-routes-check interval", 1, INT_MAX, msglevel))
6233 {
6234 goto err;
6235 }
6236 }
6237 else
6238 {
6239 check_interval = ageing_time;
6240 }
6241
6242 options->stale_routes_ageing_time = ageing_time;
6243 options->stale_routes_check_interval = check_interval;
6244 }
6245
6246 else if (streq(p[0], "client") && !p[1])
6247 {
6249 options->client = true;
6250 }
6251 else if (streq(p[0], "pull") && !p[1])
6252 {
6254 options->pull = true;
6255 }
6256 else if (streq(p[0], "push-continuation") && p[1] && !p[2])
6257 {
6259 atoi_constrained(p[1], &options->push_continuation, p[0], 0, 2, msglevel);
6260 }
6261 else if (streq(p[0], "auth-user-pass") && !p[2])
6262 {
6265 if (p[1] && streq(p[1], "username-only"))
6266 {
6268 options->auth_user_pass_file = "stdin";
6269 }
6270 else if (p[1])
6271 {
6274 }
6275 else
6276 {
6277 options->auth_user_pass_file = "stdin";
6278 }
6279 }
6280 else if (streq(p[0], "auth-retry") && p[1] && !p[2])
6281 {
6283 auth_retry_set(msglevel, p[1]);
6284 }
6285#ifdef ENABLE_MANAGEMENT
6286 else if (streq(p[0], "static-challenge") && p[1] && p[2] && !p[4])
6287 {
6290 if (boolean_flag(p[2], "static-challenge echo", msglevel))
6291 {
6293 }
6294 if (p[3] && streq(p[3], "concat"))
6295 {
6297 }
6298 else if (p[3] && !streq(p[3], "scrv1"))
6299 {
6300 msg(msglevel, "--static-challenge: unknown format indicator '%s'", p[3]);
6301 goto err;
6302 }
6303 }
6304#endif
6305 else if (streq(p[0], "msg-channel") && p[1])
6306 {
6307#ifdef _WIN32
6309 HANDLE process = GetCurrentProcess();
6310 HANDLE handle = (HANDLE)((intptr_t)atoll(p[1]));
6311 if (!DuplicateHandle(process, handle, process, &options->msg_channel, 0, FALSE,
6312 DUPLICATE_CLOSE_SOURCE | DUPLICATE_SAME_ACCESS))
6313 {
6314 msg(msglevel, "could not duplicate service pipe handle");
6315 goto err;
6316 }
6318#else /* ifdef _WIN32 */
6319 msg(msglevel, "--msg-channel is only supported on Windows");
6320 goto err;
6321#endif
6322 }
6323#ifdef _WIN32
6324 else if (streq(p[0], "win-sys") && p[1] && !p[2])
6325 {
6327 if (streq(p[1], "env"))
6328 {
6329 msg(M_INFO, "NOTE: --win-sys env is default from OpenVPN 2.3. "
6330 "This entry will now be ignored. "
6331 "Please remove this entry from your configuration file.");
6332 }
6333 else
6334 {
6335 set_win_sys_path(p[1], es);
6336 }
6337 }
6338 else if (streq(p[0], "route-method") && p[1] && !p[2])
6339 {
6341 if (streq(p[1], "adaptive"))
6342 {
6344 }
6345 else if (streq(p[1], "ipapi"))
6346 {
6348 }
6349 else if (streq(p[1], "exe"))
6350 {
6352 }
6353 else
6354 {
6355 msg(msglevel, "--route method must be 'adaptive', 'ipapi', or 'exe'");
6356 goto err;
6357 }
6358 }
6359 else if (streq(p[0], "ip-win32") && p[1] && !p[4])
6360 {
6361 const int index = ascii2ipset(p[1]);
6362 struct tuntap_options *to = &options->tuntap_options;
6363
6365
6366 if (index < 0)
6367 {
6368 msg(msglevel, "Bad --ip-win32 method: '%s'. Allowed methods: %s", p[1],
6370 goto err;
6371 }
6372
6373 if (index == IPW32_SET_ADAPTIVE)
6374 {
6376 }
6377
6378 if (index == IPW32_SET_DHCP_MASQ)
6379 {
6380 if (p[2])
6381 {
6382 if (!streq(p[2], "default"))
6383 {
6384 int offset;
6385
6386 if (!atoi_constrained(p[2], &offset, "ip-win32 offset", -256, 256, msglevel))
6387 {
6388 goto err;
6389 }
6390 to->dhcp_masq_custom_offset = true;
6391 to->dhcp_masq_offset = offset;
6392 }
6393
6394 if (p[3])
6395 {
6396 if (!atoi_constrained(p[3], &to->dhcp_lease_time,
6397 "ip-win32 lease time", 30, INT_MAX, msglevel))
6398 {
6399 goto err;
6400 }
6401 }
6402 }
6403 }
6404 to->ip_win32_type = index;
6405 to->ip_win32_defined = true;
6406 }
6407#endif /* ifdef _WIN32 */
6408 else if (streq(p[0], "dns-updown") && p[1])
6409 {
6411 if (!no_more_than_n_args(msglevel, p, 2, NM_QUOTE_HINT))
6412 {
6413 goto err;
6414 }
6415 struct dns_options *dns = &options->dns_options;
6416 if (streq(p[1], "disable"))
6417 {
6418 dns->updown = NULL;
6420 }
6421 else if (streq(p[1], "force"))
6422 {
6423 /* force dns-updown run, even if a --up script is defined */
6424 if (!dns_updown_user_set(dns))
6425 {
6426 dns->updown = DEFAULT_DNS_UPDOWN;
6428 }
6429 }
6430 else
6431 {
6432 if (dns->updown && streq(dns->updown, DEFAULT_DNS_UPDOWN))
6433 {
6434 /* Unset the default command to prevent warnings */
6435 dns->updown = NULL;
6436 }
6437 set_user_script(options, &dns->updown, p[1], p[0], false);
6439 }
6440 }
6441 else if (streq(p[0], "dns") && p[1])
6442 {
6444 if (!check_dns_option(options, p, msglevel, pull_mode))
6445 {
6446 goto err;
6447 }
6448 }
6449 else if (streq(p[0], "dhcp-option") && p[1])
6450 {
6452#if defined(_WIN32) || defined(TARGET_ANDROID)
6454#endif
6456
6457 bool dhcp_optional = false;
6458
6459 if ((streq(p[1], "DOMAIN") || streq(p[1], "ADAPTER_DOMAIN_SUFFIX")) && p[2] && !p[3])
6460 {
6461 if (!validate_domain(p[2]))
6462 {
6463 msg(msglevel, "--dhcp-option %s contains invalid characters", p[1]);
6464 goto err;
6465 }
6466
6467 dhcp->domain = p[2];
6468 dhcp_optional = true;
6469 }
6470 else if (streq(p[1], "DOMAIN-SEARCH") && p[2] && !p[3])
6471 {
6472 if (!validate_domain(p[2]))
6473 {
6474 msg(msglevel, "--dhcp-option %s contains invalid characters", p[1]);
6475 goto err;
6476 }
6477
6478 if (dhcp->domain_search_list_len < N_SEARCH_LIST_LEN)
6479 {
6480 dhcp->domain_search_list[dhcp->domain_search_list_len++] = p[2];
6481 }
6482 else
6483 {
6484 msg(msglevel, "--dhcp-option %s: maximum of %d search entries can be specified",
6485 p[1], N_SEARCH_LIST_LEN);
6486 }
6487 dhcp_optional = true;
6488 }
6489 else if ((streq(p[1], "DNS") || streq(p[1], "DNS6")) && p[2] && !p[3]
6490 && (!strstr(p[2], ":") || ipv6_addr_safe(p[2])))
6491 {
6492 if (strstr(p[2], ":"))
6493 {
6494 dhcp_option_dns6_parse(p[2], dhcp->dns6, &dhcp->dns6_len, msglevel);
6495 }
6496 else
6497 {
6498 dhcp_option_address_parse("DNS", p[2], dhcp->dns, &dhcp->dns_len, msglevel);
6499 dhcp_optional = true;
6500 }
6501 }
6502#if defined(_WIN32) || defined(TARGET_ANDROID)
6503 else if (streq(p[1], "NBS") && p[2] && !p[3])
6504 {
6505 o->netbios_scope = p[2];
6507 }
6508 else if (streq(p[1], "NBT") && p[2] && !p[3])
6509 {
6510 int t = atoi_warn(p[2], msglevel);
6511 if (!(t == 1 || t == 2 || t == 4 || t == 8))
6512 {
6513 msg(msglevel, "--dhcp-option NBT: parameter (%d) must be 1, 2, 4, or 8", t);
6514 goto err;
6515 }
6516 o->netbios_node_type = (uint8_t)t;
6518 }
6519 else if (streq(p[1], "WINS") && p[2] && !p[3])
6520 {
6521 dhcp_option_address_parse("WINS", p[2], o->wins, &o->wins_len, msglevel);
6523 }
6524 else if (streq(p[1], "NTP") && p[2] && !p[3])
6525 {
6526 dhcp_option_address_parse("NTP", p[2], o->ntp, &o->ntp_len, msglevel);
6528 }
6529 else if (streq(p[1], "NBDD") && p[2] && !p[3])
6530 {
6531 dhcp_option_address_parse("NBDD", p[2], o->nbdd, &o->nbdd_len, msglevel);
6533 }
6534 else if (streq(p[1], "DISABLE-NBT") && !p[2])
6535 {
6536 o->disable_nbt = 1;
6538 }
6539#if defined(TARGET_ANDROID)
6540 else if (streq(p[1], "PROXY_HTTP") && p[3] && !p[4])
6541 {
6542 o->http_proxy_port = positive_atoi(p[3], msglevel);
6543 o->http_proxy = p[2];
6544 }
6545#endif
6546 else
6547 {
6548 msg(msglevel, "--dhcp-option: unknown option type '%s' or missing or unknown parameter",
6549 p[1]);
6550 goto err;
6551 }
6552#else /* if defined(_WIN32) || defined(TARGET_ANDROID) */
6553 setenv_foreign_option(options, p[1], p[2], es);
6554#endif /* if defined(_WIN32) || defined(TARGET_ANDROID) */
6555
6556 if (dhcp_optional)
6557 {
6558#if defined(_WIN32) || defined(TARGET_ANDROID)
6560#endif
6561 }
6562 }
6563#ifdef _WIN32
6564 else if (streq(p[0], "show-adapters") && !p[1])
6565 {
6568 openvpn_exit(OPENVPN_EXIT_STATUS_GOOD); /* exit point */
6569 }
6570 else if (streq(p[0], "show-net") && !p[1])
6571 {
6575 openvpn_exit(OPENVPN_EXIT_STATUS_GOOD); /* exit point */
6576 }
6577 else if (streq(p[0], "show-net-up") && !p[1])
6578 {
6580 options->show_net_up = true;
6581 }
6582 else if (streq(p[0], "tap-sleep") && p[1] && !p[2])
6583 {
6585 if (!atoi_constrained(p[1], &options->tuntap_options.tap_sleep, p[0], 0, 255, msglevel))
6586 {
6587 goto err;
6588 }
6589 }
6590 else if (streq(p[0], "dhcp-renew") && !p[1])
6591 {
6594 }
6595 else if (streq(p[0], "dhcp-pre-release") && !p[1])
6596 {
6600 }
6601 else if (streq(p[0], "dhcp-release") && !p[1])
6602 {
6603 msg(M_WARN, "Obsolete option --dhcp-release detected. This is now on by default");
6604 }
6605 else if (streq(p[0], "dhcp-internal") && p[1] && !p[2]) /* standalone method for internal use */
6606 {
6607 unsigned int adapter_index;
6610 adapter_index = atou(p[1]);
6613 {
6614 dhcp_release_by_adapter_index(adapter_index);
6615 }
6617 {
6618 dhcp_renew_by_adapter_index(adapter_index);
6619 }
6620 openvpn_exit(OPENVPN_EXIT_STATUS_GOOD); /* exit point */
6621 }
6622 else if (streq(p[0], "register-dns") && !p[1])
6623 {
6626 }
6627 else if (streq(p[0], "block-outside-dns") && !p[1])
6628 {
6630 options->block_outside_dns = true;
6631 }
6632 else if (streq(p[0], "rdns-internal") && !p[1])
6633 /* standalone method for internal use
6634 *
6635 * (if --register-dns is set, openvpn needs to call itself in a
6636 * sub-process to execute the required functions in a non-blocking
6637 * way, and uses --rdns-internal to signal that to itself)
6638 */
6639 {
6643 {
6645 }
6646 openvpn_exit(OPENVPN_EXIT_STATUS_GOOD); /* exit point */
6647 }
6648 else if (streq(p[0], "show-valid-subnets") && !p[1])
6649 {
6652 openvpn_exit(OPENVPN_EXIT_STATUS_GOOD); /* exit point */
6653 }
6654 else if (streq(p[0], "pause-exit") && !p[1])
6655 {
6658 }
6659 else if (streq(p[0], "service") && p[1] && !p[3])
6660 {
6662 options->exit_event_name = p[1];
6663 if (p[2])
6664 {
6665 options->exit_event_initial_state = boolean_flag(p[2], "service state", msglevel);
6666 }
6667 }
6668 else if (streq(p[0], "allow-nonadmin") && !p[2])
6669 {
6672 openvpn_exit(OPENVPN_EXIT_STATUS_GOOD); /* exit point */
6673 }
6674 else if (streq(p[0], "user") && p[1] && !p[2])
6675 {
6677 msg(M_WARN, "NOTE: --user option is not implemented on Windows");
6678 }
6679 else if (streq(p[0], "group") && p[1] && !p[2])
6680 {
6682 msg(M_WARN, "NOTE: --group option is not implemented on Windows");
6683 }
6684#else /* ifdef _WIN32 */
6685 else if (streq(p[0], "user") && p[1] && !p[2])
6686 {
6688 options->username = p[1];
6689 }
6690 else if (streq(p[0], "group") && p[1] && !p[2])
6691 {
6693 options->groupname = p[1];
6694 }
6695 else if (streq(p[0], "dhcp-option") && p[1] && !p[3])
6696 {
6698 setenv_foreign_option(options, p[1], p[2], es);
6699 }
6700 else if (streq(p[0], "route-method") && p[1] && !p[2])
6701 {
6703 /* ignore when pushed to non-Windows OS */
6704 }
6705#endif /* ifdef _WIN32 */
6706#if PASSTOS_CAPABILITY
6707 else if (streq(p[0], "passtos") && !p[1])
6708 {
6710 options->passtos = true;
6711 }
6712#endif
6713 else if (streq(p[0], "allow-compression") && p[1] && !p[2])
6714 {
6716
6717 if (streq(p[1], "no"))
6718 {
6721 {
6722 msg(msglevel, "'--allow-compression no' conflicts with "
6723 " enabling compression");
6724 }
6725 }
6727 {
6728 /* Also printed on a push to hint at configuration problems */
6729 msg(msglevel,
6730 "Cannot set allow-compression to '%s' "
6731 "after set to 'no'",
6732 p[1]);
6733 goto err;
6734 }
6735 else if (streq(p[1], "asym"))
6736 {
6738 }
6739 else if (streq(p[1], "yes"))
6740 {
6741 msg(M_WARN,
6742 "DEPRECATED OPTION: \"--allow-compression yes\" has been removed. "
6743 "We will use \"asym\" mode instead. See the manual page for more information.");
6744
6746 }
6747 else
6748 {
6749 msg(msglevel,
6750 "bad allow-compression option: %s -- "
6751 "must be 'yes', 'no', or 'asym'",
6752 p[1]);
6753 goto err;
6754 }
6755 }
6756 else if (streq(p[0], "comp-lzo") && !p[2])
6757 {
6759
6760 /* All lzo variants do not use swap */
6761 options->comp.flags &= ~COMP_F_SWAP;
6763
6764 if (p[1])
6765 {
6766 if (streq(p[1], "no"))
6767 {
6769 }
6770 /* There is no actual difference anymore between these variants.
6771 * We never compress. On the server side we replace this with
6772 * --compress migrate later anyway.
6773 */
6774 else if (!(streq(p[1], "yes") || streq(p[1], "adaptive")))
6775 {
6776 msg(msglevel, "bad comp-lzo option: %s -- must be 'yes', 'no', or 'adaptive'",
6777 p[1]);
6778 goto err;
6779 }
6780 }
6782 }
6783 else if (streq(p[0], "comp-noadapt") && !p[1])
6784 {
6785 /* NO-OP since we never compress anymore */
6786 }
6787 else if (streq(p[0], "compress") && !p[2])
6788 {
6790 const char *alg = "stub";
6791 if (p[1])
6792 {
6793 alg = p[1];
6794 }
6795
6796 if (streq(alg, "stub"))
6797 {
6800 }
6801 else if (streq(alg, "stub-v2"))
6802 {
6805 }
6806 else if (streq(alg, "migrate"))
6807 {
6810 }
6811 else if (streq(alg, "lzo"))
6812 {
6814 options->comp.flags &= ~COMP_F_SWAP;
6815 }
6816 else if (streq(alg, "lz4"))
6817 {
6820 }
6821 else if (streq(alg, "lz4-v2"))
6822 {
6824 }
6825 else
6826 {
6827 msg(msglevel, "bad comp option: %s", alg);
6828 goto err;
6829 }
6830
6832 }
6833 else if (streq(p[0], "show-ciphers") && !p[1])
6834 {
6836 options->show_ciphers = true;
6837 }
6838 else if (streq(p[0], "show-digests") && !p[1])
6839 {
6841 options->show_digests = true;
6842 }
6843 else if (streq(p[0], "show-engines") && !p[1])
6844 {
6846 options->show_engines = true;
6847 }
6848 else if (streq(p[0], "key-direction") && p[1] && !p[2])
6849 {
6850 int key_direction;
6851
6853
6854 key_direction = ascii2keydirection(msglevel, p[1]);
6855 if (key_direction >= 0)
6856 {
6857 if (permission_mask & OPT_P_GENERAL)
6858 {
6859 options->key_direction = key_direction;
6860 }
6861 else if (permission_mask & OPT_P_CONNECTION)
6862 {
6863 options->ce.key_direction = key_direction;
6864 }
6865 }
6866 else
6867 {
6868 goto err;
6869 }
6870 }
6871 else if (streq(p[0], "genkey") && !p[4])
6872 {
6874 options->genkey = true;
6875 if (!p[1])
6876 {
6878 }
6879 else
6880 {
6881 if (streq(p[1], "secret") || streq(p[1], "tls-auth") || streq(p[1], "tls-crypt"))
6882 {
6884 }
6885 else if (streq(p[1], "tls-crypt-v2-server"))
6886 {
6888 }
6889 else if (streq(p[1], "tls-crypt-v2-client"))
6890 {
6892 if (p[3])
6893 {
6894 options->genkey_extra_data = p[3];
6895 }
6896 }
6897 else if (streq(p[1], "auth-token"))
6898 {
6900 }
6901 else
6902 {
6903 msg(msglevel, "unknown --genkey type: %s", p[1]);
6904 }
6905 }
6906 if (p[2])
6907 {
6908 options->genkey_filename = p[2];
6909 }
6910 }
6911 else if (streq(p[0], "auth") && p[1] && !p[2])
6912 {
6914 options->authname = p[1];
6915 }
6916 else if (streq(p[0], "cipher") && p[1] && !p[2])
6917 {
6919 options->ciphername = p[1];
6920 }
6921 else if (streq(p[0], "data-ciphers-fallback") && p[1] && !p[2])
6922 {
6924 options->ciphername = p[1];
6926 }
6927 else if ((streq(p[0], "data-ciphers") || streq(p[0], "ncp-ciphers")) && p[1] && !p[2])
6928 {
6930 if (streq(p[0], "ncp-ciphers"))
6931 {
6932 msg(M_INFO, "Note: Treating option '--ncp-ciphers' as "
6933 " '--data-ciphers' (renamed in OpenVPN 2.5).");
6934 }
6935 options->ncp_ciphers = p[1];
6936 }
6937 else if (streq(p[0], "key-derivation") && p[1])
6938 {
6939 /* NCP only option that is pushed by the server to enable EKM,
6940 * should not be used by normal users in config files*/
6942 if (streq(p[1], "tls-ekm"))
6943 {
6945 }
6946 else
6947 {
6948 msg(msglevel, "Unknown key-derivation method %s", p[1]);
6949 }
6950 }
6951 else if (streq(p[0], "protocol-flags") && p[1])
6952 {
6953 /* NCP only option that is pushed by the server to enable protocol
6954 * features that are negotiated, should not be used by normal users
6955 * in config files */
6957 for (size_t j = 1; j < MAX_PARMS && p[j] != NULL; j++)
6958 {
6959 if (streq(p[j], "cc-exit"))
6960 {
6962 }
6963 else if (streq(p[j], "tls-ekm"))
6964 {
6966 }
6967 else if (streq(p[j], "dyn-tls-crypt"))
6968 {
6970 }
6971 else if (streq(p[j], "aead-epoch"))
6972 {
6974 }
6975 else
6976 {
6977 msg(msglevel, "Unknown protocol-flags flag: %s", p[j]);
6978 }
6979 }
6980 }
6981 else if (streq(p[0], "force-tls-key-material-export"))
6982 {
6985 }
6986 else if (streq(p[0], "app-custom-control") && p[1] && !p[2])
6987 {
6989 if (!string_class(p[1], CC_ALNUM | CC_COLON | CC_UNDERBAR | CC_DASH, 0))
6990 {
6991 msg(msglevel, "App custom control protocols must only contain "
6992 "alphanumeric characters, '-', and '_'.");
6993 goto err;
6994 }
6995 options->acc_protocols = p[1];
6996 }
6997 else if (streq(p[0], "custom-control") && p[1] && p[2] && p[3] && !p[4])
6998 {
7000
7001 /* check if the list from the server is a real subset of our list */
7002 struct gc_arena gc_local = gc_new();
7004
7005 if (buf_len(&common_list) == 0 || !streq(p[3], buf_cstr(&common_list)))
7006 {
7007 msg(msglevel, "App custom control list from server contains "
7008 "unsupported protocols");
7009 gc_free(&gc_local);
7010 goto err;
7011 }
7012 gc_free(&gc_local);
7013
7014 if (!streq(p[2], "6:A") && !streq(p[2], "A:6"))
7015 {
7016 msg(msglevel, "App custom control encoding must be base64 and ascii");
7017 goto err;
7018 }
7019
7021 "app custom message message length", ACC_MIN_MSG_LEN, ACC_MAX_MSG_LEN, msglevel))
7022 {
7023 goto err;
7024 }
7026 }
7027 else if (streq(p[0], "prng") && p[1] && !p[3])
7028 {
7029 msg(M_WARN, "NOTICE: --prng option ignored (SSL library PRNG is used)");
7030 }
7031 else if (streq(p[0], "no-replay") && !p[1])
7032 {
7034 /* always error out, this breaks the connection */
7035 msg(M_FATAL, "--no-replay was removed in OpenVPN 2.7. "
7036 "Update your configuration.");
7037 }
7038 else if (streq(p[0], "replay-window") && !p[3])
7039 {
7041 if (p[1])
7042 {
7043 if (!atoi_constrained(p[1], &options->replay_window, "replay-window windows size",
7045 {
7046 goto err;
7047 }
7048
7049 if (p[2])
7050 {
7051 if (!atoi_constrained(p[2], &options->replay_time, "replay-window time window",
7053 {
7054 goto err;
7055 }
7056 }
7057 }
7058 else
7059 {
7060 msg(msglevel, "replay-window option is missing window size parameter");
7061 goto err;
7062 }
7063 }
7064 else if (streq(p[0], "mute-replay-warnings") && !p[1])
7065 {
7068 }
7069 else if (streq(p[0], "replay-persist") && p[1] && !p[2])
7070 {
7072 msg(M_WARN, "DEPRECATED OPTION: --replay-persist option ignored.");
7073 }
7074 else if (streq(p[0], "test-crypto") && !p[1])
7075 {
7077 options->test_crypto = true;
7078 }
7079#ifndef ENABLE_CRYPTO_MBEDTLS
7080 else if (streq(p[0], "engine") && !p[2])
7081 {
7083 if (p[1])
7084 {
7085 options->engine = p[1];
7086 }
7087 else
7088 {
7089 options->engine = "auto";
7090 }
7091 }
7092#endif /* ENABLE_CRYPTO_MBEDTLS */
7093 else if (streq(p[0], "providers") && p[1])
7094 {
7095 for (size_t j = 1; j < MAX_PARMS && p[j] != NULL; j++)
7096 {
7097 options->providers.names[j] = p[j];
7098 }
7099 }
7100 else if (streq(p[0], "show-tls") && !p[1])
7101 {
7103 options->show_tls_ciphers = true;
7104 }
7105 else if ((streq(p[0], "show-curves") || streq(p[0], "show-groups")) && !p[1])
7106 {
7108 options->show_curves = true;
7109 }
7110 else if (streq(p[0], "ecdh-curve") && p[1] && !p[2])
7111 {
7113 msg(M_WARN, "Consider setting groups/curves preference with "
7114 "tls-groups instead of forcing a specific curve with "
7115 "ecdh-curve.");
7116 options->ecdh_curve = p[1];
7117 }
7118 else if (streq(p[0], "tls-server") && !p[1])
7119 {
7121 options->tls_server = true;
7122 }
7123 else if (streq(p[0], "tls-client") && !p[1])
7124 {
7126 options->tls_client = true;
7127 }
7128 else if (streq(p[0], "ca") && p[1] && !p[2])
7129 {
7131 options->ca_file = p[1];
7133 }
7134#ifndef ENABLE_CRYPTO_MBEDTLS
7135 else if (streq(p[0], "capath") && p[1] && !p[2])
7136 {
7138 options->ca_path = p[1];
7139 }
7140#endif /* ENABLE_CRYPTO_MBEDTLS */
7141 else if (streq(p[0], "dh") && p[1] && !p[2])
7142 {
7144 options->dh_file = p[1];
7146 }
7147 else if (streq(p[0], "cert") && p[1] && !p[2])
7148 {
7150 options->cert_file = p[1];
7152 }
7153 else if (streq(p[0], "extra-certs") && p[1] && !p[2])
7154 {
7158 }
7159 else if ((streq(p[0], "verify-hash") && p[1] && !p[3])
7160 || (streq(p[0], "peer-fingerprint") && p[1] && !p[2]))
7161 {
7163
7164 int verify_hash_depth = 0;
7165 if (streq(p[0], "verify-hash"))
7166 {
7167 msg(M_WARN, "DEPRECATED OPTION: The option --verify-hash is deprecated. "
7168 "You should switch to the either use the level 1 certificate as "
7169 "--ca option, use --tls-verify or use --peer-fingerprint");
7170 /* verify level 1 cert, i.e. the CA that signed the leaf cert */
7171 verify_hash_depth = 1;
7172 }
7173
7175
7177
7178 if (options->verify_hash && options->verify_hash_depth != verify_hash_depth)
7179 {
7180 msg(msglevel,
7181 "ERROR: Setting %s not allowed. --verify-hash and"
7182 " --peer-fingerprint are mutually exclusive",
7183 p[0]);
7184 goto err;
7185 }
7186
7187 if (streq(p[0], "verify-hash"))
7188 {
7189 if ((!p[2] && !is_inline) || (p[2] && streq(p[2], "SHA1")))
7190 {
7193 }
7194 else if (p[2] && !streq(p[2], "SHA256"))
7195 {
7196 msg(msglevel,
7197 "invalid or unsupported hashing algorithm: %s "
7198 "(only SHA1 and SHA256 are supported)",
7199 p[2]);
7200 goto err;
7201 }
7202 }
7203
7204 struct verify_hash_list *newlist;
7205 newlist = parse_hash_fingerprint_multiline(p[1], digest_len, msglevel, &options->gc);
7206
7207 /* Append the new list to the end of our current list */
7208 if (!options->verify_hash)
7209 {
7210 options->verify_hash = newlist;
7211 options->verify_hash_depth = verify_hash_depth;
7212 }
7213 else
7214 {
7215 /* since both the old and new list can have multiple entries
7216 * we need to go to the end of one of them to concatenate them */
7217 struct verify_hash_list *listend = options->verify_hash;
7218 while (listend->next)
7219 {
7220 listend = listend->next;
7221 }
7222 listend->next = newlist;
7223 }
7224 }
7225#if defined(ENABLE_CRYPTOAPI) && defined(HAVE_XKEY_PROVIDER)
7226 else if (streq(p[0], "cryptoapicert") && p[1] && !p[2])
7227 {
7229 options->cryptoapi_cert = p[1];
7230 }
7231#endif
7232 else if (streq(p[0], "key") && p[1] && !p[2])
7233 {
7235 options->priv_key_file = p[1];
7236 options->priv_key_file_inline = is_inline;
7237 }
7238 else if (streq(p[0], "tls-version-min") && p[1] && !p[3])
7239 {
7241 int ver = tls_version_parse(p[1], p[2]);
7242 if (ver == TLS_VER_BAD)
7243 {
7244 msg(msglevel, "unknown tls-version-min parameter: %s", p[1]);
7245 goto err;
7246 }
7247
7248#ifdef ENABLE_CRYPTO_MBEDTLS
7249 if (ver < TLS_VER_1_2)
7250 {
7251 msg(M_WARN, "--tls-version-min %s is not supported by mbedtls, using 1.2", p[1]);
7252 ver = TLS_VER_1_2;
7253 }
7254#endif
7255
7257 options->ssl_flags |= ((unsigned int)ver << SSLF_TLS_VERSION_MIN_SHIFT);
7258 }
7259 else if (streq(p[0], "tls-version-max") && p[1] && !p[2])
7260 {
7262 int ver = tls_version_parse(p[1], NULL);
7263 if (ver == TLS_VER_BAD)
7264 {
7265 msg(msglevel, "unknown tls-version-max parameter: %s", p[1]);
7266 goto err;
7267 }
7269 options->ssl_flags |= ((unsigned int)ver << SSLF_TLS_VERSION_MAX_SHIFT);
7270 }
7271#ifndef ENABLE_CRYPTO_MBEDTLS
7272 else if (streq(p[0], "pkcs12") && p[1] && !p[2])
7273 {
7275 options->pkcs12_file = p[1];
7276 options->pkcs12_file_inline = is_inline;
7277 }
7278#endif /* ENABLE_CRYPTO_MBEDTLS */
7279 else if (streq(p[0], "askpass") && !p[2])
7280 {
7282 if (p[1])
7283 {
7284 options->key_pass_file = p[1];
7285 }
7286 else
7287 {
7288 options->key_pass_file = "stdin";
7289 }
7290 }
7291 else if (streq(p[0], "auth-nocache") && !p[1])
7292 {
7295 }
7296 else if (streq(p[0], "auth-token") && p[1] && !p[2])
7297 {
7299 ssl_set_auth_token(p[1]);
7300#ifdef ENABLE_MANAGEMENT
7301 if (management)
7302 {
7304 }
7305#endif
7306 }
7307 else if (streq(p[0], "auth-token-user") && p[1] && !p[2])
7308 {
7311 }
7312 else if (streq(p[0], "single-session") && !p[1])
7313 {
7315 options->single_session = true;
7316 }
7317 else if (streq(p[0], "push-peer-info") && !p[1])
7318 {
7320 options->push_peer_info = true;
7321 }
7322 else if (streq(p[0], "tls-exit") && !p[1])
7323 {
7325 options->tls_exit = true;
7326 }
7327 else if (streq(p[0], "tls-cipher") && p[1] && !p[2])
7328 {
7330 options->cipher_list = p[1];
7331 }
7332 else if (streq(p[0], "tls-cert-profile") && p[1] && !p[2])
7333 {
7335 options->tls_cert_profile = p[1];
7336 }
7337 else if (streq(p[0], "tls-ciphersuites") && p[1] && !p[2])
7338 {
7340 options->cipher_list_tls13 = p[1];
7341 }
7342 else if (streq(p[0], "tls-groups") && p[1] && !p[2])
7343 {
7345 options->tls_groups = p[1];
7346 }
7347 else if (streq(p[0], "crl-verify") && p[1] && ((p[2] && streq(p[2], "dir")) || !p[2]))
7348 {
7350 if (p[2] && streq(p[2], "dir"))
7351 {
7353 }
7354 options->crl_file = p[1];
7355 options->crl_file_inline = is_inline;
7356 }
7357 else if (streq(p[0], "tls-verify") && p[1])
7358 {
7360 if (!no_more_than_n_args(msglevel, p, 2, NM_QUOTE_HINT))
7361 {
7362 goto err;
7363 }
7365 string_substitute(p[1], ',', ' ', &options->gc), "tls-verify", true);
7366 }
7367 else if (streq(p[0], "tls-export-cert") && p[1] && !p[2])
7368 {
7371 }
7372 else if (streq(p[0], "compat-names"))
7373 {
7375 msg(msglevel, "--compat-names was removed in OpenVPN 2.5. "
7376 "Update your configuration.");
7377 goto err;
7378 }
7379 else if (streq(p[0], "no-name-remapping") && !p[1])
7380 {
7382 msg(msglevel, "--no-name-remapping was removed in OpenVPN 2.5. "
7383 "Update your configuration.");
7384 goto err;
7385 }
7386 else if (streq(p[0], "verify-x509-name") && p[1] && strlen(p[1]) && !p[3])
7387 {
7388 int type = VERIFY_X509_SUBJECT_DN;
7390 if (p[2])
7391 {
7392 if (streq(p[2], "subject"))
7393 {
7395 }
7396 else if (streq(p[2], "name"))
7397 {
7399 }
7400 else if (streq(p[2], "name-prefix"))
7401 {
7403 }
7404 else
7405 {
7406 msg(msglevel, "unknown X.509 name type: %s", p[2]);
7407 goto err;
7408 }
7409 }
7410 options->verify_x509_type = type;
7411 options->verify_x509_name = p[1];
7412 }
7413 else if (streq(p[0], "ns-cert-type") && p[1] && !p[2])
7414 {
7415#ifdef ENABLE_CRYPTO_MBEDTLS
7416 msg(msglevel, "--ns-cert-type is not available with mbedtls.");
7417 goto err;
7418#else
7420 if (streq(p[1], "server"))
7421 {
7423 }
7424 else if (streq(p[1], "client"))
7425 {
7427 }
7428 else
7429 {
7430 msg(msglevel, "--ns-cert-type must be 'client' or 'server'");
7431 goto err;
7432 }
7433#endif /* ENABLE_CRYPTO_MBEDTLS */
7434 }
7435 else if (streq(p[0], "remote-cert-ku"))
7436 {
7438
7439 size_t j;
7440 for (j = 1; j < MAX_PARMS && p[j] != NULL; ++j)
7441 {
7442 sscanf(p[j], "%x", &(options->remote_cert_ku[j - 1]));
7443 }
7444 if (j == 1)
7445 {
7446 /* No specific KU required, but require KU to be present */
7448 }
7449 }
7450 else if (streq(p[0], "remote-cert-eku") && p[1] && !p[2])
7451 {
7453 options->remote_cert_eku = p[1];
7454 }
7455 else if (streq(p[0], "remote-cert-tls") && p[1] && !p[2])
7456 {
7458
7459 if (streq(p[1], "server"))
7460 {
7462 options->remote_cert_eku = "TLS Web Server Authentication";
7463 }
7464 else if (streq(p[1], "client"))
7465 {
7467 options->remote_cert_eku = "TLS Web Client Authentication";
7468 }
7469 else
7470 {
7471 msg(msglevel, "--remote-cert-tls must be 'client' or 'server'");
7472 goto err;
7473 }
7474 }
7475 else if (streq(p[0], "tls-timeout") && p[1] && !p[2])
7476 {
7478 /* Constrain the timeout to not have problems with
7479 * RELIABLE_MAX_TIMEOUT_SHIFT creating an overflow. 65k seconds
7480 * timeout is already way too much anyway */
7481 if (!atoi_constrained(p[1], &options->tls_timeout, "tls-timeout", 1,
7483 {
7484 goto err;
7485 }
7486 }
7487 else if (streq(p[0], "reneg-bytes") && p[1] && !p[2])
7488 {
7490 if (!positive_atoll(p[1], &options->renegotiate_bytes, p[0], msglevel))
7491 {
7492 goto err;
7493 }
7494 }
7495 else if (streq(p[0], "reneg-pkts") && p[1] && !p[2])
7496 {
7498 if (!positive_atoll(p[1], &options->renegotiate_packets, p[0], msglevel))
7499 {
7500 goto err;
7501 }
7502 }
7503 else if (streq(p[0], "reneg-sec") && p[1] && !p[3])
7504 {
7506 options->renegotiate_seconds = positive_atoi(p[1], msglevel);
7507 if (p[2])
7508 {
7510 }
7511 }
7512#ifdef ENABLE_DEBUG
7513 else if (streq(p[0], "debug-aead-usage-limit-override"))
7514 {
7515 /* This option is undocumented since it should not be used by normal
7516 * users */
7518 if (!positive_atoll(p[1], &options->aead_usage_limit_override, p[0], msglevel))
7519 {
7520 msg(M_VERB0, "Warning: --debug-aead-usage-limit-override should "
7521 "only be used by developers and in specific tests.");
7522 goto err;
7523 }
7524 }
7525#endif
7526 else if (streq(p[0], "hand-window") && p[1] && !p[2])
7527 {
7529 options->handshake_window = positive_atoi(p[1], msglevel);
7530 }
7531 else if (streq(p[0], "tran-window") && p[1] && !p[2])
7532 {
7534 options->transition_window = positive_atoi(p[1], msglevel);
7535 }
7536 else if (streq(p[0], "tls-auth") && p[1] && !p[3])
7537 {
7538 int key_direction = -1;
7539
7541
7542 if (permission_mask & OPT_P_GENERAL)
7543 {
7544 options->tls_auth_file = p[1];
7545 options->tls_auth_file_inline = is_inline;
7546
7547 if (!is_inline && p[2])
7548 {
7549 key_direction = ascii2keydirection(msglevel, p[2]);
7550 if (key_direction < 0)
7551 {
7552 goto err;
7553 }
7554 options->key_direction = key_direction;
7555 }
7556 }
7557 else if (permission_mask & OPT_P_CONNECTION)
7558 {
7559 options->ce.tls_auth_file = p[1];
7560 options->ce.tls_auth_file_inline = is_inline;
7562
7563 if (!is_inline && p[2])
7564 {
7565 key_direction = ascii2keydirection(msglevel, p[2]);
7566 if (key_direction < 0)
7567 {
7568 goto err;
7569 }
7570 options->ce.key_direction = key_direction;
7571 }
7572 }
7573 }
7574 else if (streq(p[0], "tls-crypt") && p[1] && !p[3])
7575 {
7577 if (permission_mask & OPT_P_GENERAL)
7578 {
7579 options->tls_crypt_file = p[1];
7580 options->tls_crypt_file_inline = is_inline;
7581 }
7582 else if (permission_mask & OPT_P_CONNECTION)
7583 {
7584 options->ce.tls_crypt_file = p[1];
7585 options->ce.tls_crypt_file_inline = is_inline;
7586 }
7587 }
7588 else if (streq(p[0], "tls-crypt-v2") && p[1] && !p[3])
7589 {
7591 if (permission_mask & OPT_P_GENERAL)
7592 {
7593 options->tls_crypt_v2_file = p[1];
7594 options->tls_crypt_v2_file_inline = is_inline;
7595 }
7596 else if (permission_mask & OPT_P_CONNECTION)
7597 {
7599 options->ce.tls_crypt_v2_file_inline = is_inline;
7600 }
7601
7602 if (p[2] && streq(p[2], "force-cookie"))
7603 {
7605 }
7606 else if (p[2] && streq(p[2], "allow-noncookie"))
7607 {
7609 }
7610 else if (p[2])
7611 {
7612 msg(msglevel, "Unsupported tls-crypt-v2 argument: %s", p[2]);
7613 }
7614 }
7615 else if (streq(p[0], "tls-crypt-v2-verify") && p[1] && !p[2])
7616 {
7619 }
7620 else if (streq(p[0], "tls-crypt-v2-max-age") && p[1])
7621 {
7623 if (!atoi_constrained(p[1], &options->tls_crypt_v2_max_age, "tls-crypt-v2-max-age", 1, INT_MAX, msglevel))
7624 {
7625 goto err;
7626 }
7627 }
7628 else if (streq(p[0], "x509-track") && p[1] && !p[2])
7629 {
7631 x509_track_add(&options->x509_track, p[1], msglevel, &options->gc);
7632 }
7633 else if (streq(p[0], "x509-username-field") && p[1])
7634 {
7636 for (size_t j = 1; j < MAX_PARMS && p[j] != NULL; ++j)
7637 {
7638 char *s = p[j];
7639
7640 if (strncmp("ext:", s, 4) == 0 && !x509_username_field_ext_supported(s + 4))
7641 {
7642 msg(msglevel, "Unsupported x509-username-field extension: %s", s);
7643 }
7644 options->x509_username_field[j - 1] = p[j];
7645 }
7646 }
7647#ifdef ENABLE_PKCS11
7648 else if (streq(p[0], "show-pkcs11-ids") && !p[3])
7649 {
7650 const char *provider = p[1];
7651 bool cert_private = (p[2] == NULL ? false
7652 : boolean_flag(p[2], "show-pkcs11-ids private", msglevel));
7653
7654#ifdef DEFAULT_PKCS11_MODULE
7655 if (!provider)
7656 {
7657 provider = DEFAULT_PKCS11_MODULE;
7658 }
7659 else if (!p[2])
7660 {
7661 char *endp = NULL;
7662 long i = strtol(provider, &endp, 10);
7663
7664 if (*endp == 0)
7665 {
7666 /* There was one argument, and it was purely numeric.
7667 * Interpret it as the cert_private argument */
7668 provider = DEFAULT_PKCS11_MODULE;
7669 cert_private = i;
7670 }
7671 }
7672#else /* ifdef DEFAULT_PKCS11_MODULE */
7673 if (!provider)
7674 {
7675 msg(msglevel, "--show-pkcs11-ids requires a provider parameter");
7676 goto err;
7677 }
7678#endif /* ifdef DEFAULT_PKCS11_MODULE */
7680
7682 show_pkcs11_ids(provider, cert_private);
7683 openvpn_exit(OPENVPN_EXIT_STATUS_GOOD); /* exit point */
7684 }
7685 else if (streq(p[0], "pkcs11-providers") && p[1])
7686 {
7687 int j;
7688
7690
7691 for (j = 1; j < MAX_PARMS && p[j] != NULL; ++j)
7692 {
7693 options->pkcs11_providers[j - 1] = p[j];
7694 }
7695 }
7696 else if (streq(p[0], "pkcs11-protected-authentication"))
7697 {
7699
7700 for (int j = 1; j < MAX_PARMS && p[j] != NULL; ++j)
7701 {
7702 options->pkcs11_protected_authentication[j - 1] =
7703 boolean_flag(p[j], p[0], msglevel);
7704 }
7705 }
7706 else if (streq(p[0], "pkcs11-private-mode") && p[1])
7707 {
7708 int j;
7709
7711
7712 for (j = 1; j < MAX_PARMS && p[j] != NULL; ++j)
7713 {
7714 sscanf(p[j], "%x", &(options->pkcs11_private_mode[j - 1]));
7715 }
7716 }
7717 else if (streq(p[0], "pkcs11-cert-private"))
7718 {
7720
7721 for (int j = 1; j < MAX_PARMS && p[j] != NULL; ++j)
7722 {
7723 options->pkcs11_cert_private[j - 1] = boolean_flag(p[j], p[0], msglevel);
7724 }
7725 }
7726 else if (streq(p[0], "pkcs11-pin-cache") && p[1] && !p[2])
7727 {
7729 options->pkcs11_pin_cache_period = positive_atoi(p[1], msglevel);
7730 }
7731 else if (streq(p[0], "pkcs11-id") && p[1] && !p[2])
7732 {
7734 options->pkcs11_id = p[1];
7735 }
7736 else if (streq(p[0], "pkcs11-id-management") && !p[1])
7737 {
7739 options->pkcs11_id_management = true;
7740 }
7741#endif /* ifdef ENABLE_PKCS11 */
7742 else if (streq(p[0], "rmtun") && !p[1])
7743 {
7745 options->persist_config = true;
7746 options->persist_mode = 0;
7747 }
7748 else if (streq(p[0], "mktun") && !p[1])
7749 {
7751 options->persist_config = true;
7752 options->persist_mode = 1;
7753 }
7754 else if (streq(p[0], "peer-id") && p[1] && !p[2])
7755 {
7757 options->use_peer_id = true;
7758 options->peer_id = atoi_warn(p[1], msglevel);
7759 }
7760 else if (streq(p[0], "keying-material-exporter") && p[1] && p[2])
7761 {
7763
7764 if (strncmp(p[1], "EXPORTER", 8))
7765 {
7766 msg(msglevel, "Keying material exporter label must begin with "
7767 "\"EXPORTER\"");
7768 goto err;
7769 }
7770 if (streq(p[1], EXPORT_KEY_DATA_LABEL))
7771 {
7772 msg(msglevel,
7773 "Keying material exporter label must not be '" EXPORT_KEY_DATA_LABEL "'.");
7774 }
7775
7777 p[0], 16, 4095, msglevel))
7778 {
7779 goto err;
7780 }
7781
7783 }
7784 else if (streq(p[0], "allow-recursive-routing") && !p[1])
7785 {
7788 }
7789 else if (streq(p[0], "vlan-tagging") && !p[1])
7790 {
7792 options->vlan_tagging = true;
7793 }
7794 else if (streq(p[0], "vlan-accept") && p[1] && !p[2])
7795 {
7797 if (streq(p[1], "tagged"))
7798 {
7800 }
7801 else if (streq(p[1], "untagged"))
7802 {
7804 }
7805 else if (streq(p[1], "all"))
7806 {
7808 }
7809 else
7810 {
7811 msg(msglevel, "--vlan-accept must be 'tagged', 'untagged' or 'all'");
7812 goto err;
7813 }
7814 }
7815 else if (streq(p[0], "vlan-pvid") && p[1] && !p[2])
7816 {
7817 int vlan_pvid;
7819 if (!atoi_constrained(p[1], &vlan_pvid, p[0],
7821 {
7822 goto err;
7823 }
7824 options->vlan_pvid = (uint16_t)vlan_pvid;
7825 }
7826 else
7827 {
7828 const msglvl_t msglevel_unknown = msglevel_unknown_option(options, p[0], msglevel_fc);
7829 if (file)
7830 {
7831 msg(msglevel_unknown,
7832 "Unrecognized option or missing or extra parameter(s) in %s:%d: %s (%s)", file,
7833 line, p[0], PACKAGE_VERSION);
7834 }
7835 else
7836 {
7837 msg(msglevel_unknown, "Unrecognized option or missing or extra parameter(s): --%s (%s)",
7838 p[0], PACKAGE_VERSION);
7839 }
7840 }
7841err:
7842 gc_free(&gc);
7843}
7844
7845#if defined(__GNUC__) || defined(__clang__)
7846#pragma GCC diagnostic pop
7847#pragma GCC diagnostic pop
7848#endif
7849
7850bool
7852{
7853 if (options->ce.local_list)
7854 {
7855 for (int i = 0; i < options->ce.local_list->len; i++)
7856 {
7858 {
7859 return true;
7860 }
7861 }
7862 }
7863
7864 return false;
7865}
struct buffer get_list_intersection(struct gc_arena *gc, const char *list1, const char *list2)
Calculates the intersection of two list that are both separated by : Items in the result will have th...
Definition acc.c:350
#define ACC_MIN_MSG_LEN
Definition acc.h:31
#define ACC_MAX_MSG_LEN
Definition acc.h:34
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 gc_transfer(struct gc_arena *dest, struct gc_arena *src)
Move all allocations from one garbage collection arena to another.
Definition buffer.c:432
bool string_class(const char *str, const unsigned int inclusive, const unsigned int exclusive)
Test whether all characters in a string satisfy a character class filter.
Definition buffer.c:1003
void * gc_realloc(void *ptr, size_t size, struct gc_arena *a)
allows to realloc a pointer previously allocated by gc_malloc or gc_realloc
Definition buffer.c:346
bool string_defined_equal(const char *s1, const char *s2)
compare two strings which might be NULL, but NULL is never equal
Definition buffer.c:1106
void * gc_malloc(size_t size, bool clear, struct gc_arena *a)
Allocate memory and, optionally, zero it.
Definition buffer.c:321
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
int string_array_len(const char **array)
Return the number of elements in a NULL-terminated array of strings.
Definition buffer.c:663
struct buffer buffer_read_from_file(const char *filename, struct gc_arena *gc)
buffer_read_from_file - copy the content of a file into a buffer
Definition buffer.c:1399
char * string_substitute(const char *src, char from, char to, struct gc_arena *gc)
Definition buffer.c:1136
char * string_alloc(const char *str, struct gc_arena *gc)
Duplicate a string, allocating memory under garbage collection.
Definition buffer.c:618
Buffer management functions and garbage collection.
static void gc_detach(struct gc_arena *a)
Detach all allocations from an arena without freeing them.
Definition buffer.h:1947
#define CC_DASH
dash
Definition buffer.h:1705
#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 CC_COLON
colon
Definition buffer.h:1708
#define streq(x, y)
helper to work around the semantics of the strcmp() return value
Definition buffer.h:1822
static bool buf_valid(const struct buffer *buf)
Return true iff buf is valid.
Definition buffer.h:414
static void gc_init(struct gc_arena *a)
Initialise a garbage collection arena to an empty state.
Definition buffer.h:1932
static const char * buf_cstr(const struct buffer *buf)
Return the buffer content pointer cast to const char *.
Definition buffer.h:585
static int buf_len(const struct buffer *buf)
Return the length of the buffer content.
Definition buffer.h:462
#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 CC_UNDERBAR
underscore
Definition buffer.h:1704
#define ALLOC_OBJ_GC(dptr, type, gc)
Allocate a garbage-collected object of the given type (uninitialised).
Definition buffer.h:2120
static void gc_free(struct gc_arena *a)
Free all allocations in a garbage collection arena.
Definition buffer.h:1974
#define CC_ALNUM
alphanumeric isalnum()
Definition buffer.h:1689
static struct gc_arena gc_new(void)
Allocate and return a new, empty garbage collection arena.
Definition buffer.h:1958
bool check_cmd_access(const char *command, const char *opt, const char *chroot)
Verifies that the path in the "command" that comes after certain script options (e....
void options_postprocess_filechecks(struct options *options)
Sanity check of all file/dir options.
void add_client_nat_to_option_list(struct client_nat_option_list *dest, const char *type, const char *network, const char *netmask, const char *foreign_network, msglvl_t msglevel)
Definition clinat.c:102
struct client_nat_option_list * new_client_nat_list(struct gc_arena *gc)
Definition clinat.c:71
struct client_nat_option_list * clone_client_nat_option_list(const struct client_nat_option_list *src, struct gc_arena *gc)
Definition clinat.c:79
void copy_client_nat_option_list(struct client_nat_option_list *dest, const struct client_nat_option_list *src)
Definition clinat.c:88
#define TLS_CHANNEL_BUF_SIZE
Definition common.h:70
#define TLS_CHANNEL_MTU_MIN
Definition common.h:83
bool check_compression_settings_valid(const struct compress_options *info, msglvl_t msglevel)
Checks if the compression settings are valid.
Definition comp.c:156
#define COMP_F_ALLOW_STUB_ONLY
Only accept stub compression, even with COMP_F_ADVERTISE_STUBS_ONLY we still accept other compression...
Definition comp.h:45
#define COMP_F_SWAP
initial command byte is swapped with last byte in buffer to preserve payload alignment
Definition comp.h:40
#define COMP_ALG_LZ4
LZ4 algorithm.
Definition comp.h:59
#define COMP_ALGV2_LZ4
Definition comp.h:64
#define COMP_F_ALLOW_NOCOMP_ONLY
Do not allow compression framing (breaks DCO)
Definition comp.h:51
#define COMP_F_ALLOW_ASYM
Compression was explicitly set to allow asymetric compression.
Definition comp.h:49
#define COMP_ALGV2_UNCOMPRESSED
Definition comp.h:63
#define COMP_ALG_STUB
support compression command byte and framing without actual compression
Definition comp.h:56
#define COMP_ALG_LZO
LZO algorithm.
Definition comp.h:57
#define COMP_F_ADVERTISE_STUBS_ONLY
tell server that we only support compression stubs
Definition comp.h:42
#define COMP_F_MIGRATE
push stub-v2 or comp-lzo no when we see a client with comp-lzo in occ
Definition comp.h:47
static bool comp_non_stub_enabled(const struct compress_options *info)
Definition comp.h:81
#define COMP_ALG_UNDEF
Definition comp.h:54
char * strsep(char **stringp, const char *delim)
#define PACKAGE_NAME
Definition config.h:492
#define IPROUTE_PATH
Definition config.h:468
#define PACKAGE_VERSION
Definition config.h:504
#define CONFIGURE_DEFINES
Definition config.h:5
#define PACKAGE_STRING
Definition config.h:495
#define TARGET_ALIAS
Definition config.h:558
int ascii2keydirection(msglvl_t msglevel, const char *str)
Definition crypto.c:1597
bool check_tls_prf_working(void)
Checks if the current TLS library supports the TLS 1.0 PRF with MD5+SHA1 that OpenVPN uses when TLS K...
Definition crypto.c:1879
Data Channel Cryptography Module.
#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 KEY_DIRECTION_BIDIRECTIONAL
Definition crypto.h:224
#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
@ MD_SHA256
@ MD_SHA1
#define SHA_DIGEST_LENGTH
#define SHA256_DIGEST_LENGTH
static bool dco_check_startup_option(msglvl_t msglevel, const struct options *o)
Definition dco.h:280
static bool dco_check_option(msglvl_t msglevel, const struct options *o)
Definition dco.h:274
static const char * dco_version_string(struct gc_arena *gc)
Definition dco.h:268
bool dns_options_verify(msglvl_t msglevel, const struct dns_options *o)
Checks validity of DNS options.
Definition dns.c:221
void dns_options_postprocess_pull(struct dns_options *o)
Merges pulled DNS servers with static ones into an ordered list.
Definition dns.c:298
bool dns_server_addr_parse(struct dns_server *server, const char *addr)
Parses a string IPv4 or IPv6 address and optional colon separated port, into a in_addr or in6_addr re...
Definition dns.c:67
bool dns_domain_list_append(struct dns_domain **entry, char **domains, struct gc_arena *gc)
Appends safe DNS domain parameters to a linked list.
Definition dns.c:157
struct dns_server * dns_server_get(struct dns_server **entry, long priority, struct gc_arena *gc)
Find or create DNS server with priority in a linked list.
Definition dns.c:199
bool dns_server_priority_parse(long *priority, const char *str, bool pulled)
Parses a string DNS server priority and validates it.
Definition dns.c:184
struct dns_options clone_dns_options(const struct dns_options *o, struct gc_arena *gc)
Makes a deep copy of the passed DNS options.
Definition dns.c:275
void dns_options_preprocess_pull(struct dns_options *o)
Saves and resets the server options, so that pulled ones don't mix in.
Definition dns.c:291
static bool dns_updown_user_set(const struct dns_options *o)
Returns whether dns-updown is user defined.
Definition dns.h:218
@ DNS_UPDOWN_FORCED
Definition dns.h:50
@ DNS_UPDOWN_NO_FLAGS
Definition dns.h:48
@ DNS_UPDOWN_USER_SET
Definition dns.h:49
@ DNS_SECURITY_NO
Definition dns.h:33
@ DNS_SECURITY_YES
Definition dns.h:34
@ DNS_SECURITY_OPTIONAL
Definition dns.h:35
static bool dns_updown_forced(const struct dns_options *o)
Returns whether dns-updown is forced to run.
Definition dns.h:229
@ DNS_TRANSPORT_PLAIN
Definition dns.h:41
@ DNS_TRANSPORT_TLS
Definition dns.h:43
@ DNS_TRANSPORT_HTTPS
Definition dns.h:42
static bool validate_domain(const char *domain)
void setenv_int(struct env_set *es, const char *name, int value)
Definition env_set.c:289
void setenv_str_i(struct env_set *es, const char *name, const char *value, const int i)
Definition env_set.c:421
void setenv_str(struct env_set *es, const char *name, const char *value)
Definition env_set.c:305
const char * env_set_get(const struct env_set *es, const char *name)
Definition env_set.c:200
void setenv_str_safe(struct env_set *es, const char *name, const char *value)
Definition env_set.c:311
bool env_set_del(struct env_set *es, const char *str)
Definition env_set.c:182
void setenv_long_long(struct env_set *es, const char *name, long long value)
Definition env_set.c:297
#define D_PUSH
Definition errlevel.h:81
#define M_VERB0
Definition errlevel.h:52
#define D_TLS_DEBUG_MED
Definition errlevel.h:153
#define D_DCO
Definition errlevel.h:92
#define D_PUSH_ERRORS
Definition errlevel.h:66
#define D_TLS_ERRORS
Definition errlevel.h:58
#define M_INFO
Definition errlevel.h:54
Interface functions to the internal and external multiplexers.
#define RELIABLE_MAX_INITIAL_TIMEOUT
Maximum initial timeout (–tls-timeout) we accept.
Definition reliable.h:65
void helper_setdefault_topology(struct options *o)
Set –topology default depending on –mode.
Definition helper.c:129
void helper_tcp_nodelay(struct options *o)
Definition helper.c:598
void helper_client_server(struct options *o)
Definition helper.c:162
void helper_keepalive(struct options *o)
Definition helper.c:537
static int max_int(int x, int y)
Definition integer.h:92
static int constrain_int(int x, int min, int max)
Definition integer.h:118
void management_auth_token(const char *token)
Definition manage.c:3290
void management_echo(struct management *man, const char *string, const bool pull)
Definition manage.c:3211
#define MF_FORGET_DISCONNECT
Definition manage.h:31
#define MF_EXTERNAL_KEY_PKCS1PAD
Definition manage.h:38
#define MF_CLIENT_AUTH
Definition manage.h:33
#define MF_EXTERNAL_KEY_PSSPAD
Definition manage.h:43
#define MF_EXTERNAL_KEY_NOPADDING
Definition manage.h:37
#define MF_QUERY_PROXY
Definition manage.h:41
#define MF_EXTERNAL_KEY
Definition manage.h:36
#define MF_QUERY_REMOTE
Definition manage.h:40
#define MF_QUERY_PASSWORDS
Definition manage.h:28
#define MF_EXTERNAL_CERT
Definition manage.h:42
#define MF_EXTERNAL_KEY_DIGEST
Definition manage.h:44
#define MF_UP_DOWN
Definition manage.h:39
#define MF_HOLD
Definition manage.h:29
#define MF_SIGNAL
Definition manage.h:30
#define MF_UNIX_SOCK
Definition manage.h:35
#define MF_CONNECT_AS_CLIENT
Definition manage.h:32
#define MBUF_SIZE_MAX
Definition mbuf.h:40
#define USER_PASS_LEN
Definition misc.h:67
#define SC_CONCAT
Definition misc.h:95
#define SC_ECHO
Definition misc.h:94
int translate_mtu_discover_type_name(const char *name)
Definition mtu.c:251
#define MSSFIX_DEFAULT
Definition mtu.h:89
#define TUN_MTU_MAX_MIN
Definition mtu.h:79
#define TAP_MTU_EXTRA_DEFAULT
Definition mtu.h:84
#define LINK_MTU_DEFAULT
Definition mtu.h:64
#define TUN_MTU_DEFAULT
Definition mtu.h:69
#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 TLS_MTU_DEFAULT
Definition mtu.h:94
static bool learn_address_script(const struct multi_context *m, const struct multi_instance *mi, const char *op, const struct mroute_addr *addr)
Definition multi.c:85
static int net_ctx_init(const struct context *c, openvpn_net_ctx_t *ctx)
Definition networking.h:47
void * openvpn_net_ctx_t
Definition networking.h:38
#define BOOL_CAST(x)
Definition basic.h:26
#define CLEAR(x)
Definition basic.h:32
#define SIZE(x)
Definition basic.h:29
void errors_to_stderr(void)
Definition error.c:181
void open_syslog(const char *pgmname, bool stdio_to_null)
Definition error.c:449
void redirect_stdout_stderr(const char *file, bool append)
Definition error.c:498
void openvpn_exit(const int status)
Definition error.c:718
void set_suppress_timestamps(bool suppressed)
Definition error.c:145
void set_machine_readable_output(bool parsable)
Definition error.c:151
FILE * msg_fp(const msglvl_t flags)
Definition error.c:190
bool set_debug_level(const int level, const unsigned int flags)
Definition error.c:103
#define SDL_CONSTRAIN
Definition error.h:203
#define M_NOPREFIX
Definition error.h:98
#define M_DEBUG_LEVEL
Definition error.h:88
#define M_USAGE
Definition error.h:107
#define OPENVPN_EXIT_STATUS_USAGE
Definition error.h:54
#define OPENVPN_EXIT_STATUS_GOOD
Definition error.h:52
#define M_FATAL
Definition error.h:90
#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 MAX_PEER_ID
Definition openvpn.h:526
static void rol6_check_alloc(struct options *options)
Definition options.c:1289
static void options_postprocess_verify_ce(const struct options *options, const struct connection_entry *ce)
Definition options.c:1591
#define NM_QUOTE_HINT
Definition options.c:3549
static void options_postprocess_mutate_ce(struct options *o, struct connection_entry *ce)
Definition options.c:2182
static void usage_version(void)
Definition options.c:3438
static struct pull_filter * alloc_pull_filter(struct options *o)
Definition options.c:1495
static void reset_routes_v6(struct context *c, struct options *options, const struct env_set *es)
Definition options.c:3614
#define USAGE_VALID_SERVER_PROTOS
static void pre_connect_save(struct options *o)
Definition options.c:2373
static void setenv_connection_entry(struct env_set *es, const struct connection_entry *e, const int i)
Definition options.c:923
static int global_auth_retry
Definition options.c:3317
bool options_postprocess_pull(struct options *o, struct env_set *es)
Definition options.c:3250
void remove_option(struct context *c, struct options *options, char *p[], bool is_inline, const char *file, int line, const msglvl_t msglevel, const uint64_t permission_mask, uint64_t *option_types_found, struct env_set *es)
Resets options found in the PUSH_UPDATE message that are preceded by the - flag.
Definition options.c:3685
void uninit_options(struct options *o)
Definition options.c:907
static void connection_entry_load_re(struct connection_entry *ce, const struct remote_entry *re)
Definition options.c:1516
int parse_topology(const char *str, const msglvl_t msglevel)
Definition options.c:3270
void show_windows_version(const unsigned int flags)
Definition options.c:3405
#define VERIFY_PERMISSION(mask)
Definition options.c:3489
bool key_is_external(const struct options *options)
Definition options.c:4054
static void check_ca_required(const struct options *options)
Definition options.c:1553
static struct http_proxy_options * parse_http_proxy_override(const char *server, const char *port, const char *flags, struct gc_arena *gc)
Definition options.c:1309
void init_options(struct options *o)
Definition options.c:805
static void options_postprocess_mutate_le(const struct connection_entry *ce, struct local_entry *le, int mode)
Definition options.c:2339
static void tuntap_options_postprocess_dns(struct options *o)
Postprocess DNS related settings.
Definition options.c:2759
static void dhcp_option_dns6_parse(const char *parm, struct in6_addr *dns6_list, unsigned int *len, msglvl_t msglevel)
Definition options.c:1175
static char * get_ipv6_addr_no_netbits(const char *addr, struct gc_arena *gc)
Returns newly allocated string containing address part without "/nn".
Definition options.c:1057
static void option_iroute_ipv6(struct options *o, const char *prefix_str, msglvl_t msglevel)
Definition options.c:1243
static bool check_route_option(struct options *options, char *p[], const msglvl_t msglevel, bool pull_mode)
Definition options.c:3784
void show_dco_version(const unsigned int flags)
Definition options.c:3414
void rol_check_alloc(struct options *options)
Definition options.c:1280
static struct local_list * alloc_local_list_if_undef(struct connection_entry *ce, struct gc_arena *gc)
Definition options.c:1372
static void dhcp_option_address_parse(const char *name, const char *parm, in_addr_t *array, unsigned int *len, msglvl_t msglevel)
Definition options.c:1189
static void helper_hashmap_sizes(struct options *o)
Sets the internal hash maps sizes according to the max_clients.
Definition options.c:3019
static void reset_routes_v4(struct context *c, struct options *options, const struct env_set *es)
Definition options.c:3598
static bool verify_permission(const char *name, const char *file, int line, const uint64_t type, const uint64_t allowed, uint64_t *found, const msglvl_t msglevel, const struct options *options, bool is_inline)
Definition options.c:3499
static void set_user_script(struct options *options, const char **script, const char *new_script, const char *type, bool in_chroot)
Definition options.c:4015
void update_option(struct context *c, struct options *options, char *p[], bool is_inline, const char *file, int line, const int level, const msglvl_t msglevel, const uint64_t permission_mask, uint64_t *option_types_found, struct env_set *es)
Processes an option to update.
Definition options.c:3942
static struct verify_hash_list * parse_hash_fingerprint_multiline(const char *str, int nbytes, msglvl_t msglevel, struct gc_arena *gc)
Parses a string consisting of multiple lines of hexstrings and checks if each string has the correct ...
Definition options.c:1136
#define LZO_LIB_VER_STR
static bool no_more_than_n_args(const msglvl_t msglevel, char *p[], const int max, const unsigned int flags)
Definition options.c:3552
void options_postprocess(struct options *options, struct env_set *es)
Definition options.c:3236
static void reset_dns_options(struct options *options)
Definition options.c:3644
void usage_small(void)
Definition options.c:3397
const char * auth_retry_print(void)
Definition options.c:3349
static struct remote_entry * alloc_remote_entry(struct options *options, const msglvl_t msglevel)
Definition options.c:1459
void show_library_versions(const unsigned int flags)
Definition options.c:3424
void setenv_settings(struct env_set *es, const struct options *o)
Definition options.c:954
static const char usage_message[]
Definition options.c:132
static struct connection_list * alloc_connection_list_if_undef(struct options *options)
Definition options.c:1413
static msglvl_t msglevel_forward_compatible(const struct options *options, const msglvl_t msglevel)
Definition options.c:3577
static void cnol_check_alloc(struct options *options)
Definition options.c:1298
static void options_postprocess_mutate(struct options *o, struct env_set *es)
Definition options.c:3036
void options_detach(struct options *o)
Definition options.c:1260
static unsigned int atou(const char *str)
Definition options.c:3481
void pre_connect_restore(struct options *o, struct gc_arena *gc)
Definition options.c:2418
static struct pull_filter_list * alloc_pull_filter_list(struct options *o)
Definition options.c:1485
const char * print_topology(const int topology)
Definition options.c:3292
static struct verify_hash_list * parse_hash_fingerprint(const char *str, int nbytes, msglvl_t msglevel, struct gc_arena *gc)
Parses a hexstring and checks if the string has the correct length.
Definition options.c:1083
static bool check_dns_option(struct options *options, char *p[], const msglvl_t msglevel, bool pull_mode)
Definition options.c:3833
static void options_postprocess_cipher(struct options *o)
Definition options.c:2593
static msglvl_t msglevel_unknown_option(const struct options *options, const char *name, const msglvl_t msglevel)
Definition options.c:3584
static void options_set_backwards_compatible_options(struct options *o)
Changes default values so that OpenVPN can be compatible with the user specified version.
Definition options.c:2663
static void show_compression_warning(const struct compress_options *info)
Definition options.c:4042
#define MUST_BE_FALSE(condition, parm_name)
Definition options.c:1584
#define MUST_BE_UNDEF(parm, parm_name)
Definition options.c:1579
static void options_postprocess_http_proxy_override(struct options *o)
Definition options.c:1337
static void options_postprocess_mutate_invariant(struct options *options)
Definition options.c:2493
const char title_string[]
Definition options.c:75
static void setenv_local_entry(struct env_set *es, const struct local_entry *e, const int i)
Definition options.c:941
static void remap_redirect_gateway_flags(struct options *opt)
Definition options.c:2357
bool auth_retry_set(const msglvl_t msglevel, const char *option)
Definition options.c:3326
int auth_retry_get(void)
Definition options.c:3320
static struct remote_list * alloc_remote_list_if_undef(struct options *options)
Definition options.c:1449
static bool check_route6_option(struct options *options, char *p[], const msglvl_t msglevel, bool pull_mode)
Definition options.c:3812
void notnull(const char *arg, const char *description)
Definition options.c:3463
void usage(void)
Definition options.c:3371
static struct local_entry * alloc_local_entry(struct connection_entry *ce, const msglvl_t msglevel, struct gc_arena *gc)
Definition options.c:1382
static void reset_redirect_gateway(struct options *options, struct env_set *es)
Definition options.c:3629
static void options_process_mutate_prf(struct options *o)
Definition options.c:2731
void add_option(struct options *options, char *p[], bool is_inline, const char *file, int line, const int level, const msglvl_t msglevel, const uint64_t permission_mask, uint64_t *option_types_found, struct env_set *es)
Definition options.c:4073
bool has_udp_in_local_list(const struct options *options)
Definition options.c:7851
static void option_iroute(struct options *o, const char *network_str, const char *netmask_str, msglvl_t msglevel)
Definition options.c:1216
static void options_postprocess_verify(const struct options *o)
Definition options.c:2556
static void connection_entry_preload_key(const char **key_file, bool *key_inline, struct gc_arena *gc)
Definition options.c:1537
static struct connection_entry * alloc_connection_entry(struct options *options, const msglvl_t msglevel)
Definition options.c:1423
static void reset_dhcp_options(struct options *options, struct env_set *es)
Definition options.c:3651
static bool need_compatibility_before(const struct options *o, unsigned int version)
The option –compat-mode is used to set up default settings to values used on the specified openvpn ve...
Definition options.c:2653
#define MODE_POINT_TO_POINT
Definition options.h:264
#define OPT_P_SCRIPT
Definition options.h:745
#define PUF_TYPE_ACCEPT
filter type to accept a matching option
Definition options.h:812
#define OPT_P_PUSH
Definition options.h:757
#define SF_TCP_NODELAY_HELPER
Definition options.h:475
#define OPT_P_UP
Definition options.h:742
#define OPT_P_CONNECTION
Definition options.h:768
#define OPT_P_INSTANCE
allowed in ccd, client-connect etc
Definition options.h:758
#define OPT_P_NCP
Negotiable crypto parameters.
Definition options.h:753
#define OPT_P_ECHO
Definition options.h:761
#define OPT_P_ROUTE_TABLE
Definition options.h:772
#define OPT_P_CONFIG
Definition options.h:759
#define MODE_SERVER
Definition options.h:265
#define CONNECTION_LIST_SIZE
Definition options.h:192
#define OPT_P_U_REDIR_GATEWAY
Definition options.h:807
#define OPT_P_EXPLICIT_NOTIFY
Definition options.h:760
#define PUF_TYPE_IGNORE
filter type to ignore a matching option
Definition options.h:813
#define AR_INTERACT
Definition options.h:960
#define OPT_P_SHAPER
Definition options.h:747
#define OPT_P_U_ROUTE6
Definition options.h:804
static bool dco_enabled(const struct options *o)
Returns whether the current configuration has dco enabled.
Definition options.h:981
#define OPT_P_SOCKFLAGS
Definition options.h:767
#define SF_NOPOOL
Definition options.h:474
#define PUF_TYPE_REJECT
filter type to reject and trigger SIGUSR1
Definition options.h:814
#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 OPT_P_PLUGIN
Definition options.h:765
#define OPTION_PARM_SIZE
Definition options.h:56
#define OPT_P_TIMER
Definition options.h:748
#define OPT_P_GENERAL
Definition options.h:741
void read_config_file(struct options *options, const char *file, int level, const char *top_file, const int top_line, const msglvl_t msglevel, const uint64_t permission_mask, uint64_t *option_types_found, struct env_set *es)
#define PING_RESTART
Definition options.h:356
#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 SF_NO_PUSH_ROUTE_GATEWAY
Definition options.h:476
#define OPT_P_PERSIST
Definition options.h:749
#define MAX_PARMS
Definition options.h:51
#define OPT_P_U_DNS
Definition options.h:805
#define PLUGIN_OPTION_LIST(opt)
Definition options.h:789
#define ROUTE_OPTION_FLAGS(o)
Definition options.h:781
#define OPT_P_U_ROUTE
Definition options.h:803
#define PING_EXIT
Definition options.h:355
static void show_debug_warning(const unsigned int flags)
Definition options.h:904
#define OPT_P_COMP
Definition options.h:751
#define OPT_P_PERSIST_IP
Definition options.h:750
#define OPT_P_MTU
Definition options.h:755
#define OPT_P_ROUTE_EXTRAS
Definition options.h:763
#define OPT_P_U_DHCP
Definition options.h:806
#define OPT_P_NICE
Definition options.h:756
#define OPT_P_PEER_ID
Definition options.h:769
#define OPT_P_INHERIT
Definition options.h:762
#define OPT_P_ACC
Definition options.h:773
#define OPT_P_TLS_PARMS
Definition options.h:754
#define OPT_P_ROUTE
Definition options.h:743
#define PING_TIMEOUT_MAX
Definition options.h:59
void read_config_string(const char *prefix, 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 MAN_CLIENT_AUTH_ENABLED(opt)
Definition options.h:795
#define CE_DISABLED
Definition options.h:155
#define OPT_P_INLINE
Definition options.h:770
@ VLAN_ONLY_UNTAGGED_OR_PRIORITY
Definition options.h:227
@ VLAN_ALL
Definition options.h:228
@ VLAN_ONLY_TAGGED
Definition options.h:226
bool boolean_flag(const char *str, const char *name, msglvl_t msglevel)
Converts a str to an boolean if the string can be parsed as either 0 or 1.
int atoi_warn(const char *str, msglvl_t msglevel)
Converts a str to an integer if the string can be represented as an integer number.
int positive_atoi(const char *str, msglvl_t msglevel)
Converts a str to a positive number if the string represents a postive integer number.
bool positive_atoll(const char *str, int64_t *value, const char *name, msglvl_t msglevel)
Converts a str to an integer if the string can be represented as an integer number and is >= 0.
bool valid_integer(const char *str, bool positive)
Checks if the string is a valid integer by checking if it can be converted to an integer.
bool atoi_constrained(const char *str, int *value, const char *name, int min, int max, msglvl_t msglevel)
Converts a str to an integer if the string can be represented as an integer number and is between min...
#define MAX_SEQ_BACKTRACK
Definition packet_id.h:85
#define MIN_SEQ_BACKTRACK
Definition packet_id.h:84
#define DEFAULT_SEQ_BACKTRACK
Definition packet_id.h:86
#define MAX_TIME_BACKTRACK
Definition packet_id.h:94
#define DEFAULT_TIME_BACKTRACK
Definition packet_id.h:95
#define MIN_TIME_BACKTRACK
Definition packet_id.h:93
unsigned int platform_getpid(void)
Definition platform.c:338
int platform_chdir(const char *dir)
Definition platform.c:397
const char * platform_get_tmp_dir(void)
Get a directory for temporary files.
Definition platform.c:591
struct plugin_option_list * plugin_option_list_new(struct gc_arena *gc)
Definition plugin.c:159
bool plugin_option_list_add(struct plugin_option_list *list, char **p, struct gc_arena *gc)
Definition plugin.c:167
bool ifconfig_pool_verify_range(const msglvl_t msglevel, const in_addr_t start, const in_addr_t end)
Definition pool.c:132
#define OPENVPN_8021Q_MIN_VID
Definition proto.h:311
#define OPENVPN_8021Q_MAX_VID
Definition proto.h:312
#define DEV_TYPE_TAP
Definition proto.h:36
#define TOP_UNDEF
Definition proto.h:40
#define DEV_TYPE_UNDEF
Definition proto.h:34
#define TOP_NET30
Definition proto.h:41
#define DEV_TYPE_TUN
Definition proto.h:35
#define TOP_P2P
Definition proto.h:42
#define TOP_SUBNET
Definition proto.h:43
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 MAX_CUSTOM_HTTP_HEADER
Definition proxy.h:43
#define PAR_ALL
Definition proxy.h:50
void push_reset(struct options *o)
Definition push.c:1010
void push_options(struct options *o, char **p, msglvl_t msglevel, struct gc_arena *gc)
Definition push.c:984
void clone_push_list(struct options *o)
Definition push.c:969
void push_remove_option(struct options *o, const char *p)
Definition push.c:1016
in_addr_t get_ip_addr(const char *ip_string, msglvl_t msglevel, bool *error)
Definition resolve.c:469
bool get_ipv6_addr(const char *hostname, struct in6_addr *network, unsigned int *netbits, msglvl_t msglevel)
Translate an IPv6 addr or hostname from string form to in6_addr.
Definition resolve.c:489
in_addr_t getaddr(unsigned int flags, const char *hostname, int resolve_retry_seconds, bool *succeeded, struct signal_info *sig_info)
Translate an IPv4 addr or hostname from string form to in_addr_t.
Definition resolve.c:442
DNS resolution.
#define GETADDR_HOST_ORDER
Definition resolve.h:40
#define GETADDR_RESOLVE
Definition resolve.h:38
static bool ipv6_addr_safe_hexplusbits(const char *ipv6_prefix_spec)
Definition resolve.h:76
bool is_special_addr(const char *addr_str)
Definition route.c:289
struct route_option_list * clone_route_option_list(const struct route_option_list *src, struct gc_arena *a)
Definition route.c:156
int netmask_to_netbits2(in_addr_t netmask)
Definition route.c:3835
struct route_ipv6_option_list * new_route_ipv6_option_list(struct gc_arena *a)
Definition route.c:140
void delete_routes_v6(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:1193
void get_default_gateway_ipv6(struct route_ipv6_gateway_info *rgi6, const struct in6_addr *dest, openvpn_net_ctx_t *ctx)
Definition route.c:2611
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
void copy_route_option_list(struct route_option_list *dest, const struct route_option_list *src, struct gc_arena *a)
Definition route.c:174
void copy_route_ipv6_option_list(struct route_ipv6_option_list *dest, const struct route_ipv6_option_list *src, struct gc_arena *a)
Definition route.c:182
void print_default_gateway(const msglvl_t msglevel, const struct route_gateway_info *rgi, const struct route_ipv6_gateway_info *rgi6)
Definition route.c:1249
void get_default_gateway(struct route_gateway_info *rgi, in_addr_t dest, openvpn_net_ctx_t *ctx)
Retrieves the best gateway for a given destination based on the routing table.
Definition route.c:2514
struct route_ipv6_option_list * clone_route_ipv6_option_list(const struct route_ipv6_option_list *src, struct gc_arena *a)
Definition route.c:165
struct route_option_list * new_route_option_list(struct gc_arena *a)
Definition route.c:131
void show_routes(msglvl_t msglevel)
Definition route.c:3011
void delete_routes_v4(struct route_list *rl, const struct tuntap *tt, unsigned int flags, const struct env_set *es, openvpn_net_ctx_t *ctx)
Definition route.c:1171
void add_route_to_option_list(struct route_option_list *l, const char *network, const char *netmask, const char *gateway, const char *metric, int table_id)
Definition route.c:482
#define RG_LOCAL
Definition route.h:87
#define RG_BYPASS_DHCP
Definition route.h:89
#define ROUTE_METHOD_SERVICE
Definition route.h:42
#define ROUTE_METHOD_IPAPI
Definition route.h:40
#define ROUTE_METHOD_EXE
Definition route.h:41
#define RG_DEF1
Definition route.h:88
#define RG_BYPASS_DNS
Definition route.h:90
#define RG_ENABLE
Definition route.h:86
#define RG_REROUTE_GW
Definition route.h:91
#define ROUTE_METHOD_ADAPTIVE
Definition route.h:39
#define RG_AUTO_LOCAL
Definition route.h:92
#define RG_BLOCK_LOCAL
Definition route.h:93
void script_security_set(int level)
Definition run_command.c:48
#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
#define SSEC_NONE
strictly no calling of external programs
Definition run_command.h:31
#define SHAPER_MAX
Definition shaper.h:40
#define SHAPER_MIN
Definition shaper.h:39
#define RESOLV_RETRY_INFINITE
Definition socket.h:48
#define OPENVPN_PORT
Definition socket.h:42
#define SF_USE_IP_PKTINFO
Definition socket.h:199
#define SF_HOST_RANDOMIZE
Definition socket.h:202
#define SF_PKTINFO_COPY_IIF
Definition socket.h:206
const char * proto2ascii(int proto, sa_family_t af, bool display_form)
bool mac_addr_safe(const char *mac_addr)
const char * proto2ascii_all(struct gc_arena *gc)
sa_family_t ascii2af(const char *proto_name)
bool ipv6_addr_safe(const char *ipv6_text_addr)
const char * print_in6_addr(struct in6_addr a6, unsigned int flags, struct gc_arena *gc)
bool ip_or_dns_addr_safe(const char *addr, const bool allow_fqdn)
int ascii2proto(const char *proto_name)
const char * print_in_addr_t(in_addr_t addr, unsigned int flags, struct gc_arena *gc)
bool ip_addr_dotted_quad_safe(const char *dotted_quad)
static bool proto_is_net(int proto)
static bool proto_is_udp(int proto)
Returns if the protocol being used is UDP.
@ PROTO_NONE
@ PROTO_UDP
@ PROTO_TCP
@ PROTO_TCP_CLIENT
@ PROTO_TCP_SERVER
static bool proto_is_dgram(int proto)
Return if the protocol is datagram (UDP)
#define IA_NET_ORDER
Definition socket_util.h:90
void ssl_set_auth_token_user(const char *username)
Definition ssl.c:390
void ssl_set_auth_nocache(void)
Definition ssl.c:365
int tls_version_parse(const char *vstr, const char *extra)
Definition ssl.c:449
void ssl_set_auth_token(const char *token)
Definition ssl.c:384
bool ssl_get_auth_nocache(void)
Definition ssl.c:375
Control Channel SSL/Data channel negotiation module.
#define X509_USERNAME_FIELD_DEFAULT
Definition ssl.h:120
const char * get_ssl_library_version(void)
return a pointer to a static memory area containing the name and version number of the SSL library in...
#define TLS_VER_BAD
Parse a TLS version specifier.
#define TLS_VER_1_0
#define EXPORT_KEY_DATA_LABEL
#define TLS_VER_1_2
#define TLS_VER_1_3
int tls_version_max(void)
Return the maximum TLS version (as a TLS_VER_x constant) supported by current SSL implementation.
#define SSLF_TLS_VERSION_MAX_SHIFT
Definition ssl_common.h:436
#define SSLF_CLIENT_CERT_OPTIONAL
Definition ssl_common.h:429
#define SSLF_AUTH_USER_PASS_OPTIONAL
Definition ssl_common.h:431
#define SSLF_CLIENT_CERT_NOT_REQUIRED
Definition ssl_common.h:428
#define SSLF_CRL_VERIFY_DIR
Definition ssl_common.h:433
#define SSLF_TLS_DEBUG_ENABLED
Definition ssl_common.h:438
#define SSLF_TLS_VERSION_MAX_MASK
Definition ssl_common.h:437
#define SSLF_TLS_VERSION_MIN_SHIFT
Definition ssl_common.h:434
#define SSLF_TLS_VERSION_MIN_MASK
Definition ssl_common.h:435
#define SSLF_USERNAME_AS_COMMON_NAME
Definition ssl_common.h:430
void options_postprocess_setdefault_ncpciphers(struct options *o)
Checks for availibility of Chacha20-Poly1305 and sets the ncp_cipher to either AES-256-GCM:AES-128-GC...
Definition ssl_ncp.c:593
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
void append_cipher_to_ncp_list(struct options *o, const char *ciphername)
Appends the cipher specified by the ciphernamer parameter to to the o->ncp_ciphers list.
Definition ssl_ncp.c:186
char * mutate_ncp_cipher_list(const char *list, struct gc_arena *gc)
Check whether the ciphers in the supplied list are supported.
Definition ssl_ncp.c:86
Control Channel SSL/Data dynamic negotiation Module This file is split from ssl.h to be able to unit ...
Control Channel Verification Module.
#define OPENVPN_KU_REQUIRED
Require keyUsage to be present in cert (0xFFFF is an invalid KU value)
Definition ssl_verify.h:257
#define VERIFY_X509_SUBJECT_DN
Definition ssl_verify.h:69
#define VERIFY_X509_SUBJECT_RDN
Definition ssl_verify.h:70
#define NS_CERT_CHECK_CLIENT
Do not perform Netscape certificate type verification.
Definition ssl_verify.h:254
#define VERIFY_X509_SUBJECT_RDN_PREFIX
Definition ssl_verify.h:71
#define NS_CERT_CHECK_SERVER
Do not perform Netscape certificate type verification.
Definition ssl_verify.h:252
bool x509_username_field_ext_supported(const char *extname)
Return true iff the supplied extension field is supported by the –x509-username-field option.
void x509_track_add(const struct x509_track **ll_head, const char *name, msglvl_t msglevel, struct gc_arena *gc)
Wrapper structure for dynamically allocated memory.
Definition buffer.h:71
uint8_t * data
Pointer to the allocated memory.
Definition buffer.h:78
int len
Length in bytes of the actual content within the allocated memory.
Definition buffer.h:76
unsigned int flags
Definition comp.h:77
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
bool bind_local
Definition options.h:120
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_default
Definition options.h:147
bool mssfix_encap
Definition options.h:148
int occ_mtu
Definition options.h:130
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 bind_ipv6_only
Definition options.h:119
bool tun_mtu_defined
Definition options.h:133
bool remote_float
Definition options.h:117
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 mtu_discover_type
Definition options.h:141
int proto
Definition options.h:111
sa_family_t af
Definition options.h:112
const char * tls_auth_file
Definition options.h:167
bool local_port_defined
Definition options.h:114
int tun_mtu
Definition options.h:129
bool bind_defined
Definition options.h:118
const char * local_port
Definition options.h:113
int key_direction
Definition options.h:169
bool tls_crypt_v2_file_inline
Definition options.h:178
unsigned int flags
Definition options.h:164
bool mssfix_fixed
Definition options.h:150
struct connection_entry ** array
Definition options.h:206
struct route_list * route_list
List of routing information.
Definition openvpn.h:160
struct route_ipv6_list * route_ipv6_list
Definition openvpn.h:165
struct tuntap * tuntap
Tun/tap virtual network interface.
Definition openvpn.h:155
Contains all state information for one tunnel.
Definition openvpn.h:445
openvpn_net_ctx_t net_ctx
Networking API opaque context.
Definition openvpn.h:472
struct options options
Options loaded from command line or configuration file.
Definition openvpn.h:446
struct context_1 c1
Level 1 context.
Definition openvpn.h:489
in_addr_t dns[N_DHCP_ADDR]
Definition dns.h:101
Definition dhcp.h:62
struct dns_domain * next
Definition dns.h:55
const char * name
Definition dns.h:56
struct dns_server * servers
Definition dns.h:117
const char * updown
Definition dns.h:119
struct dhcp_options from_dhcp
Definition dns.h:114
struct gc_arena gc
Definition dns.h:118
enum dns_updown_flags updown_flags
Definition dns.h:120
struct dns_domain * search_domains
Definition dns.h:115
struct in_addr a4
Definition dns.h:63
union dns_server_addr::@0 in
sa_family_t family
Definition dns.h:66
struct in6_addr a6
Definition dns.h:64
in_port_t port
Definition dns.h:67
struct dns_server_addr addr[8]
Definition dns.h:75
enum dns_security dnssec
Definition dns.h:77
struct dns_server * next
Definition dns.h:72
long priority
Definition dns.h:73
size_t addr_count
Definition dns.h:74
struct dns_domain * domains
Definition dns.h:76
enum dns_server_transport transport
Definition dns.h:78
const char * sni
Definition dns.h:79
char * string
Definition env_set.h:38
struct env_item * next
Definition env_set.h:39
struct env_item * list
Definition env_set.h:45
Garbage collection arena used to keep track of dynamically allocated memory.
Definition buffer.h:127
Definition list.h:56
const char * name
Definition proxy.h:39
const char * content
Definition proxy.h:40
const char * auth_file
Definition proxy.h:55
const char * http_version
Definition proxy.h:57
const char * port
Definition proxy.h:47
bool inline_creds
Definition proxy.h:60
const char * user_agent
Definition proxy.h:58
const char * auth_method_string
Definition proxy.h:54
struct http_custom_header custom_headers[MAX_CUSTOM_HTTP_HEADER]
Definition proxy.h:59
const char * auth_file_up
Definition proxy.h:56
const char * server
Definition proxy.h:46
struct iroute_ipv6 * next
Definition route.h:271
unsigned int netbits
Definition route.h:270
struct in6_addr network
Definition route.h:269
in_addr_t network
Definition route.h:262
int netbits
Definition route.h:263
struct iroute * next
Definition route.h:264
Definition options.h:102
const char * port
Definition options.h:104
int proto
Definition options.h:105
const char * local
Definition options.h:103
struct local_entry ** array
Definition options.h:198
int capacity
Definition options.h:196
struct tuntap_options tuntap_options
Definition options.h:67
int ping_rec_timeout_action
Definition options.h:91
bool tuntap_options_defined
Definition options.h:66
bool routes_ipv6_defined
Definition options.h:75
struct route_option_list * routes
Definition options.h:73
struct compress_options comp
Definition options.h:94
const char * ciphername
Definition options.h:86
const char * ifconfig_local
Definition options.h:69
struct dns_options dns_options
Definition options.h:84
const char * route_default_gateway
Definition options.h:78
const char * ifconfig_ipv6_local
Definition options.h:70
const char * authname
Definition options.h:87
struct route_ipv6_option_list * routes_ipv6
Definition options.h:76
bool client_nat_defined
Definition options.h:81
struct client_nat_option_list * client_nat
Definition options.h:82
const char * route_ipv6_default_gateway
Definition options.h:79
int resolve_retry_seconds
Definition options.h:367
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
uint32_t sid_hash_size
Definition options.h:501
struct http_proxy_options * http_proxy_override
Definition options.h:313
int push_ifconfig_ipv6_netbits
Definition options.h:524
const char * acc_protocols
The app custom control protocols we should announce as supported.
Definition options.h:713
int proto_force
Definition options.h:336
bool persist_config
Definition options.h:278
struct connection_list * connection_list
Definition options.h:295
const char * management_port
Definition options.h:447
bool tls_crypt_file_inline
Definition options.h:665
const char * ifconfig_ipv6_remote
Definition options.h:331
int max_routes_per_client
Definition options.h:537
const char * ncp_ciphers_conf
The original ncp_ciphers specified by the user in the configuration.
Definition options.h:577
int status_file_version
Definition options.h:407
enum vlan_acceptable_frames vlan_accept
Definition options.h:725
int auth_token_renewal
Definition options.h:546
in_addr_t push_ifconfig_constraint_network
Definition options.h:519
const char * tmp_dir
Definition options.h:466
bool push_peer_info
Definition options.h:681
bool daemon
Definition options.h:391
struct options_pre_connect * pre_connect
Definition options.h:564
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 * cryptoapi_cert
Definition options.h:635
const char * down_script
Definition options.h:386
unsigned int backwards_compatible
What version we should try to be compatible with as major * 10000 + minor * 100 + patch,...
Definition options.h:272
hash_algo_type verify_hash_algo
Definition options.h:619
int scheduled_exit_interval
Definition options.h:566
int stale_routes_ageing_time
Definition options.h:539
bool pkcs12_file_inline
Definition options.h:602
int replay_time
Definition options.h:584
int management_state_buffer_size
Definition options.h:451
const char * ca_file
Definition options.h:590
const char * tls_auth_file
Definition options.h:660
struct provider_list providers
Definition options.h:581
bool duplicate_cn
Definition options.h:528
struct in6_addr server_network_ipv6
Definition options.h:471
int shaper
Definition options.h:334
int management_echo_buffer_size
Definition options.h:450
in_addr_t server_network
Definition options.h:468
uint32_t real_hash_size
Definition options.h:499
bool show_net_up
Definition options.h:694
bool verify_hash_no_ca
Definition options.h:621
bool allow_pull_fqdn
Definition options.h:439
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
in_addr_t ifconfig_pool_netmask
Definition options.h:491
in_addr_t server_netmask
Definition options.h:469
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
bool allow_recursive_routing
Definition options.h:732
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 cf_max
Definition options.h:530
bool dh_file_inline
Definition options.h:594
int replay_window
Definition options.h:583
bool disable
Definition options.h:508
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
uint64_t push_option_types_found
Definition options.h:559
bool single_session
Definition options.h:679
bool push_ifconfig_defined
Definition options.h:514
bool ifconfig_pool_defined
Definition options.h:488
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
in_addr_t server_bridge_netmask
Definition options.h:483
const char * ip_remote_hint
Definition options.h:369
bool vlan_tagging
Definition options.h:724
uint32_t peer_id
Definition options.h:704
struct route_option_list * routes
Definition options.h:434
in_addr_t ifconfig_pool_end
Definition options.h:490
int keepalive_timeout
Definition options.h:343
const char * writepid
Definition options.h:384
int64_t inactivity_minimum_bytes
Definition options.h:346
bool ifconfig_ipv6_pool_defined
Definition options.h:495
unsigned int server_flags
Definition options.h:477
uint32_t max_clients
Definition options.h:536
bool block_outside_dns
Definition options.h:696
bool push_ifconfig_ipv6_blocked
Definition options.h:526
bool tls_exit
Definition options.h:683
const char * pkcs12_file
Definition options.h:601
const char * client_disconnect_script
Definition options.h:503
bool show_engines
Definition options.h:284
struct remote_list * remote_list
Definition options.h:297
HANDLE msg_channel
Definition options.h:691
const char * key_pass_file
Definition options.h:281
bool mute_replay_warnings
Definition options.h:582
const char * tls_crypt_file
Definition options.h:664
int inactivity_timeout
Definition options.h:345
int n_bcast_buf
Definition options.h:510
int handshake_window
Definition options.h:651
bool server_defined
Definition options.h:467
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
struct iroute_ipv6 * iroutes_ipv6
Definition options.h:513
struct push_list push_list
Definition options.h:487
bool user_script_used
Definition options.h:387
const char * tls_groups
Definition options.h:605
bool show_tls_ciphers
Definition options.h:285
struct tuntap_options tuntap_options
Definition options.h:371
int route_method
Definition options.h:695
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
int push_continuation
Definition options.h:558
const char * route_default_gateway
Definition options.h:426
in_addr_t push_ifconfig_local_alias
Definition options.h:517
struct dns_options dns_options
Definition options.h:318
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
const char * ipchange
Definition options.h:321
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
uint32_t virtual_hash_size
Definition options.h:500
const char * learn_address_script
Definition options.h:504
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
bool forward_compatible
Definition options.h:269
const char * username
Definition options.h:377
int cf_initial_max
Definition options.h:533
int stale_routes_check_interval
Definition options.h:538
struct plugin_option_list * plugin_list
Definition options.h:462
int auth_token_lifetime
Definition options.h:545
uint16_t vlan_pvid
Definition options.h:726
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
char * bind_dev
Definition options.h:418
const char * extra_certs_file
Definition options.h:597
bool client
Definition options.h:556
bool pull
Definition options.h:557
int ifconfig_ipv6_pool_netbits
Definition options.h:497
in_addr_t push_ifconfig_constraint_netmask
Definition options.h:520
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 ping_timer_remote
Definition options.h:352
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
const char * dh_file
Definition options.h:593
int route_delay_window
Definition options.h:432
in_addr_t push_ifconfig_local
Definition options.h:515
bool mlock
Definition options.h:340
const char ** ignore_unknown_option
Definition options.h:275
int64_t aead_usage_limit_override
Debug override to trigger AEAD usage limit early.
Definition options.h:647
int sndbuf
Definition options.h:414
int foreign_option_index
Definition options.h:688
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 ca_file_inline
Definition options.h:591
bool auth_token_secret_file_inline
Definition options.h:548
bool block_ipv6
Definition options.h:436
const char * config
Definition options.h:261
bool extra_certs_file_inline
Definition options.h:598
bool push_ifconfig_constraint_defined
Definition options.h:518
int mark
Definition options.h:417
int cf_initial_per
Definition options.h:534
int keying_material_exporter_length
Definition options.h:708
bool suppress_timestamps
Definition options.h:396
bool force_key_material_export
Definition options.h:710
bool mtu_test
Definition options.h:338
struct iroute * iroutes
Definition options.h:512
int verify_x509_type
Definition options.h:610
const char * cipher_list_tls13
Definition options.h:604
const char * ecdh_curve
Definition options.h:607
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
struct pull_filter_list * pull_filter_list
Definition options.h:728
const char * management_certificate
Definition options.h:456
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
struct in6_addr push_ifconfig_ipv6_remote
Definition options.h:525
const char * ca_path
Definition options.h:592
int renegotiate_seconds
Definition options.h:643
int ping_rec_timeout
Definition options.h:351
unsigned int sockflags
Definition options.h:421
const char * engine
Definition options.h:580
const char * management_addr
Definition options.h:446
const char * client_connect_script
Definition options.h:502
const char * verify_x509_name
Definition options.h:611
int ping_send_timeout
Definition options.h:350
bool route_gateway_via_dhcp
Definition options.h:438
bool remote_random
Definition options.h:320
bool push_ifconfig_ipv6_defined
Definition options.h:522
int tcp_queue_limit
Definition options.h:511
int route_delay
Definition options.h:431
const char * dev_node
Definition options.h:324
const char * override_username
Definition options.h:509
const char * client_crresponse_script
Definition options.h:505
struct route_ipv6_option_list * routes_ipv6
Definition options.h:435
bool machine_readable_output
Definition options.h:397
int key_direction
Definition options.h:572
bool server_ipv6_defined
Definition options.h:470
const char * priv_key_file
Definition options.h:599
bool persist_remote_ip
Definition options.h:361
bool up_restart
Definition options.h:390
int keepalive_ping
Definition options.h:342
bool tls_auth_file_inline
Definition options.h:661
bool tls_crypt_v2_file_inline
Definition options.h:670
const char * groupname
Definition options.h:378
in_addr_t server_bridge_pool_start
Definition options.h:484
const char * cd_dir
Definition options.h:380
struct client_nat_option_list * client_nat
Definition options.h:440
struct in6_addr push_ifconfig_ipv6_local
Definition options.h:523
int nice
Definition options.h:398
uint64_t push_update_options_found
Definition options.h:560
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
const char * cert_file
Definition options.h:595
bool enable_c2c
Definition options.h:527
in_addr_t server_bridge_pool_end
Definition options.h:485
int cf_per
Definition options.h:531
enum tun_driver_type windows_driver
Definition options.h:697
bool cert_file_inline
Definition options.h:596
int remap_sigusr1
Definition options.h:393
int64_t renegotiate_bytes
Definition options.h:641
const char * route_script
Definition options.h:424
in_addr_t ifconfig_pool_start
Definition options.h:489
const char * management_user_pass
Definition options.h:448
unsigned int server_netbits_ipv6
Definition options.h:472
in_addr_t push_ifconfig_remote_netmask
Definition options.h:516
bool occ
Definition options.h:443
in_addr_t server_bridge_ip
Definition options.h:482
bool ifconfig_noexec
Definition options.h:332
const char * dev
Definition options.h:322
const char * management_client_group
Definition options.h:454
struct in6_addr ifconfig_ipv6_pool_base
Definition options.h:496
const char * client_config_dir
Definition options.h:506
enum genkey_type genkey_type
Definition options.h:288
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
const char * names[MAX_PARMS]
Definition options.h:219
struct pull_filter * tail
Definition options.h:824
struct pull_filter * head
Definition options.h:823
struct pull_filter * next
Definition options.h:818
struct push_entry * head
Definition pushlist.h:37
Definition options.h:185
int proto
Definition options.h:188
const char * remote
Definition options.h:186
const char * remote_port
Definition options.h:187
sa_family_t af
Definition options.h:189
struct remote_entry ** array
Definition options.h:213
int capacity
Definition options.h:211
unsigned int flags
Definition route.h:113
struct route_ipv6_option * routes_ipv6
Definition route.h:114
unsigned int flags
Definition route.h:97
struct route_option * routes
Definition route.h:98
unsigned int flags
Definition misc.h:96
const char * challenge_text
Definition misc.h:98
struct in6_addr dns6[N_DHCP_ADDR]
Definition tun.h:140
in_addr_t nbdd[N_DHCP_ADDR]
Definition tun.h:123
unsigned int dns6_len
Definition tun.h:141
in_addr_t ntp[N_DHCP_ADDR]
Definition tun.h:119
unsigned int ntp_len
Definition tun.h:120
in_addr_t wins[N_DHCP_ADDR]
Definition tun.h:115
int tap_sleep
Definition tun.h:95
uint8_t netbios_node_type
Definition tun.h:105
unsigned int dns_len
Definition tun.h:112
int dhcp_lease_time
Definition tun.h:92
in_addr_t dns[N_DHCP_ADDR]
Definition tun.h:111
const char * netbios_scope
Definition tun.h:103
bool ip_win32_defined
Definition tun.h:75
unsigned int domain_search_list_len
Definition tun.h:130
bool dhcp_masq_custom_offset
Definition tun.h:90
const char * domain
Definition tun.h:101
bool dhcp_renew
Definition tun.h:135
const char * domain_search_list[N_SEARCH_LIST_LEN]
Definition tun.h:129
int dhcp_masq_offset
Definition tun.h:91
int ip_win32_type
Definition tun.h:83
unsigned int nbdd_len
Definition tun.h:124
bool dhcp_pre_release
Definition tun.h:136
bool register_dns
Definition tun.h:138
bool disable_nbt
Definition tun.h:133
unsigned int wins_len
Definition tun.h:116
int dhcp_options
Definition tun.h:99
struct verify_hash_list * next
Definition options.h:252
uint8_t hash[SHA256_DIGEST_LENGTH]
Definition options.h:251
#define SIGHUP
Definition syshead.h:55
unsigned short sa_family_t
Definition syshead.h:405
#define SIGTERM
Definition syshead.h:59
#define sleep(x)
Definition syshead.h:42
uint32_t in_addr_t
Definition syshead.h:52
struct gc_arena gc
Definition test_ssl.c:138
void ipconfig_register_dns(const struct env_set *es)
Definition tun.c:4995
int dev_type_enum(const char *dev, const char *dev_type)
Definition tun.c:527
void show_tap_win_adapters(msglvl_t msglevel, msglvl_t warnlevel)
Definition tun.c:3922
bool dhcp_renew_by_adapter_index(const DWORD adapter_index)
Definition tun.c:4928
int ascii2ipset(const char *name)
Definition tun.c:6358
bool dhcp_release_by_adapter_index(const DWORD adapter_index)
Definition tun.c:4887
void tap_allow_nonadmin_access(const char *dev_node)
Definition tun.c:4807
void show_adapters(msglvl_t msglevel)
Definition tun.c:4758
const char * ipset2ascii_all(struct gc_arena *gc)
Definition tun.c:6387
void show_valid_win32_tun_subnets(void)
Definition tun.c:3889
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 IPW32_SET_NETSH
Definition tun.h:78
#define IPW32_SET_ADAPTIVE
Definition tun.h:81
#define DHCP_OPTIONS_DHCP_REQUIRED
Definition tun.h:70
#define N_SEARCH_LIST_LEN
Definition tun.h:126
#define IPW32_SET_DHCP_MASQ
Definition tun.h:80
#define IPW32_SET_MANUAL
Definition tun.h:77
@ WINDOWS_DRIVER_UNSPECIFIED
Definition tun.h:45
@ WINDOWS_DRIVER_TAP_WINDOWS6
Definition tun.h:46
@ DRIVER_DCO
Definition tun.h:53
#define IPW32_SET_ADAPTIVE_DELAY_WINDOW
Definition tun.h:65
#define N_DHCP_ADDR
Definition tun.h:108
#define DHCP_OPTIONS_DHCP_OPTIONAL
Definition tun.h:69
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 set_win_sys_path(const char *newpath, struct env_set *es)
Definition win32.c:1169
const char * win32_version_string(struct gc_arena *gc)
Get Windows version string with architecture info.
Definition win32.c:1415
void set_pause_exit_win32(void)
Definition win32.c:147