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