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