]> git.ipfire.org Git - thirdparty/openvpn.git/blame - options.h
Added support for building and linking with
[thirdparty/openvpn.git] / 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 *
8 * Copyright (C) 2002-2005 OpenVPN Solutions LLC <info@openvpn.net>
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"
537073fd 42#include "lzo.h"
6fbf66fa
JY
43
44/*
45 * Maximum number of parameters associated with an option,
46 * including the option name itself.
47 */
48#define MAX_PARMS 16
49
50/*
51 * Max size of options line and parameter.
52 */
53#define OPTION_PARM_SIZE 256
54#define OPTION_LINE_SIZE 256
55
56extern const char title_string[];
57
58#if P2MP
59
60#if P2MP_SERVER
61/* parameters to be pushed to peer */
62
63#define MAX_PUSH_LIST_LEN TLS_CHANNEL_BUF_SIZE /* This parm is related to PLAINTEXT_BUFFER_SIZE in ssl.h */
64
65struct push_list {
66 /* newline delimited options, like config file */
67 char options[MAX_PUSH_LIST_LEN];
68};
69#endif
70
71/* certain options are saved before --pull modifications are applied */
72struct options_pre_pull
73{
74 bool tuntap_options_defined;
75 struct tuntap_options tuntap_options;
76
77 bool routes_defined;
78 struct route_option_list routes;
79
80 int foreign_option_index;
81};
82
83#endif
84
85/* Command line options */
86struct options
87{
88 struct gc_arena gc;
89
90 /* first config file */
91 const char *config;
92
93 /* major mode */
94# define MODE_POINT_TO_POINT 0
95# define MODE_SERVER 1
96 int mode;
97
98 /* persist parms */
99 bool persist_config;
100 int persist_mode;
101
102#ifdef USE_CRYPTO
103 const char *key_pass_file;
104 bool show_ciphers;
105 bool show_digests;
106 bool show_engines;
107#ifdef USE_SSL
108 bool show_tls_ciphers;
109#endif
110 bool genkey;
111#endif
112
113 /* Networking parms */
114 const char *local;
115 int local_port;
116 bool local_port_defined;
117 int remote_port;
118 bool port_option_used;
119 bool remote_float;
120 struct remote_list *remote_list;
121 bool remote_random;
122 const char *ipchange;
04f4b793 123 bool bind_defined;
6fbf66fa
JY
124 bool bind_local;
125 const char *dev;
126 const char *dev_type;
127 const char *dev_node;
e12fe286 128 const char *lladdr;
3c7f2f55 129 int topology; /* one of the TOP_x values from proto.h */
6fbf66fa
JY
130 const char *ifconfig_local;
131 const char *ifconfig_remote_netmask;
132 bool ifconfig_noexec;
133 bool ifconfig_nowarn;
134#ifdef HAVE_GETTIMEOFDAY
135 int shaper;
136#endif
137 int tun_mtu; /* MTU of tun device */
138 int tun_mtu_extra;
139 bool tun_mtu_extra_defined;
140 int link_mtu; /* MTU of device over which tunnel packets pass via TCP/UDP */
141 bool tun_mtu_defined; /* true if user overriding parm with command line option */
142 bool link_mtu_defined; /* true if user overriding parm with command line option */
143
144 /* Protocol type (PROTO_UDP or PROTO_TCP) */
145 int proto;
146 int connect_retry_seconds;
b540a9e0 147 int connect_retry_max;
6fbf66fa 148 bool connect_retry_defined;
1ae9d051
JY
149 int connect_timeout;
150 bool connect_timeout_defined;
6fbf66fa
JY
151
152 /* Advanced MTU negotiation and datagram fragmentation options */
153 int mtu_discover_type; /* used if OS supports setting Path MTU discovery options on socket */
154
155#ifdef ENABLE_OCC
156 bool mtu_test;
157#endif
158
159 int fragment; /* internal fragmentation size */
160
161 bool mlock;
162
163 int keepalive_ping; /* a proxy for ping/ping-restart */
164 int keepalive_timeout;
165
838911cc
JY
166 int inactivity_timeout; /* --inactive */
167 int inactivity_minimum_bytes;
168
6fbf66fa
JY
169 int ping_send_timeout; /* Send a TCP/UDP ping to remote every n seconds */
170 int ping_rec_timeout; /* Expect a TCP/UDP ping from remote at least once every n seconds */
171 bool ping_timer_remote; /* Run ping timer only if we have a remote address */
172 bool tun_ipv6; /* Build tun dev that supports IPv6 */
173
174# define PING_UNDEF 0
175# define PING_EXIT 1
176# define PING_RESTART 2
177 int ping_rec_timeout_action; /* What action to take on ping_rec_timeout (exit or restart)? */
178
179#ifdef ENABLE_OCC
180 int explicit_exit_notification; /* Explicitly tell peer when we are exiting via OCC_EXIT message */
181#endif
182
183 bool persist_tun; /* Don't close/reopen TUN/TAP dev on SIGUSR1 or PING_RESTART */
184 bool persist_local_ip; /* Don't re-resolve local address on SIGUSR1 or PING_RESTART */
185 bool persist_remote_ip; /* Don't re-resolve remote address on SIGUSR1 or PING_RESTART */
186 bool persist_key; /* Don't re-read key files on SIGUSR1 or PING_RESTART */
187
188 int mssfix; /* Upper bound on TCP MSS */
189 bool mssfix_default; /* true if --mssfix was supplied without a parameter */
190
191#if PASSTOS_CAPABILITY
192 bool passtos;
193#endif
194
195 int resolve_retry_seconds; /* If hostname resolve fails, retry for n seconds */
196
197 struct tuntap_options tuntap_options;
198
199 /* Misc parms */
200 const char *username;
201 const char *groupname;
202 const char *chroot_dir;
203 const char *cd_dir;
204 const char *writepid;
205 const char *up_script;
206 const char *down_script;
207 bool down_pre;
208 bool up_delay;
209 bool up_restart;
210 bool daemon;
211
212 int remap_sigusr1;
213
214 /* inetd modes defined in socket.h */
215 int inetd;
216
217 bool log;
218 bool suppress_timestamps;
219 int nice;
220 int verbosity;
221 int mute;
222
223#ifdef ENABLE_DEBUG
224 int gremlin;
225#endif
226
227 const char *status_file;
228 int status_file_version;
229 int status_file_update_freq;
230
231 /* optimize TUN/TAP/UDP writes */
232 bool fast_io;
233
234#ifdef USE_LZO
537073fd
JY
235 /* LZO_x flags from lzo.h */
236 unsigned int lzo;
6fbf66fa
JY
237#endif
238
239 /* buffer sizes */
240 int rcvbuf;
241 int sndbuf;
242
00d39170
JY
243 /* socket flags */
244 unsigned int sockflags;
245
6fbf66fa
JY
246 /* route management */
247 const char *route_script;
248 const char *route_default_gateway;
40ac3d7a 249 int route_default_metric;
6fbf66fa
JY
250 bool route_noexec;
251 int route_delay;
252 int route_delay_window;
253 bool route_delay_defined;
254 struct route_option_list *routes;
3c7f2f55 255 bool route_nopull;
6fbf66fa 256
f214bb21
JY
257#ifdef GENERAL_PROXY_SUPPORT
258 struct auto_proxy_info *auto_proxy_info;
259#endif
260
6fbf66fa
JY
261#ifdef ENABLE_HTTP_PROXY
262 struct http_proxy_options *http_proxy_options;
263#endif
264
265#ifdef ENABLE_SOCKS
266 /* socks proxy */
267 const char *socks_proxy_server;
268 int socks_proxy_port;
269 bool socks_proxy_retry;
270#endif
271
272#ifdef ENABLE_OCC
273 /* Enable options consistency check between peers */
274 bool occ;
275#endif
276
277#ifdef ENABLE_MANAGEMENT
278 const char *management_addr;
279 int management_port;
280 const char *management_user_pass;
281 int management_log_history_cache;
282 int management_echo_buffer_size;
283 int management_state_buffer_size;
284 bool management_query_passwords;
285 bool management_hold;
1184b824 286 bool management_signal;
a032fcb7 287 bool management_forget_disconnect;
4f404ad3 288 bool management_client;
8d33c060 289 const char *management_write_peer_info_file;
6fbf66fa
JY
290#endif
291
292#ifdef ENABLE_PLUGIN
293 struct plugin_option_list *plugin_list;
294#endif
295
296#ifdef USE_PTHREAD
297 int n_threads;
298 int nice_work;
299#endif
300
301#if P2MP
302
303#if P2MP_SERVER
304 bool server_defined;
305 in_addr_t server_network;
306 in_addr_t server_netmask;
307
3c7f2f55
JY
308# define SF_NOPOOL (1<<0)
309 unsigned int server_flags;
310
6fbf66fa
JY
311 bool server_bridge_defined;
312 in_addr_t server_bridge_ip;
313 in_addr_t server_bridge_netmask;
314 in_addr_t server_bridge_pool_start;
315 in_addr_t server_bridge_pool_end;
316
317 struct push_list *push_list;
318 bool ifconfig_pool_defined;
319 in_addr_t ifconfig_pool_start;
320 in_addr_t ifconfig_pool_end;
321 in_addr_t ifconfig_pool_netmask;
322 const char *ifconfig_pool_persist_filename;
323 int ifconfig_pool_persist_refresh_freq;
6fbf66fa
JY
324 int real_hash_size;
325 int virtual_hash_size;
326 const char *client_connect_script;
327 const char *client_disconnect_script;
328 const char *learn_address_script;
329 const char *tmp_dir;
330 const char *client_config_dir;
331 bool ccd_exclusive;
332 bool disable;
333 int n_bcast_buf;
334 int tcp_queue_limit;
335 struct iroute *iroutes;
336 bool push_ifconfig_defined;
337 in_addr_t push_ifconfig_local;
338 in_addr_t push_ifconfig_remote_netmask;
3c7f2f55
JY
339 bool push_ifconfig_constraint_defined;
340 in_addr_t push_ifconfig_constraint_network;
341 in_addr_t push_ifconfig_constraint_netmask;
6fbf66fa
JY
342 bool enable_c2c;
343 bool duplicate_cn;
344 int cf_max;
345 int cf_per;
346 int max_clients;
347 int max_routes_per_client;
348
349 bool client_cert_not_required;
350 bool username_as_common_name;
351 const char *auth_user_pass_verify_script;
352 bool auth_user_pass_verify_script_via_file;
6add6b2f
JY
353#if PORT_SHARE
354 char *port_share_host;
355 int port_share_port;
356#endif
6fbf66fa
JY
357#endif
358
359 bool client;
360 bool pull; /* client pull of config options from server */
361 const char *auth_user_pass_file;
362 struct options_pre_pull *pre_pull;
363
364 int scheduled_exit_interval;
365
366#endif
367
368#ifdef USE_CRYPTO
369 /* Cipher parms */
370 const char *shared_secret_file;
c959fc74
JY
371#if ENABLE_INLINE_FILES
372 const char *shared_secret_file_inline;
373#endif
6fbf66fa
JY
374 int key_direction;
375 bool ciphername_defined;
376 const char *ciphername;
377 bool authname_defined;
378 const char *authname;
379 int keysize;
380 const char *engine;
381 bool replay;
382 bool mute_replay_warnings;
383 int replay_window;
384 int replay_time;
385 const char *packet_id_file;
386 bool use_iv;
387 bool test_crypto;
388
389#ifdef USE_SSL
390 /* TLS (control channel) parms */
391 bool tls_server;
392 bool tls_client;
393 const char *ca_file;
e9c5e170 394 const char *ca_path;
6fbf66fa
JY
395 const char *dh_file;
396 const char *cert_file;
397 const char *priv_key_file;
398 const char *pkcs12_file;
399 const char *cipher_list;
400 const char *tls_verify;
401 const char *tls_remote;
402 const char *crl_file;
d40f2b20
JY
403
404#if ENABLE_INLINE_FILES
405 const char *ca_file_inline;
406 const char *cert_file_inline;
407 char *priv_key_file_inline;
408 const char *dh_file_inline;
409#endif
410
6fbf66fa 411 int ns_cert_type; /* set to 0, NS_SSL_SERVER, or NS_SSL_CLIENT */
411e89ae
JY
412 unsigned remote_cert_ku[MAX_PARMS];
413 const char *remote_cert_eku;
bed73623
JY
414
415#ifdef ENABLE_PKCS11
ce98fd24 416 const char *pkcs11_providers[MAX_PARMS];
718526e0 417 unsigned pkcs11_private_mode[MAX_PARMS];
18597b93
JY
418 bool pkcs11_protected_authentication[MAX_PARMS];
419 bool pkcs11_cert_private[MAX_PARMS];
420 int pkcs11_pin_cache_period;
ce98fd24 421 const char *pkcs11_id;
1bda73a7 422 bool pkcs11_id_management;
bed73623
JY
423#endif
424
6fbf66fa
JY
425#ifdef WIN32
426 const char *cryptoapi_cert;
427#endif
428
429 /* data channel key exchange method */
430 int key_method;
431
432 /* Per-packet timeout on control channel */
433 int tls_timeout;
434
435 /* Data channel key renegotiation parameters */
436 int renegotiate_bytes;
437 int renegotiate_packets;
438 int renegotiate_seconds;
439
440 /* Data channel key handshake must finalize
441 within n seconds of handshake initiation. */
442 int handshake_window;
443
444 /* Old key allowed to live n seconds after new key goes active */
445 int transition_window;
446
447 /* Special authentication MAC for TLS control channel */
448 const char *tls_auth_file; /* shared secret */
c959fc74
JY
449#if ENABLE_INLINE_FILES
450 const char *tls_auth_file_inline;
451#endif
6fbf66fa
JY
452
453 /* Allow only one session */
454 bool single_session;
455
456 bool tls_exit;
457
458#endif /* USE_SSL */
459#endif /* USE_CRYPTO */
460
461 /* special state parms */
462 int foreign_option_index;
463
464#ifdef WIN32
465 const char *exit_event_name;
466 bool exit_event_initial_state;
467 bool show_net_up;
468 int route_method;
469#endif
470};
471
472#define streq(x, y) (!strcmp((x), (y)))
473
474/*
475 * Option classes.
476 */
477#define OPT_P_GENERAL (1<<0)
478#define OPT_P_UP (1<<1)
479#define OPT_P_ROUTE (1<<2)
480#define OPT_P_IPWIN32 (1<<3)
481#define OPT_P_SCRIPT (1<<4)
482#define OPT_P_SETENV (1<<5)
483#define OPT_P_SHAPER (1<<6)
484#define OPT_P_TIMER (1<<7)
485#define OPT_P_PERSIST (1<<8)
486#define OPT_P_PERSIST_IP (1<<9)
487#define OPT_P_COMP (1<<10) /* TODO */
488#define OPT_P_MESSAGES (1<<11)
489#define OPT_P_CRYPTO (1<<12) /* TODO */
490#define OPT_P_TLS_PARMS (1<<13) /* TODO */
491#define OPT_P_MTU (1<<14) /* TODO */
492#define OPT_P_NICE (1<<15)
493#define OPT_P_PUSH (1<<16)
494#define OPT_P_INSTANCE (1<<17)
495#define OPT_P_CONFIG (1<<18)
496#define OPT_P_EXPLICIT_NOTIFY (1<<19)
497#define OPT_P_ECHO (1<<20)
498#define OPT_P_INHERIT (1<<21)
3c7f2f55
JY
499#define OPT_P_ROUTE_EXTRAS (1<<22)
500#define OPT_P_PULL_MODE (1<<23)
501#define OPT_P_PLUGIN (1<<24)
00d39170
JY
502#define OPT_P_SOCKBUF (1<<25)
503#define OPT_P_SOCKFLAGS (1<<26)
6fbf66fa 504
3c7f2f55 505#define OPT_P_DEFAULT (~(OPT_P_INSTANCE|OPT_P_PULL_MODE))
6fbf66fa
JY
506
507#if P2MP
508#define PULL_DEFINED(opt) ((opt)->pull)
509#if P2MP_SERVER
510#define PUSH_DEFINED(opt) ((opt)->push_list)
511#endif
512#endif
513
514#ifndef PULL_DEFINED
515#define PULL_DEFINED(opt) (false)
516#endif
517
518#ifndef PUSH_DEFINED
519#define PUSH_DEFINED(opt) (false)
520#endif
521
522#ifdef WIN32
523#define ROUTE_OPTION_FLAGS(o) ((o)->route_method & ROUTE_METHOD_MASK)
524#else
525#define ROUTE_OPTION_FLAGS(o) (0)
526#endif
527
528#ifdef HAVE_GETTIMEOFDAY
529#define SHAPER_DEFINED(opt) ((opt)->shaper)
530#else
531#define SHAPER_DEFINED(opt) (false)
532#endif
533
534#ifdef ENABLE_PLUGIN
535#define PLUGIN_OPTION_LIST(opt) ((opt)->plugin_list)
536#else
537#define PLUGIN_OPTION_LIST(opt) (NULL)
538#endif
539
540void parse_argv (struct options *options,
541 const int argc,
542 char *argv[],
543 const int msglevel,
544 const unsigned int permission_mask,
545 unsigned int *option_types_found,
546 struct env_set *es);
547
548void notnull (const char *arg, const char *description);
549
550void usage_small (void);
551
552void init_options (struct options *o);
553void uninit_options (struct options *o);
554
555void setenv_settings (struct env_set *es, const struct options *o);
556void show_settings (const struct options *o);
557
558bool string_defined_equal (const char *s1, const char *s2);
559
560#ifdef ENABLE_OCC
561
562const char *options_string_version (const char* s, struct gc_arena *gc);
563
564char *options_string (const struct options *o,
565 const struct frame *frame,
566 struct tuntap *tt,
567 bool remote,
568 struct gc_arena *gc);
569
570int options_cmp_equal_safe (char *actual, const char *expected, size_t actual_n);
571void options_warning_safe (char *actual, const char *expected, size_t actual_n);
572int options_cmp_equal (char *actual, const char *expected);
573void options_warning (char *actual, const char *expected);
574
575#endif
576
577void options_postprocess (struct options *options, bool first_time);
578
579void pre_pull_save (struct options *o);
580void pre_pull_restore (struct options *o);
581
582bool apply_push_options (struct options *options,
583 struct buffer *buf,
584 unsigned int permission_mask,
585 unsigned int *option_types_found,
586 struct env_set *es);
587
588bool is_persist_option (const struct options *o);
589bool is_stateful_restart (const struct options *o);
590
591void options_detach (struct options *o);
592
593void options_server_import (struct options *o,
594 const char *filename,
595 int msglevel,
596 unsigned int permission_mask,
597 unsigned int *option_types_found,
598 struct env_set *es);
599
600void pre_pull_default (struct options *o);
601
602void rol_check_alloc (struct options *options);
603
604int parse_line (const char *line,
605 char *p[],
606 const int n,
607 const char *file,
608 const int line_num,
609 int msglevel,
610 struct gc_arena *gc);
611
3c7f2f55
JY
612/*
613 * parse/print topology coding
614 */
615
616int parse_topology (const char *str, const int msglevel);
617const char *print_topology (const int topology);
618
6fbf66fa
JY
619/*
620 * Manage auth-retry variable
621 */
622
623#if P2MP
624
625#define AR_NONE 0
626#define AR_INTERACT 1
627#define AR_NOINTERACT 2
628
629int auth_retry_get (void);
630bool auth_retry_set (const int msglevel, const char *option);
631const char *auth_retry_print (void);
632
633#endif
634
3c7f2f55
JY
635#ifdef ENABLE_PLUGIN
636
637void options_plugin_import (struct options *options,
638 const char *config,
639 const int msglevel,
640 const unsigned int permission_mask,
641 unsigned int *option_types_found,
642 struct env_set *es);
643
644#endif
645
6fbf66fa 646#endif