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
67#include <ctype.h>
68
69#include "memdbg.h"
70#include "options_util.h"
71
72const char title_string[] = PACKAGE_STRING
73#ifdef CONFIGURE_GIT_REVISION
74 " [git:" CONFIGURE_GIT_REVISION CONFIGURE_GIT_FLAGS "]"
75#endif
76 " " TARGET_ALIAS
77#if defined(ENABLE_CRYPTO_MBEDTLS)
78 " [SSL (mbed TLS)]"
79#elif defined(ENABLE_CRYPTO_OPENSSL)
80 " [SSL (OpenSSL)]"
81#else
82 " [SSL]"
83#endif /* defined(ENABLE_CRYPTO_MBEDTLS) */
84#ifdef USE_COMP
85#ifdef ENABLE_LZO
86 " [LZO]"
87#endif
88#ifdef ENABLE_LZ4
89 " [LZ4]"
90#endif
91#ifdef ENABLE_COMP_STUB
92 " [COMP_STUB]"
93#endif
94#endif /* USE_COMP */
95#if EPOLL
96 " [EPOLL]"
97#endif
98#ifdef PRODUCT_TAP_DEBUG
99 " [TAPDBG]"
100#endif
101#ifdef ENABLE_PKCS11
102 " [PKCS11]"
103#endif
104#if ENABLE_IP_PKTINFO
105#if defined(HAVE_IN_PKTINFO) && defined(HAVE_IPI_SPEC_DST)
106 " [MH/PKTINFO]"
107#elif defined(IP_RECVDSTADDR)
108 " [MH/RECVDA]"
109#endif
110#endif
111 " [AEAD]"
112#ifdef ENABLE_DCO
113 " [DCO]"
114#endif
115#ifdef CONFIGURE_GIT_REVISION
116 " built on " __DATE__
117#endif
118 ;
119
120#ifndef ENABLE_SMALL
121
122static const char usage_message[] =
123 "%s\n"
124 "\n"
125 "General Options:\n"
126 "--config file : Read configuration options from file.\n"
127 "--help : Show options.\n"
128 "--version : Show copyright and version information.\n"
129 "\n"
130 "Tunnel Options:\n"
131 "--local host|* [port]: Local host name or IP address and port for bind.\n"
132 " If specified, OpenVPN will bindto this address. If unspecified,\n"
133 " OpenVPN will bind to all interfaces. '*' can be used as hostname\n"
134 " and means 'any host' (OpenVPN will listen on what is returned by the OS).\n"
135 " On a client, or in point-to-point mode, this can only be specified once (1 socket).\n"
136 " On an OpenVPN setup running as ``--server``, this can be specified multiple times\n"
137 " to open multiple listening sockets on different addresses and/or different ports.\n"
138 " In order to specify multiple listen ports without specifying an address, use '*'\n"
139 " to signal 'use what the operating system gives you as default', for\n"
140 " 'all IPv4 addresses' use '0.0.0.0', for 'all IPv6 addresses' use '::'.\n"
141 " ``--local`` implies ``--bind``.\n"
142 "--remote host [port] : Remote host name or ip address.\n"
143 "--remote-random : If multiple --remote options specified, choose one randomly.\n"
144 "--remote-random-hostname : Add a random string to remote DNS name.\n"
145 "--mode m : Major mode, m = 'p2p' (default, point-to-point) or 'server'.\n"
146 "--proto p : Use protocol p for communicating with peer.\n"
147 " p = udp (default), tcp-server, tcp-client\n"
148 " udp4, tcp4-server, tcp4-client\n"
149 " udp6, tcp6-server, tcp6-client\n"
150 "--proto-force p : only consider protocol p in list of connection profiles.\n"
151 " p = udp or tcp\n"
152 "--connect-retry n [m] : For client, number of seconds to wait between\n"
153 " connection retries (default=%d). On repeated retries\n"
154 " the wait time is exponentially increased to a maximum of m\n"
155 " (default=%d).\n"
156 "--connect-retry-max n : Maximum connection attempt retries, default infinite.\n"
157 "--http-proxy s p [up] [auth] : Connect to remote host\n"
158 " through an HTTP proxy at address s and port p.\n"
159 " If proxy authentication is required,\n"
160 " up is a file containing username/password on 2 lines, or\n"
161 " 'stdin' to prompt from console. Add auth='ntlm2' if\n"
162 " the proxy requires NTLM authentication.\n"
163 "--http-proxy s p 'auto[-nct]' : Like the above directive, but automatically\n"
164 " determine auth method and query for username/password\n"
165 " if needed. auto-nct disables weak proxy auth methods.\n"
166 "--http-proxy-option type [parm] : Set extended HTTP proxy options.\n"
167 " Repeat to set multiple options.\n"
168 " VERSION version (default=1.0)\n"
169 " AGENT user-agent\n"
170 "--socks-proxy s [p] [up] : Connect to remote host through a Socks5 proxy at\n"
171 " address s and port p (default port = 1080).\n"
172 " If proxy authentication is required,\n"
173 " up is a file containing username/password on 2 lines, or\n"
174 " 'stdin' to prompt for console.\n"
175 "--socks-proxy-retry : Retry indefinitely on Socks proxy errors.\n"
176 "--resolv-retry n: If hostname resolve fails for --remote, retry\n"
177 " resolve for n seconds before failing (disabled by default).\n"
178 " Set n=\"infinite\" to retry indefinitely.\n"
179 "--float : Allow remote to change its IP address/port, such as through\n"
180 " DHCP (this is the default if --remote is not used).\n"
181 "--ipchange cmd : Run command cmd on remote ip address initial\n"
182 " setting or change -- execute as: cmd ip-address port#\n"
183 "--port port : TCP/UDP port # for both local and remote.\n"
184 "--lport port : TCP/UDP port # for local (default=%s). Implies --bind.\n"
185 "--rport port : TCP/UDP port # for remote (default=%s).\n"
186 "--bind : Bind to local address and port. (This is the default unless\n"
187 " --proto tcp-client"
188 " or --http-proxy"
189 " or --socks-proxy"
190 " is used).\n"
191 "--nobind : Do not bind to local address and port.\n"
192 "--dev tunX|tapX : tun/tap device (X can be omitted for dynamic device.\n"
193 "--dev-type dt : Which device type are we using? (dt = tun or tap) Use\n"
194 " this option only if the tun/tap device used with --dev\n"
195 " does not begin with \"tun\" or \"tap\".\n"
196 "--dev-node node : Explicitly set the device node rather than using\n"
197 " /dev/net/tun, /dev/tun, /dev/tap, etc.\n"
198#if defined(ENABLE_DCO)
199 "--disable-dco : Do not attempt using Data Channel Offload.\n"
200#endif
201 "--lladdr hw : Set the link layer address of the tap device.\n"
202 "--topology t : Set --dev tun topology: 'net30', 'p2p', or 'subnet'.\n"
203#ifdef ENABLE_IPROUTE
204 "--iproute cmd : Use this command instead of default " IPROUTE_PATH ".\n"
205#endif
206 "--ifconfig l rn : TUN: configure device to use IP address l as a local\n"
207 " endpoint and rn as a remote endpoint. l & rn should be\n"
208 " swapped on the other peer. l & rn must be private\n"
209 " addresses outside of the subnets used by either peer.\n"
210 " TAP: configure device to use IP address l as a local\n"
211 " endpoint and rn as a subnet mask.\n"
212 "--ifconfig-ipv6 l r : configure device to use IPv6 address l as local\n"
213 " endpoint (as a /64) and r as remote endpoint\n"
214 "--ifconfig-noexec : Don't actually execute ifconfig/netsh command, instead\n"
215 " pass --ifconfig parms by environment to scripts.\n"
216 "--ifconfig-nowarn : Don't warn if the --ifconfig option on this side of the\n"
217 " connection doesn't match the remote side.\n"
218#ifdef TARGET_LINUX
219 "--route-table table_id : Specify a custom routing table for use with --route(-ipv6).\n"
220 " If not specified, the id of the default routing table will be used.\n"
221#endif
222 "--route network [netmask] [gateway] [metric] :\n"
223 " Add route to routing table after connection\n"
224 " is established. Multiple routes can be specified.\n"
225 " netmask default: 255.255.255.255\n"
226 " gateway default: taken from --route-gateway or --ifconfig\n"
227 " Specify default by leaving blank or setting to \"default\".\n"
228 "--route-ipv6 network/bits [gateway] [metric] :\n"
229 " Add IPv6 route to routing table after connection\n"
230 " is established. Multiple routes can be specified.\n"
231 " gateway default: taken from --route-ipv6-gateway or 'remote'\n"
232 " in --ifconfig-ipv6\n"
233 "--route-gateway gw|'dhcp' : Specify a default gateway for use with --route.\n"
234 "--route-ipv6-gateway gw : Specify a default gateway for use with --route-ipv6.\n"
235 "--route-metric m : Specify a default metric for use with --route.\n"
236 "--route-delay n [w] : Delay n seconds after connection initiation before\n"
237 " adding routes (may be 0). If not specified, routes will\n"
238 " be added immediately after tun/tap open. On Windows, wait\n"
239 " up to w seconds for TUN/TAP adapter to come up.\n"
240 "--route-up cmd : Run command cmd after routes are added.\n"
241 "--route-pre-down cmd : Run command cmd before routes are removed.\n"
242 "--route-noexec : Don't add routes automatically. Instead pass routes to\n"
243 " --route-up script using environmental variables.\n"
244 "--route-nopull : When used with --client or --pull, accept options pushed\n"
245 " by server EXCEPT for routes, dns, and dhcp options.\n"
246 "--allow-pull-fqdn : Allow client to pull DNS names from server for\n"
247 " --ifconfig, --route, and --route-gateway.\n"
248 "--redirect-gateway [flags]: Automatically execute routing\n"
249 " commands to redirect all outgoing IP traffic through the\n"
250 " VPN. Add 'local' flag if both " PACKAGE_NAME " servers are directly\n"
251 " connected via a common subnet, such as with WiFi.\n"
252 " Add 'def1' flag to set default route using using 0.0.0.0/1\n"
253 " and 128.0.0.0/1 rather than 0.0.0.0/0. Add 'bypass-dhcp'\n"
254 " flag to add a direct route to DHCP server, bypassing tunnel.\n"
255 " Add 'bypass-dns' flag to similarly bypass tunnel for DNS.\n"
256 "--redirect-private [flags]: Like --redirect-gateway, but omit actually changing\n"
257 " the default gateway. Useful when pushing private subnets.\n"
258 "--block-ipv6 : (Client) Instead sending IPv6 to the server generate\n"
259 " ICMPv6 host unreachable messages on the client.\n"
260 " (Server) Instead of forwarding IPv6 packets send\n"
261 " ICMPv6 host unreachable packets to the client.\n"
262 "--client-nat snat|dnat network netmask alias : on client add 1-to-1 NAT rule.\n"
263 "--push-peer-info : (client only) push client info to server.\n"
264 "--setenv name value : Set a custom environmental variable to pass to script.\n"
265 "--setenv FORWARD_COMPATIBLE 1 : Relax config file syntax checking to allow\n"
266 " directives for future OpenVPN versions to be ignored.\n"
267 "--ignore-unknown-option opt1 opt2 ...: Relax config file syntax. Allow\n"
268 " these options to be ignored when unknown\n"
269 "--script-security level: Where level can be:\n"
270 " 0 -- strictly no calling of external programs\n"
271 " 1 -- (default) only call built-ins such as ifconfig\n"
272 " 2 -- allow calling of built-ins and scripts\n"
273 " 3 -- allow password to be passed to scripts via env\n"
274 "--shaper n : Restrict output to peer to n bytes per second.\n"
275 "--keepalive n m : Helper option for setting timeouts in server mode. Send\n"
276 " ping once every n seconds, restart if ping not received\n"
277 " for m seconds.\n"
278 "--inactive n [bytes] : Exit after n seconds of activity on tun/tap device\n"
279 " produces a combined in/out byte count < bytes.\n"
280 "--session-timeout n: Limit connection time to n seconds.\n"
281 "--ping-exit n : Exit if n seconds pass without reception of remote ping.\n"
282 "--ping-restart n: Restart if n seconds pass without reception of remote ping.\n"
283 "--ping-timer-rem: Run the --ping-exit/--ping-restart timer only if we have a\n"
284 " remote address.\n"
285 "--ping n : Ping remote once every n seconds over TCP/UDP port.\n"
286#if ENABLE_IP_PKTINFO
287 "--multihome : Configure a multi-homed UDP server.\n"
288#endif
289 "--remap-usr1 s : On SIGUSR1 signals, remap signal (s='SIGHUP' or 'SIGTERM').\n"
290 "--persist-tun : Keep tun/tap device open across SIGUSR1 or --ping-restart.\n"
291 "--persist-remote-ip : Keep remote IP address across SIGUSR1 or --ping-restart.\n"
292 "--persist-local-ip : Keep local IP address across SIGUSR1 or --ping-restart.\n"
293#if PASSTOS_CAPABILITY
294 "--passtos : TOS passthrough (applies to IPv4 only).\n"
295#endif
296 "--tun-mtu n : Take the tun/tap device MTU to be n and derive the\n"
297 " TCP/UDP MTU from it (default=%d).\n"
298 "--tun-mtu-extra n : Assume that tun/tap device might return as many\n"
299 " as n bytes more than the tun-mtu size on read\n"
300 " (default TUN=0 TAP=%d).\n"
301 "--tun-mtu-max n : Maximum pushable MTU (default and minimum=%d).\n"
302 "--link-mtu n : Take the TCP/UDP device MTU to be n and derive the tun MTU\n"
303 " from it.\n"
304 "--mtu-disc type : Should we do Path MTU discovery on TCP/UDP channel?\n"
305 " 'no' -- Never send DF (Don't Fragment) frames\n"
306 " 'maybe' -- Use per-route hints\n"
307 " 'yes' -- Always DF (Don't Fragment)\n"
308 "--mtu-test : Empirically measure and report MTU.\n"
309#ifdef ENABLE_FRAGMENT
310 "--fragment max : Enable internal datagram fragmentation so that no UDP\n"
311 " datagrams are sent which are larger than max bytes.\n"
312 " Adds 4 bytes of overhead per datagram.\n"
313#endif
314 "--mssfix [n] : Set upper bound on TCP MSS, default = tun-mtu size\n"
315 " or --fragment max value, whichever is lower.\n"
316 "--sndbuf size : Set the TCP/UDP send buffer size.\n"
317 "--rcvbuf size : Set the TCP/UDP receive buffer size.\n"
318#if defined(TARGET_LINUX)
319 "--mark value : Mark encrypted packets being sent with value. The mark value\n"
320 " can be matched in policy routing and packetfilter rules.\n"
321 "--bind-dev dev : Bind to the given device when making connection to a peer or\n"
322 " listening for connections. This allows sending encrypted packets\n"
323 " via a VRF present on the system.\n"
324#endif
325 "--txqueuelen n : Set the tun/tap TX queue length to n (Linux only).\n"
326 "--mlock : Disable Paging -- ensures key material and tunnel\n"
327 " data will never be written to disk.\n"
328 "--up cmd : Run command cmd after successful tun device open.\n"
329 " Execute as: cmd tun/tap-dev tun-mtu link-mtu \\\n"
330 " ifconfig-local-ip ifconfig-remote-ip\n"
331 " (pre --user or --group UID/GID change)\n"
332 "--up-delay : Delay tun/tap open and possible --up script execution\n"
333 " until after TCP/UDP connection establishment with peer.\n"
334 "--down cmd : Run command cmd after tun device close.\n"
335 " (post --user/--group UID/GID change and/or --chroot)\n"
336 " (command parameters are same as --up option)\n"
337 "--down-pre : Run --down command before TUN/TAP close.\n"
338 "--up-restart : Run up/down commands for all restarts including those\n"
339 " caused by --ping-restart or SIGUSR1\n"
340 "--user user : Set UID to user after initialization.\n"
341 "--group group : Set GID to group after initialization.\n"
342 "--chroot dir : Chroot to this directory after initialization.\n"
343#ifdef ENABLE_SELINUX
344 "--setcon context: Apply this SELinux context after initialization.\n"
345#endif
346 "--cd dir : Change to this directory before initialization.\n"
347 "--daemon [name] : Become a daemon after initialization.\n"
348 " The optional 'name' parameter will be passed\n"
349 " as the program name to the system logger.\n"
350 "--syslog [name] : Output to syslog, but do not become a daemon.\n"
351 " See --daemon above for a description of the 'name' parm.\n"
352 "--log file : Output log to file which is created/truncated on open.\n"
353 "--log-append file : Append log to file, or create file if nonexistent.\n"
354 "--suppress-timestamps : Don't log timestamps to stdout/stderr.\n"
355 "--machine-readable-output : Always log timestamp, message flags to stdout/stderr.\n"
356 "--writepid file : Write main process ID to file.\n"
357 "--nice n : Change process priority (>0 = lower, <0 = higher).\n"
358 "--echo [parms ...] : Echo parameters to log output.\n"
359 "--verb n : Set output verbosity to n (default=%d):\n"
360 " (Level 3 is recommended if you want a good summary\n"
361 " of what's happening without being swamped by output).\n"
362 " : 0 -- no output except fatal errors\n"
363 " : 1 -- startup info + connection initiated messages +\n"
364 " non-fatal encryption & net errors\n"
365 " : 2,3 -- show TLS negotiations & route info\n"
366 " : 4 -- show parameters\n"
367 " : 5 -- show 'RrWw' chars on console for each packet sent\n"
368 " and received from TCP/UDP (caps) or tun/tap (lc)\n"
369 " : 6 to 11 -- debug messages of increasing verbosity\n"
370 "--mute n : Log at most n consecutive messages in the same category.\n"
371 "--status file [n] : Write operational status to file every n seconds.\n"
372 "--status-version [n] : Choose the status file format version number.\n"
373 " Currently, n can be 1, 2, or 3 (default=1).\n"
374 "--disable-occ : (DEPRECATED) Disable options consistency check between peers.\n"
375#ifdef ENABLE_DEBUG
376 "--gremlin mask : Special stress testing mode (for debugging only).\n"
377#endif
378#if defined(USE_COMP)
379 "--compress alg : Use compression algorithm alg\n"
380 "--allow-compression: Specify whether compression should be allowed\n"
381#if defined(ENABLE_LZO)
382 "--comp-lzo : Use LZO compression -- may add up to 1 byte per\n"
383 " packet for incompressible data.\n"
384 "--comp-noadapt : Don't use adaptive compression when --comp-lzo\n"
385 " is specified.\n"
386#endif
387#endif
388#ifdef ENABLE_MANAGEMENT
389 "--management ip port [pass] : Enable a TCP server on ip:port to handle\n"
390 " management functions. pass is a password file\n"
391 " or 'stdin' to prompt from console.\n"
392#if UNIX_SOCK_SUPPORT
393 " To listen on a unix domain socket, specific the pathname\n"
394 " in place of ip and use 'unix' as the port number.\n"
395#endif
396 "--management-client : Management interface will connect as a TCP client to\n"
397 " ip/port rather than listen as a TCP server.\n"
398 "--management-query-passwords : Query management channel for private key\n"
399 " and auth-user-pass passwords.\n"
400 "--management-query-proxy : Query management channel for proxy information.\n"
401 "--management-query-remote : Query management channel for --remote directive.\n"
402 "--management-hold : Start " PACKAGE_NAME " in a hibernating state, until a client\n"
403 " of the management interface explicitly starts it.\n"
404 "--management-signal : Issue SIGUSR1 when management disconnect event occurs.\n"
405 "--management-forget-disconnect : Forget passwords when management disconnect\n"
406 " event occurs.\n"
407 "--management-up-down : Report tunnel up/down events to management interface.\n"
408 "--management-log-cache n : Cache n lines of log file history for usage\n"
409 " by the management channel.\n"
410#if UNIX_SOCK_SUPPORT
411 "--management-client-user u : When management interface is a unix socket, only\n"
412 " allow connections from user u.\n"
413 "--management-client-group g : When management interface is a unix socket, only\n"
414 " allow connections from group g.\n"
415#endif
416 "--management-client-auth : gives management interface client the responsibility\n"
417 " to authenticate clients after their client certificate\n"
418 " has been verified.\n"
419#endif /* ifdef ENABLE_MANAGEMENT */
420#ifdef ENABLE_PLUGIN
421 "--plugin m [str]: Load plug-in module m passing str as an argument\n"
422 " to its initialization function.\n"
423#endif
424 "--vlan-tagging : Enable 802.1Q-based VLAN tagging.\n"
425 "--vlan-accept tagged|untagged|all : Set VLAN tagging mode. Default is 'all'.\n"
426 "--vlan-pvid v : Sets the Port VLAN Identifier. Defaults to 1.\n"
427 "\n"
428 "Multi-Client Server options (when --mode server is used):\n"
429 "--server network netmask : Helper option to easily configure server mode.\n"
430 "--server-ipv6 network/bits : Configure IPv6 server mode.\n"
431 "--server-bridge [IP netmask pool-start-IP pool-end-IP] : Helper option to\n"
432 " easily configure ethernet bridging server mode.\n"
433 "--push \"option\" : Push a config file option back to the peer for remote\n"
434 " execution. Peer must specify --pull in its config file.\n"
435 "--push-reset : Don't inherit global push list for specific\n"
436 " client instance.\n"
437 "--push-remove opt : Remove options matching 'opt' from the push list for\n"
438 " a specific client instance.\n"
439 "--ifconfig-pool start-IP end-IP [netmask] : Set aside a pool of subnets\n"
440 " to be dynamically allocated to connecting clients.\n"
441 "--ifconfig-pool-persist file [seconds] : Persist/unpersist ifconfig-pool\n"
442 " data to file, at seconds intervals (default=600).\n"
443 " If seconds=0, file will be treated as read-only.\n"
444 "--ifconfig-ipv6-pool base-IP/bits : set aside an IPv6 network block\n"
445 " to be dynamically allocated to connecting clients.\n"
446 "--ifconfig-push local remote-netmask : Push an ifconfig option to remote,\n"
447 " overrides --ifconfig-pool dynamic allocation.\n"
448 " Only valid in a client-specific config file.\n"
449 "--ifconfig-ipv6-push local/bits remote : Push an ifconfig-ipv6 option to\n"
450 " remote, overrides --ifconfig-ipv6-pool allocation.\n"
451 " Only valid in a client-specific config file.\n"
452 "--iroute network [netmask] : Route subnet to client.\n"
453 "--iroute-ipv6 network/bits : Route IPv6 subnet to client.\n"
454 " Sets up internal routes only.\n"
455 " Only valid in a client-specific config file.\n"
456 "--disable : Client is disabled.\n"
457 " Only valid in a client-specific config file.\n"
458 "--override-username: Overrides the client-specific username to be used.\n"
459 " Only valid in a client-specific config file.\n"
460 "--verify-client-cert [none|optional|require] : perform no, optional or\n"
461 " mandatory client certificate verification.\n"
462 " Default is to require the client to supply a certificate.\n"
463 "--username-as-common-name : For auth-user-pass authentication, use\n"
464 " the authenticated username as the common name,\n"
465 " rather than the common name from the client cert.\n"
466 "--auth-user-pass-verify cmd method: Query client for username/password and\n"
467 " run command cmd to verify. If method='via-env', pass\n"
468 " user/pass via environment, if method='via-file', pass\n"
469 " user/pass via temporary file.\n"
470 "--auth-gen-token [lifetime] Generate a random authentication token which is pushed\n"
471 " to each client, replacing the password. Useful when\n"
472 " OTP based two-factor auth mechanisms are in use and\n"
473 " --reneg-* options are enabled. Optionally a lifetime in seconds\n"
474 " for generated tokens can be set.\n"
475 "--auth-user-pass-optional : Allow connections by clients that don't\n"
476 " specify a username/password.\n"
477 "--client-to-client : Internally route client-to-client traffic.\n"
478 "--duplicate-cn : Allow multiple clients with the same common name to\n"
479 " concurrently connect.\n"
480 "--client-connect cmd : Run command cmd on client connection.\n"
481 "--client-disconnect cmd : Run command cmd on client disconnection.\n"
482 "--client-config-dir dir : Directory for custom client config files.\n"
483 "--ccd-exclusive : Refuse connection unless custom client config is found.\n"
484 "--tmp-dir dir : Temporary directory, used for --client-connect return file and plugin communication.\n"
485 "--hash-size r v : Set the size of the real address hash table to r and the\n"
486 " virtual address table to v.\n"
487 "--bcast-buffers n : Allocate n broadcast buffers.\n"
488 "--tcp-queue-limit n : Maximum number of queued TCP output packets.\n"
489 "--tcp-nodelay : Macro that sets TCP_NODELAY socket flag on the server\n"
490 " as well as pushes it to connecting clients.\n"
491 "--learn-address cmd : Run command cmd to validate client virtual addresses.\n"
492 "--connect-freq n s : Allow a maximum of n new connections per s seconds.\n"
493 "--connect-freq-initial n s : Allow a maximum of n replies for initial connections attempts per s seconds.\n"
494 "--max-clients n : Allow a maximum of n simultaneously connected clients.\n"
495 "--max-routes-per-client n : Allow a maximum of n internal routes per client.\n"
496 "--stale-routes-check n [t] : Remove routes with a last activity timestamp\n"
497 " older than n seconds. Run this check every t\n"
498 " seconds (defaults to n).\n"
499 "--explicit-exit-notify [n] : In UDP server mode send [RESTART] command on exit/restart to connected\n"
500 " clients. n = 1 - reconnect to same server,\n"
501 " 2 - advance to next server, default=1.\n"
502#if PORT_SHARE
503 "--port-share host port [dir] : When run in TCP mode, proxy incoming HTTPS\n"
504 " sessions to a web server at host:port. dir specifies an\n"
505 " optional directory to write origin IP:port data.\n"
506#endif
507 "\n"
508 "Client options (when connecting to a multi-client server):\n"
509 "--client : Helper option to easily configure client mode.\n"
510 "--auth-user-pass [up] : Authenticate with server using username/password.\n"
511 " up is a file containing the username on the first line,\n"
512 " and a password on the second. If either the password or both\n"
513 " the username and the password are omitted OpenVPN will prompt\n"
514 " for them from console.\n"
515 "--pull : Accept certain config file options from the peer as if they\n"
516 " were part of the local config file. Must be specified\n"
517 " when connecting to a '--mode server' remote host.\n"
518 "--pull-filter accept|ignore|reject t : Filter each option received from the\n"
519 " server if it starts with the text t. The action flag accept,\n"
520 " ignore or reject causes the option to be allowed, removed or\n"
521 " rejected with error. May be specified multiple times, and\n"
522 " each filter is applied in the order of appearance.\n"
523 "--dns server <n> <option> <value> [value ...] : Configure option for DNS server #n\n"
524 " Valid options are :\n"
525 " address <addr[:port]> [addr[:port] ...] : server addresses 4/6\n"
526 " resolve-domains <domain> [domain ...] : split domains\n"
527 " dnssec <yes|no|optional> : option to use DNSSEC\n"
528 " transport <DoH|DoT> : query server over HTTPS / TLS\n"
529 " sni <domain> : DNS server name indication\n"
530 "--dns search-domains <domain> [domain ...]:\n"
531 " Add domains to DNS domain search list\n"
532 "--dns-updown cmd|force|disable : Run cmd as user defined dns config command,\n"
533 " force running the default script or disable running it.\n"
534 "--auth-retry t : How to handle auth failures. Set t to\n"
535 " none (default), interact, or nointeract.\n"
536 "--static-challenge t e [<scrv1|concat>]: Enable static challenge/response protocol using\n"
537 " challenge text t, with e indicating echo flag (0|1)\n"
538 " and optional argument scrv1 or concat to use SCRV1 protocol or"
539 " concatenate response with password. Default is scrv1.\n"
540 "--connect-timeout n : when polling possible remote servers to connect to\n"
541 " in a round-robin fashion, spend no more than n seconds\n"
542 " waiting for a response before trying the next server.\n"
543 "--allow-recursive-routing : When this option is set, OpenVPN will not drop\n"
544 " incoming tun packets with same destination as host.\n"
545 "--explicit-exit-notify [n] : On exit/restart, send exit signal to\n"
546 " server/remote. n = # of retries, default=1.\n"
547 "\n"
548 "Data Channel Encryption Options (must be compatible between peers):\n"
549 "(These options are meaningful for both Static Key & TLS-mode)\n"
550 "--auth alg : Authenticate packets with HMAC using message\n"
551 " digest algorithm alg (default=%s).\n"
552 " (usually adds 16 or 20 bytes per packet)\n"
553 " Set alg=none to disable authentication.\n"
554 "--cipher alg : Encrypt packets with cipher algorithm alg.\n"
555 " You should usually use --data-ciphers instead.\n"
556 " Set alg=none to disable encryption.\n"
557 "--data-ciphers list : List of ciphers that are allowed to be negotiated.\n"
558#ifndef ENABLE_CRYPTO_MBEDTLS
559 "--engine [name] : Enable OpenSSL hardware crypto engine functionality.\n"
560#endif
561 "--mute-replay-warnings : Silence the output of replay warnings to log file.\n"
562 "--replay-window n [t] : Use a replay protection sliding window of size n\n"
563 " and a time window of t seconds.\n"
564 " Default n=%d t=%d\n"
565 "--replay-persist file : Persist replay-protection state across sessions\n"
566 " using file.\n"
567 "--test-crypto : Run a self-test of crypto features enabled.\n"
568 " For debugging only.\n"
569#ifdef ENABLE_PREDICTION_RESISTANCE
570 "--use-prediction-resistance: Enable prediction resistance on the random\n"
571 " number generator.\n"
572#endif
573 "\n"
574 "TLS Key Negotiation Options:\n"
575 "(These options are meaningful only for TLS-mode)\n"
576 "--tls-server : Enable TLS and assume server role during TLS handshake.\n"
577 "--tls-client : Enable TLS and assume client role during TLS handshake.\n"
578 "--ca file : Certificate authority file in .pem format containing\n"
579 " root certificate.\n"
580#ifndef ENABLE_CRYPTO_MBEDTLS
581 "--capath dir : A directory of trusted certificates (CAs"
582 " and CRLs).\n"
583#endif /* ENABLE_CRYPTO_MBEDTLS */
584 "--dh file : File containing Diffie Hellman parameters\n"
585 " in .pem format (for --tls-server only).\n"
586 " Use \"openssl dhparam -out dh1024.pem 1024\" to generate.\n"
587 "--cert file : Local certificate in .pem format or a URI -- must be signed\n"
588 " by a Certificate Authority in --ca file used by the peer.\n"
589 "--extra-certs file : one or more PEM certs that complete the cert chain.\n"
590 "--key file : Local private key in .pem format or a URI.\n"
591 "--tls-version-min <version> ['or-highest'] : sets the minimum TLS version we\n"
592 " will accept from the peer. If version is unrecognized and 'or-highest'\n"
593 " is specified, require max TLS version supported by SSL implementation.\n"
594 "--tls-version-max <version> : sets the maximum TLS version we will use.\n"
595#ifndef ENABLE_CRYPTO_MBEDTLS
596 "--pkcs12 file : PKCS#12 file containing local private key, local certificate\n"
597 " and optionally the root CA certificate.\n"
598 "--x509-username-field : Field in x509 certificate containing the username.\n"
599 " Default is CN in the Subject field.\n"
600#endif
601 "--verify-hash hash [algo] : Specify fingerprint for level-1 certificate.\n"
602 " Valid algo flags are SHA1 and SHA256. \n"
603#ifdef _WIN32
604 "--cryptoapicert select-string : Load the certificate and private key from the\n"
605 " Windows Certificate System Store.\n"
606#endif
607 "--tls-cipher l : A list l of allowable TLS ciphers separated by : (optional).\n"
608 "--tls-ciphersuites l: A list of allowed TLS 1.3 cipher suites separated by : (optional)\n"
609 " : Use --show-tls to see a list of supported TLS ciphers (suites).\n"
610 "--tls-cert-profile p : Set the allowed certificate crypto algorithm profile\n"
611 " (default=legacy).\n"
612 "--providers l : A list l of OpenSSL providers to load.\n"
613 "--tls-timeout n : Packet retransmit timeout on TLS control channel\n"
614 " if no ACK from remote within n seconds (default=%d).\n"
615 "--reneg-bytes n : Renegotiate data chan. key after n bytes sent and recvd.\n"
616 "--reneg-pkts n : Renegotiate data chan. key after n packets sent and recvd.\n"
617 "--reneg-sec max [min] : Renegotiate data chan. key after at most max (default=%d)\n"
618 " and at least min (defaults to 90%% of max on servers and equal\n"
619 " to max on clients).\n"
620 "--hand-window n : Data channel key exchange must finalize within n seconds\n"
621 " of handshake initiation by any peer (default=%d).\n"
622 "--tran-window n : Transition window -- old key can live this many seconds\n"
623 " after new key renegotiation begins (default=%d).\n"
624 "--single-session: Allow only one session (reset state on restart).\n"
625 "--tls-exit : Exit on TLS negotiation failure.\n"
626 "--tls-auth f [d]: Add an additional layer of authentication on top of the TLS\n"
627 " control channel to protect against attacks on the TLS stack\n"
628 " and DoS attacks.\n"
629 " f (required) is a shared-secret key file.\n"
630 " The optional d parameter controls key directionality.\n"
631 "--tls-crypt key : Add an additional layer of authenticated encryption on top\n"
632 " of the TLS control channel to hide the TLS certificate,\n"
633 " provide basic post-quantum security and protect against\n"
634 " attacks on the TLS stack and DoS attacks.\n"
635 " key (required) provides the pre-shared key file.\n"
636 "--tls-crypt-v2 key : For clients: use key as a client-specific tls-crypt key.\n"
637 " For servers: use key to decrypt client-specific keys. For\n"
638 " key generation (--genkey tls-crypt-v2-client): use key to\n"
639 " encrypt generated client-specific key. (See --tls-crypt.)\n"
640 "--genkey tls-crypt-v2-client [keyfile] [base64 metadata]: Generate a\n"
641 " fresh tls-crypt-v2 client key, and store to\n"
642 " keyfile. If supplied, include metadata in wrapped key.\n"
643 "--genkey tls-crypt-v2-server [keyfile] [base64 metadata]: Generate a\n"
644 " fresh tls-crypt-v2 server key, and store to keyfile\n"
645 "--tls-crypt-v2-verify cmd : Run command cmd to verify the metadata of the\n"
646 " client-supplied tls-crypt-v2 client key\n"
647 "--tls-crypt-v2-max-age n : Only accept tls-crypt-v2 client keys that have a\n"
648 " timestamp which is at most n days old.\n"
649 "--askpass [file]: Get PEM password from controlling tty before we daemonize.\n"
650 "--auth-nocache : Don't cache --askpass or --auth-user-pass passwords.\n"
651 "--crl-verify crl ['dir']: Check peer certificate against a CRL.\n"
652 "--tls-verify cmd: Run command cmd to verify the X509 name of a\n"
653 " pending TLS connection that has otherwise passed all other\n"
654 " tests of certification. cmd should return 0 to allow\n"
655 " TLS handshake to proceed, or 1 to fail. (cmd is\n"
656 " executed as 'cmd certificate_depth subject')\n"
657 "--verify-x509-name name: Accept connections only from a host with X509 subject\n"
658 " DN name. The remote host must also pass all other tests\n"
659 " of verification.\n"
660#ifndef ENABLE_CRYPTO_MBEDTLS
661 "--ns-cert-type t: (DEPRECATED) Require that peer certificate was signed with \n"
662 " an explicit nsCertType designation t = 'client' | 'server'.\n"
663#endif
664 "--x509-track x : Save peer X509 attribute x in environment for use by\n"
665 " plugins and management interface.\n"
666 "--keying-material-exporter label len : Save Exported Keying Material (RFC5705)\n"
667 " of len bytes (min. 16 bytes) using label in environment for use by plugins.\n"
668 "--remote-cert-ku v ... : Require that the peer certificate was signed with\n"
669 " explicit key usage, you can specify more than one value.\n"
670 " value should be given in hex format.\n"
671 "--remote-cert-eku oid : Require that the peer certificate was signed with\n"
672 " explicit extended key usage. Extended key usage can be encoded\n"
673 " as an object identifier or OpenSSL string representation.\n"
674 "--remote-cert-tls t: Require that peer certificate was signed with explicit\n"
675 " key usage and extended key usage based on RFC3280 TLS rules.\n"
676 " t = 'client' | 'server'.\n"
677#ifdef ENABLE_PKCS11
678 "\n"
679 "PKCS#11 Options:\n"
680 "--pkcs11-providers provider ... : PKCS#11 provider to load.\n"
681 "--pkcs11-protected-authentication [0|1] ... : Use PKCS#11 protected authentication\n"
682 " path. Set for each provider.\n"
683 "--pkcs11-private-mode hex ... : PKCS#11 private key mode mask.\n"
684 " 0 : Try to determine automatically (default).\n"
685 " 1 : Use Sign.\n"
686 " 2 : Use SignRecover.\n"
687 " 4 : Use Decrypt.\n"
688 " 8 : Use Unwrap.\n"
689 "--pkcs11-cert-private [0|1] ... : Set if login should be performed before\n"
690 " certificate can be accessed. Set for each provider.\n"
691 "--pkcs11-pin-cache seconds : Number of seconds to cache PIN. The default is -1\n"
692 " cache until token is removed.\n"
693 "--pkcs11-id-management : Acquire identity from management interface.\n"
694 "--pkcs11-id serialized-id 'id' : Identity to use, get using standalone --show-pkcs11-ids\n"
695#endif /* ENABLE_PKCS11 */
696 "\n"
697 "SSL Library information:\n"
698 "--show-ciphers : Show cipher algorithms to use with --cipher option.\n"
699 "--show-digests : Show message digest algorithms to use with --auth option.\n"
700 "--show-engines : Show hardware crypto accelerator engines (if available).\n"
701 "--show-tls : Show all TLS ciphers (TLS used only as a control channel).\n"
702#ifdef _WIN32
703 "\n"
704 "Windows Specific:\n"
705 "--win-sys path : Pathname of Windows system directory. Default is the pathname\n"
706 " from SystemRoot environment variable.\n"
707 "--ip-win32 method : When using --ifconfig on Windows, set TAP-Windows adapter\n"
708 " IP address using method = manual, netsh, ipapi,\n"
709 " dynamic, or adaptive (default = adaptive).\n"
710 " Dynamic method allows two optional parameters:\n"
711 " offset: DHCP server address offset (> -256 and < 256).\n"
712 " If 0, use network address, if >0, take nth\n"
713 " address forward from network address, if <0,\n"
714 " take nth address backward from broadcast\n"
715 " address.\n"
716 " Default is 0.\n"
717 " lease-time: Lease time in seconds.\n"
718 " Default is one year.\n"
719 "--route-method : Which method to use for adding routes on Windows?\n"
720 " adaptive (default) -- Try ipapi then fall back to exe.\n"
721 " ipapi -- Use IP helper API.\n"
722 " exe -- Call the route.exe shell command.\n"
723 "--dhcp-option type [parm] : Set extended TAP-Windows properties, must\n"
724 " be used with --ip-win32 dynamic. For options\n"
725 " which allow multiple addresses,\n"
726 " --dhcp-option must be repeated.\n"
727 " DOMAIN name : Set DNS suffix\n"
728 " DOMAIN-SEARCH entry : Add entry to DNS domain search list\n"
729 " DNS addr : Set domain name server address(es) (IPv4 and IPv6)\n"
730 " NTP : Set NTP server address(es)\n"
731 " NBDD : Set NBDD server address(es)\n"
732 " WINS addr : Set WINS server address(es)\n"
733 " NBT type : Set NetBIOS over TCP/IP Node type\n"
734 " 1: B, 2: P, 4: M, 8: H\n"
735 " NBS id : Set NetBIOS scope ID\n"
736 " DISABLE-NBT : Disable Netbios-over-TCP/IP.\n"
737 "--dhcp-renew : Ask Windows to renew the TAP adapter lease on startup.\n"
738 "--dhcp-pre-release : Ask Windows to release the previous TAP adapter lease on\n"
739 " startup.\n"
740 "--register-dns : Run ipconfig /flushdns and ipconfig /registerdns\n"
741 " on connection initiation.\n"
742 "--tap-sleep n : Sleep for n seconds after TAP adapter open before\n"
743 " attempting to set adapter properties.\n"
744 "--pause-exit : When run from a console window, pause before exiting.\n"
745 "--service ex [0|1] : For use when " PACKAGE_NAME " is being instantiated by a\n"
746 " service, and should not be used directly by end-users.\n"
747 " ex is the name of an event object which, when\n"
748 " signaled, will cause " PACKAGE_NAME " to exit. A second\n"
749 " optional parameter controls the initial state of ex.\n"
750 "--show-net-up : Show " PACKAGE_NAME "'s view of routing table and net adapter list\n"
751 " after TAP adapter is up and routes have been added.\n"
752 "--block-outside-dns : Block DNS on other network adapters to prevent DNS leaks\n"
753 "Windows Standalone Options:\n"
754 "\n"
755 "--show-adapters : Show all TAP-Windows adapters.\n"
756 "--show-net : Show " PACKAGE_NAME "'s view of routing table and net adapter list.\n"
757 "--show-valid-subnets : Show valid subnets for --dev tun emulation.\n"
758 "--allow-nonadmin [TAP-adapter] : Allow " PACKAGE_NAME " running without admin privileges\n"
759 " to access TAP adapter.\n"
760#endif /* ifdef _WIN32 */
761 "\n"
762 "Generate a new key :\n"
763 "--genkey tls-auth file : Generate a new random key of type and write to file\n"
764 " (for use with --tls-auth or --tls-crypt)."
765#ifdef ENABLE_FEATURE_TUN_PERSIST
766 "\n"
767 "Tun/tap config mode:\n"
768 "--mktun : Create a persistent tunnel.\n"
769 "--rmtun : Remove a persistent tunnel.\n"
770 "--dev tunX|tapX : tun/tap device\n"
771 "--dev-type dt : Device type. See tunnel options above for details.\n"
772 "--user user : User to set privilege to.\n"
773 "--group group : Group to set privilege to.\n"
774#endif
775#ifdef ENABLE_PKCS11
776 "\n"
777 "PKCS#11 standalone options:\n"
778#ifdef DEFAULT_PKCS11_MODULE
779 "--show-pkcs11-ids [provider] [cert_private] : Show PKCS#11 available ids.\n"
780#else
781 "--show-pkcs11-ids provider [cert_private] : Show PKCS#11 available ids.\n"
782#endif
783 " --verb option can be added *BEFORE* this.\n"
784#endif /* ENABLE_PKCS11 */
785 "\n"
786 "General Standalone Options:\n"
787#ifdef ENABLE_DEBUG
788 "--show-gateway [address]: Show info about gateway [to v4/v6 address].\n"
789#endif
790 ;
791
792#endif /* !ENABLE_SMALL */
793
794/*
795 * This is where the options defaults go.
796 * Any option not explicitly set here
797 * will be set to 0.
798 */
799void
800init_options(struct options *o, const bool init_gc)
801{
802 CLEAR(*o);
803 if (init_gc)
804 {
805 gc_init(&o->gc);
807 o->gc_owned = true;
808 }
810 o->topology = TOP_UNDEF;
811 o->ce.proto = PROTO_UDP;
812 o->ce.af = AF_UNSPEC;
813 o->ce.bind_ipv6_only = false;
816 o->ce.connect_timeout = 120;
817 o->connect_retry_max = 0;
819 o->verbosity = 1;
821 o->status_file_version = 1;
822 o->ce.bind_local = true;
824 o->ce.occ_mtu = 0;
827 o->ce.mtu_discover_type = -1;
828 o->ce.mssfix = 0;
829 o->ce.mssfix_default = true;
830 o->ce.mssfix_encap = true;
832 o->route_delay_window = 30;
834 o->resolve_in_advance = false;
835 o->proto_force = -1;
836 o->occ = true;
837#ifdef ENABLE_MANAGEMENT
841#endif
842#ifdef ENABLE_FEATURE_TUN_PERSIST
843 o->persist_mode = 1;
844#endif
845#ifdef _WIN32
846#if 0
848#else
850#endif
851 o->tuntap_options.dhcp_lease_time = 31536000; /* one year */
852 /* use network address as internal DHCP server address */
855 o->block_outside_dns = false;
857#endif
859 o->vlan_pvid = 1;
860 o->real_hash_size = 256;
861 o->virtual_hash_size = 256;
862 o->n_bcast_buf = 256;
863 o->tcp_queue_limit = 64;
864 o->max_clients = 1024;
865 o->cf_initial_per = 10;
866 o->cf_initial_max = 100;
867 o->max_routes_per_client = 256;
871 o->authname = "SHA1";
875#ifdef ENABLE_PREDICTION_RESISTANCE
876 o->use_prediction_resistance = false;
877#endif
878 o->tls_timeout = 2;
879 o->renegotiate_bytes = -1;
880 o->renegotiate_seconds = 3600;
882 o->handshake_window = 60;
883 o->transition_window = 3600;
884 o->tls_cert_profile = NULL;
885 o->ecdh_curve = NULL;
887#ifdef ENABLE_PKCS11
888 o->pkcs11_pin_cache_period = -1;
889#endif /* ENABLE_PKCS11 */
890
891 /* P2MP server context features */
892 o->auth_token_generate = false;
893
894 /* Set default --tmp-dir */
895#ifdef _WIN32
896 /* On Windows, find temp dir via environment variables */
898
899 if (!o->tmp_dir)
900 {
901 /* Error out if we can't find a valid temporary directory, which should
902 * be very unlikely. */
903 msg(M_USAGE, "Could not find a suitable temporary directory."
904 " (GetTempPath() failed). Consider using --tmp-dir");
905 }
906#else /* ifdef _WIN32 */
907 /* Non-windows platforms use $TMPDIR, and if not set, default to '/tmp' */
908 o->tmp_dir = getenv("TMPDIR");
909 if (!o->tmp_dir)
910 {
911 o->tmp_dir = "/tmp";
912 }
913#endif /* _WIN32 */
914 o->allow_recursive_routing = false;
915
916#ifndef ENABLE_DCO
917 o->disable_dco = true;
918#endif /* ENABLE_DCO */
919
920#ifdef ENABLE_DNS_UPDOWN_BY_DEFAULT
921 o->dns_options.updown = DEFAULT_DNS_UPDOWN;
922#endif /* ENABLE_DNS_UPDOWN_BY_DEFAULT */
923}
924
925void
927{
928 if (o->connection_list)
929 {
931 }
932 if (o->remote_list)
933 {
934 CLEAR(*o->remote_list);
935 }
936 if (o->gc_owned)
937 {
938 gc_free(&o->gc);
940 }
941}
942
943#ifndef ENABLE_SMALL
944
945static const char *
947{
948 if (type == PUF_TYPE_ACCEPT)
949 {
950 return "accept";
951 }
952 if (type == PUF_TYPE_IGNORE)
953 {
954 return "ignore";
955 }
956 if (type == PUF_TYPE_REJECT)
957 {
958 return "reject";
959 }
960 else
961 {
962 return "???";
963 }
964}
965
966#define SHOW_PARM(name, value, format) msg(D_SHOW_PARMS, " " #name " = " format, (value))
967#define SHOW_STR(var) SHOW_PARM(var, (o->var ? o->var : "[UNDEF]"), "'%s'")
968#define SHOW_STR_INLINE(var) \
969 SHOW_PARM(var, o->var##_inline ? "[INLINE]" : (o->var ? o->var : "[UNDEF]"), "'%s'")
970#define SHOW_INT(var) SHOW_PARM(var, o->var, "%d")
971#define SHOW_UINT(var) SHOW_PARM(var, o->var, "%u")
972#define SHOW_INT64(var) SHOW_PARM(var, o->var, "%" PRIi64)
973#define SHOW_UNSIGNED(var) SHOW_PARM(var, o->var, "0x%08x")
974#define SHOW_BOOL(var) SHOW_PARM(var, (o->var ? "ENABLED" : "DISABLED"), "%s");
975
976#endif /* ifndef ENABLE_SMALL */
977
978static void
979setenv_connection_entry(struct env_set *es, const struct connection_entry *e, const int i)
980{
981 setenv_str_i(es, "remote", e->remote, i);
982 setenv_str_i(es, "remote_port", e->remote_port, i);
983
984 if (e->http_proxy_options)
985 {
986 setenv_str_i(es, "http_proxy_server", e->http_proxy_options->server, i);
987 setenv_str_i(es, "http_proxy_port", e->http_proxy_options->port, i);
988 }
989 if (e->socks_proxy_server)
990 {
991 setenv_str_i(es, "socks_proxy_server", e->socks_proxy_server, i);
992 setenv_str_i(es, "socks_proxy_port", e->socks_proxy_port, i);
993 }
994}
995
996static void
997setenv_local_entry(struct env_set *es, const struct local_entry *e, const int i)
998{
999 setenv_str_i(es, "proto", proto2ascii(e->proto, AF_UNSPEC, false), i);
1000 setenv_str_i(es, "local", e->local, i);
1001 setenv_str_i(es, "local_port", e->port, i);
1002}
1003
1004void
1005setenv_settings(struct env_set *es, const struct options *o)
1006{
1007 setenv_str(es, "config", o->config);
1008 setenv_int(es, "verb", o->verbosity);
1009 setenv_int(es, "daemon", o->daemon);
1010 setenv_int(es, "daemon_log_redirect", o->log);
1011 setenv_long_long(es, "daemon_start_time", time(NULL));
1012 setenv_int(es, "daemon_pid", platform_getpid());
1013
1014 if (o->connection_list)
1015 {
1016 int i;
1017 for (i = 0; i < o->connection_list->len; ++i)
1018 {
1020 }
1021 }
1022 else
1023 {
1024 setenv_connection_entry(es, &o->ce, 1);
1025 }
1026
1027 if (o->ce.local_list)
1028 {
1029 for (int i = 0; i < o->ce.local_list->len; i++)
1030 {
1031 setenv_local_entry(es, o->ce.local_list->array[i], i + 1);
1032 }
1033 }
1034}
1035
1036#ifndef _WIN32
1037static void
1038setenv_foreign_option(struct options *o, const char *option, const char *value, struct env_set *es)
1039{
1040 struct gc_arena gc = gc_new();
1043 bool good = true;
1044
1045 good &= buf_printf(&env_name, "foreign_option_%d", o->foreign_option_index + 1);
1046 if (value)
1047 {
1048 good &= buf_printf(&env_value, "dhcp-option %s %s", option, value);
1049 }
1050 else
1051 {
1052 good &= buf_printf(&env_value, "dhcp-option %s", option);
1053 }
1054 if (good)
1055 {
1057 ++o->foreign_option_index;
1058 }
1059 else
1060 {
1061 msg(M_WARN, "foreign_option: name/value overflow");
1062 }
1063 gc_free(&gc);
1064}
1065
1066static void
1067delete_all_dhcp_fo(struct options *o, struct env_item **list)
1068{
1069 struct env_item *current, *prev;
1070
1071 ASSERT(list);
1072
1073 for (current = *list, prev = NULL; current != NULL; current = current->next)
1074 {
1075 char *tmp_value = NULL;
1076 if (!strncmp(current->string, "foreign_option_", sizeof("foreign_option_") - 1))
1077 {
1078 tmp_value = strchr(current->string, '=');
1079 if (tmp_value && ++tmp_value)
1080 {
1081 if (!strncmp(tmp_value, "dhcp-option ", sizeof("dhcp-option ") - 1))
1082 {
1083 if (prev)
1084 {
1085 prev->next = current->next;
1086 }
1087 else
1088 {
1089 *list = current->next;
1090 }
1092 }
1093 }
1094 }
1095 prev = current;
1096 }
1097}
1098
1099#endif /* ifndef _WIN32 */
1100
1101static in_addr_t
1102get_ip_addr(const char *ip_string, msglvl_t msglevel, bool *error)
1103{
1104 unsigned int flags = GETADDR_HOST_ORDER;
1105 bool succeeded = false;
1106 in_addr_t ret;
1107
1108 if (msglevel & M_FATAL)
1109 {
1110 flags |= GETADDR_FATAL;
1111 }
1112
1113 ret = getaddr(flags, ip_string, 0, &succeeded, NULL);
1114 if (!succeeded && error)
1115 {
1116 *error = true;
1117 }
1118 return ret;
1119}
1120
1126static char *
1127get_ipv6_addr_no_netbits(const char *addr, struct gc_arena *gc)
1128{
1129 const char *end = strchr(addr, '/');
1130 char *ret = NULL;
1131 if (NULL == end)
1132 {
1133 ret = string_alloc(addr, gc);
1134 }
1135 else
1136 {
1137 size_t len = end - addr;
1138 ret = gc_malloc(len + 1, true, gc);
1139 memcpy(ret, addr, len);
1140 }
1141 return ret;
1142}
1143
1144static bool
1145ipv6_addr_safe_hexplusbits(const char *ipv6_prefix_spec)
1146{
1147 return get_ipv6_addr(ipv6_prefix_spec, NULL, NULL, M_WARN);
1148}
1149
1150static char *
1151string_substitute(const char *src, char from, char to, struct gc_arena *gc)
1152{
1153 char *ret = (char *)gc_malloc(strlen(src) + 1, true, gc);
1154 char *dest = ret;
1155 char c;
1156
1157 do
1158 {
1159 c = *src++;
1160 if (c == from)
1161 {
1162 c = to;
1163 }
1164 *dest++ = c;
1165 } while (c);
1166 return ret;
1167}
1168
1178static struct verify_hash_list *
1179parse_hash_fingerprint(const char *str, int nbytes, msglvl_t msglevel, struct gc_arena *gc)
1180{
1181 int i = 0;
1182 const char *cp = str;
1183
1184 struct verify_hash_list *ret;
1186
1187 char term = 0;
1188 unsigned int byte;
1189
1190 while (*cp && i < nbytes)
1191 {
1192 /* valid segments consist of exactly two hex digits, then ':' or EOS */
1193 if (!isxdigit(cp[0]) || !isxdigit(cp[1]) || (cp[2] != ':' && cp[2] != '\0')
1194 || sscanf(cp, "%x", &byte) != 1)
1195 {
1196 msg(msglevel, "format error in hash fingerprint: %s", str);
1197 break;
1198 }
1199
1200 ret->hash[i++] = (uint8_t)byte;
1201
1202 term = cp[2];
1203 if (term == '\0')
1204 {
1205 break;
1206 }
1207 cp += 3;
1208 }
1209 if (i < nbytes)
1210 {
1211 msg(msglevel, "hash fingerprint is wrong length - expected %d bytes, got %d: %s", nbytes, i,
1212 str);
1213 }
1214 else if (term != '\0')
1215 {
1216 msg(msglevel, "hash fingerprint too long - expected only %d bytes: %s", nbytes, str);
1217 }
1218 return ret;
1219}
1220
1231static struct verify_hash_list *
1232parse_hash_fingerprint_multiline(const char *str, int nbytes, msglvl_t msglevel,
1233 struct gc_arena *gc)
1234{
1235 struct gc_arena gc_temp = gc_new();
1236 char *lines = string_alloc(str, &gc_temp);
1237
1238 struct verify_hash_list *ret = NULL;
1239
1240 const char *line;
1241 while ((line = strsep(&lines, "\n")))
1242 {
1243 /* ignore leading whitespace */
1244 while (isspace(*line))
1245 {
1246 line++;
1247 }
1248 /* skip empty lines and comment lines */
1249 if (strlen(line) == 0 || *line == '#' || *line == ';')
1250 {
1251 continue;
1252 }
1253
1254 struct verify_hash_list *hash = parse_hash_fingerprint(line, nbytes, msglevel, gc);
1255
1256 if (!hash)
1257 {
1258 gc_free(&gc_temp);
1259 return NULL;
1260 }
1261
1262 hash->next = ret;
1263 ret = hash;
1264 }
1265 gc_free(&gc_temp);
1266
1267 return ret;
1268}
1269#ifdef _WIN32
1270
1271#ifndef ENABLE_SMALL
1272
1273static void
1274show_dhcp_option_list(const char *name, const char *const *array, int len)
1275{
1276 int i;
1277 for (i = 0; i < len; ++i)
1278 {
1279 msg(D_SHOW_PARMS, " %s[%d] = %s", name, i, array[i]);
1280 }
1281}
1282
1283static void
1284show_dhcp_option_addrs(const char *name, const in_addr_t *array, int len)
1285{
1286 struct gc_arena gc = gc_new();
1287 int i;
1288 for (i = 0; i < len; ++i)
1289 {
1290 msg(D_SHOW_PARMS, " %s[%d] = %s", name, i, print_in_addr_t(array[i], 0, &gc));
1291 }
1292 gc_free(&gc);
1293}
1294
1295static void
1297{
1298 SHOW_BOOL(ip_win32_defined);
1299 SHOW_INT(ip_win32_type);
1300 SHOW_INT(dhcp_masq_offset);
1301 SHOW_INT(dhcp_lease_time);
1302 SHOW_INT(tap_sleep);
1305 SHOW_BOOL(dhcp_pre_release);
1306 SHOW_STR(domain);
1307 SHOW_STR(netbios_scope);
1308 SHOW_UNSIGNED(netbios_node_type);
1309 SHOW_BOOL(disable_nbt);
1310
1311 show_dhcp_option_addrs("DNS", o->dns, o->dns_len);
1312 show_dhcp_option_addrs("WINS", o->wins, o->wins_len);
1313 show_dhcp_option_addrs("NTP", o->ntp, o->ntp_len);
1314 show_dhcp_option_addrs("NBDD", o->nbdd, o->nbdd_len);
1316}
1317
1318#endif /* ifndef ENABLE_SMALL */
1319#endif /* ifdef _WIN32 */
1320
1321static void
1322dhcp_option_dns6_parse(const char *parm, struct in6_addr *dns6_list, int *len, msglvl_t msglevel)
1323{
1324 struct in6_addr addr;
1325 if (*len >= N_DHCP_ADDR)
1326 {
1327 msg(msglevel, "--dhcp-option DNS: maximum of %d IPv6 dns servers can be specified",
1328 N_DHCP_ADDR);
1329 }
1330 else if (get_ipv6_addr(parm, &addr, NULL, msglevel))
1331 {
1332 dns6_list[(*len)++] = addr;
1333 }
1334}
1335static void
1336dhcp_option_address_parse(const char *name, const char *parm, in_addr_t *array, int *len,
1337 msglvl_t msglevel)
1338{
1339 if (*len >= N_DHCP_ADDR)
1340 {
1341 msg(msglevel, "--dhcp-option %s: maximum of %d %s servers can be specified", name,
1342 N_DHCP_ADDR, name);
1343 }
1344 else
1345 {
1346 if (ip_addr_dotted_quad_safe(parm)) /* FQDN -- IP address only */
1347 {
1348 bool error = false;
1349 const in_addr_t addr = get_ip_addr(parm, msglevel, &error);
1350 if (!error)
1351 {
1352 array[(*len)++] = addr;
1353 }
1354 }
1355 else
1356 {
1357 msg(msglevel, "dhcp-option parameter %s '%s' must be an IP address", name, parm);
1358 }
1359 }
1360}
1361
1362#ifndef ENABLE_SMALL
1363static const char *
1365{
1366 switch (mode)
1367 {
1368 case VLAN_ONLY_TAGGED:
1369 return "tagged";
1370
1372 return "untagged";
1373
1374 case VLAN_ALL:
1375 return "all";
1376 }
1377 return NULL;
1378}
1379
1380static void
1381show_p2mp_parms(const struct options *o)
1382{
1383 struct gc_arena gc = gc_new();
1384
1385 msg(D_SHOW_PARMS, " server_network = %s", print_in_addr_t(o->server_network, 0, &gc));
1386 msg(D_SHOW_PARMS, " server_netmask = %s", print_in_addr_t(o->server_netmask, 0, &gc));
1387 msg(D_SHOW_PARMS, " server_network_ipv6 = %s", print_in6_addr(o->server_network_ipv6, 0, &gc));
1388 SHOW_INT(server_netbits_ipv6);
1389 msg(D_SHOW_PARMS, " server_bridge_ip = %s", print_in_addr_t(o->server_bridge_ip, 0, &gc));
1390 msg(D_SHOW_PARMS, " server_bridge_netmask = %s",
1392 msg(D_SHOW_PARMS, " server_bridge_pool_start = %s",
1394 msg(D_SHOW_PARMS, " server_bridge_pool_end = %s",
1396 if (o->push_list.head)
1397 {
1398 const struct push_entry *e = o->push_list.head;
1399 while (e)
1400 {
1401 if (e->enable)
1402 {
1403 msg(D_SHOW_PARMS, " push_entry = '%s'", e->option);
1404 }
1405 e = e->next;
1406 }
1407 }
1408 SHOW_BOOL(ifconfig_pool_defined);
1409 msg(D_SHOW_PARMS, " ifconfig_pool_start = %s",
1411 msg(D_SHOW_PARMS, " ifconfig_pool_end = %s", print_in_addr_t(o->ifconfig_pool_end, 0, &gc));
1412 msg(D_SHOW_PARMS, " ifconfig_pool_netmask = %s",
1414 SHOW_STR(ifconfig_pool_persist_filename);
1415 SHOW_INT(ifconfig_pool_persist_refresh_freq);
1416 SHOW_BOOL(ifconfig_ipv6_pool_defined);
1417 msg(D_SHOW_PARMS, " ifconfig_ipv6_pool_base = %s",
1419 SHOW_INT(ifconfig_ipv6_pool_netbits);
1420 SHOW_INT(n_bcast_buf);
1421 SHOW_INT(tcp_queue_limit);
1422 SHOW_INT(real_hash_size);
1423 SHOW_INT(virtual_hash_size);
1424 SHOW_STR(client_connect_script);
1426 SHOW_STR(client_disconnect_script);
1427 SHOW_STR(client_crresponse_script);
1428 SHOW_STR(client_config_dir);
1429 SHOW_BOOL(ccd_exclusive);
1430 SHOW_STR(tmp_dir);
1431 SHOW_BOOL(push_ifconfig_defined);
1432 msg(D_SHOW_PARMS, " push_ifconfig_local = %s",
1434 msg(D_SHOW_PARMS, " push_ifconfig_remote_netmask = %s",
1436 SHOW_BOOL(push_ifconfig_ipv6_defined);
1437 msg(D_SHOW_PARMS, " push_ifconfig_ipv6_local = %s/%d",
1439 msg(D_SHOW_PARMS, " push_ifconfig_ipv6_remote = %s",
1441 SHOW_BOOL(enable_c2c);
1442 SHOW_BOOL(duplicate_cn);
1443 SHOW_INT(cf_max);
1444 SHOW_INT(cf_per);
1445 SHOW_INT(cf_initial_max);
1446 SHOW_INT(cf_initial_per);
1447 SHOW_INT(max_clients);
1448 SHOW_INT(max_routes_per_client);
1449 SHOW_STR(auth_user_pass_verify_script);
1450 SHOW_BOOL(auth_user_pass_verify_script_via_file);
1451 SHOW_BOOL(auth_token_generate);
1452 SHOW_BOOL(force_key_material_export);
1453 SHOW_INT(auth_token_lifetime);
1454 SHOW_STR_INLINE(auth_token_secret_file);
1455#if PORT_SHARE
1456 SHOW_STR(port_share_host);
1457 SHOW_STR(port_share_port);
1458#endif
1459 SHOW_BOOL(vlan_tagging);
1460 msg(D_SHOW_PARMS, " vlan_accept = %s", print_vlan_accept(o->vlan_accept));
1461 SHOW_INT(vlan_pvid);
1462
1463 SHOW_BOOL(client);
1464 SHOW_BOOL(pull);
1465 SHOW_STR_INLINE(auth_user_pass_file);
1466
1467 gc_free(&gc);
1468}
1469
1470#endif /* ! ENABLE_SMALL */
1471
1472static void
1473option_iroute(struct options *o, const char *network_str, const char *netmask_str,
1474 msglvl_t msglevel)
1475{
1476 struct iroute *ir;
1477
1478 ALLOC_OBJ_GC(ir, struct iroute, &o->gc);
1479 ir->network = getaddr(GETADDR_HOST_ORDER, network_str, 0, NULL, NULL);
1480 ir->netbits = 32; /* host route if no netmask given */
1481
1482 if (netmask_str)
1483 {
1484 const in_addr_t netmask = getaddr(GETADDR_HOST_ORDER, netmask_str, 0, NULL, NULL);
1485 ir->netbits = netmask_to_netbits2(netmask);
1486
1487 if (ir->netbits < 0)
1488 {
1489 msg(msglevel, "in --iroute %s %s : Bad network/subnet specification", network_str,
1490 netmask_str);
1491 return;
1492 }
1493 }
1494
1495 ir->next = o->iroutes;
1496 o->iroutes = ir;
1497}
1498
1499static void
1500option_iroute_ipv6(struct options *o, const char *prefix_str, msglvl_t msglevel)
1501{
1502 struct iroute_ipv6 *ir;
1503
1504 ALLOC_OBJ_GC(ir, struct iroute_ipv6, &o->gc);
1505
1506 if (!get_ipv6_addr(prefix_str, &ir->network, &ir->netbits, msglevel))
1507 {
1508 msg(msglevel, "in --iroute-ipv6 %s: Bad IPv6 prefix specification", prefix_str);
1509 return;
1510 }
1511
1512 ir->next = o->iroutes_ipv6;
1513 o->iroutes_ipv6 = ir;
1514}
1515
1516#ifndef ENABLE_SMALL
1517static void
1519{
1520 int i;
1521 msg(D_SHOW_PARMS, "BEGIN http_proxy");
1522 SHOW_STR(server);
1523 SHOW_STR(port);
1524 SHOW_STR(auth_method_string);
1525 SHOW_STR(auth_file);
1526 SHOW_STR(auth_file_up);
1527 SHOW_BOOL(inline_creds);
1528 SHOW_BOOL(nocache);
1529 SHOW_STR(http_version);
1530 SHOW_STR(user_agent);
1531 for (i = 0; i < MAX_CUSTOM_HTTP_HEADER && o->custom_headers[i].name; i++)
1532 {
1533 if (o->custom_headers[i].content)
1534 {
1535 msg(D_SHOW_PARMS, " custom_header[%d] = %s: %s", i, o->custom_headers[i].name,
1536 o->custom_headers[i].content);
1537 }
1538 else
1539 {
1540 msg(D_SHOW_PARMS, " custom_header[%d] = %s", i, o->custom_headers[i].name);
1541 }
1542 }
1543 msg(D_SHOW_PARMS, "END http_proxy");
1544}
1545#endif /* ifndef ENABLE_SMALL */
1546
1547void
1549{
1550 gc_detach(&o->gc);
1551 o->routes = NULL;
1552 o->client_nat = NULL;
1553 clone_push_list(o);
1554}
1555
1556void
1558{
1559 if (!options->routes)
1560 {
1562 }
1563}
1564
1565static void
1573
1574static void
1576{
1577 if (!options->client_nat)
1578 {
1580 }
1581}
1582
1583#ifndef ENABLE_SMALL
1584static void
1586{
1587 /* Display the global proto only in client mode or with no '--local'*/
1588 if (o->local_list->len == 1)
1589 {
1590 msg(D_SHOW_PARMS, " proto = %s", proto2ascii(o->proto, o->af, false));
1591 }
1592
1593 msg(D_SHOW_PARMS, " Local Sockets:");
1594 for (int i = 0; i < o->local_list->len; i++)
1595 {
1596 msg(D_SHOW_PARMS, " [%s]:%s-%s", o->local_list->array[i]->local,
1597 o->local_list->array[i]->port,
1598 proto2ascii(o->local_list->array[i]->proto, o->af, false));
1599 }
1600 SHOW_STR(remote);
1601 SHOW_STR(remote_port);
1602 SHOW_BOOL(remote_float);
1603 SHOW_BOOL(bind_defined);
1605 SHOW_BOOL(bind_ipv6_only);
1606 SHOW_INT(connect_retry_seconds);
1607 SHOW_INT(connect_timeout);
1608
1609 if (o->http_proxy_options)
1610 {
1612 }
1613 SHOW_STR(socks_proxy_server);
1614 SHOW_STR(socks_proxy_port);
1615 SHOW_INT(tun_mtu);
1616 SHOW_BOOL(tun_mtu_defined);
1617 SHOW_INT(link_mtu);
1618 SHOW_BOOL(link_mtu_defined);
1619 SHOW_INT(tun_mtu_extra);
1620 SHOW_BOOL(tun_mtu_extra_defined);
1621 SHOW_INT(tls_mtu);
1622
1623 SHOW_INT(mtu_discover_type);
1624
1625#ifdef ENABLE_FRAGMENT
1627#endif
1628 SHOW_INT(mssfix);
1629 SHOW_BOOL(mssfix_encap);
1630 SHOW_BOOL(mssfix_fixed);
1631
1632 SHOW_INT(explicit_exit_notification);
1633
1634 SHOW_STR_INLINE(tls_auth_file);
1635 SHOW_PARM(key_direction, keydirection2ascii(o->key_direction, false, true), "%s");
1636 SHOW_STR_INLINE(tls_crypt_file);
1637 SHOW_STR_INLINE(tls_crypt_v2_file);
1638}
1639
1640
1641static void
1643{
1644 if (o->connection_list)
1645 {
1646 const struct connection_list *l = o->connection_list;
1647 int i;
1648 for (i = 0; i < l->len; ++i)
1649 {
1650 msg(D_SHOW_PARMS, "Connection profiles [%d]:", i);
1651 show_connection_entry(l->array[i]);
1652 }
1653 }
1654 else
1655 {
1656 msg(D_SHOW_PARMS, "Connection profiles [default]:");
1658 }
1659 msg(D_SHOW_PARMS, "Connection profiles END");
1660}
1661
1662static void
1664{
1665 struct pull_filter *f;
1666 if (!l)
1667 {
1668 return;
1669 }
1670
1671 msg(D_SHOW_PARMS, " Pull filters:");
1672 for (f = l->head; f; f = f->next)
1673 {
1674 msg(D_SHOW_PARMS, " %s \"%s\"", pull_filter_type_name(f->type), f->pattern);
1675 }
1676}
1677
1678#endif /* ifndef ENABLE_SMALL */
1679
1680void
1681show_settings(const struct options *o)
1682{
1683#ifndef ENABLE_SMALL
1684 msg(D_SHOW_PARMS, "Current Parameter Settings:");
1685
1686 SHOW_STR(config);
1687
1688 SHOW_INT(mode);
1689
1690#ifdef ENABLE_FEATURE_TUN_PERSIST
1691 SHOW_BOOL(persist_config);
1692 SHOW_INT(persist_mode);
1693#endif
1694
1695 SHOW_BOOL(show_ciphers);
1696 SHOW_BOOL(show_digests);
1697 SHOW_BOOL(show_engines);
1698 SHOW_BOOL(genkey);
1699 SHOW_STR(genkey_filename);
1700 SHOW_STR(key_pass_file);
1701 SHOW_BOOL(show_tls_ciphers);
1702
1703 SHOW_INT(connect_retry_max);
1705
1706 SHOW_BOOL(remote_random);
1707
1708 SHOW_STR(ipchange);
1709 SHOW_STR(dev);
1710 SHOW_STR(dev_type);
1711 SHOW_STR(dev_node);
1712#if defined(ENABLE_DCO)
1713 SHOW_BOOL(disable_dco);
1714#endif
1715 SHOW_STR(lladdr);
1716 SHOW_INT(topology);
1717 SHOW_STR(ifconfig_local);
1718 SHOW_STR(ifconfig_remote_netmask);
1719 SHOW_BOOL(ifconfig_noexec);
1720 SHOW_BOOL(ifconfig_nowarn);
1721 SHOW_STR(ifconfig_ipv6_local);
1722 SHOW_INT(ifconfig_ipv6_netbits);
1723 SHOW_STR(ifconfig_ipv6_remote);
1724
1726 SHOW_INT(mtu_test);
1727
1728 SHOW_BOOL(mlock);
1729
1730 SHOW_INT(keepalive_ping);
1731 SHOW_INT(keepalive_timeout);
1732 SHOW_INT(inactivity_timeout);
1733 SHOW_INT(session_timeout);
1734 SHOW_INT64(inactivity_minimum_bytes);
1735 SHOW_INT(ping_send_timeout);
1736 SHOW_INT(ping_rec_timeout);
1737 SHOW_INT(ping_rec_timeout_action);
1738 SHOW_BOOL(ping_timer_remote);
1739 SHOW_INT(remap_sigusr1);
1740 SHOW_BOOL(persist_tun);
1741 SHOW_BOOL(persist_local_ip);
1742 SHOW_BOOL(persist_remote_ip);
1743
1744#if PASSTOS_CAPABILITY
1745 SHOW_BOOL(passtos);
1746#endif
1747
1748 SHOW_INT(resolve_retry_seconds);
1749 SHOW_BOOL(resolve_in_advance);
1750
1751 SHOW_STR(username);
1752 SHOW_STR(groupname);
1753 SHOW_STR(chroot_dir);
1754 SHOW_STR(cd_dir);
1755#ifdef ENABLE_SELINUX
1756 SHOW_STR(selinux_context);
1757#endif
1758 SHOW_STR(writepid);
1759 SHOW_STR(up_script);
1760 SHOW_STR(down_script);
1761 SHOW_BOOL(down_pre);
1762 SHOW_BOOL(up_restart);
1763 SHOW_BOOL(up_delay);
1765 SHOW_BOOL(log);
1768 SHOW_INT(nice);
1769 SHOW_INT(verbosity);
1770 SHOW_INT(mute);
1771#ifdef ENABLE_DEBUG
1772 SHOW_INT(gremlin);
1773#endif
1774 SHOW_STR(status_file);
1775 SHOW_INT(status_file_version);
1776 SHOW_INT(status_file_update_freq);
1777
1778 SHOW_BOOL(occ);
1779 SHOW_INT(rcvbuf);
1780 SHOW_INT(sndbuf);
1781#if defined(TARGET_LINUX)
1782 SHOW_INT(mark);
1783#endif
1784 SHOW_INT(sockflags);
1785
1786 SHOW_INT(comp.alg);
1787 SHOW_INT(comp.flags);
1788
1789 SHOW_STR(route_script);
1790 SHOW_STR(route_default_gateway);
1791 SHOW_INT(route_default_metric);
1792 SHOW_INT(route_default_table_id);
1793 SHOW_BOOL(route_noexec);
1794 SHOW_INT(route_delay);
1795 SHOW_INT(route_delay_window);
1796 SHOW_BOOL(route_delay_defined);
1797 SHOW_BOOL(route_nopull);
1798 SHOW_BOOL(route_gateway_via_dhcp);
1799 SHOW_BOOL(allow_pull_fqdn);
1801
1802 if (o->routes)
1803 {
1805 }
1806
1807 if (o->client_nat)
1808 {
1810 }
1811
1813
1814#ifdef ENABLE_MANAGEMENT
1815 SHOW_STR(management_addr);
1816 SHOW_STR(management_port);
1817 SHOW_STR(management_user_pass);
1818 SHOW_INT(management_log_history_cache);
1819 SHOW_INT(management_echo_buffer_size);
1820 SHOW_STR(management_client_user);
1821 SHOW_STR(management_client_group);
1822 SHOW_INT(management_flags);
1823#endif
1824#ifdef ENABLE_PLUGIN
1825 if (o->plugin_list)
1826 {
1828 }
1829#endif
1830
1831 SHOW_STR_INLINE(shared_secret_file);
1832 SHOW_PARM(key_direction, keydirection2ascii(o->key_direction, false, true), "%s");
1833 SHOW_STR(ciphername);
1834 SHOW_STR(ncp_ciphers);
1835 SHOW_STR(authname);
1836#ifndef ENABLE_CRYPTO_MBEDTLS
1837 SHOW_BOOL(engine);
1838#endif /* ENABLE_CRYPTO_MBEDTLS */
1839 SHOW_BOOL(mute_replay_warnings);
1840 SHOW_INT(replay_window);
1841 SHOW_INT(replay_time);
1842 SHOW_STR(packet_id_file);
1844#ifdef ENABLE_PREDICTION_RESISTANCE
1845 SHOW_BOOL(use_prediction_resistance);
1846#endif
1847
1848 SHOW_BOOL(tls_server);
1849 SHOW_BOOL(tls_client);
1850 SHOW_STR_INLINE(ca_file);
1851 SHOW_STR(ca_path);
1852 SHOW_STR_INLINE(dh_file);
1854 {
1855 SHOW_PARM("cert_file", "EXTERNAL_CERT", "%s");
1856 }
1857 else
1858 {
1859 SHOW_STR_INLINE(cert_file);
1860 }
1861 SHOW_STR_INLINE(extra_certs_file);
1862
1864 {
1865 SHOW_PARM("priv_key_file", "EXTERNAL_PRIVATE_KEY", "%s");
1866 }
1867 else
1868 {
1869 SHOW_STR_INLINE(priv_key_file);
1870 }
1871#ifndef ENABLE_CRYPTO_MBEDTLS
1872 SHOW_STR_INLINE(pkcs12_file);
1873#endif
1874#ifdef ENABLE_CRYPTOAPI
1875 SHOW_STR(cryptoapi_cert);
1876#endif
1877 SHOW_STR(cipher_list);
1878 SHOW_STR(cipher_list_tls13);
1879 SHOW_STR(tls_cert_profile);
1881 SHOW_STR(tls_export_peer_cert_dir);
1882 SHOW_INT(verify_x509_type);
1883 SHOW_STR(verify_x509_name);
1884 SHOW_STR_INLINE(crl_file);
1885 SHOW_INT(ns_cert_type);
1886 {
1887 int i;
1888 for (i = 0; i < MAX_PARMS; i++)
1889 {
1890 SHOW_INT(remote_cert_ku[i]);
1891 }
1892 }
1893 SHOW_STR(remote_cert_eku);
1894 if (o->verify_hash)
1895 {
1896 SHOW_INT(verify_hash_algo);
1897 SHOW_INT(verify_hash_depth);
1898 struct gc_arena gc = gc_new();
1899 struct verify_hash_list *hl = o->verify_hash;
1900 int digest_len =
1902 while (hl)
1903 {
1904 char *s = format_hex_ex(hl->hash, digest_len, 0, 1, ":", &gc);
1905 SHOW_PARM(verify_hash, s, "%s");
1906 hl = hl->next;
1907 }
1908 gc_free(&gc);
1909 }
1910 SHOW_INT(ssl_flags);
1911
1912 SHOW_INT(tls_timeout);
1913
1914 SHOW_INT64(renegotiate_bytes);
1915 SHOW_INT64(renegotiate_packets);
1916 SHOW_INT(renegotiate_seconds);
1917
1918 SHOW_INT(handshake_window);
1919 SHOW_INT(transition_window);
1920
1921 SHOW_BOOL(single_session);
1923 SHOW_BOOL(tls_exit);
1924
1925 SHOW_STR(tls_crypt_v2_metadata);
1926
1927#ifdef ENABLE_PKCS11
1928 {
1929 int i;
1930 for (i = 0; i < MAX_PARMS && o->pkcs11_providers[i] != NULL; i++)
1931 {
1932 SHOW_PARM(pkcs11_providers, o->pkcs11_providers[i], "%s");
1933 }
1934 }
1935 {
1936 int i;
1937 for (i = 0; i < MAX_PARMS; i++)
1938 {
1939 SHOW_PARM(pkcs11_protected_authentication,
1940 o->pkcs11_protected_authentication[i] ? "ENABLED" : "DISABLED", "%s");
1941 }
1942 }
1943 {
1944 int i;
1945 for (i = 0; i < MAX_PARMS; i++)
1946 {
1947 SHOW_PARM(pkcs11_private_mode, o->pkcs11_private_mode[i], "%08x");
1948 }
1949 }
1950 {
1951 int i;
1952 for (i = 0; i < MAX_PARMS; i++)
1953 {
1954 SHOW_PARM(pkcs11_cert_private, o->pkcs11_cert_private[i] ? "ENABLED" : "DISABLED",
1955 "%s");
1956 }
1957 }
1958 SHOW_INT(pkcs11_pin_cache_period);
1959 SHOW_STR(pkcs11_id);
1961#endif /* ENABLE_PKCS11 */
1962
1963 show_p2mp_parms(o);
1964
1965#ifdef _WIN32
1966 SHOW_BOOL(show_net_up);
1967 SHOW_INT(route_method);
1968 SHOW_BOOL(block_outside_dns);
1970#endif
1971#endif /* ifndef ENABLE_SMALL */
1972}
1973
1974#undef SHOW_PARM
1975#undef SHOW_STR
1976#undef SHOW_INT
1977#undef SHOW_BOOL
1978
1979#ifdef ENABLE_MANAGEMENT
1980
1981static struct http_proxy_options *
1982parse_http_proxy_override(const char *server, const char *port, const char *flags,
1983 struct gc_arena *gc)
1984{
1985 if (server && port)
1986 {
1987 struct http_proxy_options *ho;
1989 ho->server = string_alloc(server, gc);
1990 ho->port = port;
1991 if (flags && !strcmp(flags, "nct"))
1992 {
1993 ho->auth_retry = PAR_NCT;
1994 }
1995 else
1996 {
1997 ho->auth_retry = PAR_ALL;
1998 }
1999 ho->http_version = "1.0";
2000 ho->user_agent = "OpenVPN-Autoproxy/1.0";
2001 return ho;
2002 }
2003 else
2004 {
2005 return NULL;
2006 }
2007}
2008
2009static void
2011{
2012 const struct connection_list *l = o->connection_list;
2013 int i;
2014 bool succeed = false;
2015 for (i = 0; i < l->len; ++i)
2016 {
2017 struct connection_entry *ce = l->array[i];
2018 if (ce->proto == PROTO_TCP_CLIENT || ce->proto == PROTO_TCP)
2019 {
2021 succeed = true;
2022 }
2023 }
2024 if (succeed)
2025 {
2026 for (i = 0; i < l->len; ++i)
2027 {
2028 struct connection_entry *ce = l->array[i];
2029 if (ce->proto == PROTO_UDP)
2030 {
2031 ce->flags |= CE_DISABLED;
2032 }
2033 }
2034 }
2035 else
2036 {
2037 msg(M_WARN,
2038 "Note: option http-proxy-override ignored because no TCP-based connection profiles are defined");
2039 }
2040}
2041
2042#endif /* ifdef ENABLE_MANAGEMENT */
2043
2044static struct local_list *
2046{
2047 if (!ce->local_list)
2048 {
2050 }
2051 return ce->local_list;
2052}
2053
2054static struct local_entry *
2055alloc_local_entry(struct connection_entry *ce, const msglvl_t msglevel, struct gc_arena *gc)
2056{
2058 struct local_entry *e;
2059
2060 if (l->len >= l->capacity)
2061 {
2062 const int new_cap = l->capacity + 1;
2063 const size_t elem_size = sizeof(*l->array);
2064
2065 struct local_entry **new_array = gc_realloc(l->array, new_cap * elem_size, gc);
2066 if (!new_array)
2067 {
2068 msg(msglevel,
2069 "Unable to process more local options: out of memory. Number of entries = %d",
2070 l->len);
2071 return NULL;
2072 }
2073
2074 l->array = new_array;
2075 l->capacity = new_cap;
2076 }
2077
2078 ALLOC_OBJ_CLEAR_GC(e, struct local_entry, gc);
2079 e->proto = PROTO_NONE;
2080 l->array[l->len++] = e;
2081
2082 return e;
2083}
2084
2085static struct connection_list *
2094
2095static struct connection_entry *
2097{
2099 struct connection_entry *e;
2100
2101 if (l->len == l->capacity)
2102 {
2103 int capacity = l->capacity + CONNECTION_LIST_SIZE;
2104 struct connection_entry **ce =
2105 gc_realloc(l->array, capacity * sizeof(struct connection_entry *), &options->gc);
2106 if (ce == NULL)
2107 {
2108 msg(msglevel,
2109 "Unable to process more connection options: out of memory. Number of entries = %d",
2110 l->len);
2111 return NULL;
2112 }
2113 l->array = ce;
2114 l->capacity = capacity;
2115 }
2117 l->array[l->len++] = e;
2118 return e;
2119}
2120
2121static struct remote_list *
2123{
2124 if (!options->remote_list)
2125 {
2127 }
2128 return options->remote_list;
2129}
2130
2131static struct remote_entry *
2133{
2135 struct remote_entry *e;
2136
2137 if (l->len == l->capacity)
2138 {
2139 int capacity = l->capacity + CONNECTION_LIST_SIZE;
2140 struct remote_entry **re =
2141 gc_realloc(l->array, capacity * sizeof(struct remote_entry *), &options->gc);
2142 if (re == NULL)
2143 {
2144 msg(msglevel,
2145 "Unable to process more remote options: out of memory. Number of entries = %d",
2146 l->len);
2147 return NULL;
2148 }
2149 l->array = re;
2150 l->capacity = capacity;
2151 }
2152 ALLOC_OBJ_GC(e, struct remote_entry, &options->gc);
2153 l->array[l->len++] = e;
2154 return e;
2155}
2156
2157static struct pull_filter_list *
2159{
2160 if (!o->pull_filter_list)
2161 {
2163 }
2164 return o->pull_filter_list;
2165}
2166
2167static struct pull_filter *
2169{
2171 struct pull_filter *f;
2172
2173 ALLOC_OBJ_CLEAR_GC(f, struct pull_filter, &o->gc);
2174 if (l->head)
2175 {
2176 ASSERT(l->tail);
2177 l->tail->next = f;
2178 }
2179 else
2180 {
2181 ASSERT(!l->tail);
2182 l->head = f;
2183 }
2184 l->tail = f;
2185 return f;
2186}
2187
2188static void
2190{
2191 if (re->remote)
2192 {
2193 ce->remote = re->remote;
2194 }
2195 if (re->remote_port)
2196 {
2197 ce->remote_port = re->remote_port;
2198 }
2199 if (re->proto >= 0)
2200 {
2201 ce->proto = re->proto;
2202 }
2203 if (re->af > 0)
2204 {
2205 ce->af = re->af;
2206 }
2207}
2208
2209static void
2210connection_entry_preload_key(const char **key_file, bool *key_inline, struct gc_arena *gc)
2211{
2212 if (key_file && *key_file && !(*key_inline))
2213 {
2214 struct buffer in = buffer_read_from_file(*key_file, gc);
2215 if (!buf_valid(&in))
2216 {
2217 msg(M_FATAL, "Cannot pre-load keyfile (%s)", *key_file);
2218 }
2219
2220 *key_file = (const char *)in.data;
2221 *key_inline = true;
2222 }
2223}
2224
2225static void
2227{
2228#ifdef ENABLE_CRYPTO_MBEDTLS
2229 if (options->ca_path)
2230 {
2231 msg(M_USAGE, "Parameter --capath cannot be used with the mbed TLS version of OpenVPN.");
2232 }
2233#endif
2234
2237 || options->ca_path
2238#endif
2239 )
2240 {
2241 return;
2242 }
2243
2244 const char *const str = "You must define CA file (--ca)"
2245#ifndef ENABLE_CRYPTO_MBEDTLS
2246 " or CA path (--capath)"
2247#endif
2248 " and/or peer fingerprint verification (--peer-fingerprint)";
2249 msg(M_USAGE, "%s", str);
2250}
2251
2252#define MUST_BE_UNDEF(parm, parm_name) \
2253 if (options->parm != defaults.parm) \
2254 { \
2255 msg(M_USAGE, use_err, parm_name); \
2256 }
2257#define MUST_BE_FALSE(condition, parm_name) \
2258 if (condition) \
2259 { \
2260 msg(M_USAGE, use_err, parm_name); \
2261 }
2262
2263static void
2265{
2266 struct options defaults;
2267 int dev = DEV_TYPE_UNDEF;
2268 bool pull = false;
2269
2270 init_options(&defaults, true);
2271
2272 if (!options->test_crypto)
2273 {
2274 notnull(options->dev, "TUN/TAP device (--dev)");
2275 }
2276
2277 /*
2278 * Get tun/tap/null device type
2279 */
2281
2282 /*
2283 * If "proto tcp" is specified, make sure we know whether it is
2284 * tcp-client or tcp-server.
2285 */
2286 if (ce->proto == PROTO_TCP)
2287 {
2288 msg(M_USAGE, "--proto tcp is ambiguous in this context. Please specify "
2289 "--proto tcp-server or --proto tcp-client");
2290 }
2291
2292 /*
2293 * Sanity check on Client mode
2294 */
2295
2296 if (options->mode != MODE_SERVER && ce->local_list->len > 1)
2297 {
2298 msg(M_USAGE, "multiple --local statements only allowed in --server mode");
2299 }
2300
2301 if (options->lladdr && dev != DEV_TYPE_TAP)
2302 {
2303 msg(M_USAGE, "--lladdr can only be used in --dev tap mode");
2304 }
2305
2306 /*
2307 * Sanity check on MTU parameters
2308 */
2310 {
2311 msg(M_USAGE, "only one of --tun-mtu or --link-mtu may be defined");
2312 }
2313
2315 {
2316 msg(M_USAGE, "--mtu-test only makes sense with --proto udp");
2317 }
2318
2319 /* will we be pulling options from server? */
2320 pull = options->pull;
2321
2322 /*
2323 * Sanity check on --local, --remote, and --ifconfig
2324 */
2325
2328 {
2329 msg(M_USAGE, "--local and --remote addresses must be distinct from --ifconfig "
2330 "addresses");
2331 }
2332
2334 {
2335 msg(M_USAGE, "local and remote/netmask --ifconfig addresses must be different");
2336 }
2337
2338 if (ce->bind_defined && !ce->bind_local)
2339 {
2340 msg(M_USAGE, "--bind and --nobind can't be used together");
2341 }
2342
2344 {
2345 msg(M_USAGE, "--lport and --nobind don't make sense when used together");
2346 }
2347
2348 if (!ce->remote && !ce->bind_local)
2349 {
2350 msg(M_USAGE, "--nobind doesn't make sense unless used with --remote");
2351 }
2352
2353 for (int i = 0; i < ce->local_list->len; i++)
2354 {
2355 struct local_entry *le = ce->local_list->array[i];
2356
2357 if (proto_is_net(le->proto) && string_defined_equal(le->local, ce->remote)
2359 {
2360 msg(M_USAGE, "--remote and one of the --local addresses are the same");
2361 }
2362
2365 {
2366 msg(M_USAGE, "--local addresses must be distinct from --ifconfig addresses");
2367 }
2368
2369 if (le->local && !ce->bind_local)
2370 {
2371 msg(M_USAGE, "--local and --nobind don't make sense when used together");
2372 }
2373 }
2374
2375 /*
2376 * Check for consistency of management options
2377 */
2378#ifdef ENABLE_MANAGEMENT
2382 {
2383 msg(M_USAGE,
2384 "--management is not specified, however one or more options which modify the behavior of --management were specified");
2385 }
2386
2389 {
2390 msg(M_USAGE, "--management-client-(user|group) can only be used on unix domain sockets");
2391 }
2392
2395 {
2396 msg(M_WARN, "WARNING: Using --management on a TCP port WITHOUT "
2397 "passwords is STRONGLY discouraged and considered insecure");
2398 }
2399
2400#endif /* ifdef ENABLE_MANAGEMENT */
2401
2402#if !defined(HAVE_XKEY_PROVIDER)
2405 {
2406 msg(M_FATAL, "management-external-key with TLS 1.3 or later requires "
2407 "nopadding argument/support");
2408 }
2409#endif
2410 /*
2411 * Windows-specific options.
2412 */
2413
2414#ifdef _WIN32
2415 if (dev == DEV_TYPE_TUN
2417 {
2418 msg(M_USAGE, "On Windows, --ifconfig is required when --dev tun is used");
2419 }
2420
2423 {
2424 msg(M_USAGE, "On Windows, --ip-win32 doesn't make sense unless --ifconfig is also used");
2425 }
2426
2428 {
2429 const char *prefix = "Some --dhcp-option or --dns options require DHCP server";
2431 {
2432 msg(M_USAGE, "%s, which is not supported by the selected %s driver", prefix,
2434 }
2437 {
2438 msg(M_USAGE, "%s, which requires --ip-win32 dynamic or adaptive", prefix);
2439 }
2440 }
2441#endif /* ifdef _WIN32 */
2442
2443 /*
2444 * Check that protocol options make sense.
2445 */
2446
2447#ifdef ENABLE_FRAGMENT
2448 if (!proto_is_udp(ce->proto) && ce->fragment)
2449 {
2450 msg(M_USAGE, "--fragment can only be used with --proto udp");
2451 }
2452#endif
2453
2454 if (!ce->remote && ce->proto == PROTO_TCP_CLIENT)
2455 {
2456 msg(M_USAGE, "--remote MUST be used in TCP Client mode");
2457 }
2458
2459 if ((ce->http_proxy_options) && ce->proto != PROTO_TCP_CLIENT)
2460 {
2461 msg(M_USAGE, "--http-proxy MUST be used in TCP Client mode (i.e. --proto "
2462 "tcp-client)");
2463 }
2464
2465 if ((ce->http_proxy_options) && !ce->http_proxy_options->server)
2466 {
2467 msg(M_USAGE, "--http-proxy not specified but other http proxy options present");
2468 }
2469
2471 {
2472 msg(M_USAGE, "--http-proxy can not be used together with --socks-proxy");
2473 }
2474
2475 if (ce->socks_proxy_server && ce->proto == PROTO_TCP_SERVER)
2476 {
2477 msg(M_USAGE, "--socks-proxy can not be used in TCP Server mode");
2478 }
2479
2480 if (ce->proto == PROTO_TCP_SERVER && (options->connection_list->len > 1))
2481 {
2482 msg(M_USAGE, "TCP server mode allows at most one --remote address");
2483 }
2484
2485 /*
2486 * Check consistency of --mode server options.
2487 */
2488 if (options->mode == MODE_SERVER)
2489 {
2490 const char use_err[] = "--%s cannot be used with --mode server.";
2491
2492#define USAGE_VALID_SERVER_PROTOS \
2493 "--mode server currently only supports " \
2494 "--proto values of udp, tcp-server, tcp4-server, or tcp6-server"
2495#ifdef TARGET_ANDROID
2496 msg(M_FATAL, "--mode server not supported on Android");
2497#endif
2498 if (!(dev == DEV_TYPE_TUN || dev == DEV_TYPE_TAP))
2499 {
2500 msg(M_USAGE, "--mode server only works with --dev tun or --dev tap");
2501 }
2502 MUST_BE_UNDEF(pull, "pull");
2504 {
2505 msg(M_WARN, "--pull-filter ignored for --mode server");
2506 }
2507 if (!(proto_is_udp(ce->proto) || ce->proto == PROTO_TCP_SERVER))
2508 {
2510 }
2511#if PORT_SHARE
2512 if ((options->port_share_host || options->port_share_port)
2513 && (ce->proto != PROTO_TCP_SERVER))
2514 {
2515 msg(M_USAGE, "--port-share only works in TCP server mode "
2516 "(--proto values of tcp-server, tcp4-server, or tcp6-server)");
2517 }
2518#endif
2519 if (!options->tls_server)
2520 {
2521 msg(M_USAGE, "--mode server requires --tls-server");
2522 }
2523 MUST_BE_FALSE(ce->remote, "remote");
2524 MUST_BE_FALSE(!ce->bind_local, "nobind");
2525 MUST_BE_FALSE(ce->http_proxy_options, "http-proxy");
2526 MUST_BE_FALSE(ce->socks_proxy_server, "socks-proxy");
2527 /* <connection> blocks force to have a remote embedded, so we check
2528 * for the --remote and bail out if it is present
2529 */
2531 {
2532 msg(M_USAGE, "<connection> cannot be used with --mode server");
2533 }
2534
2535 MUST_BE_UNDEF(shaper, "shaper");
2536 if (options->ipchange)
2537 {
2538 msg(M_USAGE, "--ipchange cannot be used with --mode server (use "
2539 "--client-connect instead)");
2540 }
2541 if (!(proto_is_dgram(ce->proto) || ce->proto == PROTO_TCP_SERVER))
2542 {
2544 }
2545 if (!proto_is_udp(ce->proto) && (options->cf_max || options->cf_per))
2546 {
2547 msg(M_USAGE,
2548 "--connect-freq only works with --mode server --proto udp. Try --max-clients instead.");
2549 }
2550 if (!(dev == DEV_TYPE_TAP || (dev == DEV_TYPE_TUN && options->topology == TOP_SUBNET))
2552 {
2553 msg(M_USAGE,
2554 "The third parameter to --ifconfig-pool (netmask) is only valid in --dev tap mode");
2555 }
2557 {
2558 msg(M_USAGE,
2559 "--redirect-gateway cannot be used with --mode server (however --push \"redirect-gateway\" is fine)");
2560 }
2561 MUST_BE_UNDEF(route_delay_defined, "route-delay");
2562 MUST_BE_UNDEF(up_delay, "up-delay");
2565 {
2566 msg(M_USAGE,
2567 "--ifconfig-pool-persist must be used with --ifconfig-pool or --ifconfig-ipv6-pool");
2568 }
2570 {
2571 msg(M_USAGE, "--ifconfig-ipv6-pool needs --ifconfig-ipv6");
2572 }
2573 MUST_BE_UNDEF(allow_recursive_routing, "allow-recursive-routing");
2575 {
2576 msg(M_USAGE,
2577 "--auth-user-pass cannot be used with --mode server (it should be used on the client side only)");
2578 }
2580 {
2581 msg(M_USAGE, "--ccd-exclusive must be used with --client-config-dir");
2582 }
2584 {
2585 msg(M_USAGE, "--auth-gen-token needs a non-infinite "
2586 "--renegotiate_seconds setting");
2587 }
2590 {
2591 msg(M_USAGE,
2592 "--auth-gen-token renewal time needs to be at least "
2593 " two times --hand-window (%d).",
2595 }
2598 {
2599 const char *use_err =
2600 "--%s must be used with --management-client-auth, an --auth-user-pass-verify script, or plugin";
2601
2604 "verify-client-cert none|optional");
2606 "username-as-common-name");
2608 "auth-user-pass-optional");
2609 }
2610
2611 if (options->vlan_tagging && dev != DEV_TYPE_TAP)
2612 {
2613 msg(M_USAGE, "--vlan-tagging must be used with --dev tap");
2614 }
2615 if (!options->vlan_tagging)
2616 {
2617 const char use_err[] = "--%s requires --vlan-tagging";
2618 MUST_BE_UNDEF(vlan_accept, "vlan-accept");
2619 MUST_BE_UNDEF(vlan_pvid, "vlan-pvid");
2620 }
2621 }
2622 else
2623 {
2624 const char use_err[] = "--%s requires --mode server";
2625 /*
2626 * When not in server mode, err if parameters are
2627 * specified which require --mode server.
2628 */
2629 MUST_BE_UNDEF(ifconfig_pool_defined, "ifconfig-pool");
2630 MUST_BE_UNDEF(ifconfig_pool_persist_filename, "ifconfig-pool-persist");
2631 MUST_BE_UNDEF(ifconfig_ipv6_pool_defined, "ifconfig-ipv6-pool");
2632 MUST_BE_UNDEF(real_hash_size, "hash-size");
2633 MUST_BE_UNDEF(virtual_hash_size, "hash-size");
2634 MUST_BE_UNDEF(learn_address_script, "learn-address");
2635 MUST_BE_UNDEF(client_connect_script, "client-connect");
2636 MUST_BE_UNDEF(client_crresponse_script, "client-crresponse");
2637 MUST_BE_UNDEF(client_disconnect_script, "client-disconnect");
2638 MUST_BE_UNDEF(client_config_dir, "client-config-dir");
2639 MUST_BE_UNDEF(ccd_exclusive, "ccd-exclusive");
2640 MUST_BE_UNDEF(enable_c2c, "client-to-client");
2641 MUST_BE_UNDEF(duplicate_cn, "duplicate-cn");
2642 MUST_BE_UNDEF(cf_max, "connect-freq");
2643 MUST_BE_UNDEF(cf_per, "connect-freq");
2646 "verify-client-cert");
2647 MUST_BE_FALSE(options->ssl_flags & SSLF_USERNAME_AS_COMMON_NAME, "username-as-common-name");
2648 MUST_BE_FALSE(options->ssl_flags & SSLF_AUTH_USER_PASS_OPTIONAL, "auth-user-pass-optional");
2650 {
2651 msg(M_WARN, "WARNING: setting tcp-nodelay on the client side will not "
2652 "affect the server. To have TCP_NODELAY in both direction use "
2653 "tcp-nodelay in the server configuration instead.");
2654 }
2655 MUST_BE_UNDEF(auth_user_pass_verify_script, "auth-user-pass-verify");
2656 MUST_BE_UNDEF(auth_token_generate, "auth-gen-token");
2657#if PORT_SHARE
2658 if (options->port_share_host || options->port_share_port)
2659 {
2660 msg(M_USAGE,
2661 "--port-share requires TCP server mode (--mode server --proto tcp-server)");
2662 }
2663#endif
2664 MUST_BE_UNDEF(stale_routes_check_interval, "stale-routes-check");
2665 MUST_BE_UNDEF(vlan_tagging, "vlan-tagging");
2666 MUST_BE_UNDEF(vlan_accept, "vlan-accept");
2667 MUST_BE_UNDEF(vlan_pvid, "vlan-pvid");
2668 MUST_BE_UNDEF(force_key_material_export, "force-key-material-export");
2669
2670 if (options->push_list.head)
2671 {
2672 msg(M_WARN, "Note: Using --push without --mode server is an "
2673 "unsupported configuration. Negotiation of OpenVPN "
2674 "features is expected to fail.");
2675 }
2676 }
2677
2678 /*
2679 * SSL/TLS mode sanity checks.
2680 */
2682 {
2683 msg(M_USAGE, "specify only one of --tls-server, --tls-client, or --secret");
2684 }
2685
2687 {
2688 msglvl_t msglevel = M_USAGE;
2690 {
2691 msglevel = M_INFO;
2692 }
2693
2694 msg(msglevel, "DEPRECATION: No tls-client or tls-server option in "
2695 "configuration detected. OpenVPN 2.8 will remove the "
2696 "functionality to run a VPN without TLS. "
2697 "See the examples section in the manual page for "
2698 "examples of a similar quick setup with peer-fingerprint. "
2699 "OpenVPN 2.7 allows using this configuration when using "
2700 "--allow-deprecated-insecure-static-crypto but you should move "
2701 "to a proper configuration using TLS as soon as possible.");
2702 }
2703
2705 {
2706 msg(M_WARN, "WARNING: POTENTIALLY DANGEROUS OPTION "
2707 "--verify-client-cert none|optional "
2708 "may accept clients which do not present a certificate");
2709 }
2710
2711 const unsigned int tls_version_max =
2713 const unsigned int tls_version_min =
2715
2716 if (tls_version_max > 0 && tls_version_max < tls_version_min)
2717 {
2718 msg(M_USAGE, "--tls-version-min bigger than --tls-version-max");
2719 }
2720
2722 {
2724#ifdef ENABLE_PKCS11
2725 if (!options->pkcs11_providers[0] && options->pkcs11_id)
2726 {
2727 msg(M_WARN, "Option pkcs11-id is ignored as no pkcs11-providers are specified");
2728 }
2729 else if (!options->pkcs11_providers[0] && options->pkcs11_id_management)
2730 {
2731 msg(M_WARN,
2732 "Option pkcs11-id-management is ignored as no pkcs11-providers are specified");
2733 }
2734
2735 if (options->pkcs11_providers[0])
2736 {
2737 if (options->pkcs11_id_management && options->pkcs11_id != NULL)
2738 {
2739 msg(M_USAGE,
2740 "Parameter --pkcs11-id cannot be used when --pkcs11-id-management is also specified.");
2741 }
2742 if (!options->pkcs11_id_management && options->pkcs11_id == NULL)
2743 {
2744 msg(M_USAGE,
2745 "Parameter --pkcs11-id or --pkcs11-id-management should be specified.");
2746 }
2747 const char use_err[] =
2748 "Parameter --%s cannot be used when --pkcs11-provider is also specified.";
2749 MUST_BE_UNDEF(cert_file, "cert");
2750 MUST_BE_UNDEF(priv_key_file, "key");
2751 MUST_BE_UNDEF(pkcs12_file, "pkcs12");
2752 MUST_BE_FALSE(options->management_flags & MF_EXTERNAL_KEY, "management-external-key");
2753 MUST_BE_FALSE(options->management_flags & MF_EXTERNAL_CERT, "management-external-cert");
2754#ifdef ENABLE_CRYPTOAPI
2755 MUST_BE_UNDEF(cryptoapi_cert, "cryptoapicert");
2756#endif
2757 }
2758 else
2759#endif /* ifdef ENABLE_PKCS11 */
2760#ifdef ENABLE_CRYPTOAPI
2762 {
2763 const char use_err[] =
2764 "Parameter --%s cannot be used when --cryptoapicert is also specified.";
2765 MUST_BE_UNDEF(cert_file, "cert");
2766 MUST_BE_UNDEF(priv_key_file, "key");
2767 MUST_BE_UNDEF(pkcs12_file, "pkcs12");
2768 MUST_BE_FALSE(options->management_flags & MF_EXTERNAL_KEY, "management-external-key");
2769 MUST_BE_FALSE(options->management_flags & MF_EXTERNAL_CERT, "management-external-cert");
2770 }
2771 else
2772#endif
2773 if (options->pkcs12_file)
2774 {
2775#ifdef ENABLE_CRYPTO_MBEDTLS
2776 msg(M_USAGE, "Parameter --pkcs12 cannot be used with the mbed TLS version of OpenVPN.");
2777#else
2778 const char use_err[] = "Parameter --%s cannot be used when --pkcs12 is also specified.";
2779 MUST_BE_UNDEF(ca_path, "capath");
2780 MUST_BE_UNDEF(cert_file, "cert");
2781 MUST_BE_UNDEF(priv_key_file, "key");
2782 MUST_BE_FALSE(options->management_flags & MF_EXTERNAL_KEY, "management-external-key");
2783 MUST_BE_FALSE(options->management_flags & MF_EXTERNAL_CERT, "management-external-cert");
2784#endif /* ifdef ENABLE_CRYPTO_MBEDTLS */
2785 }
2786 else /* cert/key from none of pkcs11, pkcs12, cryptoapi */
2787 {
2789 {
2790 msg(M_USAGE, "--key and --management-external-key are mutually exclusive");
2791 }
2793 {
2794 if (options->cert_file)
2795 {
2796 msg(M_USAGE, "--cert and --management-external-cert are mutually exclusive");
2797 }
2799 {
2800 msg(M_USAGE,
2801 "--management-external-cert must be used with --management-external-key");
2802 }
2803 }
2804 if (pull)
2805 {
2806 const int sum =
2808 + ((options->priv_key_file != NULL)
2810
2811 if (sum == 0)
2812 {
2814 {
2815 msg(M_USAGE, "No client-side authentication method is "
2816 "specified. You must use either "
2817 "--cert/--key, --pkcs12, or "
2818 "--auth-user-pass");
2819 }
2820 }
2821 else if (sum != 2)
2822 {
2823 msg(M_USAGE, "If you use one of --cert or --key, you must use them both");
2824 }
2825 }
2826 else
2827 {
2829 {
2831 "certificate file (--cert) or PKCS#12 file (--pkcs12)");
2832 }
2834 {
2836 "private key file (--key) or PKCS#12 file (--pkcs12)");
2837 }
2838 }
2839 }
2840 if (ce->tls_auth_file && ce->tls_crypt_file)
2841 {
2842 msg(M_USAGE, "--tls-auth and --tls-crypt are mutually exclusive");
2843 }
2845 && (ce->tls_auth_file || ce->tls_crypt_file))
2846 {
2847 msg(M_USAGE,
2848 "--tls-crypt-v2, --tls-auth and --tls-crypt are mutually exclusive in client mode");
2849 }
2850 }
2851 else
2852 {
2853 /*
2854 * Make sure user doesn't specify any TLS options
2855 * when in non-TLS mode.
2856 */
2857
2858 const char use_err[] = "Parameter %s can only be specified in TLS-mode, "
2859 "i.e. where --tls-server or --tls-client is also specified.";
2860
2861 MUST_BE_UNDEF(ca_file, "ca");
2862 MUST_BE_UNDEF(ca_path, "capath");
2863 MUST_BE_UNDEF(dh_file, "dh");
2864 MUST_BE_UNDEF(cert_file, "cert");
2865 MUST_BE_UNDEF(priv_key_file, "key");
2866#ifndef ENABLE_CRYPTO_MBEDTLS
2867 MUST_BE_UNDEF(pkcs12_file, "pkcs12");
2868#endif
2869 MUST_BE_UNDEF(cipher_list, "tls-cipher");
2870 MUST_BE_UNDEF(cipher_list_tls13, "tls-ciphersuites");
2871 MUST_BE_UNDEF(tls_cert_profile, "tls-cert-profile");
2872 MUST_BE_UNDEF(tls_verify, "tls-verify");
2873 MUST_BE_UNDEF(tls_export_peer_cert_dir, "tls-export-cert");
2874 MUST_BE_UNDEF(verify_x509_name, "verify-x509-name");
2875 MUST_BE_UNDEF(tls_timeout, "tls-timeout");
2876 MUST_BE_UNDEF(renegotiate_bytes, "reneg-bytes");
2877 MUST_BE_UNDEF(renegotiate_packets, "reneg-pkts");
2878 MUST_BE_UNDEF(renegotiate_seconds, "reneg-sec");
2879 MUST_BE_UNDEF(handshake_window, "hand-window");
2880 MUST_BE_UNDEF(transition_window, "tran-window");
2881 MUST_BE_UNDEF(tls_auth_file, "tls-auth");
2882 MUST_BE_UNDEF(tls_crypt_file, "tls-crypt");
2883 MUST_BE_UNDEF(tls_crypt_v2_file, "tls-crypt-v2");
2884 MUST_BE_UNDEF(single_session, "single-session");
2885 MUST_BE_UNDEF(push_peer_info, "push-peer-info");
2886 MUST_BE_UNDEF(tls_exit, "tls-exit");
2887 MUST_BE_UNDEF(crl_file, "crl-verify");
2888 MUST_BE_UNDEF(ns_cert_type, "ns-cert-type");
2889 MUST_BE_UNDEF(remote_cert_ku[0], "remote-cert-ku");
2890 MUST_BE_UNDEF(remote_cert_eku, "remote-cert-eku");
2891#ifdef ENABLE_PKCS11
2892 MUST_BE_UNDEF(pkcs11_providers[0], "pkcs11-providers");
2893 MUST_BE_UNDEF(pkcs11_private_mode[0], "pkcs11-private-mode");
2894 MUST_BE_UNDEF(pkcs11_id, "pkcs11-id");
2895 MUST_BE_UNDEF(pkcs11_id_management, "pkcs11-id-management");
2896#endif
2897
2898 if (pull)
2899 {
2900 msg(M_USAGE, use_err, "--pull");
2901 }
2902 }
2904 {
2905 msg(M_USAGE, "--auth-user-pass requires --pull");
2906 }
2907
2908 uninit_options(&defaults);
2909}
2910
2911#undef MUST_BE_UNDEF
2912#undef MUST_BE_FALSE
2913
2914static void
2916{
2917 const int dev = dev_type_enum(o->dev, o->dev_type);
2918
2920 {
2921 if (ce->proto == PROTO_TCP)
2922 {
2923 ce->proto = PROTO_TCP_SERVER;
2924 o->ce.proto = ce->proto;
2925 }
2926 }
2927
2928 if (o->mode != MODE_SERVER)
2929 {
2930 if (ce->proto == PROTO_TCP)
2931 {
2932 ce->proto = PROTO_TCP_CLIENT;
2933 o->ce.proto = ce->proto;
2934 }
2935 }
2936
2937 /* an option is present that requires local bind to enabled */
2938 bool need_bind = ce->local_port_defined || ce->bind_defined || ce->local_list;
2939
2940 /* socks proxy is enabled */
2941 bool uses_socks = ce->proto == PROTO_UDP && ce->socks_proxy_server;
2942
2943 /* If binding is not forced by an explicit option and we have (at least)
2944 * one of --tcp-client, --pull (or --client), or socks we do not bind
2945 * locally to have "normal" IP client behaviour of a random source port */
2946 if (!need_bind && (ce->proto == PROTO_TCP_CLIENT || uses_socks || o->pull))
2947 {
2948 ce->bind_local = false;
2949 }
2950
2951 if (!ce->bind_local)
2952 {
2953 ce->local_port = NULL;
2954 }
2955
2956 /* if protocol forcing is enabled, disable all protocols
2957 * except for the forced one
2958 */
2959 if (o->proto_force >= 0 && o->proto_force != ce->proto)
2960 {
2961 ce->flags |= CE_DISABLED;
2962 }
2963
2964 if (ce->http_proxy_options)
2965 {
2967 }
2968
2969 /* our socks code is not fully IPv6 enabled yet (TCP works, UDP not)
2970 * so fall back to IPv4-only (trac #1221)
2971 */
2972 if (ce->socks_proxy_server && proto_is_udp(ce->proto) && ce->af != AF_INET)
2973 {
2974 if (ce->af == AF_INET6)
2975 {
2976 msg(M_INFO, "WARNING: '--proto udp6' is not compatible with "
2977 "'--socks-proxy' today. Forcing IPv4 mode.");
2978 }
2979 else
2980 {
2981 msg(M_INFO, "NOTICE: dual-stack mode for '--proto udp' does not "
2982 "work correctly with '--socks-proxy' today. Forcing IPv4.");
2983 }
2984 ce->af = AF_INET;
2985 }
2986
2987 /*
2988 * Set MTU defaults
2989 */
2990 {
2991 if (!ce->tun_mtu_defined && !ce->link_mtu_defined)
2992 {
2993 ce->tun_mtu_defined = true;
2994 }
2995 if ((dev == DEV_TYPE_TAP) && !ce->tun_mtu_extra_defined)
2996 {
2997 ce->tun_mtu_extra_defined = true;
2999 }
3000 }
3001
3002 /*
3003 * If --mssfix is supplied without a parameter or not specified at all,
3004 * default it to --fragment value, if --fragment is specified and otherwise
3005 * to the default if tun-mtu is 1500
3006 */
3007 if (o->ce.mssfix_default)
3008 {
3009#ifdef ENABLE_FRAGMENT
3010 if (ce->fragment)
3011 {
3012 ce->mssfix = ce->fragment;
3013 }
3014 else
3015#endif
3016 if (ce->tun_mtu_defined)
3017 {
3018 if (o->ce.tun_mtu == TUN_MTU_DEFAULT)
3019 {
3020 /* We want to only set mssfix default value if we use a default
3021 * MTU Size, otherwise the different size of tun should either
3022 * already solve the problem or mssfix might artifically make the
3023 * payload packets smaller without mssfix 0 */
3024 ce->mssfix = MSSFIX_DEFAULT;
3025 ce->mssfix_encap = true;
3026 }
3027 else
3028 {
3029 /* We still apply the mssfix value but only adjust it to the
3030 * size of the tun interface. */
3031 ce->mssfix = ce->tun_mtu;
3032 ce->mssfix_fixed = true;
3033 }
3034 }
3035 }
3036
3037 /*
3038 * Set per-connection block tls-auth/crypt/crypto-v2 fields if undefined.
3039 *
3040 * At the end only one of these will be really set because the parser
3041 * logic prevents configurations where more are set.
3042 */
3043 if (!ce->tls_auth_file && !ce->tls_crypt_file && !ce->tls_crypt_v2_file)
3044 {
3048
3051
3054 }
3055
3056 /* Pre-cache tls-auth/crypt(-v2) key file if
3057 * keys were not already embedded in the config file.
3058 */
3062
3063
3065 {
3066 msg(M_WARN, "NOTICE: --explicit-exit-notify ignored for --proto tcp");
3068 }
3069}
3070
3071static void
3073{
3074 /* use the global port if none is specified */
3075 if (!le->port)
3076 {
3077 le->port = ce->local_port;
3078 }
3079 /* use the global proto if none is specified and
3080 * allow proto bindings on server mode only */
3081 if (!le->proto || mode == MODE_POINT_TO_POINT)
3082 {
3083 le->proto = ce->proto;
3084 }
3085}
3086
3087#ifdef _WIN32
3088/* If iservice is in use, we need def1 method for redirect-gateway */
3089static void
3091{
3092 if (opt->routes && opt->route_method == ROUTE_METHOD_SERVICE
3093 && opt->routes->flags & RG_REROUTE_GW && !(opt->routes->flags & RG_DEF1))
3094 {
3095 msg(M_INFO, "Flag 'def1' added to --redirect-gateway (iservice is in use)");
3096 opt->routes->flags |= RG_DEF1;
3097 }
3098}
3099#endif /* ifdef _WIN32 */
3100
3101/*
3102 * Save/Restore certain option defaults before --pull is applied.
3103 */
3104
3105static void
3107{
3112
3113 if (o->routes)
3114 {
3116 o->pre_connect->routes_defined = true;
3117 }
3118 if (o->routes_ipv6)
3119 {
3122 }
3123 if (o->client_nat)
3124 {
3127 }
3128
3131
3134
3136
3137 /* NCP related options that can be overwritten by a push */
3139 o->pre_connect->authname = o->authname;
3140
3141 /* Ping related options should be reset to the config values on reconnect */
3145
3146 /* Miscellaneous Options */
3147 o->pre_connect->comp = o->comp;
3148}
3149
3150void
3152{
3153 const struct options_pre_connect *pp = o->pre_connect;
3154 if (pp)
3155 {
3157 if (pp->tuntap_options_defined)
3158 {
3160 }
3161
3162 if (pp->routes_defined)
3163 {
3164 rol_check_alloc(o);
3166 }
3167 else
3168 {
3169 o->routes = NULL;
3170 }
3171
3172 if (pp->routes_ipv6_defined)
3173 {
3176 }
3177 else
3178 {
3179 o->routes_ipv6 = NULL;
3180 }
3181
3184
3187
3188 /* Free DNS options and reset them to pre-pull state */
3189 gc_free(&o->dns_options.gc);
3190 struct gc_arena dns_gc = gc_new();
3191 o->dns_options = clone_dns_options(&pp->dns_options, &dns_gc);
3192 o->dns_options.gc = dns_gc;
3193
3194 if (pp->client_nat_defined)
3195 {
3198 }
3199 else
3200 {
3201 o->client_nat = NULL;
3202 }
3203
3205
3206 o->ciphername = pp->ciphername;
3207 o->authname = pp->authname;
3208
3212
3213 /* Miscellaneous Options */
3214 o->comp = pp->comp;
3215 }
3216
3217 o->push_continuation = 0;
3221}
3222
3223static void
3225{
3226#ifdef _WIN32
3227 const int dev = dev_type_enum(options->dev, options->dev_type);
3228
3229 /* when using ovpn-dco, kernel doesn't send DHCP requests, so don't use it */
3233 {
3235 }
3236
3237 if ((dev == DEV_TYPE_TUN || dev == DEV_TYPE_TAP) && !options->route_delay_defined)
3238 {
3239 /* delay may only be necessary when we perform DHCP handshake */
3242 if ((options->mode == MODE_POINT_TO_POINT) && dhcp)
3243 {
3245 options->route_delay = 5; /* Vista sometimes has a race without this */
3246 }
3247 }
3248
3250 {
3252 options->ifconfig_noexec = false;
3253 }
3254
3256
3257 /*
3258 * Check consistency of --mode server options.
3259 */
3260 if (options->mode == MODE_SERVER)
3261 {
3262 /*
3263 * We need to explicitly set --tap-sleep because
3264 * we do not schedule event timers in the top-level context.
3265 */
3268 {
3270 }
3272 }
3273#endif /* ifdef _WIN32 */
3274
3275#ifdef DEFAULT_PKCS11_MODULE
3276 /* If p11-kit is present on the system then load its p11-kit-proxy.so
3277 * by default if the user asks for PKCS#11 without otherwise specifying
3278 * the module to use. */
3279 if (!options->pkcs11_providers[0] && (options->pkcs11_id || options->pkcs11_id_management))
3280 {
3281 options->pkcs11_providers[0] = DEFAULT_PKCS11_MODULE;
3282 }
3283#endif
3284}
3285
3286static void
3288{
3289 if (o->connection_list)
3290 {
3291 int i;
3292 for (i = 0; i < o->connection_list->len; ++i)
3293 {
3295 }
3296 }
3297 else
3298 {
3300 }
3301
3303
3304 if (dco_enabled(o))
3305 {
3306 if (o->enable_c2c)
3307 {
3308 msg(M_WARN, "Note: --client-to-client has no effect when using data "
3309 "channel offload: packets are always sent to the VPN "
3310 "interface and then routed based on the system routing table");
3311 }
3312
3313 if (o->renegotiate_bytes > 0 || o->renegotiate_packets)
3314 {
3315 msg(M_WARN, "Note: '--reneg-bytes' and '--reneg-pkts' are not supported "
3316 "by data channel offload; automatic key renegotiation "
3317 "mechanisms are sufficient for modern ciphers. "
3318 "Ignoring these options.");
3319 }
3320 }
3321}
3322
3323static void
3325{
3326 if (!o->pull && !(o->mode == MODE_SERVER))
3327 {
3328 /* If the cipher is not set, use the old default of BF-CBC. We will
3329 * warn that this is deprecated on cipher initialisation, no need
3330 * to warn here as well */
3331 if (!o->ciphername)
3332 {
3333 o->ciphername = "BF-CBC";
3334 }
3335 else
3336 {
3337 o->enable_ncp_fallback = true;
3338 }
3339 return;
3340 }
3341
3342 /* pull or P2MP mode */
3343 if (!o->ciphername)
3344 {
3345 /* We still need to set the ciphername to BF-CBC since various other
3346 * parts of OpenVPN assert that the ciphername is set */
3347 o->ciphername = "BF-CBC";
3348
3349 msg(M_INFO,
3350 "Note: --cipher is not set. OpenVPN versions before 2.5 "
3351 "defaulted to BF-CBC as fallback when cipher negotiation "
3352 "failed in this case. If you need this fallback please add "
3353 "'--data-ciphers-fallback BF-CBC' to your configuration "
3354 "and/or add BF-CBC to --data-ciphers. E.g. "
3355 "--data-ciphers %s:BF-CBC",
3356 o->ncp_ciphers_conf);
3357 }
3359 {
3360 msg(M_WARN,
3361 "DEPRECATED OPTION: --cipher set to '%s' but missing in "
3362 "--data-ciphers (%s). OpenVPN ignores --cipher for cipher "
3363 "negotiations. ",
3365 }
3366}
3367
3383static bool
3384need_compatibility_before(const struct options *o, unsigned int version)
3385{
3386 return o->backwards_compatible != 0 && o->backwards_compatible < version;
3387}
3388
3393static void
3395{
3396 /* TLS min version is not set */
3397 unsigned int tls_ver_min = (o->ssl_flags >> SSLF_TLS_VERSION_MIN_SHIFT) & SSLF_TLS_VERSION_MIN_MASK;
3398 if (tls_ver_min == 0)
3399 {
3400 unsigned int tls_ver_max = (o->ssl_flags >> SSLF_TLS_VERSION_MAX_SHIFT) & SSLF_TLS_VERSION_MAX_MASK;
3401 if (need_compatibility_before(o, 20307))
3402 {
3403 /* 2.3.6 and earlier have TLS 1.0 only, set minimum to TLS 1.0 */
3405 }
3406 else if (tls_ver_max == 0 || tls_ver_max >= TLS_VER_1_2)
3407 {
3408 /* Use TLS 1.2 as proper default */
3410 }
3411 else
3412 {
3413 /* Maximize the minimum version */
3414 o->ssl_flags |= (tls_ver_max << SSLF_TLS_VERSION_MIN_SHIFT);
3415 }
3416 }
3417
3418 if (need_compatibility_before(o, 20400))
3419 {
3420 if (!o->ciphername)
3421 {
3422 /* If ciphername is not set default to BF-CBC when targeting these
3423 * old versions that do not have NCP */
3424 o->ciphername = "BF-CBC";
3425 }
3426 /* Versions < 2.4.0 additionally might be compiled with --enable-small and
3427 * not have OCC strings required for "poor man's NCP" */
3428 o->enable_ncp_fallback = true;
3429 }
3430
3431 /* Versions < 2.5.0 do need --cipher in the list of accepted ciphers.
3432 * Version 2.4 probably does not need it but NCP was not so
3433 * good with 2.4 and ncp-disable might be more common on 2.4 peers.
3434 * Only do this iff --cipher is set (explicitly or by compat mode
3435 * < 2.4.0, see above). This is not 100% correct backwards compatible
3436 * behaviour but 2.5 already behaved like this */
3437 if (o->ciphername && need_compatibility_before(o, 20500)
3439 {
3441 }
3442
3443#ifdef USE_COMP
3444 /* Compression is deprecated and we do not want to announce support for it
3445 * by default anymore, additionally DCO breaks with compression.
3446 *
3447 * Disable compression by default starting with 2.6.0 if no other
3448 * compression related option has been explicitly set */
3449 if (!need_compatibility_before(o, 20600) && (o->comp.flags == 0))
3450 {
3451 if (!comp_non_stub_enabled(&o->comp))
3452 {
3454 }
3455 }
3456#else /* ifdef USE_COMP */
3458#endif
3459}
3460
3461static void
3463{
3464 if (!check_tls_prf_working())
3465 {
3466 msg(D_TLS_ERRORS, "Warning: TLS 1.0 PRF with MD5+SHA1 PRF is not "
3467 "supported by the TLS library. Your system does not support this "
3468 "calculation anymore or your security policy (e.g. FIPS 140-2) "
3469 "forbids it. Connections will only work with peers running "
3470 "OpenVPN 2.6.0 or higher)");
3471 if (o->mode == MODE_SERVER)
3472 {
3473 msg(M_WARN, "Automatically enabling option "
3474 "--force-tls-key-material-export");
3475 o->force_key_material_export = true;
3476 }
3477 }
3478}
3479
3480#if defined(_WIN32) || defined(TARGET_ANDROID)
3489static void
3491{
3492 struct dns_options *dns = &o->dns_options;
3493 struct tuntap_options *tt = &o->tuntap_options;
3494 if (!dns->servers)
3495 {
3496 /* Copy --dhcp-options to tuntap_options */
3497 struct dhcp_options *dhcp = &dns->from_dhcp;
3498 ASSERT(sizeof(dhcp->dns) == sizeof(tt->dns));
3499 ASSERT(sizeof(dhcp->dns6) == sizeof(tt->dns6));
3500 ASSERT(sizeof(dhcp->domain_search_list) == sizeof(tt->domain_search_list));
3501
3502 tt->domain = dhcp->domain;
3503 tt->dns_len = dhcp->dns_len;
3504 tt->dns6_len = dhcp->dns6_len;
3505
3506 memcpy(tt->dns, dhcp->dns, sizeof(tt->dns));
3507 memcpy(tt->dns6, dhcp->dns6, sizeof(tt->dns6));
3508
3509 tt->domain_search_list_len = dhcp->domain_search_list_len;
3510 for (size_t i = 0; i < SIZE(tt->domain_search_list); ++i)
3511 {
3512 tt->domain_search_list[i] = dhcp->domain_search_list[i];
3513 }
3514
3515 return;
3516 }
3517
3518#if defined(_WIN32)
3520 {
3521 return; /* Not in DHCP mode */
3522 }
3523#endif /* if defined(_WIN32) */
3524
3525 /* Copy --dns options to tuntap_options */
3526
3527 const struct dns_domain *d = dns->search_domains;
3528 if (d)
3529 {
3530 tt->domain_search_list_len = 0;
3531 }
3532
3533 while (d && tt->domain_search_list_len + 1 < N_SEARCH_LIST_LEN)
3534 {
3536 d = d->next;
3537 }
3538 if (d)
3539 {
3540 msg(M_WARN, "WARNING: couldn't copy all --dns search-domains to TUN/TAP");
3541 }
3542
3543 tt->dns_len = 0;
3544 tt->dns6_len = 0;
3545
3546 const struct dns_server *s = dns->servers;
3547 while (s)
3548 {
3549 bool non_standard_server_port = false;
3550 for (int i = 0; i < s->addr_count; ++i)
3551 {
3552 if (s->addr[i].port && s->addr[i].port != 53)
3553 {
3554 non_standard_server_port = true;
3555 break;
3556 }
3557 }
3558 if ((s->transport && s->transport != DNS_TRANSPORT_PLAIN)
3559 || (s->dnssec && s->dnssec != DNS_SECURITY_NO) || non_standard_server_port)
3560 {
3561 /* Skip servers requiring unsupported config to be set */
3562 s = s->next;
3563 }
3564 else
3565 {
3566 bool overflow = false;
3567 for (int i = 0; i < s->addr_count; ++i)
3568 {
3569 if (s->addr[i].family == AF_INET && tt->dns_len + 1 < N_DHCP_ADDR)
3570 {
3571 tt->dns[tt->dns_len++] = ntohl(s->addr[i].in.a4.s_addr);
3572 }
3573 else if (tt->dns6_len + 1 < N_DHCP_ADDR)
3574 {
3575 tt->dns6[tt->dns6_len++] = s->addr[i].in.a6;
3576 }
3577 else
3578 {
3579 overflow = true;
3580 }
3581 }
3582 if (overflow)
3583 {
3584 msg(M_WARN, "WARNING: couldn't copy all --dns server addresses to TUN/TAP");
3585 }
3587 return;
3588 }
3589 }
3590}
3591
3592#else /* if defined(_WIN32) || defined(TARGET_ANDROID) */
3593
3604static void
3605dhcp_options_postprocess_dns(struct options *o, struct env_set *es)
3606{
3607 struct gc_arena gc = gc_new();
3608 struct dns_options *dns = &o->dns_options;
3609
3610 if (is_tun_afunix(o->dev_node))
3611 {
3612 /* Disable running dns-updown script with lwipovpn */
3614 dns->updown = NULL;
3615 }
3616
3617 if (dns->servers || dns_updown_user_set(dns) || dns_updown_forced(dns))
3618 {
3619 /* Clean up env from --dhcp-option DNS config */
3620 struct buffer name = alloc_buf_gc(OPTION_PARM_SIZE, &gc);
3621 struct buffer value = alloc_buf_gc(OPTION_PARM_SIZE, &gc);
3622
3623 const int fo_count = o->foreign_option_index;
3624 o->foreign_option_index = 0;
3625
3626 for (int i = 1; i <= fo_count; ++i)
3627 {
3628 buf_clear(&name);
3629 buf_printf(&name, "foreign_option_%d", i);
3630 const char *env_str = env_set_get(es, BSTR(&name));
3631 const char *item_val = strchr(env_str, '=') + 1;
3632 buf_clear(&value);
3633 buf_printf(&value, "%s", item_val);
3634
3635 /* Remove foreign option item from env set */
3636 env_set_del(es, BSTR(&name));
3637
3638 item_val = BSTR(&value);
3639 if (strncmp(item_val, "dhcp-option ", 12) != 0
3640 || (strncmp(item_val + 12, "ADAPTER-DOMAIN-SUFFIX ", 22) != 0
3641 && strncmp(item_val + 12, "DOMAIN-SEARCH ", 14) != 0
3642 && strncmp(item_val + 12, "DOMAIN ", 7) != 0
3643 && strncmp(item_val + 12, "DNS6 ", 5) != 0
3644 && strncmp(item_val + 12, "DNS ", 4) != 0))
3645 {
3646 /* Re-set the item with potentially updated name */
3647 buf_clear(&name);
3648 buf_printf(&name, "foreign_option_%d", ++o->foreign_option_index);
3649 setenv_str(es, BSTR(&name), BSTR(&value));
3650 }
3651 }
3652 }
3653
3654 if (!dns->servers)
3655 {
3656 /* Copy --dhcp-options to dns_options */
3657 struct dhcp_options *dhcp = &dns->from_dhcp;
3658
3659 if (dhcp->dns_len || dhcp->dns6_len)
3660 {
3661 struct dns_domain **entry = &dns->search_domains;
3662 ALLOC_OBJ_CLEAR_GC(*entry, struct dns_domain, &dns->gc);
3663 struct dns_domain *new = *entry;
3664 new->name = dhcp->domain;
3665 entry = &new->next;
3666
3667 for (size_t i = 0; i < dhcp->domain_search_list_len; ++i)
3668 {
3669 ALLOC_OBJ_CLEAR_GC(*entry, struct dns_domain, &dns->gc);
3670 struct dns_domain *new = *entry;
3671 new->name = dhcp->domain_search_list[i];
3672 entry = &new->next;
3673 }
3674
3675 struct dns_server *server = dns_server_get(&dns->servers, 0, &dns->gc);
3676 const size_t max_addrs = SIZE(server->addr);
3677 for (size_t i = 0; i < dhcp->dns_len && server->addr_count < max_addrs; ++i)
3678 {
3679 server->addr[server->addr_count].in.a4.s_addr = htonl(dhcp->dns[i]);
3680 server->addr[server->addr_count].family = AF_INET;
3681 server->addr_count += 1;
3682 }
3683 for (size_t i = 0; i < dhcp->dns6_len && server->addr_count < max_addrs; ++i)
3684 {
3685 server->addr[server->addr_count].in.a6 = dhcp->dns6[i];
3686 server->addr[server->addr_count].family = AF_INET6;
3687 server->addr_count += 1;
3688 }
3689 }
3690 }
3691 else if (o->up_script && !dns_updown_user_set(dns) && !dns_updown_forced(dns))
3692 {
3693 /* Set foreign option env vars from --dns config */
3694 const struct dns_domain *d = dns->search_domains;
3695 while (d)
3696 {
3697 setenv_foreign_option(o, "DOMAIN", d->name, es);
3698 d = d->next;
3699 }
3700
3701 const struct dns_server *s = dns->servers;
3702 while (s)
3703 {
3704 bool non_standard_server_port = false;
3705 for (int i = 0; i < s->addr_count; ++i)
3706 {
3707 if (s->addr[i].port && s->addr[i].port != 53)
3708 {
3709 non_standard_server_port = true;
3710 break;
3711 }
3712 }
3713 if ((s->transport && s->transport != DNS_TRANSPORT_PLAIN)
3714 || (s->dnssec && s->dnssec != DNS_SECURITY_NO) || non_standard_server_port)
3715 {
3716 /* Skip servers requiring unsupported config to be set */
3717 s = s->next;
3718 }
3719 else
3720 {
3721 for (int i = 0; i < s->addr_count; ++i)
3722 {
3723 const char *option;
3724 const char *value;
3725 if (s->addr[i].family == AF_INET)
3726 {
3727 option = "DNS";
3728 value = print_in_addr_t(s->addr[i].in.a4.s_addr, IA_NET_ORDER, &gc);
3729 }
3730 else
3731 {
3732 option = "DNS6";
3733 value = print_in6_addr(s->addr[i].in.a6, 0, &gc);
3734 }
3735 setenv_foreign_option(o, option, value, es);
3736 }
3737 break;
3738 }
3739 }
3740 }
3741
3742 gc_free(&gc);
3743}
3744#endif /* if defined(_WIN32) || defined(TARGET_ANDROID) */
3745
3746static void
3748{
3749 int i;
3750 /*
3751 * Process helper-type options which map to other, more complex
3752 * sequences of options.
3753 */
3755 /* must be called after helpers that might set --mode */
3759
3763
3766 if (o->ncp_ciphers == NULL)
3767 {
3768 msg(M_USAGE, "--data-ciphers list contains unsupported ciphers or is too long.");
3769 }
3770
3771 if (o->remote_list && !o->connection_list)
3772 {
3773 /*
3774 * Convert remotes into connection list
3775 */
3776 const struct remote_list *rl = o->remote_list;
3777 for (i = 0; i < rl->len; ++i)
3778 {
3779 const struct remote_entry *re = rl->array[i];
3780 struct connection_entry ce = o->ce;
3781 struct connection_entry *ace;
3782
3783 ASSERT(re->remote);
3784 connection_entry_load_re(&ce, re);
3786 ASSERT(ace);
3787 *ace = ce;
3788 }
3789 }
3790 else if (!o->remote_list && !o->connection_list)
3791 {
3792 struct connection_entry *ace;
3794 ASSERT(ace);
3795 *ace = o->ce;
3796 }
3797
3799 for (i = 0; i < o->connection_list->len; ++i)
3800 {
3802 }
3803
3804 if (o->ce.local_list)
3805 {
3806 for (i = 0; i < o->ce.local_list->len; i++)
3807 {
3809 }
3810
3811 for (int i = 0; i < o->ce.local_list->len; i++)
3812 {
3813 if (o->ce.local_list->array[i]->proto == PROTO_TCP)
3814 {
3816 }
3817 else if (o->ce.local_list->array[i]->proto == PROTO_NONE)
3818 {
3819 o->ce.local_list->array[i]->proto = o->ce.proto;
3820 }
3821 }
3822 }
3823 else
3824 {
3825 /* if no 'local' directive was specified, convert the global port
3826 * setting to a listen entry */
3827 struct local_entry *e = alloc_local_entry(&o->ce, M_USAGE, &o->gc);
3828 ASSERT(e);
3829 e->port = o->ce.local_port;
3830 e->proto = o->ce.proto;
3831 }
3832
3833 /* use the same listen list for every outgoing connection */
3834 for (i = 0; i < o->connection_list->len; ++i)
3835 {
3837 }
3838
3839 if (o->tls_server)
3840 {
3841 if (o->dh_file && streq(o->dh_file, "none"))
3842 {
3843 o->dh_file = NULL;
3844 }
3845 }
3846 else if (o->dh_file)
3847 {
3848 /* DH file is only meaningful in a tls-server context. */
3849 msg(M_WARN, "WARNING: Ignoring option 'dh' in tls-client mode, please only "
3850 "include this in your server configuration");
3851 o->dh_file = NULL;
3852 }
3853#if ENABLE_MANAGEMENT
3854 if (o->http_proxy_override)
3855 {
3857 }
3858#endif
3859 if (!o->ca_file && !o->ca_path && o->verify_hash && o->verify_hash_depth == 0)
3860 {
3861 msg(M_INFO, "Using certificate fingerprint to verify peer (no CA "
3862 "option set). ");
3863 o->verify_hash_no_ca = true;
3864 }
3865
3866 if (o->config && streq(o->config, "stdin") && o->remap_sigusr1 == SIGHUP)
3867 {
3868 msg(M_USAGE, "Options 'config stdin' and 'remap-usr1 SIGHUP' are "
3869 "incompatible with each other.");
3870 }
3871
3872 if (dco_enabled(o))
3873 {
3874 /* check if any option should force disabling DCO */
3876 }
3877#ifdef USE_COMP
3878 if (dco_enabled(o))
3879 {
3881 }
3882#endif
3883
3884#ifdef _WIN32
3885 if (dco_enabled(o))
3886 {
3888 }
3889 else
3890 {
3892 }
3893#else /* _WIN32 */
3894 if (dco_enabled(o) && o->dev_node)
3895 {
3896 msg(M_WARN, "Note: ignoring --dev-node as it has no effect when using "
3897 "data channel offload");
3898 o->dev_node = NULL;
3899 }
3900#endif /* _WIN32 */
3901
3902 /* this depends on o->windows_driver, which is set above */
3904
3905 /* check that compression settings in the options are okay */
3907
3908 /*
3909 * Save certain parms before modifying options during connect, especially
3910 * when using --pull
3911 */
3912 if (o->pull)
3913 {
3915 }
3916 else
3917 {
3918#if defined(_WIN32) || defined(TARGET_ANDROID)
3920#else
3921 dhcp_options_postprocess_dns(o, es);
3922#endif
3923 }
3925 {
3927 }
3929}
3930
3931/*
3932 * Check file/directory sanity
3933 *
3934 */
3935/* Expect people using the stripped down version to know what they do */
3936#ifndef ENABLE_SMALL
3937
3938#define CHKACC_FILE (1 << 0)
3939#define CHKACC_DIRPATH (1 << 1)
3940#define CHKACC_FILEXSTWR (1 << 2)
3941#define CHKACC_ACPTSTDIN (1 << 3)
3942#define CHKACC_PRIVATE (1 << 4)
3943#define CHKACC_ACCEPT_URI (1 << 5)
3945static bool
3946check_file_access(const int type, const char *file, const int mode, const char *opt)
3947{
3948 int errcode = 0;
3949
3950 /* If no file configured, no errors to look for */
3951 if (!file)
3952 {
3953 return false;
3954 }
3955
3956 /* If stdin is allowed and the file name is 'stdin', then do no
3957 * further checks as stdin is always available
3958 */
3959 if ((type & CHKACC_ACPTSTDIN) && streq(file, "stdin"))
3960 {
3961 return false;
3962 }
3963
3964 /* file name is a URI if its first segment has ":" (i.e., before any "/")
3965 * Then no checks done if CHKACC_ACCEPT_URI is set and the URI does not start with "file:"
3966 */
3967 if ((type & CHKACC_ACCEPT_URI) && strchr(file, ':'))
3968 {
3969 if (!strncmp(file, "file:", 5))
3970 {
3971 file += 5;
3972 }
3973 else if (!strchr(file, '/') || strchr(file, '/') > strchr(file, ':'))
3974 {
3975 return false;
3976 }
3977 }
3978
3979 /* Is the directory path leading to the given file accessible? */
3980 if (type & CHKACC_DIRPATH)
3981 {
3982 char *fullpath =
3983 string_alloc(file, NULL); /* POSIX dirname() implementation may modify its arguments */
3984 char *dirpath = dirname(fullpath);
3985
3986 if (platform_access(dirpath, mode | X_OK) != 0)
3987 {
3988 errcode = errno;
3989 }
3990 free(fullpath);
3991 }
3992
3993 /* Is the file itself accessible? */
3994 if (!errcode && (type & CHKACC_FILE) && (platform_access(file, mode) != 0))
3995 {
3996 errcode = errno;
3997 }
3998
3999 /* If the file exists and is accessible, is it writable? */
4000 if (!errcode && (type & CHKACC_FILEXSTWR) && (platform_access(file, F_OK) == 0))
4001 {
4002 if (platform_access(file, W_OK) != 0)
4003 {
4004 errcode = errno;
4005 }
4006 }
4007
4008 /* Warn if a given private file is group/others accessible. */
4009 if (type & CHKACC_PRIVATE)
4010 {
4011 platform_stat_t st;
4012 if (platform_stat(file, &st))
4013 {
4014 msg(M_WARN | M_ERRNO, "WARNING: cannot stat file '%s'", file);
4015 }
4016#ifndef _WIN32
4017 else
4018 {
4019 if (st.st_mode & (S_IRWXG | S_IRWXO))
4020 {
4021 msg(M_WARN, "WARNING: file '%s' is group or others accessible", file);
4022 }
4023 }
4024#endif
4025 }
4026
4027 /* Scream if an error is found */
4028 if (errcode > 0)
4029 {
4030 msg(M_NOPREFIX | M_OPTERR | M_ERRNO, "%s fails with '%s'", opt, file);
4031 }
4032
4033 /* Return true if an error occurred */
4034 return (errcode != 0 ? true : false);
4035}
4036
4037/* A wrapper for check_file_access() which also takes a chroot directory.
4038 * If chroot is NULL, behaviour is exactly the same as calling check_file_access() directly,
4039 * otherwise it will look for the file inside the given chroot directory instead.
4040 */
4041static bool
4042check_file_access_chroot(const char *chroot, const int type, const char *file, const int mode,
4043 const char *opt)
4044{
4045 bool ret = false;
4046
4047 /* If no file configured, no errors to look for */
4048 if (!file)
4049 {
4050 return false;
4051 }
4052
4053 /* If chroot is set, look for the file/directory inside the chroot */
4054 if (chroot)
4055 {
4056 struct gc_arena gc = gc_new();
4057 struct buffer chroot_file;
4058
4059 chroot_file = prepend_dir(chroot, file, &gc);
4060 ret = check_file_access(type, BSTR(&chroot_file), mode, opt);
4061 gc_free(&gc);
4062 }
4063 else
4064 {
4065 /* No chroot in play, just call core file check function */
4066 ret = check_file_access(type, file, mode, opt);
4067 }
4068 return ret;
4069}
4070
4075static bool
4076check_file_access_chroot_inline(bool is_inline, const char *chroot, const int type,
4077 const char *file, const int mode, const char *opt)
4078{
4079 if (is_inline)
4080 {
4081 return false;
4082 }
4083
4084 return check_file_access_chroot(chroot, type, file, mode, opt);
4085}
4086
4091static bool
4092check_file_access_inline(bool is_inline, const int type, const char *file, const int mode,
4093 const char *opt)
4094{
4095 if (is_inline)
4096 {
4097 return false;
4098 }
4099
4100 return check_file_access(type, file, mode, opt);
4101}
4102
4103/*
4104 * Verifies that the path in the "command" that comes after certain script options (e.g., --up) is a
4105 * valid file with appropriate permissions.
4106 *
4107 * "command" consists of a path, optionally followed by a space, which may be
4108 * followed by arbitrary arguments. It is NOT a full shell command line -- shell expansion is not
4109 * performed.
4110 *
4111 * The path and arguments in "command" may be single- or double-quoted or escaped.
4112 *
4113 * The path is extracted from "command", then check_file_access() is called to check it. The
4114 * arguments, if any, are ignored.
4115 *
4116 * Note that the type, mode, and opt arguments to this routine are the same as the corresponding
4117 * check_file_access() arguments.
4118 */
4119static bool
4120check_cmd_access(const char *command, const char *opt, const char *chroot)
4121{
4122 struct argv argv;
4123 bool return_code;
4124
4125 /* If no command was set, there are no errors to look for */
4126 if (!command)
4127 {
4128 return false;
4129 }
4130
4131 /* Extract executable path and arguments */
4132 argv = argv_new();
4133 argv_parse_cmd(&argv, command);
4134
4135 /* if an executable is specified then check it; otherwise, complain */
4136 if (argv.argv[0])
4137 {
4138 /* Scripts requires R_OK as well, but that might fail on binaries which
4139 * only requires X_OK to function on Unix - a scenario not unlikely to
4140 * be seen on suid binaries.
4141 */
4142 return_code = check_file_access_chroot(chroot, CHKACC_FILE, argv.argv[0], X_OK, opt);
4143 }
4144 else
4145 {
4146 msg(M_NOPREFIX | M_OPTERR, "%s fails with '%s': No path to executable.", opt, command);
4147 return_code = true;
4148 }
4149
4150 argv_free(&argv);
4151
4152 return return_code;
4153}
4154
4155/*
4156 * Sanity check of all file/dir options. Checks that file/dir
4157 * is accessible by OpenVPN
4158 */
4159static void
4161{
4162 bool errs = false;
4163
4164 /* ** SSL/TLS/crypto related files ** */
4166 "--dh");
4167
4169 {
4171 R_OK, "--ca");
4172 }
4173
4175 "--capath");
4176
4178 options->cert_file, R_OK, "--cert");
4179
4181 options->extra_certs_file, R_OK, "--extra-certs");
4182
4184 {
4187 options->priv_key_file, R_OK, "--key");
4188 }
4189
4191 options->pkcs12_file, R_OK, "--pkcs12");
4192
4194 {
4196 R_OK | X_OK, "--crl-verify directory");
4197 }
4198 else
4199 {
4200 errs |=
4202 CHKACC_FILE, options->crl_file, R_OK, "--crl-verify");
4203 }
4204
4206 {
4207 errs |=
4209 options->tls_export_peer_cert_dir, W_OK, "--tls-export-cert");
4210 }
4211
4213 for (int i = 0; i < options->connection_list->len; ++i)
4214 {
4216
4218 ce->tls_auth_file, R_OK, "--tls-auth");
4220 ce->tls_crypt_file, R_OK, "--tls-crypt");
4222 ce->tls_crypt_v2_file, R_OK, "--tls-crypt-v2");
4223 }
4224
4225 errs |=
4227 options->shared_secret_file, R_OK, "--secret");
4228
4230 R_OK | W_OK, "--replay-persist");
4231
4232 /* ** Password files ** */
4234 options->key_pass_file, R_OK, "--askpass");
4235#ifdef ENABLE_MANAGEMENT
4236 errs |=
4238 options->management_user_pass, R_OK, "--management user/password file");
4239#endif /* ENABLE_MANAGEMENT */
4242 options->auth_user_pass_file, R_OK, "--auth-user-pass");
4243 /* ** System related ** */
4244 errs |= check_file_access(CHKACC_FILE, options->chroot_dir, R_OK | X_OK, "--chroot directory");
4246 "--writepid");
4247
4248 /* ** Log related ** */
4250 "--status");
4251
4252 /* ** Config related ** */
4254 R_OK | X_OK, "--client-config-dir");
4256 R_OK | W_OK | X_OK, "Temporary directory (--tmp-dir)");
4257
4258 if (errs)
4259 {
4260 msg(M_USAGE, "Please correct these errors.");
4261 }
4262}
4263#endif /* !ENABLE_SMALL */
4264
4265/*
4266 * Sanity check on options.
4267 * Also set some options based on other
4268 * options.
4269 */
4270void
4272{
4275#ifndef ENABLE_SMALL
4277#endif /* !ENABLE_SMALL */
4278}
4279
4280/*
4281 * Sanity check on options after more options were pulled from server.
4282 * Also time to modify some options based on other options.
4283 */
4284bool
4286{
4287 bool success = dns_options_verify(D_PUSH_ERRORS, &o->dns_options);
4288 if (success)
4289 {
4291#if defined(_WIN32) || defined(TARGET_ANDROID)
4293#else
4294 dhcp_options_postprocess_dns(o, es);
4295#endif
4296 }
4297 return success;
4298}
4299
4300/*
4301 * Build an options string to represent data channel encryption options.
4302 * This string must match exactly between peers. The keysize is checked
4303 * separately by read_key().
4304 *
4305 * The following options must match on both peers:
4306 *
4307 * Tunnel options:
4308 *
4309 * --dev tun|tap [unit number need not match]
4310 * --dev-type tun|tap
4311 * --link-mtu
4312 * --udp-mtu
4313 * --tun-mtu
4314 * --proto udp
4315 * --proto tcp-client [matched with --proto tcp-server
4316 * on the other end of the connection]
4317 * --proto tcp-server [matched with --proto tcp-client on
4318 * the other end of the connection]
4319 * --tun-ipv6
4320 * --ifconfig x y [matched with --ifconfig y x on
4321 * the other end of the connection]
4322 *
4323 * --comp-lzo
4324 * --compress alg
4325 * --fragment
4326 *
4327 * Crypto Options:
4328 *
4329 * --cipher
4330 * --auth
4331 * --secret
4332 *
4333 * SSL Options:
4334 *
4335 * --tls-auth
4336 * --tls-client [matched with --tls-server on
4337 * the other end of the connection]
4338 * --tls-server [matched with --tls-client on
4339 * the other end of the connection]
4340 */
4341char *
4342options_string(const struct options *o, const struct frame *frame, struct tuntap *tt,
4343 openvpn_net_ctx_t *ctx, bool remote, struct gc_arena *gc)
4344{
4345 struct buffer out = alloc_buf(OPTION_LINE_SIZE);
4346 bool tt_local = false;
4347
4348 buf_printf(&out, "V4");
4349
4350 /*
4351 * Tunnel Options
4352 */
4353
4354 buf_printf(&out, ",dev-type %s", dev_type_string(o->dev, o->dev_type));
4355 /* the link-mtu that we send has only a meaning if have a fixed
4356 * cipher (p2p) or have a fallback cipher configured for older non
4357 * ncp clients. But not sending it will make even 2.4 complain
4358 * about it being missing. So still send it. */
4359 buf_printf(&out, ",link-mtu %u", (unsigned int)calc_options_string_link_mtu(o, frame));
4360
4361 if (o->ce.occ_mtu != 0)
4362 {
4363 buf_printf(&out, ",tun-mtu %d", o->ce.occ_mtu);
4364 }
4365 else
4366 {
4367 buf_printf(&out, ",tun-mtu %d", frame->tun_mtu);
4368 }
4369
4370 buf_printf(&out, ",proto %s", proto_remote(o->ce.proto, remote));
4371
4372 bool p2p_nopull = o->mode == MODE_POINT_TO_POINT && !PULL_DEFINED(o);
4373 /* send tun_ipv6 only in peer2peer mode - in client/server mode, it
4374 * is usually pushed by the server, triggering a non-helpful warning
4375 */
4376 if (o->ifconfig_ipv6_local && p2p_nopull)
4377 {
4378 buf_printf(&out, ",tun-ipv6");
4379 }
4380
4381 /*
4382 * Try to get ifconfig parameters into the options string.
4383 * If tt is undefined, make a temporary instantiation.
4384 */
4385 if (!tt)
4386 {
4387 tt = init_tun(o->dev, o->dev_type, o->topology, o->ifconfig_local,
4388 o->ifconfig_remote_netmask, o->ifconfig_ipv6_local, o->ifconfig_ipv6_netbits,
4389 o->ifconfig_ipv6_remote, NULL, NULL, false, NULL, ctx, NULL);
4390 if (tt)
4391 {
4392 tt_local = true;
4393 }
4394 }
4395
4396 if (tt && p2p_nopull)
4397 {
4398 const char *ios = ifconfig_options_string(tt, remote, o->ifconfig_nowarn, gc);
4399 if (ios && strlen(ios))
4400 {
4401 buf_printf(&out, ",ifconfig %s", ios);
4402 }
4403 }
4404 if (tt_local)
4405 {
4406 free(tt);
4407 tt = NULL;
4408 }
4409
4410#ifdef USE_COMP
4411 if (o->comp.alg != COMP_ALG_UNDEF)
4412 {
4413 buf_printf(&out, ",comp-lzo"); /* for compatibility, this simply indicates that compression
4414 context is active, not necessarily LZO per-se */
4415 }
4416#endif
4417
4418#ifdef ENABLE_FRAGMENT
4419 if (o->ce.fragment)
4420 {
4421 buf_printf(&out, ",mtu-dynamic");
4422 }
4423#endif
4424
4425#define TLS_CLIENT (o->tls_client)
4426#define TLS_SERVER (o->tls_server)
4427
4428 /*
4429 * Key direction
4430 */
4431 {
4432 const char *kd = keydirection2ascii(o->key_direction, remote, false);
4433 if (kd)
4434 {
4435 buf_printf(&out, ",keydir %s", kd);
4436 }
4437 }
4438
4439 /*
4440 * Crypto Options
4441 */
4442 if (o->shared_secret_file || TLS_CLIENT || TLS_SERVER)
4443 {
4444 struct key_type kt;
4445
4446 ASSERT((o->shared_secret_file != NULL) + (TLS_CLIENT == true) + (TLS_SERVER == true) <= 1);
4447
4448 /* Skip resolving BF-CBC to allow SSL libraries without BF-CBC
4449 * to work here in the default configuration */
4450 const char *ciphername = o->ciphername;
4451 int keysize = 0;
4452
4453 if (strcmp(o->ciphername, "BF-CBC") == 0)
4454 {
4455 init_key_type(&kt, "none", o->authname, true, false);
4456 keysize = 128;
4457 }
4458 else
4459 {
4460 init_key_type(&kt, o->ciphername, o->authname, true, false);
4461 ciphername = cipher_kt_name(kt.cipher);
4462 if (cipher_defined(o->ciphername))
4463 {
4464 keysize = cipher_kt_key_size(kt.cipher) * 8;
4465 }
4466 }
4467 /* Only announce the cipher to our peer if we are willing to
4468 * support it */
4469 if (p2p_nopull || tls_item_in_cipher_list(ciphername, o->ncp_ciphers))
4470 {
4471 buf_printf(&out, ",cipher %s", ciphername);
4472 }
4473 buf_printf(&out, ",auth %s", md_kt_name(kt.digest));
4474 buf_printf(&out, ",keysize %d", keysize);
4475 if (o->shared_secret_file)
4476 {
4477 buf_printf(&out, ",secret");
4478 }
4479
4480#ifdef ENABLE_PREDICTION_RESISTANCE
4481 if (o->use_prediction_resistance)
4482 {
4483 buf_printf(&out, ",use-prediction-resistance");
4484 }
4485#endif
4486 }
4487
4488 /*
4489 * SSL Options
4490 */
4491 {
4492 if (TLS_CLIENT || TLS_SERVER)
4493 {
4494 if (o->ce.tls_auth_file)
4495 {
4496 buf_printf(&out, ",tls-auth");
4497 }
4498 /* Not adding tls-crypt here, because we won't reach this code if
4499 * tls-auth/tls-crypt does not match. Removing tls-auth here would
4500 * break stuff, so leaving that in place. */
4501
4502 buf_printf(&out, ",key-method %d", KEY_METHOD_2);
4503 }
4504
4505 if (remote)
4506 {
4507 if (TLS_CLIENT)
4508 {
4509 buf_printf(&out, ",tls-server");
4510 }
4511 else if (TLS_SERVER)
4512 {
4513 buf_printf(&out, ",tls-client");
4514 }
4515 }
4516 else
4517 {
4518 if (TLS_CLIENT)
4519 {
4520 buf_printf(&out, ",tls-client");
4521 }
4522 else if (TLS_SERVER)
4523 {
4524 buf_printf(&out, ",tls-server");
4525 }
4526 }
4527 }
4528
4529#undef TLS_CLIENT
4530#undef TLS_SERVER
4531
4532 return BSTR(&out);
4533}
4534
4535/*
4536 * Compare option strings for equality.
4537 * If the first two chars of the strings differ, it means that
4538 * we are looking at different versions of the options string,
4539 * therefore don't compare them and return true.
4540 */
4541
4542bool
4543options_cmp_equal(char *actual, const char *expected)
4544{
4545 return options_cmp_equal_safe(actual, expected, strlen(actual) + 1);
4546}
4547
4548void
4549options_warning(char *actual, const char *expected)
4550{
4551 options_warning_safe(actual, expected, strlen(actual) + 1);
4552}
4553
4554static const char *
4555options_warning_extract_parm1(const char *option_string, struct gc_arena *gc_ret)
4556{
4557 struct gc_arena gc = gc_new();
4559 char *p = gc_malloc(OPTION_PARM_SIZE, false, &gc);
4560 const char *ret;
4561
4562 buf_parse(&b, ' ', p, OPTION_PARM_SIZE);
4563 ret = string_alloc(p, gc_ret);
4564 gc_free(&gc);
4565 return ret;
4566}
4567
4568static void
4570 const bool report_inconsistent, const char *p1,
4571 const struct buffer *b2_src, const char *b1_name,
4572 const char *b2_name)
4573{
4574 /* We will stop sending 'key-method', 'keydir', 'proto' and 'tls-auth' in
4575 * OCC in a future version (because it's not useful). To reduce questions
4576 * when interoperating, we no longer printing a warning about it.
4577 */
4578 if (strprefix(p1, "key-method ") || strprefix(p1, "keydir ") || strprefix(p1, "proto ")
4579 || streq(p1, "tls-auth") || strprefix(p1, "tun-ipv6") || strprefix(p1, "cipher "))
4580 {
4581 return;
4582 }
4583
4584 if (strlen(p1) > 0)
4585 {
4586 struct gc_arena gc = gc_new();
4587 struct buffer b2 = *b2_src;
4589 char *p2 = gc_malloc(OPTION_PARM_SIZE, false, &gc);
4590
4591 while (buf_parse(&b2, delim, p2, OPTION_PARM_SIZE))
4592 {
4593 if (strlen(p2))
4594 {
4596
4597 if (!strcmp(p1, p2))
4598 {
4599 goto done;
4600 }
4601 if (!strcmp(p1_prefix, p2_prefix))
4602 {
4604 {
4605 msg(msglevel, "WARNING: '%s' is used inconsistently, %s='%s', %s='%s'",
4607 safe_print(p2, &gc));
4608 }
4609 goto done;
4610 }
4611 }
4612 }
4613
4614 msg(msglevel, "WARNING: '%s' is present in %s config but missing in %s config, %s='%s'",
4616
4617done:
4618 gc_free(&gc);
4619 }
4620}
4621
4622static void
4624 const bool report_inconsistent, const struct buffer *b1_src,
4625 const struct buffer *b2_src, const char *b1_name, const char *b2_name)
4626{
4627 struct gc_arena gc = gc_new();
4628 struct buffer b = *b1_src;
4629 char *p = gc_malloc(OPTION_PARM_SIZE, true, &gc);
4630
4631 while (buf_parse(&b, delim, p, OPTION_PARM_SIZE))
4632 {
4634 b2_name);
4635 }
4636
4637 gc_free(&gc);
4638}
4639
4640static void
4641options_warning_safe_ml(const msglvl_t msglevel, char *actual, const char *expected, size_t actual_n)
4642{
4643 struct gc_arena gc = gc_new();
4644
4645 if (actual_n > 0)
4646 {
4647 struct buffer local = alloc_buf_gc(OPTION_PARM_SIZE + 16, &gc);
4648 struct buffer remote = alloc_buf_gc(OPTION_PARM_SIZE + 16, &gc);
4649 actual[actual_n - 1] = 0;
4650
4651 buf_printf(&local, "version %s", expected);
4652 buf_printf(&remote, "version %s", actual);
4653
4654 options_warning_safe_scan1(msglevel, ',', true, &local, &remote, "local", "remote");
4655
4656 options_warning_safe_scan1(msglevel, ',', false, &remote, &local, "remote", "local");
4657 }
4658
4659 gc_free(&gc);
4660}
4661
4662bool
4663options_cmp_equal_safe(char *actual, const char *expected, size_t actual_n)
4664{
4665 struct gc_arena gc = gc_new();
4666 bool ret = true;
4667
4668 if (actual_n > 0)
4669 {
4670 actual[actual_n - 1] = 0;
4671 if (strncmp(actual, expected, 2))
4672 {
4673 msg(D_SHOW_OCC, "NOTE: Options consistency check may be skewed by version differences");
4674 options_warning_safe_ml(D_SHOW_OCC, actual, expected, actual_n);
4675 }
4676 else
4677 {
4678 ret = !strcmp(actual, expected);
4679 }
4680 }
4681 gc_free(&gc);
4682 return ret;
4683}
4684
4685void
4686options_warning_safe(char *actual, const char *expected, size_t actual_n)
4687{
4688 options_warning_safe_ml(D_SHOW_OCC, actual, expected, actual_n);
4689}
4690
4691const char *
4692options_string_version(const char *s, struct gc_arena *gc)
4693{
4694 struct buffer out = alloc_buf_gc(4, gc);
4695 strncpynt((char *)BPTR(&out), s, 3);
4696 return BSTR(&out);
4697}
4698
4699char *
4701{
4702 char *ret = NULL;
4703 const size_t opt_name_len = strlen(opt_name);
4704
4705 const char *p = options_string;
4706 while (p)
4707 {
4708 if (0 == strncmp(p, opt_name, opt_name_len) && strlen(p) > (opt_name_len + 1)
4709 && p[opt_name_len] == ' ')
4710 {
4711 /* option found, extract value */
4712 const char *start = &p[opt_name_len + 1];
4713 const char *end = strchr(p, ',');
4714 size_t val_len = end ? end - start : strlen(start);
4715 ret = gc_malloc(val_len + 1, true, gc);
4716 memcpy(ret, start, val_len);
4717 break;
4718 }
4719 p = strchr(p, ',');
4720 if (p)
4721 {
4722 p++; /* skip delimiter */
4723 }
4724 }
4725 return ret;
4726}
4727
4728/*
4729 * parse/print topology coding
4730 */
4731
4732int
4733parse_topology(const char *str, const msglvl_t msglevel)
4734{
4735 if (streq(str, "net30"))
4736 {
4737 return TOP_NET30;
4738 }
4739 else if (streq(str, "p2p"))
4740 {
4741 return TOP_P2P;
4742 }
4743 else if (streq(str, "subnet"))
4744 {
4745 return TOP_SUBNET;
4746 }
4747 else
4748 {
4749 msg(msglevel, "--topology must be net30, p2p, or subnet");
4750 return TOP_UNDEF;
4751 }
4752}
4753
4754const char *
4755print_topology(const int topology)
4756{
4757 switch (topology)
4758 {
4759 case TOP_UNDEF:
4760 return "undef";
4761
4762 case TOP_NET30:
4763 return "net30";
4764
4765 case TOP_P2P:
4766 return "p2p";
4767
4768 case TOP_SUBNET:
4769 return "subnet";
4770
4771 default:
4772 return "unknown";
4773 }
4774}
4775
4776/*
4777 * Manage auth-retry variable
4778 */
4779
4780static int global_auth_retry; /* GLOBAL */
4781
4782int
4784{
4785 return global_auth_retry;
4786}
4787
4788bool
4789auth_retry_set(const msglvl_t msglevel, const char *option)
4790{
4791 if (streq(option, "interact"))
4792 {
4794 }
4795 else if (streq(option, "nointeract"))
4796 {
4798 }
4799 else if (streq(option, "none"))
4800 {
4802 }
4803 else
4804 {
4805 msg(msglevel, "--auth-retry method must be 'interact', 'nointeract', or 'none'");
4806 return false;
4807 }
4808 return true;
4809}
4810
4811const char *
4813{
4814 switch (global_auth_retry)
4815 {
4816 case AR_NONE:
4817 return "none";
4818
4819 case AR_NOINTERACT:
4820 return "nointeract";
4821
4822 case AR_INTERACT:
4823 return "interact";
4824
4825 default:
4826 return "???";
4827 }
4828}
4829
4830/*
4831 * Print the help message.
4832 */
4833void
4835{
4836 FILE *fp = msg_fp(0);
4837
4838#ifdef ENABLE_SMALL
4839
4840 fprintf(fp, "Usage message not available\n");
4841
4842#else
4843
4844 struct options o;
4845 init_options(&o, true);
4846
4852 fflush(fp);
4853
4854#endif /* ENABLE_SMALL */
4855
4856 openvpn_exit(OPENVPN_EXIT_STATUS_USAGE); /* exit point */
4857}
4858
4859void
4861{
4862 msg(M_WARN | M_NOPREFIX, "Use --help for more information.");
4863 openvpn_exit(OPENVPN_EXIT_STATUS_USAGE); /* exit point */
4864}
4865
4866#ifdef _WIN32
4867void
4868show_windows_version(const unsigned int flags)
4869{
4870 struct gc_arena gc = gc_new();
4871 msg(flags, "Windows version: %s", win32_version_string(&gc));
4872 gc_free(&gc);
4873}
4874#endif
4875
4876void
4877show_dco_version(const unsigned int flags)
4878{
4879#ifdef ENABLE_DCO
4880 struct gc_arena gc = gc_new();
4881 msg(flags, "DCO version: %s", dco_version_string(&gc));
4882 gc_free(&gc);
4883#endif
4884}
4885
4886void
4887show_library_versions(const unsigned int flags)
4888{
4889#ifdef ENABLE_LZO
4890#define LZO_LIB_VER_STR ", LZO ", lzo_version_string()
4891#else
4892#define LZO_LIB_VER_STR "", ""
4893#endif
4894
4895 msg(flags, "library versions: %s%s%s", get_ssl_library_version(), LZO_LIB_VER_STR);
4896
4897#undef LZO_LIB_VER_STR
4898}
4899
4900static void
4902{
4905#ifdef _WIN32
4907#endif
4909 msg(M_INFO | M_NOPREFIX, "Originally developed by James Yonan");
4910 msg(M_INFO | M_NOPREFIX, "Copyright (C) 2002-2026 OpenVPN Inc <sales@openvpn.net>");
4911#ifndef ENABLE_SMALL
4912#ifdef CONFIGURE_DEFINES
4913 msg(M_INFO | M_NOPREFIX, "Compile time defines: %s", CONFIGURE_DEFINES);
4914#endif
4915#ifdef CONFIGURE_SPECIAL_BUILD
4916 msg(M_INFO | M_NOPREFIX, "special build: %s", CONFIGURE_SPECIAL_BUILD);
4917#endif
4918#endif
4920}
4921
4922void
4923notnull(const char *arg, const char *description)
4924{
4925 if (!arg)
4926 {
4927 msg(M_USAGE, "You must define %s", description);
4928 }
4929}
4930
4931bool
4932string_defined_equal(const char *s1, const char *s2)
4933{
4934 if (s1 && s2)
4935 {
4936 return !strcmp(s1, s2);
4937 }
4938 else
4939 {
4940 return false;
4941 }
4942}
4943
4944#if 0
4945static void
4946ping_rec_err(msglvl_t msglevel)
4947{
4948 msg(msglevel, "only one of --ping-exit or --ping-restart options may be specified");
4949}
4950#endif
4951
4952#ifdef _WIN32 /* This function is only used when compiling on Windows */
4953static unsigned int
4954atou(const char *str)
4955{
4956 unsigned int val = 0;
4957 sscanf(str, "%u", &val);
4958 return val;
4959}
4960#endif
4961
4962#define VERIFY_PERMISSION(mask) \
4963 { \
4964 if (!verify_permission(p[0], file, line, (mask), permission_mask, option_types_found, \
4965 msglevel, options, is_inline)) \
4966 { \
4967 goto err; \
4968 } \
4969 }
4970
4971static bool
4972verify_permission(const char *name, const char *file, int line, const unsigned int type,
4973 const unsigned int allowed, unsigned int *found, const msglvl_t msglevel,
4974 struct options *options, bool is_inline)
4975{
4976 if (!(type & allowed))
4977 {
4978 msg(msglevel, "option '%s' cannot be used in this context (%s)", name, file);
4979 return false;
4980 }
4981
4982 if (is_inline && !(type & OPT_P_INLINE))
4983 {
4984 msg(msglevel, "option '%s' is not expected to be inline (%s:%d)", name, file, line);
4985 return false;
4986 }
4987
4988 if (found)
4989 {
4990 *found |= type;
4991 }
4992
4993#ifndef ENABLE_SMALL
4994 /* Check if this options is allowed in connection block,
4995 * but we are currently not in a connection block
4996 * unless this is a pushed option.
4997 * Parsing a connection block uses a temporary options struct without
4998 * connection_list
4999 */
5000
5001 if ((type & OPT_P_CONNECTION) && options->connection_list && !(allowed & OPT_P_PULL_MODE))
5002 {
5003 if (file)
5004 {
5005 msg(M_WARN, "Option '%s' in %s:%d is ignored by previous <connection> blocks ", name,
5006 file, line);
5007 }
5008 else
5009 {
5010 msg(M_WARN, "Option '%s' is ignored by previous <connection> blocks", name);
5011 }
5012 }
5013#endif
5014 return true;
5015}
5016
5017/*
5018 * Check that an option doesn't have too
5019 * many parameters.
5020 */
5021
5022#define NM_QUOTE_HINT (1 << 0)
5023
5024static bool
5025no_more_than_n_args(const msglvl_t msglevel, char *p[], const int max, const unsigned int flags)
5026{
5027 const int len = string_array_len((const char **)p);
5028
5029 if (!len)
5030 {
5031 return false;
5032 }
5033
5034 if (len > max)
5035 {
5036 msg(msglevel, "the --%s directive should have at most %d parameter%s.%s", p[0], max - 1,
5037 max >= 3 ? "s" : "",
5038 (flags & NM_QUOTE_HINT)
5039 ? " To pass a list of arguments as one of the parameters, try enclosing them in double quotes (\"\")."
5040 : "");
5041 return false;
5042 }
5043 else
5044 {
5045 return true;
5046 }
5047}
5048
5049static inline msglvl_t
5051{
5052 return options->forward_compatible ? M_WARN : msglevel;
5053}
5054
5055#define RESET_OPTION_ROUTES(option_ptr, field) \
5056 if (option_ptr) \
5057 { \
5058 option_ptr->field = NULL; \
5059 option_ptr->flags = 0; \
5060 }
5061
5062void
5063remove_option(struct context *c, struct options *options, char *p[], bool is_inline,
5064 const char *file, int line, const msglvl_t msglevel,
5065 const unsigned int permission_mask, unsigned int *option_types_found,
5066 struct env_set *es)
5067{
5068 msglvl_t msglevel_fc = msglevel_forward_compatible(options, msglevel);
5069
5070 if (streq(p[0], "ifconfig") && !p[1])
5071 {
5073 options->ifconfig_local = NULL;
5075 }
5076 else if (streq(p[0], "ifconfig-ipv6") && !p[1])
5077 {
5082 }
5083 else if (streq(p[0], "route") && !p[1])
5084 {
5086 if (c->c1.route_list)
5087 {
5089 &c->net_ctx);
5091 }
5092 }
5093 else if (streq(p[0], "route-ipv6") && !p[1])
5094 {
5096 if (c->c1.route_ipv6_list)
5097 {
5099 es, &c->net_ctx);
5101 }
5102 }
5103 else if (streq(p[0], "route-gateway") && !p[1])
5104 {
5108 }
5109 else if (streq(p[0], "route-metric") && !p[1])
5110 {
5113 }
5114 else if (streq(p[0], "push-continuation") && !p[1])
5115 {
5118 }
5119 else if ((streq(p[0], "redirect-gateway") || streq(p[0], "redirect-private")) && !p[1])
5120 {
5122 if (options->routes)
5123 {
5124 options->routes->flags = 0;
5125 }
5126 if (options->routes_ipv6)
5127 {
5129 }
5130 env_set_del(es, "route_redirect_gateway_ipv4");
5131 env_set_del(es, "route_redirect_gateway_ipv6");
5132 }
5133 else if (streq(p[0], "dns") && !p[1])
5134 {
5138 }
5139 else if (streq(p[0], "topology") && !p[1])
5140 {
5144 }
5145 else if (streq(p[0], "tun-mtu") && !p[1])
5146 {
5149 options->ce.tun_mtu_defined = false;
5150 options->ce.occ_mtu = 0;
5151 }
5152 else if (streq(p[0], "block-ipv6") && !p[1])
5153 {
5155 options->block_ipv6 = false;
5156 }
5157#if defined(_WIN32) || defined(TARGET_ANDROID)
5158 else if (streq(p[0], "dhcp-option") && !p[1])
5159 {
5162
5163 o->domain = NULL;
5164 o->netbios_scope = NULL;
5165 o->netbios_node_type = 0;
5166 o->dns6_len = 0;
5167 memset(o->dns6, 0, sizeof(o->dns6));
5168 o->dns_len = 0;
5169 memset(o->dns, 0, sizeof(o->dns));
5170 o->wins_len = 0;
5171 memset(o->wins, 0, sizeof(o->wins));
5172 o->ntp_len = 0;
5173 memset(o->ntp, 0, sizeof(o->ntp));
5174 o->nbdd_len = 0;
5175 memset(o->nbdd, 0, sizeof(o->nbdd));
5176 while (o->domain_search_list_len-- > 0)
5177 {
5179 }
5180 o->disable_nbt = 0;
5181 o->dhcp_options = 0;
5182#if defined(TARGET_ANDROID)
5183 o->http_proxy_port = 0;
5184 o->http_proxy = NULL;
5185#endif
5186 }
5187#endif /* if defined(_WIN32) || defined(TARGET_ANDROID) */
5188#ifdef _WIN32
5189 else if (streq(p[0], "block-outside-dns") && !p[1])
5190 {
5192 options->block_outside_dns = false;
5193 }
5194#else /* ifdef _WIN32 */
5195 else if (streq(p[0], "dhcp-option") && !p[1])
5196 {
5198 delete_all_dhcp_fo(options, &es->list);
5199 }
5200#endif
5201 else
5202 {
5203 msglvl_t msglevel_unknown = msglevel_fc;
5204 /* Check if an option is in --ignore-unknown-option and
5205 * set warning level to non fatal */
5206 for (int i = 0; options->ignore_unknown_option && options->ignore_unknown_option[i]; i++)
5207 {
5208 if (streq(p[0], options->ignore_unknown_option[i]))
5209 {
5210 msglevel_unknown = M_WARN;
5211 break;
5212 }
5213 }
5214 msg(msglevel_unknown,
5215 "Unrecognized option or missing or extra parameter(s) in %s:%d: -%s (%s)", file, line,
5216 p[0], PACKAGE_VERSION);
5217 }
5218 return;
5219err:
5220 msg(msglevel, "Error occurred trying to remove %s option", p[0]);
5221}
5222
5223
5224static bool
5225check_route_option(struct options *options, char *p[], const msglvl_t msglevel, bool pull_mode)
5226{
5228 if (pull_mode)
5229 {
5231 && !is_special_addr(p[1])) /* FQDN -- may be DNS name */
5232 {
5233 msg(msglevel, "route parameter network/IP '%s' must be a valid address", p[1]);
5234 return false;
5235 }
5236 if (p[2] && !ip_addr_dotted_quad_safe(p[2])) /* FQDN -- must be IP address */
5237 {
5238 msg(msglevel, "route parameter netmask '%s' must be an IP address", p[2]);
5239 return false;
5240 }
5241 if (p[3] && !ip_or_dns_addr_safe(p[3], options->allow_pull_fqdn)
5242 && !is_special_addr(p[3])) /* FQDN -- may be DNS name */
5243 {
5244 msg(msglevel, "route parameter gateway '%s' must be a valid address", p[3]);
5245 return false;
5246 }
5247 }
5248 return true;
5249}
5250
5251
5252static bool
5253check_route6_option(struct options *options, char *p[], const msglvl_t msglevel, bool pull_mode)
5254{
5256 if (pull_mode)
5257 {
5258 if (!ipv6_addr_safe_hexplusbits(p[1]))
5259 {
5260 msg(msglevel, "route-ipv6 parameter network/IP '%s' must be a valid address", p[1]);
5261 return false;
5262 }
5263 if (p[2] && !ipv6_addr_safe(p[2]))
5264 {
5265 msg(msglevel, "route-ipv6 parameter gateway '%s' must be a valid address", p[2]);
5266 return false;
5267 }
5268 /* p[3] is metric, if present */
5269 }
5270 return true;
5271}
5272
5273static bool
5274check_dns_option(struct options *options, char *p[], const msglvl_t msglevel, bool pull_mode)
5275{
5276 if (streq(p[1], "search-domains") && p[2])
5277 {
5280 {
5281 msg(msglevel, "--dns %s contain invalid characters", p[1]);
5282 return false;
5283 }
5284 }
5285 else if (streq(p[1], "server") && p[2] && p[3] && p[4])
5286 {
5287 long priority;
5288 if (!dns_server_priority_parse(&priority, p[2], pull_mode))
5289 {
5290 msg(msglevel, "--dns server: invalid priority value '%s'", p[2]);
5291 return false;
5292 }
5293
5294 struct dns_server *server =
5296
5297 if (streq(p[3], "address") && p[4])
5298 {
5299 for (int i = 4; p[i]; ++i)
5300 {
5301 if (!dns_server_addr_parse(server, p[i]))
5302 {
5303 msg(msglevel, "--dns server %ld: malformed address or maximum exceeded '%s'",
5304 priority, p[i]);
5305 return false;
5306 }
5307 }
5308 }
5309 else if (streq(p[3], "resolve-domains"))
5310 {
5311 if (!dns_domain_list_append(&server->domains, &p[4], &options->dns_options.gc))
5312 {
5313 msg(msglevel, "--dns server %ld: %s contain invalid characters", priority, p[3]);
5314 return false;
5315 }
5316 }
5317 else if (streq(p[3], "dnssec") && !p[5])
5318 {
5319 if (streq(p[4], "yes"))
5320 {
5321 server->dnssec = DNS_SECURITY_YES;
5322 }
5323 else if (streq(p[4], "no"))
5324 {
5325 server->dnssec = DNS_SECURITY_NO;
5326 }
5327 else if (streq(p[4], "optional"))
5328 {
5329 server->dnssec = DNS_SECURITY_OPTIONAL;
5330 }
5331 else
5332 {
5333 msg(msglevel, "--dns server %ld: malformed dnssec value '%s'", priority, p[4]);
5334 return false;
5335 }
5336 }
5337 else if (streq(p[3], "transport") && !p[5])
5338 {
5339 if (streq(p[4], "plain"))
5340 {
5342 }
5343 else if (streq(p[4], "DoH"))
5344 {
5346 }
5347 else if (streq(p[4], "DoT"))
5348 {
5349 server->transport = DNS_TRANSPORT_TLS;
5350 }
5351 else
5352 {
5353 msg(msglevel, "--dns server %ld: malformed transport value '%s'", priority, p[4]);
5354 return false;
5355 }
5356 }
5357 else if (streq(p[3], "sni") && !p[5])
5358 {
5359 if (!validate_domain(p[4]))
5360 {
5361 msg(msglevel, "--dns server %ld: %s contains invalid characters", priority, p[3]);
5362 return false;
5363 }
5364 server->sni = p[4];
5365 }
5366 else
5367 {
5368 msg(msglevel,
5369 "--dns server %ld: unknown option type '%s' or missing or unknown parameter",
5370 priority, p[3]);
5371 return false;
5372 }
5373 }
5374 else
5375 {
5376 msg(msglevel, "--dns: unknown option type '%s' or missing or unknown parameter", p[1]);
5377 return false;
5378 }
5379 return true;
5380}
5381
5382void
5383update_option(struct context *c, struct options *options, char *p[], bool is_inline,
5384 const char *file, int line, const int level, const msglvl_t msglevel,
5385 const unsigned int permission_mask, unsigned int *option_types_found,
5386 struct env_set *es)
5387{
5388 const bool pull_mode = BOOL_CAST(permission_mask & OPT_P_PULL_MODE);
5389 ASSERT(MAX_PARMS >= 7);
5390
5391 if (streq(p[0], "route") && p[1] && !p[5])
5392 {
5394 {
5396 if (!check_route_option(options, p, msglevel, pull_mode))
5397 {
5398 goto err;
5399 }
5400 if (c->c1.route_list)
5401 {
5403 es, &c->net_ctx);
5405 }
5407 }
5408 }
5409 else if (streq(p[0], "route-ipv6") && p[1] && !p[4])
5410 {
5412 {
5414 if (!check_route6_option(options, p, msglevel, pull_mode))
5415 {
5416 goto err;
5417 }
5418 if (c->c1.route_ipv6_list)
5419 {
5423 }
5425 }
5426 }
5427 else if (streq(p[0], "redirect-gateway") || streq(p[0], "redirect-private"))
5428 {
5430 {
5432 if (options->routes)
5433 {
5434 options->routes->flags = 0;
5435 }
5436 if (options->routes_ipv6)
5437 {
5439 }
5440 env_set_del(es, "route_redirect_gateway_ipv4");
5441 env_set_del(es, "route_redirect_gateway_ipv6");
5443 }
5444 }
5445 else if (streq(p[0], "dns") && p[1])
5446 {
5448 {
5450 if (!check_dns_option(options, p, msglevel, pull_mode))
5451 {
5452 goto err;
5453 }
5457 }
5458 }
5459#if defined(_WIN32) || defined(TARGET_ANDROID)
5460 else if (streq(p[0], "dhcp-option") && p[1] && !p[3])
5461 {
5463 {
5466
5467 o->domain = NULL;
5468 o->netbios_scope = NULL;
5469 o->netbios_node_type = 0;
5470 o->dns6_len = 0;
5471 CLEAR(o->dns6);
5472 o->dns_len = 0;
5473 CLEAR(o->dns);
5474 o->wins_len = 0;
5475 CLEAR(o->wins);
5476 o->ntp_len = 0;
5477 CLEAR(o->ntp);
5478 o->nbdd_len = 0;
5479 CLEAR(o->nbdd);
5480 while (o->domain_search_list_len-- > 0)
5481 {
5483 }
5484 o->disable_nbt = 0;
5485 o->dhcp_options = 0;
5486
5488#if defined(TARGET_ANDROID)
5489 o->http_proxy_port = 0;
5490 o->http_proxy = NULL;
5491#endif
5493 }
5494 }
5495#else /* if defined(_WIN32) || defined(TARGET_ANDROID) */
5496 else if (streq(p[0], "dhcp-option") && p[1] && !p[3])
5497 {
5499 {
5501 delete_all_dhcp_fo(options, &es->list);
5503 }
5504 }
5505#endif /* if defined(_WIN32) || defined(TARGET_ANDROID) */
5506 add_option(options, p, is_inline, file, line, level, msglevel, permission_mask,
5507 option_types_found, es);
5508 return;
5509err:
5510 msg(msglevel, "Error occurred trying to update %s option", p[0]);
5511}
5512
5513static void
5514set_user_script(struct options *options, const char **script, const char *new_script,
5515 const char *type, bool in_chroot)
5516{
5517 if (*script)
5518 {
5519 msg(M_WARN,
5520 "Multiple --%s scripts defined. "
5521 "The previously configured script is overridden.",
5522 type);
5523 }
5524 *script = new_script;
5525 options->user_script_used = true;
5526
5527#ifndef ENABLE_SMALL
5528 {
5529 char script_name[100];
5530 snprintf(script_name, sizeof(script_name), "--%s script", type);
5531
5532 if (check_cmd_access(*script, script_name, (in_chroot ? options->chroot_dir : NULL)))
5533 {
5534 msg(M_USAGE, "Please correct this error.");
5535 }
5536 }
5537#endif
5538}
5539
5540static void
5542{
5543 if (comp_non_stub_enabled(info))
5544 {
5545 msg(M_WARN, "WARNING: Compression for receiving enabled. "
5546 "Compression has been used in the past to break encryption. "
5547 "Compression support is deprecated and we recommend to disable "
5548 "it completely.");
5549 }
5550}
5551
5552bool
5554{
5555 bool ret = false;
5556 ret = ret || (options->management_flags & MF_EXTERNAL_KEY);
5557#ifdef ENABLE_PKCS11
5558 ret = ret || (options->pkcs11_providers[0] != NULL);
5559#endif
5560#ifdef ENABLE_CRYPTOAPI
5561 ret = ret || options->cryptoapi_cert;
5562#endif
5563
5564 return ret;
5565}
5566
5567void
5568add_option(struct options *options, char *p[], bool is_inline, const char *file, int line,
5569 const int level, const msglvl_t msglevel, const unsigned int permission_mask,
5570 unsigned int *option_types_found, struct env_set *es)
5571{
5572 struct gc_arena gc = gc_new();
5573 const bool pull_mode = BOOL_CAST(permission_mask & OPT_P_PULL_MODE);
5574 msglvl_t msglevel_fc = msglevel_forward_compatible(options, msglevel);
5575
5576 ASSERT(MAX_PARMS >= 7);
5577
5578 /*
5579 * If directive begins with "setenv opt" prefix, don't raise an error if
5580 * directive is unrecognized.
5581 */
5582 if (streq(p[0], "setenv") && p[1] && streq(p[1], "opt") && !(permission_mask & OPT_P_PULL_MODE))
5583 {
5584 if (!p[2])
5585 {
5586 p[2] = "setenv opt"; /* will trigger an error that includes setenv opt */
5587 }
5588 p += 2;
5589 msglevel_fc = M_WARN;
5590 }
5591
5592 if (!file)
5593 {
5594 file = "[CMD-LINE]";
5595 line = 1;
5596 }
5597 if (streq(p[0], "help"))
5598 {
5600 usage();
5601 if (p[1])
5602 {
5603 msg(msglevel, "--help does not accept any parameters");
5604 goto err;
5605 }
5606 }
5607 if (streq(p[0], "version") && !p[1])
5608 {
5610 usage_version();
5611 }
5612 else if (streq(p[0], "config") && p[1] && !p[2])
5613 {
5615
5616 /* save first config file only in options */
5617 if (!options->config)
5618 {
5619 options->config = p[1];
5620 }
5621
5622 read_config_file(options, p[1], level, file, line, msglevel, permission_mask,
5623 option_types_found, es);
5624 }
5625#if defined(ENABLE_DEBUG) && !defined(ENABLE_SMALL)
5626 else if (streq(p[0], "show-gateway") && !p[2])
5627 {
5628 struct route_gateway_info rgi;
5629 struct route_ipv6_gateway_info rgi6;
5630 in_addr_t remote_ipv4 = 0;
5631 struct in6_addr remote_ipv6 = IN6ADDR_ANY_INIT;
5632 openvpn_net_ctx_t net_ctx;
5634 if (p[1])
5635 {
5636 /* try parsing the argument as a v4 or v6 address - if
5637 * possible, the output will show the exact route there, and
5638 * "the default route" for the other protocol
5639 */
5640 remote_ipv4 = get_ip_addr(p[1], M_WARN, NULL);
5641 get_ipv6_addr(p[1], &remote_ipv6, NULL, M_WARN);
5642 }
5643 net_ctx_init(NULL, &net_ctx);
5644 get_default_gateway(&rgi, remote_ipv4, &net_ctx);
5645 get_default_gateway_ipv6(&rgi6, &remote_ipv6, &net_ctx);
5646 print_default_gateway(M_INFO, &rgi, &rgi6);
5647 openvpn_exit(OPENVPN_EXIT_STATUS_GOOD); /* exit point */
5648 }
5649#endif
5650 else if (streq(p[0], "echo") || streq(p[0], "parameter"))
5651 {
5652 struct buffer string = alloc_buf_gc(OPTION_PARM_SIZE, &gc);
5653 int j;
5654 bool good = true;
5655
5657
5658 for (j = 1; j < MAX_PARMS; ++j)
5659 {
5660 if (!p[j])
5661 {
5662 break;
5663 }
5664 if (j > 1)
5665 {
5666 good &= buf_printf(&string, " ");
5667 }
5668 good &= buf_printf(&string, "%s", p[j]);
5669 }
5670 if (good)
5671 {
5672 /* only message-related ECHO are logged, since other ECHOs
5673 * can potentially include security-sensitive strings */
5674 if (p[1] && strncmp(p[1], "msg", 3) == 0)
5675 {
5676 msg(M_INFO, "%s:%s", pull_mode ? "ECHO-PULL" : "ECHO", BSTR(&string));
5677 }
5678#ifdef ENABLE_MANAGEMENT
5679 if (management)
5680 {
5682 }
5683#endif
5684 }
5685 else
5686 {
5687 msg(M_WARN, "echo/parameter option overflow");
5688 }
5689 }
5690#ifdef ENABLE_MANAGEMENT
5691 else if (streq(p[0], "management") && p[1] && p[2] && !p[4])
5692 {
5694 if (streq(p[2], "unix"))
5695 {
5696#if UNIX_SOCK_SUPPORT
5698#else
5699 msg(msglevel, "MANAGEMENT: this platform does not support unix domain sockets");
5700 goto err;
5701#endif
5702 }
5703
5706 if (p[3])
5707 {
5709 }
5710 }
5711 else if (streq(p[0], "management-client-user") && p[1] && !p[2])
5712 {
5715 }
5716 else if (streq(p[0], "management-client-group") && p[1] && !p[2])
5717 {
5720 }
5721 else if (streq(p[0], "management-query-passwords") && !p[1])
5722 {
5725 }
5726 else if (streq(p[0], "management-query-remote") && !p[1])
5727 {
5730 }
5731 else if (streq(p[0], "management-query-proxy") && !p[1])
5732 {
5735 }
5736 else if (streq(p[0], "management-hold") && !p[1])
5737 {
5740 }
5741 else if (streq(p[0], "management-signal") && !p[1])
5742 {
5745 }
5746 else if (streq(p[0], "management-forget-disconnect") && !p[1])
5747 {
5750 }
5751 else if (streq(p[0], "management-up-down") && !p[1])
5752 {
5755 }
5756 else if (streq(p[0], "management-client") && !p[1])
5757 {
5760 }
5761 else if (streq(p[0], "management-external-key"))
5762 {
5764 for (int j = 1; j < MAX_PARMS && p[j] != NULL; ++j)
5765 {
5766 if (streq(p[j], "nopadding"))
5767 {
5769 }
5770 else if (streq(p[j], "pkcs1"))
5771 {
5773 }
5774 else if (streq(p[j], "pss"))
5775 {
5777 }
5778 else if (streq(p[j], "digest"))
5779 {
5781 }
5782 else
5783 {
5784 msg(msglevel, "Unknown management-external-key flag: %s", p[j]);
5785 }
5786 }
5787 /*
5788 * When no option is present, assume that only PKCS1
5789 * padding is supported
5790 */
5792 {
5794 }
5796 }
5797 else if (streq(p[0], "management-external-cert") && p[1] && !p[2])
5798 {
5802 }
5803 else if (streq(p[0], "management-client-auth") && !p[1])
5804 {
5807 }
5808 else if (streq(p[0], "management-log-cache") && p[1] && !p[2])
5809 {
5812 p[0], 1, INT_MAX, msglevel))
5813 {
5814 goto err;
5815 }
5816 }
5817#endif /* ifdef ENABLE_MANAGEMENT */
5818#ifdef ENABLE_PLUGIN
5819 else if (streq(p[0], "plugin") && p[1])
5820 {
5822 if (!options->plugin_list)
5823 {
5825 }
5827 {
5828 msg(msglevel, "plugin add failed: %s", p[1]);
5829 goto err;
5830 }
5831 }
5832#endif
5833 else if (streq(p[0], "mode") && p[1] && !p[2])
5834 {
5836 if (streq(p[1], "p2p"))
5837 {
5839 }
5840 else if (streq(p[1], "server"))
5841 {
5843 }
5844 else
5845 {
5846 msg(msglevel, "Bad --mode parameter: %s", p[1]);
5847 goto err;
5848 }
5849 }
5850 else if (streq(p[0], "dev") && p[1] && !p[2])
5851 {
5853 options->dev = p[1];
5854 }
5855 else if (streq(p[0], "dev-type") && p[1] && !p[2])
5856 {
5858 options->dev_type = p[1];
5859 }
5860#ifdef _WIN32
5861 else if (streq(p[0], "windows-driver") && p[1] && !p[2])
5862 {
5864 msg(M_WARN,
5865 "DEPRECATED OPTION: windows-driver: In OpenVPN 2.7, the default Windows driver is ovpn-dco. "
5866 "If incompatible options are used, OpenVPN will fall back to tap-windows6. Wintun support has been removed.");
5867 }
5868#endif
5869 else if (streq(p[0], "disable-dco"))
5870 {
5871 options->disable_dco = true;
5872 }
5873 else if (streq(p[0], "dev-node") && p[1] && !p[2])
5874 {
5876 options->dev_node = p[1];
5877 }
5878 else if (streq(p[0], "lladdr") && p[1] && !p[2])
5879 {
5881 if (mac_addr_safe(p[1])) /* MAC address only */
5882 {
5883 options->lladdr = p[1];
5884 }
5885 else
5886 {
5887 msg(msglevel, "lladdr parm '%s' must be a MAC address", p[1]);
5888 goto err;
5889 }
5890 }
5891 else if (streq(p[0], "topology") && p[1] && !p[2])
5892 {
5894 options->topology = parse_topology(p[1], msglevel);
5895 }
5896 else if (streq(p[0], "tun-ipv6") && !p[1])
5897 {
5898 if (!pull_mode)
5899 {
5900 msg(M_WARN,
5901 "Note: option tun-ipv6 is ignored because modern operating systems do not need special IPv6 tun handling anymore.");
5902 }
5903 }
5904#ifdef ENABLE_IPROUTE
5905 else if (streq(p[0], "iproute") && p[1] && !p[2])
5906 {
5908 iproute_path = p[1];
5909 }
5910#endif
5911 else if (streq(p[0], "ifconfig") && p[1] && p[2] && !p[3])
5912 {
5915 && ip_or_dns_addr_safe(p[2], options->allow_pull_fqdn)) /* FQDN -- may be DNS name */
5916 {
5917 options->ifconfig_local = p[1];
5919 }
5920 else
5921 {
5922 msg(msglevel, "ifconfig parms '%s' and '%s' must be valid addresses", p[1], p[2]);
5923 goto err;
5924 }
5925 }
5926 else if (streq(p[0], "ifconfig-ipv6") && p[1] && p[2] && !p[3])
5927 {
5928 unsigned int netbits;
5929
5931 if (get_ipv6_addr(p[1], NULL, &netbits, msglevel) && ipv6_addr_safe(p[2]))
5932 {
5934 {
5935 msg(msglevel, "ifconfig-ipv6: /netbits must be between 64 and 124, not '/%d'",
5936 netbits);
5937 goto err;
5938 }
5939
5941 options->ifconfig_ipv6_netbits = netbits;
5943 }
5944 else
5945 {
5946 msg(msglevel, "ifconfig-ipv6 parms '%s' and '%s' must be valid addresses", p[1], p[2]);
5947 goto err;
5948 }
5949 }
5950 else if (streq(p[0], "ifconfig-noexec") && !p[1])
5951 {
5953 options->ifconfig_noexec = true;
5954 }
5955 else if (streq(p[0], "ifconfig-nowarn") && !p[1])
5956 {
5958 options->ifconfig_nowarn = true;
5959 }
5960 else if (streq(p[0], "local") && p[1] && !p[4])
5961 {
5962 struct local_entry *e;
5963
5965
5967 ASSERT(e);
5968
5969 /* '*' is treated as 'ask the system to get some socket',
5970 * therefore force binding on a particular address only when
5971 * actually specified. */
5972 if (strcmp(p[1], "*") != 0)
5973 {
5974 e->local = p[1];
5975 }
5976
5977 if (p[2])
5978 {
5979 e->port = p[2];
5980 }
5981
5982 if (p[3])
5983 {
5984 e->proto = ascii2proto(p[3]);
5985 }
5986 }
5987 else if (streq(p[0], "remote-random") && !p[1])
5988 {
5990 options->remote_random = true;
5991 }
5992 else if (streq(p[0], "connection") && p[1] && !p[3])
5993 {
5995 if (is_inline)
5996 {
5997 struct options sub;
5998 struct connection_entry *e;
5999
6000 init_options(&sub, true);
6001 sub.ce = options->ce;
6002 read_config_string("[CONNECTION-OPTIONS]", &sub, p[1], msglevel, OPT_P_CONNECTION,
6003 option_types_found, es);
6004 if (!sub.ce.remote)
6005 {
6006 msg(msglevel,
6007 "Each 'connection' block must contain exactly one 'remote' directive");
6008 uninit_options(&sub);
6009 goto err;
6010 }
6011
6012 e = alloc_connection_entry(options, msglevel);
6013 if (!e)
6014 {
6015 uninit_options(&sub);
6016 goto err;
6017 }
6018 *e = sub.ce;
6019 gc_transfer(&options->gc, &sub.gc);
6020 uninit_options(&sub);
6021 }
6022 }
6023 else if (streq(p[0], "ignore-unknown-option") && p[1])
6024 {
6025 int i;
6026 int j;
6027 int numignored = 0;
6028 const char **ignore;
6029
6031 /* Find out how many options to be ignored */
6032 for (i = 1; p[i]; i++)
6033 {
6034 numignored++;
6035 }
6036
6037 /* add number of options already ignored */
6039 {
6040 numignored++;
6041 }
6042
6043 /* Allocate array */
6044 ALLOC_ARRAY_GC(ignore, const char *, numignored + 1, &options->gc);
6046 {
6047 ignore[i] = options->ignore_unknown_option[i];
6048 }
6049
6051
6052 for (j = 1; p[j]; j++)
6053 {
6054 /* Allow the user to specify ignore-unknown-option --opt too */
6055 if (p[j][0] == '-' && p[j][1] == '-')
6056 {
6057 options->ignore_unknown_option[i] = (p[j] + 2);
6058 }
6059 else
6060 {
6061 options->ignore_unknown_option[i] = p[j];
6062 }
6063 i++;
6064 }
6065
6066 options->ignore_unknown_option[i] = NULL;
6067 }
6068#if ENABLE_MANAGEMENT
6069 else if (streq(p[0], "http-proxy-override") && p[1] && p[2] && !p[4])
6070 {
6074 {
6075 goto err;
6076 }
6077 }
6078#endif
6079 else if (streq(p[0], "remote") && p[1] && !p[4])
6080 {
6081 struct remote_entry re;
6082 re.remote = re.remote_port = NULL;
6083 re.proto = -1;
6084 re.af = 0;
6085
6087 re.remote = p[1];
6088 if (p[2])
6089 {
6090 re.remote_port = p[2];
6091 if (p[3])
6092 {
6093 const int proto = ascii2proto(p[3]);
6094 const sa_family_t af = ascii2af(p[3]);
6095 if (proto < 0)
6096 {
6097 msg(msglevel, "remote: bad protocol associated with host %s: '%s'", p[1], p[3]);
6098 goto err;
6099 }
6100 re.proto = proto;
6101 re.af = af;
6102 }
6103 }
6104 if (permission_mask & OPT_P_GENERAL)
6105 {
6106 struct remote_entry *e = alloc_remote_entry(options, msglevel);
6107 if (!e)
6108 {
6109 goto err;
6110 }
6111 *e = re;
6112 }
6113 else if (permission_mask & OPT_P_CONNECTION)
6114 {
6116 }
6117 }
6118 else if (streq(p[0], "resolv-retry") && p[1] && !p[2])
6119 {
6121 if (streq(p[1], "infinite"))
6122 {
6124 }
6125 else
6126 {
6127 options->resolve_retry_seconds = positive_atoi(p[1], msglevel);
6128 }
6129 }
6130 else if ((streq(p[0], "preresolve") || streq(p[0], "ip-remote-hint")) && !p[2])
6131 {
6134 /* Note the ip-remote-hint and the argument p[1] are for
6135 * backward compatibility */
6136 if (p[1])
6137 {
6138 options->ip_remote_hint = p[1];
6139 }
6140 }
6141 else if (streq(p[0], "connect-retry") && p[1] && !p[3])
6142 {
6144 options->ce.connect_retry_seconds = positive_atoi(p[1], msglevel);
6145 /*
6146 * Limit the base value of retry wait interval to 16 bits to avoid
6147 * overflow when scaled up for exponential backoff
6148 */
6149 if (options->ce.connect_retry_seconds > 0xFFFF)
6150 {
6152 msg(M_WARN, "connect retry wait interval truncated to %d",
6154 }
6155
6156 if (p[2])
6157 {
6160 }
6161 }
6162 else if ((streq(p[0], "connect-timeout") || streq(p[0], "server-poll-timeout")) && p[1]
6163 && !p[2])
6164 {
6166 options->ce.connect_timeout = positive_atoi(p[1], msglevel);
6167 }
6168 else if (streq(p[0], "connect-retry-max") && p[1] && !p[2])
6169 {
6171 options->connect_retry_max = positive_atoi(p[1], msglevel);
6172 }
6173 else if (streq(p[0], "ipchange") && p[1])
6174 {
6176 if (!no_more_than_n_args(msglevel, p, 2, NM_QUOTE_HINT))
6177 {
6178 goto err;
6179 }
6181 string_substitute(p[1], ',', ' ', &options->gc), "ipchange", true);
6182 }
6183 else if (streq(p[0], "float") && !p[1])
6184 {
6186 options->ce.remote_float = true;
6187 }
6188#ifdef ENABLE_DEBUG
6189 else if (streq(p[0], "gremlin") && p[1] && !p[2])
6190 {
6192 options->gremlin = positive_atoi(p[1], msglevel);
6193 }
6194#endif
6195 else if (streq(p[0], "chroot") && p[1] && !p[2])
6196 {
6198 options->chroot_dir = p[1];
6199 }
6200 else if (streq(p[0], "cd") && p[1] && !p[2])
6201 {
6203 if (platform_chdir(p[1]))
6204 {
6205 msg(M_ERR, "cd to '%s' failed", p[1]);
6206 goto err;
6207 }
6208 options->cd_dir = p[1];
6209 }
6210#ifdef ENABLE_SELINUX
6211 else if (streq(p[0], "setcon") && p[1] && !p[2])
6212 {
6214 options->selinux_context = p[1];
6215 }
6216#endif
6217 else if (streq(p[0], "writepid") && p[1] && !p[2])
6218 {
6220 options->writepid = p[1];
6221 }
6222 else if (streq(p[0], "up") && p[1])
6223 {
6225 if (!no_more_than_n_args(msglevel, p, 2, NM_QUOTE_HINT))
6226 {
6227 goto err;
6228 }
6229 set_user_script(options, &options->up_script, p[1], "up", false);
6230 }
6231 else if (streq(p[0], "down") && p[1])
6232 {
6234 if (!no_more_than_n_args(msglevel, p, 2, NM_QUOTE_HINT))
6235 {
6236 goto err;
6237 }
6238 set_user_script(options, &options->down_script, p[1], "down", true);
6239 }
6240 else if (streq(p[0], "down-pre") && !p[1])
6241 {
6243 options->down_pre = true;
6244 }
6245 else if (streq(p[0], "up-delay") && !p[1])
6246 {
6248 options->up_delay = true;
6249 }
6250 else if (streq(p[0], "up-restart") && !p[1])
6251 {
6253 options->up_restart = true;
6254 }
6255 else if (streq(p[0], "syslog") && !p[2])
6256 {
6258 open_syslog(p[1], false);
6259 }
6260 else if (streq(p[0], "daemon") && !p[2])
6261 {
6262 bool didit = false;
6264 if (!options->daemon)
6265 {
6266 options->daemon = didit = true;
6267 open_syslog(p[1], false);
6268 }
6269 if (p[1])
6270 {
6271 if (!didit)
6272 {
6273 msg(M_WARN,
6274 "WARNING: Multiple --daemon directives specified, ignoring --daemon %s. (Note that initscripts sometimes add their own --daemon directive.)",
6275 p[1]);
6276 goto err;
6277 }
6278 }
6279 }
6280 else if (streq(p[0], "log") && p[1] && !p[2])
6281 {
6283 options->log = true;
6284 redirect_stdout_stderr(p[1], false);
6285 }
6286 else if (streq(p[0], "suppress-timestamps") && !p[1])
6287 {
6291 }
6292 else if (streq(p[0], "machine-readable-output") && !p[1])
6293 {
6297 }
6298 else if (streq(p[0], "log-append") && p[1] && !p[2])
6299 {
6301 options->log = true;
6302 redirect_stdout_stderr(p[1], true);
6303 }
6304 else if (streq(p[0], "mlock") && !p[1])
6305 {
6307 options->mlock = true;
6308 }
6309#if ENABLE_IP_PKTINFO
6310 else if (streq(p[0], "multihome") && !p[2])
6311 {
6314 if (p[1] && streq(p[1], "same-interface"))
6315 {
6317 }
6318 else if (p[1])
6319 {
6320 msg(msglevel, "Unknown parameter to --multihome: %s", p[1]);
6321 }
6322 }
6323#endif
6324 else if (streq(p[0], "verb") && p[1] && !p[2])
6325 {
6327 options->verbosity = positive_atoi(p[1], msglevel);
6329 {
6330 /* We pass this flag to the SSL library to avoid
6331 * mbed TLS always generating debug level logging */
6333 }
6334#if !defined(ENABLE_DEBUG) && !defined(ENABLE_SMALL)
6335 /* Warn when a debug verbosity is supplied when built without debug support */
6336 if (options->verbosity >= 7)
6337 {
6338 msg(M_WARN,
6339 "NOTE: debug verbosity (--verb %d) is enabled but this build lacks debug support.",
6341 }
6342#endif
6343 }
6344 else if (streq(p[0], "mute") && p[1] && !p[2])
6345 {
6347 options->mute = positive_atoi(p[1], msglevel);
6348 }
6349 else if (streq(p[0], "errors-to-stderr") && !p[1])
6350 {
6353 }
6354 else if (streq(p[0], "status") && p[1] && !p[3])
6355 {
6357 options->status_file = p[1];
6358 if (p[2])
6359 {
6361 }
6362 }
6363 else if (streq(p[0], "status-version") && p[1] && !p[2])
6364 {
6366 if (!atoi_constrained(p[1], &options->status_file_version, p[0], 1, 3, msglevel))
6367 {
6368 goto err;
6369 }
6370 }
6371 else if (streq(p[0], "remap-usr1") && p[1] && !p[2])
6372 {
6374 if (streq(p[1], "SIGHUP"))
6375 {
6377 }
6378 else if (streq(p[1], "SIGTERM"))
6379 {
6381 }
6382 else
6383 {
6384 msg(msglevel, "--remap-usr1 parm must be 'SIGHUP' or 'SIGTERM'");
6385 goto err;
6386 }
6387 }
6388 else if ((streq(p[0], "link-mtu") || streq(p[0], "udp-mtu")) && p[1] && !p[2])
6389 {
6391 options->ce.link_mtu = positive_atoi(p[1], msglevel);
6392 options->ce.link_mtu_defined = true;
6393 }
6394 else if (streq(p[0], "tun-mtu") && p[1] && !p[3])
6395 {
6397 options->ce.tun_mtu = positive_atoi(p[1], msglevel);
6398 options->ce.tun_mtu_defined = true;
6399 if (p[2])
6400 {
6401 options->ce.occ_mtu = positive_atoi(p[2], msglevel);
6402 }
6403 else
6404 {
6405 options->ce.occ_mtu = 0;
6406 }
6407 }
6408 else if (streq(p[0], "tun-mtu-max") && p[1] && !p[2])
6409 {
6411 atoi_constrained(p[1], &options->ce.tun_mtu_max, p[0], TUN_MTU_MAX_MIN, 65536, msglevel);
6412 }
6413 else if (streq(p[0], "tun-mtu-extra") && p[1] && !p[2])
6414 {
6416 if (atoi_constrained(p[1], &options->ce.tun_mtu_extra, p[0], 0, 65536, msglevel))
6417 {
6419 }
6420 }
6421 else if (streq(p[0], "max-packet-size") && p[1] && !p[2])
6422 {
6424 int maxmtu = positive_atoi(p[1], msglevel);
6426
6427 if (maxmtu < TLS_CHANNEL_MTU_MIN || maxmtu > TLS_CHANNEL_BUF_SIZE)
6428 {
6429 msg(M_WARN,
6430 "Note: max-packet-size value outside of allowed "
6431 "control channel packet size (%d to %d), will use %d "
6432 "instead.",
6434 }
6435
6436 /* also set mssfix maxmtu mtu */
6437 options->ce.mssfix = maxmtu;
6438 options->ce.mssfix_default = false;
6439 options->ce.mssfix_encap = true;
6440 }
6441#ifdef ENABLE_FRAGMENT
6442 else if (streq(p[0], "mtu-dynamic"))
6443 {
6445 msg(msglevel, "--mtu-dynamic has been replaced by --fragment");
6446 goto err;
6447 }
6448 else if (streq(p[0], "fragment") && p[1] && !p[3])
6449 {
6451 if (!atoi_constrained(p[1], &options->ce.fragment, p[0], 68, INT_MAX, msglevel))
6452 {
6453 goto err;
6454 }
6455
6456 if (p[2] && streq(p[2], "mtu"))
6457 {
6458 options->ce.fragment_encap = true;
6459 }
6460 else if (p[2])
6461 {
6462 msg(msglevel, "Unknown parameter to --fragment: %s", p[2]);
6463 }
6464 }
6465#endif /* ifdef ENABLE_FRAGMENT */
6466 else if (streq(p[0], "mtu-disc") && p[1] && !p[2])
6467 {
6470 }
6471 else if (streq(p[0], "mtu-test") && !p[1])
6472 {
6474 options->mtu_test = true;
6475 }
6476 else if (streq(p[0], "nice") && p[1] && !p[2])
6477 {
6479 options->nice = atoi_warn(p[1], msglevel);
6480 }
6481 else if (streq(p[0], "rcvbuf") && p[1] && !p[2])
6482 {
6484 options->rcvbuf = positive_atoi(p[1], msglevel);
6485 }
6486 else if (streq(p[0], "sndbuf") && p[1] && !p[2])
6487 {
6489 options->sndbuf = positive_atoi(p[1], msglevel);
6490 }
6491 else if (streq(p[0], "mark") && p[1] && !p[2])
6492 {
6493#if defined(TARGET_LINUX)
6495 options->mark = atoi_warn(p[1], msglevel);
6496#endif
6497 }
6498 else if (streq(p[0], "socket-flags"))
6499 {
6500 int j;
6502 for (j = 1; j < MAX_PARMS && p[j]; ++j)
6503 {
6504 if (streq(p[j], "TCP_NODELAY"))
6505 {
6507 }
6508 else
6509 {
6510 msg(msglevel, "unknown socket flag: %s", p[j]);
6511 }
6512 }
6513 }
6514#ifdef TARGET_LINUX
6515 else if (streq(p[0], "bind-dev") && p[1])
6516 {
6518 options->bind_dev = p[1];
6519 }
6520#endif
6521 else if (streq(p[0], "txqueuelen") && p[1] && !p[2])
6522 {
6524#ifdef TARGET_LINUX
6525 options->tuntap_options.txqueuelen = positive_atoi(p[1], msglevel);
6526#else
6527 msg(msglevel, "--txqueuelen not supported on this OS");
6528 goto err;
6529#endif
6530 }
6531 else if (streq(p[0], "shaper") && p[1] && !p[2])
6532 {
6534 if (!atoi_constrained(p[1], &options->shaper, p[0], SHAPER_MIN, SHAPER_MAX, msglevel))
6535 {
6536 goto err;
6537 }
6538 }
6539 else if (streq(p[0], "port") && p[1] && !p[2])
6540 {
6543 }
6544 else if (streq(p[0], "lport") && p[1] && !p[2])
6545 {
6547
6548 /* only trigger bind() if port is not 0 (or --local is used) */
6549 if (!streq(p[1], "0"))
6550 {
6552 }
6553 options->ce.local_port = p[1];
6554 }
6555 else if (streq(p[0], "rport") && p[1] && !p[2])
6556 {
6558 options->ce.remote_port = p[1];
6559 }
6560 else if (streq(p[0], "bind") && !p[2])
6561 {
6563 options->ce.bind_defined = true;
6564 if (p[1] && streq(p[1], "ipv6only"))
6565 {
6566 options->ce.bind_ipv6_only = true;
6567 }
6568 }
6569 else if (streq(p[0], "nobind") && !p[1])
6570 {
6572 options->ce.bind_local = false;
6573 }
6574 else if (streq(p[0], "fast-io") && !p[1])
6575 {
6577 msg(M_WARN, "DEPRECATED OPTION: --fast-io option ignored.");
6578 }
6579 else if (streq(p[0], "inactive") && p[1] && !p[3])
6580 {
6582 options->inactivity_timeout = positive_atoi(p[1], msglevel);
6583 if (p[2])
6584 {
6585 positive_atoll(p[2], &options->inactivity_minimum_bytes, p[0], msglevel);
6586 if (options->inactivity_minimum_bytes > INT_MAX)
6587 {
6588 msg(M_WARN,
6589 "WARNING: '--inactive' with a 'bytes' value"
6590 " >2 Gbyte was silently ignored in older versions. If "
6591 " your VPN exits unexpectedly with 'Inactivity timeout'"
6592 " in %d seconds, revisit this value.",
6594 }
6595 }
6596 }
6597 else if (streq(p[0], "session-timeout") && p[1] && !p[2])
6598 {
6600 options->session_timeout = positive_atoi(p[1], msglevel);
6601 }
6602 else if (streq(p[0], "proto") && p[1] && !p[2])
6603 {
6604 int proto;
6607 proto = ascii2proto(p[1]);
6608 af = ascii2af(p[1]);
6609 if (proto < 0)
6610 {
6611 msg(msglevel, "Bad protocol: '%s'. Allowed protocols with --proto option: %s", p[1],
6613 goto err;
6614 }
6615 options->ce.proto = proto;
6616 options->ce.af = af;
6617 }
6618 else if (streq(p[0], "proto-force") && p[1] && !p[2])
6619 {
6620 int proto_force;
6622 proto_force = ascii2proto(p[1]);
6623 if (proto_force < 0)
6624 {
6625 msg(msglevel, "Bad --proto-force protocol: '%s'", p[1]);
6626 goto err;
6627 }
6628 options->proto_force = proto_force;
6629 }
6630 else if (streq(p[0], "http-proxy") && p[1] && !p[5])
6631 {
6632 struct http_proxy_options *ho;
6633
6635
6636 {
6637 if (!p[2])
6638 {
6639 msg(msglevel, "http-proxy port number not defined");
6640 goto err;
6641 }
6642
6644
6645 ho->server = p[1];
6646 ho->port = p[2];
6647 }
6648
6649 if (p[3])
6650 {
6651 /* auto -- try to figure out proxy addr, port, and type automatically */
6652 /* auto-nct -- disable proxy auth cleartext protocols (i.e. basic auth) */
6653 if (streq(p[3], "auto"))
6654 {
6655 ho->auth_retry = PAR_ALL;
6656 }
6657 else if (streq(p[3], "auto-nct"))
6658 {
6659 ho->auth_retry = PAR_NCT;
6660 }
6661 else
6662 {
6663 ho->auth_method_string = "basic";
6664 ho->auth_file = p[3];
6665
6666 if (p[4])
6667 {
6668 ho->auth_method_string = p[4];
6669 }
6670 }
6671 }
6672 else
6673 {
6674 ho->auth_method_string = "none";
6675 }
6676 }
6677 else if (streq(p[0], "http-proxy-user-pass") && p[1])
6678 {
6679 struct http_proxy_options *ho;
6682 ho->auth_file_up = p[1];
6683 ho->inline_creds = is_inline;
6684 }
6685 else if (streq(p[0], "http-proxy-retry") || streq(p[0], "socks-proxy-retry") || streq(p[0], "http-proxy-timeout"))
6686 {
6688 msg(M_WARN, "DEPRECATED OPTION: %s option ignored.", p[0]);
6689 }
6690 else if (streq(p[0], "http-proxy-option") && p[1] && !p[4])
6691 {
6692 struct http_proxy_options *ho;
6693
6696
6697 if (streq(p[1], "VERSION") && p[2] && !p[3])
6698 {
6699 ho->http_version = p[2];
6700 }
6701 else if (streq(p[1], "AGENT") && p[2] && !p[3])
6702 {
6703 ho->user_agent = p[2];
6704 }
6705 else if ((streq(p[1], "EXT1") || streq(p[1], "EXT2") || streq(p[1], "CUSTOM-HEADER"))
6706 && p[2])
6707 {
6708 /* In the wild patched versions use both EXT1/2 and CUSTOM-HEADER
6709 * with either two argument or one */
6710
6711 struct http_custom_header *custom_header = NULL;
6712 int i;
6713 /* Find the first free header */
6714 for (i = 0; i < MAX_CUSTOM_HTTP_HEADER; i++)
6715 {
6716 if (!ho->custom_headers[i].name)
6717 {
6718 custom_header = &ho->custom_headers[i];
6719 break;
6720 }
6721 }
6722 if (!custom_header)
6723 {
6724 msg(msglevel, "Cannot use more than %d http-proxy-option CUSTOM-HEADER : '%s'",
6726 }
6727 else
6728 {
6729 /* We will save p[2] and p[3], the proxy code will detect if
6730 * p[3] is NULL */
6731 custom_header->name = p[2];
6732 custom_header->content = p[3];
6733 }
6734 }
6735 else
6736 {
6737 msg(msglevel, "Bad http-proxy-option or missing or extra parameter: '%s'", p[1]);
6738 }
6739 }
6740 else if (streq(p[0], "socks-proxy") && p[1] && !p[4])
6741 {
6743
6744 if (p[2])
6745 {
6746 options->ce.socks_proxy_port = p[2];
6747 }
6748 else
6749 {
6750 options->ce.socks_proxy_port = "1080";
6751 }
6753 options->ce.socks_proxy_authfile = p[3]; /* might be NULL */
6754 }
6755 else if (streq(p[0], "keepalive") && p[1] && p[2] && !p[3])
6756 {
6758 options->keepalive_ping = atoi_warn(p[1], msglevel);
6759 options->keepalive_timeout = atoi_warn(p[2], msglevel);
6760 }
6761 else if (streq(p[0], "ping") && p[1] && !p[2])
6762 {
6764 options->ping_send_timeout = positive_atoi(p[1], msglevel);
6765 }
6766 else if (streq(p[0], "ping-exit") && p[1] && !p[2])
6767 {
6769 options->ping_rec_timeout = positive_atoi(p[1], msglevel);
6771 }
6772 else if (streq(p[0], "ping-restart") && p[1] && !p[2])
6773 {
6775 options->ping_rec_timeout = positive_atoi(p[1], msglevel);
6777 }
6778 else if (streq(p[0], "ping-timer-rem") && !p[1])
6779 {
6781 options->ping_timer_remote = true;
6782 }
6783 else if (streq(p[0], "explicit-exit-notify") && !p[2])
6784 {
6786 if (p[1])
6787 {
6789 }
6790 else
6791 {
6793 }
6794 }
6795 else if (streq(p[0], "persist-tun") && !p[1])
6796 {
6798 options->persist_tun = true;
6799 }
6800 else if (streq(p[0], "persist-key") && !p[1])
6801 {
6803 msg(M_WARN, "DEPRECATED OPTION: --persist-key option ignored. "
6804 "Keys are now always persisted across restarts. ");
6805 }
6806 else if (streq(p[0], "persist-local-ip") && !p[1])
6807 {
6809 options->persist_local_ip = true;
6810 }
6811 else if (streq(p[0], "persist-remote-ip") && !p[1])
6812 {
6814 options->persist_remote_ip = true;
6815 }
6816 else if (streq(p[0], "client-nat") && p[1] && p[2] && p[3] && p[4] && !p[5])
6817 {
6820 add_client_nat_to_option_list(options->client_nat, p[1], p[2], p[3], p[4], msglevel);
6821 }
6822 else if (streq(p[0], "route-table") && p[1] && !p[2])
6823 {
6824#ifndef ENABLE_SITNL
6825 msg(M_WARN, "NOTE: --route-table is supported only on Linux when SITNL is built-in");
6826#endif
6828 options->route_default_table_id = positive_atoi(p[1], msglevel);
6829 }
6830 else if (streq(p[0], "route") && p[1] && !p[5])
6831 {
6833 if (!check_route_option(options, p, msglevel, pull_mode))
6834 {
6835 goto err;
6836 }
6837 add_route_to_option_list(options->routes, p[1], p[2], p[3], p[4],
6839 }
6840 else if (streq(p[0], "route-ipv6") && p[1] && !p[4])
6841 {
6843 if (!check_route6_option(options, p, msglevel, pull_mode))
6844 {
6845 goto err;
6846 }
6849 }
6850 else if (streq(p[0], "max-routes") && !p[2])
6851 {
6852 msg(M_WARN, "DEPRECATED OPTION: --max-routes option ignored.");
6853 }
6854 else if (streq(p[0], "route-gateway") && p[1] && !p[2])
6855 {
6857 if (streq(p[1], "dhcp"))
6858 {
6860 }
6861 else
6862 {
6864 || is_special_addr(p[1])) /* FQDN -- may be DNS name */
6865 {
6867 }
6868 else
6869 {
6870 msg(msglevel, "route-gateway parm '%s' must be a valid address", p[1]);
6871 goto err;
6872 }
6873 }
6874 }
6875 else if (streq(p[0], "route-ipv6-gateway") && p[1] && !p[2])
6876 {
6877 if (ipv6_addr_safe(p[1]))
6878 {
6880 }
6881 else
6882 {
6883 msg(msglevel, "route-ipv6-gateway parm '%s' must be a valid address", p[1]);
6884 goto err;
6885 }
6886 }
6887 else if (streq(p[0], "route-metric") && p[1] && !p[2])
6888 {
6890 options->route_default_metric = positive_atoi(p[1], msglevel);
6891 }
6892 else if (streq(p[0], "route-delay") && !p[3])
6893 {
6896 if (p[1])
6897 {
6898 options->route_delay = positive_atoi(p[1], msglevel);
6899 if (p[2])
6900 {
6901 options->route_delay_window = positive_atoi(p[2], msglevel);
6902 }
6903 }
6904 else
6905 {
6906 options->route_delay = 0;
6907 }
6908 }
6909 else if (streq(p[0], "route-up") && p[1])
6910 {
6912 if (!no_more_than_n_args(msglevel, p, 2, NM_QUOTE_HINT))
6913 {
6914 goto err;
6915 }
6916 set_user_script(options, &options->route_script, p[1], "route-up", false);
6917 }
6918 else if (streq(p[0], "route-pre-down") && p[1])
6919 {
6921 if (!no_more_than_n_args(msglevel, p, 2, NM_QUOTE_HINT))
6922 {
6923 goto err;
6924 }
6925 set_user_script(options, &options->route_predown_script, p[1], "route-pre-down", true);
6926 }
6927 else if (streq(p[0], "route-noexec") && !p[1])
6928 {
6930 options->route_noexec = true;
6931 }
6932 else if (streq(p[0], "route-nopull") && !p[1])
6933 {
6935 options->route_nopull = true;
6936 }
6937 else if (streq(p[0], "pull-filter") && p[1] && p[2] && !p[3])
6938 {
6939 struct pull_filter *f;
6942
6943 if (strcmp("accept", p[1]) == 0)
6944 {
6945 f->type = PUF_TYPE_ACCEPT;
6946 }
6947 else if (strcmp("ignore", p[1]) == 0)
6948 {
6949 f->type = PUF_TYPE_IGNORE;
6950 }
6951 else if (strcmp("reject", p[1]) == 0)
6952 {
6953 f->type = PUF_TYPE_REJECT;
6954 }
6955 else
6956 {
6957 msg(msglevel, "Unknown --pull-filter type: %s", p[1]);
6958 goto err;
6959 }
6960 f->pattern = p[2];
6961 f->size = strlen(p[2]);
6962 }
6963 else if (streq(p[0], "allow-pull-fqdn") && !p[1])
6964 {
6966 options->allow_pull_fqdn = true;
6967 }
6968 else if (streq(p[0], "redirect-gateway") || streq(p[0], "redirect-private"))
6969 {
6970 int j;
6973
6974 if (options->routes->flags & RG_ENABLE)
6975 {
6976 msg(M_WARN, "WARNING: You have specified redirect-gateway and "
6977 "redirect-private at the same time (or the same option "
6978 "multiple times). This is not well supported and may lead to "
6979 "unexpected results");
6980 }
6981
6983
6984 if (streq(p[0], "redirect-gateway"))
6985 {
6987 }
6988 for (j = 1; j < MAX_PARMS && p[j] != NULL; ++j)
6989 {
6990 if (streq(p[j], "local"))
6991 {
6993 }
6994 else if (streq(p[j], "autolocal"))
6995 {
6997 }
6998 else if (streq(p[j], "def1"))
6999 {
7001 }
7002 else if (streq(p[j], "bypass-dhcp"))
7003 {
7005 }
7006 else if (streq(p[j], "bypass-dns"))
7007 {
7009 }
7010 else if (streq(p[j], "block-local"))
7011 {
7013 }
7014 else if (streq(p[j], "ipv6"))
7015 {
7018 }
7019 else if (streq(p[j], "!ipv4"))
7020 {
7022 }
7023 else
7024 {
7025 msg(msglevel, "unknown --%s flag: %s", p[0], p[j]);
7026 goto err;
7027 }
7028 }
7030 {
7031 setenv_int(es, "route_redirect_gateway_ipv4",
7032 options->routes->flags & RG_BLOCK_LOCAL ? 2 : 1);
7033 }
7035 {
7036 setenv_int(es, "route_redirect_gateway_ipv6",
7037 options->routes->flags & RG_BLOCK_LOCAL ? 2 : 1);
7038 }
7039#ifdef _WIN32
7040 /* we need this here to handle pushed --redirect-gateway */
7042#endif
7043 }
7044 else if (streq(p[0], "block-ipv6") && !p[1])
7045 {
7047 options->block_ipv6 = true;
7048 }
7049 else if (streq(p[0], "remote-random-hostname") && !p[1])
7050 {
7053 }
7054 else if (streq(p[0], "setenv") && p[1] && !p[3])
7055 {
7057 if (streq(p[1], "REMOTE_RANDOM_HOSTNAME") && !p[2])
7058 {
7060 }
7061 else if (streq(p[1], "GENERIC_CONFIG"))
7062 {
7063 msg(msglevel, "this is a generic configuration and cannot directly be used");
7064 goto err;
7065 }
7066 else if (streq(p[1], "PUSH_PEER_INFO") && !p[2])
7067 {
7068 options->push_peer_info = true;
7069 }
7070 else if (streq(p[1], "SERVER_POLL_TIMEOUT") && p[2])
7071 {
7072 options->ce.connect_timeout = positive_atoi(p[2], msglevel);
7073 }
7074 else
7075 {
7076 if (streq(p[1], "FORWARD_COMPATIBLE") && p[2] && streq(p[2], "1"))
7077 {
7079 msglevel_fc = msglevel_forward_compatible(options, msglevel);
7080 }
7081 setenv_str(es, p[1], p[2] ? p[2] : "");
7082 }
7083 }
7084 else if (streq(p[0], "compat-mode") && p[1] && !p[3])
7085 {
7086 unsigned int major, minor, patch;
7087 if (!(sscanf(p[1], "%u.%u.%u", &major, &minor, &patch) == 3))
7088 {
7089 msg(msglevel, "cannot parse version number for --compat-mode: %s", p[1]);
7090 goto err;
7091 }
7092
7093 options->backwards_compatible = major * 10000 + minor * 100 + patch;
7094 }
7095 else if (streq(p[0], "setenv-safe") && p[1] && !p[3])
7096 {
7098 setenv_str_safe(es, p[1], p[2] ? p[2] : "");
7099 }
7100 else if (streq(p[0], "script-security") && p[1] && !p[2])
7101 {
7103 int security;
7104 if (atoi_constrained(p[1], &security, p[0], SSEC_NONE, SSEC_PW_ENV, msglevel))
7105 {
7106 script_security_set(security);
7107 }
7108 }
7109 else if (streq(p[0], "mssfix") && !p[3])
7110 {
7112 if (p[1])
7113 {
7114 int mssfix;
7115 if (!atoi_constrained(p[1], &mssfix, p[0], 0, UINT16_MAX, msglevel))
7116 {
7117 goto err;
7118 }
7119 if (mssfix != 0 && mssfix < TLS_CHANNEL_MTU_MIN)
7120 {
7121 msg(msglevel, "mssfix needs to be >= %d, not %d", TLS_CHANNEL_MTU_MIN, mssfix);
7122 goto err;
7123 }
7124
7125 /* value specified, assume encapsulation is not
7126 * included unless "mtu" follows later */
7127 options->ce.mssfix = mssfix;
7128 options->ce.mssfix_encap = false;
7129 options->ce.mssfix_default = false;
7130 }
7131 else
7132 {
7133 /* Set MTU to default values */
7134 options->ce.mssfix_default = true;
7135 options->ce.mssfix_encap = true;
7136 options->ce.mssfix_fixed = false;
7137 }
7138
7139 if (p[2] && streq(p[2], "mtu"))
7140 {
7141 options->ce.mssfix_encap = true;
7142 }
7143 else if (p[2] && streq(p[2], "fixed"))
7144 {
7145 options->ce.mssfix_fixed = true;
7146 }
7147 else if (p[2])
7148 {
7149 msg(msglevel, "Unknown parameter to --mssfix: %s", p[2]);
7150 }
7151 }
7152 else if (streq(p[0], "disable-occ") && !p[1])
7153 {
7155 options->occ = false;
7156 }
7157 else if (streq(p[0], "server") && p[1] && p[2] && !p[4])
7158 {
7159 const int lev = M_WARN;
7160 bool error = false;
7161 in_addr_t network, netmask;
7162
7164 network = get_ip_addr(p[1], lev, &error);
7165 netmask = get_ip_addr(p[2], lev, &error);
7166 if (error || !network || !netmask)
7167 {
7168 msg(msglevel, "error parsing --server parameters");
7169 goto err;
7170 }
7171 options->server_defined = true;
7172 options->server_network = network;
7173 options->server_netmask = netmask;
7174
7175 if (p[3])
7176 {
7177 if (streq(p[3], "nopool"))
7178 {
7180 }
7181 else
7182 {
7183 msg(msglevel, "error parsing --server: %s is not a recognized flag", p[3]);
7184 goto err;
7185 }
7186 }
7187 }
7188 else if (streq(p[0], "server-ipv6") && p[1] && !p[2])
7189 {
7190 const int lev = M_WARN;
7191 struct in6_addr network;
7192 unsigned int netbits = 0;
7193
7195 if (!get_ipv6_addr(p[1], &network, &netbits, lev))
7196 {
7197 msg(msglevel, "error parsing --server-ipv6 parameter");
7198 goto err;
7199 }
7200 if (netbits < 64 || netbits > 124)
7201 {
7202 msg(msglevel, "--server-ipv6 settings: network must be between /64 and /124 (not /%d)",
7203 netbits);
7204
7205 goto err;
7206 }
7208 options->server_network_ipv6 = network;
7209 options->server_netbits_ipv6 = netbits;
7210 }
7211 else if (streq(p[0], "server-bridge") && p[1] && p[2] && p[3] && p[4] && !p[5])
7212 {
7213 const int lev = M_WARN;
7214 bool error = false;
7215 in_addr_t ip, netmask, pool_start, pool_end;
7216
7218 ip = get_ip_addr(p[1], lev, &error);
7219 netmask = get_ip_addr(p[2], lev, &error);
7220 pool_start = get_ip_addr(p[3], lev, &error);
7221 pool_end = get_ip_addr(p[4], lev, &error);
7222 if (error || !ip || !netmask || !pool_start || !pool_end)
7223 {
7224 msg(msglevel, "error parsing --server-bridge parameters");
7225 goto err;
7226 }
7229 options->server_bridge_netmask = netmask;
7230 options->server_bridge_pool_start = pool_start;
7231 options->server_bridge_pool_end = pool_end;
7232 }
7233 else if (streq(p[0], "server-bridge") && p[1] && streq(p[1], "nogw") && !p[2])
7234 {
7238 }
7239 else if (streq(p[0], "server-bridge") && !p[1])
7240 {
7243 }
7244 else if (streq(p[0], "push") && p[1] && !p[2])
7245 {
7247 push_options(options, &p[1], msglevel, &options->gc);
7248 }
7249 else if (streq(p[0], "push-reset") && !p[1])
7250 {
7253 }
7254 else if (streq(p[0], "push-remove") && p[1] && !p[2])
7255 {
7257 msg(D_PUSH, "PUSH_REMOVE '%s'", p[1]);
7259 }
7260 else if (streq(p[0], "ifconfig-pool") && p[1] && p[2] && !p[4])
7261 {
7262 const int lev = M_WARN;
7263 bool error = false;
7264 in_addr_t start, end, netmask = 0;
7265
7267 start = get_ip_addr(p[1], lev, &error);
7268 end = get_ip_addr(p[2], lev, &error);
7269 if (p[3])
7270 {
7271 netmask = get_ip_addr(p[3], lev, &error);
7272 }
7273 if (error)
7274 {
7275 msg(msglevel, "error parsing --ifconfig-pool parameters");
7276 goto err;
7277 }
7278 if (!ifconfig_pool_verify_range(msglevel, start, end))
7279 {
7280 goto err;
7281 }
7282
7286 if (netmask)
7287 {
7288 options->ifconfig_pool_netmask = netmask;
7289 }
7290 }
7291 else if (streq(p[0], "ifconfig-pool-persist") && p[1] && !p[3])
7292 {
7295 if (p[2])
7296 {
7298 }
7299 }
7300 else if (streq(p[0], "ifconfig-ipv6-pool") && p[1] && !p[2])
7301 {
7302 const int lev = M_WARN;
7303 struct in6_addr network;
7304 unsigned int netbits = 0;
7305
7307 if (!get_ipv6_addr(p[1], &network, &netbits, lev))
7308 {
7309 msg(msglevel, "error parsing --ifconfig-ipv6-pool parameters");
7310 goto err;
7311 }
7312 if (netbits < 64 || netbits > 124)
7313 {
7314 msg(msglevel,
7315 "--ifconfig-ipv6-pool settings: network must be between /64 and /124 (not /%d)",
7316 netbits);
7317 goto err;
7318 }
7319
7323 }
7324 else if (streq(p[0], "hash-size") && p[1] && p[2] && !p[3])
7325 {
7326 int real, virtual;
7327
7329 if (!atoi_constrained(p[1], &real, "hash-size real", 1, INT_MAX, msglevel)
7330 || !atoi_constrained(p[2], &virtual, "hash-size virtual", 1, INT_MAX, msglevel))
7331 {
7332 goto err;
7333 }
7334 options->real_hash_size = (uint32_t)real;
7335 options->virtual_hash_size = (uint32_t)virtual;
7336 }
7337 else if (streq(p[0], "connect-freq") && p[1] && p[2] && !p[3])
7338 {
7339 int cf_max, cf_per;
7340
7342 if (!atoi_constrained(p[1], &cf_max, "connect-freq n", 1, INT_MAX, msglevel)
7343 || !atoi_constrained(p[2], &cf_per, "connect-freq seconds", 1, INT_MAX, msglevel))
7344 {
7345 goto err;
7346 }
7347 options->cf_max = cf_max;
7348 options->cf_per = cf_per;
7349 }
7350 else if (streq(p[0], "connect-freq-initial") && p[1] && p[2] && !p[3])
7351 {
7352 int cf_max, cf_per;
7353
7355 if (!atoi_constrained(p[1], &cf_max, "connect-freq-initial n", 1, INT_MAX, msglevel)
7356 || !atoi_constrained(p[2], &cf_per, "connect-freq-initial seconds", 1, INT_MAX, msglevel))
7357 {
7358 goto err;
7359 }
7360 options->cf_initial_max = cf_max;
7361 options->cf_initial_per = cf_per;
7362 }
7363 else if (streq(p[0], "max-clients") && p[1] && !p[2])
7364 {
7366 if (!atoi_constrained(p[1], &options->max_clients, p[0], 1, MAX_PEER_ID, msglevel))
7367 {
7368 goto err;
7369 }
7370 }
7371 else if (streq(p[0], "max-routes-per-client") && p[1] && !p[2])
7372 {
7374 atoi_constrained(p[1], &options->max_routes_per_client, p[0], 1, INT_MAX, msglevel);
7375 }
7376 else if (streq(p[0], "client-cert-not-required") && !p[1])
7377 {
7379 msg(M_FATAL,
7380 "REMOVED OPTION: --client-cert-not-required, use '--verify-client-cert none' instead");
7381 }
7382 else if (streq(p[0], "verify-client-cert") && !p[2])
7383 {
7385
7386 /* Reset any existing flags */
7387 options->ssl_flags &= ~SSLF_CLIENT_CERT_OPTIONAL;
7388 options->ssl_flags &= ~SSLF_CLIENT_CERT_NOT_REQUIRED;
7389 if (p[1])
7390 {
7391 if (streq(p[1], "none"))
7392 {
7394 }
7395 else if (streq(p[1], "optional"))
7396 {
7398 }
7399 else if (!streq(p[1], "require"))
7400 {
7401 msg(msglevel,
7402 "parameter to --verify-client-cert must be 'none', 'optional' or 'require'");
7403 goto err;
7404 }
7405 }
7406 }
7407 else if (streq(p[0], "username-as-common-name") && !p[1])
7408 {
7411 }
7412 else if (streq(p[0], "auth-user-pass-optional") && !p[1])
7413 {
7416 }
7417 else if (streq(p[0], "opt-verify") && !p[1])
7418 {
7420 msg(M_INFO, "DEPRECATED OPTION: --opt-verify was removed in OpenVPN 2.7.");
7421 }
7422 else if (streq(p[0], "auth-user-pass-verify") && p[1])
7423 {
7425 if (!no_more_than_n_args(msglevel, p, 3, NM_QUOTE_HINT))
7426 {
7427 goto err;
7428 }
7429 if (p[2])
7430 {
7431 if (streq(p[2], "via-env"))
7432 {
7434 }
7435 else if (streq(p[2], "via-file"))
7436 {
7438 }
7439 else
7440 {
7441 msg(msglevel,
7442 "second parm to --auth-user-pass-verify must be 'via-env' or 'via-file'");
7443 goto err;
7444 }
7445 }
7446 else
7447 {
7448 msg(msglevel,
7449 "--auth-user-pass-verify requires a second parameter ('via-env' or 'via-file')");
7450 goto err;
7451 }
7453 "auth-user-pass-verify", true);
7454 }
7455 else if (streq(p[0], "auth-gen-token"))
7456 {
7459 options->auth_token_lifetime = p[1] ? positive_atoi(p[1], msglevel) : 0;
7460
7461 for (int i = 2; i < MAX_PARMS && p[i] != NULL; i++)
7462 {
7463 /* the second parameter can be the renewal time */
7464 if (i == 2 && valid_integer(p[i], true))
7465 {
7466 options->auth_token_renewal = positive_atoi(p[i], msglevel);
7467 }
7468 else if (streq(p[i], "external-auth"))
7469 {
7471 }
7472 else
7473 {
7474 msg(msglevel, "Invalid argument to auth-gen-token: %s (%d)", p[i], i);
7475 }
7476 }
7477 }
7478 else if (streq(p[0], "auth-gen-token-secret") && p[1] && !p[2])
7479 {
7483 }
7484 else if (streq(p[0], "client-connect") && p[1])
7485 {
7487 if (!no_more_than_n_args(msglevel, p, 2, NM_QUOTE_HINT))
7488 {
7489 goto err;
7490 }
7491 set_user_script(options, &options->client_connect_script, p[1], "client-connect", true);
7492 }
7493 else if (streq(p[0], "client-crresponse") && p[1])
7494 {
7496 if (!no_more_than_n_args(msglevel, p, 2, NM_QUOTE_HINT))
7497 {
7498 goto err;
7499 }
7500 set_user_script(options, &options->client_crresponse_script, p[1], "client-crresponse",
7501 true);
7502 }
7503 else if (streq(p[0], "client-disconnect") && p[1])
7504 {
7506 if (!no_more_than_n_args(msglevel, p, 2, NM_QUOTE_HINT))
7507 {
7508 goto err;
7509 }
7510 set_user_script(options, &options->client_disconnect_script, p[1], "client-disconnect",
7511 true);
7512 }
7513 else if (streq(p[0], "learn-address") && p[1])
7514 {
7516 if (!no_more_than_n_args(msglevel, p, 2, NM_QUOTE_HINT))
7517 {
7518 goto err;
7519 }
7520 set_user_script(options, &options->learn_address_script, p[1], "learn-address", true);
7521 }
7522 else if (streq(p[0], "tmp-dir") && p[1] && !p[2])
7523 {
7525 options->tmp_dir = p[1];
7526 }
7527 else if (streq(p[0], "client-config-dir") && p[1] && !p[2])
7528 {
7530 options->client_config_dir = p[1];
7531 }
7532 else if (streq(p[0], "ccd-exclusive") && !p[1])
7533 {
7535 options->ccd_exclusive = true;
7536 }
7537 else if (streq(p[0], "bcast-buffers") && p[1] && !p[2])
7538 {
7540 atoi_constrained(p[1], &options->n_bcast_buf, p[0], 1, MBUF_SIZE_MAX, msglevel);
7541 }
7542 else if (streq(p[0], "tcp-queue-limit") && p[1] && !p[2])
7543 {
7545 atoi_constrained(p[1], &options->tcp_queue_limit, p[0], 1, INT_MAX, msglevel);
7546 }
7547#if PORT_SHARE
7548 else if (streq(p[0], "port-share") && p[1] && p[2] && !p[4])
7549 {
7551 options->port_share_host = p[1];
7552 options->port_share_port = p[2];
7553 options->port_share_journal_dir = p[3];
7554 }
7555#endif
7556 else if (streq(p[0], "client-to-client") && !p[1])
7557 {
7559 options->enable_c2c = true;
7560 }
7561 else if (streq(p[0], "duplicate-cn") && !p[1])
7562 {
7564 options->duplicate_cn = true;
7565 }
7566 else if (streq(p[0], "iroute") && p[1] && !p[3])
7567 {
7569 option_iroute(options, p[1], p[2], msglevel);
7570 }
7571 else if (streq(p[0], "iroute-ipv6") && p[1] && !p[2])
7572 {
7574 option_iroute_ipv6(options, p[1], msglevel);
7575 }
7576 else if (streq(p[0], "ifconfig-push") && p[1] && p[2] && !p[4])
7577 {
7578 in_addr_t local, remote_netmask;
7579
7581 local = getaddr(GETADDR_HOST_ORDER | GETADDR_RESOLVE, p[1], 0, NULL, NULL);
7582 remote_netmask = getaddr(GETADDR_HOST_ORDER | GETADDR_RESOLVE, p[2], 0, NULL, NULL);
7583 if (local && remote_netmask)
7584 {
7587 options->push_ifconfig_remote_netmask = remote_netmask;
7588 if (p[3])
7589 {
7591 getaddr(GETADDR_HOST_ORDER | GETADDR_RESOLVE, p[3], 0, NULL, NULL);
7592 }
7593 }
7594 else
7595 {
7596 msg(msglevel, "cannot parse --ifconfig-push addresses");
7597 goto err;
7598 }
7599 }
7600 else if (streq(p[0], "ifconfig-push-constraint") && p[1] && p[2] && !p[3])
7601 {
7602 in_addr_t network, netmask;
7603
7605 network = getaddr(GETADDR_HOST_ORDER | GETADDR_RESOLVE, p[1], 0, NULL, NULL);
7606 netmask = getaddr(GETADDR_HOST_ORDER, p[2], 0, NULL, NULL);
7607 if (network && netmask)
7608 {
7612 }
7613 else
7614 {
7615 msg(msglevel, "cannot parse --ifconfig-push-constraint addresses");
7616 goto err;
7617 }
7618 }
7619 else if (streq(p[0], "ifconfig-ipv6-push") && p[1] && !p[3])
7620 {
7621 struct in6_addr local, remote;
7622 unsigned int netbits;
7623
7625
7626 if (!get_ipv6_addr(p[1], &local, &netbits, msglevel))
7627 {
7628 msg(msglevel, "cannot parse --ifconfig-ipv6-push addresses");
7629 goto err;
7630 }
7631
7632 if (p[2])
7633 {
7634 if (!get_ipv6_addr(p[2], &remote, NULL, msglevel))
7635 {
7636 msg(msglevel, "cannot parse --ifconfig-ipv6-push addresses");
7637 goto err;
7638 }
7639 }
7640 else
7641 {
7643 || !get_ipv6_addr(options->ifconfig_ipv6_local, &remote, NULL, msglevel))
7644 {
7645 msg(msglevel,
7646 "second argument to --ifconfig-ipv6-push missing and no global --ifconfig-ipv6 address set");
7647 goto err;
7648 }
7649 }
7650
7656 }
7657 else if (streq(p[0], "disable") && !p[1])
7658 {
7660 options->disable = true;
7661 }
7662 else if (streq(p[0], "override-username") && p[1] && !p[2])
7663 {
7665 if (strlen(p[1]) > USER_PASS_LEN)
7666 {
7667 msg(msglevel,
7668 "override-username exceeds the maximum length of %d "
7669 "characters",
7671
7672 /* disable the connection since ignoring the request to
7673 * set another username might cause serious problems */
7674 options->disable = true;
7675 }
7676 else
7677 {
7678 options->override_username = p[1];
7679 }
7680 }
7681 else if (streq(p[0], "tcp-nodelay") && !p[1])
7682 {
7685 }
7686 else if (streq(p[0], "stale-routes-check") && p[1] && !p[3])
7687 {
7688 int ageing_time, check_interval;
7689
7691 if (!atoi_constrained(p[1], &ageing_time, "stale-routes-check age", 1, INT_MAX, msglevel))
7692 {
7693 goto err;
7694 }
7695
7696 if (p[2])
7697 {
7698 if (!atoi_constrained(p[2], &check_interval,
7699 "stale-routes-check interval", 1, INT_MAX, msglevel))
7700 {
7701 goto err;
7702 }
7703 }
7704 else
7705 {
7706 check_interval = ageing_time;
7707 }
7708
7709 options->stale_routes_ageing_time = ageing_time;
7710 options->stale_routes_check_interval = check_interval;
7711 }
7712
7713 else if (streq(p[0], "client") && !p[1])
7714 {
7716 options->client = true;
7717 }
7718 else if (streq(p[0], "pull") && !p[1])
7719 {
7721 options->pull = true;
7722 }
7723 else if (streq(p[0], "push-continuation") && p[1] && !p[2])
7724 {
7726 atoi_constrained(p[1], &options->push_continuation, p[0], 0, 2, msglevel);
7727 }
7728 else if (streq(p[0], "auth-user-pass") && !p[2])
7729 {
7731 if (p[1])
7732 {
7735 }
7736 else
7737 {
7738 options->auth_user_pass_file = "stdin";
7739 }
7740 }
7741 else if (streq(p[0], "auth-retry") && p[1] && !p[2])
7742 {
7744 auth_retry_set(msglevel, p[1]);
7745 }
7746#ifdef ENABLE_MANAGEMENT
7747 else if (streq(p[0], "static-challenge") && p[1] && p[2] && !p[4])
7748 {
7751 if (atoi_warn(p[2], msglevel))
7752 {
7754 }
7755 if (p[3] && streq(p[3], "concat"))
7756 {
7758 }
7759 else if (p[3] && !streq(p[3], "scrv1"))
7760 {
7761 msg(msglevel, "--static-challenge: unknown format indicator '%s'", p[3]);
7762 goto err;
7763 }
7764 }
7765#endif
7766 else if (streq(p[0], "msg-channel") && p[1])
7767 {
7768#ifdef _WIN32
7770 HANDLE process = GetCurrentProcess();
7771 HANDLE handle = (HANDLE)((intptr_t)atoll(p[1]));
7772 if (!DuplicateHandle(process, handle, process, &options->msg_channel, 0, FALSE,
7773 DUPLICATE_CLOSE_SOURCE | DUPLICATE_SAME_ACCESS))
7774 {
7775 msg(msglevel, "could not duplicate service pipe handle");
7776 goto err;
7777 }
7779#else /* ifdef _WIN32 */
7780 msg(msglevel, "--msg-channel is only supported on Windows");
7781 goto err;
7782#endif
7783 }
7784#ifdef _WIN32
7785 else if (streq(p[0], "win-sys") && p[1] && !p[2])
7786 {
7788 if (streq(p[1], "env"))
7789 {
7790 msg(M_INFO, "NOTE: --win-sys env is default from OpenVPN 2.3. "
7791 "This entry will now be ignored. "
7792 "Please remove this entry from your configuration file.");
7793 }
7794 else
7795 {
7796 set_win_sys_path(p[1], es);
7797 }
7798 }
7799 else if (streq(p[0], "route-method") && p[1] && !p[2])
7800 {
7802 if (streq(p[1], "adaptive"))
7803 {
7805 }
7806 else if (streq(p[1], "ipapi"))
7807 {
7809 }
7810 else if (streq(p[1], "exe"))
7811 {
7813 }
7814 else
7815 {
7816 msg(msglevel, "--route method must be 'adaptive', 'ipapi', or 'exe'");
7817 goto err;
7818 }
7819 }
7820 else if (streq(p[0], "ip-win32") && p[1] && !p[4])
7821 {
7822 const int index = ascii2ipset(p[1]);
7823 struct tuntap_options *to = &options->tuntap_options;
7824
7826
7827 if (index < 0)
7828 {
7829 msg(msglevel, "Bad --ip-win32 method: '%s'. Allowed methods: %s", p[1],
7831 goto err;
7832 }
7833
7834 if (index == IPW32_SET_ADAPTIVE)
7835 {
7837 }
7838
7839 if (index == IPW32_SET_DHCP_MASQ)
7840 {
7841 if (p[2])
7842 {
7843 if (!streq(p[2], "default"))
7844 {
7845 int offset;
7846
7847 if (!atoi_constrained(p[2], &offset, "ip-win32 offset", -256, 256, msglevel))
7848 {
7849 goto err;
7850 }
7851 to->dhcp_masq_custom_offset = true;
7852 to->dhcp_masq_offset = offset;
7853 }
7854
7855 if (p[3])
7856 {
7857 if (!atoi_constrained(p[3], &to->dhcp_lease_time,
7858 "ip-win32 lease time", 30, INT_MAX, msglevel))
7859 {
7860 goto err;
7861 }
7862 }
7863 }
7864 }
7865 to->ip_win32_type = index;
7866 to->ip_win32_defined = true;
7867 }
7868#endif /* ifdef _WIN32 */
7869 else if (streq(p[0], "dns-updown") && p[1])
7870 {
7872 if (!no_more_than_n_args(msglevel, p, 2, NM_QUOTE_HINT))
7873 {
7874 goto err;
7875 }
7876 struct dns_options *dns = &options->dns_options;
7877 if (streq(p[1], "disable"))
7878 {
7879 dns->updown = NULL;
7881 }
7882 else if (streq(p[1], "force"))
7883 {
7884 /* force dns-updown run, even if a --up script is defined */
7885 if (!dns_updown_user_set(dns))
7886 {
7887 dns->updown = DEFAULT_DNS_UPDOWN;
7889 }
7890 }
7891 else
7892 {
7893 if (dns->updown && streq(dns->updown, DEFAULT_DNS_UPDOWN))
7894 {
7895 /* Unset the default command to prevent warnings */
7896 dns->updown = NULL;
7897 }
7898 set_user_script(options, &dns->updown, p[1], p[0], false);
7900 }
7901 }
7902 else if (streq(p[0], "dns") && p[1])
7903 {
7905 if (!check_dns_option(options, p, msglevel, pull_mode))
7906 {
7907 goto err;
7908 }
7909 }
7910 else if (streq(p[0], "dhcp-option") && p[1])
7911 {
7913#if defined(_WIN32) || defined(TARGET_ANDROID)
7915#endif
7917
7918 bool dhcp_optional = false;
7919
7920 if ((streq(p[1], "DOMAIN") || streq(p[1], "ADAPTER_DOMAIN_SUFFIX")) && p[2] && !p[3])
7921 {
7922 if (!validate_domain(p[2]))
7923 {
7924 msg(msglevel, "--dhcp-option %s contains invalid characters", p[1]);
7925 goto err;
7926 }
7927
7928 dhcp->domain = p[2];
7929 dhcp_optional = true;
7930 }
7931 else if (streq(p[1], "DOMAIN-SEARCH") && p[2] && !p[3])
7932 {
7933 if (!validate_domain(p[2]))
7934 {
7935 msg(msglevel, "--dhcp-option %s contains invalid characters", p[1]);
7936 goto err;
7937 }
7938
7939 if (dhcp->domain_search_list_len < N_SEARCH_LIST_LEN)
7940 {
7941 dhcp->domain_search_list[dhcp->domain_search_list_len++] = p[2];
7942 }
7943 else
7944 {
7945 msg(msglevel, "--dhcp-option %s: maximum of %d search entries can be specified",
7946 p[1], N_SEARCH_LIST_LEN);
7947 }
7948 dhcp_optional = true;
7949 }
7950 else if ((streq(p[1], "DNS") || streq(p[1], "DNS6")) && p[2] && !p[3]
7951 && (!strstr(p[2], ":") || ipv6_addr_safe(p[2])))
7952 {
7953 if (strstr(p[2], ":"))
7954 {
7955 dhcp_option_dns6_parse(p[2], dhcp->dns6, &dhcp->dns6_len, msglevel);
7956 }
7957 else
7958 {
7959 dhcp_option_address_parse("DNS", p[2], dhcp->dns, &dhcp->dns_len, msglevel);
7960 dhcp_optional = true;
7961 }
7962 }
7963#if defined(_WIN32) || defined(TARGET_ANDROID)
7964 else if (streq(p[1], "NBS") && p[2] && !p[3])
7965 {
7966 o->netbios_scope = p[2];
7968 }
7969 else if (streq(p[1], "NBT") && p[2] && !p[3])
7970 {
7971 int t = atoi_warn(p[2], msglevel);
7972 if (!(t == 1 || t == 2 || t == 4 || t == 8))
7973 {
7974 msg(msglevel, "--dhcp-option NBT: parameter (%d) must be 1, 2, 4, or 8", t);
7975 goto err;
7976 }
7977 o->netbios_node_type = (uint8_t)t;
7979 }
7980 else if (streq(p[1], "WINS") && p[2] && !p[3])
7981 {
7982 dhcp_option_address_parse("WINS", p[2], o->wins, &o->wins_len, msglevel);
7984 }
7985 else if (streq(p[1], "NTP") && p[2] && !p[3])
7986 {
7987 dhcp_option_address_parse("NTP", p[2], o->ntp, &o->ntp_len, msglevel);
7989 }
7990 else if (streq(p[1], "NBDD") && p[2] && !p[3])
7991 {
7992 dhcp_option_address_parse("NBDD", p[2], o->nbdd, &o->nbdd_len, msglevel);
7994 }
7995 else if (streq(p[1], "DISABLE-NBT") && !p[2])
7996 {
7997 o->disable_nbt = 1;
7999 }
8000#if defined(TARGET_ANDROID)
8001 else if (streq(p[1], "PROXY_HTTP") && p[3] && !p[4])
8002 {
8003 o->http_proxy_port = positive_atoi(p[3], msglevel);
8004 o->http_proxy = p[2];
8005 }
8006#endif
8007 else
8008 {
8009 msg(msglevel, "--dhcp-option: unknown option type '%s' or missing or unknown parameter",
8010 p[1]);
8011 goto err;
8012 }
8013#else /* if defined(_WIN32) || defined(TARGET_ANDROID) */
8014 setenv_foreign_option(options, p[1], p[2], es);
8015#endif /* if defined(_WIN32) || defined(TARGET_ANDROID) */
8016
8017 if (dhcp_optional)
8018 {
8019#if defined(_WIN32) || defined(TARGET_ANDROID)
8021#endif
8022 }
8023 }
8024#ifdef _WIN32
8025 else if (streq(p[0], "show-adapters") && !p[1])
8026 {
8029 openvpn_exit(OPENVPN_EXIT_STATUS_GOOD); /* exit point */
8030 }
8031 else if (streq(p[0], "show-net") && !p[1])
8032 {
8036 openvpn_exit(OPENVPN_EXIT_STATUS_GOOD); /* exit point */
8037 }
8038 else if (streq(p[0], "show-net-up") && !p[1])
8039 {
8041 options->show_net_up = true;
8042 }
8043 else if (streq(p[0], "tap-sleep") && p[1] && !p[2])
8044 {
8046 if (!atoi_constrained(p[1], &options->tuntap_options.tap_sleep, p[0], 0, 255, msglevel))
8047 {
8048 goto err;
8049 }
8050 }
8051 else if (streq(p[0], "dhcp-renew") && !p[1])
8052 {
8055 }
8056 else if (streq(p[0], "dhcp-pre-release") && !p[1])
8057 {
8061 }
8062 else if (streq(p[0], "dhcp-release") && !p[1])
8063 {
8064 msg(M_WARN, "Obsolete option --dhcp-release detected. This is now on by default");
8065 }
8066 else if (streq(p[0], "dhcp-internal") && p[1] && !p[2]) /* standalone method for internal use */
8067 {
8068 unsigned int adapter_index;
8071 adapter_index = atou(p[1]);
8074 {
8075 dhcp_release_by_adapter_index(adapter_index);
8076 }
8078 {
8079 dhcp_renew_by_adapter_index(adapter_index);
8080 }
8081 openvpn_exit(OPENVPN_EXIT_STATUS_GOOD); /* exit point */
8082 }
8083 else if (streq(p[0], "register-dns") && !p[1])
8084 {
8087 }
8088 else if (streq(p[0], "block-outside-dns") && !p[1])
8089 {
8091 options->block_outside_dns = true;
8092 }
8093 else if (streq(p[0], "rdns-internal") && !p[1])
8094 /* standalone method for internal use
8095 *
8096 * (if --register-dns is set, openvpn needs to call itself in a
8097 * sub-process to execute the required functions in a non-blocking
8098 * way, and uses --rdns-internal to signal that to itself)
8099 */
8100 {
8104 {
8106 }
8107 openvpn_exit(OPENVPN_EXIT_STATUS_GOOD); /* exit point */
8108 }
8109 else if (streq(p[0], "show-valid-subnets") && !p[1])
8110 {
8113 openvpn_exit(OPENVPN_EXIT_STATUS_GOOD); /* exit point */
8114 }
8115 else if (streq(p[0], "pause-exit") && !p[1])
8116 {
8119 }
8120 else if (streq(p[0], "service") && p[1] && !p[3])
8121 {
8123 options->exit_event_name = p[1];
8124 if (p[2])
8125 {
8126 options->exit_event_initial_state = (atoi_warn(p[2], msglevel) != 0);
8127 }
8128 }
8129 else if (streq(p[0], "allow-nonadmin") && !p[2])
8130 {
8133 openvpn_exit(OPENVPN_EXIT_STATUS_GOOD); /* exit point */
8134 }
8135 else if (streq(p[0], "user") && p[1] && !p[2])
8136 {
8138 msg(M_WARN, "NOTE: --user option is not implemented on Windows");
8139 }
8140 else if (streq(p[0], "group") && p[1] && !p[2])
8141 {
8143 msg(M_WARN, "NOTE: --group option is not implemented on Windows");
8144 }
8145#else /* ifdef _WIN32 */
8146 else if (streq(p[0], "user") && p[1] && !p[2])
8147 {
8149 options->username = p[1];
8150 }
8151 else if (streq(p[0], "group") && p[1] && !p[2])
8152 {
8154 options->groupname = p[1];
8155 }
8156 else if (streq(p[0], "dhcp-option") && p[1] && !p[3])
8157 {
8159 setenv_foreign_option(options, p[1], p[2], es);
8160 }
8161 else if (streq(p[0], "route-method") && p[1] && !p[2])
8162 {
8164 /* ignore when pushed to non-Windows OS */
8165 }
8166#endif /* ifdef _WIN32 */
8167#if PASSTOS_CAPABILITY
8168 else if (streq(p[0], "passtos") && !p[1])
8169 {
8171 options->passtos = true;
8172 }
8173#endif
8174 else if (streq(p[0], "allow-compression") && p[1] && !p[2])
8175 {
8177
8178 if (streq(p[1], "no"))
8179 {
8182 {
8183 msg(msglevel, "'--allow-compression no' conflicts with "
8184 " enabling compression");
8185 }
8186 }
8188 {
8189 /* Also printed on a push to hint at configuration problems */
8190 msg(msglevel,
8191 "Cannot set allow-compression to '%s' "
8192 "after set to 'no'",
8193 p[1]);
8194 goto err;
8195 }
8196 else if (streq(p[1], "asym"))
8197 {
8199 }
8200 else if (streq(p[1], "yes"))
8201 {
8202 msg(M_WARN,
8203 "DEPRECATED OPTION: \"--allow-compression yes\" has been removed. "
8204 "We will use \"asym\" mode instead. See the manual page for more information.");
8205
8207 }
8208 else
8209 {
8210 msg(msglevel,
8211 "bad allow-compression option: %s -- "
8212 "must be 'yes', 'no', or 'asym'",
8213 p[1]);
8214 goto err;
8215 }
8216 }
8217 else if (streq(p[0], "comp-lzo") && !p[2])
8218 {
8220
8221 /* All lzo variants do not use swap */
8222 options->comp.flags &= ~COMP_F_SWAP;
8224
8225 if (p[1])
8226 {
8227 if (streq(p[1], "no"))
8228 {
8230 }
8231 /* There is no actual difference anymore between these variants.
8232 * We never compress. On the server side we replace this with
8233 * --compress migrate later anyway.
8234 */
8235 else if (!(streq(p[1], "yes") || streq(p[1], "adaptive")))
8236 {
8237 msg(msglevel, "bad comp-lzo option: %s -- must be 'yes', 'no', or 'adaptive'",
8238 p[1]);
8239 goto err;
8240 }
8241 }
8243 }
8244 else if (streq(p[0], "comp-noadapt") && !p[1])
8245 {
8246 /* NO-OP since we never compress anymore */
8247 }
8248 else if (streq(p[0], "compress") && !p[2])
8249 {
8251 const char *alg = "stub";
8252 if (p[1])
8253 {
8254 alg = p[1];
8255 }
8256
8257 if (streq(alg, "stub"))
8258 {
8261 }
8262 else if (streq(alg, "stub-v2"))
8263 {
8266 }
8267 else if (streq(alg, "migrate"))
8268 {
8271 }
8272 else if (streq(alg, "lzo"))
8273 {
8275 options->comp.flags &= ~COMP_F_SWAP;
8276 }
8277 else if (streq(alg, "lz4"))
8278 {
8281 }
8282 else if (streq(alg, "lz4-v2"))
8283 {
8285 }
8286 else
8287 {
8288 msg(msglevel, "bad comp option: %s", alg);
8289 goto err;
8290 }
8291
8293 }
8294 else if (streq(p[0], "show-ciphers") && !p[1])
8295 {
8297 options->show_ciphers = true;
8298 }
8299 else if (streq(p[0], "show-digests") && !p[1])
8300 {
8302 options->show_digests = true;
8303 }
8304 else if (streq(p[0], "show-engines") && !p[1])
8305 {
8307 options->show_engines = true;
8308 }
8309 else if (streq(p[0], "key-direction") && p[1] && !p[2])
8310 {
8311 int key_direction;
8312
8314
8315 key_direction = ascii2keydirection(msglevel, p[1]);
8316 if (key_direction >= 0)
8317 {
8318 if (permission_mask & OPT_P_GENERAL)
8319 {
8320 options->key_direction = key_direction;
8321 }
8322 else if (permission_mask & OPT_P_CONNECTION)
8323 {
8324 options->ce.key_direction = key_direction;
8325 }
8326 }
8327 else
8328 {
8329 goto err;
8330 }
8331 }
8332 else if (streq(p[0], "secret") && p[1] && !p[3])
8333 {
8334 msg(M_WARN, "DEPRECATED OPTION: The option --secret is deprecated.");
8338 if (!is_inline && p[2])
8339 {
8340 int key_direction;
8341
8342 key_direction = ascii2keydirection(msglevel, p[2]);
8343 if (key_direction >= 0)
8344 {
8345 options->key_direction = key_direction;
8346 }
8347 else
8348 {
8349 goto err;
8350 }
8351 }
8352 }
8353 else if (streq(p[0], "allow-deprecated-insecure-static-crypto"))
8354 {
8357 }
8358 else if (streq(p[0], "genkey") && !p[4])
8359 {
8361 options->genkey = true;
8362 if (!p[1])
8363 {
8365 }
8366 else
8367 {
8368 if (streq(p[1], "secret") || streq(p[1], "tls-auth") || streq(p[1], "tls-crypt"))
8369 {
8371 }
8372 else if (streq(p[1], "tls-crypt-v2-server"))
8373 {
8375 }
8376 else if (streq(p[1], "tls-crypt-v2-client"))
8377 {
8379 if (p[3])
8380 {
8381 options->genkey_extra_data = p[3];
8382 }
8383 }
8384 else if (streq(p[1], "auth-token"))
8385 {
8387 }
8388 else
8389 {
8390 msg(msglevel, "unknown --genkey type: %s", p[1]);
8391 }
8392 }
8393 if (p[2])
8394 {
8395 options->genkey_filename = p[2];
8396 }
8397 }
8398 else if (streq(p[0], "auth") && p[1] && !p[2])
8399 {
8401 options->authname = p[1];
8402 }
8403 else if (streq(p[0], "cipher") && p[1] && !p[2])
8404 {
8406 options->ciphername = p[1];
8407 }
8408 else if (streq(p[0], "data-ciphers-fallback") && p[1] && !p[2])
8409 {
8411 options->ciphername = p[1];
8413 }
8414 else if ((streq(p[0], "data-ciphers") || streq(p[0], "ncp-ciphers")) && p[1] && !p[2])
8415 {
8417 if (streq(p[0], "ncp-ciphers"))
8418 {
8419 msg(M_INFO, "Note: Treating option '--ncp-ciphers' as "
8420 " '--data-ciphers' (renamed in OpenVPN 2.5).");
8421 }
8422 options->ncp_ciphers = p[1];
8423 }
8424 else if (streq(p[0], "key-derivation") && p[1])
8425 {
8426 /* NCP only option that is pushed by the server to enable EKM,
8427 * should not be used by normal users in config files*/
8429 if (streq(p[1], "tls-ekm"))
8430 {
8432 }
8433 else
8434 {
8435 msg(msglevel, "Unknown key-derivation method %s", p[1]);
8436 }
8437 }
8438 else if (streq(p[0], "protocol-flags") && p[1])
8439 {
8440 /* NCP only option that is pushed by the server to enable protocol
8441 * features that are negotiated, should not be used by normal users
8442 * in config files */
8444 for (size_t j = 1; j < MAX_PARMS && p[j] != NULL; j++)
8445 {
8446 if (streq(p[j], "cc-exit"))
8447 {
8449 }
8450 else if (streq(p[j], "tls-ekm"))
8451 {
8453 }
8454 else if (streq(p[j], "dyn-tls-crypt"))
8455 {
8457 }
8458 else if (streq(p[j], "aead-epoch"))
8459 {
8461 }
8462 else
8463 {
8464 msg(msglevel, "Unknown protocol-flags flag: %s", p[j]);
8465 }
8466 }
8467 }
8468 else if (streq(p[0], "force-tls-key-material-export"))
8469 {
8472 }
8473 else if (streq(p[0], "prng") && p[1] && !p[3])
8474 {
8475 msg(M_WARN, "NOTICE: --prng option ignored (SSL library PRNG is used)");
8476 }
8477 else if (streq(p[0], "no-replay") && !p[1])
8478 {
8480 /* always error out, this breaks the connection */
8481 msg(M_FATAL, "--no-replay was removed in OpenVPN 2.7. "
8482 "Update your configuration.");
8483 }
8484 else if (streq(p[0], "replay-window") && !p[3])
8485 {
8487 if (p[1])
8488 {
8489 if (!atoi_constrained(p[1], &options->replay_window, "replay-window windows size",
8491 {
8492 goto err;
8493 }
8494
8495 if (p[2])
8496 {
8497 if (!atoi_constrained(p[2], &options->replay_time, "replay-window time window",
8499 {
8500 goto err;
8501 }
8502 }
8503 }
8504 else
8505 {
8506 msg(msglevel, "replay-window option is missing window size parameter");
8507 goto err;
8508 }
8509 }
8510 else if (streq(p[0], "mute-replay-warnings") && !p[1])
8511 {
8514 }
8515 else if (streq(p[0], "replay-persist") && p[1] && !p[2])
8516 {
8518 options->packet_id_file = p[1];
8519 }
8520 else if (streq(p[0], "test-crypto") && !p[1])
8521 {
8523 options->test_crypto = true;
8524 }
8525#ifndef ENABLE_CRYPTO_MBEDTLS
8526 else if (streq(p[0], "engine") && !p[2])
8527 {
8529 if (p[1])
8530 {
8531 options->engine = p[1];
8532 }
8533 else
8534 {
8535 options->engine = "auto";
8536 }
8537 }
8538#endif /* ENABLE_CRYPTO_MBEDTLS */
8539 else if (streq(p[0], "providers") && p[1])
8540 {
8541 for (size_t j = 1; j < MAX_PARMS && p[j] != NULL; j++)
8542 {
8543 options->providers.names[j] = p[j];
8544 }
8545 }
8546#ifdef ENABLE_PREDICTION_RESISTANCE
8547 else if (streq(p[0], "use-prediction-resistance") && !p[1])
8548 {
8550 options->use_prediction_resistance = true;
8551 }
8552#endif
8553 else if (streq(p[0], "show-tls") && !p[1])
8554 {
8556 options->show_tls_ciphers = true;
8557 }
8558 else if ((streq(p[0], "show-curves") || streq(p[0], "show-groups")) && !p[1])
8559 {
8561 options->show_curves = true;
8562 }
8563 else if (streq(p[0], "ecdh-curve") && p[1] && !p[2])
8564 {
8566 msg(M_WARN, "Consider setting groups/curves preference with "
8567 "tls-groups instead of forcing a specific curve with "
8568 "ecdh-curve.");
8569 options->ecdh_curve = p[1];
8570 }
8571 else if (streq(p[0], "tls-server") && !p[1])
8572 {
8574 options->tls_server = true;
8575 }
8576 else if (streq(p[0], "tls-client") && !p[1])
8577 {
8579 options->tls_client = true;
8580 }
8581 else if (streq(p[0], "ca") && p[1] && !p[2])
8582 {
8584 options->ca_file = p[1];
8585 options->ca_file_inline = is_inline;
8586 }
8587#ifndef ENABLE_CRYPTO_MBEDTLS
8588 else if (streq(p[0], "capath") && p[1] && !p[2])
8589 {
8591 options->ca_path = p[1];
8592 }
8593#endif /* ENABLE_CRYPTO_MBEDTLS */
8594 else if (streq(p[0], "dh") && p[1] && !p[2])
8595 {
8597 options->dh_file = p[1];
8598 options->dh_file_inline = is_inline;
8599 }
8600 else if (streq(p[0], "cert") && p[1] && !p[2])
8601 {
8603 options->cert_file = p[1];
8604 options->cert_file_inline = is_inline;
8605 }
8606 else if (streq(p[0], "extra-certs") && p[1] && !p[2])
8607 {
8609 options->extra_certs_file = p[1];
8610 options->extra_certs_file_inline = is_inline;
8611 }
8612 else if ((streq(p[0], "verify-hash") && p[1] && !p[3])
8613 || (streq(p[0], "peer-fingerprint") && p[1] && !p[2]))
8614 {
8616
8617 int verify_hash_depth = 0;
8618 if (streq(p[0], "verify-hash"))
8619 {
8620 msg(M_WARN, "DEPRECATED OPTION: The option --verify-hash is deprecated. "
8621 "You should switch to the either use the level 1 certificate as "
8622 "--ca option, use --tls-verify or use --peer-fingerprint");
8623 /* verify level 1 cert, i.e. the CA that signed the leaf cert */
8624 verify_hash_depth = 1;
8625 }
8626
8628
8629 int digest_len = SHA256_DIGEST_LENGTH;
8630
8631 if (options->verify_hash && options->verify_hash_depth != verify_hash_depth)
8632 {
8633 msg(msglevel,
8634 "ERROR: Setting %s not allowed. --verify-hash and"
8635 " --peer-fingerprint are mutually exclusive",
8636 p[0]);
8637 goto err;
8638 }
8639
8640 if (streq(p[0], "verify-hash"))
8641 {
8642 if ((!p[2] && !is_inline) || (p[2] && streq(p[2], "SHA1")))
8643 {
8645 digest_len = SHA_DIGEST_LENGTH;
8646 }
8647 else if (p[2] && !streq(p[2], "SHA256"))
8648 {
8649 msg(msglevel,
8650 "invalid or unsupported hashing algorithm: %s "
8651 "(only SHA1 and SHA256 are supported)",
8652 p[2]);
8653 goto err;
8654 }
8655 }
8656
8657 struct verify_hash_list *newlist;
8658 newlist = parse_hash_fingerprint_multiline(p[1], digest_len, msglevel, &options->gc);
8659
8660 /* Append the new list to the end of our current list */
8661 if (!options->verify_hash)
8662 {
8663 options->verify_hash = newlist;
8664 options->verify_hash_depth = verify_hash_depth;
8665 }
8666 else
8667 {
8668 /* since both the old and new list can have multiple entries
8669 * we need to go to the end of one of them to concatenate them */
8670 struct verify_hash_list *listend = options->verify_hash;
8671 while (listend->next)
8672 {
8673 listend = listend->next;
8674 }
8675 listend->next = newlist;
8676 }
8677 }
8678#if defined(ENABLE_CRYPTOAPI) && defined(HAVE_XKEY_PROVIDER)
8679 else if (streq(p[0], "cryptoapicert") && p[1] && !p[2])
8680 {
8682 options->cryptoapi_cert = p[1];
8683 }
8684#endif
8685 else if (streq(p[0], "key") && p[1] && !p[2])
8686 {
8688 options->priv_key_file = p[1];
8689 options->priv_key_file_inline = is_inline;
8690 }
8691 else if (streq(p[0], "tls-version-min") && p[1] && !p[3])
8692 {
8694 int ver = tls_version_parse(p[1], p[2]);
8695 if (ver == TLS_VER_BAD)
8696 {
8697 msg(msglevel, "unknown tls-version-min parameter: %s", p[1]);
8698 goto err;
8699 }
8700
8701#ifdef ENABLE_CRYPTO_MBEDTLS
8702 if (ver < TLS_VER_1_2)
8703 {
8704 msg(M_WARN, "--tls-version-min %s is not supported by mbedtls, using 1.2", p[1]);
8705 ver = TLS_VER_1_2;
8706 }
8707#endif
8708
8710 options->ssl_flags |= ((unsigned int)ver << SSLF_TLS_VERSION_MIN_SHIFT);
8711 }
8712 else if (streq(p[0], "tls-version-max") && p[1] && !p[2])
8713 {
8715 int ver = tls_version_parse(p[1], NULL);
8716 if (ver == TLS_VER_BAD)
8717 {
8718 msg(msglevel, "unknown tls-version-max parameter: %s", p[1]);
8719 goto err;
8720 }
8722 options->ssl_flags |= ((unsigned int)ver << SSLF_TLS_VERSION_MAX_SHIFT);
8723 }
8724#ifndef ENABLE_CRYPTO_MBEDTLS
8725 else if (streq(p[0], "pkcs12") && p[1] && !p[2])
8726 {
8728 options->pkcs12_file = p[1];
8729 options->pkcs12_file_inline = is_inline;
8730 }
8731#endif /* ENABLE_CRYPTO_MBEDTLS */
8732 else if (streq(p[0], "askpass") && !p[2])
8733 {
8735 if (p[1])
8736 {
8737 options->key_pass_file = p[1];
8738 }
8739 else
8740 {
8741 options->key_pass_file = "stdin";
8742 }
8743 }
8744 else if (streq(p[0], "auth-nocache") && !p[1])
8745 {
8748 }
8749 else if (streq(p[0], "auth-token") && p[1] && !p[2])
8750 {
8752 ssl_set_auth_token(p[1]);
8753#ifdef ENABLE_MANAGEMENT
8754 if (management)
8755 {
8757 }
8758#endif
8759 }
8760 else if (streq(p[0], "auth-token-user") && p[1] && !p[2])
8761 {
8764 }
8765 else if (streq(p[0], "single-session") && !p[1])
8766 {
8768 options->single_session = true;
8769 }
8770 else if (streq(p[0], "push-peer-info") && !p[1])
8771 {
8773 options->push_peer_info = true;
8774 }
8775 else if (streq(p[0], "tls-exit") && !p[1])
8776 {
8778 options->tls_exit = true;
8779 }
8780 else if (streq(p[0], "tls-cipher") && p[1] && !p[2])
8781 {
8783 options->cipher_list = p[1];
8784 }
8785 else if (streq(p[0], "tls-cert-profile") && p[1] && !p[2])
8786 {
8788 options->tls_cert_profile = p[1];
8789 }
8790 else if (streq(p[0], "tls-ciphersuites") && p[1] && !p[2])
8791 {
8793 options->cipher_list_tls13 = p[1];
8794 }
8795 else if (streq(p[0], "tls-groups") && p[1] && !p[2])
8796 {
8798 options->tls_groups = p[1];
8799 }
8800 else if (streq(p[0], "crl-verify") && p[1] && ((p[2] && streq(p[2], "dir")) || !p[2]))
8801 {
8803 if (p[2] && streq(p[2], "dir"))
8804 {
8806 }
8807 options->crl_file = p[1];
8808 options->crl_file_inline = is_inline;
8809 }
8810 else if (streq(p[0], "tls-verify") && p[1])
8811 {
8813 if (!no_more_than_n_args(msglevel, p, 2, NM_QUOTE_HINT))
8814 {
8815 goto err;
8816 }
8818 string_substitute(p[1], ',', ' ', &options->gc), "tls-verify", true);
8819 }
8820 else if (streq(p[0], "tls-export-cert") && p[1] && !p[2])
8821 {
8824 }
8825 else if (streq(p[0], "compat-names"))
8826 {
8828 msg(msglevel, "--compat-names was removed in OpenVPN 2.5. "
8829 "Update your configuration.");
8830 goto err;
8831 }
8832 else if (streq(p[0], "no-name-remapping") && !p[1])
8833 {
8835 msg(msglevel, "--no-name-remapping was removed in OpenVPN 2.5. "
8836 "Update your configuration.");
8837 goto err;
8838 }
8839 else if (streq(p[0], "verify-x509-name") && p[1] && strlen(p[1]) && !p[3])
8840 {
8841 int type = VERIFY_X509_SUBJECT_DN;
8843 if (p[2])
8844 {
8845 if (streq(p[2], "subject"))
8846 {
8848 }
8849 else if (streq(p[2], "name"))
8850 {
8852 }
8853 else if (streq(p[2], "name-prefix"))
8854 {
8856 }
8857 else
8858 {
8859 msg(msglevel, "unknown X.509 name type: %s", p[2]);
8860 goto err;
8861 }
8862 }
8863 options->verify_x509_type = type;
8864 options->verify_x509_name = p[1];
8865 }
8866 else if (streq(p[0], "ns-cert-type") && p[1] && !p[2])
8867 {
8868#ifdef ENABLE_CRYPTO_MBEDTLS
8869 msg(msglevel, "--ns-cert-type is not available with mbedtls.");
8870 goto err;
8871#else
8873 if (streq(p[1], "server"))
8874 {
8876 }
8877 else if (streq(p[1], "client"))
8878 {
8880 }
8881 else
8882 {
8883 msg(msglevel, "--ns-cert-type must be 'client' or 'server'");
8884 goto err;
8885 }
8886#endif /* ENABLE_CRYPTO_MBEDTLS */
8887 }
8888 else if (streq(p[0], "remote-cert-ku"))
8889 {
8891
8892 size_t j;
8893 for (j = 1; j < MAX_PARMS && p[j] != NULL; ++j)
8894 {
8895 sscanf(p[j], "%x", &(options->remote_cert_ku[j - 1]));
8896 }
8897 if (j == 1)
8898 {
8899 /* No specific KU required, but require KU to be present */
8901 }
8902 }
8903 else if (streq(p[0], "remote-cert-eku") && p[1] && !p[2])
8904 {
8906 options->remote_cert_eku = p[1];
8907 }
8908 else if (streq(p[0], "remote-cert-tls") && p[1] && !p[2])
8909 {
8911
8912 if (streq(p[1], "server"))
8913 {
8915 options->remote_cert_eku = "TLS Web Server Authentication";
8916 }
8917 else if (streq(p[1], "client"))
8918 {
8920 options->remote_cert_eku = "TLS Web Client Authentication";
8921 }
8922 else
8923 {
8924 msg(msglevel, "--remote-cert-tls must be 'client' or 'server'");
8925 goto err;
8926 }
8927 }
8928 else if (streq(p[0], "tls-timeout") && p[1] && !p[2])
8929 {
8931 options->tls_timeout = positive_atoi(p[1], msglevel);
8932 }
8933 else if (streq(p[0], "reneg-bytes") && p[1] && !p[2])
8934 {
8936 if (!positive_atoll(p[1], &options->renegotiate_bytes, p[0], msglevel))
8937 {
8938 goto err;
8939 }
8940 }
8941 else if (streq(p[0], "reneg-pkts") && p[1] && !p[2])
8942 {
8944 if (!positive_atoll(p[1], &options->renegotiate_packets, p[0], msglevel))
8945 {
8946 goto err;
8947 }
8948 }
8949 else if (streq(p[0], "reneg-sec") && p[1] && !p[3])
8950 {
8952 options->renegotiate_seconds = positive_atoi(p[1], msglevel);
8953 if (p[2])
8954 {
8956 }
8957 }
8958 else if (streq(p[0], "hand-window") && p[1] && !p[2])
8959 {
8961 options->handshake_window = positive_atoi(p[1], msglevel);
8962 }
8963 else if (streq(p[0], "tran-window") && p[1] && !p[2])
8964 {
8966 options->transition_window = positive_atoi(p[1], msglevel);
8967 }
8968 else if (streq(p[0], "tls-auth") && p[1] && !p[3])
8969 {
8970 int key_direction = -1;
8971
8973
8974 if (permission_mask & OPT_P_GENERAL)
8975 {
8976 options->tls_auth_file = p[1];
8977 options->tls_auth_file_inline = is_inline;
8978
8979 if (!is_inline && p[2])
8980 {
8981 key_direction = ascii2keydirection(msglevel, p[2]);
8982 if (key_direction < 0)
8983 {
8984 goto err;
8985 }
8986 options->key_direction = key_direction;
8987 }
8988 }
8989 else if (permission_mask & OPT_P_CONNECTION)
8990 {
8991 options->ce.tls_auth_file = p[1];
8992 options->ce.tls_auth_file_inline = is_inline;
8994
8995 if (!is_inline && p[2])
8996 {
8997 key_direction = ascii2keydirection(msglevel, p[2]);
8998 if (key_direction < 0)
8999 {
9000 goto err;
9001 }
9002 options->ce.key_direction = key_direction;
9003 }
9004 }
9005 }
9006 else if (streq(p[0], "tls-crypt") && p[1] && !p[3])
9007 {
9009 if (permission_mask & OPT_P_GENERAL)
9010 {
9011 options->tls_crypt_file = p[1];
9012 options->tls_crypt_file_inline = is_inline;
9013 }
9014 else if (permission_mask & OPT_P_CONNECTION)
9015 {
9016 options->ce.tls_crypt_file = p[1];
9017 options->ce.tls_crypt_file_inline = is_inline;
9018 }
9019 }
9020 else if (streq(p[0], "tls-crypt-v2") && p[1] && !p[3])
9021 {
9023 if (permission_mask & OPT_P_GENERAL)
9024 {
9025 options->tls_crypt_v2_file = p[1];
9026 options->tls_crypt_v2_file_inline = is_inline;
9027 }
9028 else if (permission_mask & OPT_P_CONNECTION)
9029 {
9031 options->ce.tls_crypt_v2_file_inline = is_inline;
9032 }
9033
9034 if (p[2] && streq(p[2], "force-cookie"))
9035 {
9037 }
9038 else if (p[2] && streq(p[2], "allow-noncookie"))
9039 {
9041 }
9042 else if (p[2])
9043 {
9044 msg(msglevel, "Unsupported tls-crypt-v2 argument: %s", p[2]);
9045 }
9046 }
9047 else if (streq(p[0], "tls-crypt-v2-verify") && p[1] && !p[2])
9048 {
9051 }
9052 else if (streq(p[0], "tls-crypt-v2-max-age") && p[1])
9053 {
9055 if (!atoi_constrained(p[1], &options->tls_crypt_v2_max_age, "tls-crypt-v2-max-age", 1, INT_MAX, msglevel))
9056 {
9057 goto err;
9058 }
9059 }
9060 else if (streq(p[0], "x509-track") && p[1] && !p[2])
9061 {
9063 x509_track_add(&options->x509_track, p[1], msglevel, &options->gc);
9064 }
9065 else if (streq(p[0], "x509-username-field") && p[1])
9066 {
9068 for (size_t j = 1; j < MAX_PARMS && p[j] != NULL; ++j)
9069 {
9070 char *s = p[j];
9071
9072 if (strncmp("ext:", s, 4) == 0 && !x509_username_field_ext_supported(s + 4))
9073 {
9074 msg(msglevel, "Unsupported x509-username-field extension: %s", s);
9075 }
9076 options->x509_username_field[j - 1] = p[j];
9077 }
9078 }
9079#ifdef ENABLE_PKCS11
9080 else if (streq(p[0], "show-pkcs11-ids") && !p[3])
9081 {
9082 char *provider = p[1];
9083 bool cert_private = (p[2] == NULL ? false : (atoi_warn(p[2], msglevel) != 0));
9084
9085#ifdef DEFAULT_PKCS11_MODULE
9086 if (!provider)
9087 {
9088 provider = DEFAULT_PKCS11_MODULE;
9089 }
9090 else if (!p[2])
9091 {
9092 char *endp = NULL;
9093 long i = strtol(provider, &endp, 10);
9094
9095 if (*endp == 0)
9096 {
9097 /* There was one argument, and it was purely numeric.
9098 * Interpret it as the cert_private argument */
9099 provider = DEFAULT_PKCS11_MODULE;
9100 cert_private = i;
9101 }
9102 }
9103#else /* ifdef DEFAULT_PKCS11_MODULE */
9104 if (!provider)
9105 {
9106 msg(msglevel, "--show-pkcs11-ids requires a provider parameter");
9107 goto err;
9108 }
9109#endif /* ifdef DEFAULT_PKCS11_MODULE */
9111
9113 show_pkcs11_ids(provider, cert_private);
9114 openvpn_exit(OPENVPN_EXIT_STATUS_GOOD); /* exit point */
9115 }
9116 else if (streq(p[0], "pkcs11-providers") && p[1])
9117 {
9118 int j;
9119
9121
9122 for (j = 1; j < MAX_PARMS && p[j] != NULL; ++j)
9123 {
9124 options->pkcs11_providers[j - 1] = p[j];
9125 }
9126 }
9127 else if (streq(p[0], "pkcs11-protected-authentication"))
9128 {
9129 int j;
9130
9132
9133 for (j = 1; j < MAX_PARMS && p[j] != NULL; ++j)
9134 {
9135 options->pkcs11_protected_authentication[j - 1] =
9136 atoi_warn(p[j], msglevel) != 0 ? 1 : 0;
9137 }
9138 }
9139 else if (streq(p[0], "pkcs11-private-mode") && p[1])
9140 {
9141 int j;
9142
9144
9145 for (j = 1; j < MAX_PARMS && p[j] != NULL; ++j)
9146 {
9147 sscanf(p[j], "%x", &(options->pkcs11_private_mode[j - 1]));
9148 }
9149 }
9150 else if (streq(p[0], "pkcs11-cert-private"))
9151 {
9152 int j;
9153
9155
9156 for (j = 1; j < MAX_PARMS && p[j] != NULL; ++j)
9157 {
9158 options->pkcs11_cert_private[j - 1] = (bool)(atoi_warn(p[j], msglevel));
9159 }
9160 }
9161 else if (streq(p[0], "pkcs11-pin-cache") && p[1] && !p[2])
9162 {
9164 options->pkcs11_pin_cache_period = positive_atoi(p[1], msglevel);
9165 }
9166 else if (streq(p[0], "pkcs11-id") && p[1] && !p[2])
9167 {
9169 options->pkcs11_id = p[1];
9170 }
9171 else if (streq(p[0], "pkcs11-id-management") && !p[1])
9172 {
9174 options->pkcs11_id_management = true;
9175 }
9176#endif /* ifdef ENABLE_PKCS11 */
9177 else if (streq(p[0], "rmtun") && !p[1])
9178 {
9180 options->persist_config = true;
9181 options->persist_mode = 0;
9182 }
9183 else if (streq(p[0], "mktun") && !p[1])
9184 {
9186 options->persist_config = true;
9187 options->persist_mode = 1;
9188 }
9189 else if (streq(p[0], "peer-id") && p[1] && !p[2])
9190 {
9192 options->use_peer_id = true;
9193 options->peer_id = atoi_warn(p[1], msglevel);
9194 }
9195 else if (streq(p[0], "keying-material-exporter") && p[1] && p[2])
9196 {
9198
9199 if (strncmp(p[1], "EXPORTER", 8))
9200 {
9201 msg(msglevel, "Keying material exporter label must begin with "
9202 "\"EXPORTER\"");
9203 goto err;
9204 }
9205 if (streq(p[1], EXPORT_KEY_DATA_LABEL))
9206 {
9207 msg(msglevel,
9208 "Keying material exporter label must not be '" EXPORT_KEY_DATA_LABEL "'.");
9209 }
9210
9212 p[0], 16, 4095, msglevel))
9213 {
9214 goto err;
9215 }
9216
9218 }
9219 else if (streq(p[0], "allow-recursive-routing") && !p[1])
9220 {
9223 }
9224 else if (streq(p[0], "vlan-tagging") && !p[1])
9225 {
9227 options->vlan_tagging = true;
9228 }
9229 else if (streq(p[0], "vlan-accept") && p[1] && !p[2])
9230 {
9232 if (streq(p[1], "tagged"))
9233 {
9235 }
9236 else if (streq(p[1], "untagged"))
9237 {
9239 }
9240 else if (streq(p[1], "all"))
9241 {
9243 }
9244 else
9245 {
9246 msg(msglevel, "--vlan-accept must be 'tagged', 'untagged' or 'all'");
9247 goto err;
9248 }
9249 }
9250 else if (streq(p[0], "vlan-pvid") && p[1] && !p[2])
9251 {
9252 int vlan_pvid;
9254 if (!atoi_constrained(p[1], &vlan_pvid, p[0],
9256 {
9257 goto err;
9258 }
9259 options->vlan_pvid = (uint16_t)vlan_pvid;
9260 }
9261 else
9262 {
9263 int i;
9264 msglvl_t msglevel_unknown = msglevel_fc;
9265 /* Check if an option is in --ignore-unknown-option and
9266 * set warning level to non fatal */
9268 {
9269 if (streq(p[0], options->ignore_unknown_option[i]))
9270 {
9271 msglevel_unknown = M_WARN;
9272 break;
9273 }
9274 }
9275 if (file)
9276 {
9277 msg(msglevel_unknown,
9278 "Unrecognized option or missing or extra parameter(s) in %s:%d: %s (%s)", file,
9279 line, p[0], PACKAGE_VERSION);
9280 }
9281 else
9282 {
9283 msg(msglevel_unknown, "Unrecognized option or missing or extra parameter(s): --%s (%s)",
9284 p[0], PACKAGE_VERSION);
9285 }
9286 }
9287err:
9288 gc_free(&gc);
9289}
9290
9291bool
9293{
9294 if (options->ce.local_list)
9295 {
9296 for (int i = 0; i < options->ce.local_list->len; i++)
9297 {
9299 {
9300 return true;
9301 }
9302 }
9303 }
9304
9305 return false;
9306}
void argv_parse_cmd(struct argv *argres, const char *cmdstr)
Parses a command string, tokenizes it and puts each element into a separate struct argv argument slot...
Definition argv.c:481
void argv_free(struct argv *a)
Frees all memory allocations allocated by the struct argv related functions.
Definition argv.c:101
struct argv argv_new(void)
Allocates a new struct argv and ensures it is initialised.
Definition argv.c:87
void buf_clear(struct buffer *buf)
Definition buffer.c:163
bool buf_printf(struct buffer *buf, const char *format,...)
Definition buffer.c:241
void gc_transfer(struct gc_arena *dest, struct gc_arena *src)
Definition buffer.c:460
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:370
void * gc_malloc(size_t size, bool clear, struct gc_arena *a)
Definition buffer.c:336
struct buffer alloc_buf_gc(size_t size, struct gc_arena *gc)
Definition buffer.c:89
char * format_hex_ex(const uint8_t *data, size_t size, size_t maxoutput, unsigned int space_break_flags, const char *separator, struct gc_arena *gc)
Definition buffer.c:483
struct buffer alloc_buf(size_t size)
Definition buffer.c:63
int string_array_len(const char **array)
Definition buffer.c:702
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:1352
bool buf_parse(struct buffer *buf, const int delim, char *line, const int size)
Definition buffer.c:824
char * string_alloc(const char *str, struct gc_arena *gc)
Definition buffer.c:648
struct buffer string_alloc_buf(const char *str, struct gc_arena *gc)
Definition buffer.c:751
static void gc_detach(struct gc_arena *a)
Definition buffer.h:1011
#define BSTR(buf)
Definition buffer.h:128
#define BPTR(buf)
Definition buffer.h:123
#define ALLOC_ARRAY_GC(dptr, type, n, gc)
Definition buffer.h:1075
static bool buf_valid(const struct buffer *buf)
Definition buffer.h:234
static void gc_init(struct gc_arena *a)
Definition buffer.h:1004
#define ALLOC_OBJ_CLEAR_GC(dptr, type, gc)
Definition buffer.h:1101
#define ALLOC_OBJ_GC(dptr, type, gc)
Definition buffer.h:1096
static void strncpynt(char *dest, const char *src, size_t maxlen)
Definition buffer.h:361
static void gc_free(struct gc_arena *a)
Definition buffer.h:1025
static bool strprefix(const char *str, const char *prefix)
Return true iff str starts with prefix.
Definition buffer.h:969
static struct gc_arena gc_new(void)
Definition buffer.h:1017
void add_client_nat_to_option_list(struct client_nat_option_list *dest, const char *type, const char *network, const char *netmask, const char *foreign_network, msglvl_t msglevel)
Definition clinat.c:102
void print_client_nat_list(const struct client_nat_option_list *list, msglvl_t msglevel)
Definition clinat.c:50
struct client_nat_option_list * new_client_nat_list(struct gc_arena *gc)
Definition clinat.c:71
struct client_nat_option_list * clone_client_nat_option_list(const struct client_nat_option_list *src, struct gc_arena *gc)
Definition clinat.c:79
void copy_client_nat_option_list(struct client_nat_option_list *dest, const struct client_nat_option_list *src)
Definition clinat.c:88
#define TLS_CHANNEL_BUF_SIZE
Definition common.h:70
#define TLS_CHANNEL_MTU_MIN
Definition common.h:83
bool check_compression_settings_valid(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
int daemon(int nochdir, int noclose)
char * dirname(char *path)
char * strsep(char **stringp, const char *delim)
void init_key_type(struct key_type *kt, const char *ciphername, const char *authname, bool tls_mode, bool warn)
Initialize a key_type structure with.
Definition crypto.c:875
int ascii2keydirection(msglvl_t msglevel, const char *str)
Definition crypto.c:1632
const char * keydirection2ascii(int kd, bool remote, bool humanreadable)
Definition crypto.c:1655
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:1915
void test_crypto(struct crypto_options *co, struct frame *frame)
Definition crypto.c:1199
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
static bool cipher_defined(const char *ciphername)
Checks if the cipher is defined and is not the null (none) cipher.
const char * md_kt_name(const char *mdname)
Retrieve a string describing the digest digest (e.g.
const char * cipher_kt_name(const char *ciphername)
Retrieve a normalised string describing the cipher (e.g.
int cipher_kt_key_size(const char *ciphername)
Returns the size of keys used by the cipher, in bytes.
#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 show_dns_options(const struct dns_options *o)
Prints configured DNS options.
Definition dns.c:780
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:291
void setenv_str_i(struct env_set *es, const char *name, const char *value, const int i)
Definition env_set.c:423
void setenv_str(struct env_set *es, const char *name, const char *value)
Definition env_set.c:307
const char * env_set_get(const struct env_set *es, const char *name)
Definition env_set.c:201
void setenv_str_safe(struct env_set *es, const char *name, const char *value)
Definition env_set.c:313
bool env_set_del(struct env_set *es, const char *str)
Definition env_set.c:183
void setenv_long_long(struct env_set *es, const char *name, long long value)
Definition env_set.c:299
#define D_SHOW_OCC
Definition errlevel.h:150
#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_SHOW_PARMS
Definition errlevel.h:95
#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.
void helper_setdefault_topology(struct options *o)
Set –topology default depending on –mode.
Definition helper.c:137
void helper_tcp_nodelay(struct options *o)
Definition helper.c:608
void helper_client_server(struct options *o)
Definition helper.c:165
void helper_keepalive(struct options *o)
Definition helper.c:548
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(struct management *man, const char *token)
Definition manage.c:3116
void management_echo(struct management *man, const char *string, const bool pull)
Definition manage.c:3037
#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
struct buffer prepend_dir(const char *dir, const char *path, struct gc_arena *gc)
Prepend a directory to a path.
Definition misc.c:777
const char * safe_print(const char *str, struct gc_arena *gc)
Definition misc.c:543
#define USER_PASS_LEN
Definition misc.h:64
#define SC_CONCAT
Definition misc.h:92
#define SC_ECHO
Definition misc.h:91
int translate_mtu_discover_type_name(const char *name)
Definition mtu.c:253
size_t calc_options_string_link_mtu(const struct options *o, const struct frame *frame)
Calculate the link-mtu to advertise to our peer.
Definition mtu.c:147
#define MSSFIX_DEFAULT
Definition mtu.h:84
#define TUN_MTU_MAX_MIN
Definition mtu.h:74
#define TAP_MTU_EXTRA_DEFAULT
Definition mtu.h:79
#define LINK_MTU_DEFAULT
Definition mtu.h:64
#define TUN_MTU_DEFAULT
Definition mtu.h:69
#define TLS_MTU_DEFAULT
Definition mtu.h:89
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:179
void open_syslog(const char *pgmname, bool stdio_to_null)
Definition error.c:442
void redirect_stdout_stderr(const char *file, bool append)
Definition error.c:491
void openvpn_exit(const int status)
Definition error.c:700
static bool machine_readable_output
Definition error.c:74
void set_suppress_timestamps(bool suppressed)
Definition error.c:143
void set_machine_readable_output(bool parsable)
Definition error.c:149
FILE * msg_fp(const msglvl_t flags)
Definition error.c:188
bool set_debug_level(const int level, const unsigned int flags)
Definition error.c:101
static bool suppress_timestamps
Definition error.c:77
#define M_OPTERR
Definition error.h:101
#define SDL_CONSTRAIN
Definition error.h:201
#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:219
#define M_WARN
Definition error.h:92
#define M_ERRNO
Definition error.h:95
#define MAX_PEER_ID
Definition openvpn.h:550
bool options_cmp_equal(char *actual, const char *expected)
Definition options.c:4543
#define RESET_OPTION_ROUTES(option_ptr, field)
Definition options.c:5055
static void rol6_check_alloc(struct options *options)
Definition options.c:1566
#define CHKACC_PRIVATE
Warn if this (private) file is group/others accessible.
Definition options.c:3942
static bool check_file_access_chroot_inline(bool is_inline, const char *chroot, const int type, const char *file, const int mode, const char *opt)
A wrapper for check_file_access_chroot() that returns false immediately if the file is inline (and th...
Definition options.c:4076
static bool check_file_access_chroot(const char *chroot, const int type, const char *file, const int mode, const char *opt)
Definition options.c:4042
static void options_postprocess_verify_ce(const struct options *options, const struct connection_entry *ce)
Definition options.c:2264
#define NM_QUOTE_HINT
Definition options.c:5022
static void options_postprocess_mutate_ce(struct options *o, struct connection_entry *ce)
Definition options.c:2915
static void usage_version(void)
Definition options.c:4901
static in_addr_t get_ip_addr(const char *ip_string, msglvl_t msglevel, bool *error)
Definition options.c:1102
static struct pull_filter * alloc_pull_filter(struct options *o)
Definition options.c:2168
#define USAGE_VALID_SERVER_PROTOS
#define SHOW_BOOL(var)
Definition options.c:974
#define CHKACC_DIRPATH
Check for directory presence where a file should reside.
Definition options.c:3939
static void pre_connect_save(struct options *o)
Definition options.c:3106
#define CHKACC_ACPTSTDIN
If filename is stdin, it's allowed and "exists".
Definition options.c:3941
#define TLS_CLIENT
static void setenv_connection_entry(struct env_set *es, const struct connection_entry *e, const int i)
Definition options.c:979
static int global_auth_retry
Definition options.c:4780
bool options_postprocess_pull(struct options *o, struct env_set *es)
Definition options.c:4285
void uninit_options(struct options *o)
Definition options.c:926
static void dhcp_option_dns6_parse(const char *parm, struct in6_addr *dns6_list, int *len, msglvl_t msglevel)
Definition options.c:1322
static void connection_entry_load_re(struct connection_entry *ce, const struct remote_entry *re)
Definition options.c:2189
#define SHOW_STR(var)
Definition options.c:967
int parse_topology(const char *str, const msglvl_t msglevel)
Definition options.c:4733
void show_windows_version(const unsigned int flags)
Definition options.c:4868
#define VERIFY_PERMISSION(mask)
Definition options.c:4962
static const char * options_warning_extract_parm1(const char *option_string, struct gc_arena *gc_ret)
Definition options.c:4555
bool key_is_external(const struct options *options)
Definition options.c:5553
static char * string_substitute(const char *src, char from, char to, struct gc_arena *gc)
Definition options.c:1151
static void check_ca_required(const struct options *options)
Definition options.c:2226
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:1982
static bool verify_permission(const char *name, const char *file, int line, const unsigned int type, const unsigned int allowed, unsigned int *found, const msglvl_t msglevel, struct options *options, bool is_inline)
Definition options.c:4972
#define CHKACC_FILEXSTWR
If file exists, is it writable?
Definition options.c:3940
static void tuntap_options_postprocess_dns(struct options *o)
Postprocess DNS related settings.
Definition options.c:3490
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:1127
static void option_iroute_ipv6(struct options *o, const char *prefix_str, msglvl_t msglevel)
Definition options.c:1500
static bool check_route_option(struct options *options, char *p[], const msglvl_t msglevel, bool pull_mode)
Definition options.c:5225
void show_dco_version(const unsigned int flags)
Definition options.c:4877
void rol_check_alloc(struct options *options)
Definition options.c:1557
static struct local_list * alloc_local_list_if_undef(struct connection_entry *ce, struct gc_arena *gc)
Definition options.c:2045
#define SHOW_UNSIGNED(var)
Definition options.c:973
void show_settings(const struct options *o)
Definition options.c:1681
static void set_user_script(struct options *options, const char **script, const char *new_script, const char *type, bool in_chroot)
Definition options.c:5514
void remove_option(struct context *c, struct options *options, char *p[], bool is_inline, const char *file, int line, const msglvl_t msglevel, const unsigned int permission_mask, unsigned int *option_types_found, struct env_set *es)
Resets options found in the PUSH_UPDATE message that are preceded by the - flag.
Definition options.c:5063
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:1232
#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:5025
static void show_dhcp_option_list(const char *name, const char *const *array, int len)
Definition options.c:1274
static void show_connection_entries(const struct options *o)
Definition options.c:1642
static void options_postprocess_mutate_le(struct connection_entry *ce, struct local_entry *le, int mode)
Definition options.c:3072
bool options_cmp_equal_safe(char *actual, const char *expected, size_t actual_n)
Definition options.c:4663
bool string_defined_equal(const char *s1, const char *s2)
Definition options.c:4932
static bool check_file_access_inline(bool is_inline, const int type, const char *file, const int mode, const char *opt)
A wrapper for check_file_access() that returns false immediately if the file is inline (and therefore...
Definition options.c:4092
void options_postprocess(struct options *options, struct env_set *es)
Definition options.c:4271
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 unsigned int permission_mask, unsigned int *option_types_found, struct env_set *es)
Processes an option to update.
Definition options.c:5383
static void show_dhcp_option_addrs(const char *name, const in_addr_t *array, int len)
Definition options.c:1284
void usage_small(void)
Definition options.c:4860
const char * auth_retry_print(void)
Definition options.c:4812
static void show_http_proxy_options(const struct http_proxy_options *o)
Definition options.c:1518
static void options_postprocess_filechecks(struct options *options)
Definition options.c:4160
static struct remote_entry * alloc_remote_entry(struct options *options, const msglvl_t msglevel)
Definition options.c:2132
static void show_connection_entry(const struct connection_entry *o)
Definition options.c:1585
void options_warning_safe(char *actual, const char *expected, size_t actual_n)
Definition options.c:4686
void show_library_versions(const unsigned int flags)
Definition options.c:4887
void setenv_settings(struct env_set *es, const struct options *o)
Definition options.c:1005
#define CHKACC_ACCEPT_URI
Do not check URIs, unless they start with file:
Definition options.c:3943
static const char usage_message[]
Definition options.c:122
static void options_warning_safe_scan1(const msglvl_t msglevel, const int delim, const bool report_inconsistent, const struct buffer *b1_src, const struct buffer *b2_src, const char *b1_name, const char *b2_name)
Definition options.c:4623
static struct connection_list * alloc_connection_list_if_undef(struct options *options)
Definition options.c:2086
static bool check_cmd_access(const char *command, const char *opt, const char *chroot)
Definition options.c:4120
#define SHOW_INT64(var)
Definition options.c:972
static bool check_file_access(const int type, const char *file, const int mode, const char *opt)
Definition options.c:3946
static void show_p2mp_parms(const struct options *o)
Definition options.c:1381
static const char * pull_filter_type_name(int type)
Definition options.c:946
void add_option(struct options *options, char *p[], bool is_inline, const char *file, int line, const int level, const msglvl_t msglevel, const unsigned int permission_mask, unsigned int *option_types_found, struct env_set *es)
Definition options.c:5568
static void cnol_check_alloc(struct options *options)
Definition options.c:1575
static void options_postprocess_mutate(struct options *o, struct env_set *es)
Definition options.c:3747
void options_detach(struct options *o)
Definition options.c:1548
static void options_warning_safe_ml(const msglvl_t msglevel, char *actual, const char *expected, size_t actual_n)
Definition options.c:4641
static unsigned int atou(const char *str)
Definition options.c:4954
void pre_connect_restore(struct options *o, struct gc_arena *gc)
Definition options.c:3151
static struct pull_filter_list * alloc_pull_filter_list(struct options *o)
Definition options.c:2158
const char * print_topology(const int topology)
Definition options.c:4755
char * options_string_extract_option(const char *options_string, const char *opt_name, struct gc_arena *gc)
Given an OpenVPN options string, extract the value of an option.
Definition options.c:4700
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:1179
static bool check_dns_option(struct options *options, char *p[], const msglvl_t msglevel, bool pull_mode)
Definition options.c:5274
#define SHOW_STR_INLINE(var)
Definition options.c:968
static void options_warning_safe_scan2(const msglvl_t msglevel, const int delim, const bool report_inconsistent, const char *p1, const struct buffer *b2_src, const char *b1_name, const char *b2_name)
Definition options.c:4569
static void options_postprocess_cipher(struct options *o)
Definition options.c:3324
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:3394
static void show_tuntap_options(const struct tuntap_options *o)
Definition options.c:1296
void init_options(struct options *o, const bool init_gc)
Definition options.c:800
#define MUST_BE_FALSE(condition, parm_name)
Definition options.c:2257
#define MUST_BE_UNDEF(parm, parm_name)
Definition options.c:2252
static const char * print_vlan_accept(enum vlan_acceptable_frames mode)
Definition options.c:1364
#define SHOW_PARM(name, value, format)
Definition options.c:966
static void options_postprocess_http_proxy_override(struct options *o)
Definition options.c:2010
void options_warning(char *actual, const char *expected)
Definition options.c:4549
static void show_pull_filter_list(const struct pull_filter_list *l)
Definition options.c:1663
#define CHKACC_FILE
Check for a file/directory presence.
Definition options.c:3938
const char * options_string_version(const char *s, struct gc_arena *gc)
Definition options.c:4692
static void options_postprocess_mutate_invariant(struct options *options)
Definition options.c:3224
static bool ipv6_addr_safe_hexplusbits(const char *ipv6_prefix_spec)
Definition options.c:1145
const char title_string[]
Definition options.c:72
static void setenv_local_entry(struct env_set *es, const struct local_entry *e, const int i)
Definition options.c:997
static void remap_redirect_gateway_flags(struct options *opt)
Definition options.c:3090
#define TLS_SERVER
static msglvl_t msglevel_forward_compatible(struct options *options, const msglvl_t msglevel)
Definition options.c:5050
bool auth_retry_set(const msglvl_t msglevel, const char *option)
Definition options.c:4789
int auth_retry_get(void)
Definition options.c:4783
static void dhcp_option_address_parse(const char *name, const char *parm, in_addr_t *array, int *len, msglvl_t msglevel)
Definition options.c:1336
static struct remote_list * alloc_remote_list_if_undef(struct options *options)
Definition options.c:2122
static bool check_route6_option(struct options *options, char *p[], const msglvl_t msglevel, bool pull_mode)
Definition options.c:5253
void notnull(const char *arg, const char *description)
Definition options.c:4923
void usage(void)
Definition options.c:4834
static struct local_entry * alloc_local_entry(struct connection_entry *ce, const msglvl_t msglevel, struct gc_arena *gc)
Definition options.c:2055
static void show_compression_warning(struct compress_options *info)
Definition options.c:5541
static void options_process_mutate_prf(struct options *o)
Definition options.c:3462
bool has_udp_in_local_list(const struct options *options)
Definition options.c:9292
char * options_string(const struct options *o, const struct frame *frame, struct tuntap *tt, openvpn_net_ctx_t *ctx, bool remote, struct gc_arena *gc)
Definition options.c:4342
static void option_iroute(struct options *o, const char *network_str, const char *netmask_str, msglvl_t msglevel)
Definition options.c:1473
static void options_postprocess_verify(const struct options *o)
Definition options.c:3287
static void connection_entry_preload_key(const char **key_file, bool *key_inline, struct gc_arena *gc)
Definition options.c:2210
static struct connection_entry * alloc_connection_entry(struct options *options, const msglvl_t msglevel)
Definition options.c:2096
#define SHOW_INT(var)
Definition options.c:970
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:3384
#define MODE_POINT_TO_POINT
Definition options.h:263
#define OPT_P_SCRIPT
Definition options.h:733
#define PUF_TYPE_ACCEPT
filter type to accept a matching option
Definition options.h:798
#define OPT_P_PUSH
Definition options.h:745
#define SF_TCP_NODELAY_HELPER
Definition options.h:474
#define OPT_P_UP
Definition options.h:730
#define OPT_P_CONNECTION
Definition options.h:756
#define OPT_P_INSTANCE
allowed in ccd, client-connect etc
Definition options.h:746
#define OPT_P_NCP
Negotiable crypto parameters.
Definition options.h:741
void read_config_file(struct options *options, const char *file, int level, const char *top_file, const int top_line, const msglvl_t msglevel, const unsigned int permission_mask, unsigned int *option_types_found, struct env_set *es)
#define OPT_P_ECHO
Definition options.h:749
#define OPT_P_ROUTE_TABLE
Definition options.h:760
#define OPT_P_CONFIG
Definition options.h:747
#define MODE_SERVER
Definition options.h:264
#define CONNECTION_LIST_SIZE
Definition options.h:190
#define streq(x, y)
Definition options.h:724
#define OPT_P_U_REDIR_GATEWAY
Definition options.h:793
#define OPT_P_EXPLICIT_NOTIFY
Definition options.h:748
#define PUF_TYPE_IGNORE
filter type to ignore a matching option
Definition options.h:799
#define AR_INTERACT
Definition options.h:969
#define OPT_P_SHAPER
Definition options.h:735
#define OPT_P_U_ROUTE6
Definition options.h:790
static bool dco_enabled(const struct options *o)
Returns whether the current configuration has dco enabled.
Definition options.h:990
#define OPT_P_SOCKFLAGS
Definition options.h:755
#define SF_NOPOOL
Definition options.h:473
#define PUF_TYPE_REJECT
filter type to reject and trigger SIGUSR1
Definition options.h:800
#define OPT_P_MESSAGES
Definition options.h:740
#define OPT_P_SETENV
Definition options.h:734
#define OPT_P_SOCKBUF
Definition options.h:754
#define OPT_P_PLUGIN
Definition options.h:753
#define OPTION_PARM_SIZE
Definition options.h:56
#define OPT_P_TIMER
Definition options.h:736
#define OPT_P_GENERAL
Definition options.h:729
#define PING_RESTART
Definition options.h:355
#define OPT_P_DHCPDNS
Definition options.h:732
#define OPT_P_PULL_MODE
Definition options.h:752
@ GENKEY_AUTH_TOKEN
Definition options.h:242
@ GENKEY_SECRET
Definition options.h:239
@ GENKEY_TLS_CRYPTV2_SERVER
Definition options.h:241
@ GENKEY_TLS_CRYPTV2_CLIENT
Definition options.h:240
#define OPT_P_PUSH_MTU
Definition options.h:759
#define AR_NONE
Definition options.h:968
#define AR_NOINTERACT
Definition options.h:970
#define SF_NO_PUSH_ROUTE_GATEWAY
Definition options.h:475
#define OPT_P_PERSIST
Definition options.h:737
#define MAX_PARMS
Definition options.h:51
#define PULL_DEFINED(opt)
Definition options.h:764
#define OPT_P_U_DNS
Definition options.h:791
#define PLUGIN_OPTION_LIST(opt)
Definition options.h:775
#define ROUTE_OPTION_FLAGS(o)
Definition options.h:767
#define OPTION_LINE_SIZE
Definition options.h:57
#define OPT_P_U_ROUTE
Definition options.h:789
#define PING_EXIT
Definition options.h:354
#define OPT_P_COMP
Definition options.h:739
#define OPT_P_PERSIST_IP
Definition options.h:738
#define OPT_P_MTU
Definition options.h:743
#define OPT_P_ROUTE_EXTRAS
Definition options.h:751
#define OPT_P_U_DHCP
Definition options.h:792
#define OPT_P_NICE
Definition options.h:744
#define OPT_P_PEER_ID
Definition options.h:757
#define OPT_P_INHERIT
Definition options.h:750
#define OPT_P_TLS_PARMS
Definition options.h:742
#define OPT_P_ROUTE
Definition options.h:731
void read_config_string(const char *prefix, struct options *options, const char *config, const msglvl_t msglevel, const unsigned int permission_mask, unsigned int *option_types_found, struct env_set *es)
#define MAN_CLIENT_AUTH_ENABLED(opt)
Definition options.h:781
#define CE_DISABLED
Definition options.h:153
#define OPT_P_INLINE
Definition options.h:758
vlan_acceptable_frames
Definition options.h:223
@ VLAN_ONLY_UNTAGGED_OR_PRIORITY
Definition options.h:225
@ VLAN_ALL
Definition options.h:226
@ VLAN_ONLY_TAGGED
Definition options.h:224
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_access(const char *path, int mode)
Definition platform.c:457
int platform_chdir(const char *dir)
Definition platform.c:392
int platform_stat(const char *path, platform_stat_t *buf)
Definition platform.c:526
struct _stat platform_stat_t
Definition platform.h:118
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
void plugin_option_list_print(const struct plugin_option_list *list, msglvl_t msglevel)
Definition plugin.c:187
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:45
#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
void print_route_options(const struct route_option_list *rol, msglvl_t msglevel)
Definition route.c:1240
bool is_special_addr(const char *addr_str)
Definition route.c:301
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:3897
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:1198
void get_default_gateway_ipv6(struct route_ipv6_gateway_info *rgi6, const struct in6_addr *dest, openvpn_net_ctx_t *ctx)
Definition route.c:2664
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:509
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:1254
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:2566
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:3067
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:1176
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:494
#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
static void bind_local(struct link_socket *sock, const sa_family_t ai_family)
Definition socket.c:652
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:224
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:197
#define SF_TCP_NODELAY
Definition socket.h:192
#define RESOLV_RETRY_INFINITE
Definition socket.h:48
#define OPENVPN_PORT
Definition socket.h:42
#define SF_USE_IP_PKTINFO
Definition socket.h:191
#define SF_HOST_RANDOMIZE
Definition socket.h:194
#define SF_PKTINFO_COPY_IIF
Definition socket.h:198
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)
const char * proto_remote(int proto, bool remote)
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:361
void ssl_set_auth_nocache(void)
Definition ssl.c:336
int tls_version_parse(const char *vstr, const char *extra)
Definition ssl.c:420
void ssl_set_auth_token(const char *token)
Definition ssl.c:355
bool ssl_get_auth_nocache(void)
Definition ssl.c:346
static bool push_peer_info(struct buffer *buf, 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:1872
Control Channel SSL/Data channel negotiation module.
#define X509_USERNAME_FIELD_DEFAULT
Definition ssl.h:120
#define KEY_METHOD_2
Definition ssl.h:122
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:576
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:206
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:195
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:96
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)
Definition argv.h:35
char ** argv
Definition argv.h:39
Wrapper structure for dynamically allocated memory.
Definition buffer.h:60
uint8_t * data
Pointer to the allocated memory.
Definition buffer.h:67
int len
Length in bytes of the actual content within the allocated memory.
Definition buffer.h:65
unsigned int flags
Definition comp.h:77
Definition options.h:107
struct local_list * local_list
Definition options.h:108
int tun_mtu_max
Definition options.h:129
int connect_retry_seconds
Definition options.h:119
bool tls_crypt_v2_force_cookie
Definition options.h:179
int link_mtu
Definition options.h:134
bool link_mtu_defined
Definition options.h:135
int tun_mtu_extra
Definition options.h:132
int connect_retry_seconds_max
Definition options.h:120
bool bind_local
Definition options.h:118
int mssfix
Definition options.h:144
const char * tls_crypt_file
Definition options.h:170
const char * tls_crypt_v2_file
Definition options.h:175
bool tun_mtu_extra_defined
Definition options.h:133
const char * remote
Definition options.h:114
int connect_timeout
Definition options.h:121
const char * socks_proxy_port
Definition options.h:124
bool mssfix_default
Definition options.h:145
bool mssfix_encap
Definition options.h:146
int occ_mtu
Definition options.h:128
struct http_proxy_options * http_proxy_options
Definition options.h:122
bool tls_crypt_file_inline
Definition options.h:171
bool tls_auth_file_inline
Definition options.h:166
bool bind_ipv6_only
Definition options.h:117
bool tun_mtu_defined
Definition options.h:131
bool remote_float
Definition options.h:115
int tls_mtu
Definition options.h:136
int explicit_exit_notification
Definition options.h:150
const char * socks_proxy_authfile
Definition options.h:125
const char * remote_port
Definition options.h:113
bool fragment_encap
Definition options.h:142
const char * socks_proxy_server
Definition options.h:123
int fragment
Definition options.h:141
int mtu_discover_type
Definition options.h:139
int proto
Definition options.h:109
sa_family_t af
Definition options.h:110
const char * tls_auth_file
Definition options.h:165
bool local_port_defined
Definition options.h:112
int tun_mtu
Definition options.h:127
bool bind_defined
Definition options.h:116
const char * local_port
Definition options.h:111
int key_direction
Definition options.h:167
bool tls_crypt_v2_file_inline
Definition options.h:176
unsigned int flags
Definition options.h:162
bool mssfix_fixed
Definition options.h:148
struct connection_entry ** array
Definition options.h:204
struct route_list * route_list
List of routing information.
Definition openvpn.h:177
struct route_ipv6_list * route_ipv6_list
Definition openvpn.h:182
struct tuntap * tuntap
Tun/tap virtual network interface.
Definition openvpn.h:172
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:513
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
Structure for reassembling one incoming fragmented packet.
Definition fragment.h:65
Packet geometry parameters.
Definition mtu.h:108
int tun_mtu
the (user) configured tun-mtu.
Definition mtu.h:142
Garbage collection arena used to keep track of dynamically allocated memory.
Definition buffer.h:116
Definition list.h:53
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
const char * cipher
const name of the cipher
Definition crypto.h:142
const char * digest
Message digest static parameters.
Definition crypto.h:143
Definition options.h:100
const char * port
Definition options.h:102
int proto
Definition options.h:103
const char * local
Definition options.h:101
struct local_entry ** array
Definition options.h:196
int capacity
Definition options.h:194
struct tuntap_options tuntap_options
Definition options.h:65
int ping_rec_timeout_action
Definition options.h:89
bool tuntap_options_defined
Definition options.h:64
bool routes_ipv6_defined
Definition options.h:73
struct route_option_list * routes
Definition options.h:71
struct compress_options comp
Definition options.h:92
const char * ciphername
Definition options.h:84
const char * ifconfig_local
Definition options.h:67
struct dns_options dns_options
Definition options.h:82
const char * route_default_gateway
Definition options.h:76
const char * ifconfig_ipv6_local
Definition options.h:68
const char * authname
Definition options.h:85
struct route_ipv6_option_list * routes_ipv6
Definition options.h:74
bool client_nat_defined
Definition options.h:79
struct client_nat_option_list * client_nat
Definition options.h:80
const char * route_ipv6_default_gateway
Definition options.h:77
int resolve_retry_seconds
Definition options.h:366
int rcvbuf
Definition options.h:412
bool resolve_in_advance
Definition options.h:367
bool route_nopull
Definition options.h:436
const char * genkey_extra_data
Definition options.h:289
struct compress_options comp
Definition options.h:409
struct http_proxy_options * http_proxy_override
Definition options.h:312
int push_ifconfig_ipv6_netbits
Definition options.h:522
int proto_force
Definition options.h:335
bool persist_config
Definition options.h:277
struct connection_list * connection_list
Definition options.h:294
const char * management_port
Definition options.h:446
bool tls_crypt_file_inline
Definition options.h:666
const char * ifconfig_ipv6_remote
Definition options.h:330
int max_routes_per_client
Definition options.h:535
const char * ncp_ciphers_conf
The original ncp_ciphers specified by the user in the configuration.
Definition options.h:577
int status_file_version
Definition options.h:406
enum vlan_acceptable_frames vlan_accept
Definition options.h:711
int auth_token_renewal
Definition options.h:544
in_addr_t push_ifconfig_constraint_network
Definition options.h:517
const char * tmp_dir
Definition options.h:465
bool push_peer_info
Definition options.h:682
bool daemon
Definition options.h:390
struct options_pre_connect * pre_connect
Definition options.h:561
int route_default_metric
Definition options.h:428
int renegotiate_seconds_min
Definition options.h:648
const char * auth_token_secret_file
Definition options.h:545
unsigned int imported_protocol_flags
Definition options.h:721
const char * tls_export_peer_cert_dir
Definition options.h:613
bool crl_file_inline
Definition options.h:617
const char * cryptoapi_cert
Definition options.h:639
const char * down_script
Definition options.h:385
unsigned int backwards_compatible
What version we should try to be compatible with as major * 10000 + minor * 100 + patch,...
Definition options.h:271
hash_algo_type verify_hash_algo
Definition options.h:623
int scheduled_exit_interval
Definition options.h:563
int stale_routes_ageing_time
Definition options.h:537
bool pkcs12_file_inline
Definition options.h:606
int replay_time
Definition options.h:584
unsigned int push_option_types_found
Definition options.h:557
int management_state_buffer_size
Definition options.h:450
const char * ca_file
Definition options.h:594
const char * tls_auth_file
Definition options.h:661
struct provider_list providers
Definition options.h:581
bool duplicate_cn
Definition options.h:526
struct in6_addr server_network_ipv6
Definition options.h:470
int shaper
Definition options.h:333
int management_echo_buffer_size
Definition options.h:449
in_addr_t server_network
Definition options.h:467
uint32_t real_hash_size
Definition options.h:498
bool show_net_up
Definition options.h:695
bool verify_hash_no_ca
Definition options.h:625
bool allow_pull_fqdn
Definition options.h:438
bool use_peer_id
Definition options.h:701
unsigned remote_cert_ku[MAX_PARMS]
Definition options.h:620
bool server_bridge_defined
Definition options.h:480
const char * keying_material_exporter_label
Definition options.h:705
const char * status_file
Definition options.h:405
unsigned int ssl_flags
Definition options.h:626
bool route_noexec
Definition options.h:429
bool ifconfig_nowarn
Definition options.h:332
const char * remote_cert_eku
Definition options.h:621
in_addr_t ifconfig_pool_netmask
Definition options.h:490
in_addr_t server_netmask
Definition options.h:468
int tls_timeout
Definition options.h:642
bool test_crypto
Definition options.h:586
bool up_delay
Definition options.h:388
bool server_bridge_proxy_dhcp
Definition options.h:478
bool allow_recursive_routing
Definition options.h:718
const char * authname
Definition options.h:579
const char * exit_event_name
Definition options.h:693
const char * ifconfig_ipv6_local
Definition options.h:328
int cf_max
Definition options.h:528
bool dh_file_inline
Definition options.h:598
unsigned int push_update_options_found
Definition options.h:558
int replay_window
Definition options.h:583
bool disable
Definition options.h:506
int mute
Definition options.h:399
bool auth_user_pass_verify_script_via_file
Definition options.h:540
const char * dev_type
Definition options.h:322
int persist_mode
Definition options.h:278
int ifconfig_pool_persist_refresh_freq
Definition options.h:492
bool show_digests
Definition options.h:282
const char * up_script
Definition options.h:384
bool single_session
Definition options.h:680
bool push_ifconfig_defined
Definition options.h:512
bool ifconfig_pool_defined
Definition options.h:487
int verify_hash_depth
Definition options.h:624
bool route_delay_defined
Definition options.h:432
const char * packet_id_file
Definition options.h:585
const char * tls_crypt_v2_file
Definition options.h:670
int management_log_history_cache
Definition options.h:448
in_addr_t server_bridge_netmask
Definition options.h:482
const char * ip_remote_hint
Definition options.h:368
bool vlan_tagging
Definition options.h:710
uint32_t peer_id
Definition options.h:702
struct route_option_list * routes
Definition options.h:433
in_addr_t ifconfig_pool_end
Definition options.h:489
int keepalive_timeout
Definition options.h:342
const char * writepid
Definition options.h:383
int64_t inactivity_minimum_bytes
Definition options.h:345
bool ifconfig_ipv6_pool_defined
Definition options.h:494
unsigned int server_flags
Definition options.h:476
bool block_outside_dns
Definition options.h:697
bool push_ifconfig_ipv6_blocked
Definition options.h:524
bool tls_exit
Definition options.h:684
const char * pkcs12_file
Definition options.h:605
const char * client_disconnect_script
Definition options.h:501
bool show_engines
Definition options.h:283
struct remote_list * remote_list
Definition options.h:296
HANDLE msg_channel
Definition options.h:692
const char * key_pass_file
Definition options.h:280
bool mute_replay_warnings
Definition options.h:582
const char * tls_crypt_file
Definition options.h:665
int inactivity_timeout
Definition options.h:344
int n_bcast_buf
Definition options.h:508
int handshake_window
Definition options.h:652
bool server_defined
Definition options.h:466
const char * ifconfig_local
Definition options.h:326
char * x509_username_field[MAX_PARMS]
Definition options.h:655
struct connection_entry ce
Definition options.h:293
struct iroute_ipv6 * iroutes_ipv6
Definition options.h:511
struct push_list push_list
Definition options.h:486
bool user_script_used
Definition options.h:386
const char * tls_groups
Definition options.h:609
bool show_tls_ciphers
Definition options.h:284
struct tuntap_options tuntap_options
Definition options.h:370
int route_method
Definition options.h:696
struct verify_hash_list * verify_hash
Definition options.h:622
const char * tls_cert_profile
Definition options.h:610
int64_t renegotiate_packets
Definition options.h:646
unsigned int management_flags
Definition options.h:458
int push_continuation
Definition options.h:556
const char * route_default_gateway
Definition options.h:425
in_addr_t push_ifconfig_local_alias
Definition options.h:515
struct dns_options dns_options
Definition options.h:317
bool exit_event_initial_state
Definition options.h:694
struct static_challenge_info sc_info
Definition options.h:566
bool auth_token_call_auth
Definition options.h:542
const char * ipchange
Definition options.h:320
int topology
Definition options.h:325
bool disable_dco
Definition options.h:373
const char * ncp_ciphers
Definition options.h:578
bool genkey
Definition options.h:286
uint32_t virtual_hash_size
Definition options.h:499
const char * learn_address_script
Definition options.h:502
const char * ciphername
Definition options.h:573
const char * auth_user_pass_file
Definition options.h:559
int tls_crypt_v2_max_age
Definition options.h:677
bool forward_compatible
Definition options.h:268
const char * username
Definition options.h:376
int cf_initial_max
Definition options.h:531
int stale_routes_check_interval
Definition options.h:536
struct plugin_option_list * plugin_list
Definition options.h:461
int auth_token_lifetime
Definition options.h:543
uint16_t vlan_pvid
Definition options.h:712
int ns_cert_type
Definition options.h:619
const char * tls_crypt_v2_verify_script
Definition options.h:675
int mode
Definition options.h:265
bool tls_server
Definition options.h:592
const char * auth_user_pass_verify_script
Definition options.h:539
int connect_retry_max
Definition options.h:292
char * bind_dev
Definition options.h:417
const char * extra_certs_file
Definition options.h:601
bool client
Definition options.h:554
bool pull
Definition options.h:555
int ifconfig_ipv6_pool_netbits
Definition options.h:496
in_addr_t push_ifconfig_constraint_netmask
Definition options.h:518
bool show_curves
Definition options.h:285
const char * route_ipv6_default_gateway
Definition options.h:426
bool tls_client
Definition options.h:593
bool ping_timer_remote
Definition options.h:351
bool auth_token_generate
Definition options.h:541
bool priv_key_file_inline
Definition options.h:604
const char * tls_verify
Definition options.h:612
const char * crl_file
Definition options.h:616
int ping_rec_timeout_action
Definition options.h:356
bool auth_user_pass_file_inline
Definition options.h:560
bool show_ciphers
Definition options.h:281
bool enable_ncp_fallback
If defined fall back to ciphername if NCP fails.
Definition options.h:574
const char * route_predown_script
Definition options.h:424
const char * dh_file
Definition options.h:597
int route_delay_window
Definition options.h:431
in_addr_t push_ifconfig_local
Definition options.h:513
bool mlock
Definition options.h:339
const char ** ignore_unknown_option
Definition options.h:274
int sndbuf
Definition options.h:413
int foreign_option_index
Definition options.h:689
struct gc_arena gc
Definition options.h:256
bool gc_owned
Definition options.h:257
bool down_pre
Definition options.h:387
bool persist_tun
Definition options.h:358
int route_default_table_id
Definition options.h:427
bool ca_file_inline
Definition options.h:595
bool auth_token_secret_file_inline
Definition options.h:546
bool block_ipv6
Definition options.h:435
const char * config
Definition options.h:260
bool extra_certs_file_inline
Definition options.h:602
bool push_ifconfig_constraint_defined
Definition options.h:516
int mark
Definition options.h:416
int cf_initial_per
Definition options.h:532
int keying_material_exporter_length
Definition options.h:706
bool suppress_timestamps
Definition options.h:395
bool force_key_material_export
Definition options.h:708
bool mtu_test
Definition options.h:337
struct iroute * iroutes
Definition options.h:510
int verify_x509_type
Definition options.h:614
const char * cipher_list_tls13
Definition options.h:608
const char * ecdh_curve
Definition options.h:611
int status_file_update_freq
Definition options.h:407
const char * management_client_user
Definition options.h:452
const char * cipher_list
Definition options.h:607
bool ccd_exclusive
Definition options.h:505
bool allow_deprecated_insecure_static_crypto
Definition options.h:571
struct pull_filter_list * pull_filter_list
Definition options.h:714
const char * management_certificate
Definition options.h:455
const char * genkey_filename
Definition options.h:288
const struct x509_track * x509_track
Definition options.h:686
const char * chroot_dir
Definition options.h:378
bool log
Definition options.h:394
bool shared_secret_file_inline
Definition options.h:570
struct in6_addr push_ifconfig_ipv6_remote
Definition options.h:523
const char * ca_path
Definition options.h:596
int renegotiate_seconds
Definition options.h:647
int ping_rec_timeout
Definition options.h:350
unsigned int sockflags
Definition options.h:420
const char * engine
Definition options.h:580
const char * management_addr
Definition options.h:445
const char * client_connect_script
Definition options.h:500
const char * verify_x509_name
Definition options.h:615
int ping_send_timeout
Definition options.h:349
bool route_gateway_via_dhcp
Definition options.h:437
bool remote_random
Definition options.h:319
bool push_ifconfig_ipv6_defined
Definition options.h:520
int tcp_queue_limit
Definition options.h:509
int route_delay
Definition options.h:430
const char * dev_node
Definition options.h:323
const char * override_username
Definition options.h:507
const char * client_crresponse_script
Definition options.h:503
struct route_ipv6_option_list * routes_ipv6
Definition options.h:434
bool machine_readable_output
Definition options.h:396
int key_direction
Definition options.h:572
bool server_ipv6_defined
Definition options.h:469
const char * priv_key_file
Definition options.h:603
bool persist_remote_ip
Definition options.h:360
bool up_restart
Definition options.h:389
int keepalive_ping
Definition options.h:341
bool tls_auth_file_inline
Definition options.h:662
bool tls_crypt_v2_file_inline
Definition options.h:671
const char * groupname
Definition options.h:377
in_addr_t server_bridge_pool_start
Definition options.h:483
const char * cd_dir
Definition options.h:379
struct client_nat_option_list * client_nat
Definition options.h:439
struct in6_addr push_ifconfig_ipv6_local
Definition options.h:521
int nice
Definition options.h:397
int max_clients
Definition options.h:534
int transition_window
Definition options.h:658
const char * ifconfig_remote_netmask
Definition options.h:327
const char * lladdr
Definition options.h:324
int verbosity
Definition options.h:398
int session_timeout
Definition options.h:347
const char * cert_file
Definition options.h:599
bool enable_c2c
Definition options.h:525
in_addr_t server_bridge_pool_end
Definition options.h:484
int cf_per
Definition options.h:529
enum tun_driver_type windows_driver
Definition options.h:698
bool cert_file_inline
Definition options.h:600
int remap_sigusr1
Definition options.h:392
int64_t renegotiate_bytes
Definition options.h:645
const char * route_script
Definition options.h:423
in_addr_t ifconfig_pool_start
Definition options.h:488
const char * management_user_pass
Definition options.h:447
unsigned int server_netbits_ipv6
Definition options.h:471
in_addr_t push_ifconfig_remote_netmask
Definition options.h:514
bool occ
Definition options.h:442
in_addr_t server_bridge_ip
Definition options.h:481
const char * shared_secret_file
Definition options.h:569
bool ifconfig_noexec
Definition options.h:331
const char * dev
Definition options.h:321
const char * management_client_group
Definition options.h:453
struct in6_addr ifconfig_ipv6_pool_base
Definition options.h:495
const char * client_config_dir
Definition options.h:504
enum genkey_type genkey_type
Definition options.h:287
const char * ifconfig_pool_persist_filename
Definition options.h:491
int ifconfig_ipv6_netbits
Definition options.h:329
bool persist_local_ip
Definition options.h:359
const char * names[MAX_PARMS]
Definition options.h:217
struct pull_filter * tail
Definition options.h:810
struct pull_filter * head
Definition options.h:809
struct pull_filter * next
Definition options.h:804
char * pattern
Definition options.h:803
size_t size
Definition options.h:802
Definition pushlist.h:29
struct push_entry * next
Definition pushlist.h:30
bool enable
Definition pushlist.h:31
const char * option
Definition pushlist.h:32
struct push_entry * head
Definition pushlist.h:37
Definition options.h:183
int proto
Definition options.h:186
const char * remote
Definition options.h:184
const char * remote_port
Definition options.h:185
sa_family_t af
Definition options.h:187
struct remote_entry ** array
Definition options.h:211
int capacity
Definition options.h:209
unsigned int flags
Definition route.h:113
unsigned int flags
Definition route.h:97
unsigned int flags
Definition misc.h:93
const char * challenge_text
Definition misc.h:95
int wins_len
Definition tun.h:118
struct in6_addr dns6[N_DHCP_ADDR]
Definition tun.h:142
in_addr_t nbdd[N_DHCP_ADDR]
Definition tun.h:125
int dns_len
Definition tun.h:114
int dns6_len
Definition tun.h:143
in_addr_t ntp[N_DHCP_ADDR]
Definition tun.h:121
int ntp_len
Definition tun.h:122
in_addr_t wins[N_DHCP_ADDR]
Definition tun.h:117
int tap_sleep
Definition tun.h:97
uint8_t netbios_node_type
Definition tun.h:107
int dhcp_lease_time
Definition tun.h:94
in_addr_t dns[N_DHCP_ADDR]
Definition tun.h:113
const char * netbios_scope
Definition tun.h:105
int nbdd_len
Definition tun.h:126
bool ip_win32_defined
Definition tun.h:77
bool dhcp_masq_custom_offset
Definition tun.h:92
const char * domain
Definition tun.h:103
int domain_search_list_len
Definition tun.h:132
bool dhcp_renew
Definition tun.h:137
const char * domain_search_list[N_SEARCH_LIST_LEN]
Definition tun.h:131
int dhcp_masq_offset
Definition tun.h:93
int ip_win32_type
Definition tun.h:85
bool dhcp_pre_release
Definition tun.h:138
bool register_dns
Definition tun.h:140
bool disable_nbt
Definition tun.h:135
int dhcp_options
Definition tun.h:101
Definition tun.h:183
struct verify_hash_list * next
Definition options.h:250
uint8_t hash[SHA256_DIGEST_LENGTH]
Definition options.h:249
#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
struct env_set * es
static bool pkcs11_id_management
struct gc_arena gc
Definition test_ssl.c:131
void ipconfig_register_dns(const struct env_set *es)
Definition tun.c:4884
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:3810
bool dhcp_renew_by_adapter_index(const DWORD adapter_index)
Definition tun.c:4817
int ascii2ipset(const char *name)
Definition tun.c:6245
struct tuntap * init_tun(const char *dev, const char *dev_type, int topology, const char *ifconfig_local_parm, const char *ifconfig_remote_netmask_parm, const char *ifconfig_ipv6_local_parm, int ifconfig_ipv6_netbits_parm, const char *ifconfig_ipv6_remote_parm, struct addrinfo *local_public, struct addrinfo *remote_public, const bool strict_warn, struct env_set *es, openvpn_net_ctx_t *ctx, struct tuntap *tt)
Definition tun.c:830
bool dhcp_release_by_adapter_index(const DWORD adapter_index)
Definition tun.c:4776
const char * dev_type_string(const char *dev, const char *dev_type)
Definition tun.c:540
void tap_allow_nonadmin_access(const char *dev_node)
Definition tun.c:4696
void show_adapters(msglvl_t msglevel)
Definition tun.c:4647
static bool dhcp_renew(const struct tuntap *tt)
Definition tun.c:4843
const char * ifconfig_options_string(const struct tuntap *tt, bool remote, bool disable, struct gc_arena *gc)
Definition tun.c:694
const char * ipset2ascii_all(struct gc_arena *gc)
Definition tun.c:6274
void show_valid_win32_tun_subnets(void)
Definition tun.c:3777
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:80
#define IPW32_SET_ADAPTIVE
Definition tun.h:83
#define DHCP_OPTIONS_DHCP_REQUIRED
Definition tun.h:72
#define N_SEARCH_LIST_LEN
Definition tun.h:128
#define IPW32_SET_DHCP_MASQ
Definition tun.h:82
#define IPW32_SET_MANUAL
Definition tun.h:79
@ 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:67
#define N_DHCP_ADDR
Definition tun.h:110
#define DHCP_OPTIONS_DHCP_OPTIONAL
Definition tun.h:71
static bool is_tun_afunix(const char *devnode)
Checks whether a –dev-node parameter specifies a AF_UNIX device.
Definition tun_afunix.h:61
const char * win_get_tempdir(void)
Definition win32-util.c:150
void set_win_sys_path(const char *newpath, struct env_set *es)
Definition win32.c:1116
const char * win32_version_string(struct gc_arena *gc)
Get Windows version string with architecture info.
Definition win32.c:1381
void set_pause_exit_win32(void)
Definition win32.c:144