]> git.ipfire.org Git - thirdparty/openvpn.git/blame - src/openvpn/options.h
Fix a null-pointer dereference in establish_http_proxy_passthru()
[thirdparty/openvpn.git] / src / openvpn / options.h
CommitLineData
6fbf66fa
JY
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 *
58716979 8 * Copyright (C) 2002-2017 OpenVPN Technologies, Inc. <sales@openvpn.net>
6fbf66fa
JY
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2
12 * as published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program (see the file COPYING included with this
21 * distribution); if not, write to the Free Software Foundation, Inc.,
22 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */
24
25/*
26 * 2004-01-28: Added Socks5 proxy support
27 * (Christof Meerwald, http://cmeerw.org)
28 */
29
30#ifndef OPTIONS_H
31#define OPTIONS_H
32
33#include "basic.h"
34#include "common.h"
35#include "mtu.h"
36#include "route.h"
37#include "tun.h"
38#include "socket.h"
39#include "plugin.h"
40#include "manage.h"
41#include "proxy.h"
38d96bd7 42#include "comp.h"
3eee126e 43#include "pushlist.h"
581bef87 44#include "clinat.h"
2193d7c0
DS
45#ifdef ENABLE_CRYPTO
46#include "crypto_backend.h"
47#endif
48
6fbf66fa
JY
49
50/*
51 * Maximum number of parameters associated with an option,
52 * including the option name itself.
53 */
54#define MAX_PARMS 16
55
56/*
57 * Max size of options line and parameter.
58 */
59#define OPTION_PARM_SIZE 256
60#define OPTION_LINE_SIZE 256
61
62extern const char title_string[];
63
64#if P2MP
65
6fbf66fa
JY
66/* certain options are saved before --pull modifications are applied */
67struct options_pre_pull
68{
81d882d5
DS
69 bool tuntap_options_defined;
70 struct tuntap_options tuntap_options;
6fbf66fa 71
81d882d5
DS
72 bool routes_defined;
73 struct route_option_list *routes;
6fbf66fa 74
81d882d5
DS
75 bool routes_ipv6_defined;
76 struct route_ipv6_option_list *routes_ipv6;
91402236 77
81d882d5
DS
78 bool client_nat_defined;
79 struct client_nat_option_list *client_nat;
581bef87 80
81d882d5 81 int foreign_option_index;
6fbf66fa
JY
82};
83
253329a8 84#endif
86d8cd68 85#if defined(ENABLE_CRYPTO) && !defined(ENABLE_CRYPTO_OPENSSL) && !defined(ENABLE_CRYPTO_MBEDTLS)
81d882d5 86#error "At least one of OpenSSL or mbed TLS needs to be defined."
6fbf66fa
JY
87#endif
88
4e9a51d7
JY
89struct connection_entry
90{
81d882d5
DS
91 int proto;
92 sa_family_t af;
93 const char *local_port;
94 bool local_port_defined;
95 const char *remote_port;
96 const char *local;
97 const char *remote;
98 bool remote_float;
99 bool bind_defined;
100 bool bind_ipv6_only;
101 bool bind_local;
102 int connect_retry_seconds;
103 int connect_retry_seconds_max;
104 int connect_timeout;
105 struct http_proxy_options *http_proxy_options;
106 const char *socks_proxy_server;
107 const char *socks_proxy_port;
108 const char *socks_proxy_authfile;
109
110 int tun_mtu; /* MTU of tun device */
111 bool tun_mtu_defined; /* true if user overriding parm with command line option */
112 int tun_mtu_extra;
113 bool tun_mtu_extra_defined;
114 int link_mtu; /* MTU of device over which tunnel packets pass via TCP/UDP */
115 bool link_mtu_defined; /* true if user overriding parm with command line option */
116
117 /* Advanced MTU negotiation and datagram fragmentation options */
118 int mtu_discover_type; /* used if OS supports setting Path MTU discovery options on socket */
119
120 int fragment; /* internal fragmentation size */
121 int mssfix; /* Upper bound on TCP MSS */
122 bool mssfix_default; /* true if --mssfix was supplied without a parameter */
123
124 int explicit_exit_notification; /* Explicitly tell peer when we are exiting via OCC_EXIT or [RESTART] message */
125
126#define CE_DISABLED (1<<0)
127#define CE_MAN_QUERY_PROXY (1<<1)
128#define CE_MAN_QUERY_REMOTE_UNDEF 0
129#define CE_MAN_QUERY_REMOTE_QUERY 1
130#define CE_MAN_QUERY_REMOTE_ACCEPT 2
131#define CE_MAN_QUERY_REMOTE_MOD 3
132#define CE_MAN_QUERY_REMOTE_SKIP 4
133#define CE_MAN_QUERY_REMOTE_MASK (0x07)
134#define CE_MAN_QUERY_REMOTE_SHIFT (2)
135 unsigned int flags;
4e9a51d7
JY
136};
137
138struct remote_entry
139{
81d882d5
DS
140 const char *remote;
141 const char *remote_port;
142 int proto;
143 sa_family_t af;
4e9a51d7
JY
144};
145
4e9a51d7
JY
146#define CONNECTION_LIST_SIZE 64
147
148struct connection_list
149{
81d882d5
DS
150 int len;
151 int current;
152 struct connection_entry *array[CONNECTION_LIST_SIZE];
4e9a51d7
JY
153};
154
155struct remote_list
156{
81d882d5
DS
157 int len;
158 struct remote_entry *array[CONNECTION_LIST_SIZE];
4e9a51d7
JY
159};
160
54561af6
JY
161struct remote_host_store
162{
81d882d5
DS
163#define RH_HOST_LEN 80
164 char host[RH_HOST_LEN];
076fd3e4 165#define RH_PORT_LEN 20
81d882d5 166 char port[RH_PORT_LEN];
54561af6 167};
54561af6 168
6fbf66fa
JY
169/* Command line options */
170struct options
171{
81d882d5
DS
172 struct gc_arena gc;
173 bool gc_owned;
6fbf66fa 174
81d882d5
DS
175 /* first config file */
176 const char *config;
6fbf66fa 177
81d882d5
DS
178 /* major mode */
179#define MODE_POINT_TO_POINT 0
180#define MODE_SERVER 1
181 int mode;
6fbf66fa 182
81d882d5
DS
183 /* enable forward compatibility for post-2.1 features */
184 bool forward_compatible;
185 /* list of options that should be ignored even if unkown */
186 const char **ignore_unknown_option;
373faab1 187
81d882d5
DS
188 /* persist parms */
189 bool persist_config;
190 int persist_mode;
6fbf66fa 191
9b33b5a4 192#ifdef ENABLE_CRYPTO
81d882d5
DS
193 const char *key_pass_file;
194 bool show_ciphers;
195 bool show_digests;
196 bool show_engines;
197 bool show_tls_ciphers;
198 bool show_curves;
199 bool genkey;
200#endif
201
202 /* Networking parms */
203 int connect_retry_max;
204 struct connection_entry ce;
205 struct connection_list *connection_list;
206
207 struct remote_list *remote_list;
208 /* Do not advanced the connection or remote addr list*/
209 bool no_advance;
210 /* Counts the number of unsuccessful connection attempts */
211 unsigned int unsuccessful_attempts;
4e9a51d7 212
a4b8f653 213#if ENABLE_MANAGEMENT
81d882d5
DS
214 struct http_proxy_options *http_proxy_override;
215#endif
216
217 struct remote_host_store *rh_store;
218
219 bool remote_random;
220 const char *ipchange;
221 const char *dev;
222 const char *dev_type;
223 const char *dev_node;
224 const char *lladdr;
225 int topology; /* one of the TOP_x values from proto.h */
226 const char *ifconfig_local;
227 const char *ifconfig_remote_netmask;
228 const char *ifconfig_ipv6_local;
229 int ifconfig_ipv6_netbits;
230 const char *ifconfig_ipv6_remote;
231 bool ifconfig_noexec;
232 bool ifconfig_nowarn;
3d163bc5 233#ifdef ENABLE_FEATURE_SHAPER
81d882d5 234 int shaper;
6fbf66fa 235#endif
6fbf66fa 236
81d882d5 237 int proto_force;
51e6e5b0 238
6fbf66fa 239#ifdef ENABLE_OCC
81d882d5 240 bool mtu_test;
6fbf66fa
JY
241#endif
242
ffea644c 243#ifdef ENABLE_MEMSTATS
81d882d5 244 char *memstats_fn;
ffea644c
JY
245#endif
246
81d882d5 247 bool mlock;
6fbf66fa 248
81d882d5
DS
249 int keepalive_ping; /* a proxy for ping/ping-restart */
250 int keepalive_timeout;
6fbf66fa 251
81d882d5
DS
252 int inactivity_timeout; /* --inactive */
253 int inactivity_minimum_bytes;
838911cc 254
81d882d5
DS
255 int ping_send_timeout; /* Send a TCP/UDP ping to remote every n seconds */
256 int ping_rec_timeout; /* Expect a TCP/UDP ping from remote at least once every n seconds */
257 bool ping_timer_remote; /* Run ping timer only if we have a remote address */
6fbf66fa 258
81d882d5
DS
259#define PING_UNDEF 0
260#define PING_EXIT 1
261#define PING_RESTART 2
262 int ping_rec_timeout_action; /* What action to take on ping_rec_timeout (exit or restart)? */
6fbf66fa 263
81d882d5
DS
264 bool persist_tun; /* Don't close/reopen TUN/TAP dev on SIGUSR1 or PING_RESTART */
265 bool persist_local_ip; /* Don't re-resolve local address on SIGUSR1 or PING_RESTART */
266 bool persist_remote_ip; /* Don't re-resolve remote address on SIGUSR1 or PING_RESTART */
267 bool persist_key; /* Don't re-read key files on SIGUSR1 or PING_RESTART */
6fbf66fa 268
6fbf66fa 269#if PASSTOS_CAPABILITY
81d882d5 270 bool passtos;
6fbf66fa
JY
271#endif
272
81d882d5
DS
273 int resolve_retry_seconds; /* If hostname resolve fails, retry for n seconds */
274 bool resolve_in_advance;
275 const char *ip_remote_hint;
6fbf66fa 276
81d882d5 277 struct tuntap_options tuntap_options;
6fbf66fa 278
81d882d5
DS
279 /* Misc parms */
280 const char *username;
281 const char *groupname;
282 const char *chroot_dir;
283 const char *cd_dir;
cd5990e0 284#ifdef ENABLE_SELINUX
81d882d5 285 char *selinux_context;
99385447 286#endif
81d882d5
DS
287 const char *writepid;
288 const char *up_script;
289 const char *down_script;
290 bool user_script_used;
291 bool down_pre;
292 bool up_delay;
293 bool up_restart;
294 bool daemon;
6fbf66fa 295
81d882d5 296 int remap_sigusr1;
6fbf66fa 297
81d882d5
DS
298 /* inetd modes defined in socket.h */
299 int inetd;
6fbf66fa 300
81d882d5
DS
301 bool log;
302 bool suppress_timestamps;
303 bool machine_readable_output;
304 int nice;
305 int verbosity;
306 int mute;
6fbf66fa
JY
307
308#ifdef ENABLE_DEBUG
81d882d5 309 int gremlin;
6fbf66fa
JY
310#endif
311
81d882d5
DS
312 const char *status_file;
313 int status_file_version;
314 int status_file_update_freq;
6fbf66fa 315
81d882d5
DS
316 /* optimize TUN/TAP/UDP writes */
317 bool fast_io;
6fbf66fa 318
38d96bd7 319#ifdef USE_COMP
81d882d5
DS
320 struct compress_options comp;
321#endif
322
323 /* buffer sizes */
324 int rcvbuf;
325 int sndbuf;
326
327 /* mark value */
328 int mark;
329
330 /* socket flags */
331 unsigned int sockflags;
332
333 /* route management */
334 const char *route_script;
335 const char *route_predown_script;
336 const char *route_default_gateway;
337 int route_default_metric;
338 bool route_noexec;
339 int route_delay;
340 int route_delay_window;
341 bool route_delay_defined;
342 struct route_option_list *routes;
343 struct route_ipv6_option_list *routes_ipv6; /* IPv6 */
344 bool route_nopull;
345 bool route_gateway_via_dhcp;
346 bool allow_pull_fqdn; /* as a client, allow server to push a FQDN for certain parameters */
347 struct client_nat_option_list *client_nat;
581bef87 348
6fbf66fa 349#ifdef ENABLE_OCC
81d882d5
DS
350 /* Enable options consistency check between peers */
351 bool occ;
6fbf66fa
JY
352#endif
353
354#ifdef ENABLE_MANAGEMENT
81d882d5
DS
355 const char *management_addr;
356 const char *management_port;
357 const char *management_user_pass;
358 int management_log_history_cache;
359 int management_echo_buffer_size;
360 int management_state_buffer_size;
361 const char *management_write_peer_info_file;
90efcacb 362
81d882d5
DS
363 const char *management_client_user;
364 const char *management_client_group;
bb564a59 365
81d882d5
DS
366 /* Mask of MF_ values of manage.h */
367 unsigned int management_flags;
368 const char *management_certificate;
6fbf66fa
JY
369#endif
370
371#ifdef ENABLE_PLUGIN
81d882d5 372 struct plugin_option_list *plugin_list;
6fbf66fa
JY
373#endif
374
ea5e091e 375
b70d99fb 376
6fbf66fa
JY
377#if P2MP
378
379#if P2MP_SERVER
81d882d5
DS
380 /* the tmp dir is for now only used in the P2P server context */
381 const char *tmp_dir;
382 bool server_defined;
383 in_addr_t server_network;
384 in_addr_t server_netmask;
385 bool server_ipv6_defined; /* IPv6 */
386 struct in6_addr server_network_ipv6; /* IPv6 */
387 unsigned int server_netbits_ipv6; /* IPv6 */
388
389#define SF_NOPOOL (1<<0)
390#define SF_TCP_NODELAY_HELPER (1<<1)
391#define SF_NO_PUSH_ROUTE_GATEWAY (1<<2)
392 unsigned int server_flags;
393
394 bool server_bridge_proxy_dhcp;
395
396 bool server_bridge_defined;
397 in_addr_t server_bridge_ip;
398 in_addr_t server_bridge_netmask;
399 in_addr_t server_bridge_pool_start;
400 in_addr_t server_bridge_pool_end;
401
402 struct push_list push_list;
403 bool ifconfig_pool_defined;
404 in_addr_t ifconfig_pool_start;
405 in_addr_t ifconfig_pool_end;
406 in_addr_t ifconfig_pool_netmask;
407 const char *ifconfig_pool_persist_filename;
408 int ifconfig_pool_persist_refresh_freq;
409
410 bool ifconfig_ipv6_pool_defined; /* IPv6 */
411 struct in6_addr ifconfig_ipv6_pool_base; /* IPv6 */
412 int ifconfig_ipv6_pool_netbits; /* IPv6 */
413
414 int real_hash_size;
415 int virtual_hash_size;
416 const char *client_connect_script;
417 const char *client_disconnect_script;
418 const char *learn_address_script;
419 const char *client_config_dir;
420 bool ccd_exclusive;
421 bool disable;
422 int n_bcast_buf;
423 int tcp_queue_limit;
424 struct iroute *iroutes;
425 struct iroute_ipv6 *iroutes_ipv6; /* IPv6 */
426 bool push_ifconfig_defined;
427 in_addr_t push_ifconfig_local;
428 in_addr_t push_ifconfig_remote_netmask;
429 in_addr_t push_ifconfig_local_alias;
430 bool push_ifconfig_constraint_defined;
431 in_addr_t push_ifconfig_constraint_network;
432 in_addr_t push_ifconfig_constraint_netmask;
433 bool push_ifconfig_ipv6_defined; /* IPv6 */
434 struct in6_addr push_ifconfig_ipv6_local; /* IPv6 */
435 int push_ifconfig_ipv6_netbits; /* IPv6 */
436 struct in6_addr push_ifconfig_ipv6_remote; /* IPv6 */
437 bool push_ifconfig_ipv6_blocked; /* IPv6 */
438 bool enable_c2c;
439 bool duplicate_cn;
440 int cf_max;
441 int cf_per;
442 int max_clients;
443 int max_routes_per_client;
444 int stale_routes_check_interval;
445 int stale_routes_ageing_time;
446
447 const char *auth_user_pass_verify_script;
448 bool auth_user_pass_verify_script_via_file;
449 bool auth_token_generate;
450 unsigned int auth_token_lifetime;
6add6b2f 451#if PORT_SHARE
81d882d5
DS
452 char *port_share_host;
453 char *port_share_port;
454 const char *port_share_journal_dir;
6fbf66fa 455#endif
81d882d5 456#endif /* if P2MP_SERVER */
6fbf66fa 457
81d882d5
DS
458 bool client;
459 bool pull; /* client pull of config options from server */
460 int push_continuation;
461 unsigned int push_option_types_found;
462 const char *auth_user_pass_file;
463 struct options_pre_pull *pre_pull;
6fbf66fa 464
81d882d5 465 int scheduled_exit_interval;
6fbf66fa 466
75987303 467#ifdef ENABLE_CLIENT_CR
81d882d5 468 struct static_challenge_info sc_info;
6fbf66fa 469#endif
81d882d5 470#endif /* if P2MP */
6fbf66fa 471
9b33b5a4 472#ifdef ENABLE_CRYPTO
81d882d5
DS
473 /* Cipher parms */
474 const char *shared_secret_file;
475 const char *shared_secret_file_inline;
476 int key_direction;
477 const char *ciphername;
478 bool ncp_enabled;
479 const char *ncp_ciphers;
480 const char *authname;
481 int keysize;
482 const char *prng_hash;
483 int prng_nonce_secret_len;
484 const char *engine;
485 bool replay;
486 bool mute_replay_warnings;
487 int replay_window;
488 int replay_time;
489 const char *packet_id_file;
81d882d5 490 bool test_crypto;
0f25d296 491#ifdef ENABLE_PREDICTION_RESISTANCE
81d882d5
DS
492 bool use_prediction_resistance;
493#endif
494
495 /* TLS (control channel) parms */
496 bool tls_server;
497 bool tls_client;
498 const char *ca_file;
499 const char *ca_path;
500 const char *dh_file;
501 const char *cert_file;
502 const char *extra_certs_file;
503 const char *priv_key_file;
504 const char *pkcs12_file;
505 const char *cipher_list;
506 const char *ecdh_curve;
507 const char *tls_verify;
508 int verify_x509_type;
509 const char *verify_x509_name;
510 const char *tls_export_cert;
511 const char *crl_file;
512
513 const char *ca_file_inline;
514 const char *cert_file_inline;
515 const char *extra_certs_file_inline;
516 const char *crl_file_inline;
517 char *priv_key_file_inline;
518 const char *dh_file_inline;
519 const char *pkcs12_file_inline; /* contains the base64 encoding of pkcs12 file */
520
521 int ns_cert_type; /* set to 0, NS_CERT_CHECK_SERVER, or NS_CERT_CHECK_CLIENT */
522 unsigned remote_cert_ku[MAX_PARMS];
523 const char *remote_cert_eku;
524 uint8_t *verify_hash;
2193d7c0 525 hash_algo_type verify_hash_algo;
81d882d5 526 unsigned int ssl_flags; /* set to SSLF_x flags from ssl.h */
bed73623
JY
527
528#ifdef ENABLE_PKCS11
81d882d5
DS
529 const char *pkcs11_providers[MAX_PARMS];
530 unsigned pkcs11_private_mode[MAX_PARMS];
531 bool pkcs11_protected_authentication[MAX_PARMS];
532 bool pkcs11_cert_private[MAX_PARMS];
533 int pkcs11_pin_cache_period;
534 const char *pkcs11_id;
535 bool pkcs11_id_management;
bed73623
JY
536#endif
537
93c22ecc 538#ifdef ENABLE_CRYPTOAPI
81d882d5 539 const char *cryptoapi_cert;
6fbf66fa
JY
540#endif
541
81d882d5
DS
542 /* data channel key exchange method */
543 int key_method;
6fbf66fa 544
81d882d5
DS
545 /* Per-packet timeout on control channel */
546 int tls_timeout;
6fbf66fa 547
81d882d5
DS
548 /* Data channel key renegotiation parameters */
549 int renegotiate_bytes;
550 int renegotiate_packets;
551 int renegotiate_seconds;
6fbf66fa 552
81d882d5
DS
553 /* Data channel key handshake must finalize
554 * within n seconds of handshake initiation. */
555 int handshake_window;
6fbf66fa 556
fbd18db6 557#ifdef ENABLE_X509ALTUSERNAME
81d882d5
DS
558 /* Field used to be the username in X509 cert. */
559 char *x509_username_field;
fbd18db6 560#endif
2e8337de 561
81d882d5
DS
562 /* Old key allowed to live n seconds after new key goes active */
563 int transition_window;
6fbf66fa 564
81d882d5
DS
565 /* Shared secret used for TLS control channel authentication */
566 const char *tls_auth_file;
567 const char *tls_auth_file_inline;
6fbf66fa 568
81d882d5
DS
569 /* Shared secret used for TLS control channel authenticated encryption */
570 const char *tls_crypt_file;
571 const char *tls_crypt_inline;
c6e24fa3 572
81d882d5
DS
573 /* Allow only one session */
574 bool single_session;
6fbf66fa 575
aaf72974 576#ifdef ENABLE_PUSH_PEER_INFO
81d882d5 577 bool push_peer_info;
aaf72974
JY
578#endif
579
81d882d5 580 bool tls_exit;
6fbf66fa 581
9b33b5a4 582#endif /* ENABLE_CRYPTO */
6fbf66fa 583
81d882d5 584 const struct x509_track *x509_track;
9356bae8 585
81d882d5
DS
586 /* special state parms */
587 int foreign_option_index;
6fbf66fa 588
445b192a 589#ifdef _WIN32
81d882d5
DS
590 HANDLE msg_channel;
591 const char *exit_event_name;
592 bool exit_event_initial_state;
593 bool show_net_up;
594 int route_method;
595 bool block_outside_dns;
6fbf66fa 596#endif
65eedc35 597
81d882d5
DS
598 bool use_peer_id;
599 uint32_t peer_id;
685e486e
DK
600
601#if defined(ENABLE_CRYPTO_OPENSSL) && OPENSSL_VERSION_NUMBER >= 0x10001000
81d882d5
DS
602 /* Keying Material Exporters [RFC 5705] */
603 const char *keying_material_exporter_label;
604 int keying_material_exporter_length;
685e486e 605#endif
7f74c27e 606
81d882d5 607 struct pull_filter_list *pull_filter_list;
e8c42658 608
81d882d5
DS
609 /* Useful when packets sent by openvpn itself are not subject
610 * to the routing tables that would move packets into the tunnel. */
611 bool allow_recursive_routing;
6fbf66fa
JY
612};
613
614#define streq(x, y) (!strcmp((x), (y)))
615
616/*
617 * Option classes.
618 */
619#define OPT_P_GENERAL (1<<0)
620#define OPT_P_UP (1<<1)
621#define OPT_P_ROUTE (1<<2)
622#define OPT_P_IPWIN32 (1<<3)
623#define OPT_P_SCRIPT (1<<4)
624#define OPT_P_SETENV (1<<5)
625#define OPT_P_SHAPER (1<<6)
626#define OPT_P_TIMER (1<<7)
627#define OPT_P_PERSIST (1<<8)
628#define OPT_P_PERSIST_IP (1<<9)
629#define OPT_P_COMP (1<<10) /* TODO */
630#define OPT_P_MESSAGES (1<<11)
d728ebed 631#define OPT_P_NCP (1<<12) /**< Negotiable crypto parameters */
6fbf66fa
JY
632#define OPT_P_TLS_PARMS (1<<13) /* TODO */
633#define OPT_P_MTU (1<<14) /* TODO */
634#define OPT_P_NICE (1<<15)
635#define OPT_P_PUSH (1<<16)
636#define OPT_P_INSTANCE (1<<17)
637#define OPT_P_CONFIG (1<<18)
638#define OPT_P_EXPLICIT_NOTIFY (1<<19)
639#define OPT_P_ECHO (1<<20)
640#define OPT_P_INHERIT (1<<21)
3c7f2f55
JY
641#define OPT_P_ROUTE_EXTRAS (1<<22)
642#define OPT_P_PULL_MODE (1<<23)
643#define OPT_P_PLUGIN (1<<24)
00d39170
JY
644#define OPT_P_SOCKBUF (1<<25)
645#define OPT_P_SOCKFLAGS (1<<26)
4e9a51d7 646#define OPT_P_CONNECTION (1<<27)
65eedc35 647#define OPT_P_PEER_ID (1<<28)
6fbf66fa 648
3c7f2f55 649#define OPT_P_DEFAULT (~(OPT_P_INSTANCE|OPT_P_PULL_MODE))
6fbf66fa
JY
650
651#if P2MP
652#define PULL_DEFINED(opt) ((opt)->pull)
653#if P2MP_SERVER
654#define PUSH_DEFINED(opt) ((opt)->push_list)
655#endif
656#endif
657
658#ifndef PULL_DEFINED
659#define PULL_DEFINED(opt) (false)
660#endif
661
662#ifndef PUSH_DEFINED
663#define PUSH_DEFINED(opt) (false)
664#endif
665
445b192a 666#ifdef _WIN32
6fbf66fa
JY
667#define ROUTE_OPTION_FLAGS(o) ((o)->route_method & ROUTE_METHOD_MASK)
668#else
669#define ROUTE_OPTION_FLAGS(o) (0)
670#endif
671
3d163bc5 672#ifdef ENABLE_FEATURE_SHAPER
6fbf66fa
JY
673#define SHAPER_DEFINED(opt) ((opt)->shaper)
674#else
675#define SHAPER_DEFINED(opt) (false)
676#endif
677
678#ifdef ENABLE_PLUGIN
679#define PLUGIN_OPTION_LIST(opt) ((opt)->plugin_list)
680#else
681#define PLUGIN_OPTION_LIST(opt) (NULL)
682#endif
683
90efcacb
JY
684#ifdef MANAGEMENT_DEF_AUTH
685#define MAN_CLIENT_AUTH_ENABLED(opt) ((opt)->management_flags & MF_CLIENT_AUTH)
686#else
687#define MAN_CLIENT_AUTH_ENABLED(opt) (false)
688#endif
689
81d882d5
DS
690void parse_argv(struct options *options,
691 const int argc,
692 char *argv[],
693 const int msglevel,
694 const unsigned int permission_mask,
695 unsigned int *option_types_found,
696 struct env_set *es);
6fbf66fa 697
81d882d5 698void notnull(const char *arg, const char *description);
6fbf66fa 699
81d882d5 700void usage_small(void);
6fbf66fa 701
5b17803e
JY
702void show_library_versions(const unsigned int flags);
703
445b192a 704#ifdef _WIN32
cdc65ea0 705void show_windows_version(const unsigned int flags);
81d882d5 706
cdc65ea0
LS
707#endif
708
81d882d5
DS
709void init_options(struct options *o, const bool init_gc);
710
711void uninit_options(struct options *o);
6fbf66fa 712
81d882d5 713void setenv_settings(struct env_set *es, const struct options *o);
6fbf66fa 714
81d882d5
DS
715void show_settings(const struct options *o);
716
717bool string_defined_equal(const char *s1, const char *s2);
6fbf66fa
JY
718
719#ifdef ENABLE_OCC
720
81d882d5
DS
721const char *options_string_version(const char *s, struct gc_arena *gc);
722
723char *options_string(const struct options *o,
724 const struct frame *frame,
725 struct tuntap *tt,
726 bool remote,
727 struct gc_arena *gc);
728
729bool options_cmp_equal_safe(char *actual, const char *expected, size_t actual_n);
6fbf66fa 730
81d882d5 731void options_warning_safe(char *actual, const char *expected, size_t actual_n);
6fbf66fa 732
81d882d5
DS
733bool options_cmp_equal(char *actual, const char *expected);
734
735void options_warning(char *actual, const char *expected);
6fbf66fa
JY
736
737#endif
738
6e5ad2fa
SK
739/**
740 * Given an OpenVPN options string, extract the value of an option.
741 *
81d882d5
DS
742 * @param options_string Zero-terminated, comma-separated options string
743 * @param opt_name The name of the option to extract
744 * @param gc The gc to allocate the return value
6e5ad2fa
SK
745 *
746 * @return gc-allocated value of option with name opt_name if option was found,
747 * or NULL otherwise.
748 */
81d882d5
DS
749char *options_string_extract_option(const char *options_string,
750 const char *opt_name, struct gc_arena *gc);
751
6e5ad2fa 752
81d882d5 753void options_postprocess(struct options *options);
6e5ad2fa 754
81d882d5 755void pre_pull_save(struct options *o);
6fbf66fa 756
81d882d5 757void pre_pull_restore(struct options *o, struct gc_arena *gc);
6fbf66fa 758
81d882d5
DS
759bool apply_push_options(struct options *options,
760 struct buffer *buf,
761 unsigned int permission_mask,
762 unsigned int *option_types_found,
763 struct env_set *es);
6fbf66fa 764
81d882d5 765void options_detach(struct options *o);
6fbf66fa 766
81d882d5
DS
767void options_server_import(struct options *o,
768 const char *filename,
769 int msglevel,
770 unsigned int permission_mask,
771 unsigned int *option_types_found,
772 struct env_set *es);
6fbf66fa 773
81d882d5 774void pre_pull_default(struct options *o);
6fbf66fa 775
81d882d5 776void rol_check_alloc(struct options *options);
6fbf66fa 777
81d882d5
DS
778int parse_line(const char *line,
779 char *p[],
780 const int n,
781 const char *file,
782 const int line_num,
783 int msglevel,
784 struct gc_arena *gc);
6fbf66fa 785
3c7f2f55
JY
786/*
787 * parse/print topology coding
788 */
789
81d882d5
DS
790int parse_topology(const char *str, const int msglevel);
791
792const char *print_topology(const int topology);
3c7f2f55 793
6fbf66fa
JY
794/*
795 * Manage auth-retry variable
796 */
797
798#if P2MP
799
800#define AR_NONE 0
801#define AR_INTERACT 1
802#define AR_NOINTERACT 2
803
81d882d5
DS
804int auth_retry_get(void);
805
806bool auth_retry_set(const int msglevel, const char *option);
807
808const char *auth_retry_print(void);
6fbf66fa
JY
809
810#endif
811
81d882d5
DS
812void options_string_import(struct options *options,
813 const char *config,
814 const int msglevel,
815 const unsigned int permission_mask,
816 unsigned int *option_types_found,
817 struct env_set *es);
3c7f2f55 818
81d882d5
DS
819bool get_ipv6_addr( const char *prefix_str, struct in6_addr *network,
820 unsigned int *netbits, int msglevel );
512cda46 821
4e9a51d7 822
81d882d5 823#endif /* ifndef OPTIONS_H */