Go to the documentation of this file.
31 #include <systemd/sd-daemon.h>
67 #define CF_LOAD_PERSISTED_PACKET_ID (1<<0)
68 #define CF_INIT_TLS_MULTI (1<<1)
69 #define CF_INIT_TLS_AUTH_STANDALONE (1<<2)
115 const char *dev_type,
117 const char *ifconfig_local,
118 const char *ifconfig_remote,
120 const char *signal_text,
121 const char *script_type,
145 if (!ifconfig_remote)
147 ifconfig_remote =
"";
160 arg, tun_mtu, ifconfig_local, ifconfig_remote,
context);
164 msg(
M_FATAL,
"ERROR: up/down plugin call failed");
177 ifconfig_local, ifconfig_remote,
context);
208 #ifdef ENABLE_MANAGEMENT
218 if (
streq(p[1],
"NONE"))
222 else if (p[2] && p[3])
226 msg(
M_INFO,
"Proxy set via management, disabling Data Channel Offload.");
230 if (
streq(p[1],
"HTTP"))
235 msg(
M_WARN,
"HTTP proxy support only works for TCP based connections");
244 else if (
streq(p[1],
"SOCKS"))
314 const char *parameters)
317 size_t len = strlen(command) + 1 + strlen(parameters) + 1;
365 char *out = malloc(len);
374 msg(
M_WARN,
"Out of bounds index in management query for remote entry: index = %u", index);
389 if (!strcmp(p[1],
"ACCEPT"))
394 else if (!strcmp(p[1],
"SKIP"))
400 else if (!strcmp(p[1],
"MOD") && p[2] && p[3])
433 int ce_changed =
true;
486 for (i = 0; i < l->
len; ++i)
573 int advance_count = 1;
597 msg(
M_FATAL,
"No usable connection profiles are present");
612 #ifdef ENABLE_MANAGEMENT
631 }
while (!ce_defined);
637 msg(
M_FATAL,
"All connections have been connect-retry-max (%d) times unsuccessful, exiting",
659 #ifdef ENABLE_MANAGEMENT
694 bool did_http =
false;
742 #if defined(ENABLE_PKCS11)
746 pkcs11_initialize(
true, c->
options.pkcs11_pin_cache_period);
749 pkcs11_addProvider(c->
options.pkcs11_providers[i], c->
options.pkcs11_protected_authentication[i],
750 c->
options.pkcs11_private_mode[i], c->
options.pkcs11_cert_private[i]);
762 strcpy(up.
username,
"Please insert your cryptographic token");
769 #ifdef ENABLE_SYSTEMD
774 sd_notifyf(0,
"READY=1\nSTATUS=Pre-connection initialization successful\nMAINPID=%lu",
775 (
unsigned long) getpid());
791 close_port_share(
void)
795 port_share_close(port_share);
801 init_port_share(
struct context *c)
803 if (!port_share && (c->
options.port_share_host && c->
options.port_share_port))
805 port_share = port_share_open(c->
options.port_share_host,
808 c->
options.port_share_journal_dir);
809 if (port_share == NULL)
811 msg(
M_FATAL,
"Fatal error: Port sharing failed");
825 crypto_init_dmalloc();
836 if (!gettimeofday(&tv, NULL))
838 const unsigned int seed = (
unsigned int) tv.tv_sec ^ tv.tv_usec;
849 #ifdef OPENVPN_DEBUG_COMMAND_LINE
852 for (i = 0; i < argc; ++i)
873 #ifdef IFCONFIG_POOL_TEST
874 ifconfig_pool_test(0x0A010004, 0x0A0100FF);
878 #ifdef CHARACTER_CLASS_DEBUG
879 character_class_debug();
883 #ifdef EXTRACT_X509_FIELD_TEST
893 #ifdef TEST_GET_DEFAULT_GATEWAY
907 const char *fn = gen_path(
"foo",
916 #ifdef STATUS_PRINTF_TEST
925 msg(
M_WARN,
"STATUS_PRINTF_TEST: %s: write error", tmp_file);
935 mstats_open(
"/dev/shm/mstats.dat");
936 for (i = 0; i < 30; ++i)
938 mmap_stats->n_clients += 1;
939 mmap_stats->link_write_bytes += 8;
940 mmap_stats->link_read_bytes += 16;
964 #if defined(MEASURE_TLS_HANDSHAKE_STATS)
965 show_tls_performance_stats();
1057 msg(
M_USAGE,
"Using --genkey type with --secret filename is "
1058 "not supported. Use --genkey type filename instead.");
1066 msg(
M_USAGE,
"You must provide a filename to either --genkey "
1067 "or --secret, not both");
1076 msg(
M_WARN,
"WARNING: Using --genkey --secret filename is "
1077 "DEPRECATED. Use --genkey secret filename instead.");
1082 if (nbits_written < 0)
1088 "Randomly generated %d bit key written to %s", nbits_written,
1102 "--genkey tls-crypt-v2-client requires a server key to be set via --tls-crypt-v2 to create a client key");
1141 "options --mktun or --rmtun should only be used together with --dev");
1144 #if defined(ENABLE_DCO)
1156 msg(
M_WARN,
"Note: --mktun does not support DCO. Creating TUN interface.");
1163 #ifdef ENABLE_FEATURE_TUN_PERSIST
1175 "options --mktun and --rmtun are not available on your operating "
1176 "system. Please check 'man tun' (or 'tap'), whether your system "
1177 "supports using 'ifconfig %s create' / 'destroy' to create/remove "
1178 "persistent tunnel interfaces.",
options->
dev );
1192 #ifdef ENABLE_SYSTEMD
1194 if (sd_notify(0,
"READY=0") > 0)
1204 #if defined(__APPLE__) && defined(__clang__)
1205 #pragma clang diagnostic push
1206 #pragma clang diagnostic ignored "-Wdeprecated-declarations"
1210 msg(
M_ERR,
"daemon() failed or unsupported");
1212 #if defined(__APPLE__) && defined(__clang__)
1213 #pragma clang diagnostic pop
1232 static const char why_not[] =
"will be delayed because of --client, --pull, or --up-delay";
1246 msg(
M_INFO,
"NOTE: chroot %s", why_not);
1261 msg(
M_INFO,
"NOTE: UID/GID downgrade %s", why_not);
1265 #ifdef ENABLE_MEMSTATS
1268 mstats_open(c->
options.memstats_fn);
1272 #ifdef ENABLE_SELINUX
1279 if (c->
options.selinux_context)
1283 if (-1 == setcon(c->
options.selinux_context))
1285 msg(
M_ERR,
"setcon to '%s' failed; is /proc accessible?", c->
options.selinux_context);
1294 msg(
M_INFO,
"NOTE: setcon %s", why_not);
1502 const char *gw = NULL;
1548 const char *gw = NULL;
1572 char *opt_list[] = {
"::/3",
"2000::/4",
"3000::/4",
"fc00::/7", NULL };
1575 for (i = 0; opt_list[i]; i++)
1603 static const char message[] =
"Initialization Sequence Completed";
1617 msg(
M_INFO,
"%s With Errors ( see http://openvpn.net/faq.html#dhcpclientserv )", message);
1619 #ifdef ENABLE_SYSTEMD
1620 sd_notifyf(0,
"STATUS=Failed to start up: %s With Errors\nERRNO=1", message);
1627 #ifdef ENABLE_SYSTEMD
1628 sd_notifyf(0,
"STATUS=%s", message);
1643 #ifdef ENABLE_MANAGEMENT
1647 in_addr_t *tun_local = NULL;
1648 struct in6_addr *tun_local6 = NULL;
1651 socklen_t sa_len =
sizeof(local);
1652 const char *detail =
"SUCCESS";
1660 #if defined(_WIN32) || defined(ENABLE_SITNL)
1663 detail =
"ROUTE_ERROR";
1669 remote = actual->
dest;
1671 #if ENABLE_IP_PKTINFO
1674 switch (local.
addr.
sa.sa_family)
1677 #if defined(HAVE_IN_PKTINFO) && defined(HAVE_IPI_SPEC_DST)
1678 local.
addr.
in4.sin_addr = actual->pi.in4.ipi_spec_dst;
1680 local.
addr.
in4.sin_addr = actual->pi.in4;
1685 local.
addr.
in6.sin6_addr = actual->pi.in6.ipi6_addr;
1731 #ifdef ENABLE_MANAGEMENT
1742 msg(
M_WARN,
"WARNING: route-up plugin call failed");
1810 #ifdef TARGET_ANDROID
1826 #ifdef TARGET_ANDROID
1851 msg(
D_ROUTE,
"interactive service msg_channel=%" PRIuPTR,
1894 #ifdef TARGET_ANDROID
1963 msg(
M_INFO,
"Preserving previous TUN/TAP instance: %s",
2057 #ifdef ENABLE_MANAGEMENT
2210 msg(
D_DCO,
"Cannot set parameters for DCO peer (id=%u): %s",
2226 if (
buf_len(buf) > strlen(header))
2243 uint8_t line[1024] = { 0 };
2249 buf_printf(&out,
"Data Channel: cipher '%s'",
2254 buf_printf(&out,
"Data Channel: cipher '%s', auth '%s'",
2264 if (c->
c2.comp_context)
2266 buf_printf(&out,
", compression: '%s'", c->
c2.comp_context->alg.name);
2274 const char *header =
"Timers: ";
2315 if (
buf_len(&out) > strlen(header))
2321 header =
"Protocol options: ";
2349 if (
buf_len(&out) > strlen(header))
2366 struct frame *frame_fragment = NULL;
2367 #ifdef ENABLE_FRAGMENT
2388 do_up(
struct context *c,
bool pulled_options,
unsigned int option_types_found)
2390 int error_flags = 0;
2421 msg(
M_INFO,
"NOTE: Pulled options changed on restart, will need to close and reopen TUN/TAP device.");
2428 msg(
M_NONFATAL,
"dco-win doesn't yet support reopening TUN device");
2457 msg(
D_DCO,
"Cannot add peer to DCO: %s (%d)", strerror(-ret), ret);
2481 msg(
D_TLS_ERRORS,
"ERROR: Failed to apply P2P negotiated protocol options");
2489 msg(
D_TLS_ERRORS,
"ERROR: Failed to apply DCO keepalive or MSS fix parameters");
2534 unsigned int flags =
2582 "--data-ciphers-fallback not enabled. No usable "
2583 "data channel cipher");
2587 struct frame *frame_fragment = NULL;
2588 #ifdef ENABLE_FRAGMENT
2614 msg(
D_PUSH,
"OPTIONS IMPORT: --verb and/or --mute level changed");
2626 msg(
D_PUSH,
"OPTIONS IMPORT: --explicit-exit-notify can only be used with --proto udp");
2631 msg(
D_PUSH_DEBUG,
"OPTIONS IMPORT: explicit notify parm(s) modified");
2640 "settings that are not allowed and will result "
2641 "in a non-working connection. "
2642 "See also allow-compression in the manual.");
2647 comp_uninit(c->
c2.comp_context);
2654 msg(
D_PUSH,
"OPTIONS IMPORT: traffic shaper enabled");
2660 msg(
D_PUSH,
"OPTIONS IMPORT: --sndbuf/--rcvbuf options modified");
2666 msg(
D_PUSH,
"OPTIONS IMPORT: --socket-flags option modified");
2672 msg(
D_PUSH,
"OPTIONS IMPORT: --persist options modified");
2676 msg(
D_PUSH,
"OPTIONS IMPORT: --ifconfig/up options modified");
2680 msg(
D_PUSH,
"OPTIONS IMPORT: route options modified");
2684 msg(
D_PUSH,
"OPTIONS IMPORT: route-related options modified");
2688 msg(
D_PUSH,
"OPTIONS IMPORT: --ip-win32 and/or --dhcp-option options modified");
2692 msg(
D_PUSH,
"OPTIONS IMPORT: environment modified");
2715 "with data channel offload. Use --disable-dco to connect to "
2732 "tun-mtu-max %d in the client configuration",
2748 #ifdef ENABLE_MANAGEMENT
2783 if (GREMLIN_CONNECTION_FLOOD_LEVEL(c->
options.gremlin))
2953 msg(
D_MTU_DEBUG,
"MTU: adding %zu buffer tailroom for compression for %zu "
2996 #ifdef ENABLE_PREDICTION_RESISTANCE
2997 if (c->
options.use_prediction_resistance)
2999 rand_ctx_enable_prediction_resistance();
3049 msg(
M_INFO,
"Re-using pre-shared static key");
3076 msg(
M_FATAL,
"ERROR: tls-auth enabled, but no valid --auth "
3085 "Control Channel Authentication",
"tls-auth",
3125 msg(
M_WARN,
"ERROR: tls-crypt-v2 client key too large to work with "
3126 "requested --max-packet-size %d, requires at least "
3127 "--max-packet-size %d. Packets will ignore requested "
3157 msg(
M_FATAL,
"Error: private key password verification failed");
3242 bool packet_id_long_form;
3274 if (packet_id_long_form)
3349 #ifdef ENABLE_X509ALTUSERNAME
3363 #ifdef ENABLE_MANAGEMENT
3385 #ifdef ENABLE_MANAGEMENT
3393 #ifdef HAVE_EXPORT_KEYING_MATERIAL
3394 if (
options->keying_material_exporter_label)
3480 "Control Channel MTU parms");
3490 "TLS-Auth MTU parms");
3510 "******* WARNING *******: All encryption and authentication features "
3511 "disabled -- All data will be tunnelled as clear text and will not be "
3512 "protected against man-in-the-middle changes. "
3513 "PLEASE DO RECONSIDER THIS CONFIGURATION!");
3550 #ifdef ENABLE_FRAGMENT
3560 #if defined(ENABLE_FRAGMENT)
3567 "WARNING: using --fragment and --mtu-test together may produce an inaccurate MTU test result");
3571 #ifdef ENABLE_FRAGMENT
3574 msg(
M_WARN,
"WARNING: if you use --mssfix and --fragment, you should "
3575 "set --fragment (%d) larger or equal than --mssfix (%d)",
3581 msg(
M_WARN,
"WARNING: if you use --mssfix and --fragment, you should "
3582 "use the \"mtu\" flag for both or none of of them.");
3594 msg(
M_WARN,
"WARNING: --ping should normally be used with --ping-restart or --ping-exit");
3598 #ifdef ENABLE_SELINUX
3599 || o->selinux_context
3605 msg(
M_WARN,
"WARNING: you are using user/group/chroot/setcon without persist-tun -- this may cause restarts to fail");
3608 #ifdef ENABLE_PKCS11
3613 msg(
M_WARN,
"WARNING: you are using user/group/chroot/setcon without persist-key -- this may cause restarts to fail");
3619 msg(
M_WARN,
"WARNING: you are using chroot without specifying user and group -- this may cause the chroot jail to be insecure");
3624 msg(
M_WARN,
"WARNING: using --pull/--client and --ifconfig together is probably not what you want");
3629 msg(
M_WARN,
"NOTE: when bridging your LAN adapter with the TAP adapter, note that the new bridge adapter will often take on its own IP address that is different from what the LAN adapter was previously set to");
3636 msg(
M_WARN,
"WARNING: using --duplicate-cn and --client-config-dir together is probably not what you want");
3640 msg(
M_WARN,
"WARNING: --ifconfig-pool-persist will not work with --duplicate-cn");
3644 msg(
M_WARN,
"WARNING: --keepalive option is missing from server config");
3650 msg(
M_WARN,
"WARNING: You have disabled Replay Protection (--no-replay) which may make " PACKAGE_NAME " less secure");
3663 msg(
M_WARN,
"WARNING: No server certificate verification method has been enabled. See http://openvpn.net/howto.html#mitm for more info.");
3667 msg(
M_WARN,
"WARNING: --ns-cert-type is DEPRECATED. Use --remote-cert-tls instead.");
3675 msg(
M_WARN,
"NOTE: the current --script-security setting may allow this configuration to call user-defined scripts");
3679 msg(
M_WARN,
"WARNING: the current --script-security setting may allow passwords to be passed to scripts via environmental variables");
3683 msg(
M_WARN,
"NOTE: starting with " PACKAGE_NAME " 2.1, '--script-security 2' or higher is required to call user-defined scripts or executables");
3707 b->decompress_buf =
alloc_buf(buf_size);
3745 #ifdef ENABLE_FRAGMENT
3778 #ifdef ENABLE_FRAGMENT
3782 "Fragmentation MTU parms");
3805 msg(
D_SHOW_OCC,
"Expected Remote Options String (VER=%s): '%s'",
3984 #ifdef ENABLE_FRAGMENT
4005 bool need_us_timeout)
4007 unsigned int flags = 0;
4013 if (need_us_timeout)
4130 msg(
M_INFO,
"NOTE: --fast-io is disabled since we are running on Windows");
4134 msg(
M_INFO,
"NOTE: --fast-io is disabled since we are not using UDP");
4140 msg(
M_INFO,
"NOTE: --fast-io is disabled since we are using --shaper");
4164 #ifdef ENABLE_PLUGIN
4190 for (i = 0; i < config.
n; ++i)
4192 unsigned int option_types_found = 0;
4199 &option_types_found,
4236 #ifdef ENABLE_MANAGEMENT
4251 msg(msglevel,
"END");
4253 msg(msglevel,
"ERROR: Sorry, this command is currently only implemented on Windows");
4257 #ifdef TARGET_ANDROID
4259 management_callback_network_change(
void *arg,
bool samenetwork)
4301 #ifdef ENABLE_MANAGEMENT
4312 #ifdef TARGET_ANDROID
4313 cb.network_change = management_callback_network_change;
4322 #ifdef ENABLE_MANAGEMENT
4371 msg(
M_WARN,
"Signal received from management interface, exiting");
4399 #ifdef ENABLE_MANAGEMENT
4410 #ifdef ENABLE_MANAGEMENT
4532 #ifdef ENABLE_PLUGIN
4586 #ifdef ENABLE_FRAGMENT
4596 unsigned int crypto_flags = 0;
4636 #ifdef ENABLE_FRAGMENT
4654 int error_flags = 0;
4678 #ifdef ENABLE_PLUGIN
4715 #ifdef ENABLE_PLUGIN
4763 if (c->
c2.comp_context)
4765 comp_uninit(c->
c2.comp_context);
4766 c->
c2.comp_context = NULL;
4789 #ifdef ENABLE_MANAGEMENT
4796 #ifdef ENABLE_PLUGIN
4807 #ifdef ENABLE_FRAGMENT
4868 #ifdef ENABLE_PLUGIN
4950 dest->
c2.comp_context = NULL;
4991 unsigned int pid = 0;
4995 msg(
M_ERR,
"Open error on pid file %s", filename);
5000 fprintf(fp,
"%u\n", pid);
5003 msg(
M_ERR,
"Close error on pid file %s", filename);
const char * tls_crypt_file
struct status_output * status_open(const char *filename, const int refresh_freq, const int msglevel, const struct virtual_output *vout, const unsigned int flags)
struct openvpn_plugin_string_list * list[MAX_PLUGINS]
struct tuntap * init_tun(const char *dev, const char *dev_type, int topology, const char *ifconfig_local_parm, const char *ifconfig_remote_netmask_parm, const char *ifconfig_ipv6_local_parm, int ifconfig_ipv6_netbits_parm, const char *ifconfig_ipv6_remote_parm, struct addrinfo *local_public, struct addrinfo *remote_public, const bool strict_warn, struct env_set *es, openvpn_net_ctx_t *ctx, struct tuntap *tt)
static void do_close_ifconfig_pool_persist(struct context *c)
unsigned int pull_permission_mask(const struct context *c)
struct event_timeout route_wakeup
void tun_standby_init(struct tuntap *tt)
bool do_test_crypto(const struct options *o)
struct tls_auth_standalone * tls_auth_standalone
TLS state structure required for the initial authentication of a client's connection attempt.
enum genkey_type genkey_type
struct plugin_list * plugin_list_init(const struct plugin_option_list *list)
void management_set_state(struct management *man, const int state, const char *detail, const in_addr_t *tun_local_ip, const struct in6_addr *tun_local_ip6, const struct openvpn_sockaddr *local, const struct openvpn_sockaddr *remote)
static void do_close_plugins(struct context *c)
int write_key_file(const int nkeys, const char *filename)
Write nkeys 1024-bits keys to file.
volatile int signal_received
void do_ifconfig_setenv(const struct tuntap *tt, struct env_set *es)
static void do_init_server_poll_timeout(struct context *c)
void tls_init_control_channel_frame_parameters(struct frame *frame, int tls_mtu)
static void next_connection_entry(struct context *c)
#define CE_MAN_QUERY_REMOTE_MOD
union openvpn_sockaddr::@14 addr
struct verify_hash_list * verify_hash
#define OPENVPN_PLUGIN_UP
void tls_crypt_v2_init_server_key(struct key_ctx *key_ctx, bool encrypt, const char *key_file, bool key_inline)
Initialize a tls-crypt-v2 server key (used to encrypt/decrypt client keys).
unsigned int mss_fix
The actual MSS value that should be written to the payload packets.
void get_default_gateway_ipv6(struct route_ipv6_gateway_info *rgi6, const struct in6_addr *dest, openvpn_net_ctx_t *ctx)
const char * config_ncp_ciphers
void management_post_tunnel_open(struct management *man, const in_addr_t tun_local_ip)
static void do_close_tls(struct context *c)
void fragment_frame_init(struct fragment_master *f, const struct frame *frame)
Allocate internal packet buffers for a fragment_master structure.
void notnull(const char *arg, const char *description)
const char * verify_x509_name
struct static_challenge_info sc_info
#define OPENVPN_PLUGIN_DOWN
struct key2 original_wrap_keydata
original key data to be xored in to the key for dynamic tls-crypt.
const struct link_socket * accept_from
bool enable_ncp_fallback
If defined fall back to ciphername if NCP fails.
void add_route_ipv6_to_option_list(struct route_ipv6_option_list *l, const char *prefix, const char *gateway, const char *metric)
static struct gc_arena gc_new(void)
struct fragment_master * fragment_init(struct frame *frame)
Allocate and initialize a fragment_master structure.
void do_ifconfig(struct tuntap *tt, const char *ifname, int tun_mtu, const struct env_set *es, openvpn_net_ctx_t *ctx)
do_ifconfig - configure the tunnel interface
int connect_retry_seconds
int explicit_exit_notification
struct tls_multi * tls_multi
TLS state structure for this VPN tunnel.
bool open_management(struct context *c)
struct frame frame_initial
void fragment_free(struct fragment_master *f)
Free a fragment_master structure and its internal packet buffers.
static bool key_ctx_bi_defined(const struct key_ctx_bi *key)
struct context_persist persist
Persistent context.
int len
Length in bytes of the actual content within the allocated memory.
void restore_signal_state(void)
void frame_print(const struct frame *frame, int level, const char *prefix)
const char * socks_proxy_server
int set_lladdr(openvpn_net_ctx_t *ctx, const char *ifname, const char *lladdr, const struct env_set *es)
void open_tun(const char *dev, const char *dev_type, const char *dev_node, struct tuntap *tt, openvpn_net_ctx_t *ctx)
static void init_connection_list(struct context *c)
void packet_id_init(struct packet_id *p, int seq_backtrack, int time_backtrack, const char *name, int unit)
bool management_hold(struct management *man, int holdtime)
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.
void init_query_passwords(const struct context *c)
Query for private key and auth-user-pass username/passwords.
void env_set_destroy(struct env_set *es)
const char * auth_token_secret_file
#define EVENT_METHOD_US_TIMEOUT
enum windows_driver_type windows_driver
char * options_string(const struct options *o, const struct frame *frame, struct tuntap *tt, openvpn_net_ctx_t *ctx, bool remote, struct gc_arena *gc)
struct tuntap * tuntap
Tun/tap virtual network interface.
bool tls_crypt_file_inline
static void set_check_status_error_delay(unsigned int milliseconds)
const char * proto2ascii(int proto, sa_family_t af, bool display_form)
int64_t inactivity_minimum_bytes
void packet_id_persist_load(struct packet_id_persist *p, const char *filename)
static void do_close_free_buf(struct context *c)
const struct buffer * tls_crypt_v2_wkc
Wrapped client key, sent to server.
static int occ_reset_op(void)
void management_sleep(const int n)
A sleep function that services the management layer for n seconds rather than doing nothing.
bool tuntap_owned
Whether the tun/tap interface should be cleaned up when this context is cleaned up.