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
8 * Copyright (C) 2002-2008 OpenVPN Technologies, Inc. <sales@openvpn.net>
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.
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.
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
26 * 2004-01-28: Added Socks5 proxy support
27 * (Christof Meerwald, http://cmeerw.org)
45 * Maximum number of parameters associated with an option,
46 * including the option name itself.
51 * Max size of options line and parameter.
53 #define OPTION_PARM_SIZE 256
54 #define OPTION_LINE_SIZE 256
56 extern const char title_string
[];
61 /* parameters to be pushed to peer */
63 #define MAX_PUSH_LIST_LEN TLS_CHANNEL_BUF_SIZE /* This parm is related to PLAINTEXT_BUFFER_SIZE in ssl.h */
66 /* newline delimited options, like config file */
67 char options
[MAX_PUSH_LIST_LEN
];
71 /* certain options are saved before --pull modifications are applied */
72 struct options_pre_pull
74 bool tuntap_options_defined
;
75 struct tuntap_options tuntap_options
;
78 struct route_option_list routes
;
80 int foreign_option_index
;
85 struct connection_entry
89 bool local_port_defined
;
91 bool port_option_used
;
97 int connect_retry_seconds
;
98 bool connect_retry_defined
;
99 int connect_retry_max
;
101 bool connect_timeout_defined
;
102 #ifdef ENABLE_HTTP_PROXY
103 struct http_proxy_options
*http_proxy_options
;
106 const char *socks_proxy_server
;
107 int socks_proxy_port
;
108 bool socks_proxy_retry
;
119 #ifdef ENABLE_CONNECTION
121 #define CONNECTION_LIST_SIZE 64
123 struct connection_list
128 struct connection_entry
*array
[CONNECTION_LIST_SIZE
];
134 struct remote_entry
*array
[CONNECTION_LIST_SIZE
];
139 /* Command line options */
145 /* first config file */
149 # define MODE_POINT_TO_POINT 0
150 # define MODE_SERVER 1
158 const char *key_pass_file
;
163 bool show_tls_ciphers
;
168 /* Networking parms */
169 struct connection_entry ce
;
171 #ifdef ENABLE_CONNECTION
172 struct connection_list
*connection_list
;
173 struct remote_list
*remote_list
;
176 #ifdef GENERAL_PROXY_SUPPORT
177 struct auto_proxy_info
*auto_proxy_info
;
181 const char *ipchange
;
183 const char *dev_type
;
184 const char *dev_node
;
186 int topology
; /* one of the TOP_x values from proto.h */
187 const char *ifconfig_local
;
188 const char *ifconfig_remote_netmask
;
189 bool ifconfig_noexec
;
190 bool ifconfig_nowarn
;
191 #ifdef HAVE_GETTIMEOFDAY
194 int tun_mtu
; /* MTU of tun device */
196 bool tun_mtu_extra_defined
;
197 int link_mtu
; /* MTU of device over which tunnel packets pass via TCP/UDP */
198 bool tun_mtu_defined
; /* true if user overriding parm with command line option */
199 bool link_mtu_defined
; /* true if user overriding parm with command line option */
201 /* Advanced MTU negotiation and datagram fragmentation options */
202 int mtu_discover_type
; /* used if OS supports setting Path MTU discovery options on socket */
208 int fragment
; /* internal fragmentation size */
212 int keepalive_ping
; /* a proxy for ping/ping-restart */
213 int keepalive_timeout
;
215 int inactivity_timeout
; /* --inactive */
216 int inactivity_minimum_bytes
;
218 int ping_send_timeout
; /* Send a TCP/UDP ping to remote every n seconds */
219 int ping_rec_timeout
; /* Expect a TCP/UDP ping from remote at least once every n seconds */
220 bool ping_timer_remote
; /* Run ping timer only if we have a remote address */
221 bool tun_ipv6
; /* Build tun dev that supports IPv6 */
223 # define PING_UNDEF 0
225 # define PING_RESTART 2
226 int ping_rec_timeout_action
; /* What action to take on ping_rec_timeout (exit or restart)? */
229 int explicit_exit_notification
; /* Explicitly tell peer when we are exiting via OCC_EXIT message */
232 bool persist_tun
; /* Don't close/reopen TUN/TAP dev on SIGUSR1 or PING_RESTART */
233 bool persist_local_ip
; /* Don't re-resolve local address on SIGUSR1 or PING_RESTART */
234 bool persist_remote_ip
; /* Don't re-resolve remote address on SIGUSR1 or PING_RESTART */
235 bool persist_key
; /* Don't re-read key files on SIGUSR1 or PING_RESTART */
237 int mssfix
; /* Upper bound on TCP MSS */
238 bool mssfix_default
; /* true if --mssfix was supplied without a parameter */
240 #if PASSTOS_CAPABILITY
244 int resolve_retry_seconds
; /* If hostname resolve fails, retry for n seconds */
246 struct tuntap_options tuntap_options
;
249 const char *username
;
250 const char *groupname
;
251 const char *chroot_dir
;
253 const char *writepid
;
254 const char *up_script
;
255 const char *down_script
;
263 /* inetd modes defined in socket.h */
267 bool suppress_timestamps
;
276 const char *status_file
;
277 int status_file_version
;
278 int status_file_update_freq
;
280 /* optimize TUN/TAP/UDP writes */
284 /* LZO_x flags from lzo.h */
293 unsigned int sockflags
;
295 /* route management */
296 const char *route_script
;
297 const char *route_default_gateway
;
298 int route_default_metric
;
301 int route_delay_window
;
302 bool route_delay_defined
;
303 struct route_option_list
*routes
;
305 bool route_gateway_via_dhcp
;
306 bool allow_pull_fqdn
; /* as a client, allow server to push a FQDN for certain parameters */
309 /* Enable options consistency check between peers */
313 #ifdef ENABLE_MANAGEMENT
314 const char *management_addr
;
316 const char *management_user_pass
;
317 int management_log_history_cache
;
318 int management_echo_buffer_size
;
319 int management_state_buffer_size
;
320 const char *management_write_peer_info_file
;
322 const char *management_client_user
;
323 const char *management_client_group
;
325 /* Mask of MF_ values of manage.h */
326 unsigned int management_flags
;
330 struct plugin_option_list
*plugin_list
;
342 in_addr_t server_network
;
343 in_addr_t server_netmask
;
345 # define SF_NOPOOL (1<<0)
346 unsigned int server_flags
;
348 bool server_bridge_proxy_dhcp
;
350 bool server_bridge_defined
;
351 in_addr_t server_bridge_ip
;
352 in_addr_t server_bridge_netmask
;
353 in_addr_t server_bridge_pool_start
;
354 in_addr_t server_bridge_pool_end
;
356 struct push_list
*push_list
;
357 bool ifconfig_pool_defined
;
358 in_addr_t ifconfig_pool_start
;
359 in_addr_t ifconfig_pool_end
;
360 in_addr_t ifconfig_pool_netmask
;
361 const char *ifconfig_pool_persist_filename
;
362 int ifconfig_pool_persist_refresh_freq
;
364 int virtual_hash_size
;
365 const char *client_connect_script
;
366 const char *client_disconnect_script
;
367 const char *learn_address_script
;
369 const char *client_config_dir
;
374 struct iroute
*iroutes
;
375 bool push_ifconfig_defined
;
376 in_addr_t push_ifconfig_local
;
377 in_addr_t push_ifconfig_remote_netmask
;
378 bool push_ifconfig_constraint_defined
;
379 in_addr_t push_ifconfig_constraint_network
;
380 in_addr_t push_ifconfig_constraint_netmask
;
386 int max_routes_per_client
;
388 bool client_cert_not_required
;
389 bool username_as_common_name
;
390 const char *auth_user_pass_verify_script
;
391 bool auth_user_pass_verify_script_via_file
;
393 char *port_share_host
;
399 bool pull
; /* client pull of config options from server */
400 const char *auth_user_pass_file
;
401 struct options_pre_pull
*pre_pull
;
403 int scheduled_exit_interval
;
409 const char *shared_secret_file
;
410 #if ENABLE_INLINE_FILES
411 const char *shared_secret_file_inline
;
414 bool ciphername_defined
;
415 const char *ciphername
;
416 bool authname_defined
;
417 const char *authname
;
421 bool mute_replay_warnings
;
424 const char *packet_id_file
;
429 /* TLS (control channel) parms */
435 const char *cert_file
;
436 const char *priv_key_file
;
437 const char *pkcs12_file
;
438 const char *cipher_list
;
439 const char *tls_verify
;
440 const char *tls_remote
;
441 const char *crl_file
;
443 #if ENABLE_INLINE_FILES
444 const char *ca_file_inline
;
445 const char *cert_file_inline
;
446 char *priv_key_file_inline
;
447 const char *dh_file_inline
;
450 int ns_cert_type
; /* set to 0, NS_SSL_SERVER, or NS_SSL_CLIENT */
451 unsigned remote_cert_ku
[MAX_PARMS
];
452 const char *remote_cert_eku
;
455 const char *pkcs11_providers
[MAX_PARMS
];
456 unsigned pkcs11_private_mode
[MAX_PARMS
];
457 bool pkcs11_protected_authentication
[MAX_PARMS
];
458 bool pkcs11_cert_private
[MAX_PARMS
];
459 int pkcs11_pin_cache_period
;
460 const char *pkcs11_id
;
461 bool pkcs11_id_management
;
465 const char *cryptoapi_cert
;
468 /* data channel key exchange method */
471 /* Per-packet timeout on control channel */
474 /* Data channel key renegotiation parameters */
475 int renegotiate_bytes
;
476 int renegotiate_packets
;
477 int renegotiate_seconds
;
479 /* Data channel key handshake must finalize
480 within n seconds of handshake initiation. */
481 int handshake_window
;
483 /* Old key allowed to live n seconds after new key goes active */
484 int transition_window
;
486 /* Special authentication MAC for TLS control channel */
487 const char *tls_auth_file
; /* shared secret */
488 #if ENABLE_INLINE_FILES
489 const char *tls_auth_file_inline
;
492 /* Allow only one session */
498 #endif /* USE_CRYPTO */
500 /* special state parms */
501 int foreign_option_index
;
504 const char *exit_event_name
;
505 bool exit_event_initial_state
;
511 #define streq(x, y) (!strcmp((x), (y)))
516 #define OPT_P_GENERAL (1<<0)
517 #define OPT_P_UP (1<<1)
518 #define OPT_P_ROUTE (1<<2)
519 #define OPT_P_IPWIN32 (1<<3)
520 #define OPT_P_SCRIPT (1<<4)
521 #define OPT_P_SETENV (1<<5)
522 #define OPT_P_SHAPER (1<<6)
523 #define OPT_P_TIMER (1<<7)
524 #define OPT_P_PERSIST (1<<8)
525 #define OPT_P_PERSIST_IP (1<<9)
526 #define OPT_P_COMP (1<<10) /* TODO */
527 #define OPT_P_MESSAGES (1<<11)
528 #define OPT_P_CRYPTO (1<<12) /* TODO */
529 #define OPT_P_TLS_PARMS (1<<13) /* TODO */
530 #define OPT_P_MTU (1<<14) /* TODO */
531 #define OPT_P_NICE (1<<15)
532 #define OPT_P_PUSH (1<<16)
533 #define OPT_P_INSTANCE (1<<17)
534 #define OPT_P_CONFIG (1<<18)
535 #define OPT_P_EXPLICIT_NOTIFY (1<<19)
536 #define OPT_P_ECHO (1<<20)
537 #define OPT_P_INHERIT (1<<21)
538 #define OPT_P_ROUTE_EXTRAS (1<<22)
539 #define OPT_P_PULL_MODE (1<<23)
540 #define OPT_P_PLUGIN (1<<24)
541 #define OPT_P_SOCKBUF (1<<25)
542 #define OPT_P_SOCKFLAGS (1<<26)
543 #define OPT_P_CONNECTION (1<<27)
545 #define OPT_P_DEFAULT (~(OPT_P_INSTANCE|OPT_P_PULL_MODE))
548 #define PULL_DEFINED(opt) ((opt)->pull)
550 #define PUSH_DEFINED(opt) ((opt)->push_list)
555 #define PULL_DEFINED(opt) (false)
559 #define PUSH_DEFINED(opt) (false)
563 #define ROUTE_OPTION_FLAGS(o) ((o)->route_method & ROUTE_METHOD_MASK)
565 #define ROUTE_OPTION_FLAGS(o) (0)
568 #ifdef HAVE_GETTIMEOFDAY
569 #define SHAPER_DEFINED(opt) ((opt)->shaper)
571 #define SHAPER_DEFINED(opt) (false)
575 #define PLUGIN_OPTION_LIST(opt) ((opt)->plugin_list)
577 #define PLUGIN_OPTION_LIST(opt) (NULL)
580 #ifdef MANAGEMENT_DEF_AUTH
581 #define MAN_CLIENT_AUTH_ENABLED(opt) ((opt)->management_flags & MF_CLIENT_AUTH)
583 #define MAN_CLIENT_AUTH_ENABLED(opt) (false)
586 void parse_argv (struct options
*options
,
590 const unsigned int permission_mask
,
591 unsigned int *option_types_found
,
594 void notnull (const char *arg
, const char *description
);
596 void usage_small (void);
598 void init_options (struct options
*o
, const bool init_gc
);
599 void uninit_options (struct options
*o
);
601 void setenv_settings (struct env_set
*es
, const struct options
*o
);
602 void show_settings (const struct options
*o
);
604 bool string_defined_equal (const char *s1
, const char *s2
);
608 const char *options_string_version (const char* s
, struct gc_arena
*gc
);
610 char *options_string (const struct options
*o
,
611 const struct frame
*frame
,
614 struct gc_arena
*gc
);
616 bool options_cmp_equal_safe (char *actual
, const char *expected
, size_t actual_n
);
617 void options_warning_safe (char *actual
, const char *expected
, size_t actual_n
);
618 bool options_cmp_equal (char *actual
, const char *expected
);
619 void options_warning (char *actual
, const char *expected
);
623 void options_postprocess (struct options
*options
);
625 void pre_pull_save (struct options
*o
);
626 void pre_pull_restore (struct options
*o
);
628 bool apply_push_options (struct options
*options
,
630 unsigned int permission_mask
,
631 unsigned int *option_types_found
,
634 bool is_persist_option (const struct options
*o
);
635 bool is_stateful_restart (const struct options
*o
);
637 void options_detach (struct options
*o
);
639 void options_server_import (struct options
*o
,
640 const char *filename
,
642 unsigned int permission_mask
,
643 unsigned int *option_types_found
,
646 void pre_pull_default (struct options
*o
);
648 void rol_check_alloc (struct options
*options
);
650 int parse_line (const char *line
,
656 struct gc_arena
*gc
);
659 * parse/print topology coding
662 int parse_topology (const char *str
, const int msglevel
);
663 const char *print_topology (const int topology
);
666 * Manage auth-retry variable
672 #define AR_INTERACT 1
673 #define AR_NOINTERACT 2
675 int auth_retry_get (void);
676 bool auth_retry_set (const int msglevel
, const char *option
);
677 const char *auth_retry_print (void);
681 void options_string_import (struct options
*options
,
684 const unsigned int permission_mask
,
685 unsigned int *option_types_found
,
692 connection_list_defined (const struct options
*o
)
694 #ifdef ENABLE_CONNECTION
695 return o
->connection_list
!= NULL
;
702 connection_list_set_no_advance (struct options
*o
)
704 #ifdef ENABLE_CONNECTION
705 if (o
->connection_list
)
706 o
->connection_list
->no_advance
= true;