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 "buffer.h"
39#include "error.h"
40#include "common.h"
41#include "run_command.h"
42#include "shaper.h"
43#include "crypto.h"
44#include "ssl.h"
45#include "ssl_ncp.h"
46#include "options.h"
47#include "misc.h"
48#include "socket_util.h"
49#include "packet_id.h"
50#include "pkcs11.h"
51#include "win32.h"
52#include "push.h"
53#include "pool.h"
54#include "proto.h"
55#include "helper.h"
56#include "manage.h"
57#include "forward.h"
58#include "ssl_verify.h"
59#include "platform.h"
60#include "xkey_common.h"
61#include "dco.h"
62#include "options_util.h"
63#include "tun_afunix.h"
64#include "domain_helper.h"
65#include "mbuf.h"
66#include "check_file_access.h"
67
68#include <ctype.h>
69
70#include "memdbg.h"
71#include "options_util.h"
72
74#ifdef CONFIGURE_GIT_REVISION
75 " [git:" CONFIGURE_GIT_REVISION CONFIGURE_GIT_FLAGS "]"
76#endif
77 " " TARGET_ALIAS
78#if defined(ENABLE_CRYPTO_MBEDTLS)
79 " [SSL (mbed TLS)]"
80#elif defined(ENABLE_CRYPTO_OPENSSL)
81 " [SSL (OpenSSL)]"
82#else
83 " [SSL]"
84#endif /* defined(ENABLE_CRYPTO_MBEDTLS) */
85#ifdef USE_COMP
86#ifdef ENABLE_LZO
87 " [LZO]"
88#endif
89#ifdef ENABLE_LZ4
90 " [LZ4]"
91#endif
92#ifdef ENABLE_COMP_STUB
93 " [COMP_STUB]"
94#endif
95#endif /* USE_COMP */
96#if EPOLL
97 " [EPOLL]"
98#endif
99#ifdef PRODUCT_TAP_DEBUG
100 " [TAPDBG]"
101#endif
102#ifdef ENABLE_PKCS11
103 " [PKCS11]"
104#endif
105#if ENABLE_IP_PKTINFO
106#if defined(HAVE_IN_PKTINFO) && defined(HAVE_IPI_SPEC_DST)
107 " [MH/PKTINFO]"
108#elif defined(IP_RECVDSTADDR)
109 " [MH/RECVDA]"
110#endif
111#endif
112 " [AEAD]"
113#ifdef ENABLE_DCO
114 " [DCO]"
115#endif
116#ifdef ENABLE_SMALL
117 " [SMALL]"
118#endif
119#ifdef ENABLE_DEBUG
120 " [DEBUG]"
121#endif
122#ifdef CONFIGURE_GIT_REVISION
123 " built on " __DATE__
124#endif
125
126 ;
127
128#ifndef ENABLE_SMALL
129
130static const char usage_message[] =
131 "%s\n"
132 "\n"
133 "General Options:\n"
134 "--config file : Read configuration options from file.\n"
135 "--help : Show options.\n"
136 "--version : Show copyright and version information.\n"
137 "\n"
138 "Tunnel Options:\n"
139 "--local host|* [port]: Local host name or IP address and port for bind.\n"
140 " If specified, OpenVPN will bindto this address. If unspecified,\n"
141 " OpenVPN will bind to all interfaces. '*' can be used as hostname\n"
142 " and means 'any host' (OpenVPN will listen on what is returned by the OS).\n"
143 " On a client, or in point-to-point mode, this can only be specified once (1 socket).\n"
144 " On an OpenVPN setup running as ``--server``, this can be specified multiple times\n"
145 " to open multiple listening sockets on different addresses and/or different ports.\n"
146 " In order to specify multiple listen ports without specifying an address, use '*'\n"
147 " to signal 'use what the operating system gives you as default', for\n"
148 " 'all IPv4 addresses' use '0.0.0.0', for 'all IPv6 addresses' use '::'.\n"
149 " ``--local`` implies ``--bind``.\n"
150 "--remote host [port] : Remote host name or ip address.\n"
151 "--remote-random : If multiple --remote options specified, choose one randomly.\n"
152 "--remote-random-hostname : Add a random string to remote DNS name.\n"
153 "--mode m : Major mode, m = 'p2p' (default, point-to-point) or 'server'.\n"
154 "--proto p : Use protocol p for communicating with peer.\n"
155 " p = udp (default), tcp-server, tcp-client\n"
156 " udp4, tcp4-server, tcp4-client\n"
157 " udp6, tcp6-server, tcp6-client\n"
158 "--proto-force p : only consider protocol p in list of connection profiles.\n"
159 " p = udp or tcp\n"
160 "--connect-retry n [m] : For client, number of seconds to wait between\n"
161 " connection retries (default=%d). On repeated retries\n"
162 " the wait time is exponentially increased to a maximum of m\n"
163 " (default=%d).\n"
164 "--connect-retry-max n : Maximum connection attempt retries, default infinite.\n"
165 "--http-proxy s p [up] [auth] : Connect to remote host\n"
166 " through an HTTP proxy at address s and port p.\n"
167 " If proxy authentication is required,\n"
168 " up is a file containing username/password on 2 lines, or\n"
169 " 'stdin' to prompt from console.\n"
170 "--http-proxy s p 'auto[-nct]' : Like the above directive, but automatically\n"
171 " determine auth method and query for username/password\n"
172 " if needed. auto-nct disables weak proxy auth methods.\n"
173 "--http-proxy-option type [parm] : Set extended HTTP proxy options.\n"
174 " Repeat to set multiple options.\n"
175 " VERSION version (default=1.0)\n"
176 " AGENT user-agent\n"
177 "--socks-proxy s [p] [up] : Connect to remote host through a Socks5 proxy at\n"
178 " address s and port p (default port = 1080).\n"
179 " If proxy authentication is required,\n"
180 " up is a file containing username/password on 2 lines, or\n"
181 " 'stdin' to prompt for console.\n"
182 "--socks-proxy-retry : Retry indefinitely on Socks proxy errors.\n"
183 "--resolv-retry n: If hostname resolve fails for --remote, retry\n"
184 " resolve for n seconds before failing (disabled by default).\n"
185 " Set n=\"infinite\" to retry indefinitely.\n"
186 "--preresolve : Resolve configured --remote, --local, and proxy hostnames at startup.\n"
187 "--float : Allow remote to change its IP address/port, such as through\n"
188 " DHCP (this is the default if --remote is not used).\n"
189 "--ipchange cmd : Run command cmd on remote ip address initial\n"
190 " setting or change -- execute as: cmd ip-address port#\n"
191 "--port port : TCP/UDP port # for both local and remote.\n"
192 "--lport port : TCP/UDP port # for local (default=%s). Implies --bind.\n"
193 "--rport port : TCP/UDP port # for remote (default=%s).\n"
194 "--bind : Bind to local address and port. (This is the default unless\n"
195 " --proto tcp-client"
196 " or --http-proxy"
197 " or --socks-proxy"
198 " is used).\n"
199 "--nobind : Do not bind to local address and port.\n"
200 "--dev tunX|tapX : tun/tap device (X can be omitted for dynamic device).\n"
201 " Defaults to \"tun\" if neither --dev nor --dev-type is given.\n"
202 "--dev-type dt : Which device type are we using? (dt = tun or tap) Use\n"
203 " this option only if the tun/tap device used with --dev\n"
204 " does not begin with \"tun\" or \"tap\".\n"
205 "--dev-node node : Explicitly set the device node rather than using\n"
206 " /dev/net/tun, /dev/tun, /dev/tap, etc.\n"
207#if defined(ENABLE_DCO)
208 "--disable-dco : Do not attempt using Data Channel Offload.\n"
209#endif
210 "--lladdr hw : Set the link layer address of the tap device.\n"
211 "--topology t : Set --dev tun topology: 'net30', 'p2p', or 'subnet'.\n"
212#ifdef ENABLE_IPROUTE
213 "--iproute cmd : Use this command instead of default " IPROUTE_PATH ".\n"
214#endif
215 "--ifconfig l rn : TUN: configure device to use IP address l as a local\n"
216 " endpoint and rn as a remote endpoint. l & rn should be\n"
217 " swapped on the other peer. l & rn must be private\n"
218 " addresses outside of the subnets used by either peer.\n"
219 " TAP: configure device to use IP address l as a local\n"
220 " endpoint and rn as a subnet mask.\n"
221 "--ifconfig-ipv6 l r : configure device to use IPv6 address l as local\n"
222 " endpoint (as a /64) and r as remote endpoint\n"
223 "--ifconfig-noexec : Don't actually execute ifconfig/netsh command, instead\n"
224 " pass --ifconfig parms by environment to scripts.\n"
225 "--ifconfig-nowarn : Don't warn if the --ifconfig option on this side of the\n"
226 " connection doesn't match the remote side.\n"
227#ifdef TARGET_LINUX
228 "--route-table table_id : Specify a custom routing table for use with --route(-ipv6).\n"
229 " If not specified, the id of the default routing table will be used.\n"
230#endif
231 "--route network [netmask] [gateway] [metric] :\n"
232 " Add route to routing table after connection\n"
233 " is established. Multiple routes can be specified.\n"
234 " netmask default: 255.255.255.255\n"
235 " gateway default: taken from --route-gateway or --ifconfig\n"
236 " Specify default by leaving blank or setting to \"default\".\n"
237 "--route-ipv6 network/bits [gateway] [metric] :\n"
238 " Add IPv6 route to routing table after connection\n"
239 " is established. Multiple routes can be specified.\n"
240 " gateway default: taken from --route-ipv6-gateway or 'remote'\n"
241 " in --ifconfig-ipv6\n"
242 "--route-gateway gw|'dhcp' : Specify a default gateway for use with --route.\n"
243 "--route-ipv6-gateway gw : Specify a default gateway for use with --route-ipv6.\n"
244 "--route-metric m : Specify a default metric for use with --route.\n"
245 "--route-delay n [w] : Delay n seconds after connection initiation before\n"
246 " adding routes (may be 0). If not specified, routes will\n"
247 " be added immediately after tun/tap open. On Windows, wait\n"
248 " up to w seconds for TUN/TAP adapter to come up.\n"
249 "--route-up cmd : Run command cmd after routes are added.\n"
250 "--route-pre-down cmd : Run command cmd before routes are removed.\n"
251 "--route-noexec : Don't add routes automatically. Instead pass routes to\n"
252 " --route-up script using environmental variables.\n"
253 "--route-nopull : When used with --client or --pull, accept options pushed\n"
254 " by server EXCEPT for routes, dns, and dhcp options.\n"
255 "--allow-pull-fqdn : Allow client to pull DNS names from server for\n"
256 " --ifconfig, --route, and --route-gateway.\n"
257 "--redirect-gateway [flags]: Automatically execute routing\n"
258 " commands to redirect all outgoing IP traffic through the\n"
259 " VPN. Add 'local' flag if both " PACKAGE_NAME " servers are directly\n"
260 " connected via a common subnet, such as with WiFi.\n"
261 " Add 'def1' flag to set default route using using 0.0.0.0/1\n"
262 " and 128.0.0.0/1 rather than 0.0.0.0/0. Add 'bypass-dhcp'\n"
263 " flag to add a direct route to DHCP server, bypassing tunnel.\n"
264 " Add 'bypass-dns' flag to similarly bypass tunnel for DNS.\n"
265 "--redirect-private [flags]: Like --redirect-gateway, but omit actually changing\n"
266 " the default gateway. Useful when pushing private subnets.\n"
267 "--block-ipv6 : (Client) Instead sending IPv6 to the server generate\n"
268 " ICMPv6 host unreachable messages on the client.\n"
269 " (Server) Instead of forwarding IPv6 packets send\n"
270 " ICMPv6 host unreachable packets to the client.\n"
271 "--client-nat snat|dnat network netmask alias : on client add 1-to-1 NAT rule.\n"
272 "--push-peer-info : (client only) push client info to server.\n"
273 "--setenv name value : Set a custom environmental variable to pass to script.\n"
274 "--setenv FORWARD_COMPATIBLE 1 : Relax config file syntax checking to allow\n"
275 " directives for future OpenVPN versions to be ignored.\n"
276 "--ignore-unknown-option opt1 opt2 ...: Relax config file syntax. Allow\n"
277 " these options to be ignored when unknown\n"
278 "--script-security level: Where level can be:\n"
279 " 0 -- strictly no calling of external programs\n"
280 " 1 -- (default) only call built-ins such as ifconfig\n"
281 " 2 -- allow calling of built-ins and scripts\n"
282 " 3 -- allow password to be passed to scripts via env\n"
283 "--shaper n : Restrict output to peer to n bytes per second.\n"
284 "--keepalive n m : Helper option for setting timeouts in server mode. Send\n"
285 " ping once every n seconds, restart if ping not received\n"
286 " for m seconds.\n"
287 "--inactive n [bytes] : Exit after n seconds of activity on tun/tap device\n"
288 " produces a combined in/out byte count < bytes.\n"
289 "--session-timeout n: Limit connection time to n seconds.\n"
290 "--ping-exit n : Exit if n seconds pass without reception of remote ping.\n"
291 "--ping-restart n: Restart if n seconds pass without reception of remote ping.\n"
292 "--ping-timer-rem: Run the --ping-exit/--ping-restart timer only if we have a\n"
293 " remote address.\n"
294 "--ping n : Ping remote once every n seconds over TCP/UDP port.\n"
295#if ENABLE_IP_PKTINFO
296 "--multihome : Configure a multi-homed UDP server.\n"
297#endif
298 "--remap-usr1 s : On SIGUSR1 signals, remap signal (s='SIGHUP' or 'SIGTERM').\n"
299 "--persist-tun : Keep tun/tap device open across SIGUSR1 or --ping-restart.\n"
300 "--persist-remote-ip : Keep remote IP address across SIGUSR1 or --ping-restart.\n"
301 "--persist-local-ip : Keep local IP address across SIGUSR1 or --ping-restart.\n"
302#if PASSTOS_CAPABILITY
303 "--passtos : TOS passthrough (applies to IPv4 only).\n"
304#endif
305 "--tun-mtu n : Take the tun/tap device MTU to be n and derive the\n"
306 " TCP/UDP MTU from it (default=%d).\n"
307 "--tun-mtu-extra n : Assume that tun/tap device might return as many\n"
308 " as n bytes more than the tun-mtu size on read\n"
309 " (default TUN=0 TAP=%d).\n"
310 "--tun-mtu-max n : Maximum pushable MTU (default and minimum=%d).\n"
311 "--link-mtu n : Take the TCP/UDP device MTU to be n and derive the tun MTU\n"
312 " from it.\n"
313 "--mtu-disc type : Should we do Path MTU discovery on TCP/UDP channel?\n"
314 " 'no' -- Never send DF (Don't Fragment) frames\n"
315 " 'maybe' -- Use per-route hints\n"
316 " 'yes' -- Always DF (Don't Fragment)\n"
317 "--mtu-test : Empirically measure and report MTU.\n"
318#ifdef ENABLE_FRAGMENT
319 "--fragment max : Enable internal datagram fragmentation so that no UDP\n"
320 " datagrams are sent which are larger than max bytes.\n"
321 " Adds 4 bytes of overhead per datagram.\n"
322#endif
323 "--mssfix [n] : Set upper bound on TCP MSS, default = tun-mtu size\n"
324 " or --fragment max value, whichever is lower.\n"
325 "--sndbuf size : Set the TCP/UDP send buffer size.\n"
326 "--rcvbuf size : Set the TCP/UDP receive buffer size.\n"
327#if defined(TARGET_LINUX)
328 "--mark value : Mark encrypted packets being sent with value. The mark value\n"
329 " can be matched in policy routing and packetfilter rules.\n"
330 "--bind-dev dev : Bind to the given device when making connection to a peer or\n"
331 " listening for connections. This allows sending encrypted packets\n"
332 " via a VRF present on the system.\n"
333#endif
334 "--txqueuelen n : Set the tun/tap TX queue length to n (Linux only).\n"
335 "--mlock : Disable Paging -- ensures key material and tunnel\n"
336 " data will never be written to disk.\n"
337 "--up cmd : Run command cmd after successful tun device open.\n"
338 " Execute as: cmd tun/tap-dev tun-mtu link-mtu \\\n"
339 " ifconfig-local-ip ifconfig-remote-ip\n"
340 " (pre --user or --group UID/GID change)\n"
341 "--up-delay : Delay tun/tap open and possible --up script execution\n"
342 " until after TCP/UDP connection establishment with peer.\n"
343 "--down cmd : Run command cmd after tun device close.\n"
344 " (post --user/--group UID/GID change and/or --chroot)\n"
345 " (command parameters are same as --up option)\n"
346 "--down-pre : Run --down command before TUN/TAP close.\n"
347 "--up-restart : Run up/down commands for all restarts including those\n"
348 " caused by --ping-restart or SIGUSR1\n"
349 "--user user : Set UID to user after initialization.\n"
350 "--group group : Set GID to group after initialization.\n"
351 "--chroot dir : Chroot to this directory after initialization.\n"
352#ifdef ENABLE_SELINUX
353 "--setcon context: Apply this SELinux context after initialization.\n"
354#endif
355 "--cd dir : Change to this directory before initialization.\n"
356 "--daemon [name] : Become a daemon after initialization.\n"
357 " The optional 'name' parameter will be passed\n"
358 " as the program name to the system logger.\n"
359 "--syslog [name] : Output to syslog, but do not become a daemon.\n"
360 " See --daemon above for a description of the 'name' parm.\n"
361 "--log file : Output log to file which is created/truncated on open.\n"
362 "--log-append file : Append log to file, or create file if nonexistent.\n"
363 "--suppress-timestamps : Don't log timestamps to stdout/stderr.\n"
364 "--machine-readable-output : Always log timestamp, message flags to stdout/stderr.\n"
365 "--writepid file : Write main process ID to file.\n"
366 "--nice n : Change process priority (>0 = lower, <0 = higher).\n"
367 "--echo [parms ...] : Echo parameters to log output.\n"
368 "--verb n : Set output verbosity to n (default=%d):\n"
369 " (Level 3 is recommended if you want a good summary\n"
370 " of what's happening without being swamped by output).\n"
371 " : 0 -- no output except fatal errors\n"
372 " : 1 -- startup info + connection initiated messages +\n"
373 " non-fatal encryption & net errors\n"
374 " : 2,3 -- show TLS negotiations & route info\n"
375 " : 4 -- show parameters\n"
376 " : 5 -- show 'RrWw' chars on console for each packet sent\n"
377 " and received from TCP/UDP (caps) or tun/tap (lc)\n"
378 " : 6 to 11 -- debug messages of increasing verbosity\n"
379 "--mute n : Log at most n consecutive messages in the same category.\n"
380 "--status file [n] : Write operational status to file every n seconds.\n"
381 "--status-version [n] : Choose the status file format version number.\n"
382 " Currently, n can be 1, 2, or 3 (default=1).\n"
383 "--disable-occ : (DEPRECATED) Disable options consistency check between peers.\n"
384#ifdef ENABLE_DEBUG
385 "--gremlin mask : Special stress testing mode (for debugging only).\n"
386#endif
387#if defined(USE_COMP)
388 "--compress alg : Use compression algorithm alg\n"
389 "--allow-compression: Specify whether compression should be allowed\n"
390#if defined(ENABLE_LZO)
391 "--comp-lzo : Use LZO compression -- may add up to 1 byte per\n"
392 " packet for incompressible data.\n"
393 "--comp-noadapt : Don't use adaptive compression when --comp-lzo\n"
394 " is specified.\n"
395#endif
396#endif
397#ifdef ENABLE_MANAGEMENT
398 "--management ip port [pass] : Enable a TCP server on ip:port to handle\n"
399 " management functions. pass is a password file\n"
400 " or 'stdin' to prompt from console.\n"
401#if UNIX_SOCK_SUPPORT
402 " To listen on a unix domain socket, specific the pathname\n"
403 " in place of ip and use 'unix' as the port number.\n"
404#endif
405 "--management-client : Management interface will connect as a TCP client to\n"
406 " ip/port rather than listen as a TCP server.\n"
407 "--management-query-passwords : Query management channel for private key\n"
408 " and auth-user-pass passwords.\n"
409 "--management-query-proxy : Query management channel for proxy information.\n"
410 "--management-query-remote : Query management channel for --remote directive.\n"
411 "--management-hold : Start " PACKAGE_NAME " in a hibernating state, until a client\n"
412 " of the management interface explicitly starts it.\n"
413 "--management-signal : Issue SIGUSR1 when management disconnect event occurs.\n"
414 "--management-forget-disconnect : Forget passwords when management disconnect\n"
415 " event occurs.\n"
416 "--management-up-down : Report tunnel up/down events to management interface.\n"
417 "--management-log-cache n : Cache n lines of log file history for usage\n"
418 " by the management channel.\n"
419#if UNIX_SOCK_SUPPORT
420 "--management-client-user u : When management interface is a unix socket, only\n"
421 " allow connections from user u.\n"
422 "--management-client-group g : When management interface is a unix socket, only\n"
423 " allow connections from group g.\n"
424#endif
425 "--management-client-auth : gives management interface client the responsibility\n"
426 " to authenticate clients after their client certificate\n"
427 " has been verified.\n"
428#endif /* ifdef ENABLE_MANAGEMENT */
429#ifdef ENABLE_PLUGIN
430 "--plugin m [str]: Load plug-in module m passing str as an argument\n"
431 " to its initialization function.\n"
432#endif
433 "--vlan-tagging : Enable 802.1Q-based VLAN tagging.\n"
434 "--vlan-accept tagged|untagged|all : Set VLAN tagging mode. Default is 'all'.\n"
435 "--vlan-pvid v : Sets the Port VLAN Identifier. Defaults to 1.\n"
436 "\n"
437 "Multi-Client Server options (when --mode server is used):\n"
438 "--server network netmask : Helper option to easily configure server mode.\n"
439 "--server-ipv6 network/bits : Configure IPv6 server mode.\n"
440 "--server-bridge [IP netmask pool-start-IP pool-end-IP] : Helper option to\n"
441 " easily configure ethernet bridging server mode.\n"
442 "--push \"option\" : Push a config file option back to the peer for remote\n"
443 " execution. Peer must specify --pull in its config file.\n"
444 "--push-reset : Don't inherit global push list for specific\n"
445 " client instance.\n"
446 "--push-remove opt : Remove options matching 'opt' from the push list for\n"
447 " a specific client instance.\n"
448 "--ifconfig-pool start-IP end-IP [netmask] : Set aside a pool of subnets\n"
449 " to be dynamically allocated to connecting clients.\n"
450 "--ifconfig-pool-persist file [seconds] : Persist/unpersist ifconfig-pool\n"
451 " data to file, at seconds intervals (default=600).\n"
452 " If seconds=0, file will be treated as read-only.\n"
453 "--ifconfig-ipv6-pool base-IP/bits : set aside an IPv6 network block\n"
454 " to be dynamically allocated to connecting clients.\n"
455 "--ifconfig-push local remote-netmask : Push an ifconfig option to remote,\n"
456 " overrides --ifconfig-pool dynamic allocation.\n"
457 " Only valid in a client-specific config file.\n"
458 "--ifconfig-ipv6-push local/bits remote : Push an ifconfig-ipv6 option to\n"
459 " remote, overrides --ifconfig-ipv6-pool allocation.\n"
460 " Only valid in a client-specific config file.\n"
461 "--iroute network [netmask] : Route subnet to client.\n"
462 "--iroute-ipv6 network/bits : Route IPv6 subnet to client.\n"
463 " Sets up internal routes only.\n"
464 " Only valid in a client-specific config file.\n"
465 "--disable : Client is disabled.\n"
466 " Only valid in a client-specific config file.\n"
467 "--override-username: Overrides the client-specific username to be used.\n"
468 " Only valid in a client-specific config file.\n"
469 "--verify-client-cert [none|optional|require] : perform no, optional or\n"
470 " mandatory client certificate verification.\n"
471 " Default is to require the client to supply a certificate.\n"
472 "--username-as-common-name : For auth-user-pass authentication, use\n"
473 " the authenticated username as the common name,\n"
474 " rather than the common name from the client cert.\n"
475 "--auth-user-pass-verify cmd method: Query client for username/password and\n"
476 " run command cmd to verify. If method='via-env', pass\n"
477 " user/pass via environment, if method='via-file', pass\n"
478 " user/pass via temporary file.\n"
479 "--auth-gen-token [lifetime] Generate a random authentication token which is pushed\n"
480 " to each client, replacing the password. Useful when\n"
481 " OTP based two-factor auth mechanisms are in use and\n"
482 " --reneg-* options are enabled. Optionally a lifetime in seconds\n"
483 " for generated tokens can be set.\n"
484 "--auth-user-pass-optional : Allow connections by clients that don't\n"
485 " specify a username/password.\n"
486 "--client-to-client : Internally route client-to-client traffic.\n"
487 "--duplicate-cn : Allow multiple clients with the same common name to\n"
488 " concurrently connect.\n"
489 "--client-connect cmd : Run command cmd on client connection.\n"
490 "--client-disconnect cmd : Run command cmd on client disconnection.\n"
491 "--client-config-dir dir : Directory for custom client config files.\n"
492 "--ccd-exclusive : Refuse connection unless custom client config is found.\n"
493 "--tmp-dir dir : Temporary directory, used for --client-connect return file and plugin communication.\n"
494 "--hash-size r v : Set the size of the real address hash table to r and the\n"
495 " virtual address table to v.\n"
496 "--bcast-buffers n : Allocate n broadcast buffers.\n"
497 "--tcp-queue-limit n : Maximum number of queued TCP output packets.\n"
498 "--tcp-nodelay : In server mode, push TCP_NODELAY to clients (it is\n"
499 " enabled by default on the local socket).\n"
500 "--learn-address cmd : Run command cmd to validate client virtual addresses.\n"
501 "--connect-freq n s : Allow a maximum of n new connections per s seconds.\n"
502 "--connect-freq-initial n s : Allow a maximum of n replies for initial connections attempts per s seconds.\n"
503 "--max-clients n : Allow a maximum of n simultaneously connected clients.\n"
504 "--max-routes-per-client n : Allow a maximum of n internal routes per client.\n"
505 "--stale-routes-check n [t] : Remove routes with a last activity timestamp\n"
506 " older than n seconds. Run this check every t\n"
507 " seconds (defaults to n).\n"
508 "--explicit-exit-notify [n] : In UDP server mode send [RESTART] command on exit/restart to connected\n"
509 " clients. n = 1 - reconnect to same server,\n"
510 " 2 - advance to next server, default=1.\n"
511#if PORT_SHARE
512 "--port-share host port [dir] : When run in TCP mode, proxy incoming HTTPS\n"
513 " sessions to a web server at host:port. dir specifies an\n"
514 " optional directory to write origin IP:port data.\n"
515#endif
516 "\n"
517 "Client options (when connecting to a multi-client server):\n"
518 "--client : Helper option to easily configure client mode.\n"
519 "--auth-user-pass [up] : Authenticate with server using username/password.\n"
520 " up is a file containing the username on the first line,\n"
521 " and a password on the second. If either the password or both\n"
522 " the username and the password are omitted OpenVPN will prompt\n"
523 " for them from console. If [up] is 'username-only', only username\n"
524 " will be prompted for from console or management interface.\n"
525 "--pull : Accept certain config file options from the peer as if they\n"
526 " were part of the local config file. Must be specified\n"
527 " when connecting to a '--mode server' remote host.\n"
528 "--pull-filter accept|ignore|reject t : Filter each option received from the\n"
529 " server if it starts with the text t. The action flag accept,\n"
530 " ignore or reject causes the option to be allowed, removed or\n"
531 " rejected with error. May be specified multiple times, and\n"
532 " each filter is applied in the order of appearance.\n"
533 "--dns server <n> <option> <value> [value ...] : Configure option for DNS server #n\n"
534 " Valid options are :\n"
535 " address <addr[:port]> [addr[:port] ...] : server addresses 4/6\n"
536 " resolve-domains <domain> [domain ...] : split domains\n"
537 " dnssec <yes|no|optional> : option to use DNSSEC\n"
538 " transport <DoH|DoT> : query server over HTTPS / TLS\n"
539 " sni <domain> : DNS server name indication\n"
540 "--dns search-domains <domain> [domain ...]:\n"
541 " Add domains to DNS domain search list\n"
542 "--dns-updown cmd|force|disable : Run cmd as user defined dns config command,\n"
543 " force running the default script or disable running it.\n"
544 "--auth-retry t : How to handle auth failures. Set t to\n"
545 " none (default), interact, or nointeract.\n"
546 "--static-challenge t e [<scrv1|concat>]: Enable static challenge/response protocol using\n"
547 " challenge text t, with e indicating echo flag (0|1)\n"
548 " and optional argument scrv1 or concat to use SCRV1 protocol or"
549 " concatenate response with password. Default is scrv1.\n"
550 "--connect-timeout n : when polling possible remote servers to connect to\n"
551 " in a round-robin fashion, spend no more than n seconds\n"
552 " waiting for a response before trying the next server.\n"
553 "--allow-recursive-routing : When this option is set, OpenVPN will not drop\n"
554 " incoming tun packets with same destination as host.\n"
555 "--explicit-exit-notify [n] : On exit/restart, send exit signal to\n"
556 " server/remote. n = # of retries, default=1.\n"
557 "\n"
558 "Data Channel Encryption Options (must be compatible between peers):\n"
559 "(These options are meaningful for both Static Key & TLS-mode)\n"
560 "--auth alg : Authenticate packets with HMAC using message\n"
561 " digest algorithm alg (default=%s).\n"
562 " (usually adds 16 or 20 bytes per packet)\n"
563 " Set alg=none to disable authentication.\n"
564 "--cipher alg : Encrypt packets with cipher algorithm alg.\n"
565 " You should usually use --data-ciphers instead.\n"
566 " Set alg=none to disable encryption.\n"
567 "--data-ciphers list : List of ciphers that are allowed to be negotiated.\n"
568#ifndef ENABLE_CRYPTO_MBEDTLS
569 "--engine [name] : Enable OpenSSL hardware crypto engine functionality.\n"
570#endif
571 "--mute-replay-warnings : Silence the output of replay warnings to log file.\n"
572 "--replay-window n [t] : Use a replay protection sliding window of size n\n"
573 " and a time window of t seconds.\n"
574 " Default n=%d t=%d\n"
575 "--replay-persist file : Persist replay-protection state across sessions\n"
576 " using file.\n"
577 "--test-crypto : Run a self-test of crypto features enabled.\n"
578 " For debugging only.\n"
579 "\n"
580 "TLS Key Negotiation Options:\n"
581 "(These options are meaningful only for TLS-mode)\n"
582 "--tls-server : Enable TLS and assume server role during TLS handshake.\n"
583 "--tls-client : Enable TLS and assume client role during TLS handshake.\n"
584 "--ca file : Certificate authority file in .pem format containing\n"
585 " root certificate.\n"
586#ifndef ENABLE_CRYPTO_MBEDTLS
587 "--capath dir : A directory of trusted certificates (CAs"
588 " and CRLs).\n"
589#endif /* ENABLE_CRYPTO_MBEDTLS */
590 "--dh file : File containing Diffie Hellman parameters\n"
591 " in .pem format (for --tls-server only).\n"
592 " Use \"openssl dhparam -out dh1024.pem 1024\" to generate.\n"
593 "--cert file : Local certificate in .pem format or a URI -- must be signed\n"
594 " by a Certificate Authority in --ca file used by the peer.\n"
595 "--extra-certs file : one or more PEM certs that complete the cert chain.\n"
596 "--key file : Local private key in .pem format or a URI.\n"
597 "--tls-version-min <version> ['or-highest'] : sets the minimum TLS version we\n"
598 " will accept from the peer. If version is unrecognized and 'or-highest'\n"
599 " is specified, require max TLS version supported by SSL implementation.\n"
600 "--tls-version-max <version> : sets the maximum TLS version we will use.\n"
601#ifndef ENABLE_CRYPTO_MBEDTLS
602 "--pkcs12 file : PKCS#12 file containing local private key, local certificate\n"
603 " and optionally the root CA certificate.\n"
604 "--x509-username-field : Field in x509 certificate containing the username.\n"
605 " Default is CN in the Subject field.\n"
606#endif
607 "--verify-hash hash [algo] : Specify fingerprint for level-1 certificate.\n"
608 " Valid algo flags are SHA1 and SHA256. \n"
609#ifdef _WIN32
610 "--cryptoapicert select-string : Load the certificate and private key from the\n"
611 " Windows Certificate System Store.\n"
612#endif
613 "--tls-cipher l : A list l of allowable TLS ciphers separated by : (optional).\n"
614 "--tls-ciphersuites l: A list of allowed TLS 1.3 cipher suites separated by : (optional)\n"
615 " : Use --show-tls to see a list of supported TLS ciphers (suites).\n"
616 "--tls-cert-profile p : Set the allowed certificate crypto algorithm profile\n"
617 " (default=legacy).\n"
618#ifndef ENABLE_CRYPTO_MBEDTLS
619 "--providers l : A list l of OpenSSL providers to load.\n"
620#endif
621 "--tls-timeout n : Packet retransmit timeout on TLS control channel\n"
622 " if no ACK from remote within n seconds (default=%d).\n"
623 "--reneg-bytes n : Renegotiate data chan. key after n bytes sent and recvd.\n"
624 "--reneg-pkts n : Renegotiate data chan. key after n packets sent and recvd.\n"
625 "--reneg-sec max [min] : Renegotiate data chan. key after at most max (default=%d)\n"
626 " and at least min (defaults to 90%% of max on servers and equal\n"
627 " to max on clients).\n"
628 "--hand-window n : Data channel key exchange must finalize within n seconds\n"
629 " of handshake initiation by any peer (default=%d).\n"
630 "--tran-window n : Transition window -- old key can live this many seconds\n"
631 " after new key renegotiation begins (default=%d).\n"
632 "--single-session: Allow only one session (reset state on restart).\n"
633 "--tls-exit : Exit on TLS negotiation failure.\n"
634 "--tls-auth f [d]: Add an additional layer of authentication on top of the TLS\n"
635 " control channel to protect against attacks on the TLS stack\n"
636 " and DoS attacks.\n"
637 " f (required) is a shared-secret key file.\n"
638 " The optional d parameter controls key directionality.\n"
639 "--tls-crypt key : Add an additional layer of authenticated encryption on top\n"
640 " of the TLS control channel to hide the TLS certificate,\n"
641 " provide basic post-quantum security and protect against\n"
642 " attacks on the TLS stack and DoS attacks.\n"
643 " key (required) provides the pre-shared key file.\n"
644 "--tls-crypt-v2 key : For clients: use key as a client-specific tls-crypt key.\n"
645 " For servers: use key to decrypt client-specific keys. For\n"
646 " key generation (--genkey tls-crypt-v2-client): use key to\n"
647 " encrypt generated client-specific key. (See --tls-crypt.)\n"
648 "--genkey tls-crypt-v2-client [keyfile] [base64 metadata]: Generate a\n"
649 " fresh tls-crypt-v2 client key, and store to\n"
650 " keyfile. If supplied, include metadata in wrapped key.\n"
651 "--genkey tls-crypt-v2-server [keyfile] [base64 metadata]: Generate a\n"
652 " fresh tls-crypt-v2 server key, and store to keyfile\n"
653 "--tls-crypt-v2-verify cmd : Run command cmd to verify the metadata of the\n"
654 " client-supplied tls-crypt-v2 client key\n"
655 "--tls-crypt-v2-max-age n : Only accept tls-crypt-v2 client keys that have a\n"
656 " timestamp which is at most n days old.\n"
657 "--askpass [file]: Get PEM password from controlling tty before we daemonize.\n"
658 "--auth-nocache : Don't cache --askpass or --auth-user-pass passwords.\n"
659 "--crl-verify crl ['dir']: Check peer certificate against a CRL.\n"
660 "--tls-verify cmd: Run command cmd to verify the X509 name of a\n"
661 " pending TLS connection that has otherwise passed all other\n"
662 " tests of certification. cmd should return 0 to allow\n"
663 " TLS handshake to proceed, or 1 to fail. (cmd is\n"
664 " executed as 'cmd certificate_depth subject')\n"
665 "--verify-x509-name name: Accept connections only from a host with X509 subject\n"
666 " DN name. The remote host must also pass all other tests\n"
667 " of verification.\n"
668#ifndef ENABLE_CRYPTO_MBEDTLS
669 "--ns-cert-type t: (DEPRECATED) Require that peer certificate was signed with \n"
670 " an explicit nsCertType designation t = 'client' | 'server'.\n"
671#endif
672 "--x509-track x : Save peer X509 attribute x in environment for use by\n"
673 " plugins and management interface.\n"
674 "--keying-material-exporter label len : Save Exported Keying Material (RFC5705)\n"
675 " of len bytes (min. 16 bytes) using label in environment for use by plugins.\n"
676 "--remote-cert-ku v ... : Require that the peer certificate was signed with\n"
677 " explicit key usage, you can specify more than one value.\n"
678 " value should be given in hex format.\n"
679 "--remote-cert-eku oid : Require that the peer certificate was signed with\n"
680 " explicit extended key usage. Extended key usage can be encoded\n"
681 " as an object identifier or OpenSSL string representation.\n"
682 "--remote-cert-tls t: Require that peer certificate was signed with explicit\n"
683 " key usage and extended key usage based on RFC3280 TLS rules.\n"
684 " t = 'client' | 'server'.\n"
685#ifdef ENABLE_PKCS11
686 "\n"
687 "PKCS#11 Options:\n"
688 "--pkcs11-providers provider ... : PKCS#11 provider to load.\n"
689 "--pkcs11-protected-authentication [0|1] ... : Use PKCS#11 protected authentication\n"
690 " path. Set for each provider.\n"
691 "--pkcs11-private-mode hex ... : PKCS#11 private key mode mask.\n"
692 " 0 : Try to determine automatically (default).\n"
693 " 1 : Use Sign.\n"
694 " 2 : Use SignRecover.\n"
695 " 4 : Use Decrypt.\n"
696 " 8 : Use Unwrap.\n"
697 "--pkcs11-cert-private [0|1] ... : Set if login should be performed before\n"
698 " certificate can be accessed. Set for each provider.\n"
699 "--pkcs11-pin-cache seconds : Number of seconds to cache PIN. The default is -1\n"
700 " cache until token is removed.\n"
701 "--pkcs11-id-management : Acquire identity from management interface.\n"
702 "--pkcs11-id serialized-id 'id' : Identity to use, get using standalone --show-pkcs11-ids\n"
703#endif /* ENABLE_PKCS11 */
704 "\n"
705 "SSL Library information:\n"
706 "--show-ciphers : Show cipher algorithms to use with --cipher option.\n"
707 "--show-digests : Show message digest algorithms to use with --auth option.\n"
708 "--show-engines : Show hardware crypto accelerator engines (if available).\n"
709 "--show-tls : Show all TLS ciphers (TLS used only as a control channel).\n"
710#ifdef _WIN32
711 "\n"
712 "Windows Specific:\n"
713 "--win-sys path : Pathname of Windows system directory. Default is the pathname\n"
714 " from SystemRoot environment variable.\n"
715 "--ip-win32 method : When using --ifconfig on Windows, set TAP-Windows adapter\n"
716 " IP address using method = manual, netsh, ipapi,\n"
717 " dynamic, or adaptive (default = adaptive).\n"
718 " Dynamic method allows two optional parameters:\n"
719 " offset: DHCP server address offset (> -256 and < 256).\n"
720 " If 0, use network address, if >0, take nth\n"
721 " address forward from network address, if <0,\n"
722 " take nth address backward from broadcast\n"
723 " address.\n"
724 " Default is 0.\n"
725 " lease-time: Lease time in seconds.\n"
726 " Default is one year.\n"
727 "--route-method : Which method to use for adding routes on Windows?\n"
728 " adaptive (default) -- Try ipapi then fall back to exe.\n"
729 " ipapi -- Use IP helper API.\n"
730 " exe -- Call the route.exe shell command.\n"
731 "--dhcp-option type [parm] : Set extended TAP-Windows properties, must\n"
732 " be used with --ip-win32 dynamic. For options\n"
733 " which allow multiple addresses,\n"
734 " --dhcp-option must be repeated.\n"
735 " DOMAIN name : Set DNS suffix\n"
736 " DOMAIN-SEARCH entry : Add entry to DNS domain search list\n"
737 " DNS addr : Set domain name server address(es) (IPv4 and IPv6)\n"
738 " NTP : Set NTP server address(es)\n"
739 " NBDD : Set NBDD server address(es)\n"
740 " WINS addr : Set WINS server address(es)\n"
741 " NBT type : Set NetBIOS over TCP/IP Node type\n"
742 " 1: B, 2: P, 4: M, 8: H\n"
743 " NBS id : Set NetBIOS scope ID\n"
744 " DISABLE-NBT : Disable Netbios-over-TCP/IP.\n"
745 "--dhcp-renew : Ask Windows to renew the TAP adapter lease on startup.\n"
746 "--dhcp-pre-release : Ask Windows to release the previous TAP adapter lease on\n"
747 " startup.\n"
748 "--register-dns : Run ipconfig /flushdns and ipconfig /registerdns\n"
749 " on connection initiation.\n"
750 "--tap-sleep n : Sleep for n seconds after TAP adapter open before\n"
751 " attempting to set adapter properties.\n"
752 "--pause-exit : When run from a console window, pause before exiting.\n"
753 "--service ex [0|1] : For use when " PACKAGE_NAME " is being instantiated by a\n"
754 " service, and should not be used directly by end-users.\n"
755 " ex is the name of an event object which, when\n"
756 " signaled, will cause " PACKAGE_NAME " to exit. A second\n"
757 " optional parameter controls the initial state of ex.\n"
758 "--show-net-up : Show " PACKAGE_NAME "'s view of routing table and net adapter list\n"
759 " after TAP adapter is up and routes have been added.\n"
760 "--block-outside-dns : Block DNS on other network adapters to prevent DNS leaks\n"
761 "Windows Standalone Options:\n"
762 "\n"
763 "--show-adapters : Show all TAP-Windows adapters.\n"
764 "--show-net : Show " PACKAGE_NAME "'s view of routing table and net adapter list.\n"
765 "--show-valid-subnets : Show valid subnets for --dev tun emulation.\n"
766 "--allow-nonadmin [TAP-adapter] : Allow " PACKAGE_NAME " running without admin privileges\n"
767 " to access TAP adapter.\n"
768#endif /* ifdef _WIN32 */
769 "\n"
770 "Generate a new key :\n"
771 "--genkey tls-auth file : Generate a new random key of type and write to file\n"
772 " (for use with --tls-auth or --tls-crypt)."
773#ifdef ENABLE_FEATURE_TUN_PERSIST
774 "\n"
775 "Tun/tap config mode:\n"
776 "--mktun : Create a persistent tunnel.\n"
777 "--rmtun : Remove a persistent tunnel.\n"
778 "--dev tunX|tapX : tun/tap device\n"
779 "--dev-type dt : Device type. See tunnel options above for details.\n"
780 "--user user : User to set privilege to.\n"
781 "--group group : Group to set privilege to.\n"
782#endif
783#ifdef ENABLE_PKCS11
784 "\n"
785 "PKCS#11 standalone options:\n"
786#ifdef DEFAULT_PKCS11_MODULE
787 "--show-pkcs11-ids [provider] [cert_private] : Show PKCS#11 available ids.\n"
788#else
789 "--show-pkcs11-ids provider [cert_private] : Show PKCS#11 available ids.\n"
790#endif
791 " --verb option can be added *BEFORE* this.\n"
792#endif /* ENABLE_PKCS11 */
793 "\n"
794 "General Standalone Options:\n"
795#ifndef ENABLE_SMALL
796 "--show-gateway [address]: Show info about gateway [to v4/v6 address].\n"
797#endif
798 ;
799
800#endif /* !ENABLE_SMALL */
801
802/*
803 * This is where the options defaults go.
804 * Any option not explicitly set here
805 * will be set to 0.
806 */
807void
809{
810 CLEAR(*o);
811 gc_init(&o->gc);
813
815 o->dev = "tun";
816 o->topology = TOP_UNDEF;
817 o->ce.proto = PROTO_UDP;
818 o->ce.af = AF_UNSPEC;
819 o->ce.bind_ipv6_only = false;
822 o->ce.connect_timeout = 120;
823 o->connect_retry_max = 0;
825 o->verbosity = 1;
827 o->status_file_version = 1;
828 o->ce.bind_local = true;
830 o->ce.occ_mtu = 0;
833 o->ce.mtu_discover_type = -1;
834 o->ce.mssfix = 0;
835 o->ce.mssfix_default = true;
836 o->ce.mssfix_encap = true;
838 o->route_delay_window = 30;
840 o->resolve_in_advance = false;
841 o->proto_force = -1;
842 o->occ = true;
843#ifdef ENABLE_MANAGEMENT
847#endif
848#ifdef ENABLE_FEATURE_TUN_PERSIST
849 o->persist_mode = 1;
850#endif
851#ifdef _WIN32
852#if 0
854#else
856#endif
857 o->tuntap_options.dhcp_lease_time = 31536000; /* one year */
858 /* use network address as internal DHCP server address */
861 o->block_outside_dns = false;
863#endif
865 o->vlan_pvid = 1;
866 o->n_bcast_buf = 256;
867 o->tcp_queue_limit = 64;
868 o->max_clients = 1024;
869 o->cf_initial_per = 10;
870 o->cf_initial_max = 100;
871 o->max_routes_per_client = 256;
875 o->authname = "SHA1";
879 o->tls_timeout = 2;
880 o->renegotiate_bytes = -1;
881 o->renegotiate_seconds = 3600;
883 o->handshake_window = 60;
884 o->transition_window = 3600;
885 o->tls_cert_profile = NULL;
886 o->ecdh_curve = NULL;
888#ifdef ENABLE_PKCS11
889 o->pkcs11_pin_cache_period = -1;
890#endif /* ENABLE_PKCS11 */
891
892 /* P2MP server context features */
893 o->auth_token_generate = false;
894
895 /* Set default --tmp-dir */
897
898 o->allow_recursive_routing = false;
899
900#ifndef ENABLE_DCO
901 o->disable_dco = true;
902#endif /* ENABLE_DCO */
903
904#ifdef ENABLE_DNS_UPDOWN_BY_DEFAULT
905 o->dns_options.updown = DEFAULT_DNS_UPDOWN;
906#endif /* ENABLE_DNS_UPDOWN_BY_DEFAULT */
907}
908
909void
911{
912 if (o->connection_list)
913 {
915 }
916 if (o->remote_list)
917 {
918 CLEAR(*o->remote_list);
919 }
920
921 gc_free(&o->gc);
923}
924
925static void
926setenv_connection_entry(struct env_set *es, const struct connection_entry *e, const int i)
927{
928 setenv_str_i(es, "remote", e->remote, i);
929 setenv_str_i(es, "remote_port", e->remote_port, i);
930
931 if (e->http_proxy_options)
932 {
933 setenv_str_i(es, "http_proxy_server", e->http_proxy_options->server, i);
934 setenv_str_i(es, "http_proxy_port", e->http_proxy_options->port, i);
935 }
936 if (e->socks_proxy_server)
937 {
938 setenv_str_i(es, "socks_proxy_server", e->socks_proxy_server, i);
939 setenv_str_i(es, "socks_proxy_port", e->socks_proxy_port, i);
940 }
941}
942
943static void
944setenv_local_entry(struct env_set *es, const struct local_entry *e, const int i)
945{
946 setenv_str_i(es, "proto", proto2ascii(e->proto, AF_UNSPEC, false), i);
947 setenv_str_i(es, "local", e->local, i);
948 setenv_str_i(es, "local_port", e->port, i);
949}
950
951void
952setenv_settings(struct env_set *es, const struct options *o)
953{
954 setenv_str(es, "config", o->config);
955 setenv_int(es, "verb", o->verbosity);
956 setenv_int(es, "daemon", o->daemon);
957 setenv_int(es, "daemon_log_redirect", o->log);
958 setenv_long_long(es, "daemon_start_time", time(NULL));
959 setenv_int(es, "daemon_pid", platform_getpid());
960
961 if (o->connection_list)
962 {
963 int i;
964 for (i = 0; i < o->connection_list->len; ++i)
965 {
967 }
968 }
969 else
970 {
971 setenv_connection_entry(es, &o->ce, 1);
972 }
973
974 if (o->ce.local_list)
975 {
976 for (int i = 0; i < o->ce.local_list->len; i++)
977 {
978 setenv_local_entry(es, o->ce.local_list->array[i], i + 1);
979 }
980 }
981}
982
983#ifndef _WIN32
984static void
985setenv_foreign_option(struct options *o, const char *option, const char *value, struct env_set *es)
986{
987 struct gc_arena gc = gc_new();
990 bool good = true;
991
992 good &= buf_printf(&env_name, "foreign_option_%d", o->foreign_option_index + 1);
993 if (value)
994 {
995 good &= buf_printf(&env_value, "dhcp-option %s %s", option, value);
996 }
997 else
998 {
999 good &= buf_printf(&env_value, "dhcp-option %s", option);
1000 }
1001 if (good)
1002 {
1004 ++o->foreign_option_index;
1005 }
1006 else
1007 {
1008 msg(M_WARN, "foreign_option: name/value overflow");
1009 }
1010 gc_free(&gc);
1011}
1012
1013static void
1014delete_all_dhcp_fo(struct options *o, struct env_item **list)
1015{
1016 struct env_item *current, *prev;
1017
1018 ASSERT(list);
1019
1020 for (current = *list, prev = NULL; current != NULL; current = current->next)
1021 {
1022 if (!strncmp(current->string, "foreign_option_", sizeof("foreign_option_") - 1))
1023 {
1024 const char *tmp_value = strchr(current->string, '=');
1025 if (tmp_value && ++tmp_value)
1026 {
1027 if (!strncmp(tmp_value, "dhcp-option ", sizeof("dhcp-option ") - 1))
1028 {
1029 if (prev)
1030 {
1031 prev->next = current->next;
1032 }
1033 else
1034 {
1035 *list = current->next;
1036 }
1038 }
1039 }
1040 }
1041 prev = current;
1042 }
1043}
1044
1045#endif /* ifndef _WIN32 */
1046
1047static in_addr_t
1048get_ip_addr(const char *ip_string, msglvl_t msglevel, bool *error)
1049{
1050 unsigned int flags = GETADDR_HOST_ORDER;
1051 bool succeeded = false;
1052 in_addr_t ret;
1053
1054 if (msglevel & M_FATAL)
1055 {
1056 flags |= GETADDR_FATAL;
1057 }
1058
1059 ret = getaddr(flags, ip_string, 0, &succeeded, NULL);
1060 if (!succeeded && error)
1061 {
1062 *error = true;
1063 }
1064 return ret;
1065}
1066
1072static char *
1073get_ipv6_addr_no_netbits(const char *addr, struct gc_arena *gc)
1074{
1075 const char *end = strchr(addr, '/');
1076 char *ret = NULL;
1077 if (NULL == end)
1078 {
1079 ret = string_alloc(addr, gc);
1080 }
1081 else
1082 {
1083 size_t len = end - addr;
1084 ret = gc_malloc(len + 1, true, gc);
1085 memcpy(ret, addr, len);
1086 }
1087 return ret;
1088}
1089
1090static bool
1091ipv6_addr_safe_hexplusbits(const char *ipv6_prefix_spec)
1092{
1093 return get_ipv6_addr(ipv6_prefix_spec, NULL, NULL, M_WARN);
1094}
1095
1105static struct verify_hash_list *
1106parse_hash_fingerprint(const char *str, int nbytes, msglvl_t msglevel, struct gc_arena *gc)
1107{
1108 int i = 0;
1109 const char *cp = str;
1110
1111 struct verify_hash_list *ret;
1113
1114 char term = 0;
1115 unsigned int byte;
1116
1117 while (*cp && i < nbytes)
1118 {
1119 /* valid segments consist of exactly two hex digits, then ':' or EOS */
1120 if (!isxdigit(cp[0]) || !isxdigit(cp[1]) || (cp[2] != ':' && cp[2] != '\0')
1121 || sscanf(cp, "%x", &byte) != 1)
1122 {
1123 msg(msglevel, "format error in hash fingerprint: %s", str);
1124 break;
1125 }
1126
1127 ret->hash[i++] = (uint8_t)byte;
1128
1129 term = cp[2];
1130 if (term == '\0')
1131 {
1132 break;
1133 }
1134 cp += 3;
1135 }
1136 if (i < nbytes)
1137 {
1138 msg(msglevel, "hash fingerprint is wrong length - expected %d bytes, got %d: %s", nbytes, i,
1139 str);
1140 }
1141 else if (term != '\0')
1142 {
1143 msg(msglevel, "hash fingerprint too long - expected only %d bytes: %s", nbytes, str);
1144 }
1145 return ret;
1146}
1147
1158static struct verify_hash_list *
1159parse_hash_fingerprint_multiline(const char *str, int nbytes, msglvl_t msglevel,
1160 struct gc_arena *gc)
1161{
1162 struct gc_arena gc_temp = gc_new();
1163 char *lines = string_alloc(str, &gc_temp);
1164
1165 struct verify_hash_list *ret = NULL;
1166
1167 const char *line;
1168 while ((line = strsep(&lines, "\n")))
1169 {
1170 /* ignore leading whitespace */
1171 while (isspace(*line))
1172 {
1173 line++;
1174 }
1175 /* skip empty lines and comment lines */
1176 if (strlen(line) == 0 || *line == '#' || *line == ';')
1177 {
1178 continue;
1179 }
1180
1181 struct verify_hash_list *hash = parse_hash_fingerprint(line, nbytes, msglevel, gc);
1182
1183 if (!hash)
1184 {
1185 gc_free(&gc_temp);
1186 return NULL;
1187 }
1188
1189 hash->next = ret;
1190 ret = hash;
1191 }
1192 gc_free(&gc_temp);
1193
1194 return ret;
1195}
1196
1197static void
1198dhcp_option_dns6_parse(const char *parm, struct in6_addr *dns6_list, unsigned int *len, msglvl_t msglevel)
1199{
1200 struct in6_addr addr;
1201 if (*len >= N_DHCP_ADDR)
1202 {
1203 msg(msglevel, "--dhcp-option DNS: maximum of %u IPv6 dns servers can be specified",
1204 N_DHCP_ADDR);
1205 }
1206 else if (get_ipv6_addr(parm, &addr, NULL, msglevel))
1207 {
1208 dns6_list[(*len)++] = addr;
1209 }
1210}
1211static void
1212dhcp_option_address_parse(const char *name, const char *parm, in_addr_t *array, unsigned int *len,
1213 msglvl_t msglevel)
1214{
1215 if (*len >= N_DHCP_ADDR)
1216 {
1217 msg(msglevel, "--dhcp-option %s: maximum of %u %s servers can be specified", name,
1218 N_DHCP_ADDR, name);
1219 }
1220 else
1221 {
1222 if (ip_addr_dotted_quad_safe(parm)) /* FQDN -- IP address only */
1223 {
1224 bool error = false;
1225 const in_addr_t addr = get_ip_addr(parm, msglevel, &error);
1226 if (!error)
1227 {
1228 array[(*len)++] = addr;
1229 }
1230 }
1231 else
1232 {
1233 msg(msglevel, "dhcp-option parameter %s '%s' must be an IP address", name, parm);
1234 }
1235 }
1236}
1237
1238static void
1239option_iroute(struct options *o, const char *network_str, const char *netmask_str,
1240 msglvl_t msglevel)
1241{
1242 struct iroute *ir;
1243
1244 ALLOC_OBJ_GC(ir, struct iroute, &o->gc);
1245 ir->network = getaddr(GETADDR_HOST_ORDER, network_str, 0, NULL, NULL);
1246 ir->netbits = 32; /* host route if no netmask given */
1247
1248 if (netmask_str)
1249 {
1250 const in_addr_t netmask = getaddr(GETADDR_HOST_ORDER, netmask_str, 0, NULL, NULL);
1251 ir->netbits = netmask_to_netbits2(netmask);
1252
1253 if (ir->netbits < 0)
1254 {
1255 msg(msglevel, "in --iroute %s %s : Bad network/subnet specification", network_str,
1256 netmask_str);
1257 return;
1258 }
1259 }
1260
1261 ir->next = o->iroutes;
1262 o->iroutes = ir;
1263}
1264
1265static void
1266option_iroute_ipv6(struct options *o, const char *prefix_str, msglvl_t msglevel)
1267{
1268 struct iroute_ipv6 *ir;
1269
1270 ALLOC_OBJ_GC(ir, struct iroute_ipv6, &o->gc);
1271
1272 if (!get_ipv6_addr(prefix_str, &ir->network, &ir->netbits, msglevel))
1273 {
1274 msg(msglevel, "in --iroute-ipv6 %s: Bad IPv6 prefix specification", prefix_str);
1275 return;
1276 }
1277
1278 ir->next = o->iroutes_ipv6;
1279 o->iroutes_ipv6 = ir;
1280}
1281
1282void
1284{
1285 /* The options struct carries two gc_arena's (one generic and one specific
1286 * to the DNS settings), which the by-value options
1287 * copy in inherit_context_child()/inherit_context_top() shares with the
1288 * source.
1289 *
1290 * Detach both (i.e. re-initialize them), otherwise child's call of
1291 * gc_free() (or context teardown) would free allocations the source
1292 * context still references, leading to a use-after-free (and subsequent
1293 * double-free).
1294 */
1295 gc_detach(&o->gc);
1297 o->routes = NULL;
1298 o->client_nat = NULL;
1299 clone_push_list(o);
1300}
1301
1302void
1304{
1305 if (!options->routes)
1306 {
1308 }
1309}
1310
1311static void
1319
1320static void
1322{
1323 if (!options->client_nat)
1324 {
1326 }
1327}
1328
1329#ifdef ENABLE_MANAGEMENT
1330
1331static struct http_proxy_options *
1332parse_http_proxy_override(const char *server, const char *port, const char *flags,
1333 struct gc_arena *gc)
1334{
1335 if (server && port)
1336 {
1337 struct http_proxy_options *ho;
1339 ho->server = string_alloc(server, gc);
1340 ho->port = port;
1341 if (flags && !strcmp(flags, "nct"))
1342 {
1343 ho->auth_retry = PAR_NCT;
1344 }
1345 else
1346 {
1347 ho->auth_retry = PAR_ALL;
1348 }
1349 ho->http_version = "1.0";
1350 ho->user_agent = "OpenVPN-Autoproxy/1.0";
1351 return ho;
1352 }
1353 else
1354 {
1355 return NULL;
1356 }
1357}
1358
1359static void
1361{
1362 const struct connection_list *l = o->connection_list;
1363 int i;
1364 bool succeed = false;
1365 for (i = 0; i < l->len; ++i)
1366 {
1367 struct connection_entry *ce = l->array[i];
1368 if (ce->proto == PROTO_TCP_CLIENT || ce->proto == PROTO_TCP)
1369 {
1371 succeed = true;
1372 }
1373 }
1374 if (succeed)
1375 {
1376 for (i = 0; i < l->len; ++i)
1377 {
1378 struct connection_entry *ce = l->array[i];
1379 if (ce->proto == PROTO_UDP)
1380 {
1381 ce->flags |= CE_DISABLED;
1382 }
1383 }
1384 }
1385 else
1386 {
1387 msg(M_WARN,
1388 "Note: option http-proxy-override ignored because no TCP-based connection profiles are defined");
1389 }
1390}
1391
1392#endif /* ifdef ENABLE_MANAGEMENT */
1393
1394static struct local_list *
1396{
1397 if (!ce->local_list)
1398 {
1400 }
1401 return ce->local_list;
1402}
1403
1404static struct local_entry *
1405alloc_local_entry(struct connection_entry *ce, const msglvl_t msglevel, struct gc_arena *gc)
1406{
1408 struct local_entry *e;
1409
1410 if (l->len >= l->capacity)
1411 {
1412 const int new_cap = l->capacity + 1;
1413 const size_t elem_size = sizeof(*l->array);
1414
1415 struct local_entry **new_array = gc_realloc(l->array, new_cap * elem_size, gc);
1416 if (!new_array)
1417 {
1418 msg(msglevel,
1419 "Unable to process more local options: out of memory. Number of entries = %d",
1420 l->len);
1421 return NULL;
1422 }
1423
1424 l->array = new_array;
1425 l->capacity = new_cap;
1426 }
1427
1428 ALLOC_OBJ_CLEAR_GC(e, struct local_entry, gc);
1429 e->proto = PROTO_NONE;
1430 l->array[l->len++] = e;
1431
1432 return e;
1433}
1434
1435static struct connection_list *
1444
1445static struct connection_entry *
1447{
1449 struct connection_entry *e;
1450
1451 if (l->len == l->capacity)
1452 {
1453 int capacity = l->capacity + CONNECTION_LIST_SIZE;
1454 struct connection_entry **ce =
1455 gc_realloc(l->array, capacity * sizeof(struct connection_entry *), &options->gc);
1456 if (ce == NULL)
1457 {
1458 msg(msglevel,
1459 "Unable to process more connection options: out of memory. Number of entries = %d",
1460 l->len);
1461 return NULL;
1462 }
1463 l->array = ce;
1464 l->capacity = capacity;
1465 }
1467 l->array[l->len++] = e;
1468 return e;
1469}
1470
1471static struct remote_list *
1473{
1474 if (!options->remote_list)
1475 {
1477 }
1478 return options->remote_list;
1479}
1480
1481static struct remote_entry *
1483{
1485 struct remote_entry *e;
1486
1487 if (l->len == l->capacity)
1488 {
1489 int capacity = l->capacity + CONNECTION_LIST_SIZE;
1490 struct remote_entry **re =
1491 gc_realloc(l->array, capacity * sizeof(struct remote_entry *), &options->gc);
1492 if (re == NULL)
1493 {
1494 msg(msglevel,
1495 "Unable to process more remote options: out of memory. Number of entries = %d",
1496 l->len);
1497 return NULL;
1498 }
1499 l->array = re;
1500 l->capacity = capacity;
1501 }
1502 ALLOC_OBJ_GC(e, struct remote_entry, &options->gc);
1503 l->array[l->len++] = e;
1504 return e;
1505}
1506
1507static struct pull_filter_list *
1509{
1510 if (!o->pull_filter_list)
1511 {
1513 }
1514 return o->pull_filter_list;
1515}
1516
1517static struct pull_filter *
1519{
1521 struct pull_filter *f;
1522
1523 ALLOC_OBJ_CLEAR_GC(f, struct pull_filter, &o->gc);
1524 if (l->head)
1525 {
1526 ASSERT(l->tail);
1527 l->tail->next = f;
1528 }
1529 else
1530 {
1531 ASSERT(!l->tail);
1532 l->head = f;
1533 }
1534 l->tail = f;
1535 return f;
1536}
1537
1538static void
1540{
1541 if (re->remote)
1542 {
1543 ce->remote = re->remote;
1544 }
1545 if (re->remote_port)
1546 {
1547 ce->remote_port = re->remote_port;
1548 }
1549 if (re->proto >= 0)
1550 {
1551 ce->proto = re->proto;
1552 }
1553 if (re->af > 0)
1554 {
1555 ce->af = re->af;
1556 }
1557}
1558
1559static void
1560connection_entry_preload_key(const char **key_file, bool *key_inline, struct gc_arena *gc)
1561{
1562 if (key_file && *key_file && !(*key_inline))
1563 {
1564 struct buffer in = buffer_read_from_file(*key_file, gc);
1565 if (!buf_valid(&in))
1566 {
1567 msg(M_FATAL, "Cannot pre-load keyfile (%s)", *key_file);
1568 }
1569
1570 *key_file = (const char *)in.data;
1571 *key_inline = true;
1572 }
1573}
1574
1575static void
1577{
1578#ifdef ENABLE_CRYPTO_MBEDTLS
1579 if (options->ca_path)
1580 {
1581 msg(M_USAGE, "Parameter --capath cannot be used with the mbed TLS version of OpenVPN.");
1582 }
1583#endif
1584
1587 || options->ca_path
1588#endif
1589 )
1590 {
1591 return;
1592 }
1593
1594 const char *const str = "You must define CA file (--ca)"
1595#ifndef ENABLE_CRYPTO_MBEDTLS
1596 " or CA path (--capath)"
1597#endif
1598 " and/or peer fingerprint verification (--peer-fingerprint)";
1599 msg(M_USAGE, "%s", str);
1600}
1601
1602#define MUST_BE_UNDEF(parm, parm_name) \
1603 if (options->parm != defaults.parm) \
1604 { \
1605 msg(M_USAGE, use_err, parm_name); \
1606 }
1607#define MUST_BE_FALSE(condition, parm_name) \
1608 if (condition) \
1609 { \
1610 msg(M_USAGE, use_err, parm_name); \
1611 }
1612
1613static void
1615{
1616 struct options defaults;
1617 int dev = DEV_TYPE_UNDEF;
1618 bool pull = false;
1619
1620 init_options(&defaults);
1621
1622 if (!options->test_crypto)
1623 {
1624 notnull(options->dev, "TUN/TAP device (--dev)");
1625 }
1626
1627 /*
1628 * Get tun/tap/null device type
1629 */
1631
1632 /*
1633 * If "proto tcp" is specified, make sure we know whether it is
1634 * tcp-client or tcp-server.
1635 */
1636 if (ce->proto == PROTO_TCP)
1637 {
1638 msg(M_USAGE, "--proto tcp is ambiguous in this context. Please specify "
1639 "--proto tcp-server or --proto tcp-client");
1640 }
1641
1642 /*
1643 * Sanity check on Client mode
1644 */
1645
1646 if (options->mode != MODE_SERVER && ce->local_list->len > 1)
1647 {
1648 msg(M_USAGE, "multiple --local statements only allowed in --server mode");
1649 }
1650
1651 if (options->lladdr && dev != DEV_TYPE_TAP)
1652 {
1653 msg(M_USAGE, "--lladdr can only be used in --dev tap mode");
1654 }
1655
1656 /*
1657 * Sanity check on MTU parameters
1658 */
1660 {
1661 msg(M_USAGE, "only one of --tun-mtu or --link-mtu may be defined");
1662 }
1663
1665 {
1666 msg(M_USAGE, "--mtu-test only makes sense with --proto udp");
1667 }
1668
1669 /* will we be pulling options from server? */
1670 pull = options->pull;
1671
1672 /*
1673 * Sanity check on --local, --remote, and --ifconfig
1674 */
1675
1678 {
1679 msg(M_USAGE, "--local and --remote addresses must be distinct from --ifconfig "
1680 "addresses");
1681 }
1682
1684 {
1685 msg(M_USAGE, "local and remote/netmask --ifconfig addresses must be different");
1686 }
1687
1688 if (ce->bind_defined && !ce->bind_local)
1689 {
1690 msg(M_USAGE, "--bind and --nobind can't be used together");
1691 }
1692
1694 {
1695 msg(M_USAGE, "--lport and --nobind don't make sense when used together");
1696 }
1697
1698 if (!ce->remote && !ce->bind_local)
1699 {
1700 msg(M_USAGE, "--nobind doesn't make sense unless used with --remote");
1701 }
1702
1703 for (int i = 0; i < ce->local_list->len; i++)
1704 {
1705 const struct local_entry *le = ce->local_list->array[i];
1706
1707 if (proto_is_net(le->proto) && string_defined_equal(le->local, ce->remote)
1709 {
1710 msg(M_USAGE, "--remote and one of the --local addresses are the same");
1711 }
1712
1715 {
1716 msg(M_USAGE, "--local addresses must be distinct from --ifconfig addresses");
1717 }
1718
1719 if (le->local && !ce->bind_local)
1720 {
1721 msg(M_USAGE, "--local and --nobind don't make sense when used together");
1722 }
1723 }
1724
1725 /*
1726 * Check for consistency of management options
1727 */
1728#ifdef ENABLE_MANAGEMENT
1732 {
1733 msg(M_USAGE,
1734 "--management is not specified, however one or more options which modify the behavior of --management were specified");
1735 }
1736
1739 {
1740 msg(M_USAGE, "--management-client-(user|group) can only be used on unix domain sockets");
1741 }
1742
1745 {
1746 msg(M_WARN, "WARNING: Using --management on a TCP port WITHOUT "
1747 "passwords is STRONGLY discouraged and considered insecure");
1748 }
1749
1750#endif /* ifdef ENABLE_MANAGEMENT */
1751
1752#if !defined(HAVE_XKEY_PROVIDER)
1755 {
1756 msg(M_FATAL, "management-external-key with TLS 1.3 or later requires "
1757 "nopadding argument/support");
1758 }
1759#endif
1760 /*
1761 * Windows-specific options.
1762 */
1763
1764#ifdef _WIN32
1765 if (dev == DEV_TYPE_TUN
1767 {
1768 msg(M_USAGE, "On Windows, --ifconfig is required when --dev tun is used");
1769 }
1770
1773 {
1774 msg(M_USAGE, "On Windows, --ip-win32 doesn't make sense unless --ifconfig is also used");
1775 }
1776
1778 {
1779 const char *prefix = "Some --dhcp-option or --dns options require DHCP server";
1781 {
1782 msg(M_USAGE, "%s, which is not supported by the selected %s driver", prefix,
1784 }
1787 {
1788 msg(M_USAGE, "%s, which requires --ip-win32 dynamic or adaptive", prefix);
1789 }
1790 }
1791#endif /* ifdef _WIN32 */
1792
1793 /*
1794 * Check that protocol options make sense.
1795 */
1796
1797#ifdef ENABLE_FRAGMENT
1798 if (!proto_is_udp(ce->proto) && ce->fragment)
1799 {
1800 msg(M_USAGE, "--fragment can only be used with --proto udp");
1801 }
1802#endif
1803
1804 if (!ce->remote && ce->proto == PROTO_TCP_CLIENT)
1805 {
1806 msg(M_USAGE, "--remote MUST be used in TCP Client mode");
1807 }
1808
1809 if ((ce->http_proxy_options) && ce->proto != PROTO_TCP_CLIENT)
1810 {
1811 msg(M_USAGE, "--http-proxy MUST be used in TCP Client mode (i.e. --proto "
1812 "tcp-client)");
1813 }
1814
1815 if ((ce->http_proxy_options) && !ce->http_proxy_options->server)
1816 {
1817 msg(M_USAGE, "--http-proxy not specified but other http proxy options present");
1818 }
1819
1821 {
1822 msg(M_USAGE, "--http-proxy can not be used together with --socks-proxy");
1823 }
1824
1825 if (ce->socks_proxy_server && ce->proto == PROTO_TCP_SERVER)
1826 {
1827 msg(M_USAGE, "--socks-proxy can not be used in TCP Server mode");
1828 }
1829
1830 if (ce->proto == PROTO_TCP_SERVER && (options->connection_list->len > 1))
1831 {
1832 msg(M_USAGE, "TCP server mode allows at most one --remote address");
1833 }
1834
1835 /*
1836 * Check consistency of --mode server options.
1837 */
1838 if (options->mode == MODE_SERVER)
1839 {
1840 const char use_err[] = "--%s cannot be used with --mode server.";
1841
1842#define USAGE_VALID_SERVER_PROTOS \
1843 "--mode server currently only supports " \
1844 "--proto values of udp, tcp-server, tcp4-server, or tcp6-server"
1845#ifdef TARGET_ANDROID
1846 msg(M_FATAL, "--mode server not supported on Android");
1847#endif
1848 if (!(dev == DEV_TYPE_TUN || dev == DEV_TYPE_TAP))
1849 {
1850 msg(M_USAGE, "--mode server only works with --dev tun or --dev tap");
1851 }
1852 MUST_BE_UNDEF(pull, "pull");
1854 {
1855 msg(M_WARN, "--pull-filter ignored for --mode server");
1856 }
1857 if (!(proto_is_udp(ce->proto) || ce->proto == PROTO_TCP_SERVER))
1858 {
1860 }
1861#if PORT_SHARE
1862 bool has_tcp = false;
1863 for (int i = 0; i < ce->local_list->len && !has_tcp; i++)
1864 {
1865 has_tcp = (ce->local_list->array[i]->proto == PROTO_TCP_SERVER);
1866 }
1867 if ((options->port_share_host || options->port_share_port)
1868 && !has_tcp)
1869 {
1870 msg(M_USAGE, "--port-share only works in TCP server mode "
1871 "(--proto values of tcp-server, tcp4-server, or tcp6-server)");
1872 }
1873#endif
1874 if (!options->tls_server)
1875 {
1876 msg(M_USAGE, "--mode server requires --tls-server");
1877 }
1878 MUST_BE_FALSE(ce->remote, "remote");
1879 MUST_BE_FALSE(!ce->bind_local, "nobind");
1880 MUST_BE_FALSE(ce->http_proxy_options, "http-proxy");
1881 MUST_BE_FALSE(ce->socks_proxy_server, "socks-proxy");
1882 /* <connection> blocks force to have a remote embedded, so we check
1883 * for the --remote and bail out if it is present
1884 */
1886 {
1887 msg(M_USAGE, "<connection> cannot be used with --mode server");
1888 }
1889
1890 MUST_BE_UNDEF(shaper, "shaper");
1891 if (options->ipchange)
1892 {
1893 msg(M_USAGE, "--ipchange cannot be used with --mode server (use "
1894 "--client-connect instead)");
1895 }
1896 if (!(proto_is_dgram(ce->proto) || ce->proto == PROTO_TCP_SERVER))
1897 {
1899 }
1900 if (!proto_is_udp(ce->proto) && (options->cf_max || options->cf_per))
1901 {
1902 msg(M_USAGE,
1903 "--connect-freq only works with --mode server --proto udp. Try --max-clients instead.");
1904 }
1905 if (!(dev == DEV_TYPE_TAP || (dev == DEV_TYPE_TUN && options->topology == TOP_SUBNET))
1907 {
1908 msg(M_USAGE,
1909 "The third parameter to --ifconfig-pool (netmask) is only valid in --dev tap mode");
1910 }
1912 {
1913 msg(M_USAGE,
1914 "--redirect-gateway cannot be used with --mode server (however --push \"redirect-gateway\" is fine)");
1915 }
1916 MUST_BE_UNDEF(route_delay_defined, "route-delay");
1917 MUST_BE_UNDEF(up_delay, "up-delay");
1920 {
1921 msg(M_USAGE,
1922 "--ifconfig-pool-persist must be used with --ifconfig-pool or --ifconfig-ipv6-pool");
1923 }
1925 {
1926 msg(M_USAGE, "--ifconfig-ipv6-pool needs --ifconfig-ipv6");
1927 }
1928 MUST_BE_UNDEF(allow_recursive_routing, "allow-recursive-routing");
1930 {
1931 msg(M_USAGE,
1932 "--auth-user-pass cannot be used with --mode server (it should be used on the client side only)");
1933 }
1935 {
1936 msg(M_USAGE, "--ccd-exclusive must be used with --client-config-dir");
1937 }
1939 {
1940 msg(M_USAGE, "--auth-gen-token needs a non-infinite "
1941 "--renegotiate_seconds setting");
1942 }
1945 {
1946 msg(M_USAGE,
1947 "--auth-gen-token renewal time needs to be at least "
1948 " two times --hand-window (%d).",
1950 }
1953 {
1954 const char *use_err =
1955 "--%s must be used with --management-client-auth, an --auth-user-pass-verify script, or plugin";
1956
1959 "verify-client-cert none|optional");
1961 "username-as-common-name");
1963 "auth-user-pass-optional");
1964 }
1965
1966 if (options->vlan_tagging && dev != DEV_TYPE_TAP)
1967 {
1968 msg(M_USAGE, "--vlan-tagging must be used with --dev tap");
1969 }
1970 if (!options->vlan_tagging)
1971 {
1972 const char use_err[] = "--%s requires --vlan-tagging";
1973 MUST_BE_UNDEF(vlan_accept, "vlan-accept");
1974 MUST_BE_UNDEF(vlan_pvid, "vlan-pvid");
1975 }
1976
1978 {
1979 msg(M_INFO, "NOTE: TCP_NODELAY is always enabled locally; "
1980 "--tcp-nodelay is now only useful to push the flag to "
1981 "clients older than 2.7.6.");
1982 }
1983 }
1984 else
1985 {
1986 const char use_err[] = "--%s requires --mode server";
1987 /*
1988 * When not in server mode, err if parameters are
1989 * specified which require --mode server.
1990 */
1991 MUST_BE_UNDEF(ifconfig_pool_defined, "ifconfig-pool");
1992 MUST_BE_UNDEF(ifconfig_pool_persist_filename, "ifconfig-pool-persist");
1993 MUST_BE_UNDEF(ifconfig_ipv6_pool_defined, "ifconfig-ipv6-pool");
1994 MUST_BE_UNDEF(real_hash_size, "hash-size");
1995 MUST_BE_UNDEF(virtual_hash_size, "hash-size");
1996 MUST_BE_UNDEF(learn_address_script, "learn-address");
1997 MUST_BE_UNDEF(client_connect_script, "client-connect");
1998 MUST_BE_UNDEF(client_crresponse_script, "client-crresponse");
1999 MUST_BE_UNDEF(client_disconnect_script, "client-disconnect");
2000 MUST_BE_UNDEF(client_config_dir, "client-config-dir");
2001 MUST_BE_UNDEF(ccd_exclusive, "ccd-exclusive");
2002 MUST_BE_UNDEF(enable_c2c, "client-to-client");
2003 MUST_BE_UNDEF(duplicate_cn, "duplicate-cn");
2004 MUST_BE_UNDEF(cf_max, "connect-freq");
2005 MUST_BE_UNDEF(cf_per, "connect-freq");
2008 "verify-client-cert");
2009 MUST_BE_FALSE(options->ssl_flags & SSLF_USERNAME_AS_COMMON_NAME, "username-as-common-name");
2010 MUST_BE_FALSE(options->ssl_flags & SSLF_AUTH_USER_PASS_OPTIONAL, "auth-user-pass-optional");
2012 {
2013 msg(M_WARN, "DEPRECATED OPTION: --tcp-nodelay is always enabled on clients");
2014 }
2015 MUST_BE_UNDEF(auth_user_pass_verify_script, "auth-user-pass-verify");
2016 MUST_BE_UNDEF(auth_token_generate, "auth-gen-token");
2017#if PORT_SHARE
2018 if (options->port_share_host || options->port_share_port)
2019 {
2020 msg(M_USAGE,
2021 "--port-share requires TCP server mode (--mode server --proto tcp-server)");
2022 }
2023#endif
2024 MUST_BE_UNDEF(stale_routes_check_interval, "stale-routes-check");
2025 MUST_BE_UNDEF(vlan_tagging, "vlan-tagging");
2026 MUST_BE_UNDEF(vlan_accept, "vlan-accept");
2027 MUST_BE_UNDEF(vlan_pvid, "vlan-pvid");
2028 MUST_BE_UNDEF(force_key_material_export, "force-key-material-export");
2029
2030 if (options->push_list.head)
2031 {
2032 msg(M_WARN, "Note: Using --push without --mode server is an "
2033 "unsupported configuration. Negotiation of OpenVPN "
2034 "features is expected to fail.");
2035 }
2036 }
2037
2038 /*
2039 * SSL/TLS mode sanity checks.
2040 */
2042 {
2043 msg(M_USAGE, "specify only one of --tls-server, --tls-client, or --secret");
2044 }
2045
2047 {
2048 msglvl_t msglevel = M_USAGE;
2050 {
2051 msglevel = M_INFO;
2052 }
2053
2054 msg(msglevel, "DEPRECATION: No tls-client or tls-server option in "
2055 "configuration detected. OpenVPN 2.8 will remove the "
2056 "functionality to run a VPN without TLS. "
2057 "See the examples section in the manual page for "
2058 "examples of a similar quick setup with peer-fingerprint. "
2059 "OpenVPN 2.7 allows using this configuration when using "
2060 "--allow-deprecated-insecure-static-crypto but you should move "
2061 "to a proper configuration using TLS as soon as possible.");
2062 }
2063
2065 {
2066 msg(M_WARN, "WARNING: POTENTIALLY DANGEROUS OPTION "
2067 "--verify-client-cert none|optional "
2068 "may accept clients which do not present a certificate");
2069 }
2070
2071 const unsigned int tls_ver_max =
2073 const unsigned int tls_ver_min =
2075
2076 if (tls_ver_max > 0 && tls_ver_max < tls_ver_min)
2077 {
2078 msg(M_USAGE, "--tls-version-min bigger than --tls-version-max");
2079 }
2080
2082 {
2084#ifdef ENABLE_PKCS11
2085 if (!options->pkcs11_providers[0] && options->pkcs11_id)
2086 {
2087 msg(M_WARN, "Option pkcs11-id is ignored as no pkcs11-providers are specified");
2088 }
2089 else if (!options->pkcs11_providers[0] && options->pkcs11_id_management)
2090 {
2091 msg(M_WARN,
2092 "Option pkcs11-id-management is ignored as no pkcs11-providers are specified");
2093 }
2094
2095 if (options->pkcs11_providers[0])
2096 {
2097 if (options->pkcs11_id_management && options->pkcs11_id != NULL)
2098 {
2099 msg(M_USAGE,
2100 "Parameter --pkcs11-id cannot be used when --pkcs11-id-management is also specified.");
2101 }
2102 if (!options->pkcs11_id_management && options->pkcs11_id == NULL)
2103 {
2104 msg(M_USAGE,
2105 "Parameter --pkcs11-id or --pkcs11-id-management should be specified.");
2106 }
2107 const char use_err[] =
2108 "Parameter --%s cannot be used when --pkcs11-provider is also specified.";
2109 MUST_BE_UNDEF(cert_file, "cert");
2110 MUST_BE_UNDEF(priv_key_file, "key");
2111 MUST_BE_UNDEF(pkcs12_file, "pkcs12");
2112 MUST_BE_FALSE(options->management_flags & MF_EXTERNAL_KEY, "management-external-key");
2113 MUST_BE_FALSE(options->management_flags & MF_EXTERNAL_CERT, "management-external-cert");
2114#ifdef ENABLE_CRYPTOAPI
2115 MUST_BE_UNDEF(cryptoapi_cert, "cryptoapicert");
2116#endif
2117 }
2118 else
2119#endif /* ifdef ENABLE_PKCS11 */
2120#ifdef ENABLE_CRYPTOAPI
2122 {
2123 const char use_err[] =
2124 "Parameter --%s cannot be used when --cryptoapicert is also specified.";
2125 MUST_BE_UNDEF(cert_file, "cert");
2126 MUST_BE_UNDEF(priv_key_file, "key");
2127 MUST_BE_UNDEF(pkcs12_file, "pkcs12");
2128 MUST_BE_FALSE(options->management_flags & MF_EXTERNAL_KEY, "management-external-key");
2129 MUST_BE_FALSE(options->management_flags & MF_EXTERNAL_CERT, "management-external-cert");
2130 }
2131 else
2132#endif
2133 if (options->pkcs12_file)
2134 {
2135#ifdef ENABLE_CRYPTO_MBEDTLS
2136 msg(M_USAGE, "Parameter --pkcs12 cannot be used with the mbed TLS version of OpenVPN.");
2137#else
2138 const char use_err[] = "Parameter --%s cannot be used when --pkcs12 is also specified.";
2139 MUST_BE_UNDEF(ca_path, "capath");
2140 MUST_BE_UNDEF(cert_file, "cert");
2141 MUST_BE_UNDEF(priv_key_file, "key");
2142 MUST_BE_FALSE(options->management_flags & MF_EXTERNAL_KEY, "management-external-key");
2143 MUST_BE_FALSE(options->management_flags & MF_EXTERNAL_CERT, "management-external-cert");
2144#endif /* ifdef ENABLE_CRYPTO_MBEDTLS */
2145 }
2146 else /* cert/key from none of pkcs11, pkcs12, cryptoapi */
2147 {
2149 {
2150 msg(M_USAGE, "--key and --management-external-key are mutually exclusive");
2151 }
2153 {
2154 if (options->cert_file)
2155 {
2156 msg(M_USAGE, "--cert and --management-external-cert are mutually exclusive");
2157 }
2159 {
2160 msg(M_USAGE,
2161 "--management-external-cert must be used with --management-external-key");
2162 }
2163 }
2164 if (pull)
2165 {
2166 const int sum =
2168 + ((options->priv_key_file != NULL)
2170
2171 if (sum == 0)
2172 {
2174 {
2175 msg(M_USAGE, "No client-side authentication method is "
2176 "specified. You must use either "
2177 "--cert/--key, --pkcs12, or "
2178 "--auth-user-pass");
2179 }
2180 }
2181 else if (sum != 2)
2182 {
2183 msg(M_USAGE, "If you use one of --cert or --key, you must use them both");
2184 }
2185 }
2186 else
2187 {
2189 {
2191 "certificate file (--cert) or PKCS#12 file (--pkcs12)");
2192 }
2194 {
2196 "private key file (--key) or PKCS#12 file (--pkcs12)");
2197 }
2198 }
2199 }
2200 if (ce->tls_auth_file && ce->tls_crypt_file)
2201 {
2202 msg(M_USAGE, "--tls-auth and --tls-crypt are mutually exclusive");
2203 }
2205 && (ce->tls_auth_file || ce->tls_crypt_file))
2206 {
2207 msg(M_USAGE,
2208 "--tls-crypt-v2, --tls-auth and --tls-crypt are mutually exclusive in client mode");
2209 }
2210 }
2211 else
2212 {
2213 /*
2214 * Make sure user doesn't specify any TLS options
2215 * when in non-TLS mode.
2216 */
2217
2218 const char use_err[] = "Parameter %s can only be specified in TLS-mode, "
2219 "i.e. where --tls-server or --tls-client is also specified.";
2220
2221 MUST_BE_UNDEF(ca_file, "ca");
2222 MUST_BE_UNDEF(ca_path, "capath");
2223 MUST_BE_UNDEF(dh_file, "dh");
2224 MUST_BE_UNDEF(cert_file, "cert");
2225 MUST_BE_UNDEF(priv_key_file, "key");
2226#ifndef ENABLE_CRYPTO_MBEDTLS
2227 MUST_BE_UNDEF(pkcs12_file, "pkcs12");
2228#endif
2229 MUST_BE_UNDEF(cipher_list, "tls-cipher");
2230 MUST_BE_UNDEF(cipher_list_tls13, "tls-ciphersuites");
2231 MUST_BE_UNDEF(tls_cert_profile, "tls-cert-profile");
2232 MUST_BE_UNDEF(tls_verify, "tls-verify");
2233 MUST_BE_UNDEF(tls_export_peer_cert_dir, "tls-export-cert");
2234 MUST_BE_UNDEF(verify_x509_name, "verify-x509-name");
2235 MUST_BE_UNDEF(tls_timeout, "tls-timeout");
2236 MUST_BE_UNDEF(renegotiate_bytes, "reneg-bytes");
2237 MUST_BE_UNDEF(renegotiate_packets, "reneg-pkts");
2238 MUST_BE_UNDEF(renegotiate_seconds, "reneg-sec");
2239 MUST_BE_UNDEF(handshake_window, "hand-window");
2240 MUST_BE_UNDEF(transition_window, "tran-window");
2241 MUST_BE_UNDEF(tls_auth_file, "tls-auth");
2242 MUST_BE_UNDEF(tls_crypt_file, "tls-crypt");
2243 MUST_BE_UNDEF(tls_crypt_v2_file, "tls-crypt-v2");
2244 MUST_BE_UNDEF(single_session, "single-session");
2245 MUST_BE_UNDEF(push_peer_info, "push-peer-info");
2246 MUST_BE_UNDEF(tls_exit, "tls-exit");
2247 MUST_BE_UNDEF(crl_file, "crl-verify");
2248 MUST_BE_UNDEF(ns_cert_type, "ns-cert-type");
2249 MUST_BE_UNDEF(remote_cert_ku[0], "remote-cert-ku");
2250 MUST_BE_UNDEF(remote_cert_eku, "remote-cert-eku");
2251#ifdef ENABLE_PKCS11
2252 MUST_BE_UNDEF(pkcs11_providers[0], "pkcs11-providers");
2253 MUST_BE_UNDEF(pkcs11_private_mode[0], "pkcs11-private-mode");
2254 MUST_BE_UNDEF(pkcs11_id, "pkcs11-id");
2255 MUST_BE_UNDEF(pkcs11_id_management, "pkcs11-id-management");
2256#endif
2257
2258 if (pull)
2259 {
2260 msg(M_USAGE, use_err, "--pull");
2261 }
2262 }
2264 {
2265 msg(M_USAGE, "--auth-user-pass requires --pull");
2266 }
2267
2268 uninit_options(&defaults);
2269}
2270
2271#undef MUST_BE_UNDEF
2272#undef MUST_BE_FALSE
2273
2274static void
2276{
2277 const int dev = dev_type_enum(o->dev, o->dev_type);
2278
2280 {
2281 if (ce->proto == PROTO_TCP)
2282 {
2283 ce->proto = PROTO_TCP_SERVER;
2284 o->ce.proto = ce->proto;
2285 }
2286 }
2287
2288 if (o->mode != MODE_SERVER)
2289 {
2290 if (ce->proto == PROTO_TCP)
2291 {
2292 ce->proto = PROTO_TCP_CLIENT;
2293 o->ce.proto = ce->proto;
2294 }
2295 }
2296
2297 /* an option is present that requires local bind to enabled */
2298 bool need_bind = ce->local_port_defined || ce->bind_defined || ce->local_list;
2299
2300 /* socks proxy is enabled */
2301 bool uses_socks = ce->proto == PROTO_UDP && ce->socks_proxy_server;
2302
2303 /* If binding is not forced by an explicit option and we have (at least)
2304 * one of --tcp-client, --pull (or --client), or socks we do not bind
2305 * locally to have "normal" IP client behaviour of a random source port */
2306 if (!need_bind && (ce->proto == PROTO_TCP_CLIENT || uses_socks || o->pull))
2307 {
2308 ce->bind_local = false;
2309 }
2310
2311 if (!ce->bind_local)
2312 {
2313 ce->local_port = NULL;
2314 }
2315
2316 /* if protocol forcing is enabled, disable all protocols
2317 * except for the forced one
2318 */
2319 if (o->proto_force >= 0 && o->proto_force != ce->proto)
2320 {
2321 ce->flags |= CE_DISABLED;
2322 }
2323
2324 if (ce->http_proxy_options)
2325 {
2327 }
2328
2329 /* our socks code is not fully IPv6 enabled yet (TCP works, UDP not)
2330 * so fall back to IPv4-only (trac #1221)
2331 */
2332 if (ce->socks_proxy_server && proto_is_udp(ce->proto) && ce->af != AF_INET)
2333 {
2334 if (ce->af == AF_INET6)
2335 {
2336 msg(M_INFO, "WARNING: '--proto udp6' is not compatible with "
2337 "'--socks-proxy' today. Forcing IPv4 mode.");
2338 }
2339 else
2340 {
2341 msg(M_INFO, "NOTICE: dual-stack mode for '--proto udp' does not "
2342 "work correctly with '--socks-proxy' today. Forcing IPv4.");
2343 }
2344 ce->af = AF_INET;
2345 }
2346
2347 /*
2348 * Set MTU defaults
2349 */
2350 {
2351 if (!ce->tun_mtu_defined && !ce->link_mtu_defined)
2352 {
2353 ce->tun_mtu_defined = true;
2354 }
2355 if ((dev == DEV_TYPE_TAP) && !ce->tun_mtu_extra_defined)
2356 {
2357 ce->tun_mtu_extra_defined = true;
2359 }
2360 }
2361
2362 /*
2363 * If --mssfix is supplied without a parameter or not specified at all,
2364 * default it to --fragment value, if --fragment is specified and otherwise
2365 * to the default if tun-mtu is 1500
2366 */
2367 if (o->ce.mssfix_default)
2368 {
2369#ifdef ENABLE_FRAGMENT
2370 if (ce->fragment)
2371 {
2372 ce->mssfix = ce->fragment;
2373 }
2374 else
2375#endif
2376 if (ce->tun_mtu_defined)
2377 {
2378 if (o->ce.tun_mtu == TUN_MTU_DEFAULT)
2379 {
2380 /* We want to only set mssfix default value if we use a default
2381 * MTU Size, otherwise the different size of tun should either
2382 * already solve the problem or mssfix might artifically make the
2383 * payload packets smaller without mssfix 0 */
2384 ce->mssfix = MSSFIX_DEFAULT;
2385 ce->mssfix_encap = true;
2386 }
2387 else
2388 {
2389 /* We still apply the mssfix value but only adjust it to the
2390 * size of the tun interface. */
2391 ce->mssfix = ce->tun_mtu;
2392 ce->mssfix_fixed = true;
2393 }
2394 }
2395 }
2396
2397 /*
2398 * Set per-connection block tls-auth/crypt/crypto-v2 fields if undefined.
2399 *
2400 * At the end only one of these will be really set because the parser
2401 * logic prevents configurations where more are set.
2402 */
2403 if (!ce->tls_auth_file && !ce->tls_crypt_file && !ce->tls_crypt_v2_file)
2404 {
2408
2411
2414 }
2415
2416 /* Pre-cache tls-auth/crypt(-v2) key file if
2417 * keys were not already embedded in the config file.
2418 */
2422
2423
2425 {
2426 msg(M_WARN, "NOTICE: --explicit-exit-notify ignored for --proto tcp");
2428 }
2429}
2430
2431static void
2433{
2434 /* use the global port if none is specified */
2435 if (!le->port)
2436 {
2437 le->port = ce->local_port;
2438 }
2439 /* use the global proto if none is specified and
2440 * allow proto bindings on server mode only */
2441 if (!le->proto || mode == MODE_POINT_TO_POINT)
2442 {
2443 le->proto = ce->proto;
2444 }
2445}
2446
2447#ifdef _WIN32
2448/* If iservice is in use, we need def1 method for redirect-gateway */
2449static void
2451{
2452 if (opt->routes && opt->route_method == ROUTE_METHOD_SERVICE
2453 && opt->routes->flags & RG_REROUTE_GW && !(opt->routes->flags & RG_DEF1))
2454 {
2455 msg(M_INFO, "Flag 'def1' added to --redirect-gateway (iservice is in use)");
2456 opt->routes->flags |= RG_DEF1;
2457 }
2458}
2459#endif /* ifdef _WIN32 */
2460
2461/*
2462 * Save/Restore certain option defaults before --pull is applied.
2463 */
2464
2465static void
2467{
2472
2473 if (o->routes)
2474 {
2476 o->pre_connect->routes_defined = true;
2477 }
2478 if (o->routes_ipv6)
2479 {
2482 }
2483 if (o->client_nat)
2484 {
2487 }
2488
2491
2494
2496
2497 /* NCP related options that can be overwritten by a push */
2499 o->pre_connect->authname = o->authname;
2500
2501 /* Ping related options should be reset to the config values on reconnect */
2505
2506 /* Miscellaneous Options */
2507 o->pre_connect->comp = o->comp;
2508}
2509
2510void
2512{
2513 const struct options_pre_connect *pp = o->pre_connect;
2514 if (pp)
2515 {
2517 if (pp->tuntap_options_defined)
2518 {
2520 }
2521
2522 if (pp->routes_defined)
2523 {
2524 rol_check_alloc(o);
2526 }
2527 else
2528 {
2529 o->routes = NULL;
2530 }
2531
2532 if (pp->routes_ipv6_defined)
2533 {
2536 }
2537 else
2538 {
2539 o->routes_ipv6 = NULL;
2540 }
2541
2544
2547
2548 /* Free DNS options and reset them to pre-pull state */
2549 gc_free(&o->dns_options.gc);
2550 struct gc_arena dns_gc = gc_new();
2551 o->dns_options = clone_dns_options(&pp->dns_options, &dns_gc);
2552 o->dns_options.gc = dns_gc;
2553
2554 if (pp->client_nat_defined)
2555 {
2558 }
2559 else
2560 {
2561 o->client_nat = NULL;
2562 }
2563
2565
2566 o->ciphername = pp->ciphername;
2567 o->authname = pp->authname;
2568
2572
2573 /* Miscellaneous Options */
2574 o->comp = pp->comp;
2575 }
2576
2577 o->push_continuation = 0;
2581}
2582
2583static void
2585{
2586#ifdef _WIN32
2587 const int dev = dev_type_enum(options->dev, options->dev_type);
2588
2589 /* when using ovpn-dco, kernel doesn't send DHCP requests, so don't use it */
2593 {
2595 }
2596
2597 if ((dev == DEV_TYPE_TUN || dev == DEV_TYPE_TAP) && !options->route_delay_defined)
2598 {
2599 /* delay may only be necessary when we perform DHCP handshake */
2602 if ((options->mode == MODE_POINT_TO_POINT) && dhcp)
2603 {
2605 options->route_delay = 5; /* Vista sometimes has a race without this */
2606 }
2607 }
2608
2610 {
2612 options->ifconfig_noexec = false;
2613 }
2614
2616
2617 /*
2618 * Check consistency of --mode server options.
2619 */
2620 if (options->mode == MODE_SERVER)
2621 {
2622 /*
2623 * We need to explicitly set --tap-sleep because
2624 * we do not schedule event timers in the top-level context.
2625 */
2628 {
2630 }
2632 }
2633#endif /* ifdef _WIN32 */
2634
2635#ifdef DEFAULT_PKCS11_MODULE
2636 /* If p11-kit is present on the system then load its p11-kit-proxy.so
2637 * by default if the user asks for PKCS#11 without otherwise specifying
2638 * the module to use. */
2639 if (!options->pkcs11_providers[0] && (options->pkcs11_id || options->pkcs11_id_management))
2640 {
2641 options->pkcs11_providers[0] = DEFAULT_PKCS11_MODULE;
2642 }
2643#endif
2644}
2645
2646static void
2648{
2649 if (o->connection_list)
2650 {
2651 int i;
2652 for (i = 0; i < o->connection_list->len; ++i)
2653 {
2655 }
2656 }
2657 else
2658 {
2660 }
2661
2663
2664 if (dco_enabled(o))
2665 {
2666 if (o->enable_c2c)
2667 {
2668 msg(M_WARN, "Note: --client-to-client has no effect when using data "
2669 "channel offload: packets are always sent to the VPN "
2670 "interface and then routed based on the system routing table");
2671 }
2672
2673 if (o->renegotiate_bytes > 0 || o->renegotiate_packets)
2674 {
2675 msg(M_WARN, "Note: '--reneg-bytes' and '--reneg-pkts' are not supported "
2676 "by data channel offload; automatic key renegotiation "
2677 "mechanisms are sufficient for modern ciphers. "
2678 "Ignoring these options.");
2679 }
2680 }
2681}
2682
2683static void
2685{
2686 if (!o->pull && !(o->mode == MODE_SERVER))
2687 {
2688 /* If the cipher is not set, use the old default of BF-CBC. We will
2689 * warn that this is deprecated on cipher initialisation, no need
2690 * to warn here as well */
2691 if (!o->ciphername)
2692 {
2693 o->ciphername = "BF-CBC";
2694 }
2695 else
2696 {
2697 o->enable_ncp_fallback = true;
2698 }
2699 return;
2700 }
2701
2702 /* pull or P2MP mode */
2703 if (!o->ciphername)
2704 {
2705 /* We still need to set the ciphername to BF-CBC since various other
2706 * parts of OpenVPN assert that the ciphername is set */
2707 o->ciphername = "BF-CBC";
2708
2709 msg(M_INFO,
2710 "Note: --cipher is not set. OpenVPN versions before 2.5 "
2711 "defaulted to BF-CBC as fallback when cipher negotiation "
2712 "failed in this case. If you need this fallback please add "
2713 "'--data-ciphers-fallback BF-CBC' to your configuration "
2714 "and/or add BF-CBC to --data-ciphers. E.g. "
2715 "--data-ciphers %s:BF-CBC",
2716 o->ncp_ciphers_conf);
2717 }
2719 {
2720 msg(M_WARN,
2721 "DEPRECATED OPTION: --cipher set to '%s' but missing in "
2722 "--data-ciphers (%s). OpenVPN ignores --cipher for cipher "
2723 "negotiations. ",
2725 }
2726}
2727
2743static bool
2744need_compatibility_before(const struct options *o, unsigned int version)
2745{
2746 return o->backwards_compatible != 0 && o->backwards_compatible < version;
2747}
2748
2753static void
2755{
2756 /* TLS min version is not set */
2757 unsigned int tls_ver_min = (o->ssl_flags >> SSLF_TLS_VERSION_MIN_SHIFT) & SSLF_TLS_VERSION_MIN_MASK;
2758 if (tls_ver_min == 0)
2759 {
2760 unsigned int tls_ver_max = (o->ssl_flags >> SSLF_TLS_VERSION_MAX_SHIFT) & SSLF_TLS_VERSION_MAX_MASK;
2761 if (need_compatibility_before(o, 20307))
2762 {
2763 /* 2.3.6 and earlier have TLS 1.0 only, set minimum to TLS 1.0 */
2765 }
2766 else if (tls_ver_max == 0 || tls_ver_max >= TLS_VER_1_2)
2767 {
2768 /* Use TLS 1.2 as proper default */
2770 }
2771 else
2772 {
2773 /* Maximize the minimum version */
2774 o->ssl_flags |= (tls_ver_max << SSLF_TLS_VERSION_MIN_SHIFT);
2775 }
2776 }
2777
2778 if (need_compatibility_before(o, 20400))
2779 {
2780 if (!o->ciphername)
2781 {
2782 /* If ciphername is not set default to BF-CBC when targeting these
2783 * old versions that do not have NCP */
2784 o->ciphername = "BF-CBC";
2785 }
2786 /* Versions < 2.4.0 additionally might be compiled with --enable-small and
2787 * not have OCC strings required for "poor man's NCP" */
2788 o->enable_ncp_fallback = true;
2789 }
2790
2791 /* Versions < 2.5.0 do need --cipher in the list of accepted ciphers.
2792 * Version 2.4 probably does not need it but NCP was not so
2793 * good with 2.4 and ncp-disable might be more common on 2.4 peers.
2794 * Only do this iff --cipher is set (explicitly or by compat mode
2795 * < 2.4.0, see above). This is not 100% correct backwards compatible
2796 * behaviour but 2.5 already behaved like this */
2797 if (o->ciphername && need_compatibility_before(o, 20500)
2799 {
2801 }
2802
2803#ifdef USE_COMP
2804 /* Compression is deprecated and we do not want to announce support for it
2805 * by default anymore, additionally DCO breaks with compression.
2806 *
2807 * Disable compression by default starting with 2.6.0 if no other
2808 * compression related option has been explicitly set */
2809 if (!need_compatibility_before(o, 20600) && (o->comp.flags == 0))
2810 {
2811 if (!comp_non_stub_enabled(&o->comp))
2812 {
2814 }
2815 }
2816#else /* ifdef USE_COMP */
2818#endif
2819}
2820
2821static void
2823{
2824 if (!check_tls_prf_working())
2825 {
2826 msg(D_TLS_ERRORS, "Warning: TLS 1.0 PRF with MD5+SHA1 PRF is not "
2827 "supported by the TLS library. Your system does not support this "
2828 "calculation anymore or your security policy (e.g. FIPS 140-2) "
2829 "forbids it. Connections will only work with peers running "
2830 "OpenVPN 2.6.0 or higher)");
2831 if (o->mode == MODE_SERVER)
2832 {
2833 msg(M_WARN, "Automatically enabling option "
2834 "--force-tls-key-material-export");
2835 o->force_key_material_export = true;
2836 }
2837 }
2838}
2839
2840#if defined(_WIN32) || defined(TARGET_ANDROID)
2849static void
2851{
2852 struct dns_options *dns = &o->dns_options;
2853 struct tuntap_options *tt = &o->tuntap_options;
2854 if (!dns->servers)
2855 {
2856 /* Copy --dhcp-options to tuntap_options */
2857 struct dhcp_options *dhcp = &dns->from_dhcp;
2858 ASSERT(sizeof(dhcp->dns) == sizeof(tt->dns));
2859 ASSERT(sizeof(dhcp->dns6) == sizeof(tt->dns6));
2860 ASSERT(sizeof(dhcp->domain_search_list) == sizeof(tt->domain_search_list));
2861
2862 tt->domain = dhcp->domain;
2863 tt->dns_len = dhcp->dns_len;
2864 tt->dns6_len = dhcp->dns6_len;
2865
2866 memcpy(tt->dns, dhcp->dns, sizeof(tt->dns));
2867 memcpy(tt->dns6, dhcp->dns6, sizeof(tt->dns6));
2868
2869 tt->domain_search_list_len = dhcp->domain_search_list_len;
2870 for (size_t i = 0; i < SIZE(tt->domain_search_list); ++i)
2871 {
2872 tt->domain_search_list[i] = dhcp->domain_search_list[i];
2873 }
2874
2875 return;
2876 }
2877
2878#if defined(_WIN32)
2880 {
2881 return; /* Not in DHCP mode */
2882 }
2883#endif /* if defined(_WIN32) */
2884
2885 /* Copy --dns options to tuntap_options */
2886
2887 const struct dns_domain *d = dns->search_domains;
2888 if (d)
2889 {
2890 tt->domain_search_list_len = 0;
2891 }
2892
2893 while (d && tt->domain_search_list_len + 1 < N_SEARCH_LIST_LEN)
2894 {
2896 d = d->next;
2897 }
2898 if (d)
2899 {
2900 msg(M_WARN, "WARNING: couldn't copy all --dns search-domains to TUN/TAP");
2901 }
2902
2903 tt->dns_len = 0;
2904 tt->dns6_len = 0;
2905
2906 const struct dns_server *s = dns->servers;
2907 while (s)
2908 {
2909 bool non_standard_server_port = false;
2910 for (size_t i = 0; i < s->addr_count; ++i)
2911 {
2912 if (s->addr[i].port && s->addr[i].port != 53)
2913 {
2914 non_standard_server_port = true;
2915 break;
2916 }
2917 }
2918 if ((s->transport && s->transport != DNS_TRANSPORT_PLAIN)
2919 || (s->dnssec && s->dnssec != DNS_SECURITY_NO) || non_standard_server_port)
2920 {
2921 /* Skip servers requiring unsupported config to be set */
2922 s = s->next;
2923 }
2924 else
2925 {
2926 bool overflow = false;
2927 for (size_t i = 0; i < s->addr_count; ++i)
2928 {
2929 if (s->addr[i].family == AF_INET && tt->dns_len + 1 < N_DHCP_ADDR)
2930 {
2931 tt->dns[tt->dns_len++] = ntohl(s->addr[i].in.a4.s_addr);
2932 }
2933 else if (tt->dns6_len + 1 < N_DHCP_ADDR)
2934 {
2935 tt->dns6[tt->dns6_len++] = s->addr[i].in.a6;
2936 }
2937 else
2938 {
2939 overflow = true;
2940 }
2941 }
2942 if (overflow)
2943 {
2944 msg(M_WARN, "WARNING: couldn't copy all --dns server addresses to TUN/TAP");
2945 }
2947 return;
2948 }
2949 }
2950}
2951
2952#else /* if defined(_WIN32) || defined(TARGET_ANDROID) */
2953
2964static void
2965dhcp_options_postprocess_dns(struct options *o, struct env_set *es)
2966{
2967 struct gc_arena gc = gc_new();
2968 struct dns_options *dns = &o->dns_options;
2969
2970 if (is_tun_afunix(o->dev_node))
2971 {
2972 /* Disable running dns-updown script with lwipovpn */
2974 dns->updown = NULL;
2975 }
2976
2977 if (dns->servers || dns_updown_user_set(dns) || dns_updown_forced(dns))
2978 {
2979 /* Clean up env from --dhcp-option DNS config */
2980 struct buffer name = alloc_buf_gc(OPTION_PARM_SIZE, &gc);
2981 struct buffer value = alloc_buf_gc(OPTION_PARM_SIZE, &gc);
2982
2983 const int fo_count = o->foreign_option_index;
2984 o->foreign_option_index = 0;
2985
2986 for (int i = 1; i <= fo_count; ++i)
2987 {
2988 buf_clear(&name);
2989 buf_printf(&name, "foreign_option_%d", i);
2990 const char *env_str = env_set_get(es, BSTR(&name));
2991 const char *item_val = strchr(env_str, '=') + 1;
2992 buf_clear(&value);
2993 buf_printf(&value, "%s", item_val);
2994
2995 /* Remove foreign option item from env set */
2996 env_set_del(es, BSTR(&name));
2997
2998 item_val = BSTR(&value);
2999 if (strncmp(item_val, "dhcp-option ", 12) != 0
3000 || (strncmp(item_val + 12, "ADAPTER-DOMAIN-SUFFIX ", 22) != 0
3001 && strncmp(item_val + 12, "DOMAIN-SEARCH ", 14) != 0
3002 && strncmp(item_val + 12, "DOMAIN ", 7) != 0
3003 && strncmp(item_val + 12, "DNS6 ", 5) != 0
3004 && strncmp(item_val + 12, "DNS ", 4) != 0))
3005 {
3006 /* Re-set the item with potentially updated name */
3007 buf_clear(&name);
3008 buf_printf(&name, "foreign_option_%d", ++o->foreign_option_index);
3009 setenv_str(es, BSTR(&name), BSTR(&value));
3010 }
3011 }
3012 }
3013
3014 if (!dns->servers)
3015 {
3016 /* Copy --dhcp-options to dns_options */
3017 struct dhcp_options *dhcp = &dns->from_dhcp;
3018
3019 if (dhcp->dns_len || dhcp->dns6_len)
3020 {
3021 struct dns_domain **entry = &dns->search_domains;
3022 ALLOC_OBJ_CLEAR_GC(*entry, struct dns_domain, &dns->gc);
3023 struct dns_domain *domain = *entry;
3024 domain->name = dhcp->domain;
3025 entry = &domain->next;
3026
3027 for (unsigned int i = 0; i < dhcp->domain_search_list_len; ++i)
3028 {
3029 ALLOC_OBJ_CLEAR_GC(*entry, struct dns_domain, &dns->gc);
3030 struct dns_domain *search_domain = *entry;
3031 search_domain->name = dhcp->domain_search_list[i];
3032 entry = &search_domain->next;
3033 }
3034
3035 struct dns_server *server = dns_server_get(&dns->servers, 0, &dns->gc);
3036 const size_t max_addrs = SIZE(server->addr);
3037 for (unsigned int i = 0; i < dhcp->dns_len && server->addr_count < max_addrs; ++i)
3038 {
3039 server->addr[server->addr_count].in.a4.s_addr = htonl(dhcp->dns[i]);
3040 server->addr[server->addr_count].family = AF_INET;
3041 server->addr_count += 1;
3042 }
3043 for (unsigned int i = 0; i < dhcp->dns6_len && server->addr_count < max_addrs; ++i)
3044 {
3045 server->addr[server->addr_count].in.a6 = dhcp->dns6[i];
3046 server->addr[server->addr_count].family = AF_INET6;
3047 server->addr_count += 1;
3048 }
3049 }
3050 }
3051 else if (o->up_script && !dns_updown_user_set(dns) && !dns_updown_forced(dns))
3052 {
3053 /* Set foreign option env vars from --dns config */
3054 const struct dns_domain *d = dns->search_domains;
3055 while (d)
3056 {
3057 setenv_foreign_option(o, "DOMAIN", d->name, es);
3058 d = d->next;
3059 }
3060
3061 const struct dns_server *s = dns->servers;
3062 while (s)
3063 {
3064 bool non_standard_server_port = false;
3065 for (size_t i = 0; i < s->addr_count; ++i)
3066 {
3067 if (s->addr[i].port && s->addr[i].port != 53)
3068 {
3069 non_standard_server_port = true;
3070 break;
3071 }
3072 }
3073 if ((s->transport && s->transport != DNS_TRANSPORT_PLAIN)
3074 || (s->dnssec && s->dnssec != DNS_SECURITY_NO) || non_standard_server_port)
3075 {
3076 /* Skip servers requiring unsupported config to be set */
3077 s = s->next;
3078 }
3079 else
3080 {
3081 for (size_t i = 0; i < s->addr_count; ++i)
3082 {
3083 const char *option;
3084 const char *value;
3085 if (s->addr[i].family == AF_INET)
3086 {
3087 option = "DNS";
3088 value = print_in_addr_t(s->addr[i].in.a4.s_addr, IA_NET_ORDER, &gc);
3089 }
3090 else
3091 {
3092 option = "DNS6";
3093 value = print_in6_addr(s->addr[i].in.a6, 0, &gc);
3094 }
3095 setenv_foreign_option(o, option, value, es);
3096 }
3097 break;
3098 }
3099 }
3100 }
3101
3102 gc_free(&gc);
3103}
3104#endif /* if defined(_WIN32) || defined(TARGET_ANDROID) */
3109static void
3111{
3112 if (!o->real_hash_size)
3113 {
3114 o->real_hash_size = 4 * o->max_clients;
3115 }
3116 if (!o->virtual_hash_size)
3117 {
3118 o->virtual_hash_size = 4 * o->max_clients;
3119 }
3120}
3121
3122static void
3124{
3125 /*
3126 * Process helper-type options which map to other, more complex
3127 * sequences of options.
3128 */
3130 /* must be called after helpers that might set --mode */
3134
3135 if (o->mode == MODE_SERVER)
3136 {
3138 }
3139
3143
3146 if (o->ncp_ciphers == NULL)
3147 {
3148 msg(M_USAGE, "--data-ciphers list contains unsupported ciphers or is too long.");
3149 }
3150
3151 if (o->remote_list && !o->connection_list)
3152 {
3153 /*
3154 * Convert remotes into connection list
3155 */
3156 const struct remote_list *rl = o->remote_list;
3157 for (int i = 0; i < rl->len; ++i)
3158 {
3159 const struct remote_entry *re = rl->array[i];
3160 struct connection_entry ce = o->ce;
3161 struct connection_entry *ace;
3162
3163 ASSERT(re->remote);
3164 connection_entry_load_re(&ce, re);
3166 ASSERT(ace);
3167 *ace = ce;
3168 }
3169 }
3170 else if (!o->remote_list && !o->connection_list)
3171 {
3172 struct connection_entry *ace;
3174 ASSERT(ace);
3175 *ace = o->ce;
3176 }
3177
3179 for (int i = 0; i < o->connection_list->len; ++i)
3180 {
3182 }
3183
3184 if (o->ce.local_list)
3185 {
3186 for (int i = 0; i < o->ce.local_list->len; i++)
3187 {
3189 }
3190
3191 for (int i = 0; i < o->ce.local_list->len; i++)
3192 {
3193 if (o->ce.local_list->array[i]->proto == PROTO_TCP)
3194 {
3196 }
3197 else if (o->ce.local_list->array[i]->proto == PROTO_NONE)
3198 {
3199 o->ce.local_list->array[i]->proto = o->ce.proto;
3200 }
3201 }
3202 }
3203 else
3204 {
3205 /* if no 'local' directive was specified, convert the global port
3206 * setting to a listen entry */
3207 struct local_entry *e = alloc_local_entry(&o->ce, M_USAGE, &o->gc);
3208 ASSERT(e);
3209 e->port = o->ce.local_port;
3210 e->proto = o->ce.proto;
3211 }
3212
3213 /* use the same listen list for every outgoing connection */
3214 for (int i = 0; i < o->connection_list->len; ++i)
3215 {
3217 }
3218
3219 if (o->tls_server)
3220 {
3221 if (o->dh_file && streq(o->dh_file, "none"))
3222 {
3223 o->dh_file = NULL;
3224 }
3225 }
3226 else if (o->dh_file)
3227 {
3228 /* DH file is only meaningful in a tls-server context. */
3229 msg(M_WARN, "WARNING: Ignoring option 'dh' in tls-client mode, please only "
3230 "include this in your server configuration");
3231 o->dh_file = NULL;
3232 }
3233#if ENABLE_MANAGEMENT
3234 if (o->http_proxy_override)
3235 {
3237 }
3238#endif
3239 if (!o->ca_file && !o->ca_path && o->verify_hash && o->verify_hash_depth == 0)
3240 {
3241 msg(M_INFO, "Using certificate fingerprint to verify peer (no CA "
3242 "option set). ");
3243 o->verify_hash_no_ca = true;
3244 }
3245
3246 if (o->config && streq(o->config, "stdin") && o->remap_sigusr1 == SIGHUP)
3247 {
3248 msg(M_USAGE, "Options 'config stdin' and 'remap-usr1 SIGHUP' are "
3249 "incompatible with each other.");
3250 }
3251
3252 if (dco_enabled(o))
3253 {
3254 /* check if any option should force disabling DCO */
3256 }
3257#ifdef USE_COMP
3258 if (dco_enabled(o))
3259 {
3261 }
3262#endif
3263
3264#ifdef _WIN32
3265 if (dco_enabled(o))
3266 {
3268 }
3269 else
3270 {
3272 }
3273#else /* _WIN32 */
3274 if (dco_enabled(o) && o->dev_node)
3275 {
3276 msg(M_WARN, "Note: ignoring --dev-node as it has no effect when using "
3277 "data channel offload");
3278 o->dev_node = NULL;
3279 }
3280#endif /* _WIN32 */
3281
3282 /* this depends on o->windows_driver, which is set above */
3284
3285 /* check that compression settings in the options are okay */
3287
3288 /*
3289 * Save certain parms before modifying options during connect, especially
3290 * when using --pull
3291 */
3292 if (o->pull)
3293 {
3295 }
3296 else
3297 {
3298#if defined(_WIN32) || defined(TARGET_ANDROID)
3300#else
3301 dhcp_options_postprocess_dns(o, es);
3302#endif
3303 }
3305 {
3307 }
3308#if ENABLE_MANAGEMENT
3310 {
3311 msg(M_USAGE, "'auth-user-pass username-only' cannot be used with static challenge");
3312 }
3313#endif
3315}
3316
3317/*
3318 * Sanity check on options.
3319 * Also set some options based on other
3320 * options.
3321 */
3322void
3324{
3327#ifndef ENABLE_SMALL
3329#endif /* !ENABLE_SMALL */
3330}
3331
3332/*
3333 * Sanity check on options after more options were pulled from server.
3334 * Also time to modify some options based on other options.
3335 */
3336bool
3338{
3339 bool success = dns_options_verify(D_PUSH_ERRORS, &o->dns_options);
3340 if (success)
3341 {
3343#if defined(_WIN32) || defined(TARGET_ANDROID)
3345#else
3346 dhcp_options_postprocess_dns(o, es);
3347#endif
3348 }
3349 return success;
3350}
3351
3352/*
3353 * parse/print topology coding
3354 */
3355
3356int
3357parse_topology(const char *str, const msglvl_t msglevel)
3358{
3359 if (streq(str, "net30"))
3360 {
3361 return TOP_NET30;
3362 }
3363 else if (streq(str, "p2p"))
3364 {
3365 return TOP_P2P;
3366 }
3367 else if (streq(str, "subnet"))
3368 {
3369 return TOP_SUBNET;
3370 }
3371 else
3372 {
3373 msg(msglevel, "--topology must be net30, p2p, or subnet");
3374 return TOP_UNDEF;
3375 }
3376}
3377
3378const char *
3379print_topology(const int topology)
3380{
3381 switch (topology)
3382 {
3383 case TOP_UNDEF:
3384 return "undef";
3385
3386 case TOP_NET30:
3387 return "net30";
3388
3389 case TOP_P2P:
3390 return "p2p";
3391
3392 case TOP_SUBNET:
3393 return "subnet";
3394
3395 default:
3396 return "unknown";
3397 }
3398}
3399
3400/*
3401 * Manage auth-retry variable
3402 */
3403
3404static int global_auth_retry; /* GLOBAL */
3405
3406int
3408{
3409 return global_auth_retry;
3410}
3411
3412bool
3413auth_retry_set(const msglvl_t msglevel, const char *option)
3414{
3415 if (streq(option, "interact"))
3416 {
3418 }
3419 else if (streq(option, "nointeract"))
3420 {
3422 }
3423 else if (streq(option, "none"))
3424 {
3426 }
3427 else
3428 {
3429 msg(msglevel, "--auth-retry method must be 'interact', 'nointeract', or 'none'");
3430 return false;
3431 }
3432 return true;
3433}
3434
3435const char *
3437{
3438 switch (global_auth_retry)
3439 {
3440 case AR_NONE:
3441 return "none";
3442
3443 case AR_NOINTERACT:
3444 return "nointeract";
3445
3446 case AR_INTERACT:
3447 return "interact";
3448
3449 default:
3450 return "???";
3451 }
3452}
3453
3454/*
3455 * Print the help message.
3456 */
3457void
3459{
3460 FILE *fp = msg_fp(0);
3461
3462#ifdef ENABLE_SMALL
3463
3464 fprintf(fp, "Usage message not available\n");
3465
3466#else
3467
3468 struct options o;
3469 init_options(&o);
3470
3476 fflush(fp);
3477
3478#endif /* ENABLE_SMALL */
3479
3480 openvpn_exit(OPENVPN_EXIT_STATUS_USAGE); /* exit point */
3481}
3482
3483void
3485{
3486 msg(M_WARN | M_NOPREFIX, "Use --help for more information.");
3487 openvpn_exit(OPENVPN_EXIT_STATUS_USAGE); /* exit point */
3488}
3489
3490#ifdef _WIN32
3491void
3492show_windows_version(const unsigned int flags)
3493{
3494 struct gc_arena gc = gc_new();
3495 msg(flags, "Windows version: %s", win32_version_string(&gc));
3496 gc_free(&gc);
3497}
3498#endif
3499
3500void
3501show_dco_version(const unsigned int flags)
3502{
3503#ifdef ENABLE_DCO
3504 struct gc_arena gc = gc_new();
3505 msg(flags, "DCO version: %s", dco_version_string(&gc));
3506 gc_free(&gc);
3507#endif
3508}
3509
3510void
3511show_library_versions(const unsigned int flags)
3512{
3513#ifdef ENABLE_LZO
3514#define LZO_LIB_VER_STR ", LZO ", lzo_version_string()
3515#else
3516#define LZO_LIB_VER_STR "", ""
3517#endif
3518
3519 msg(flags, "library versions: %s%s%s", get_ssl_library_version(), LZO_LIB_VER_STR);
3520
3521#undef LZO_LIB_VER_STR
3522}
3523
3524static void
3526{
3529#ifdef _WIN32
3531#endif
3533 msg(M_INFO | M_NOPREFIX, "Originally developed by James Yonan");
3534 msg(M_INFO | M_NOPREFIX, "Copyright (C) 2002-2026 OpenVPN Inc <sales@openvpn.net>");
3535#ifndef ENABLE_SMALL
3536#ifdef CONFIGURE_DEFINES
3537 msg(M_INFO | M_NOPREFIX, "Compile time defines: %s", CONFIGURE_DEFINES);
3538#endif
3539#ifdef CONFIGURE_SPECIAL_BUILD
3540 msg(M_INFO | M_NOPREFIX, "special build: %s", CONFIGURE_SPECIAL_BUILD);
3541#endif
3542#endif
3543
3545
3547}
3548
3549void
3550notnull(const char *arg, const char *description)
3551{
3552 if (!arg)
3553 {
3554 msg(M_USAGE, "You must define %s", description);
3555 }
3556}
3557
3558#if 0
3559static void
3560ping_rec_err(msglvl_t msglevel)
3561{
3562 msg(msglevel, "only one of --ping-exit or --ping-restart options may be specified");
3563}
3564#endif
3565
3566#ifdef _WIN32 /* This function is only used when compiling on Windows */
3567static unsigned int
3568atou(const char *str)
3569{
3570 unsigned int val = 0;
3571 sscanf(str, "%u", &val);
3572 return val;
3573}
3574#endif
3575
3576#define VERIFY_PERMISSION(mask) \
3577 { \
3578 if (!verify_permission(p[0], file, line, (mask), permission_mask, option_types_found, \
3579 msglevel, options, is_inline)) \
3580 { \
3581 goto err; \
3582 } \
3583 }
3584
3585static bool
3586verify_permission(const char *name, const char *file, int line, const uint64_t type,
3587 const uint64_t allowed, uint64_t *found, const msglvl_t msglevel,
3588 struct options *options, bool is_inline)
3589{
3590 if (!(type & allowed))
3591 {
3592 msg(msglevel, "option '%s' cannot be used in this context (%s)", name, file);
3593 return false;
3594 }
3595
3596 if (is_inline && !(type & OPT_P_INLINE))
3597 {
3598 msg(msglevel, "option '%s' is not expected to be inline (%s:%d)", name, file, line);
3599 return false;
3600 }
3601
3602 if (found)
3603 {
3604 *found |= type;
3605 }
3606
3607#ifndef ENABLE_SMALL
3608 /* Check if this options is allowed in connection block,
3609 * but we are currently not in a connection block
3610 * unless this is a pushed option.
3611 * Parsing a connection block uses a temporary options struct without
3612 * connection_list
3613 */
3614
3615 if ((type & OPT_P_CONNECTION) && options->connection_list && !(allowed & OPT_P_PULL_MODE))
3616 {
3617 if (file)
3618 {
3619 msg(M_WARN, "Option '%s' in %s:%d is ignored by previous <connection> blocks ", name,
3620 file, line);
3621 }
3622 else
3623 {
3624 msg(M_WARN, "Option '%s' is ignored by previous <connection> blocks", name);
3625 }
3626 }
3627#endif
3628 return true;
3629}
3630
3631/*
3632 * Check that an option doesn't have too
3633 * many parameters.
3634 */
3635
3636#define NM_QUOTE_HINT (1 << 0)
3637
3638static bool
3639no_more_than_n_args(const msglvl_t msglevel, char *p[], const int max, const unsigned int flags)
3640{
3641 const int len = string_array_len((const char **)p);
3642
3643 if (!len)
3644 {
3645 return false;
3646 }
3647
3648 if (len > max)
3649 {
3650 msg(msglevel, "the --%s directive should have at most %d parameter%s.%s", p[0], max - 1,
3651 max >= 3 ? "s" : "",
3652 (flags & NM_QUOTE_HINT)
3653 ? " To pass a list of arguments as one of the parameters, try enclosing them in double quotes (\"\")."
3654 : "");
3655 return false;
3656 }
3657 else
3658 {
3659 return true;
3660 }
3661}
3662
3663static inline msglvl_t
3665{
3666 return options->forward_compatible ? M_WARN : msglevel;
3667}
3668
3669#define RESET_OPTION_ROUTES(option_ptr, field) \
3670 if (option_ptr) \
3671 { \
3672 option_ptr->field = NULL; \
3673 option_ptr->flags = 0; \
3674 }
3675
3676void
3677remove_option(struct context *c, struct options *options, char *p[], bool is_inline,
3678 const char *file, int line, const msglvl_t msglevel,
3679 const uint64_t permission_mask, uint64_t *option_types_found,
3680 struct env_set *es)
3681{
3682 msglvl_t msglevel_fc = msglevel_forward_compatible(options, msglevel);
3683
3684 if (streq(p[0], "ifconfig") && !p[1])
3685 {
3687 options->ifconfig_local = NULL;
3689 }
3690 else if (streq(p[0], "ifconfig-ipv6") && !p[1])
3691 {
3696 }
3697 else if (streq(p[0], "route") && !p[1])
3698 {
3700 if (c->c1.route_list)
3701 {
3703 &c->net_ctx);
3705 }
3706 }
3707 else if (streq(p[0], "route-ipv6") && !p[1])
3708 {
3710 if (c->c1.route_ipv6_list)
3711 {
3713 es, &c->net_ctx);
3715 }
3716 }
3717 else if (streq(p[0], "route-gateway") && !p[1])
3718 {
3722 }
3723 else if (streq(p[0], "route-metric") && !p[1])
3724 {
3727 }
3728 else if (streq(p[0], "push-continuation") && !p[1])
3729 {
3732 }
3733 else if ((streq(p[0], "redirect-gateway") || streq(p[0], "redirect-private")) && !p[1])
3734 {
3736 if (options->routes)
3737 {
3738 options->routes->flags = 0;
3739 }
3740 if (options->routes_ipv6)
3741 {
3743 }
3744 env_set_del(es, "route_redirect_gateway_ipv4");
3745 env_set_del(es, "route_redirect_gateway_ipv6");
3746 }
3747 else if (streq(p[0], "dns") && !p[1])
3748 {
3752 }
3753 else if (streq(p[0], "topology") && !p[1])
3754 {
3758 }
3759 else if (streq(p[0], "tun-mtu") && !p[1])
3760 {
3763 options->ce.tun_mtu_defined = false;
3764 options->ce.occ_mtu = 0;
3765 }
3766 else if (streq(p[0], "block-ipv6") && !p[1])
3767 {
3769 options->block_ipv6 = false;
3770 }
3771#if defined(_WIN32) || defined(TARGET_ANDROID)
3772 else if (streq(p[0], "dhcp-option") && !p[1])
3773 {
3776
3777 o->domain = NULL;
3778 o->netbios_scope = NULL;
3779 o->netbios_node_type = 0;
3780 o->dns6_len = 0;
3781 memset(o->dns6, 0, sizeof(o->dns6));
3782 o->dns_len = 0;
3783 memset(o->dns, 0, sizeof(o->dns));
3784 o->wins_len = 0;
3785 memset(o->wins, 0, sizeof(o->wins));
3786 o->ntp_len = 0;
3787 memset(o->ntp, 0, sizeof(o->ntp));
3788 o->nbdd_len = 0;
3789 memset(o->nbdd, 0, sizeof(o->nbdd));
3792 o->disable_nbt = 0;
3793 o->dhcp_options = 0;
3795
3796#if defined(TARGET_ANDROID)
3797 o->http_proxy_port = 0;
3798 o->http_proxy = NULL;
3799#endif
3800 }
3801#endif /* if defined(_WIN32) || defined(TARGET_ANDROID) */
3802#ifdef _WIN32
3803 else if (streq(p[0], "block-outside-dns") && !p[1])
3804 {
3806 options->block_outside_dns = false;
3807 }
3808#else /* ifdef _WIN32 */
3809 else if (streq(p[0], "dhcp-option") && !p[1])
3810 {
3812 delete_all_dhcp_fo(options, &es->list);
3813 }
3814#endif
3815 else
3816 {
3817 msglvl_t msglevel_unknown = msglevel_fc;
3818 /* Check if an option is in --ignore-unknown-option and
3819 * set warning level to non fatal */
3820 for (int i = 0; options->ignore_unknown_option && options->ignore_unknown_option[i]; i++)
3821 {
3822 if (streq(p[0], options->ignore_unknown_option[i]))
3823 {
3824 msglevel_unknown = M_WARN;
3825 break;
3826 }
3827 }
3828 msg(msglevel_unknown,
3829 "Unrecognized option or missing or extra parameter(s) in %s:%d: -%s (%s)", file, line,
3830 p[0], PACKAGE_VERSION);
3831 }
3832 return;
3833err:
3834 msg(msglevel, "Error occurred trying to remove %s option", p[0]);
3835}
3836
3837
3838static bool
3839check_route_option(struct options *options, char *p[], const msglvl_t msglevel, bool pull_mode)
3840{
3842 if (pull_mode)
3843 {
3845 && !is_special_addr(p[1])) /* FQDN -- may be DNS name */
3846 {
3847 msg(msglevel, "route parameter network/IP '%s' must be a valid address", p[1]);
3848 return false;
3849 }
3850 if (p[2] && !ip_addr_dotted_quad_safe(p[2])) /* FQDN -- must be IP address */
3851 {
3852 msg(msglevel, "route parameter netmask '%s' must be an IP address", p[2]);
3853 return false;
3854 }
3855 if (p[3] && !ip_or_dns_addr_safe(p[3], options->allow_pull_fqdn)
3856 && !is_special_addr(p[3])) /* FQDN -- may be DNS name */
3857 {
3858 msg(msglevel, "route parameter gateway '%s' must be a valid address", p[3]);
3859 return false;
3860 }
3861 }
3862 return true;
3863}
3864
3865
3866static bool
3867check_route6_option(struct options *options, char *p[], const msglvl_t msglevel, bool pull_mode)
3868{
3870 if (pull_mode)
3871 {
3872 if (!ipv6_addr_safe_hexplusbits(p[1]))
3873 {
3874 msg(msglevel, "route-ipv6 parameter network/IP '%s' must be a valid address", p[1]);
3875 return false;
3876 }
3877 if (p[2] && !ipv6_addr_safe(p[2]))
3878 {
3879 msg(msglevel, "route-ipv6 parameter gateway '%s' must be a valid address", p[2]);
3880 return false;
3881 }
3882 /* p[3] is metric, if present */
3883 }
3884 return true;
3885}
3886
3887static bool
3888check_dns_option(struct options *options, char *p[], const msglvl_t msglevel, bool pull_mode)
3889{
3890 if (streq(p[1], "search-domains") && p[2])
3891 {
3894 {
3895 msg(msglevel, "--dns %s contain invalid characters", p[1]);
3896 return false;
3897 }
3898 }
3899 else if (streq(p[1], "server") && p[2] && p[3] && p[4])
3900 {
3901 long priority;
3902 if (!dns_server_priority_parse(&priority, p[2], pull_mode))
3903 {
3904 msg(msglevel, "--dns server: invalid priority value '%s'", p[2]);
3905 return false;
3906 }
3907
3908 struct dns_server *server =
3910
3911 if (streq(p[3], "address"))
3912 {
3913 for (int i = 4; p[i]; ++i)
3914 {
3915 if (!dns_server_addr_parse(server, p[i]))
3916 {
3917 msg(msglevel, "--dns server %ld: malformed address or maximum exceeded '%s'",
3918 priority, p[i]);
3919 return false;
3920 }
3921 }
3922 }
3923 else if (streq(p[3], "resolve-domains"))
3924 {
3925 if (!dns_domain_list_append(&server->domains, &p[4], &options->dns_options.gc))
3926 {
3927 msg(msglevel, "--dns server %ld: %s contain invalid characters", priority, p[3]);
3928 return false;
3929 }
3930 }
3931 else if (streq(p[3], "dnssec") && !p[5])
3932 {
3933 if (streq(p[4], "yes"))
3934 {
3935 server->dnssec = DNS_SECURITY_YES;
3936 }
3937 else if (streq(p[4], "no"))
3938 {
3939 server->dnssec = DNS_SECURITY_NO;
3940 }
3941 else if (streq(p[4], "optional"))
3942 {
3943 server->dnssec = DNS_SECURITY_OPTIONAL;
3944 }
3945 else
3946 {
3947 msg(msglevel, "--dns server %ld: malformed dnssec value '%s'", priority, p[4]);
3948 return false;
3949 }
3950 }
3951 else if (streq(p[3], "transport") && !p[5])
3952 {
3953 if (streq(p[4], "plain"))
3954 {
3956 }
3957 else if (streq(p[4], "DoH"))
3958 {
3960 }
3961 else if (streq(p[4], "DoT"))
3962 {
3963 server->transport = DNS_TRANSPORT_TLS;
3964 }
3965 else
3966 {
3967 msg(msglevel, "--dns server %ld: malformed transport value '%s'", priority, p[4]);
3968 return false;
3969 }
3970 }
3971 else if (streq(p[3], "sni") && !p[5])
3972 {
3973 if (!validate_domain(p[4]))
3974 {
3975 msg(msglevel, "--dns server %ld: %s contains invalid characters", priority, p[3]);
3976 return false;
3977 }
3978 server->sni = p[4];
3979 }
3980 else
3981 {
3982 msg(msglevel,
3983 "--dns server %ld: unknown option type '%s' or missing or unknown parameter",
3984 priority, p[3]);
3985 return false;
3986 }
3987 }
3988 else
3989 {
3990 msg(msglevel, "--dns: unknown option type '%s' or missing or unknown parameter", p[1]);
3991 return false;
3992 }
3993 return true;
3994}
3995
3996void
3997update_option(struct context *c, struct options *options, char *p[], bool is_inline,
3998 const char *file, int line, const int level, const msglvl_t msglevel,
3999 const uint64_t permission_mask, uint64_t *option_types_found,
4000 struct env_set *es)
4001{
4002 const bool pull_mode = BOOL_CAST(permission_mask & OPT_P_PULL_MODE);
4003 ASSERT(MAX_PARMS >= 7);
4004
4005 if (streq(p[0], "route") && p[1] && !p[5])
4006 {
4008 {
4010 if (!check_route_option(options, p, msglevel, pull_mode))
4011 {
4012 goto err;
4013 }
4014 if (c->c1.route_list)
4015 {
4017 es, &c->net_ctx);
4019 }
4021 }
4022 }
4023 else if (streq(p[0], "route-ipv6") && p[1] && !p[4])
4024 {
4026 {
4028 if (!check_route6_option(options, p, msglevel, pull_mode))
4029 {
4030 goto err;
4031 }
4032 if (c->c1.route_ipv6_list)
4033 {
4035 ROUTE_OPTION_FLAGS(&c->options), es, &c->net_ctx);
4037 }
4039 }
4040 }
4041 else if (streq(p[0], "redirect-gateway") || streq(p[0], "redirect-private"))
4042 {
4044 {
4046 if (options->routes)
4047 {
4048 options->routes->flags = 0;
4049 }
4050 if (options->routes_ipv6)
4051 {
4053 }
4054 env_set_del(es, "route_redirect_gateway_ipv4");
4055 env_set_del(es, "route_redirect_gateway_ipv6");
4057 }
4058 }
4059 else if (streq(p[0], "dns") && p[1])
4060 {
4062 {
4064 if (!check_dns_option(options, p, msglevel, pull_mode))
4065 {
4066 goto err;
4067 }
4071 }
4072 }
4073#if defined(_WIN32) || defined(TARGET_ANDROID)
4074 else if (streq(p[0], "dhcp-option") && p[1] && !p[3])
4075 {
4077 {
4080
4081 o->domain = NULL;
4082 o->netbios_scope = NULL;
4083 o->netbios_node_type = 0;
4084 o->dns6_len = 0;
4085 CLEAR(o->dns6);
4086 o->dns_len = 0;
4087 CLEAR(o->dns);
4088 o->wins_len = 0;
4089 CLEAR(o->wins);
4090 o->ntp_len = 0;
4091 CLEAR(o->ntp);
4092 o->nbdd_len = 0;
4093 CLEAR(o->nbdd);
4096 o->disable_nbt = 0;
4097 o->dhcp_options = 0;
4098
4100#if defined(TARGET_ANDROID)
4101 o->http_proxy_port = 0;
4102 o->http_proxy = NULL;
4103#endif
4105 }
4106 }
4107#else /* if defined(_WIN32) || defined(TARGET_ANDROID) */
4108 else if (streq(p[0], "dhcp-option") && p[1] && !p[3])
4109 {
4111 {
4113 delete_all_dhcp_fo(options, &es->list);
4115 }
4116 }
4117#endif /* if defined(_WIN32) || defined(TARGET_ANDROID) */
4118 add_option(options, p, is_inline, file, line, level, msglevel, permission_mask,
4119 option_types_found, es);
4120 return;
4121err:
4122 msg(msglevel, "Error occurred trying to update %s option", p[0]);
4123}
4124
4125static void
4126set_user_script(struct options *options, const char **script, const char *new_script,
4127 const char *type, bool in_chroot)
4128{
4129 if (*script)
4130 {
4131 msg(M_WARN,
4132 "Multiple --%s scripts defined. "
4133 "The previously configured script is overridden.",
4134 type);
4135 }
4136 *script = new_script;
4137 options->user_script_used = true;
4138
4139#ifndef ENABLE_SMALL
4140 {
4141 char script_name[100];
4142 snprintf(script_name, sizeof(script_name), "--%s script", type);
4143
4144 if (check_cmd_access(*script, script_name, (in_chroot ? options->chroot_dir : NULL)))
4145 {
4146 msg(M_USAGE, "Please correct this error.");
4147 }
4148 }
4149#endif
4150}
4151
4152static void
4154{
4155 if (comp_non_stub_enabled(info))
4156 {
4157 msg(M_WARN, "WARNING: Compression for receiving enabled. "
4158 "Compression has been used in the past to break encryption. "
4159 "Compression support is deprecated and we recommend to disable "
4160 "it completely.");
4161 }
4162}
4163
4164bool
4166{
4168#ifdef ENABLE_PKCS11
4169 ret = ret || (options->pkcs11_providers[0] != NULL);
4170#endif
4171#ifdef ENABLE_CRYPTOAPI
4172 ret = ret || options->cryptoapi_cert;
4173#endif
4174
4175 return ret;
4176}
4177
4178#if defined(__GNUC__) || defined(__clang__)
4179#pragma GCC diagnostic push
4180#pragma GCC diagnostic ignored "-Wsign-compare"
4181#endif
4182
4183void
4184add_option(struct options *options, char *p[], bool is_inline, const char *file, int line,
4185 const int level, const msglvl_t msglevel, const uint64_t permission_mask,
4186 uint64_t *option_types_found, struct env_set *es)
4187{
4188 struct gc_arena gc = gc_new();
4189 const bool pull_mode = BOOL_CAST(permission_mask & OPT_P_PULL_MODE);
4190 msglvl_t msglevel_fc = msglevel_forward_compatible(options, msglevel);
4191
4192 ASSERT(MAX_PARMS >= 7);
4193
4194 /*
4195 * If directive begins with "setenv opt" prefix, don't raise an error if
4196 * directive is unrecognized.
4197 */
4198 if (streq(p[0], "setenv") && p[1] && streq(p[1], "opt") && !(permission_mask & OPT_P_PULL_MODE))
4199 {
4200 if (!p[2])
4201 {
4202 p[2] = "setenv opt"; /* will trigger an error that includes setenv opt */
4203 }
4204 p += 2;
4205 msglevel_fc = M_WARN;
4206 }
4207
4208 if (!file)
4209 {
4210 file = "[CMD-LINE]";
4211 line = 1;
4212 }
4213 if (streq(p[0], "help"))
4214 {
4216 usage();
4217 if (p[1])
4218 {
4219 msg(msglevel, "--help does not accept any parameters");
4220 goto err;
4221 }
4222 }
4223 if (streq(p[0], "version") && !p[1])
4224 {
4226 usage_version();
4227 }
4228 else if (streq(p[0], "config") && p[1] && !p[2])
4229 {
4231
4232 /* save first config file only in options */
4233 if (!options->config)
4234 {
4235 options->config = p[1];
4236 }
4237
4238 read_config_file(options, p[1], level, file, line, msglevel, permission_mask,
4239 option_types_found, es);
4240 }
4241#ifndef ENABLE_SMALL
4242 else if (streq(p[0], "show-gateway") && !p[2])
4243 {
4244 struct route_gateway_info rgi;
4245 struct route_ipv6_gateway_info rgi6;
4246 in_addr_t remote_ipv4 = 0;
4247 struct in6_addr remote_ipv6 = IN6ADDR_ANY_INIT;
4248 openvpn_net_ctx_t net_ctx;
4250 if (p[1])
4251 {
4252 /* try parsing the argument as a v4 or v6 address - if
4253 * possible, the output will show the exact route there, and
4254 * "the default route" for the other protocol
4255 */
4256 remote_ipv4 = get_ip_addr(p[1], M_WARN, NULL);
4257 get_ipv6_addr(p[1], &remote_ipv6, NULL, M_WARN);
4258 }
4259 net_ctx_init(NULL, &net_ctx);
4260 get_default_gateway(&rgi, remote_ipv4, &net_ctx);
4261 get_default_gateway_ipv6(&rgi6, &remote_ipv6, &net_ctx);
4262 print_default_gateway(M_INFO, &rgi, &rgi6);
4263 openvpn_exit(OPENVPN_EXIT_STATUS_GOOD); /* exit point */
4264 }
4265#endif
4266 else if (streq(p[0], "echo") || streq(p[0], "parameter"))
4267 {
4268 struct buffer string = alloc_buf_gc(OPTION_PARM_SIZE, &gc);
4269 int j;
4270 bool good = true;
4271
4273
4274 for (j = 1; j < MAX_PARMS; ++j)
4275 {
4276 if (!p[j])
4277 {
4278 break;
4279 }
4280 if (j > 1)
4281 {
4282 good &= buf_printf(&string, " ");
4283 }
4284 good &= buf_printf(&string, "%s", p[j]);
4285 }
4286 if (good)
4287 {
4288 /* only message-related ECHO are logged, since other ECHOs
4289 * can potentially include security-sensitive strings */
4290 if (p[1] && strncmp(p[1], "msg", 3) == 0)
4291 {
4292 msg(M_INFO, "%s:%s", pull_mode ? "ECHO-PULL" : "ECHO", BSTR(&string));
4293 }
4294#ifdef ENABLE_MANAGEMENT
4295 if (management)
4296 {
4298 }
4299#endif
4300 }
4301 else
4302 {
4303 msg(M_WARN, "echo/parameter option overflow");
4304 }
4305 }
4306#ifdef ENABLE_MANAGEMENT
4307 else if (streq(p[0], "management") && p[1] && p[2] && !p[4])
4308 {
4310 if (streq(p[2], "unix"))
4311 {
4312#if UNIX_SOCK_SUPPORT
4314#else
4315 msg(msglevel, "MANAGEMENT: this platform does not support unix domain sockets");
4316 goto err;
4317#endif
4318 }
4319
4322 if (p[3])
4323 {
4325 }
4326 }
4327 else if (streq(p[0], "management-client-user") && p[1] && !p[2])
4328 {
4331 }
4332 else if (streq(p[0], "management-client-group") && p[1] && !p[2])
4333 {
4336 }
4337 else if (streq(p[0], "management-query-passwords") && !p[1])
4338 {
4341 }
4342 else if (streq(p[0], "management-query-remote") && !p[1])
4343 {
4346 }
4347 else if (streq(p[0], "management-query-proxy") && !p[1])
4348 {
4351 }
4352 else if (streq(p[0], "management-hold") && !p[1])
4353 {
4356 }
4357 else if (streq(p[0], "management-signal") && !p[1])
4358 {
4361 }
4362 else if (streq(p[0], "management-forget-disconnect") && !p[1])
4363 {
4366 }
4367 else if (streq(p[0], "management-up-down") && !p[1])
4368 {
4371 }
4372 else if (streq(p[0], "management-client") && !p[1])
4373 {
4376 }
4377 else if (streq(p[0], "management-external-key"))
4378 {
4380 for (int j = 1; j < MAX_PARMS && p[j] != NULL; ++j)
4381 {
4382 if (streq(p[j], "nopadding"))
4383 {
4385 }
4386 else if (streq(p[j], "pkcs1"))
4387 {
4389 }
4390 else if (streq(p[j], "pss"))
4391 {
4393 }
4394 else if (streq(p[j], "digest"))
4395 {
4397 }
4398 else
4399 {
4400 msg(msglevel, "Unknown management-external-key flag: %s", p[j]);
4401 }
4402 }
4403 /*
4404 * When no option is present, assume that only PKCS1
4405 * padding is supported
4406 */
4408 {
4410 }
4412 }
4413 else if (streq(p[0], "management-external-cert") && p[1] && !p[2])
4414 {
4418 }
4419 else if (streq(p[0], "management-client-auth") && !p[1])
4420 {
4423 }
4424 else if (streq(p[0], "management-log-cache") && p[1] && !p[2])
4425 {
4428 p[0], 1, INT_MAX, msglevel))
4429 {
4430 goto err;
4431 }
4432 }
4433#endif /* ifdef ENABLE_MANAGEMENT */
4434#ifdef ENABLE_PLUGIN
4435 else if (streq(p[0], "plugin") && p[1])
4436 {
4438 if (!options->plugin_list)
4439 {
4441 }
4443 {
4444 msg(msglevel, "plugin add failed: %s", p[1]);
4445 goto err;
4446 }
4447 }
4448#endif
4449 else if (streq(p[0], "mode") && p[1] && !p[2])
4450 {
4452 if (streq(p[1], "p2p"))
4453 {
4455 }
4456 else if (streq(p[1], "server"))
4457 {
4459 }
4460 else
4461 {
4462 msg(msglevel, "Bad --mode parameter: %s", p[1]);
4463 goto err;
4464 }
4465 }
4466 else if (streq(p[0], "dev") && p[1] && !p[2])
4467 {
4469 options->dev = p[1];
4470 }
4471 else if (streq(p[0], "dev-type") && p[1] && !p[2])
4472 {
4474 options->dev_type = p[1];
4475 }
4476#ifdef _WIN32
4477 else if (streq(p[0], "windows-driver") && p[1] && !p[2])
4478 {
4480 msg(M_WARN,
4481 "DEPRECATED OPTION: windows-driver: In OpenVPN 2.7, the default Windows driver is ovpn-dco. "
4482 "If incompatible options are used, OpenVPN will fall back to tap-windows6. Wintun support has been removed.");
4483 }
4484#endif
4485 else if (streq(p[0], "disable-dco"))
4486 {
4487 options->disable_dco = true;
4488 }
4489 else if (streq(p[0], "dev-node") && p[1] && !p[2])
4490 {
4492 options->dev_node = p[1];
4493 }
4494 else if (streq(p[0], "lladdr") && p[1] && !p[2])
4495 {
4497 if (mac_addr_safe(p[1])) /* MAC address only */
4498 {
4499 options->lladdr = p[1];
4500 }
4501 else
4502 {
4503 msg(msglevel, "lladdr parm '%s' must be a MAC address", p[1]);
4504 goto err;
4505 }
4506 }
4507 else if (streq(p[0], "topology") && p[1] && !p[2])
4508 {
4510 options->topology = parse_topology(p[1], msglevel);
4511 }
4512 else if (streq(p[0], "tun-ipv6") && !p[1])
4513 {
4514 if (!pull_mode)
4515 {
4516 msg(M_WARN,
4517 "Note: option tun-ipv6 is ignored because modern operating systems do not need special IPv6 tun handling anymore.");
4518 }
4519 }
4520#ifdef ENABLE_IPROUTE
4521 else if (streq(p[0], "iproute") && p[1] && !p[2])
4522 {
4524 iproute_path = p[1];
4525 }
4526#endif
4527 else if (streq(p[0], "ifconfig") && p[1] && p[2] && !p[3])
4528 {
4531 && ip_or_dns_addr_safe(p[2], options->allow_pull_fqdn)) /* FQDN -- may be DNS name */
4532 {
4533 options->ifconfig_local = p[1];
4535 }
4536 else
4537 {
4538 msg(msglevel, "ifconfig parms '%s' and '%s' must be valid addresses", p[1], p[2]);
4539 goto err;
4540 }
4541 }
4542 else if (streq(p[0], "ifconfig-ipv6") && p[1] && p[2] && !p[3])
4543 {
4544 unsigned int netbits;
4545
4547 if (get_ipv6_addr(p[1], NULL, &netbits, msglevel) && ipv6_addr_safe(p[2]))
4548 {
4550 {
4551 msg(msglevel, "ifconfig-ipv6: /netbits must be between 64 and 124, not '/%u'",
4552 netbits);
4553 goto err;
4554 }
4555
4557 options->ifconfig_ipv6_netbits = netbits;
4559 }
4560 else
4561 {
4562 msg(msglevel, "ifconfig-ipv6 parms '%s' and '%s' must be valid addresses", p[1], p[2]);
4563 goto err;
4564 }
4565 }
4566 else if (streq(p[0], "ifconfig-noexec") && !p[1])
4567 {
4569 options->ifconfig_noexec = true;
4570 }
4571 else if (streq(p[0], "ifconfig-nowarn") && !p[1])
4572 {
4574 options->ifconfig_nowarn = true;
4575 }
4576 else if (streq(p[0], "local") && p[1] && !p[4])
4577 {
4578 struct local_entry *e;
4579
4581
4583 ASSERT(e);
4584
4585 /* '*' is treated as 'ask the system to get some socket',
4586 * therefore force binding on a particular address only when
4587 * actually specified. */
4588 if (strcmp(p[1], "*") != 0)
4589 {
4590 e->local = p[1];
4591 }
4592
4593 if (p[2])
4594 {
4595 e->port = p[2];
4596 }
4597
4598 if (p[3])
4599 {
4600 e->proto = ascii2proto(p[3]);
4601 }
4602 }
4603 else if (streq(p[0], "remote-random") && !p[1])
4604 {
4606 options->remote_random = true;
4607 }
4608 else if (streq(p[0], "connection") && p[1] && !p[3])
4609 {
4611 if (is_inline)
4612 {
4613 struct options sub;
4614 struct connection_entry *e;
4615
4616 init_options(&sub);
4617 sub.ce = options->ce;
4618 read_config_string("[CONNECTION-OPTIONS]", &sub, p[1], msglevel, OPT_P_CONNECTION,
4619 option_types_found, es);
4620 if (!sub.ce.remote)
4621 {
4622 msg(msglevel,
4623 "Each 'connection' block must contain exactly one 'remote' directive");
4624 uninit_options(&sub);
4625 goto err;
4626 }
4627
4628 e = alloc_connection_entry(options, msglevel);
4629 if (!e)
4630 {
4631 uninit_options(&sub);
4632 goto err;
4633 }
4634 *e = sub.ce;
4635 gc_transfer(&options->gc, &sub.gc);
4636 uninit_options(&sub);
4637 }
4638 }
4639 else if (streq(p[0], "ignore-unknown-option") && p[1])
4640 {
4641 int i;
4642 int j;
4643 int numignored = 0;
4644 const char **ignore;
4645
4647 /* Find out how many options to be ignored */
4648 for (i = 1; p[i]; i++)
4649 {
4650 numignored++;
4651 }
4652
4653 /* add number of options already ignored */
4655 {
4656 numignored++;
4657 }
4658
4659 /* Allocate array */
4660 ALLOC_ARRAY_GC(ignore, const char *, numignored + 1, &options->gc);
4662 {
4663 ignore[i] = options->ignore_unknown_option[i];
4664 }
4665
4667
4668 for (j = 1; p[j]; j++)
4669 {
4670 /* Allow the user to specify ignore-unknown-option --opt too */
4671 if (p[j][0] == '-' && p[j][1] == '-')
4672 {
4673 options->ignore_unknown_option[i] = (p[j] + 2);
4674 }
4675 else
4676 {
4677 options->ignore_unknown_option[i] = p[j];
4678 }
4679 i++;
4680 }
4681
4682 options->ignore_unknown_option[i] = NULL;
4683 }
4684#if ENABLE_MANAGEMENT
4685 else if (streq(p[0], "http-proxy-override") && p[1] && p[2] && !p[4])
4686 {
4690 {
4691 goto err;
4692 }
4693 }
4694#endif
4695 else if (streq(p[0], "remote") && p[1] && !p[4])
4696 {
4697 struct remote_entry re;
4698 re.remote = re.remote_port = NULL;
4699 re.proto = -1;
4700 re.af = 0;
4701
4703 re.remote = p[1];
4704 if (p[2])
4705 {
4706 re.remote_port = p[2];
4707 if (p[3])
4708 {
4709 const int proto = ascii2proto(p[3]);
4710 const sa_family_t af = ascii2af(p[3]);
4711 if (proto < 0)
4712 {
4713 msg(msglevel, "remote: bad protocol associated with host %s: '%s'", p[1], p[3]);
4714 goto err;
4715 }
4716 re.proto = proto;
4717 re.af = af;
4718 }
4719 }
4720 if (permission_mask & OPT_P_GENERAL)
4721 {
4722 struct remote_entry *e = alloc_remote_entry(options, msglevel);
4723 if (!e)
4724 {
4725 goto err;
4726 }
4727 *e = re;
4728 }
4729 else if (permission_mask & OPT_P_CONNECTION)
4730 {
4732 }
4733 }
4734 else if (streq(p[0], "resolv-retry") && p[1] && !p[2])
4735 {
4737 if (streq(p[1], "infinite"))
4738 {
4740 }
4741 else
4742 {
4743 options->resolve_retry_seconds = positive_atoi(p[1], msglevel);
4744 }
4745 }
4746 else if ((streq(p[0], "preresolve") || streq(p[0], "ip-remote-hint")) && !p[2])
4747 {
4750 /* Note the ip-remote-hint and the argument p[1] are for
4751 * backward compatibility */
4752 if (p[1])
4753 {
4754 options->ip_remote_hint = p[1];
4755 }
4756 }
4757 else if (streq(p[0], "connect-retry") && p[1] && !p[3])
4758 {
4760 options->ce.connect_retry_seconds = positive_atoi(p[1], msglevel);
4761 /*
4762 * Limit the base value of retry wait interval to 16 bits to avoid
4763 * overflow when scaled up for exponential backoff
4764 */
4765 if (options->ce.connect_retry_seconds > 0xFFFF)
4766 {
4768 msg(M_WARN, "connect retry wait interval truncated to %d",
4770 }
4771
4772 if (p[2])
4773 {
4776 }
4777 }
4778 else if ((streq(p[0], "connect-timeout") || streq(p[0], "server-poll-timeout")) && p[1]
4779 && !p[2])
4780 {
4782 options->ce.connect_timeout = positive_atoi(p[1], msglevel);
4783 }
4784 else if (streq(p[0], "connect-retry-max") && p[1] && !p[2])
4785 {
4787 options->connect_retry_max = positive_atoi(p[1], msglevel);
4788 }
4789 else if (streq(p[0], "ipchange") && p[1])
4790 {
4792 if (!no_more_than_n_args(msglevel, p, 2, NM_QUOTE_HINT))
4793 {
4794 goto err;
4795 }
4797 string_substitute(p[1], ',', ' ', &options->gc), "ipchange", true);
4798 }
4799 else if (streq(p[0], "float") && !p[1])
4800 {
4802 options->ce.remote_float = true;
4803 }
4804#ifdef ENABLE_DEBUG
4805 else if (streq(p[0], "gremlin") && p[1] && !p[2])
4806 {
4808 options->gremlin = positive_atoi(p[1], msglevel);
4809 }
4810#endif
4811 else if (streq(p[0], "chroot") && p[1] && !p[2])
4812 {
4814 options->chroot_dir = p[1];
4815 }
4816 else if (streq(p[0], "cd") && p[1] && !p[2])
4817 {
4819 if (platform_chdir(p[1]))
4820 {
4821 msg(M_ERR, "cd to '%s' failed", p[1]);
4822 goto err;
4823 }
4824 options->cd_dir = p[1];
4825 }
4826#ifdef ENABLE_SELINUX
4827 else if (streq(p[0], "setcon") && p[1] && !p[2])
4828 {
4830 options->selinux_context = p[1];
4831 }
4832#endif
4833 else if (streq(p[0], "writepid") && p[1] && !p[2])
4834 {
4836 options->writepid = p[1];
4837 }
4838 else if (streq(p[0], "up") && p[1])
4839 {
4841 if (!no_more_than_n_args(msglevel, p, 2, NM_QUOTE_HINT))
4842 {
4843 goto err;
4844 }
4845 set_user_script(options, &options->up_script, p[1], "up", false);
4846 }
4847 else if (streq(p[0], "down") && p[1])
4848 {
4850 if (!no_more_than_n_args(msglevel, p, 2, NM_QUOTE_HINT))
4851 {
4852 goto err;
4853 }
4854 set_user_script(options, &options->down_script, p[1], "down", true);
4855 }
4856 else if (streq(p[0], "down-pre") && !p[1])
4857 {
4859 options->down_pre = true;
4860 }
4861 else if (streq(p[0], "up-delay") && !p[1])
4862 {
4864 options->up_delay = true;
4865 }
4866 else if (streq(p[0], "up-restart") && !p[1])
4867 {
4869 options->up_restart = true;
4870 }
4871 else if (streq(p[0], "syslog") && !p[2])
4872 {
4874 open_syslog(p[1], false);
4875 }
4876 else if (streq(p[0], "daemon") && !p[2])
4877 {
4878 bool didit = false;
4880 if (!options->daemon)
4881 {
4882 options->daemon = didit = true;
4883 open_syslog(p[1], false);
4884 }
4885 if (p[1])
4886 {
4887 if (!didit)
4888 {
4889 msg(M_WARN,
4890 "WARNING: Multiple --daemon directives specified, ignoring --daemon %s. (Note that initscripts sometimes add their own --daemon directive.)",
4891 p[1]);
4892 goto err;
4893 }
4894 }
4895 }
4896 else if (streq(p[0], "log") && p[1] && !p[2])
4897 {
4899 options->log = true;
4900 redirect_stdout_stderr(p[1], false);
4901 }
4902 else if (streq(p[0], "suppress-timestamps") && !p[1])
4903 {
4907 }
4908 else if (streq(p[0], "machine-readable-output") && !p[1])
4909 {
4913 }
4914 else if (streq(p[0], "log-append") && p[1] && !p[2])
4915 {
4917 options->log = true;
4918 redirect_stdout_stderr(p[1], true);
4919 }
4920 else if (streq(p[0], "mlock") && !p[1])
4921 {
4923 options->mlock = true;
4924 }
4925#if ENABLE_IP_PKTINFO
4926 else if (streq(p[0], "multihome") && !p[2])
4927 {
4930 if (p[1] && streq(p[1], "same-interface"))
4931 {
4933 }
4934 else if (p[1])
4935 {
4936 msg(msglevel, "Unknown parameter to --multihome: %s", p[1]);
4937 }
4938 }
4939#endif
4940 else if (streq(p[0], "verb") && p[1] && !p[2])
4941 {
4943 options->verbosity = positive_atoi(p[1], msglevel);
4945 {
4946 /* We pass this flag to the SSL library to avoid
4947 * mbed TLS always generating debug level logging */
4949 }
4950#ifdef ENABLE_SMALL
4951 /* Warn when a debug verbosity is supplied when built without debug support */
4952 if (options->verbosity >= 7)
4953 {
4954 msg(M_WARN,
4955 "NOTE: debug verbosity (--verb %d) is enabled but this build is "
4956 "built with --enable-small that lacks support for high --verb settings",
4958 }
4959#endif
4960 }
4961 else if (streq(p[0], "mute") && p[1] && !p[2])
4962 {
4964 options->mute = positive_atoi(p[1], msglevel);
4965 }
4966 else if (streq(p[0], "errors-to-stderr") && !p[1])
4967 {
4970 }
4971 else if (streq(p[0], "status") && p[1] && !p[3])
4972 {
4974 options->status_file = p[1];
4975 if (p[2])
4976 {
4978 }
4979 }
4980 else if (streq(p[0], "status-version") && p[1] && !p[2])
4981 {
4983 if (!atoi_constrained(p[1], &options->status_file_version, p[0], 1, 3, msglevel))
4984 {
4985 goto err;
4986 }
4987 }
4988 else if (streq(p[0], "remap-usr1") && p[1] && !p[2])
4989 {
4991 if (streq(p[1], "SIGHUP"))
4992 {
4994 }
4995 else if (streq(p[1], "SIGTERM"))
4996 {
4998 }
4999 else
5000 {
5001 msg(msglevel, "--remap-usr1 parm must be 'SIGHUP' or 'SIGTERM'");
5002 goto err;
5003 }
5004 }
5005 else if ((streq(p[0], "link-mtu") || streq(p[0], "udp-mtu")) && p[1] && !p[2])
5006 {
5008 options->ce.link_mtu = positive_atoi(p[1], msglevel);
5009 options->ce.link_mtu_defined = true;
5010 }
5011 else if (streq(p[0], "tun-mtu") && p[1] && !p[3])
5012 {
5014 if (atoi_constrained(p[1], &options->ce.tun_mtu, "tun-mtu", TUN_MTU_MIN, TUN_MTU_MAX, msglevel))
5015 {
5016 options->ce.tun_mtu_defined = true;
5017 if (p[2])
5018 {
5019 atoi_constrained(p[2], &options->ce.occ_mtu, "tun-mtu occ-mtu", TUN_MTU_MIN, TUN_MTU_MAX, msglevel);
5020 }
5021 else
5022 {
5023 options->ce.occ_mtu = 0;
5024 }
5025 }
5026 }
5027 else if (streq(p[0], "tun-mtu-max") && p[1] && !p[2])
5028 {
5031 }
5032 else if (streq(p[0], "tun-mtu-extra") && p[1] && !p[2])
5033 {
5035 if (atoi_constrained(p[1], &options->ce.tun_mtu_extra, p[0], 0, TUN_MTU_MAX, msglevel))
5036 {
5038 }
5039 }
5040 else if (streq(p[0], "max-packet-size") && p[1] && !p[2])
5041 {
5043 int maxmtu = positive_atoi(p[1], msglevel);
5045
5046 if (maxmtu < TLS_CHANNEL_MTU_MIN || maxmtu > TLS_CHANNEL_BUF_SIZE)
5047 {
5048 msg(M_WARN,
5049 "Note: max-packet-size value outside of allowed "
5050 "control channel packet size (%d to %d), will use %d "
5051 "instead.",
5053 }
5054
5055 /* also set mssfix maxmtu mtu */
5056 options->ce.mssfix = maxmtu;
5057 options->ce.mssfix_default = false;
5058 options->ce.mssfix_encap = true;
5059 }
5060#ifdef ENABLE_FRAGMENT
5061 else if (streq(p[0], "mtu-dynamic"))
5062 {
5064 msg(msglevel, "--mtu-dynamic has been replaced by --fragment");
5065 goto err;
5066 }
5067 else if (streq(p[0], "fragment") && p[1] && !p[3])
5068 {
5070 if (!atoi_constrained(p[1], &options->ce.fragment, p[0], 68, INT_MAX, msglevel))
5071 {
5072 goto err;
5073 }
5074
5075 if (p[2] && streq(p[2], "mtu"))
5076 {
5077 options->ce.fragment_encap = true;
5078 }
5079 else if (p[2])
5080 {
5081 msg(msglevel, "Unknown parameter to --fragment: %s", p[2]);
5082 }
5083 }
5084#endif /* ifdef ENABLE_FRAGMENT */
5085 else if (streq(p[0], "mtu-disc") && p[1] && !p[2])
5086 {
5089 }
5090 else if (streq(p[0], "mtu-test") && !p[1])
5091 {
5093 options->mtu_test = true;
5094 }
5095 else if (streq(p[0], "nice") && p[1] && !p[2])
5096 {
5098 options->nice = atoi_warn(p[1], msglevel);
5099 }
5100 else if (streq(p[0], "rcvbuf") && p[1] && !p[2])
5101 {
5103 options->rcvbuf = positive_atoi(p[1], msglevel);
5104 }
5105 else if (streq(p[0], "sndbuf") && p[1] && !p[2])
5106 {
5108 options->sndbuf = positive_atoi(p[1], msglevel);
5109 }
5110 else if (streq(p[0], "mark") && p[1] && !p[2])
5111 {
5112#if defined(TARGET_LINUX)
5114 options->mark = atoi_warn(p[1], msglevel);
5115#endif
5116 }
5117 else if (streq(p[0], "socket-flags"))
5118 {
5119 int j;
5121 for (j = 1; j < MAX_PARMS && p[j]; ++j)
5122 {
5123 /* TCP_NODELAY is enabled by default; the flag is still accepted
5124 * for backwards compatibility but no longer has any effect */
5125 if (!streq(p[j], "TCP_NODELAY"))
5126 {
5127 msg(msglevel, "unknown socket flag: %s", p[j]);
5128 }
5129 }
5130 }
5131#ifdef TARGET_LINUX
5132 else if (streq(p[0], "bind-dev") && p[1])
5133 {
5135 if (strlen(p[1]) < IFNAMSIZ)
5136 {
5137 options->bind_dev = p[1];
5138 }
5139 else
5140 {
5141 msg(msglevel, "argument to --bind-dev is longer than allowed %d", IFNAMSIZ - 1);
5142 goto err;
5143 }
5144 }
5145#endif
5146 else if (streq(p[0], "txqueuelen") && p[1] && !p[2])
5147 {
5149#ifdef TARGET_LINUX
5150 options->tuntap_options.txqueuelen = positive_atoi(p[1], msglevel);
5151#else
5152 msg(msglevel, "--txqueuelen not supported on this OS");
5153 goto err;
5154#endif
5155 }
5156 else if (streq(p[0], "shaper") && p[1] && !p[2])
5157 {
5159 if (!atoi_constrained(p[1], &options->shaper, p[0], SHAPER_MIN, SHAPER_MAX, msglevel))
5160 {
5161 goto err;
5162 }
5163 }
5164 else if (streq(p[0], "port") && p[1] && !p[2])
5165 {
5168 }
5169 else if (streq(p[0], "lport") && p[1] && !p[2])
5170 {
5172
5173 /* only trigger bind() if port is not 0 (or --local is used) */
5174 if (!streq(p[1], "0"))
5175 {
5177 }
5178 options->ce.local_port = p[1];
5179 }
5180 else if (streq(p[0], "rport") && p[1] && !p[2])
5181 {
5183 options->ce.remote_port = p[1];
5184 }
5185 else if (streq(p[0], "bind") && !p[2])
5186 {
5188 options->ce.bind_defined = true;
5189 if (p[1] && streq(p[1], "ipv6only"))
5190 {
5191 options->ce.bind_ipv6_only = true;
5192 }
5193 }
5194 else if (streq(p[0], "nobind") && !p[1])
5195 {
5197 options->ce.bind_local = false;
5198 }
5199 else if (streq(p[0], "fast-io") && !p[1])
5200 {
5202 msg(M_WARN, "DEPRECATED OPTION: --fast-io option ignored.");
5203 }
5204 else if (streq(p[0], "inactive") && p[1] && !p[3])
5205 {
5207 options->inactivity_timeout = positive_atoi(p[1], msglevel);
5208 if (p[2])
5209 {
5210 positive_atoll(p[2], &options->inactivity_minimum_bytes, p[0], msglevel);
5211 if (options->inactivity_minimum_bytes > INT_MAX)
5212 {
5213 msg(M_WARN,
5214 "WARNING: '--inactive' with a 'bytes' value"
5215 " >2 Gbyte was silently ignored in older versions. If "
5216 " your VPN exits unexpectedly with 'Inactivity timeout'"
5217 " in %d seconds, revisit this value.",
5219 }
5220 }
5221 }
5222 else if (streq(p[0], "session-timeout") && p[1] && !p[2])
5223 {
5225 options->session_timeout = positive_atoi(p[1], msglevel);
5226 }
5227 else if (streq(p[0], "proto") && p[1] && !p[2])
5228 {
5230 int proto = ascii2proto(p[1]);
5231 sa_family_t af = ascii2af(p[1]);
5232 if (proto < 0)
5233 {
5234 msg(msglevel, "Bad protocol: '%s'. Allowed protocols with --proto option: %s", p[1],
5236 goto err;
5237 }
5238 options->ce.proto = proto;
5239 options->ce.af = af;
5240 }
5241 else if (streq(p[0], "proto-force") && p[1] && !p[2])
5242 {
5243 int proto_force;
5245 proto_force = ascii2proto(p[1]);
5246 if (proto_force < 0)
5247 {
5248 msg(msglevel, "Bad --proto-force protocol: '%s'", p[1]);
5249 goto err;
5250 }
5251 options->proto_force = proto_force;
5252 }
5253 else if (streq(p[0], "http-proxy") && p[1] && !p[5])
5254 {
5255 struct http_proxy_options *ho;
5256
5258
5259 {
5260 if (!p[2])
5261 {
5262 msg(msglevel, "http-proxy port number not defined");
5263 goto err;
5264 }
5265
5267
5268 ho->server = p[1];
5269 ho->port = p[2];
5270 }
5271
5272 if (p[3])
5273 {
5274 /* auto -- try to figure out proxy addr, port, and type automatically */
5275 /* auto-nct -- disable proxy auth cleartext protocols (i.e. basic auth) */
5276 if (streq(p[3], "auto"))
5277 {
5278 ho->auth_retry = PAR_ALL;
5279 }
5280 else if (streq(p[3], "auto-nct"))
5281 {
5282 ho->auth_retry = PAR_NCT;
5283 }
5284 else
5285 {
5286 ho->auth_method_string = "basic";
5287 ho->auth_file = p[3];
5288
5289 if (p[4])
5290 {
5291 ho->auth_method_string = p[4];
5292 }
5293 }
5294 }
5295 else
5296 {
5297 ho->auth_method_string = "none";
5298 }
5299 }
5300 else if (streq(p[0], "http-proxy-user-pass") && p[1])
5301 {
5302 struct http_proxy_options *ho;
5305 ho->auth_file_up = p[1];
5306 ho->inline_creds = is_inline;
5307 }
5308 else if (streq(p[0], "http-proxy-retry") || streq(p[0], "socks-proxy-retry") || streq(p[0], "http-proxy-timeout"))
5309 {
5311 msg(M_WARN, "DEPRECATED OPTION: %s option ignored.", p[0]);
5312 }
5313 else if (streq(p[0], "http-proxy-option") && p[1] && !p[4])
5314 {
5315 struct http_proxy_options *ho;
5316
5319
5320 if (streq(p[1], "VERSION") && p[2] && !p[3])
5321 {
5322 ho->http_version = p[2];
5323 }
5324 else if (streq(p[1], "AGENT") && p[2] && !p[3])
5325 {
5326 ho->user_agent = p[2];
5327 }
5328 else if ((streq(p[1], "EXT1") || streq(p[1], "EXT2") || streq(p[1], "CUSTOM-HEADER"))
5329 && p[2])
5330 {
5331 /* In the wild patched versions use both EXT1/2 and CUSTOM-HEADER
5332 * with either two argument or one */
5333
5334 struct http_custom_header *custom_header = NULL;
5335 int i;
5336 /* Find the first free header */
5337 for (i = 0; i < MAX_CUSTOM_HTTP_HEADER; i++)
5338 {
5339 if (!ho->custom_headers[i].name)
5340 {
5341 custom_header = &ho->custom_headers[i];
5342 break;
5343 }
5344 }
5345 if (!custom_header)
5346 {
5347 msg(msglevel, "Cannot use more than %d http-proxy-option CUSTOM-HEADER : '%s'",
5349 }
5350 else
5351 {
5352 /* We will save p[2] and p[3], the proxy code will detect if
5353 * p[3] is NULL */
5354 custom_header->name = p[2];
5355 custom_header->content = p[3];
5356 }
5357 }
5358 else
5359 {
5360 msg(msglevel, "Bad http-proxy-option or missing or extra parameter: '%s'", p[1]);
5361 }
5362 }
5363 else if (streq(p[0], "socks-proxy") && p[1] && !p[4])
5364 {
5366
5367 if (p[2])
5368 {
5369 options->ce.socks_proxy_port = p[2];
5370 }
5371 else
5372 {
5373 options->ce.socks_proxy_port = "1080";
5374 }
5376 options->ce.socks_proxy_authfile = p[3]; /* might be NULL */
5377 }
5378 else if (streq(p[0], "keepalive") && p[1] && p[2] && !p[3])
5379 {
5381 atoi_constrained(p[1], &options->keepalive_ping, "keepalive ping",
5382 1, PING_TIMEOUT_MAX, msglevel);
5383 atoi_constrained(p[2], &options->keepalive_timeout, "keepalive timeout",
5384 1, PING_TIMEOUT_MAX, msglevel);
5385 }
5386 else if (streq(p[0], "ping") && p[1] && !p[2])
5387 {
5390 0, PING_TIMEOUT_MAX, msglevel);
5391 }
5392 else if (streq(p[0], "ping-exit") && p[1] && !p[2])
5393 {
5396 0, PING_TIMEOUT_MAX, msglevel);
5398 }
5399 else if (streq(p[0], "ping-restart") && p[1] && !p[2])
5400 {
5403 0, PING_TIMEOUT_MAX, msglevel);
5405 }
5406 else if (streq(p[0], "ping-timer-rem") && !p[1])
5407 {
5409 options->ping_timer_remote = true;
5410 }
5411 else if (streq(p[0], "explicit-exit-notify") && !p[2])
5412 {
5414 if (p[1])
5415 {
5417 }
5418 else
5419 {
5421 }
5422 }
5423 else if (streq(p[0], "persist-tun") && !p[1])
5424 {
5426 options->persist_tun = true;
5427 }
5428 else if (streq(p[0], "persist-key") && !p[1])
5429 {
5431 msg(M_WARN, "DEPRECATED OPTION: --persist-key option ignored. "
5432 "Keys are now always persisted across restarts. ");
5433 }
5434 else if (streq(p[0], "persist-local-ip") && !p[1])
5435 {
5437 options->persist_local_ip = true;
5438 }
5439 else if (streq(p[0], "persist-remote-ip") && !p[1])
5440 {
5442 options->persist_remote_ip = true;
5443 }
5444 else if (streq(p[0], "client-nat") && p[1] && p[2] && p[3] && p[4] && !p[5])
5445 {
5448 add_client_nat_to_option_list(options->client_nat, p[1], p[2], p[3], p[4], msglevel);
5449 }
5450 else if (streq(p[0], "route-table") && p[1] && !p[2])
5451 {
5452#ifndef ENABLE_SITNL
5453 msg(M_WARN, "NOTE: --route-table is supported only on Linux when SITNL is built-in");
5454#endif
5456 options->route_default_table_id = positive_atoi(p[1], msglevel);
5457 }
5458 else if (streq(p[0], "route") && p[1] && !p[5])
5459 {
5461 if (!check_route_option(options, p, msglevel, pull_mode))
5462 {
5463 goto err;
5464 }
5465 add_route_to_option_list(options->routes, p[1], p[2], p[3], p[4],
5467 }
5468 else if (streq(p[0], "route-ipv6") && p[1] && !p[4])
5469 {
5471 if (!check_route6_option(options, p, msglevel, pull_mode))
5472 {
5473 goto err;
5474 }
5477 }
5478 else if (streq(p[0], "max-routes") && !p[2])
5479 {
5480 msg(M_WARN, "DEPRECATED OPTION: --max-routes option ignored.");
5481 }
5482 else if (streq(p[0], "route-gateway") && p[1] && !p[2])
5483 {
5485 if (streq(p[1], "dhcp"))
5486 {
5488 }
5489 else
5490 {
5492 || is_special_addr(p[1])) /* FQDN -- may be DNS name */
5493 {
5495 }
5496 else
5497 {
5498 msg(msglevel, "route-gateway parm '%s' must be a valid address", p[1]);
5499 goto err;
5500 }
5501 }
5502 }
5503 else if (streq(p[0], "route-ipv6-gateway") && p[1] && !p[2])
5504 {
5505 if (ipv6_addr_safe(p[1]))
5506 {
5508 }
5509 else
5510 {
5511 msg(msglevel, "route-ipv6-gateway parm '%s' must be a valid address", p[1]);
5512 goto err;
5513 }
5514 }
5515 else if (streq(p[0], "route-metric") && p[1] && !p[2])
5516 {
5518 options->route_default_metric = positive_atoi(p[1], msglevel);
5519 }
5520 else if (streq(p[0], "route-delay") && !p[3])
5521 {
5524 if (p[1])
5525 {
5526 options->route_delay = positive_atoi(p[1], msglevel);
5527 if (p[2])
5528 {
5529 options->route_delay_window = positive_atoi(p[2], msglevel);
5530 }
5531 }
5532 else
5533 {
5534 options->route_delay = 0;
5535 }
5536 }
5537 else if (streq(p[0], "route-up") && p[1])
5538 {
5540 if (!no_more_than_n_args(msglevel, p, 2, NM_QUOTE_HINT))
5541 {
5542 goto err;
5543 }
5544 set_user_script(options, &options->route_script, p[1], "route-up", false);
5545 }
5546 else if (streq(p[0], "route-pre-down") && p[1])
5547 {
5549 if (!no_more_than_n_args(msglevel, p, 2, NM_QUOTE_HINT))
5550 {
5551 goto err;
5552 }
5553 set_user_script(options, &options->route_predown_script, p[1], "route-pre-down", true);
5554 }
5555 else if (streq(p[0], "route-noexec") && !p[1])
5556 {
5558 options->route_noexec = true;
5559 }
5560 else if (streq(p[0], "route-nopull") && !p[1])
5561 {
5563 options->route_nopull = true;
5564 }
5565 else if (streq(p[0], "pull-filter") && p[1] && p[2] && !p[3])
5566 {
5567 struct pull_filter *f;
5570
5571 if (strcmp("accept", p[1]) == 0)
5572 {
5573 f->type = PUF_TYPE_ACCEPT;
5574 }
5575 else if (strcmp("ignore", p[1]) == 0)
5576 {
5577 f->type = PUF_TYPE_IGNORE;
5578 }
5579 else if (strcmp("reject", p[1]) == 0)
5580 {
5581 f->type = PUF_TYPE_REJECT;
5582 }
5583 else
5584 {
5585 msg(msglevel, "Unknown --pull-filter type: %s", p[1]);
5586 goto err;
5587 }
5588 f->pattern = p[2];
5589 f->size = strlen(p[2]);
5590 }
5591 else if (streq(p[0], "allow-pull-fqdn") && !p[1])
5592 {
5594 options->allow_pull_fqdn = true;
5595 }
5596 else if (streq(p[0], "redirect-gateway") || streq(p[0], "redirect-private"))
5597 {
5598 int j;
5601
5602 if (options->routes->flags & RG_ENABLE)
5603 {
5604 msg(M_WARN, "WARNING: You have specified redirect-gateway and "
5605 "redirect-private at the same time (or the same option "
5606 "multiple times). This is not well supported and may lead to "
5607 "unexpected results");
5608 }
5609
5611
5612 if (streq(p[0], "redirect-gateway"))
5613 {
5615 }
5616 for (j = 1; j < MAX_PARMS && p[j] != NULL; ++j)
5617 {
5618 if (streq(p[j], "local"))
5619 {
5621 }
5622 else if (streq(p[j], "autolocal"))
5623 {
5625 }
5626 else if (streq(p[j], "def1"))
5627 {
5628#ifndef TARGET_ANDROID
5629 /* The hack that def1 uses to split 0.0.0.0 into 0.0.0.0/1 and
5630 * 128.0.0.0/1 is not needed on Android and will even
5631 * make some Android implementations (e.g. Samsung)
5632 * misbehave, so silently ignore the flag and always use
5633 * 0.0.0.0/0 instead */
5635#endif
5636 }
5637 else if (streq(p[j], "bypass-dhcp"))
5638 {
5640 }
5641 else if (streq(p[j], "bypass-dns"))
5642 {
5644 }
5645 else if (streq(p[j], "block-local"))
5646 {
5648 }
5649 else if (streq(p[j], "ipv6"))
5650 {
5653 }
5654 else if (streq(p[j], "!ipv4"))
5655 {
5657 }
5658 else
5659 {
5660 msg(msglevel, "unknown --%s flag: %s", p[0], p[j]);
5661 goto err;
5662 }
5663 }
5665 {
5666 setenv_int(es, "route_redirect_gateway_ipv4",
5667 (options->routes->flags & RG_BLOCK_LOCAL) ? 2 : 1);
5668 }
5670 {
5671 setenv_int(es, "route_redirect_gateway_ipv6",
5672 (options->routes->flags & RG_BLOCK_LOCAL) ? 2 : 1);
5673 }
5674#ifdef _WIN32
5675 /* we need this here to handle pushed --redirect-gateway */
5677#endif
5678 }
5679 else if (streq(p[0], "block-ipv6") && !p[1])
5680 {
5682 options->block_ipv6 = true;
5683 }
5684 else if (streq(p[0], "remote-random-hostname") && !p[1])
5685 {
5688 }
5689 else if (streq(p[0], "setenv") && p[1] && !p[3])
5690 {
5692 if (streq(p[1], "REMOTE_RANDOM_HOSTNAME") && !p[2])
5693 {
5695 }
5696 else if (streq(p[1], "GENERIC_CONFIG"))
5697 {
5698 msg(msglevel, "this is a generic configuration and cannot directly be used");
5699 goto err;
5700 }
5701 else if (streq(p[1], "PUSH_PEER_INFO") && !p[2])
5702 {
5703 options->push_peer_info = true;
5704 }
5705 else if (streq(p[1], "SERVER_POLL_TIMEOUT") && p[2])
5706 {
5707 options->ce.connect_timeout = positive_atoi(p[2], msglevel);
5708 }
5709 else
5710 {
5711 if (streq(p[1], "FORWARD_COMPATIBLE") && p[2] && streq(p[2], "1"))
5712 {
5714 }
5715 setenv_str(es, p[1], p[2] ? p[2] : "");
5716 }
5717 }
5718 else if (streq(p[0], "compat-mode") && p[1] && !p[3])
5719 {
5720 unsigned int major, minor, patch;
5721 if (!(sscanf(p[1], "%u.%u.%u", &major, &minor, &patch) == 3))
5722 {
5723 msg(msglevel, "cannot parse version number for --compat-mode: %s", p[1]);
5724 goto err;
5725 }
5726
5727 options->backwards_compatible = major * 10000 + minor * 100 + patch;
5728 }
5729 else if (streq(p[0], "setenv-safe") && p[1] && !p[3])
5730 {
5732 setenv_str_safe(es, p[1], p[2] ? p[2] : "");
5733 }
5734 else if (streq(p[0], "script-security") && p[1] && !p[2])
5735 {
5737 int security;
5738 if (atoi_constrained(p[1], &security, p[0], SSEC_NONE, SSEC_PW_ENV, msglevel))
5739 {
5740 script_security_set(security);
5741 }
5742 }
5743 else if (streq(p[0], "mssfix") && !p[3])
5744 {
5746 if (p[1])
5747 {
5748 int mssfix;
5749 if (!atoi_constrained(p[1], &mssfix, p[0], 0, UINT16_MAX, msglevel))
5750 {
5751 goto err;
5752 }
5753 if (mssfix != 0 && mssfix < TLS_CHANNEL_MTU_MIN)
5754 {
5755 msg(msglevel, "mssfix needs to be >= %d, not %d", TLS_CHANNEL_MTU_MIN, mssfix);
5756 goto err;
5757 }
5758
5759 /* value specified, assume encapsulation is not
5760 * included unless "mtu" follows later */
5761 options->ce.mssfix = mssfix;
5762 options->ce.mssfix_encap = false;
5763 options->ce.mssfix_default = false;
5764 }
5765 else
5766 {
5767 /* Set MTU to default values */
5768 options->ce.mssfix_default = true;
5769 options->ce.mssfix_encap = true;
5770 options->ce.mssfix_fixed = false;
5771 }
5772
5773 if (p[2] && streq(p[2], "mtu"))
5774 {
5775 options->ce.mssfix_encap = true;
5776 }
5777 else if (p[2] && streq(p[2], "fixed"))
5778 {
5779 options->ce.mssfix_fixed = true;
5780 }
5781 else if (p[2])
5782 {
5783 msg(msglevel, "Unknown parameter to --mssfix: %s", p[2]);
5784 }
5785 }
5786 else if (streq(p[0], "disable-occ") && !p[1])
5787 {
5789 options->occ = false;
5790 }
5791 else if (streq(p[0], "server") && p[1] && p[2] && !p[4])
5792 {
5793 const int lev = M_WARN;
5794 bool error = false;
5795 in_addr_t network, netmask;
5796
5798 network = get_ip_addr(p[1], lev, &error);
5799 netmask = get_ip_addr(p[2], lev, &error);
5800 if (error || !network || !netmask)
5801 {
5802 msg(msglevel, "error parsing --server parameters");
5803 goto err;
5804 }
5805 options->server_defined = true;
5806 options->server_network = network;
5807 options->server_netmask = netmask;
5808
5809 if (p[3])
5810 {
5811 if (streq(p[3], "nopool"))
5812 {
5814 }
5815 else
5816 {
5817 msg(msglevel, "error parsing --server: %s is not a recognized flag", p[3]);
5818 goto err;
5819 }
5820 }
5821 }
5822 else if (streq(p[0], "server-ipv6") && p[1] && !p[2])
5823 {
5824 const int lev = M_WARN;
5825 struct in6_addr network;
5826 unsigned int netbits = 0;
5827
5829 if (!get_ipv6_addr(p[1], &network, &netbits, lev))
5830 {
5831 msg(msglevel, "error parsing --server-ipv6 parameter");
5832 goto err;
5833 }
5834 if (netbits < 64 || netbits > 124)
5835 {
5836 msg(msglevel, "--server-ipv6 settings: network must be between /64 and /124 (not /%u)",
5837 netbits);
5838
5839 goto err;
5840 }
5842 options->server_network_ipv6 = network;
5843 options->server_netbits_ipv6 = netbits;
5844 }
5845 else if (streq(p[0], "server-bridge") && p[1] && p[2] && p[3] && p[4] && !p[5])
5846 {
5847 const int lev = M_WARN;
5848 bool error = false;
5849 in_addr_t ip, netmask, pool_start, pool_end;
5850
5852 ip = get_ip_addr(p[1], lev, &error);
5853 netmask = get_ip_addr(p[2], lev, &error);
5854 pool_start = get_ip_addr(p[3], lev, &error);
5855 pool_end = get_ip_addr(p[4], lev, &error);
5856 if (error || !ip || !netmask || !pool_start || !pool_end)
5857 {
5858 msg(msglevel, "error parsing --server-bridge parameters");
5859 goto err;
5860 }
5863 options->server_bridge_netmask = netmask;
5864 options->server_bridge_pool_start = pool_start;
5865 options->server_bridge_pool_end = pool_end;
5866 }
5867 else if (streq(p[0], "server-bridge") && p[1] && streq(p[1], "nogw") && !p[2])
5868 {
5872 }
5873 else if (streq(p[0], "server-bridge") && !p[1])
5874 {
5877 }
5878 else if (streq(p[0], "push") && p[1] && !p[2])
5879 {
5881 push_options(options, &p[1], msglevel, &options->gc);
5882 }
5883 else if (streq(p[0], "push-reset") && !p[1])
5884 {
5887 }
5888 else if (streq(p[0], "push-remove") && p[1] && !p[2])
5889 {
5891 msg(D_PUSH, "PUSH_REMOVE '%s'", p[1]);
5893 }
5894 else if (streq(p[0], "ifconfig-pool") && p[1] && p[2] && !p[4])
5895 {
5896 const int lev = M_WARN;
5897 bool error = false;
5898 in_addr_t start, end, netmask = 0;
5899
5901 start = get_ip_addr(p[1], lev, &error);
5902 end = get_ip_addr(p[2], lev, &error);
5903 if (p[3])
5904 {
5905 netmask = get_ip_addr(p[3], lev, &error);
5906 }
5907 if (error)
5908 {
5909 msg(msglevel, "error parsing --ifconfig-pool parameters");
5910 goto err;
5911 }
5912 if (!ifconfig_pool_verify_range(msglevel, start, end))
5913 {
5914 goto err;
5915 }
5916
5920 if (netmask)
5921 {
5922 options->ifconfig_pool_netmask = netmask;
5923 }
5924 }
5925 else if (streq(p[0], "ifconfig-pool-persist") && p[1] && !p[3])
5926 {
5929 if (p[2])
5930 {
5932 }
5933 }
5934 else if (streq(p[0], "ifconfig-ipv6-pool") && p[1] && !p[2])
5935 {
5936 const int lev = M_WARN;
5937 struct in6_addr network;
5938 unsigned int netbits = 0;
5939
5941 if (!get_ipv6_addr(p[1], &network, &netbits, lev))
5942 {
5943 msg(msglevel, "error parsing --ifconfig-ipv6-pool parameters");
5944 goto err;
5945 }
5946 if (netbits < 64 || netbits > 124)
5947 {
5948 msg(msglevel,
5949 "--ifconfig-ipv6-pool settings: network must be between /64 and /124 (not /%u)",
5950 netbits);
5951 goto err;
5952 }
5953
5957 }
5958 else if (streq(p[0], "hash-size") && p[1] && p[2] && !p[3])
5959 {
5960 int real, virtual;
5961
5963 if (!atoi_constrained(p[1], &real, "hash-size real", 1, INT_MAX, msglevel)
5964 || !atoi_constrained(p[2], &virtual, "hash-size virtual", 1, INT_MAX, msglevel))
5965 {
5966 goto err;
5967 }
5968 options->real_hash_size = (uint32_t)real;
5969 options->virtual_hash_size = (uint32_t)virtual;
5970 }
5971 else if (streq(p[0], "connect-freq") && p[1] && p[2] && !p[3])
5972 {
5973 int cf_max, cf_per;
5974
5976 if (!atoi_constrained(p[1], &cf_max, "connect-freq n", 1, INT_MAX, msglevel)
5977 || !atoi_constrained(p[2], &cf_per, "connect-freq seconds", 1, INT_MAX, msglevel))
5978 {
5979 goto err;
5980 }
5981 options->cf_max = cf_max;
5982 options->cf_per = cf_per;
5983 }
5984 else if (streq(p[0], "connect-freq-initial") && p[1] && p[2] && !p[3])
5985 {
5986 int cf_max, cf_per;
5987
5989 if (!atoi_constrained(p[1], &cf_max, "connect-freq-initial n", 1, INT_MAX, msglevel)
5990 || !atoi_constrained(p[2], &cf_per, "connect-freq-initial seconds", 1, INT_MAX, msglevel))
5991 {
5992 goto err;
5993 }
5994 options->cf_initial_max = cf_max;
5995 options->cf_initial_per = cf_per;
5996 }
5997 else if (streq(p[0], "max-clients") && p[1] && !p[2])
5998 {
6000 if (!atoi_constrained(p[1], (int *)&options->max_clients, p[0], 1, MAX_PEER_ID - 1, msglevel))
6001 {
6002 goto err;
6003 }
6004 }
6005 else if (streq(p[0], "max-routes-per-client") && p[1] && !p[2])
6006 {
6008 atoi_constrained(p[1], &options->max_routes_per_client, p[0], 1, INT_MAX, msglevel);
6009 }
6010 else if (streq(p[0], "client-cert-not-required") && !p[1])
6011 {
6013 msg(M_FATAL,
6014 "REMOVED OPTION: --client-cert-not-required, use '--verify-client-cert none' instead");
6015 }
6016 else if (streq(p[0], "verify-client-cert") && !p[2])
6017 {
6019
6020 /* Reset any existing flags */
6021 options->ssl_flags &= ~SSLF_CLIENT_CERT_OPTIONAL;
6022 options->ssl_flags &= ~SSLF_CLIENT_CERT_NOT_REQUIRED;
6023 if (p[1])
6024 {
6025 if (streq(p[1], "none"))
6026 {
6028 }
6029 else if (streq(p[1], "optional"))
6030 {
6032 }
6033 else if (!streq(p[1], "require"))
6034 {
6035 msg(msglevel,
6036 "parameter to --verify-client-cert must be 'none', 'optional' or 'require'");
6037 goto err;
6038 }
6039 }
6040 }
6041 else if (streq(p[0], "username-as-common-name") && !p[1])
6042 {
6045 }
6046 else if (streq(p[0], "auth-user-pass-optional") && !p[1])
6047 {
6050 }
6051 else if (streq(p[0], "opt-verify") && !p[1])
6052 {
6054 msg(M_INFO, "DEPRECATED OPTION: --opt-verify was removed in OpenVPN 2.7.");
6055 }
6056 else if (streq(p[0], "auth-user-pass-verify") && p[1])
6057 {
6059 if (!no_more_than_n_args(msglevel, p, 3, NM_QUOTE_HINT))
6060 {
6061 goto err;
6062 }
6063 if (p[2])
6064 {
6065 if (streq(p[2], "via-env"))
6066 {
6068 }
6069 else if (streq(p[2], "via-file"))
6070 {
6072 }
6073 else
6074 {
6075 msg(msglevel,
6076 "second parm to --auth-user-pass-verify must be 'via-env' or 'via-file'");
6077 goto err;
6078 }
6079 }
6080 else
6081 {
6082 msg(msglevel,
6083 "--auth-user-pass-verify requires a second parameter ('via-env' or 'via-file')");
6084 goto err;
6085 }
6087 "auth-user-pass-verify", true);
6088 }
6089 else if (streq(p[0], "auth-gen-token"))
6090 {
6093 options->auth_token_lifetime = p[1] ? positive_atoi(p[1], msglevel) : 0;
6094
6095 for (int i = 2; i < MAX_PARMS && p[i] != NULL; i++)
6096 {
6097 /* the second parameter can be the renewal time */
6098 if (i == 2 && valid_integer(p[i], true))
6099 {
6100 options->auth_token_renewal = positive_atoi(p[i], msglevel);
6101 }
6102 else if (streq(p[i], "external-auth"))
6103 {
6105 }
6106 else
6107 {
6108 msg(msglevel, "Invalid argument to auth-gen-token: %s (%d)", p[i], i);
6109 }
6110 }
6111 }
6112 else if (streq(p[0], "auth-gen-token-secret") && p[1] && !p[2])
6113 {
6117 }
6118 else if (streq(p[0], "client-connect") && p[1])
6119 {
6121 if (!no_more_than_n_args(msglevel, p, 2, NM_QUOTE_HINT))
6122 {
6123 goto err;
6124 }
6125 set_user_script(options, &options->client_connect_script, p[1], "client-connect", true);
6126 }
6127 else if (streq(p[0], "client-crresponse") && p[1])
6128 {
6130 if (!no_more_than_n_args(msglevel, p, 2, NM_QUOTE_HINT))
6131 {
6132 goto err;
6133 }
6134 set_user_script(options, &options->client_crresponse_script, p[1], "client-crresponse",
6135 true);
6136 }
6137 else if (streq(p[0], "client-disconnect") && p[1])
6138 {
6140 if (!no_more_than_n_args(msglevel, p, 2, NM_QUOTE_HINT))
6141 {
6142 goto err;
6143 }
6144 set_user_script(options, &options->client_disconnect_script, p[1], "client-disconnect",
6145 true);
6146 }
6147 else if (streq(p[0], "learn-address") && p[1])
6148 {
6150 if (!no_more_than_n_args(msglevel, p, 2, NM_QUOTE_HINT))
6151 {
6152 goto err;
6153 }
6154 set_user_script(options, &options->learn_address_script, p[1], "learn-address", true);
6155 }
6156 else if (streq(p[0], "tmp-dir") && p[1] && !p[2])
6157 {
6159 options->tmp_dir = p[1];
6160 }
6161 else if (streq(p[0], "client-config-dir") && p[1] && !p[2])
6162 {
6164 options->client_config_dir = p[1];
6165 }
6166 else if (streq(p[0], "ccd-exclusive") && !p[1])
6167 {
6169 options->ccd_exclusive = true;
6170 }
6171 else if (streq(p[0], "bcast-buffers") && p[1] && !p[2])
6172 {
6174 atoi_constrained(p[1], &options->n_bcast_buf, p[0], 1, MBUF_SIZE_MAX, msglevel);
6175 }
6176 else if (streq(p[0], "tcp-queue-limit") && p[1] && !p[2])
6177 {
6179 atoi_constrained(p[1], &options->tcp_queue_limit, p[0], 1, INT_MAX, msglevel);
6180 }
6181#if PORT_SHARE
6182 else if (streq(p[0], "port-share") && p[1] && p[2] && !p[4])
6183 {
6185 options->port_share_host = p[1];
6186 options->port_share_port = p[2];
6187 options->port_share_journal_dir = p[3];
6188 }
6189#endif
6190 else if (streq(p[0], "client-to-client") && !p[1])
6191 {
6193 options->enable_c2c = true;
6194 }
6195 else if (streq(p[0], "duplicate-cn") && !p[1])
6196 {
6198 options->duplicate_cn = true;
6199 }
6200 else if (streq(p[0], "iroute") && p[1] && !p[3])
6201 {
6203 option_iroute(options, p[1], p[2], msglevel);
6204 }
6205 else if (streq(p[0], "iroute-ipv6") && p[1] && !p[2])
6206 {
6208 option_iroute_ipv6(options, p[1], msglevel);
6209 }
6210 else if (streq(p[0], "ifconfig-push") && p[1] && p[2] && !p[4])
6211 {
6212 in_addr_t local, remote_netmask;
6213
6215 local = getaddr(GETADDR_HOST_ORDER | GETADDR_RESOLVE, p[1], 0, NULL, NULL);
6216 remote_netmask = getaddr(GETADDR_HOST_ORDER | GETADDR_RESOLVE, p[2], 0, NULL, NULL);
6217 if (local && remote_netmask)
6218 {
6221 options->push_ifconfig_remote_netmask = remote_netmask;
6222 if (p[3])
6223 {
6225 getaddr(GETADDR_HOST_ORDER | GETADDR_RESOLVE, p[3], 0, NULL, NULL);
6226 }
6227 }
6228 else
6229 {
6230 msg(msglevel, "cannot parse --ifconfig-push addresses");
6231 goto err;
6232 }
6233 }
6234 else if (streq(p[0], "ifconfig-push-constraint") && p[1] && p[2] && !p[3])
6235 {
6236 in_addr_t network, netmask;
6237
6239 network = getaddr(GETADDR_HOST_ORDER | GETADDR_RESOLVE, p[1], 0, NULL, NULL);
6240 netmask = getaddr(GETADDR_HOST_ORDER, p[2], 0, NULL, NULL);
6241 if (network && netmask)
6242 {
6246 }
6247 else
6248 {
6249 msg(msglevel, "cannot parse --ifconfig-push-constraint addresses");
6250 goto err;
6251 }
6252 }
6253 else if (streq(p[0], "ifconfig-ipv6-push") && p[1] && !p[3])
6254 {
6255 struct in6_addr local, remote;
6256 unsigned int netbits;
6257
6259
6260 if (!get_ipv6_addr(p[1], &local, &netbits, msglevel))
6261 {
6262 msg(msglevel, "cannot parse --ifconfig-ipv6-push addresses");
6263 goto err;
6264 }
6265
6266 if (p[2])
6267 {
6268 if (!get_ipv6_addr(p[2], &remote, NULL, msglevel))
6269 {
6270 msg(msglevel, "cannot parse --ifconfig-ipv6-push addresses");
6271 goto err;
6272 }
6273 }
6274 else
6275 {
6277 || !get_ipv6_addr(options->ifconfig_ipv6_local, &remote, NULL, msglevel))
6278 {
6279 msg(msglevel,
6280 "second argument to --ifconfig-ipv6-push missing and no global --ifconfig-ipv6 address set");
6281 goto err;
6282 }
6283 }
6284
6290 }
6291 else if (streq(p[0], "disable") && !p[1])
6292 {
6294 options->disable = true;
6295 }
6296 else if (streq(p[0], "override-username") && p[1] && !p[2])
6297 {
6299 if (strlen(p[1]) > USER_PASS_LEN)
6300 {
6301 msg(msglevel,
6302 "override-username exceeds the maximum length of %d "
6303 "characters",
6305
6306 /* disable the connection since ignoring the request to
6307 * set another username might cause serious problems */
6308 options->disable = true;
6309 }
6310 else
6311 {
6312 options->override_username = p[1];
6313 }
6314 }
6315 else if (streq(p[0], "tcp-nodelay") && !p[1])
6316 {
6319 }
6320 else if (streq(p[0], "stale-routes-check") && p[1] && !p[3])
6321 {
6322 int ageing_time, check_interval;
6323
6325 if (!atoi_constrained(p[1], &ageing_time, "stale-routes-check age", 1, INT_MAX, msglevel))
6326 {
6327 goto err;
6328 }
6329
6330 if (p[2])
6331 {
6332 if (!atoi_constrained(p[2], &check_interval,
6333 "stale-routes-check interval", 1, INT_MAX, msglevel))
6334 {
6335 goto err;
6336 }
6337 }
6338 else
6339 {
6340 check_interval = ageing_time;
6341 }
6342
6343 options->stale_routes_ageing_time = ageing_time;
6344 options->stale_routes_check_interval = check_interval;
6345 }
6346
6347 else if (streq(p[0], "client") && !p[1])
6348 {
6350 options->client = true;
6351 }
6352 else if (streq(p[0], "pull") && !p[1])
6353 {
6355 options->pull = true;
6356 }
6357 else if (streq(p[0], "push-continuation") && p[1] && !p[2])
6358 {
6360 atoi_constrained(p[1], &options->push_continuation, p[0], 0, 2, msglevel);
6361 }
6362 else if (streq(p[0], "auth-user-pass") && !p[2])
6363 {
6366 if (p[1] && streq(p[1], "username-only"))
6367 {
6369 options->auth_user_pass_file = "stdin";
6370 }
6371 else if (p[1])
6372 {
6375 }
6376 else
6377 {
6378 options->auth_user_pass_file = "stdin";
6379 }
6380 }
6381 else if (streq(p[0], "auth-retry") && p[1] && !p[2])
6382 {
6384 auth_retry_set(msglevel, p[1]);
6385 }
6386#ifdef ENABLE_MANAGEMENT
6387 else if (streq(p[0], "static-challenge") && p[1] && p[2] && !p[4])
6388 {
6391 if (atoi_warn(p[2], msglevel))
6392 {
6394 }
6395 if (p[3] && streq(p[3], "concat"))
6396 {
6398 }
6399 else if (p[3] && !streq(p[3], "scrv1"))
6400 {
6401 msg(msglevel, "--static-challenge: unknown format indicator '%s'", p[3]);
6402 goto err;
6403 }
6404 }
6405#endif
6406 else if (streq(p[0], "msg-channel") && p[1])
6407 {
6408#ifdef _WIN32
6410 HANDLE process = GetCurrentProcess();
6411 HANDLE handle = (HANDLE)((intptr_t)atoll(p[1]));
6412 if (!DuplicateHandle(process, handle, process, &options->msg_channel, 0, FALSE,
6413 DUPLICATE_CLOSE_SOURCE | DUPLICATE_SAME_ACCESS))
6414 {
6415 msg(msglevel, "could not duplicate service pipe handle");
6416 goto err;
6417 }
6419#else /* ifdef _WIN32 */
6420 msg(msglevel, "--msg-channel is only supported on Windows");
6421 goto err;
6422#endif
6423 }
6424#ifdef _WIN32
6425 else if (streq(p[0], "win-sys") && p[1] && !p[2])
6426 {
6428 if (streq(p[1], "env"))
6429 {
6430 msg(M_INFO, "NOTE: --win-sys env is default from OpenVPN 2.3. "
6431 "This entry will now be ignored. "
6432 "Please remove this entry from your configuration file.");
6433 }
6434 else
6435 {
6436 set_win_sys_path(p[1], es);
6437 }
6438 }
6439 else if (streq(p[0], "route-method") && p[1] && !p[2])
6440 {
6442 if (streq(p[1], "adaptive"))
6443 {
6445 }
6446 else if (streq(p[1], "ipapi"))
6447 {
6449 }
6450 else if (streq(p[1], "exe"))
6451 {
6453 }
6454 else
6455 {
6456 msg(msglevel, "--route method must be 'adaptive', 'ipapi', or 'exe'");
6457 goto err;
6458 }
6459 }
6460 else if (streq(p[0], "ip-win32") && p[1] && !p[4])
6461 {
6462 const int index = ascii2ipset(p[1]);
6463 struct tuntap_options *to = &options->tuntap_options;
6464
6466
6467 if (index < 0)
6468 {
6469 msg(msglevel, "Bad --ip-win32 method: '%s'. Allowed methods: %s", p[1],
6471 goto err;
6472 }
6473
6474 if (index == IPW32_SET_ADAPTIVE)
6475 {
6477 }
6478
6479 if (index == IPW32_SET_DHCP_MASQ)
6480 {
6481 if (p[2])
6482 {
6483 if (!streq(p[2], "default"))
6484 {
6485 int offset;
6486
6487 if (!atoi_constrained(p[2], &offset, "ip-win32 offset", -256, 256, msglevel))
6488 {
6489 goto err;
6490 }
6491 to->dhcp_masq_custom_offset = true;
6492 to->dhcp_masq_offset = offset;
6493 }
6494
6495 if (p[3])
6496 {
6497 if (!atoi_constrained(p[3], &to->dhcp_lease_time,
6498 "ip-win32 lease time", 30, INT_MAX, msglevel))
6499 {
6500 goto err;
6501 }
6502 }
6503 }
6504 }
6505 to->ip_win32_type = index;
6506 to->ip_win32_defined = true;
6507 }
6508#endif /* ifdef _WIN32 */
6509 else if (streq(p[0], "dns-updown") && p[1])
6510 {
6512 if (!no_more_than_n_args(msglevel, p, 2, NM_QUOTE_HINT))
6513 {
6514 goto err;
6515 }
6516 struct dns_options *dns = &options->dns_options;
6517 if (streq(p[1], "disable"))
6518 {
6519 dns->updown = NULL;
6521 }
6522 else if (streq(p[1], "force"))
6523 {
6524 /* force dns-updown run, even if a --up script is defined */
6525 if (!dns_updown_user_set(dns))
6526 {
6527 dns->updown = DEFAULT_DNS_UPDOWN;
6529 }
6530 }
6531 else
6532 {
6533 if (dns->updown && streq(dns->updown, DEFAULT_DNS_UPDOWN))
6534 {
6535 /* Unset the default command to prevent warnings */
6536 dns->updown = NULL;
6537 }
6538 set_user_script(options, &dns->updown, p[1], p[0], false);
6540 }
6541 }
6542 else if (streq(p[0], "dns") && p[1])
6543 {
6545 if (!check_dns_option(options, p, msglevel, pull_mode))
6546 {
6547 goto err;
6548 }
6549 }
6550 else if (streq(p[0], "dhcp-option") && p[1])
6551 {
6553#if defined(_WIN32) || defined(TARGET_ANDROID)
6555#endif
6557
6558 bool dhcp_optional = false;
6559
6560 if ((streq(p[1], "DOMAIN") || streq(p[1], "ADAPTER_DOMAIN_SUFFIX")) && p[2] && !p[3])
6561 {
6562 if (!validate_domain(p[2]))
6563 {
6564 msg(msglevel, "--dhcp-option %s contains invalid characters", p[1]);
6565 goto err;
6566 }
6567
6568 dhcp->domain = p[2];
6569 dhcp_optional = true;
6570 }
6571 else if (streq(p[1], "DOMAIN-SEARCH") && p[2] && !p[3])
6572 {
6573 if (!validate_domain(p[2]))
6574 {
6575 msg(msglevel, "--dhcp-option %s contains invalid characters", p[1]);
6576 goto err;
6577 }
6578
6579 if (dhcp->domain_search_list_len < N_SEARCH_LIST_LEN)
6580 {
6581 dhcp->domain_search_list[dhcp->domain_search_list_len++] = p[2];
6582 }
6583 else
6584 {
6585 msg(msglevel, "--dhcp-option %s: maximum of %d search entries can be specified",
6586 p[1], N_SEARCH_LIST_LEN);
6587 }
6588 dhcp_optional = true;
6589 }
6590 else if ((streq(p[1], "DNS") || streq(p[1], "DNS6")) && p[2] && !p[3]
6591 && (!strstr(p[2], ":") || ipv6_addr_safe(p[2])))
6592 {
6593 if (strstr(p[2], ":"))
6594 {
6595 dhcp_option_dns6_parse(p[2], dhcp->dns6, &dhcp->dns6_len, msglevel);
6596 }
6597 else
6598 {
6599 dhcp_option_address_parse("DNS", p[2], dhcp->dns, &dhcp->dns_len, msglevel);
6600 dhcp_optional = true;
6601 }
6602 }
6603#if defined(_WIN32) || defined(TARGET_ANDROID)
6604 else if (streq(p[1], "NBS") && p[2] && !p[3])
6605 {
6606 o->netbios_scope = p[2];
6608 }
6609 else if (streq(p[1], "NBT") && p[2] && !p[3])
6610 {
6611 int t = atoi_warn(p[2], msglevel);
6612 if (!(t == 1 || t == 2 || t == 4 || t == 8))
6613 {
6614 msg(msglevel, "--dhcp-option NBT: parameter (%d) must be 1, 2, 4, or 8", t);
6615 goto err;
6616 }
6617 o->netbios_node_type = (uint8_t)t;
6619 }
6620 else if (streq(p[1], "WINS") && p[2] && !p[3])
6621 {
6622 dhcp_option_address_parse("WINS", p[2], o->wins, &o->wins_len, msglevel);
6624 }
6625 else if (streq(p[1], "NTP") && p[2] && !p[3])
6626 {
6627 dhcp_option_address_parse("NTP", p[2], o->ntp, &o->ntp_len, msglevel);
6629 }
6630 else if (streq(p[1], "NBDD") && p[2] && !p[3])
6631 {
6632 dhcp_option_address_parse("NBDD", p[2], o->nbdd, &o->nbdd_len, msglevel);
6634 }
6635 else if (streq(p[1], "DISABLE-NBT") && !p[2])
6636 {
6637 o->disable_nbt = 1;
6639 }
6640#if defined(TARGET_ANDROID)
6641 else if (streq(p[1], "PROXY_HTTP") && p[3] && !p[4])
6642 {
6643 o->http_proxy_port = positive_atoi(p[3], msglevel);
6644 o->http_proxy = p[2];
6645 }
6646#endif
6647 else
6648 {
6649 msg(msglevel, "--dhcp-option: unknown option type '%s' or missing or unknown parameter",
6650 p[1]);
6651 goto err;
6652 }
6653#else /* if defined(_WIN32) || defined(TARGET_ANDROID) */
6654 setenv_foreign_option(options, p[1], p[2], es);
6655#endif /* if defined(_WIN32) || defined(TARGET_ANDROID) */
6656
6657 if (dhcp_optional)
6658 {
6659#if defined(_WIN32) || defined(TARGET_ANDROID)
6661#endif
6662 }
6663 }
6664#ifdef _WIN32
6665 else if (streq(p[0], "show-adapters") && !p[1])
6666 {
6669 openvpn_exit(OPENVPN_EXIT_STATUS_GOOD); /* exit point */
6670 }
6671 else if (streq(p[0], "show-net") && !p[1])
6672 {
6676 openvpn_exit(OPENVPN_EXIT_STATUS_GOOD); /* exit point */
6677 }
6678 else if (streq(p[0], "show-net-up") && !p[1])
6679 {
6681 options->show_net_up = true;
6682 }
6683 else if (streq(p[0], "tap-sleep") && p[1] && !p[2])
6684 {
6686 if (!atoi_constrained(p[1], &options->tuntap_options.tap_sleep, p[0], 0, 255, msglevel))
6687 {
6688 goto err;
6689 }
6690 }
6691 else if (streq(p[0], "dhcp-renew") && !p[1])
6692 {
6695 }
6696 else if (streq(p[0], "dhcp-pre-release") && !p[1])
6697 {
6701 }
6702 else if (streq(p[0], "dhcp-release") && !p[1])
6703 {
6704 msg(M_WARN, "Obsolete option --dhcp-release detected. This is now on by default");
6705 }
6706 else if (streq(p[0], "dhcp-internal") && p[1] && !p[2]) /* standalone method for internal use */
6707 {
6708 unsigned int adapter_index;
6711 adapter_index = atou(p[1]);
6714 {
6715 dhcp_release_by_adapter_index(adapter_index);
6716 }
6718 {
6719 dhcp_renew_by_adapter_index(adapter_index);
6720 }
6721 openvpn_exit(OPENVPN_EXIT_STATUS_GOOD); /* exit point */
6722 }
6723 else if (streq(p[0], "register-dns") && !p[1])
6724 {
6727 }
6728 else if (streq(p[0], "block-outside-dns") && !p[1])
6729 {
6731 options->block_outside_dns = true;
6732 }
6733 else if (streq(p[0], "rdns-internal") && !p[1])
6734 /* standalone method for internal use
6735 *
6736 * (if --register-dns is set, openvpn needs to call itself in a
6737 * sub-process to execute the required functions in a non-blocking
6738 * way, and uses --rdns-internal to signal that to itself)
6739 */
6740 {
6744 {
6746 }
6747 openvpn_exit(OPENVPN_EXIT_STATUS_GOOD); /* exit point */
6748 }
6749 else if (streq(p[0], "show-valid-subnets") && !p[1])
6750 {
6753 openvpn_exit(OPENVPN_EXIT_STATUS_GOOD); /* exit point */
6754 }
6755 else if (streq(p[0], "pause-exit") && !p[1])
6756 {
6759 }
6760 else if (streq(p[0], "service") && p[1] && !p[3])
6761 {
6763 options->exit_event_name = p[1];
6764 if (p[2])
6765 {
6766 options->exit_event_initial_state = (atoi_warn(p[2], msglevel) != 0);
6767 }
6768 }
6769 else if (streq(p[0], "allow-nonadmin") && !p[2])
6770 {
6773 openvpn_exit(OPENVPN_EXIT_STATUS_GOOD); /* exit point */
6774 }
6775 else if (streq(p[0], "user") && p[1] && !p[2])
6776 {
6778 msg(M_WARN, "NOTE: --user option is not implemented on Windows");
6779 }
6780 else if (streq(p[0], "group") && p[1] && !p[2])
6781 {
6783 msg(M_WARN, "NOTE: --group option is not implemented on Windows");
6784 }
6785#else /* ifdef _WIN32 */
6786 else if (streq(p[0], "user") && p[1] && !p[2])
6787 {
6789 options->username = p[1];
6790 }
6791 else if (streq(p[0], "group") && p[1] && !p[2])
6792 {
6794 options->groupname = p[1];
6795 }
6796 else if (streq(p[0], "dhcp-option") && p[1] && !p[3])
6797 {
6799 setenv_foreign_option(options, p[1], p[2], es);
6800 }
6801 else if (streq(p[0], "route-method") && p[1] && !p[2])
6802 {
6804 /* ignore when pushed to non-Windows OS */
6805 }
6806#endif /* ifdef _WIN32 */
6807#if PASSTOS_CAPABILITY
6808 else if (streq(p[0], "passtos") && !p[1])
6809 {
6811 options->passtos = true;
6812 }
6813#endif
6814 else if (streq(p[0], "allow-compression") && p[1] && !p[2])
6815 {
6817
6818 if (streq(p[1], "no"))
6819 {
6822 {
6823 msg(msglevel, "'--allow-compression no' conflicts with "
6824 " enabling compression");
6825 }
6826 }
6828 {
6829 /* Also printed on a push to hint at configuration problems */
6830 msg(msglevel,
6831 "Cannot set allow-compression to '%s' "
6832 "after set to 'no'",
6833 p[1]);
6834 goto err;
6835 }
6836 else if (streq(p[1], "asym"))
6837 {
6839 }
6840 else if (streq(p[1], "yes"))
6841 {
6842 msg(M_WARN,
6843 "DEPRECATED OPTION: \"--allow-compression yes\" has been removed. "
6844 "We will use \"asym\" mode instead. See the manual page for more information.");
6845
6847 }
6848 else
6849 {
6850 msg(msglevel,
6851 "bad allow-compression option: %s -- "
6852 "must be 'yes', 'no', or 'asym'",
6853 p[1]);
6854 goto err;
6855 }
6856 }
6857 else if (streq(p[0], "comp-lzo") && !p[2])
6858 {
6860
6861 /* All lzo variants do not use swap */
6862 options->comp.flags &= ~COMP_F_SWAP;
6864
6865 if (p[1])
6866 {
6867 if (streq(p[1], "no"))
6868 {
6870 }
6871 /* There is no actual difference anymore between these variants.
6872 * We never compress. On the server side we replace this with
6873 * --compress migrate later anyway.
6874 */
6875 else if (!(streq(p[1], "yes") || streq(p[1], "adaptive")))
6876 {
6877 msg(msglevel, "bad comp-lzo option: %s -- must be 'yes', 'no', or 'adaptive'",
6878 p[1]);
6879 goto err;
6880 }
6881 }
6883 }
6884 else if (streq(p[0], "comp-noadapt") && !p[1])
6885 {
6886 /* NO-OP since we never compress anymore */
6887 }
6888 else if (streq(p[0], "compress") && !p[2])
6889 {
6891 const char *alg = "stub";
6892 if (p[1])
6893 {
6894 alg = p[1];
6895 }
6896
6897 if (streq(alg, "stub"))
6898 {
6901 }
6902 else if (streq(alg, "stub-v2"))
6903 {
6906 }
6907 else if (streq(alg, "migrate"))
6908 {
6911 }
6912 else if (streq(alg, "lzo"))
6913 {
6915 options->comp.flags &= ~COMP_F_SWAP;
6916 }
6917 else if (streq(alg, "lz4"))
6918 {
6921 }
6922 else if (streq(alg, "lz4-v2"))
6923 {
6925 }
6926 else
6927 {
6928 msg(msglevel, "bad comp option: %s", alg);
6929 goto err;
6930 }
6931
6933 }
6934 else if (streq(p[0], "show-ciphers") && !p[1])
6935 {
6937 options->show_ciphers = true;
6938 }
6939 else if (streq(p[0], "show-digests") && !p[1])
6940 {
6942 options->show_digests = true;
6943 }
6944 else if (streq(p[0], "show-engines") && !p[1])
6945 {
6947 options->show_engines = true;
6948 }
6949 else if (streq(p[0], "key-direction") && p[1] && !p[2])
6950 {
6951 int key_direction;
6952
6954
6955 key_direction = ascii2keydirection(msglevel, p[1]);
6956 if (key_direction >= 0)
6957 {
6958 if (permission_mask & OPT_P_GENERAL)
6959 {
6960 options->key_direction = key_direction;
6961 }
6962 else if (permission_mask & OPT_P_CONNECTION)
6963 {
6964 options->ce.key_direction = key_direction;
6965 }
6966 }
6967 else
6968 {
6969 goto err;
6970 }
6971 }
6972 else if (streq(p[0], "secret") && p[1] && !p[3])
6973 {
6974 msg(M_WARN, "DEPRECATED OPTION: The option --secret is deprecated.");
6978 if (!is_inline && p[2])
6979 {
6980 int key_direction;
6981
6982 key_direction = ascii2keydirection(msglevel, p[2]);
6983 if (key_direction >= 0)
6984 {
6985 options->key_direction = key_direction;
6986 }
6987 else
6988 {
6989 goto err;
6990 }
6991 }
6992 }
6993 else if (streq(p[0], "allow-deprecated-insecure-static-crypto"))
6994 {
6997 }
6998 else if (streq(p[0], "genkey") && !p[4])
6999 {
7001 options->genkey = true;
7002 if (!p[1])
7003 {
7005 }
7006 else
7007 {
7008 if (streq(p[1], "secret") || streq(p[1], "tls-auth") || streq(p[1], "tls-crypt"))
7009 {
7011 }
7012 else if (streq(p[1], "tls-crypt-v2-server"))
7013 {
7015 }
7016 else if (streq(p[1], "tls-crypt-v2-client"))
7017 {
7019 if (p[3])
7020 {
7021 options->genkey_extra_data = p[3];
7022 }
7023 }
7024 else if (streq(p[1], "auth-token"))
7025 {
7027 }
7028 else
7029 {
7030 msg(msglevel, "unknown --genkey type: %s", p[1]);
7031 }
7032 }
7033 if (p[2])
7034 {
7035 options->genkey_filename = p[2];
7036 }
7037 }
7038 else if (streq(p[0], "auth") && p[1] && !p[2])
7039 {
7041 options->authname = p[1];
7042 }
7043 else if (streq(p[0], "cipher") && p[1] && !p[2])
7044 {
7046 options->ciphername = p[1];
7047 }
7048 else if (streq(p[0], "data-ciphers-fallback") && p[1] && !p[2])
7049 {
7051 options->ciphername = p[1];
7053 }
7054 else if ((streq(p[0], "data-ciphers") || streq(p[0], "ncp-ciphers")) && p[1] && !p[2])
7055 {
7057 if (streq(p[0], "ncp-ciphers"))
7058 {
7059 msg(M_INFO, "Note: Treating option '--ncp-ciphers' as "
7060 " '--data-ciphers' (renamed in OpenVPN 2.5).");
7061 }
7062 options->ncp_ciphers = p[1];
7063 }
7064 else if (streq(p[0], "key-derivation") && p[1])
7065 {
7066 /* NCP only option that is pushed by the server to enable EKM,
7067 * should not be used by normal users in config files*/
7069 if (streq(p[1], "tls-ekm"))
7070 {
7072 }
7073 else
7074 {
7075 msg(msglevel, "Unknown key-derivation method %s", p[1]);
7076 }
7077 }
7078 else if (streq(p[0], "protocol-flags") && p[1])
7079 {
7080 /* NCP only option that is pushed by the server to enable protocol
7081 * features that are negotiated, should not be used by normal users
7082 * in config files */
7084 for (size_t j = 1; j < MAX_PARMS && p[j] != NULL; j++)
7085 {
7086 if (streq(p[j], "cc-exit"))
7087 {
7089 }
7090 else if (streq(p[j], "tls-ekm"))
7091 {
7093 }
7094 else if (streq(p[j], "dyn-tls-crypt"))
7095 {
7097 }
7098 else if (streq(p[j], "aead-epoch"))
7099 {
7101 }
7102 else
7103 {
7104 msg(msglevel, "Unknown protocol-flags flag: %s", p[j]);
7105 }
7106 }
7107 }
7108 else if (streq(p[0], "force-tls-key-material-export"))
7109 {
7112 }
7113 else if (streq(p[0], "prng") && p[1] && !p[3])
7114 {
7115 msg(M_WARN, "NOTICE: --prng option ignored (SSL library PRNG is used)");
7116 }
7117 else if (streq(p[0], "no-replay") && !p[1])
7118 {
7120 /* always error out, this breaks the connection */
7121 msg(M_FATAL, "--no-replay was removed in OpenVPN 2.7. "
7122 "Update your configuration.");
7123 }
7124 else if (streq(p[0], "replay-window") && !p[3])
7125 {
7127 if (p[1])
7128 {
7129 if (!atoi_constrained(p[1], &options->replay_window, "replay-window windows size",
7131 {
7132 goto err;
7133 }
7134
7135 if (p[2])
7136 {
7137 if (!atoi_constrained(p[2], &options->replay_time, "replay-window time window",
7139 {
7140 goto err;
7141 }
7142 }
7143 }
7144 else
7145 {
7146 msg(msglevel, "replay-window option is missing window size parameter");
7147 goto err;
7148 }
7149 }
7150 else if (streq(p[0], "mute-replay-warnings") && !p[1])
7151 {
7154 }
7155 else if (streq(p[0], "replay-persist") && p[1] && !p[2])
7156 {
7158 options->packet_id_file = p[1];
7159 }
7160 else if (streq(p[0], "test-crypto") && !p[1])
7161 {
7163 options->test_crypto = true;
7164 }
7165#ifndef ENABLE_CRYPTO_MBEDTLS
7166 else if (streq(p[0], "engine") && !p[2])
7167 {
7169 if (p[1])
7170 {
7171 options->engine = p[1];
7172 }
7173 else
7174 {
7175 options->engine = "auto";
7176 }
7177 }
7178#endif /* ENABLE_CRYPTO_MBEDTLS */
7179 else if (streq(p[0], "providers") && p[1])
7180 {
7181 for (size_t j = 1; j < MAX_PARMS && p[j] != NULL; j++)
7182 {
7183 options->providers.names[j] = p[j];
7184 }
7185 }
7186 else if (streq(p[0], "show-tls") && !p[1])
7187 {
7189 options->show_tls_ciphers = true;
7190 }
7191 else if ((streq(p[0], "show-curves") || streq(p[0], "show-groups")) && !p[1])
7192 {
7194 options->show_curves = true;
7195 }
7196 else if (streq(p[0], "ecdh-curve") && p[1] && !p[2])
7197 {
7199 msg(M_WARN, "Consider setting groups/curves preference with "
7200 "tls-groups instead of forcing a specific curve with "
7201 "ecdh-curve.");
7202 options->ecdh_curve = p[1];
7203 }
7204 else if (streq(p[0], "tls-server") && !p[1])
7205 {
7207 options->tls_server = true;
7208 }
7209 else if (streq(p[0], "tls-client") && !p[1])
7210 {
7212 options->tls_client = true;
7213 }
7214 else if (streq(p[0], "ca") && p[1] && !p[2])
7215 {
7217 options->ca_file = p[1];
7218 options->ca_file_inline = is_inline;
7219 }
7220#ifndef ENABLE_CRYPTO_MBEDTLS
7221 else if (streq(p[0], "capath") && p[1] && !p[2])
7222 {
7224 options->ca_path = p[1];
7225 }
7226#endif /* ENABLE_CRYPTO_MBEDTLS */
7227 else if (streq(p[0], "dh") && p[1] && !p[2])
7228 {
7230 options->dh_file = p[1];
7231 options->dh_file_inline = is_inline;
7232 }
7233 else if (streq(p[0], "cert") && p[1] && !p[2])
7234 {
7236 options->cert_file = p[1];
7237 options->cert_file_inline = is_inline;
7238 }
7239 else if (streq(p[0], "extra-certs") && p[1] && !p[2])
7240 {
7242 options->extra_certs_file = p[1];
7243 options->extra_certs_file_inline = is_inline;
7244 }
7245 else if ((streq(p[0], "verify-hash") && p[1] && !p[3])
7246 || (streq(p[0], "peer-fingerprint") && p[1] && !p[2]))
7247 {
7249
7250 int verify_hash_depth = 0;
7251 if (streq(p[0], "verify-hash"))
7252 {
7253 msg(M_WARN, "DEPRECATED OPTION: The option --verify-hash is deprecated. "
7254 "You should switch to the either use the level 1 certificate as "
7255 "--ca option, use --tls-verify or use --peer-fingerprint");
7256 /* verify level 1 cert, i.e. the CA that signed the leaf cert */
7257 verify_hash_depth = 1;
7258 }
7259
7261
7262 int digest_len = SHA256_DIGEST_LENGTH;
7263
7264 if (options->verify_hash && options->verify_hash_depth != verify_hash_depth)
7265 {
7266 msg(msglevel,
7267 "ERROR: Setting %s not allowed. --verify-hash and"
7268 " --peer-fingerprint are mutually exclusive",
7269 p[0]);
7270 goto err;
7271 }
7272
7273 if (streq(p[0], "verify-hash"))
7274 {
7275 if ((!p[2] && !is_inline) || (p[2] && streq(p[2], "SHA1")))
7276 {
7278 digest_len = SHA_DIGEST_LENGTH;
7279 }
7280 else if (p[2] && !streq(p[2], "SHA256"))
7281 {
7282 msg(msglevel,
7283 "invalid or unsupported hashing algorithm: %s "
7284 "(only SHA1 and SHA256 are supported)",
7285 p[2]);
7286 goto err;
7287 }
7288 }
7289
7290 struct verify_hash_list *newlist;
7291 newlist = parse_hash_fingerprint_multiline(p[1], digest_len, msglevel, &options->gc);
7292
7293 /* Append the new list to the end of our current list */
7294 if (!options->verify_hash)
7295 {
7296 options->verify_hash = newlist;
7297 options->verify_hash_depth = verify_hash_depth;
7298 }
7299 else
7300 {
7301 /* since both the old and new list can have multiple entries
7302 * we need to go to the end of one of them to concatenate them */
7303 struct verify_hash_list *listend = options->verify_hash;
7304 while (listend->next)
7305 {
7306 listend = listend->next;
7307 }
7308 listend->next = newlist;
7309 }
7310 }
7311#if defined(ENABLE_CRYPTOAPI) && defined(HAVE_XKEY_PROVIDER)
7312 else if (streq(p[0], "cryptoapicert") && p[1] && !p[2])
7313 {
7315 options->cryptoapi_cert = p[1];
7316 }
7317#endif
7318 else if (streq(p[0], "key") && p[1] && !p[2])
7319 {
7321 options->priv_key_file = p[1];
7322 options->priv_key_file_inline = is_inline;
7323 }
7324 else if (streq(p[0], "tls-version-min") && p[1] && !p[3])
7325 {
7327 int ver = tls_version_parse(p[1], p[2]);
7328 if (ver == TLS_VER_BAD)
7329 {
7330 msg(msglevel, "unknown tls-version-min parameter: %s", p[1]);
7331 goto err;
7332 }
7333
7334#ifdef ENABLE_CRYPTO_MBEDTLS
7335 if (ver < TLS_VER_1_2)
7336 {
7337 msg(M_WARN, "--tls-version-min %s is not supported by mbedtls, using 1.2", p[1]);
7338 ver = TLS_VER_1_2;
7339 }
7340#endif
7341
7343 options->ssl_flags |= ((unsigned int)ver << SSLF_TLS_VERSION_MIN_SHIFT);
7344 }
7345 else if (streq(p[0], "tls-version-max") && p[1] && !p[2])
7346 {
7348 int ver = tls_version_parse(p[1], NULL);
7349 if (ver == TLS_VER_BAD)
7350 {
7351 msg(msglevel, "unknown tls-version-max parameter: %s", p[1]);
7352 goto err;
7353 }
7355 options->ssl_flags |= ((unsigned int)ver << SSLF_TLS_VERSION_MAX_SHIFT);
7356 }
7357#ifndef ENABLE_CRYPTO_MBEDTLS
7358 else if (streq(p[0], "pkcs12") && p[1] && !p[2])
7359 {
7361 options->pkcs12_file = p[1];
7362 options->pkcs12_file_inline = is_inline;
7363 }
7364#endif /* ENABLE_CRYPTO_MBEDTLS */
7365 else if (streq(p[0], "askpass") && !p[2])
7366 {
7368 if (p[1])
7369 {
7370 options->key_pass_file = p[1];
7371 }
7372 else
7373 {
7374 options->key_pass_file = "stdin";
7375 }
7376 }
7377 else if (streq(p[0], "auth-nocache") && !p[1])
7378 {
7381 }
7382 else if (streq(p[0], "auth-token") && p[1] && !p[2])
7383 {
7385 ssl_set_auth_token(p[1]);
7386#ifdef ENABLE_MANAGEMENT
7387 if (management)
7388 {
7390 }
7391#endif
7392 }
7393 else if (streq(p[0], "auth-token-user") && p[1] && !p[2])
7394 {
7397 }
7398 else if (streq(p[0], "single-session") && !p[1])
7399 {
7401 options->single_session = true;
7402 }
7403 else if (streq(p[0], "push-peer-info") && !p[1])
7404 {
7406 options->push_peer_info = true;
7407 }
7408 else if (streq(p[0], "tls-exit") && !p[1])
7409 {
7411 options->tls_exit = true;
7412 }
7413 else if (streq(p[0], "tls-cipher") && p[1] && !p[2])
7414 {
7416 options->cipher_list = p[1];
7417 }
7418 else if (streq(p[0], "tls-cert-profile") && p[1] && !p[2])
7419 {
7421 options->tls_cert_profile = p[1];
7422 }
7423 else if (streq(p[0], "tls-ciphersuites") && p[1] && !p[2])
7424 {
7426 options->cipher_list_tls13 = p[1];
7427 }
7428 else if (streq(p[0], "tls-groups") && p[1] && !p[2])
7429 {
7431 options->tls_groups = p[1];
7432 }
7433 else if (streq(p[0], "crl-verify") && p[1] && ((p[2] && streq(p[2], "dir")) || !p[2]))
7434 {
7436 if (p[2] && streq(p[2], "dir"))
7437 {
7439 }
7440 options->crl_file = p[1];
7441 options->crl_file_inline = is_inline;
7442 }
7443 else if (streq(p[0], "tls-verify") && p[1])
7444 {
7446 if (!no_more_than_n_args(msglevel, p, 2, NM_QUOTE_HINT))
7447 {
7448 goto err;
7449 }
7451 string_substitute(p[1], ',', ' ', &options->gc), "tls-verify", true);
7452 }
7453 else if (streq(p[0], "tls-export-cert") && p[1] && !p[2])
7454 {
7457 }
7458 else if (streq(p[0], "compat-names"))
7459 {
7461 msg(msglevel, "--compat-names was removed in OpenVPN 2.5. "
7462 "Update your configuration.");
7463 goto err;
7464 }
7465 else if (streq(p[0], "no-name-remapping") && !p[1])
7466 {
7468 msg(msglevel, "--no-name-remapping was removed in OpenVPN 2.5. "
7469 "Update your configuration.");
7470 goto err;
7471 }
7472 else if (streq(p[0], "verify-x509-name") && p[1] && strlen(p[1]) && !p[3])
7473 {
7474 int type = VERIFY_X509_SUBJECT_DN;
7476 if (p[2])
7477 {
7478 if (streq(p[2], "subject"))
7479 {
7481 }
7482 else if (streq(p[2], "name"))
7483 {
7485 }
7486 else if (streq(p[2], "name-prefix"))
7487 {
7489 }
7490 else
7491 {
7492 msg(msglevel, "unknown X.509 name type: %s", p[2]);
7493 goto err;
7494 }
7495 }
7496 options->verify_x509_type = type;
7497 options->verify_x509_name = p[1];
7498 }
7499 else if (streq(p[0], "ns-cert-type") && p[1] && !p[2])
7500 {
7501#ifdef ENABLE_CRYPTO_MBEDTLS
7502 msg(msglevel, "--ns-cert-type is not available with mbedtls.");
7503 goto err;
7504#else
7506 if (streq(p[1], "server"))
7507 {
7509 }
7510 else if (streq(p[1], "client"))
7511 {
7513 }
7514 else
7515 {
7516 msg(msglevel, "--ns-cert-type must be 'client' or 'server'");
7517 goto err;
7518 }
7519#endif /* ENABLE_CRYPTO_MBEDTLS */
7520 }
7521 else if (streq(p[0], "remote-cert-ku"))
7522 {
7524
7525 size_t j;
7526 for (j = 1; j < MAX_PARMS && p[j] != NULL; ++j)
7527 {
7528 sscanf(p[j], "%x", &(options->remote_cert_ku[j - 1]));
7529 }
7530 if (j == 1)
7531 {
7532 /* No specific KU required, but require KU to be present */
7534 }
7535 }
7536 else if (streq(p[0], "remote-cert-eku") && p[1] && !p[2])
7537 {
7539 options->remote_cert_eku = p[1];
7540 }
7541 else if (streq(p[0], "remote-cert-tls") && p[1] && !p[2])
7542 {
7544
7545 if (streq(p[1], "server"))
7546 {
7548 options->remote_cert_eku = "TLS Web Server Authentication";
7549 }
7550 else if (streq(p[1], "client"))
7551 {
7553 options->remote_cert_eku = "TLS Web Client Authentication";
7554 }
7555 else
7556 {
7557 msg(msglevel, "--remote-cert-tls must be 'client' or 'server'");
7558 goto err;
7559 }
7560 }
7561 else if (streq(p[0], "tls-timeout") && p[1] && !p[2])
7562 {
7564 /* Constrain the timeout to not have problems with
7565 * RELIABLE_MAX_TIMEOUT_SHIFT creating an overflow. 65k seconds
7566 * timeout is already way too much anyway */
7567 if (!atoi_constrained(p[1], &options->tls_timeout, "tls-timeout", 1,
7569 {
7570 goto err;
7571 }
7572 }
7573 else if (streq(p[0], "reneg-bytes") && p[1] && !p[2])
7574 {
7576 if (!positive_atoll(p[1], &options->renegotiate_bytes, p[0], msglevel))
7577 {
7578 goto err;
7579 }
7580 }
7581 else if (streq(p[0], "reneg-pkts") && p[1] && !p[2])
7582 {
7584 if (!positive_atoll(p[1], &options->renegotiate_packets, p[0], msglevel))
7585 {
7586 goto err;
7587 }
7588 }
7589 else if (streq(p[0], "reneg-sec") && p[1] && !p[3])
7590 {
7592 options->renegotiate_seconds = positive_atoi(p[1], msglevel);
7593 if (p[2])
7594 {
7596 }
7597 }
7598 else if (streq(p[0], "hand-window") && p[1] && !p[2])
7599 {
7601 options->handshake_window = positive_atoi(p[1], msglevel);
7602 }
7603 else if (streq(p[0], "tran-window") && p[1] && !p[2])
7604 {
7606 options->transition_window = positive_atoi(p[1], msglevel);
7607 }
7608 else if (streq(p[0], "tls-auth") && p[1] && !p[3])
7609 {
7610 int key_direction = -1;
7611
7613
7614 if (permission_mask & OPT_P_GENERAL)
7615 {
7616 options->tls_auth_file = p[1];
7617 options->tls_auth_file_inline = is_inline;
7618
7619 if (!is_inline && p[2])
7620 {
7621 key_direction = ascii2keydirection(msglevel, p[2]);
7622 if (key_direction < 0)
7623 {
7624 goto err;
7625 }
7626 options->key_direction = key_direction;
7627 }
7628 }
7629 else if (permission_mask & OPT_P_CONNECTION)
7630 {
7631 options->ce.tls_auth_file = p[1];
7632 options->ce.tls_auth_file_inline = is_inline;
7634
7635 if (!is_inline && p[2])
7636 {
7637 key_direction = ascii2keydirection(msglevel, p[2]);
7638 if (key_direction < 0)
7639 {
7640 goto err;
7641 }
7642 options->ce.key_direction = key_direction;
7643 }
7644 }
7645 }
7646 else if (streq(p[0], "tls-crypt") && p[1] && !p[3])
7647 {
7649 if (permission_mask & OPT_P_GENERAL)
7650 {
7651 options->tls_crypt_file = p[1];
7652 options->tls_crypt_file_inline = is_inline;
7653 }
7654 else if (permission_mask & OPT_P_CONNECTION)
7655 {
7656 options->ce.tls_crypt_file = p[1];
7657 options->ce.tls_crypt_file_inline = is_inline;
7658 }
7659 }
7660 else if (streq(p[0], "tls-crypt-v2") && p[1] && !p[3])
7661 {
7663 if (permission_mask & OPT_P_GENERAL)
7664 {
7665 options->tls_crypt_v2_file = p[1];
7666 options->tls_crypt_v2_file_inline = is_inline;
7667 }
7668 else if (permission_mask & OPT_P_CONNECTION)
7669 {
7671 options->ce.tls_crypt_v2_file_inline = is_inline;
7672 }
7673
7674 if (p[2] && streq(p[2], "force-cookie"))
7675 {
7677 }
7678 else if (p[2] && streq(p[2], "allow-noncookie"))
7679 {
7681 }
7682 else if (p[2])
7683 {
7684 msg(msglevel, "Unsupported tls-crypt-v2 argument: %s", p[2]);
7685 }
7686 }
7687 else if (streq(p[0], "tls-crypt-v2-verify") && p[1] && !p[2])
7688 {
7691 }
7692 else if (streq(p[0], "tls-crypt-v2-max-age") && p[1])
7693 {
7695 if (!atoi_constrained(p[1], &options->tls_crypt_v2_max_age, "tls-crypt-v2-max-age", 1, INT_MAX, msglevel))
7696 {
7697 goto err;
7698 }
7699 }
7700 else if (streq(p[0], "x509-track") && p[1] && !p[2])
7701 {
7703 x509_track_add(&options->x509_track, p[1], msglevel, &options->gc);
7704 }
7705 else if (streq(p[0], "x509-username-field") && p[1])
7706 {
7708 for (size_t j = 1; j < MAX_PARMS && p[j] != NULL; ++j)
7709 {
7710 char *s = p[j];
7711
7712 if (strncmp("ext:", s, 4) == 0 && !x509_username_field_ext_supported(s + 4))
7713 {
7714 msg(msglevel, "Unsupported x509-username-field extension: %s", s);
7715 }
7716 options->x509_username_field[j - 1] = p[j];
7717 }
7718 }
7719#ifdef ENABLE_PKCS11
7720 else if (streq(p[0], "show-pkcs11-ids") && !p[3])
7721 {
7722 const char *provider = p[1];
7723 bool cert_private = (p[2] == NULL ? false : (atoi_warn(p[2], msglevel) != 0));
7724
7725#ifdef DEFAULT_PKCS11_MODULE
7726 if (!provider)
7727 {
7728 provider = DEFAULT_PKCS11_MODULE;
7729 }
7730 else if (!p[2])
7731 {
7732 char *endp = NULL;
7733 long i = strtol(provider, &endp, 10);
7734
7735 if (*endp == 0)
7736 {
7737 /* There was one argument, and it was purely numeric.
7738 * Interpret it as the cert_private argument */
7739 provider = DEFAULT_PKCS11_MODULE;
7740 cert_private = i;
7741 }
7742 }
7743#else /* ifdef DEFAULT_PKCS11_MODULE */
7744 if (!provider)
7745 {
7746 msg(msglevel, "--show-pkcs11-ids requires a provider parameter");
7747 goto err;
7748 }
7749#endif /* ifdef DEFAULT_PKCS11_MODULE */
7751
7753 show_pkcs11_ids(provider, cert_private);
7754 openvpn_exit(OPENVPN_EXIT_STATUS_GOOD); /* exit point */
7755 }
7756 else if (streq(p[0], "pkcs11-providers") && p[1])
7757 {
7758 int j;
7759
7761
7762 for (j = 1; j < MAX_PARMS && p[j] != NULL; ++j)
7763 {
7764 options->pkcs11_providers[j - 1] = p[j];
7765 }
7766 }
7767 else if (streq(p[0], "pkcs11-protected-authentication"))
7768 {
7769 int j;
7770
7772
7773 for (j = 1; j < MAX_PARMS && p[j] != NULL; ++j)
7774 {
7775 options->pkcs11_protected_authentication[j - 1] =
7776 atoi_warn(p[j], msglevel) != 0 ? 1 : 0;
7777 }
7778 }
7779 else if (streq(p[0], "pkcs11-private-mode") && p[1])
7780 {
7781 int j;
7782
7784
7785 for (j = 1; j < MAX_PARMS && p[j] != NULL; ++j)
7786 {
7787 sscanf(p[j], "%x", &(options->pkcs11_private_mode[j - 1]));
7788 }
7789 }
7790 else if (streq(p[0], "pkcs11-cert-private"))
7791 {
7792 int j;
7793
7795
7796 for (j = 1; j < MAX_PARMS && p[j] != NULL; ++j)
7797 {
7798 options->pkcs11_cert_private[j - 1] = (bool)(atoi_warn(p[j], msglevel));
7799 }
7800 }
7801 else if (streq(p[0], "pkcs11-pin-cache") && p[1] && !p[2])
7802 {
7804 options->pkcs11_pin_cache_period = positive_atoi(p[1], msglevel);
7805 }
7806 else if (streq(p[0], "pkcs11-id") && p[1] && !p[2])
7807 {
7809 options->pkcs11_id = p[1];
7810 }
7811 else if (streq(p[0], "pkcs11-id-management") && !p[1])
7812 {
7814 options->pkcs11_id_management = true;
7815 }
7816#endif /* ifdef ENABLE_PKCS11 */
7817 else if (streq(p[0], "rmtun") && !p[1])
7818 {
7820 options->persist_config = true;
7821 options->persist_mode = 0;
7822 }
7823 else if (streq(p[0], "mktun") && !p[1])
7824 {
7826 options->persist_config = true;
7827 options->persist_mode = 1;
7828 }
7829 else if (streq(p[0], "peer-id") && p[1] && !p[2])
7830 {
7832 options->use_peer_id = true;
7833 options->peer_id = atoi_warn(p[1], msglevel);
7834 }
7835 else if (streq(p[0], "keying-material-exporter") && p[1] && p[2])
7836 {
7838
7839 if (strncmp(p[1], "EXPORTER", 8))
7840 {
7841 msg(msglevel, "Keying material exporter label must begin with "
7842 "\"EXPORTER\"");
7843 goto err;
7844 }
7845 if (streq(p[1], EXPORT_KEY_DATA_LABEL))
7846 {
7847 msg(msglevel,
7848 "Keying material exporter label must not be '" EXPORT_KEY_DATA_LABEL "'.");
7849 }
7850
7852 p[0], 16, 4095, msglevel))
7853 {
7854 goto err;
7855 }
7856
7858 }
7859 else if (streq(p[0], "allow-recursive-routing") && !p[1])
7860 {
7863 }
7864 else if (streq(p[0], "vlan-tagging") && !p[1])
7865 {
7867 options->vlan_tagging = true;
7868 }
7869 else if (streq(p[0], "vlan-accept") && p[1] && !p[2])
7870 {
7872 if (streq(p[1], "tagged"))
7873 {
7875 }
7876 else if (streq(p[1], "untagged"))
7877 {
7879 }
7880 else if (streq(p[1], "all"))
7881 {
7883 }
7884 else
7885 {
7886 msg(msglevel, "--vlan-accept must be 'tagged', 'untagged' or 'all'");
7887 goto err;
7888 }
7889 }
7890 else if (streq(p[0], "vlan-pvid") && p[1] && !p[2])
7891 {
7892 int vlan_pvid;
7894 if (!atoi_constrained(p[1], &vlan_pvid, p[0],
7896 {
7897 goto err;
7898 }
7899 options->vlan_pvid = (uint16_t)vlan_pvid;
7900 }
7901 else
7902 {
7903 int i;
7904 msglvl_t msglevel_unknown = msglevel_fc;
7905 /* Check if an option is in --ignore-unknown-option and
7906 * set warning level to non fatal */
7908 {
7909 if (streq(p[0], options->ignore_unknown_option[i]))
7910 {
7911 msglevel_unknown = M_WARN;
7912 break;
7913 }
7914 }
7915 if (file)
7916 {
7917 msg(msglevel_unknown,
7918 "Unrecognized option or missing or extra parameter(s) in %s:%d: %s (%s)", file,
7919 line, p[0], PACKAGE_VERSION);
7920 }
7921 else
7922 {
7923 msg(msglevel_unknown, "Unrecognized option or missing or extra parameter(s): --%s (%s)",
7924 p[0], PACKAGE_VERSION);
7925 }
7926 }
7927err:
7928 gc_free(&gc);
7929}
7930
7931#if defined(__GNUC__) || defined(__clang__)
7932#pragma GCC diagnostic pop
7933#endif
7934
7935bool
7937{
7938 if (options->ce.local_list)
7939 {
7940 for (int i = 0; i < options->ce.local_list->len; i++)
7941 {
7943 {
7944 return true;
7945 }
7946 }
7947 }
7948
7949 return false;
7950}
void buf_clear(struct buffer *buf)
Zeroise and reset a buffer.
Definition buffer.c:148
bool buf_printf(struct buffer *buf, const char *format,...)
printf-style append to a buffer with overflow check.
Definition buffer.c:226
void gc_transfer(struct gc_arena *dest, struct gc_arena *src)
Move all allocations from one garbage collection arena to another.
Definition buffer.c:429
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:343
bool string_defined_equal(const char *s1, const char *s2)
Definition buffer.c:1089
void * gc_malloc(size_t size, bool clear, struct gc_arena *a)
Allocate memory and, optionally, zero it.
Definition buffer.c:318
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:661
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:1356
char * string_substitute(const char *src, char from, char to, struct gc_arena *gc)
Definition buffer.c:1102
char * string_alloc(const char *str, struct gc_arena *gc)
Duplicate a string, allocating memory under garbage collection.
Definition buffer.c:616
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:1949
#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:2067
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:1934
#define ALLOC_OBJ_CLEAR_GC(dptr, type, gc)
Allocate and zero-initialise a garbage-collected object of the given type.
Definition buffer.h:2134
#define ALLOC_OBJ_GC(dptr, type, gc)
Allocate a garbage-collected object of the given type (uninitialised).
Definition buffer.h:2122
static void gc_free(struct gc_arena *a)
Free all allocations in a garbage collection arena.
Definition buffer.h:1976
static struct gc_arena gc_new(void)
Allocate and return a new, empty garbage collection arena.
Definition buffer.h:1960
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:101
struct client_nat_option_list * new_client_nat_list(struct gc_arena *gc)
Definition clinat.c:70
struct client_nat_option_list * clone_client_nat_option_list(const struct client_nat_option_list *src, struct gc_arena *gc)
Definition clinat.c:78
void copy_client_nat_option_list(struct client_nat_option_list *dest, const struct client_nat_option_list *src)
Definition clinat.c:87
#define TLS_CHANNEL_BUF_SIZE
Definition common.h:70
#define TLS_CHANNEL_MTU_MIN
Definition common.h:83
bool check_compression_settings_valid(struct compress_options *info, msglvl_t msglevel)
Checks if the compression settings are valid.
Definition comp.c:162
#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:1630
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:1911
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:359
#define CO_USE_DYNAMIC_TLS_CRYPT
Bit-flag indicating that renegotiations are using tls-crypt with a TLS-EKM derived key.
Definition crypto.h:375
#define CO_EPOCH_DATA_KEY_FORMAT
Bit-flag indicating the epoch the data format.
Definition crypto.h:379
#define KEY_DIRECTION_BIDIRECTIONAL
Definition crypto.h:231
#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:371
@ 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:212
void dns_options_postprocess_pull(struct dns_options *o)
Merges pulled DNS servers with static ones into an ordered list.
Definition dns.c:289
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:62
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:148
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:190
bool dns_server_priority_parse(long *priority, const char *str, bool pulled)
Parses a string DNS server priority and validates it.
Definition dns.c:175
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:266
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:282
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:82
#define D_TLS_DEBUG_MED
Definition errlevel.h:156
#define D_DCO
Definition errlevel.h:93
#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:601
void helper_client_server(struct options *o)
Definition helper.c:157
void helper_keepalive(struct options *o)
Definition helper.c:540
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
static int tls_verify(struct openvpn_plugin_args_func_in const *args)
void management_auth_token(const char *token)
Definition manage.c:3224
void management_echo(struct management *man, const char *string, const bool pull)
Definition manage.c:3145
#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:261
#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:83
static int net_ctx_init(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:444
void redirect_stdout_stderr(const char *file, bool append)
Definition error.c:493
void openvpn_exit(const int status)
Definition error.c:709
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:552
#define RESET_OPTION_ROUTES(option_ptr, field)
Definition options.c:3669
static void rol6_check_alloc(struct options *options)
Definition options.c:1312
static void options_postprocess_verify_ce(const struct options *options, const struct connection_entry *ce)
Definition options.c:1614
#define NM_QUOTE_HINT
Definition options.c:3636
static void options_postprocess_mutate_ce(struct options *o, struct connection_entry *ce)
Definition options.c:2275
static void usage_version(void)
Definition options.c:3525
static in_addr_t get_ip_addr(const char *ip_string, msglvl_t msglevel, bool *error)
Definition options.c:1048
static struct pull_filter * alloc_pull_filter(struct options *o)
Definition options.c:1518
#define USAGE_VALID_SERVER_PROTOS
static void pre_connect_save(struct options *o)
Definition options.c:2466
static void setenv_connection_entry(struct env_set *es, const struct connection_entry *e, const int i)
Definition options.c:926
static int global_auth_retry
Definition options.c:3404
bool options_postprocess_pull(struct options *o, struct env_set *es)
Definition options.c:3337
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:3677
void uninit_options(struct options *o)
Definition options.c:910
static void connection_entry_load_re(struct connection_entry *ce, const struct remote_entry *re)
Definition options.c:1539
int parse_topology(const char *str, const msglvl_t msglevel)
Definition options.c:3357
void show_windows_version(const unsigned int flags)
Definition options.c:3492
#define VERIFY_PERMISSION(mask)
Definition options.c:3576
bool key_is_external(const struct options *options)
Definition options.c:4165
static void check_ca_required(const struct options *options)
Definition options.c:1576
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:1332
void init_options(struct options *o)
Definition options.c:808
static void tuntap_options_postprocess_dns(struct options *o)
Postprocess DNS related settings.
Definition options.c:2850
static void dhcp_option_dns6_parse(const char *parm, struct in6_addr *dns6_list, unsigned int *len, msglvl_t msglevel)
Definition options.c:1198
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:1073
static void option_iroute_ipv6(struct options *o, const char *prefix_str, msglvl_t msglevel)
Definition options.c:1266
static bool check_route_option(struct options *options, char *p[], const msglvl_t msglevel, bool pull_mode)
Definition options.c:3839
void show_dco_version(const unsigned int flags)
Definition options.c:3501
void rol_check_alloc(struct options *options)
Definition options.c:1303
static struct local_list * alloc_local_list_if_undef(struct connection_entry *ce, struct gc_arena *gc)
Definition options.c:1395
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:1212
static void helper_hashmap_sizes(struct options *o)
Sets the internal hash maps sizes according to the max_clients.
Definition options.c:3110
static void set_user_script(struct options *options, const char **script, const char *new_script, const char *type, bool in_chroot)
Definition options.c:4126
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:3997
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, struct options *options, bool is_inline)
Definition options.c:3586
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:1159
#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:3639
static void options_postprocess_mutate_le(struct connection_entry *ce, struct local_entry *le, int mode)
Definition options.c:2432
void options_postprocess(struct options *options, struct env_set *es)
Definition options.c:3323
void usage_small(void)
Definition options.c:3484
const char * auth_retry_print(void)
Definition options.c:3436
static struct remote_entry * alloc_remote_entry(struct options *options, const msglvl_t msglevel)
Definition options.c:1482
void show_library_versions(const unsigned int flags)
Definition options.c:3511
void setenv_settings(struct env_set *es, const struct options *o)
Definition options.c:952
static const char usage_message[]
Definition options.c:130
static struct connection_list * alloc_connection_list_if_undef(struct options *options)
Definition options.c:1436
static void cnol_check_alloc(struct options *options)
Definition options.c:1321
static void options_postprocess_mutate(struct options *o, struct env_set *es)
Definition options.c:3123
void options_detach(struct options *o)
Definition options.c:1283
static unsigned int atou(const char *str)
Definition options.c:3568
void pre_connect_restore(struct options *o, struct gc_arena *gc)
Definition options.c:2511
static struct pull_filter_list * alloc_pull_filter_list(struct options *o)
Definition options.c:1508
const char * print_topology(const int topology)
Definition options.c:3379
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:1106
static bool check_dns_option(struct options *options, char *p[], const msglvl_t msglevel, bool pull_mode)
Definition options.c:3888
static void options_postprocess_cipher(struct options *o)
Definition options.c:2684
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:2754
#define MUST_BE_FALSE(condition, parm_name)
Definition options.c:1607
#define MUST_BE_UNDEF(parm, parm_name)
Definition options.c:1602
static void options_postprocess_http_proxy_override(struct options *o)
Definition options.c:1360
static void options_postprocess_mutate_invariant(struct options *options)
Definition options.c:2584
static bool ipv6_addr_safe_hexplusbits(const char *ipv6_prefix_spec)
Definition options.c:1091
const char title_string[]
Definition options.c:73
static void setenv_local_entry(struct env_set *es, const struct local_entry *e, const int i)
Definition options.c:944
static void remap_redirect_gateway_flags(struct options *opt)
Definition options.c:2450
static msglvl_t msglevel_forward_compatible(struct options *options, const msglvl_t msglevel)
Definition options.c:3664
bool auth_retry_set(const msglvl_t msglevel, const char *option)
Definition options.c:3413
int auth_retry_get(void)
Definition options.c:3407
static struct remote_list * alloc_remote_list_if_undef(struct options *options)
Definition options.c:1472
static bool check_route6_option(struct options *options, char *p[], const msglvl_t msglevel, bool pull_mode)
Definition options.c:3867
void notnull(const char *arg, const char *description)
Definition options.c:3550
void usage(void)
Definition options.c:3458
static struct local_entry * alloc_local_entry(struct connection_entry *ce, const msglvl_t msglevel, struct gc_arena *gc)
Definition options.c:1405
static void show_compression_warning(struct compress_options *info)
Definition options.c:4153
static void options_process_mutate_prf(struct options *o)
Definition options.c:2822
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:4184
bool has_udp_in_local_list(const struct options *options)
Definition options.c:7936
static void option_iroute(struct options *o, const char *network_str, const char *netmask_str, msglvl_t msglevel)
Definition options.c:1239
static void options_postprocess_verify(const struct options *o)
Definition options.c:2647
static void connection_entry_preload_key(const char **key_file, bool *key_inline, struct gc_arena *gc)
Definition options.c:1560
static struct connection_entry * alloc_connection_entry(struct options *options, const msglvl_t msglevel)
Definition options.c:1446
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:2744
#define MODE_POINT_TO_POINT
Definition options.h:264
#define OPT_P_SCRIPT
Definition options.h:735
#define PUF_TYPE_ACCEPT
filter type to accept a matching option
Definition options.h:800
#define OPT_P_PUSH
Definition options.h:747
#define SF_TCP_NODELAY_HELPER
Definition options.h:475
#define OPT_P_UP
Definition options.h:732
#define OPT_P_CONNECTION
Definition options.h:758
#define OPT_P_INSTANCE
allowed in ccd, client-connect etc
Definition options.h:748
#define OPT_P_NCP
Negotiable crypto parameters.
Definition options.h:743
#define OPT_P_ECHO
Definition options.h:751
#define OPT_P_ROUTE_TABLE
Definition options.h:762
#define OPT_P_CONFIG
Definition options.h:749
#define MODE_SERVER
Definition options.h:265
#define CONNECTION_LIST_SIZE
Definition options.h:192
#define streq(x, y)
Definition options.h:726
#define OPT_P_U_REDIR_GATEWAY
Definition options.h:795
#define OPT_P_EXPLICIT_NOTIFY
Definition options.h:750
#define PUF_TYPE_IGNORE
filter type to ignore a matching option
Definition options.h:801
#define AR_INTERACT
Definition options.h:950
#define OPT_P_SHAPER
Definition options.h:737
#define OPT_P_U_ROUTE6
Definition options.h:792
static bool dco_enabled(const struct options *o)
Returns whether the current configuration has dco enabled.
Definition options.h:971
#define OPT_P_SOCKFLAGS
Definition options.h:757
#define SF_NOPOOL
Definition options.h:474
#define PUF_TYPE_REJECT
filter type to reject and trigger SIGUSR1
Definition options.h:802
#define OPT_P_MESSAGES
Definition options.h:742
#define OPT_P_SETENV
Definition options.h:736
#define OPT_P_SOCKBUF
Definition options.h:756
#define OPT_P_PLUGIN
Definition options.h:755
#define OPTION_PARM_SIZE
Definition options.h:56
#define OPT_P_TIMER
Definition options.h:738
#define OPT_P_GENERAL
Definition options.h:731
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:734
#define OPT_P_PULL_MODE
Definition options.h:754
@ 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:761
#define AR_NONE
Definition options.h:949
#define AR_NOINTERACT
Definition options.h:951
#define SF_NO_PUSH_ROUTE_GATEWAY
Definition options.h:476
#define OPT_P_PERSIST
Definition options.h:739
#define MAX_PARMS
Definition options.h:51
#define OPT_P_U_DNS
Definition options.h:793
#define PLUGIN_OPTION_LIST(opt)
Definition options.h:777
#define ROUTE_OPTION_FLAGS(o)
Definition options.h:769
#define OPT_P_U_ROUTE
Definition options.h:791
#define PING_EXIT
Definition options.h:355
static void show_debug_warning(const unsigned int flags)
Definition options.h:892
#define OPT_P_COMP
Definition options.h:741
#define OPT_P_PERSIST_IP
Definition options.h:740
#define OPT_P_MTU
Definition options.h:745
#define OPT_P_ROUTE_EXTRAS
Definition options.h:753
#define OPT_P_U_DHCP
Definition options.h:794
#define OPT_P_NICE
Definition options.h:746
#define OPT_P_PEER_ID
Definition options.h:759
#define OPT_P_INHERIT
Definition options.h:752
#define OPT_P_TLS_PARMS
Definition options.h:744
#define OPT_P_ROUTE
Definition options.h:733
#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:783
#define CE_DISABLED
Definition options.h:155
#define OPT_P_INLINE
Definition options.h:760
@ VLAN_ONLY_UNTAGGED_OR_PRIORITY
Definition options.h:227
@ VLAN_ALL
Definition options.h:228
@ VLAN_ONLY_TAGGED
Definition options.h:226
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:333
int platform_chdir(const char *dir)
Definition platform.c:392
const char * platform_get_tmp_dir(void)
Get a directory for temporary files.
Definition platform.c:586
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:117
#define OPENVPN_8021Q_MIN_VID
Definition proto.h:316
#define OPENVPN_8021Q_MAX_VID
Definition proto.h:317
#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:943
void push_options(struct options *o, char **p, msglvl_t msglevel, struct gc_arena *gc)
Definition push.c:917
void clone_push_list(struct options *o)
Definition push.c:902
void push_remove_option(struct options *o, const char *p)
Definition push.c:949
bool is_special_addr(const char *addr_str)
Definition route.c:288
struct route_option_list * clone_route_option_list(const struct route_option_list *src, struct gc_arena *a)
Definition route.c:155
int netmask_to_netbits2(in_addr_t netmask)
Definition route.c:3853
struct route_ipv6_option_list * new_route_ipv6_option_list(struct gc_arena *a)
Definition route.c:139
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:1185
void get_default_gateway_ipv6(struct route_ipv6_gateway_info *rgi6, const struct in6_addr *dest, openvpn_net_ctx_t *ctx)
Definition route.c:2628
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:496
void copy_route_option_list(struct route_option_list *dest, const struct route_option_list *src, struct gc_arena *a)
Definition route.c:173
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:181
void print_default_gateway(const msglvl_t msglevel, const struct route_gateway_info *rgi, const struct route_ipv6_gateway_info *rgi6)
Definition route.c:1241
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:2531
struct route_ipv6_option_list * clone_route_ipv6_option_list(const struct route_ipv6_option_list *src, struct gc_arena *a)
Definition route.c:164
struct route_option_list * new_route_option_list(struct gc_arena *a)
Definition route.c:130
void show_routes(msglvl_t msglevel)
Definition route.c:3029
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:1163
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:481
#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
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 socket.c:222
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 socket.c:195
#define RESOLV_RETRY_INFINITE
Definition socket.h:48
#define OPENVPN_PORT
Definition socket.h:42
#define SF_USE_IP_PKTINFO
Definition socket.h:210
#define SF_HOST_RANDOMIZE
Definition socket.h:213
#define SF_PKTINFO_COPY_IIF
Definition socket.h:217
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.
#define GETADDR_FATAL
@ PROTO_NONE
@ PROTO_UDP
@ PROTO_TCP
@ PROTO_TCP_CLIENT
@ PROTO_TCP_SERVER
#define GETADDR_HOST_ORDER
static bool proto_is_dgram(int proto)
Return if the protocol is datagram (UDP)
#define GETADDR_RESOLVE
#define IA_NET_ORDER
Definition socket_util.h:90
void ssl_set_auth_token_user(const char *username)
Definition ssl.c:375
void ssl_set_auth_nocache(void)
Definition ssl.c:350
static bool push_peer_info(struct buffer *buf, struct tls_multi *multi, struct tls_session *session)
Prepares the IV_ and UV_ variables that are part of the exchange to signal the peer's capabilities.
Definition ssl.c:1958
int tls_version_parse(const char *vstr, const char *extra)
Definition ssl.c:434
void ssl_set_auth_token(const char *token)
Definition ssl.c:369
bool ssl_get_auth_nocache(void)
Definition ssl.c:360
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:431
#define SSLF_CLIENT_CERT_OPTIONAL
Definition ssl_common.h:424
#define SSLF_AUTH_USER_PASS_OPTIONAL
Definition ssl_common.h:426
#define SSLF_CLIENT_CERT_NOT_REQUIRED
Definition ssl_common.h:423
#define SSLF_CRL_VERIFY_DIR
Definition ssl_common.h:428
#define SSLF_TLS_DEBUG_ENABLED
Definition ssl_common.h:433
#define SSLF_TLS_VERSION_MAX_MASK
Definition ssl_common.h:432
#define SSLF_TLS_VERSION_MIN_SHIFT
Definition ssl_common.h:429
#define SSLF_TLS_VERSION_MIN_MASK
Definition ssl_common.h:430
#define SSLF_USERNAME_AS_COMMON_NAME
Definition ssl_common.h:425
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:585
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:178
struct route_ipv6_list * route_ipv6_list
Definition openvpn.h:183
struct tuntap * tuntap
Tun/tap virtual network interface.
Definition openvpn.h:173
Contains all state information for one tunnel.
Definition openvpn.h:471
openvpn_net_ctx_t net_ctx
Networking API opaque context.
Definition openvpn.h:498
struct options options
Options loaded from command line or configuration file.
Definition openvpn.h:472
struct context_1 c1
Level 1 context.
Definition openvpn.h:515
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
struct http_proxy_options * http_proxy_override
Definition options.h:313
int push_ifconfig_ipv6_netbits
Definition options.h:523
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:536
const char * ncp_ciphers_conf
The original ncp_ciphers specified by the user in the configuration.
Definition options.h:579
int status_file_version
Definition options.h:407
enum vlan_acceptable_frames vlan_accept
Definition options.h:713
int auth_token_renewal
Definition options.h:545
in_addr_t push_ifconfig_constraint_network
Definition options.h:518
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:563
int route_default_metric
Definition options.h:429
int renegotiate_seconds_min
Definition options.h:647
const char * auth_token_secret_file
Definition options.h:546
unsigned int imported_protocol_flags
Definition options.h:723
const char * tls_export_peer_cert_dir
Definition options.h:612
bool crl_file_inline
Definition options.h:616
const char * cryptoapi_cert
Definition options.h:638
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:622
int scheduled_exit_interval
Definition options.h:565
int stale_routes_ageing_time
Definition options.h:538
bool pkcs12_file_inline
Definition options.h:605
int replay_time
Definition options.h:586
int management_state_buffer_size
Definition options.h:451
const char * ca_file
Definition options.h:593
const char * tls_auth_file
Definition options.h:660
struct provider_list providers
Definition options.h:583
bool duplicate_cn
Definition options.h:527
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:624
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:619
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:625
bool route_noexec
Definition options.h:430
bool ifconfig_nowarn
Definition options.h:333
const char * remote_cert_eku
Definition options.h:620
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:641
bool test_crypto
Definition options.h:588
bool up_delay
Definition options.h:389
bool server_bridge_proxy_dhcp
Definition options.h:479
bool allow_recursive_routing
Definition options.h:720
const char * authname
Definition options.h:581
const char * exit_event_name
Definition options.h:692
const char * ifconfig_ipv6_local
Definition options.h:329
int cf_max
Definition options.h:529
bool dh_file_inline
Definition options.h:597
int replay_window
Definition options.h:585
bool disable
Definition options.h:507
int mute
Definition options.h:400
bool auth_user_pass_verify_script_via_file
Definition options.h:541
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
bool show_digests
Definition options.h:283
const char * up_script
Definition options.h:385
uint64_t push_option_types_found
Definition options.h:558
bool single_session
Definition options.h:679
bool push_ifconfig_defined
Definition options.h:513
bool ifconfig_pool_defined
Definition options.h:488
int verify_hash_depth
Definition options.h:623
bool route_delay_defined
Definition options.h:433
const char * packet_id_file
Definition options.h:587
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:712
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:535
bool block_outside_dns
Definition options.h:696
bool push_ifconfig_ipv6_blocked
Definition options.h:525
bool tls_exit
Definition options.h:683
const char * pkcs12_file
Definition options.h:604
const char * client_disconnect_script
Definition options.h:502
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:584
const char * tls_crypt_file
Definition options.h:664
int inactivity_timeout
Definition options.h:345
int n_bcast_buf
Definition options.h:509
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
struct iroute_ipv6 * iroutes_ipv6
Definition options.h:512
struct push_list push_list
Definition options.h:487
bool user_script_used
Definition options.h:387
const char * tls_groups
Definition options.h:608
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:621
const char * tls_cert_profile
Definition options.h:609
int64_t renegotiate_packets
Definition options.h:645
unsigned int management_flags
Definition options.h:459
int push_continuation
Definition options.h:557
const char * route_default_gateway
Definition options.h:426
in_addr_t push_ifconfig_local_alias
Definition options.h:516
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:568
bool auth_token_call_auth
Definition options.h:543
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:580
bool genkey
Definition options.h:287
uint32_t virtual_hash_size
Definition options.h:500
const char * learn_address_script
Definition options.h:503
const char * ciphername
Definition options.h:575
const char * auth_user_pass_file
Definition options.h:560
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:532
int stale_routes_check_interval
Definition options.h:537
struct plugin_option_list * plugin_list
Definition options.h:462
int auth_token_lifetime
Definition options.h:544
uint16_t vlan_pvid
Definition options.h:714
int ns_cert_type
Definition options.h:618
const char * tls_crypt_v2_verify_script
Definition options.h:674
int mode
Definition options.h:266
bool tls_server
Definition options.h:591
const char * auth_user_pass_verify_script
Definition options.h:540
int connect_retry_max
Definition options.h:293
char * bind_dev
Definition options.h:418
const char * extra_certs_file
Definition options.h:600
bool client
Definition options.h:555
bool pull
Definition options.h:556
int ifconfig_ipv6_pool_netbits
Definition options.h:497
in_addr_t push_ifconfig_constraint_netmask
Definition options.h:519
bool show_curves
Definition options.h:286
const char * route_ipv6_default_gateway
Definition options.h:427
bool tls_client
Definition options.h:592
bool ping_timer_remote
Definition options.h:352
bool auth_token_generate
Definition options.h:542
bool priv_key_file_inline
Definition options.h:603
const char * tls_verify
Definition options.h:611
const char * crl_file
Definition options.h:615
int ping_rec_timeout_action
Definition options.h:357
bool auth_user_pass_file_inline
Definition options.h:561
bool show_ciphers
Definition options.h:282
bool enable_ncp_fallback
If defined fall back to ciphername if NCP fails.
Definition options.h:576
const char * route_predown_script
Definition options.h:425
const char * dh_file
Definition options.h:596
int route_delay_window
Definition options.h:432
in_addr_t push_ifconfig_local
Definition options.h:514
bool mlock
Definition options.h:340
const char ** ignore_unknown_option
Definition options.h:275
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:594
bool auth_token_secret_file_inline
Definition options.h:547
bool block_ipv6
Definition options.h:436
const char * config
Definition options.h:261
bool extra_certs_file_inline
Definition options.h:601
bool push_ifconfig_constraint_defined
Definition options.h:517
int mark
Definition options.h:417
int cf_initial_per
Definition options.h:533
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:511
int verify_x509_type
Definition options.h:613
const char * cipher_list_tls13
Definition options.h:607
const char * ecdh_curve
Definition options.h:610
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:606
bool ccd_exclusive
Definition options.h:506
bool allow_deprecated_insecure_static_crypto
Definition options.h:573
struct pull_filter_list * pull_filter_list
Definition options.h:716
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:562
bool log
Definition options.h:395
bool shared_secret_file_inline
Definition options.h:572
struct in6_addr push_ifconfig_ipv6_remote
Definition options.h:524
const char * ca_path
Definition options.h:595
int renegotiate_seconds
Definition options.h:646
int ping_rec_timeout
Definition options.h:351
unsigned int sockflags
Definition options.h:421
const char * engine
Definition options.h:582
const char * management_addr
Definition options.h:446
const char * client_connect_script
Definition options.h:501
const char * verify_x509_name
Definition options.h:614
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:521
int tcp_queue_limit
Definition options.h:510
int route_delay
Definition options.h:431
const char * dev_node
Definition options.h:324
const char * override_username
Definition options.h:508
const char * client_crresponse_script
Definition options.h:504
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:574
bool server_ipv6_defined
Definition options.h:470
const char * priv_key_file
Definition options.h:602
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:522
int nice
Definition options.h:398
uint64_t push_update_options_found
Definition options.h:559
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:598
bool enable_c2c
Definition options.h:526
in_addr_t server_bridge_pool_end
Definition options.h:485
int cf_per
Definition options.h:530
enum tun_driver_type windows_driver
Definition options.h:697
bool cert_file_inline
Definition options.h:599
int remap_sigusr1
Definition options.h:393
int64_t renegotiate_bytes
Definition options.h:644
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:515
bool occ
Definition options.h:443
in_addr_t server_bridge_ip
Definition options.h:482
const char * shared_secret_file
Definition options.h:571
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:505
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:812
struct pull_filter * head
Definition options.h:811
struct pull_filter * next
Definition options.h:806
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
unsigned int flags
Definition route.h:97
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:409
#define SIGTERM
Definition syshead.h:59
#define sleep(x)
Definition syshead.h:42
uint32_t in_addr_t
Definition syshead.h:52
static bool pkcs11_id_management
struct gc_arena gc
Definition test_ssl.c:122
void ipconfig_register_dns(const struct env_set *es)
Definition tun.c:4876
int dev_type_enum(const char *dev, const char *dev_type)
Definition tun.c:521
void show_tap_win_adapters(msglvl_t msglevel, msglvl_t warnlevel)
Definition tun.c:3805
bool dhcp_renew_by_adapter_index(const DWORD adapter_index)
Definition tun.c:4809
int ascii2ipset(const char *name)
Definition tun.c:6233
bool dhcp_release_by_adapter_index(const DWORD adapter_index)
Definition tun.c:4768
void tap_allow_nonadmin_access(const char *dev_node)
Definition tun.c:4688
void show_adapters(msglvl_t msglevel)
Definition tun.c:4639
const char * ipset2ascii_all(struct gc_arena *gc)
Definition tun.c:6262
void show_valid_win32_tun_subnets(void)
Definition tun.c:3772
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:1164
const char * win32_version_string(struct gc_arena *gc)
Get Windows version string with architecture info.
Definition win32.c:1410
void set_pause_exit_win32(void)
Definition win32.c:147