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
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_INT(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 if ((options->port_share_host || options->port_share_port)
2494 && (ce->proto != PROTO_TCP_SERVER))
2495 {
2496 msg(M_USAGE, "--port-share only works in TCP server mode "
2497 "(--proto values of tcp-server, tcp4-server, or tcp6-server)");
2498 }
2499#endif
2500 if (!options->tls_server)
2501 {
2502 msg(M_USAGE, "--mode server requires --tls-server");
2503 }
2504 MUST_BE_FALSE(ce->remote, "remote");
2505 MUST_BE_FALSE(!ce->bind_local, "nobind");
2506 MUST_BE_FALSE(ce->http_proxy_options, "http-proxy");
2507 MUST_BE_FALSE(ce->socks_proxy_server, "socks-proxy");
2508 /* <connection> blocks force to have a remote embedded, so we check
2509 * for the --remote and bail out if it is present
2510 */
2512 {
2513 msg(M_USAGE, "<connection> cannot be used with --mode server");
2514 }
2515
2516 MUST_BE_UNDEF(shaper, "shaper");
2517 if (options->ipchange)
2518 {
2519 msg(M_USAGE, "--ipchange cannot be used with --mode server (use "
2520 "--client-connect instead)");
2521 }
2522 if (!(proto_is_dgram(ce->proto) || ce->proto == PROTO_TCP_SERVER))
2523 {
2525 }
2526 if (!proto_is_udp(ce->proto) && (options->cf_max || options->cf_per))
2527 {
2528 msg(M_USAGE,
2529 "--connect-freq only works with --mode server --proto udp. Try --max-clients instead.");
2530 }
2531 if (!(dev == DEV_TYPE_TAP || (dev == DEV_TYPE_TUN && options->topology == TOP_SUBNET))
2533 {
2534 msg(M_USAGE,
2535 "The third parameter to --ifconfig-pool (netmask) is only valid in --dev tap mode");
2536 }
2538 {
2539 msg(M_USAGE,
2540 "--redirect-gateway cannot be used with --mode server (however --push \"redirect-gateway\" is fine)");
2541 }
2542 MUST_BE_UNDEF(route_delay_defined, "route-delay");
2543 MUST_BE_UNDEF(up_delay, "up-delay");
2546 {
2547 msg(M_USAGE,
2548 "--ifconfig-pool-persist must be used with --ifconfig-pool or --ifconfig-ipv6-pool");
2549 }
2551 {
2552 msg(M_USAGE, "--ifconfig-ipv6-pool needs --ifconfig-ipv6");
2553 }
2554 MUST_BE_UNDEF(allow_recursive_routing, "allow-recursive-routing");
2556 {
2557 msg(M_USAGE,
2558 "--auth-user-pass cannot be used with --mode server (it should be used on the client side only)");
2559 }
2561 {
2562 msg(M_USAGE, "--ccd-exclusive must be used with --client-config-dir");
2563 }
2565 {
2566 msg(M_USAGE, "--auth-gen-token needs a non-infinite "
2567 "--renegotiate_seconds setting");
2568 }
2571 {
2572 msg(M_USAGE,
2573 "--auth-gen-token renewal time needs to be at least "
2574 " two times --hand-window (%d).",
2576 }
2579 {
2580 const char *use_err =
2581 "--%s must be used with --management-client-auth, an --auth-user-pass-verify script, or plugin";
2582
2585 "verify-client-cert none|optional");
2587 "username-as-common-name");
2589 "auth-user-pass-optional");
2590 }
2591
2592 if (options->vlan_tagging && dev != DEV_TYPE_TAP)
2593 {
2594 msg(M_USAGE, "--vlan-tagging must be used with --dev tap");
2595 }
2596 if (!options->vlan_tagging)
2597 {
2598 const char use_err[] = "--%s requires --vlan-tagging";
2599 MUST_BE_UNDEF(vlan_accept, "vlan-accept");
2600 MUST_BE_UNDEF(vlan_pvid, "vlan-pvid");
2601 }
2602 }
2603 else
2604 {
2605 const char use_err[] = "--%s requires --mode server";
2606 /*
2607 * When not in server mode, err if parameters are
2608 * specified which require --mode server.
2609 */
2610 MUST_BE_UNDEF(ifconfig_pool_defined, "ifconfig-pool");
2611 MUST_BE_UNDEF(ifconfig_pool_persist_filename, "ifconfig-pool-persist");
2612 MUST_BE_UNDEF(ifconfig_ipv6_pool_defined, "ifconfig-ipv6-pool");
2613 MUST_BE_UNDEF(real_hash_size, "hash-size");
2614 MUST_BE_UNDEF(virtual_hash_size, "hash-size");
2615 MUST_BE_UNDEF(learn_address_script, "learn-address");
2616 MUST_BE_UNDEF(client_connect_script, "client-connect");
2617 MUST_BE_UNDEF(client_crresponse_script, "client-crresponse");
2618 MUST_BE_UNDEF(client_disconnect_script, "client-disconnect");
2619 MUST_BE_UNDEF(client_config_dir, "client-config-dir");
2620 MUST_BE_UNDEF(ccd_exclusive, "ccd-exclusive");
2621 MUST_BE_UNDEF(enable_c2c, "client-to-client");
2622 MUST_BE_UNDEF(duplicate_cn, "duplicate-cn");
2623 MUST_BE_UNDEF(cf_max, "connect-freq");
2624 MUST_BE_UNDEF(cf_per, "connect-freq");
2627 "verify-client-cert");
2628 MUST_BE_FALSE(options->ssl_flags & SSLF_USERNAME_AS_COMMON_NAME, "username-as-common-name");
2629 MUST_BE_FALSE(options->ssl_flags & SSLF_AUTH_USER_PASS_OPTIONAL, "auth-user-pass-optional");
2631 {
2632 msg(M_WARN, "WARNING: setting tcp-nodelay on the client side will not "
2633 "affect the server. To have TCP_NODELAY in both direction use "
2634 "tcp-nodelay in the server configuration instead.");
2635 }
2636 MUST_BE_UNDEF(auth_user_pass_verify_script, "auth-user-pass-verify");
2637 MUST_BE_UNDEF(auth_token_generate, "auth-gen-token");
2638#if PORT_SHARE
2639 if (options->port_share_host || options->port_share_port)
2640 {
2641 msg(M_USAGE,
2642 "--port-share requires TCP server mode (--mode server --proto tcp-server)");
2643 }
2644#endif
2645 MUST_BE_UNDEF(stale_routes_check_interval, "stale-routes-check");
2646 MUST_BE_UNDEF(vlan_tagging, "vlan-tagging");
2647 MUST_BE_UNDEF(vlan_accept, "vlan-accept");
2648 MUST_BE_UNDEF(vlan_pvid, "vlan-pvid");
2649 MUST_BE_UNDEF(force_key_material_export, "force-key-material-export");
2650
2651 if (options->push_list.head)
2652 {
2653 msg(M_WARN, "Note: Using --push without --mode server is an "
2654 "unsupported configuration. Negotiation of OpenVPN "
2655 "features is expected to fail.");
2656 }
2657 }
2658
2659 /*
2660 * SSL/TLS mode sanity checks.
2661 */
2663 {
2664 msg(M_USAGE, "specify only one of --tls-server, --tls-client, or --secret");
2665 }
2666
2668 {
2669 msglvl_t msglevel = M_USAGE;
2671 {
2672 msglevel = M_INFO;
2673 }
2674
2675 msg(msglevel, "DEPRECATION: No tls-client or tls-server option in "
2676 "configuration detected. OpenVPN 2.8 will remove the "
2677 "functionality to run a VPN without TLS. "
2678 "See the examples section in the manual page for "
2679 "examples of a similar quick setup with peer-fingerprint. "
2680 "OpenVPN 2.7 allows using this configuration when using "
2681 "--allow-deprecated-insecure-static-crypto but you should move "
2682 "to a proper configuration using TLS as soon as possible.");
2683 }
2684
2686 {
2687 msg(M_WARN, "WARNING: POTENTIALLY DANGEROUS OPTION "
2688 "--verify-client-cert none|optional "
2689 "may accept clients which do not present a certificate");
2690 }
2691
2692 const unsigned int tls_version_max =
2694 const unsigned int tls_version_min =
2696
2697 if (tls_version_max > 0 && tls_version_max < tls_version_min)
2698 {
2699 msg(M_USAGE, "--tls-version-min bigger than --tls-version-max");
2700 }
2701
2703 {
2705#ifdef ENABLE_PKCS11
2706 if (!options->pkcs11_providers[0] && options->pkcs11_id)
2707 {
2708 msg(M_WARN, "Option pkcs11-id is ignored as no pkcs11-providers are specified");
2709 }
2710 else if (!options->pkcs11_providers[0] && options->pkcs11_id_management)
2711 {
2712 msg(M_WARN,
2713 "Option pkcs11-id-management is ignored as no pkcs11-providers are specified");
2714 }
2715
2716 if (options->pkcs11_providers[0])
2717 {
2718 if (options->pkcs11_id_management && options->pkcs11_id != NULL)
2719 {
2720 msg(M_USAGE,
2721 "Parameter --pkcs11-id cannot be used when --pkcs11-id-management is also specified.");
2722 }
2723 if (!options->pkcs11_id_management && options->pkcs11_id == NULL)
2724 {
2725 msg(M_USAGE,
2726 "Parameter --pkcs11-id or --pkcs11-id-management should be specified.");
2727 }
2728 const char use_err[] =
2729 "Parameter --%s cannot be used when --pkcs11-provider is also specified.";
2730 MUST_BE_UNDEF(cert_file, "cert");
2731 MUST_BE_UNDEF(priv_key_file, "key");
2732 MUST_BE_UNDEF(pkcs12_file, "pkcs12");
2733 MUST_BE_FALSE(options->management_flags & MF_EXTERNAL_KEY, "management-external-key");
2734 MUST_BE_FALSE(options->management_flags & MF_EXTERNAL_CERT, "management-external-cert");
2735#ifdef ENABLE_CRYPTOAPI
2736 MUST_BE_UNDEF(cryptoapi_cert, "cryptoapicert");
2737#endif
2738 }
2739 else
2740#endif /* ifdef ENABLE_PKCS11 */
2741#ifdef ENABLE_CRYPTOAPI
2743 {
2744 const char use_err[] =
2745 "Parameter --%s cannot be used when --cryptoapicert is also specified.";
2746 MUST_BE_UNDEF(cert_file, "cert");
2747 MUST_BE_UNDEF(priv_key_file, "key");
2748 MUST_BE_UNDEF(pkcs12_file, "pkcs12");
2749 MUST_BE_FALSE(options->management_flags & MF_EXTERNAL_KEY, "management-external-key");
2750 MUST_BE_FALSE(options->management_flags & MF_EXTERNAL_CERT, "management-external-cert");
2751 }
2752 else
2753#endif
2754 if (options->pkcs12_file)
2755 {
2756#ifdef ENABLE_CRYPTO_MBEDTLS
2757 msg(M_USAGE, "Parameter --pkcs12 cannot be used with the mbed TLS version of OpenVPN.");
2758#else
2759 const char use_err[] = "Parameter --%s cannot be used when --pkcs12 is also specified.";
2760 MUST_BE_UNDEF(ca_path, "capath");
2761 MUST_BE_UNDEF(cert_file, "cert");
2762 MUST_BE_UNDEF(priv_key_file, "key");
2763 MUST_BE_FALSE(options->management_flags & MF_EXTERNAL_KEY, "management-external-key");
2764 MUST_BE_FALSE(options->management_flags & MF_EXTERNAL_CERT, "management-external-cert");
2765#endif /* ifdef ENABLE_CRYPTO_MBEDTLS */
2766 }
2767 else /* cert/key from none of pkcs11, pkcs12, cryptoapi */
2768 {
2770 {
2771 msg(M_USAGE, "--key and --management-external-key are mutually exclusive");
2772 }
2774 {
2775 if (options->cert_file)
2776 {
2777 msg(M_USAGE, "--cert and --management-external-cert are mutually exclusive");
2778 }
2780 {
2781 msg(M_USAGE,
2782 "--management-external-cert must be used with --management-external-key");
2783 }
2784 }
2785 if (pull)
2786 {
2787 const int sum =
2789 + ((options->priv_key_file != NULL)
2791
2792 if (sum == 0)
2793 {
2795 {
2796 msg(M_USAGE, "No client-side authentication method is "
2797 "specified. You must use either "
2798 "--cert/--key, --pkcs12, or "
2799 "--auth-user-pass");
2800 }
2801 }
2802 else if (sum != 2)
2803 {
2804 msg(M_USAGE, "If you use one of --cert or --key, you must use them both");
2805 }
2806 }
2807 else
2808 {
2810 {
2812 "certificate file (--cert) or PKCS#12 file (--pkcs12)");
2813 }
2815 {
2817 "private key file (--key) or PKCS#12 file (--pkcs12)");
2818 }
2819 }
2820 }
2821 if (ce->tls_auth_file && ce->tls_crypt_file)
2822 {
2823 msg(M_USAGE, "--tls-auth and --tls-crypt are mutually exclusive");
2824 }
2826 && (ce->tls_auth_file || ce->tls_crypt_file))
2827 {
2828 msg(M_USAGE,
2829 "--tls-crypt-v2, --tls-auth and --tls-crypt are mutually exclusive in client mode");
2830 }
2831 }
2832 else
2833 {
2834 /*
2835 * Make sure user doesn't specify any TLS options
2836 * when in non-TLS mode.
2837 */
2838
2839 const char use_err[] = "Parameter %s can only be specified in TLS-mode, "
2840 "i.e. where --tls-server or --tls-client is also specified.";
2841
2842 MUST_BE_UNDEF(ca_file, "ca");
2843 MUST_BE_UNDEF(ca_path, "capath");
2844 MUST_BE_UNDEF(dh_file, "dh");
2845 MUST_BE_UNDEF(cert_file, "cert");
2846 MUST_BE_UNDEF(priv_key_file, "key");
2847#ifndef ENABLE_CRYPTO_MBEDTLS
2848 MUST_BE_UNDEF(pkcs12_file, "pkcs12");
2849#endif
2850 MUST_BE_UNDEF(cipher_list, "tls-cipher");
2851 MUST_BE_UNDEF(cipher_list_tls13, "tls-ciphersuites");
2852 MUST_BE_UNDEF(tls_cert_profile, "tls-cert-profile");
2853 MUST_BE_UNDEF(tls_verify, "tls-verify");
2854 MUST_BE_UNDEF(tls_export_peer_cert_dir, "tls-export-cert");
2855 MUST_BE_UNDEF(verify_x509_name, "verify-x509-name");
2856 MUST_BE_UNDEF(tls_timeout, "tls-timeout");
2857 MUST_BE_UNDEF(renegotiate_bytes, "reneg-bytes");
2858 MUST_BE_UNDEF(renegotiate_packets, "reneg-pkts");
2859 MUST_BE_UNDEF(renegotiate_seconds, "reneg-sec");
2860 MUST_BE_UNDEF(handshake_window, "hand-window");
2861 MUST_BE_UNDEF(transition_window, "tran-window");
2862 MUST_BE_UNDEF(tls_auth_file, "tls-auth");
2863 MUST_BE_UNDEF(tls_crypt_file, "tls-crypt");
2864 MUST_BE_UNDEF(tls_crypt_v2_file, "tls-crypt-v2");
2865 MUST_BE_UNDEF(single_session, "single-session");
2866 MUST_BE_UNDEF(push_peer_info, "push-peer-info");
2867 MUST_BE_UNDEF(tls_exit, "tls-exit");
2868 MUST_BE_UNDEF(crl_file, "crl-verify");
2869 MUST_BE_UNDEF(ns_cert_type, "ns-cert-type");
2870 MUST_BE_UNDEF(remote_cert_ku[0], "remote-cert-ku");
2871 MUST_BE_UNDEF(remote_cert_eku, "remote-cert-eku");
2872#ifdef ENABLE_PKCS11
2873 MUST_BE_UNDEF(pkcs11_providers[0], "pkcs11-providers");
2874 MUST_BE_UNDEF(pkcs11_private_mode[0], "pkcs11-private-mode");
2875 MUST_BE_UNDEF(pkcs11_id, "pkcs11-id");
2876 MUST_BE_UNDEF(pkcs11_id_management, "pkcs11-id-management");
2877#endif
2878
2879 if (pull)
2880 {
2881 msg(M_USAGE, use_err, "--pull");
2882 }
2883 }
2885 {
2886 msg(M_USAGE, "--auth-user-pass requires --pull");
2887 }
2888
2889 uninit_options(&defaults);
2890}
2891
2892#undef MUST_BE_UNDEF
2893#undef MUST_BE_FALSE
2894
2895static void
2897{
2898 const int dev = dev_type_enum(o->dev, o->dev_type);
2899
2901 {
2902 if (ce->proto == PROTO_TCP)
2903 {
2904 ce->proto = PROTO_TCP_SERVER;
2905 o->ce.proto = ce->proto;
2906 }
2907 }
2908
2909 if (o->mode != MODE_SERVER)
2910 {
2911 if (ce->proto == PROTO_TCP)
2912 {
2913 ce->proto = PROTO_TCP_CLIENT;
2914 o->ce.proto = ce->proto;
2915 }
2916 }
2917
2918 /* an option is present that requires local bind to enabled */
2919 bool need_bind = ce->local_port_defined || ce->bind_defined || ce->local_list;
2920
2921 /* socks proxy is enabled */
2922 bool uses_socks = ce->proto == PROTO_UDP && ce->socks_proxy_server;
2923
2924 /* If binding is not forced by an explicit option and we have (at least)
2925 * one of --tcp-client, --pull (or --client), or socks we do not bind
2926 * locally to have "normal" IP client behaviour of a random source port */
2927 if (!need_bind && (ce->proto == PROTO_TCP_CLIENT || uses_socks || o->pull))
2928 {
2929 ce->bind_local = false;
2930 }
2931
2932 if (!ce->bind_local)
2933 {
2934 ce->local_port = NULL;
2935 }
2936
2937 /* if protocol forcing is enabled, disable all protocols
2938 * except for the forced one
2939 */
2940 if (o->proto_force >= 0 && o->proto_force != ce->proto)
2941 {
2942 ce->flags |= CE_DISABLED;
2943 }
2944
2945 if (ce->http_proxy_options)
2946 {
2948 }
2949
2950 /* our socks code is not fully IPv6 enabled yet (TCP works, UDP not)
2951 * so fall back to IPv4-only (trac #1221)
2952 */
2953 if (ce->socks_proxy_server && proto_is_udp(ce->proto) && ce->af != AF_INET)
2954 {
2955 if (ce->af == AF_INET6)
2956 {
2957 msg(M_INFO, "WARNING: '--proto udp6' is not compatible with "
2958 "'--socks-proxy' today. Forcing IPv4 mode.");
2959 }
2960 else
2961 {
2962 msg(M_INFO, "NOTICE: dual-stack mode for '--proto udp' does not "
2963 "work correctly with '--socks-proxy' today. Forcing IPv4.");
2964 }
2965 ce->af = AF_INET;
2966 }
2967
2968 /*
2969 * Set MTU defaults
2970 */
2971 {
2972 if (!ce->tun_mtu_defined && !ce->link_mtu_defined)
2973 {
2974 ce->tun_mtu_defined = true;
2975 }
2976 if ((dev == DEV_TYPE_TAP) && !ce->tun_mtu_extra_defined)
2977 {
2978 ce->tun_mtu_extra_defined = true;
2980 }
2981 }
2982
2983 /*
2984 * If --mssfix is supplied without a parameter or not specified at all,
2985 * default it to --fragment value, if --fragment is specified and otherwise
2986 * to the default if tun-mtu is 1500
2987 */
2988 if (o->ce.mssfix_default)
2989 {
2990#ifdef ENABLE_FRAGMENT
2991 if (ce->fragment)
2992 {
2993 ce->mssfix = ce->fragment;
2994 }
2995 else
2996#endif
2997 if (ce->tun_mtu_defined)
2998 {
2999 if (o->ce.tun_mtu == TUN_MTU_DEFAULT)
3000 {
3001 /* We want to only set mssfix default value if we use a default
3002 * MTU Size, otherwise the different size of tun should either
3003 * already solve the problem or mssfix might artifically make the
3004 * payload packets smaller without mssfix 0 */
3005 ce->mssfix = MSSFIX_DEFAULT;
3006 ce->mssfix_encap = true;
3007 }
3008 else
3009 {
3010 /* We still apply the mssfix value but only adjust it to the
3011 * size of the tun interface. */
3012 ce->mssfix = ce->tun_mtu;
3013 ce->mssfix_fixed = true;
3014 }
3015 }
3016 }
3017
3018 /*
3019 * Set per-connection block tls-auth/crypt/crypto-v2 fields if undefined.
3020 *
3021 * At the end only one of these will be really set because the parser
3022 * logic prevents configurations where more are set.
3023 */
3024 if (!ce->tls_auth_file && !ce->tls_crypt_file && !ce->tls_crypt_v2_file)
3025 {
3029
3032
3035 }
3036
3037 /* Pre-cache tls-auth/crypt(-v2) key file if
3038 * keys were not already embedded in the config file.
3039 */
3043
3044
3046 {
3047 msg(M_WARN, "NOTICE: --explicit-exit-notify ignored for --proto tcp");
3049 }
3050}
3051
3052static void
3054{
3055 /* use the global port if none is specified */
3056 if (!le->port)
3057 {
3058 le->port = ce->local_port;
3059 }
3060 /* use the global proto if none is specified and
3061 * allow proto bindings on server mode only */
3062 if (!le->proto || mode == MODE_POINT_TO_POINT)
3063 {
3064 le->proto = ce->proto;
3065 }
3066}
3067
3068#ifdef _WIN32
3069/* If iservice is in use, we need def1 method for redirect-gateway */
3070static void
3072{
3073 if (opt->routes && opt->route_method == ROUTE_METHOD_SERVICE
3074 && opt->routes->flags & RG_REROUTE_GW && !(opt->routes->flags & RG_DEF1))
3075 {
3076 msg(M_INFO, "Flag 'def1' added to --redirect-gateway (iservice is in use)");
3077 opt->routes->flags |= RG_DEF1;
3078 }
3079}
3080#endif /* ifdef _WIN32 */
3081
3082/*
3083 * Save/Restore certain option defaults before --pull is applied.
3084 */
3085
3086static void
3088{
3093
3094 if (o->routes)
3095 {
3097 o->pre_connect->routes_defined = true;
3098 }
3099 if (o->routes_ipv6)
3100 {
3103 }
3104 if (o->client_nat)
3105 {
3108 }
3109
3112
3115
3117
3118 /* NCP related options that can be overwritten by a push */
3120 o->pre_connect->authname = o->authname;
3121
3122 /* Ping related options should be reset to the config values on reconnect */
3126
3127 /* Miscellaneous Options */
3128 o->pre_connect->comp = o->comp;
3129}
3130
3131void
3133{
3134 const struct options_pre_connect *pp = o->pre_connect;
3135 if (pp)
3136 {
3138 if (pp->tuntap_options_defined)
3139 {
3141 }
3142
3143 if (pp->routes_defined)
3144 {
3145 rol_check_alloc(o);
3147 }
3148 else
3149 {
3150 o->routes = NULL;
3151 }
3152
3153 if (pp->routes_ipv6_defined)
3154 {
3157 }
3158 else
3159 {
3160 o->routes_ipv6 = NULL;
3161 }
3162
3165
3168
3169 /* Free DNS options and reset them to pre-pull state */
3170 gc_free(&o->dns_options.gc);
3171 struct gc_arena dns_gc = gc_new();
3172 o->dns_options = clone_dns_options(&pp->dns_options, &dns_gc);
3173 o->dns_options.gc = dns_gc;
3174
3175 if (pp->client_nat_defined)
3176 {
3179 }
3180 else
3181 {
3182 o->client_nat = NULL;
3183 }
3184
3186
3187 o->ciphername = pp->ciphername;
3188 o->authname = pp->authname;
3189
3193
3194 /* Miscellaneous Options */
3195 o->comp = pp->comp;
3196 }
3197
3198 o->push_continuation = 0;
3202}
3203
3204static void
3206{
3207#ifdef _WIN32
3208 const int dev = dev_type_enum(options->dev, options->dev_type);
3209
3210 /* when using ovpn-dco, kernel doesn't send DHCP requests, so don't use it */
3214 {
3216 }
3217
3218 if ((dev == DEV_TYPE_TUN || dev == DEV_TYPE_TAP) && !options->route_delay_defined)
3219 {
3220 /* delay may only be necessary when we perform DHCP handshake */
3223 if ((options->mode == MODE_POINT_TO_POINT) && dhcp)
3224 {
3226 options->route_delay = 5; /* Vista sometimes has a race without this */
3227 }
3228 }
3229
3231 {
3233 options->ifconfig_noexec = false;
3234 }
3235
3237
3238 /*
3239 * Check consistency of --mode server options.
3240 */
3241 if (options->mode == MODE_SERVER)
3242 {
3243 /*
3244 * We need to explicitly set --tap-sleep because
3245 * we do not schedule event timers in the top-level context.
3246 */
3249 {
3251 }
3253 }
3254#endif /* ifdef _WIN32 */
3255
3256#ifdef DEFAULT_PKCS11_MODULE
3257 /* If p11-kit is present on the system then load its p11-kit-proxy.so
3258 * by default if the user asks for PKCS#11 without otherwise specifying
3259 * the module to use. */
3260 if (!options->pkcs11_providers[0] && (options->pkcs11_id || options->pkcs11_id_management))
3261 {
3262 options->pkcs11_providers[0] = DEFAULT_PKCS11_MODULE;
3263 }
3264#endif
3265}
3266
3267static void
3269{
3270 if (o->connection_list)
3271 {
3272 int i;
3273 for (i = 0; i < o->connection_list->len; ++i)
3274 {
3276 }
3277 }
3278 else
3279 {
3281 }
3282
3284
3285 if (dco_enabled(o))
3286 {
3287 if (o->enable_c2c)
3288 {
3289 msg(M_WARN, "Note: --client-to-client has no effect when using data "
3290 "channel offload: packets are always sent to the VPN "
3291 "interface and then routed based on the system routing table");
3292 }
3293
3294 if (o->renegotiate_bytes > 0 || o->renegotiate_packets)
3295 {
3296 msg(M_WARN, "Note: '--reneg-bytes' and '--reneg-pkts' are not supported "
3297 "by data channel offload; automatic key renegotiation "
3298 "mechanisms are sufficient for modern ciphers. "
3299 "Ignoring these options.");
3300 }
3301 }
3302}
3303
3304static void
3306{
3307 if (!o->pull && !(o->mode == MODE_SERVER))
3308 {
3309 /* If the cipher is not set, use the old default of BF-CBC. We will
3310 * warn that this is deprecated on cipher initialisation, no need
3311 * to warn here as well */
3312 if (!o->ciphername)
3313 {
3314 o->ciphername = "BF-CBC";
3315 }
3316 else
3317 {
3318 o->enable_ncp_fallback = true;
3319 }
3320 return;
3321 }
3322
3323 /* pull or P2MP mode */
3324 if (!o->ciphername)
3325 {
3326 /* We still need to set the ciphername to BF-CBC since various other
3327 * parts of OpenVPN assert that the ciphername is set */
3328 o->ciphername = "BF-CBC";
3329
3330 msg(M_INFO,
3331 "Note: --cipher is not set. OpenVPN versions before 2.5 "
3332 "defaulted to BF-CBC as fallback when cipher negotiation "
3333 "failed in this case. If you need this fallback please add "
3334 "'--data-ciphers-fallback BF-CBC' to your configuration "
3335 "and/or add BF-CBC to --data-ciphers. E.g. "
3336 "--data-ciphers %s:BF-CBC",
3337 o->ncp_ciphers_conf);
3338 }
3340 {
3341 msg(M_WARN,
3342 "DEPRECATED OPTION: --cipher set to '%s' but missing in "
3343 "--data-ciphers (%s). OpenVPN ignores --cipher for cipher "
3344 "negotiations. ",
3346 }
3347}
3348
3364static bool
3365need_compatibility_before(const struct options *o, unsigned int version)
3366{
3367 return o->backwards_compatible != 0 && o->backwards_compatible < version;
3368}
3369
3374static void
3376{
3377 /* TLS min version is not set */
3378 unsigned int tls_ver_min = (o->ssl_flags >> SSLF_TLS_VERSION_MIN_SHIFT) & SSLF_TLS_VERSION_MIN_MASK;
3379 if (tls_ver_min == 0)
3380 {
3381 unsigned int tls_ver_max = (o->ssl_flags >> SSLF_TLS_VERSION_MAX_SHIFT) & SSLF_TLS_VERSION_MAX_MASK;
3382 if (need_compatibility_before(o, 20307))
3383 {
3384 /* 2.3.6 and earlier have TLS 1.0 only, set minimum to TLS 1.0 */
3386 }
3387 else if (tls_ver_max == 0 || tls_ver_max >= TLS_VER_1_2)
3388 {
3389 /* Use TLS 1.2 as proper default */
3391 }
3392 else
3393 {
3394 /* Maximize the minimum version */
3395 o->ssl_flags |= (tls_ver_max << SSLF_TLS_VERSION_MIN_SHIFT);
3396 }
3397 }
3398
3399 if (need_compatibility_before(o, 20400))
3400 {
3401 if (!o->ciphername)
3402 {
3403 /* If ciphername is not set default to BF-CBC when targeting these
3404 * old versions that do not have NCP */
3405 o->ciphername = "BF-CBC";
3406 }
3407 /* Versions < 2.4.0 additionally might be compiled with --enable-small and
3408 * not have OCC strings required for "poor man's NCP" */
3409 o->enable_ncp_fallback = true;
3410 }
3411
3412 /* Versions < 2.5.0 do need --cipher in the list of accepted ciphers.
3413 * Version 2.4 probably does not need it but NCP was not so
3414 * good with 2.4 and ncp-disable might be more common on 2.4 peers.
3415 * Only do this iff --cipher is set (explicitly or by compat mode
3416 * < 2.4.0, see above). This is not 100% correct backwards compatible
3417 * behaviour but 2.5 already behaved like this */
3418 if (o->ciphername && need_compatibility_before(o, 20500)
3420 {
3422 }
3423
3424#ifdef USE_COMP
3425 /* Compression is deprecated and we do not want to announce support for it
3426 * by default anymore, additionally DCO breaks with compression.
3427 *
3428 * Disable compression by default starting with 2.6.0 if no other
3429 * compression related option has been explicitly set */
3430 if (!need_compatibility_before(o, 20600) && (o->comp.flags == 0))
3431 {
3432 if (!comp_non_stub_enabled(&o->comp))
3433 {
3435 }
3436 }
3437#else /* ifdef USE_COMP */
3439#endif
3440}
3441
3442static void
3444{
3445 if (!check_tls_prf_working())
3446 {
3447 msg(D_TLS_ERRORS, "Warning: TLS 1.0 PRF with MD5+SHA1 PRF is not "
3448 "supported by the TLS library. Your system does not support this "
3449 "calculation anymore or your security policy (e.g. FIPS 140-2) "
3450 "forbids it. Connections will only work with peers running "
3451 "OpenVPN 2.6.0 or higher)");
3452 if (o->mode == MODE_SERVER)
3453 {
3454 msg(M_WARN, "Automatically enabling option "
3455 "--force-tls-key-material-export");
3456 o->force_key_material_export = true;
3457 }
3458 }
3459}
3460
3461#if defined(_WIN32) || defined(TARGET_ANDROID)
3470static void
3472{
3473 struct dns_options *dns = &o->dns_options;
3474 struct tuntap_options *tt = &o->tuntap_options;
3475 if (!dns->servers)
3476 {
3477 /* Copy --dhcp-options to tuntap_options */
3478 struct dhcp_options *dhcp = &dns->from_dhcp;
3479 ASSERT(sizeof(dhcp->dns) == sizeof(tt->dns));
3480 ASSERT(sizeof(dhcp->dns6) == sizeof(tt->dns6));
3481 ASSERT(sizeof(dhcp->domain_search_list) == sizeof(tt->domain_search_list));
3482
3483 tt->domain = dhcp->domain;
3484 tt->dns_len = dhcp->dns_len;
3485 tt->dns6_len = dhcp->dns6_len;
3486
3487 memcpy(tt->dns, dhcp->dns, sizeof(tt->dns));
3488 memcpy(tt->dns6, dhcp->dns6, sizeof(tt->dns6));
3489
3490 tt->domain_search_list_len = dhcp->domain_search_list_len;
3491 for (size_t i = 0; i < SIZE(tt->domain_search_list); ++i)
3492 {
3493 tt->domain_search_list[i] = dhcp->domain_search_list[i];
3494 }
3495
3496 return;
3497 }
3498
3499#if defined(_WIN32)
3501 {
3502 return; /* Not in DHCP mode */
3503 }
3504#endif /* if defined(_WIN32) */
3505
3506 /* Copy --dns options to tuntap_options */
3507
3508 const struct dns_domain *d = dns->search_domains;
3509 if (d)
3510 {
3511 tt->domain_search_list_len = 0;
3512 }
3513
3514 while (d && tt->domain_search_list_len + 1 < N_SEARCH_LIST_LEN)
3515 {
3517 d = d->next;
3518 }
3519 if (d)
3520 {
3521 msg(M_WARN, "WARNING: couldn't copy all --dns search-domains to TUN/TAP");
3522 }
3523
3524 tt->dns_len = 0;
3525 tt->dns6_len = 0;
3526
3527 const struct dns_server *s = dns->servers;
3528 while (s)
3529 {
3530 bool non_standard_server_port = false;
3531 for (size_t i = 0; i < s->addr_count; ++i)
3532 {
3533 if (s->addr[i].port && s->addr[i].port != 53)
3534 {
3535 non_standard_server_port = true;
3536 break;
3537 }
3538 }
3539 if ((s->transport && s->transport != DNS_TRANSPORT_PLAIN)
3540 || (s->dnssec && s->dnssec != DNS_SECURITY_NO) || non_standard_server_port)
3541 {
3542 /* Skip servers requiring unsupported config to be set */
3543 s = s->next;
3544 }
3545 else
3546 {
3547 bool overflow = false;
3548 for (size_t i = 0; i < s->addr_count; ++i)
3549 {
3550 if (s->addr[i].family == AF_INET && tt->dns_len + 1 < N_DHCP_ADDR)
3551 {
3552 tt->dns[tt->dns_len++] = ntohl(s->addr[i].in.a4.s_addr);
3553 }
3554 else if (tt->dns6_len + 1 < N_DHCP_ADDR)
3555 {
3556 tt->dns6[tt->dns6_len++] = s->addr[i].in.a6;
3557 }
3558 else
3559 {
3560 overflow = true;
3561 }
3562 }
3563 if (overflow)
3564 {
3565 msg(M_WARN, "WARNING: couldn't copy all --dns server addresses to TUN/TAP");
3566 }
3568 return;
3569 }
3570 }
3571}
3572
3573#else /* if defined(_WIN32) || defined(TARGET_ANDROID) */
3574
3585static void
3586dhcp_options_postprocess_dns(struct options *o, struct env_set *es)
3587{
3588 struct gc_arena gc = gc_new();
3589 struct dns_options *dns = &o->dns_options;
3590
3591 if (is_tun_afunix(o->dev_node))
3592 {
3593 /* Disable running dns-updown script with lwipovpn */
3595 dns->updown = NULL;
3596 }
3597
3598 if (dns->servers || dns_updown_user_set(dns) || dns_updown_forced(dns))
3599 {
3600 /* Clean up env from --dhcp-option DNS config */
3601 struct buffer name = alloc_buf_gc(OPTION_PARM_SIZE, &gc);
3602 struct buffer value = alloc_buf_gc(OPTION_PARM_SIZE, &gc);
3603
3604 const int fo_count = o->foreign_option_index;
3605 o->foreign_option_index = 0;
3606
3607 for (int i = 1; i <= fo_count; ++i)
3608 {
3609 buf_clear(&name);
3610 buf_printf(&name, "foreign_option_%d", i);
3611 const char *env_str = env_set_get(es, BSTR(&name));
3612 const char *item_val = strchr(env_str, '=') + 1;
3613 buf_clear(&value);
3614 buf_printf(&value, "%s", item_val);
3615
3616 /* Remove foreign option item from env set */
3617 env_set_del(es, BSTR(&name));
3618
3619 item_val = BSTR(&value);
3620 if (strncmp(item_val, "dhcp-option ", 12) != 0
3621 || (strncmp(item_val + 12, "ADAPTER-DOMAIN-SUFFIX ", 22) != 0
3622 && strncmp(item_val + 12, "DOMAIN-SEARCH ", 14) != 0
3623 && strncmp(item_val + 12, "DOMAIN ", 7) != 0
3624 && strncmp(item_val + 12, "DNS6 ", 5) != 0
3625 && strncmp(item_val + 12, "DNS ", 4) != 0))
3626 {
3627 /* Re-set the item with potentially updated name */
3628 buf_clear(&name);
3629 buf_printf(&name, "foreign_option_%d", ++o->foreign_option_index);
3630 setenv_str(es, BSTR(&name), BSTR(&value));
3631 }
3632 }
3633 }
3634
3635 if (!dns->servers)
3636 {
3637 /* Copy --dhcp-options to dns_options */
3638 struct dhcp_options *dhcp = &dns->from_dhcp;
3639
3640 if (dhcp->dns_len || dhcp->dns6_len)
3641 {
3642 struct dns_domain **entry = &dns->search_domains;
3643 ALLOC_OBJ_CLEAR_GC(*entry, struct dns_domain, &dns->gc);
3644 struct dns_domain *new = *entry;
3645 new->name = dhcp->domain;
3646 entry = &new->next;
3647
3648 for (unsigned int i = 0; i < dhcp->domain_search_list_len; ++i)
3649 {
3650 ALLOC_OBJ_CLEAR_GC(*entry, struct dns_domain, &dns->gc);
3651 struct dns_domain *new = *entry;
3652 new->name = dhcp->domain_search_list[i];
3653 entry = &new->next;
3654 }
3655
3656 struct dns_server *server = dns_server_get(&dns->servers, 0, &dns->gc);
3657 const size_t max_addrs = SIZE(server->addr);
3658 for (unsigned int i = 0; i < dhcp->dns_len && server->addr_count < max_addrs; ++i)
3659 {
3660 server->addr[server->addr_count].in.a4.s_addr = htonl(dhcp->dns[i]);
3661 server->addr[server->addr_count].family = AF_INET;
3662 server->addr_count += 1;
3663 }
3664 for (unsigned int i = 0; i < dhcp->dns6_len && server->addr_count < max_addrs; ++i)
3665 {
3666 server->addr[server->addr_count].in.a6 = dhcp->dns6[i];
3667 server->addr[server->addr_count].family = AF_INET6;
3668 server->addr_count += 1;
3669 }
3670 }
3671 }
3672 else if (o->up_script && !dns_updown_user_set(dns) && !dns_updown_forced(dns))
3673 {
3674 /* Set foreign option env vars from --dns config */
3675 const struct dns_domain *d = dns->search_domains;
3676 while (d)
3677 {
3678 setenv_foreign_option(o, "DOMAIN", d->name, es);
3679 d = d->next;
3680 }
3681
3682 const struct dns_server *s = dns->servers;
3683 while (s)
3684 {
3685 bool non_standard_server_port = false;
3686 for (size_t i = 0; i < s->addr_count; ++i)
3687 {
3688 if (s->addr[i].port && s->addr[i].port != 53)
3689 {
3690 non_standard_server_port = true;
3691 break;
3692 }
3693 }
3694 if ((s->transport && s->transport != DNS_TRANSPORT_PLAIN)
3695 || (s->dnssec && s->dnssec != DNS_SECURITY_NO) || non_standard_server_port)
3696 {
3697 /* Skip servers requiring unsupported config to be set */
3698 s = s->next;
3699 }
3700 else
3701 {
3702 for (size_t i = 0; i < s->addr_count; ++i)
3703 {
3704 const char *option;
3705 const char *value;
3706 if (s->addr[i].family == AF_INET)
3707 {
3708 option = "DNS";
3709 value = print_in_addr_t(s->addr[i].in.a4.s_addr, IA_NET_ORDER, &gc);
3710 }
3711 else
3712 {
3713 option = "DNS6";
3714 value = print_in6_addr(s->addr[i].in.a6, 0, &gc);
3715 }
3716 setenv_foreign_option(o, option, value, es);
3717 }
3718 break;
3719 }
3720 }
3721 }
3722
3723 gc_free(&gc);
3724}
3725#endif /* if defined(_WIN32) || defined(TARGET_ANDROID) */
3730static void
3732{
3733 if (!o->real_hash_size)
3734 {
3735 o->real_hash_size = 4 * o->max_clients;
3736 }
3737 if (!o->virtual_hash_size)
3738 {
3739 o->virtual_hash_size = 4 * o->max_clients;
3740 }
3741}
3742
3743static void
3745{
3746 int i;
3747 /*
3748 * Process helper-type options which map to other, more complex
3749 * sequences of options.
3750 */
3752 /* must be called after helpers that might set --mode */
3756
3757 if (o->mode == MODE_SERVER)
3758 {
3760 }
3761
3765
3768 if (o->ncp_ciphers == NULL)
3769 {
3770 msg(M_USAGE, "--data-ciphers list contains unsupported ciphers or is too long.");
3771 }
3772
3773 if (o->remote_list && !o->connection_list)
3774 {
3775 /*
3776 * Convert remotes into connection list
3777 */
3778 const struct remote_list *rl = o->remote_list;
3779 for (i = 0; i < rl->len; ++i)
3780 {
3781 const struct remote_entry *re = rl->array[i];
3782 struct connection_entry ce = o->ce;
3783 struct connection_entry *ace;
3784
3785 ASSERT(re->remote);
3786 connection_entry_load_re(&ce, re);
3788 ASSERT(ace);
3789 *ace = ce;
3790 }
3791 }
3792 else if (!o->remote_list && !o->connection_list)
3793 {
3794 struct connection_entry *ace;
3796 ASSERT(ace);
3797 *ace = o->ce;
3798 }
3799
3801 for (i = 0; i < o->connection_list->len; ++i)
3802 {
3804 }
3805
3806 if (o->ce.local_list)
3807 {
3808 for (i = 0; i < o->ce.local_list->len; i++)
3809 {
3811 }
3812
3813 for (int i = 0; i < o->ce.local_list->len; i++)
3814 {
3815 if (o->ce.local_list->array[i]->proto == PROTO_TCP)
3816 {
3818 }
3819 else if (o->ce.local_list->array[i]->proto == PROTO_NONE)
3820 {
3821 o->ce.local_list->array[i]->proto = o->ce.proto;
3822 }
3823 }
3824 }
3825 else
3826 {
3827 /* if no 'local' directive was specified, convert the global port
3828 * setting to a listen entry */
3829 struct local_entry *e = alloc_local_entry(&o->ce, M_USAGE, &o->gc);
3830 ASSERT(e);
3831 e->port = o->ce.local_port;
3832 e->proto = o->ce.proto;
3833 }
3834
3835 /* use the same listen list for every outgoing connection */
3836 for (i = 0; i < o->connection_list->len; ++i)
3837 {
3839 }
3840
3841 if (o->tls_server)
3842 {
3843 if (o->dh_file && streq(o->dh_file, "none"))
3844 {
3845 o->dh_file = NULL;
3846 }
3847 }
3848 else if (o->dh_file)
3849 {
3850 /* DH file is only meaningful in a tls-server context. */
3851 msg(M_WARN, "WARNING: Ignoring option 'dh' in tls-client mode, please only "
3852 "include this in your server configuration");
3853 o->dh_file = NULL;
3854 }
3855#if ENABLE_MANAGEMENT
3856 if (o->http_proxy_override)
3857 {
3859 }
3860#endif
3861 if (!o->ca_file && !o->ca_path && o->verify_hash && o->verify_hash_depth == 0)
3862 {
3863 msg(M_INFO, "Using certificate fingerprint to verify peer (no CA "
3864 "option set). ");
3865 o->verify_hash_no_ca = true;
3866 }
3867
3868 if (o->config && streq(o->config, "stdin") && o->remap_sigusr1 == SIGHUP)
3869 {
3870 msg(M_USAGE, "Options 'config stdin' and 'remap-usr1 SIGHUP' are "
3871 "incompatible with each other.");
3872 }
3873
3874 if (dco_enabled(o))
3875 {
3876 /* check if any option should force disabling DCO */
3878 }
3879#ifdef USE_COMP
3880 if (dco_enabled(o))
3881 {
3883 }
3884#endif
3885
3886#ifdef _WIN32
3887 if (dco_enabled(o))
3888 {
3890 }
3891 else
3892 {
3894 }
3895#else /* _WIN32 */
3896 if (dco_enabled(o) && o->dev_node)
3897 {
3898 msg(M_WARN, "Note: ignoring --dev-node as it has no effect when using "
3899 "data channel offload");
3900 o->dev_node = NULL;
3901 }
3902#endif /* _WIN32 */
3903
3904 /* this depends on o->windows_driver, which is set above */
3906
3907 /* check that compression settings in the options are okay */
3909
3910 /*
3911 * Save certain parms before modifying options during connect, especially
3912 * when using --pull
3913 */
3914 if (o->pull)
3915 {
3917 }
3918 else
3919 {
3920#if defined(_WIN32) || defined(TARGET_ANDROID)
3922#else
3923 dhcp_options_postprocess_dns(o, es);
3924#endif
3925 }
3927 {
3929 }
3930#if ENABLE_MANAGEMENT
3932 {
3933 msg(M_USAGE, "'auth-user-pass username-only' cannot be used with static challenge");
3934 }
3935#endif
3937}
3938
3939/*
3940 * Check file/directory sanity
3941 *
3942 */
3943/* Expect people using the stripped down version to know what they do */
3944#ifndef ENABLE_SMALL
3945
3946#define CHKACC_FILE (1 << 0)
3947#define CHKACC_DIRPATH (1 << 1)
3948#define CHKACC_FILEXSTWR (1 << 2)
3949#define CHKACC_ACPTSTDIN (1 << 3)
3950#define CHKACC_PRIVATE (1 << 4)
3951#define CHKACC_ACCEPT_URI (1 << 5)
3953static bool
3954check_file_access(const int type, const char *file, const int mode, const char *opt)
3955{
3956 int errcode = 0;
3957
3958 /* If no file configured, no errors to look for */
3959 if (!file)
3960 {
3961 return false;
3962 }
3963
3964 /* If stdin is allowed and the file name is 'stdin', then do no
3965 * further checks as stdin is always available
3966 */
3967 if ((type & CHKACC_ACPTSTDIN) && streq(file, "stdin"))
3968 {
3969 return false;
3970 }
3971
3972 /* file name is a URI if its first segment has ":" (i.e., before any "/")
3973 * Then no checks done if CHKACC_ACCEPT_URI is set and the URI does not start with "file:"
3974 */
3975 if ((type & CHKACC_ACCEPT_URI) && strchr(file, ':'))
3976 {
3977 if (!strncmp(file, "file:", 5))
3978 {
3979 file += 5;
3980 }
3981 else if (!strchr(file, '/') || strchr(file, '/') > strchr(file, ':'))
3982 {
3983 return false;
3984 }
3985 }
3986
3987 /* Is the directory path leading to the given file accessible? */
3988 if (type & CHKACC_DIRPATH)
3989 {
3990 char *fullpath =
3991 string_alloc(file, NULL); /* POSIX dirname() implementation may modify its arguments */
3992 char *dirpath = dirname(fullpath);
3993
3994 if (platform_access(dirpath, mode | X_OK) != 0)
3995 {
3996 errcode = errno;
3997 }
3998 free(fullpath);
3999 }
4000
4001 /* Is the file itself accessible? */
4002 if (!errcode && (type & CHKACC_FILE) && (platform_access(file, mode) != 0))
4003 {
4004 errcode = errno;
4005 }
4006
4007 /* If the file exists and is accessible, is it writable? */
4008 if (!errcode && (type & CHKACC_FILEXSTWR) && (platform_access(file, F_OK) == 0))
4009 {
4010 if (platform_access(file, W_OK) != 0)
4011 {
4012 errcode = errno;
4013 }
4014 }
4015
4016 /* Warn if a given private file is group/others accessible. */
4017 if (type & CHKACC_PRIVATE)
4018 {
4019 platform_stat_t st;
4020 if (platform_stat(file, &st))
4021 {
4022 msg(M_WARN | M_ERRNO, "WARNING: cannot stat file '%s'", file);
4023 }
4024#ifndef _WIN32
4025 else
4026 {
4027 if (st.st_mode & (S_IRWXG | S_IRWXO))
4028 {
4029 msg(M_WARN, "WARNING: file '%s' is group or others accessible", file);
4030 }
4031 }
4032#endif
4033 }
4034
4035 /* Scream if an error is found */
4036 if (errcode > 0)
4037 {
4038 msg(M_NOPREFIX | M_OPTERR | M_ERRNO, "%s fails with '%s'", opt, file);
4039 }
4040
4041 /* Return true if an error occurred */
4042 return (errcode != 0 ? true : false);
4043}
4044
4045/* A wrapper for check_file_access() which also takes a chroot directory.
4046 * If chroot is NULL, behaviour is exactly the same as calling check_file_access() directly,
4047 * otherwise it will look for the file inside the given chroot directory instead.
4048 */
4049static bool
4050check_file_access_chroot(const char *chroot, const int type, const char *file, const int mode,
4051 const char *opt)
4052{
4053 bool ret = false;
4054
4055 /* If no file configured, no errors to look for */
4056 if (!file)
4057 {
4058 return false;
4059 }
4060
4061 /* If chroot is set, look for the file/directory inside the chroot */
4062 if (chroot)
4063 {
4064 struct gc_arena gc = gc_new();
4065 struct buffer chroot_file;
4066
4067 chroot_file = prepend_dir(chroot, file, &gc);
4068 ret = check_file_access(type, BSTR(&chroot_file), mode, opt);
4069 gc_free(&gc);
4070 }
4071 else
4072 {
4073 /* No chroot in play, just call core file check function */
4074 ret = check_file_access(type, file, mode, opt);
4075 }
4076 return ret;
4077}
4078
4083static bool
4084check_file_access_chroot_inline(bool is_inline, const char *chroot, const int type,
4085 const char *file, const int mode, const char *opt)
4086{
4087 if (is_inline)
4088 {
4089 return false;
4090 }
4091
4092 return check_file_access_chroot(chroot, type, file, mode, opt);
4093}
4094
4099static bool
4100check_file_access_inline(bool is_inline, const int type, const char *file, const int mode,
4101 const char *opt)
4102{
4103 if (is_inline)
4104 {
4105 return false;
4106 }
4107
4108 return check_file_access(type, file, mode, opt);
4109}
4110
4111/*
4112 * Verifies that the path in the "command" that comes after certain script options (e.g., --up) is a
4113 * valid file with appropriate permissions.
4114 *
4115 * "command" consists of a path, optionally followed by a space, which may be
4116 * followed by arbitrary arguments. It is NOT a full shell command line -- shell expansion is not
4117 * performed.
4118 *
4119 * The path and arguments in "command" may be single- or double-quoted or escaped.
4120 *
4121 * The path is extracted from "command", then check_file_access() is called to check it. The
4122 * arguments, if any, are ignored.
4123 *
4124 * Note that the type, mode, and opt arguments to this routine are the same as the corresponding
4125 * check_file_access() arguments.
4126 */
4127static bool
4128check_cmd_access(const char *command, const char *opt, const char *chroot)
4129{
4130 struct argv argv;
4131 bool return_code;
4132
4133 /* If no command was set, there are no errors to look for */
4134 if (!command)
4135 {
4136 return false;
4137 }
4138
4139 /* Extract executable path and arguments */
4140 argv = argv_new();
4141 argv_parse_cmd(&argv, command);
4142
4143 /* if an executable is specified then check it; otherwise, complain */
4144 if (argv.argv[0])
4145 {
4146 /* Scripts requires R_OK as well, but that might fail on binaries which
4147 * only requires X_OK to function on Unix - a scenario not unlikely to
4148 * be seen on suid binaries.
4149 */
4150 return_code = check_file_access_chroot(chroot, CHKACC_FILE, argv.argv[0], X_OK, opt);
4151 }
4152 else
4153 {
4154 msg(M_NOPREFIX | M_OPTERR, "%s fails with '%s': No path to executable.", opt, command);
4155 return_code = true;
4156 }
4157
4158 argv_free(&argv);
4159
4160 return return_code;
4161}
4162
4163/*
4164 * Sanity check of all file/dir options. Checks that file/dir
4165 * is accessible by OpenVPN
4166 */
4167static void
4169{
4170 bool errs = false;
4171
4172 /* ** SSL/TLS/crypto related files ** */
4174 "--dh");
4175
4177 {
4179 R_OK, "--ca");
4180 }
4181
4183 "--capath");
4184
4186 options->cert_file, R_OK, "--cert");
4187
4189 options->extra_certs_file, R_OK, "--extra-certs");
4190
4192 {
4195 options->priv_key_file, R_OK, "--key");
4196 }
4197
4199 options->pkcs12_file, R_OK, "--pkcs12");
4200
4202 {
4204 R_OK | X_OK, "--crl-verify directory");
4205 }
4206 else
4207 {
4208 errs |=
4210 CHKACC_FILE, options->crl_file, R_OK, "--crl-verify");
4211 }
4212
4214 {
4215 errs |=
4217 options->tls_export_peer_cert_dir, W_OK, "--tls-export-cert");
4218 }
4219
4221 for (int i = 0; i < options->connection_list->len; ++i)
4222 {
4224
4226 ce->tls_auth_file, R_OK, "--tls-auth");
4228 ce->tls_crypt_file, R_OK, "--tls-crypt");
4230 ce->tls_crypt_v2_file, R_OK, "--tls-crypt-v2");
4231 }
4232
4233 errs |=
4235 options->shared_secret_file, R_OK, "--secret");
4236
4238 R_OK | W_OK, "--replay-persist");
4239
4240 /* ** Password files ** */
4242 options->key_pass_file, R_OK, "--askpass");
4243#ifdef ENABLE_MANAGEMENT
4244 errs |=
4246 options->management_user_pass, R_OK, "--management user/password file");
4247#endif /* ENABLE_MANAGEMENT */
4250 options->auth_user_pass_file, R_OK, "--auth-user-pass");
4251 /* ** System related ** */
4252 errs |= check_file_access(CHKACC_FILE, options->chroot_dir, R_OK | X_OK, "--chroot directory");
4254 "--writepid");
4255
4256 /* ** Log related ** */
4258 "--status");
4259
4260 /* ** Config related ** */
4262 R_OK | X_OK, "--client-config-dir");
4264 R_OK | W_OK | X_OK, "Temporary directory (--tmp-dir)");
4265
4266 if (errs)
4267 {
4268 msg(M_USAGE, "Please correct these errors.");
4269 }
4270}
4271#endif /* !ENABLE_SMALL */
4272
4273/*
4274 * Sanity check on options.
4275 * Also set some options based on other
4276 * options.
4277 */
4278void
4280{
4283#ifndef ENABLE_SMALL
4285#endif /* !ENABLE_SMALL */
4286}
4287
4288/*
4289 * Sanity check on options after more options were pulled from server.
4290 * Also time to modify some options based on other options.
4291 */
4292bool
4294{
4295 bool success = dns_options_verify(D_PUSH_ERRORS, &o->dns_options);
4296 if (success)
4297 {
4299#if defined(_WIN32) || defined(TARGET_ANDROID)
4301#else
4302 dhcp_options_postprocess_dns(o, es);
4303#endif
4304 }
4305 return success;
4306}
4307
4308/*
4309 * Build an options string to represent data channel encryption options.
4310 * This string must match exactly between peers. The keysize is checked
4311 * separately by read_key().
4312 *
4313 * The following options must match on both peers:
4314 *
4315 * Tunnel options:
4316 *
4317 * --dev tun|tap [unit number need not match]
4318 * --dev-type tun|tap
4319 * --link-mtu
4320 * --udp-mtu
4321 * --tun-mtu
4322 * --proto udp
4323 * --proto tcp-client [matched with --proto tcp-server
4324 * on the other end of the connection]
4325 * --proto tcp-server [matched with --proto tcp-client on
4326 * the other end of the connection]
4327 * --tun-ipv6
4328 * --ifconfig x y [matched with --ifconfig y x on
4329 * the other end of the connection]
4330 *
4331 * --comp-lzo
4332 * --compress alg
4333 * --fragment
4334 *
4335 * Crypto Options:
4336 *
4337 * --cipher
4338 * --auth
4339 * --secret
4340 *
4341 * SSL Options:
4342 *
4343 * --tls-auth
4344 * --tls-client [matched with --tls-server on
4345 * the other end of the connection]
4346 * --tls-server [matched with --tls-client on
4347 * the other end of the connection]
4348 */
4349char *
4350options_string(const struct options *o, const struct frame *frame, struct tuntap *tt,
4351 openvpn_net_ctx_t *ctx, bool remote, struct gc_arena *gc)
4352{
4353 struct buffer out = alloc_buf(OPTION_LINE_SIZE);
4354 bool tt_local = false;
4355
4356 buf_printf(&out, "V4");
4357
4358 /*
4359 * Tunnel Options
4360 */
4361
4362 buf_printf(&out, ",dev-type %s", dev_type_string(o->dev, o->dev_type));
4363 /* the link-mtu that we send has only a meaning if have a fixed
4364 * cipher (p2p) or have a fallback cipher configured for older non
4365 * ncp clients. But not sending it will make even 2.4 complain
4366 * about it being missing. So still send it. */
4367 buf_printf(&out, ",link-mtu %u", (unsigned int)calc_options_string_link_mtu(o, frame));
4368
4369 if (o->ce.occ_mtu != 0)
4370 {
4371 buf_printf(&out, ",tun-mtu %d", o->ce.occ_mtu);
4372 }
4373 else
4374 {
4375 buf_printf(&out, ",tun-mtu %d", frame->tun_mtu);
4376 }
4377
4378 buf_printf(&out, ",proto %s", proto_remote(o->ce.proto, remote));
4379
4380 bool p2p_nopull = o->mode == MODE_POINT_TO_POINT && !PULL_DEFINED(o);
4381 /* send tun_ipv6 only in peer2peer mode - in client/server mode, it
4382 * is usually pushed by the server, triggering a non-helpful warning
4383 */
4384 if (o->ifconfig_ipv6_local && p2p_nopull)
4385 {
4386 buf_printf(&out, ",tun-ipv6");
4387 }
4388
4389 /*
4390 * Try to get ifconfig parameters into the options string.
4391 * If tt is undefined, make a temporary instantiation.
4392 */
4393 if (!tt)
4394 {
4395 tt = init_tun(o->dev, o->dev_type, o->topology, o->ifconfig_local,
4396 o->ifconfig_remote_netmask, o->ifconfig_ipv6_local, o->ifconfig_ipv6_netbits,
4397 o->ifconfig_ipv6_remote, NULL, NULL, false, NULL, ctx, NULL);
4398 if (tt)
4399 {
4400 tt_local = true;
4401 }
4402 }
4403
4404 if (tt && p2p_nopull)
4405 {
4406 const char *ios = ifconfig_options_string(tt, remote, o->ifconfig_nowarn, gc);
4407 if (ios && strlen(ios))
4408 {
4409 buf_printf(&out, ",ifconfig %s", ios);
4410 }
4411 }
4412 if (tt_local)
4413 {
4414 free(tt);
4415 tt = NULL;
4416 }
4417
4418#ifdef USE_COMP
4419 if (o->comp.alg != COMP_ALG_UNDEF)
4420 {
4421 buf_printf(&out, ",comp-lzo"); /* for compatibility, this simply indicates that compression
4422 context is active, not necessarily LZO per-se */
4423 }
4424#endif
4425
4426#ifdef ENABLE_FRAGMENT
4427 if (o->ce.fragment)
4428 {
4429 buf_printf(&out, ",mtu-dynamic");
4430 }
4431#endif
4432
4433#define TLS_CLIENT (o->tls_client)
4434#define TLS_SERVER (o->tls_server)
4435
4436 /*
4437 * Key direction
4438 */
4439 {
4440 const char *kd = keydirection2ascii(o->key_direction, remote, false);
4441 if (kd)
4442 {
4443 buf_printf(&out, ",keydir %s", kd);
4444 }
4445 }
4446
4447 /*
4448 * Crypto Options
4449 */
4450 if (o->shared_secret_file || TLS_CLIENT || TLS_SERVER)
4451 {
4452 struct key_type kt;
4453
4454 ASSERT((o->shared_secret_file != NULL) + (TLS_CLIENT == true) + (TLS_SERVER == true) <= 1);
4455
4456 /* Skip resolving BF-CBC to allow SSL libraries without BF-CBC
4457 * to work here in the default configuration */
4458 const char *ciphername = o->ciphername;
4459 size_t keysize = 0;
4460
4461 if (strcmp(o->ciphername, "BF-CBC") == 0)
4462 {
4463 init_key_type(&kt, "none", o->authname, true, false);
4464 keysize = 128;
4465 }
4466 else
4467 {
4468 init_key_type(&kt, o->ciphername, o->authname, true, false);
4469 ciphername = cipher_kt_name(kt.cipher);
4470 if (cipher_defined(o->ciphername))
4471 {
4472 keysize = cipher_kt_key_size(kt.cipher) * 8;
4473 }
4474 }
4475 /* Only announce the cipher to our peer if we are willing to
4476 * support it */
4477 if (p2p_nopull || tls_item_in_cipher_list(ciphername, o->ncp_ciphers))
4478 {
4479 buf_printf(&out, ",cipher %s", ciphername);
4480 }
4481 buf_printf(&out, ",auth %s", md_kt_name(kt.digest));
4482 buf_printf(&out, ",keysize %zu", keysize);
4483 if (o->shared_secret_file)
4484 {
4485 buf_printf(&out, ",secret");
4486 }
4487 }
4488
4489 /*
4490 * SSL Options
4491 */
4492 {
4493 if (TLS_CLIENT || TLS_SERVER)
4494 {
4495 if (o->ce.tls_auth_file)
4496 {
4497 buf_printf(&out, ",tls-auth");
4498 }
4499 /* Not adding tls-crypt here, because we won't reach this code if
4500 * tls-auth/tls-crypt does not match. Removing tls-auth here would
4501 * break stuff, so leaving that in place. */
4502
4503 buf_printf(&out, ",key-method %d", KEY_METHOD_2);
4504 }
4505
4506 if (remote)
4507 {
4508 if (TLS_CLIENT)
4509 {
4510 buf_printf(&out, ",tls-server");
4511 }
4512 else if (TLS_SERVER)
4513 {
4514 buf_printf(&out, ",tls-client");
4515 }
4516 }
4517 else
4518 {
4519 if (TLS_CLIENT)
4520 {
4521 buf_printf(&out, ",tls-client");
4522 }
4523 else if (TLS_SERVER)
4524 {
4525 buf_printf(&out, ",tls-server");
4526 }
4527 }
4528 }
4529
4530#undef TLS_CLIENT
4531#undef TLS_SERVER
4532
4533 return BSTR(&out);
4534}
4535
4536/*
4537 * Compare option strings for equality.
4538 * If the first two chars of the strings differ, it means that
4539 * we are looking at different versions of the options string,
4540 * therefore don't compare them and return true.
4541 */
4542
4543bool
4544options_cmp_equal(char *actual, const char *expected)
4545{
4546 return options_cmp_equal_safe(actual, expected, strlen(actual) + 1);
4547}
4548
4549void
4550options_warning(char *actual, const char *expected)
4551{
4552 options_warning_safe(actual, expected, strlen(actual) + 1);
4553}
4554
4555static const char *
4556options_warning_extract_parm1(const char *option_string, struct gc_arena *gc_ret)
4557{
4558 struct gc_arena gc = gc_new();
4560 char *p = gc_malloc(OPTION_PARM_SIZE, false, &gc);
4561 const char *ret;
4562
4563 buf_parse(&b, ' ', p, OPTION_PARM_SIZE);
4564 ret = string_alloc(p, gc_ret);
4565 gc_free(&gc);
4566 return ret;
4567}
4568
4569static void
4571 const bool report_inconsistent, const char *p1,
4572 const struct buffer *b2_src, const char *b1_name,
4573 const char *b2_name)
4574{
4575 /* We will stop sending 'key-method', 'keydir', 'proto' and 'tls-auth' in
4576 * OCC in a future version (because it's not useful). To reduce questions
4577 * when interoperating, we no longer printing a warning about it.
4578 */
4579 if (strprefix(p1, "key-method ") || strprefix(p1, "keydir ") || strprefix(p1, "proto ")
4580 || streq(p1, "tls-auth") || strprefix(p1, "tun-ipv6") || strprefix(p1, "cipher "))
4581 {
4582 return;
4583 }
4584
4585 if (strlen(p1) > 0)
4586 {
4587 struct gc_arena gc = gc_new();
4588 struct buffer b2 = *b2_src;
4590 char *p2 = gc_malloc(OPTION_PARM_SIZE, false, &gc);
4591
4592 while (buf_parse(&b2, delim, p2, OPTION_PARM_SIZE))
4593 {
4594 if (strlen(p2))
4595 {
4597
4598 if (!strcmp(p1, p2))
4599 {
4600 goto done;
4601 }
4602 if (!strcmp(p1_prefix, p2_prefix))
4603 {
4605 {
4606 msg(msglevel, "WARNING: '%s' is used inconsistently, %s='%s', %s='%s'",
4608 safe_print(p2, &gc));
4609 }
4610 goto done;
4611 }
4612 }
4613 }
4614
4615 msg(msglevel, "WARNING: '%s' is present in %s config but missing in %s config, %s='%s'",
4617
4618done:
4619 gc_free(&gc);
4620 }
4621}
4622
4623static void
4625 const bool report_inconsistent, const struct buffer *b1_src,
4626 const struct buffer *b2_src, const char *b1_name, const char *b2_name)
4627{
4628 struct gc_arena gc = gc_new();
4629 struct buffer b = *b1_src;
4630 char *p = gc_malloc(OPTION_PARM_SIZE, true, &gc);
4631
4632 while (buf_parse(&b, delim, p, OPTION_PARM_SIZE))
4633 {
4635 b2_name);
4636 }
4637
4638 gc_free(&gc);
4639}
4640
4641static void
4642options_warning_safe_ml(const msglvl_t msglevel, char *actual, const char *expected, size_t actual_n)
4643{
4644 struct gc_arena gc = gc_new();
4645
4646 if (actual_n > 0)
4647 {
4648 struct buffer local = alloc_buf_gc(OPTION_PARM_SIZE + 16, &gc);
4649 struct buffer remote = alloc_buf_gc(OPTION_PARM_SIZE + 16, &gc);
4650 actual[actual_n - 1] = 0;
4651
4652 buf_printf(&local, "version %s", expected);
4653 buf_printf(&remote, "version %s", actual);
4654
4655 options_warning_safe_scan1(msglevel, ',', true, &local, &remote, "local", "remote");
4656
4657 options_warning_safe_scan1(msglevel, ',', false, &remote, &local, "remote", "local");
4658 }
4659
4660 gc_free(&gc);
4661}
4662
4663bool
4664options_cmp_equal_safe(char *actual, const char *expected, size_t actual_n)
4665{
4666 struct gc_arena gc = gc_new();
4667 bool ret = true;
4668
4669 if (actual_n > 0)
4670 {
4671 actual[actual_n - 1] = 0;
4672 if (strncmp(actual, expected, 2))
4673 {
4674 msg(D_SHOW_OCC, "NOTE: Options consistency check may be skewed by version differences");
4675 options_warning_safe_ml(D_SHOW_OCC, actual, expected, actual_n);
4676 }
4677 else
4678 {
4679 ret = !strcmp(actual, expected);
4680 }
4681 }
4682 gc_free(&gc);
4683 return ret;
4684}
4685
4686void
4687options_warning_safe(char *actual, const char *expected, size_t actual_n)
4688{
4689 options_warning_safe_ml(D_SHOW_OCC, actual, expected, actual_n);
4690}
4691
4692const char *
4693options_string_version(const char *s, struct gc_arena *gc)
4694{
4695 struct buffer out = alloc_buf_gc(4, gc);
4696 strncpynt((char *)BPTR(&out), s, 3);
4697 return BSTR(&out);
4698}
4699
4700#if defined(__GNUC__) || defined(__clang__)
4701#pragma GCC diagnostic push
4702#pragma GCC diagnostic ignored "-Wsign-compare"
4703#endif
4704
4705char *
4707{
4708 char *ret = NULL;
4709 const size_t opt_name_len = strlen(opt_name);
4710
4711 const char *p = options_string;
4712 while (p)
4713 {
4714 if (0 == strncmp(p, opt_name, opt_name_len) && strlen(p) > (opt_name_len + 1)
4715 && p[opt_name_len] == ' ')
4716 {
4717 /* option found, extract value */
4718 const char *start = &p[opt_name_len + 1];
4719 const char *end = strchr(p, ',');
4720 size_t val_len = end ? end - start : strlen(start);
4721 ret = gc_malloc(val_len + 1, true, gc);
4722 memcpy(ret, start, val_len);
4723 break;
4724 }
4725 p = strchr(p, ',');
4726 if (p)
4727 {
4728 p++; /* skip delimiter */
4729 }
4730 }
4731 return ret;
4732}
4733
4734#if defined(__GNUC__) || defined(__clang__)
4735#pragma GCC diagnostic pop
4736#endif
4737
4738/*
4739 * parse/print topology coding
4740 */
4741
4742int
4743parse_topology(const char *str, const msglvl_t msglevel)
4744{
4745 if (streq(str, "net30"))
4746 {
4747 return TOP_NET30;
4748 }
4749 else if (streq(str, "p2p"))
4750 {
4751 return TOP_P2P;
4752 }
4753 else if (streq(str, "subnet"))
4754 {
4755 return TOP_SUBNET;
4756 }
4757 else
4758 {
4759 msg(msglevel, "--topology must be net30, p2p, or subnet");
4760 return TOP_UNDEF;
4761 }
4762}
4763
4764const char *
4765print_topology(const int topology)
4766{
4767 switch (topology)
4768 {
4769 case TOP_UNDEF:
4770 return "undef";
4771
4772 case TOP_NET30:
4773 return "net30";
4774
4775 case TOP_P2P:
4776 return "p2p";
4777
4778 case TOP_SUBNET:
4779 return "subnet";
4780
4781 default:
4782 return "unknown";
4783 }
4784}
4785
4786/*
4787 * Manage auth-retry variable
4788 */
4789
4790static int global_auth_retry; /* GLOBAL */
4791
4792int
4794{
4795 return global_auth_retry;
4796}
4797
4798bool
4799auth_retry_set(const msglvl_t msglevel, const char *option)
4800{
4801 if (streq(option, "interact"))
4802 {
4804 }
4805 else if (streq(option, "nointeract"))
4806 {
4808 }
4809 else if (streq(option, "none"))
4810 {
4812 }
4813 else
4814 {
4815 msg(msglevel, "--auth-retry method must be 'interact', 'nointeract', or 'none'");
4816 return false;
4817 }
4818 return true;
4819}
4820
4821const char *
4823{
4824 switch (global_auth_retry)
4825 {
4826 case AR_NONE:
4827 return "none";
4828
4829 case AR_NOINTERACT:
4830 return "nointeract";
4831
4832 case AR_INTERACT:
4833 return "interact";
4834
4835 default:
4836 return "???";
4837 }
4838}
4839
4840/*
4841 * Print the help message.
4842 */
4843void
4845{
4846 FILE *fp = msg_fp(0);
4847
4848#ifdef ENABLE_SMALL
4849
4850 fprintf(fp, "Usage message not available\n");
4851
4852#else
4853
4854 struct options o;
4855 init_options(&o);
4856
4862 fflush(fp);
4863
4864#endif /* ENABLE_SMALL */
4865
4866 openvpn_exit(OPENVPN_EXIT_STATUS_USAGE); /* exit point */
4867}
4868
4869void
4871{
4872 msg(M_WARN | M_NOPREFIX, "Use --help for more information.");
4873 openvpn_exit(OPENVPN_EXIT_STATUS_USAGE); /* exit point */
4874}
4875
4876#ifdef _WIN32
4877void
4878show_windows_version(const unsigned int flags)
4879{
4880 struct gc_arena gc = gc_new();
4881 msg(flags, "Windows version: %s", win32_version_string(&gc));
4882 gc_free(&gc);
4883}
4884#endif
4885
4886void
4887show_dco_version(const unsigned int flags)
4888{
4889#ifdef ENABLE_DCO
4890 struct gc_arena gc = gc_new();
4891 msg(flags, "DCO version: %s", dco_version_string(&gc));
4892 gc_free(&gc);
4893#endif
4894}
4895
4896void
4897show_library_versions(const unsigned int flags)
4898{
4899#ifdef ENABLE_LZO
4900#define LZO_LIB_VER_STR ", LZO ", lzo_version_string()
4901#else
4902#define LZO_LIB_VER_STR "", ""
4903#endif
4904
4905 msg(flags, "library versions: %s%s%s", get_ssl_library_version(), LZO_LIB_VER_STR);
4906
4907#undef LZO_LIB_VER_STR
4908}
4909
4910static void
4912{
4915#ifdef _WIN32
4917#endif
4919 msg(M_INFO | M_NOPREFIX, "Originally developed by James Yonan");
4920 msg(M_INFO | M_NOPREFIX, "Copyright (C) 2002-2026 OpenVPN Inc <sales@openvpn.net>");
4921#ifndef ENABLE_SMALL
4922#ifdef CONFIGURE_DEFINES
4923 msg(M_INFO | M_NOPREFIX, "Compile time defines: %s", CONFIGURE_DEFINES);
4924#endif
4925#ifdef CONFIGURE_SPECIAL_BUILD
4926 msg(M_INFO | M_NOPREFIX, "special build: %s", CONFIGURE_SPECIAL_BUILD);
4927#endif
4928#endif
4930}
4931
4932void
4933notnull(const char *arg, const char *description)
4934{
4935 if (!arg)
4936 {
4937 msg(M_USAGE, "You must define %s", description);
4938 }
4939}
4940
4941bool
4942string_defined_equal(const char *s1, const char *s2)
4943{
4944 if (s1 && s2)
4945 {
4946 return !strcmp(s1, s2);
4947 }
4948 else
4949 {
4950 return false;
4951 }
4952}
4953
4954#if 0
4955static void
4956ping_rec_err(msglvl_t msglevel)
4957{
4958 msg(msglevel, "only one of --ping-exit or --ping-restart options may be specified");
4959}
4960#endif
4961
4962#ifdef _WIN32 /* This function is only used when compiling on Windows */
4963static unsigned int
4964atou(const char *str)
4965{
4966 unsigned int val = 0;
4967 sscanf(str, "%u", &val);
4968 return val;
4969}
4970#endif
4971
4972#define VERIFY_PERMISSION(mask) \
4973 { \
4974 if (!verify_permission(p[0], file, line, (mask), permission_mask, option_types_found, \
4975 msglevel, options, is_inline)) \
4976 { \
4977 goto err; \
4978 } \
4979 }
4980
4981static bool
4982verify_permission(const char *name, const char *file, int line, const uint64_t type,
4983 const uint64_t allowed, uint64_t *found, const msglvl_t msglevel,
4984 struct options *options, bool is_inline)
4985{
4986 if (!(type & allowed))
4987 {
4988 msg(msglevel, "option '%s' cannot be used in this context (%s)", name, file);
4989 return false;
4990 }
4991
4992 if (is_inline && !(type & OPT_P_INLINE))
4993 {
4994 msg(msglevel, "option '%s' is not expected to be inline (%s:%d)", name, file, line);
4995 return false;
4996 }
4997
4998 if (found)
4999 {
5000 *found |= type;
5001 }
5002
5003#ifndef ENABLE_SMALL
5004 /* Check if this options is allowed in connection block,
5005 * but we are currently not in a connection block
5006 * unless this is a pushed option.
5007 * Parsing a connection block uses a temporary options struct without
5008 * connection_list
5009 */
5010
5011 if ((type & OPT_P_CONNECTION) && options->connection_list && !(allowed & OPT_P_PULL_MODE))
5012 {
5013 if (file)
5014 {
5015 msg(M_WARN, "Option '%s' in %s:%d is ignored by previous <connection> blocks ", name,
5016 file, line);
5017 }
5018 else
5019 {
5020 msg(M_WARN, "Option '%s' is ignored by previous <connection> blocks", name);
5021 }
5022 }
5023#endif
5024 return true;
5025}
5026
5027/*
5028 * Check that an option doesn't have too
5029 * many parameters.
5030 */
5031
5032#define NM_QUOTE_HINT (1 << 0)
5033
5034static bool
5035no_more_than_n_args(const msglvl_t msglevel, char *p[], const int max, const unsigned int flags)
5036{
5037 const int len = string_array_len((const char **)p);
5038
5039 if (!len)
5040 {
5041 return false;
5042 }
5043
5044 if (len > max)
5045 {
5046 msg(msglevel, "the --%s directive should have at most %d parameter%s.%s", p[0], max - 1,
5047 max >= 3 ? "s" : "",
5048 (flags & NM_QUOTE_HINT)
5049 ? " To pass a list of arguments as one of the parameters, try enclosing them in double quotes (\"\")."
5050 : "");
5051 return false;
5052 }
5053 else
5054 {
5055 return true;
5056 }
5057}
5058
5059static inline msglvl_t
5061{
5062 return options->forward_compatible ? M_WARN : msglevel;
5063}
5064
5065#define RESET_OPTION_ROUTES(option_ptr, field) \
5066 if (option_ptr) \
5067 { \
5068 option_ptr->field = NULL; \
5069 option_ptr->flags = 0; \
5070 }
5071
5072void
5073remove_option(struct context *c, struct options *options, char *p[], bool is_inline,
5074 const char *file, int line, const msglvl_t msglevel,
5075 const uint64_t permission_mask, uint64_t *option_types_found,
5076 struct env_set *es)
5077{
5078 msglvl_t msglevel_fc = msglevel_forward_compatible(options, msglevel);
5079
5080 if (streq(p[0], "ifconfig") && !p[1])
5081 {
5083 options->ifconfig_local = NULL;
5085 }
5086 else if (streq(p[0], "ifconfig-ipv6") && !p[1])
5087 {
5092 }
5093 else if (streq(p[0], "route") && !p[1])
5094 {
5096 if (c->c1.route_list)
5097 {
5099 &c->net_ctx);
5101 }
5102 }
5103 else if (streq(p[0], "route-ipv6") && !p[1])
5104 {
5106 if (c->c1.route_ipv6_list)
5107 {
5109 es, &c->net_ctx);
5111 }
5112 }
5113 else if (streq(p[0], "route-gateway") && !p[1])
5114 {
5118 }
5119 else if (streq(p[0], "route-metric") && !p[1])
5120 {
5123 }
5124 else if (streq(p[0], "push-continuation") && !p[1])
5125 {
5128 }
5129 else if ((streq(p[0], "redirect-gateway") || streq(p[0], "redirect-private")) && !p[1])
5130 {
5132 if (options->routes)
5133 {
5134 options->routes->flags = 0;
5135 }
5136 if (options->routes_ipv6)
5137 {
5139 }
5140 env_set_del(es, "route_redirect_gateway_ipv4");
5141 env_set_del(es, "route_redirect_gateway_ipv6");
5142 }
5143 else if (streq(p[0], "dns") && !p[1])
5144 {
5148 }
5149 else if (streq(p[0], "topology") && !p[1])
5150 {
5154 }
5155 else if (streq(p[0], "tun-mtu") && !p[1])
5156 {
5159 options->ce.tun_mtu_defined = false;
5160 options->ce.occ_mtu = 0;
5161 }
5162 else if (streq(p[0], "block-ipv6") && !p[1])
5163 {
5165 options->block_ipv6 = false;
5166 }
5167#if defined(_WIN32) || defined(TARGET_ANDROID)
5168 else if (streq(p[0], "dhcp-option") && !p[1])
5169 {
5172
5173 o->domain = NULL;
5174 o->netbios_scope = NULL;
5175 o->netbios_node_type = 0;
5176 o->dns6_len = 0;
5177 memset(o->dns6, 0, sizeof(o->dns6));
5178 o->dns_len = 0;
5179 memset(o->dns, 0, sizeof(o->dns));
5180 o->wins_len = 0;
5181 memset(o->wins, 0, sizeof(o->wins));
5182 o->ntp_len = 0;
5183 memset(o->ntp, 0, sizeof(o->ntp));
5184 o->nbdd_len = 0;
5185 memset(o->nbdd, 0, sizeof(o->nbdd));
5186 while (o->domain_search_list_len-- > 0)
5187 {
5189 }
5190 o->disable_nbt = 0;
5191 o->dhcp_options = 0;
5192#if defined(TARGET_ANDROID)
5193 o->http_proxy_port = 0;
5194 o->http_proxy = NULL;
5195#endif
5196 }
5197#endif /* if defined(_WIN32) || defined(TARGET_ANDROID) */
5198#ifdef _WIN32
5199 else if (streq(p[0], "block-outside-dns") && !p[1])
5200 {
5202 options->block_outside_dns = false;
5203 }
5204#else /* ifdef _WIN32 */
5205 else if (streq(p[0], "dhcp-option") && !p[1])
5206 {
5208 delete_all_dhcp_fo(options, &es->list);
5209 }
5210#endif
5211 else
5212 {
5213 msglvl_t msglevel_unknown = msglevel_fc;
5214 /* Check if an option is in --ignore-unknown-option and
5215 * set warning level to non fatal */
5216 for (int i = 0; options->ignore_unknown_option && options->ignore_unknown_option[i]; i++)
5217 {
5218 if (streq(p[0], options->ignore_unknown_option[i]))
5219 {
5220 msglevel_unknown = M_WARN;
5221 break;
5222 }
5223 }
5224 msg(msglevel_unknown,
5225 "Unrecognized option or missing or extra parameter(s) in %s:%d: -%s (%s)", file, line,
5226 p[0], PACKAGE_VERSION);
5227 }
5228 return;
5229err:
5230 msg(msglevel, "Error occurred trying to remove %s option", p[0]);
5231}
5232
5233
5234static bool
5235check_route_option(struct options *options, char *p[], const msglvl_t msglevel, bool pull_mode)
5236{
5238 if (pull_mode)
5239 {
5241 && !is_special_addr(p[1])) /* FQDN -- may be DNS name */
5242 {
5243 msg(msglevel, "route parameter network/IP '%s' must be a valid address", p[1]);
5244 return false;
5245 }
5246 if (p[2] && !ip_addr_dotted_quad_safe(p[2])) /* FQDN -- must be IP address */
5247 {
5248 msg(msglevel, "route parameter netmask '%s' must be an IP address", p[2]);
5249 return false;
5250 }
5251 if (p[3] && !ip_or_dns_addr_safe(p[3], options->allow_pull_fqdn)
5252 && !is_special_addr(p[3])) /* FQDN -- may be DNS name */
5253 {
5254 msg(msglevel, "route parameter gateway '%s' must be a valid address", p[3]);
5255 return false;
5256 }
5257 }
5258 return true;
5259}
5260
5261
5262static bool
5263check_route6_option(struct options *options, char *p[], const msglvl_t msglevel, bool pull_mode)
5264{
5266 if (pull_mode)
5267 {
5268 if (!ipv6_addr_safe_hexplusbits(p[1]))
5269 {
5270 msg(msglevel, "route-ipv6 parameter network/IP '%s' must be a valid address", p[1]);
5271 return false;
5272 }
5273 if (p[2] && !ipv6_addr_safe(p[2]))
5274 {
5275 msg(msglevel, "route-ipv6 parameter gateway '%s' must be a valid address", p[2]);
5276 return false;
5277 }
5278 /* p[3] is metric, if present */
5279 }
5280 return true;
5281}
5282
5283static bool
5284check_dns_option(struct options *options, char *p[], const msglvl_t msglevel, bool pull_mode)
5285{
5286 if (streq(p[1], "search-domains") && p[2])
5287 {
5290 {
5291 msg(msglevel, "--dns %s contain invalid characters", p[1]);
5292 return false;
5293 }
5294 }
5295 else if (streq(p[1], "server") && p[2] && p[3] && p[4])
5296 {
5297 long priority;
5298 if (!dns_server_priority_parse(&priority, p[2], pull_mode))
5299 {
5300 msg(msglevel, "--dns server: invalid priority value '%s'", p[2]);
5301 return false;
5302 }
5303
5304 struct dns_server *server =
5306
5307 if (streq(p[3], "address") && p[4])
5308 {
5309 for (int i = 4; p[i]; ++i)
5310 {
5311 if (!dns_server_addr_parse(server, p[i]))
5312 {
5313 msg(msglevel, "--dns server %ld: malformed address or maximum exceeded '%s'",
5314 priority, p[i]);
5315 return false;
5316 }
5317 }
5318 }
5319 else if (streq(p[3], "resolve-domains"))
5320 {
5321 if (!dns_domain_list_append(&server->domains, &p[4], &options->dns_options.gc))
5322 {
5323 msg(msglevel, "--dns server %ld: %s contain invalid characters", priority, p[3]);
5324 return false;
5325 }
5326 }
5327 else if (streq(p[3], "dnssec") && !p[5])
5328 {
5329 if (streq(p[4], "yes"))
5330 {
5331 server->dnssec = DNS_SECURITY_YES;
5332 }
5333 else if (streq(p[4], "no"))
5334 {
5335 server->dnssec = DNS_SECURITY_NO;
5336 }
5337 else if (streq(p[4], "optional"))
5338 {
5339 server->dnssec = DNS_SECURITY_OPTIONAL;
5340 }
5341 else
5342 {
5343 msg(msglevel, "--dns server %ld: malformed dnssec value '%s'", priority, p[4]);
5344 return false;
5345 }
5346 }
5347 else if (streq(p[3], "transport") && !p[5])
5348 {
5349 if (streq(p[4], "plain"))
5350 {
5352 }
5353 else if (streq(p[4], "DoH"))
5354 {
5356 }
5357 else if (streq(p[4], "DoT"))
5358 {
5359 server->transport = DNS_TRANSPORT_TLS;
5360 }
5361 else
5362 {
5363 msg(msglevel, "--dns server %ld: malformed transport value '%s'", priority, p[4]);
5364 return false;
5365 }
5366 }
5367 else if (streq(p[3], "sni") && !p[5])
5368 {
5369 if (!validate_domain(p[4]))
5370 {
5371 msg(msglevel, "--dns server %ld: %s contains invalid characters", priority, p[3]);
5372 return false;
5373 }
5374 server->sni = p[4];
5375 }
5376 else
5377 {
5378 msg(msglevel,
5379 "--dns server %ld: unknown option type '%s' or missing or unknown parameter",
5380 priority, p[3]);
5381 return false;
5382 }
5383 }
5384 else
5385 {
5386 msg(msglevel, "--dns: unknown option type '%s' or missing or unknown parameter", p[1]);
5387 return false;
5388 }
5389 return true;
5390}
5391
5392void
5393update_option(struct context *c, struct options *options, char *p[], bool is_inline,
5394 const char *file, int line, const int level, const msglvl_t msglevel,
5395 const uint64_t permission_mask, uint64_t *option_types_found,
5396 struct env_set *es)
5397{
5398 const bool pull_mode = BOOL_CAST(permission_mask & OPT_P_PULL_MODE);
5399 ASSERT(MAX_PARMS >= 7);
5400
5401 if (streq(p[0], "route") && p[1] && !p[5])
5402 {
5404 {
5406 if (!check_route_option(options, p, msglevel, pull_mode))
5407 {
5408 goto err;
5409 }
5410 if (c->c1.route_list)
5411 {
5413 es, &c->net_ctx);
5415 }
5417 }
5418 }
5419 else if (streq(p[0], "route-ipv6") && p[1] && !p[4])
5420 {
5422 {
5424 if (!check_route6_option(options, p, msglevel, pull_mode))
5425 {
5426 goto err;
5427 }
5428 if (c->c1.route_ipv6_list)
5429 {
5433 }
5435 }
5436 }
5437 else if (streq(p[0], "redirect-gateway") || streq(p[0], "redirect-private"))
5438 {
5440 {
5442 if (options->routes)
5443 {
5444 options->routes->flags = 0;
5445 }
5446 if (options->routes_ipv6)
5447 {
5449 }
5450 env_set_del(es, "route_redirect_gateway_ipv4");
5451 env_set_del(es, "route_redirect_gateway_ipv6");
5453 }
5454 }
5455 else if (streq(p[0], "dns") && p[1])
5456 {
5458 {
5460 if (!check_dns_option(options, p, msglevel, pull_mode))
5461 {
5462 goto err;
5463 }
5467 }
5468 }
5469#if defined(_WIN32) || defined(TARGET_ANDROID)
5470 else if (streq(p[0], "dhcp-option") && p[1] && !p[3])
5471 {
5473 {
5476
5477 o->domain = NULL;
5478 o->netbios_scope = NULL;
5479 o->netbios_node_type = 0;
5480 o->dns6_len = 0;
5481 CLEAR(o->dns6);
5482 o->dns_len = 0;
5483 CLEAR(o->dns);
5484 o->wins_len = 0;
5485 CLEAR(o->wins);
5486 o->ntp_len = 0;
5487 CLEAR(o->ntp);
5488 o->nbdd_len = 0;
5489 CLEAR(o->nbdd);
5490 while (o->domain_search_list_len-- > 0)
5491 {
5493 }
5494 o->disable_nbt = 0;
5495 o->dhcp_options = 0;
5496
5498#if defined(TARGET_ANDROID)
5499 o->http_proxy_port = 0;
5500 o->http_proxy = NULL;
5501#endif
5503 }
5504 }
5505#else /* if defined(_WIN32) || defined(TARGET_ANDROID) */
5506 else if (streq(p[0], "dhcp-option") && p[1] && !p[3])
5507 {
5509 {
5511 delete_all_dhcp_fo(options, &es->list);
5513 }
5514 }
5515#endif /* if defined(_WIN32) || defined(TARGET_ANDROID) */
5516 add_option(options, p, is_inline, file, line, level, msglevel, permission_mask,
5517 option_types_found, es);
5518 return;
5519err:
5520 msg(msglevel, "Error occurred trying to update %s option", p[0]);
5521}
5522
5523static void
5524set_user_script(struct options *options, const char **script, const char *new_script,
5525 const char *type, bool in_chroot)
5526{
5527 if (*script)
5528 {
5529 msg(M_WARN,
5530 "Multiple --%s scripts defined. "
5531 "The previously configured script is overridden.",
5532 type);
5533 }
5534 *script = new_script;
5535 options->user_script_used = true;
5536
5537#ifndef ENABLE_SMALL
5538 {
5539 char script_name[100];
5540 snprintf(script_name, sizeof(script_name), "--%s script", type);
5541
5542 if (check_cmd_access(*script, script_name, (in_chroot ? options->chroot_dir : NULL)))
5543 {
5544 msg(M_USAGE, "Please correct this error.");
5545 }
5546 }
5547#endif
5548}
5549
5550static void
5552{
5553 if (comp_non_stub_enabled(info))
5554 {
5555 msg(M_WARN, "WARNING: Compression for receiving enabled. "
5556 "Compression has been used in the past to break encryption. "
5557 "Compression support is deprecated and we recommend to disable "
5558 "it completely.");
5559 }
5560}
5561
5562bool
5564{
5565 bool ret = false;
5566 ret = ret || (options->management_flags & MF_EXTERNAL_KEY);
5567#ifdef ENABLE_PKCS11
5568 ret = ret || (options->pkcs11_providers[0] != NULL);
5569#endif
5570#ifdef ENABLE_CRYPTOAPI
5571 ret = ret || options->cryptoapi_cert;
5572#endif
5573
5574 return ret;
5575}
5576
5577#if defined(__GNUC__) || defined(__clang__)
5578#pragma GCC diagnostic push
5579#pragma GCC diagnostic ignored "-Wsign-compare"
5580#endif
5581
5582void
5583add_option(struct options *options, char *p[], bool is_inline, const char *file, int line,
5584 const int level, const msglvl_t msglevel, const uint64_t permission_mask,
5585 uint64_t *option_types_found, struct env_set *es)
5586{
5587 struct gc_arena gc = gc_new();
5588 const bool pull_mode = BOOL_CAST(permission_mask & OPT_P_PULL_MODE);
5589 msglvl_t msglevel_fc = msglevel_forward_compatible(options, msglevel);
5590
5591 ASSERT(MAX_PARMS >= 7);
5592
5593 /*
5594 * If directive begins with "setenv opt" prefix, don't raise an error if
5595 * directive is unrecognized.
5596 */
5597 if (streq(p[0], "setenv") && p[1] && streq(p[1], "opt") && !(permission_mask & OPT_P_PULL_MODE))
5598 {
5599 if (!p[2])
5600 {
5601 p[2] = "setenv opt"; /* will trigger an error that includes setenv opt */
5602 }
5603 p += 2;
5604 msglevel_fc = M_WARN;
5605 }
5606
5607 if (!file)
5608 {
5609 file = "[CMD-LINE]";
5610 line = 1;
5611 }
5612 if (streq(p[0], "help"))
5613 {
5615 usage();
5616 if (p[1])
5617 {
5618 msg(msglevel, "--help does not accept any parameters");
5619 goto err;
5620 }
5621 }
5622 if (streq(p[0], "version") && !p[1])
5623 {
5625 usage_version();
5626 }
5627 else if (streq(p[0], "config") && p[1] && !p[2])
5628 {
5630
5631 /* save first config file only in options */
5632 if (!options->config)
5633 {
5634 options->config = p[1];
5635 }
5636
5637 read_config_file(options, p[1], level, file, line, msglevel, permission_mask,
5638 option_types_found, es);
5639 }
5640#if defined(ENABLE_DEBUG) && !defined(ENABLE_SMALL)
5641 else if (streq(p[0], "show-gateway") && !p[2])
5642 {
5643 struct route_gateway_info rgi;
5644 struct route_ipv6_gateway_info rgi6;
5645 in_addr_t remote_ipv4 = 0;
5646 struct in6_addr remote_ipv6 = IN6ADDR_ANY_INIT;
5647 openvpn_net_ctx_t net_ctx;
5649 if (p[1])
5650 {
5651 /* try parsing the argument as a v4 or v6 address - if
5652 * possible, the output will show the exact route there, and
5653 * "the default route" for the other protocol
5654 */
5655 remote_ipv4 = get_ip_addr(p[1], M_WARN, NULL);
5656 get_ipv6_addr(p[1], &remote_ipv6, NULL, M_WARN);
5657 }
5658 net_ctx_init(NULL, &net_ctx);
5659 get_default_gateway(&rgi, remote_ipv4, &net_ctx);
5660 get_default_gateway_ipv6(&rgi6, &remote_ipv6, &net_ctx);
5661 print_default_gateway(M_INFO, &rgi, &rgi6);
5662 openvpn_exit(OPENVPN_EXIT_STATUS_GOOD); /* exit point */
5663 }
5664#endif
5665 else if (streq(p[0], "echo") || streq(p[0], "parameter"))
5666 {
5667 struct buffer string = alloc_buf_gc(OPTION_PARM_SIZE, &gc);
5668 int j;
5669 bool good = true;
5670
5672
5673 for (j = 1; j < MAX_PARMS; ++j)
5674 {
5675 if (!p[j])
5676 {
5677 break;
5678 }
5679 if (j > 1)
5680 {
5681 good &= buf_printf(&string, " ");
5682 }
5683 good &= buf_printf(&string, "%s", p[j]);
5684 }
5685 if (good)
5686 {
5687 /* only message-related ECHO are logged, since other ECHOs
5688 * can potentially include security-sensitive strings */
5689 if (p[1] && strncmp(p[1], "msg", 3) == 0)
5690 {
5691 msg(M_INFO, "%s:%s", pull_mode ? "ECHO-PULL" : "ECHO", BSTR(&string));
5692 }
5693#ifdef ENABLE_MANAGEMENT
5694 if (management)
5695 {
5697 }
5698#endif
5699 }
5700 else
5701 {
5702 msg(M_WARN, "echo/parameter option overflow");
5703 }
5704 }
5705#ifdef ENABLE_MANAGEMENT
5706 else if (streq(p[0], "management") && p[1] && p[2] && !p[4])
5707 {
5709 if (streq(p[2], "unix"))
5710 {
5711#if UNIX_SOCK_SUPPORT
5713#else
5714 msg(msglevel, "MANAGEMENT: this platform does not support unix domain sockets");
5715 goto err;
5716#endif
5717 }
5718
5721 if (p[3])
5722 {
5724 }
5725 }
5726 else if (streq(p[0], "management-client-user") && p[1] && !p[2])
5727 {
5730 }
5731 else if (streq(p[0], "management-client-group") && p[1] && !p[2])
5732 {
5735 }
5736 else if (streq(p[0], "management-query-passwords") && !p[1])
5737 {
5740 }
5741 else if (streq(p[0], "management-query-remote") && !p[1])
5742 {
5745 }
5746 else if (streq(p[0], "management-query-proxy") && !p[1])
5747 {
5750 }
5751 else if (streq(p[0], "management-hold") && !p[1])
5752 {
5755 }
5756 else if (streq(p[0], "management-signal") && !p[1])
5757 {
5760 }
5761 else if (streq(p[0], "management-forget-disconnect") && !p[1])
5762 {
5765 }
5766 else if (streq(p[0], "management-up-down") && !p[1])
5767 {
5770 }
5771 else if (streq(p[0], "management-client") && !p[1])
5772 {
5775 }
5776 else if (streq(p[0], "management-external-key"))
5777 {
5779 for (int j = 1; j < MAX_PARMS && p[j] != NULL; ++j)
5780 {
5781 if (streq(p[j], "nopadding"))
5782 {
5784 }
5785 else if (streq(p[j], "pkcs1"))
5786 {
5788 }
5789 else if (streq(p[j], "pss"))
5790 {
5792 }
5793 else if (streq(p[j], "digest"))
5794 {
5796 }
5797 else
5798 {
5799 msg(msglevel, "Unknown management-external-key flag: %s", p[j]);
5800 }
5801 }
5802 /*
5803 * When no option is present, assume that only PKCS1
5804 * padding is supported
5805 */
5807 {
5809 }
5811 }
5812 else if (streq(p[0], "management-external-cert") && p[1] && !p[2])
5813 {
5817 }
5818 else if (streq(p[0], "management-client-auth") && !p[1])
5819 {
5822 }
5823 else if (streq(p[0], "management-log-cache") && p[1] && !p[2])
5824 {
5827 p[0], 1, INT_MAX, msglevel))
5828 {
5829 goto err;
5830 }
5831 }
5832#endif /* ifdef ENABLE_MANAGEMENT */
5833#ifdef ENABLE_PLUGIN
5834 else if (streq(p[0], "plugin") && p[1])
5835 {
5837 if (!options->plugin_list)
5838 {
5840 }
5842 {
5843 msg(msglevel, "plugin add failed: %s", p[1]);
5844 goto err;
5845 }
5846 }
5847#endif
5848 else if (streq(p[0], "mode") && p[1] && !p[2])
5849 {
5851 if (streq(p[1], "p2p"))
5852 {
5854 }
5855 else if (streq(p[1], "server"))
5856 {
5858 }
5859 else
5860 {
5861 msg(msglevel, "Bad --mode parameter: %s", p[1]);
5862 goto err;
5863 }
5864 }
5865 else if (streq(p[0], "dev") && p[1] && !p[2])
5866 {
5868 options->dev = p[1];
5869 }
5870 else if (streq(p[0], "dev-type") && p[1] && !p[2])
5871 {
5873 options->dev_type = p[1];
5874 }
5875#ifdef _WIN32
5876 else if (streq(p[0], "windows-driver") && p[1] && !p[2])
5877 {
5879 msg(M_WARN,
5880 "DEPRECATED OPTION: windows-driver: In OpenVPN 2.7, the default Windows driver is ovpn-dco. "
5881 "If incompatible options are used, OpenVPN will fall back to tap-windows6. Wintun support has been removed.");
5882 }
5883#endif
5884 else if (streq(p[0], "disable-dco"))
5885 {
5886 options->disable_dco = true;
5887 }
5888 else if (streq(p[0], "dev-node") && p[1] && !p[2])
5889 {
5891 options->dev_node = p[1];
5892 }
5893 else if (streq(p[0], "lladdr") && p[1] && !p[2])
5894 {
5896 if (mac_addr_safe(p[1])) /* MAC address only */
5897 {
5898 options->lladdr = p[1];
5899 }
5900 else
5901 {
5902 msg(msglevel, "lladdr parm '%s' must be a MAC address", p[1]);
5903 goto err;
5904 }
5905 }
5906 else if (streq(p[0], "topology") && p[1] && !p[2])
5907 {
5909 options->topology = parse_topology(p[1], msglevel);
5910 }
5911 else if (streq(p[0], "tun-ipv6") && !p[1])
5912 {
5913 if (!pull_mode)
5914 {
5915 msg(M_WARN,
5916 "Note: option tun-ipv6 is ignored because modern operating systems do not need special IPv6 tun handling anymore.");
5917 }
5918 }
5919#ifdef ENABLE_IPROUTE
5920 else if (streq(p[0], "iproute") && p[1] && !p[2])
5921 {
5923 iproute_path = p[1];
5924 }
5925#endif
5926 else if (streq(p[0], "ifconfig") && p[1] && p[2] && !p[3])
5927 {
5930 && ip_or_dns_addr_safe(p[2], options->allow_pull_fqdn)) /* FQDN -- may be DNS name */
5931 {
5932 options->ifconfig_local = p[1];
5934 }
5935 else
5936 {
5937 msg(msglevel, "ifconfig parms '%s' and '%s' must be valid addresses", p[1], p[2]);
5938 goto err;
5939 }
5940 }
5941 else if (streq(p[0], "ifconfig-ipv6") && p[1] && p[2] && !p[3])
5942 {
5943 unsigned int netbits;
5944
5946 if (get_ipv6_addr(p[1], NULL, &netbits, msglevel) && ipv6_addr_safe(p[2]))
5947 {
5949 {
5950 msg(msglevel, "ifconfig-ipv6: /netbits must be between 64 and 124, not '/%d'",
5951 netbits);
5952 goto err;
5953 }
5954
5956 options->ifconfig_ipv6_netbits = netbits;
5958 }
5959 else
5960 {
5961 msg(msglevel, "ifconfig-ipv6 parms '%s' and '%s' must be valid addresses", p[1], p[2]);
5962 goto err;
5963 }
5964 }
5965 else if (streq(p[0], "ifconfig-noexec") && !p[1])
5966 {
5968 options->ifconfig_noexec = true;
5969 }
5970 else if (streq(p[0], "ifconfig-nowarn") && !p[1])
5971 {
5973 options->ifconfig_nowarn = true;
5974 }
5975 else if (streq(p[0], "local") && p[1] && !p[4])
5976 {
5977 struct local_entry *e;
5978
5980
5982 ASSERT(e);
5983
5984 /* '*' is treated as 'ask the system to get some socket',
5985 * therefore force binding on a particular address only when
5986 * actually specified. */
5987 if (strcmp(p[1], "*") != 0)
5988 {
5989 e->local = p[1];
5990 }
5991
5992 if (p[2])
5993 {
5994 e->port = p[2];
5995 }
5996
5997 if (p[3])
5998 {
5999 e->proto = ascii2proto(p[3]);
6000 }
6001 }
6002 else if (streq(p[0], "remote-random") && !p[1])
6003 {
6005 options->remote_random = true;
6006 }
6007 else if (streq(p[0], "connection") && p[1] && !p[3])
6008 {
6010 if (is_inline)
6011 {
6012 struct options sub;
6013 struct connection_entry *e;
6014
6015 init_options(&sub);
6016 sub.ce = options->ce;
6017 read_config_string("[CONNECTION-OPTIONS]", &sub, p[1], msglevel, OPT_P_CONNECTION,
6018 option_types_found, es);
6019 if (!sub.ce.remote)
6020 {
6021 msg(msglevel,
6022 "Each 'connection' block must contain exactly one 'remote' directive");
6023 uninit_options(&sub);
6024 goto err;
6025 }
6026
6027 e = alloc_connection_entry(options, msglevel);
6028 if (!e)
6029 {
6030 uninit_options(&sub);
6031 goto err;
6032 }
6033 *e = sub.ce;
6034 gc_transfer(&options->gc, &sub.gc);
6035 uninit_options(&sub);
6036 }
6037 }
6038 else if (streq(p[0], "ignore-unknown-option") && p[1])
6039 {
6040 int i;
6041 int j;
6042 int numignored = 0;
6043 const char **ignore;
6044
6046 /* Find out how many options to be ignored */
6047 for (i = 1; p[i]; i++)
6048 {
6049 numignored++;
6050 }
6051
6052 /* add number of options already ignored */
6054 {
6055 numignored++;
6056 }
6057
6058 /* Allocate array */
6059 ALLOC_ARRAY_GC(ignore, const char *, numignored + 1, &options->gc);
6061 {
6062 ignore[i] = options->ignore_unknown_option[i];
6063 }
6064
6066
6067 for (j = 1; p[j]; j++)
6068 {
6069 /* Allow the user to specify ignore-unknown-option --opt too */
6070 if (p[j][0] == '-' && p[j][1] == '-')
6071 {
6072 options->ignore_unknown_option[i] = (p[j] + 2);
6073 }
6074 else
6075 {
6076 options->ignore_unknown_option[i] = p[j];
6077 }
6078 i++;
6079 }
6080
6081 options->ignore_unknown_option[i] = NULL;
6082 }
6083#if ENABLE_MANAGEMENT
6084 else if (streq(p[0], "http-proxy-override") && p[1] && p[2] && !p[4])
6085 {
6089 {
6090 goto err;
6091 }
6092 }
6093#endif
6094 else if (streq(p[0], "remote") && p[1] && !p[4])
6095 {
6096 struct remote_entry re;
6097 re.remote = re.remote_port = NULL;
6098 re.proto = -1;
6099 re.af = 0;
6100
6102 re.remote = p[1];
6103 if (p[2])
6104 {
6105 re.remote_port = p[2];
6106 if (p[3])
6107 {
6108 const int proto = ascii2proto(p[3]);
6109 const sa_family_t af = ascii2af(p[3]);
6110 if (proto < 0)
6111 {
6112 msg(msglevel, "remote: bad protocol associated with host %s: '%s'", p[1], p[3]);
6113 goto err;
6114 }
6115 re.proto = proto;
6116 re.af = af;
6117 }
6118 }
6119 if (permission_mask & OPT_P_GENERAL)
6120 {
6121 struct remote_entry *e = alloc_remote_entry(options, msglevel);
6122 if (!e)
6123 {
6124 goto err;
6125 }
6126 *e = re;
6127 }
6128 else if (permission_mask & OPT_P_CONNECTION)
6129 {
6131 }
6132 }
6133 else if (streq(p[0], "resolv-retry") && p[1] && !p[2])
6134 {
6136 if (streq(p[1], "infinite"))
6137 {
6139 }
6140 else
6141 {
6142 options->resolve_retry_seconds = positive_atoi(p[1], msglevel);
6143 }
6144 }
6145 else if ((streq(p[0], "preresolve") || streq(p[0], "ip-remote-hint")) && !p[2])
6146 {
6149 /* Note the ip-remote-hint and the argument p[1] are for
6150 * backward compatibility */
6151 if (p[1])
6152 {
6153 options->ip_remote_hint = p[1];
6154 }
6155 }
6156 else if (streq(p[0], "connect-retry") && p[1] && !p[3])
6157 {
6159 options->ce.connect_retry_seconds = positive_atoi(p[1], msglevel);
6160 /*
6161 * Limit the base value of retry wait interval to 16 bits to avoid
6162 * overflow when scaled up for exponential backoff
6163 */
6164 if (options->ce.connect_retry_seconds > 0xFFFF)
6165 {
6167 msg(M_WARN, "connect retry wait interval truncated to %d",
6169 }
6170
6171 if (p[2])
6172 {
6175 }
6176 }
6177 else if ((streq(p[0], "connect-timeout") || streq(p[0], "server-poll-timeout")) && p[1]
6178 && !p[2])
6179 {
6181 options->ce.connect_timeout = positive_atoi(p[1], msglevel);
6182 }
6183 else if (streq(p[0], "connect-retry-max") && p[1] && !p[2])
6184 {
6186 options->connect_retry_max = positive_atoi(p[1], msglevel);
6187 }
6188 else if (streq(p[0], "ipchange") && p[1])
6189 {
6191 if (!no_more_than_n_args(msglevel, p, 2, NM_QUOTE_HINT))
6192 {
6193 goto err;
6194 }
6196 string_substitute(p[1], ',', ' ', &options->gc), "ipchange", true);
6197 }
6198 else if (streq(p[0], "float") && !p[1])
6199 {
6201 options->ce.remote_float = true;
6202 }
6203#ifdef ENABLE_DEBUG
6204 else if (streq(p[0], "gremlin") && p[1] && !p[2])
6205 {
6207 options->gremlin = positive_atoi(p[1], msglevel);
6208 }
6209#endif
6210 else if (streq(p[0], "chroot") && p[1] && !p[2])
6211 {
6213 options->chroot_dir = p[1];
6214 }
6215 else if (streq(p[0], "cd") && p[1] && !p[2])
6216 {
6218 if (platform_chdir(p[1]))
6219 {
6220 msg(M_ERR, "cd to '%s' failed", p[1]);
6221 goto err;
6222 }
6223 options->cd_dir = p[1];
6224 }
6225#ifdef ENABLE_SELINUX
6226 else if (streq(p[0], "setcon") && p[1] && !p[2])
6227 {
6229 options->selinux_context = p[1];
6230 }
6231#endif
6232 else if (streq(p[0], "writepid") && p[1] && !p[2])
6233 {
6235 options->writepid = p[1];
6236 }
6237 else if (streq(p[0], "up") && p[1])
6238 {
6240 if (!no_more_than_n_args(msglevel, p, 2, NM_QUOTE_HINT))
6241 {
6242 goto err;
6243 }
6244 set_user_script(options, &options->up_script, p[1], "up", false);
6245 }
6246 else if (streq(p[0], "down") && p[1])
6247 {
6249 if (!no_more_than_n_args(msglevel, p, 2, NM_QUOTE_HINT))
6250 {
6251 goto err;
6252 }
6253 set_user_script(options, &options->down_script, p[1], "down", true);
6254 }
6255 else if (streq(p[0], "down-pre") && !p[1])
6256 {
6258 options->down_pre = true;
6259 }
6260 else if (streq(p[0], "up-delay") && !p[1])
6261 {
6263 options->up_delay = true;
6264 }
6265 else if (streq(p[0], "up-restart") && !p[1])
6266 {
6268 options->up_restart = true;
6269 }
6270 else if (streq(p[0], "syslog") && !p[2])
6271 {
6273 open_syslog(p[1], false);
6274 }
6275 else if (streq(p[0], "daemon") && !p[2])
6276 {
6277 bool didit = false;
6279 if (!options->daemon)
6280 {
6281 options->daemon = didit = true;
6282 open_syslog(p[1], false);
6283 }
6284 if (p[1])
6285 {
6286 if (!didit)
6287 {
6288 msg(M_WARN,
6289 "WARNING: Multiple --daemon directives specified, ignoring --daemon %s. (Note that initscripts sometimes add their own --daemon directive.)",
6290 p[1]);
6291 goto err;
6292 }
6293 }
6294 }
6295 else if (streq(p[0], "log") && p[1] && !p[2])
6296 {
6298 options->log = true;
6299 redirect_stdout_stderr(p[1], false);
6300 }
6301 else if (streq(p[0], "suppress-timestamps") && !p[1])
6302 {
6306 }
6307 else if (streq(p[0], "machine-readable-output") && !p[1])
6308 {
6312 }
6313 else if (streq(p[0], "log-append") && p[1] && !p[2])
6314 {
6316 options->log = true;
6317 redirect_stdout_stderr(p[1], true);
6318 }
6319 else if (streq(p[0], "mlock") && !p[1])
6320 {
6322 options->mlock = true;
6323 }
6324#if ENABLE_IP_PKTINFO
6325 else if (streq(p[0], "multihome") && !p[2])
6326 {
6329 if (p[1] && streq(p[1], "same-interface"))
6330 {
6332 }
6333 else if (p[1])
6334 {
6335 msg(msglevel, "Unknown parameter to --multihome: %s", p[1]);
6336 }
6337 }
6338#endif
6339 else if (streq(p[0], "verb") && p[1] && !p[2])
6340 {
6342 options->verbosity = positive_atoi(p[1], msglevel);
6344 {
6345 /* We pass this flag to the SSL library to avoid
6346 * mbed TLS always generating debug level logging */
6348 }
6349#if !defined(ENABLE_DEBUG) && !defined(ENABLE_SMALL)
6350 /* Warn when a debug verbosity is supplied when built without debug support */
6351 if (options->verbosity >= 7)
6352 {
6353 msg(M_WARN,
6354 "NOTE: debug verbosity (--verb %d) is enabled but this build lacks debug support.",
6356 }
6357#endif
6358 }
6359 else if (streq(p[0], "mute") && p[1] && !p[2])
6360 {
6362 options->mute = positive_atoi(p[1], msglevel);
6363 }
6364 else if (streq(p[0], "errors-to-stderr") && !p[1])
6365 {
6368 }
6369 else if (streq(p[0], "status") && p[1] && !p[3])
6370 {
6372 options->status_file = p[1];
6373 if (p[2])
6374 {
6376 }
6377 }
6378 else if (streq(p[0], "status-version") && p[1] && !p[2])
6379 {
6381 if (!atoi_constrained(p[1], &options->status_file_version, p[0], 1, 3, msglevel))
6382 {
6383 goto err;
6384 }
6385 }
6386 else if (streq(p[0], "remap-usr1") && p[1] && !p[2])
6387 {
6389 if (streq(p[1], "SIGHUP"))
6390 {
6392 }
6393 else if (streq(p[1], "SIGTERM"))
6394 {
6396 }
6397 else
6398 {
6399 msg(msglevel, "--remap-usr1 parm must be 'SIGHUP' or 'SIGTERM'");
6400 goto err;
6401 }
6402 }
6403 else if ((streq(p[0], "link-mtu") || streq(p[0], "udp-mtu")) && p[1] && !p[2])
6404 {
6406 options->ce.link_mtu = positive_atoi(p[1], msglevel);
6407 options->ce.link_mtu_defined = true;
6408 }
6409 else if (streq(p[0], "tun-mtu") && p[1] && !p[3])
6410 {
6412 options->ce.tun_mtu = positive_atoi(p[1], msglevel);
6413 options->ce.tun_mtu_defined = true;
6414 if (p[2])
6415 {
6416 options->ce.occ_mtu = positive_atoi(p[2], msglevel);
6417 }
6418 else
6419 {
6420 options->ce.occ_mtu = 0;
6421 }
6422 }
6423 else if (streq(p[0], "tun-mtu-max") && p[1] && !p[2])
6424 {
6426 atoi_constrained(p[1], &options->ce.tun_mtu_max, p[0], TUN_MTU_MAX_MIN, 65536, msglevel);
6427 }
6428 else if (streq(p[0], "tun-mtu-extra") && p[1] && !p[2])
6429 {
6431 if (atoi_constrained(p[1], &options->ce.tun_mtu_extra, p[0], 0, 65536, msglevel))
6432 {
6434 }
6435 }
6436 else if (streq(p[0], "max-packet-size") && p[1] && !p[2])
6437 {
6439 int maxmtu = positive_atoi(p[1], msglevel);
6441
6442 if (maxmtu < TLS_CHANNEL_MTU_MIN || maxmtu > TLS_CHANNEL_BUF_SIZE)
6443 {
6444 msg(M_WARN,
6445 "Note: max-packet-size value outside of allowed "
6446 "control channel packet size (%d to %d), will use %d "
6447 "instead.",
6449 }
6450
6451 /* also set mssfix maxmtu mtu */
6452 options->ce.mssfix = maxmtu;
6453 options->ce.mssfix_default = false;
6454 options->ce.mssfix_encap = true;
6455 }
6456#ifdef ENABLE_FRAGMENT
6457 else if (streq(p[0], "mtu-dynamic"))
6458 {
6460 msg(msglevel, "--mtu-dynamic has been replaced by --fragment");
6461 goto err;
6462 }
6463 else if (streq(p[0], "fragment") && p[1] && !p[3])
6464 {
6466 if (!atoi_constrained(p[1], &options->ce.fragment, p[0], 68, INT_MAX, msglevel))
6467 {
6468 goto err;
6469 }
6470
6471 if (p[2] && streq(p[2], "mtu"))
6472 {
6473 options->ce.fragment_encap = true;
6474 }
6475 else if (p[2])
6476 {
6477 msg(msglevel, "Unknown parameter to --fragment: %s", p[2]);
6478 }
6479 }
6480#endif /* ifdef ENABLE_FRAGMENT */
6481 else if (streq(p[0], "mtu-disc") && p[1] && !p[2])
6482 {
6485 }
6486 else if (streq(p[0], "mtu-test") && !p[1])
6487 {
6489 options->mtu_test = true;
6490 }
6491 else if (streq(p[0], "nice") && p[1] && !p[2])
6492 {
6494 options->nice = atoi_warn(p[1], msglevel);
6495 }
6496 else if (streq(p[0], "rcvbuf") && p[1] && !p[2])
6497 {
6499 options->rcvbuf = positive_atoi(p[1], msglevel);
6500 }
6501 else if (streq(p[0], "sndbuf") && p[1] && !p[2])
6502 {
6504 options->sndbuf = positive_atoi(p[1], msglevel);
6505 }
6506 else if (streq(p[0], "mark") && p[1] && !p[2])
6507 {
6508#if defined(TARGET_LINUX)
6510 options->mark = atoi_warn(p[1], msglevel);
6511#endif
6512 }
6513 else if (streq(p[0], "socket-flags"))
6514 {
6515 int j;
6517 for (j = 1; j < MAX_PARMS && p[j]; ++j)
6518 {
6519 if (streq(p[j], "TCP_NODELAY"))
6520 {
6522 }
6523 else
6524 {
6525 msg(msglevel, "unknown socket flag: %s", p[j]);
6526 }
6527 }
6528 }
6529#ifdef TARGET_LINUX
6530 else if (streq(p[0], "bind-dev") && p[1])
6531 {
6533 options->bind_dev = p[1];
6534 }
6535#endif
6536 else if (streq(p[0], "txqueuelen") && p[1] && !p[2])
6537 {
6539#ifdef TARGET_LINUX
6540 options->tuntap_options.txqueuelen = positive_atoi(p[1], msglevel);
6541#else
6542 msg(msglevel, "--txqueuelen not supported on this OS");
6543 goto err;
6544#endif
6545 }
6546 else if (streq(p[0], "shaper") && p[1] && !p[2])
6547 {
6549 if (!atoi_constrained(p[1], &options->shaper, p[0], SHAPER_MIN, SHAPER_MAX, msglevel))
6550 {
6551 goto err;
6552 }
6553 }
6554 else if (streq(p[0], "port") && p[1] && !p[2])
6555 {
6558 }
6559 else if (streq(p[0], "lport") && p[1] && !p[2])
6560 {
6562
6563 /* only trigger bind() if port is not 0 (or --local is used) */
6564 if (!streq(p[1], "0"))
6565 {
6567 }
6568 options->ce.local_port = p[1];
6569 }
6570 else if (streq(p[0], "rport") && p[1] && !p[2])
6571 {
6573 options->ce.remote_port = p[1];
6574 }
6575 else if (streq(p[0], "bind") && !p[2])
6576 {
6578 options->ce.bind_defined = true;
6579 if (p[1] && streq(p[1], "ipv6only"))
6580 {
6581 options->ce.bind_ipv6_only = true;
6582 }
6583 }
6584 else if (streq(p[0], "nobind") && !p[1])
6585 {
6587 options->ce.bind_local = false;
6588 }
6589 else if (streq(p[0], "fast-io") && !p[1])
6590 {
6592 msg(M_WARN, "DEPRECATED OPTION: --fast-io option ignored.");
6593 }
6594 else if (streq(p[0], "inactive") && p[1] && !p[3])
6595 {
6597 options->inactivity_timeout = positive_atoi(p[1], msglevel);
6598 if (p[2])
6599 {
6600 positive_atoll(p[2], &options->inactivity_minimum_bytes, p[0], msglevel);
6601 if (options->inactivity_minimum_bytes > INT_MAX)
6602 {
6603 msg(M_WARN,
6604 "WARNING: '--inactive' with a 'bytes' value"
6605 " >2 Gbyte was silently ignored in older versions. If "
6606 " your VPN exits unexpectedly with 'Inactivity timeout'"
6607 " in %d seconds, revisit this value.",
6609 }
6610 }
6611 }
6612 else if (streq(p[0], "session-timeout") && p[1] && !p[2])
6613 {
6615 options->session_timeout = positive_atoi(p[1], msglevel);
6616 }
6617 else if (streq(p[0], "proto") && p[1] && !p[2])
6618 {
6619 int proto;
6622 proto = ascii2proto(p[1]);
6623 af = ascii2af(p[1]);
6624 if (proto < 0)
6625 {
6626 msg(msglevel, "Bad protocol: '%s'. Allowed protocols with --proto option: %s", p[1],
6628 goto err;
6629 }
6630 options->ce.proto = proto;
6631 options->ce.af = af;
6632 }
6633 else if (streq(p[0], "proto-force") && p[1] && !p[2])
6634 {
6635 int proto_force;
6637 proto_force = ascii2proto(p[1]);
6638 if (proto_force < 0)
6639 {
6640 msg(msglevel, "Bad --proto-force protocol: '%s'", p[1]);
6641 goto err;
6642 }
6643 options->proto_force = proto_force;
6644 }
6645 else if (streq(p[0], "http-proxy") && p[1] && !p[5])
6646 {
6647 struct http_proxy_options *ho;
6648
6650
6651 {
6652 if (!p[2])
6653 {
6654 msg(msglevel, "http-proxy port number not defined");
6655 goto err;
6656 }
6657
6659
6660 ho->server = p[1];
6661 ho->port = p[2];
6662 }
6663
6664 if (p[3])
6665 {
6666 /* auto -- try to figure out proxy addr, port, and type automatically */
6667 /* auto-nct -- disable proxy auth cleartext protocols (i.e. basic auth) */
6668 if (streq(p[3], "auto"))
6669 {
6670 ho->auth_retry = PAR_ALL;
6671 }
6672 else if (streq(p[3], "auto-nct"))
6673 {
6674 ho->auth_retry = PAR_NCT;
6675 }
6676 else
6677 {
6678 ho->auth_method_string = "basic";
6679 ho->auth_file = p[3];
6680
6681 if (p[4])
6682 {
6683 ho->auth_method_string = p[4];
6684 }
6685 }
6686 }
6687 else
6688 {
6689 ho->auth_method_string = "none";
6690 }
6691 }
6692 else if (streq(p[0], "http-proxy-user-pass") && p[1])
6693 {
6694 struct http_proxy_options *ho;
6697 ho->auth_file_up = p[1];
6698 ho->inline_creds = is_inline;
6699 }
6700 else if (streq(p[0], "http-proxy-retry") || streq(p[0], "socks-proxy-retry") || streq(p[0], "http-proxy-timeout"))
6701 {
6703 msg(M_WARN, "DEPRECATED OPTION: %s option ignored.", p[0]);
6704 }
6705 else if (streq(p[0], "http-proxy-option") && p[1] && !p[4])
6706 {
6707 struct http_proxy_options *ho;
6708
6711
6712 if (streq(p[1], "VERSION") && p[2] && !p[3])
6713 {
6714 ho->http_version = p[2];
6715 }
6716 else if (streq(p[1], "AGENT") && p[2] && !p[3])
6717 {
6718 ho->user_agent = p[2];
6719 }
6720 else if ((streq(p[1], "EXT1") || streq(p[1], "EXT2") || streq(p[1], "CUSTOM-HEADER"))
6721 && p[2])
6722 {
6723 /* In the wild patched versions use both EXT1/2 and CUSTOM-HEADER
6724 * with either two argument or one */
6725
6726 struct http_custom_header *custom_header = NULL;
6727 int i;
6728 /* Find the first free header */
6729 for (i = 0; i < MAX_CUSTOM_HTTP_HEADER; i++)
6730 {
6731 if (!ho->custom_headers[i].name)
6732 {
6733 custom_header = &ho->custom_headers[i];
6734 break;
6735 }
6736 }
6737 if (!custom_header)
6738 {
6739 msg(msglevel, "Cannot use more than %d http-proxy-option CUSTOM-HEADER : '%s'",
6741 }
6742 else
6743 {
6744 /* We will save p[2] and p[3], the proxy code will detect if
6745 * p[3] is NULL */
6746 custom_header->name = p[2];
6747 custom_header->content = p[3];
6748 }
6749 }
6750 else
6751 {
6752 msg(msglevel, "Bad http-proxy-option or missing or extra parameter: '%s'", p[1]);
6753 }
6754 }
6755 else if (streq(p[0], "socks-proxy") && p[1] && !p[4])
6756 {
6758
6759 if (p[2])
6760 {
6761 options->ce.socks_proxy_port = p[2];
6762 }
6763 else
6764 {
6765 options->ce.socks_proxy_port = "1080";
6766 }
6768 options->ce.socks_proxy_authfile = p[3]; /* might be NULL */
6769 }
6770 else if (streq(p[0], "keepalive") && p[1] && p[2] && !p[3])
6771 {
6773 options->keepalive_ping = atoi_warn(p[1], msglevel);
6774 options->keepalive_timeout = atoi_warn(p[2], msglevel);
6775 }
6776 else if (streq(p[0], "ping") && p[1] && !p[2])
6777 {
6779 options->ping_send_timeout = positive_atoi(p[1], msglevel);
6780 }
6781 else if (streq(p[0], "ping-exit") && p[1] && !p[2])
6782 {
6784 options->ping_rec_timeout = positive_atoi(p[1], msglevel);
6786 }
6787 else if (streq(p[0], "ping-restart") && p[1] && !p[2])
6788 {
6790 options->ping_rec_timeout = positive_atoi(p[1], msglevel);
6792 }
6793 else if (streq(p[0], "ping-timer-rem") && !p[1])
6794 {
6796 options->ping_timer_remote = true;
6797 }
6798 else if (streq(p[0], "explicit-exit-notify") && !p[2])
6799 {
6801 if (p[1])
6802 {
6804 }
6805 else
6806 {
6808 }
6809 }
6810 else if (streq(p[0], "persist-tun") && !p[1])
6811 {
6813 options->persist_tun = true;
6814 }
6815 else if (streq(p[0], "persist-key") && !p[1])
6816 {
6818 msg(M_WARN, "DEPRECATED OPTION: --persist-key option ignored. "
6819 "Keys are now always persisted across restarts. ");
6820 }
6821 else if (streq(p[0], "persist-local-ip") && !p[1])
6822 {
6824 options->persist_local_ip = true;
6825 }
6826 else if (streq(p[0], "persist-remote-ip") && !p[1])
6827 {
6829 options->persist_remote_ip = true;
6830 }
6831 else if (streq(p[0], "client-nat") && p[1] && p[2] && p[3] && p[4] && !p[5])
6832 {
6835 add_client_nat_to_option_list(options->client_nat, p[1], p[2], p[3], p[4], msglevel);
6836 }
6837 else if (streq(p[0], "route-table") && p[1] && !p[2])
6838 {
6839#ifndef ENABLE_SITNL
6840 msg(M_WARN, "NOTE: --route-table is supported only on Linux when SITNL is built-in");
6841#endif
6843 options->route_default_table_id = positive_atoi(p[1], msglevel);
6844 }
6845 else if (streq(p[0], "route") && p[1] && !p[5])
6846 {
6848 if (!check_route_option(options, p, msglevel, pull_mode))
6849 {
6850 goto err;
6851 }
6852 add_route_to_option_list(options->routes, p[1], p[2], p[3], p[4],
6854 }
6855 else if (streq(p[0], "route-ipv6") && p[1] && !p[4])
6856 {
6858 if (!check_route6_option(options, p, msglevel, pull_mode))
6859 {
6860 goto err;
6861 }
6864 }
6865 else if (streq(p[0], "max-routes") && !p[2])
6866 {
6867 msg(M_WARN, "DEPRECATED OPTION: --max-routes option ignored.");
6868 }
6869 else if (streq(p[0], "route-gateway") && p[1] && !p[2])
6870 {
6872 if (streq(p[1], "dhcp"))
6873 {
6875 }
6876 else
6877 {
6879 || is_special_addr(p[1])) /* FQDN -- may be DNS name */
6880 {
6882 }
6883 else
6884 {
6885 msg(msglevel, "route-gateway parm '%s' must be a valid address", p[1]);
6886 goto err;
6887 }
6888 }
6889 }
6890 else if (streq(p[0], "route-ipv6-gateway") && p[1] && !p[2])
6891 {
6892 if (ipv6_addr_safe(p[1]))
6893 {
6895 }
6896 else
6897 {
6898 msg(msglevel, "route-ipv6-gateway parm '%s' must be a valid address", p[1]);
6899 goto err;
6900 }
6901 }
6902 else if (streq(p[0], "route-metric") && p[1] && !p[2])
6903 {
6905 options->route_default_metric = positive_atoi(p[1], msglevel);
6906 }
6907 else if (streq(p[0], "route-delay") && !p[3])
6908 {
6911 if (p[1])
6912 {
6913 options->route_delay = positive_atoi(p[1], msglevel);
6914 if (p[2])
6915 {
6916 options->route_delay_window = positive_atoi(p[2], msglevel);
6917 }
6918 }
6919 else
6920 {
6921 options->route_delay = 0;
6922 }
6923 }
6924 else if (streq(p[0], "route-up") && p[1])
6925 {
6927 if (!no_more_than_n_args(msglevel, p, 2, NM_QUOTE_HINT))
6928 {
6929 goto err;
6930 }
6931 set_user_script(options, &options->route_script, p[1], "route-up", false);
6932 }
6933 else if (streq(p[0], "route-pre-down") && p[1])
6934 {
6936 if (!no_more_than_n_args(msglevel, p, 2, NM_QUOTE_HINT))
6937 {
6938 goto err;
6939 }
6940 set_user_script(options, &options->route_predown_script, p[1], "route-pre-down", true);
6941 }
6942 else if (streq(p[0], "route-noexec") && !p[1])
6943 {
6945 options->route_noexec = true;
6946 }
6947 else if (streq(p[0], "route-nopull") && !p[1])
6948 {
6950 options->route_nopull = true;
6951 }
6952 else if (streq(p[0], "pull-filter") && p[1] && p[2] && !p[3])
6953 {
6954 struct pull_filter *f;
6957
6958 if (strcmp("accept", p[1]) == 0)
6959 {
6960 f->type = PUF_TYPE_ACCEPT;
6961 }
6962 else if (strcmp("ignore", p[1]) == 0)
6963 {
6964 f->type = PUF_TYPE_IGNORE;
6965 }
6966 else if (strcmp("reject", p[1]) == 0)
6967 {
6968 f->type = PUF_TYPE_REJECT;
6969 }
6970 else
6971 {
6972 msg(msglevel, "Unknown --pull-filter type: %s", p[1]);
6973 goto err;
6974 }
6975 f->pattern = p[2];
6976 f->size = strlen(p[2]);
6977 }
6978 else if (streq(p[0], "allow-pull-fqdn") && !p[1])
6979 {
6981 options->allow_pull_fqdn = true;
6982 }
6983 else if (streq(p[0], "redirect-gateway") || streq(p[0], "redirect-private"))
6984 {
6985 int j;
6988
6989 if (options->routes->flags & RG_ENABLE)
6990 {
6991 msg(M_WARN, "WARNING: You have specified redirect-gateway and "
6992 "redirect-private at the same time (or the same option "
6993 "multiple times). This is not well supported and may lead to "
6994 "unexpected results");
6995 }
6996
6998
6999 if (streq(p[0], "redirect-gateway"))
7000 {
7002 }
7003 for (j = 1; j < MAX_PARMS && p[j] != NULL; ++j)
7004 {
7005 if (streq(p[j], "local"))
7006 {
7008 }
7009 else if (streq(p[j], "autolocal"))
7010 {
7012 }
7013 else if (streq(p[j], "def1"))
7014 {
7016 }
7017 else if (streq(p[j], "bypass-dhcp"))
7018 {
7020 }
7021 else if (streq(p[j], "bypass-dns"))
7022 {
7024 }
7025 else if (streq(p[j], "block-local"))
7026 {
7028 }
7029 else if (streq(p[j], "ipv6"))
7030 {
7033 }
7034 else if (streq(p[j], "!ipv4"))
7035 {
7037 }
7038 else
7039 {
7040 msg(msglevel, "unknown --%s flag: %s", p[0], p[j]);
7041 goto err;
7042 }
7043 }
7045 {
7046 setenv_int(es, "route_redirect_gateway_ipv4",
7047 options->routes->flags & RG_BLOCK_LOCAL ? 2 : 1);
7048 }
7050 {
7051 setenv_int(es, "route_redirect_gateway_ipv6",
7052 options->routes->flags & RG_BLOCK_LOCAL ? 2 : 1);
7053 }
7054#ifdef _WIN32
7055 /* we need this here to handle pushed --redirect-gateway */
7057#endif
7058 }
7059 else if (streq(p[0], "block-ipv6") && !p[1])
7060 {
7062 options->block_ipv6 = true;
7063 }
7064 else if (streq(p[0], "remote-random-hostname") && !p[1])
7065 {
7068 }
7069 else if (streq(p[0], "setenv") && p[1] && !p[3])
7070 {
7072 if (streq(p[1], "REMOTE_RANDOM_HOSTNAME") && !p[2])
7073 {
7075 }
7076 else if (streq(p[1], "GENERIC_CONFIG"))
7077 {
7078 msg(msglevel, "this is a generic configuration and cannot directly be used");
7079 goto err;
7080 }
7081 else if (streq(p[1], "PUSH_PEER_INFO") && !p[2])
7082 {
7083 options->push_peer_info = true;
7084 }
7085 else if (streq(p[1], "SERVER_POLL_TIMEOUT") && p[2])
7086 {
7087 options->ce.connect_timeout = positive_atoi(p[2], msglevel);
7088 }
7089 else
7090 {
7091 if (streq(p[1], "FORWARD_COMPATIBLE") && p[2] && streq(p[2], "1"))
7092 {
7094 msglevel_fc = msglevel_forward_compatible(options, msglevel);
7095 }
7096 setenv_str(es, p[1], p[2] ? p[2] : "");
7097 }
7098 }
7099 else if (streq(p[0], "compat-mode") && p[1] && !p[3])
7100 {
7101 unsigned int major, minor, patch;
7102 if (!(sscanf(p[1], "%u.%u.%u", &major, &minor, &patch) == 3))
7103 {
7104 msg(msglevel, "cannot parse version number for --compat-mode: %s", p[1]);
7105 goto err;
7106 }
7107
7108 options->backwards_compatible = major * 10000 + minor * 100 + patch;
7109 }
7110 else if (streq(p[0], "setenv-safe") && p[1] && !p[3])
7111 {
7113 setenv_str_safe(es, p[1], p[2] ? p[2] : "");
7114 }
7115 else if (streq(p[0], "script-security") && p[1] && !p[2])
7116 {
7118 int security;
7119 if (atoi_constrained(p[1], &security, p[0], SSEC_NONE, SSEC_PW_ENV, msglevel))
7120 {
7121 script_security_set(security);
7122 }
7123 }
7124 else if (streq(p[0], "mssfix") && !p[3])
7125 {
7127 if (p[1])
7128 {
7129 int mssfix;
7130 if (!atoi_constrained(p[1], &mssfix, p[0], 0, UINT16_MAX, msglevel))
7131 {
7132 goto err;
7133 }
7134 if (mssfix != 0 && mssfix < TLS_CHANNEL_MTU_MIN)
7135 {
7136 msg(msglevel, "mssfix needs to be >= %d, not %d", TLS_CHANNEL_MTU_MIN, mssfix);
7137 goto err;
7138 }
7139
7140 /* value specified, assume encapsulation is not
7141 * included unless "mtu" follows later */
7142 options->ce.mssfix = mssfix;
7143 options->ce.mssfix_encap = false;
7144 options->ce.mssfix_default = false;
7145 }
7146 else
7147 {
7148 /* Set MTU to default values */
7149 options->ce.mssfix_default = true;
7150 options->ce.mssfix_encap = true;
7151 options->ce.mssfix_fixed = false;
7152 }
7153
7154 if (p[2] && streq(p[2], "mtu"))
7155 {
7156 options->ce.mssfix_encap = true;
7157 }
7158 else if (p[2] && streq(p[2], "fixed"))
7159 {
7160 options->ce.mssfix_fixed = true;
7161 }
7162 else if (p[2])
7163 {
7164 msg(msglevel, "Unknown parameter to --mssfix: %s", p[2]);
7165 }
7166 }
7167 else if (streq(p[0], "disable-occ") && !p[1])
7168 {
7170 options->occ = false;
7171 }
7172 else if (streq(p[0], "server") && p[1] && p[2] && !p[4])
7173 {
7174 const int lev = M_WARN;
7175 bool error = false;
7176 in_addr_t network, netmask;
7177
7179 network = get_ip_addr(p[1], lev, &error);
7180 netmask = get_ip_addr(p[2], lev, &error);
7181 if (error || !network || !netmask)
7182 {
7183 msg(msglevel, "error parsing --server parameters");
7184 goto err;
7185 }
7186 options->server_defined = true;
7187 options->server_network = network;
7188 options->server_netmask = netmask;
7189
7190 if (p[3])
7191 {
7192 if (streq(p[3], "nopool"))
7193 {
7195 }
7196 else
7197 {
7198 msg(msglevel, "error parsing --server: %s is not a recognized flag", p[3]);
7199 goto err;
7200 }
7201 }
7202 }
7203 else if (streq(p[0], "server-ipv6") && p[1] && !p[2])
7204 {
7205 const int lev = M_WARN;
7206 struct in6_addr network;
7207 unsigned int netbits = 0;
7208
7210 if (!get_ipv6_addr(p[1], &network, &netbits, lev))
7211 {
7212 msg(msglevel, "error parsing --server-ipv6 parameter");
7213 goto err;
7214 }
7215 if (netbits < 64 || netbits > 124)
7216 {
7217 msg(msglevel, "--server-ipv6 settings: network must be between /64 and /124 (not /%d)",
7218 netbits);
7219
7220 goto err;
7221 }
7223 options->server_network_ipv6 = network;
7224 options->server_netbits_ipv6 = netbits;
7225 }
7226 else if (streq(p[0], "server-bridge") && p[1] && p[2] && p[3] && p[4] && !p[5])
7227 {
7228 const int lev = M_WARN;
7229 bool error = false;
7230 in_addr_t ip, netmask, pool_start, pool_end;
7231
7233 ip = get_ip_addr(p[1], lev, &error);
7234 netmask = get_ip_addr(p[2], lev, &error);
7235 pool_start = get_ip_addr(p[3], lev, &error);
7236 pool_end = get_ip_addr(p[4], lev, &error);
7237 if (error || !ip || !netmask || !pool_start || !pool_end)
7238 {
7239 msg(msglevel, "error parsing --server-bridge parameters");
7240 goto err;
7241 }
7244 options->server_bridge_netmask = netmask;
7245 options->server_bridge_pool_start = pool_start;
7246 options->server_bridge_pool_end = pool_end;
7247 }
7248 else if (streq(p[0], "server-bridge") && p[1] && streq(p[1], "nogw") && !p[2])
7249 {
7253 }
7254 else if (streq(p[0], "server-bridge") && !p[1])
7255 {
7258 }
7259 else if (streq(p[0], "push") && p[1] && !p[2])
7260 {
7262 push_options(options, &p[1], msglevel, &options->gc);
7263 }
7264 else if (streq(p[0], "push-reset") && !p[1])
7265 {
7268 }
7269 else if (streq(p[0], "push-remove") && p[1] && !p[2])
7270 {
7272 msg(D_PUSH, "PUSH_REMOVE '%s'", p[1]);
7274 }
7275 else if (streq(p[0], "ifconfig-pool") && p[1] && p[2] && !p[4])
7276 {
7277 const int lev = M_WARN;
7278 bool error = false;
7279 in_addr_t start, end, netmask = 0;
7280
7282 start = get_ip_addr(p[1], lev, &error);
7283 end = get_ip_addr(p[2], lev, &error);
7284 if (p[3])
7285 {
7286 netmask = get_ip_addr(p[3], lev, &error);
7287 }
7288 if (error)
7289 {
7290 msg(msglevel, "error parsing --ifconfig-pool parameters");
7291 goto err;
7292 }
7293 if (!ifconfig_pool_verify_range(msglevel, start, end))
7294 {
7295 goto err;
7296 }
7297
7301 if (netmask)
7302 {
7303 options->ifconfig_pool_netmask = netmask;
7304 }
7305 }
7306 else if (streq(p[0], "ifconfig-pool-persist") && p[1] && !p[3])
7307 {
7310 if (p[2])
7311 {
7313 }
7314 }
7315 else if (streq(p[0], "ifconfig-ipv6-pool") && p[1] && !p[2])
7316 {
7317 const int lev = M_WARN;
7318 struct in6_addr network;
7319 unsigned int netbits = 0;
7320
7322 if (!get_ipv6_addr(p[1], &network, &netbits, lev))
7323 {
7324 msg(msglevel, "error parsing --ifconfig-ipv6-pool parameters");
7325 goto err;
7326 }
7327 if (netbits < 64 || netbits > 124)
7328 {
7329 msg(msglevel,
7330 "--ifconfig-ipv6-pool settings: network must be between /64 and /124 (not /%d)",
7331 netbits);
7332 goto err;
7333 }
7334
7338 }
7339 else if (streq(p[0], "hash-size") && p[1] && p[2] && !p[3])
7340 {
7341 int real, virtual;
7342
7344 if (!atoi_constrained(p[1], &real, "hash-size real", 1, INT_MAX, msglevel)
7345 || !atoi_constrained(p[2], &virtual, "hash-size virtual", 1, INT_MAX, msglevel))
7346 {
7347 goto err;
7348 }
7349 options->real_hash_size = (uint32_t)real;
7350 options->virtual_hash_size = (uint32_t)virtual;
7351 }
7352 else if (streq(p[0], "connect-freq") && p[1] && p[2] && !p[3])
7353 {
7354 int cf_max, cf_per;
7355
7357 if (!atoi_constrained(p[1], &cf_max, "connect-freq n", 1, INT_MAX, msglevel)
7358 || !atoi_constrained(p[2], &cf_per, "connect-freq seconds", 1, INT_MAX, msglevel))
7359 {
7360 goto err;
7361 }
7362 options->cf_max = cf_max;
7363 options->cf_per = cf_per;
7364 }
7365 else if (streq(p[0], "connect-freq-initial") && p[1] && p[2] && !p[3])
7366 {
7367 int cf_max, cf_per;
7368
7370 if (!atoi_constrained(p[1], &cf_max, "connect-freq-initial n", 1, INT_MAX, msglevel)
7371 || !atoi_constrained(p[2], &cf_per, "connect-freq-initial seconds", 1, INT_MAX, msglevel))
7372 {
7373 goto err;
7374 }
7375 options->cf_initial_max = cf_max;
7376 options->cf_initial_per = cf_per;
7377 }
7378 else if (streq(p[0], "max-clients") && p[1] && !p[2])
7379 {
7381 if (!atoi_constrained(p[1], &options->max_clients, p[0], 1, MAX_PEER_ID, msglevel))
7382 {
7383 goto err;
7384 }
7385 }
7386 else if (streq(p[0], "max-routes-per-client") && p[1] && !p[2])
7387 {
7389 atoi_constrained(p[1], &options->max_routes_per_client, p[0], 1, INT_MAX, msglevel);
7390 }
7391 else if (streq(p[0], "client-cert-not-required") && !p[1])
7392 {
7394 msg(M_FATAL,
7395 "REMOVED OPTION: --client-cert-not-required, use '--verify-client-cert none' instead");
7396 }
7397 else if (streq(p[0], "verify-client-cert") && !p[2])
7398 {
7400
7401 /* Reset any existing flags */
7402 options->ssl_flags &= ~SSLF_CLIENT_CERT_OPTIONAL;
7403 options->ssl_flags &= ~SSLF_CLIENT_CERT_NOT_REQUIRED;
7404 if (p[1])
7405 {
7406 if (streq(p[1], "none"))
7407 {
7409 }
7410 else if (streq(p[1], "optional"))
7411 {
7413 }
7414 else if (!streq(p[1], "require"))
7415 {
7416 msg(msglevel,
7417 "parameter to --verify-client-cert must be 'none', 'optional' or 'require'");
7418 goto err;
7419 }
7420 }
7421 }
7422 else if (streq(p[0], "username-as-common-name") && !p[1])
7423 {
7426 }
7427 else if (streq(p[0], "auth-user-pass-optional") && !p[1])
7428 {
7431 }
7432 else if (streq(p[0], "opt-verify") && !p[1])
7433 {
7435 msg(M_INFO, "DEPRECATED OPTION: --opt-verify was removed in OpenVPN 2.7.");
7436 }
7437 else if (streq(p[0], "auth-user-pass-verify") && p[1])
7438 {
7440 if (!no_more_than_n_args(msglevel, p, 3, NM_QUOTE_HINT))
7441 {
7442 goto err;
7443 }
7444 if (p[2])
7445 {
7446 if (streq(p[2], "via-env"))
7447 {
7449 }
7450 else if (streq(p[2], "via-file"))
7451 {
7453 }
7454 else
7455 {
7456 msg(msglevel,
7457 "second parm to --auth-user-pass-verify must be 'via-env' or 'via-file'");
7458 goto err;
7459 }
7460 }
7461 else
7462 {
7463 msg(msglevel,
7464 "--auth-user-pass-verify requires a second parameter ('via-env' or 'via-file')");
7465 goto err;
7466 }
7468 "auth-user-pass-verify", true);
7469 }
7470 else if (streq(p[0], "auth-gen-token"))
7471 {
7474 options->auth_token_lifetime = p[1] ? positive_atoi(p[1], msglevel) : 0;
7475
7476 for (int i = 2; i < MAX_PARMS && p[i] != NULL; i++)
7477 {
7478 /* the second parameter can be the renewal time */
7479 if (i == 2 && valid_integer(p[i], true))
7480 {
7481 options->auth_token_renewal = positive_atoi(p[i], msglevel);
7482 }
7483 else if (streq(p[i], "external-auth"))
7484 {
7486 }
7487 else
7488 {
7489 msg(msglevel, "Invalid argument to auth-gen-token: %s (%d)", p[i], i);
7490 }
7491 }
7492 }
7493 else if (streq(p[0], "auth-gen-token-secret") && p[1] && !p[2])
7494 {
7498 }
7499 else if (streq(p[0], "client-connect") && p[1])
7500 {
7502 if (!no_more_than_n_args(msglevel, p, 2, NM_QUOTE_HINT))
7503 {
7504 goto err;
7505 }
7506 set_user_script(options, &options->client_connect_script, p[1], "client-connect", true);
7507 }
7508 else if (streq(p[0], "client-crresponse") && p[1])
7509 {
7511 if (!no_more_than_n_args(msglevel, p, 2, NM_QUOTE_HINT))
7512 {
7513 goto err;
7514 }
7515 set_user_script(options, &options->client_crresponse_script, p[1], "client-crresponse",
7516 true);
7517 }
7518 else if (streq(p[0], "client-disconnect") && p[1])
7519 {
7521 if (!no_more_than_n_args(msglevel, p, 2, NM_QUOTE_HINT))
7522 {
7523 goto err;
7524 }
7525 set_user_script(options, &options->client_disconnect_script, p[1], "client-disconnect",
7526 true);
7527 }
7528 else if (streq(p[0], "learn-address") && p[1])
7529 {
7531 if (!no_more_than_n_args(msglevel, p, 2, NM_QUOTE_HINT))
7532 {
7533 goto err;
7534 }
7535 set_user_script(options, &options->learn_address_script, p[1], "learn-address", true);
7536 }
7537 else if (streq(p[0], "tmp-dir") && p[1] && !p[2])
7538 {
7540 options->tmp_dir = p[1];
7541 }
7542 else if (streq(p[0], "client-config-dir") && p[1] && !p[2])
7543 {
7545 options->client_config_dir = p[1];
7546 }
7547 else if (streq(p[0], "ccd-exclusive") && !p[1])
7548 {
7550 options->ccd_exclusive = true;
7551 }
7552 else if (streq(p[0], "bcast-buffers") && p[1] && !p[2])
7553 {
7555 atoi_constrained(p[1], &options->n_bcast_buf, p[0], 1, MBUF_SIZE_MAX, msglevel);
7556 }
7557 else if (streq(p[0], "tcp-queue-limit") && p[1] && !p[2])
7558 {
7560 atoi_constrained(p[1], &options->tcp_queue_limit, p[0], 1, INT_MAX, msglevel);
7561 }
7562#if PORT_SHARE
7563 else if (streq(p[0], "port-share") && p[1] && p[2] && !p[4])
7564 {
7566 options->port_share_host = p[1];
7567 options->port_share_port = p[2];
7568 options->port_share_journal_dir = p[3];
7569 }
7570#endif
7571 else if (streq(p[0], "client-to-client") && !p[1])
7572 {
7574 options->enable_c2c = true;
7575 }
7576 else if (streq(p[0], "duplicate-cn") && !p[1])
7577 {
7579 options->duplicate_cn = true;
7580 }
7581 else if (streq(p[0], "iroute") && p[1] && !p[3])
7582 {
7584 option_iroute(options, p[1], p[2], msglevel);
7585 }
7586 else if (streq(p[0], "iroute-ipv6") && p[1] && !p[2])
7587 {
7589 option_iroute_ipv6(options, p[1], msglevel);
7590 }
7591 else if (streq(p[0], "ifconfig-push") && p[1] && p[2] && !p[4])
7592 {
7593 in_addr_t local, remote_netmask;
7594
7596 local = getaddr(GETADDR_HOST_ORDER | GETADDR_RESOLVE, p[1], 0, NULL, NULL);
7597 remote_netmask = getaddr(GETADDR_HOST_ORDER | GETADDR_RESOLVE, p[2], 0, NULL, NULL);
7598 if (local && remote_netmask)
7599 {
7602 options->push_ifconfig_remote_netmask = remote_netmask;
7603 if (p[3])
7604 {
7606 getaddr(GETADDR_HOST_ORDER | GETADDR_RESOLVE, p[3], 0, NULL, NULL);
7607 }
7608 }
7609 else
7610 {
7611 msg(msglevel, "cannot parse --ifconfig-push addresses");
7612 goto err;
7613 }
7614 }
7615 else if (streq(p[0], "ifconfig-push-constraint") && p[1] && p[2] && !p[3])
7616 {
7617 in_addr_t network, netmask;
7618
7620 network = getaddr(GETADDR_HOST_ORDER | GETADDR_RESOLVE, p[1], 0, NULL, NULL);
7621 netmask = getaddr(GETADDR_HOST_ORDER, p[2], 0, NULL, NULL);
7622 if (network && netmask)
7623 {
7627 }
7628 else
7629 {
7630 msg(msglevel, "cannot parse --ifconfig-push-constraint addresses");
7631 goto err;
7632 }
7633 }
7634 else if (streq(p[0], "ifconfig-ipv6-push") && p[1] && !p[3])
7635 {
7636 struct in6_addr local, remote;
7637 unsigned int netbits;
7638
7640
7641 if (!get_ipv6_addr(p[1], &local, &netbits, msglevel))
7642 {
7643 msg(msglevel, "cannot parse --ifconfig-ipv6-push addresses");
7644 goto err;
7645 }
7646
7647 if (p[2])
7648 {
7649 if (!get_ipv6_addr(p[2], &remote, NULL, msglevel))
7650 {
7651 msg(msglevel, "cannot parse --ifconfig-ipv6-push addresses");
7652 goto err;
7653 }
7654 }
7655 else
7656 {
7658 || !get_ipv6_addr(options->ifconfig_ipv6_local, &remote, NULL, msglevel))
7659 {
7660 msg(msglevel,
7661 "second argument to --ifconfig-ipv6-push missing and no global --ifconfig-ipv6 address set");
7662 goto err;
7663 }
7664 }
7665
7671 }
7672 else if (streq(p[0], "disable") && !p[1])
7673 {
7675 options->disable = true;
7676 }
7677 else if (streq(p[0], "override-username") && p[1] && !p[2])
7678 {
7680 if (strlen(p[1]) > USER_PASS_LEN)
7681 {
7682 msg(msglevel,
7683 "override-username exceeds the maximum length of %d "
7684 "characters",
7686
7687 /* disable the connection since ignoring the request to
7688 * set another username might cause serious problems */
7689 options->disable = true;
7690 }
7691 else
7692 {
7693 options->override_username = p[1];
7694 }
7695 }
7696 else if (streq(p[0], "tcp-nodelay") && !p[1])
7697 {
7700 }
7701 else if (streq(p[0], "stale-routes-check") && p[1] && !p[3])
7702 {
7703 int ageing_time, check_interval;
7704
7706 if (!atoi_constrained(p[1], &ageing_time, "stale-routes-check age", 1, INT_MAX, msglevel))
7707 {
7708 goto err;
7709 }
7710
7711 if (p[2])
7712 {
7713 if (!atoi_constrained(p[2], &check_interval,
7714 "stale-routes-check interval", 1, INT_MAX, msglevel))
7715 {
7716 goto err;
7717 }
7718 }
7719 else
7720 {
7721 check_interval = ageing_time;
7722 }
7723
7724 options->stale_routes_ageing_time = ageing_time;
7725 options->stale_routes_check_interval = check_interval;
7726 }
7727
7728 else if (streq(p[0], "client") && !p[1])
7729 {
7731 options->client = true;
7732 }
7733 else if (streq(p[0], "pull") && !p[1])
7734 {
7736 options->pull = true;
7737 }
7738 else if (streq(p[0], "push-continuation") && p[1] && !p[2])
7739 {
7741 atoi_constrained(p[1], &options->push_continuation, p[0], 0, 2, msglevel);
7742 }
7743 else if (streq(p[0], "auth-user-pass") && !p[2])
7744 {
7747 if (p[1] && streq(p[1], "username-only"))
7748 {
7750 options->auth_user_pass_file = "stdin";
7751 }
7752 else if (p[1])
7753 {
7756 }
7757 else
7758 {
7759 options->auth_user_pass_file = "stdin";
7760 }
7761 }
7762 else if (streq(p[0], "auth-retry") && p[1] && !p[2])
7763 {
7765 auth_retry_set(msglevel, p[1]);
7766 }
7767#ifdef ENABLE_MANAGEMENT
7768 else if (streq(p[0], "static-challenge") && p[1] && p[2] && !p[4])
7769 {
7772 if (atoi_warn(p[2], msglevel))
7773 {
7775 }
7776 if (p[3] && streq(p[3], "concat"))
7777 {
7779 }
7780 else if (p[3] && !streq(p[3], "scrv1"))
7781 {
7782 msg(msglevel, "--static-challenge: unknown format indicator '%s'", p[3]);
7783 goto err;
7784 }
7785 }
7786#endif
7787 else if (streq(p[0], "msg-channel") && p[1])
7788 {
7789#ifdef _WIN32
7791 HANDLE process = GetCurrentProcess();
7792 HANDLE handle = (HANDLE)((intptr_t)atoll(p[1]));
7793 if (!DuplicateHandle(process, handle, process, &options->msg_channel, 0, FALSE,
7794 DUPLICATE_CLOSE_SOURCE | DUPLICATE_SAME_ACCESS))
7795 {
7796 msg(msglevel, "could not duplicate service pipe handle");
7797 goto err;
7798 }
7800#else /* ifdef _WIN32 */
7801 msg(msglevel, "--msg-channel is only supported on Windows");
7802 goto err;
7803#endif
7804 }
7805#ifdef _WIN32
7806 else if (streq(p[0], "win-sys") && p[1] && !p[2])
7807 {
7809 if (streq(p[1], "env"))
7810 {
7811 msg(M_INFO, "NOTE: --win-sys env is default from OpenVPN 2.3. "
7812 "This entry will now be ignored. "
7813 "Please remove this entry from your configuration file.");
7814 }
7815 else
7816 {
7817 set_win_sys_path(p[1], es);
7818 }
7819 }
7820 else if (streq(p[0], "route-method") && p[1] && !p[2])
7821 {
7823 if (streq(p[1], "adaptive"))
7824 {
7826 }
7827 else if (streq(p[1], "ipapi"))
7828 {
7830 }
7831 else if (streq(p[1], "exe"))
7832 {
7834 }
7835 else
7836 {
7837 msg(msglevel, "--route method must be 'adaptive', 'ipapi', or 'exe'");
7838 goto err;
7839 }
7840 }
7841 else if (streq(p[0], "ip-win32") && p[1] && !p[4])
7842 {
7843 const int index = ascii2ipset(p[1]);
7844 struct tuntap_options *to = &options->tuntap_options;
7845
7847
7848 if (index < 0)
7849 {
7850 msg(msglevel, "Bad --ip-win32 method: '%s'. Allowed methods: %s", p[1],
7852 goto err;
7853 }
7854
7855 if (index == IPW32_SET_ADAPTIVE)
7856 {
7858 }
7859
7860 if (index == IPW32_SET_DHCP_MASQ)
7861 {
7862 if (p[2])
7863 {
7864 if (!streq(p[2], "default"))
7865 {
7866 int offset;
7867
7868 if (!atoi_constrained(p[2], &offset, "ip-win32 offset", -256, 256, msglevel))
7869 {
7870 goto err;
7871 }
7872 to->dhcp_masq_custom_offset = true;
7873 to->dhcp_masq_offset = offset;
7874 }
7875
7876 if (p[3])
7877 {
7878 if (!atoi_constrained(p[3], &to->dhcp_lease_time,
7879 "ip-win32 lease time", 30, INT_MAX, msglevel))
7880 {
7881 goto err;
7882 }
7883 }
7884 }
7885 }
7886 to->ip_win32_type = index;
7887 to->ip_win32_defined = true;
7888 }
7889#endif /* ifdef _WIN32 */
7890 else if (streq(p[0], "dns-updown") && p[1])
7891 {
7893 if (!no_more_than_n_args(msglevel, p, 2, NM_QUOTE_HINT))
7894 {
7895 goto err;
7896 }
7897 struct dns_options *dns = &options->dns_options;
7898 if (streq(p[1], "disable"))
7899 {
7900 dns->updown = NULL;
7902 }
7903 else if (streq(p[1], "force"))
7904 {
7905 /* force dns-updown run, even if a --up script is defined */
7906 if (!dns_updown_user_set(dns))
7907 {
7908 dns->updown = DEFAULT_DNS_UPDOWN;
7910 }
7911 }
7912 else
7913 {
7914 if (dns->updown && streq(dns->updown, DEFAULT_DNS_UPDOWN))
7915 {
7916 /* Unset the default command to prevent warnings */
7917 dns->updown = NULL;
7918 }
7919 set_user_script(options, &dns->updown, p[1], p[0], false);
7921 }
7922 }
7923 else if (streq(p[0], "dns") && p[1])
7924 {
7926 if (!check_dns_option(options, p, msglevel, pull_mode))
7927 {
7928 goto err;
7929 }
7930 }
7931 else if (streq(p[0], "dhcp-option") && p[1])
7932 {
7934#if defined(_WIN32) || defined(TARGET_ANDROID)
7936#endif
7938
7939 bool dhcp_optional = false;
7940
7941 if ((streq(p[1], "DOMAIN") || streq(p[1], "ADAPTER_DOMAIN_SUFFIX")) && p[2] && !p[3])
7942 {
7943 if (!validate_domain(p[2]))
7944 {
7945 msg(msglevel, "--dhcp-option %s contains invalid characters", p[1]);
7946 goto err;
7947 }
7948
7949 dhcp->domain = p[2];
7950 dhcp_optional = true;
7951 }
7952 else if (streq(p[1], "DOMAIN-SEARCH") && p[2] && !p[3])
7953 {
7954 if (!validate_domain(p[2]))
7955 {
7956 msg(msglevel, "--dhcp-option %s contains invalid characters", p[1]);
7957 goto err;
7958 }
7959
7960 if (dhcp->domain_search_list_len < N_SEARCH_LIST_LEN)
7961 {
7962 dhcp->domain_search_list[dhcp->domain_search_list_len++] = p[2];
7963 }
7964 else
7965 {
7966 msg(msglevel, "--dhcp-option %s: maximum of %d search entries can be specified",
7967 p[1], N_SEARCH_LIST_LEN);
7968 }
7969 dhcp_optional = true;
7970 }
7971 else if ((streq(p[1], "DNS") || streq(p[1], "DNS6")) && p[2] && !p[3]
7972 && (!strstr(p[2], ":") || ipv6_addr_safe(p[2])))
7973 {
7974 if (strstr(p[2], ":"))
7975 {
7976 dhcp_option_dns6_parse(p[2], dhcp->dns6, &dhcp->dns6_len, msglevel);
7977 }
7978 else
7979 {
7980 dhcp_option_address_parse("DNS", p[2], dhcp->dns, &dhcp->dns_len, msglevel);
7981 dhcp_optional = true;
7982 }
7983 }
7984#if defined(_WIN32) || defined(TARGET_ANDROID)
7985 else if (streq(p[1], "NBS") && p[2] && !p[3])
7986 {
7987 o->netbios_scope = p[2];
7989 }
7990 else if (streq(p[1], "NBT") && p[2] && !p[3])
7991 {
7992 int t = atoi_warn(p[2], msglevel);
7993 if (!(t == 1 || t == 2 || t == 4 || t == 8))
7994 {
7995 msg(msglevel, "--dhcp-option NBT: parameter (%d) must be 1, 2, 4, or 8", t);
7996 goto err;
7997 }
7998 o->netbios_node_type = (uint8_t)t;
8000 }
8001 else if (streq(p[1], "WINS") && p[2] && !p[3])
8002 {
8003 dhcp_option_address_parse("WINS", p[2], o->wins, &o->wins_len, msglevel);
8005 }
8006 else if (streq(p[1], "NTP") && p[2] && !p[3])
8007 {
8008 dhcp_option_address_parse("NTP", p[2], o->ntp, &o->ntp_len, msglevel);
8010 }
8011 else if (streq(p[1], "NBDD") && p[2] && !p[3])
8012 {
8013 dhcp_option_address_parse("NBDD", p[2], o->nbdd, &o->nbdd_len, msglevel);
8015 }
8016 else if (streq(p[1], "DISABLE-NBT") && !p[2])
8017 {
8018 o->disable_nbt = 1;
8020 }
8021#if defined(TARGET_ANDROID)
8022 else if (streq(p[1], "PROXY_HTTP") && p[3] && !p[4])
8023 {
8024 o->http_proxy_port = positive_atoi(p[3], msglevel);
8025 o->http_proxy = p[2];
8026 }
8027#endif
8028 else
8029 {
8030 msg(msglevel, "--dhcp-option: unknown option type '%s' or missing or unknown parameter",
8031 p[1]);
8032 goto err;
8033 }
8034#else /* if defined(_WIN32) || defined(TARGET_ANDROID) */
8035 setenv_foreign_option(options, p[1], p[2], es);
8036#endif /* if defined(_WIN32) || defined(TARGET_ANDROID) */
8037
8038 if (dhcp_optional)
8039 {
8040#if defined(_WIN32) || defined(TARGET_ANDROID)
8042#endif
8043 }
8044 }
8045#ifdef _WIN32
8046 else if (streq(p[0], "show-adapters") && !p[1])
8047 {
8050 openvpn_exit(OPENVPN_EXIT_STATUS_GOOD); /* exit point */
8051 }
8052 else if (streq(p[0], "show-net") && !p[1])
8053 {
8057 openvpn_exit(OPENVPN_EXIT_STATUS_GOOD); /* exit point */
8058 }
8059 else if (streq(p[0], "show-net-up") && !p[1])
8060 {
8062 options->show_net_up = true;
8063 }
8064 else if (streq(p[0], "tap-sleep") && p[1] && !p[2])
8065 {
8067 if (!atoi_constrained(p[1], &options->tuntap_options.tap_sleep, p[0], 0, 255, msglevel))
8068 {
8069 goto err;
8070 }
8071 }
8072 else if (streq(p[0], "dhcp-renew") && !p[1])
8073 {
8076 }
8077 else if (streq(p[0], "dhcp-pre-release") && !p[1])
8078 {
8082 }
8083 else if (streq(p[0], "dhcp-release") && !p[1])
8084 {
8085 msg(M_WARN, "Obsolete option --dhcp-release detected. This is now on by default");
8086 }
8087 else if (streq(p[0], "dhcp-internal") && p[1] && !p[2]) /* standalone method for internal use */
8088 {
8089 unsigned int adapter_index;
8092 adapter_index = atou(p[1]);
8095 {
8096 dhcp_release_by_adapter_index(adapter_index);
8097 }
8099 {
8100 dhcp_renew_by_adapter_index(adapter_index);
8101 }
8102 openvpn_exit(OPENVPN_EXIT_STATUS_GOOD); /* exit point */
8103 }
8104 else if (streq(p[0], "register-dns") && !p[1])
8105 {
8108 }
8109 else if (streq(p[0], "block-outside-dns") && !p[1])
8110 {
8112 options->block_outside_dns = true;
8113 }
8114 else if (streq(p[0], "rdns-internal") && !p[1])
8115 /* standalone method for internal use
8116 *
8117 * (if --register-dns is set, openvpn needs to call itself in a
8118 * sub-process to execute the required functions in a non-blocking
8119 * way, and uses --rdns-internal to signal that to itself)
8120 */
8121 {
8125 {
8127 }
8128 openvpn_exit(OPENVPN_EXIT_STATUS_GOOD); /* exit point */
8129 }
8130 else if (streq(p[0], "show-valid-subnets") && !p[1])
8131 {
8134 openvpn_exit(OPENVPN_EXIT_STATUS_GOOD); /* exit point */
8135 }
8136 else if (streq(p[0], "pause-exit") && !p[1])
8137 {
8140 }
8141 else if (streq(p[0], "service") && p[1] && !p[3])
8142 {
8144 options->exit_event_name = p[1];
8145 if (p[2])
8146 {
8147 options->exit_event_initial_state = (atoi_warn(p[2], msglevel) != 0);
8148 }
8149 }
8150 else if (streq(p[0], "allow-nonadmin") && !p[2])
8151 {
8154 openvpn_exit(OPENVPN_EXIT_STATUS_GOOD); /* exit point */
8155 }
8156 else if (streq(p[0], "user") && p[1] && !p[2])
8157 {
8159 msg(M_WARN, "NOTE: --user option is not implemented on Windows");
8160 }
8161 else if (streq(p[0], "group") && p[1] && !p[2])
8162 {
8164 msg(M_WARN, "NOTE: --group option is not implemented on Windows");
8165 }
8166#else /* ifdef _WIN32 */
8167 else if (streq(p[0], "user") && p[1] && !p[2])
8168 {
8170 options->username = p[1];
8171 }
8172 else if (streq(p[0], "group") && p[1] && !p[2])
8173 {
8175 options->groupname = p[1];
8176 }
8177 else if (streq(p[0], "dhcp-option") && p[1] && !p[3])
8178 {
8180 setenv_foreign_option(options, p[1], p[2], es);
8181 }
8182 else if (streq(p[0], "route-method") && p[1] && !p[2])
8183 {
8185 /* ignore when pushed to non-Windows OS */
8186 }
8187#endif /* ifdef _WIN32 */
8188#if PASSTOS_CAPABILITY
8189 else if (streq(p[0], "passtos") && !p[1])
8190 {
8192 options->passtos = true;
8193 }
8194#endif
8195 else if (streq(p[0], "allow-compression") && p[1] && !p[2])
8196 {
8198
8199 if (streq(p[1], "no"))
8200 {
8203 {
8204 msg(msglevel, "'--allow-compression no' conflicts with "
8205 " enabling compression");
8206 }
8207 }
8209 {
8210 /* Also printed on a push to hint at configuration problems */
8211 msg(msglevel,
8212 "Cannot set allow-compression to '%s' "
8213 "after set to 'no'",
8214 p[1]);
8215 goto err;
8216 }
8217 else if (streq(p[1], "asym"))
8218 {
8220 }
8221 else if (streq(p[1], "yes"))
8222 {
8223 msg(M_WARN,
8224 "DEPRECATED OPTION: \"--allow-compression yes\" has been removed. "
8225 "We will use \"asym\" mode instead. See the manual page for more information.");
8226
8228 }
8229 else
8230 {
8231 msg(msglevel,
8232 "bad allow-compression option: %s -- "
8233 "must be 'yes', 'no', or 'asym'",
8234 p[1]);
8235 goto err;
8236 }
8237 }
8238 else if (streq(p[0], "comp-lzo") && !p[2])
8239 {
8241
8242 /* All lzo variants do not use swap */
8243 options->comp.flags &= ~COMP_F_SWAP;
8245
8246 if (p[1])
8247 {
8248 if (streq(p[1], "no"))
8249 {
8251 }
8252 /* There is no actual difference anymore between these variants.
8253 * We never compress. On the server side we replace this with
8254 * --compress migrate later anyway.
8255 */
8256 else if (!(streq(p[1], "yes") || streq(p[1], "adaptive")))
8257 {
8258 msg(msglevel, "bad comp-lzo option: %s -- must be 'yes', 'no', or 'adaptive'",
8259 p[1]);
8260 goto err;
8261 }
8262 }
8264 }
8265 else if (streq(p[0], "comp-noadapt") && !p[1])
8266 {
8267 /* NO-OP since we never compress anymore */
8268 }
8269 else if (streq(p[0], "compress") && !p[2])
8270 {
8272 const char *alg = "stub";
8273 if (p[1])
8274 {
8275 alg = p[1];
8276 }
8277
8278 if (streq(alg, "stub"))
8279 {
8282 }
8283 else if (streq(alg, "stub-v2"))
8284 {
8287 }
8288 else if (streq(alg, "migrate"))
8289 {
8292 }
8293 else if (streq(alg, "lzo"))
8294 {
8296 options->comp.flags &= ~COMP_F_SWAP;
8297 }
8298 else if (streq(alg, "lz4"))
8299 {
8302 }
8303 else if (streq(alg, "lz4-v2"))
8304 {
8306 }
8307 else
8308 {
8309 msg(msglevel, "bad comp option: %s", alg);
8310 goto err;
8311 }
8312
8314 }
8315 else if (streq(p[0], "show-ciphers") && !p[1])
8316 {
8318 options->show_ciphers = true;
8319 }
8320 else if (streq(p[0], "show-digests") && !p[1])
8321 {
8323 options->show_digests = true;
8324 }
8325 else if (streq(p[0], "show-engines") && !p[1])
8326 {
8328 options->show_engines = true;
8329 }
8330 else if (streq(p[0], "key-direction") && p[1] && !p[2])
8331 {
8332 int key_direction;
8333
8335
8336 key_direction = ascii2keydirection(msglevel, p[1]);
8337 if (key_direction >= 0)
8338 {
8339 if (permission_mask & OPT_P_GENERAL)
8340 {
8341 options->key_direction = key_direction;
8342 }
8343 else if (permission_mask & OPT_P_CONNECTION)
8344 {
8345 options->ce.key_direction = key_direction;
8346 }
8347 }
8348 else
8349 {
8350 goto err;
8351 }
8352 }
8353 else if (streq(p[0], "secret") && p[1] && !p[3])
8354 {
8355 msg(M_WARN, "DEPRECATED OPTION: The option --secret is deprecated.");
8359 if (!is_inline && p[2])
8360 {
8361 int key_direction;
8362
8363 key_direction = ascii2keydirection(msglevel, p[2]);
8364 if (key_direction >= 0)
8365 {
8366 options->key_direction = key_direction;
8367 }
8368 else
8369 {
8370 goto err;
8371 }
8372 }
8373 }
8374 else if (streq(p[0], "allow-deprecated-insecure-static-crypto"))
8375 {
8378 }
8379 else if (streq(p[0], "genkey") && !p[4])
8380 {
8382 options->genkey = true;
8383 if (!p[1])
8384 {
8386 }
8387 else
8388 {
8389 if (streq(p[1], "secret") || streq(p[1], "tls-auth") || streq(p[1], "tls-crypt"))
8390 {
8392 }
8393 else if (streq(p[1], "tls-crypt-v2-server"))
8394 {
8396 }
8397 else if (streq(p[1], "tls-crypt-v2-client"))
8398 {
8400 if (p[3])
8401 {
8402 options->genkey_extra_data = p[3];
8403 }
8404 }
8405 else if (streq(p[1], "auth-token"))
8406 {
8408 }
8409 else
8410 {
8411 msg(msglevel, "unknown --genkey type: %s", p[1]);
8412 }
8413 }
8414 if (p[2])
8415 {
8416 options->genkey_filename = p[2];
8417 }
8418 }
8419 else if (streq(p[0], "auth") && p[1] && !p[2])
8420 {
8422 options->authname = p[1];
8423 }
8424 else if (streq(p[0], "cipher") && p[1] && !p[2])
8425 {
8427 options->ciphername = p[1];
8428 }
8429 else if (streq(p[0], "data-ciphers-fallback") && p[1] && !p[2])
8430 {
8432 options->ciphername = p[1];
8434 }
8435 else if ((streq(p[0], "data-ciphers") || streq(p[0], "ncp-ciphers")) && p[1] && !p[2])
8436 {
8438 if (streq(p[0], "ncp-ciphers"))
8439 {
8440 msg(M_INFO, "Note: Treating option '--ncp-ciphers' as "
8441 " '--data-ciphers' (renamed in OpenVPN 2.5).");
8442 }
8443 options->ncp_ciphers = p[1];
8444 }
8445 else if (streq(p[0], "key-derivation") && p[1])
8446 {
8447 /* NCP only option that is pushed by the server to enable EKM,
8448 * should not be used by normal users in config files*/
8450 if (streq(p[1], "tls-ekm"))
8451 {
8453 }
8454 else
8455 {
8456 msg(msglevel, "Unknown key-derivation method %s", p[1]);
8457 }
8458 }
8459 else if (streq(p[0], "protocol-flags") && p[1])
8460 {
8461 /* NCP only option that is pushed by the server to enable protocol
8462 * features that are negotiated, should not be used by normal users
8463 * in config files */
8465 for (size_t j = 1; j < MAX_PARMS && p[j] != NULL; j++)
8466 {
8467 if (streq(p[j], "cc-exit"))
8468 {
8470 }
8471 else if (streq(p[j], "tls-ekm"))
8472 {
8474 }
8475 else if (streq(p[j], "dyn-tls-crypt"))
8476 {
8478 }
8479 else if (streq(p[j], "aead-epoch"))
8480 {
8482 }
8483 else
8484 {
8485 msg(msglevel, "Unknown protocol-flags flag: %s", p[j]);
8486 }
8487 }
8488 }
8489 else if (streq(p[0], "force-tls-key-material-export"))
8490 {
8493 }
8494 else if (streq(p[0], "prng") && p[1] && !p[3])
8495 {
8496 msg(M_WARN, "NOTICE: --prng option ignored (SSL library PRNG is used)");
8497 }
8498 else if (streq(p[0], "no-replay") && !p[1])
8499 {
8501 /* always error out, this breaks the connection */
8502 msg(M_FATAL, "--no-replay was removed in OpenVPN 2.7. "
8503 "Update your configuration.");
8504 }
8505 else if (streq(p[0], "replay-window") && !p[3])
8506 {
8508 if (p[1])
8509 {
8510 if (!atoi_constrained(p[1], &options->replay_window, "replay-window windows size",
8512 {
8513 goto err;
8514 }
8515
8516 if (p[2])
8517 {
8518 if (!atoi_constrained(p[2], &options->replay_time, "replay-window time window",
8520 {
8521 goto err;
8522 }
8523 }
8524 }
8525 else
8526 {
8527 msg(msglevel, "replay-window option is missing window size parameter");
8528 goto err;
8529 }
8530 }
8531 else if (streq(p[0], "mute-replay-warnings") && !p[1])
8532 {
8535 }
8536 else if (streq(p[0], "replay-persist") && p[1] && !p[2])
8537 {
8539 options->packet_id_file = p[1];
8540 }
8541 else if (streq(p[0], "test-crypto") && !p[1])
8542 {
8544 options->test_crypto = true;
8545 }
8546#ifndef ENABLE_CRYPTO_MBEDTLS
8547 else if (streq(p[0], "engine") && !p[2])
8548 {
8550 if (p[1])
8551 {
8552 options->engine = p[1];
8553 }
8554 else
8555 {
8556 options->engine = "auto";
8557 }
8558 }
8559#endif /* ENABLE_CRYPTO_MBEDTLS */
8560 else if (streq(p[0], "providers") && p[1])
8561 {
8562 for (size_t j = 1; j < MAX_PARMS && p[j] != NULL; j++)
8563 {
8564 options->providers.names[j] = p[j];
8565 }
8566 }
8567 else if (streq(p[0], "show-tls") && !p[1])
8568 {
8570 options->show_tls_ciphers = true;
8571 }
8572 else if ((streq(p[0], "show-curves") || streq(p[0], "show-groups")) && !p[1])
8573 {
8575 options->show_curves = true;
8576 }
8577 else if (streq(p[0], "ecdh-curve") && p[1] && !p[2])
8578 {
8580 msg(M_WARN, "Consider setting groups/curves preference with "
8581 "tls-groups instead of forcing a specific curve with "
8582 "ecdh-curve.");
8583 options->ecdh_curve = p[1];
8584 }
8585 else if (streq(p[0], "tls-server") && !p[1])
8586 {
8588 options->tls_server = true;
8589 }
8590 else if (streq(p[0], "tls-client") && !p[1])
8591 {
8593 options->tls_client = true;
8594 }
8595 else if (streq(p[0], "ca") && p[1] && !p[2])
8596 {
8598 options->ca_file = p[1];
8599 options->ca_file_inline = is_inline;
8600 }
8601#ifndef ENABLE_CRYPTO_MBEDTLS
8602 else if (streq(p[0], "capath") && p[1] && !p[2])
8603 {
8605 options->ca_path = p[1];
8606 }
8607#endif /* ENABLE_CRYPTO_MBEDTLS */
8608 else if (streq(p[0], "dh") && p[1] && !p[2])
8609 {
8611 options->dh_file = p[1];
8612 options->dh_file_inline = is_inline;
8613 }
8614 else if (streq(p[0], "cert") && p[1] && !p[2])
8615 {
8617 options->cert_file = p[1];
8618 options->cert_file_inline = is_inline;
8619 }
8620 else if (streq(p[0], "extra-certs") && p[1] && !p[2])
8621 {
8623 options->extra_certs_file = p[1];
8624 options->extra_certs_file_inline = is_inline;
8625 }
8626 else if ((streq(p[0], "verify-hash") && p[1] && !p[3])
8627 || (streq(p[0], "peer-fingerprint") && p[1] && !p[2]))
8628 {
8630
8631 int verify_hash_depth = 0;
8632 if (streq(p[0], "verify-hash"))
8633 {
8634 msg(M_WARN, "DEPRECATED OPTION: The option --verify-hash is deprecated. "
8635 "You should switch to the either use the level 1 certificate as "
8636 "--ca option, use --tls-verify or use --peer-fingerprint");
8637 /* verify level 1 cert, i.e. the CA that signed the leaf cert */
8638 verify_hash_depth = 1;
8639 }
8640
8642
8643 int digest_len = SHA256_DIGEST_LENGTH;
8644
8645 if (options->verify_hash && options->verify_hash_depth != verify_hash_depth)
8646 {
8647 msg(msglevel,
8648 "ERROR: Setting %s not allowed. --verify-hash and"
8649 " --peer-fingerprint are mutually exclusive",
8650 p[0]);
8651 goto err;
8652 }
8653
8654 if (streq(p[0], "verify-hash"))
8655 {
8656 if ((!p[2] && !is_inline) || (p[2] && streq(p[2], "SHA1")))
8657 {
8659 digest_len = SHA_DIGEST_LENGTH;
8660 }
8661 else if (p[2] && !streq(p[2], "SHA256"))
8662 {
8663 msg(msglevel,
8664 "invalid or unsupported hashing algorithm: %s "
8665 "(only SHA1 and SHA256 are supported)",
8666 p[2]);
8667 goto err;
8668 }
8669 }
8670
8671 struct verify_hash_list *newlist;
8672 newlist = parse_hash_fingerprint_multiline(p[1], digest_len, msglevel, &options->gc);
8673
8674 /* Append the new list to the end of our current list */
8675 if (!options->verify_hash)
8676 {
8677 options->verify_hash = newlist;
8678 options->verify_hash_depth = verify_hash_depth;
8679 }
8680 else
8681 {
8682 /* since both the old and new list can have multiple entries
8683 * we need to go to the end of one of them to concatenate them */
8684 struct verify_hash_list *listend = options->verify_hash;
8685 while (listend->next)
8686 {
8687 listend = listend->next;
8688 }
8689 listend->next = newlist;
8690 }
8691 }
8692#if defined(ENABLE_CRYPTOAPI) && defined(HAVE_XKEY_PROVIDER)
8693 else if (streq(p[0], "cryptoapicert") && p[1] && !p[2])
8694 {
8696 options->cryptoapi_cert = p[1];
8697 }
8698#endif
8699 else if (streq(p[0], "key") && p[1] && !p[2])
8700 {
8702 options->priv_key_file = p[1];
8703 options->priv_key_file_inline = is_inline;
8704 }
8705 else if (streq(p[0], "tls-version-min") && p[1] && !p[3])
8706 {
8708 int ver = tls_version_parse(p[1], p[2]);
8709 if (ver == TLS_VER_BAD)
8710 {
8711 msg(msglevel, "unknown tls-version-min parameter: %s", p[1]);
8712 goto err;
8713 }
8714
8715#ifdef ENABLE_CRYPTO_MBEDTLS
8716 if (ver < TLS_VER_1_2)
8717 {
8718 msg(M_WARN, "--tls-version-min %s is not supported by mbedtls, using 1.2", p[1]);
8719 ver = TLS_VER_1_2;
8720 }
8721#endif
8722
8724 options->ssl_flags |= ((unsigned int)ver << SSLF_TLS_VERSION_MIN_SHIFT);
8725 }
8726 else if (streq(p[0], "tls-version-max") && p[1] && !p[2])
8727 {
8729 int ver = tls_version_parse(p[1], NULL);
8730 if (ver == TLS_VER_BAD)
8731 {
8732 msg(msglevel, "unknown tls-version-max parameter: %s", p[1]);
8733 goto err;
8734 }
8736 options->ssl_flags |= ((unsigned int)ver << SSLF_TLS_VERSION_MAX_SHIFT);
8737 }
8738#ifndef ENABLE_CRYPTO_MBEDTLS
8739 else if (streq(p[0], "pkcs12") && p[1] && !p[2])
8740 {
8742 options->pkcs12_file = p[1];
8743 options->pkcs12_file_inline = is_inline;
8744 }
8745#endif /* ENABLE_CRYPTO_MBEDTLS */
8746 else if (streq(p[0], "askpass") && !p[2])
8747 {
8749 if (p[1])
8750 {
8751 options->key_pass_file = p[1];
8752 }
8753 else
8754 {
8755 options->key_pass_file = "stdin";
8756 }
8757 }
8758 else if (streq(p[0], "auth-nocache") && !p[1])
8759 {
8762 }
8763 else if (streq(p[0], "auth-token") && p[1] && !p[2])
8764 {
8766 ssl_set_auth_token(p[1]);
8767#ifdef ENABLE_MANAGEMENT
8768 if (management)
8769 {
8771 }
8772#endif
8773 }
8774 else if (streq(p[0], "auth-token-user") && p[1] && !p[2])
8775 {
8778 }
8779 else if (streq(p[0], "single-session") && !p[1])
8780 {
8782 options->single_session = true;
8783 }
8784 else if (streq(p[0], "push-peer-info") && !p[1])
8785 {
8787 options->push_peer_info = true;
8788 }
8789 else if (streq(p[0], "tls-exit") && !p[1])
8790 {
8792 options->tls_exit = true;
8793 }
8794 else if (streq(p[0], "tls-cipher") && p[1] && !p[2])
8795 {
8797 options->cipher_list = p[1];
8798 }
8799 else if (streq(p[0], "tls-cert-profile") && p[1] && !p[2])
8800 {
8802 options->tls_cert_profile = p[1];
8803 }
8804 else if (streq(p[0], "tls-ciphersuites") && p[1] && !p[2])
8805 {
8807 options->cipher_list_tls13 = p[1];
8808 }
8809 else if (streq(p[0], "tls-groups") && p[1] && !p[2])
8810 {
8812 options->tls_groups = p[1];
8813 }
8814 else if (streq(p[0], "crl-verify") && p[1] && ((p[2] && streq(p[2], "dir")) || !p[2]))
8815 {
8817 if (p[2] && streq(p[2], "dir"))
8818 {
8820 }
8821 options->crl_file = p[1];
8822 options->crl_file_inline = is_inline;
8823 }
8824 else if (streq(p[0], "tls-verify") && p[1])
8825 {
8827 if (!no_more_than_n_args(msglevel, p, 2, NM_QUOTE_HINT))
8828 {
8829 goto err;
8830 }
8832 string_substitute(p[1], ',', ' ', &options->gc), "tls-verify", true);
8833 }
8834 else if (streq(p[0], "tls-export-cert") && p[1] && !p[2])
8835 {
8838 }
8839 else if (streq(p[0], "compat-names"))
8840 {
8842 msg(msglevel, "--compat-names was removed in OpenVPN 2.5. "
8843 "Update your configuration.");
8844 goto err;
8845 }
8846 else if (streq(p[0], "no-name-remapping") && !p[1])
8847 {
8849 msg(msglevel, "--no-name-remapping was removed in OpenVPN 2.5. "
8850 "Update your configuration.");
8851 goto err;
8852 }
8853 else if (streq(p[0], "verify-x509-name") && p[1] && strlen(p[1]) && !p[3])
8854 {
8855 int type = VERIFY_X509_SUBJECT_DN;
8857 if (p[2])
8858 {
8859 if (streq(p[2], "subject"))
8860 {
8862 }
8863 else if (streq(p[2], "name"))
8864 {
8866 }
8867 else if (streq(p[2], "name-prefix"))
8868 {
8870 }
8871 else
8872 {
8873 msg(msglevel, "unknown X.509 name type: %s", p[2]);
8874 goto err;
8875 }
8876 }
8877 options->verify_x509_type = type;
8878 options->verify_x509_name = p[1];
8879 }
8880 else if (streq(p[0], "ns-cert-type") && p[1] && !p[2])
8881 {
8882#ifdef ENABLE_CRYPTO_MBEDTLS
8883 msg(msglevel, "--ns-cert-type is not available with mbedtls.");
8884 goto err;
8885#else
8887 if (streq(p[1], "server"))
8888 {
8890 }
8891 else if (streq(p[1], "client"))
8892 {
8894 }
8895 else
8896 {
8897 msg(msglevel, "--ns-cert-type must be 'client' or 'server'");
8898 goto err;
8899 }
8900#endif /* ENABLE_CRYPTO_MBEDTLS */
8901 }
8902 else if (streq(p[0], "remote-cert-ku"))
8903 {
8905
8906 size_t j;
8907 for (j = 1; j < MAX_PARMS && p[j] != NULL; ++j)
8908 {
8909 sscanf(p[j], "%x", &(options->remote_cert_ku[j - 1]));
8910 }
8911 if (j == 1)
8912 {
8913 /* No specific KU required, but require KU to be present */
8915 }
8916 }
8917 else if (streq(p[0], "remote-cert-eku") && p[1] && !p[2])
8918 {
8920 options->remote_cert_eku = p[1];
8921 }
8922 else if (streq(p[0], "remote-cert-tls") && p[1] && !p[2])
8923 {
8925
8926 if (streq(p[1], "server"))
8927 {
8929 options->remote_cert_eku = "TLS Web Server Authentication";
8930 }
8931 else if (streq(p[1], "client"))
8932 {
8934 options->remote_cert_eku = "TLS Web Client Authentication";
8935 }
8936 else
8937 {
8938 msg(msglevel, "--remote-cert-tls must be 'client' or 'server'");
8939 goto err;
8940 }
8941 }
8942 else if (streq(p[0], "tls-timeout") && p[1] && !p[2])
8943 {
8945 options->tls_timeout = positive_atoi(p[1], msglevel);
8946 }
8947 else if (streq(p[0], "reneg-bytes") && p[1] && !p[2])
8948 {
8950 if (!positive_atoll(p[1], &options->renegotiate_bytes, p[0], msglevel))
8951 {
8952 goto err;
8953 }
8954 }
8955 else if (streq(p[0], "reneg-pkts") && p[1] && !p[2])
8956 {
8958 if (!positive_atoll(p[1], &options->renegotiate_packets, p[0], msglevel))
8959 {
8960 goto err;
8961 }
8962 }
8963 else if (streq(p[0], "reneg-sec") && p[1] && !p[3])
8964 {
8966 options->renegotiate_seconds = positive_atoi(p[1], msglevel);
8967 if (p[2])
8968 {
8970 }
8971 }
8972 else if (streq(p[0], "hand-window") && p[1] && !p[2])
8973 {
8975 options->handshake_window = positive_atoi(p[1], msglevel);
8976 }
8977 else if (streq(p[0], "tran-window") && p[1] && !p[2])
8978 {
8980 options->transition_window = positive_atoi(p[1], msglevel);
8981 }
8982 else if (streq(p[0], "tls-auth") && p[1] && !p[3])
8983 {
8984 int key_direction = -1;
8985
8987
8988 if (permission_mask & OPT_P_GENERAL)
8989 {
8990 options->tls_auth_file = p[1];
8991 options->tls_auth_file_inline = is_inline;
8992
8993 if (!is_inline && p[2])
8994 {
8995 key_direction = ascii2keydirection(msglevel, p[2]);
8996 if (key_direction < 0)
8997 {
8998 goto err;
8999 }
9000 options->key_direction = key_direction;
9001 }
9002 }
9003 else if (permission_mask & OPT_P_CONNECTION)
9004 {
9005 options->ce.tls_auth_file = p[1];
9006 options->ce.tls_auth_file_inline = is_inline;
9008
9009 if (!is_inline && p[2])
9010 {
9011 key_direction = ascii2keydirection(msglevel, p[2]);
9012 if (key_direction < 0)
9013 {
9014 goto err;
9015 }
9016 options->ce.key_direction = key_direction;
9017 }
9018 }
9019 }
9020 else if (streq(p[0], "tls-crypt") && p[1] && !p[3])
9021 {
9023 if (permission_mask & OPT_P_GENERAL)
9024 {
9025 options->tls_crypt_file = p[1];
9026 options->tls_crypt_file_inline = is_inline;
9027 }
9028 else if (permission_mask & OPT_P_CONNECTION)
9029 {
9030 options->ce.tls_crypt_file = p[1];
9031 options->ce.tls_crypt_file_inline = is_inline;
9032 }
9033 }
9034 else if (streq(p[0], "tls-crypt-v2") && p[1] && !p[3])
9035 {
9037 if (permission_mask & OPT_P_GENERAL)
9038 {
9039 options->tls_crypt_v2_file = p[1];
9040 options->tls_crypt_v2_file_inline = is_inline;
9041 }
9042 else if (permission_mask & OPT_P_CONNECTION)
9043 {
9045 options->ce.tls_crypt_v2_file_inline = is_inline;
9046 }
9047
9048 if (p[2] && streq(p[2], "force-cookie"))
9049 {
9051 }
9052 else if (p[2] && streq(p[2], "allow-noncookie"))
9053 {
9055 }
9056 else if (p[2])
9057 {
9058 msg(msglevel, "Unsupported tls-crypt-v2 argument: %s", p[2]);
9059 }
9060 }
9061 else if (streq(p[0], "tls-crypt-v2-verify") && p[1] && !p[2])
9062 {
9065 }
9066 else if (streq(p[0], "tls-crypt-v2-max-age") && p[1])
9067 {
9069 if (!atoi_constrained(p[1], &options->tls_crypt_v2_max_age, "tls-crypt-v2-max-age", 1, INT_MAX, msglevel))
9070 {
9071 goto err;
9072 }
9073 }
9074 else if (streq(p[0], "x509-track") && p[1] && !p[2])
9075 {
9077 x509_track_add(&options->x509_track, p[1], msglevel, &options->gc);
9078 }
9079 else if (streq(p[0], "x509-username-field") && p[1])
9080 {
9082 for (size_t j = 1; j < MAX_PARMS && p[j] != NULL; ++j)
9083 {
9084 char *s = p[j];
9085
9086 if (strncmp("ext:", s, 4) == 0 && !x509_username_field_ext_supported(s + 4))
9087 {
9088 msg(msglevel, "Unsupported x509-username-field extension: %s", s);
9089 }
9090 options->x509_username_field[j - 1] = p[j];
9091 }
9092 }
9093#ifdef ENABLE_PKCS11
9094 else if (streq(p[0], "show-pkcs11-ids") && !p[3])
9095 {
9096 char *provider = p[1];
9097 bool cert_private = (p[2] == NULL ? false : (atoi_warn(p[2], msglevel) != 0));
9098
9099#ifdef DEFAULT_PKCS11_MODULE
9100 if (!provider)
9101 {
9102 provider = DEFAULT_PKCS11_MODULE;
9103 }
9104 else if (!p[2])
9105 {
9106 char *endp = NULL;
9107 long i = strtol(provider, &endp, 10);
9108
9109 if (*endp == 0)
9110 {
9111 /* There was one argument, and it was purely numeric.
9112 * Interpret it as the cert_private argument */
9113 provider = DEFAULT_PKCS11_MODULE;
9114 cert_private = i;
9115 }
9116 }
9117#else /* ifdef DEFAULT_PKCS11_MODULE */
9118 if (!provider)
9119 {
9120 msg(msglevel, "--show-pkcs11-ids requires a provider parameter");
9121 goto err;
9122 }
9123#endif /* ifdef DEFAULT_PKCS11_MODULE */
9125
9127 show_pkcs11_ids(provider, cert_private);
9128 openvpn_exit(OPENVPN_EXIT_STATUS_GOOD); /* exit point */
9129 }
9130 else if (streq(p[0], "pkcs11-providers") && p[1])
9131 {
9132 int j;
9133
9135
9136 for (j = 1; j < MAX_PARMS && p[j] != NULL; ++j)
9137 {
9138 options->pkcs11_providers[j - 1] = p[j];
9139 }
9140 }
9141 else if (streq(p[0], "pkcs11-protected-authentication"))
9142 {
9143 int j;
9144
9146
9147 for (j = 1; j < MAX_PARMS && p[j] != NULL; ++j)
9148 {
9149 options->pkcs11_protected_authentication[j - 1] =
9150 atoi_warn(p[j], msglevel) != 0 ? 1 : 0;
9151 }
9152 }
9153 else if (streq(p[0], "pkcs11-private-mode") && p[1])
9154 {
9155 int j;
9156
9158
9159 for (j = 1; j < MAX_PARMS && p[j] != NULL; ++j)
9160 {
9161 sscanf(p[j], "%x", &(options->pkcs11_private_mode[j - 1]));
9162 }
9163 }
9164 else if (streq(p[0], "pkcs11-cert-private"))
9165 {
9166 int j;
9167
9169
9170 for (j = 1; j < MAX_PARMS && p[j] != NULL; ++j)
9171 {
9172 options->pkcs11_cert_private[j - 1] = (bool)(atoi_warn(p[j], msglevel));
9173 }
9174 }
9175 else if (streq(p[0], "pkcs11-pin-cache") && p[1] && !p[2])
9176 {
9178 options->pkcs11_pin_cache_period = positive_atoi(p[1], msglevel);
9179 }
9180 else if (streq(p[0], "pkcs11-id") && p[1] && !p[2])
9181 {
9183 options->pkcs11_id = p[1];
9184 }
9185 else if (streq(p[0], "pkcs11-id-management") && !p[1])
9186 {
9188 options->pkcs11_id_management = true;
9189 }
9190#endif /* ifdef ENABLE_PKCS11 */
9191 else if (streq(p[0], "rmtun") && !p[1])
9192 {
9194 options->persist_config = true;
9195 options->persist_mode = 0;
9196 }
9197 else if (streq(p[0], "mktun") && !p[1])
9198 {
9200 options->persist_config = true;
9201 options->persist_mode = 1;
9202 }
9203 else if (streq(p[0], "peer-id") && p[1] && !p[2])
9204 {
9206 options->use_peer_id = true;
9207 options->peer_id = atoi_warn(p[1], msglevel);
9208 }
9209 else if (streq(p[0], "keying-material-exporter") && p[1] && p[2])
9210 {
9212
9213 if (strncmp(p[1], "EXPORTER", 8))
9214 {
9215 msg(msglevel, "Keying material exporter label must begin with "
9216 "\"EXPORTER\"");
9217 goto err;
9218 }
9219 if (streq(p[1], EXPORT_KEY_DATA_LABEL))
9220 {
9221 msg(msglevel,
9222 "Keying material exporter label must not be '" EXPORT_KEY_DATA_LABEL "'.");
9223 }
9224
9226 p[0], 16, 4095, msglevel))
9227 {
9228 goto err;
9229 }
9230
9232 }
9233 else if (streq(p[0], "allow-recursive-routing") && !p[1])
9234 {
9237 }
9238 else if (streq(p[0], "vlan-tagging") && !p[1])
9239 {
9241 options->vlan_tagging = true;
9242 }
9243 else if (streq(p[0], "vlan-accept") && p[1] && !p[2])
9244 {
9246 if (streq(p[1], "tagged"))
9247 {
9249 }
9250 else if (streq(p[1], "untagged"))
9251 {
9253 }
9254 else if (streq(p[1], "all"))
9255 {
9257 }
9258 else
9259 {
9260 msg(msglevel, "--vlan-accept must be 'tagged', 'untagged' or 'all'");
9261 goto err;
9262 }
9263 }
9264 else if (streq(p[0], "vlan-pvid") && p[1] && !p[2])
9265 {
9266 int vlan_pvid;
9268 if (!atoi_constrained(p[1], &vlan_pvid, p[0],
9270 {
9271 goto err;
9272 }
9273 options->vlan_pvid = (uint16_t)vlan_pvid;
9274 }
9275 else
9276 {
9277 int i;
9278 msglvl_t msglevel_unknown = msglevel_fc;
9279 /* Check if an option is in --ignore-unknown-option and
9280 * set warning level to non fatal */
9282 {
9283 if (streq(p[0], options->ignore_unknown_option[i]))
9284 {
9285 msglevel_unknown = M_WARN;
9286 break;
9287 }
9288 }
9289 if (file)
9290 {
9291 msg(msglevel_unknown,
9292 "Unrecognized option or missing or extra parameter(s) in %s:%d: %s (%s)", file,
9293 line, p[0], PACKAGE_VERSION);
9294 }
9295 else
9296 {
9297 msg(msglevel_unknown, "Unrecognized option or missing or extra parameter(s): --%s (%s)",
9298 p[0], PACKAGE_VERSION);
9299 }
9300 }
9301err:
9302 gc_free(&gc);
9303}
9304
9305#if defined(__GNUC__) || defined(__clang__)
9306#pragma GCC diagnostic pop
9307#endif
9308
9309bool
9311{
9312 if (options->ce.local_list)
9313 {
9314 for (int i = 0; i < options->ce.local_list->len; i++)
9315 {
9317 {
9318 return true;
9319 }
9320 }
9321 }
9322
9323 return false;
9324}
void argv_parse_cmd(struct argv *argres, const char *cmdstr)
Parses a command string, tokenizes it and puts each element into a separate struct argv argument slot...
Definition argv.c:481
void argv_free(struct argv *a)
Frees all memory allocations allocated by the struct argv related functions.
Definition argv.c:101
struct argv argv_new(void)
Allocates a new struct argv and ensures it is initialised.
Definition argv.c:87
void buf_clear(struct buffer *buf)
Definition buffer.c:163
bool buf_printf(struct buffer *buf, const char *format,...)
Definition buffer.c:241
void gc_transfer(struct gc_arena *dest, struct gc_arena *src)
Definition buffer.c:460
void * gc_realloc(void *ptr, size_t size, struct gc_arena *a)
allows to realloc a pointer previously allocated by gc_malloc or gc_realloc
Definition buffer.c:370
void * gc_malloc(size_t size, bool clear, struct gc_arena *a)
Definition buffer.c:336
struct buffer alloc_buf_gc(size_t size, struct gc_arena *gc)
Definition buffer.c:89
char * format_hex_ex(const uint8_t *data, size_t size, size_t maxoutput, unsigned int space_break_flags, const char *separator, struct gc_arena *gc)
Definition buffer.c:483
struct buffer alloc_buf(size_t size)
Definition buffer.c:63
int string_array_len(const char **array)
Definition buffer.c:702
struct buffer buffer_read_from_file(const char *filename, struct gc_arena *gc)
buffer_read_from_file - copy the content of a file into a buffer
Definition buffer.c:1373
bool buf_parse(struct buffer *buf, const int delim, char *line, const int size)
Definition buffer.c:824
char * string_alloc(const char *str, struct gc_arena *gc)
Definition buffer.c:648
struct buffer string_alloc_buf(const char *str, struct gc_arena *gc)
Definition buffer.c:751
static void gc_detach(struct gc_arena *a)
Definition buffer.h: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)
#define PACKAGE_NAME
Definition config.h:492
#define IPROUTE_PATH
Definition config.h:468
#define PACKAGE_VERSION
Definition config.h:504
#define CONFIGURE_DEFINES
Definition config.h:5
#define PACKAGE_STRING
Definition config.h:495
#define TARGET_ALIAS
Definition config.h:558
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:788
void dns_options_preprocess_pull(struct dns_options *o)
Saves and resets the server options, so that pulled ones don't mix in.
Definition dns.c:282
static bool dns_updown_user_set(const struct dns_options *o)
Returns whether dns-updown is user defined.
Definition dns.h:218
@ DNS_UPDOWN_FORCED
Definition dns.h:50
@ DNS_UPDOWN_NO_FLAGS
Definition dns.h:48
@ DNS_UPDOWN_USER_SET
Definition dns.h:49
@ DNS_SECURITY_NO
Definition dns.h:33
@ DNS_SECURITY_YES
Definition dns.h:34
@ DNS_SECURITY_OPTIONAL
Definition dns.h:35
static bool dns_updown_forced(const struct dns_options *o)
Returns whether dns-updown is forced to run.
Definition dns.h:229
@ DNS_TRANSPORT_PLAIN
Definition dns.h:41
@ DNS_TRANSPORT_TLS
Definition dns.h:43
@ DNS_TRANSPORT_HTTPS
Definition dns.h:42
static bool validate_domain(const char *domain)
void setenv_int(struct env_set *es, const char *name, int value)
Definition env_set.c:291
void setenv_str_i(struct env_set *es, const char *name, const char *value, const int i)
Definition env_set.c:423
void setenv_str(struct env_set *es, const char *name, const char *value)
Definition env_set.c:307
const char * env_set_get(const struct env_set *es, const char *name)
Definition env_set.c:201
void setenv_str_safe(struct env_set *es, const char *name, const char *value)
Definition env_set.c:313
bool env_set_del(struct env_set *es, const char *str)
Definition env_set.c:183
void setenv_long_long(struct env_set *es, const char *name, long long value)
Definition env_set.c:299
#define D_SHOW_OCC
Definition errlevel.h:150
#define D_PUSH
Definition errlevel.h:82
#define D_TLS_DEBUG_MED
Definition errlevel.h:156
#define D_DCO
Definition errlevel.h:93
#define D_SHOW_PARMS
Definition errlevel.h:95
#define D_PUSH_ERRORS
Definition errlevel.h:66
#define D_TLS_ERRORS
Definition errlevel.h:58
#define M_INFO
Definition errlevel.h:54
Interface functions to the internal and external multiplexers.
void helper_setdefault_topology(struct options *o)
Set –topology default depending on –mode.
Definition helper.c:137
void helper_tcp_nodelay(struct options *o)
Definition helper.c:608
void helper_client_server(struct options *o)
Definition helper.c:165
void helper_keepalive(struct options *o)
Definition helper.c:548
static int max_int(int x, int y)
Definition integer.h:92
static int constrain_int(int x, int min, int max)
Definition integer.h:118
static int tls_verify(struct openvpn_plugin_args_func_in const *args)
void management_auth_token(struct management *man, const char *token)
Definition manage.c:3143
void management_echo(struct management *man, const char *string, const bool pull)
Definition manage.c:3064
#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:782
const char * safe_print(const char *str, struct gc_arena *gc)
Definition misc.c:548
#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:84
#define TUN_MTU_MAX_MIN
Definition mtu.h:74
#define TAP_MTU_EXTRA_DEFAULT
Definition mtu.h:79
#define LINK_MTU_DEFAULT
Definition mtu.h:64
#define TUN_MTU_DEFAULT
Definition mtu.h:69
#define TLS_MTU_DEFAULT
Definition mtu.h:89
static bool learn_address_script(const struct multi_context *m, const struct multi_instance *mi, const char *op, const struct mroute_addr *addr)
Definition multi.c:83
static int net_ctx_init(struct context *c, openvpn_net_ctx_t *ctx)
Definition networking.h:47
void * openvpn_net_ctx_t
Definition networking.h:38
#define BOOL_CAST(x)
Definition basic.h:26
#define CLEAR(x)
Definition basic.h:32
#define SIZE(x)
Definition basic.h:29
void errors_to_stderr(void)
Definition error.c:179
void open_syslog(const char *pgmname, bool stdio_to_null)
Definition error.c:442
void redirect_stdout_stderr(const char *file, bool append)
Definition error.c:491
void openvpn_exit(const int status)
Definition error.c: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:4544
#define RESET_OPTION_ROUTES(option_ptr, field)
Definition options.c:5065
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:3950
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:4084
static bool check_file_access_chroot(const char *chroot, const int type, const char *file, const int mode, const char *opt)
Definition options.c:4050
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:5032
static void options_postprocess_mutate_ce(struct options *o, struct connection_entry *ce)
Definition options.c:2896
static void usage_version(void)
Definition options.c:4911
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:3947
static void pre_connect_save(struct options *o)
Definition options.c:3087
#define CHKACC_ACPTSTDIN
If filename is stdin, it's allowed and "exists".
Definition options.c:3949
#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:4790
bool options_postprocess_pull(struct options *o, struct env_set *es)
Definition options.c:4293
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:5073
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:4743
void show_windows_version(const unsigned int flags)
Definition options.c:4878
#define VERIFY_PERMISSION(mask)
Definition options.c:4972
static const char * options_warning_extract_parm1(const char *option_string, struct gc_arena *gc_ret)
Definition options.c:4556
bool key_is_external(const struct options *options)
Definition options.c:5563
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:3948
static void tuntap_options_postprocess_dns(struct options *o)
Postprocess DNS related settings.
Definition options.c:3471
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:5235
void show_dco_version(const unsigned int flags)
Definition options.c:4887
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:3731
#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:5524
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:5393
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:4982
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:5035
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:3053
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:4664
bool string_defined_equal(const char *s1, const char *s2)
Definition options.c:4942
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:4100
void options_postprocess(struct options *options, struct env_set *es)
Definition options.c:4279
void usage_small(void)
Definition options.c:4870
const char * auth_retry_print(void)
Definition options.c:4822
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:4168
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:4687
void show_library_versions(const unsigned int flags)
Definition options.c:4897
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:3951
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:4624
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:4128
#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:3954
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:3744
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:4642
static unsigned int atou(const char *str)
Definition options.c:4964
void pre_connect_restore(struct options *o, struct gc_arena *gc)
Definition options.c:3132
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:4765
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:4706
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:5284
#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:4570
static void options_postprocess_cipher(struct options *o)
Definition options.c:3305
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:3375
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:4550
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:3946
const char * options_string_version(const char *s, struct gc_arena *gc)
Definition options.c:4693
static void options_postprocess_mutate_invariant(struct options *options)
Definition options.c:3205
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:3071
#define TLS_SERVER
static msglvl_t msglevel_forward_compatible(struct options *options, const msglvl_t msglevel)
Definition options.c:5060
bool auth_retry_set(const msglvl_t msglevel, const char *option)
Definition options.c:4799
int auth_retry_get(void)
Definition options.c:4793
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:5263
void notnull(const char *arg, const char *description)
Definition options.c:4933
void usage(void)
Definition options.c:4844
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:5551
static void options_process_mutate_prf(struct options *o)
Definition options.c:3443
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:5583
bool has_udp_in_local_list(const struct options *options)
Definition options.c:9310
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:4350
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:3268
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:3365
#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:943
void push_options(struct options *o, char **p, msglvl_t msglevel, struct gc_arena *gc)
Definition push.c:917
void clone_push_list(struct options *o)
Definition push.c:902
void push_remove_option(struct options *o, const char *p)
Definition push.c:949
void print_route_options(const struct route_option_list *rol, msglvl_t msglevel)
Definition route.c:1240
bool is_special_addr(const char *addr_str)
Definition route.c:301
struct route_option_list * clone_route_option_list(const struct route_option_list *src, struct gc_arena *a)
Definition route.c:155
int netmask_to_netbits2(in_addr_t netmask)
Definition route.c:3895
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:108
int tun_mtu
the (user) configured tun-mtu.
Definition mtu.h:142
Garbage collection arena used to keep track of dynamically allocated memory.
Definition buffer.h:116
Definition list.h:53
const char * name
Definition proxy.h:39
const char * content
Definition proxy.h:40
const char * auth_file
Definition proxy.h:55
const char * http_version
Definition proxy.h:57
const char * port
Definition proxy.h:47
bool inline_creds
Definition proxy.h:60
const char * user_agent
Definition proxy.h:58
const char * auth_method_string
Definition proxy.h:54
struct http_custom_header custom_headers[MAX_CUSTOM_HTTP_HEADER]
Definition proxy.h:59
const char * auth_file_up
Definition proxy.h:56
const char * server
Definition proxy.h:46
struct iroute_ipv6 * next
Definition route.h:271
unsigned int netbits
Definition route.h:270
struct in6_addr network
Definition route.h:269
in_addr_t network
Definition route.h:262
int netbits
Definition route.h:263
struct iroute * next
Definition route.h:264
const char * cipher
const name of the cipher
Definition crypto.h:142
const char * digest
Message digest static parameters.
Definition crypto.h:143
Definition options.h:100
const char * port
Definition options.h:102
int proto
Definition options.h:103
const char * local
Definition options.h:101
struct local_entry ** array
Definition options.h:196
int capacity
Definition options.h:194
struct tuntap_options tuntap_options
Definition options.h:65
int ping_rec_timeout_action
Definition options.h:89
bool tuntap_options_defined
Definition options.h:64
bool routes_ipv6_defined
Definition options.h:73
struct route_option_list * routes
Definition options.h:71
struct compress_options comp
Definition options.h:92
const char * ciphername
Definition options.h:84
const char * ifconfig_local
Definition options.h:67
struct dns_options dns_options
Definition options.h:82
const char * route_default_gateway
Definition options.h:76
const char * ifconfig_ipv6_local
Definition options.h:68
const char * authname
Definition options.h:85
struct route_ipv6_option_list * routes_ipv6
Definition options.h:74
bool client_nat_defined
Definition options.h:79
struct client_nat_option_list * client_nat
Definition options.h:80
const char * route_ipv6_default_gateway
Definition options.h:77
int resolve_retry_seconds
Definition options.h: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
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 max_clients
Definition options.h:533
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
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:131
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:6249
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:6278
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